[cvs] [Wiki] changed: MIMEHowTo
Jan Schneider
jan at horde.org
Thu Aug 12 04:03:04 PDT 2004
jan Thu, 12 Aug 2004 04:03:04 -0700
Modified page: http://wiki.horde.org/display.php?page=MIMEHowTo
New Revision: 1.5
@@ -4,61 +4,61 @@
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:
-<php>
+<code type="php">
require_once 'Horde/MIME/Message.php';
$message = &new MIME_Message();
$part = &new MIME_Part('text/plain', $message_text);
$message->addPart($part);
-</php>
+</code>
For text/calendar attachment:
-<php>
+<code type="php">
$part = &new MIME_Part('text/calendar', $text_calendar_data);
$message->addPart($part);
-</php>
+</code>
For Headers:
-<php>
+<code type="php">
require_once 'Horde/MIME/Headers.php';
$headers = &new MIME_Headers();
$headers->addHeader('Header 1', $Header_1_Value);
$headers->addHeader('Header 2', $Header_2_Value);
$headers->addMIMEHeaders($message);
-</php>
+</code>
To return the message as a string:
-<php>
+<code type="php">
$string = $headers->toString() . "\n\n" . $message->toString();
-</php>
+</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>
+<code type="php">
require_once 'Horde/MIME/Structure.php';
$message = &MIME_Structure::parseTextMIMEMessage($message_text);
$part = $message->getPart($mime_id);
-</php>
+</code>
To determine the structure of the MIME message, e.g. to find out the MIME ID we are looking for:
-<php>
+<code type="php">
$map = $message->contentTypeMap();
-</php>
+</code>
$map is an array with key being the MIME IDs and values being the Content Types of that IDs.
++ 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.''
-<php>
+<code type="php">
require HORDE_BASE . '/config/mime_drivers.php';
require_once 'Horde/MIME/Viewer.php';
$viewer = &MIME_Viewer::factory($part);
$html = $viewer->render();
-</php>
+</code>
More information about the cvs
mailing list