Skip to content
Snippets Groups Projects
Commit e1f2abc0 authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Sieve-filter: corrected and optimized mail filter loop.

parent f002157d
No related branches found
No related tags found
No related merge requests found
...@@ -139,11 +139,17 @@ static int filter_mailbox ...@@ -139,11 +139,17 @@ static int filter_mailbox
struct mail *mail; struct mail *mail;
int ret = 1; int ret = 1;
/* Search non-deleted messages in the indicated folder */ /* Sync mailbox */
if ( mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ, 0, NULL) < 0 ) {
return -1;
}
/* Search non-deleted messages in the source folder */
search_args = mail_search_build_init(); search_args = mail_search_build_init();
mail_search_build_add_flags(search_args, MAIL_DELETED, TRUE); mail_search_build_add_flags(search_args, MAIL_DELETED, TRUE);
/* Iterate through all requested messages */ /* Iterate through all requested messages */
t = mailbox_transaction_begin(box, MAILBOX_TRANSACTION_FLAG_REFRESH); t = mailbox_transaction_begin(box, MAILBOX_TRANSACTION_FLAG_REFRESH);
...@@ -165,11 +171,10 @@ static int filter_mailbox ...@@ -165,11 +171,10 @@ static int filter_mailbox
continue; continue;
} }
(void)mail_get_first_header(mail, "date", &date); if ( mail_get_first_header(mail, "date", &date) <= 0 )
(void)mail_get_first_header(mail, "subject", &subject); date = "";
if ( mail_get_first_header(mail, "subject", &subject) <= 0 )
if ( subject == NULL ) subject = ""; subject = "";
if ( date == NULL ) date = "";
sieve_info(ehandler, NULL, sieve_info(ehandler, NULL,
"filtering: [%s; %"PRIuUOFF_T" bytes] %s", date, size, subject); "filtering: [%s; %"PRIuUOFF_T" bytes] %s", date, size, subject);
...@@ -184,14 +189,19 @@ static int filter_mailbox ...@@ -184,14 +189,19 @@ static int filter_mailbox
ret = -1; ret = -1;
} }
if ( mailbox_transaction_commit(&t) < 0 ) { if ( ret < 0 ) {
ret = -1; mailbox_transaction_rollback(&t);
return -1;
} else {
if ( mailbox_transaction_commit(&t) < 0 ) {
return -1;
}
} }
/* Synchronize mailbox */ /* Sync mailbox */
if ( mailbox_sync(box, MAILBOX_SYNC_FLAG_FAST, 0, NULL) < 0 ) { if ( mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_WRITE, 0, NULL) < 0 ) {
ret = -1; return -1;
} }
return ret; return ret;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.