Discussion:
[Zend_Mail] Iterating into a RCF822 message part
Nico Edtinger
2007-05-06 21:56:49 UTC
Permalink
Hi Kevin!

Zend_Mail is made and discussed in/by the MFS team. I've changed the
mailing list to fw-formats.

I'm glad you like the RecursiveIterator interface. To you have an
example for a message that doesn't work? It should be able to decode
any multipart MIME message. Maybe there's a problem with the boundary
or there's a bug in Zend_Mime_Decode I didn't catch yet.

nico
I had sent this message to zend-core, but it didn't seem to get
much attention there (the list seems fairly quiet).
Datum: 02. Mai 2007 20:36:56 GMT+02:00
Betreff: [Zend_Mail] Iterating into a RCF822 message part
I'm finding the RecursiveIteratorIterator very hand for looping
through a message, however it won't seem to go into a multipart
rcf822 for me. If I echo out my part, then it will show all parts
of the message, but countParts shows 0 and the iterator won't go
further into it. Is there any elegant way to handle a rcf822
message part in Zend_Mail?
Florian Hoenig
2007-05-07 22:17:44 UTC
Permalink
Hey,

I'd need some help on Zend_Mime please.

Going through the manual of Zend_Mime, it is really unclear how to create
nested mime messages. I want to implement a MM7 protocol and like to use
Zend_Mime. How would you create the following message:


--mms_header
Content-Type: text/xml;
Content-id: <soap-envelope>;
Content-Transfer-Encoding: 7bit

<?xml version='1.0'?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:HEADER>
<mm7:TransactionID
xmlns:mm7="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL
-5-MM7-1-3">
20051104_522468110
</mm7:TransactionID>
</SOAP-ENV:HEADER>
<SOAP-ENV:Body>
<SubmitReq
xmlns="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-M
M7-1-3">
<MM7Version>5.6.0</MM7Version>
<SenderIdentification>
<VASPID>33</VASPID>
<VASID>Username+Passwort</VASID>
<SenderAddress>082822828800</SenderAddress>
</SenderIdentification>
<Recipients><To><Number>436648395060</Number></To></Recipients>
<DeliveryReport>false</DeliveryReport>
<Subject>pr-sms</Subject>
<EarliestDeliveryTime>20060529135300</EarliestDeliveryTime>
<Content href="cid:message1"/>
</SubmitReq>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

--mms_header
Content-Type: multipart/related; boundary="mms_body"; start="mms_smil"
Content-id: <message1>

--mms_body
Content-Type: application/smil; name=mms_smil
Content-id: <mms_smil>

<?xml version='1.0' encoding="UTF-8"?>
<smil>
<head>
<layout>
<root-layout height="160" width="140" />
<region id="Image" height="120" width="160" left="0" top="0"/>
<region id="Text" height="20" width="160" left="0" top="120"/>
</layout>
</head>
<body>
<par dur="15000ms">
<img src="cid:20051104101125_logo_klein.jpg" region="Image" />
<text src="cid:3026243590.txt" region="Text" beginn="1000ms" end="15000ms"/>
</par>
</body>
</smil>

--mms_body
Content-Type: image/jpeg; Name="logo_klein.jpg"
Content-Transfer-Encoding: base64
Content-Id: <20051104101125_logo_klein.jpg>

/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAUAAA/+4ADkFkb2JlAGTAAAAAAf/b
...more cut out here

--mms_body
Content-Type: text/plain; Name="prsms_3026243590.txt";charset=iso-8859-1
Content-Id: <3026243590.txt>

Das ist ein Test!
--mms_body--

--mms_header--



Thanks a lot!

Florian
Nico Edtinger
2007-05-14 12:19:58 UTC
Permalink
Hi Florian!

The easiest way to create a nested mime message is to create a
seperate Zend_Mime_Message for the subparts and add them as part to
the parent:

$sub = new Zend_Mime_Message();
$sub->addPart(new Zend_Mime_Part('part one sub'));
$sub->addPart(new Zend_Mime_Part('part two sub'));
$sub->addPart(new Zend_Mime_Part('part three sub'));

$main = new Zend_Mime_Message();
$main->addPart(new Zend_Mime_Part('part one main'));
$main->addPart(new Zend_Mime_Part($sub->generateMessage()));
var_dump($main->generateMessage());

If you have a mail, $main would be your mail and you'd use Zend_Mail.
Also I've left out changing the attributes of the mime parts.

nico
Post by Florian Hoenig
Hey,
I'd need some help on Zend_Mime please.
Going through the manual of Zend_Mime, it is really unclear how to create
nested mime messages. I want to implement a MM7 protocol and like to use
--mms_header
Content-Type: text/xml;
Content-id: <soap-envelope>;
Content-Transfer-Encoding: 7bit
<?xml version='1.0'?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:HEADER>
<mm7:TransactionID
xmlns:mm7="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/
schema/REL
-5-MM7-1-3">
20051104_522468110
</mm7:TransactionID>
</SOAP-ENV:HEADER>
<SOAP-ENV:Body>
<SubmitReq
xmlns="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/
schema/REL-5-M
M7-1-3">
<MM7Version>5.6.0</MM7Version>
<SenderIdentification>
<VASPID>33</VASPID>
<VASID>Username+Passwort</VASID>
<SenderAddress>082822828800</SenderAddress>
</SenderIdentification>
<Recipients><To><Number>436648395060</Number></To></Recipients>
<DeliveryReport>false</DeliveryReport>
<Subject>pr-sms</Subject>
<EarliestDeliveryTime>20060529135300</EarliestDeliveryTime>
<Content href="cid:message1"/>
</SubmitReq>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
--mms_header
Content-Type: multipart/related; boundary="mms_body"; start="mms_smil"
Content-id: <message1>
--mms_body
Content-Type: application/smil; name=mms_smil
Content-id: <mms_smil>
<?xml version='1.0' encoding="UTF-8"?>
<smil>
<head>
<layout>
<root-layout height="160" width="140" />
<region id="Image" height="120" width="160" left="0" top="0"/>
<region id="Text" height="20" width="160" left="0" top="120"/>
</layout>
</head>
<body>
<par dur="15000ms">
<img src="cid:20051104101125_logo_klein.jpg" region="Image" />
<text src="cid:3026243590.txt" region="Text" beginn="1000ms"
end="15000ms"/>
</par>
</body>
</smil>
--mms_body
Content-Type: image/jpeg; Name="logo_klein.jpg"
Content-Transfer-Encoding: base64
Content-Id: <20051104101125_logo_klein.jpg>
/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAUAAA/
+4ADkFkb2JlAGTAAAAAAf/b
...more cut out here
--mms_body
Content-Type: text/plain;
Name="prsms_3026243590.txt";charset=iso-8859-1
Content-Id: <3026243590.txt>
Das ist ein Test!
--mms_body--
--mms_header--
Thanks a lot!
Florian
Kevin Jordan
2007-08-08 19:39:54 UTC
Permalink
Finally got a chance to work on my e-mail parser again. I can't really post
the e-mail, but it does happen with multiple e-mails. I can however post my
code for parsing through the e-mails.

<?php
$mail = new Zend_Mail_Storage_Imap(array('host' => '<server>',

'user' => '<user>',

'password' => '<password>',

'ssl' => 'SSL'));
$mail->selectFolder($_REQUEST['mailbox']);
$message = $mail->getMessage($_REQUEST['mid']);
if ($message->countParts() == 0) {
if (!isset($message->contentType) || strtok($message->contentType,
';') == 'text/plain') {
$text =
ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
" \"\\0\" \\0 ", $message);
echo nl2br($text);
} else {
echo $message;
}
} else {
$content = '';
$vcard = '';
foreach (new RecursiveIteratorIterator($message) as $part) {
try {
if (strtok($part->contentType, ';') ==
'message/rfc822') {
/*RFC822 messages get stuck here, they aren't
recursed into and I can get the full RFC e-mail by just echoing, but it may
have attachments in there that need to be parsed out*/
} else if (strtok($part->contentType, ';') ==
'text/plain') {
$text =
ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
" \"\\0\" \\0 ",
$part);
$content .= nl2br($text)."<br />";
} elseif (strtok($part->contentType, ';') ==
'text/html') {
$content .= $part."<br />";
} elseif (strtok($part->contentType, ';') ==
'text/x-vcard') {
$parse = new Contact_Vcard_Parse();
$cardinfo = $parse->fromText($part);
// echo
"<pre>".print_r($cardinfo,true)."</pre>";
$vcard .= "<div class='vcard'>";
$vcard .= " /system/i/vcard.png
&nbsp;".$cardinfo[0]['FN'][0]['value'][0][0];
$vcard .= "&nbsp;&lt; mailto:".$cardinfo[0][
".$cardinfo[0]['EMAIL'][0]['value'][0][0]." &gt;";
$vcard .= "<br
/>".$cardinfo[0]['TITLE'][0]['value'][0][0];
for ($i = 0; $i <
count($cardinfo[0]['ORG'][0]['value'][0][0]); $i++) {
$vcard .= "<br
/>".$cardinfo[0]['ORG'][0]['value'][0][0];
}
$vcard .= "</div>";
}else {
}
} catch (Zend_Mail_Exception $e) {
}
}
echo $content."<br />".$vcard;
}
?>
Post by Nico Edtinger
Hi Kevin!
Zend_Mail is made and discussed in/by the MFS team. I've changed the
mailing list to fw-formats.
I'm glad you like the RecursiveIterator interface. To you have an
example for a message that doesn't work? It should be able to decode
any multipart MIME message. Maybe there's a problem with the boundary
or there's a bug in Zend_Mime_Decode I didn't catch yet.
nico
I had sent this message to zend-core, but it didn't seem to get
much attention there (the list seems fairly quiet).
Datum: 02. Mai 2007 20:36:56 GMT+02:00
Betreff: [Zend_Mail] Iterating into a RCF822 message part
I'm finding the RecursiveIteratorIterator very hand for looping
through a message, however it won't seem to go into a multipart
rcf822 for me. If I echo out my part, then it will show all parts
of the message, but countParts shows 0 and the iterator won't go
further into it. Is there any elegant way to handle a rcf822
message part in Zend_Mail?
--
View this message in context: http://www.nabble.com/Re%3A--Zend_Mail--Iterating-into-a-RCF822-message-part-tf3703513s16154.html#a12060448
Sent from the Zend MFS mailing list archive at Nabble.com.
Nico Edtinger
2007-08-26 19:30:39 UTC
Permalink
[example handling a message/rfc822 and other parts]
Ok now I know what the problem is. There are messages parts like:

[...]
--boundary
Content-Type: message/rfc822

From: ...
Date: ...
To: ...

... message ...

--boundary
[...]

I'm still thinking about the best way to handle this. We still want
to be able to get the headers of the message/.. part without mixing
it with the headers of the encapsulated message. But it should also
be easy to get the headers and body of this message.

IMO all message/* (rfc822, news, http, ...) parts should be handled
the same. Thus we could handle it very similar to multipart/*.

What do you (everyone reading this list and/or interested in mail)
think of a new method isMessage(), which returns true if the content
type starts with message/. countParts() would always return 1 and
getPart(1) would return the encapsulated message as instance of
Zend_Mail_Part. Also the RecursiveIterator would return this message.

Any objections? Are there any special message/.. content types that
can't be handled this way?

nico

Loading...