diff --git a/Cargo.lock b/Cargo.lock index af7d471ad..f8611f84e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -470,6 +470,15 @@ dependencies = [ "syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "debug_stub_derive" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "deltachat" version = "1.0.0-alpha.4" @@ -481,6 +490,7 @@ dependencies = [ "cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "charset 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", + "debug_stub_derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "deltachat_derive 0.1.0", "escaper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1723,6 +1733,11 @@ dependencies = [ "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "quote" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "quote" version = "0.6.13" @@ -2338,6 +2353,16 @@ name = "subtle" version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "syn" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "syn" version = "0.14.9" @@ -2368,6 +2393,14 @@ dependencies = [ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "synom" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "synstructure" version = "0.10.2" @@ -2641,6 +2674,11 @@ name = "unicode-width" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "unicode-xid" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "unicode-xid" version = "0.1.0" @@ -2912,6 +2950,7 @@ dependencies = [ "checksum darling 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fcfbcb0c5961907597a7d1148e3af036268f2b773886b8bb3eeb1e1281d3d3d6" "checksum darling_core 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6afc018370c3bff3eb51f89256a6bdb18b4fdcda72d577982a14954a7a0b402c" "checksum darling_macro 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c6d8dac1c6f1d29a41c4712b4400f878cb4fcc4c7628f298dd75038e024998d1" +"checksum debug_stub_derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "496b7f8a2f853313c3ca370641d7ff3e42c32974fdccda8f0684599ed0a3ff6b" "checksum derive_builder 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3ac53fa6a3cda160df823a9346442525dcaf1e171999a1cf23e67067e4fd64d4" "checksum derive_builder_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0288a23da9333c246bb18c143426074a6ae96747995c5819d2947b64cd942b37" "checksum derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6d944ac6003ed268757ef1ee686753b57efc5fcf0ebe7b64c9fc81e7e32ff839" @@ -3039,6 +3078,7 @@ dependencies = [ "checksum pulldown-cmark 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eef52fac62d0ea7b9b4dc7da092aa64ea7ec3d90af6679422d3d7e0e14b6ee15" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quick-xml 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c2b074258da4f2ccb1c450380c5bd8e77db2508de2161f574c70930d8e880482" +"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" "checksum quote 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "49d77c41ca8767f2f41394c11a4eebccab83da25e7cc035387a3125f02be90a3" "checksum r2d2 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bc42ce75d9f4447fb2a04bbe1ed5d18dd949104572850ec19b164e274919f81b" @@ -3106,9 +3146,11 @@ dependencies = [ "checksum strum 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e5d1c33039533f051704951680f1adfd468fd37ac46816ded0d9ee068e60f05f" "checksum strum_macros 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "47cd23f5c7dee395a00fa20135e2ec0fffcdfa151c56182966d7a3261343432e" "checksum subtle 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "01f40907d9ffc762709e4ff3eb4a6f6b41b650375a3f09ac92b641942b7fb082" +"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" "checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741" "checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" "checksum syn 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2ae5cd13590144ea968ba5d5520da7a4c08415861014399b5b349f74591c375f" +"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" @@ -3138,6 +3180,7 @@ dependencies = [ "checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" "checksum unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1967f4cdfc355b37fd76d2a954fb2ed3871034eb4f26d60537d88795cfc332a9" "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" +"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" diff --git a/Cargo.toml b/Cargo.toml index b992f8874..4cf4e9fc2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,6 +51,7 @@ quick-xml = "0.15.0" escaper = "0.1.0" bitflags = "1.1.0" jetscii = "0.4.4" +debug_stub_derive = "0.3.0" [dev-dependencies] tempfile = "3.0" diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index f2c889d7d..0a6ccedc6 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -20,7 +20,6 @@ use deltachat::message::*; use deltachat::peerstate::*; use deltachat::qr::*; use deltachat::sql; -use deltachat::types::*; use deltachat::x::*; use num_traits::FromPrimitive; @@ -96,7 +95,7 @@ unsafe fn dc_poke_eml_file(context: &Context, filename: *const libc::c_char) -> /* mainly for testing, may be called by dc_import_spec() */ let mut success: libc::c_int = 0i32; let mut data: *mut libc::c_char = ptr::null_mut(); - let mut data_bytes: size_t = 0; + let mut data_bytes = 0; if !(dc_read_file( context, filename, @@ -199,7 +198,11 @@ unsafe fn poke_spec(context: &Context, spec: *const libc::c_char) -> libc::c_int as_str(real_spec) ); if read_cnt > 0 { - context.call_cb(Event::MSGS_CHANGED, 0 as uintptr_t, 0 as uintptr_t); + context.call_cb( + Event::MSGS_CHANGED, + 0 as libc::uintptr_t, + 0 as libc::uintptr_t, + ); } success = 1 } @@ -615,7 +618,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E ); } } - if location::is_sending_locations_to_chat(context, 0 as uint32_t) { + if location::is_sending_locations_to_chat(context, 0) { info!(context, "Location streaming enabled."); } println!("{} chats", cnt); @@ -664,7 +667,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E "createchat" => { ensure!(!arg1.is_empty(), "Argument missing."); let contact_id: libc::c_int = arg1.parse()?; - let chat_id = chat::create_by_contact_id(context, contact_id as uint32_t)?; + let chat_id = chat::create_by_contact_id(context, contact_id as u32)?; println!("Single#{} created successfully.", chat_id,); } @@ -696,7 +699,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E if chat::add_contact_to_chat( context, sel_chat.as_ref().unwrap().get_id(), - contact_id_0 as uint32_t, + contact_id_0 as u32, ) { println!("Contact added to chat."); } else { @@ -710,7 +713,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E chat::remove_contact_from_chat( context, sel_chat.as_ref().unwrap().get_id(), - contact_id_1 as uint32_t, + contact_id_1 as u32, )?; println!("Contact added to chat."); @@ -1017,7 +1020,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E ensure!(!arg1.is_empty(), "Argument missing."); let event = arg1.parse()?; let event = Event::from_u32(event).ok_or(format_err!("Event::from_u32({})", event))?; - let r = context.call_cb(event, 0 as uintptr_t, 0 as uintptr_t); + let r = context.call_cb(event, 0 as libc::uintptr_t, 0 as libc::uintptr_t); println!( "Sending event {:?}({}), received value {}.", event, event as usize, r as libc::c_int, diff --git a/examples/repl/main.rs b/examples/repl/main.rs index e95655383..fb8505eea 100644 --- a/examples/repl/main.rs +++ b/examples/repl/main.rs @@ -28,7 +28,6 @@ use deltachat::dc_tools::*; use deltachat::job::*; use deltachat::oauth2::*; use deltachat::securejoin::*; -use deltachat::types::*; use deltachat::x::*; use rustyline::completion::{Completer, FilenameCompleter, Pair}; use rustyline::config::OutputStreamType; @@ -47,9 +46,9 @@ use self::cmdline::*; fn receive_event( _context: &Context, event: Event, - data1: uintptr_t, - data2: uintptr_t, -) -> uintptr_t { + data1: libc::uintptr_t, + data2: libc::uintptr_t, +) -> libc::uintptr_t { match event { Event::GET_STRING => {} Event::INFO => { diff --git a/src/chat.rs b/src/chat.rs index 36d11f00c..864dcf220 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1,5 +1,8 @@ use std::ffi::CString; use std::path::{Path, PathBuf}; +use std::ptr; + +use libc::uintptr_t; use crate::chatlist::*; use crate::config::*; @@ -13,15 +16,13 @@ use crate::message::*; use crate::param::*; use crate::sql::{self, Sql}; use crate::stock::StockMessage; -use crate::types::*; use crate::x::*; -use std::ptr; /// An object representing a single chat in memory. /// Chat objects are created using eg. `Chat::load_from_db` /// and are not updated on database changes; /// if you want an update, you have to recreate the object. -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct Chat { pub id: u32, pub typ: Chattype, diff --git a/src/chatlist.rs b/src/chatlist.rs index 1a29b05e4..06b027ea7 100644 --- a/src/chatlist.rs +++ b/src/chatlist.rs @@ -31,6 +31,7 @@ use crate::stock::StockMessage; /// first entry and only present on new messages, there is the rough idea that it can be optionally always /// present and sorted into the list by date. Rendering the deaddrop in the described way /// would not add extra work in the UI then. +#[derive(Debug)] pub struct Chatlist { /// Stores pairs of `chat_id, message_id` ids: Vec<(u32, u32)>, diff --git a/src/configure/mod.rs b/src/configure/mod.rs index 0b60fe6e5..4e2fc15d5 100644 --- a/src/configure/mod.rs +++ b/src/configure/mod.rs @@ -1,3 +1,4 @@ +use libc::uintptr_t; use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; use crate::constants::*; @@ -9,7 +10,6 @@ use crate::job::*; use crate::login_param::LoginParam; use crate::oauth2::*; use crate::param::Params; -use crate::types::*; mod auto_outlook; use auto_outlook::outlk_autodiscover; diff --git a/src/contact.rs b/src/contact.rs index 434358d19..bd2641e8c 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -1,7 +1,9 @@ +use std::path::PathBuf; + use deltachat_derive::*; use itertools::Itertools; +use libc::uintptr_t; use rusqlite; -use std::path::PathBuf; use crate::aheader::EncryptPreference; use crate::config::Config; @@ -16,7 +18,6 @@ use crate::message::MessageState; use crate::peerstate::*; use crate::sql; use crate::stock::StockMessage; -use crate::types::*; /// Contacts with at least this origin value are shown in the contact list. const DC_ORIGIN_MIN_CONTACT_LIST: i32 = 0x100; @@ -31,6 +32,7 @@ const DC_ORIGIN_MIN_CONTACT_LIST: i32 = 0x100; /// For this purpose, internally, two names are tracked - /// authorized-name and given-name. /// By default, these names are equal, but functions working with contact names +#[derive(Debug)] pub struct Contact { /// The contact ID. /// diff --git a/src/context.rs b/src/context.rs index e66931fc2..b7a98f4f5 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,12 +1,11 @@ +use libc::uintptr_t; use std::ffi::OsString; use std::path::{Path, PathBuf}; -use std::ptr; use std::sync::{Arc, Condvar, Mutex, RwLock}; use crate::chat::*; use crate::constants::*; use crate::contact::*; -use crate::dc_receive_imf::*; use crate::dc_tools::*; use crate::error::*; use crate::imap::*; @@ -19,8 +18,6 @@ use crate::message::*; use crate::param::Params; use crate::smtp::*; use crate::sql::Sql; -use crate::types::*; -use crate::x::*; /// Callback function type for [Context] /// @@ -37,6 +34,7 @@ use crate::x::*; /// description at [Event]. pub type ContextCallback = dyn Fn(&Context, Event, uintptr_t, uintptr_t) -> uintptr_t + Send + Sync; +#[derive(DebugStub)] pub struct Context { pub(crate) dbfile: PathBuf, pub(crate) blobdir: PathBuf, @@ -49,6 +47,7 @@ pub struct Context { pub smtp: Arc>, pub smtp_state: Arc<(Mutex, Condvar)>, pub oauth2_critical: Arc>, + #[debug_stub = "Callback"] pub cb: Box, pub os_name: Option, pub cmdline_sel_chat_id: Arc>, @@ -91,14 +90,7 @@ impl Context { let ctx = Context { blobdir, dbfile, - inbox: Arc::new(RwLock::new({ - Imap::new( - cb_get_config, - cb_set_config, - cb_precheck_imf, - cb_receive_imf, - ) - })), + inbox: Arc::new(RwLock::new(Imap::new())), cb, os_name: Some(os_name), running_state: Arc::new(RwLock::new(Default::default())), @@ -112,22 +104,12 @@ impl Context { sentbox_thread: Arc::new(RwLock::new(JobThread::new( "SENTBOX", "configured_sentbox_folder", - Imap::new( - cb_get_config, - cb_set_config, - cb_precheck_imf, - cb_receive_imf, - ), + Imap::new(), ))), mvbox_thread: Arc::new(RwLock::new(JobThread::new( "MVBOX", "configured_mvbox_folder", - Imap::new( - cb_get_config, - cb_set_config, - cb_precheck_imf, - cb_receive_imf, - ), + Imap::new(), ))), probe_imap_network: Arc::new(RwLock::new(false)), perform_inbox_jobs_needed: Arc::new(RwLock::new(false)), @@ -178,7 +160,7 @@ impl Default for RunningState { } } -#[derive(Default)] +#[derive(Debug, Default)] pub struct BobStatus { pub expects: i32, pub status: i32, @@ -194,89 +176,6 @@ pub struct SmtpState { pub probe_network: bool, } -unsafe fn cb_receive_imf( - context: &Context, - imf_raw_not_terminated: *const libc::c_char, - imf_raw_bytes: size_t, - server_folder: &str, - server_uid: uint32_t, - flags: uint32_t, -) { - dc_receive_imf( - context, - imf_raw_not_terminated, - imf_raw_bytes, - server_folder, - server_uid, - flags, - ); -} - -unsafe fn cb_precheck_imf( - context: &Context, - rfc724_mid: *const libc::c_char, - server_folder: &str, - server_uid: uint32_t, -) -> libc::c_int { - let mut rfc724_mid_exists: libc::c_int = 0i32; - let msg_id: uint32_t; - let mut old_server_folder: *mut libc::c_char = ptr::null_mut(); - let mut old_server_uid: uint32_t = 0i32 as uint32_t; - let mut mark_seen: libc::c_int = 0i32; - msg_id = dc_rfc724_mid_exists( - context, - rfc724_mid, - &mut old_server_folder, - &mut old_server_uid, - ); - if msg_id != 0i32 as libc::c_uint { - rfc724_mid_exists = 1i32; - if *old_server_folder.offset(0isize) as libc::c_int == 0i32 - && old_server_uid == 0i32 as libc::c_uint - { - info!(context, "[move] detected bbc-self {}", as_str(rfc724_mid),); - mark_seen = 1i32 - } else if as_str(old_server_folder) != server_folder { - info!( - context, - "[move] detected moved message {}", - as_str(rfc724_mid), - ); - dc_update_msg_move_state(context, rfc724_mid, MoveState::Stay); - } - if as_str(old_server_folder) != server_folder || old_server_uid != server_uid { - dc_update_server_uid(context, rfc724_mid, server_folder, server_uid); - } - do_heuristics_moves(context, server_folder, msg_id); - if 0 != mark_seen { - job_add( - context, - Action::MarkseenMsgOnImap, - msg_id as libc::c_int, - Params::new(), - 0, - ); - } - } - free(old_server_folder as *mut libc::c_void); - rfc724_mid_exists -} - -fn cb_set_config(context: &Context, key: &str, value: Option<&str>) { - context.sql.set_config(context, key, value).ok(); -} - -/* * - * The following three callback are given to dc_imap_new() to read/write configuration - * and to handle received messages. As the imap-functions are typically used in - * a separate user-thread, also these functions may be called from a different thread. - * - * @private @memberof Context - */ -fn cb_get_config(context: &Context, key: &str) -> Option { - context.sql.get_config(context, key) -} - /* ****************************************************************************** * INI-handling, Information ******************************************************************************/ @@ -386,7 +285,7 @@ pub unsafe fn dc_get_info(context: &Context) -> *mut libc::c_char { level=awesome\n", &*DC_VERSION_STR, rusqlite::version(), - sqlite3_threadsafe(), + rusqlite::ffi::sqlite3_threadsafe(), // arch (::std::mem::size_of::<*mut libc::c_void>()).wrapping_mul(8), chats, @@ -448,11 +347,7 @@ pub fn dc_get_fresh_msgs(context: &Context) -> Vec { } #[allow(non_snake_case)] -pub fn dc_search_msgs( - context: &Context, - chat_id: uint32_t, - query: *const libc::c_char, -) -> Vec { +pub fn dc_search_msgs(context: &Context, chat_id: u32, query: *const libc::c_char) -> Vec { if query.is_null() { return Vec::new(); } diff --git a/src/dc_array.rs b/src/dc_array.rs index c3e2dcbe0..d9b2d8d2a 100644 --- a/src/dc_array.rs +++ b/src/dc_array.rs @@ -1,8 +1,7 @@ use crate::location::Location; -use crate::types::*; /* * the structure behind dc_array_t */ -#[derive(Clone)] +#[derive(Debug, Clone)] #[allow(non_camel_case_types)] pub enum dc_array_t { Locations(Vec), @@ -19,7 +18,7 @@ impl dc_array_t { dc_array_t::Locations(Vec::with_capacity(capacity)) } - pub fn add_id(&mut self, item: uint32_t) { + pub fn add_id(&mut self, item: u32) { if let Self::Uint(array) = self { array.push(item); } else { @@ -35,10 +34,10 @@ impl dc_array_t { } } - pub fn get_id(&self, index: usize) -> uint32_t { + pub fn get_id(&self, index: usize) -> u32 { match self { Self::Locations(array) => array[index].location_id, - Self::Uint(array) => array[index] as uint32_t, + Self::Uint(array) => array[index] as u32, } } diff --git a/src/dc_imex.rs b/src/dc_imex.rs index e40d9af27..f53e89382 100644 --- a/src/dc_imex.rs +++ b/src/dc_imex.rs @@ -2,6 +2,7 @@ use std::ffi::CString; use std::path::Path; use std::ptr; +use libc::uintptr_t; use mmime::mailmime_content::*; use mmime::mmapstring::*; use mmime::other::*; @@ -22,7 +23,6 @@ use crate::param::*; use crate::pgp::*; use crate::sql::{self, Sql}; use crate::stock::StockMessage; -use crate::types::*; use crate::x::*; // import/export and tools @@ -242,7 +242,7 @@ pub fn dc_render_setup_file(context: &Context, passphrase: &str) -> Result String { - let mut random_val: uint16_t; + let mut random_val: u16; let mut rng = thread_rng(); let mut ret = String::new(); @@ -253,7 +253,7 @@ pub fn dc_create_setup_code(_context: &Context) -> String { break; } } - random_val = (random_val as libc::c_int % 10000) as uint16_t; + random_val = (random_val as libc::c_int % 10000) as u16; ret += &format!( "{}{:04}", if 0 != i { "-" } else { "" }, @@ -266,7 +266,7 @@ pub fn dc_create_setup_code(_context: &Context) -> String { pub unsafe fn dc_continue_key_transfer( context: &Context, - msg_id: uint32_t, + msg_id: u32, setup_code: *const libc::c_char, ) -> bool { let mut success = false; @@ -405,8 +405,8 @@ pub unsafe fn dc_decrypt_setup_file( let mut fc_headerline: *const libc::c_char = ptr::null(); let mut fc_base64: *const libc::c_char = ptr::null(); let mut binary: *mut libc::c_char = ptr::null_mut(); - let mut binary_bytes: size_t = 0i32 as size_t; - let mut indx: size_t = 0i32 as size_t; + let mut binary_bytes: libc::size_t = 0; + let mut indx: libc::size_t = 0; let mut payload: *mut libc::c_char = ptr::null_mut(); fc_buf = dc_strdup(filecontent); @@ -872,7 +872,7 @@ unsafe fn import_self_keys(context: &Context, dir_name: *const libc::c_char) -> let mut path_plus_name: *mut libc::c_char = ptr::null_mut(); let mut set_default: libc::c_int; let mut buf: *mut libc::c_char = ptr::null_mut(); - let mut buf_bytes: size_t = 0 as size_t; + let mut buf_bytes: libc::size_t = 0; // a pointer inside buf, MUST NOT be free()'d let mut private_key: *const libc::c_char; let mut buf2: *mut libc::c_char = ptr::null_mut(); diff --git a/src/dc_mimefactory.rs b/src/dc_mimefactory.rs index 9fbeeb376..fb8b8bc19 100644 --- a/src/dc_mimefactory.rs +++ b/src/dc_mimefactory.rs @@ -2,6 +2,7 @@ use std::ffi::CString; use std::ptr; use chrono::TimeZone; +use mmime::clist::*; use mmime::mailimf_types::*; use mmime::mailimf_types_helper::*; use mmime::mailmime_disposition::*; @@ -23,7 +24,6 @@ use crate::location; use crate::message::*; use crate::param::*; use crate::stock::StockMessage; -use crate::types::*; use crate::x::*; #[derive(Clone)] @@ -46,7 +46,7 @@ pub struct dc_mimefactory_t<'a> { pub out: *mut MMAPString, pub out_encrypted: libc::c_int, pub out_gossiped: libc::c_int, - pub out_last_added_location_id: uint32_t, + pub out_last_added_location_id: u32, pub error: *mut libc::c_char, pub context: &'a Context, } @@ -264,7 +264,7 @@ unsafe fn load_from(factory: &mut dc_mimefactory_t) { pub unsafe fn dc_mimefactory_load_mdn<'a>( context: &'a Context, - msg_id: uint32_t, + msg_id: u32, ) -> Result { if 0 == context .sql @@ -1248,7 +1248,7 @@ unsafe fn build_body_file( ptr::null_mut(), ptr::null_mut(), ptr::null_mut(), - 0 as size_t, + 0 as libc::size_t, mailmime_parameter_new( strdup( b"filename*\x00" as *const u8 as *const libc::c_char, diff --git a/src/dc_mimeparser.rs b/src/dc_mimeparser.rs index 48c180d3d..02aed946d 100644 --- a/src/dc_mimeparser.rs +++ b/src/dc_mimeparser.rs @@ -3,6 +3,7 @@ use std::ffi::{CStr, CString}; use std::ptr; use charset::Charset; +use mmime::clist::*; use mmime::mailimf::*; use mmime::mailimf_types::*; use mmime::mailmime::*; @@ -22,13 +23,12 @@ use crate::e2ee::*; use crate::location; use crate::param::*; use crate::stock::StockMessage; -use crate::types::*; use crate::x::*; /* Parse MIME body; this is the text part of an IMF, see https://tools.ietf.org/html/rfc5322 dc_mimeparser_t has no deep dependencies to Context or to the database (Context is used for logging only). */ -#[derive(Clone)] +#[derive(Debug, Clone)] #[repr(C)] pub struct dc_mimepart_t { pub type_0: Viewtype, @@ -43,7 +43,7 @@ pub struct dc_mimepart_t { /* * * @class dc_mimeparser_t */ -#[allow(non_camel_case_types)] +#[allow(non_camel_case_types, missing_debug_implementations)] pub struct dc_mimeparser_t<'a> { pub parts: Vec, pub mimeroot: *mut mailmime, @@ -114,7 +114,7 @@ const DC_MIMETYPE_AC_SETUP_FILE: i32 = 111; pub unsafe fn dc_mimeparser_parse<'a>(context: &'a Context, body: &[u8]) -> dc_mimeparser_t<'a> { let r: libc::c_int; - let mut index: size_t = 0i32 as size_t; + let mut index: libc::size_t = 0; let optional_field: *mut mailimf_optional_field; let mut mimeparser = dc_mimeparser_new(context); @@ -294,7 +294,7 @@ pub unsafe fn dc_mimeparser_parse<'a>(context: &'a Context, body: &[u8]) -> dc_m ); if !dn_field.is_null() && dc_mimeparser_get_last_nonmeta(&mut mimeparser).is_some() { let mut mb_list: *mut mailimf_mailbox_list = ptr::null_mut(); - let mut index_0: size_t = 0i32 as size_t; + let mut index_0: libc::size_t = 0; if mailimf_mailbox_list_parse( (*dn_field).fld_value, strlen((*dn_field).fld_value), @@ -459,7 +459,7 @@ unsafe fn dc_mimeparser_parse_mime_recursive( return 0i32; } if mimeparser.header_protected.is_null() { - let mut dummy: size_t = 0i32 as size_t; + let mut dummy: libc::size_t = 0; if mailimf_envelope_and_optional_fields_parse( (*mime).mm_mime_start, (*mime).mm_length, @@ -1298,7 +1298,7 @@ unsafe fn do_add_single_file_part( mime_type: libc::c_int, raw_mime: &str, decoded_data: *const libc::c_char, - decoded_data_bytes: size_t, + decoded_data_bytes: libc::size_t, desired_filename: *const libc::c_char, ) { let pathNfilename: *mut libc::c_char; @@ -1353,14 +1353,14 @@ unsafe fn do_add_single_part(parser: &mut dc_mimeparser_t, mut part: dc_mimepart pub unsafe fn mailmime_transfer_decode( mime: *mut mailmime, ret_decoded_data: *mut *const libc::c_char, - ret_decoded_data_bytes: *mut size_t, + ret_decoded_data_bytes: *mut libc::size_t, ret_to_mmap_string_unref: *mut *mut libc::c_char, ) -> bool { let mut mime_transfer_encoding: libc::c_int = MAILMIME_MECHANISM_BINARY as libc::c_int; let mime_data: *mut mailmime_data; /* must not be free()'d */ let decoded_data: *const libc::c_char; - let mut decoded_data_bytes: size_t = 0i32 as size_t; + let mut decoded_data_bytes: libc::size_t = 0; /* mmap_string_unref()'d if set */ let mut transfer_decoding_buffer: *mut libc::c_char = ptr::null_mut(); if mime.is_null() @@ -1409,7 +1409,7 @@ pub unsafe fn mailmime_transfer_decode( } } else { let r: libc::c_int; - let mut current_index: size_t = 0i32 as size_t; + let mut current_index = 0; r = mailmime_part_parse( (*mime_data).dt_data.dt_text.dt_data, (*mime_data).dt_data.dt_text.dt_length, @@ -1722,7 +1722,7 @@ mod tests { let txt: *const libc::c_char = b"FieldA: ValueA\nFieldB: ValueB\n\x00" as *const u8 as *const libc::c_char; let mut mime: *mut mailmime = ptr::null_mut(); - let mut dummy: size_t = 0i32 as size_t; + let mut dummy = 0; let res = mailmime_parse(txt, strlen(txt), &mut dummy, &mut mime); assert_eq!(res, MAIL_NO_ERROR as libc::c_int); diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 27860c147..e7f5b9622 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -2,6 +2,8 @@ use std::ffi::CString; use std::ptr; use itertools::join; +use libc::uintptr_t; +use mmime::clist::*; use mmime::mailimf::*; use mmime::mailimf_types::*; use mmime::mailmime::*; @@ -27,14 +29,13 @@ use crate::peerstate::*; use crate::securejoin::handle_securejoin_handshake; use crate::sql; use crate::stock::StockMessage; -use crate::types::*; use crate::x::*; /// Receive a message and add it to the database. pub unsafe fn dc_receive_imf( context: &Context, imf_raw_not_terminated: *const libc::c_char, - imf_raw_bytes: size_t, + imf_raw_bytes: libc::size_t, server_folder: impl AsRef, server_uid: u32, flags: u32, @@ -260,7 +261,7 @@ unsafe fn add_parts( context: &Context, mut mime_parser: &mut dc_mimeparser_t, imf_raw_not_terminated: *const libc::c_char, - imf_raw_bytes: size_t, + imf_raw_bytes: libc::size_t, incoming: i32, incoming_origin: &mut Origin, server_folder: impl AsRef, @@ -1028,7 +1029,7 @@ unsafe fn create_or_lookup_group( create_blocked: Blocked, from_id: u32, to_ids: &mut Vec, - ret_chat_id: *mut uint32_t, + ret_chat_id: *mut u32, ret_chat_id_blocked: &mut Blocked, ) { let group_explicitly_left: bool; @@ -1050,7 +1051,7 @@ unsafe fn create_or_lookup_group( let cleanup = |grpname: *mut libc::c_char, failure_reason: *mut libc::c_char, - ret_chat_id: *mut uint32_t, + ret_chat_id: *mut u32, ret_chat_id_blocked: &mut Blocked, chat_id: u32, chat_id_blocked: Blocked| { @@ -1218,7 +1219,7 @@ unsafe fn create_or_lookup_group( && 0 == check_verified_properties( context, mime_parser, - from_id as uint32_t, + from_id as u32, to_ids, &mut failure_reason, ) @@ -1256,7 +1257,7 @@ unsafe fn create_or_lookup_group( if 0 == check_verified_properties( context, mime_parser, - from_id as uint32_t, + from_id as u32, to_ids, &mut failure_reason, ) { @@ -1444,7 +1445,7 @@ unsafe fn create_or_lookup_adhoc_group( create_blocked: Blocked, from_id: u32, to_ids: &mut Vec, - ret_chat_id: *mut uint32_t, + ret_chat_id: *mut u32, ret_chat_id_blocked: &mut Blocked, ) { // if we're here, no grpid was found, check there is an existing ad-hoc @@ -1454,7 +1455,7 @@ unsafe fn create_or_lookup_adhoc_group( let mut grpname = ptr::null_mut(); let cleanup = |grpname: *mut libc::c_char, - ret_chat_id: *mut uint32_t, + ret_chat_id: *mut u32, ret_chat_id_blocked: &mut Blocked, chat_id: u32, chat_id_blocked: Blocked| { diff --git a/src/dc_strencode.rs b/src/dc_strencode.rs index d0e07e435..fbab86c91 100644 --- a/src/dc_strencode.rs +++ b/src/dc_strencode.rs @@ -9,7 +9,6 @@ use mmime::other::*; use percent_encoding::{percent_decode, utf8_percent_encode, AsciiSet, CONTROLS}; use crate::dc_tools::*; -use crate::types::*; use crate::x::*; /** @@ -66,7 +65,7 @@ pub unsafe fn dc_encode_header_words(to_encode: *const libc::c_char) -> *mut lib b"utf-8\x00" as *const u8 as *const libc::c_char, mmapstr, begin, - end.wrapping_offset_from(begin) as size_t, + end.wrapping_offset_from(begin) as libc::size_t, ) { ok_to_continue = false; continue; @@ -82,7 +81,7 @@ pub unsafe fn dc_encode_header_words(to_encode: *const libc::c_char) -> *mut lib if mmap_string_append_len( mmapstr, end, - cur.wrapping_offset_from(end) as size_t, + cur.wrapping_offset_from(end) as libc::size_t, ) .is_null() { @@ -93,7 +92,7 @@ pub unsafe fn dc_encode_header_words(to_encode: *const libc::c_char) -> *mut lib } else if mmap_string_append_len( mmapstr, begin, - cur.wrapping_offset_from(begin) as size_t, + cur.wrapping_offset_from(begin) as libc::size_t, ) .is_null() { @@ -122,10 +121,10 @@ unsafe fn quote_word( display_charset: *const libc::c_char, mmapstr: *mut MMAPString, word: *const libc::c_char, - size: size_t, + size: libc::size_t, ) -> bool { let mut cur: *const libc::c_char; - let mut i: size_t = 0i32 as size_t; + let mut i = 0; let mut hex: [libc::c_char; 4] = [0; 4]; // let mut col: libc::c_int = 0i32; if mmap_string_append(mmapstr, b"=?\x00" as *const u8 as *const libc::c_char).is_null() { @@ -188,7 +187,7 @@ unsafe fn get_word( { cur = cur.offset(1isize) } - *pto_be_quoted = to_be_quoted(begin, cur.wrapping_offset_from(begin) as size_t); + *pto_be_quoted = to_be_quoted(begin, cur.wrapping_offset_from(begin) as libc::size_t); *pend = cur; } @@ -197,9 +196,9 @@ unsafe fn get_word( ******************************************************************************/ /* see comment below */ -unsafe fn to_be_quoted(word: *const libc::c_char, size: size_t) -> bool { +unsafe fn to_be_quoted(word: *const libc::c_char, size: libc::size_t) -> bool { let mut cur: *const libc::c_char = word; - let mut i: size_t = 0i32 as size_t; + let mut i = 0; while i < size { match *cur as libc::c_int { 44 | 58 | 33 | 34 | 35 | 36 | 64 | 91 | 92 | 93 | 94 | 96 | 123 | 124 | 125 | 126 @@ -222,7 +221,7 @@ pub unsafe fn dc_decode_header_words(in_0: *const libc::c_char) -> *mut libc::c_ return ptr::null_mut(); } let mut out: *mut libc::c_char = ptr::null_mut(); - let mut cur_token: size_t = 0i32 as size_t; + let mut cur_token = 0; let r: libc::c_int = mailmime_encoded_phrase_parse( b"iso-8859-1\x00" as *const u8 as *const libc::c_char, in_0, diff --git a/src/dc_tools.rs b/src/dc_tools.rs index d86c565ab..cb8c6d6b6 100644 --- a/src/dc_tools.rs +++ b/src/dc_tools.rs @@ -6,16 +6,16 @@ use std::time::SystemTime; use std::{fmt, fs, ptr}; use chrono::{Local, TimeZone}; +use itertools::max; +use libc::uintptr_t; +use mmime::clist::*; use mmime::mailimf_types::*; use rand::{thread_rng, Rng}; use crate::context::Context; use crate::error::Error; -use crate::types::*; use crate::x::*; -use itertools::max; - /* Some tools and enhancements to the used libraries, there should be no references to Context and other "larger" classes here. */ /* ** library-private **********************************************************/ @@ -98,7 +98,7 @@ pub unsafe fn dc_str_replace( } unsafe fn dc_ltrim(buf: *mut libc::c_char) { - let mut len: size_t; + let mut len: libc::size_t; let mut cur: *const libc::c_uchar; if !buf.is_null() && 0 != *buf as libc::c_int { len = strlen(buf); @@ -118,7 +118,7 @@ unsafe fn dc_ltrim(buf: *mut libc::c_char) { } unsafe fn dc_rtrim(buf: *mut libc::c_char) { - let mut len: size_t; + let mut len: libc::size_t; let mut cur: *mut libc::c_uchar; if !buf.is_null() && 0 != *buf as libc::c_int { len = strlen(buf); @@ -301,9 +301,9 @@ pub unsafe fn dc_truncate_n_unwrap_str( if *p1 as libc::c_int > ' ' as i32 { lastIsCharacter = 1 } else if 0 != lastIsCharacter { - let used_bytes: size_t = (p1 as uintptr_t).wrapping_sub(buf as uintptr_t) as size_t; + let used_bytes = (p1 as uintptr_t).wrapping_sub(buf as uintptr_t) as libc::size_t; if dc_utf8_strnlen(buf, used_bytes) >= approx_characters as usize { - let buf_bytes: size_t = strlen(buf); + let buf_bytes = strlen(buf); if buf_bytes.wrapping_sub(used_bytes) >= strlen(ellipse_utf8) { strcpy(p1 as *mut libc::c_char, ellipse_utf8); } @@ -324,12 +324,12 @@ pub unsafe fn dc_truncate_n_unwrap_str( }; } -unsafe fn dc_utf8_strnlen(s: *const libc::c_char, n: size_t) -> size_t { +unsafe fn dc_utf8_strnlen(s: *const libc::c_char, n: libc::size_t) -> libc::size_t { if s.is_null() { return 0; } - let mut j: size_t = 0; + let mut j: libc::size_t = 0; for i in 0..n { if *s.add(i) as libc::c_int & 0xc0 != 0x80 { j = j.wrapping_add(1) @@ -543,7 +543,7 @@ pub fn dc_create_id() -> String { - the group-id should be a string with the characters [a-zA-Z0-9\-_] */ let mut rng = thread_rng(); - let buf: [uint32_t; 3] = [rng.gen(), rng.gen(), rng.gen()]; + let buf: [u32; 3] = [rng.gen(), rng.gen(), rng.gen()]; encode_66bits_as_base64(buf[0usize], buf[1usize], buf[2usize]) } @@ -808,10 +808,10 @@ pub fn dc_file_exist(context: &Context, path: impl AsRef) -> bo dc_get_abs_path(context, &path).exists() } -pub fn dc_get_filebytes(context: &Context, path: impl AsRef) -> uint64_t { +pub fn dc_get_filebytes(context: &Context, path: impl AsRef) -> u64 { let path_abs = dc_get_abs_path(context, &path); match fs::metadata(&path_abs) { - Ok(meta) => meta.len() as uint64_t, + Ok(meta) => meta.len() as u64, Err(_err) => 0, } } @@ -881,7 +881,7 @@ pub unsafe fn dc_write_file( context: &Context, pathNfilename: *const libc::c_char, buf: *const libc::c_void, - buf_bytes: size_t, + buf_bytes: libc::size_t, ) -> libc::c_int { let bytes = std::slice::from_raw_parts(buf as *const u8, buf_bytes); @@ -912,7 +912,7 @@ pub unsafe fn dc_read_file( context: &Context, pathNfilename: *const libc::c_char, buf: *mut *mut libc::c_void, - buf_bytes: *mut size_t, + buf_bytes: *mut libc::size_t, ) -> libc::c_int { if pathNfilename.is_null() { return 0; diff --git a/src/e2ee.rs b/src/e2ee.rs index 18987f270..dddd24810 100644 --- a/src/e2ee.rs +++ b/src/e2ee.rs @@ -30,10 +30,9 @@ use crate::keyring::*; use crate::peerstate::*; use crate::pgp::*; use crate::securejoin::handle_degrade_event; -use crate::types::*; use crate::x::*; -#[derive(Default)] +#[derive(Debug, Default)] pub struct E2eeHelper { pub encryption_successfull: bool, cdata_to_free: Option>, @@ -166,7 +165,7 @@ impl E2eeHelper { let message_to_encrypt: *mut mailmime = mailmime_new( MAILMIME_MESSAGE as libc::c_int, ptr::null(), - 0i32 as size_t, + 0 as libc::size_t, mailmime_fields_new_empty(), mailmime_get_content_message(), ptr::null_mut(), @@ -312,7 +311,7 @@ impl E2eeHelper { /* create MIME-structure that will contain the encrypted text */ let mut encrypted_part: *mut mailmime = new_data_part( ptr::null_mut(), - 0i32 as size_t, + 0 as libc::size_t, b"multipart/encrypted\x00" as *const u8 as *const libc::c_char as *mut libc::c_char, @@ -494,7 +493,7 @@ impl E2eeHelper { unsafe fn new_data_part( data: *mut libc::c_void, - data_bytes: size_t, + data_bytes: libc::size_t, default_content_type: *mut libc::c_char, default_encoding: libc::c_int, ) -> *mut mailmime { @@ -745,7 +744,7 @@ unsafe fn decrypt_recursive( &mut decrypted_mime, ) { if (*ret_gossip_headers).is_null() && ret_valid_signatures.len() > 0 { - let mut dummy: size_t = 0i32 as size_t; + let mut dummy: libc::size_t = 0i32 as libc::size_t; let mut test: *mut mailimf_fields = ptr::null_mut(); if mailimf_envelope_and_optional_fields_parse( (*decrypted_mime).mm_mime_start, @@ -832,7 +831,7 @@ unsafe fn decrypt_part( let mut transfer_decoding_buffer: *mut libc::c_char = ptr::null_mut(); /* must not be free()'d */ let mut decoded_data: *const libc::c_char = ptr::null_mut(); - let mut decoded_data_bytes: size_t = 0i32 as size_t; + let mut decoded_data_bytes: libc::size_t = 0; let mut sth_decrypted = false; *ret_decrypted_mime = ptr::null_mut(); @@ -878,7 +877,7 @@ unsafe fn decrypt_part( } } else { let r: libc::c_int; - let mut current_index: size_t = 0i32 as size_t; + let mut current_index: libc::size_t = 0; r = mailmime_part_parse( (*mime_data).dt_data.dt_text.dt_data, (*mime_data).dt_data.dt_text.dt_length, @@ -915,7 +914,7 @@ unsafe fn decrypt_part( let plain_bytes = plain.len(); let plain_buf = plain.as_ptr() as *const libc::c_char; - let mut index: size_t = 0i32 as size_t; + let mut index: libc::size_t = 0; let mut decrypted_mime: *mut mailmime = ptr::null_mut(); if mailmime_parse( plain_buf as *const _, diff --git a/src/imap.rs b/src/imap.rs index d245612d1..4520e2ab5 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -1,5 +1,6 @@ use std::ffi::CString; use std::net; +use std::ptr; use std::sync::{ atomic::{AtomicBool, Ordering}, Arc, Condvar, Mutex, RwLock, @@ -7,11 +8,15 @@ use std::sync::{ use std::time::{Duration, SystemTime}; use crate::constants::*; -use crate::context::Context; +use crate::context::{do_heuristics_moves, Context}; +use crate::dc_receive_imf::dc_receive_imf; use crate::dc_tools::CStringExt; +use crate::dc_tools::*; +use crate::job::{job_add, Action}; use crate::login_param::LoginParam; +use crate::message::{dc_rfc724_mid_exists, dc_update_msg_move_state, dc_update_server_uid}; use crate::oauth2::dc_get_oauth2_access_token; -use crate::types::*; +use crate::param::Params; const DC_IMAP_SEEN: usize = 0x0001; const DC_REGENERATE: usize = 0x01; @@ -25,15 +30,11 @@ const PREFETCH_FLAGS: &str = "(UID ENVELOPE)"; const BODY_FLAGS: &str = "(FLAGS BODY.PEEK[])"; const FETCH_FLAGS: &str = "(FLAGS)"; +#[derive(Debug)] pub struct Imap { config: Arc>, watch: Arc<(Mutex, Condvar)>, - get_config: dc_get_config_t, - set_config: dc_set_config_t, - precheck_imf: dc_precheck_imf_t, - receive_imf: dc_receive_imf_t, - session: Arc>>, stream: Arc>>, connected: Arc>, @@ -41,6 +42,7 @@ pub struct Imap { should_reconnect: AtomicBool, } +#[derive(Debug)] struct OAuth2 { user: String, access_token: String, @@ -65,6 +67,7 @@ enum FolderMeaning { Other, } +#[derive(Debug)] enum Client { Secure( imap::Client>, @@ -73,11 +76,13 @@ enum Client { Insecure(imap::Client, net::TcpStream), } +#[derive(Debug)] enum Session { Secure(imap::Session>), Insecure(imap::Session), } +#[derive(Debug)] enum IdleHandle<'a> { Secure(imap::extensions::idle::Handle<'a, native_tls::TlsStream>), Insecure(imap::extensions::idle::Handle<'a, net::TcpStream>), @@ -307,6 +312,7 @@ impl Session { } } +#[derive(Debug)] struct ImapConfig { pub addr: String, pub imap_server: String, @@ -346,21 +352,12 @@ impl Default for ImapConfig { } impl Imap { - pub fn new( - get_config: dc_get_config_t, - set_config: dc_set_config_t, - precheck_imf: dc_precheck_imf_t, - receive_imf: dc_receive_imf_t, - ) -> Self { + pub fn new() -> Self { Imap { session: Arc::new(Mutex::new(None)), stream: Arc::new(RwLock::new(None)), config: Arc::new(RwLock::new(ImapConfig::default())), watch: Arc::new((Mutex::new(false), Condvar::new())), - get_config, - set_config, - precheck_imf, - receive_imf, connected: Arc::new(Mutex::new(false)), should_reconnect: AtomicBool::new(false), } @@ -694,7 +691,7 @@ impl Imap { fn get_config_last_seen_uid>(&self, context: &Context, folder: S) -> (u32, u32) { let key = format!("imap.mailbox.{}", folder.as_ref()); - if let Some(entry) = (self.get_config)(context, &key) { + if let Some(entry) = context.sql.get_config(context, &key) { // the entry has the format `imap.mailbox.=:` let mut parts = entry.split(':'); ( @@ -828,7 +825,7 @@ impl Imap { if 0 == unsafe { let message_id_c = CString::yolo(message_id); - (self.precheck_imf)(context, message_id_c.as_ptr(), folder.as_ref(), cur_uid) + precheck_imf(context, message_id_c.as_ptr(), folder.as_ref(), cur_uid) } { // check passed, go fetch the rest if self.fetch_single_msg(context, &folder, cur_uid) == 0 { @@ -892,7 +889,7 @@ impl Imap { let key = format!("imap.mailbox.{}", folder.as_ref()); let val = format!("{}:{}", uidvalidity, lastseenuid); - (self.set_config)(context, &key, Some(&val)); + context.sql.set_config(context, &key, Some(&val)).ok(); } fn fetch_single_msg>( @@ -962,7 +959,7 @@ impl Imap { if !is_deleted && msg.body().is_some() { let body = msg.body().unwrap(); unsafe { - (self.receive_imf)( + dc_receive_imf( context, body.as_ptr() as *const libc::c_char, body.len(), @@ -1647,3 +1644,53 @@ fn get_folder_meaning(folder_name: &imap::types::Name) -> FolderMeaning { _ => res, } } + +unsafe fn precheck_imf( + context: &Context, + rfc724_mid: *const libc::c_char, + server_folder: &str, + server_uid: u32, +) -> libc::c_int { + let mut rfc724_mid_exists: libc::c_int = 0i32; + let msg_id: u32; + let mut old_server_folder: *mut libc::c_char = ptr::null_mut(); + let mut old_server_uid: u32 = 0i32 as u32; + let mut mark_seen: libc::c_int = 0i32; + msg_id = dc_rfc724_mid_exists( + context, + rfc724_mid, + &mut old_server_folder, + &mut old_server_uid, + ); + if msg_id != 0i32 as libc::c_uint { + rfc724_mid_exists = 1i32; + if *old_server_folder.offset(0isize) as libc::c_int == 0i32 + && old_server_uid == 0i32 as libc::c_uint + { + info!(context, "[move] detected bbc-self {}", as_str(rfc724_mid),); + mark_seen = 1i32 + } else if as_str(old_server_folder) != server_folder { + info!( + context, + "[move] detected moved message {}", + as_str(rfc724_mid), + ); + dc_update_msg_move_state(context, rfc724_mid, MoveState::Stay); + } + if as_str(old_server_folder) != server_folder || old_server_uid != server_uid { + dc_update_server_uid(context, rfc724_mid, server_folder, server_uid); + } + do_heuristics_moves(context, server_folder, msg_id); + if 0 != mark_seen { + job_add( + context, + Action::MarkseenMsgOnImap, + msg_id as libc::c_int, + Params::new(), + 0, + ); + } + } + libc::free(old_server_folder as *mut libc::c_void); + rfc724_mid_exists +} diff --git a/src/job.rs b/src/job.rs index 2f4e6d399..46d5d7e05 100644 --- a/src/job.rs +++ b/src/job.rs @@ -3,6 +3,8 @@ use std::ptr; use std::time::Duration; use deltachat_derive::{FromSql, ToSql}; +use libc::uintptr_t; +use mmime::clist::*; use rand::{thread_rng, Rng}; use crate::chat; @@ -18,7 +20,6 @@ use crate::login_param::LoginParam; use crate::message::*; use crate::param::*; use crate::sql; -use crate::types::*; use crate::x::*; /// Thread IDs @@ -642,7 +643,7 @@ pub fn job_action_exists(context: &Context, action: Action) -> bool { /* special case for DC_JOB_SEND_MSG_TO_SMTP */ #[allow(non_snake_case)] -pub unsafe fn job_send_msg(context: &Context, msg_id: uint32_t) -> libc::c_int { +pub unsafe fn job_send_msg(context: &Context, msg_id: u32) -> libc::c_int { let mut success = 0; /* load message data */ @@ -988,7 +989,7 @@ fn connect_to_inbox(context: &Context, inbox: &Imap) -> libc::c_int { ret_connected } -fn send_mdn(context: &Context, msg_id: uint32_t) { +fn send_mdn(context: &Context, msg_id: u32) { if let Ok(mut mimefactory) = unsafe { dc_mimefactory_load_mdn(context, msg_id) } { if unsafe { dc_mimefactory_render(context, &mut mimefactory) } { add_smtp_job(context, Action::SendMdn, &mut mimefactory); diff --git a/src/job_thread.rs b/src/job_thread.rs index 39384c159..c45d39e72 100644 --- a/src/job_thread.rs +++ b/src/job_thread.rs @@ -4,6 +4,7 @@ use crate::configure::*; use crate::context::Context; use crate::imap::Imap; +#[derive(Debug)] pub struct JobThread { pub name: &'static str, pub folder_config_name: &'static str, diff --git a/src/lib.rs b/src/lib.rs index b6621088f..0d578a3cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![deny(clippy::correctness)] +#![deny(clippy::correctness, missing_debug_implementations)] // TODO: make all of these errors, such that clippy actually passes. #![warn(clippy::all, clippy::perf, clippy::not_unsafe_ptr_arg_deref)] // This is nice, but for now just annoying. @@ -18,6 +18,8 @@ extern crate strum; extern crate strum_macros; #[macro_use] extern crate jetscii; +#[macro_use] +extern crate debug_stub_derive; #[macro_use] mod log; @@ -49,7 +51,6 @@ pub mod qr; mod smtp; pub mod sql; mod stock; -pub mod types; pub mod x; pub mod dc_array; diff --git a/src/location.rs b/src/location.rs index f3056a922..07f63e84f 100644 --- a/src/location.rs +++ b/src/location.rs @@ -1,4 +1,5 @@ use bitflags::bitflags; +use libc::uintptr_t; use quick_xml; use quick_xml::events::{BytesEnd, BytesStart, BytesText}; @@ -13,7 +14,6 @@ use crate::message::*; use crate::param::*; use crate::sql; use crate::stock::StockMessage; -use crate::types::*; // location handling #[derive(Debug, Clone, Default)] diff --git a/src/message.rs b/src/message.rs index 368a2f83f..b8bb8a382 100644 --- a/src/message.rs +++ b/src/message.rs @@ -3,6 +3,7 @@ use std::path::{Path, PathBuf}; use std::ptr; use deltachat_derive::{FromSql, ToSql}; +use libc::uintptr_t; use phf::phf_map; use crate::chat::{self, Chat}; @@ -17,7 +18,6 @@ use crate::param::*; use crate::pgp::*; use crate::sql; use crate::stock::StockMessage; -use crate::types::*; use crate::x::*; /// In practice, the user additionally cuts the string himself pixel-accurate. @@ -136,7 +136,7 @@ impl Lot { /// to check if a mail was sent, use dc_msg_is_sent() /// approx. max. length returned by dc_msg_get_text() /// approx. max. length returned by dc_get_msg_info() -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct Message { pub id: u32, pub from_id: u32, @@ -680,7 +680,7 @@ pub unsafe fn dc_msg_get_filename(msg: &Message) -> *mut libc::c_char { } } -pub fn dc_msg_get_filebytes(context: &Context, msg: &Message) -> uint64_t { +pub fn dc_msg_get_filebytes(context: &Context, msg: &Message) -> u64 { if let Some(file) = msg.param.get(Param::File) { return dc_get_filebytes(context, &file); } @@ -1146,7 +1146,7 @@ pub fn dc_get_real_msg_cnt(context: &Context) -> libc::c_int { } } -pub fn dc_get_deaddrop_msg_cnt(context: &Context) -> size_t { +pub fn dc_get_deaddrop_msg_cnt(context: &Context) -> libc::size_t { match context.sql.query_row( "SELECT COUNT(*) \ FROM msgs m LEFT JOIN chats c ON c.id=m.chat_id \ @@ -1154,7 +1154,7 @@ pub fn dc_get_deaddrop_msg_cnt(context: &Context) -> size_t { rusqlite::NO_PARAMS, |row| row.get::<_, isize>(0), ) { - Ok(res) => res as size_t, + Ok(res) => res as libc::size_t, Err(err) => { error!(context, "dc_get_deaddrop_msg_cnt() failed. {}", err); 0 diff --git a/src/pgp.rs b/src/pgp.rs index 5adf95c51..3aa018d68 100644 --- a/src/pgp.rs +++ b/src/pgp.rs @@ -14,7 +14,6 @@ use rand::thread_rng; use crate::dc_tools::*; use crate::key::*; use crate::keyring::*; -use crate::types::*; use crate::x::*; pub unsafe fn dc_split_armored_data( @@ -25,7 +24,7 @@ pub unsafe fn dc_split_armored_data( ret_base64: *mut *const libc::c_char, ) -> bool { let mut success = false; - let mut line_chars: size_t = 0i32 as size_t; + let mut line_chars: libc::size_t = 0; let mut line: *mut libc::c_char = buf; let mut p1: *mut libc::c_char = buf; let mut p2: *mut libc::c_char; @@ -105,7 +104,7 @@ pub unsafe fn dc_split_armored_data( } p1 = p1.offset(1isize); line = p1; - line_chars = 0i32 as size_t + line_chars = 0; } else { p1 = p1.offset(1isize); line_chars = line_chars.wrapping_add(1) diff --git a/src/securejoin.rs b/src/securejoin.rs index 5ab3948d1..d1e6d93d5 100644 --- a/src/securejoin.rs +++ b/src/securejoin.rs @@ -21,7 +21,6 @@ use crate::peerstate::*; use crate::qr::check_qr; use crate::stock::StockMessage; use crate::token; -use crate::types::*; pub const NON_ALPHANUMERIC_WITHOUT_DOT: &AsciiSet = &NON_ALPHANUMERIC.remove(b'.'); @@ -31,7 +30,11 @@ macro_rules! progress { $progress >= 0 && $progress <= 1000, "value in range 0..1000 expected with: 0=error, 1..999=progress, 1000=success" ); - $context.call_cb($event, $contact_id as uintptr_t, $progress as uintptr_t); + $context.call_cb( + $event, + $contact_id as libc::uintptr_t, + $progress as libc::uintptr_t, + ); }; } @@ -72,7 +75,7 @@ macro_rules! get_qr_attr { }; } -pub fn dc_get_securejoin_qr(context: &Context, group_chat_id: uint32_t) -> Option { +pub fn dc_get_securejoin_qr(context: &Context, group_chat_id: u32) -> Option { /* ========================================================= ==== Alice - the inviter side ==== ==== Step 1 in "Setup verified contact" protocol ==== @@ -148,7 +151,7 @@ fn get_self_fingerprint(context: &Context) -> Option { None } -pub fn dc_join_securejoin(context: &Context, qr: &str) -> uint32_t { +pub fn dc_join_securejoin(context: &Context, qr: &str) -> u32 { let cleanup = |context: &Context, contact_chat_id: u32, ongoing_allocated: bool, join_vg: bool| { let mut bob = context.bob.write().unwrap(); @@ -171,13 +174,13 @@ pub fn dc_join_securejoin(context: &Context, qr: &str) -> uint32_t { if ongoing_allocated { dc_free_ongoing(context); } - ret_chat_id as uint32_t + ret_chat_id as u32 }; /* ========================================================== ==== Bob - the joiner's side ===== ==== Step 2 in "Setup verified contact" protocol ===== ========================================================== */ - let mut contact_chat_id: uint32_t = 0; + let mut contact_chat_id: u32 = 0; let mut join_vg: bool = false; info!(context, "Requesting secure-join ...",); @@ -269,7 +272,7 @@ fn check_exit(context: &Context) -> bool { fn send_handshake_msg( context: &Context, - contact_chat_id: uint32_t, + contact_chat_id: u32, step: &str, param2: impl AsRef, fingerprint: Option, @@ -306,7 +309,7 @@ fn send_handshake_msg( chat::send_msg(context, contact_chat_id, &mut msg).unwrap(); } -fn chat_id_2_contact_id(context: &Context, contact_chat_id: uint32_t) -> uint32_t { +fn chat_id_2_contact_id(context: &Context, contact_chat_id: u32) -> u32 { let contacts = chat::get_chat_contacts(context, contact_chat_id); if contacts.len() == 1 { contacts[0] @@ -342,7 +345,7 @@ fn fingerprint_equals_sender( pub fn handle_securejoin_handshake( context: &Context, mimeparser: &dc_mimeparser_t, - contact_id: uint32_t, + contact_id: u32, ) -> libc::c_int { let own_fingerprint: String; @@ -644,8 +647,8 @@ fn end_bobs_joining(context: &Context, status: libc::c_int) { dc_stop_ongoing_process(context); } -fn secure_connection_established(context: &Context, contact_chat_id: uint32_t) { - let contact_id: uint32_t = chat_id_2_contact_id(context, contact_chat_id); +fn secure_connection_established(context: &Context, contact_chat_id: u32) { + let contact_id: u32 = chat_id_2_contact_id(context, contact_chat_id); let contact = Contact::get_by_id(context, contact_id); let addr = if let Ok(ref contact) = contact { contact.get_addr() @@ -675,11 +678,7 @@ fn lookup_field(mimeparser: &dc_mimeparser_t, key: &str) -> Option { } } -fn could_not_establish_secure_connection( - context: &Context, - contact_chat_id: uint32_t, - details: &str, -) { +fn could_not_establish_secure_connection(context: &Context, contact_chat_id: u32, details: &str) { let contact_id = chat_id_2_contact_id(context, contact_chat_id); let contact = Contact::get_by_id(context, contact_id); let msg = context.stock_string_repl_str( diff --git a/src/smtp.rs b/src/smtp.rs index e9c815a01..2d32396cf 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -7,7 +7,9 @@ use crate::context::Context; use crate::login_param::LoginParam; use crate::oauth2::*; +#[derive(DebugStub)] pub struct Smtp { + #[debug_stub(some = "SmtpTransport")] transport: Option, transport_connected: bool, /// Email address we are sending from. diff --git a/src/sql.rs b/src/sql.rs index 99a0d5d2d..44f464667 100644 --- a/src/sql.rs +++ b/src/sql.rs @@ -13,8 +13,10 @@ use crate::peerstate::*; const DC_OPEN_READONLY: usize = 0x01; /// A wrapper around the underlying Sqlite3 object. +#[derive(DebugStub)] pub struct Sql { pool: RwLock>>, + #[debug_stub = "ThreadLocal"] in_use: Arc>, } diff --git a/src/stock.rs b/src/stock.rs index ffd97462e..d0f0d2800 100644 --- a/src/stock.rs +++ b/src/stock.rs @@ -238,7 +238,7 @@ mod tests { use crate::test_utils::*; use crate::constants::DC_CONTACT_ID_SELF; - use crate::types::uintptr_t; + use libc::uintptr_t; use num_traits::ToPrimitive; diff --git a/src/types.rs b/src/types.rs deleted file mode 100644 index 94ab0d072..000000000 --- a/src/types.rs +++ /dev/null @@ -1,31 +0,0 @@ -#![allow(non_camel_case_types)] -use crate::context::Context; - -pub use mmime::clist::*; -pub use rusqlite::ffi::*; - -pub type dc_receive_imf_t = unsafe fn( - _: &Context, - _: *const libc::c_char, - _: size_t, - _: &str, - _: uint32_t, - _: uint32_t, -) -> (); - -/* Purpose: Reading from IMAP servers with no dependencies to the database. -Context is only used for logging and to get information about -the online state. */ - -pub type dc_precheck_imf_t = - unsafe fn(_: &Context, _: *const libc::c_char, _: &str, _: u32) -> libc::c_int; -pub type dc_set_config_t = fn(_: &Context, _: &str, _: Option<&str>) -> (); -pub type dc_get_config_t = fn(_: &Context, _: &str) -> Option; - -pub type int32_t = i32; -pub type uintptr_t = libc::uintptr_t; -pub type size_t = libc::size_t; -pub type uint32_t = libc::c_uint; -pub type uint8_t = libc::c_uchar; -pub type uint16_t = libc::c_ushort; -pub type uint64_t = u64; diff --git a/tests/stress.rs b/tests/stress.rs index 2b7ee1b13..88447312e 100644 --- a/tests/stress.rs +++ b/tests/stress.rs @@ -15,7 +15,6 @@ use deltachat::dc_tools::*; use deltachat::keyring::*; use deltachat::oauth2::*; use deltachat::pgp::*; -use deltachat::types::*; use deltachat::x::*; use libc; @@ -44,14 +43,11 @@ unsafe fn stress_functions(context: &Context) { context, b"$BLOBDIR/foobar\x00" as *const u8 as *const libc::c_char, b"content\x00" as *const u8 as *const libc::c_char as *const libc::c_void, - 7i32 as size_t, + 7, ); assert!(dc_file_exist(context, "$BLOBDIR/foobar",)); assert!(!dc_file_exist(context, "$BLOBDIR/foobarx")); - assert_eq!( - dc_get_filebytes(context, "$BLOBDIR/foobar",), - 7i32 as libc::c_ulonglong - ); + assert_eq!(dc_get_filebytes(context, "$BLOBDIR/foobar",), 7); let abs_path = context .get_blobdir() @@ -68,7 +64,7 @@ unsafe fn stress_functions(context: &Context) { assert_eq!(dc_get_filebytes(context, "$BLOBDIR/dada",), 7); let mut buf: *mut libc::c_void = ptr::null_mut(); - let mut buf_bytes: size_t = 0; + let mut buf_bytes: libc::size_t = 0; assert_eq!( dc_read_file( @@ -108,7 +104,7 @@ unsafe fn stress_functions(context: &Context) { context, fn0, b"content\x00" as *const u8 as *const libc::c_char as *const libc::c_void, - 7i32 as size_t, + 7, ); let fn1: *mut libc::c_char = dc_get_fine_pathNfilename( context, @@ -566,7 +562,12 @@ fn test_encryption_decryption() { assert_eq!(plain, original_text); } -fn cb(_context: &Context, _event: Event, _data1: uintptr_t, _data2: uintptr_t) -> uintptr_t { +fn cb( + _context: &Context, + _event: Event, + _data1: libc::uintptr_t, + _data2: libc::uintptr_t, +) -> libc::uintptr_t { 0 }