From b1fe12881e8bb29e948d411b706a841454413d15 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Tue, 24 Oct 2023 17:42:34 +0200 Subject: [PATCH 1/4] document `configured_addr` in fact, it was already used like that, eg. to detect an AEAP change on android. but it was never documented officially. --- deltachat-ffi/deltachat.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index c330f5510a..a1c45214f4 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -384,7 +384,12 @@ char* dc_get_blobdir (const dc_context_t* context); /** * Configure the context. The configuration is handled by key=value pairs as: * - * - `addr` = address to display (always needed) + * - `addr` = Email address to use for configuration. + * If dc_configure() fails this is not the email address actually in use. + * Use `configured_addr` to find out the email address actually in use. + * - `configured_addr` = Email address actually in use. + * Unless for testing, do not set this value using dc_set_config(). + * Instead, set `addr` and call dc_configure(). * - `mail_server` = IMAP-server, guessed if left out * - `mail_user` = IMAP-username, guessed if left out * - `mail_pw` = IMAP-password (always needed) From 0ba3501a46439f08cddc706576986e259ebca5c0 Mon Sep 17 00:00:00 2001 From: link2xt Date: Tue, 24 Oct 2023 17:00:14 +0000 Subject: [PATCH 2/4] chore: update trust-dns-resolver to hickory-resolver --- Cargo.lock | 117 +++++++++++++++++++++--------------------------- Cargo.toml | 2 +- src/provider.rs | 4 +- 3 files changed, 53 insertions(+), 70 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f1176b4364..212dbe9f2c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1116,6 +1116,7 @@ dependencies = [ "futures", "futures-lite", "hex", + "hickory-resolver", "humansize", "image", "iroh", @@ -1162,7 +1163,6 @@ dependencies = [ "tokio-tar", "tokio-util", "toml", - "trust-dns-resolver", "url", "uuid", ] @@ -1708,14 +1708,14 @@ checksum = "b5320ae4c3782150d900b79807611a59a99fc9a1d61d686faafc24b93fc8d7ca" [[package]] name = "enum-as-inner" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9720bba047d567ffc8a3cba48bf19126600e249ab7f128e9233e6376976a116" +checksum = "5ffccbb6966c05b32ef8fbac435df276c4ae4d3dc55a8cd0eb9745e6c12f546a" dependencies = [ "heck", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.23", ] [[package]] @@ -2199,6 +2199,51 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hickory-proto" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "091a6fbccf4860009355e3efc52ff4acf37a63489aad7435372d44ceeb6fbbcf" +dependencies = [ + "async-trait", + "cfg-if", + "data-encoding", + "enum-as-inner", + "futures-channel", + "futures-io", + "futures-util", + "idna", + "ipnet", + "once_cell", + "rand 0.8.5", + "thiserror", + "tinyvec", + "tokio", + "tracing", + "url", +] + +[[package]] +name = "hickory-resolver" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35b8f021164e6a984c9030023544c57789c51760065cd510572fedcfb04164e8" +dependencies = [ + "cfg-if", + "futures-util", + "hickory-proto", + "ipconfig", + "lru-cache", + "once_cell", + "parking_lot", + "rand 0.8.5", + "resolv-conf", + "smallvec", + "thiserror", + "tokio", + "tracing", +] + [[package]] name = "hkdf" version = "0.12.3" @@ -2375,17 +2420,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" -[[package]] -name = "idna" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" -dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "idna" version = "0.4.0" @@ -2717,12 +2751,6 @@ dependencies = [ "regex-automata", ] -[[package]] -name = "matches" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" - [[package]] name = "matchit" version = "0.7.0" @@ -5093,51 +5121,6 @@ dependencies = [ "tracing-log", ] -[[package]] -name = "trust-dns-proto" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f7f83d1e4a0e4358ac54c5c3681e5d7da5efc5a7a632c90bb6d6669ddd9bc26" -dependencies = [ - "async-trait", - "cfg-if", - "data-encoding", - "enum-as-inner", - "futures-channel", - "futures-io", - "futures-util", - "idna 0.2.3", - "ipnet", - "lazy_static", - "rand 0.8.5", - "smallvec", - "thiserror", - "tinyvec", - "tokio", - "tracing", - "url", -] - -[[package]] -name = "trust-dns-resolver" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aff21aa4dcefb0a1afbfac26deb0adc93888c7d295fb63ab273ef276ba2b7cfe" -dependencies = [ - "cfg-if", - "futures-util", - "ipconfig", - "lazy_static", - "lru-cache", - "parking_lot", - "resolv-conf", - "smallvec", - "thiserror", - "tokio", - "tracing", - "trust-dns-proto", -] - [[package]] name = "try-lock" version = "0.2.4" @@ -5266,7 +5249,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" dependencies = [ "form_urlencoded", - "idna 0.4.0", + "idna", "percent-encoding", ] diff --git a/Cargo.toml b/Cargo.toml index ac0a42870e..b9b4e456a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,6 +52,7 @@ fast-socks5 = "0.8" futures = "0.3" futures-lite = "1.13.0" hex = "0.4.0" +hickory-resolver = "0.24" humansize = "2" image = { version = "0.24.6", default-features=false, features = ["gif", "jpeg", "ico", "png", "pnm", "webp", "bmp"] } iroh = { version = "0.4.1", default-features = false } @@ -92,7 +93,6 @@ tokio-stream = { version = "0.1.14", features = ["fs"] } tokio-tar = { version = "0.3" } # TODO: integrate tokio into async-tar tokio-util = "0.7.8" toml = "0.7" -trust-dns-resolver = "0.22" url = "2" uuid = { version = "1", features = ["serde", "v4"] } diff --git a/src/provider.rs b/src/provider.rs index fe7073ebe6..c79815c6c3 100644 --- a/src/provider.rs +++ b/src/provider.rs @@ -3,7 +3,7 @@ mod data; use anyhow::Result; -use trust_dns_resolver::{config, AsyncResolver, TokioAsyncResolver}; +use hickory_resolver::{config, AsyncResolver, TokioAsyncResolver}; use crate::config::Config; use crate::context::Context; @@ -172,7 +172,7 @@ fn get_resolver() -> Result { let resolver = AsyncResolver::tokio( config::ResolverConfig::default(), config::ResolverOpts::default(), - )?; + ); Ok(resolver) } From ac557f73b3ed48540845cef8a9bd81779bb510b0 Mon Sep 17 00:00:00 2001 From: link2xt Date: Tue, 24 Oct 2023 17:02:16 +0000 Subject: [PATCH 3/4] chore: remove unneeded idna rule for cargo-deny --- deny.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/deny.toml b/deny.toml index fb905719ba..2231b94c14 100644 --- a/deny.toml +++ b/deny.toml @@ -26,7 +26,6 @@ skip = [ { name = "ed25519", version = "1.5.3" }, { name = "getrandom", version = "<0.2" }, { name = "hashbrown", version = "<0.14.0" }, - { name = "idna", version = "<0.3" }, { name = "indexmap", version = "<2.0.0" }, { name = "linux-raw-sys", version = "0.3.8" }, { name = "num-derive", version = "0.3.3" }, From e725bdfb2bc56d1995db2a8840cdb7d0b41d2311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kl=C3=A4hn?= <39526136+Septias@users.noreply.github.com> Date: Sun, 15 Oct 2023 12:40:32 +0200 Subject: [PATCH 4/4] feat: add bot field to contact (#4821) closes #4647 --- src/contact.rs | 21 ++++++++++++++++++++- src/message.rs | 4 ++++ src/mimeparser.rs | 8 ++++++++ src/receive_imf.rs | 2 ++ src/sql/migrations.rs | 9 +++++++++ 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/contact.rs b/src/contact.rs index be04523f9d..4a4ff35406 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -139,6 +139,15 @@ impl ContactId { pub const fn to_u32(&self) -> u32 { self.0 } + + /// Mark contact as bot. + pub(crate) async fn mark_bot(&self, context: &Context, is_bot: bool) -> Result<()> { + context + .sql + .execute("UPDATE contacts SET is_bot=? WHERE id=?;", (is_bot, self.0)) + .await?; + Ok(()) + } } impl fmt::Display for ContactId { @@ -223,6 +232,9 @@ pub struct Contact { /// Last seen message signature for this contact, to be displayed in the profile. status: String, + + /// If the contact is a bot. + is_bot: bool, } /// Possible origins of a contact. @@ -366,7 +378,7 @@ impl Contact { .sql .query_row_optional( "SELECT c.name, c.addr, c.origin, c.blocked, c.last_seen, - c.authname, c.param, c.status + c.authname, c.param, c.status, c.is_bot FROM contacts c WHERE c.id=?;", (contact_id,), @@ -379,6 +391,7 @@ impl Contact { let authname: String = row.get(5)?; let param: String = row.get(6)?; let status: Option = row.get(7)?; + let is_bot: bool = row.get(8)?; let contact = Self { id: contact_id, name, @@ -389,6 +402,7 @@ impl Contact { origin, param: param.parse().unwrap_or_default(), status: status.unwrap_or_default(), + is_bot, }; Ok(contact) }, @@ -498,6 +512,11 @@ impl Contact { Ok(()) } + /// Returns whether contact is a bot. + pub fn is_bot(&self) -> bool { + self.is_bot + } + /// Check if an e-mail address belongs to a known and unblocked contact. /// /// Known and unblocked contacts will be returned by `get_contacts()`. diff --git a/src/message.rs b/src/message.rs index 0a299c3e94..8d5ec6fea0 100644 --- a/src/message.rs +++ b/src/message.rs @@ -2341,6 +2341,8 @@ mod tests { let msg = alice.get_last_msg().await; assert_eq!(msg.get_text(), "hello".to_string()); assert!(msg.is_bot()); + let contact = Contact::get_by_id(&alice, msg.from_id).await?; + assert!(contact.is_bot()); // Alice receives a message from Bob who is not the bot anymore. receive_imf( @@ -2358,6 +2360,8 @@ mod tests { let msg = alice.get_last_msg().await; assert_eq!(msg.get_text(), "hello again".to_string()); assert!(!msg.is_bot()); + let contact = Contact::get_by_id(&alice, msg.from_id).await?; + assert!(!contact.is_bot()); Ok(()) } diff --git a/src/mimeparser.rs b/src/mimeparser.rs index d1cfd5fa2d..21207a86ad 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -114,7 +114,11 @@ pub(crate) struct MimeMessage { /// for e.g. late-parsing HTML. pub decoded_data: Vec, + /// Hop info for debugging. pub(crate) hop_info: String, + + /// Whether the contact sending this should be marked as bot. + pub(crate) is_bot: bool, } #[derive(Debug, PartialEq)] @@ -373,6 +377,9 @@ impl MimeMessage { signatures.clear(); } + // Auto-submitted is also set by holiday-notices so we also check `chat-version` + let is_bot = headers.contains_key("auto-submitted") && headers.contains_key("chat-version"); + let mut parser = MimeMessage { parts: Vec::new(), headers, @@ -401,6 +408,7 @@ impl MimeMessage { is_mime_modified: false, decoded_data: Vec::new(), hop_info, + is_bot, }; match partial { diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 58a094c919..f254459e70 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -377,6 +377,8 @@ pub(crate) async fn receive_imf_inner( .handle_reports(context, from_id, sent_timestamp, &mime_parser.parts) .await; + from_id.mark_bot(context, mime_parser.is_bot).await?; + Ok(Some(received_msg)) } diff --git a/src/sql/migrations.rs b/src/sql/migrations.rs index a90f36b0ea..8f3b245093 100644 --- a/src/sql/migrations.rs +++ b/src/sql/migrations.rs @@ -740,6 +740,15 @@ CREATE INDEX smtp_messageid ON imap(rfc724_mid); .await?; } + // Add is_bot column to contacts table with default false. + if dbversion < 103 { + sql.execute_migration( + "ALTER TABLE contacts ADD COLUMN is_bot INTEGER NOT NULL DEFAULT 0", + 103, + ) + .await?; + } + let new_version = sql .get_raw_config_int(VERSION_CFG) .await?