46
46
Calculate EZMLM list hash value. */
47
47
PHP_FUNCTION (ezmlm_hash )
48
48
{
49
- pval * * pstr = NULL ;
50
49
char * str = NULL ;
51
50
unsigned long h = 5381L ;
52
- int j , l ;
51
+ int j , str_len ;
53
52
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 ;
56
56
}
57
57
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 ++ ) {
68
59
h = (h + (h <<5 )) ^ (unsigned long ) (unsigned char ) tolower (str [j ]);
69
60
}
70
61
@@ -78,57 +69,39 @@ PHP_FUNCTION(ezmlm_hash)
78
69
Send an email message */
79
70
PHP_FUNCTION (mail )
80
71
{
81
- pval * * argv [5 ];
82
72
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 ;
84
74
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 ;
96
84
}
97
85
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' ;
105
89
}
106
90
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' ;
115
94
}
116
95
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 );
126
98
127
99
if (php_mail (to , subject , message , headers , extra_cmd )) {
128
100
RETVAL_TRUE ;
129
101
} else {
130
102
RETVAL_FALSE ;
131
103
}
104
+
132
105
if (extra_cmd ) efree (extra_cmd );
133
106
}
134
107
/* }}} */
0 commit comments