Bläddra i källkod

added parameters id and mailbox to formadBody / magicHTML for better/ easier
handle message/rfc822 attachments

stekkel 23 år sedan
förälder
incheckning
891b3dd79d
1 ändrade filer med 16 tillägg och 20 borttagningar
  1. 16 20
      functions/mime.php

+ 16 - 20
functions/mime.php

@@ -408,7 +408,7 @@ be displayed as the actual message in the HTML. It contains
 everything needed, including HTML Tags, Attachments at the
 everything needed, including HTML Tags, Attachments at the
 bottom, etc.
 bottom, etc.
 */
 */
-function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num) {
+function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num, $id, $mailbox='INBOX') {
     // this if statement checks for the entity to show as the
     // this if statement checks for the entity to show as the
     // primary message. To add more of them, just put them in the
     // primary message. To add more of them, just put them in the
     // order that is their priority.
     // order that is their priority.
@@ -417,10 +417,8 @@ function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num) {
 
 
     $has_unsafe_images = 0;
     $has_unsafe_images = 0;
 
 
-    $id = $message->id;
-
     if ($message->type0 == 'message' && $message->type1 == 'rfc822') {
     if ($message->type0 == 'message' && $message->type1 == 'rfc822') {
-       $message = $message->entities[0];
+        $message = $message->entities[0];
     }
     }
     $urlmailbox = urlencode($message->mailbox);
     $urlmailbox = urlencode($message->mailbox);
     $body_message = getEntity($message, $ent_num);
     $body_message = getEntity($message, $ent_num);
@@ -438,7 +436,7 @@ function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num) {
                 $body = strip_tags( $body );
                 $body = strip_tags( $body );
                 translateText($body, $wrap_at, $body_message->header->charset);
                 translateText($body, $wrap_at, $body_message->header->charset);
             } else {
             } else {
-                $body = magicHTML( $body, $id, $message );
+                $body = magicHTML( $body, $id, $message, $mailbox );
             }
             }
         } else {
         } else {
             translateText($body, $wrap_at, $body_message->header->charset);
             translateText($body, $wrap_at, $body_message->header->charset);
@@ -453,19 +451,13 @@ function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num) {
         }
         }
 
 
         /** Display the ATTACHMENTS: message if there's more than one part **/
         /** Display the ATTACHMENTS: message if there's more than one part **/
-	if ($message->type0 == 'message') {
-	    $id = $message->id;
-	    $mailbox = $message->mailbox;
-//	    $message->header->setVar('message_id',$id);
-//	    $message->header->setVar('mailbox',$mailbox);
-	}
         if (isset($message->entities[1])) {
         if (isset($message->entities[1])) {
 	    /* Header-type alternative means we choose the best one to display 
 	    /* Header-type alternative means we choose the best one to display 
 	       so don't show the alternatives as attachment. Header-type related
 	       so don't show the alternatives as attachment. Header-type related
 	       means that the attachments are already part of the related message.
 	       means that the attachments are already part of the related message.
 	    */   
 	    */   
 	    if ($message->header->type1 !='related' && $message->header->type1 !='alternative') {
 	    if ($message->header->type1 !='related' && $message->header->type1 !='alternative') {
-        	$body .= formatAttachments ($message, $ent_num, $message->mailbox, $id);
+        	$body .= formatAttachments ($message, $ent_num, $mailbox, $id);
 	    }
 	    }
         }
         }
     } else {
     } else {
@@ -1239,7 +1231,8 @@ function sq_fixatts($tagname,
                     $bad_attvals,
                     $bad_attvals,
                     $add_attr_to_tag,
                     $add_attr_to_tag,
                     $message,
                     $message,
-                    $id
+                    $id,
+		    $mailbox
                     ){
                     ){
     $me = "sq_fixatts";
     $me = "sq_fixatts";
     while (list($attname, $attvalue) = each($attary)){
     while (list($attname, $attvalue) = each($attary)){
@@ -1290,7 +1283,7 @@ function sq_fixatts($tagname,
          * Turn cid: urls into http-friendly ones.
          * Turn cid: urls into http-friendly ones.
          */
          */
         if (preg_match("/^[\'\"]\s*cid:/si", $attvalue)){
         if (preg_match("/^[\'\"]\s*cid:/si", $attvalue)){
-            $attary{$attname} = sq_cid2http($message, $id, $attvalue);
+            $attary{$attname} = sq_cid2http($message, $id, $attvalue, $mailbox);
         }
         }
     }
     }
     /**
     /**
@@ -1370,7 +1363,7 @@ function sq_fixstyle($message, $id, $content){
  * @param  $cidurl   the cid: url.
  * @param  $cidurl   the cid: url.
  * @return           a string with a http-friendly url
  * @return           a string with a http-friendly url
  */
  */
-function sq_cid2http($message, $id, $cidurl){
+function sq_cid2http($message, $id, $cidurl, $mailbox){
     /**
     /**
      * Get rid of quotes.
      * Get rid of quotes.
      */
      */
@@ -1378,7 +1371,7 @@ function sq_cid2http($message, $id, $cidurl){
     $cidurl = str_replace($quotchar, "", $cidurl);
     $cidurl = str_replace($quotchar, "", $cidurl);
     $cidurl = substr(trim($cidurl), 4);
     $cidurl = substr(trim($cidurl), 4);
     $httpurl = $quotchar . "../src/download.php?absolute_dl=true&" .
     $httpurl = $quotchar . "../src/download.php?absolute_dl=true&" .
-        "passed_id=$id&mailbox=" . urlencode($message->mailbox) .
+        "passed_id=$id&mailbox=" . urlencode($mailbox) .
         "&passed_ent_id=" . find_ent_id($cidurl, $message) . $quotchar;
         "&passed_ent_id=" . find_ent_id($cidurl, $message) . $quotchar;
     return $httpurl;
     return $httpurl;
 }
 }
@@ -1447,7 +1440,8 @@ function sq_sanitize($body,
                      $bad_attvals,
                      $bad_attvals,
                      $add_attr_to_tag,
                      $add_attr_to_tag,
                      $message,
                      $message,
-                     $id
+                     $id,
+		     $mailbox
                      ){
                      ){
     $me = "sq_sanitize";
     $me = "sq_sanitize";
     /**
     /**
@@ -1556,7 +1550,8 @@ function sq_sanitize($body,
                                                      $bad_attvals,
                                                      $bad_attvals,
                                                      $add_attr_to_tag,
                                                      $add_attr_to_tag,
                                                      $message,
                                                      $message,
-                                                     $id
+                                                     $id,
+						     $mailbox
                                                      );
                                                      );
                             }
                             }
                             /**
                             /**
@@ -1599,7 +1594,7 @@ function sq_sanitize($body,
  * @param  $id    the id of the message
  * @param  $id    the id of the message
  * @return        a string with html safe to display in the browser.
  * @return        a string with html safe to display in the browser.
  */
  */
-function magicHTML($body, $id, $message){
+function magicHTML($body, $id, $message, $mailbox = 'INBOX'){
     global $attachment_common_show_images, $view_unsafe_images,
     global $attachment_common_show_images, $view_unsafe_images,
         $has_unsafe_images;
         $has_unsafe_images;
     /**
     /**
@@ -1725,7 +1720,8 @@ function magicHTML($body, $id, $message){
                            $bad_attvals,
                            $bad_attvals,
                            $add_attr_to_tag,
                            $add_attr_to_tag,
                            $message,
                            $message,
-                           $id
+                           $id,
+			   $mailbox
                            );
                            );
     if (preg_match("|$secremoveimg|si", $trusted)){
     if (preg_match("|$secremoveimg|si", $trusted)){
         $has_unsafe_images = true;
         $has_unsafe_images = true;