|
1 <?php |
|
2 |
|
3 /* |
|
4 * This file is part of SwiftMailer. |
|
5 * (c) 2004-2009 Chris Corbyn |
|
6 * |
|
7 * For the full copyright and license information, please view the LICENSE |
|
8 * file that was distributed with this source code. |
|
9 */ |
|
10 |
|
11 require_once dirname(__FILE__) . '/../HeaderEncoder.php'; |
|
12 require_once dirname(__FILE__) . '/../../Encoder/QpEncoder.php'; |
|
13 require_once dirname(__FILE__) . '/../../CharacterStream.php'; |
|
14 |
|
15 /** |
|
16 * Handles Quoted Printable (Q) Header Encoding in Swift Mailer. |
|
17 * @package Swift |
|
18 * @subpackage Mime |
|
19 * @author Chris Corbyn |
|
20 */ |
|
21 class Swift_Mime_HeaderEncoder_QpHeaderEncoder extends Swift_Encoder_QpEncoder |
|
22 implements Swift_Mime_HeaderEncoder |
|
23 { |
|
24 |
|
25 /** |
|
26 * Creates a new QpHeaderEncoder for the given CharacterStream. |
|
27 * @param Swift_CharacterStream $charStream to use for reading characters |
|
28 */ |
|
29 public function __construct(Swift_CharacterStream $charStream) |
|
30 { |
|
31 parent::__construct($charStream); |
|
32 // Reset the safeMap |
|
33 $this->_safeMap=array(); |
|
34 foreach (array_merge( |
|
35 range(0x61, 0x7A), range(0x41, 0x5A), |
|
36 range(0x30, 0x39), array(0x20, 0x21, 0x2A, 0x2B, 0x2D, 0x2F) |
|
37 ) as $byte) |
|
38 { |
|
39 $this->_safeMap[$byte] = chr($byte); |
|
40 } |
|
41 } |
|
42 |
|
43 /** |
|
44 * Get the name of this encoding scheme. |
|
45 * Returns the string 'Q'. |
|
46 * @return string |
|
47 */ |
|
48 public function getName() |
|
49 { |
|
50 return 'Q'; |
|
51 } |
|
52 |
|
53 /** |
|
54 * Takes an unencoded string and produces a Q encoded string from it. |
|
55 * @param string $string to encode |
|
56 * @param int $firstLineOffset, optional |
|
57 * @param int $maxLineLength, optional, 0 indicates the default of 76 chars |
|
58 * @return string |
|
59 */ |
|
60 public function encodeString($string, $firstLineOffset = 0, |
|
61 $maxLineLength = 0) |
|
62 { |
|
63 return str_replace(array(' ', '=20', "=\r\n"), array('_', '_', "\r\n"), |
|
64 parent::encodeString($string, $firstLineOffset, $maxLineLength) |
|
65 ); |
|
66 } |
|
67 |
|
68 } |