From e7c14f56b26abd51d770220e79f6db41b97f523f Mon Sep 17 00:00:00 2001 From: Simon Chopin Date: Tue, 24 Oct 2023 11:50:12 +0200 Subject: [PATCH] feature: compose: allow not storing the sent emails I'm using lieer/gmi to send email, and it has the builtin assumption that no new messages will be added to the maildir. See https://github.com/gauteh/lieer/issues/54 --- dodo/compose.py | 11 +++++++---- dodo/settings.py | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/dodo/compose.py b/dodo/compose.py index 53856d3..b33d166 100644 --- a/dodo/compose.py +++ b/dodo/compose.py @@ -468,14 +468,17 @@ def run(self) -> None: sendmail.wait(30) if sendmail.returncode == 0: # save to sent folder - m = mailbox.MaildirMessage(str(eml)) - m.set_flags('S') if isinstance(settings.sent_dir, dict): sent_dir = settings.sent_dir[account] else: sent_dir = settings.sent_dir - key = mailbox.Maildir(sent_dir).add(m) - # print(f'add: {key}') + # None means we should discard the email, presumably because it's already + # handled by whatever mechanism sends it in the first place + if sent_dir is not None: + m = mailbox.MaildirMessage(str(eml)) + m.set_flags('S') + key = mailbox.Maildir(sent_dir).add(m) + # print(f'add: {key}') subprocess.run(['notmuch', 'new', '--no-hooks']) diff --git a/dodo/settings.py b/dodo/settings.py index 2e72eb9..07fa005 100644 --- a/dodo/settings.py +++ b/dodo/settings.py @@ -53,6 +53,10 @@ :func:`~dodo.settings.sync_mail_command`. This setting can be given either as a string to use one global sent directory, or as a dictionary mapping account names in :func:`~dodo.settings.smtp_accounts` to their own sent dirs. + +A value of None, either standalone or as one of the dict value, can be used to +indicate the email should be discarded. This can be useful if the sendmail +command already has a mechanism for that feature. """ editor_command = "xterm -e vim '{file}'"