quentez / talonjs

JavaScript port of the Talon email quote parsing library.
MIT License
15 stars 9 forks source link

PB-17798 — Don't crop image-only messages #31

Closed cunisia closed 4 years ago

cunisia commented 4 years ago

JIRA

⛳ State the problem being solved.

If a message only contains an img, it is cropped from the lightBody. In conversation cnv_41uvyv7, it caused message msg_80hsp1f content to be invisible unless clicking on ....

💭 Explain your solution and thought process.

In extractQuoteHtmlViaMarkers, the document we:

  1. convert passed document into text using elementToText,
  2. split the output text by lines,
  3. remove the checkpoints that were added before extractQuoteHtmlViaMarkers,
  4. map each line to a character representing its nature (empty [e], text [t], quote [m], splitter [s], forwarded [f]),
  5. use the concatenation of those markers to recognize patterns.

The issue was that, in step 1, elementToText only returned the nodeValue of img (and others embedded contents tag) elements, which is its checkpoint value. Since the checkpoint value is then removed in step 3, nothing remained for lines containing img only, so it was marked as empty in step 4.

We therefore ended up with a marker string like that: eesmmm. With such marker we display by default the content of previous messages.

To fix that elementToText now append the src attribute of a tag to the string it returns. I took inspiration of a similar fix that appends the href attribute to the returned string. So the marker string is now etsmmm. This is closer to reality and does not cause the message's body to get cropped grom its lightBody.

cunisia commented 4 years ago

@quentez @evonck if you guys find time to have a look at this one :)

quentez commented 4 years ago

@cunisia Package published!

cunisia commented 4 years ago

@quentez @evonck thanks guys !