1 | <?php |
||
18 | class Swift_Mime_HeaderEncoder_Base64HeaderEncoder extends Swift_Encoder_Base64Encoder implements Swift_Mime_HeaderEncoder |
||
|
|||
19 | { |
||
20 | /** |
||
21 | * Get the name of this encoding scheme. |
||
22 | * Returns the string 'B'. |
||
23 | * |
||
24 | * @return string |
||
25 | */ |
||
26 | 2 | public function getName() |
|
30 | |||
31 | /** |
||
32 | * Takes an unencoded string and produces a Base64 encoded string from it. |
||
33 | * |
||
34 | * If the charset is iso-2022-jp, it uses mb_encode_mimeheader instead of |
||
35 | * default encodeString, otherwise pass to the parent method. |
||
36 | * |
||
37 | * @param string $string string to encode |
||
38 | * @param int $firstLineOffset |
||
39 | * @param int $maxLineLength optional, 0 indicates the default of 76 bytes |
||
40 | * @param string $charset |
||
41 | * |
||
42 | * @return string |
||
43 | */ |
||
44 | 1 | public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0, $charset = 'utf-8') |
|
45 | { |
||
46 | 1 | if (Swift::strtolowerWithStaticCache($charset) === 'iso-2022-jp') { |
|
47 | 1 | UTF8::checkForSupport(); |
|
48 | |||
49 | 1 | $old = mb_internal_encoding(); |
|
50 | |||
51 | 1 | mb_internal_encoding('utf-8'); |
|
52 | 1 | $newString = mb_encode_mimeheader($string, $charset, $this->getName(), "\r\n"); |
|
53 | |||
54 | 1 | mb_internal_encoding($old); |
|
55 | |||
56 | 1 | return $newString; |
|
57 | } |
||
58 | |||
59 | // safety measure copy-pasted from parent method |
||
60 | if (0 >= $maxLineLength || 76 < $maxLineLength) { |
||
61 | $maxLineLength = 76; |
||
62 | } |
||
63 | |||
64 | $cursorPosition = 0; |
||
65 | $encoded = ''; |
||
66 | while ($cursorPosition < strlen($string)) { |
||
67 | $maxChunkLength = $this->maxChunkLength($firstLineOffset, $maxLineLength); |
||
68 | if ($cursorPosition > 0 || $firstLineOffset > $maxChunkLength) { |
||
69 | $encoded .= "\r\n"; |
||
70 | $maxChunkLength = $this->maxChunkLength(0, $maxLineLength); |
||
71 | } |
||
72 | $chunk = mb_strcut($string, $cursorPosition, $maxChunkLength); |
||
73 | $encoded .= base64_encode($chunk); |
||
74 | $cursorPosition += strlen($chunk); |
||
75 | } |
||
76 | |||
77 | return $encoded; |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Returns maximum number of bytes that can fit in a line with given |
||
82 | * offset and maximum length if encoded with base64 |
||
83 | * |
||
84 | * @param int $firstLineOffset |
||
85 | * @param int $maxLineLength |
||
86 | * |
||
87 | * @return int |
||
88 | */ |
||
89 | private function maxChunkLength($firstLineOffset, $maxLineLength) |
||
93 | } |
||
94 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.