Added function for initializing attachments (for compose)
[squirrelmail.git] / class / mime / Message.class.php
index dfa6ba066f7510b945a24d2daf6a83ce0be50747..fdf01bad4efda14b97ea842e5507557cee4614c2 100644 (file)
@@ -23,6 +23,7 @@ class Message {
         $type0='',
         $type1='',
         $entities = array(),
+       $entity_id = '',
         $parent_ent, $entity,
         $parent = '', $decoded_body='',
         $is_seen = 0, $is_answered = 0, $is_deleted = 0, $is_flagged = 0,
@@ -209,9 +210,7 @@ class Message {
                         case 3:
                             if (isset($msg->type0) && ($msg->type0 == 'multipart')) {
                                 ++$i;
-                                $res= $msg->parseLanguage($read, $i);
-                                $arg_a[] = $res[0];
-                                $i = $res[1];
+                                $arg_a[]= $msg->parseLanguage($read, $i);
                             }
                         case 7:
                             if (($arg_a[0] == 'message') && ($arg_a[1] == 'rfc822')) {
@@ -220,9 +219,7 @@ class Message {
                                 $msg->type0 = $arg_a[0];
                                 $msg->type1 = $arg_a[1];
                                 $rfc822_hdr = new Rfc822Header();
-                                $res = $msg->parseEnvelope($read, $i, $rfc822_hdr);
-                                $msg->rfc822_header = $res[0];
-                                $i = $res[1] + 1;
+                                $msg->rfc822_header = $msg->parseEnvelope($read, $i, $rfc822_hdr);
                                 while (($i < $cnt) && ($read{$i} != '(')) {
                                     ++$i;
                                 }
@@ -371,7 +368,7 @@ class Message {
         return $properties;
     }
 
-    function parseEnvelope($read, $i, $hdr) {
+    function parseEnvelope($read, &$i, $hdr) {
         $arg_no = 0;
         $arg_a = array();
 
@@ -405,9 +402,7 @@ class Message {
                     $a=0;
                     for (; $i < $cnt && $read{$i} != ')'; ++$i) {
                         if ($read{$i} == '(') {
-                            $res = $this->parseAddress($read, $i);
-                            $addr = $res[0];
-                            $i = $res[1];
+                            $addr = $this->parseAddress($read, $i);
                             if (($addr->host == '') && ($addr->mailbox != '')) {
                                 /* start of group */
                                 $group = $addr->mailbox;
@@ -454,7 +449,7 @@ class Message {
             $hdr->inreplyto = $arg_a[8];   /* argument 9: in-reply-to */
             $hdr->message_id = $arg_a[9];  /* argument 10: message-id */
         }
-        return (array($hdr, $i));
+        return $hdr;
     }
 
     function parseLiteral($read, &$i) {
@@ -482,7 +477,7 @@ class Message {
         return $s;
     }
 
-    function parseAddress($read, $i) {
+    function parseAddress($read, &$i) {
         $arg_a = array();
 
         for (; $read{$i} != ')'; ++$i) {
@@ -512,7 +507,7 @@ class Message {
         } else {
             $adr = '';
         }
-        return (array($adr, $i));
+        return $adr;
     }
 
     function parseDisposition($read, &$i) {
@@ -781,6 +776,25 @@ class Message {
 
         return $result;
     }
+    
+    function initAttachment($type, $name, $location) {
+        $attachment = new Message();
+        $mime_header = new MessageHeader();
+        $mime_header->setParameter('name', $name);
+       $pos = strpos($type, '/');
+       if ($pos > 0) {
+           $mime_header->type0 = substr($type, 0, $pos);
+           $mime_header->type1 = substr($type, $pos+1);
+       } else {
+           $mime_header->type0 = $type;
+       }
+       $attachment->att_local_name = $location;
+       $disposition = new Disposition('attachment');
+       $disposition->properties['filename'] = $name;
+       $mime_header->disposition = $disposition;
+       $attachment->mime_header = $mime_header;
+       $this->entities[]=$attachment;
+    }
 }
 
 ?>