瀏覽代碼

Changed name of rfc1522Decode to decodeHeader. The function now returns
HTML-entities and the output should not be run through htmlspecialchars.
Added full support for all characters in iso-8859-15 (translated into Unicode
HTML entities according to HTML 4.0).

gustavf 25 年之前
父節點
當前提交
a38cdabfdd
共有 4 個文件被更改,包括 49 次插入18 次删除
  1. 2 2
      functions/mailbox_display.php
  2. 40 9
      functions/mime.php
  3. 5 5
      src/compose.php
  4. 2 2
      src/read_body.php

+ 2 - 2
functions/mailbox_display.php

@@ -53,8 +53,8 @@
          $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
          $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]);
          $messages[$j]["ID"] = $j+1;
-         $messages[$j]["FROM"] = rfc1522Decode($from[$j]);
-         $messages[$j]["SUBJECT"] = rfc1522Decode($subject[$j]);
+         $messages[$j]["FROM"] = decodeHeader($from[$j]);
+         $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
          $messages[$j]["FLAG_DELETED"] = false;
          $messages[$j]["FLAG_ANSWERED"] = false;
          $messages[$j]["FLAG_SEEN"] = false;

+ 40 - 9
functions/mime.php

@@ -201,7 +201,7 @@
 
    // This functions decode strings that is encoded according to 
    // RFC1522 (MIME Part Two: Message Header Extensions for Non-ASCII Text).
-   function rfc1522Decode ($string) {
+   function decodeHeader ($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)\?([^?]+)\?=', 
@@ -213,13 +213,43 @@
             $replace = quoted_printable_decode($replace);
          }
 
-         if ($res[2] != "" && $res[2] == "15") {
-            // Remove all chararacters in iso-8859-15 that is not the same
-            // as in iso-8859-1
-            $replace = strtr($replace, "\244\246\250\255\264\270\274\275".
-                             "\276", "??????????");
-         } else if ($res[2] != "" && $res[2] != "1") {
-            // This gets rid of all characters with over 0x9F for other
+         // All HTML characters are in the 7-bit ASCII range and can
+         // be replaced before doing anything with the 8-bi
+         // characters.
+         $replace = htmlspecialchars($replace);
+
+         if ($res[2] == 1) {
+            // This if clause is debug code. -- gustavf
+            // Latin small letter o with stroke
+            while (ereg("\370", $replace))
+               $replace = ereg_replace ("\370", "ø", $replace);
+         } else if ($res[2] == "15") {
+            // Euro sign
+            while (ereg("\244", $replace))
+               $replace = ereg_replace ("\244", "€", $replace);
+            // Latin capital letter S with caron
+            while (ereg("\246", $replace))
+               $replace = ereg_replace ("\244", "Š", $replace);
+            // Latin small letter s with caron
+            while (ereg("\250", $replace))
+               $replace = ereg_replace ("\250", "š", $replace);
+            // Latin capital letter Z with caron
+            while (ereg("\264", $replace))
+               $replace = ereg_replace ("\264", "Ž", $replace);
+            // Latin small letter z with caron
+            while (ereg("\270", $replace))
+               $replace = ereg_replace ("\270", "ž", $replace);
+            // Latin capital ligature OE
+            while (ereg("\274", $replace))
+               $replace = ereg_replace ("\274", "Œ", $replace);
+            // Latin small ligature oe
+            while (ereg("\275", $replace))
+               $replace = ereg_replace ("\275", "œ", $replace);
+            // Latin capital letter Y with diaeresis
+            while (ereg("\276", $replace))
+               $replace = ereg_replace ("\276", "Ÿ", $replace);
+         } else if ($res[2] != "") {
+            // This gets rid of all characters over 0x9F for other
             // iso-8859 charsets.
             $replace = strtr($replace, "\240\241\242\243\244\245\246\247".
                              "\250\251\252\253\254\255\256\257".
@@ -243,7 +273,8 @@
             ('=\?(us-ascii|iso-8859-([0-9])+)\?(q|b)\?([^?]+)\?=',
              $replace, $string);
 
-         return (rfc1522Decode($string));
+         // In case there should be more encoding in the string: recurse
+         return (decodeHeader($string));
       } else         
          return ($string);
    }

+ 5 - 5
src/compose.php

@@ -27,8 +27,8 @@
       global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
          $reply_id, $send_to, $send_to_cc, $mailbox;
 
-      $send_to = rfc1522Decode($send_to);
-      $send_to_cc = rfc1522Decode($send_to_cc);
+      $send_to = decodeHeader($send_to);
+      $send_to_cc = decodeHeader($send_to_cc);
 
       if ($forward_id) {
          sqimap_mailbox_select($imapConnection, $mailbox);
@@ -138,9 +138,9 @@
          $passed_body, $color, $use_signature, $signature, $editor_size,
          $attachments, $subject, $newmail;
 
-      $subject = rfc1522Decode($subject);
-      $reply_subj = rfc1522Decode($reply_subj);
-      $forward_subj = rfc1522Decode($forward_subj);
+      $subject = decodeHeader($subject);
+      $reply_subj = decodeHeader($reply_subj);
+      $forward_subj = decodeHeader($forward_subj);
 
       echo "\n<FORM action=\"compose.php\" METHOD=POST\n";
       echo "ENCTYPE=\"multipart/form-data\">\n";

+ 2 - 2
src/read_body.php

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