My problem is that when the incoming email is of MIME type the body gets gets repeated twice. I'll post an example and then the offending code.
Say I send an email with this body (the quote symbol is not part of the email):
It will come out the other end to the users as:this does not work.
Now here is the offending code:this does not work.
this does not work.
Code: Select all
$file = 'php://stdin';
$fd = fopen($file, 'r') or die("could not open file");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
$params['include_bodies'] = true;
$params['decode_bodies'] = true;
$params['decode_headers'] = true;
$params['input'] = $email;
$structure = Mail_mimeDecode::decode($params);
...
above is relevant setup
there is some irrelevant stuff here between these two blocks
below is the offending code
...
$message = new Mail_mime();
$message->setTXTBody("");
if(strcmp($structure->ctype_primary, "text") == 0) {
$message->setTXTBody($structure->body);
$body = $message->get();
$headers = $message->headers($extraheaders);
} else {
$paras['content_type'] = 'multipart/mixed';
$email = new Mail_mimePart('', $paras);
foreach ($structure->parts as $part) {
$paras["content_type"] = $part->headers['content-type'];
$paras["encoding"] = $part->headers['content-transfer-encoding'];
$paras["disposition"] = $part->disposition;
if(strcmp($paras["disposition"], "inline")==0)
$paras["disposition"] = "attachment";
$paras["dfilename"] = $part->d_parameters['filename'];
$paras["charset"] = $part->ctype_parameters['charset'];
$email->addSubPart($part->body, $paras);
}
$message = $email->encode();
$body = $message['body'];
$headers = $message['headers'];
}
if(strcmp($structure->ctype_primary, "text") == 0) {
this goes when the email is plain text and emails work properly. The else handles MIME emails and this is where the problem occurs.
I have found that the loop:
foreach ($structure->parts as $part) {
goes through 2 iterations, signifying 2 parts. The first iteration adds the plain text to the body while the second part adds the proper stylized text.
Any input or advice would be appreciated.
Thanks,
Shawn