summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfoobar <sniper@php.net>2005-08-07 22:06:29 +0000
committerfoobar <sniper@php.net>2005-08-07 22:06:29 +0000
commitdf5cfe27b48c41d79861af3342d3adbbe33467fb (patch)
tree9a22aa56d7f13b14dcbad7dc7dd149279dc84396
parent757a76df3f0dd4d6b75856befe0cf1621ef71662 (diff)
downloadphp-git-df5cfe27b48c41d79861af3342d3adbbe33467fb.tar.gz
- Fixed bug #29334 (mail() provides incorrect message time header)
-rw-r--r--ext/imap/php_imap.c2
-rw-r--r--ext/standard/mail.c2
-rw-r--r--win32/sendmail.c68
-rw-r--r--win32/sendmail.h16
4 files changed, 31 insertions, 57 deletions
diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c
index 5f00f96282..5d738dbe67 100644
--- a/ext/imap/php_imap.c
+++ b/ext/imap/php_imap.c
@@ -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);
diff --git a/ext/standard/mail.c b/ext/standard/mail.c
index 5d56d061cd..d60c5bb3db 100644
--- a/ext/standard/mail.c
+++ b/ext/standard/mail.c
@@ -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);
diff --git a/win32/sendmail.c b/win32/sendmail.c
index 0764f803b6..5ca4f6adbb 100644
--- a/win32/sendmail.c
+++ b/win32/sendmail.c
@@ -43,22 +43,14 @@
#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;
diff --git a/win32/sendmail.h b/win32/sendmail.h
index 28b5d73499..0ec916d6c8 100644
--- a/win32/sendmail.h
+++ b/win32/sendmail.h
@@ -36,15 +36,15 @@
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 */