cvs: php4 /win32 sendmail.c
| From: | Markus Fischer | Date: | Tue, 14 May 2002 15:29:29 +0000 |
| Subject: | cvs: php4 /win32 sendmail.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-11914@lists.php.net to get a copy of this message | ||
mfischer Tue May 14 11:29:29 2002 EDT
Modified files:
/php4/win32 sendmail.c
Log:
- Try to find From: field in header, fallback to sendmail_from php.ini setting
(Original patch by Michael Sisolak <msisolak@yahoo.com>, enhanced a bit).
@- Win32 mail() supports parsing 'From:' field from header (msisolak@yahoo.com, Markus).
Index: php4/win32/sendmail.c
diff -u php4/win32/sendmail.c:1.25 php4/win32/sendmail.c:1.26
--- php4/win32/sendmail.c:1.25 Tue May 14 09:52:17 2002
+++ php4/win32/sendmail.c Tue May 14 11:29:28 2002
@@ -18,7 +18,7 @@
*
*/
-/* $Id: sendmail.c,v 1.25 2002/05/14 13:52:17 mfischer Exp $ */
+/* $Id: sendmail.c,v 1.26 2002/05/14 15:29:28 mfischer Exp $ */
#include "php.h" /*php specific */
#include <stdio.h>
@@ -88,7 +88,7 @@
{"Bad Message Return Path"},
{"Bad Mail Host"},
{"Bad Message File"},
- {"\"sendmail_from\" NOT set in php.ini"},
+ {"\"sendmail_from\" not set in php.ini"},
{"Mailserver rejected our \"sendmail_from\" setting"} /* 20 */
};
@@ -125,11 +125,37 @@
strcpy(MailHost, host);
}
- if (INI_STR("sendmail_from")){
- RPath = estrdup(INI_STR("sendmail_from"));
- } else {
- *error = W32_SM_SENDMAIL_FROM_NOT_SET;
+ /* use from address as return path (if specified in headers) */
+ if (headers) {
+ char *pos = NULL;
+ /* Try to match 'From:' only at start of the string or after following a \r\n */
+ if (strstr(headers, "\r\nFrom:")) {
+ pos = strstr(headers, "\r\nFrom:") + 7;
+ } else if (!strncmp(headers, "From:", 5)) {
+ pos = headers + 5;
+ }
+ if (pos) {
+ char *pos_end;
+ /* Ignore any whitespaces */
+ while (pos && ((*pos == ' ' || *pos == '\t')))
+ pos++;
+ /* Match until \r\n or end of header string */
+ if (pos_end = strstr(pos, "\r\n")) {
+ RPath = estrndup(pos, pos_end - pos);
+ } else {
+ RPath = estrndup(pos, strlen(pos));
+ }
+ }
+ }
+
+ /* Fall back to sendmail_from php.ini setting */
+ if (!RPath) {
+ if (INI_STR("sendmail_from")) {
+ RPath = estrdup(INI_STR("sendmail_from"));
+ } else {
+ *error = W32_SM_SENDMAIL_FROM_NOT_SET;
return FAILURE;
+ }
}
/* attempt to connect with mail host */