]> granicus.if.org Git - php/commitdiff
MFH
authorFrank M. Kromann <fmk@php.net>
Sat, 30 Nov 2002 21:52:36 +0000 (21:52 +0000)
committerFrank M. Kromann <fmk@php.net>
Sat, 30 Nov 2002 21:52:36 +0000 (21:52 +0000)
ext/imap/php_imap.c
win32/sendmail.c

index 4a475d85e751b80a7159641e51dec6ec45a05d87..de4bb1e16258f73533e7101e08536016f271cd2c 100644 (file)
@@ -3144,10 +3144,22 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char *
        char *tempMailTo;
        char *tsm_errmsg = NULL;
        ADDRESS *addr;
-       char *bufferTo = NULL, *bufferCc = NULL, *bufferBcc = NULL;
-       int offset;
-
+       char *bufferTo = NULL, *bufferCc = NULL, *bufferBcc = NULL, *bufferHeader = NULL;
+       int offset, bufferLen = 0;;
+
+       if (headers)
+               bufferLen += strlen(headers);
+       if (to)
+               bufferLen += strlen(to) + 6;
+       if (cc)
+               bufferLen += strlen(cc) + 6;
+
+       bufferHeader = (char *)emalloc(bufferLen);
+       memset(bufferHeader, 0, bufferLen);
        if (to && *to) {
+               strcat(bufferHeader, "To: ");
+               strcat(bufferHeader, to);
+               strcat(bufferHeader, "\r\n");
                tempMailTo = estrdup(to);
                bufferTo = (char *)emalloc(strlen(to));
                offset = 0;
@@ -3168,6 +3180,9 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char *
        }
 
        if (cc && *cc) {
+               strcat(bufferHeader, "Cc: ");
+               strcat(bufferHeader, cc);
+               strcat(bufferHeader, "\r\n");
                tempMailTo = estrdup(cc);
                bufferCc = (char *)emalloc(strlen(cc));
                offset = 0;
@@ -3207,8 +3222,9 @@ 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, headers, subject, bufferTo, message, bufferCc, bufferBcc, rpath) != SUCCESS) {
+       if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, bufferHeader, subject, bufferTo, message, bufferCc, bufferBcc, rpath) != SUCCESS) {
                if (tsm_errmsg) {
                        php_error(E_WARNING, "%s(): %s", get_active_function_name(TSRMLS_C), tsm_errmsg);
                        efree(tsm_errmsg);
@@ -3226,6 +3242,9 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char *
        if (bufferBcc) {
                efree(bufferBcc);
        }
+       if (bufferHeader) {
+               efree(bufferHeader);
+       }
 #else
        if (!INI_STR("sendmail_path")) {
                return 0;
index 8e4581595e724bf4cbc2e2359c4844ab48c31b6b..d98ce3c768c071aab4eb29a2d6e01b74cdf83b66 100644 (file)
@@ -414,8 +414,28 @@ int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char *mailB
        }
        efree(tempMailTo);
 
+       if (mailCc && *mailCc) {
+               tempMailTo = estrdup(mailCc);
+               /* Send mail to all rcpt's */
+               token = strtok(tempMailTo, ",");
+               while(token != NULL)
+               {
+                       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, ",");
+               }
+               efree(tempMailTo);
+       }
        /* Send mail to all Cc rcpt's */
-       if (headers && (pos1 = strstr(headers_lc, "cc:"))) {
+       else if (headers && (pos1 = strstr(headers_lc, "cc:"))) {
                /* Real offset is memaddress from the original headers + difference of
                 * string found in the lowercase headrs + 3 characters to jump over
                 * the cc: */
@@ -444,8 +464,11 @@ int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char *mailB
                efree(tempMailTo);
        }
 
-       if (mailCc && *mailCc) {
-               tempMailTo = estrdup(mailCc);
+       /* Send mail to all Bcc rcpt's
+          This is basically a rip of the Cc code above.
+          Just don't forget to remove the Bcc: from the header afterwards. */
+       if (mailBcc && *mailBcc) {
+               tempMailTo = estrdup(mailBcc);
                /* Send mail to all rcpt's */
                token = strtok(tempMailTo, ",");
                while(token != NULL)
@@ -464,11 +487,7 @@ int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char *mailB
                }
                efree(tempMailTo);
        }
-
-       /* Send mail to all Bcc rcpt's
-          This is basically a rip of the Cc code above.
-          Just don't forget to remove the Bcc: from the header afterwards. */
-       if (headers) {
+       else if (headers) {
                if (pos1 = strstr(headers_lc, "bcc:")) {
                        /* Real offset is memaddress from the original headers + difference of
                         * string found in the lowercase headrs + 4 characters to jump over
@@ -526,27 +545,6 @@ int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char *mailB
                }
        }
 
-       if (mailBcc && *mailBcc) {
-               tempMailTo = estrdup(mailBcc);
-               /* Send mail to all rcpt's */
-               token = strtok(tempMailTo, ",");
-               while(token != NULL)
-               {
-                       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, ",");
-               }
-               efree(tempMailTo);
-       }
-
        if ((res = Post("DATA\r\n")) != SUCCESS) {
                efree(stripped_header);
                return (res);