added bugs. (:
[squirrelmail.git] / functions / mime.php
index ecbc6abcf217047c0cfd5e3986afa34e64b77222..ef00957c74b2519bb77c3eeb645d7466fde66b63 100644 (file)
@@ -1,4 +1,4 @@
-<?
+<?php
    /** mime.php
     **
     ** This contains the functions necessary to detect and decode MIME
        bottom, etc.
     **/
    function formatBody($message, $color, $wrap_at) {
-
       /** this if statement checks for the entity to show as the
           primary message. To add more of them, just put them in the
           order that is their priority.
          return ($string);
    }
 
+   // Encode a string according to RFC 1522 for use in headers if it
+   // contains 8-bit characters
+   function encodeHeader ($string) {
+      global $default_charset;
+
+      // Encode only if the string contains 8-bit characters
+      if (ereg("[\200-\377]", $string)) {
+         $newstring = "=?$default_charset?Q?";
+         $newstring .= str_replace(" ", "_", $string);
+         
+         while (ereg("([\200-\377])", $newstring, $regs)) {
+            $replace = $regs[1];
+            $insert = "=" . bin2hex($replace);
+            $newstring = str_replace($replace, $insert, $newstring);
+         }
+
+         $newstring .= "?=";
+
+         return $newstring;
+      }
+
+      return $string;
+   }
+
 ?>