mail icon indicating copy to clipboard operation
mail copied to clipboard

Encoding problem with outgoing messages

Open Thomas-AIRS-Informatique opened this issue 4 years ago • 24 comments

Steps to reproduce

1.Hello, I just realized that I have a formatting problem with sending emails via the Mail application. I am on version 2.0.3. Formatting is enabled in the app. On Nextcloud version 25.0.0 2. 3.

Expected behavior

Correct text formatting

Actual behavior

For exemple : Je reste à votre disposition pour tout complément d'information.

Mail app version

2.0.3

Mailserver or service

IMAP

Operating system

Ubuntu 20.04

PHP engine version

PHP 7.4

Web server

Apache (supported)

Database

PostgreSQL

Additional info

Hello, I just realized that I have a formatting problem with sending emails via the Mail application. I am on version 2.0.3. Formatting is enabled in the app. For exemple : Un exemple : Je reste à votre disposition pour tout complément d'information.

I performed a test on version 1.6.3 on Nextcloud v24.0.6 and there is no problem.

Happens to me also on Nextcloud 25.0.0 with Mail v2.0.3. It didn't happen on Nextcloud 24.x

All accents are broken. Let me know if you need someone to test potential fixes/configuration changes.

Extarys avatar Oct 31 '22 16:10 Extarys

Does anyone know a way to fix this fault? Let me mention that the national characters in the subject line are correct. Only in the text of the message, the recipient gets strange letters. I will be grateful. I like to use this app to reply to email.

jejusek avatar Nov 05 '22 08:11 jejusek

Hello, it's a critical issue for many people. The application is broken for a lot of non-English communities. We can just send plain text.

There is also a problem with the content preview of incoming mail (in the mails list). For instance, accent characters are replaced by '?'.

In fact, the problem seems to be appearing when the mail is in rich text mode.

Thanks for your contribution to this project and your work.

MrWaaWe avatar Nov 05 '22 13:11 MrWaaWe

Same problem in spanish, nextcloud 25.0.1, and mail app 2.1.0, the problem is not solved in this version. it's a critical issue. image

mvalberto avatar Nov 06 '22 09:11 mvalberto

Outgoing messages are temporarily stored in a database table oc_mail_local_messages. Could this be an issue with the utf8 support of your db?

Check https://docs.nextcloud.com/server/stable/admin_manual/configuration_database/mysql_4byte_support.html if you use mysql/mariadb.

ChristophWurst avatar Nov 07 '22 08:11 ChristophWurst

Good morning, that does not seem to be the problem, I have additionally performed the process described in the link, but the problem continues. image

mvalberto avatar Nov 07 '22 08:11 mvalberto

Compose a new message an schedule it for tomorrow so that it isn't sent immediately. Then inspect the latest row in oc_mail_local_message. Is the message body encoding correct?

ChristophWurst avatar Nov 07 '22 09:11 ChristophWurst

Hello, The mail is correctly formatting in oc_mail_local_messages table but the error is still present after sending the message.

Compose a new message an schedule it for tomorrow so that it isn't sent immediately. Then inspect the latest row in oc_mail_local_message. Is the message body encoding correct?

df911 avatar Nov 07 '22 09:11 df911

Thanks, I will try it after hours, I have reverted the snapshot to make everything work correctly in version 24.0.7.

mvalberto avatar Nov 07 '22 09:11 mvalberto

Tried to reproduce after I had this issue myself while testing something else.

DB: image)

Message: image

DB entry (I think the question marks are down to PHPStroms table inspector, not due to an error):

10,0,31,,1667832900,Testing ÄÖÜ,"<p style=""margin:0;"">ÄÜÜÜÜ ÜÖÖÖÖÖ LMAO</p><p style=""margin:0;"">&nbsp;</p><p style=""margin:0;""><span style=""background-color:rgb(255,255,255);color:rgb(51,51,51);"">????????????????????</span></p>",1,,0,"<p style=""margin:0;"">ÄÜÜÜÜ ÜÖÖÖÖÖ LMAO</p><p style=""margin:0;"">&nbsp;</p><p style=""margin:0;""><span style=""background-color:rgb(255,255,255);color:rgb(51,51,51);"">????????????????????</span></p>"

Message in OutboxController::send: image

Same in OutboxService::sendMessage, MailTransmission::send, etc... right until \Horde_Mime_Headers::toArray.

Final send headers:

From: admin <[email protected]>
To: [email protected]
Cc: 
Subject: Testing =?utf-8?b?w4TDlsOc?=
Message-ID: <[email protected]>
User-Agent: Horde Application Framework 5
Date: Mon, 07 Nov 2022 13:37:33 +0000
Content-Type: multipart/alternative; boundary="=_s7DfCJ4VzDrqlwfw0yHJqbw"
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

The problem is visible when reading the stream in \Horde_Smtp_Connection::write. It's also recorded with the broken UTF-8 chars in the Horde Log.

Sent chunk:

From: admin <[email protected]>
To: "Alice ([email protected])" <[email protected]>
Cc: 
Subject: Testing =?utf-8?b?w4TDlsOc?=
Message-ID: <[email protected]>
User-Agent: Horde Application Framework 5
Date: Mon, 07 Nov 2022 13:54:00 +0000
Content-Type: multipart/alternative; boundary="=_rremQ8vRS8oMsnrOYm3UVxj"
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

This message is in MIME format.

--=_rremQ8vRS8oMsnrOYm3UVxj
Content-Type: text/plain; charset=utf-8
Content-Description: Plaintext Version of Message
Content-Transfer-Encoding: 8bit

ÄÜÜÜÜ ÜÖÖÖÖÖ LMAO
 
😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊
--=_rremQ8vRS8oMsnrOYm3UVxj
Content-Type: text/html; charset=utf-8
Content-Description: HTML Version of Message

<p style="margin:0;">&Atilde;&#132;&Atilde;&#156;&Atilde;&#156;&Atilde;&#156;&Atilde;&#156; &Atilde;&#156;&Atilde;&#150;&Atilde;&#150;&Atilde;&#150;&Atilde;&#150;&Atilde;&#150; LMAO<p style="margin:0;">&nbsp;</p><p style="margin:0;"><span style="background-color:rgb(255,255,255);color:rgb(51,51,51);">&eth;&#159;&#152;&#138;&eth;&#159;&#152;&#138;&eth;&#159;&#152;&#138;&eth;&#159;&#152;&#138;&eth;&#159;&#152;&#138;&eth;&#159;&#152;&#138;&eth;&#159;&#152;&#138;&eth;&#159;&#152;&#138;&eth;&#159;&#152;&#138;&eth;&#159;&#152;&#138;&eth;&#159;&#152;&#138;&eth;&#159;&#152;&#138;&eth;&#159;&#152;&#138;&eth;&#159;&#152;&#138;&eth;&#159;&#152;&#138;&eth;&#159;&#152;&#138;&eth;&#159;&#152;&#138;&eth;&#159;&#152;&#138;&eth;&#159;&#152;&#138;</span></p></p>

--=_rremQ8vRS8oMsnrOYm3UVxj--

Final result (in the Web Client for GMX):

image

Stacktrace (from cron, but underlying trace is the same from Controller directly):

Connection.php:41, Horde_Smtp_Connection->write()
Smtp.php:835, Horde_Smtp->_hello()
Smtp.php:421, Horde_Smtp->login()
Smtphorde.php:160, Horde_Mail_Transport_Smtphorde->getSMTPObject()
Part.php:1581, Horde_Mime_Part->send()
Mail.php:479, Horde_Mime_Mail->send()
MailTransmission.php:207, OCA\Mail\Service\MailTransmission->sendMessage()
MailTransmission.php:275, OCA\Mail\Service\MailTransmission->sendLocalMessage()
OutboxService.php:131, OCA\Mail\Service\OutboxService->sendMessage()
OutboxService.php:224, OCA\Mail\Service\OutboxService->flush()
OutboxWorkerJob.php:53, OCA\Mail\BackgroundJob\OutboxWorkerJob->run()
Job.php:78, OCP\BackgroundJob\Job->start()
TimedJob.php:103, OCP\BackgroundJob\TimedJob->start()
TimedJob.php:93, OCP\BackgroundJob\TimedJob->execute()
cron.php:152, {main}()

miaulalala avatar Nov 07 '22 13:11 miaulalala

Can y'all please check your writing mode?

image

miaulalala avatar Nov 07 '22 14:11 miaulalala

Ok, debug finished:

For everyone needing a quick fix, please check your account settings and set your writing mode. That will fix the issue.

As a code fix, looks like the default assumption when the writing mode is not set is $isHtmlMessage = true which then mangles your messages through the Html2text filter:

image

The default writing mode should probably be set to false as a default.

miaulalala avatar Nov 07 '22 14:11 miaulalala

set your writing mode. That will fix the issue.

Can't confirm... The mode was already set to Rich Text. I switched it to Plain Text and back to Rich Text, but this didn't fix the issue. In Plain Text mode, everything is correctly encoded.

Chartman123 avatar Nov 08 '22 21:11 Chartman123

Good to know, so the issue is with rich text and possibly CKEditor. @kesselb you're the expert there :)

miaulalala avatar Nov 09 '22 10:11 miaulalala

Compose a new message an schedule it for tomorrow so that it isn't sent immediately. Then inspect the latest row in oc_mail_local_message. Is the message body encoding correct?

I would like to confirm what @d911 said. The message body encoding in oc_mail_local_messages table is correct, but after the message is sent the body encoding in oc_mail_messages is wrong. See the screenshots attached (an example with Greek characters).

Please note that this issue occurs only in Rich Text mode and not in Plain Text mode.

At least we can safely say that we have pinpointed the problem.

oc_mail_local_messages

oc_mail_messages

cardaris avatar Nov 09 '22 23:11 cardaris

I have looked into it. Sounds this problem happens right before sending via SMTP (some 4 bytes encoding getting lost somehow). But also for all previews of incoming html only messages... Capture d’écran 2022-11-10 à 16 54 38

fix avatar Nov 10 '22 15:11 fix

Note this is really showstopper for us, as rich text is enabled by default when you answer to html message (whatever the option chosen in the config). You have to think to remove formatting for virtually any answer.... I would rank this as high priority

fix avatar Nov 10 '22 16:11 fix

might be linked to https://github.com/nextcloud/mail/issues/7408 but. i am not sure if the fix works for this issue too

fix avatar Nov 10 '22 16:11 fix

Thanks for your reports :+1:

Would you mind trying https://github.com/nextcloud/mail/pull/7575 and tell us if it fixes the encoding issues?

kesselb avatar Nov 10 '22 22:11 kesselb