Archived Forum Post

Index of archived forum posts

Question:

How can I add a custom header to an email and store it on the imap server

Sep 20 '12 at 18:51

Hi,

I want to add a header field to an email retrieved from an imap server and save this change back to the server.

This does not do the job: [email AddHeaderField:@"X-name" fieldValue:@"value"];

Do I have to do more or something else?

Thanks,

Marcel


Answer

Messages on an IMAP server are immutable, meaning they cannot be changed. See this from the IMAP specification (RFC):

The combination of mailbox name, UIDVALIDITY, and UID
must refer to a single immutable message on that server
forever.  In particular, the internal date, [RFC-2822]
size, envelope, body structure, and message texts
(RFC822, RFC822.HEADER, RFC822.TEXT, and all BODY[...]
fetch data items) must never change.  This does not
include message numbers, nor does it include attributes
that can be set by a STORE command (e.g., FLAGS).

Also, if the IMAP RFC is reviewed in detail, you'll find there is no IMAP protocol command for replacing an existing email with different content. In other words, once an email is on the server, it cannot be modified.

The only choice is to fetch the email from the server, make modifications, then upload the modified email to the server using any of the following methods: AppendMail, AppendMime, AppendMimeWithDate, or AppendMimeWithFlags, and then finally to delete the original email from the server.