@@ -136,32 +136,32 @@ public static function escape(string $string): string
136136 */
137137 public static function decodeUtf7Imap (string $ string ): string
138138 {
139- // If the string doesn't contain any '&' character, it's not UTF-7 encoded
139+ // If the string doesn't contain any '&' character, it's not UTF-7 encoded/
140140 if (! str_contains ($ string , '& ' )) {
141141 return $ string ;
142142 }
143143
144- // Handle the special case of '&-' which represents '&' in UTF-7
144+ // Handle the special case of '&-' which represents '&' in UTF-7.
145145 if ($ string === '&- ' ) {
146146 return '& ' ;
147147 }
148148
149- // Direct implementation of IMAP's modified UTF-7 decoding
149+ // Direct implementation of IMAP's modified UTF-7 decoding.
150150 return preg_replace_callback ('/&([^-]*)-?/ ' , function ($ matches ) {
151- // If it's just an ampersand
151+ // If it's just an ampersand.
152152 if ($ matches [1 ] === '' ) {
153153 return '& ' ;
154154 }
155155
156- // If it's the special case for ampersand
156+ // If it's the special case for ampersand.
157157 if ($ matches [1 ] === '- ' ) {
158158 return '& ' ;
159159 }
160160
161- // Convert modified base64 to standard base64
161+ // Convert modified base64 to standard base64.
162162 $ base64 = strtr ($ matches [1 ], ', ' , '/ ' );
163163
164- // Add padding if necessary
164+ // Add padding if necessary.
165165 switch (strlen ($ base64 ) % 4 ) {
166166 case 1 : $ base64 .= '=== ' ;
167167 break ;
@@ -171,15 +171,15 @@ public static function decodeUtf7Imap(string $string): string
171171 break ;
172172 }
173173
174- // Decode base64 to binary
174+ // Decode base64 to binary.
175175 $ binary = base64_decode ($ base64 , true );
176176
177177 if ($ binary === false ) {
178- // If decoding fails, return the original string
178+ // If decoding fails, return the original string.
179179 return '& ' .$ matches [1 ].(isset ($ matches [2 ]) ? $ matches [2 ] : '' );
180180 }
181181
182- // Convert binary UTF-16BE to UTF-8
182+ // Convert binary UTF-16BE to UTF-8.
183183 $ result = '' ;
184184
185185 for ($ i = 0 ; $ i < strlen ($ binary ); $ i += 2 ) {
0 commit comments