thunderbird / thunderbird-android

Thunderbird for Android – Open Source Email App for Android (fka K-9 Mail)
https://thunderbird.net/mobile
Apache License 2.0
11.07k stars 2.51k forks source link

Text inserted in wrong place when replying (including quoted text) to message from AOL Android #4237

Open jkavery opened 5 years ago

jkavery commented 5 years ago

When replying to an email sent by AOL Android that is itself a reply, the text of the reply I type, followed by the prefix or header (depending on the "Reply quoting style" setting) are not placed before the quoted AOL message. Instead, they are inserted inside the quoted AOL message after its first reply header.

Expected behavior

Text of reply, followed by the prefix/header created by K9, precede the entire quoted message.

Actual behavior

Text of reply, followed by the prefix/header created by K9, are inserted into the quoted message after the first reply header it contains.

Steps to reproduce

  1. Send a message to an AOL email account.
  2. Using the AOL Android app, reply to the message.
  3. Using the K9 Android app, reply to the reply. Observe that in this reply, K9 inserted the reply and header after the header contained in the AOL reply, not before the AOL reply.

The following (a decoding of the quoted-printable content sent by K9) shows the result of this test:

The first reply, using the AOL Android app.




On Tuesday, November 5, 2019 John A <john@fastmail.net> wrote:

The second reply, using K9.


From: Bruce B <bruce@aol.com>
Sent: November 5, 2019 5:06:07 PM EST
To: john@fastmail.net
Subject: RE: Test message

This is the original message.

Environment

K-9 Mail version: 5.600

Android version: 8.0.0

Account type (IMAP, POP3, WebDAV/Exchange): IMAP

Example AOL mailers:

cketti commented 4 years ago

Can you provide the source of a message that is a reply from AOL Android?

It's probably a bug in HtmlQuoteCreator. That class is using some crude regular expressions trying to find a point in the original HTML where the app can insert the reply text. We should probably throw this code away and reimplement the functionality using Jsoup to parse the HTML and find the correct place to insert text.

jkavery commented 4 years ago

message-source.txt

cketti commented 4 years ago

I was hoping for the second message. The one that was replied to using K-9 Mail. Not the third message, the one generated by K-9 Mail.

jkavery commented 4 years ago

second-message.txt

cketti commented 4 years ago

Thanks :+1:

It looks like the AOL Android app just put the reply text in front of the original HTML so that we end up with something like this:

<p>[reply text]</p>
<div>[quote header]</div>
<!-- HTML from original message -->
<html>
[original message]
</html>

This is not exactly clean HTML and is what confuses K-9 Mail's insertion algorithm. There's probably no way to work around this without using a proper HTML parser as suggested in https://github.com/k9mail/k-9/issues/4237#issuecomment-706751106