|
0
|
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 |
|
|
|
12 |
/** |
|
|
13 |
* Handles Quoted Printable (QP) Transfer Encoding in Swift Mailer. |
|
|
14 |
* @package Swift |
|
|
15 |
* @subpackage Mime |
|
|
16 |
* @author Chris Corbyn |
|
|
17 |
*/ |
|
|
18 |
class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder |
|
|
19 |
implements Swift_Mime_ContentEncoder |
|
|
20 |
{ |
|
|
21 |
|
|
|
22 |
/** |
|
|
23 |
* Creates a new QpContentEncoder for the given CharacterStream. |
|
|
24 |
* @param Swift_CharacterStream $charStream to use for reading characters |
|
|
25 |
* @param Swift_StreamFilter $filter if canonicalization should occur |
|
|
26 |
* @param boolean $dotEscape if dot stuffing workaround must be enabled |
|
|
27 |
*/ |
|
|
28 |
public function __construct(Swift_CharacterStream $charStream, |
|
|
29 |
Swift_StreamFilter $filter = null, $dotEscape=false) |
|
|
30 |
{ |
|
|
31 |
parent::__construct($charStream, $filter); |
|
|
32 |
if ($dotEscape) { |
|
|
33 |
/* Encode . as =2e for buggy remote servers */ |
|
|
34 |
unset($this->_safeMap[0x2e]); |
|
|
35 |
} |
|
|
36 |
} |
|
|
37 |
|
|
|
38 |
/** |
|
|
39 |
* Encode stream $in to stream $out. |
|
|
40 |
* QP encoded strings have a maximum line length of 76 characters. |
|
|
41 |
* If the first line needs to be shorter, indicate the difference with |
|
|
42 |
* $firstLineOffset. |
|
|
43 |
* @param Swift_OutputByteStream $os output stream |
|
|
44 |
* @param Swift_InputByteStream $is input stream |
|
|
45 |
* @param int $firstLineOffset |
|
|
46 |
* @param int $maxLineLength |
|
|
47 |
*/ |
|
|
48 |
public function encodeByteStream( |
|
|
49 |
Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, |
|
|
50 |
$maxLineLength = 0) |
|
|
51 |
{ |
|
|
52 |
if ($maxLineLength > 76 || $maxLineLength <= 0) |
|
|
53 |
{ |
|
|
54 |
$maxLineLength = 76; |
|
|
55 |
} |
|
|
56 |
|
|
|
57 |
$thisLineLength = $maxLineLength - $firstLineOffset; |
|
|
58 |
|
|
|
59 |
$this->_charStream->flushContents(); |
|
|
60 |
$this->_charStream->importByteStream($os); |
|
|
61 |
|
|
|
62 |
$currentLine = ''; |
|
|
63 |
$prepend = ''; |
|
|
64 |
$size=$lineLen=0; |
|
|
65 |
|
|
|
66 |
while (false !== $bytes = $this->_nextSequence()) |
|
|
67 |
{ |
|
|
68 |
//If we're filtering the input |
|
|
69 |
if (isset($this->_filter)) |
|
|
70 |
{ |
|
|
71 |
//If we can't filter because we need more bytes |
|
|
72 |
while ($this->_filter->shouldBuffer($bytes)) |
|
|
73 |
{ |
|
|
74 |
//Then collect bytes into the buffer |
|
|
75 |
if (false === $moreBytes = $this->_nextSequence(1)) |
|
|
76 |
{ |
|
|
77 |
break; |
|
|
78 |
} |
|
|
79 |
|
|
|
80 |
foreach ($moreBytes as $b) |
|
|
81 |
{ |
|
|
82 |
$bytes[] = $b; |
|
|
83 |
} |
|
|
84 |
} |
|
|
85 |
//And filter them |
|
|
86 |
$bytes = $this->_filter->filter($bytes); |
|
|
87 |
} |
|
|
88 |
|
|
|
89 |
$enc = $this->_encodeByteSequence($bytes, $size); |
|
|
90 |
if ($currentLine && $lineLen+$size >= $thisLineLength) |
|
|
91 |
{ |
|
|
92 |
$is->write($prepend . $this->_standardize($currentLine)); |
|
|
93 |
$currentLine = ''; |
|
|
94 |
$prepend = "=\r\n"; |
|
|
95 |
$thisLineLength = $maxLineLength; |
|
|
96 |
$lineLen=0; |
|
|
97 |
} |
|
|
98 |
$lineLen+=$size; |
|
|
99 |
$currentLine .= $enc; |
|
|
100 |
} |
|
|
101 |
if (strlen($currentLine)) |
|
|
102 |
{ |
|
|
103 |
$is->write($prepend . $this->_standardize($currentLine)); |
|
|
104 |
} |
|
|
105 |
} |
|
|
106 |
|
|
|
107 |
/** |
|
|
108 |
* Get the name of this encoding scheme. |
|
|
109 |
* Returns the string 'quoted-printable'. |
|
|
110 |
* @return string |
|
|
111 |
*/ |
|
|
112 |
public function getName() |
|
|
113 |
{ |
|
|
114 |
return 'quoted-printable'; |
|
|
115 |
} |
|
|
116 |
|
|
|
117 |
} |