Closed issuefiler closed 4 years ago
Personally this is the number one priority for me. I can tackle everything else as I have my own set of processors, but this……, this, unfortunately, is a job of the core, which I have zero knowledge of. I need your insight and help on this if you don’t mind.
Unlike internationalized emails (SMTPUTF8
) (#152), of which go-guerrilla
lacks support to begin with, go-guerrilla
doesn’t decline those addresses above (as they are valid), and it may cause some processors to malfunction.
Thanks!
The evaluation of quoted/escaped strings in the todo list https://github.com/flashmob/go-guerrilla/issues/201 , so that one should be done first.
TODO
mail.Address
. Add a new property, AddressType
, with 0 = none, 1 = ipv4, 2 = ipv6). The literal will be stored in the Host, but when String() is used, the literal will be output inside square brackets []ipv6AddressLiteral
. Instead of using ipstr, we should use v.String() and save that result to our s.accept
buffer postmaster
Changes made in PR #202
Quoted bool
property added to Address
, to flag if local part's quotedIP net.IP
property added added to Address
to store the IP in binary form. (It's nil
if no valid address matched)address-literals
should now format with braces when returned from String()
https://github.com/flashmob/go-guerrilla/blob/51f7dda326b1e9878e5f679ccb34a134127951b0/mail/envelope.go#L32-L48
What this little structure can do is rather limited.
Address.String()
is and may be used in many places throughout the code (e.g. populating headers, storing into a database.), yet it sometimes screws things up; it is not reliable.Test cases
Quoted
Local-part
s âś… VALID INPUTS(return_path).User
:[SPACE][SPACE]yo--[SPACE]man[SPACE]wazz'''up?[SPACE]surprise[SPACE]surprise,[SPACE]this[SPACE]is[SPACE]POSSIBLE@fake.com[SPACE]
. ❌ INVALIDLocal-part
(return_path).Host
:example.com
.(return_path).String()
:[SPACE][SPACE]yo--[SPACE]man[SPACE]wazz'''up?[SPACE]surprise[SPACE]surprise,[SPACE]this[SPACE]is[SPACE]POSSIBLE@fake.com[SPACE]@example.com
. ❌ INVALIDMailbox
address-literal
mailboxes âś… VALID INPUTS(return_path).User
:hi
.(return_path).Host
:1.1.1.1
. ❌ INVALIDaddress-literal
(return_path).String()
:hi@1.1.1.1
. ❌ INVALIDMailbox
(return_path).User
:hi
.(return_path).Host
:2001:db8::8a2e:370:7334
. ❌ INVALIDaddress-literal
; NEEDS TO BE NORMALIZED FOR CORRECT COMPARISONS.(return_path).String()
:hi@2001:db8::8a2e:370:7334
. ❌ INVALIDMailbox
(return_path).User
:hi
.(return_path).Host
:2001:DB8::8A2E:370:7334
. ❌ INVALIDaddress-literal
; NEEDS TO BE NORMALIZED FOR CORRECT COMPARISONS.(return_path).String()
:hi@2001:DB8::8A2E:370:7334
. ❌ INVALIDMailbox
Null return-path and Postmaster recipient âś… VALID INPUTS
(return_path).IsEmpty()
:true
. âś…(return_path).String()
:@
. ❌ INVALIDMailbox
; andp_sql.go
doesn’t care about it. Would be better to make it return an empty string instead.(recipient).String()
:Postmaster@
❌ SHOULD JUST BEPostmaster
.Notes
For the
User
part" al\ph\a "@grr.la
should be" alpha "@grr.la
."alpha"@grr.la
should bealpha@grr.la
."alp\h\a"@grr.la
should bealpha@grr.la
.From RFC 5321:
go-guerrilla
may safely normalize it intoPostmaster
.https://github.com/flashmob/go-guerrilla/blob/51f7dda326b1e9878e5f679ccb34a134127951b0/mail/rfc5321/parse.go#L96-L99
That’s the code doing that, but what’s inconsistent there is that it only does that when it has no host part:
<posTMAstEr>
→<Postmaster>
but<pOstMastEr@example.com>
→<pOstMastEr@example.com>
. Postmaster is case-insensitive regardless of having a host. So why don’t we normalize it for the both cases? Hold on, what should we do for<"P\O\STMASTER"@example.com>
?For the
Host
partIf an
address-literal
is given, it should normalize it into bytes, and give them some appropriate brackets,[IPv6:……]
or[……]
. Such normalization also helps to resolve #197.Considerations
Local-part
: as shown above, the currentgo-guerrilla
does unquote it, but does it unescape it, too? ⸺ No, it doesn’t……."moto\y\a\s\u"
becomes justmoto\y\a\s\u
. Could we modify the parser not to accumulate the backslash, so that we can use it for the normalization steps? https://github.com/flashmob/go-guerrilla/blob/51f7dda326b1e9878e5f679ccb34a134127951b0/mail/rfc5321/parse.go#L487-L490Local-part
has a character that is neitheratext
nor.
.\
and"
.