You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Wiser to test the mail functionality of my Google App Engine app and discovered that there is an issue in the Google App Engine SDK's usage of the Python smtplib.SMTP.sendmail function such that when given a FROM header like "Foo Bar <[email protected]>", it wraps the address string within another pair of angle brackets and issues an SMTP command like mail FROM:<Foo Bar <[email protected]>>, which is unusual, and Wiser returns a 553 / "Invalid email address" response.
I found that changing the address = address.substring(1, address.indexOf('>')) line in org.subethamail.smtp.util.EmailUtils.extractEmailAddress to use lastIndexOf instead of indexOf is a simple solution to the aforementioned problem,
/**
* Extracts the email address within a <> after a specified offset.
*/
public static String extractEmailAddress(String args, int offset) {
String address = args.substring(offset).trim();
if (address.indexOf('<') == 0) {
// address = address.substring(1, address.indexOf('>'));
// **this patch allows nested angle brackets (e.g. "<Foo Bar <[email protected]>>"):**
address = address.substring(1, address.lastIndexOf('>'));
// spaces within the <> are also possible, Postfix apparently
// trims these away:
return address.trim();
}
// find space (e.g. SIZE argument)
int nextarg = address.indexOf(" ");
if (nextarg > -1) {
address = address.substring(0, nextarg).trim();
}
return address;
}
I believe that this change will not break compatibility with the SMTP RFC, which specifies only that:
The <reverse-path> portion of the first or only argument contains the source mailbox (between < and > brackets)
This spec does not appear to explicitly prohibit nested brackets.
My patched code still supports addresses without additional nested brackets (i.e. both MAIL FROM:Foo Bar <[email protected]> and MAIL FROM:<Foo Bar <[email protected]>> will be accepted.
I realize that the App Engine/Python peculiarity that I described doesn't have anything to do with subethasmtp, but I was wondering if you'd be willing to accept this tiny patch anyways. Would be happy to create a pull request if you accept.
Since Wiser is intended to be used for testing, I think it should be pretty lenient with what it accepts. Another argument in favor of this patch is that Dumbster is able to handle such email addresses without a problem.
The text was updated successfully, but these errors were encountered:
aepshteyn
added a commit
to aepshteyn/subethasmtp
that referenced
this issue
Feb 14, 2020
Originally posted on voodoodyne#97 (comment):
I'm using Wiser to test the mail functionality of my Google App Engine app and discovered that there is an issue in the Google App Engine SDK's usage of the Python
smtplib.SMTP.sendmail
function such that when given aFROM
header like"Foo Bar <[email protected]>"
, it wraps the address string within another pair of angle brackets and issues an SMTP command likemail FROM:<Foo Bar <[email protected]>>
, which is unusual, and Wiser returns a 553 / "Invalid email address" response.I found that changing the
address = address.substring(1, address.indexOf('>'))
line inorg.subethamail.smtp.util.EmailUtils.extractEmailAddress
to uselastIndexOf
instead ofindexOf
is a simple solution to the aforementioned problem,I believe that this change will not break compatibility with the SMTP RFC, which specifies only that:
This spec does not appear to explicitly prohibit nested brackets.
My patched code still supports addresses without additional nested brackets (i.e. both
MAIL FROM:Foo Bar <[email protected]>
andMAIL FROM:<Foo Bar <[email protected]>>
will be accepted.I realize that the App Engine/Python peculiarity that I described doesn't have anything to do with subethasmtp, but I was wondering if you'd be willing to accept this tiny patch anyways. Would be happy to create a pull request if you accept.
Since Wiser is intended to be used for testing, I think it should be pretty lenient with what it accepts. Another argument in favor of this patch is that Dumbster is able to handle such email addresses without a problem.
The text was updated successfully, but these errors were encountered: