diff options
author | Garrett Serack <garretts@php.net> | 2009-08-18 18:58:33 +0000 |
---|---|---|
committer | Garrett Serack <garretts@php.net> | 2009-08-18 18:58:33 +0000 |
commit | 827469c94e9d3ec554dabcb79f478e06b31f6a14 (patch) | |
tree | a7d254da3830e50a4600b34896de532c9fd74c25 /win32/sendmail.c | |
parent | 26f27ad7a838fc8eaa16852d8ec17c2230f18ed1 (diff) | |
download | php-git-827469c94e9d3ec554dabcb79f478e06b31f6a14.tar.gz |
- Fixed bug #28038 (Sent incorrect RCPT TO commands to SMTP server)
Diffstat (limited to 'win32/sendmail.c')
-rw-r--r-- | win32/sendmail.c | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/win32/sendmail.c b/win32/sendmail.c index bd84dac8b9..6ff89e14f7 100644 --- a/win32/sendmail.c +++ b/win32/sendmail.c @@ -422,7 +422,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); } @@ -437,7 +437,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); @@ -458,7 +458,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); @@ -488,7 +488,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); @@ -513,7 +513,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); @@ -546,7 +546,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); @@ -960,3 +960,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() */ |