User Contributed Notes 16 notes

As we have been struggling with this for some time I wanted to share how we got imap_append working properly with all MIME parts including attachments. If you are sending email and also wish to append the sent message to the Sent Items folder, I cannot think of an easier way to do this, as follows:

<?php// after creating content of mail you have to run preSend() - part of send() method$mail->send();// and you can get whole raw message with getSentMIMEMessage() methodimap_append($imap, $mailserver.'INBOX.Sent',$mail->getSentMIMEMessage(), "\\Seen");

I have used this function to copy all the emails of one account from one server to another. The problem was that this function don't copy the original receiving date for each message.To add a fifth field to provide the date, I have made some changes at some php source files following the steps described in http://www.zend.com/lists/php-dev/200303/msg00843.html and it has worked fine.The correct date format is the returned by the function mail_date in c-client/mail.c source file, for instance: "17-Jan-2007 10:00:01 +0100"

The parameter description is misleading. You can pass a string of flags such as '\Seen' [see imap_setflag_full()] as the last argument. In the other imap functions, 'options' seems to usually refer to a bitmask, not message flags.

With SIMS IMAP server you also need to use \r\n as a line terminator, otherwise you will be able to add all the header lines correctly, but the body of the message will not be saved.<br>
You can use \n by itself for each header line, but when creating the blank line between the headers and the body you must use \r\n\r\n

We couldn't get this function to work properly with MS-Exchange/IMAP, not because there's a problem with a the function as such, but because MS-Exchange changed the content-type in the header from multipart/[anything] to text/plain in every instance. We set ImapMessagesRetrievalMimeFormat to HtmlAndTextAlternativeon the Exchange server, and that didn't help either. I even tried wrapping the multipart message in a message/rfc822 wrapper and it reached inside the outer message and tweeked the inner message from multipart/alternative to text/plain.

Messages emailed to the mbox were unaffected, I suggest you try that route instead, and move the relevant messages to where you want them.

This inserts the current date into the email and lets it support html content. The one thing that I haven't got working yet is including attachments. I presumably have to make the boundaries and attachment content part of the message body.