Completed
Branch develop (354a31)
by
unknown
22:20
created
includes/swiftmailer/lib/classes/Swift/CharacterReader/Utf8Reader.php 1 patch
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -16,161 +16,161 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
includes/swiftmailer/lib/classes/Swift/CharacterReader/UsAsciiReader.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -15,70 +15,70 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
htdocs/includes/swiftmailer/lib/classes/Swift/MimePart.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -15,31 +15,31 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
htdocs/includes/swiftmailer/lib/classes/Swift/SwiftException.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -15,14 +15,14 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
htdocs/includes/swiftmailer/lib/classes/Swift/Attachment.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -15,40 +15,40 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
htdocs/includes/swiftmailer/lib/classes/Swift/Transport/SmtpAgent.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -15,22 +15,22 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
includes/swiftmailer/lib/classes/Swift/Transport/SendmailTransport.php 1 patch
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -19,140 +19,140 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
htdocs/includes/swiftmailer/lib/classes/Swift/Transport/EsmtpHandler.php 1 patch
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -15,72 +15,72 @@
 block discarded – undo
15 15
  */
16 16
 interface Swift_Transport_EsmtpHandler
17 17
 {
18
-    /**
19
-     * Get the name of the ESMTP extension this handles.
20
-     *
21
-     * @return string
22
-     */
23
-    public function getHandledKeyword();
18
+	/**
19
+	 * Get the name of the ESMTP extension this handles.
20
+	 *
21
+	 * @return string
22
+	 */
23
+	public function getHandledKeyword();
24 24
 
25
-    /**
26
-     * Set the parameters which the EHLO greeting indicated.
27
-     *
28
-     * @param string[] $parameters
29
-     */
30
-    public function setKeywordParams(array $parameters);
25
+	/**
26
+	 * Set the parameters which the EHLO greeting indicated.
27
+	 *
28
+	 * @param string[] $parameters
29
+	 */
30
+	public function setKeywordParams(array $parameters);
31 31
 
32
-    /**
33
-     * Runs immediately after a EHLO has been issued.
34
-     *
35
-     * @param Swift_Transport_SmtpAgent $agent to read/write
36
-     */
37
-    public function afterEhlo(Swift_Transport_SmtpAgent $agent);
32
+	/**
33
+	 * Runs immediately after a EHLO has been issued.
34
+	 *
35
+	 * @param Swift_Transport_SmtpAgent $agent to read/write
36
+	 */
37
+	public function afterEhlo(Swift_Transport_SmtpAgent $agent);
38 38
 
39
-    /**
40
-     * Get params which are appended to MAIL FROM:<>.
41
-     *
42
-     * @return string[]
43
-     */
44
-    public function getMailParams();
39
+	/**
40
+	 * Get params which are appended to MAIL FROM:<>.
41
+	 *
42
+	 * @return string[]
43
+	 */
44
+	public function getMailParams();
45 45
 
46
-    /**
47
-     * Get params which are appended to RCPT TO:<>.
48
-     *
49
-     * @return string[]
50
-     */
51
-    public function getRcptParams();
46
+	/**
47
+	 * Get params which are appended to RCPT TO:<>.
48
+	 *
49
+	 * @return string[]
50
+	 */
51
+	public function getRcptParams();
52 52
 
53
-    /**
54
-     * Runs when a command is due to be sent.
55
-     *
56
-     * @param Swift_Transport_SmtpAgent $agent            to read/write
57
-     * @param string                    $command          to send
58
-     * @param int[]                     $codes            expected in response
59
-     * @param string[]                  $failedRecipients to collect failures
60
-     * @param bool                      $stop             to be set true  by-reference if the command is now sent
61
-     */
62
-    public function onCommand(Swift_Transport_SmtpAgent $agent, $command, $codes = [], &$failedRecipients = null, &$stop = false);
53
+	/**
54
+	 * Runs when a command is due to be sent.
55
+	 *
56
+	 * @param Swift_Transport_SmtpAgent $agent            to read/write
57
+	 * @param string                    $command          to send
58
+	 * @param int[]                     $codes            expected in response
59
+	 * @param string[]                  $failedRecipients to collect failures
60
+	 * @param bool                      $stop             to be set true  by-reference if the command is now sent
61
+	 */
62
+	public function onCommand(Swift_Transport_SmtpAgent $agent, $command, $codes = [], &$failedRecipients = null, &$stop = false);
63 63
 
64
-    /**
65
-     * Returns +1, -1 or 0 according to the rules for usort().
66
-     *
67
-     * This method is called to ensure extensions can be execute in an appropriate order.
68
-     *
69
-     * @param string $esmtpKeyword to compare with
70
-     *
71
-     * @return int
72
-     */
73
-    public function getPriorityOver($esmtpKeyword);
64
+	/**
65
+	 * Returns +1, -1 or 0 according to the rules for usort().
66
+	 *
67
+	 * This method is called to ensure extensions can be execute in an appropriate order.
68
+	 *
69
+	 * @param string $esmtpKeyword to compare with
70
+	 *
71
+	 * @return int
72
+	 */
73
+	public function getPriorityOver($esmtpKeyword);
74 74
 
75
-    /**
76
-     * Returns an array of method names which are exposed to the Esmtp class.
77
-     *
78
-     * @return string[]
79
-     */
80
-    public function exposeMixinMethods();
75
+	/**
76
+	 * Returns an array of method names which are exposed to the Esmtp class.
77
+	 *
78
+	 * @return string[]
79
+	 */
80
+	public function exposeMixinMethods();
81 81
 
82
-    /**
83
-     * Tells this handler to clear any buffers and reset its state.
84
-     */
85
-    public function resetState();
82
+	/**
83
+	 * Tells this handler to clear any buffers and reset its state.
84
+	 */
85
+	public function resetState();
86 86
 }
Please login to merge, or discard this patch.
htdocs/includes/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php 2 patches
Indentation   +428 added lines, -428 removed lines patch added patch discarded remove patch
@@ -15,432 +15,432 @@
 block discarded – undo
15 15
  */
16 16
 class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTransport implements Swift_Transport_SmtpAgent
17 17
 {
18
-    /**
19
-     * ESMTP extension handlers.
20
-     *
21
-     * @var Swift_Transport_EsmtpHandler[]
22
-     */
23
-    private $handlers = [];
24
-
25
-    /**
26
-     * ESMTP capabilities.
27
-     *
28
-     * @var string[]
29
-     */
30
-    private $capabilities = [];
31
-
32
-    /**
33
-     * Connection buffer parameters.
34
-     *
35
-     * @var array
36
-     */
37
-    private $params = [
38
-        'protocol' => 'tcp',
39
-        'host' => 'localhost',
40
-        'port' => 25,
41
-        'timeout' => 30,
42
-        'blocking' => 1,
43
-        'tls' => false,
44
-        'type' => Swift_Transport_IoBuffer::TYPE_SOCKET,
45
-        'stream_context_options' => [],
46
-        ];
47
-
48
-    /**
49
-     * Creates a new EsmtpTransport using the given I/O buffer.
50
-     *
51
-     * @param Swift_Transport_EsmtpHandler[] $extensionHandlers
52
-     * @param string                         $localDomain
53
-     */
54
-    public function __construct(Swift_Transport_IoBuffer $buf, array $extensionHandlers, Swift_Events_EventDispatcher $dispatcher, $localDomain = '127.0.0.1', Swift_AddressEncoder $addressEncoder = null)
55
-    {
56
-        parent::__construct($buf, $dispatcher, $localDomain, $addressEncoder);
57
-        $this->setExtensionHandlers($extensionHandlers);
58
-    }
59
-
60
-    /**
61
-     * Set the host to connect to.
62
-     *
63
-     * Literal IPv6 addresses should be wrapped in square brackets.
64
-     *
65
-     * @param string $host
66
-     *
67
-     * @return $this
68
-     */
69
-    public function setHost($host)
70
-    {
71
-        $this->params['host'] = $host;
72
-
73
-        return $this;
74
-    }
75
-
76
-    /**
77
-     * Get the host to connect to.
78
-     *
79
-     * @return string
80
-     */
81
-    public function getHost()
82
-    {
83
-        return $this->params['host'];
84
-    }
85
-
86
-    /**
87
-     * Set the port to connect to.
88
-     *
89
-     * @param int $port
90
-     *
91
-     * @return $this
92
-     */
93
-    public function setPort($port)
94
-    {
95
-        $this->params['port'] = (int) $port;
96
-
97
-        return $this;
98
-    }
99
-
100
-    /**
101
-     * Get the port to connect to.
102
-     *
103
-     * @return int
104
-     */
105
-    public function getPort()
106
-    {
107
-        return $this->params['port'];
108
-    }
109
-
110
-    /**
111
-     * Set the connection timeout.
112
-     *
113
-     * @param int $timeout seconds
114
-     *
115
-     * @return $this
116
-     */
117
-    public function setTimeout($timeout)
118
-    {
119
-        $this->params['timeout'] = (int) $timeout;
120
-        $this->buffer->setParam('timeout', (int) $timeout);
121
-
122
-        return $this;
123
-    }
124
-
125
-    /**
126
-     * Get the connection timeout.
127
-     *
128
-     * @return int
129
-     */
130
-    public function getTimeout()
131
-    {
132
-        return $this->params['timeout'];
133
-    }
134
-
135
-    /**
136
-     * Set the encryption type (tls or ssl).
137
-     *
138
-     * @param string $encryption
139
-     *
140
-     * @return $this
141
-     */
142
-    public function setEncryption($encryption)
143
-    {
144
-        $encryption = strtolower($encryption ?? '');
145
-        if ('tls' == $encryption) {
146
-            $this->params['protocol'] = 'tcp';
147
-            $this->params['tls'] = true;
148
-        } else {
149
-            $this->params['protocol'] = $encryption;
150
-            $this->params['tls'] = false;
151
-        }
152
-
153
-        return $this;
154
-    }
155
-
156
-    /**
157
-     * Get the encryption type.
158
-     *
159
-     * @return string
160
-     */
161
-    public function getEncryption()
162
-    {
163
-        return $this->params['tls'] ? 'tls' : $this->params['protocol'];
164
-    }
165
-
166
-    /**
167
-     * Sets the stream context options.
168
-     *
169
-     * @param array $options
170
-     *
171
-     * @return $this
172
-     */
173
-    public function setStreamOptions($options)
174
-    {
175
-        $this->params['stream_context_options'] = $options;
176
-
177
-        return $this;
178
-    }
179
-
180
-    /**
181
-     * Returns the stream context options.
182
-     *
183
-     * @return array
184
-     */
185
-    public function getStreamOptions()
186
-    {
187
-        return $this->params['stream_context_options'];
188
-    }
189
-
190
-    /**
191
-     * Sets the source IP.
192
-     *
193
-     * IPv6 addresses should be wrapped in square brackets.
194
-     *
195
-     * @param string $source
196
-     *
197
-     * @return $this
198
-     */
199
-    public function setSourceIp($source)
200
-    {
201
-        $this->params['sourceIp'] = $source;
202
-
203
-        return $this;
204
-    }
205
-
206
-    /**
207
-     * Returns the IP used to connect to the destination.
208
-     *
209
-     * @return string
210
-     */
211
-    public function getSourceIp()
212
-    {
213
-        return $this->params['sourceIp'] ?? null;
214
-    }
215
-
216
-    /**
217
-     * Sets whether SMTP pipelining is enabled.
218
-     *
219
-     * By default, support is auto-detected using the PIPELINING SMTP extension.
220
-     * Use this function to override that in the unlikely event of compatibility
221
-     * issues.
222
-     *
223
-     * @param bool $enabled
224
-     *
225
-     * @return $this
226
-     */
227
-    public function setPipelining($enabled)
228
-    {
229
-        $this->pipelining = $enabled;
230
-
231
-        return $this;
232
-    }
233
-
234
-    /**
235
-     * Returns whether SMTP pipelining is enabled.
236
-     *
237
-     * @return bool|null a boolean if pipelining is explicitly enabled or disabled,
238
-     *                   or null if support is auto-detected
239
-     */
240
-    public function getPipelining()
241
-    {
242
-        return $this->pipelining;
243
-    }
244
-
245
-    /**
246
-     * Set ESMTP extension handlers.
247
-     *
248
-     * @param Swift_Transport_EsmtpHandler[] $handlers
249
-     *
250
-     * @return $this
251
-     */
252
-    public function setExtensionHandlers(array $handlers)
253
-    {
254
-        $assoc = [];
255
-        foreach ($handlers as $handler) {
256
-            $assoc[$handler->getHandledKeyword()] = $handler;
257
-        }
258
-        uasort($assoc, function ($a, $b) {
259
-            return $a->getPriorityOver($b->getHandledKeyword());
260
-        });
261
-        $this->handlers = $assoc;
262
-        $this->setHandlerParams();
263
-
264
-        return $this;
265
-    }
266
-
267
-    /**
268
-     * Get ESMTP extension handlers.
269
-     *
270
-     * @return Swift_Transport_EsmtpHandler[]
271
-     */
272
-    public function getExtensionHandlers()
273
-    {
274
-        return array_values($this->handlers);
275
-    }
276
-
277
-    /**
278
-     * Run a command against the buffer, expecting the given response codes.
279
-     *
280
-     * If no response codes are given, the response will not be validated.
281
-     * If codes are given, an exception will be thrown on an invalid response.
282
-     *
283
-     * @param string   $command
284
-     * @param int[]    $codes
285
-     * @param string[] $failures An array of failures by-reference
286
-     * @param bool     $pipeline Do not wait for response
287
-     * @param string   $address  the address, if command is RCPT TO
288
-     *
289
-     * @return string|null The server response, or null if pipelining is enabled
290
-     */
291
-    public function executeCommand($command, $codes = [], &$failures = null, $pipeline = false, $address = null)
292
-    {
293
-        $failures = (array) $failures;
294
-        $stopSignal = false;
295
-        $response = null;
296
-        foreach ($this->getActiveHandlers() as $handler) {
297
-            $response = $handler->onCommand(
298
-                $this, $command, $codes, $failures, $stopSignal
299
-                );
300
-            if ($stopSignal) {
301
-                return $response;
302
-            }
303
-        }
304
-
305
-        return parent::executeCommand($command, $codes, $failures, $pipeline, $address);
306
-    }
307
-
308
-    /** Mixin handling method for ESMTP handlers */
309
-    public function __call($method, $args)
310
-    {
311
-        foreach ($this->handlers as $handler) {
312
-            if (\in_array(strtolower($method),
313
-                array_map('strtolower', (array) $handler->exposeMixinMethods())
314
-                )) {
315
-                $return = \call_user_func_array([$handler, $method], $args);
316
-                // Allow fluid method calls
317
-                if (null === $return && 'set' == substr($method, 0, 3)) {
318
-                    return $this;
319
-                } else {
320
-                    return $return;
321
-                }
322
-            }
323
-        }
324
-        trigger_error('Call to undefined method '.$method, E_USER_ERROR);
325
-    }
326
-
327
-    /** Get the params to initialize the buffer */
328
-    protected function getBufferParams()
329
-    {
330
-        return $this->params;
331
-    }
332
-
333
-    /** Overridden to perform EHLO instead */
334
-    protected function doHeloCommand()
335
-    {
336
-        try {
337
-            $response = $this->executeCommand(
338
-                sprintf("EHLO %s\r\n", $this->domain), [250]
339
-                );
340
-        } catch (Swift_TransportException $e) {
341
-            return parent::doHeloCommand();
342
-        }
343
-
344
-        if ($this->params['tls']) {
345
-            try {
346
-                $this->executeCommand("STARTTLS\r\n", [220]);
347
-
348
-                if (!$this->buffer->startTLS()) {
349
-                    throw new Swift_TransportException('Unable to connect with TLS encryption');
350
-                }
351
-
352
-                try {
353
-                    $response = $this->executeCommand(
354
-                        sprintf("EHLO %s\r\n", $this->domain), [250]
355
-                        );
356
-                } catch (Swift_TransportException $e) {
357
-                    return parent::doHeloCommand();
358
-                }
359
-            } catch (Swift_TransportException $e) {
360
-                $this->throwException($e);
361
-            }
362
-        }
363
-
364
-        $this->capabilities = $this->getCapabilities($response);
365
-        if (!isset($this->pipelining)) {
366
-            $this->pipelining = isset($this->capabilities['PIPELINING']);
367
-        }
368
-
369
-        $this->setHandlerParams();
370
-        foreach ($this->getActiveHandlers() as $handler) {
371
-            $handler->afterEhlo($this);
372
-        }
373
-    }
374
-
375
-    /** Overridden to add Extension support */
376
-    protected function doMailFromCommand($address)
377
-    {
378
-        $address = $this->addressEncoder->encodeString($address);
379
-        $handlers = $this->getActiveHandlers();
380
-        $params = [];
381
-        foreach ($handlers as $handler) {
382
-            $params = array_merge($params, (array) $handler->getMailParams());
383
-        }
384
-        $paramStr = !empty($params) ? ' '.implode(' ', $params) : '';
385
-        $this->executeCommand(
386
-            sprintf("MAIL FROM:<%s>%s\r\n", $address, $paramStr), [250], $failures, true
387
-            );
388
-    }
389
-
390
-    /** Overridden to add Extension support */
391
-    protected function doRcptToCommand($address)
392
-    {
393
-        $address = $this->addressEncoder->encodeString($address);
394
-        $handlers = $this->getActiveHandlers();
395
-        $params = [];
396
-        foreach ($handlers as $handler) {
397
-            $params = array_merge($params, (array) $handler->getRcptParams());
398
-        }
399
-        $paramStr = !empty($params) ? ' '.implode(' ', $params) : '';
400
-        $this->executeCommand(
401
-            sprintf("RCPT TO:<%s>%s\r\n", $address, $paramStr), [250, 251, 252], $failures, true, $address
402
-            );
403
-    }
404
-
405
-    /** Determine ESMTP capabilities by function group */
406
-    private function getCapabilities($ehloResponse)
407
-    {
408
-        $capabilities = [];
409
-        $ehloResponse = trim($ehloResponse ?? '');
410
-        $lines = explode("\r\n", $ehloResponse);
411
-        array_shift($lines);
412
-        foreach ($lines as $line) {
413
-            if (preg_match('/^[0-9]{3}[ -]([A-Z0-9-]+)((?:[ =].*)?)$/Di', $line, $matches)) {
414
-                $keyword = strtoupper($matches[1]);
415
-                $paramStr = strtoupper(ltrim($matches[2], ' ='));
416
-                $params = !empty($paramStr) ? explode(' ', $paramStr) : [];
417
-                $capabilities[$keyword] = $params;
418
-            }
419
-        }
420
-
421
-        return $capabilities;
422
-    }
423
-
424
-    /** Set parameters which are used by each extension handler */
425
-    private function setHandlerParams()
426
-    {
427
-        foreach ($this->handlers as $keyword => $handler) {
428
-            if (\array_key_exists($keyword, $this->capabilities)) {
429
-                $handler->setKeywordParams($this->capabilities[$keyword]);
430
-            }
431
-        }
432
-    }
433
-
434
-    /** Get ESMTP handlers which are currently ok to use */
435
-    private function getActiveHandlers()
436
-    {
437
-        $handlers = [];
438
-        foreach ($this->handlers as $keyword => $handler) {
439
-            if (\array_key_exists($keyword, $this->capabilities)) {
440
-                $handlers[] = $handler;
441
-            }
442
-        }
443
-
444
-        return $handlers;
445
-    }
18
+	/**
19
+	 * ESMTP extension handlers.
20
+	 *
21
+	 * @var Swift_Transport_EsmtpHandler[]
22
+	 */
23
+	private $handlers = [];
24
+
25
+	/**
26
+	 * ESMTP capabilities.
27
+	 *
28
+	 * @var string[]
29
+	 */
30
+	private $capabilities = [];
31
+
32
+	/**
33
+	 * Connection buffer parameters.
34
+	 *
35
+	 * @var array
36
+	 */
37
+	private $params = [
38
+		'protocol' => 'tcp',
39
+		'host' => 'localhost',
40
+		'port' => 25,
41
+		'timeout' => 30,
42
+		'blocking' => 1,
43
+		'tls' => false,
44
+		'type' => Swift_Transport_IoBuffer::TYPE_SOCKET,
45
+		'stream_context_options' => [],
46
+		];
47
+
48
+	/**
49
+	 * Creates a new EsmtpTransport using the given I/O buffer.
50
+	 *
51
+	 * @param Swift_Transport_EsmtpHandler[] $extensionHandlers
52
+	 * @param string                         $localDomain
53
+	 */
54
+	public function __construct(Swift_Transport_IoBuffer $buf, array $extensionHandlers, Swift_Events_EventDispatcher $dispatcher, $localDomain = '127.0.0.1', Swift_AddressEncoder $addressEncoder = null)
55
+	{
56
+		parent::__construct($buf, $dispatcher, $localDomain, $addressEncoder);
57
+		$this->setExtensionHandlers($extensionHandlers);
58
+	}
59
+
60
+	/**
61
+	 * Set the host to connect to.
62
+	 *
63
+	 * Literal IPv6 addresses should be wrapped in square brackets.
64
+	 *
65
+	 * @param string $host
66
+	 *
67
+	 * @return $this
68
+	 */
69
+	public function setHost($host)
70
+	{
71
+		$this->params['host'] = $host;
72
+
73
+		return $this;
74
+	}
75
+
76
+	/**
77
+	 * Get the host to connect to.
78
+	 *
79
+	 * @return string
80
+	 */
81
+	public function getHost()
82
+	{
83
+		return $this->params['host'];
84
+	}
85
+
86
+	/**
87
+	 * Set the port to connect to.
88
+	 *
89
+	 * @param int $port
90
+	 *
91
+	 * @return $this
92
+	 */
93
+	public function setPort($port)
94
+	{
95
+		$this->params['port'] = (int) $port;
96
+
97
+		return $this;
98
+	}
99
+
100
+	/**
101
+	 * Get the port to connect to.
102
+	 *
103
+	 * @return int
104
+	 */
105
+	public function getPort()
106
+	{
107
+		return $this->params['port'];
108
+	}
109
+
110
+	/**
111
+	 * Set the connection timeout.
112
+	 *
113
+	 * @param int $timeout seconds
114
+	 *
115
+	 * @return $this
116
+	 */
117
+	public function setTimeout($timeout)
118
+	{
119
+		$this->params['timeout'] = (int) $timeout;
120
+		$this->buffer->setParam('timeout', (int) $timeout);
121
+
122
+		return $this;
123
+	}
124
+
125
+	/**
126
+	 * Get the connection timeout.
127
+	 *
128
+	 * @return int
129
+	 */
130
+	public function getTimeout()
131
+	{
132
+		return $this->params['timeout'];
133
+	}
134
+
135
+	/**
136
+	 * Set the encryption type (tls or ssl).
137
+	 *
138
+	 * @param string $encryption
139
+	 *
140
+	 * @return $this
141
+	 */
142
+	public function setEncryption($encryption)
143
+	{
144
+		$encryption = strtolower($encryption ?? '');
145
+		if ('tls' == $encryption) {
146
+			$this->params['protocol'] = 'tcp';
147
+			$this->params['tls'] = true;
148
+		} else {
149
+			$this->params['protocol'] = $encryption;
150
+			$this->params['tls'] = false;
151
+		}
152
+
153
+		return $this;
154
+	}
155
+
156
+	/**
157
+	 * Get the encryption type.
158
+	 *
159
+	 * @return string
160
+	 */
161
+	public function getEncryption()
162
+	{
163
+		return $this->params['tls'] ? 'tls' : $this->params['protocol'];
164
+	}
165
+
166
+	/**
167
+	 * Sets the stream context options.
168
+	 *
169
+	 * @param array $options
170
+	 *
171
+	 * @return $this
172
+	 */
173
+	public function setStreamOptions($options)
174
+	{
175
+		$this->params['stream_context_options'] = $options;
176
+
177
+		return $this;
178
+	}
179
+
180
+	/**
181
+	 * Returns the stream context options.
182
+	 *
183
+	 * @return array
184
+	 */
185
+	public function getStreamOptions()
186
+	{
187
+		return $this->params['stream_context_options'];
188
+	}
189
+
190
+	/**
191
+	 * Sets the source IP.
192
+	 *
193
+	 * IPv6 addresses should be wrapped in square brackets.
194
+	 *
195
+	 * @param string $source
196
+	 *
197
+	 * @return $this
198
+	 */
199
+	public function setSourceIp($source)
200
+	{
201
+		$this->params['sourceIp'] = $source;
202
+
203
+		return $this;
204
+	}
205
+
206
+	/**
207
+	 * Returns the IP used to connect to the destination.
208
+	 *
209
+	 * @return string
210
+	 */
211
+	public function getSourceIp()
212
+	{
213
+		return $this->params['sourceIp'] ?? null;
214
+	}
215
+
216
+	/**
217
+	 * Sets whether SMTP pipelining is enabled.
218
+	 *
219
+	 * By default, support is auto-detected using the PIPELINING SMTP extension.
220
+	 * Use this function to override that in the unlikely event of compatibility
221
+	 * issues.
222
+	 *
223
+	 * @param bool $enabled
224
+	 *
225
+	 * @return $this
226
+	 */
227
+	public function setPipelining($enabled)
228
+	{
229
+		$this->pipelining = $enabled;
230
+
231
+		return $this;
232
+	}
233
+
234
+	/**
235
+	 * Returns whether SMTP pipelining is enabled.
236
+	 *
237
+	 * @return bool|null a boolean if pipelining is explicitly enabled or disabled,
238
+	 *                   or null if support is auto-detected
239
+	 */
240
+	public function getPipelining()
241
+	{
242
+		return $this->pipelining;
243
+	}
244
+
245
+	/**
246
+	 * Set ESMTP extension handlers.
247
+	 *
248
+	 * @param Swift_Transport_EsmtpHandler[] $handlers
249
+	 *
250
+	 * @return $this
251
+	 */
252
+	public function setExtensionHandlers(array $handlers)
253
+	{
254
+		$assoc = [];
255
+		foreach ($handlers as $handler) {
256
+			$assoc[$handler->getHandledKeyword()] = $handler;
257
+		}
258
+		uasort($assoc, function ($a, $b) {
259
+			return $a->getPriorityOver($b->getHandledKeyword());
260
+		});
261
+		$this->handlers = $assoc;
262
+		$this->setHandlerParams();
263
+
264
+		return $this;
265
+	}
266
+
267
+	/**
268
+	 * Get ESMTP extension handlers.
269
+	 *
270
+	 * @return Swift_Transport_EsmtpHandler[]
271
+	 */
272
+	public function getExtensionHandlers()
273
+	{
274
+		return array_values($this->handlers);
275
+	}
276
+
277
+	/**
278
+	 * Run a command against the buffer, expecting the given response codes.
279
+	 *
280
+	 * If no response codes are given, the response will not be validated.
281
+	 * If codes are given, an exception will be thrown on an invalid response.
282
+	 *
283
+	 * @param string   $command
284
+	 * @param int[]    $codes
285
+	 * @param string[] $failures An array of failures by-reference
286
+	 * @param bool     $pipeline Do not wait for response
287
+	 * @param string   $address  the address, if command is RCPT TO
288
+	 *
289
+	 * @return string|null The server response, or null if pipelining is enabled
290
+	 */
291
+	public function executeCommand($command, $codes = [], &$failures = null, $pipeline = false, $address = null)
292
+	{
293
+		$failures = (array) $failures;
294
+		$stopSignal = false;
295
+		$response = null;
296
+		foreach ($this->getActiveHandlers() as $handler) {
297
+			$response = $handler->onCommand(
298
+				$this, $command, $codes, $failures, $stopSignal
299
+				);
300
+			if ($stopSignal) {
301
+				return $response;
302
+			}
303
+		}
304
+
305
+		return parent::executeCommand($command, $codes, $failures, $pipeline, $address);
306
+	}
307
+
308
+	/** Mixin handling method for ESMTP handlers */
309
+	public function __call($method, $args)
310
+	{
311
+		foreach ($this->handlers as $handler) {
312
+			if (\in_array(strtolower($method),
313
+				array_map('strtolower', (array) $handler->exposeMixinMethods())
314
+				)) {
315
+				$return = \call_user_func_array([$handler, $method], $args);
316
+				// Allow fluid method calls
317
+				if (null === $return && 'set' == substr($method, 0, 3)) {
318
+					return $this;
319
+				} else {
320
+					return $return;
321
+				}
322
+			}
323
+		}
324
+		trigger_error('Call to undefined method '.$method, E_USER_ERROR);
325
+	}
326
+
327
+	/** Get the params to initialize the buffer */
328
+	protected function getBufferParams()
329
+	{
330
+		return $this->params;
331
+	}
332
+
333
+	/** Overridden to perform EHLO instead */
334
+	protected function doHeloCommand()
335
+	{
336
+		try {
337
+			$response = $this->executeCommand(
338
+				sprintf("EHLO %s\r\n", $this->domain), [250]
339
+				);
340
+		} catch (Swift_TransportException $e) {
341
+			return parent::doHeloCommand();
342
+		}
343
+
344
+		if ($this->params['tls']) {
345
+			try {
346
+				$this->executeCommand("STARTTLS\r\n", [220]);
347
+
348
+				if (!$this->buffer->startTLS()) {
349
+					throw new Swift_TransportException('Unable to connect with TLS encryption');
350
+				}
351
+
352
+				try {
353
+					$response = $this->executeCommand(
354
+						sprintf("EHLO %s\r\n", $this->domain), [250]
355
+						);
356
+				} catch (Swift_TransportException $e) {
357
+					return parent::doHeloCommand();
358
+				}
359
+			} catch (Swift_TransportException $e) {
360
+				$this->throwException($e);
361
+			}
362
+		}
363
+
364
+		$this->capabilities = $this->getCapabilities($response);
365
+		if (!isset($this->pipelining)) {
366
+			$this->pipelining = isset($this->capabilities['PIPELINING']);
367
+		}
368
+
369
+		$this->setHandlerParams();
370
+		foreach ($this->getActiveHandlers() as $handler) {
371
+			$handler->afterEhlo($this);
372
+		}
373
+	}
374
+
375
+	/** Overridden to add Extension support */
376
+	protected function doMailFromCommand($address)
377
+	{
378
+		$address = $this->addressEncoder->encodeString($address);
379
+		$handlers = $this->getActiveHandlers();
380
+		$params = [];
381
+		foreach ($handlers as $handler) {
382
+			$params = array_merge($params, (array) $handler->getMailParams());
383
+		}
384
+		$paramStr = !empty($params) ? ' '.implode(' ', $params) : '';
385
+		$this->executeCommand(
386
+			sprintf("MAIL FROM:<%s>%s\r\n", $address, $paramStr), [250], $failures, true
387
+			);
388
+	}
389
+
390
+	/** Overridden to add Extension support */
391
+	protected function doRcptToCommand($address)
392
+	{
393
+		$address = $this->addressEncoder->encodeString($address);
394
+		$handlers = $this->getActiveHandlers();
395
+		$params = [];
396
+		foreach ($handlers as $handler) {
397
+			$params = array_merge($params, (array) $handler->getRcptParams());
398
+		}
399
+		$paramStr = !empty($params) ? ' '.implode(' ', $params) : '';
400
+		$this->executeCommand(
401
+			sprintf("RCPT TO:<%s>%s\r\n", $address, $paramStr), [250, 251, 252], $failures, true, $address
402
+			);
403
+	}
404
+
405
+	/** Determine ESMTP capabilities by function group */
406
+	private function getCapabilities($ehloResponse)
407
+	{
408
+		$capabilities = [];
409
+		$ehloResponse = trim($ehloResponse ?? '');
410
+		$lines = explode("\r\n", $ehloResponse);
411
+		array_shift($lines);
412
+		foreach ($lines as $line) {
413
+			if (preg_match('/^[0-9]{3}[ -]([A-Z0-9-]+)((?:[ =].*)?)$/Di', $line, $matches)) {
414
+				$keyword = strtoupper($matches[1]);
415
+				$paramStr = strtoupper(ltrim($matches[2], ' ='));
416
+				$params = !empty($paramStr) ? explode(' ', $paramStr) : [];
417
+				$capabilities[$keyword] = $params;
418
+			}
419
+		}
420
+
421
+		return $capabilities;
422
+	}
423
+
424
+	/** Set parameters which are used by each extension handler */
425
+	private function setHandlerParams()
426
+	{
427
+		foreach ($this->handlers as $keyword => $handler) {
428
+			if (\array_key_exists($keyword, $this->capabilities)) {
429
+				$handler->setKeywordParams($this->capabilities[$keyword]);
430
+			}
431
+		}
432
+	}
433
+
434
+	/** Get ESMTP handlers which are currently ok to use */
435
+	private function getActiveHandlers()
436
+	{
437
+		$handlers = [];
438
+		foreach ($this->handlers as $keyword => $handler) {
439
+			if (\array_key_exists($keyword, $this->capabilities)) {
440
+				$handlers[] = $handler;
441
+			}
442
+		}
443
+
444
+		return $handlers;
445
+	}
446 446
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -255,7 +255,7 @@
 block discarded – undo
255 255
         foreach ($handlers as $handler) {
256 256
             $assoc[$handler->getHandledKeyword()] = $handler;
257 257
         }
258
-        uasort($assoc, function ($a, $b) {
258
+        uasort($assoc, function($a, $b) {
259 259
             return $a->getPriorityOver($b->getHandledKeyword());
260 260
         });
261 261
         $this->handlers = $assoc;
Please login to merge, or discard this patch.