Subversion Repositories Applications.papyrus

Rev

Rev 1688 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1688 Rev 1700
Line 1... Line 1...
1
<?php
1
<?php
-
 
2
/**
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
 * The Mail_Mime class is used to create MIME E-mail messages
-
 
4
 *
3
// +-----------------------------------------------------------------------+
5
 * The Mail_Mime class provides an OO interface to create MIME
4
// | Copyright (c) 2002-2003  Richard Heyes                                |
6
 * enabled email messages. This way you can create emails that
5
// | Copyright (c) 2003-2005  The PHP Group                                |
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.
6
// | All rights reserved.                                                  |
13
 * Copyright (c) 2002-2003, Richard Heyes <richard@phpguru.org>
7
// |                                                                       |
14
 * Copyright (c) 2003-2006, PEAR <pear-group@php.net>
-
 
15
 * All rights reserved.
-
 
16
 *
8
// | Redistribution and use in source and binary forms, with or without    |
17
 * Redistribution and use in source and binary forms, with or
9
// | modification, are permitted provided that the following conditions    |
18
 * without modification, are permitted provided that the following
10
// | are met:                                                              |
19
 * conditions are met:
11
// |                                                                       |
-
 
-
 
20
 *
12
// | o Redistributions of source code must retain the above copyright      |
21
 * - Redistributions of source code must retain the above copyright
13
// |   notice, this list of conditions and the following disclaimer.       |
22
 *   notice, this list of conditions and the following disclaimer.
14
// | o Redistributions in binary form must reproduce the above copyright   |
23
 * - Redistributions in binary form must reproduce the above copyright
15
// |   notice, this list of conditions and the following disclaimer in the |
24
 *   notice, this list of conditions and the following disclaimer in the
16
// |   documentation and/or other materials provided with the distribution.|
25
 *   documentation and/or other materials provided with the distribution.
17
// | o The names of the authors may not be used to endorse or promote      |
26
 * - Neither the name of the authors, nor the names of its contributors 
18
// |   products derived from this software without specific prior written  |
27
 *   may be used to endorse or promote products derived from this 
19
// |   permission.                                                         |
28
 *   software without specific prior written permission.
20
// |                                                                       |
-
 
-
 
29
 *
21
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |
30
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |
31
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
32
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |
33
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25
// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
34
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |
35
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
36
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
37
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |
38
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
39
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31
// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |
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>
32
// |                                                                       |
49
 * @license   http://www.opensource.org/licenses/bsd-license.php BSD License
33
// +-----------------------------------------------------------------------+
50
 * @version   CVS: $Id: mime.php,v 1.1.6.1 2007-11-19 12:53:54 alexandre_tb Exp $
-
 
51
 * @link      http://pear.php.net/package/Mail_mime
-
 
52
 *
-
 
53
 *            This class is based on HTML Mime Mail class from
34
// | Author: Richard Heyes <richard@phpguru.org>                           |
54
 *            Richard Heyes <richard@phpguru.org> which was based also
35
// |         Tomas V.V.Cox <cox@idecnet.com> (port to PEAR)                |
55
 *            in the mime_mail.class by Tobias Ratschiller <tobias@dnet.it>
36
// +-----------------------------------------------------------------------+
56
 *            and Sascha Schumann <sascha@schumann.cx>
37
//
57
 */
38
// $Id: mime.php,v 1.1 2006-09-13 08:49:41 alexandre_tb Exp $
-
 
Line 39... Line -...
39
 
-
 
40
require_once('PEAR.php');
-
 
Line 41... Line 58...
41
require_once('Mail/mimePart.php');
58
 
-
 
59
 
-
 
60
/**
42
 
61
 * require PEAR
-
 
62
 *
-
 
63
 * This package depends on PEAR to raise errors.
-
 
64
 */
-
 
65
require_once 'PEAR.php';
43
/**
66
 
-
 
67
/**
44
 * Mime mail composer class. Can handle: text and html bodies, embedded html
68
 * require Mail_mimePart
45
 * images and attachments.
69
 *
-
 
70
 * Mail_mimePart contains the code required to
46
 * Documentation and examples of this class are avaible here:
71
 * create all the different parts a mail can
-
 
72
 * consist of.
-
 
73
 */
-
 
74
require_once 'Mail/mimePart.php';
-
 
75
 
47
 * http://pear.php.net/manual/
76
 
48
 *
77
/**
49
 * @notes This class is based on HTML Mime Mail class from
78
 * The Mail_Mime class provides an OO interface to create MIME
50
 *   Richard Heyes <richard@phpguru.org> which was based also
79
 * enabled email messages. This way you can create emails that
51
 *   in the mime_mail.class by Tobias Ratschiller <tobias@dnet.it> and
80
 * contain plain-text bodies, HTML bodies, attachments, inline
-
 
81
 * images and specific headers.
-
 
82
 *
52
 *   Sascha Schumann <sascha@schumann.cx>
83
 * @category  Mail
53
 *
84
 * @package   Mail_Mime
-
 
85
 * @author    Richard Heyes  <richard@phpguru.org>
54
 * @author   Richard Heyes <richard.heyes@heyes-computing.net>
86
 * @author    Tomas V.V. Cox <cox@idecnet.com>
-
 
87
 * @author    Cipriano Groenendal <cipri@php.net>
-
 
88
 * @author    Sean Coates <sean@php.net>
55
 * @author   Tomas V.V.Cox <cox@idecnet.com>
89
 * @copyright 2003-2006 PEAR <pear-group@php.net>
-
 
90
 * @license   http://www.opensource.org/licenses/bsd-license.php BSD License
56
 * @package  Mail
91
 * @version   Release: @package_version@
57
 * @access   public
92
 * @link      http://pear.php.net/package/Mail_mime
58
 */
93
 */
59
class Mail_mime
94
class Mail_mime
60
{
95
{
-
 
96
    /**
61
    /**
97
     * Contains the plain text part of the email
-
 
98
     *
62
     * Contains the plain text part of the email
99
     * @var string
63
     * @var string
100
     * @access private
-
 
101
     */
64
     */
102
    var $_txtbody;
65
    var $_txtbody;
103
 
-
 
104
    /**
66
    /**
105
     * Contains the html part of the email
-
 
106
     *
67
     * Contains the html part of the email
107
     * @var string
68
     * @var string
108
     * @access private
-
 
109
     */
69
     */
110
    var $_htmlbody;
70
    var $_htmlbody;
111
 
-
 
112
    /**
71
    /**
113
     * contains the mime encoded text
-
 
114
     *
72
     * contains the mime encoded text
115
     * @var string
73
     * @var string
116
     * @access private
-
 
117
     */
74
     */
118
    var $_mime;
75
    var $_mime;
119
 
-
 
120
    /**
76
    /**
121
     * contains the multipart content
-
 
122
     *
77
     * contains the multipart content
123
     * @var string
78
     * @var string
124
     * @access private
-
 
125
     */
79
     */
126
    var $_multipart;
80
    var $_multipart;
127
 
-
 
128
    /**
81
    /**
129
     * list of the attached images
-
 
130
     *
82
     * list of the attached images
131
     * @var array
83
     * @var array
132
     * @access private
-
 
133
     */
84
     */
134
    var $_html_images = array();
85
    var $_html_images = array();
135
 
-
 
136
    /**
86
    /**
137
     * list of the attachements
-
 
138
     *
87
     * list of the attachements
139
     * @var array
88
     * @var array
140
     * @access private
-
 
141
     */
89
     */
142
    var $_parts = array();
90
    var $_parts = array();
143
 
-
 
144
    /**
91
    /**
145
     * Build parameters
-
 
146
     *
92
     * Build parameters
147
     * @var array
93
     * @var array
148
     * @access private
-
 
149
     */
94
     */
150
    var $_build_params = array();
95
    var $_build_params = array();
151
 
-
 
152
    /**
96
    /**
153
     * Headers for the mail
-
 
154
     *
97
     * Headers for the mail
155
     * @var array
98
     * @var array
156
     * @access private
-
 
157
     */
99
     */
158
    var $_headers = array();
100
    var $_headers = array();
159
 
-
 
160
    /**
101
    /**
161
     * End Of Line sequence (for serialize)
-
 
162
     *
102
     * End Of Line sequence (for serialize)
163
     * @var string
103
     * @var string
164
     * @access private
Line 104... Line 165...
104
     */
165
     */
105
    var $_eol;
166
    var $_eol;
-
 
167
 
-
 
168
 
-
 
169
    /**
-
 
170
     * Constructor function.
-
 
171
     *
106
 
172
     * @param string $crlf what type of linebreak to use.
107
 
173
     *                     Defaults to "\r\n"
108
    /**
174
     *
109
     * Constructor function
175
     * @return void
110
     *
176
     *
111
     * @access public
177
     * @access public
112
     */
178
     */
-
 
179
    function Mail_mime($crlf = "\r\n")
113
    function Mail_mime($crlf = "\r\n")
180
    {
114
    {
181
        $this->_setEOL($crlf);
115
        $this->_setEOL($crlf);
182
        $this->_build_params = array(
116
        $this->_build_params = array(
183
                                     'head_encoding' => 'quoted-printable',
117
                                     'text_encoding' => '7bit',
184
                                     'text_encoding' => '7bit',
118
                                     'html_encoding' => 'quoted-printable',
185
                                     'html_encoding' => 'quoted-printable',
119
                                     '7bit_wrap'     => 998,
186
                                     '7bit_wrap'     => 998,
120
                                     'html_charset'  => 'ISO-8859-1',
187
                                     'html_charset'  => 'ISO-8859-1',
Line 121... Line 188...
121
                                     'text_charset'  => 'ISO-8859-1',
188
                                     'text_charset'  => 'ISO-8859-1',
122
                                     'head_charset'  => 'ISO-8859-1'
189
                                     'head_charset'  => 'ISO-8859-1'
123
                                    );
190
                                    );
124
    }
191
    }
-
 
192
 
125
 
193
    /**
126
    /**
194
     * wakeup function called by unserialize. It re-sets the EOL constant
127
     * Wakeup (unserialize) - re-sets EOL constant
195
     *
128
     *
196
     * @access private
129
     * @access private
197
     * @return void
Line -... Line 198...
-
 
198
     */
130
     */
199
    function __wakeup()
131
    function __wakeup()
200
    {
132
    {
201
        $this->_setEOL($this->_eol);
133
        $this->_setEOL($this->_eol);
202
    }
134
    }
203
 
135
 
204
 
136
    /**
205
    /**
137
     * Accessor function to set the body text. Body text is used if
206
     * Accessor function to set the body text. Body text is used if
138
     * it's not an html mail being sent or else is used to fill the
207
     * it's not an html mail being sent or else is used to fill the
139
     * text/plain part that emails clients who don't support
208
     * text/plain part that emails clients who don't support
140
     * html should show.
209
     * html should show.
141
     *
210
     *
142
     * @param  string  $data   Either a string or
211
     * @param string $data   Either a string or
-
 
212
     *                        the file name with the contents
143
     *                         the file name with the contents
213
     * @param bool   $isfile If true the first param should be treated
144
     * @param  bool    $isfile If true the first param should be treated
214
     *                        as a file name, else as a string (default)
145
     *                         as a file name, else as a string (default)
215
     * @param bool   $append If true the text or file is appended to
146
     * @param  bool    $append If true the text or file is appended to
216
     *                        the existing body, else the old body is
147
     *                         the existing body, else the old body is
217
     *                        overwritten
Line 170... Line 240...
170
        }
240
        }
171
        return true;
241
        return true;
172
    }
242
    }
Line 173... Line 243...
173
 
243
 
174
    /**
244
    /**
175
     * Adds a html part to the mail
245
     * Adds a html part to the mail.
176
     *
246
     *
177
     * @param  string  $data   Either a string or the file name with the
247
     * @param string $data   either a string or the file name with the
178
     *                         contents
248
     *                        contents
179
     * @param  bool    $isfile If true the first param should be treated
249
     * @param bool   $isfile a flag that determines whether $data is a
-
 
250
     *                        filename, or a string(false, default)
180
     *                         as a file name, else as a string (default)
251
     *
181
     * @return mixed   true on success or PEAR_Error object
252
     * @return bool    true on success
182
     * @access public
253
     * @access public
183
     */
254
     */
184
    function setHTMLBody($data, $isfile = false)
255
    function setHTMLBody($data, $isfile = false)
185
    {
256
    {
Line 197... Line 268...
197
    }
268
    }
Line 198... Line 269...
198
 
269
 
199
    /**
270
    /**
200
     * Adds an image to the list of embedded images.
271
     * Adds an image to the list of embedded images.
201
     *
272
     *
202
     * @param  string  $file       The image file name OR image data itself
273
     * @param string $file   the image file name OR image data itself
203
     * @param  string  $c_type     The content type
274
     * @param string $c_type the content type
204
     * @param  string  $name       The filename of the image.
275
     * @param string $name   the filename of the image.
205
     *                             Only use if $file is the image data
276
     *                        Only used if $file is the image data.
206
     * @param  bool    $isfilename Whether $file is a filename or not
277
     * @param bool   $isfile whether $file is a filename or not.
-
 
278
     *                        Defaults to true
207
     *                             Defaults to true
279
     *
208
     * @return mixed   true on success or PEAR_Error object
280
     * @return bool          true on success
209
     * @access public
281
     * @access public
210
     */
282
     */
211
    function addHTMLImage($file, $c_type='application/octet-stream',
283
    function addHTMLImage($file, $c_type='application/octet-stream',
212
                          $name = '', $isfilename = true)
284
                          $name = '', $isfile = true)
213
    {
285
    {
214
        $filedata = ($isfilename === true) ? $this->_file2str($file)
286
        $filedata = ($isfile === true) ? $this->_file2str($file)
215
                                           : $file;
287
                                           : $file;
216
        if ($isfilename === true) {
288
        if ($isfile === true) {
217
            $filename = ($name == '' ? basename($file) : basename($name));
289
            $filename = ($name == '' ? $file : $name);
218
        } else {
290
        } else {
219
            $filename = basename($name);
291
            $filename = $name;
220
        }
292
        }
221
        if (PEAR::isError($filedata)) {
293
        if (PEAR::isError($filedata)) {
222
            return $filedata;
294
            return $filedata;
223
        }
295
        }
Line 231... Line 303...
231
    }
303
    }
Line 232... Line 304...
232
 
304
 
233
    /**
305
    /**
234
     * Adds a file to the list of attachments.
306
     * Adds a file to the list of attachments.
235
     *
307
     *
236
     * @param  string  $file       The file name of the file to attach
308
     * @param string $file        The file name of the file to attach
237
     *                             OR the file data itself
309
     *                             OR the file contents itself
238
     * @param  string  $c_type     The content type
310
     * @param string $c_type      The content type
239
     * @param  string  $name       The filename of the attachment
311
     * @param string $name        The filename of the attachment
240
     *                             Only use if $file is the file data
312
     *                             Only use if $file is the contents
241
     * @param  bool    $isFilename Whether $file is a filename or not
313
     * @param bool   $isfile      Whether $file is a filename or not
-
 
314
     *                             Defaults to true
-
 
315
     * @param string $encoding    The type of encoding to use.
-
 
316
     *                             Defaults to base64.
-
 
317
     *                             Possible values: 7bit, 8bit, base64, 
-
 
318
     *                             or quoted-printable.
-
 
319
     * @param string $disposition The content-disposition of this file
-
 
320
     *                             Defaults to attachment.
-
 
321
     *                             Possible values: attachment, inline.
-
 
322
     * @param string $charset     The character set used in the filename
-
 
323
     *                             of this attachment.
-
 
324
     * @param string $language    The language of the attachment
-
 
325
     * @param string $location    The RFC 2557.4 location of the attachment
242
     *                             Defaults to true
326
     *
243
     * @return mixed true on success or PEAR_Error object
327
     * @return mixed true on success or PEAR_Error object
244
     * @access public
328
     * @access public
-
 
329
     */
245
     */
330
    function addAttachment($file,
-
 
331
                           $c_type      = 'application/octet-stream',
246
    function addAttachment($file, $c_type = 'application/octet-stream',
332
                           $name        = '',
247
                           $name = '', $isfilename = true,
333
                            $isfile     = true,
-
 
334
                           $encoding    = 'base64',
-
 
335
                           $disposition = 'attachment',
-
 
336
                           $charset     = '',
-
 
337
                            $language   = '',
248
                           $encoding = 'base64')
338
                           $location    = '')
249
    {
339
    {
250
        $filedata = ($isfilename === true) ? $this->_file2str($file)
340
        $filedata = ($isfile === true) ? $this->_file2str($file)
251
                                           : $file;
341
                                           : $file;
252
        if ($isfilename === true) {
342
        if ($isfile === true) {
253
            // Force the name the user supplied, otherwise use $file
343
            // Force the name the user supplied, otherwise use $file
254
            $filename = (!empty($name)) ? $name : $file;
344
            $filename = (strlen($name)) ? $name : $file;
255
        } else {
345
        } else {
256
            $filename = $name;
346
            $filename = $name;
257
        }
347
        }
258
        if (empty($filename)) {
-
 
259
            return PEAR::raiseError(
348
        if (!strlen($filename)) {
-
 
349
            $msg = "The supplied filename for the attachment can't be empty";
260
              'The supplied filename for the attachment can\'t be empty'
350
            $err = PEAR::raiseError($msg);
261
            );
351
            return $err;
262
        }
352
        }
263
        $filename = basename($filename);
353
        $filename = basename($filename);
264
        if (PEAR::isError($filedata)) {
354
        if (PEAR::isError($filedata)) {
265
            return $filedata;
355
            return $filedata;
Line 266... Line 356...
266
        }
356
        }
267
 
357
 
268
        $this->_parts[] = array(
358
        $this->_parts[] = array(
269
                                'body'     => $filedata,
359
                                'body'        => $filedata,
270
                                'name'     => $filename,
360
                                'name'        => $filename,
-
 
361
                                'c_type'      => $c_type,
-
 
362
                                'encoding'    => $encoding,
-
 
363
                                'charset'     => $charset,
-
 
364
                                'language'    => $language,
271
                                'c_type'   => $c_type,
365
                                'location'    => $location,
272
                                'encoding' => $encoding
366
                                'disposition' => $disposition
273
                               );
367
                               );
Line 274... Line 368...
274
        return true;
368
        return true;
275
    }
369
    }
276
 
370
 
277
    /**
371
    /**
-
 
372
     * Get the contents of the given file name as string
278
     * Get the contents of the given file name as string
373
     *
279
     *
374
     * @param string $file_name path of file to process
280
     * @param  string  $file_name  path of file to process
375
     *
281
     * @return string  contents of $file_name
376
     * @return string  contents of $file_name
282
     * @access private
377
     * @access private
283
     */
378
     */
284
    function &_file2str($file_name)
379
    function &_file2str($file_name)
-
 
380
    {
285
    {
381
        if (!is_readable($file_name)) {
286
        if (!is_readable($file_name)) {
382
            $err = PEAR::raiseError('File is not readable ' . $file_name);
287
            return PEAR::raiseError('File is not readable ' . $file_name);
383
            return $err;
-
 
384
        }
288
        }
385
        if (!$fd = fopen($file_name, 'rb')) {
289
        if (!$fd = fopen($file_name, 'rb')) {
386
            $err = PEAR::raiseError('Could not open ' . $file_name);
290
            return PEAR::raiseError('Could not open ' . $file_name);
387
            return $err;
291
        }
388
        }
292
        $filesize = filesize($file_name);
389
        $filesize = filesize($file_name);
-
 
390
        if ($filesize == 0) {
-
 
391
            $cont =  "";
-
 
392
        } else {
293
        if ($filesize == 0){
393
            if ($magic_quote_setting = get_magic_quotes_runtime()) {
-
 
394
                set_magic_quotes_runtime(0);
-
 
395
            }
-
 
396
            $cont = fread($fd, $filesize);
294
            $cont =  "";
397
            if ($magic_quote_setting) {
295
        }else{
398
                set_magic_quotes_runtime($magic_quote_setting);
296
            $cont = fread($fd, $filesize);
399
            }
297
        }
400
        }
Line 298... Line 401...
298
        fclose($fd);
401
        fclose($fd);
299
        return $cont;
402
        return $cont;
300
    }
403
    }
301
 
404
 
302
    /**
405
    /**
303
     * Adds a text subpart to the mimePart object and
406
     * Adds a text subpart to the mimePart object and
304
     * returns it during the build process.
407
     * returns it during the build process.
-
 
408
     *
305
     *
409
     * @param mixed  &$obj The object to add the part to, or
306
     * @param mixed    The object to add the part to, or
410
     *                      null if a new object is to be created.
307
     *                 null if a new object is to be created.
411
     * @param string $text The text to add.
308
     * @param string   The text to add.
412
     *
309
     * @return object  The text mimePart object
413
     * @return object  The text mimePart object
310
     * @access private
414
     * @access private
311
     */
415
     */
312
    function &_addTextPart(&$obj, $text)
416
    function &_addTextPart(&$obj, $text)
313
    {
417
    {
314
        $params['content_type'] = 'text/plain';
418
        $params['content_type'] = 'text/plain';
-
 
419
        $params['encoding']     = $this->_build_params['text_encoding'];
315
        $params['encoding']     = $this->_build_params['text_encoding'];
420
        $params['charset']      = $this->_build_params['text_charset'];
316
        $params['charset']      = $this->_build_params['text_charset'];
421
        if (is_object($obj)) {
-
 
422
            $ret = $obj->addSubpart($text, $params);
317
        if (is_object($obj)) {
423
            return $ret;
318
            return $obj->addSubpart($text, $params);
424
        } else {
Line 319... Line 425...
319
        } else {
425
            $ret = new Mail_mimePart($text, $params);
320
            return new Mail_mimePart($text, $params);
426
            return $ret;
321
        }
427
        }
322
    }
428
    }
323
 
429
 
324
    /**
430
    /**
-
 
431
     * Adds a html subpart to the mimePart object and
325
     * Adds a html subpart to the mimePart object and
432
     * returns it during the build process.
326
     * returns it during the build process.
433
     *
327
     *
434
     * @param mixed &$obj The object to add the part to, or
328
     * @param  mixed   The object to add the part to, or
435
     *                     null if a new object is to be created.
329
     *                 null if a new object is to be created.
436
     *
330
     * @return object  The html mimePart object
437
     * @return object The html mimePart object
331
     * @access private
438
     * @access private
332
     */
439
     */
333
    function &_addHtmlPart(&$obj)
440
    function &_addHtmlPart(&$obj)
334
    {
441
    {
-
 
442
        $params['content_type'] = 'text/html';
335
        $params['content_type'] = 'text/html';
443
        $params['encoding']     = $this->_build_params['html_encoding'];
336
        $params['encoding']     = $this->_build_params['html_encoding'];
444
        $params['charset']      = $this->_build_params['html_charset'];
-
 
445
        if (is_object($obj)) {
337
        $params['charset']      = $this->_build_params['html_charset'];
446
            $ret = $obj->addSubpart($this->_htmlbody, $params);
338
        if (is_object($obj)) {
447
            return $ret;
Line 339... Line 448...
339
            return $obj->addSubpart($this->_htmlbody, $params);
448
        } else {
340
        } else {
449
            $ret = new Mail_mimePart($this->_htmlbody, $params);
341
            return new Mail_mimePart($this->_htmlbody, $params);
450
            return $ret;
342
        }
451
        }
343
    }
452
    }
344
 
453
 
345
    /**
454
    /**
346
     * Creates a new mimePart object, using multipart/mixed as
455
     * Creates a new mimePart object, using multipart/mixed as
347
     * the initial content-type and returns it during the
456
     * the initial content-type and returns it during the
348
     * build process.
457
     * build process.
-
 
458
     *
349
     *
459
     * @return object The multipart/mixed mimePart object
-
 
460
     * @access private
-
 
461
     */
350
     * @return object  The multipart/mixed mimePart object
462
    function &_addMixedPart()
-
 
463
    {
351
     * @access private
464
        $params                 = array();
Line 352... Line 465...
352
     */
465
        $params['content_type'] = 'multipart/mixed';
353
    function &_addMixedPart()
466
        
354
    {
467
        //Create empty multipart/mixed Mail_mimePart object to return
355
        $params['content_type'] = 'multipart/mixed';
468
        $ret = new Mail_mimePart('', $params);
356
        return new Mail_mimePart('', $params);
469
        return $ret;
357
    }
470
    }
358
 
471
 
-
 
472
    /**
359
    /**
473
     * Adds a multipart/alternative part to a mimePart
360
     * Adds a multipart/alternative part to a mimePart
474
     * object (or creates one), and returns it during
361
     * object (or creates one), and returns it during
475
     * the build process.
362
     * the build process.
476
     *
363
     *
477
     * @param mixed &$obj The object to add the part to, or
364
     * @param  mixed   The object to add the part to, or
478
     *                     null if a new object is to be created.
365
     *                 null if a new object is to be created.
479
     *
366
     * @return object  The multipart/mixed mimePart object
480
     * @return object  The multipart/mixed mimePart object
367
     * @access private
481
     * @access private
368
     */
482
     */
-
 
483
    function &_addAlternativePart(&$obj)
369
    function &_addAlternativePart(&$obj)
484
    {
370
    {
485
        $params['content_type'] = 'multipart/alternative';
Line 371... Line 486...
371
        $params['content_type'] = 'multipart/alternative';
486
        if (is_object($obj)) {
372
        if (is_object($obj)) {
487
            return $obj->addSubpart('', $params);
373
            return $obj->addSubpart('', $params);
488
        } else {
374
        } else {
489
            $ret = new Mail_mimePart('', $params);
375
            return new Mail_mimePart('', $params);
490
            return $ret;
376
        }
491
        }
377
    }
492
    }
-
 
493
 
378
 
494
    /**
379
    /**
495
     * Adds a multipart/related part to a mimePart
380
     * Adds a multipart/related part to a mimePart
496
     * object (or creates one), and returns it during
381
     * object (or creates one), and returns it during
497
     * the build process.
382
     * the build process.
498
     *
383
     *
499
     * @param mixed &$obj The object to add the part to, or
384
     * @param mixed    The object to add the part to, or
500
     *                     null if a new object is to be created
385
     *                 null if a new object is to be created
501
     *
386
     * @return object  The multipart/mixed mimePart object
502
     * @return object  The multipart/mixed mimePart object
387
     * @access private
503
     * @access private
-
 
504
     */
388
     */
505
    function &_addRelatedPart(&$obj)
389
    function &_addRelatedPart(&$obj)
506
    {
Line 390... Line 507...
390
    {
507
        $params['content_type'] = 'multipart/related';
391
        $params['content_type'] = 'multipart/related';
508
        if (is_object($obj)) {
392
        if (is_object($obj)) {
509
            return $obj->addSubpart('', $params);
393
            return $obj->addSubpart('', $params);
510
        } else {
394
        } else {
511
            $ret = new Mail_mimePart('', $params);
395
            return new Mail_mimePart('', $params);
512
            return $ret;
-
 
513
        }
396
        }
514
    }
397
    }
515
 
398
 
516
    /**
399
    /**
517
     * Adds an html image subpart to a mimePart object
400
     * Adds an html image subpart to a mimePart object
518
     * and returns it during the build process.
401
     * and returns it during the build process.
519
     *
402
     *
520
     * @param object &$obj  The mimePart to add the image to
403
     * @param  object  The mimePart to add the image to
521
     * @param array  $value The image information
404
     * @param  array   The image information
522
     *
405
     * @return object  The image mimePart object
523
     * @return object  The image mimePart object
-
 
524
     * @access private
406
     * @access private
525
     */
-
 
526
    function &_addHtmlImagePart(&$obj, $value)
-
 
527
    {
407
     */
528
        $params['content_type'] = $value['c_type'];
Line 408... Line 529...
408
    function &_addHtmlImagePart(&$obj, $value)
529
        $params['encoding']     = 'base64';
409
    {
530
        $params['disposition']  = 'inline';
410
        $params['content_type'] = $value['c_type'];
531
        $params['dfilename']    = $value['name'];
411
        $params['encoding']     = 'base64';
532
        $params['cid']          = $value['cid'];
412
        $params['disposition']  = 'inline';
533
        
413
        $params['dfilename']    = $value['name'];
534
        $ret = $obj->addSubpart($value['body'], $params);
-
 
535
        return $ret;
414
        $params['cid']          = $value['cid'];
536
    
415
        $obj->addSubpart($value['body'], $params);
537
    }
416
    }
538
 
417
 
539
    /**
418
    /**
540
     * Adds an attachment subpart to a mimePart object
-
 
541
     * and returns it during the build process.
-
 
542
     *
-
 
543
     * @param object &$obj  The mimePart to add the image to
-
 
544
     * @param array  $value The attachment information
-
 
545
     *
-
 
546
     * @return object  The image mimePart object
-
 
547
     * @access private
-
 
548
     */
-
 
549
    function &_addAttachmentPart(&$obj, $value)
-
 
550
    {
-
 
551
        $params['dfilename'] = $value['name'];
419
     * Adds an attachment subpart to a mimePart object
552
        $params['encoding']  = $value['encoding'];
420
     * and returns it during the build process.
553
        if ($value['charset']) {
421
     *
554
            $params['charset'] = $value['charset'];
422
     * @param  object  The mimePart to add the image to
555
        }
-
 
556
        if ($value['language']) {
-
 
557
            $params['language'] = $value['language'];
-
 
558
        }
-
 
559
        if ($value['location']) {
-
 
560
            $params['location'] = $value['location'];
-
 
561
        }
-
 
562
        $params['content_type'] = $value['c_type'];
-
 
563
        $params['disposition']  = isset($value['disposition']) ? 
-
 
564
                                  $value['disposition'] : 'attachment';
-
 
565
        $ret = $obj->addSubpart($value['body'], $params);
-
 
566
        return $ret;
-
 
567
    }
-
 
568
 
-
 
569
    /**
-
 
570
     * Returns the complete e-mail, ready to send using an alternative
-
 
571
     * mail delivery method. Note that only the mailpart that is made
-
 
572
     * with Mail_Mime is created. This means that,
-
 
573
     * YOU WILL HAVE NO TO: HEADERS UNLESS YOU SET IT YOURSELF 
-
 
574
     * using the $xtra_headers parameter!
-
 
575
     * 
-
 
576
     * @param string $separation   The separation etween these two parts.
-
 
577
     * @param array  $build_params The Build parameters passed to the
-
 
578
     *                             &get() function. See &get for more info.
-
 
579
     * @param array  $xtra_headers The extra headers that should be passed
-
 
580
     *                             to the &headers() function.
-
 
581
     *                             See that function for more info.
-
 
582
     * @param bool   $overwrite    Overwrite the existing headers with new.
-
 
583
     *
-
 
584
     * @return string The complete e-mail.
-
 
585
     * @access public
-
 
586
     */
423
     * @param  array   The attachment information
587
    function getMessage(
-
 
588
                        $separation   = null, 
-
 
589
                        $build_params = null, 
-
 
590
                        $xtra_headers = null, 
424
     * @return object  The image mimePart object
591
                        $overwrite    = false
Line -... Line 592...
-
 
592
                       )
425
     * @access private
593
    {
426
     */
594
        if ($separation === null) {
427
    function &_addAttachmentPart(&$obj, $value)
595
            $separation = MAIL_MIME_CRLF;
428
    {
596
        }
429
        $params['content_type'] = $value['c_type'];
597
        $body = $this->get($build_params);
430
        $params['encoding']     = $value['encoding'];
598
        $head = $this->txtHeaders($xtra_headers, $overwrite);
-
 
599
        $mail = $head . $separation . $body;
-
 
600
        return $mail;
-
 
601
    }
431
        $params['disposition']  = 'attachment';
602
 
-
 
603
 
-
 
604
    /**
432
        $params['dfilename']    = $value['name'];
605
     * Builds the multipart message from the list ($this->_parts) and
433
        $obj->addSubpart($value['body'], $params);
606
     * returns the mime content.
-
 
607
     *
-
 
608
     * @param array $build_params Build parameters that change the way the email
434
    }
609
     *                             is built. Should be associative. Can contain:
435
 
610
     *                head_encoding  -  What encoding to use for the headers. 
436
    /**
611
     *                                  Options: quoted-printable or base64
437
     * Builds the multipart message from the list ($this->_parts) and
612
     *                                  Default is quoted-printable
438
     * returns the mime content.
613
     *                text_encoding  -  What encoding to use for plain text
439
     *
614
     *                                  Options: 7bit, 8bit,
440
     * @param  array  Build parameters that change the way the email
615
     *                                  base64, or quoted-printable
441
     *                is built. Should be associative. Can contain:
616
     *                                  Default is 7bit
442
     *                text_encoding  -  What encoding to use for plain text
617
     *                html_encoding  -  What encoding to use for html
443
     *                                  Default is 7bit
618
     *                                  Options: 7bit, 8bit,
-
 
619
     *                                  base64, or quoted-printable
444
     *                html_encoding  -  What encoding to use for html
620
     *                                  Default is quoted-printable
445
     *                                  Default is quoted-printable
621
     *                7bit_wrap      -  Number of characters before text is
446
     *                7bit_wrap      -  Number of characters before text is
622
     *                                  wrapped in 7bit encoding
447
     *                                  wrapped in 7bit encoding
623
     *                                  Default is 998
448
     *                                  Default is 998
624
     *                html_charset   -  The character set to use for html.
449
     *                html_charset   -  The character set to use for html.
625
     *                                  Default is iso-8859-1
450
     *                                  Default is iso-8859-1
626
     *                text_charset   -  The character set to use for text.
451
     *                text_charset   -  The character set to use for text.
627
     *                                  Default is iso-8859-1
452
     *                                  Default is iso-8859-1
628
     *                head_charset   -  The character set to use for headers.
453
     *                head_charset   -  The character set to use for headers.
629
     *                                  Default is iso-8859-1
454
     *                                  Default is iso-8859-1
630
     *
-
 
631
     * @return string The mime content
-
 
632
     * @access public
-
 
633
     */
-
 
634
    function &get($build_params = null)
-
 
635
    {
-
 
636
        if (isset($build_params)) {
-
 
637
            while (list($key, $value) = each($build_params)) {
-
 
638
                $this->_build_params[$key] = $value;
-
 
639
            }
-
 
640
        }
455
     * @return string The mime content
641
        
456
     * @access public
642
        if (isset($this->_headers['From'])){
-
 
643
            $domain = @strstr($this->_headers['From'],'@');
457
     */
644
            //Bug #11381: Illegal characters in domain ID
-
 
645
            $domain = str_replace(array("<", ">", "&", "(", ")", " ", "\"", "'"), "", $domain);
-
 
646
            $domain = urlencode($domain);
-
 
647
            foreach($this->_html_images as $i => $img){
-
 
648
                $this->_html_images[$i]['cid'] = $this->_html_images[$i]['cid'] . $domain;
458
    function &get($build_params = null)
649
            }
459
    {
650
        }
-
 
651
        
-
 
652
        if (count($this->_html_images) AND isset($this->_htmlbody)) {
460
        if (isset($build_params)) {
653
            foreach ($this->_html_images as $key => $value) {
461
            while (list($key, $value) = each($build_params)) {
654
                $regex   = array();
462
                $this->_build_params[$key] = $value;
655
                $regex[] = '#(\s)((?i)src|background|href(?-i))\s*=\s*(["\']?)' .
463
            }
656
                            preg_quote($value['name'], '#') . '\3#';
464
        }
657
                $regex[] = '#(?i)url(?-i)\(\s*(["\']?)' .
Line 465... Line 658...
465
 
658
                            preg_quote($value['name'], '#') . '\1\s*\)#';
466
        if (!empty($this->_html_images) AND isset($this->_htmlbody)) {
659
 
467
            foreach ($this->_html_images as $value) {
660
                $rep   = array();
468
                $regex = '#(\s)((?i)src|background|href(?-i))\s*=\s*(["\']?)' . preg_quote($value['name'], '#') .
661
                $rep[] = '\1\2=\3cid:' . $value['cid'] .'\3';
469
                         '\3#';
662
                $rep[] = 'url(\1cid:' . $value['cid'] . '\2)';
Line 470... Line 663...
470
                $rep = '\1\2=\3cid:' . $value['cid'] .'\3';
663
 
471
                $this->_htmlbody = preg_replace($regex, $rep,
664
                $this->_htmlbody = preg_replace($regex, $rep, $this->_htmlbody);
472
                                       $this->_htmlbody
665
                $this->_html_images[$key]['name'] = 
473
                                   );
666
                    basename($this->_html_images[$key]['name']);
Line 509... Line 702...
509
                $message =& $this->_addHtmlPart($null);
702
                $message =& $this->_addHtmlPart($null);
510
            }
703
            }
511
            break;
704
            break;
Line 512... Line 705...
512
 
705
 
-
 
706
        case $html AND !$attachments AND $html_images:
513
        case $html AND !$attachments AND $html_images:
707
            $message =& $this->_addRelatedPart($null);
514
            if (isset($this->_txtbody)) {
708
            if (isset($this->_txtbody)) {
515
                $message =& $this->_addAlternativePart($null);
709
                $alt =& $this->_addAlternativePart($message);
516
                $this->_addTextPart($message, $this->_txtbody);
710
                $this->_addTextPart($alt, $this->_txtbody);
517
                $related =& $this->_addRelatedPart($message);
711
                $this->_addHtmlPart($alt);
518
            } else {
-
 
519
                $message =& $this->_addRelatedPart($null);
712
            } else {
520
                $related =& $message;
713
                $this->_addHtmlPart($message);
521
            }
-
 
522
            $this->_addHtmlPart($related);
714
            }
523
            for ($i = 0; $i < count($this->_html_images); $i++) {
715
            for ($i = 0; $i < count($this->_html_images); $i++) {
524
                $this->_addHtmlImagePart($related, $this->_html_images[$i]);
716
                $this->_addHtmlImagePart($message, $this->_html_images[$i]);
525
            }
717
            }
Line 526... Line 718...
526
            break;
718
            break;
527
 
719
 
Line 559... Line 751...
559
 
751
 
Line 560... Line 752...
560
        }
752
        }
561
 
753
 
-
 
754
        if (isset($message)) {
562
        if (isset($message)) {
755
            $output = $message->encode();
563
            $output = $message->encode();
756
            
564
            $this->_headers = array_merge($this->_headers,
757
            $this->_headers = array_merge($this->_headers,
-
 
758
                                          $output['headers']);
Line 565... Line 759...
565
                                          $output['headers']);
759
            $body = $output['body'];
566
            return $output['body'];
760
            return $body;
-
 
761
 
567
 
762
        } else {
568
        } else {
763
            $ret = false;
Line 569... Line 764...
569
            return false;
764
            return $ret;
570
        }
765
        }
571
    }
766
    }
572
 
767
 
573
    /**
768
    /**
574
     * Returns an array with the headers needed to prepend to the email
769
     * Returns an array with the headers needed to prepend to the email
575
     * (MIME-Version and Content-Type). Format of argument is:
770
     * (MIME-Version and Content-Type). Format of argument is:
-
 
771
     * $array['header-name'] = 'header-value';
-
 
772
     *
576
     * $array['header-name'] = 'header-value';
773
     * @param array $xtra_headers Assoc array with any extra headers.
577
     *
774
     *                             Optional.
578
     * @param  array $xtra_headers Assoc array with any extra headers.
775
     * @param bool  $overwrite    Overwrite already existing headers.
579
     *                             Optional.
776
     * 
580
     * @return array Assoc array with the mime headers
777
     * @return array Assoc array with the mime headers
581
     * @access public
778
     * @access public
582
     */
779
     */
583
    function &headers($xtra_headers = null)
780
    function &headers($xtra_headers = null, $overwrite = false)
584
    {
781
    {
585
        // Content-Type header should already be present,
782
        // Content-Type header should already be present,
586
        // So just add mime version header
783
        // So just add mime version header
-
 
784
        $headers['MIME-Version'] = '1.0';
-
 
785
        if (isset($xtra_headers)) {
-
 
786
            $headers = array_merge($headers, $xtra_headers);
587
        $headers['MIME-Version'] = '1.0';
787
        }
-
 
788
        if ($overwrite) {
Line 588... Line 789...
588
        if (isset($xtra_headers)) {
789
            $this->_headers = array_merge($this->_headers, $headers);
-
 
790
        } else {
589
            $headers = array_merge($headers, $xtra_headers);
791
            $this->_headers = array_merge($headers, $this->_headers);
Line 590... Line 792...
590
        }
792
        }
591
        $this->_headers = array_merge($headers, $this->_headers);
793
 
592
 
794
        $encodedHeaders = $this->_encodeHeaders($this->_headers);
593
        return $this->_encodeHeaders($this->_headers);
795
        return $encodedHeaders;
594
    }
796
    }
595
 
797
 
-
 
798
    /**
-
 
799
     * Get the text version of the headers
596
    /**
800
     * (usefull if you want to use the PHP mail() function)
597
     * Get the text version of the headers
801
     *
598
     * (usefull if you want to use the PHP mail() function)
802
     * @param array $xtra_headers Assoc array with any extra headers.
599
     *
803
     *                             Optional.
600
     * @param  array   $xtra_headers Assoc array with any extra headers.
804
     * @param bool  $overwrite    Overwrite the existing heaers with new.
601
     *                               Optional.
805
     *
-
 
806
     * @return string  Plain text headers
602
     * @return string  Plain text headers
807
     * @access public
603
     * @access public
808
     */
604
     */
809
    function txtHeaders($xtra_headers = null, $overwrite = false)
605
    function txtHeaders($xtra_headers = null)
810
    {
606
    {
811
        $headers = $this->headers($xtra_headers, $overwrite);
607
        $headers = $this->headers($xtra_headers);
812
        
Line 608... Line 813...
608
        $ret = '';
813
        $ret = '';
609
        foreach ($headers as $key => $val) {
814
        foreach ($headers as $key => $val) {
610
            $ret .= "$key: $val" . MAIL_MIME_CRLF;
815
            $ret .= "$key: $val" . MAIL_MIME_CRLF;
611
        }
816
        }
-
 
817
        return $ret;
-
 
818
    }
612
        return $ret;
819
 
613
    }
820
    /**
614
 
821
     * Sets the Subject header
615
    /**
822
     *
616
     * Sets the Subject header
823
     * @param string $subject String to set the subject to.
617
     *
824
     *
Line 618... Line 825...
618
     * @param  string $subject String to set the subject to
825
     * @return void
619
     * access  public
826
     * @access public
620
     */
827
     */
621
    function setSubject($subject)
828
    function setSubject($subject)
-
 
829
    {
-
 
830
        $this->_headers['Subject'] = $subject;
622
    {
831
    }
623
        $this->_headers['Subject'] = $subject;
832
 
624
    }
833
    /**
625
 
834
     * Set an email to the From (the sender) header
626
    /**
835
     *
Line 636... Line 845...
636
 
845
 
637
    /**
846
    /**
638
     * Add an email to the Cc (carbon copy) header
847
     * Add an email to the Cc (carbon copy) header
639
     * (multiple calls to this method are allowed)
848
     * (multiple calls to this method are allowed)
640
     *
849
     *
-
 
850
     * @param string $email The email direction to add
-
 
851
     *
641
     * @param  string $email The email direction to add
852
     * @return void
642
     * @access public
853
     * @access public
643
     */
854
     */
644
    function addCc($email)
855
    function addCc($email)
645
    {
856
    {
Line 652... Line 863...
652
 
863
 
653
    /**
864
    /**
654
     * Add an email to the Bcc (blank carbon copy) header
865
     * Add an email to the Bcc (blank carbon copy) header
655
     * (multiple calls to this method are allowed)
866
     * (multiple calls to this method are allowed)
656
     *
867
     *
-
 
868
     * @param string $email The email direction to add
-
 
869
     *
657
     * @param  string $email The email direction to add
870
     * @return void
658
     * @access public
871
     * @access public
659
     */
872
     */
660
    function addBcc($email)
873
    function addBcc($email)
661
    {
874
    {
Line 665... Line 878...
665
            $this->_headers['Bcc'] = $email;
878
            $this->_headers['Bcc'] = $email;
666
        }
879
        }
667
    }
880
    }
Line 668... Line 881...
668
 
881
 
-
 
882
    /**
-
 
883
     * Since the PHP send function requires you to specifiy 
-
 
884
     * recipients (To: header) separately from the other
-
 
885
     * headers, the To: header is not properly encoded.
-
 
886
     * To fix this, you can use this public method to 
-
 
887
     * encode your recipients before sending to the send
-
 
888
     * function
-
 
889
     *
-
 
890
     * @param string $recipients A comma-delimited list of recipients
-
 
891
     *
-
 
892
     * @return string Encoded data
-
 
893
     * @access public
-
 
894
     */
-
 
895
    function encodeRecipients($recipients)
-
 
896
    {
-
 
897
        $input = array("To" => $recipients);
-
 
898
        $retval = $this->_encodeHeaders($input);
-
 
899
        return $retval["To"] ;
-
 
900
    }
-
 
901
 
669
    /**
902
    /**
670
     * Encodes a header as per RFC2047
903
     * Encodes a header as per RFC2047
671
     *
904
     *
-
 
905
     * @param array $input  The header data to encode
-
 
906
     * @param array $params Extra build parameters
672
     * @param  string  $input The header data to encode
907
     *
673
     * @return string  Encoded data
908
     * @return array Encoded data
674
     * @access private
909
     * @access private
675
     */
910
     */
676
    function _encodeHeaders($input)
911
    function _encodeHeaders($input, $params = array())
-
 
912
    {
-
 
913
        
-
 
914
        $build_params = $this->_build_params;
-
 
915
        while (list($key, $value) = each($params)) {
-
 
916
            $build_params[$key] = $value;
-
 
917
        }
-
 
918
        //$hdr_name: Name of the heaer
-
 
919
        //$hdr_value: Full line of header value.
-
 
920
        //$hdr_value_out: The recombined $hdr_val-atoms, or the encoded string.
-
 
921
                
-
 
922
        $useIconv = true;        
-
 
923
        if (isset($build_params['ignore-iconv'])) {
-
 
924
            $useIconv = !$build_params['ignore-iconv'];
677
    {
925
        }            
678
        foreach ($input as $hdr_name => $hdr_value) {
926
        foreach ($input as $hdr_name => $hdr_value) {
-
 
927
            if (preg_match('#([\x80-\xFF]){1}#', $hdr_value)) {
-
 
928
                if (function_exists('iconv_mime_encode') && $useIconv) {
-
 
929
                    $imePrefs = array();
-
 
930
                    if ($build_params['head_encoding'] == 'base64') {
-
 
931
                        $imePrefs['scheme'] = 'B';
-
 
932
                    } else {
-
 
933
                        $imePrefs['scheme'] = 'Q';
-
 
934
                    }
-
 
935
                    $imePrefs['input-charset']  = $build_params['head_charset'];
-
 
936
                    $imePrefs['output-charset'] = $build_params['head_charset'];
-
 
937
                    $imePrefs['line-length'] = 74;
-
 
938
                    $imePrefs['line-break-chars'] = "\r\n"; //Specified in RFC2047
-
 
939
                    
-
 
940
                    $hdr_value = iconv_mime_encode($hdr_name, $hdr_value, $imePrefs);
-
 
941
                    $hdr_value = preg_replace("#^{$hdr_name}\:\ #", "", $hdr_value);
-
 
942
                } elseif ($build_params['head_encoding'] == 'base64') {
-
 
943
                    //Base64 encoding has been selected.
-
 
944
                    //Base64 encode the entire string
-
 
945
                    $hdr_value = base64_encode($hdr_value);
-
 
946
                    
-
 
947
                    //Generate the header using the specified params and dynamicly 
-
 
948
                    //determine the maximum length of such strings.
-
 
949
                    //75 is the value specified in the RFC. The first -2 is there so 
-
 
950
                    //the later regexp doesn't break any of the translated chars.
-
 
951
                    //The -2 on the first line-regexp is to compensate for the ": "
-
 
952
                    //between the header-name and the header value
-
 
953
                    $prefix = '=?' . $build_params['head_charset'] . '?B?';
-
 
954
                    $suffix = '?=';
-
 
955
                    $maxLength = 75 - strlen($prefix . $suffix) - 2;
-
 
956
                    $maxLength1stLine = $maxLength - strlen($hdr_name) - 2;
-
 
957
 
-
 
958
                    //We can cut base4 every 4 characters, so the real max
-
 
959
                    //we can get must be rounded down.
-
 
960
                    $maxLength = $maxLength - ($maxLength % 4);
-
 
961
                    $maxLength1stLine = $maxLength1stLine - ($maxLength1stLine % 4);
-
 
962
                    
-
 
963
                    $cutpoint = $maxLength1stLine;
-
 
964
                    $hdr_value_out = $hdr_value;
-
 
965
                    $output = "";
-
 
966
                    while ($hdr_value_out) {
-
 
967
                        //Split translated string at every $maxLength
-
 
968
                        $part = substr($hdr_value_out, 0, $cutpoint);
-
 
969
                        $hdr_value_out = substr($hdr_value_out, $cutpoint);
-
 
970
                        $cutpoint = $maxLength;
-
 
971
                        //RFC 2047 specifies that any split header should 
-
 
972
                        //be seperated by a CRLF SPACE. 
-
 
973
                        if ($output) {
-
 
974
                            $output .=  "\r\n ";
-
 
975
                        }
-
 
976
                        $output .= $prefix . $part . $suffix;
-
 
977
                    }
-
 
978
                    $hdr_value = $output;
-
 
979
                } else {
-
 
980
                    //quoted-printable encoding has been selected
-
 
981
 
-
 
982
                    //Fix for Bug #10298, Ota Mares <om@viazenetti.de>
-
 
983
                    //Check if there is a double quote at beginning or end of
-
 
984
                    //the string to prevent that an open or closing quote gets 
-
 
985
                    //ignored because it is encapsuled by an encoding pre/suffix.
-
 
986
                    //Remove the double quote and set the specific prefix or 
-
 
987
                    //suffix variable so that we can concat the encoded string and
-
 
988
                    //the double quotes back together to get the intended string.
-
 
989
                    $quotePrefix = $quoteSuffix = '';
-
 
990
                    if ($hdr_value{0} == '"') {
-
 
991
                        $hdr_value = substr($hdr_value, 1);
-
 
992
                        $quotePrefix = '"';
-
 
993
                    }
-
 
994
                    if ($hdr_value{strlen($hdr_value)-1} == '"') {
-
 
995
                        $hdr_value = substr($hdr_value, 0, -1);
-
 
996
                        $quoteSuffix = '"';
-
 
997
                    }
-
 
998
                    
-
 
999
                    //Generate the header using the specified params and dynamicly 
-
 
1000
                    //determine the maximum length of such strings.
-
 
1001
                    //75 is the value specified in the RFC. The -2 is there so 
-
 
1002
                    //the later regexp doesn't break any of the translated chars.
-
 
1003
                    //The -2 on the first line-regexp is to compensate for the ": "
-
 
1004
                    //between the header-name and the header value
-
 
1005
                    $prefix = '=?' . $build_params['head_charset'] . '?Q?';
-
 
1006
                    $suffix = '?=';
-
 
1007
                    $maxLength = 75 - strlen($prefix . $suffix) - 2 - 1;
679
            preg_match_all('/(\w*[\x80-\xFF]+\w*)/', $hdr_value, $matches);
1008
                    $maxLength1stLine = $maxLength - strlen($hdr_name) - 2;
-
 
1009
                    $maxLength = $maxLength - 1;
-
 
1010
                    
-
 
1011
                    //Replace all special characters used by the encoder.
-
 
1012
                    $search  = array('=',   '_',   '?',   ' ');
-
 
1013
                    $replace = array('=3D', '=5F', '=3F', '_');
-
 
1014
                    $hdr_value = str_replace($search, $replace, $hdr_value);
-
 
1015
                    
-
 
1016
                    //Replace all extended characters (\x80-xFF) with their
680
            foreach ($matches[1] as $value) {
1017
                    //ASCII values.
-
 
1018
                    $hdr_value = preg_replace('#([\x80-\xFF])#e',
-
 
1019
                        '"=" . strtoupper(dechex(ord("\1")))',
-
 
1020
                        $hdr_value);
-
 
1021
 
-
 
1022
                    //This regexp will break QP-encoded text at every $maxLength
-
 
1023
                    //but will not break any encoded letters.
-
 
1024
                    $reg1st = "|(.{0,$maxLength1stLine}[^\=][^\=])|";
-
 
1025
                    $reg2nd = "|(.{0,$maxLength}[^\=][^\=])|";
-
 
1026
                    //Fix for Bug #10298, Ota Mares <om@viazenetti.de>
-
 
1027
                    //Concat the double quotes and encoded string together
-
 
1028
                    $hdr_value = $quotePrefix . $hdr_value . $quoteSuffix;
-
 
1029
                    
-
 
1030
 
-
 
1031
                    $hdr_value_out = $hdr_value;
-
 
1032
                    $realMax = $maxLength1stLine + strlen($prefix . $suffix);
-
 
1033
                    if (strlen($hdr_value_out) >= $realMax) {
-
 
1034
                        //Begin with the regexp for the first line.
-
 
1035
                        $reg = $reg1st;
-
 
1036
                        $output = "";
-
 
1037
                        while ($hdr_value_out) {
-
 
1038
                            //Split translated string at every $maxLength
-
 
1039
                            //But make sure not to break any translated chars.
-
 
1040
                            $found = preg_match($reg, $hdr_value_out, $matches);
-
 
1041
                            
-
 
1042
                            //After this first line, we need to use a different
-
 
1043
                            //regexp for the first line.
-
 
1044
                            $reg = $reg2nd;
-
 
1045
                            
-
 
1046
                            //Save the found part and encapsulate it in the
-
 
1047
                            //prefix & suffix. Then remove the part from the
-
 
1048
                            //$hdr_value_out variable.
681
                $replacement = preg_replace('/([\x80-\xFF])/e',
1049
                            if ($found) {
682
                                            '"=" .
1050
                                $part = $matches[0];
-
 
1051
                                $len = strlen($matches[0]);
-
 
1052
                                $hdr_value_out = substr($hdr_value_out, $len);
683
                                            strtoupper(dechex(ord("\1")))',
1053
                            } else {
684
                                            $value);
1054
                                $part = $hdr_value_out;
-
 
1055
                                $hdr_value_out = "";
-
 
1056
                            }
685
                $hdr_value = str_replace($value, '=?' .
1057
                            
-
 
1058
                            //RFC 2047 specifies that any split header should 
-
 
1059
                            //be seperated by a CRLF SPACE
-
 
1060
                            if ($output) {
-
 
1061
                                $output .=  "\r\n ";
686
                                         $this->_build_params['head_charset'] .
1062
                            }
-
 
1063
                            $output .= $prefix . $part . $suffix;
-
 
1064
                        }
-
 
1065
                        $hdr_value_out = $output;
-
 
1066
                    } else {
-
 
1067
                        $hdr_value_out = $prefix . $hdr_value_out . $suffix;
687
                                         '?Q?' . $replacement . '?=',
1068
                    }
-
 
1069
                    $hdr_value = $hdr_value_out;
688
                                         $hdr_value);
1070
                }
689
            }
1071
            }
690
            $input[$hdr_name] = $hdr_value;
1072
            $input[$hdr_name] = $hdr_value;
691
        }
-
 
692
 
1073
        }
693
        return $input;
1074
        return $input;
Line 694... Line 1075...
694
    }
1075
    }
695
 
1076
 
696
    /**
1077
    /**
697
     * Set the object's end-of-line and define the constant if applicable
1078
     * Set the object's end-of-line and define the constant if applicable.
-
 
1079
     *
-
 
1080
     * @param string $eol End Of Line sequence
698
     *
1081
     *
699
     * @param string $eol End Of Line sequence
1082
     * @return void
700
     * @access private
1083
     * @access private
701
     */
1084
     */
702
    function _setEOL($eol)
1085
    function _setEOL($eol)
Line 708... Line 1091...
708
    }
1091
    }
Line 709... Line 1092...
709
 
1092
 
710
    
-