Skip to content

Commit 34feef0

Browse files
author
Hartmut Holzgraefe
committed
- switch to new paramter parser
- make sure To: and Subject: do not end with a newline character
1 parent 3f9f54d commit 34feef0

File tree

1 file changed

+24
-51
lines changed

1 file changed

+24
-51
lines changed

ext/standard/mail.c

+24-51
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,16 @@
4646
Calculate EZMLM list hash value. */
4747
PHP_FUNCTION(ezmlm_hash)
4848
{
49-
pval **pstr = NULL;
5049
char *str=NULL;
5150
unsigned long h = 5381L;
52-
int j, l;
51+
int j, str_len;
5352

54-
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &pstr) == FAILURE) {
55-
WRONG_PARAM_COUNT;
53+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
54+
&str, &str_len) == FAILURE) {
55+
return;
5656
}
5757

58-
convert_to_string_ex(pstr);
59-
if (Z_STRVAL_PP(pstr)) {
60-
str = Z_STRVAL_PP(pstr);
61-
} else {
62-
php_error(E_WARNING, "Must give string parameter to ezmlm_hash()");
63-
RETURN_FALSE;
64-
}
65-
66-
l = strlen(str);
67-
for (j=0; j<l; j++) {
58+
for (j=0; j<str_len; j++) {
6859
h = (h + (h<<5)) ^ (unsigned long) (unsigned char) tolower(str[j]);
6960
}
7061

@@ -78,57 +69,39 @@ PHP_FUNCTION(ezmlm_hash)
7869
Send an email message */
7970
PHP_FUNCTION(mail)
8071
{
81-
pval **argv[5];
8272
char *to=NULL, *message=NULL, *headers=NULL, *subject=NULL, *extra_cmd=NULL;
83-
int argc;
73+
int to_len,message_len,headers_len,subject_len,extra_cmd_len;
8474

85-
argc = ZEND_NUM_ARGS();
86-
if (argc < 3 || argc > 5 || zend_get_parameters_array_ex(argc, argv) == FAILURE) {
87-
WRONG_PARAM_COUNT;
88-
}
89-
/* To: */
90-
convert_to_string_ex(argv[0]);
91-
if (Z_STRVAL_PP(argv[0])) {
92-
to = Z_STRVAL_PP(argv[0]);
93-
} else {
94-
php_error(E_WARNING, "No to field in mail command");
95-
RETURN_FALSE;
75+
76+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|ss",
77+
&to, &to_len,
78+
&subject, &subject_len,
79+
&message, &message_len,
80+
&headers, &headers_len,
81+
&extra_cmd, &extra_cmd_len
82+
) == FAILURE) {
83+
return;
9684
}
9785

98-
/* Subject: */
99-
convert_to_string_ex(argv[1]);
100-
if (Z_STRVAL_PP(argv[1])) {
101-
subject = Z_STRVAL_PP(argv[1]);
102-
} else {
103-
php_error(E_WARNING, "No subject field in mail command");
104-
RETURN_FALSE;
86+
for(to_len--;to_len;to_len--) {
87+
if(!isspace(to[to_len]))break;
88+
to[to_len]='\0';
10589
}
10690

107-
/* message body */
108-
convert_to_string_ex(argv[2]);
109-
if (Z_STRVAL_PP(argv[2])) {
110-
message = Z_STRVAL_PP(argv[2]);
111-
} else {
112-
/* this is not really an error, so it is allowed. */
113-
php_error(E_WARNING, "No message string in mail command");
114-
message = NULL;
91+
for(subject_len--;subject_len;subject_len--) {
92+
if(!isspace(subject[subject_len]))break;
93+
subject[subject_len]='\0';
11594
}
11695

117-
if (argc >= 4) { /* other headers */
118-
convert_to_string_ex(argv[3]);
119-
headers = Z_STRVAL_PP(argv[3]);
120-
}
121-
122-
if (argc == 5) { /* extra options that get passed to the mailer */
123-
convert_to_string_ex(argv[4]);
124-
extra_cmd = php_escape_shell_arg(Z_STRVAL_PP(argv[4]));
125-
}
96+
if(extra_cmd)
97+
extra_cmd = php_escape_shell_arg(extra_cmd);
12698

12799
if (php_mail(to, subject, message, headers, extra_cmd)) {
128100
RETVAL_TRUE;
129101
} else {
130102
RETVAL_FALSE;
131103
}
104+
132105
if (extra_cmd) efree (extra_cmd);
133106
}
134107
/* }}} */

0 commit comments

Comments
 (0)