sniper Fri Jan 6 02:04:22 2006 UTC
Modified files:
/php-src/win32 sendmail.c
Log:
- Cleanups:
* unify the address handling to always strip leading whitespace
* ws fixes
http://cvs.php.net/viewcvs.cgi/php-src/win32/sendmail.c?r1=1.65&r2=1.66&diff_format=u
Index: php-src/win32/sendmail.c
diff -u php-src/win32/sendmail.c:1.65 php-src/win32/sendmail.c:1.66
--- php-src/win32/sendmail.c:1.65 Sun Aug 7 22:06:29 2005
+++ php-src/win32/sendmail.c Fri Jan 6 02:04:22 2006
@@ -17,7 +17,7 @@
*
*/
-/* $Id: sendmail.c,v 1.65 2005/08/07 22:06:29 sniper Exp $ */
+/* $Id: sendmail.c,v 1.66 2006/01/06 02:04:22 sniper Exp $ */
#include "php.h" /*php specific */
#include <stdio.h>
@@ -42,8 +42,8 @@
#include "ext/pcre/php_pcre.h"
#endif
-#include "ext/standard/php_string.h"
-#include "ext/date/php_date.h"
+#include "ext/standard/php_string.h"
+#include "ext/date/php_date.h"
/*enum
{
@@ -269,7 +269,7 @@
if (NULL == (pos2 = strstr(pos1, "\r\n"))) {
RPath = estrndup(pos1, strlen(pos1));
} else {
- RPath = estrndup(pos1, pos2-pos1);
+ RPath = estrndup(pos1, pos2 - pos1);
}
} else {
if (headers) {
@@ -360,7 +360,7 @@
/*********************************************************************
-// Name: TSendText
+// Name: SendText
// Input: 1) RPath: return path of the message
// Is used to fill the "Return-Path" and the
// "X-Sender" fields of the message.
@@ -411,17 +411,20 @@
/* attempt reconnect if the first Post fail */
if ((res = Post(Buffer)) != SUCCESS) {
MailConnect();
- if ((res = Post(Buffer)) != SUCCESS)
+ if ((res = Post(Buffer)) != SUCCESS) {
return (res);
+ }
}
if ((res = Ack(&server_response)) != SUCCESS) {
SMTP_ERROR_RESPONSE(server_response);
return (res);
}
+ SMTP_SKIP_SPACE(RPath);
snprintf(Buffer, MAIL_BUFFER_SIZE, "MAIL FROM:<%s>\r\n", RPath);
- if ((res = Post(Buffer)) != SUCCESS)
+ if ((res = Post(Buffer)) != SUCCESS) {
return (res);
+ }
if ((res = Ack(&server_response)) != SUCCESS) {
SMTP_ERROR_RESPONSE(server_response);
return W32_SM_SENDMAIL_FROM_MALFORMED;
@@ -430,8 +433,9 @@
tempMailTo = estrdup(mailTo);
/* Send mail to all rcpt's */
token = strtok(tempMailTo, ",");
- while(token != NULL)
+ while (token != NULL)
{
+ SMTP_SKIP_SPACE(token);
snprintf(Buffer, MAIL_BUFFER_SIZE, "RCPT TO:<%s>\r\n", token);
if ((res = Post(Buffer)) != SUCCESS) {
efree(tempMailTo);
@@ -450,8 +454,9 @@
tempMailTo = estrdup(mailCc);
/* Send mail to all rcpt's */
token = strtok(tempMailTo, ",");
- while(token != NULL)
+ while (token != NULL)
{
+ SMTP_SKIP_SPACE(token);
snprintf(Buffer, MAIL_BUFFER_SIZE, "RCPT TO:<%s>\r\n",
token);
if ((res = Post(Buffer)) != SUCCESS) {
efree(tempMailTo);
@@ -473,23 +478,23 @@
* the cc: */
pos1 = headers + (pos1 - headers_lc) + 3;
if (NULL == (pos2 = strstr(pos1, "\r\n"))) {
-
tempMailTo = estrndup(pos1, strlen(pos1));
-
} else {
- tempMailTo = estrndup(pos1, pos2-pos1);
-
+ tempMailTo = estrndup(pos1, pos2 - pos1);
}
token = strtok(tempMailTo, ",");
- while(token != NULL)
+ while (token != NULL)
{
SMTP_SKIP_SPACE(token);
- sprintf(Buffer, "RCPT TO:<%s>\r\n", token);
- if ((res = Post(Buffer)) != SUCCESS)
+ snprintf(Buffer, MAIL_BUFFER_SIZE, "RCPT TO:<%s>\r\n",
token);
+ if ((res = Post(Buffer)) != SUCCESS) {
+ efree(tempMailTo);
return (res);
+ }
if ((res = Ack(&server_response)) != SUCCESS) {
SMTP_ERROR_RESPONSE(server_response);
+ efree(tempMailTo);
return (res);
}
token = strtok(NULL, ",");
@@ -504,7 +509,7 @@
tempMailTo = estrdup(mailBcc);
/* Send mail to all rcpt's */
token = strtok(tempMailTo, ",");
- while(token != NULL)
+ while (token != NULL)
{
SMTP_SKIP_SPACE(token);
snprintf(Buffer, MAIL_BUFFER_SIZE, "RCPT TO:<%s>\r\n",
token);
@@ -528,7 +533,6 @@
* the bcc: */
pos1 = headers + (pos1 - headers_lc) + 4;
if (NULL == (pos2 = strstr(pos1, "\r\n"))) {
- int foo = strlen(pos1);
tempMailTo = estrndup(pos1, strlen(pos1));
/* Later, when we remove the Bcc: out of the
header we know it was the last thing. */
@@ -538,15 +542,17 @@
}
token = strtok(tempMailTo, ",");
- while(token != NULL)
+ while (token != NULL)
{
SMTP_SKIP_SPACE(token);
- sprintf(Buffer, "RCPT TO:<%s>\r\n", token);
+ snprintf(Buffer, MAIL_BUFFER_SIZE, "RCPT
TO:<%s>\r\n", token);
if ((res = Post(Buffer)) != SUCCESS) {
+ efree(tempMailTo);
return (res);
}
if ((res = Ack(&server_response)) != SUCCESS) {
SMTP_ERROR_RESPONSE(server_response);
+ efree(tempMailTo);
return (res);
}
token = strtok(NULL, ",");
@@ -699,11 +705,11 @@
}
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);
+ 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:")) {
@@ -721,7 +727,7 @@
goto PostHeader_outofmem;
}
}
- if(xheaders){
+ if (xheaders) {
if (!addToHeader(&header_buffer, "%s\r\n", xheaders)) {
goto PostHeader_outofmem;
}
@@ -779,7 +785,7 @@
{
return (FAILED_TO_RESOLVE_HOST);
}
- */
+ */
portnum = (short) INI_INT("smtp_port");
if (!portnum) {
@@ -842,11 +848,11 @@
int Index = 0;
int Received = 0;
- again:
+again:
- if ((rlen = recv(sc, buf + Index, ((MAIL_BUFFER_SIZE) - 1) - Received,
0)) < 1)
+ if ((rlen = recv(sc, buf + Index, ((MAIL_BUFFER_SIZE) - 1) - Received,
0)) < 1) {
return (FAILED_TO_RECEIVE);
-
+ }
Received += rlen;
buf[Received] = 0;
/*err_msg fprintf(stderr,"Received: (%d bytes) %s", rlen, buf +
Index); */
@@ -918,4 +924,4 @@
}
}
return (lAddr);
-} /* end
GetAddr() */
+} /* end GetAddr() */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php