knadh / listmonk

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.
https://listmonk.app
GNU Affero General Public License v3.0
14.6k stars 1.34k forks source link

From address field does not support accents #34

Closed HLFH closed 3 years ago

HLFH commented 4 years ago

Hi,

In a test campaign, I can set in From address field: "Bécassine becassine@example.com" If I do that, the received email shows:

From: =?UTF-8?q?B=C3=A9cassine_ becassine@example.com, ?=@myhost.example.com

So I get in From the username weirdly written on the accent part, and the host, which did not need to be written here.

Therefore, I can also set in From address field: "Becassine becassine@example.com". If I do that without accent, the received email shows:

From: Becassine becassine@example.com

And it is correct.

Can you fix it?

Thanks, HLFH

knadh commented 4 years ago

Name <email@email.com>. Are you wrapping the e-mail address in < and >?

HLFH commented 4 years ago

In the WebUI of Listmonk, in a new campaign, yes, it was set correctly.

vividvilla commented 3 years ago

The issue here is that the library we use for sending an email - smtppool doesn't properly set the From header when it contains non-ASCII characters. Here is the output of email header sent from Listmonk

Content-Type: multipart/alternative; boundary=033f1d4f07462bda1c37264f8326d5e4680ada45f1bdac434a3088585485
Date: Sat, 03 Oct 2020 18:41:34 +0530
From: =?UTF-8?q?B=C3=A9cassine_<noreply@listmonk.yoursite.com>?=
Message-Id: <1601730694564650000.90971.8760276615512442859@shire.local>
Mime-Version: 1.0
Return-Path: <noreply@listmonk.yoursite.com>
Subject: Hello there
To: user1@mail.com

So according to RFC 2047 the From address should be encoded to =?utf-8?q?B=C3=A9cassine?= <noreply@listmonk.yoursite.com> instead of =?UTF-8?q?B=C3=A9cassine_<noreply@listmonk.yoursite.com>?=. This is because smtppool sets From header as whatever string received instead of parsing it to Name and Address separately.

Here is the code in smtppool lib which does this.

    if _, ok := res[HdrFrom]; !ok {
        res.Set(HdrFrom, e.From)
    }

So the ideal solution here is to parse incoming From address to mail.Adderess using mail.ParseAdress and then encoding it again to a string using mail.Address.String().

The fix will look somewhat like below. I tested this locally and it seems fine.

    if _, ok := res[HdrFrom]; !ok {
        fromAddr, err := mail.ParseAddress(e.From)
        if err != nil {
            return nil, err
        }
        res.Set(HdrFrom, fromAddr.String())
    }

This has to be done wherever an email address is handled like setting From, To, CC and BCC headers. I will send an MR for the same to smtppool lib soon.

knadh commented 3 years ago

smtppool (v0.2.1) with the address fix is now merged into master, however the "from" address is still malformatted. Tested with mailhog.

image

vividvilla commented 3 years ago

@knadh that's after encodig which is fine and email readers will be able to parse it properly.

image

Check above mailhog inbox screenshot, first email is with the patch and last one is without it.

HLFH commented 3 years ago

@vividvilla Shall I close this issue, then? I cannot test now, but it seems it is fixed.

vividvilla commented 3 years ago

I tested this on prod SMTP as well and I could see that from address is parsed properly. You can close this issue for now and if needed reopen it later.