--- php-4.2.3/ext/standard/mail.c       Thu Nov 28 11:37:12 2002
+++ php-4.2.3-daniel/ext/standard/mail.c        Fri Nov 29 01:50:09 2002
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 #include <ctype.h>
 #include <stdio.h>
+#include <string.h>
 #include "php.h"
 #include "ext/standard/info.h"
 #if !defined(PHP_WIN32)
@@ -124,6 +125,66 @@
 }
 /* }}} */
 
+char *get_header(char *header_name, char *headers)
+{
+       char *tmp;
+       char *header_value = NULL;
+       int len=0, i;
+       
+       do {
+               if(*headers == '\n' || *headers == '\0') {
+                       if(len < strlen(header_name)) {
+                               len = 0;
+                               continue;
+                       }
+                       
+                       if((tmp = (char *)malloc(strlen(header_name) + 1)) == NULL)
+                               return NULL;
+
+                       /* rewind pointer */
+                       for(i = 0; i < len; ++i)
+                               --headers;
+
+                       /* copy data */
+                       for(i = 0; i < strlen(header_name); ++i) {
+                               tmp[i] = *headers++;
+                       }
+               
+                       tmp[i] = '\0';
+
+                       /* compare */
+                       if(strcasecmp(header_name, tmp) == 0) {
+                               header_value = (char *)malloc(len - 
+strlen(header_name) - 2 /* colon and space */ + 1);
+                               
+                               *headers++; /* colon */
+                               *headers++; /* space */
+                               
+                               for(i = 0; i < len - strlen(header_name) - 2 /* colon 
+and space */; ++i) {
+                                       header_value[i] = *headers++;
+                               }
+                               
+                               header_value[i] = '\0';
+                       }
+                       else {
+                               /* fast foward pointer :) */
+                               for(i = strlen(header_name); i < len; ++i) {
+                                       headers++;
+                               }
+                       }
+
+                       free(tmp);
+                       
+                       len = 0;
+               }
+               else {
+                       ++len;
+               }
+       }
+       while(*headers++ && header_value == NULL);
+
+       return header_value;
+}
+
 /* {{{ php_mail
  */
 PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char 
*extra_cmd)
@@ -135,6 +196,7 @@
        int ret;
        char *sendmail_path = INI_STR("sendmail_path");
        char *sendmail_cmd = NULL;
+       char *return_path;
 
        if (!sendmail_path) {
 #ifdef PHP_WIN32
@@ -169,6 +231,21 @@
                fprintf(sendmail, "To: %s\n", to);
                fprintf(sendmail, "Subject: %s\n", subject);
                if (headers != NULL) {
+
+                       if((return_path = get_header("Return-Path", headers)) == NULL) 
+{
+                               if((return_path = get_header("From", headers)) != 
+NULL) {
+                                       if(strchr(return_path, '<'))
+                                               fprintf(sendmail, "Return-Path: %s\n", 
+return_path);
+                                       else
+                                               fprintf(sendmail, "Return-Path: 
+<%s>\n", return_path);
+
+                                       free(return_path);
+                               }
+                       }
+                       else {
+                               free(return_path);
+                       }
+
                        fprintf(sendmail, "%s\n", headers);
                }
                fprintf(sendmail, "\n%s\n", message);

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to