cleanup logging a bit

This commit is contained in:
dignifiedquire
2019-05-07 18:28:16 +01:00
parent 671271a999
commit 127677223e
5 changed files with 277 additions and 440 deletions

View File

@@ -520,7 +520,6 @@ pub unsafe fn dc_cmdline(context: &dc_context_t, cmdline: &str) -> *mut libc::c_
let arg1_c = CString::new(arg1).unwrap(); let arg1_c = CString::new(arg1).unwrap();
let arg2 = args.next().unwrap_or_default(); let arg2 = args.next().unwrap_or_default();
let arg2_c = CString::new(arg2).unwrap(); let arg2_c = CString::new(arg2).unwrap();
println!("{} -- {:?}, {}, {}", cmdline, args.clone().collect::<Vec<_>>(), arg1, arg2);
if cmdline == "help" || cmdline == "?" { if cmdline == "help" || cmdline == "?" {
if arg1 == "imex" { if arg1 == "imex" {

View File

@@ -154,13 +154,10 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
b"Configure ...\x00" as *const u8 as *const libc::c_char, b"Configure ...\x00" as *const u8 as *const libc::c_char,
); );
println!("configure lock");
let s_a = context.running_state.clone(); let s_a = context.running_state.clone();
let s = s_a.read().unwrap(); let s = s_a.read().unwrap();
println!("ongoing: {:?}", s);
if !s.shall_stop_ongoing { if !s.shall_stop_ongoing {
println!("configure progress");
(context.cb)( (context.cb)(
context, context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
@@ -174,14 +171,12 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
0i32 as uintptr_t, 0i32 as uintptr_t,
); );
param = dc_loginparam_new(); param = dc_loginparam_new();
println!("reading params");
dc_loginparam_read( dc_loginparam_read(
context, context,
param, param,
&context.sql.clone().read().unwrap(), &context.sql.clone().read().unwrap(),
b"\x00" as *const u8 as *const libc::c_char, b"\x00" as *const u8 as *const libc::c_char,
); );
println!("got params");
if (*param).addr.is_null() { if (*param).addr.is_null() {
dc_log_error( dc_log_error(
@@ -1760,7 +1755,6 @@ pub unsafe fn dc_connect_to_configured_imap(
context: &dc_context_t, context: &dc_context_t,
imap: &dc_imap_t, imap: &dc_imap_t,
) -> libc::c_int { ) -> libc::c_int {
println!("connect to imap");
let mut ret_connected: libc::c_int = 0i32; let mut ret_connected: libc::c_int = 0i32;
let mut param: *mut dc_loginparam_t = dc_loginparam_new(); let mut param: *mut dc_loginparam_t = dc_loginparam_new();
if imap.is_connected() { if imap.is_connected() {
@@ -1790,6 +1784,5 @@ pub unsafe fn dc_connect_to_configured_imap(
} }
} }
dc_loginparam_unref(param); dc_loginparam_unref(param);
println!("done, {}", ret_connected);
ret_connected ret_connected
} }

View File

@@ -389,11 +389,9 @@ impl dc_imap_t {
match connection_res { match connection_res {
Ok(client) => { Ok(client) => {
println!("imap: loggingin with user {}", imap_user);
// TODO: handle oauth2 // TODO: handle oauth2
match client.login(imap_user, imap_pw) { match client.login(imap_user, imap_pw) {
Ok(mut session) => { Ok(mut session) => {
println!("imap: logged in");
// TODO: error handling // TODO: error handling
let caps = session.capabilities().unwrap(); let caps = session.capabilities().unwrap();
let can_idle = caps.has("IDLE"); let can_idle = caps.has("IDLE");
@@ -406,14 +404,7 @@ impl dc_imap_t {
}); });
let caps_list_c = std::ffi::CString::new(caps_list).unwrap(); let caps_list_c = std::ffi::CString::new(caps_list).unwrap();
unsafe { info!(context, 0, "IMAP-capabilities:%s", caps_list_c.as_ptr());
dc_log_info(
context,
0,
b"IMAP-capabilities:%s\x00" as *const u8 as *const libc::c_char,
caps_list_c.as_ptr(),
)
};
let mut config = self.config.write().unwrap(); let mut config = self.config.write().unwrap();
config.can_idle = can_idle; config.can_idle = can_idle;
@@ -465,8 +456,6 @@ impl dc_imap_t {
} }
pub fn disconnect(&self, context: &dc_context_t) { pub fn disconnect(&self, context: &dc_context_t) {
println!("disconnecting");
let mut session = self.session.lock().unwrap().take(); let mut session = self.session.lock().unwrap().take();
if session.is_some() { if session.is_some() {
match session.unwrap().close() { match session.unwrap().close() {
@@ -491,14 +480,7 @@ impl dc_imap_t {
cfg.watch_folder = None; cfg.watch_folder = None;
cfg.selected_folder = None; cfg.selected_folder = None;
cfg.selected_mailbox = None; cfg.selected_mailbox = None;
info!(context, 0, "IMAP disconnected.",);
unsafe {
dc_log_info(
context,
0,
b"IMAP disconnected.\x00" as *const u8 as *const libc::c_char,
)
};
} }
pub fn set_watch_folder(&self, watch_folder: *const libc::c_char) { pub fn set_watch_folder(&self, watch_folder: *const libc::c_char) {
@@ -506,7 +488,6 @@ impl dc_imap_t {
} }
pub fn fetch(&self, context: &dc_context_t) -> libc::c_int { pub fn fetch(&self, context: &dc_context_t) -> libc::c_int {
println!("dc_imap_fetch");
let mut success = 0; let mut success = 0;
let watch_folder = self.config.read().unwrap().watch_folder.to_owned(); let watch_folder = self.config.read().unwrap().watch_folder.to_owned();
@@ -521,7 +502,6 @@ impl dc_imap_t {
success = 1; success = 1;
} }
println!("dc_imap_fetch done {}", success);
success success
} }
@@ -546,14 +526,12 @@ impl dc_imap_t {
// deselect existing folder, if needed (it's also done implicitly by SELECT, however, without EXPUNGE then) // deselect existing folder, if needed (it's also done implicitly by SELECT, however, without EXPUNGE then)
if self.config.read().unwrap().selected_folder_needs_expunge { if self.config.read().unwrap().selected_folder_needs_expunge {
if let Some(ref folder) = self.config.read().unwrap().selected_folder { if let Some(ref folder) = self.config.read().unwrap().selected_folder {
unsafe { info!(
dc_log_info( context,
context, 0,
0, "Expunge messages in \"%s\".",
b"Expunge messages in \"%s\".\x00" as *const u8 as *const libc::c_char, CString::new(folder.to_owned()).unwrap().as_ptr()
CString::new(folder.to_owned()).unwrap().as_ptr(), );
)
};
// a CLOSE-SELECT is considerably faster than an EXPUNGE-SELECT, see https://tools.ietf.org/html/rfc3501#section-6.4.2 // a CLOSE-SELECT is considerably faster than an EXPUNGE-SELECT, see https://tools.ietf.org/html/rfc3501#section-6.4.2
if let Some(ref mut session) = *self.session.lock().unwrap() { if let Some(ref mut session) = *self.session.lock().unwrap() {
@@ -573,13 +551,7 @@ impl dc_imap_t {
} }
Err(err) => { Err(err) => {
eprintln!("select error: {:?}", err); eprintln!("select error: {:?}", err);
unsafe { info!(context, 0, "Cannot select folder.");
dc_log_info(
context,
0,
b"Cannot select folder.\x00" as *const u8 as *const libc::c_char,
)
};
self.config.write().unwrap().selected_folder = None; self.config.write().unwrap().selected_folder = None;
} }
} }
@@ -618,53 +590,41 @@ impl dc_imap_t {
} }
fn fetch_from_single_folder<S: AsRef<str>>(&self, context: &dc_context_t, folder: S) -> usize { fn fetch_from_single_folder<S: AsRef<str>>(&self, context: &dc_context_t, folder: S) -> usize {
println!("fetching from single folder");
if !self.is_connected() { if !self.is_connected() {
unsafe { info!(
dc_log_info( context,
context, 0,
0, "Cannot fetch from \"%s\" - not connected.",
b"Cannot fetch from \"%s\" - not connected.\x00" as *const u8 CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
as *const libc::c_char, );
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
)
};
return 0; return 0;
} }
if self.select_folder(context, Some(&folder)) == 0 { if self.select_folder(context, Some(&folder)) == 0 {
unsafe { info!(
dc_log_info( context,
context, 0,
0, "Cannot select folder \"%s\" for fetching.",
b"Cannot select folder \"%s\" for fetching.\x00" as *const u8 CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
as *const libc::c_char, );
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
)
};
return 0; return 0;
} }
println!("selected folder {}", folder.as_ref());
let (mut uid_validity, mut last_seen_uid) = self.get_config_last_seen_uid(context, &folder); let (mut uid_validity, mut last_seen_uid) = self.get_config_last_seen_uid(context, &folder);
println!("got validity: {} - {}", uid_validity, last_seen_uid);
let config = self.config.read().unwrap(); let config = self.config.read().unwrap();
let mailbox = config.selected_mailbox.as_ref().expect("just selected"); let mailbox = config.selected_mailbox.as_ref().expect("just selected");
if mailbox.uid_validity.is_none() { if mailbox.uid_validity.is_none() {
unsafe { error!(
dc_log_error( context,
context, 0,
0, "Cannot get UIDVALIDITY for folder \"%s\".",
b"Cannot get UIDVALIDITY for folder \"%s\".\x00" as *const u8 CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
as *const libc::c_char, );
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
)
};
return 0; return 0;
} }
@@ -672,14 +632,12 @@ impl dc_imap_t {
// first time this folder is selected or UIDVALIDITY has changed, init lastseenuid and save it to config // first time this folder is selected or UIDVALIDITY has changed, init lastseenuid and save it to config
if mailbox.exists == 0 { if mailbox.exists == 0 {
unsafe { info!(
dc_log_info( context,
context, 0,
0, "Folder \"%s\" is empty.",
b"Folder \"%s\" is empty.\x00" as *const u8 as *const libc::c_char, CString::new(folder.as_ref().to_owned()).unwrap().as_ptr()
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(), );
)
};
// set lastseenuid=0 for empty folders. // set lastseenuid=0 for empty folders.
// id we do not do this here, we'll miss the first message // id we do not do this here, we'll miss the first message
@@ -696,22 +654,19 @@ impl dc_imap_t {
Ok(list) => list, Ok(list) => list,
Err(err) => { Err(err) => {
eprintln!("fetch error: {:?}", err); eprintln!("fetch error: {:?}", err);
unsafe { info!(
dc_log_info( context,
context, 0,
0, "No result returned for folder \"%s\".",
b"No result returned for folder \"%s\".\x00" as *const u8 CString::new(folder.as_ref().to_owned()).unwrap().as_ptr()
as *const libc::c_char, );
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
)
};
return 0; return 0;
} }
} }
} else { } else {
return 0; return 0;
}; };
println!("fetched {} messages", list.len());
last_seen_uid = list[0].uid.unwrap_or_else(|| 0); last_seen_uid = list[0].uid.unwrap_or_else(|| 0);
@@ -722,17 +677,14 @@ impl dc_imap_t {
uid_validity = mailbox.uid_validity.unwrap(); uid_validity = mailbox.uid_validity.unwrap();
self.set_config_last_seen_uid(context, &folder, uid_validity, last_seen_uid); self.set_config_last_seen_uid(context, &folder, uid_validity, last_seen_uid);
unsafe { info!(
dc_log_info( context,
context, 0,
0, "lastseenuid initialized to %i for %s@%i",
b"lastseenuid initialized to %i for %s@%i\x00" as *const u8 last_seen_uid as libc::c_int,
as *const libc::c_char, CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
last_seen_uid as libc::c_int, uid_validity as libc::c_int
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(), );
uid_validity as libc::c_int,
);
}
} }
let mut read_cnt = 0; let mut read_cnt = 0;
@@ -754,7 +706,6 @@ impl dc_imap_t {
return 0; return 0;
}; };
println!("fetched {} messages", list.len());
// go through all mails in folder (this is typically _fast_ as we already have the whole list) // go through all mails in folder (this is typically _fast_ as we already have the whole list)
for msg in &list { for msg in &list {
@@ -775,31 +726,25 @@ impl dc_imap_t {
} { } {
// check passed, go fetch the rest // check passed, go fetch the rest
if self.fetch_single_msg(context, &folder, cur_uid) == 0 { if self.fetch_single_msg(context, &folder, cur_uid) == 0 {
unsafe { info!(
dc_log_info( context,
context, 0,
0, "Read error for message %s from \"%s\", trying over later.",
b"Read error for message %s from \"%s\", trying over later.\x00" message_id_c.as_ptr(),
as *const u8 folder_c.as_ptr()
as *const libc::c_char, );
message_id_c.as_ptr(),
folder_c.as_ptr(),
)
};
read_errors += 1; read_errors += 1;
} }
} else { } else {
// check failed // check failed
unsafe { info!(
dc_log_info( context,
context, 0,
0, "Skipping message %s from \"%s\" by precheck.",
b"Skipping message %s from \"%s\" by precheck.\x00" as *const u8 message_id_c.as_ptr(),
as *const libc::c_char, folder_c.as_ptr()
message_id_c.as_ptr(), );
folder_c.as_ptr(),
)
};
} }
if cur_uid > new_last_seen_uid { if cur_uid > new_last_seen_uid {
new_last_seen_uid = cur_uid new_last_seen_uid = cur_uid
@@ -814,27 +759,22 @@ impl dc_imap_t {
} }
if read_errors > 0 { if read_errors > 0 {
unsafe { warn!(
dc_log_warning( context,
context, 0,
0i32, "%i mails read from \"%s\" with %i errors.",
b"%i mails read from \"%s\" with %i errors.\x00" as *const u8 read_cnt as libc::c_int,
as *const libc::c_char, CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
read_cnt as libc::c_int, read_errors as libc::c_int,
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(), );
read_errors as libc::c_int,
)
};
} else { } else {
unsafe { info!(
dc_log_info( context,
context, 0,
0i32, "%i mails read from \"%s\".",
b"%i mails read from \"%s\".\x00" as *const u8 as *const libc::c_char, read_cnt as libc::c_int,
read_cnt as libc::c_int, CString::new(folder.as_ref().to_owned()).unwrap().as_ptr()
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(), );
)
};
} }
read_cnt read_cnt
@@ -880,17 +820,14 @@ impl dc_imap_t {
Ok(msgs) => msgs, Ok(msgs) => msgs,
Err(err) => { Err(err) => {
eprintln!("error fetch single: {:?}", err); eprintln!("error fetch single: {:?}", err);
unsafe { warn!(
dc_log_warning( context,
context, 0,
0, "Error on fetching message #%i from folder \"%s\"; retry=%i.",
b"Error on fetching message #%i from folder \"%s\"; retry=%i.\x00" server_uid as libc::c_int,
as *const u8 as *const libc::c_char, CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
server_uid as libc::c_int, self.should_reconnect() as libc::c_int,
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(), );
self.should_reconnect() as libc::c_int,
)
};
if self.should_reconnect() { if self.should_reconnect() {
retry_later = true; retry_later = true;
@@ -904,16 +841,13 @@ impl dc_imap_t {
}; };
if msgs.is_empty() { if msgs.is_empty() {
unsafe { warn!(
dc_log_warning( context,
context, 0,
0, "Message #%i does not exist in folder \"%s\".",
b"Message #%i does not exist in folder \"%s\".\x00" as *const u8 server_uid as libc::c_int,
as *const libc::c_char, CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
server_uid as libc::c_int, );
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
)
};
} else { } else {
let msg = &msgs[0]; let msg = &msgs[0];
@@ -959,29 +893,18 @@ impl dc_imap_t {
} }
pub fn idle(&self, context: &dc_context_t) { pub fn idle(&self, context: &dc_context_t) {
println!(
"trying idle: can_idle: {}",
self.config.read().unwrap().can_idle
);
if !self.config.read().unwrap().can_idle { if !self.config.read().unwrap().can_idle {
return self.fake_idle(context); return self.fake_idle(context);
} }
// TODO: reconnect in all methods that need it // TODO: reconnect in all methods that need it
if !self.is_connected() { if !self.is_connected() {
println!("can't idle, disconnected");
return; return;
} }
let watch_folder = self.config.read().unwrap().watch_folder.clone(); let watch_folder = self.config.read().unwrap().watch_folder.clone();
if self.select_folder(context, watch_folder.as_ref()) == 0 { if self.select_folder(context, watch_folder.as_ref()) == 0 {
unsafe { warn!(context, 0, "IMAP-IDLE not setup.",);
dc_log_warning(
context,
0,
b"IMAP-IDLE not setup.\x00" as *const u8 as *const libc::c_char,
)
};
return self.fake_idle(context); return self.fake_idle(context);
} }
@@ -1009,19 +932,12 @@ impl dc_imap_t {
// } // }
// } // }
println!("setting up idle");
let mut session = self.session.lock().unwrap().take().unwrap(); let mut session = self.session.lock().unwrap().take().unwrap();
let mut idle = match session.idle() { let mut idle = match session.idle() {
Ok(idle) => idle, Ok(idle) => idle,
Err(err) => { Err(err) => {
eprintln!("imap idle error: {:?}", err); eprintln!("imap idle error: {:?}", err);
unsafe { warn!(context, 0, "IMAP-IDLE: Cannot start.",);
dc_log_warning(
context,
0,
b"IMAP-IDLE: Cannot start.\x00" as *const u8 as *const libc::c_char,
);
}
return self.fake_idle(context); return self.fake_idle(context);
} }
@@ -1032,13 +948,10 @@ impl dc_imap_t {
// if needed, the ui can call dc_imap_interrupt_idle() to trigger a reconnect. // if needed, the ui can call dc_imap_interrupt_idle() to trigger a reconnect.
idle.set_keepalive(Duration::from_secs(23 * 60)); idle.set_keepalive(Duration::from_secs(23 * 60));
println!("imap idle waiting");
// TODO: proper logging of different states // TODO: proper logging of different states
// TODO: reconnect if we timed out // TODO: reconnect if we timed out
match idle.wait_keepalive() { match idle.wait_keepalive() {
Ok(_) => { Ok(_) => {}
println!("imap done");
}
Err(err) => { Err(err) => {
eprintln!("idle error: {:?}", err); eprintln!("idle error: {:?}", err);
} }
@@ -1049,19 +962,12 @@ impl dc_imap_t {
} }
fn fake_idle(&self, context: &dc_context_t) { fn fake_idle(&self, context: &dc_context_t) {
println!("fake idle");
// Idle using timeouts. This is also needed if we're not yet configured - // Idle using timeouts. This is also needed if we're not yet configured -
// in this case, we're waiting for a configure job // in this case, we're waiting for a configure job
let mut fake_idle_start_time = SystemTime::now(); let mut fake_idle_start_time = SystemTime::now();
unsafe { info!(context, 0, "IMAP-fake-IDLEing...");
dc_log_info(
context,
0,
b"IMAP-fake-IDLEing...\x00" as *const u8 as *const libc::c_char,
)
};
let mut do_fake_idle = true; let mut do_fake_idle = true;
while do_fake_idle { while do_fake_idle {
let seconds_to_wait = let seconds_to_wait =
@@ -1102,17 +1008,13 @@ impl dc_imap_t {
} }
pub fn interrupt_idle(&self) { pub fn interrupt_idle(&self) {
println!("interrupt idle");
// TODO: interrupt real idle // TODO: interrupt real idle
// ref: https://github.com/jonhoo/rust-imap/issues/121 // ref: https://github.com/jonhoo/rust-imap/issues/121
println!("waiting for lock");
let &(ref lock, ref cvar) = &*self.watch.clone(); let &(ref lock, ref cvar) = &*self.watch.clone();
let mut watch = lock.lock().unwrap(); let mut watch = lock.lock().unwrap();
*watch = true; *watch = true;
println!("notify");
cvar.notify_one(); cvar.notify_one();
} }
@@ -1130,43 +1032,37 @@ impl dc_imap_t {
if uid == 0 { if uid == 0 {
res = DC_FAILED; res = DC_FAILED;
} else if folder.as_ref() == dest_folder.as_ref() { } else if folder.as_ref() == dest_folder.as_ref() {
unsafe { info!(
dc_log_info( context,
context, 0,
0, "Skip moving message; message %s/%i is already in %s...",
b"Skip moving message; message %s/%i is already in %s...\x00" as *const u8 CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
as *const libc::c_char, uid as libc::c_int,
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(), CString::new(dest_folder.as_ref().to_owned())
uid as libc::c_int, .unwrap()
CString::new(dest_folder.as_ref().to_owned()) .as_ptr()
.unwrap() );
.as_ptr(),
)
};
res = DC_ALREADY_DONE; res = DC_ALREADY_DONE;
} else { } else {
unsafe { info!(
dc_log_info( context,
0,
"Moving message %s/%i to %s...",
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
uid as libc::c_int,
CString::new(dest_folder.as_ref().to_owned())
.unwrap()
.as_ptr()
);
if self.select_folder(context, Some(folder.as_ref())) == 0 {
warn!(
context, context,
0, 0,
b"Moving message %s/%i to %s...\x00" as *const u8 as *const libc::c_char, "Cannot select folder %s for moving message.",
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(), CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
uid as libc::c_int, );
CString::new(dest_folder.as_ref().to_owned())
.unwrap()
.as_ptr(),
)
};
if self.select_folder(context, Some(folder.as_ref())) == 0 {
unsafe {
dc_log_warning(
context,
0,
b"Cannot select folder %s for moving message.\x00" as *const u8
as *const libc::c_char,
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
)
};
} else { } else {
let moved = if let Some(ref mut session) = *self.session.lock().unwrap() { let moved = if let Some(ref mut session) = *self.session.lock().unwrap() {
match session.uid_mv(&set, &dest_folder) { match session.uid_mv(&set, &dest_folder) {
@@ -1176,17 +1072,17 @@ impl dc_imap_t {
} }
Err(err) => { Err(err) => {
eprintln!("move error: {:?}", err); eprintln!("move error: {:?}", err);
unsafe { info!(
dc_log_info( context,
context, 0,
0, "Cannot move message, fallback to COPY/DELETE %s/%i to %s...",
b"Cannot move message, fallback to COPY/DELETE %s/%i to %s...\x00" CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
as *const u8 as *const libc::c_char, uid as libc::c_int,
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(), CString::new(dest_folder.as_ref().to_owned())
uid as libc::c_int, .unwrap()
CString::new(dest_folder.as_ref().to_owned()).unwrap().as_ptr(), .as_ptr()
) );
};
false false
} }
} }
@@ -1200,14 +1096,8 @@ impl dc_imap_t {
Ok(_) => true, Ok(_) => true,
Err(err) => { Err(err) => {
eprintln!("error copy: {:?}", err); eprintln!("error copy: {:?}", err);
unsafe { info!(context, 0, "Cannot copy message.",);
dc_log_info(
context,
0,
b"Cannot copy message.\x00" as *const u8
as *const libc::c_char,
)
};
false false
} }
} }
@@ -1217,14 +1107,7 @@ impl dc_imap_t {
if copied { if copied {
if self.add_flag(uid, "\\Deleted") == 0 { if self.add_flag(uid, "\\Deleted") == 0 {
unsafe { warn!(context, 0, "Cannot mark message as \"Deleted\".",);
dc_log_warning(
context,
0,
b"Cannot mark message as \"Deleted\".\x00" as *const u8
as *const libc::c_char,
)
};
} }
self.config.write().unwrap().selected_folder_needs_expunge = true; self.config.write().unwrap().selected_folder_needs_expunge = true;
res = DC_SUCCESS; res = DC_SUCCESS;
@@ -1276,33 +1159,23 @@ impl dc_imap_t {
} else if self.is_connected() { } else if self.is_connected() {
let folder_c = CString::new(folder.as_ref().to_owned()).unwrap(); let folder_c = CString::new(folder.as_ref().to_owned()).unwrap();
unsafe { info!(
dc_log_info( context,
0,
"Marking message %s/%i as seen...",
folder_c.as_ptr(),
uid as libc::c_int
);
if self.select_folder(context, Some(folder)) == 0 {
warn!(
context, context,
0, 0,
b"Marking message %s/%i as seen...\x00" as *const u8 as *const libc::c_char, "Cannot select folder %s for setting SEEN flag.",
folder_c.as_ptr(), folder_c.as_ptr(),
uid as libc::c_int, );
)
};
if self.select_folder(context, Some(folder)) == 0 {
unsafe {
dc_log_warning(
context,
0,
b"Cannot select folder %s for setting SEEN flag.\x00" as *const u8
as *const libc::c_char,
folder_c.as_ptr(),
)
};
} else if self.add_flag(uid, "\\Seen") == 0 { } else if self.add_flag(uid, "\\Seen") == 0 {
unsafe { warn!(context, 0, "Cannot mark message as seen.",);
dc_log_warning(
context,
0,
b"Cannot mark message as seen.\x00" as *const u8 as *const libc::c_char,
)
};
} else { } else {
res = DC_SUCCESS res = DC_SUCCESS
} }
@@ -1328,26 +1201,21 @@ impl dc_imap_t {
res = DC_FAILED; res = DC_FAILED;
} else if self.is_connected() { } else if self.is_connected() {
let folder_c = CString::new(folder.as_ref().to_owned()).unwrap(); let folder_c = CString::new(folder.as_ref().to_owned()).unwrap();
unsafe { info!(
dc_log_info( context,
context, 0,
0, "Marking message %s/%i as $MDNSent...",
b"Marking message %s/%i as $MDNSent...\x00" as *const u8 as *const libc::c_char, folder_c.as_ptr(),
folder_c.as_ptr(), uid as libc::c_int
uid as libc::c_int, );
)
};
if self.select_folder(context, Some(folder)) == 0 { if self.select_folder(context, Some(folder)) == 0 {
unsafe { warn!(
dc_log_warning( context,
context, 0,
0, "Cannot select folder %s for setting $MDNSent flag.",
b"Cannot select folder %s for setting $MDNSent flag.\x00" as *const u8 folder_c.as_ptr(),
as *const libc::c_char, );
folder_c.as_ptr(),
)
};
} else { } else {
// Check if the folder can handle the `$MDNSent` flag (see RFC 3503). If so, and not // Check if the folder can handle the `$MDNSent` flag (see RFC 3503). If so, and not
// set: set the flags and return this information. // set: set the flags and return this information.
@@ -1410,30 +1278,20 @@ impl dc_imap_t {
res res
}; };
unsafe { let msg = if res == DC_SUCCESS {
dc_log_info( "$MDNSent just set and MDN will be sent."
context, } else {
0, "$MDNSent already set and MDN already sent."
if res == DC_SUCCESS {
b"$MDNSent just set and MDN will be sent.\x00" as *const u8
as *const libc::c_char
} else {
b"$MDNSent already set and MDN already sent.\x00" as *const u8
as *const libc::c_char
},
)
}; };
info!(context, 0, msg);
} }
} else { } else {
res = DC_SUCCESS; res = DC_SUCCESS;
unsafe { info!(
dc_log_info( context,
context, 0, "Cannot store $MDNSent flags, risk sending duplicate MDN.",
0, );
b"Cannot store $MDNSent flags, risk sending duplicate MDN.\x00"
as *const u8 as *const libc::c_char,
)
};
} }
} }
} }
@@ -1461,28 +1319,22 @@ impl dc_imap_t {
if *server_uid == 0 { if *server_uid == 0 {
success = true success = true
} else { } else {
unsafe { info!(
dc_log_info( context,
context, 0,
0, "Marking message \"%s\", %s/%i for deletion...",
b"Marking message \"%s\", %s/%i for deletion...\x00" as *const u8 &message_id,
as *const libc::c_char, CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
&message_id, *server_uid as libc::c_int
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(), );
*server_uid as libc::c_int,
)
};
if self.select_folder(context, Some(&folder)) == 0 { if self.select_folder(context, Some(&folder)) == 0 {
unsafe { warn!(
dc_log_warning( context,
context, 0,
0, "Cannot select folder %s for deleting message.",
b"Cannot select folder %s for deleting message.\x00" as *const u8 CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
as *const libc::c_char, );
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
)
};
} else { } else {
let set = format!("{}", server_uid); let set = format!("{}", server_uid);
if let Some(ref mut session) = *self.session.lock().unwrap() { if let Some(ref mut session) = *self.session.lock().unwrap() {
@@ -1498,34 +1350,27 @@ impl dc_imap_t {
.expect("missing message id") .expect("missing message id")
!= message_id.as_ref() != message_id.as_ref()
{ {
unsafe { warn!(
dc_log_warning( context,
context, 0,
0, "Cannot delete on IMAP, %s/%i does not match %s.",
b"Cannot delete on IMAP, %s/%i does not match %s.\x00" CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
as *const u8 *server_uid as libc::c_int,
as *const libc::c_char, message_id,
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(), );
*server_uid as libc::c_int,
message_id,
)
};
*server_uid = 0; *server_uid = 0;
} }
} }
Err(err) => { Err(err) => {
eprintln!("fetch error: {:?}", err); eprintln!("fetch error: {:?}", err);
unsafe { warn!(
dc_log_warning( context,
context, 0,
0, "Cannot delete on IMAP, %s/%i not found.",
b"Cannot delete on IMAP, %s/%i not found.\x00" as *const u8 CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(),
as *const libc::c_char, *server_uid as libc::c_int,
CString::new(folder.as_ref().to_owned()).unwrap().as_ptr(), );
*server_uid as libc::c_int,
)
};
*server_uid = 0; *server_uid = 0;
} }
} }
@@ -1533,14 +1378,7 @@ impl dc_imap_t {
// mark the message for deletion // mark the message for deletion
if self.add_flag(*server_uid, "\\Deleted") == 0 { if self.add_flag(*server_uid, "\\Deleted") == 0 {
unsafe { warn!(context, 0, "Cannot mark message as \"Deleted\".");
dc_log_warning(
context,
0,
b"Cannot mark message as \"Deleted\".\x00" as *const u8
as *const libc::c_char,
)
};
} else { } else {
self.config.write().unwrap().selected_folder_needs_expunge = true; self.config.write().unwrap().selected_folder_needs_expunge = true;
success = true success = true
@@ -1560,13 +1398,7 @@ impl dc_imap_t {
return; return;
} }
unsafe { info!(context, 0, "Configuring IMAP-folders.");
dc_log_info(
context,
0,
b"Configuring IMAP-folders.\x00" as *const u8 as *const libc::c_char,
)
};
let folders = self.list_folders(context).unwrap(); let folders = self.list_folders(context).unwrap();
let delimiter = self.config.read().unwrap().imap_delimiter; let delimiter = self.config.read().unwrap().imap_delimiter;
@@ -1584,65 +1416,36 @@ impl dc_imap_t {
_ => false, _ => false,
}); });
println!("folders: {:?} - {:?}", mvbox_folder, sentbox_folder);
if mvbox_folder.is_none() && 0 != (flags as usize & DC_CREATE_MVBOX) { if mvbox_folder.is_none() && 0 != (flags as usize & DC_CREATE_MVBOX) {
unsafe { info!(
dc_log_info( context,
context, 0,
0i32, "Creating MVBOX-folder \"%s\"...",
b"Creating MVBOX-folder \"%s\"...\x00" as *const u8 as *const libc::c_char, b"DeltaChat\x00" as *const u8 as *const libc::c_char
b"DeltaChat\x00" as *const u8 as *const libc::c_char, );
)
};
if let Some(ref mut session) = *self.session.lock().unwrap() { if let Some(ref mut session) = *self.session.lock().unwrap() {
match session.create("DeltaChat") { match session.create("DeltaChat") {
Ok(_) => { Ok(_) => {
mvbox_folder = Some("DeltaChat".into()); mvbox_folder = Some("DeltaChat".into());
unsafe { info!(context, 0, "MVBOX-folder created.",);
dc_log_info(
context,
0i32,
b"MVBOX-folder created.\x00" as *const u8 as *const libc::c_char,
)
};
} }
Err(err) => { Err(err) => {
eprintln!("create error: {:?}", err); eprintln!("create error: {:?}", err);
unsafe { warn!(
dc_log_warning( context,
context, 0, "Cannot create MVBOX-folder, using trying INBOX subfolder."
0, );
b"Cannot create MVBOX-folder, using trying INBOX subfolder.\x00"
as *const u8
as *const libc::c_char,
)
};
match session.create(&fallback_folder) { match session.create(&fallback_folder) {
Ok(_) => { Ok(_) => {
mvbox_folder = Some(fallback_folder); mvbox_folder = Some(fallback_folder);
unsafe { info!(context, 0, "MVBOX-folder created as INBOX subfolder.",);
dc_log_info(
context,
0,
b"MVBOX-folder created as INBOX subfolder.\x00" as *const u8
as *const libc::c_char,
)
};
} }
Err(err) => { Err(err) => {
eprintln!("create error: {:?}", err); eprintln!("create error: {:?}", err);
unsafe { warn!(context, 0, "Cannot create MVBOX-folder.",);
dc_log_warning(
context,
0i32,
b"Cannot create MVBOX-folder.\x00" as *const u8
as *const libc::c_char,
)
};
} }
} }
} }
@@ -1692,25 +1495,14 @@ impl dc_imap_t {
match session.list(Some(""), Some("*")) { match session.list(Some(""), Some("*")) {
Ok(list) => { Ok(list) => {
if list.is_empty() { if list.is_empty() {
unsafe { warn!(context, 0, "Folder list is empty.",);
dc_log_warning(
context,
0i32,
b"Folder list is empty.\x00" as *const u8 as *const libc::c_char,
)
};
} }
Some(list) Some(list)
} }
Err(err) => { Err(err) => {
eprintln!("list error: {:?}", err); eprintln!("list error: {:?}", err);
unsafe { warn!(context, 0, "Cannot get folder list.",);
dc_log_warning(
context,
0i32,
b"Cannot get folder list.\x00" as *const u8 as *const libc::c_char,
)
};
None None
} }
} }

View File

@@ -88,3 +88,54 @@ pub unsafe extern "C" fn dc_log_info(
) { ) {
log_vprintf(context, Event::INFO, data1, msg, va_3); log_vprintf(context, Event::INFO, data1, msg, va_3);
} }
#[macro_export]
macro_rules! info {
($ctx:expr, $data1:expr, $msg:expr) => {
info!($ctx, $data1, $msg,)
};
($ctx:expr, $data1:expr, $msg:expr, $($args:expr),* $(,)?) => {
unsafe {
dc_log_info(
$ctx,
$data1,
std::ffi::CString::new($msg).unwrap().as_ptr(),
$($args),*
)
}
};
}
#[macro_export]
macro_rules! warn {
($ctx:expr, $data1:expr, $msg:expr) => {
warn!($ctx, $data1, $msg,)
};
($ctx:expr, $data1:expr, $msg:expr, $($args:expr),* $(,)?) => {
unsafe {
dc_log_warning(
$ctx,
$data1,
std::ffi::CString::new($msg).unwrap().as_ptr(),
$($args),*
)
}
};
}
#[macro_export]
macro_rules! error {
($ctx:expr, $data1:expr, $msg:expr) => {
error!($ctx, $data1, $msg,)
};
($ctx:expr, $data1:expr, $msg:expr, $($args:expr),* $(,)?) => {
unsafe {
dc_log_error(
$ctx,
$data1,
std::ffi::CString::new($msg).unwrap().as_ptr(),
$($args),*
)
}
};
}

View File

@@ -23,6 +23,9 @@ extern crate num_derive;
// #[macro_use] // #[macro_use]
// extern crate rental; // extern crate rental;
#[macro_use]
pub mod dc_log;
mod pgp; mod pgp;
pub mod dc_aheader; pub mod dc_aheader;
@@ -45,7 +48,6 @@ pub mod dc_key;
pub mod dc_keyhistory; pub mod dc_keyhistory;
pub mod dc_keyring; pub mod dc_keyring;
pub mod dc_location; pub mod dc_location;
pub mod dc_log;
pub mod dc_loginparam; pub mod dc_loginparam;
pub mod dc_lot; pub mod dc_lot;
pub mod dc_mimefactory; pub mod dc_mimefactory;