Add store_sent_mail option for gmail

- store_sent_mail boolean

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.
jmap-eventsource
Manos Pitsidianakis 2020-11-09 22:22:11 +02:00
parent 23777171f2
commit 72084da185
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
5 changed files with 70 additions and 22 deletions

View File

@ -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:

View File

@ -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

View File

@ -2058,6 +2058,7 @@ pub fn send_draft_async(
mailbox_type: SpecialUsageMailbox,
flags: Flag,
) -> Result<Pin<Box<dyn Future<Output = 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
}))
}

View File

@ -53,6 +53,11 @@ pub struct ComposingSettings {
/// Default: empty
#[serde(default, alias = "default-header-values")]
pub default_header_values: HashMap<String, String>,
/// 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,
}
}
}

View File

@ -252,6 +252,11 @@ pub struct ComposingSettingsOverride {
#[serde(alias = "default-header-values")]
#[serde(default)]
pub default_header_values: Option<HashMap<String, String>>,
#[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<bool>,
}
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,
}
}
}