f3-factory / fatfree-core

Fat-Free Framework core library
GNU General Public License v3.0
206 stars 89 forks source link

Smtp non 8BITMIME compatible server #328

Closed kumy closed 3 years ago

kumy commented 3 years ago

Relates to :

https://github.com/bcosca/fatfree-core/blob/e8334115f9aa69421427259e8e0b673945591ff4/smtp.php#L186-L192

$message=preg_replace('/^\.(.+)/m','..$1',quoted_printable_code($message); 

I'm wondering what's the purpose of this replacement? I have trouble with this, some urls in my mail receive this double dot and break links. Also from what I've read about Content-Transfer-Encoding 'quote-printable'

The Quoted-Printable encoding REQUIRES that encoded lines be no more than 76 characters long.

(Source: 5.1 Quoted-Printable Content-Transfer-Encoding)

but adding one character brings the line to 77 character.

Here are two examples:

| lign-center">=0A                <a href=3D"https://new-theme.geokrety.house=
| ..kumy.net/en">=0A                    Geo<span class=3D"black">Krety</span>.=
| org=0A                </a>=0A            </h1>=0A            <div class=3D"=
 | g src=3D"https://cdn.new-theme.geokrety.house.kumy.net/images/log-icons/0/5=
 | ..png" title=3D"2421303: dip" data-gk-move-type=3D"5" data-gk-move-id=3D"242=
 | 1303"></a>=0A                </td>=0A                <td>=0A               =

As the code was already broken when it was committed 5 years ago by a syntax error, and fixed two times (2f84f9cc , 2756ccc) after, I'm wondering if this edge case has a real sense at all?

ikkez commented 3 years ago

The purpose of that dot-stuffing replacement is https://tools.ietf.org/html/rfc5321#section-4.5.2

it basically says that all lines should be prefixed by a dot and you have to make sure a single dot line is not terminating the message. But after reading some comments on SO, there might be better solutions https://stackoverflow.com/a/38447917

kumy commented 3 years ago

Thanks for pointing me in the right direction. So it seems the MTA job to remove that double dot.

For this use case, I'm using https://github.com/aarongough/mini-smtp-server so it should be it's job to remove this double dot. And another point is that this smtp server doesn't announce it's capabilities (as for example postfix do), that's why I'm reaching the else part of this code.

Also as proposed in another response in the stackoverflow thread, converting all dots to =2E may help to communicate with server not respecting standard. But it's only a workaround against some broken servers, which could be generally a "wrong approach" :/


SMTP session with mini-smtp-server:

$ telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
220 hello
EHLO kumy.net
220 go on...

SMTP sessions with postfix:

$ telnet xxxx 25
Trying 2001:xxxxx...
Connected to mx6.kumy.net.
Escape character is '^]'.
220 xxxx ESMTP Postfix
EHLO kumy.net
250-xxxxxx
250-PIPELINING
250-SIZE 502400000
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250 SMTPUTF8

I'll also report this problem to aarongough/mini-smtp-server project.

kumy commented 3 years ago

So I feel it's not a bug in f3, I'll close. Thanks again for your support @ikkez!