[cvs] [Wiki] changed: Doc/Dev/MIMEPackage

Chuck Hagenbuch chuck at horde.org
Sat Oct 20 03:35:22 UTC 2007


chuck  Fri, 19 Oct 2007 20:35:22 -0700

Modified page: http://wiki.horde.org/Doc/Dev/MIMEPackage
New Revision:  3.3
Change log:  clean up MIME_Mail example, remove & that shouldn't be needed

@@ -8,23 +8,23 @@

 For Message Body:
 <code type="php">
 require_once 'Horde/MIME/Message.php';
-$message = &new MIME_Message();
-$part = $new MIME_Part('text/plain', $message_text);
+$message = new MIME_Message();
+$part = new MIME_Part('text/plain', $message_text);
 $message->addPart($part);
 </code>

 For text/calendar attachment:
 <code type="php">
-$part = &new MIME_Part('text/calendar', $text_calendar_data);
+$part = new MIME_Part('text/calendar', $text_calendar_data);
 $message->addPart($part);
 </code>

 For Headers:
 <code type="php">
 require_once 'Horde/MIME/Headers.php';
-$headers = &new MIME_Headers();
+$headers = new MIME_Headers();
 $headers->addHeader('Header 1', $Header_1_Value);
 $headers->addHeader('Header 2', $Header_2_Value);
 $headers->addMIMEHeaders($message);
 </code>
@@ -35,49 +35,30 @@
 </code>

 ++ Creating and Sending E-Mail with an attachment by using MIME Mail
 <code type="php">
-// Why this? I don't know! perhaps because using the HORDE BASE libs and
there by get the mail_driver
- at define('AUTH_HANDLER', true);
-
-// Please find your horde base directory, absolute or relative its all up
to you.
- at define('HORDE_BASE', '/var/www/localhost/htdocs/horde/');
-
-require_once HORDE_BASE . '/lib/base.php';
-require_once HORDE_BASE . '/lib/version.php';
-
-// This are the main library for this example
-require_once 'Horde/MIME.php';
 require_once 'Horde/MIME/Mail.php';

-// Various variables for our mail
-$email_to = 'a.guy.called.gerald at localhost';
-$email_from = 'nobody at localhost';
-$subject = 'Simple horde MIME Mail test';
-$file_attachment = '/tmp/some_file.zip';
-$body = "If you can read this and got the attached file, you are on good
track with horde MIME library.";
-
-// New MIME_Mail Object
-$Mail = &new MIME_Mail();
+// New Horde MIME_Mail Object
+$mail = new MIME_Mail();

 // Set the header date
-$Mail->addHeader('Date', date('r'));
+$mail->addHeader('Date', date('r'));

 // Set the from address
-$Mail->addHeader('From', $email_from);
+$mail->addHeader('From', 'sender at example.com');

 // Set the subject of the mail
-$Mail->addHeader('Subject', $subject);
+$mail->addHeader('Subject', 'Horde MIME_Mail example');

 // Set the text message body
-$Mail->setBody($body);
+$mail->setBody('Example MIME message with an attachment');

-// Add the file as an attachment, set the file name and what kind of mime
it is,
-// Haven't tried this yet, but i assume that the two last parameters can be
left out for automatic detection
-$Mail->addAttachment($file_attachment, 'some_file.zip',
'application/x-zip-compressed');
+// Add the file as an attachment, set the file name and what kind of file
it is.
+$mail->addAttachment('/tmp/some_file.zip', 'some_file.zip',
'application/x-zip-compressed');

-// Add a recipients
-$Mail->addRecipients($email_to);
+// Add recipients
+$mail->addRecipients('recipient at example.com');

 // Get the mail driver
 $mail_driver = $conf['mailer']['type'];
 $mail_params = $conf['mailer']['params'];
@@ -89,9 +70,9 @@
     }
 }

 // Send the mail
-if (!is_a($sent = $Mail->send($mail_driver, $mail_params), 'PEAR_Error')) {
+if (!is_a($sent = $mail->send($mail_driver, $mail_params), 'PEAR_Error')) {
     print "E-Mail sent\n";
 } else {
     print "E-Mail not sent\n";
 }
@@ -102,9 +83,9 @@
 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.

 <code type="php">
 require_once 'Horde/MIME/Structure.php';
-$message = &MIME_Structure::parseTextMIMEMessage($message_text);
+$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:
@@ -119,9 +100,9 @@

 <code type="php">
 require HORDE_BASE . '/config/mime_drivers.php';
 require_once 'Horde/MIME/Viewer.php';
-$viewer = &MIME_Viewer::factory($part);
+$viewer = MIME_Viewer::factory($part);
 $html = $viewer->render();
 </code>

 ++ Reading message headers
@@ -135,16 +116,16 @@

 /* Custom MIME_Headers class because we need to implement _getStream(). */
 class MyHeaders extends MIME_Headers {

-    function &_getStream()
+    function _getStream()
     {
         return imap_open('{localhost/imap}INBOX', 'username', 'password');
     }
 }

 /* Get message subject. */
-$headers = &new MyHeaders($message_uid);
+$headers = new MyHeaders($message_uid);
 $headers->buildHeaders();
 $subject = $headers->getValue('Subject');
 </code>

@@ -209,9 +190,9 @@

 /* Custom MIME_Headers class. */
 class MyHeaders extends MIME_Headers {

-    function &_getStream()
+    function _getStream()
     {
         return $GLOBALS['imap'];
     }
 }
@@ -239,9 +220,9 @@

     /* Parse message structure. */
     $body = imap_fetchheader($imap, $uid, FT_UID) .
             imap_body($imap, $uid, FT_UID);
-    $message = &MIME_Structure::parseTextMIMEMessage($body);
+    $message = MIME_Structure::parseTextMIMEMessage($body);
     $map = $message->contentTypeMap();

     /* Search for message with possible CSV attachment. */
     foreach ($map as $mime_id => $mime_type) {
@@ -257,9 +238,9 @@
         /* CSV file found. */
         $content = $mime_part->transferDecode();

         /* Get message subject. */
-        $headers = &new MyHeaders($uid);
+        $headers = new MyHeaders($uid);
         $headers->buildHeaders();
         $subject = $headers->getValue('Subject');
         if (empty($subject)) {
             $subject = $filename;


More information about the cvs mailing list