@@ -16,17 +16,17 @@ |
||
16 | 16 | */ |
17 | 17 | class Swift_AddressEncoderException extends Swift_RfcComplianceException |
18 | 18 | { |
19 | - protected $address; |
|
19 | + protected $address; |
|
20 | 20 | |
21 | - public function __construct(string $message, string $address) |
|
22 | - { |
|
23 | - parent::__construct($message); |
|
21 | + public function __construct(string $message, string $address) |
|
22 | + { |
|
23 | + parent::__construct($message); |
|
24 | 24 | |
25 | - $this->address = $address; |
|
26 | - } |
|
25 | + $this->address = $address; |
|
26 | + } |
|
27 | 27 | |
28 | - public function getAddress(): string |
|
29 | - { |
|
30 | - return $this->address; |
|
31 | - } |
|
28 | + public function getAddress(): string |
|
29 | + { |
|
30 | + return $this->address; |
|
31 | + } |
|
32 | 32 | } |
@@ -16,82 +16,82 @@ |
||
16 | 16 | */ |
17 | 17 | class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterReader |
18 | 18 | { |
19 | - /** |
|
20 | - * The number of bytes in a single character. |
|
21 | - * |
|
22 | - * @var int |
|
23 | - */ |
|
24 | - private $width; |
|
19 | + /** |
|
20 | + * The number of bytes in a single character. |
|
21 | + * |
|
22 | + * @var int |
|
23 | + */ |
|
24 | + private $width; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Creates a new GenericFixedWidthReader using $width bytes per character. |
|
28 | - * |
|
29 | - * @param int $width |
|
30 | - */ |
|
31 | - public function __construct($width) |
|
32 | - { |
|
33 | - $this->width = $width; |
|
34 | - } |
|
26 | + /** |
|
27 | + * Creates a new GenericFixedWidthReader using $width bytes per character. |
|
28 | + * |
|
29 | + * @param int $width |
|
30 | + */ |
|
31 | + public function __construct($width) |
|
32 | + { |
|
33 | + $this->width = $width; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Returns the complete character map. |
|
38 | - * |
|
39 | - * @param string $string |
|
40 | - * @param int $startOffset |
|
41 | - * @param array $currentMap |
|
42 | - * @param mixed $ignoredChars |
|
43 | - * |
|
44 | - * @return int |
|
45 | - */ |
|
46 | - public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars) |
|
47 | - { |
|
48 | - $strlen = \strlen($string); |
|
49 | - // % and / are CPU intensive, so, maybe find a better way |
|
50 | - $ignored = $strlen % $this->width; |
|
51 | - $ignoredChars = $ignored ? substr($string, -$ignored) : ''; |
|
52 | - $currentMap = $this->width; |
|
36 | + /** |
|
37 | + * Returns the complete character map. |
|
38 | + * |
|
39 | + * @param string $string |
|
40 | + * @param int $startOffset |
|
41 | + * @param array $currentMap |
|
42 | + * @param mixed $ignoredChars |
|
43 | + * |
|
44 | + * @return int |
|
45 | + */ |
|
46 | + public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars) |
|
47 | + { |
|
48 | + $strlen = \strlen($string); |
|
49 | + // % and / are CPU intensive, so, maybe find a better way |
|
50 | + $ignored = $strlen % $this->width; |
|
51 | + $ignoredChars = $ignored ? substr($string, -$ignored) : ''; |
|
52 | + $currentMap = $this->width; |
|
53 | 53 | |
54 | - return ($strlen - $ignored) / $this->width; |
|
55 | - } |
|
54 | + return ($strlen - $ignored) / $this->width; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Returns the mapType. |
|
59 | - * |
|
60 | - * @return int |
|
61 | - */ |
|
62 | - public function getMapType() |
|
63 | - { |
|
64 | - return self::MAP_TYPE_FIXED_LEN; |
|
65 | - } |
|
57 | + /** |
|
58 | + * Returns the mapType. |
|
59 | + * |
|
60 | + * @return int |
|
61 | + */ |
|
62 | + public function getMapType() |
|
63 | + { |
|
64 | + return self::MAP_TYPE_FIXED_LEN; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Returns an integer which specifies how many more bytes to read. |
|
69 | - * |
|
70 | - * A positive integer indicates the number of more bytes to fetch before invoking |
|
71 | - * this method again. |
|
72 | - * |
|
73 | - * A value of zero means this is already a valid character. |
|
74 | - * A value of -1 means this cannot possibly be a valid character. |
|
75 | - * |
|
76 | - * @param string $bytes |
|
77 | - * @param int $size |
|
78 | - * |
|
79 | - * @return int |
|
80 | - */ |
|
81 | - public function validateByteSequence($bytes, $size) |
|
82 | - { |
|
83 | - $needed = $this->width - $size; |
|
67 | + /** |
|
68 | + * Returns an integer which specifies how many more bytes to read. |
|
69 | + * |
|
70 | + * A positive integer indicates the number of more bytes to fetch before invoking |
|
71 | + * this method again. |
|
72 | + * |
|
73 | + * A value of zero means this is already a valid character. |
|
74 | + * A value of -1 means this cannot possibly be a valid character. |
|
75 | + * |
|
76 | + * @param string $bytes |
|
77 | + * @param int $size |
|
78 | + * |
|
79 | + * @return int |
|
80 | + */ |
|
81 | + public function validateByteSequence($bytes, $size) |
|
82 | + { |
|
83 | + $needed = $this->width - $size; |
|
84 | 84 | |
85 | - return $needed > -1 ? $needed : -1; |
|
86 | - } |
|
85 | + return $needed > -1 ? $needed : -1; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Returns the number of bytes which should be read to start each character. |
|
90 | - * |
|
91 | - * @return int |
|
92 | - */ |
|
93 | - public function getInitialByteSize() |
|
94 | - { |
|
95 | - return $this->width; |
|
96 | - } |
|
88 | + /** |
|
89 | + * Returns the number of bytes which should be read to start each character. |
|
90 | + * |
|
91 | + * @return int |
|
92 | + */ |
|
93 | + public function getInitialByteSize() |
|
94 | + { |
|
95 | + return $this->width; |
|
96 | + } |
|
97 | 97 | } |
@@ -16,161 +16,161 @@ |
||
16 | 16 | */ |
17 | 17 | class Swift_CharacterReader_Utf8Reader implements Swift_CharacterReader |
18 | 18 | { |
19 | - /** Pre-computed for optimization */ |
|
20 | - private static $length_map = [ |
|
21 | - // N=0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F |
|
22 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x0N |
|
23 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x1N |
|
24 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x2N |
|
25 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x3N |
|
26 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x4N |
|
27 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x5N |
|
28 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x6N |
|
29 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x7N |
|
30 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x8N |
|
31 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x9N |
|
32 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xAN |
|
33 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xBN |
|
34 | - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xCN |
|
35 | - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xDN |
|
36 | - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 0xEN |
|
37 | - 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 0, 0, // 0xFN |
|
38 | - ]; |
|
19 | + /** Pre-computed for optimization */ |
|
20 | + private static $length_map = [ |
|
21 | + // N=0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F |
|
22 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x0N |
|
23 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x1N |
|
24 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x2N |
|
25 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x3N |
|
26 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x4N |
|
27 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x5N |
|
28 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x6N |
|
29 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x7N |
|
30 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x8N |
|
31 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x9N |
|
32 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xAN |
|
33 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xBN |
|
34 | + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xCN |
|
35 | + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xDN |
|
36 | + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 0xEN |
|
37 | + 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 0, 0, // 0xFN |
|
38 | + ]; |
|
39 | 39 | |
40 | - private static $s_length_map = [ |
|
41 | - "\x00" => 1, "\x01" => 1, "\x02" => 1, "\x03" => 1, "\x04" => 1, "\x05" => 1, "\x06" => 1, "\x07" => 1, |
|
42 | - "\x08" => 1, "\x09" => 1, "\x0a" => 1, "\x0b" => 1, "\x0c" => 1, "\x0d" => 1, "\x0e" => 1, "\x0f" => 1, |
|
43 | - "\x10" => 1, "\x11" => 1, "\x12" => 1, "\x13" => 1, "\x14" => 1, "\x15" => 1, "\x16" => 1, "\x17" => 1, |
|
44 | - "\x18" => 1, "\x19" => 1, "\x1a" => 1, "\x1b" => 1, "\x1c" => 1, "\x1d" => 1, "\x1e" => 1, "\x1f" => 1, |
|
45 | - "\x20" => 1, "\x21" => 1, "\x22" => 1, "\x23" => 1, "\x24" => 1, "\x25" => 1, "\x26" => 1, "\x27" => 1, |
|
46 | - "\x28" => 1, "\x29" => 1, "\x2a" => 1, "\x2b" => 1, "\x2c" => 1, "\x2d" => 1, "\x2e" => 1, "\x2f" => 1, |
|
47 | - "\x30" => 1, "\x31" => 1, "\x32" => 1, "\x33" => 1, "\x34" => 1, "\x35" => 1, "\x36" => 1, "\x37" => 1, |
|
48 | - "\x38" => 1, "\x39" => 1, "\x3a" => 1, "\x3b" => 1, "\x3c" => 1, "\x3d" => 1, "\x3e" => 1, "\x3f" => 1, |
|
49 | - "\x40" => 1, "\x41" => 1, "\x42" => 1, "\x43" => 1, "\x44" => 1, "\x45" => 1, "\x46" => 1, "\x47" => 1, |
|
50 | - "\x48" => 1, "\x49" => 1, "\x4a" => 1, "\x4b" => 1, "\x4c" => 1, "\x4d" => 1, "\x4e" => 1, "\x4f" => 1, |
|
51 | - "\x50" => 1, "\x51" => 1, "\x52" => 1, "\x53" => 1, "\x54" => 1, "\x55" => 1, "\x56" => 1, "\x57" => 1, |
|
52 | - "\x58" => 1, "\x59" => 1, "\x5a" => 1, "\x5b" => 1, "\x5c" => 1, "\x5d" => 1, "\x5e" => 1, "\x5f" => 1, |
|
53 | - "\x60" => 1, "\x61" => 1, "\x62" => 1, "\x63" => 1, "\x64" => 1, "\x65" => 1, "\x66" => 1, "\x67" => 1, |
|
54 | - "\x68" => 1, "\x69" => 1, "\x6a" => 1, "\x6b" => 1, "\x6c" => 1, "\x6d" => 1, "\x6e" => 1, "\x6f" => 1, |
|
55 | - "\x70" => 1, "\x71" => 1, "\x72" => 1, "\x73" => 1, "\x74" => 1, "\x75" => 1, "\x76" => 1, "\x77" => 1, |
|
56 | - "\x78" => 1, "\x79" => 1, "\x7a" => 1, "\x7b" => 1, "\x7c" => 1, "\x7d" => 1, "\x7e" => 1, "\x7f" => 1, |
|
57 | - "\x80" => 0, "\x81" => 0, "\x82" => 0, "\x83" => 0, "\x84" => 0, "\x85" => 0, "\x86" => 0, "\x87" => 0, |
|
58 | - "\x88" => 0, "\x89" => 0, "\x8a" => 0, "\x8b" => 0, "\x8c" => 0, "\x8d" => 0, "\x8e" => 0, "\x8f" => 0, |
|
59 | - "\x90" => 0, "\x91" => 0, "\x92" => 0, "\x93" => 0, "\x94" => 0, "\x95" => 0, "\x96" => 0, "\x97" => 0, |
|
60 | - "\x98" => 0, "\x99" => 0, "\x9a" => 0, "\x9b" => 0, "\x9c" => 0, "\x9d" => 0, "\x9e" => 0, "\x9f" => 0, |
|
61 | - "\xa0" => 0, "\xa1" => 0, "\xa2" => 0, "\xa3" => 0, "\xa4" => 0, "\xa5" => 0, "\xa6" => 0, "\xa7" => 0, |
|
62 | - "\xa8" => 0, "\xa9" => 0, "\xaa" => 0, "\xab" => 0, "\xac" => 0, "\xad" => 0, "\xae" => 0, "\xaf" => 0, |
|
63 | - "\xb0" => 0, "\xb1" => 0, "\xb2" => 0, "\xb3" => 0, "\xb4" => 0, "\xb5" => 0, "\xb6" => 0, "\xb7" => 0, |
|
64 | - "\xb8" => 0, "\xb9" => 0, "\xba" => 0, "\xbb" => 0, "\xbc" => 0, "\xbd" => 0, "\xbe" => 0, "\xbf" => 0, |
|
65 | - "\xc0" => 2, "\xc1" => 2, "\xc2" => 2, "\xc3" => 2, "\xc4" => 2, "\xc5" => 2, "\xc6" => 2, "\xc7" => 2, |
|
66 | - "\xc8" => 2, "\xc9" => 2, "\xca" => 2, "\xcb" => 2, "\xcc" => 2, "\xcd" => 2, "\xce" => 2, "\xcf" => 2, |
|
67 | - "\xd0" => 2, "\xd1" => 2, "\xd2" => 2, "\xd3" => 2, "\xd4" => 2, "\xd5" => 2, "\xd6" => 2, "\xd7" => 2, |
|
68 | - "\xd8" => 2, "\xd9" => 2, "\xda" => 2, "\xdb" => 2, "\xdc" => 2, "\xdd" => 2, "\xde" => 2, "\xdf" => 2, |
|
69 | - "\xe0" => 3, "\xe1" => 3, "\xe2" => 3, "\xe3" => 3, "\xe4" => 3, "\xe5" => 3, "\xe6" => 3, "\xe7" => 3, |
|
70 | - "\xe8" => 3, "\xe9" => 3, "\xea" => 3, "\xeb" => 3, "\xec" => 3, "\xed" => 3, "\xee" => 3, "\xef" => 3, |
|
71 | - "\xf0" => 4, "\xf1" => 4, "\xf2" => 4, "\xf3" => 4, "\xf4" => 4, "\xf5" => 4, "\xf6" => 4, "\xf7" => 4, |
|
72 | - "\xf8" => 5, "\xf9" => 5, "\xfa" => 5, "\xfb" => 5, "\xfc" => 6, "\xfd" => 6, "\xfe" => 0, "\xff" => 0, |
|
73 | - ]; |
|
40 | + private static $s_length_map = [ |
|
41 | + "\x00" => 1, "\x01" => 1, "\x02" => 1, "\x03" => 1, "\x04" => 1, "\x05" => 1, "\x06" => 1, "\x07" => 1, |
|
42 | + "\x08" => 1, "\x09" => 1, "\x0a" => 1, "\x0b" => 1, "\x0c" => 1, "\x0d" => 1, "\x0e" => 1, "\x0f" => 1, |
|
43 | + "\x10" => 1, "\x11" => 1, "\x12" => 1, "\x13" => 1, "\x14" => 1, "\x15" => 1, "\x16" => 1, "\x17" => 1, |
|
44 | + "\x18" => 1, "\x19" => 1, "\x1a" => 1, "\x1b" => 1, "\x1c" => 1, "\x1d" => 1, "\x1e" => 1, "\x1f" => 1, |
|
45 | + "\x20" => 1, "\x21" => 1, "\x22" => 1, "\x23" => 1, "\x24" => 1, "\x25" => 1, "\x26" => 1, "\x27" => 1, |
|
46 | + "\x28" => 1, "\x29" => 1, "\x2a" => 1, "\x2b" => 1, "\x2c" => 1, "\x2d" => 1, "\x2e" => 1, "\x2f" => 1, |
|
47 | + "\x30" => 1, "\x31" => 1, "\x32" => 1, "\x33" => 1, "\x34" => 1, "\x35" => 1, "\x36" => 1, "\x37" => 1, |
|
48 | + "\x38" => 1, "\x39" => 1, "\x3a" => 1, "\x3b" => 1, "\x3c" => 1, "\x3d" => 1, "\x3e" => 1, "\x3f" => 1, |
|
49 | + "\x40" => 1, "\x41" => 1, "\x42" => 1, "\x43" => 1, "\x44" => 1, "\x45" => 1, "\x46" => 1, "\x47" => 1, |
|
50 | + "\x48" => 1, "\x49" => 1, "\x4a" => 1, "\x4b" => 1, "\x4c" => 1, "\x4d" => 1, "\x4e" => 1, "\x4f" => 1, |
|
51 | + "\x50" => 1, "\x51" => 1, "\x52" => 1, "\x53" => 1, "\x54" => 1, "\x55" => 1, "\x56" => 1, "\x57" => 1, |
|
52 | + "\x58" => 1, "\x59" => 1, "\x5a" => 1, "\x5b" => 1, "\x5c" => 1, "\x5d" => 1, "\x5e" => 1, "\x5f" => 1, |
|
53 | + "\x60" => 1, "\x61" => 1, "\x62" => 1, "\x63" => 1, "\x64" => 1, "\x65" => 1, "\x66" => 1, "\x67" => 1, |
|
54 | + "\x68" => 1, "\x69" => 1, "\x6a" => 1, "\x6b" => 1, "\x6c" => 1, "\x6d" => 1, "\x6e" => 1, "\x6f" => 1, |
|
55 | + "\x70" => 1, "\x71" => 1, "\x72" => 1, "\x73" => 1, "\x74" => 1, "\x75" => 1, "\x76" => 1, "\x77" => 1, |
|
56 | + "\x78" => 1, "\x79" => 1, "\x7a" => 1, "\x7b" => 1, "\x7c" => 1, "\x7d" => 1, "\x7e" => 1, "\x7f" => 1, |
|
57 | + "\x80" => 0, "\x81" => 0, "\x82" => 0, "\x83" => 0, "\x84" => 0, "\x85" => 0, "\x86" => 0, "\x87" => 0, |
|
58 | + "\x88" => 0, "\x89" => 0, "\x8a" => 0, "\x8b" => 0, "\x8c" => 0, "\x8d" => 0, "\x8e" => 0, "\x8f" => 0, |
|
59 | + "\x90" => 0, "\x91" => 0, "\x92" => 0, "\x93" => 0, "\x94" => 0, "\x95" => 0, "\x96" => 0, "\x97" => 0, |
|
60 | + "\x98" => 0, "\x99" => 0, "\x9a" => 0, "\x9b" => 0, "\x9c" => 0, "\x9d" => 0, "\x9e" => 0, "\x9f" => 0, |
|
61 | + "\xa0" => 0, "\xa1" => 0, "\xa2" => 0, "\xa3" => 0, "\xa4" => 0, "\xa5" => 0, "\xa6" => 0, "\xa7" => 0, |
|
62 | + "\xa8" => 0, "\xa9" => 0, "\xaa" => 0, "\xab" => 0, "\xac" => 0, "\xad" => 0, "\xae" => 0, "\xaf" => 0, |
|
63 | + "\xb0" => 0, "\xb1" => 0, "\xb2" => 0, "\xb3" => 0, "\xb4" => 0, "\xb5" => 0, "\xb6" => 0, "\xb7" => 0, |
|
64 | + "\xb8" => 0, "\xb9" => 0, "\xba" => 0, "\xbb" => 0, "\xbc" => 0, "\xbd" => 0, "\xbe" => 0, "\xbf" => 0, |
|
65 | + "\xc0" => 2, "\xc1" => 2, "\xc2" => 2, "\xc3" => 2, "\xc4" => 2, "\xc5" => 2, "\xc6" => 2, "\xc7" => 2, |
|
66 | + "\xc8" => 2, "\xc9" => 2, "\xca" => 2, "\xcb" => 2, "\xcc" => 2, "\xcd" => 2, "\xce" => 2, "\xcf" => 2, |
|
67 | + "\xd0" => 2, "\xd1" => 2, "\xd2" => 2, "\xd3" => 2, "\xd4" => 2, "\xd5" => 2, "\xd6" => 2, "\xd7" => 2, |
|
68 | + "\xd8" => 2, "\xd9" => 2, "\xda" => 2, "\xdb" => 2, "\xdc" => 2, "\xdd" => 2, "\xde" => 2, "\xdf" => 2, |
|
69 | + "\xe0" => 3, "\xe1" => 3, "\xe2" => 3, "\xe3" => 3, "\xe4" => 3, "\xe5" => 3, "\xe6" => 3, "\xe7" => 3, |
|
70 | + "\xe8" => 3, "\xe9" => 3, "\xea" => 3, "\xeb" => 3, "\xec" => 3, "\xed" => 3, "\xee" => 3, "\xef" => 3, |
|
71 | + "\xf0" => 4, "\xf1" => 4, "\xf2" => 4, "\xf3" => 4, "\xf4" => 4, "\xf5" => 4, "\xf6" => 4, "\xf7" => 4, |
|
72 | + "\xf8" => 5, "\xf9" => 5, "\xfa" => 5, "\xfb" => 5, "\xfc" => 6, "\xfd" => 6, "\xfe" => 0, "\xff" => 0, |
|
73 | + ]; |
|
74 | 74 | |
75 | - /** |
|
76 | - * Returns the complete character map. |
|
77 | - * |
|
78 | - * @param string $string |
|
79 | - * @param int $startOffset |
|
80 | - * @param array $currentMap |
|
81 | - * @param mixed $ignoredChars |
|
82 | - * |
|
83 | - * @return int |
|
84 | - */ |
|
85 | - public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars) |
|
86 | - { |
|
87 | - if (!isset($currentMap['i']) || !isset($currentMap['p'])) { |
|
88 | - $currentMap['p'] = $currentMap['i'] = []; |
|
89 | - } |
|
75 | + /** |
|
76 | + * Returns the complete character map. |
|
77 | + * |
|
78 | + * @param string $string |
|
79 | + * @param int $startOffset |
|
80 | + * @param array $currentMap |
|
81 | + * @param mixed $ignoredChars |
|
82 | + * |
|
83 | + * @return int |
|
84 | + */ |
|
85 | + public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars) |
|
86 | + { |
|
87 | + if (!isset($currentMap['i']) || !isset($currentMap['p'])) { |
|
88 | + $currentMap['p'] = $currentMap['i'] = []; |
|
89 | + } |
|
90 | 90 | |
91 | - $strlen = \strlen($string); |
|
92 | - $charPos = \count($currentMap['p']); |
|
93 | - $foundChars = 0; |
|
94 | - $invalid = false; |
|
95 | - for ($i = 0; $i < $strlen; ++$i) { |
|
96 | - $char = $string[$i]; |
|
97 | - $size = self::$s_length_map[$char]; |
|
98 | - if (0 == $size) { |
|
99 | - /* char is invalid, we must wait for a resync */ |
|
100 | - $invalid = true; |
|
101 | - continue; |
|
102 | - } else { |
|
103 | - if (true === $invalid) { |
|
104 | - /* We mark the chars as invalid and start a new char */ |
|
105 | - $currentMap['p'][$charPos + $foundChars] = $startOffset + $i; |
|
106 | - $currentMap['i'][$charPos + $foundChars] = true; |
|
107 | - ++$foundChars; |
|
108 | - $invalid = false; |
|
109 | - } |
|
110 | - if (($i + $size) > $strlen) { |
|
111 | - $ignoredChars = substr($string, $i); |
|
112 | - break; |
|
113 | - } |
|
114 | - for ($j = 1; $j < $size; ++$j) { |
|
115 | - $char = $string[$i + $j]; |
|
116 | - if ($char > "\x7F" && $char < "\xC0") { |
|
117 | - // Valid - continue parsing |
|
118 | - } else { |
|
119 | - /* char is invalid, we must wait for a resync */ |
|
120 | - $invalid = true; |
|
121 | - continue 2; |
|
122 | - } |
|
123 | - } |
|
124 | - /* Ok we got a complete char here */ |
|
125 | - $currentMap['p'][$charPos + $foundChars] = $startOffset + $i + $size; |
|
126 | - $i += $j - 1; |
|
127 | - ++$foundChars; |
|
128 | - } |
|
129 | - } |
|
91 | + $strlen = \strlen($string); |
|
92 | + $charPos = \count($currentMap['p']); |
|
93 | + $foundChars = 0; |
|
94 | + $invalid = false; |
|
95 | + for ($i = 0; $i < $strlen; ++$i) { |
|
96 | + $char = $string[$i]; |
|
97 | + $size = self::$s_length_map[$char]; |
|
98 | + if (0 == $size) { |
|
99 | + /* char is invalid, we must wait for a resync */ |
|
100 | + $invalid = true; |
|
101 | + continue; |
|
102 | + } else { |
|
103 | + if (true === $invalid) { |
|
104 | + /* We mark the chars as invalid and start a new char */ |
|
105 | + $currentMap['p'][$charPos + $foundChars] = $startOffset + $i; |
|
106 | + $currentMap['i'][$charPos + $foundChars] = true; |
|
107 | + ++$foundChars; |
|
108 | + $invalid = false; |
|
109 | + } |
|
110 | + if (($i + $size) > $strlen) { |
|
111 | + $ignoredChars = substr($string, $i); |
|
112 | + break; |
|
113 | + } |
|
114 | + for ($j = 1; $j < $size; ++$j) { |
|
115 | + $char = $string[$i + $j]; |
|
116 | + if ($char > "\x7F" && $char < "\xC0") { |
|
117 | + // Valid - continue parsing |
|
118 | + } else { |
|
119 | + /* char is invalid, we must wait for a resync */ |
|
120 | + $invalid = true; |
|
121 | + continue 2; |
|
122 | + } |
|
123 | + } |
|
124 | + /* Ok we got a complete char here */ |
|
125 | + $currentMap['p'][$charPos + $foundChars] = $startOffset + $i + $size; |
|
126 | + $i += $j - 1; |
|
127 | + ++$foundChars; |
|
128 | + } |
|
129 | + } |
|
130 | 130 | |
131 | - return $foundChars; |
|
132 | - } |
|
131 | + return $foundChars; |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * Returns mapType. |
|
136 | - * |
|
137 | - * @return int mapType |
|
138 | - */ |
|
139 | - public function getMapType() |
|
140 | - { |
|
141 | - return self::MAP_TYPE_POSITIONS; |
|
142 | - } |
|
134 | + /** |
|
135 | + * Returns mapType. |
|
136 | + * |
|
137 | + * @return int mapType |
|
138 | + */ |
|
139 | + public function getMapType() |
|
140 | + { |
|
141 | + return self::MAP_TYPE_POSITIONS; |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * Returns an integer which specifies how many more bytes to read. |
|
146 | - * |
|
147 | - * A positive integer indicates the number of more bytes to fetch before invoking |
|
148 | - * this method again. |
|
149 | - * A value of zero means this is already a valid character. |
|
150 | - * A value of -1 means this cannot possibly be a valid character. |
|
151 | - * |
|
152 | - * @param string $bytes |
|
153 | - * @param int $size |
|
154 | - * |
|
155 | - * @return int |
|
156 | - */ |
|
157 | - public function validateByteSequence($bytes, $size) |
|
158 | - { |
|
159 | - if ($size < 1) { |
|
160 | - return -1; |
|
161 | - } |
|
162 | - $needed = self::$length_map[$bytes[0]] - $size; |
|
144 | + /** |
|
145 | + * Returns an integer which specifies how many more bytes to read. |
|
146 | + * |
|
147 | + * A positive integer indicates the number of more bytes to fetch before invoking |
|
148 | + * this method again. |
|
149 | + * A value of zero means this is already a valid character. |
|
150 | + * A value of -1 means this cannot possibly be a valid character. |
|
151 | + * |
|
152 | + * @param string $bytes |
|
153 | + * @param int $size |
|
154 | + * |
|
155 | + * @return int |
|
156 | + */ |
|
157 | + public function validateByteSequence($bytes, $size) |
|
158 | + { |
|
159 | + if ($size < 1) { |
|
160 | + return -1; |
|
161 | + } |
|
162 | + $needed = self::$length_map[$bytes[0]] - $size; |
|
163 | 163 | |
164 | - return $needed > -1 ? $needed : -1; |
|
165 | - } |
|
164 | + return $needed > -1 ? $needed : -1; |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * Returns the number of bytes which should be read to start each character. |
|
169 | - * |
|
170 | - * @return int |
|
171 | - */ |
|
172 | - public function getInitialByteSize() |
|
173 | - { |
|
174 | - return 1; |
|
175 | - } |
|
167 | + /** |
|
168 | + * Returns the number of bytes which should be read to start each character. |
|
169 | + * |
|
170 | + * @return int |
|
171 | + */ |
|
172 | + public function getInitialByteSize() |
|
173 | + { |
|
174 | + return 1; |
|
175 | + } |
|
176 | 176 | } |
@@ -15,70 +15,70 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader |
17 | 17 | { |
18 | - /** |
|
19 | - * Returns the complete character map. |
|
20 | - * |
|
21 | - * @param string $string |
|
22 | - * @param int $startOffset |
|
23 | - * @param array $currentMap |
|
24 | - * @param string $ignoredChars |
|
25 | - * |
|
26 | - * @return int |
|
27 | - */ |
|
28 | - public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars) |
|
29 | - { |
|
30 | - $strlen = \strlen($string); |
|
31 | - $ignoredChars = ''; |
|
32 | - for ($i = 0; $i < $strlen; ++$i) { |
|
33 | - if ($string[$i] > "\x07F") { |
|
34 | - // Invalid char |
|
35 | - $currentMap[$i + $startOffset] = $string[$i]; |
|
36 | - } |
|
37 | - } |
|
18 | + /** |
|
19 | + * Returns the complete character map. |
|
20 | + * |
|
21 | + * @param string $string |
|
22 | + * @param int $startOffset |
|
23 | + * @param array $currentMap |
|
24 | + * @param string $ignoredChars |
|
25 | + * |
|
26 | + * @return int |
|
27 | + */ |
|
28 | + public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars) |
|
29 | + { |
|
30 | + $strlen = \strlen($string); |
|
31 | + $ignoredChars = ''; |
|
32 | + for ($i = 0; $i < $strlen; ++$i) { |
|
33 | + if ($string[$i] > "\x07F") { |
|
34 | + // Invalid char |
|
35 | + $currentMap[$i + $startOffset] = $string[$i]; |
|
36 | + } |
|
37 | + } |
|
38 | 38 | |
39 | - return $strlen; |
|
40 | - } |
|
39 | + return $strlen; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Returns mapType. |
|
44 | - * |
|
45 | - * @return int mapType |
|
46 | - */ |
|
47 | - public function getMapType() |
|
48 | - { |
|
49 | - return self::MAP_TYPE_INVALID; |
|
50 | - } |
|
42 | + /** |
|
43 | + * Returns mapType. |
|
44 | + * |
|
45 | + * @return int mapType |
|
46 | + */ |
|
47 | + public function getMapType() |
|
48 | + { |
|
49 | + return self::MAP_TYPE_INVALID; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Returns an integer which specifies how many more bytes to read. |
|
54 | - * |
|
55 | - * A positive integer indicates the number of more bytes to fetch before invoking |
|
56 | - * this method again. |
|
57 | - * A value of zero means this is already a valid character. |
|
58 | - * A value of -1 means this cannot possibly be a valid character. |
|
59 | - * |
|
60 | - * @param string $bytes |
|
61 | - * @param int $size |
|
62 | - * |
|
63 | - * @return int |
|
64 | - */ |
|
65 | - public function validateByteSequence($bytes, $size) |
|
66 | - { |
|
67 | - $byte = reset($bytes); |
|
68 | - if (1 == \count($bytes) && $byte >= 0x00 && $byte <= 0x7F) { |
|
69 | - return 0; |
|
70 | - } |
|
52 | + /** |
|
53 | + * Returns an integer which specifies how many more bytes to read. |
|
54 | + * |
|
55 | + * A positive integer indicates the number of more bytes to fetch before invoking |
|
56 | + * this method again. |
|
57 | + * A value of zero means this is already a valid character. |
|
58 | + * A value of -1 means this cannot possibly be a valid character. |
|
59 | + * |
|
60 | + * @param string $bytes |
|
61 | + * @param int $size |
|
62 | + * |
|
63 | + * @return int |
|
64 | + */ |
|
65 | + public function validateByteSequence($bytes, $size) |
|
66 | + { |
|
67 | + $byte = reset($bytes); |
|
68 | + if (1 == \count($bytes) && $byte >= 0x00 && $byte <= 0x7F) { |
|
69 | + return 0; |
|
70 | + } |
|
71 | 71 | |
72 | - return -1; |
|
73 | - } |
|
72 | + return -1; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Returns the number of bytes which should be read to start each character. |
|
77 | - * |
|
78 | - * @return int |
|
79 | - */ |
|
80 | - public function getInitialByteSize() |
|
81 | - { |
|
82 | - return 1; |
|
83 | - } |
|
75 | + /** |
|
76 | + * Returns the number of bytes which should be read to start each character. |
|
77 | + * |
|
78 | + * @return int |
|
79 | + */ |
|
80 | + public function getInitialByteSize() |
|
81 | + { |
|
82 | + return 1; |
|
83 | + } |
|
84 | 84 | } |
@@ -15,31 +15,31 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_MimePart extends Swift_Mime_MimePart |
17 | 17 | { |
18 | - /** |
|
19 | - * Create a new MimePart. |
|
20 | - * |
|
21 | - * Details may be optionally passed into the constructor. |
|
22 | - * |
|
23 | - * @param string $body |
|
24 | - * @param string $contentType |
|
25 | - * @param string $charset |
|
26 | - */ |
|
27 | - public function __construct($body = null, $contentType = null, $charset = null) |
|
28 | - { |
|
29 | - \call_user_func_array( |
|
30 | - [$this, 'Swift_Mime_MimePart::__construct'], |
|
31 | - Swift_DependencyContainer::getInstance() |
|
32 | - ->createDependenciesFor('mime.part') |
|
33 | - ); |
|
18 | + /** |
|
19 | + * Create a new MimePart. |
|
20 | + * |
|
21 | + * Details may be optionally passed into the constructor. |
|
22 | + * |
|
23 | + * @param string $body |
|
24 | + * @param string $contentType |
|
25 | + * @param string $charset |
|
26 | + */ |
|
27 | + public function __construct($body = null, $contentType = null, $charset = null) |
|
28 | + { |
|
29 | + \call_user_func_array( |
|
30 | + [$this, 'Swift_Mime_MimePart::__construct'], |
|
31 | + Swift_DependencyContainer::getInstance() |
|
32 | + ->createDependenciesFor('mime.part') |
|
33 | + ); |
|
34 | 34 | |
35 | - if (!isset($charset)) { |
|
36 | - $charset = Swift_DependencyContainer::getInstance() |
|
37 | - ->lookup('properties.charset'); |
|
38 | - } |
|
39 | - $this->setBody($body); |
|
40 | - $this->setCharset($charset); |
|
41 | - if ($contentType) { |
|
42 | - $this->setContentType($contentType); |
|
43 | - } |
|
44 | - } |
|
35 | + if (!isset($charset)) { |
|
36 | + $charset = Swift_DependencyContainer::getInstance() |
|
37 | + ->lookup('properties.charset'); |
|
38 | + } |
|
39 | + $this->setBody($body); |
|
40 | + $this->setCharset($charset); |
|
41 | + if ($contentType) { |
|
42 | + $this->setContentType($contentType); |
|
43 | + } |
|
44 | + } |
|
45 | 45 | } |
@@ -15,14 +15,14 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_SwiftException extends Exception |
17 | 17 | { |
18 | - /** |
|
19 | - * Create a new SwiftException with $message. |
|
20 | - * |
|
21 | - * @param string $message |
|
22 | - * @param int $code |
|
23 | - */ |
|
24 | - public function __construct($message, $code = 0, Exception $previous = null) |
|
25 | - { |
|
26 | - parent::__construct($message, $code, $previous); |
|
27 | - } |
|
18 | + /** |
|
19 | + * Create a new SwiftException with $message. |
|
20 | + * |
|
21 | + * @param string $message |
|
22 | + * @param int $code |
|
23 | + */ |
|
24 | + public function __construct($message, $code = 0, Exception $previous = null) |
|
25 | + { |
|
26 | + parent::__construct($message, $code, $previous); |
|
27 | + } |
|
28 | 28 | } |
@@ -15,40 +15,40 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_Attachment extends Swift_Mime_Attachment |
17 | 17 | { |
18 | - /** |
|
19 | - * Create a new Attachment. |
|
20 | - * |
|
21 | - * Details may be optionally provided to the constructor. |
|
22 | - * |
|
23 | - * @param string|Swift_OutputByteStream $data |
|
24 | - * @param string $filename |
|
25 | - * @param string $contentType |
|
26 | - */ |
|
27 | - public function __construct($data = null, $filename = null, $contentType = null) |
|
28 | - { |
|
29 | - \call_user_func_array( |
|
30 | - [$this, 'Swift_Mime_Attachment::__construct'], |
|
31 | - Swift_DependencyContainer::getInstance() |
|
32 | - ->createDependenciesFor('mime.attachment') |
|
33 | - ); |
|
18 | + /** |
|
19 | + * Create a new Attachment. |
|
20 | + * |
|
21 | + * Details may be optionally provided to the constructor. |
|
22 | + * |
|
23 | + * @param string|Swift_OutputByteStream $data |
|
24 | + * @param string $filename |
|
25 | + * @param string $contentType |
|
26 | + */ |
|
27 | + public function __construct($data = null, $filename = null, $contentType = null) |
|
28 | + { |
|
29 | + \call_user_func_array( |
|
30 | + [$this, 'Swift_Mime_Attachment::__construct'], |
|
31 | + Swift_DependencyContainer::getInstance() |
|
32 | + ->createDependenciesFor('mime.attachment') |
|
33 | + ); |
|
34 | 34 | |
35 | - $this->setBody($data, $contentType); |
|
36 | - $this->setFilename($filename); |
|
37 | - } |
|
35 | + $this->setBody($data, $contentType); |
|
36 | + $this->setFilename($filename); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Create a new Attachment from a filesystem path. |
|
41 | - * |
|
42 | - * @param string $path |
|
43 | - * @param string $contentType optional |
|
44 | - * |
|
45 | - * @return self |
|
46 | - */ |
|
47 | - public static function fromPath($path, $contentType = null) |
|
48 | - { |
|
49 | - return (new self())->setFile( |
|
50 | - new Swift_ByteStream_FileByteStream($path), |
|
51 | - $contentType |
|
52 | - ); |
|
53 | - } |
|
39 | + /** |
|
40 | + * Create a new Attachment from a filesystem path. |
|
41 | + * |
|
42 | + * @param string $path |
|
43 | + * @param string $contentType optional |
|
44 | + * |
|
45 | + * @return self |
|
46 | + */ |
|
47 | + public static function fromPath($path, $contentType = null) |
|
48 | + { |
|
49 | + return (new self())->setFile( |
|
50 | + new Swift_ByteStream_FileByteStream($path), |
|
51 | + $contentType |
|
52 | + ); |
|
53 | + } |
|
54 | 54 | } |
@@ -15,22 +15,22 @@ |
||
15 | 15 | */ |
16 | 16 | interface Swift_Transport_SmtpAgent |
17 | 17 | { |
18 | - /** |
|
19 | - * Get the IoBuffer where read/writes are occurring. |
|
20 | - * |
|
21 | - * @return Swift_Transport_IoBuffer |
|
22 | - */ |
|
23 | - public function getBuffer(); |
|
18 | + /** |
|
19 | + * Get the IoBuffer where read/writes are occurring. |
|
20 | + * |
|
21 | + * @return Swift_Transport_IoBuffer |
|
22 | + */ |
|
23 | + public function getBuffer(); |
|
24 | 24 | |
25 | - /** |
|
26 | - * Run a command against the buffer, expecting the given response codes. |
|
27 | - * |
|
28 | - * If no response codes are given, the response will not be validated. |
|
29 | - * If codes are given, an exception will be thrown on an invalid response. |
|
30 | - * |
|
31 | - * @param string $command |
|
32 | - * @param int[] $codes |
|
33 | - * @param string[] $failures An array of failures by-reference |
|
34 | - */ |
|
35 | - public function executeCommand($command, $codes = [], &$failures = null); |
|
25 | + /** |
|
26 | + * Run a command against the buffer, expecting the given response codes. |
|
27 | + * |
|
28 | + * If no response codes are given, the response will not be validated. |
|
29 | + * If codes are given, an exception will be thrown on an invalid response. |
|
30 | + * |
|
31 | + * @param string $command |
|
32 | + * @param int[] $codes |
|
33 | + * @param string[] $failures An array of failures by-reference |
|
34 | + */ |
|
35 | + public function executeCommand($command, $codes = [], &$failures = null); |
|
36 | 36 | } |
@@ -19,140 +19,140 @@ |
||
19 | 19 | */ |
20 | 20 | class Swift_Transport_SendmailTransport extends Swift_Transport_AbstractSmtpTransport |
21 | 21 | { |
22 | - /** |
|
23 | - * Connection buffer parameters. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - private $params = [ |
|
28 | - 'timeout' => 30, |
|
29 | - 'blocking' => 1, |
|
30 | - 'command' => '/usr/sbin/sendmail -bs', |
|
31 | - 'type' => Swift_Transport_IoBuffer::TYPE_PROCESS, |
|
32 | - ]; |
|
33 | - |
|
34 | - /** |
|
35 | - * Create a new SendmailTransport with $buf for I/O. |
|
36 | - * |
|
37 | - * @param string $localDomain |
|
38 | - */ |
|
39 | - public function __construct(Swift_Transport_IoBuffer $buf, Swift_Events_EventDispatcher $dispatcher, $localDomain = '127.0.0.1', Swift_AddressEncoder $addressEncoder = null) |
|
40 | - { |
|
41 | - parent::__construct($buf, $dispatcher, $localDomain, $addressEncoder); |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Start the standalone SMTP session if running in -bs mode. |
|
46 | - */ |
|
47 | - public function start() |
|
48 | - { |
|
49 | - if (false !== strpos($this->getCommand(), ' -bs')) { |
|
50 | - parent::start(); |
|
51 | - } |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Set the command to invoke. |
|
56 | - * |
|
57 | - * If using -t mode you are strongly advised to include -oi or -i in the flags. |
|
58 | - * For example: /usr/sbin/sendmail -oi -t |
|
59 | - * Swift will append a -f<sender> flag if one is not present. |
|
60 | - * |
|
61 | - * The recommended mode is "-bs" since it is interactive and failure notifications |
|
62 | - * are hence possible. |
|
63 | - * |
|
64 | - * @param string $command |
|
65 | - * |
|
66 | - * @return $this |
|
67 | - */ |
|
68 | - public function setCommand($command) |
|
69 | - { |
|
70 | - $this->params['command'] = $command; |
|
71 | - |
|
72 | - return $this; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Get the sendmail command which will be invoked. |
|
77 | - * |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public function getCommand() |
|
81 | - { |
|
82 | - return $this->params['command']; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Send the given Message. |
|
87 | - * |
|
88 | - * Recipient/sender data will be retrieved from the Message API. |
|
89 | - * |
|
90 | - * The return value is the number of recipients who were accepted for delivery. |
|
91 | - * NOTE: If using 'sendmail -t' you will not be aware of any failures until |
|
92 | - * they bounce (i.e. send() will always return 100% success). |
|
93 | - * |
|
94 | - * @param string[] $failedRecipients An array of failures by-reference |
|
95 | - * |
|
96 | - * @return int |
|
97 | - */ |
|
98 | - public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null) |
|
99 | - { |
|
100 | - $failedRecipients = (array) $failedRecipients; |
|
101 | - $command = $this->getCommand(); |
|
102 | - $buffer = $this->getBuffer(); |
|
103 | - $count = 0; |
|
104 | - |
|
105 | - if (false !== strpos($command, ' -t')) { |
|
106 | - if ($evt = $this->eventDispatcher->createSendEvent($this, $message)) { |
|
107 | - $this->eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed'); |
|
108 | - if ($evt->bubbleCancelled()) { |
|
109 | - return 0; |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - if (false === strpos($command, ' -f')) { |
|
114 | - $command .= ' -f'.escapeshellarg($this->getReversePath($message) ?? ''); |
|
115 | - } |
|
116 | - |
|
117 | - $buffer->initialize(array_merge($this->params, ['command' => $command])); |
|
118 | - |
|
119 | - if (false === strpos($command, ' -i') && false === strpos($command, ' -oi')) { |
|
120 | - $buffer->setWriteTranslations(["\r\n" => "\n", "\n." => "\n.."]); |
|
121 | - } else { |
|
122 | - $buffer->setWriteTranslations(["\r\n" => "\n"]); |
|
123 | - } |
|
124 | - |
|
125 | - $count = \count((array) $message->getTo()) |
|
126 | - + \count((array) $message->getCc()) |
|
127 | - + \count((array) $message->getBcc()) |
|
128 | - ; |
|
129 | - $message->toByteStream($buffer); |
|
130 | - $buffer->flushBuffers(); |
|
131 | - $buffer->setWriteTranslations([]); |
|
132 | - $buffer->terminate(); |
|
133 | - |
|
134 | - if ($evt) { |
|
135 | - $evt->setResult(Swift_Events_SendEvent::RESULT_SUCCESS); |
|
136 | - $evt->setFailedRecipients($failedRecipients); |
|
137 | - $this->eventDispatcher->dispatchEvent($evt, 'sendPerformed'); |
|
138 | - } |
|
139 | - |
|
140 | - $message->generateId(); |
|
141 | - } elseif (false !== strpos($command, ' -bs')) { |
|
142 | - $count = parent::send($message, $failedRecipients); |
|
143 | - } else { |
|
144 | - $this->throwException(new Swift_TransportException( |
|
145 | - 'Unsupported sendmail command flags ['.$command.']. '. |
|
146 | - 'Must be one of "-bs" or "-t" but can include additional flags.' |
|
147 | - )); |
|
148 | - } |
|
149 | - |
|
150 | - return $count; |
|
151 | - } |
|
152 | - |
|
153 | - /** Get the params to initialize the buffer */ |
|
154 | - protected function getBufferParams() |
|
155 | - { |
|
156 | - return $this->params; |
|
157 | - } |
|
22 | + /** |
|
23 | + * Connection buffer parameters. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + private $params = [ |
|
28 | + 'timeout' => 30, |
|
29 | + 'blocking' => 1, |
|
30 | + 'command' => '/usr/sbin/sendmail -bs', |
|
31 | + 'type' => Swift_Transport_IoBuffer::TYPE_PROCESS, |
|
32 | + ]; |
|
33 | + |
|
34 | + /** |
|
35 | + * Create a new SendmailTransport with $buf for I/O. |
|
36 | + * |
|
37 | + * @param string $localDomain |
|
38 | + */ |
|
39 | + public function __construct(Swift_Transport_IoBuffer $buf, Swift_Events_EventDispatcher $dispatcher, $localDomain = '127.0.0.1', Swift_AddressEncoder $addressEncoder = null) |
|
40 | + { |
|
41 | + parent::__construct($buf, $dispatcher, $localDomain, $addressEncoder); |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Start the standalone SMTP session if running in -bs mode. |
|
46 | + */ |
|
47 | + public function start() |
|
48 | + { |
|
49 | + if (false !== strpos($this->getCommand(), ' -bs')) { |
|
50 | + parent::start(); |
|
51 | + } |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Set the command to invoke. |
|
56 | + * |
|
57 | + * If using -t mode you are strongly advised to include -oi or -i in the flags. |
|
58 | + * For example: /usr/sbin/sendmail -oi -t |
|
59 | + * Swift will append a -f<sender> flag if one is not present. |
|
60 | + * |
|
61 | + * The recommended mode is "-bs" since it is interactive and failure notifications |
|
62 | + * are hence possible. |
|
63 | + * |
|
64 | + * @param string $command |
|
65 | + * |
|
66 | + * @return $this |
|
67 | + */ |
|
68 | + public function setCommand($command) |
|
69 | + { |
|
70 | + $this->params['command'] = $command; |
|
71 | + |
|
72 | + return $this; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Get the sendmail command which will be invoked. |
|
77 | + * |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public function getCommand() |
|
81 | + { |
|
82 | + return $this->params['command']; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Send the given Message. |
|
87 | + * |
|
88 | + * Recipient/sender data will be retrieved from the Message API. |
|
89 | + * |
|
90 | + * The return value is the number of recipients who were accepted for delivery. |
|
91 | + * NOTE: If using 'sendmail -t' you will not be aware of any failures until |
|
92 | + * they bounce (i.e. send() will always return 100% success). |
|
93 | + * |
|
94 | + * @param string[] $failedRecipients An array of failures by-reference |
|
95 | + * |
|
96 | + * @return int |
|
97 | + */ |
|
98 | + public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null) |
|
99 | + { |
|
100 | + $failedRecipients = (array) $failedRecipients; |
|
101 | + $command = $this->getCommand(); |
|
102 | + $buffer = $this->getBuffer(); |
|
103 | + $count = 0; |
|
104 | + |
|
105 | + if (false !== strpos($command, ' -t')) { |
|
106 | + if ($evt = $this->eventDispatcher->createSendEvent($this, $message)) { |
|
107 | + $this->eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed'); |
|
108 | + if ($evt->bubbleCancelled()) { |
|
109 | + return 0; |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + if (false === strpos($command, ' -f')) { |
|
114 | + $command .= ' -f'.escapeshellarg($this->getReversePath($message) ?? ''); |
|
115 | + } |
|
116 | + |
|
117 | + $buffer->initialize(array_merge($this->params, ['command' => $command])); |
|
118 | + |
|
119 | + if (false === strpos($command, ' -i') && false === strpos($command, ' -oi')) { |
|
120 | + $buffer->setWriteTranslations(["\r\n" => "\n", "\n." => "\n.."]); |
|
121 | + } else { |
|
122 | + $buffer->setWriteTranslations(["\r\n" => "\n"]); |
|
123 | + } |
|
124 | + |
|
125 | + $count = \count((array) $message->getTo()) |
|
126 | + + \count((array) $message->getCc()) |
|
127 | + + \count((array) $message->getBcc()) |
|
128 | + ; |
|
129 | + $message->toByteStream($buffer); |
|
130 | + $buffer->flushBuffers(); |
|
131 | + $buffer->setWriteTranslations([]); |
|
132 | + $buffer->terminate(); |
|
133 | + |
|
134 | + if ($evt) { |
|
135 | + $evt->setResult(Swift_Events_SendEvent::RESULT_SUCCESS); |
|
136 | + $evt->setFailedRecipients($failedRecipients); |
|
137 | + $this->eventDispatcher->dispatchEvent($evt, 'sendPerformed'); |
|
138 | + } |
|
139 | + |
|
140 | + $message->generateId(); |
|
141 | + } elseif (false !== strpos($command, ' -bs')) { |
|
142 | + $count = parent::send($message, $failedRecipients); |
|
143 | + } else { |
|
144 | + $this->throwException(new Swift_TransportException( |
|
145 | + 'Unsupported sendmail command flags ['.$command.']. '. |
|
146 | + 'Must be one of "-bs" or "-t" but can include additional flags.' |
|
147 | + )); |
|
148 | + } |
|
149 | + |
|
150 | + return $count; |
|
151 | + } |
|
152 | + |
|
153 | + /** Get the params to initialize the buffer */ |
|
154 | + protected function getBufferParams() |
|
155 | + { |
|
156 | + return $this->params; |
|
157 | + } |
|
158 | 158 | } |