Skip to content

Commit a171b20

Browse files
committed
ext/standard/mail.c: Move macros out of the header
1 parent 312c919 commit a171b20

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
lines changed

ext/standard/mail.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,20 @@ static void php_mail_build_headers_elems(smart_str *s, zend_string *key, zval *v
181181
} ZEND_HASH_FOREACH_END();
182182
}
183183

184+
#define PHP_MAIL_BUILD_HEADER_CHECK(target, s, key, val) \
185+
do { \
186+
if (Z_TYPE_P(val) == IS_STRING) { \
187+
php_mail_build_headers_elem(&s, key, val); \
188+
} else if (Z_TYPE_P(val) == IS_ARRAY) { \
189+
if (zend_string_equals_literal_ci(key, target)) { \
190+
zend_type_error("Header \"%s\" must be of type string, array given", target); \
191+
break; \
192+
} \
193+
php_mail_build_headers_elems(&s, key, val); \
194+
} else { \
195+
zend_type_error("Header \"%s\" must be of type array|string, %s given", ZSTR_VAL(key), zend_zval_value_name(val)); \
196+
} \
197+
} while(0)
184198

185199
PHPAPI zend_string *php_mail_build_headers(HashTable *headers)
186200
{
@@ -219,7 +233,13 @@ PHPAPI zend_string *php_mail_build_headers(HashTable *headers)
219233
} else if (zend_string_equals_literal_ci(key, "subject")) {
220234
zend_value_error("The additional headers cannot contain the \"Subject\" header");
221235
} else {
222-
PHP_MAIL_BUILD_HEADER_DEFAULT(s, key, val);
236+
if (Z_TYPE_P(val) == IS_STRING) {
237+
php_mail_build_headers_elem(&s, key, val);
238+
} else if (Z_TYPE_P(val) == IS_ARRAY) {
239+
php_mail_build_headers_elems(&s, key, val);
240+
} else {
241+
zend_type_error("Header \"%s\" must be of type array|string, %s given", ZSTR_VAL(key), zend_zval_value_name(val));
242+
}
223243
}
224244

225245
if (EG(exception)) {

ext/standard/php_mail.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,6 @@ PHP_MINFO_FUNCTION(mail);
2222
PHPAPI zend_string *php_mail_build_headers(HashTable *headers);
2323
PHPAPI extern bool php_mail(const char *to, const char *subject, const char *message, const char *headers, const char *extra_cmd);
2424

25-
#define PHP_MAIL_BUILD_HEADER_CHECK(target, s, key, val) \
26-
do { \
27-
if (Z_TYPE_P(val) == IS_STRING) { \
28-
php_mail_build_headers_elem(&s, key, val); \
29-
} else if (Z_TYPE_P(val) == IS_ARRAY) { \
30-
if (zend_string_equals_literal_ci(key, target)) { \
31-
zend_type_error("Header \"%s\" must be of type string, array given", target); \
32-
break; \
33-
} \
34-
php_mail_build_headers_elems(&s, key, val); \
35-
} else { \
36-
zend_type_error("Header \"%s\" must be of type array|string, %s given", ZSTR_VAL(key), zend_zval_value_name(val)); \
37-
} \
38-
} while(0)
39-
40-
41-
#define PHP_MAIL_BUILD_HEADER_DEFAULT(s, key, val) \
42-
do { \
43-
if (Z_TYPE_P(val) == IS_STRING) { \
44-
php_mail_build_headers_elem(&s, key, val); \
45-
} else if (Z_TYPE_P(val) == IS_ARRAY) { \
46-
php_mail_build_headers_elems(&s, key, val); \
47-
} else { \
48-
zend_type_error("Header \"%s\" must be of type array|string, %s given", ZSTR_VAL(key), zend_zval_value_name(val)); \
49-
} \
50-
} while(0)
51-
5225
typedef enum {
5326
NO_HEADER_ERROR,
5427
CONTAINS_LF_ONLY,

0 commit comments

Comments
 (0)