]> granicus.if.org Git - php/commitdiff
- Fixed bug #28038 (Sent incorrect RCPT TO commands to SMTP server)
authorGarrett Serack <garretts@php.net>
Tue, 18 Aug 2009 18:58:33 +0000 (18:58 +0000)
committerGarrett Serack <garretts@php.net>
Tue, 18 Aug 2009 18:58:33 +0000 (18:58 +0000)
NEWS
win32/sendmail.c

diff --git a/NEWS b/NEWS
index 68ef9e2c8bee79a54fea089da9950abf646bd606..12c3343620586ef550f97112b9074490aff8cf8e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ PHP                                                                        NEWS
 - Fixed bug #49236 (Missing PHP_SUBST(PDO_MYSQL_SHARED_LIBADD)). (Jani)
 - Fixed bug #49144 (Import of schema from different host transmits original
   authentication details). (Dmitry)
+- Fixed bug #28038  (Sent incorrect RCPT TO commands to SMTP server) (Garrett)
 
 
 13 Aug 2009, PHP 5.2.11RC1
index 85af4d923f11a3971600946e2b65f3181efb572a..cd60b40db6f164319a463eff8ddc9cc50521fce7 100644 (file)
@@ -421,7 +421,7 @@ static int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char
        }
 
        SMTP_SKIP_SPACE(RPath);
-       snprintf(Buffer, MAIL_BUFFER_SIZE, "MAIL FROM:<%s>\r\n", RPath);
+       FormatEmailAddress(Buffer, RPath, "MAIL FROM:<%s>\r\n");
        if ((res = Post(Buffer)) != SUCCESS) {
                return (res);
        }
@@ -436,7 +436,7 @@ static int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char
        while (token != NULL)
        {
                SMTP_SKIP_SPACE(token);
-               snprintf(Buffer, MAIL_BUFFER_SIZE, "RCPT TO:<%s>\r\n", token);
+               FormatEmailAddress(Buffer, token, "RCPT TO:<%s>\r\n");
                if ((res = Post(Buffer)) != SUCCESS) {
                        efree(tempMailTo);
                        return (res);
@@ -457,7 +457,7 @@ static int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char
                while (token != NULL)
                {
                        SMTP_SKIP_SPACE(token);
-                       snprintf(Buffer, MAIL_BUFFER_SIZE, "RCPT TO:<%s>\r\n", token);
+                       FormatEmailAddress(Buffer, token, "RCPT TO:<%s>\r\n");
                        if ((res = Post(Buffer)) != SUCCESS) {
                                efree(tempMailTo);
                                return (res);
@@ -487,7 +487,7 @@ static int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char
                while (token != NULL)
                {
                        SMTP_SKIP_SPACE(token);
-                       snprintf(Buffer, MAIL_BUFFER_SIZE, "RCPT TO:<%s>\r\n", token);
+                       FormatEmailAddress(Buffer, token, "RCPT TO:<%s>\r\n");
                        if ((res = Post(Buffer)) != SUCCESS) {
                                efree(tempMailTo);
                                return (res);
@@ -512,7 +512,7 @@ static int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char
                while (token != NULL)
                {
                        SMTP_SKIP_SPACE(token);
-                       snprintf(Buffer, MAIL_BUFFER_SIZE, "RCPT TO:<%s>\r\n", token);
+                       FormatEmailAddress(Buffer, token, "RCPT TO:<%s>\r\n");
                        if ((res = Post(Buffer)) != SUCCESS) {
                                efree(tempMailTo);
                                return (res);
@@ -545,7 +545,7 @@ static int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char
                        while (token != NULL)
                        {
                                SMTP_SKIP_SPACE(token);
-                               snprintf(Buffer, MAIL_BUFFER_SIZE, "RCPT TO:<%s>\r\n", token);
+                               FormatEmailAddress(Buffer, token, "RCPT TO:<%s>\r\n");
                                if ((res = Post(Buffer)) != SUCCESS) {
                                        efree(tempMailTo);
                                        return (res);
@@ -922,3 +922,30 @@ static unsigned long GetAddr(LPSTR szHost)
        }
        return (lAddr);
 } /* end GetAddr() */
+
+
+/*********************************************************************
+// Name:  int FormatEmailAddress
+// Input: 
+// Output:
+// Description: Formats the email address to remove any content ouside
+//   of the angle brackets < > as per RFC 2821.
+//
+//   Returns the invalidly formatted mail address if the < > are 
+//   unbalanced (the SMTP server should reject it if it's out of spec.)
+//  
+// Author/Date:  garretts 08/18/2009
+// History:
+//********************************************************************/
+int FormatEmailAddress(char* Buffer, char* EmailAddress, char* FormatString )  {
+       char *tmpAddress1, *tmpAddress2;
+       int result;
+
+       if( (tmpAddress1 = strchr(EmailAddress, '<')) && (tmpAddress2 = strchr(tmpAddress1, '>'))  ) {
+               *tmpAddress2 = 0; // terminate the string temporarily.
+               result = snprintf(Buffer, MAIL_BUFFER_SIZE, FormatString , tmpAddress1+1);
+               *tmpAddress2 = '>'; // put it back the way it was.
+               return result;
+       } 
+       return snprintf(Buffer, MAIL_BUFFER_SIZE , FormatString , EmailAddress );
+} /* end FormatEmailAddress() */