iliaa           Wed Jul 23 12:03:10 2003 EDT

  Modified files:              
    /php-src/win32      sendmail.c 
  Log:
  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.54 php-src/win32/sendmail.c:1.55
--- php-src/win32/sendmail.c:1.54       Sat Feb 15 22:48:49 2003
+++ php-src/win32/sendmail.c    Wed Jul 23 12:03:10 2003
@@ -17,7 +17,7 @@
  *
  */
 
-/* $Id: sendmail.c,v 1.54 2003/02/16 03:48:49 wez Exp $ */
+/* $Id: sendmail.c,v 1.55 2003/07/23 16:03:10 iliaa Exp $ */
 
 #include "php.h"                               /*php specific */
 #include <stdio.h>
@@ -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 @@
                                                                                       
         efree(response); \
                                                                                       
 } \
                                                                                }
+#define SMTP_SKIP_SPACE(str)   { while (isspace(*str)) { str++; } }
+
 
 #ifndef THREAD_SAFE
 char Buffer[MAIL_BUFFER_SIZE];
@@ -139,6 +144,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:
@@ -378,6 +390,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)
@@ -475,6 +489,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);
@@ -496,6 +511,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);
@@ -529,6 +545,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);
@@ -597,30 +614,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

Reply via email to