]> granicus.if.org Git - php/commitdiff
- Fixed bug #29334 (mail() provides incorrect message time header)
authorfoobar <sniper@php.net>
Sun, 7 Aug 2005 22:06:29 +0000 (22:06 +0000)
committerfoobar <sniper@php.net>
Sun, 7 Aug 2005 22:06:29 +0000 (22:06 +0000)
ext/imap/php_imap.c
ext/standard/mail.c
win32/sendmail.c
win32/sendmail.h

index 5f00f96282a2c63aef57b4e50108dd0f4ee6e739..5d738dbe67707bf0506495711cc64628b7c2c650 100644 (file)
@@ -3346,7 +3346,7 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char *
                strcat(bufferHeader, headers);
        }
 
-       if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, bufferHeader, subject, bufferTo, message, bufferCc, bufferBcc, rpath) != SUCCESS) {
+       if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, bufferHeader, subject, bufferTo, message, bufferCc, bufferBcc, rpath TSRMLS_CC) != SUCCESS) {
                if (tsm_errmsg) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", tsm_errmsg);
                        efree(tsm_errmsg);
index 5d56d061cded5ee0a4deb022bac900bda2a13b9f..d60c5bb3db557d76bdb44d2690682842df3e6580 100644 (file)
@@ -185,7 +185,7 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
        if (!sendmail_path) {
 #if (defined PHP_WIN32 || defined NETWARE)
                /* handle old style win smtp sending */
-               if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, headers, subject, to, message, NULL, NULL, NULL) == FAILURE) {
+               if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, headers, subject, to, message, NULL, NULL, NULL TSRMLS_CC) == FAILURE) {
                        if (tsm_errmsg) {
                                php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", tsm_errmsg);
                                efree(tsm_errmsg);
index 0764f803b6a9c6f70bb27150efc790af06a53833..5ca4f6adbbf7bdba01e2e6abe492ebc603a3aeb7 100644 (file)
 #endif
 
 #include "ext/standard/php_string.h"
+#include "ext/date/php_date.h"
 
-/*
-   extern int _daylight;
-   extern long _timezone;
- */
 /*enum
    {
    DO_CONNECT = WM_USER +1
    };
  */
 
-static char *days[] =
-{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
-static char *months[] =
-{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
-
 /* '*error_message' has to be passed around from php_mail() */
 #define SMTP_ERROR_RESPONSE_SPEC       "SMTP server response: %s"
 /* Convinient way to handle error messages from the SMTP server.
@@ -98,8 +90,6 @@ char *php_mailer = "PHP 4 WIN32";
 char *php_mailer = "PHP 4 NetWare";
 #endif /* NETWARE */
 
-char *get_header(char *h, char *headers);
-
 /* Error messages */
 static char *ErrorMessages[] =
 {
@@ -220,13 +210,12 @@ static char *php_win32_mail_trim_header(char *header TSRMLS_DC)
 //********************************************************************/
 PHPAPI int TSendMail(char *host, int *error, char **error_message,
                          char *headers, char *Subject, char *mailTo, char *data,
-                         char *mailCc, char *mailBcc, char *mailRPath)
+                         char *mailCc, char *mailBcc, char *mailRPath TSRMLS_DC)
 {
        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();
 
 #ifndef NETWARE
        WinsockStarted = FALSE;
@@ -311,7 +300,7 @@ PHPAPI int TSendMail(char *host, int *error, char **error_message,
                        MailHost, !INI_INT("smtp_port") ? 25 : INI_INT("smtp_port"));
                return FAILURE;
        } else {
-               ret = SendText(RPath, Subject, mailTo, mailCc, mailBcc, data, headers, headers_lc, error_message);
+               ret = SendText(RPath, Subject, mailTo, mailCc, mailBcc, data, headers, headers_lc, error_message TSRMLS_CC);
                TSMClose();
                if (RPath) {
                        efree(RPath);
@@ -388,8 +377,8 @@ PHPAPI char *GetSMErrorText(int index)
 // Author/Date:  jcar 20/9/96
 // History:
 //*******************************************************************/
-int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char *mailBcc, char *data, 
-                        char *headers, char *headers_lc, char **error_message)
+static int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char *mailBcc, char *data, 
+                        char *headers, char *headers_lc, char **error_message TSRMLS_DC)
 {
        int res;
        char *p;
@@ -609,9 +598,9 @@ int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char *mailB
 
        /* send message header */
        if (Subject == NULL) {
-               res = PostHeader(RPath, "No Subject", mailTo, stripped_header);
+               res = PostHeader(RPath, "No Subject", mailTo, stripped_header TSRMLS_CC);
        } else {
-               res = PostHeader(RPath, Subject, mailTo, stripped_header);
+               res = PostHeader(RPath, Subject, mailTo, stripped_header TSRMLS_CC);
        }
        if (stripped_header) {
                efree(stripped_header);
@@ -665,7 +654,8 @@ int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char *mailB
        return (SUCCESS);
 }
 
-int addToHeader(char **header_buffer, const char *specifier, char *string) {
+static int addToHeader(char **header_buffer, const char *specifier, char *string)
+{
        if (NULL == (*header_buffer = erealloc(*header_buffer, strlen(*header_buffer) + strlen(specifier) + strlen(string) + 1))) {
                return 0;
        }
@@ -684,16 +674,12 @@ int addToHeader(char **header_buffer, const char *specifier, char *string) {
 // Author/Date:  jcar 20/9/96
 // History:
 //********************************************************************/
-int PostHeader(char *RPath, char *Subject, char *mailTo, char *xheaders)
+static int PostHeader(char *RPath, char *Subject, char *mailTo, char *xheaders TSRMLS_DC)
 {
-
        /* Print message header according to RFC 822 */
        /* Return-path, Received, Date, From, Subject, Sender, To, cc */
 
-       time_t tNow = time(NULL);
-       struct tm *tm = localtime(&tNow);
-       int zoneh = abs(_timezone);
-       int zonem, res;
+       int res;
        char *header_buffer;
        char *headers_lc = NULL;
        size_t i;
@@ -711,21 +697,13 @@ int PostHeader(char *RPath, char *Subject, char *mailTo, char *xheaders)
                efree(headers_lc);
                return OUT_OF_MEMORY;
        }
-       zoneh /= (60 * 60);
-       zonem = (abs(_timezone) / 60) - (zoneh * 60);
 
-       if(!xheaders || !strstr(headers_lc, "date:")){
-               sprintf(header_buffer, "Date: %s, %02d %s %04d %02d:%02d:%02d %s%02d%02d\r\n",
-                                        days[tm->tm_wday],
-                                        tm->tm_mday,
-                                        months[tm->tm_mon],
-                                        tm->tm_year + 1900,
-                                        tm->tm_hour,
-                                        tm->tm_min,
-                                        tm->tm_sec,
-                                        (_timezone <= 0) ? "+" : (_timezone > 0) ? "-" : "",
-                                        zoneh,
-                                        zonem);
+       if (!xheaders || !strstr(headers_lc, "date:")) {
+               time_t tNow = time(NULL);
+               char *dt = php_format_date("r", 1, tNow, 1 TSRMLS_CC);
+
+               sprintf(header_buffer, "Date: %s\r\n", dt);
+               efree(dt);
        }
 
        if (!headers_lc || !strstr(headers_lc, "from:")) {
@@ -781,7 +759,7 @@ PostHeader_outofmem:
 // Author/Date:  jcar 20/9/96
 // History:
 //********************************************************************/
-int MailConnect()
+static int MailConnect()
 {
 
        int res;
@@ -822,10 +800,6 @@ int MailConnect()
 }
 
 
-
-
-
-
 /*********************************************************************
 // Name:  Post
 // Input:
@@ -834,7 +808,7 @@ int MailConnect()
 // Author/Date:  jcar 20/9/96
 // History:
 //********************************************************************/
-int Post(LPCSTR msg)
+static int Post(LPCSTR msg)
 {
        int len = strlen(msg);
        int slen;
@@ -861,7 +835,7 @@ int Post(LPCSTR msg)
 // Author/Date:  jcar 20/9/96
 // History:
 //********************************************************************/
-int Ack(char **server_response)
+static int Ack(char **server_response)
 {
        static char buf[MAIL_BUFFER_SIZE];
        int rlen;
@@ -921,7 +895,7 @@ int Ack(char **server_response)
 // Author/Date:  jcar 20/9/96
 // History:
 //********************************************************************/
-unsigned long GetAddr(LPSTR szHost)
+static unsigned long GetAddr(LPSTR szHost)
 {
        LPHOSTENT lpstHost;
        u_long lAddr = INADDR_ANY;
index 28b5d734994f1ec1b34e0fd913dd180d18827da1..0ec916d6c8fc7ab5a5d5b62511a4c27b071aba4d 100644 (file)
 
 PHPAPI int TSendMail(char *smtpaddr, int *returnerror, char **error_message,
                          char *RPath, char *Subject, char *mailTo, char *data,
-                         char *mailCc, char *mailBcc, char *mailRPath);
+                         char *mailCc, char *mailBcc, char *mailRPath TSRMLS_DC);
 PHPAPI void TSMClose(void);
-int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char *mailBcc, char *data, 
-                        char *headers, char *headers_lc, char **error_message);
+static int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char *mailBcc, char *data, 
+                        char *headers, char *headers_lc, char **error_message TSRMLS_DC);
 PHPAPI char *GetSMErrorText(int index);
 
-int MailConnect();
-int PostHeader(char *, char *, char *, char *);
-int Post(LPCSTR msg);
-int Ack(char **server_response);
-unsigned long GetAddr(LPSTR szHost);
+static int MailConnect();
+static int PostHeader(char *RPath, char *Subject, char *mailTo, char *xheaders TSRMLS_DC);
+static int Post(LPCSTR msg);
+static int Ack(char **server_response);
+static unsigned long GetAddr(LPSTR szHost);
 #endif                                                 /* sendmail_h */