[cvs] [Wiki] changed: MIMEHowTo
Jan Schneider
jan at horde.org
Thu Jul 1 05:17:30 PDT 2004
jan Thu, 1 Jul 2004 05:17:30 -0700
Modified page: http://wiki.horde.org/display.php?page=MIMEHowTo
New Revision: 1.3
@@ -1,38 +1,53 @@
-> 1. We have a text block (such as text/calendar data) which needs to be added
-> as a MIME part to an email message. We then need to add a couple of
-> additional headers to this message and finally read it back as a string.
++ How to use the MIME API
+
+++ Creating MIME messages
+
+Scenario: We have a text block (such as text/calendar data) which needs to be added as a MIME part to an email message. We then need to add a couple of additional headers to this message and finally read it back as a string.
For Message Body:
-<code>
+<php>
+require_once 'Horde/MIME/Message.php';
$message = &new MIME_Message();
-$part = $new MIME_Part('text/calendar', $text_calendar_data);
+$part = &new MIME_Part('text/plain', $message_text);
$message->addPart($part);
-</code>
+</php>
+
+For text/calendar attachment:
+<php>
+$part = &new MIME_Part('text/calendar', $text_calendar_data);
+$message->addPart($part);
+</php>
For Headers:
-<code>
+<php>
+require_once 'Horde/MIME/Headers.php';
$headers = &new MIME_Headers();
-$headers->addHeaders('Header 1', $Header_1_Value);
-$headers->addHeaders('Header 2', $Header_2_Value);
+$headers->addHeader('Header 1', $Header_1_Value);
+$headers->addHeader('Header 2', $Header_2_Value);
$headers->addMIMEHeaders($message);
-</code>
+</php>
To return the message as a string:
-<code>
-$string = $headers->toString() . "\n\n" . $part->toString();
-</code>
+<php>
+$string = $headers->toString() . "\n\n" . $message->toString();
+</php>
-> 2. We have an existing text string which contains a valid MIME email message.
-> We need to parse this string in order to read back the body of a specific
-> MIME part with a certain content type.
-<code>
+++ Parsing a MIME message
+
+Scenario: We have an existing text string which contains a valid MIME email message. We need to parse this string in order to read back the body of a specific MIME part with a certain content type.
+
+<php>
+require_once 'Horde/MIME/Structure.php';
$message = &MIME_Structure::parseTextMIMEMessage($message_text);
$message->getPart($mime_id);
-</code>
- -OR-
-<code>
+</php>
+
+To determine the structure of the MIME message, e.g. to find out the MIME ID we are looking for:
+
+<php>
$map = $message->contentTypeMap();
-</code>
- Map is an array with KEY = MIME ID and VALUE = Content type of that ID
+</php>
+
+$map is an array with key being the MIME IDs and values being the Content Types of that IDs.
More information about the cvs
mailing list