Changeset ab6f807 in github
- Timestamp:
- Mar 21, 2007 5:54:10 AM (6 years ago)
- Branches:
- master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
- Children:
- 3cf6649
- Parents:
- ab71a53
- Location:
- program
- Files:
-
- 1 added
- 5 edited
-
lib/Mail/mime.php (modified) (15 diffs)
-
lib/Mail/mimeDecode.php (modified) (8 diffs)
-
lib/Mail/mimePart.php (modified) (9 diffs)
-
lib/html2text.inc (modified) (2 diffs)
-
lib/rc_mail_mime.inc (added)
-
steps/mail/sendmail.inc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
program/lib/Mail/mime.php
r5a6ad20 rab6f807 1 1 <?php 2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 3 // +-----------------------------------------------------------------------+ 4 // | Copyright (c) 2002-2003 Richard Heyes | 5 // | Copyright (c) 2003-2005 The PHP Group | 6 // | All rights reserved. | 7 // | | 8 // | Redistribution and use in source and binary forms, with or without | 9 // | modification, are permitted provided that the following conditions | 10 // | are met: | 11 // | | 12 // | o Redistributions of source code must retain the above copyright | 13 // | notice, this list of conditions and the following disclaimer. | 14 // | o Redistributions in binary form must reproduce the above copyright | 15 // | notice, this list of conditions and the following disclaimer in the | 16 // | documentation and/or other materials provided with the distribution.| 17 // | o The names of the authors may not be used to endorse or promote | 18 // | products derived from this software without specific prior written | 19 // | permission. | 20 // | | 21 // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 22 // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 23 // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 24 // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 25 // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 26 // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 27 // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 28 // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 29 // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 30 // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 31 // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 32 // | | 33 // +-----------------------------------------------------------------------+ 34 // | Author: Richard Heyes <richard@phpguru.org> | 35 // | Tomas V.V.Cox <cox@idecnet.com> (port to PEAR) | 36 // +-----------------------------------------------------------------------+ 37 // 38 // $Id$ 39 2 /** 3 * The Mail_Mime class is used to create MIME E-mail messages 4 * 5 * The Mail_Mime class provides an OO interface to create MIME 6 * enabled email messages. This way you can create emails that 7 * contain plain-text bodies, HTML bodies, attachments, inline 8 * images and specific headers. 9 * 10 * Compatible with PHP versions 4 and 5 11 * 12 * LICENSE: This LICENSE is in the BSD license style. 13 * Copyright (c) 2002-2003, Richard Heyes <richard@phpguru.org> 14 * Copyright (c) 2003-2006, PEAR <pear-group@php.net> 15 * All rights reserved. 16 * 17 * Redistribution and use in source and binary forms, with or 18 * without modification, are permitted provided that the following 19 * conditions are met: 20 * 21 * - Redistributions of source code must retain the above copyright 22 * notice, this list of conditions and the following disclaimer. 23 * - Redistributions in binary form must reproduce the above copyright 24 * notice, this list of conditions and the following disclaimer in the 25 * documentation and/or other materials provided with the distribution. 26 * - Neither the name of the authors, nor the names of its contributors 27 * may be used to endorse or promote products derived from this 28 * software without specific prior written permission. 29 * 30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 31 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 33 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 34 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 36 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 38 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 40 * THE POSSIBILITY OF SUCH DAMAGE. 41 * 42 * @category Mail 43 * @package Mail_Mime 44 * @author Richard Heyes <richard@phpguru.org> 45 * @author Tomas V.V. Cox <cox@idecnet.com> 46 * @author Cipriano Groenendal <cipri@php.net> 47 * @author Sean Coates <sean@php.net> 48 * @copyright 2003-2006 PEAR <pear-group@php.net> 49 * @license http://www.opensource.org/licenses/bsd-license.php BSD License 50 * @version CVS: $Id$ 51 * @link http://pear.php.net/package/Mail_mime 52 * @notes This class is based on HTML Mime Mail class from 53 * Richard Heyes <richard@phpguru.org> which was based also 54 * in the mime_mail.class by Tobias Ratschiller <tobias@dnet.it> 55 * and Sascha Schumann <sascha@schumann.cx> 56 */ 57 58 59 /** 60 * require PEAR 61 * 62 * This package depends on PEAR to raise errors. 63 */ 40 64 require_once('PEAR.php'); 65 66 /** 67 * require Mail_mimePart 68 * 69 * Mail_mimePart contains the code required to 70 * create all the different parts a mail can 71 * consist of. 72 */ 41 73 require_once('Mail/mimePart.php'); 42 74 75 43 76 /** 44 * Mime mail composer class. Can handle: text and html bodies, embedded html45 * images and attachments.46 * Documentation and examples of this class are avaible here:47 * http://pear.php.net/manual/77 * The Mail_Mime class provides an OO interface to create MIME 78 * enabled email messages. This way you can create emails that 79 * contain plain-text bodies, HTML bodies, attachments, inline 80 * images and specific headers. 48 81 * 49 * @notes This class is based on HTML Mime Mail class from 50 * Richard Heyes <richard@phpguru.org> which was based also 51 * in the mime_mail.class by Tobias Ratschiller <tobias@dnet.it> and 52 * Sascha Schumann <sascha@schumann.cx> 53 * 54 * @author Richard Heyes <richard.heyes@heyes-computing.net> 55 * @author Tomas V.V.Cox <cox@idecnet.com> 56 * @package Mail 57 * @access public 82 * @category Mail 83 * @package Mail_Mime 84 * @author Richard Heyes <richard@phpguru.org> 85 * @author Tomas V.V. Cox <cox@idecnet.com> 86 * @author Cipriano Groenendal <cipri@php.net> 87 * @author Sean Coates <sean@php.net> 88 * @copyright 2003-2006 PEAR <pear-group@php.net> 89 * @license http://www.opensource.org/licenses/bsd-license.php BSD License 90 * @version Release: @package_version@ 91 * @link http://pear.php.net/package/Mail_mime 58 92 */ 59 93 class Mail_mime … … 61 95 /** 62 96 * Contains the plain text part of the email 97 * 63 98 * @var string 99 * @access private 64 100 */ 65 101 var $_txtbody; 102 66 103 /** 67 104 * Contains the html part of the email 105 * 68 106 * @var string 107 * @access private 69 108 */ 70 109 var $_htmlbody; 110 71 111 /** 72 112 * contains the mime encoded text 113 * 73 114 * @var string 115 * @access private 74 116 */ 75 117 var $_mime; 118 76 119 /** 77 120 * contains the multipart content 121 * 78 122 * @var string 123 * @access private 79 124 */ 80 125 var $_multipart; 126 81 127 /** 82 128 * list of the attached images 129 * 83 130 * @var array 131 * @access private 84 132 */ 85 133 var $_html_images = array(); 134 86 135 /** 87 136 * list of the attachements 137 * 88 138 * @var array 139 * @access private 89 140 */ 90 141 var $_parts = array(); 142 91 143 /** 92 144 * Build parameters 145 * 93 146 * @var array 147 * @access private 94 148 */ 95 149 var $_build_params = array(); 150 96 151 /** 97 152 * Headers for the mail 153 * 98 154 * @var array 155 * @access private 99 156 */ 100 157 var $_headers = array(); 158 101 159 /** 102 160 * End Of Line sequence (for serialize) 161 * 103 162 * @var string 163 * @access private 104 164 */ 105 165 var $_eol; … … 107 167 108 168 /** 109 * Constructor function 169 * Constructor function. 170 * 171 * @param string $crlf what type of linebreak to use. 172 * Defaults to "\r\n" 173 * @return void 110 174 * 111 175 * @access public … … 126 190 127 191 /** 128 * Wakeup (unserialize) - re-setsEOL constant192 * wakeup function called by unserialize. It re-sets the EOL constant 129 193 * 130 194 * @access private … … 134 198 $this->_setEOL($this->_eol); 135 199 } 200 136 201 137 202 /** … … 142 207 * 143 208 * @param string $data Either a string or 144 * the file name with the contents209 * the file name with the contents 145 210 * @param bool $isfile If true the first param should be treated 146 * as a file name, else as a string (default)211 * as a file name, else as a string (default) 147 212 * @param bool $append If true the text or file is appended to 148 * the existing body, else the old body is149 * overwritten213 * the existing body, else the old body is 214 * overwritten 150 215 * @return mixed true on success or PEAR_Error object 151 216 * @access public … … 174 239 175 240 /** 176 * Adds a html part to the mail 177 * 178 * @param string $data Either a string or the file name with the179 * contents180 * @param bool $isfile If true the first param should be treated181 * as a file name, else as a string (default)182 * @return mixed true on success or PEAR_Error object241 * Adds a html part to the mail. 242 * 243 * @param string $data either a string or the file name with the 244 * contents 245 * @param bool $isfile a flag that determines whether $data is a 246 * filename, or a string(false, default) 247 * @return bool true on success 183 248 * @access public 184 249 */ … … 199 264 200 265 /** 201 * returns the HTML body portion of the message202 * @return string HTML body of the message203 * @access public204 */205 function getHTMLBody()206 {207 return $this->_htmlbody;208 }209 210 /**211 266 * Adds an image to the list of embedded images. 212 267 * 213 * @param string $file The image file name OR image data itself 214 * @param string $c_type The content type 215 * @param string $name The filename of the image. 216 * Only use if $file is the image data 217 * @param bool $isfilename Whether $file is a filename or not 218 * Defaults to true 219 * @param string $contentid Desired Content-ID of MIME part 220 * Defaults to generated unique ID 221 * @return mixed true on success or PEAR_Error object 268 * @param string $file the image file name OR image data itself 269 * @param string $c_type the content type 270 * @param string $name the filename of the image. 271 * Only use if $file is the image data. 272 * @param bool $isfile whether $file is a filename or not. 273 * Defaults to true 274 * @return bool true on success 222 275 * @access public 223 276 */ 224 277 function addHTMLImage($file, $c_type='application/octet-stream', 225 $name = '', $isfile name = true, $contentid = '')226 { 227 $filedata = ($isfile name=== true) ? $this->_file2str($file)278 $name = '', $isfile = true) 279 { 280 $filedata = ($isfile === true) ? $this->_file2str($file) 228 281 : $file; 229 if ($isfile name=== true) {282 if ($isfile === true) { 230 283 $filename = ($name == '' ? $file : $name); 231 284 } else { … … 234 287 if (PEAR::isError($filedata)) { 235 288 return $filedata; 236 }237 if ($contentid == '') {238 $contentid = md5(uniqid(time()));239 289 } 240 290 $this->_html_images[] = array( … … 242 292 'name' => $filename, 243 293 'c_type' => $c_type, 244 'cid' => $contentid294 'cid' => md5(uniqid(time())) 245 295 ); 246 296 return true; … … 255 305 * @param string $name The filename of the attachment 256 306 * Only use if $file is the contents 257 * @param bool $is FilenameWhether $file is a filename or not307 * @param bool $isfile Whether $file is a filename or not 258 308 * Defaults to true 259 309 * @param string $encoding The type of encoding to use. … … 270 320 */ 271 321 function addAttachment($file, $c_type = 'application/octet-stream', 272 $name = '', $isfile name= true,322 $name = '', $isfile = true, 273 323 $encoding = 'base64', 274 324 $disposition = 'attachment', $charset = '') 275 325 { 276 $filedata = ($isfile name=== true) ? $this->_file2str($file)326 $filedata = ($isfile === true) ? $this->_file2str($file) 277 327 : $file; 278 if ($isfile name=== true) {328 if ($isfile === true) { 279 329 // Force the name the user supplied, otherwise use $file 280 330 $filename = (!empty($name)) ? $name : $file; … … 478 528 if ($value['disposition'] != "inline") { 479 529 $fname = array("fname" => $value['name']); 480 $fname_enc = $this->_encodeHeaders($fname );530 $fname_enc = $this->_encodeHeaders($fname, array('head_charset' => $value['charset'] ? $value['charset'] : 'iso-8859-1')); 481 531 $params['dfilename'] = $fname_enc['fname']; 482 532 } … … 797 847 * Encodes a header as per RFC2047 798 848 * 799 * @param array $input The header data to encode 849 * @param array $input The header data to encode 850 * @param array $params Extra build parameters 800 851 * @return array Encoded data 801 852 * @access private 802 853 */ 803 function _encodeHeaders($input) 804 { 805 $maxlen = 73; 854 function _encodeHeaders($input, $params = array()) 855 { 856 857 $build_params = $this->_build_params; 858 while (list($key, $value) = each($params)) { 859 $build_params[$key] = $value; 860 } 861 806 862 foreach ($input as $hdr_name => $hdr_value) { 807 // if header contains e-mail addresses808 if (preg_match('/\s<.+@[a-z0-9\-\.]+\.[a-z]+>/U', $hdr_value))809 $chunks = $this->_explode_quoted_string(',', $hdr_value);810 else811 $chunks = array($hdr_value);812 813 $hdr_value = '';814 $line_len = 0;815 816 foreach ($chunks as $i => $value){817 $value = trim($value);818 819 //This header contains non ASCII chars and should be encoded.820 if ( preg_match('#[\x80-\xFF]{1}#', $value)){821 $ suffix = '';822 // Don't encode e-mail address823 if (preg_match('/(.+)\s(<.+@[a-z0-9\-\.]+>)$/Ui', $value, $matches)) {824 $value = $matches[1];825 $ suffix = ' '.$matches[2];863 $hdr_vals = preg_split("|(\s)|", $hdr_value, -1, PREG_SPLIT_DELIM_CAPTURE); 864 $hdr_value_out=""; 865 $previous = ""; 866 foreach ($hdr_vals as $hdr_val){ 867 if (!trim($hdr_val)){ 868 //whitespace needs to be handled with another string, or it 869 //won't show between encoded strings. Prepend this to the next item. 870 $previous .= $hdr_val; 871 continue; 872 }else{ 873 $hdr_val = $previous . $hdr_val; 874 $previous = ""; 875 } 876 if (function_exists('iconv_mime_encode') && preg_match('#[\x80-\xFF]{1}#', $hdr_val)){ 877 $imePref = array(); 878 if ($build_params['head_encoding'] == 'base64'){ 879 $imePrefs['scheme'] = 'B'; 880 }else{ 881 $imePrefs['scheme'] = 'Q'; 826 882 } 827 828 switch ($this->_build_params['head_encoding']) { 883 $imePrefs['input-charset'] = $build_params['head_charset']; 884 $imePrefs['output-charset'] = $build_params['head_charset']; 885 $hdr_val = iconv_mime_encode($hdr_name, $hdr_val, $imePrefs); 886 $hdr_val = preg_replace("#^{$hdr_name}\:\ #", "", $hdr_val); 887 }elseif (preg_match('#[\x80-\xFF]{1}#', $hdr_val)){ 888 //This header contains non ASCII chars and should be encoded. 889 switch ($build_params['head_encoding']) { 829 890 case 'base64': 830 // Base64 encoding has been selected. 831 $mode = 'B'; 832 $encoded = base64_encode($value); 891 //Base64 encoding has been selected. 892 893 //Generate the header using the specified params and dynamicly 894 //determine the maximum length of such strings. 895 //75 is the value specified in the RFC. The first -2 is there so 896 //the later regexp doesn't break any of the translated chars. 897 //The -2 on the first line-regexp is to compensate for the ": " 898 //between the header-name and the header value 899 $prefix = '=?' . $build_params['head_charset'] . '?B?'; 900 $suffix = '?='; 901 $maxLength = 75 - strlen($prefix . $suffix) - 2; 902 $maxLength1stLine = $maxLength - strlen($hdr_name) - 2; 903 904 //Base64 encode the entire string 905 $hdr_val = base64_encode($hdr_val); 906 907 //This regexp will break base64-encoded text at every 908 //$maxLength but will not break any encoded letters. 909 $reg1st = "|.{0,$maxLength1stLine}[^\=][^\=]|"; 910 $reg2nd = "|.{0,$maxLength}[^\=][^\=]|"; 833 911 break; 834 835 912 case 'quoted-printable': 836 913 default: 837 // quoted-printable encoding has been selected 838 $mode = 'Q'; 839 $encoded = preg_replace('/([\x2C\x3F\x80-\xFF])/e', "'='.sprintf('%02X', ord('\\1'))", $value); 840 // replace spaces with _ 841 $encoded = str_replace(' ', '_', $encoded); 914 //quoted-printable encoding has been selected 915 916 //Generate the header using the specified params and dynamicly 917 //determine the maximum length of such strings. 918 //75 is the value specified in the RFC. The -2 is there so 919 //the later regexp doesn't break any of the translated chars. 920 //The -2 on the first line-regexp is to compensate for the ": " 921 //between the header-name and the header value 922 $prefix = '=?' . $build_params['head_charset'] . '?Q?'; 923 $suffix = '?='; 924 $maxLength = 75 - strlen($prefix . $suffix) - 2; 925 $maxLength1stLine = $maxLength - strlen($hdr_name) - 2; 926 927 //Replace all special characters used by the encoder. 928 $search = array("=", "_", "?", " "); 929 $replace = array("=3D", "=5F", "=3F", "_"); 930 $hdr_val = str_replace($search, $replace, $hdr_val); 931 932 //Replace all extended characters (\x80-xFF) with their 933 //ASCII values. 934 $hdr_val = preg_replace( 935 '#([\x80-\xFF])#e', 936 '"=" . strtoupper(dechex(ord("\1")))', 937 $hdr_val 938 ); 939 //This regexp will break QP-encoded text at every $maxLength 940 //but will not break any encoded letters. 941 $reg1st = "|(.{0,$maxLength1stLine})[^\=]|"; 942 $reg2nd = "|(.{0,$maxLength})[^\=]|"; 943 break; 842 944 } 843 844 $value = '=?' . $this->_build_params['head_charset'] . '?' . $mode . '?' . $encoded . '?=' . $suffix; 945 //Begin with the regexp for the first line. 946 $reg = $reg1st; 947 //Prevent lins that are just way to short; 948 if ($maxLength1stLine >1){ 949 $reg = $reg2nd; 950 } 951 $output = ""; 952 while ($hdr_val) { 953 //Split translated string at every $maxLength 954 //But make sure not to break any translated chars. 955 $found = preg_match($reg, $hdr_val, $matches); 956 957 //After this first line, we need to use a different 958 //regexp for the first line. 959 $reg = $reg2nd; 960 961 //Save the found part and encapsulate it in the 962 //prefix & suffix. Then remove the part from the 963 //$hdr_val variable. 964 if ($found){ 965 $part = $matches[0]; 966 $hdr_val = substr($hdr_val, strlen($matches[0])); 967 }else{ 968 $part = $hdr_val; 969 $hdr_val = ""; 970 } 971 972 //RFC 2047 specifies that any split header should be seperated 973 //by a CRLF SPACE. 974 if ($output){ 975 $output .= "\r\n "; 976 } 977 $output .= $prefix . $part . $suffix; 978 } 979 $hdr_val = $output; 845 980 } 846 847 // add chunk to output string by regarding the header maxlen 848 $len = strlen($value); 849 if ($line_len + $len < $maxlen) { 850 $hdr_value .= ($i>0?', ':'') . $value; 851 $line_len += $len + ($i>0?2:0); 852 } 853 else { 854 $hdr_value .= ($i>0?', ':'') . "\n " . $value; 855 $line_len = $len; 856 } 857 } 858 859 $input[$hdr_name] = $hdr_value; 981 $hdr_value_out .= $hdr_val; 982 } 983 $input[$hdr_name] = $hdr_value_out; 860 984 } 861 985 862 986 return $input; 863 987 } 864 865 866 function _explode_quoted_string($delimiter, $string)867 {868 $quotes = explode("\"", $string);869 foreach ($quotes as $key => $val)870 if (($key % 2) == 1)871 $quotes[$key] = str_replace($delimiter, "_!@!_", $quotes[$key]);872 873 $string = implode("\"", $quotes);874 875 $result = explode($delimiter, $string);876 foreach ($result as $key => $val)877 $result[$key] = str_replace("_!@!_", $delimiter, $result[$key]);878 879 return $result;880 }881 882 988 883 989 /** … … 898 1004 899 1005 } // End of class 900 ?>901 -
program/lib/Mail/mimeDecode.php
r856110d rab6f807 1 1 <?php 2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 3 // +-----------------------------------------------------------------------+ 4 // | Copyright (c) 2002-2003 Richard Heyes | 5 // | Copyright (c) 2003-2005 The PHP Group | 6 // | All rights reserved. | 7 // | | 8 // | Redistribution and use in source and binary forms, with or without | 9 // | modification, are permitted provided that the following conditions | 10 // | are met: | 11 // | | 12 // | o Redistributions of source code must retain the above copyright | 13 // | notice, this list of conditions and the following disclaimer. | 14 // | o Redistributions in binary form must reproduce the above copyright | 15 // | notice, this list of conditions and the following disclaimer in the | 16 // | documentation and/or other materials provided with the distribution.| 17 // | o The names of the authors may not be used to endorse or promote | 18 // | products derived from this software without specific prior written | 19 // | permission. | 20 // | | 21 // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 22 // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 23 // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 24 // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 25 // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 26 // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 27 // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 28 // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 29 // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 30 // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 31 // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 32 // | | 33 // +-----------------------------------------------------------------------+ 34 // | Author: Richard Heyes <richard@phpguru.org> | 35 // +-----------------------------------------------------------------------+ 36 2 /** 3 * The Mail_mimeDecode class is used to decode mail/mime messages 4 * 5 * This class will parse a raw mime email and return 6 * the structure. Returned structure is similar to 7 * that returned by imap_fetchstructure(). 8 * 9 * +----------------------------- IMPORTANT ------------------------------+ 10 * | Usage of this class compared to native php extensions such as | 11 * | mailparse or imap, is slow and may be feature deficient. If available| 12 * | you are STRONGLY recommended to use the php extensions. | 13 * +----------------------------------------------------------------------+ 14 * 15 * Compatible with PHP versions 4 and 5 16 * 17 * LICENSE: This LICENSE is in the BSD license style. 18 * Copyright (c) 2002-2003, Richard Heyes <richard@phpguru.org> 19 * Copyright (c) 2003-2006, PEAR <pear-group@php.net> 20 * All rights reserved. 21 * 22 * Redistribution and use in source and binary forms, with or 23 * without modification, are permitted provided that the following 24 * conditions are met: 25 * 26 * - Redistributions of source code must retain the above copyright 27 * notice, this list of conditions and the following disclaimer. 28 * - Redistributions in binary form must reproduce the above copyright 29 * notice, this list of conditions and the following disclaimer in the 30 * documentation and/or other materials provided with the distribution. 31 * - Neither the name of the authors, nor the names of its contributors 32 * may be used to endorse or promote products derived from this 33 * software without specific prior written permission. 34 * 35 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 36 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 38 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 39 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 40 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 41 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 42 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 43 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 44 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 45 * THE POSSIBILITY OF SUCH DAMAGE. 46 * 47 * @category Mail 48 * @package Mail_Mime 49 * @author Richard Heyes <richard@phpguru.org> 50 * @author George Schlossnagle <george@omniti.com> 51 * @author Cipriano Groenendal <cipri@php.net> 52 * @author Sean Coates <sean@php.net> 53 * @copyright 2003-2006 PEAR <pear-group@php.net> 54 * @license http://www.opensource.org/licenses/bsd-license.php BSD License 55 * @version CVS: $Id$ 56 * @link http://pear.php.net/package/Mail_mime 57 */ 58 59 60 /** 61 * require PEAR 62 * 63 * This package depends on PEAR to raise errors. 64 */ 37 65 require_once 'PEAR.php'; 38 66 67 39 68 /** 40 * +----------------------------- IMPORTANT ------------------------------+ 41 * | Usage of this class compared to native php extensions such as | 42 * | mailparse or imap, is slow and may be feature deficient. If available| 43 * | you are STRONGLY recommended to use the php extensions. | 44 * +----------------------------------------------------------------------+ 45 * 46 * Mime Decoding class 47 * 48 * This class will parse a raw mime email and return 49 * the structure. Returned structure is similar to 50 * that returned by imap_fetchstructure(). 51 * 52 * USAGE: (assume $input is your raw email) 53 * 54 * $decode = new Mail_mimeDecode($input, "\r\n"); 55 * $structure = $decode->decode(); 56 * print_r($structure); 57 * 58 * Or statically: 59 * 60 * $params['input'] = $input; 61 * $structure = Mail_mimeDecode::decode($params); 62 * print_r($structure); 63 * 64 * TODO: 65 * o UTF8: ??? 66 67 > 4. We have also found a solution for decoding the UTF-8 68 > headers. Therefore I made the following function: 69 > 70 > function decode_utf8($txt) { 71 > $trans=array("Å‘"=>"õ","ű"=>"û","Å"=>"Õ","Ű" 72 =>"Û"); 73 > $txt=strtr($txt,$trans); 74 > return(utf8_decode($txt)); 75 > } 76 > 77 > And I have inserted the following line to the class: 78 > 79 > if (strtolower($charset)=="utf-8") $text=decode_utf8($text); 80 > 81 > ... before the following one in the "_decodeHeader" function: 82 > 83 > $input = str_replace($encoded, $text, $input); 84 > 85 > This way from now on it can easily decode the UTF-8 headers too. 86 87 * 88 * @author Richard Heyes <richard@phpguru.org> 89 * @version $Revision$ 90 * @package Mail 91 */ 69 * The Mail_mimeDecode class is used to decode mail/mime messages 70 * 71 * This class will parse a raw mime email and return the structure. 72 * Returned structure is similar to that returned by imap_fetchstructure(). 73 * 74 * +----------------------------- IMPORTANT ------------------------------+ 75 * | Usage of this class compared to native php extensions such as | 76 * | mailparse or imap, is slow and may be feature deficient. If available| 77 * | you are STRONGLY recommended to use the php extensions. | 78 * +----------------------------------------------------------------------+ 79 * 80 * @category Mail 81 * @package Mail_Mime 82 * @author Richard Heyes <richard@phpguru.org> 83 * @author George Schlossnagle <george@omniti.com> 84 * @author Cipriano Groenendal <cipri@php.net> 85 * @author Sean Coates <sean@php.net> 86 * @copyright 2003-2006 PEAR <pear-group@php.net> 87 * @license http://www.opensource.org/licenses/bsd-license.php BSD License 88 * @version Release: @package_version@ 89 * @link http://pear.php.net/package/Mail_mime 90 */ 92 91 class Mail_mimeDecode extends PEAR 93 92 { 94 93 /** 95 94 * The raw email to decode 95 * 96 96 * @var string 97 * @access private 97 98 */ 98 99 var $_input; … … 100 101 /** 101 102 * The header part of the input 103 * 102 104 * @var string 105 * @access private 103 106 */ 104 107 var $_header; … … 106 109 /** 107 110 * The body part of the input 111 * 108 112 * @var string 113 * @access private 109 114 */ 110 115 var $_body; … … 112 117 /** 113 118 * If an error occurs, this is used to store the message 119 * 114 120 * @var string 121 * @access private 115 122 */ 116 123 var $_error; … … 119 126 * Flag to determine whether to include bodies in the 120 127 * returned object. 128 * 121 129 * @var boolean 130 * @access private 122 131 */ 123 132 var $_include_bodies; … … 125 134 /** 126 135 * Flag to determine whether to decode bodies 136 * 127 137 * @var boolean 138 * @access private 128 139 */ 129 140 var $_decode_bodies; … … 131 142 /** 132 143 * Flag to determine whether to decode headers 144 * 133 145 * @var boolean 146 * @access private 134 147 */ 135 148 var $_decode_headers; … … 835 848 836 849 } // End of class 837 ?> -
program/lib/Mail/mimePart.php
r15fee7b rab6f807 1 1 <?php 2 // +-----------------------------------------------------------------------+3 // | Copyright (c) 2002-2003 Richard Heyes |4 // | All rights reserved. |5 // | |6 // | Redistribution and use in source and binary forms, with or without |7 // | modification, are permitted provided that the following conditions |8 // | are met: |9 // | |10 // | o Redistributions of source code must retain the above copyright |11 // | notice, this list of conditions and the following disclaimer. |12 // | o Redistributions in binary form must reproduce the above copyright |13 // | notice, this list of conditions and the following disclaimer in the |14 // | documentation and/or other materials provided with the distribution.|15 // | o The names of the authors may not be used to endorse or promote |16 // | products derived from this software without specific prior written |17 // | permission. |18 // | |19 // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |20 // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |21 // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |22 // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |23 // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |24 // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |25 // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |26 // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |27 // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |28 // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |29 // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |30 // | |31 // +-----------------------------------------------------------------------+32 // | Author: Richard Heyes <richard@phpguru.org> |33 // +-----------------------------------------------------------------------+34 35 2 /** 36 * 37 * Raw mime encoding class 38 * 39 * What is it? 40 * This class enables you to manipulate and build 41 * a mime email from the ground up. 42 * 43 * Why use this instead of mime.php? 44 * mime.php is a userfriendly api to this class for 45 * people who aren't interested in the internals of 46 * mime mail. This class however allows full control 47 * over the email. 48 * 49 * Eg. 50 * 51 * // Since multipart/mixed has no real body, (the body is 52 * // the subpart), we set the body argument to blank. 53 * 54 * $params['content_type'] = 'multipart/mixed'; 55 * $email = new Mail_mimePart('', $params); 56 * 57 * // Here we add a text part to the multipart we have 58 * // already. Assume $body contains plain text. 59 * 60 * $params['content_type'] = 'text/plain'; 61 * $params['encoding'] = '7bit'; 62 * $text = $email->addSubPart($body, $params); 63 * 64 * // Now add an attachment. Assume $attach is 65 * the contents of the attachment 66 * 67 * $params['content_type'] = 'application/zip'; 68 * $params['encoding'] = 'base64'; 69 * $params['disposition'] = 'attachment'; 70 * $params['dfilename'] = 'example.zip'; 71 * $attach =& $email->addSubPart($body, $params); 72 * 73 * // Now build the email. Note that the encode 74 * // function returns an associative array containing two 75 * // elements, body and headers. You will need to add extra 76 * // headers, (eg. Mime-Version) before sending. 77 * 78 * $email = $message->encode(); 79 * $email['headers'][] = 'Mime-Version: 1.0'; 80 * 81 * 82 * Further examples are available at http://www.phpguru.org 83 * 84 * TODO: 85 * - Set encode() to return the $obj->encoded if encode() 86 * has already been run. Unless a flag is passed to specifically 87 * re-build the message. 88 * 89 * @author Richard Heyes <richard@phpguru.org> 90 * @version $Revision$ 91 * @package Mail 92 */ 93 3 * The Mail_mimePart class is used to create MIME E-mail messages 4 * 5 * This class enables you to manipulate and build a mime email 6 * from the ground up. The Mail_Mime class is a userfriendly api 7 * to this class for people who aren't interested in the internals 8 * of mime mail. 9 * This class however allows full control over the email. 10 * 11 * Compatible with PHP versions 4 and 5 12 * 13 * LICENSE: This LICENSE is in the BSD license style. 14 * Copyright (c) 2002-2003, Richard Heyes <richard@phpguru.org> 15 * Copyright (c) 2003-2006, PEAR <pear-group@php.net> 16 * All rights reserved. 17 * 18 * Redistribution and use in source and binary forms, with or 19 * without modification, are permitted provided that the following 20 * conditions are met: 21 * 22 * - Redistributions of source code must retain the above copyright 23 * notice, this list of conditions and the following disclaimer. 24 * - Redistributions in binary form must reproduce the above copyright 25 * notice, this list of conditions and the following disclaimer in the 26 * documentation and/or other materials provided with the distribution. 27 * - Neither the name of the authors, nor the names of its contributors 28 * may be used to endorse or promote products derived from this 29 * software without specific prior written permission. 30 * 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 32 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 35 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 36 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 39 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 41 * THE POSSIBILITY OF SUCH DAMAGE. 42 * 43 * @category Mail 44 * @package Mail_Mime 45 * @author Richard Heyes <richard@phpguru.org> 46 * @author Cipriano Groenendal <cipri@php.net> 47 * @author Sean Coates <sean@php.net> 48 * @copyright 2003-2006 PEAR <pear-group@php.net> 49 * @license http://www.opensource.org/licenses/bsd-license.php BSD License 50 * @version CVS: $Id$ 51 * @link http://pear.php.net/package/Mail_mime 52 */ 53 54 55 /** 56 * The Mail_mimePart class is used to create MIME E-mail messages 57 * 58 * This class enables you to manipulate and build a mime email 59 * from the ground up. The Mail_Mime class is a userfriendly api 60 * to this class for people who aren't interested in the internals 61 * of mime mail. 62 * This class however allows full control over the email. 63 * 64 * @category Mail 65 * @package Mail_Mime 66 * @author Richard Heyes <richard@phpguru.org> 67 * @author Cipriano Groenendal <cipri@php.net> 68 * @author Sean Coates <sean@php.net> 69 * @copyright 2003-2006 PEAR <pear-group@php.net> 70 * @license http://www.opensource.org/licenses/bsd-license.php BSD License 71 * @version Release: @package_version@ 72 * @link http://pear.php.net/package/Mail_mime 73 */ 94 74 class Mail_mimePart { 95 75 96 76 /** 97 77 * The encoding type of this part 78 * 98 79 * @var string 80 * @access private 99 81 */ 100 82 var $_encoding; … … 102 84 /** 103 85 * An array of subparts 86 * 104 87 * @var array 88 * @access private 105 89 */ 106 90 var $_subparts; … … 108 92 /** 109 93 * The output of this part after being built 94 * 110 95 * @var string 96 * @access private 111 97 */ 112 98 var $_encoded; … … 114 100 /** 115 101 * Headers for this part 102 * 116 103 * @var array 104 * @access private 117 105 */ 118 106 var $_headers; … … 120 108 /** 121 109 * The body of this part (not encoded) 110 * 122 111 * @var string 112 * @access private 123 113 */ 124 114 var $_body; … … 235 225 $encoded['body'] = '--' . $boundary . MAIL_MIMEPART_CRLF . 236 226 implode('--' . $boundary . MAIL_MIMEPART_CRLF, $subparts) . 237 '--' . $boundary.'--' . MAIL_MIMEPART_CRLF ;227 '--' . $boundary.'--' . MAIL_MIMEPART_CRLF . MAIL_MIMEPART_CRLF; 238 228 239 229 } else { … … 300 290 301 291 /** 302 * quote adPrintableEncode()292 * quotedPrintableEncode() 303 293 * 304 294 * Encodes data to quoted-printable standard. … … 319 309 while(list(, $line) = each($lines)){ 320 310 321 $linlen = strlen($line); 311 $line = preg_split('||', $line, -1, PREG_SPLIT_NO_EMPTY); 312 $linlen = count($line); 322 313 $newline = ''; 323 314 324 315 for ($i = 0; $i < $linlen; $i++) { 325 $char = substr($line, $i, 1);316 $char = $line[$i]; 326 317 $dec = ord($char); 327 318 … … 349 340 } 350 341 } // End of class 351 ?> -
program/lib/html2text.inc
r5cc4b13 rab6f807 113 113 '/<script[^>]*>.*?<\/script>/i', // <script>s -- which strip_tags supposedly has problems with 114 114 //'/<!-- .* -->/', // Comments -- which strip_tags might have problem a with 115 '/<a [^>]*href= "([^"]+)"[^>]*>(.+?)<\/a>/ie', // <a href="">115 '/<a [^>]*href=("|\')([^"\']+)\1[^>]*>(.+?)<\/a>/ie', // <a href=""> 116 116 '/<h[123][^>]*>(.+?)<\/h[123]>/ie', // H1 - H3 117 117 '/<h[456][^>]*>(.+?)<\/h[456]>/ie', // H4 - H6 … … 162 162 '', // <script>s -- which strip_tags supposedly has problems with 163 163 //'', // Comments -- which strip_tags might have problem a with 164 '$this->_build_link_list("\\ 1", "\\2")', // <a href="">164 '$this->_build_link_list("\\2", "\\3")', // <a href=""> 165 165 "strtoupper(\"\n\n\\1\n\n\")", // H1 - H3 166 166 "ucwords(\"\n\n\\1\n\")", // H4 - H6 -
program/steps/mail/sendmail.inc
r5a6ad20 rab6f807 25 25 require_once('include/rcube_smtp.inc'); 26 26 require_once('lib/html2text.inc'); 27 require_once(' Mail/mime.php');27 require_once('lib/rc_mail_mime.inc'); 28 28 29 29 … … 245 245 $header_delm = "\n"; 246 246 247 // create PEAR::Mail_mime instance248 247 249 248 $isHtmlVal = strtolower(get_input_value('_is_html', RCUBE_INPUT_POST)); 250 249 $isHtml = ($isHtmlVal == "1"); 251 250 252 $MAIL_MIME = new Mail_mime($header_delm); 251 // create extended PEAR::Mail_mime instance 252 $MAIL_MIME = new rc_mail_mime($header_delm); 253 253 254 254 // For HTML-formatted messages, construct the MIME message with both … … 276 276 if (is_array($_SESSION['compose']['attachments'])) 277 277 foreach ($_SESSION['compose']['attachments'] as $attachment) 278 $MAIL_MIME->addAttachment($attachment['path'], $attachment['mimetype'], $attachment['name'], TRUE); 279 280 278 $MAIL_MIME->addAttachment($attachment['path'], $attachment['mimetype'], $attachment['name'], true, 'base64', 'attachment', $message_charset); 279 281 280 // add submitted attachments 282 281 if (is_array($_FILES['_attachments']['tmp_name'])) 283 282 foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath) 284 $MAIL_MIME->addAttachment($filepath, $files['type'][$i], $files['name'][$i], TRUE);283 $MAIL_MIME->addAttachment($filepath, $files['type'][$i], $files['name'][$i], true, 'base64', 'attachment', $message_charset); 285 284 286 285
Note: See TracChangeset
for help on using the changeset viewer.
