diff --git a/examples/simple.rs b/examples/simple.rs index b715dbb3e..d4c88d31e 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -35,93 +35,90 @@ fn cb(_ctx: &Context, event: Event) -> usize { } fn main() { - unsafe { - let dir = tempdir().unwrap(); - let dbfile = dir.path().join("db.sqlite"); - println!("creating database {:?}", dbfile); - let ctx = - Context::new(Box::new(cb), "FakeOs".into(), dbfile).expect("Failed to create context"); - let running = Arc::new(RwLock::new(true)); - let info = ctx.get_info(); - let duration = time::Duration::from_millis(4000); - println!("info: {:#?}", info); + let dir = tempdir().unwrap(); + let dbfile = dir.path().join("db.sqlite"); + println!("creating database {:?}", dbfile); + let ctx = + Context::new(Box::new(cb), "FakeOs".into(), dbfile).expect("Failed to create context"); + let running = Arc::new(RwLock::new(true)); + let info = ctx.get_info(); + let duration = time::Duration::from_millis(4000); + println!("info: {:#?}", info); + + let ctx = Arc::new(ctx); + let ctx1 = ctx.clone(); + let r1 = running.clone(); + let t1 = thread::spawn(move || { + while *r1.read().unwrap() { + perform_imap_jobs(&ctx1); + if *r1.read().unwrap() { + perform_imap_fetch(&ctx1); - let ctx = Arc::new(ctx); - let ctx1 = ctx.clone(); - let r1 = running.clone(); - let t1 = thread::spawn(move || { - while *r1.read().unwrap() { - perform_imap_jobs(&ctx1); if *r1.read().unwrap() { - perform_imap_fetch(&ctx1); - - if *r1.read().unwrap() { - perform_imap_idle(&ctx1); - } + perform_imap_idle(&ctx1); } } - }); - - let ctx1 = ctx.clone(); - let r1 = running.clone(); - let t2 = thread::spawn(move || { - while *r1.read().unwrap() { - perform_smtp_jobs(&ctx1); - if *r1.read().unwrap() { - perform_smtp_idle(&ctx1); - } - } - }); - - println!("configuring"); - let args = std::env::args().collect::>(); - assert_eq!(args.len(), 2, "missing password"); - let pw = args[1].clone(); - ctx.set_config(config::Config::Addr, Some("d@testrun.org")) - .unwrap(); - ctx.set_config(config::Config::MailPw, Some(&pw)).unwrap(); - configure(&ctx); - - thread::sleep(duration); - - println!("sending a message"); - let contact_id = - Contact::create(&ctx, "dignifiedquire", "dignifiedquire@gmail.com").unwrap(); - let chat_id = chat::create_by_contact_id(&ctx, contact_id).unwrap(); - chat::send_text_msg(&ctx, chat_id, "Hi, here is my first message!".into()).unwrap(); - - println!("fetching chats.."); - let chats = Chatlist::try_load(&ctx, 0, None, None).unwrap(); - - for i in 0..chats.len() { - let summary = chats.get_summary(&ctx, 0, None); - let text1 = summary.get_text1(); - let text2 = summary.get_text2(); - println!("chat: {} - {:?} - {:?}", i, text1, text2,); } + }); - thread::sleep(duration); + let ctx1 = ctx.clone(); + let r1 = running.clone(); + let t2 = thread::spawn(move || { + while *r1.read().unwrap() { + perform_smtp_jobs(&ctx1); + if *r1.read().unwrap() { + perform_smtp_idle(&ctx1); + } + } + }); - // let msglist = dc_get_chat_msgs(&ctx, chat_id, 0, 0); - // for i in 0..dc_array_get_cnt(msglist) { - // let msg_id = dc_array_get_id(msglist, i); - // let msg = dc_get_msg(context, msg_id); - // let text = CStr::from_ptr(dc_msg_get_text(msg)).unwrap(); - // println!("Message {}: {}\n", i + 1, text.to_str().unwrap()); - // dc_msg_unref(msg); - // } - // dc_array_unref(msglist); + println!("configuring"); + let args = std::env::args().collect::>(); + assert_eq!(args.len(), 2, "missing password"); + let pw = args[1].clone(); + ctx.set_config(config::Config::Addr, Some("d@testrun.org")) + .unwrap(); + ctx.set_config(config::Config::MailPw, Some(&pw)).unwrap(); + configure(&ctx); - println!("stopping threads"); + thread::sleep(duration); - *running.clone().write().unwrap() = false; - deltachat::job::interrupt_imap_idle(&ctx); - deltachat::job::interrupt_smtp_idle(&ctx); + println!("sending a message"); + let contact_id = Contact::create(&ctx, "dignifiedquire", "dignifiedquire@gmail.com").unwrap(); + let chat_id = chat::create_by_contact_id(&ctx, contact_id).unwrap(); + chat::send_text_msg(&ctx, chat_id, "Hi, here is my first message!".into()).unwrap(); - println!("joining"); - t1.join().unwrap(); - t2.join().unwrap(); + println!("fetching chats.."); + let chats = Chatlist::try_load(&ctx, 0, None, None).unwrap(); - println!("closing"); + for i in 0..chats.len() { + let summary = chats.get_summary(&ctx, 0, None); + let text1 = summary.get_text1(); + let text2 = summary.get_text2(); + println!("chat: {} - {:?} - {:?}", i, text1, text2,); } + + thread::sleep(duration); + + // let msglist = dc_get_chat_msgs(&ctx, chat_id, 0, 0); + // for i in 0..dc_array_get_cnt(msglist) { + // let msg_id = dc_array_get_id(msglist, i); + // let msg = dc_get_msg(context, msg_id); + // let text = CStr::from_ptr(dc_msg_get_text(msg)).unwrap(); + // println!("Message {}: {}\n", i + 1, text.to_str().unwrap()); + // dc_msg_unref(msg); + // } + // dc_array_unref(msglist); + + println!("stopping threads"); + + *running.clone().write().unwrap() = false; + deltachat::job::interrupt_imap_idle(&ctx); + deltachat::job::interrupt_smtp_idle(&ctx); + + println!("joining"); + t1.join().unwrap(); + t2.join().unwrap(); + + println!("closing"); } diff --git a/src/configure/mod.rs b/src/configure/mod.rs index 4015c239b..6701b8391 100644 --- a/src/configure/mod.rs +++ b/src/configure/mod.rs @@ -27,7 +27,7 @@ macro_rules! progress { } // connect -pub unsafe fn configure(context: &Context) { +pub fn configure(context: &Context) { if context.has_ongoing() { warn!(context, "There is already another ongoing process running.",); return; diff --git a/src/e2ee.rs b/src/e2ee.rs index c4e3515c6..b256939d6 100644 --- a/src/e2ee.rs +++ b/src/e2ee.rs @@ -263,7 +263,7 @@ pub fn try_decrypt( in_out_message: *mut Mailmime, ) -> Result<(bool, HashSet, HashSet)> { // just a pointer into mailmime structure, must not be freed - let imffields = unsafe { mailmime_find_mailimf_fields(in_out_message) }; + let imffields = mailmime_find_mailimf_fields(in_out_message); ensure!( !in_out_message.is_null() && !imffields.is_null(), "corrupt invalid mime inputs" diff --git a/src/wrapmime.rs b/src/wrapmime.rs index 6ae63ab70..ea312887c 100644 --- a/src/wrapmime.rs +++ b/src/wrapmime.rs @@ -175,21 +175,21 @@ pub fn mailimf_find_field( } /*the result is a pointer to mime, must not be freed*/ -pub unsafe fn mailmime_find_mailimf_fields(mime: *mut Mailmime) -> *mut mailimf_fields { +pub fn mailmime_find_mailimf_fields(mime: *mut Mailmime) -> *mut mailimf_fields { if mime.is_null() { return ptr::null_mut(); } - match (*mime).mm_type as _ { + match unsafe { (*mime).mm_type as _ } { MAILMIME_MULTIPLE => { - for cur_data in (*(*mime).mm_data.mm_multipart.mm_mp_list).into_iter() { + for cur_data in unsafe { (*(*mime).mm_data.mm_multipart.mm_mp_list).into_iter() } { let header = mailmime_find_mailimf_fields(cur_data as *mut _); if !header.is_null() { return header; } } } - MAILMIME_MESSAGE => return (*mime).mm_data.mm_message.mm_fields, + MAILMIME_MESSAGE => return unsafe { (*mime).mm_data.mm_message.mm_fields }, _ => {} }