Skip to content

Commit 4474f92

Browse files
author
Ilia Alshanetsky
committed
Fixed bug #22355 (PHP would remove folding from Subject & To fields).
1 parent a628a6a commit 4474f92

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

ext/standard/mail.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@
4646
#include "netware/sysexits.h" /* For exit status codes like EX_OK */
4747
#endif
4848

49+
#define SKIP_LONG_HEADER_SEP(str, pos) \
50+
if (str[pos] == '\r' && str[pos + 1] == '\n' && (str[pos + 2] == ' ' || str[pos + 2] == '\t')) { \
51+
pos += 3; \
52+
while (str[pos] == ' ' || str[pos] == '\t') { \
53+
pos++; \
54+
} \
55+
continue; \
56+
} \
57+
4958
/* {{{ proto int ezmlm_hash(string addr)
5059
Calculate EZMLM list hash value. */
5160
PHP_FUNCTION(ezmlm_hash)
@@ -102,6 +111,12 @@ PHP_FUNCTION(mail)
102111
}
103112
for (i = 0; to[i]; i++) {
104113
if (iscntrl((unsigned char) to[i])) {
114+
/* According to RFC 822, section 3.1.1 long headers may be separated into
115+
* parts using CRLF followed at least one linear-white-space character ('\t' or ' ').
116+
* To prevent these separators from being replaced with a space, we use the
117+
* SKIP_LONG_HEADER_SEP to skip over them.
118+
*/
119+
SKIP_LONG_HEADER_SEP(to, i);
105120
to[i] = ' ';
106121
}
107122
}
@@ -116,6 +131,7 @@ PHP_FUNCTION(mail)
116131
}
117132
for(i = 0; subject[i]; i++) {
118133
if (iscntrl((unsigned char) subject[i])) {
134+
SKIP_LONG_HEADER_SEP(subject, i);
119135
subject[i] = ' ';
120136
}
121137
}

0 commit comments

Comments
 (0)