Lines 23-28
Link Here
|
23 |
#include <stdio.h> |
23 |
#include <stdio.h> |
24 |
#include "php.h" |
24 |
#include "php.h" |
25 |
#include "ext/standard/info.h" |
25 |
#include "ext/standard/info.h" |
|
|
26 |
#include "ext/standard/php_string.h" |
27 |
#include "ext/standard/basic_functions.h" |
26 |
|
28 |
|
27 |
#if HAVE_SYSEXITS_H |
29 |
#if HAVE_SYSEXITS_H |
28 |
#include <sysexits.h> |
30 |
#include <sysexits.h> |
Lines 62-67
Link Here
|
62 |
*p = ' '; \ |
64 |
*p = ' '; \ |
63 |
} \ |
65 |
} \ |
64 |
|
66 |
|
|
|
67 |
extern long php_getuid(void); |
65 |
|
68 |
|
66 |
/* {{{ proto int ezmlm_hash(string addr) |
69 |
/* {{{ proto int ezmlm_hash(string addr) |
67 |
Calculate EZMLM list hash value. */ |
70 |
Calculate EZMLM list hash value. */ |
Lines 201-222
Link Here
|
201 |
int ret; |
204 |
int ret; |
202 |
char *sendmail_path = INI_STR("sendmail_path"); |
205 |
char *sendmail_path = INI_STR("sendmail_path"); |
203 |
char *sendmail_cmd = NULL; |
206 |
char *sendmail_cmd = NULL; |
|
|
207 |
char *mail_log = INI_STR("mail.log"); |
208 |
char *hdr = headers; |
209 |
|
210 |
#define MAIL_RET(val) \ |
211 |
if (hdr != headers) { \ |
212 |
efree(hdr); \ |
213 |
} \ |
214 |
return val; \ |
215 |
|
216 |
if (mail_log) { |
217 |
char *tmp; |
218 |
int l = spprintf(&tmp, 0, "mail() on [%s:%d]: To: %s -- Headers: %s\n", zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C), to, hdr ? hdr : ""); |
219 |
if (hdr) { /* find all \r\n instances and replace them with spaces, so a log line is always one line long */ |
220 |
char *p = tmp; |
221 |
while ((p = strpbrk(p, "\r\n"))) { |
222 |
*p = ' '; |
223 |
} |
224 |
tmp[l - 1] = '\n'; |
225 |
} |
226 |
_php_error_log(3, tmp, mail_log, NULL TSRMLS_CC); |
227 |
efree(tmp); |
228 |
} |
229 |
if (PG(mail_x_header)) { |
230 |
char *tmp = zend_get_executed_filename(TSRMLS_C); |
231 |
char *f; |
232 |
size_t f_len; |
233 |
php_basename(tmp, strlen(tmp), NULL, 0, &f, &f_len TSRMLS_CC); |
234 |
|
235 |
if (!sendmail_path) { |
236 |
/* sending via SMTP requires \r\n, but ... */ |
237 |
if (headers != NULL) { |
238 |
spprintf(&hdr, 0, "%s\r\nX-PHP-Originating-Script: %ld:%s\r\n", headers, php_getuid(), f); |
239 |
} else { |
240 |
spprintf(&hdr, 0, "X-PHP-Originating-Script: %ld:%s\r\n", php_getuid(), f); |
241 |
} |
242 |
} else { |
243 |
/* ... sending via sendmail requires \n */ |
244 |
if (headers != NULL) { |
245 |
spprintf(&hdr, 0, "%s\nX-PHP-Originating-Script: %ld:%s\n", headers, php_getuid(), f); |
246 |
} else { |
247 |
spprintf(&hdr, 0, "X-PHP-Originating-Script: %ld:%s\n", php_getuid(), f); |
248 |
} |
249 |
} |
250 |
efree(f); |
251 |
} |
204 |
|
252 |
|
205 |
if (!sendmail_path) { |
253 |
if (!sendmail_path) { |
206 |
#if (defined PHP_WIN32 || defined NETWARE) |
254 |
#if (defined PHP_WIN32 || defined NETWARE) |
207 |
/* handle old style win smtp sending */ |
255 |
/* handle old style win smtp sending */ |
208 |
if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, headers, subject, to, message, NULL, NULL, NULL TSRMLS_CC) == FAILURE) { |
256 |
if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, hdr, subject, to, message, NULL, NULL, NULL TSRMLS_CC) == FAILURE) { |
209 |
if (tsm_errmsg) { |
257 |
if (tsm_errmsg) { |
210 |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", tsm_errmsg); |
258 |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", tsm_errmsg); |
211 |
efree(tsm_errmsg); |
259 |
efree(tsm_errmsg); |
212 |
} else { |
260 |
} else { |
213 |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", GetSMErrorText(tsm_err)); |
261 |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", GetSMErrorText(tsm_err)); |
214 |
} |
262 |
} |
215 |
return 0; |
263 |
MAIL_RET(0); |
216 |
} |
264 |
} |
217 |
return 1; |
265 |
MAIL_RET(1); |
218 |
#else |
266 |
#else |
219 |
return 0; |
267 |
MAIL_RET(0); |
220 |
#endif |
268 |
#endif |
221 |
} |
269 |
} |
222 |
if (extra_cmd != NULL) { |
270 |
if (extra_cmd != NULL) { |
Lines 242-254
Link Here
|
242 |
if (EACCES == errno) { |
290 |
if (EACCES == errno) { |
243 |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Permission denied: unable to execute shell to run mail delivery binary '%s'", sendmail_path); |
291 |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Permission denied: unable to execute shell to run mail delivery binary '%s'", sendmail_path); |
244 |
pclose(sendmail); |
292 |
pclose(sendmail); |
245 |
return 0; |
293 |
MAIL_RET(0); |
246 |
} |
294 |
} |
247 |
#endif |
295 |
#endif |
248 |
fprintf(sendmail, "To: %s\n", to); |
296 |
fprintf(sendmail, "To: %s\n", to); |
249 |
fprintf(sendmail, "Subject: %s\n", subject); |
297 |
fprintf(sendmail, "Subject: %s\n", subject); |
250 |
if (headers != NULL) { |
298 |
if (hdr != NULL) { |
251 |
fprintf(sendmail, "%s\n", headers); |
299 |
fprintf(sendmail, "%s\n", hdr); |
252 |
} |
300 |
} |
253 |
fprintf(sendmail, "\n%s\n", message); |
301 |
fprintf(sendmail, "\n%s\n", message); |
254 |
ret = pclose(sendmail); |
302 |
ret = pclose(sendmail); |
Lines 264-279
Link Here
|
264 |
#endif |
312 |
#endif |
265 |
#endif |
313 |
#endif |
266 |
{ |
314 |
{ |
267 |
return 0; |
315 |
MAIL_RET(0); |
268 |
} else { |
316 |
} else { |
269 |
return 1; |
317 |
MAIL_RET(1); |
270 |
} |
318 |
} |
271 |
} else { |
319 |
} else { |
272 |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not execute mail delivery program '%s'", sendmail_path); |
320 |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not execute mail delivery program '%s'", sendmail_path); |
273 |
return 0; |
321 |
MAIL_RET(0); |
274 |
} |
322 |
} |
275 |
|
323 |
|
276 |
return 1; /* never reached */ |
324 |
MAIL_RET(1); /* never reached */ |
277 |
} |
325 |
} |
278 |
/* }}} */ |
326 |
/* }}} */ |
279 |
|
327 |
|