]> git.pld-linux.org Git - packages/eventum.git/blob - eventum-maildecode.patch
- updated to 20050227 snap; added multibyte patch
[packages/eventum.git] / eventum-maildecode.patch
1 --- eventum-1.4/include/class.mime_helper.php~  2005-01-26 00:28:42.000000000 +0200
2 +++ eventum-1.4/include/class.mime_helper.php   2005-01-26 02:24:08.000000000 +0200
3 @@ -180,11 +180,73 @@
4       */
5      function encodeAddress($address)
6      {
7 +        $charset = APP_CHARSET;
8          $address = MIME_Helper::removeQuotes($address);
9 -        $address = MIME_Helper::encode($address);
10 -        return MIME_Helper::quoteSender($address);
11 +        if (Mime_Helper::is8bit($address)) {
12 +            // split into name and address section
13 +            preg_match("/(.*)<(.*)>/", $address, $matches);
14 +           $address = "=?$charset?Q?" . 
15 +                str_replace(' ', '_', trim(preg_replace('/([\x80-\xFF]|[\x21-\x29]|[\xFC]|[\x3F])/e', '"=" . strtoupper(dechex(ord(stripslashes("\1"))))', $matches[1]))) . "?= <" . $matches[2] . ">";
16 +           return $address;
17 +        } else {
18 +            return MIME_Helper::quoteSender($address);
19 +        }
20      }
21 -
22 +    
23 +        
24 +    /**
25 +     * Wraps a Quoted printable encoded address into multiple lines if string is longer then 68 characters.
26 +     * 
27 +     * @param   string $string The address string to wrap.
28 +     * @return  string The address on multiple lines if needed.
29 +     */
30 +    function wrapQP($string)
31 +    {
32 +        $max_length = 68;
33 +        if (strlen($string) >= $max_length) {
34 +            // get charset and content
35 +            preg_match("/=\?(.+)\?Q\?(.+)\?= <(.+)>/", $string, $matches);
36 +            $charset = $matches[1];
37 +            $address = $matches[3];
38 +            
39 +            $length = $max_length - (strlen($charset) + 5);
40 +            
41 +            // try to find a space
42 +            $last_space = strrpos(substr($matches[2], 0, $length), "_");
43 +            if ($last_space != false) {
44 +                $length = $last_space;
45 +            }
46 +            
47 +            $return = "=?$charset?Q?" . substr($matches[2], 0, $length) . "?=\n ";
48 +            $remaining_string = substr($matches[2], $length);
49 +            if (strlen($remaining_string) > 0) {
50 +                $return .= Mime_Helper::wrapQP("=?$charset?Q?" . $remaining_string . "?= <$address>");
51 +            } else {
52 +                $return .= "<$address>";
53 +            }
54 +            return $return;
55 +        } else {
56 +            return $string;
57 +        }
58 +        
59 +    }
60 +    
61 +    
62 +    /**
63 +     * Decodes a quoted printable encoded address and returns the string.
64 +     * 
65 +     * @param   string $address The address to decode
66 +     * @return  string The decoded address
67 +     */
68 +    function decodeAddress($address)
69 +    {
70 +        if (preg_match("/=\?.+\?Q\?(.+)\?= <(.+)>/i", $address, $matches)) {
71 +            return str_replace("_", ' ', quoted_printable_decode($matches[1])) . " <" . $matches[2] . ">";
72 +        } else {
73 +            return $address;
74 +        }
75 +    }
76 +    
77  
78      /**
79       * Determine if a string contains 8-bit characters.
This page took 0.114955 seconds and 3 git commands to generate.