]> granicus.if.org Git - php/commitdiff
MFH: - Fixed bug #28976 (use From: from headers if sendmail_from is empty)
authorfoobar <sniper@php.net>
Wed, 19 Jan 2005 17:38:41 +0000 (17:38 +0000)
committerfoobar <sniper@php.net>
Wed, 19 Jan 2005 17:38:41 +0000 (17:38 +0000)
win32/sendmail.c

index f6894c1ba9109bf1067271bc04c85002c2dc14d0..156ffef90332004cacc1ac630b61f0171c06003a 100644 (file)
@@ -211,6 +211,7 @@ int TSendMail(char *host, int *error, char **error_message,
        int ret;
        char *RPath = NULL;
        char *headers_lc = NULL; /* headers_lc is only created if we've a header at all */
+       char *pos1 = NULL, *pos2 = NULL;
        TSRMLS_FETCH();
 
        WinsockStarted = FALSE;
@@ -250,9 +251,21 @@ int TSendMail(char *host, int *error, char **error_message,
        /* Fall back to sendmail_from php.ini setting */
        if (mailRPath && *mailRPath) {
                RPath = estrdup(mailRPath);
-       }
-       else if (INI_STR("sendmail_from")) {
+       } else if (INI_STR("sendmail_from")) {
                RPath = estrdup(INI_STR("sendmail_from"));
+       } else if (     headers_lc &&
+                               (pos1 = strstr(headers_lc, "from:")) &&
+                               ((pos1 == headers_lc) || (*(pos1-1) == '\n'))
+       ) {
+               /* Real offset is memaddress from the original headers + difference of
+                * string found in the lowercase headrs + 5 characters to jump over   
+                * the from: */
+               pos1 = headers + (pos1 - headers_lc) + 5;
+               if (NULL == (pos2 = strstr(pos1, "\r\n"))) {
+                       RPath = estrndup(pos1, strlen(pos1));
+               } else {
+                       RPath = estrndup(pos1, pos2-pos1);
+               }
        } else {
                if (headers) {
                        efree(headers);