Bug 2687

Summary: Unable to clean an mbox mailbox
Product: Claws Mail (GTK 2) Reporter: pv4
Component: Plugins/mailMBOXAssignee: users
Status: RESOLVED FIXED    
Severity: normal    
Priority: P3    
Version: 3.8.1   
Hardware: PC   
OS: Linux   
Attachments:
Description Flags
The fix none

Description pv4 2012-07-01 11:47:17 UTC
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.
Comment 1 Paul 2012-07-15 06:13:03 UTC
Thanks for your contribution.