summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2003-07-23 16:03:10 +0000
committerIlia Alshanetsky <iliaa@php.net>2003-07-23 16:03:10 +0000
commit9826911139d1ed8fd19b26b47a5b8694c0c8e668 (patch)
treeef4e8bfc5b9928747091f2273a0213fa943d5ff1 /win32
parent237116aa2747440a4fe74432a5d792922f235538 (diff)
downloadphp-git-9826911139d1ed8fd19b26b47a5b8694c0c8e668.tar.gz
Fixed bug #23798 (Spaces were not being stripped from Bcc header)
Fixed bug #24663 (\n. sequences were not being escaped)
Diffstat (limited to 'win32')
-rw-r--r--win32/sendmail.c64
1 files changed, 47 insertions, 17 deletions
diff --git a/win32/sendmail.c b/win32/sendmail.c
index 82f8efab5d..4082b5f7a8 100644
--- a/win32/sendmail.c
+++ b/win32/sendmail.c
@@ -29,6 +29,7 @@
#endif /* NETWARE */
#include "time.h"
#include <string.h>
+#include <math.h>
#ifndef NETWARE
#include <malloc.h>
#include <memory.h>
@@ -41,6 +42,8 @@
#include "ext/pcre/php_pcre.h"
#endif
+#include "ext/standard/php_string.h"
+
/*
extern int _daylight;
extern long _timezone;
@@ -69,6 +72,8 @@ static char *months[] =
efree(response); \
} \
}
+#define SMTP_SKIP_SPACE(str) { while (isspace(*str)) { str++; } }
+
#ifndef THREAD_SAFE
char Buffer[MAIL_BUFFER_SIZE];
@@ -139,6 +144,13 @@ static char *ErrorMessages[] =
#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:
@@ -378,6 +390,8 @@ int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char *mailB
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)
@@ -475,6 +489,7 @@ int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char *mailB
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);
@@ -496,6 +511,7 @@ int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char *mailB
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);
@@ -529,6 +545,7 @@ int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char *mailB
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);
@@ -597,31 +614,44 @@ int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char *mailB
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)
return (res);