Modify stored mail contents?
Evan Martin
dovecot-ml at realityexists.net
Sun Jul 23 18:11:20 EEST 2017
On 23/07/2017 3:30 PM, Sami Ketola wrote:
> On 23 Jul 2017, at 16.14, Tom Hendrikx <tom at whyscream.net> wrote:
>> In general, you should not do this. When a message is stored using IMAP,
>> it is immutable. The IMAP server also remembers things like size and
>> assigns messages a unique ID, so mail readers that have already
>> downloaded the message with that ID, don't have to download the whole
>> message again to verify whether it's contents have magically changed.
>> What you're suggesting is not simply compatible with IMAP standards.
>>
>> The normal way of applying changes to messages is just like a mail
>> client connecting to IMAP: create a new message and save it to the
>> store, then delete the old one.
> Just like that. But instead of using IMAP interface to do it, you can also do
> it with doveadm:
>
> 1. doveadm fetch mail
> 2. doveadm delete mail
> 3. modify fetched mail
> 4. doveadm import modified mail back
>
> Simple as that. There is no other supported way to do it. Editing mail objects
> on storage will break things.
>
> Sami
Thank you, that's an interesting idea. Exporting the mail and deleting
it is easy enough, but I'm not sure where I would import the message
from. doveadm import expects a mailbox store as source, so I'm back to
the problem of safely writing emails in a mailbox store format that
Dovecot understands!
I can export to Maildir format [doveadm backup -u USER
"maildir:/mymaildir:LAYOUT=fs"], where each file contains one message
and nothing else, but even that has extra files like dovecot-uidlist,
dovecot.index.cache, etc. I'm not sure if it's safe to import from a
Maildir where the message contents have been modified, but the other
files haven't.
Also, would the import create new UIDs? I probably want UIDs to change,
so that the IMAP client re-downloads the messages. I'd want to preserve
IMAP flags like "Seen", though and, ideally, the sequence of messages
inside a mailbox.
More information about the dovecot
mailing list