[cvs] [Wiki] changed: Doc/Dev/MIMEPackage
Jan Schneider
jan at horde.org
Fri Feb 29 17:33:59 UTC 2008
jan Fri, 29 Feb 2008 12:33:59 -0500
Modified page: http://wiki.horde.org/Doc/Dev/MIMEPackage
New Revision: 3.7
Change log: Add more Horde 3.2 examples for parsing messages
@@ -34,8 +34,9 @@
$string = $headers->toString() . "\n\n" . $message->toString();
</code>
++ Creating and Sending E-Mail with an attachment by using the MIME_Mail
class
+
<code type="php">
require_once 'Horde/MIME/Mail.php';
// New Horde MIME_Mail Object
@@ -84,16 +85,48 @@
<code type="php">
require_once 'Horde/MIME/Structure.php';
$message = MIME_Structure::parseTextMIMEMessage($message_text);
-$part = $message->getPart($mime_id);
</code>
To determine the structure of the MIME message, e.g. to find out the MIME
ID we are looking for:
+
<code type="php">
$map = $message->contentTypeMap();
</code>
-$map is an array with key being the MIME IDs and values being the Content
Types of that IDs.
+
+{{$map}} is an array with key being the MIME IDs and values being the
Content Types of that IDs.
+
+To retrieve a certain MIME part of the message:
+
+<code type="php">
+$part = $message->getPart($mime_id);
+</code>
+
+The following code snippets require at least Horde 3.2.
+
+To retrieve the body text:
+
+<code type="php">
+require_once 'Horde/MIME/Contents.php';
+$contents = new MIME_Contents($message);
+$body_id = $contents->findBody();
+if ($body_id) {
+ $part = &$contents->getMIMEPart($body_id);
+ $body = $part->transferDecode();
+} else {
+ $body = 'Could not render body of message.';
+}
+</code>
+
+To retrieve a list of all attachments:
+
+<code type="php">
+$attachments = $contents->getAttachmentContents();
+foreach ($attachments as $attachment) {
+ echo 'Attachment ' . htmlspecialchars($attachment['name']) . ' is ' .
strlen($attachment['data']) . ' bytes long.';
+}
+</code>
++ Using MIME Viewers
Scenario: Continuing the previous example we want to render the
text/calendar part to HTML. ''This code currently only works inside of a
Horde application because it relies on the registry and Horde's
configuration files.''
More information about the cvs
mailing list