Skip to content

Commit

Permalink
plugins: imapsieve: Expunge discarded messages when imapsieve_expunge…
Browse files Browse the repository at this point in the history
…_discarded=yes.
  • Loading branch information
stephanbosch committed Dec 11, 2018
1 parent 26621c5 commit dab0f6d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
7 changes: 7 additions & 0 deletions doc/plugins/imapsieve.txt
Expand Up @@ -122,6 +122,13 @@ imapsieve_mailboxXXX_copy_source_after =
moved messages, since the message is removed from the source mailbox in that
case.

imapsieve_expunge_discarded=no
When enabled, discarded messages (for which no keep action is in effect) will
be expunged immediately when the Sieve script execution is succcessful.
Normally, such messages are only marked with the "\Deleted" flag and will be
expunged only when the client explicitly issues an IMAP EXPUNGE command on the
mailbox at a later time.

Example
-------

Expand Down
21 changes: 17 additions & 4 deletions src/plugins/imapsieve/imap-sieve-storage.c
Expand Up @@ -76,6 +76,7 @@ struct imap_sieve_user {

bool sieve_active:1;
bool user_script:1;
bool expunge_discarded:1;
};

struct imap_sieve_mailbox_event {
Expand Down Expand Up @@ -760,9 +761,15 @@ imap_sieve_mailbox_transaction_run(
if (ret < 0) {
/* Sieve error; keep */
} else {
if (ret > 0 && can_discard) {
/* Discard */
mail_update_flags(mail, MODIFY_ADD, MAIL_DELETED);
if (ret <= 0 || !can_discard) {
/* Keep */
} else if (!isuser->expunge_discarded) {
/* Mark as \Deleted */
mail_update_flags(mail,
MODIFY_ADD, MAIL_DELETED);
} else {
/* Expunge */
mail_expunge(mail);
}

imap_sieve_mailbox_run_copy_source
Expand Down Expand Up @@ -1226,10 +1233,16 @@ static void imap_sieve_command_post(struct client_command_context *cmd)
void imap_sieve_storage_client_created(struct client *client,
bool user_script)
{
struct imap_sieve_user *isuser = IMAP_SIEVE_USER_CONTEXT_REQUIRE(client->user);
struct mail_user *user = client->user;
struct imap_sieve_user *isuser = IMAP_SIEVE_USER_CONTEXT_REQUIRE(user);
const char *set;

isuser->client = client;
isuser->user_script = user_script;

set = mail_user_plugin_getenv(user, "imapsieve_expunge_discarded");
isuser->expunge_discarded =
(set != NULL && strcasecmp(set, "yes") == 0);
}

/*
Expand Down

0 comments on commit dab0f6d

Please sign in to comment.