Explorar el Código

Added support for RFC1522 (MIME coding of headers).

gustavf hace 25 años
padre
commit
3a4d89fc67
Se han modificado 4 ficheros con 52 adiciones y 4 borrados
  1. 3 2
      functions/mailbox_display.php
  2. 46 0
      functions/mime.php
  3. 2 2
      src/read_body.php
  4. 1 0
      src/right_main.php

+ 3 - 2
functions/mailbox_display.php

@@ -7,6 +7,7 @@
     **  table row that has sender, date, subject, etc...
     **  table row that has sender, date, subject, etc...
     **
     **
     **/
     **/
+
    function printMessageInfo($imapConnection, $t, $i, $from, $subject, $dateString, $answered, $seen, $mailbox, $sort, $startMessage) {
    function printMessageInfo($imapConnection, $t, $i, $from, $subject, $dateString, $answered, $seen, $mailbox, $sort, $startMessage) {
       require ("../config/config.php");
       require ("../config/config.php");
 
 
@@ -52,8 +53,8 @@
          $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
          $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
          $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
          $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
          $messages[$j]["ID"] = $j+1;
          $messages[$j]["ID"] = $j+1;
-         $messages[$j]["FROM"] = $from[$j];
-         $messages[$j]["SUBJECT"] = $subject[$j];
+         $messages[$j]["FROM"] = rfc1522Decode($from[$j]);
+         $messages[$j]["SUBJECT"] = rfc1522Decode($subject[$j]);
          $messages[$j]["FLAG_DELETED"] = false;
          $messages[$j]["FLAG_DELETED"] = false;
          $messages[$j]["FLAG_ANSWERED"] = false;
          $messages[$j]["FLAG_ANSWERED"] = false;
          $messages[$j]["FLAG_SEEN"] = false;
          $messages[$j]["FLAG_SEEN"] = false;

+ 46 - 0
functions/mime.php

@@ -220,4 +220,50 @@
       }
       }
       return $newbody;
       return $newbody;
    }
    }
+
+
+   // This functions decode strings that is encoded according to 
+   // RFC1522 (MIME Part Two: Message Header Extensions for Non-ASCII Text).
+   function rfc1522Decode ($string) {
+      // Recognizing only US-ASCII and ISO-8859. Other charsets should
+      // probably be recognized as well.
+      if (eregi('=\?(us-ascii|iso-8859-([0-9])+)\?(q|b)\?([^?]+)\?=', 
+                $string, $res)) {
+         if (ucfirst($res[3]) == "B") {
+            $replace = base64_decode($res[4]);
+         } else {
+            $replace = ereg_replace("_", " ", $res[4]);
+            $replace = quoted_printable_decode($replace);
+         }
+
+         // Only US-ASCII and ISO-8859-1 can be displayed without further ado
+         if ($res[2] != "" && $res[2] != "1") {
+            // This get rid of all characters with over 0x9F
+            $replace = strtr($replace, "\240\241\242\243\244\245\246\247".
+                             "\250\251\252\253\254\255\256\257".
+                             "\260\261\262\263\264\265\266\267".
+                             "\270\271\272\273\274\275\276\277".
+                             "\300\301\302\303\304\305\306\307".
+                             "\310\311\312\313\314\315\316\317".
+                             "\320\321\322\323\324\325\326\327".
+                             "\330\331\332\333\334\335\336\337".
+                             "\340\341\342\343\344\345\346\347".
+                             "\350\351\352\353\354\355\356\357".
+                             "\360\361\362\363\364\365\366\367".
+                             "\370\371\372\373\374\375\376\377", 
+                             "????????????????????????????????????????".
+                             "????????????????????????????????????????".
+                             "????????????????????????????????????????".
+                             "????????");
+         }
+
+         $string = eregi_replace
+            ('=\?(us-ascii|iso-8859-([0-9])+)\?(q|b)\?([^?]+)\?=',
+             $replace, $string);
+
+         return (rfc1522Decode($string));
+      } else         
+         return ($string);
+   }
+
 ?>
 ?>

+ 2 - 2
src/read_body.php

@@ -82,8 +82,8 @@
    }
    }
 
 
    /** make sure everything will display in HTML format **/
    /** make sure everything will display in HTML format **/
-   $from_name = htmlspecialchars($message["HEADER"]["FROM"]);
-   $subject = htmlspecialchars(stripslashes($message["HEADER"]["SUBJECT"]));
+   $from_name = htmlspecialchars(rfc1522Decode($message["HEADER"]["FROM"]));
+   $subject = htmlspecialchars(rfc1522Decode(stripslashes($message["HEADER"]["SUBJECT"])));
 
 
    echo "<BR>";
    echo "<BR>";
    echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=98% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
    echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=98% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";

+ 1 - 0
src/right_main.php

@@ -29,6 +29,7 @@
    include("../functions/date.php");
    include("../functions/date.php");
    include("../functions/page_header.php");
    include("../functions/page_header.php");
    include("../functions/array.php");
    include("../functions/array.php");
+   include("../functions/mime.php");
    include("../functions/mailbox_display.php");
    include("../functions/mailbox_display.php");
    include("../functions/display_messages.php");
    include("../functions/display_messages.php");