Is there an easy way to forward multipart messages out of an IMAP mailbox using Swift? Right now I'm constructing a new Message using the raw body as retrieved by imap_body(). I'm also attempting to retrieve the Content-Type header from the message in the IMAP box and set the Content-Type header on the Swift Message to the same string using Message->headers->set(), but my string is getting encoded and having a different charset tacked on the end of it, as well as format=flowed. So, it looks like this:
Content-Type: =?iso-8859-1?B?b250ZW50LVR5cGU6IG11bHRpcGFydC9taXhlZDsg?=
=?iso-8859-1?B?Ym91bmRhcnk9QXBwbGUtTWFpbC0yNS05NDY3NTM2MzcN?=;
charset=iso-8859-1; format=flowed
Am I going to have to parse the original Content-Type and set it and its attributes piecemeal with Message->headers->set() followed by Message->headers->setAttribute()? Will this even work for what I'm trying to do (forward a message with the content essentially unchanged except for From, Sender and Return-Path headers)?
I'd really love to not have to parse the entire MIME structure and rebuild a Message from scratch in order to resend it, considering I have the already-packaged MIME message already for free.
forwarding multipart messages
Moderators: Chris Corbyn, General Moderators
-
gmorehoudh
- Forum Commoner
- Posts: 50
- Joined: Tue Mar 04, 2008 1:49 pm
-
gmorehoudh
- Forum Commoner
- Posts: 50
- Joined: Tue Mar 04, 2008 1:49 pm
Re: forwarding multipart messages
Okay, I've got it working on a single multipart test e-mail for starters. 
$content_type contains the mime type from the original header, $content_type_attributes is an associative array of the attributes from the original header.
Of course this is still sticking a default charset in, as well as format=flowed, but it's a lot more functional than what I had when I first posted.
Tips appreciated.
Code: Select all
$message =& new Swift_Message($subject, $rawbody, $content_type);
// copy the original content-type attributes over
foreach($content_type_attributes as $attr => $val) {
$message->headers->setAttribute("Content-Type", trim($attr), trim($val));
}
Of course this is still sticking a default charset in, as well as format=flowed, but it's a lot more functional than what I had when I first posted.
Tips appreciated.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: forwarding multipart messages
You can attach a message to forward it. This is how thunderbird does it.
NOTE: $originalMessage is the entire message including all headers (unmodified).
NOTE: $originalMessage is the entire message including all headers (unmodified).
Code: Select all
$message = new Swift_Message('FW: Whatever');
$message->attach(new Swift_Message_Part("Here's a forwarded message"));
$message->attach(new Swift_Message_Attachment($originalMessage, 'Whatever.eml', 'message/rfc822'));
$swift->send($message, .... );-
gmorehoudh
- Forum Commoner
- Posts: 50
- Joined: Tue Mar 04, 2008 1:49 pm
Re: forwarding multipart messages
I should clarify this isn't a 'normal' forward, I'm building a little app that resends e-mails out of an IMAP box to a distribution list, so I don't want them to appear as an attachment. Is what I described above the best way to do it?
Edit: I'm trying some other test messages now and finding that Swift is re-encoding the raw body (for example, one original message was quoted-printable and the resulting message sent out of swift is double-encoded quoted-printable). So I'm digging through the API docs looking for a way to stop/circumvent this.
Edit: I'm trying some other test messages now and finding that Swift is re-encoding the raw body (for example, one original message was quoted-printable and the resulting message sent out of swift is double-encoded quoted-printable). So I'm digging through the API docs looking for a way to stop/circumvent this.