Created attachment 1123[details]
The fix
OVERVIEW:
If removing message(s) from an mbox mailbox causes it to have no messages after the removal, then the removed messages return back to the mailbox after claws-mail restart.
STEPS TO REPRODUCE:
0. use claws-mail-3.8.1, mailmbox-1.14.7, linux 3.4.2 (according to mmap manpage, linux-2.6.12 and above are affected),
1. start claws-mail with mailmbox.so plugin enabled,
2. create an empty mbox mailbox, and a folder in it,
3. copy a message to the folder
4. restart claws-mail
5. enter the folder and delete the message
6. restart claws-mail
7. enter the folder
EXPECTED RESULT: folder is empty
ACTUAL RESULT: folder contains the removed message (and it's unread)
EXPLANATION:
When writing mbox file mmap(0, size, ...) is used with zero size (since there
are no messages in the box). mmap returns MAP_FAILED and
MAILBOX_ERROR_FILE error is returned (which I guess causes the newly
created file to not overwrite the old one).
FIX:
Don't call *map functions if size is zero. The loop between mmap and munmap
won't generate segmentation faults since there are no messages to write so we
can leave it as is.
This causes an empty file to be created and MAILMBOX_NO_ERROR is returned
so the new empty file overwrites the old one.
Created attachment 1123 [details] The fix OVERVIEW: If removing message(s) from an mbox mailbox causes it to have no messages after the removal, then the removed messages return back to the mailbox after claws-mail restart. STEPS TO REPRODUCE: 0. use claws-mail-3.8.1, mailmbox-1.14.7, linux 3.4.2 (according to mmap manpage, linux-2.6.12 and above are affected), 1. start claws-mail with mailmbox.so plugin enabled, 2. create an empty mbox mailbox, and a folder in it, 3. copy a message to the folder 4. restart claws-mail 5. enter the folder and delete the message 6. restart claws-mail 7. enter the folder EXPECTED RESULT: folder is empty ACTUAL RESULT: folder contains the removed message (and it's unread) EXPLANATION: When writing mbox file mmap(0, size, ...) is used with zero size (since there are no messages in the box). mmap returns MAP_FAILED and MAILBOX_ERROR_FILE error is returned (which I guess causes the newly created file to not overwrite the old one). FIX: Don't call *map functions if size is zero. The loop between mmap and munmap won't generate segmentation faults since there are no messages to write so we can leave it as is. This causes an empty file to be created and MAILMBOX_NO_ERROR is returned so the new empty file overwrites the old one.