diff --git a/docs/meli.conf.5 b/docs/meli.conf.5 index e4918715b..8c3864532 100644 --- a/docs/meli.conf.5 +++ b/docs/meli.conf.5 @@ -397,6 +397,12 @@ Add meli User-Agent header in new drafts .Pq Em true .It Ic default_header_values Ar hash table String[String] Default header values used when creating a new draft. +.It Ic store_sent_mail Ar boolean +.Pq Em optional +Store sent mail after successful submission. +This setting is meant to be disabled for non-standard behaviour in gmail, which auto-saves sent mail on its own. +.\" default value +.Pq Em true .El .Sh SHORTCUTS Shortcuts can take the following values: diff --git a/docs/samples/sample-config.toml b/docs/samples/sample-config.toml index 367310a79..d2062c528 100644 --- a/docs/samples/sample-config.toml +++ b/docs/samples/sample-config.toml @@ -59,7 +59,25 @@ # "INBOX" = { query="tag:inbox", subscribe = true } # "Drafts" = { query="tag:draft", subscribe = true } # "Sent" = { query="from:username@server.tld from:username2@server.tld", subscribe = true } -## +# +## Setting up a Gmail account +#[accounts."gmail"] +#root_mailbox = '[Gmail]' +#format = "imap" +#server_hostname='imap.gmail.com' +#server_password="password" +#server_username="username@gmail.com" +#server_port="993" +#index_style = "Conversations" +#identity = "username@server.tld" +#display_name = "Name Name" +### match every mailbox: +#subscribed_mailboxes = ["*" ] +#composing.send_mail = 'msmtp --read-recipients --read-envelope-from' +### Gmail auto saves sent mail to Sent folder, so don't duplicate the effort: +#composing.store_sent_mail = false +# +# #[pager] #filter = "COLUMNS=72 /usr/local/bin/pygmentize -l email" #pager_context = 0 # default, optional diff --git a/src/components/mail/compose.rs b/src/components/mail/compose.rs index ba0b96af1..fb918ac74 100644 --- a/src/components/mail/compose.rs +++ b/src/components/mail/compose.rs @@ -2058,6 +2058,7 @@ pub fn send_draft_async( mailbox_type: SpecialUsageMailbox, flags: Flag, ) -> Result> + Send>>> { + let store_sent_mail = *account_settings!(context[account_hash].composing.store_sent_mail); let format_flowed = *account_settings!(context[account_hash].composing.format_flowed); let event_sender = context.sender.clone(); #[cfg(feature = "gpgme")] @@ -2127,27 +2128,38 @@ pub fn send_draft_async( let message = Arc::new(draft.finalise()?); let ret = send_cb(message.clone()).await; let is_ok = ret.is_ok(); - event_sender - .send(ThreadEvent::UIEvent(UIEvent::Callback(CallbackFn( - Box::new(move |context| { - save_draft( - message.as_bytes(), - context, - if is_ok { - mailbox_type - } else { - SpecialUsageMailbox::Drafts - }, - if is_ok { - flags - } else { - Flag::SEEN | Flag::DRAFT - }, - account_hash, - ); - }), - )))) - .unwrap(); + if !is_ok || (store_sent_mail && is_ok) { + event_sender + .send(ThreadEvent::UIEvent(UIEvent::Callback(CallbackFn( + Box::new(move |context| { + save_draft( + message.as_bytes(), + context, + if is_ok { + mailbox_type + } else { + SpecialUsageMailbox::Drafts + }, + if is_ok { + flags + } else { + Flag::SEEN | Flag::DRAFT + }, + account_hash, + ); + }), + )))) + .unwrap(); + } else if !store_sent_mail && is_ok { + let f = create_temp_file(message.as_bytes(), None, None, false); + log( + format!( + "store_sent_mail is false; stored sent mail to {}", + f.path().display() + ), + INFO, + ); + } ret })) } diff --git a/src/conf/composing.rs b/src/conf/composing.rs index a7600fa5a..cb790d3cb 100644 --- a/src/conf/composing.rs +++ b/src/conf/composing.rs @@ -53,6 +53,11 @@ pub struct ComposingSettings { /// Default: empty #[serde(default, alias = "default-header-values")] pub default_header_values: HashMap, + /// Store sent mail after successful submission. This setting is meant to be disabled for + /// non-standard behaviour in gmail, which auto-saves sent mail on its own. + /// Default: true + #[serde(default = "true_val")] + pub store_sent_mail: bool, } impl Default for ComposingSettings { @@ -64,6 +69,7 @@ impl Default for ComposingSettings { format_flowed: true, insert_user_agent: true, default_header_values: HashMap::default(), + store_sent_mail: true, } } } diff --git a/src/conf/overrides.rs b/src/conf/overrides.rs index 577e084e0..9acfabafa 100644 --- a/src/conf/overrides.rs +++ b/src/conf/overrides.rs @@ -252,6 +252,11 @@ pub struct ComposingSettingsOverride { #[serde(alias = "default-header-values")] #[serde(default)] pub default_header_values: Option>, + #[doc = " Store sent mail after successful submission. This setting is meant to be disabled for"] + #[doc = " non-standard behaviour in gmail, which auto-saves sent mail on its own."] + #[doc = " Default: true"] + #[serde(default)] + pub store_sent_mail: Option, } impl Default for ComposingSettingsOverride { fn default() -> Self { @@ -262,6 +267,7 @@ impl Default for ComposingSettingsOverride { format_flowed: None, insert_user_agent: None, default_header_values: None, + store_sent_mail: None, } } }