iliaa Wed Jul 23 12:03:27 2003 EDT
Modified files: (Branch: PHP_4_3)
/php-src/win32 sendmail.c
Log:
MFH:
Fixed bug #23798 (Spaces were not being stripped from Bcc header)
Fixed bug #24663 (\n. sequences were not being escaped)
Index: php-src/win32/sendmail.c
diff -u php-src/win32/sendmail.c:1.47.2.4 php-src/win32/sendmail.c:1.47.2.5
--- php-src/win32/sendmail.c:1.47.2.4 Sun Feb 2 22:47:00 2003
+++ php-src/win32/sendmail.c Wed Jul 23 12:03:27 2003
@@ -17,7 +17,7 @@
*
*/
-/* $Id: sendmail.c,v 1.47.2.4 2003/02/03 03:47:00 pollita Exp $ */
+/* $Id: sendmail.c,v 1.47.2.5 2003/07/23 16:03:27 iliaa Exp $ */
#include "php.h" /*php specific */
#include <stdio.h>
@@ -25,6 +25,7 @@
#include <winsock.h>
#include "time.h"
#include <string.h>
+#include <math.h>
#include <malloc.h>
#include <memory.h>
#include <winbase.h>
@@ -35,6 +36,8 @@
#include "ext/pcre/php_pcre.h"
#endif
+#include "ext/standard/php_string.h"
+
/*
extern int _daylight;
extern long _timezone;
@@ -63,6 +66,8 @@
efree(response); \
} \
}
+#define SMTP_SKIP_SPACE(str) { while (isspace(*str)) { str++; } }
+
#ifndef THREAD_SAFE
char Buffer[MAIL_BUFFER_SIZE];
@@ -125,6 +130,13 @@
#define PHP_WIN32_MAIL_RMVDBL_PATTERN "/^\r\n|(\r\n)+$/m"
#define PHP_WIN32_MAIL_RMVDBL_REPLACE ""
+/* This pattern escapes \n. inside the message body. It prevents
+ * premature end of message if \n.\n or \r\n.\r\n is encountered
+ * and ensures that \n. sequences are properly displayed in the
+ * message body. */
+#define PHP_WIN32_MAIL_DOT_PATTERN "\n."
+#define PHP_WIN32_MAIL_DOT_REPLACE "\n.."
+
/* This function is meant to unify the headers passed to to mail()
* This means, use PCRE to transform single occurences of \n or \r in \r\n
* As a second step we also eleminate all \r\n occurences which are:
@@ -355,6 +367,8 @@
char *tempMailTo, *token, *pos1, *pos2;
char *server_response = NULL;
char *stripped_header = NULL;
+ char *data_cln;
+ int data_cln_len;
/* check for NULL parameters */
if (data == NULL)
@@ -452,6 +466,7 @@
token = strtok(tempMailTo, ",");
while(token != NULL)
{
+ SMTP_SKIP_SPACE(token);
sprintf(Buffer, "RCPT TO:<%s>\r\n", token);
if ((res = Post(Buffer)) != SUCCESS)
return (res);
@@ -473,6 +488,7 @@
token = strtok(tempMailTo, ",");
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);
@@ -506,6 +522,7 @@
token = strtok(tempMailTo, ",");
while(token != NULL)
{
+ SMTP_SKIP_SPACE(token);
sprintf(Buffer, "RCPT TO:<%s>\r\n", token);
if ((res = Post(Buffer)) != SUCCESS) {
return (res);
@@ -574,30 +591,43 @@
return (res);
}
+ /* Escape \n. sequences
+ * We use php_str_to_str() and not php_str_replace_in_subject(), since the
latter
+ * uses ZVAL as it's parameters */
+ data_cln = php_str_to_str(data, strlen(data), PHP_WIN32_MAIL_DOT_PATTERN,
sizeof(PHP_WIN32_MAIL_DOT_PATTERN) - 1,
+ PHP_WIN32_MAIL_DOT_REPLACE,
sizeof(PHP_WIN32_MAIL_DOT_REPLACE) - 1, &data_cln_len);
+
/* send message contents in 1024 chunks */
- if (strlen(data) <= 1024) {
- if ((res = Post(data)) != SUCCESS)
+ if (data_cln_len <= 1024) {
+ if ((res = Post(data_cln)) != SUCCESS) {
+ efree(data_cln);
return (res);
+ }
} else {
- p = data;
- while (1) {
- if (*p == '\0')
- break;
- if (strlen(p) >= 1024)
- i = 1024;
- else
- i = strlen(p);
-
- /* put next chunk in buffer */
- strncpy(Buffer, p, i);
- Buffer[i] = '\0';
- p += i;
+ int parts = (int) floor(data_cln_len / 1024);
+ p = data_cln;
+ for (i = 0; i < parts; i++) {
+ strlcpy(Buffer, p, 1024);
+ Buffer[1024] = '\0';
+ p += 1024;
+send_chunk:
/* send chunk */
- if ((res = Post(Buffer)) != SUCCESS)
+ if ((res = Post(Buffer)) != SUCCESS) {
+ efree(data_cln);
return (res);
+ }
+ }
+
+ if ((parts * 1024) < data_cln_len) {
+ i = data_cln_len - (parts * 1024);
+ strlcpy(Buffer, p, i);
+ Buffer[i] = '\0';
+ goto send_chunk;
}
}
+
+ efree(data_cln);
/*send termination dot */
if ((res = Post("\r\n.\r\n")) != SUCCESS)
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php