quentez / talonjs

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

Improve detection of forwarded messages #36

Closed khennes closed 4 years ago

khennes commented 4 years ago

Identify more messages as forwards by trimming whitespace from --- Forwarded message --- lines before applying the ForwardRegexp.

The intended behavior of talonjs is to consider a forwarded message part of the reply. It does this by checking if the message begins with any number of text markers or empty lines, followed by a line that matches the ForwardRegexp. If it does, then talonjs returns the message intact, without cutting any lines.

In practice, this hasn't been applied if the line is bookended by whitespace or followed by a newline character. In those cases, the forwarded content has been parsed as quoted text and removed from the reply. (However, since the --- Forwarded message --- does not match any of the splitter regexes, it's been preserved as part of the reply.) This PR fixes that by applying .trim() to the line before trying to match it against the regexp.

Alternatives considered

I almost changed the ForwardRegexp to allow for trailing whitespace instead of using trim(), but thought that this would be clearer (and we already call trim() on the line earlier in the same function).