sup-heliotrope / sup

A curses threads-with-tags style email client (mailing list: supmua@googlegroups.com)
http://sup-heliotrope.github.io
GNU General Public License v2.0
889 stars 96 forks source link

unknown encoding causes crash #585

Closed jtyers closed 3 years ago

jtyers commented 3 years ago

Hello, I'm a new user of sup, just trying it out. I've imported my mail from Gmail as per your instructions using offlineimap. Lots of emails appear in sup, though only up to 2009.

While playing with the keybindings to find my way around, I triggered a crash. For this one I pressed , from the inbox buffer.

I'm running Arch.

$ (pacman -Q; gem list) | grep -E '^(ruby|sup|offlineimap) '
offlineimap 7.3.3-1
ruby 2.7.2-1
sup (1.0)

Trace below:

[2020-10-16 08:34:35 +0100] WARNING: URI.escape is obsolete
[2020-10-16 08:34:35 +0100] WARNING: URI.unescape is obsolete
[2020-10-16 08:36:51 +0100] ERROR: oh crap, an exception
----------------------------------------------------------------
We are very sorry. It seems that an error occurred in Sup. Please
accept our sincere apologies. Please submit the contents of
/home/jonny/.sup/exception-log.txt and a brief report of the
circumstances to https://github.com/sup-heliotrope/sup/issues so that
we might address this problem. Thank you!

Sincerely,
The Sup Developers
----------------------------------------------------------------
--- ArgumentError from thread: poll after loading inbox
unknown encoding name - iso 8859-15
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/message_chunks.rb:131:in `force_encoding'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/message_chunks.rb:131:in `initialize'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/message.rb:571:in `new'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/message.rb:571:in `message_to_chunks'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/message.rb:481:in `block in message_to_chunks'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/message.rb:481:in `map'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/message.rb:481:in `message_to_chunks'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/message.rb:270:in `load_from_source!'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/message.rb:381:in `build_from_source'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/poll.rb:204:in `block in poll_from'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/maildir.rb:161:in `block in poll'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/maildir.rb:160:in `each'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/maildir.rb:160:in `each_with_index'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/maildir.rb:160:in `poll'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/poll.rb:201:in `poll_from'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/poll.rb:146:in `block (2 levels) in do_poll'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/poll.rb:136:in `each'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/poll.rb:136:in `block in do_poll'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/poll.rb:135:in `synchronize'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/poll.rb:135:in `do_poll'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/util.rb:605:in `method_missing'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/modes/poll_mode.rb:15:in `poll'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/poll.rb:58:in `poll_with_sources'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/poll.rb:94:in `poll'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup/util.rb:605:in `method_missing'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/bin/sup:209:in `block (2 levels) in <module:Redwood>'
/home/jonny/.gem/ruby/2.7.0/gems/sup-1.0/lib/sup.rb:87:in `block in reporting_thread'
jtyers commented 3 years ago

Grepping for this string yields a single email (!) dated 2009. It contains an attachment with this frontmatter:

--Boundary-00=_R8akJcfwJIaKgCU
  6 Content-Type: text/plain;
  5   charset="iso 8859-15";
  4   name="chain.mk"
  3 Content-Transfer-Encoding: 7bit
  2 Content-Disposition: attachment;
  1   filename="chain.mk"

Manually changing the encoding in here to iso-8859-15 (notice the -) fixes it! I'd suggest handling thing like this more gracefully though, the wild world of email can contain all sorts of bad inputs...

danc86 commented 3 years ago

Thanks for the bug report. Indeed, sup should handle unrecognised encodings more gracefully than this.

IPv2 commented 3 years ago

Thank you very much for this bug report, @jtyers.

I am able to reproduce the crash: it seems to require a MIME part without a name, along with MIME header Content-Type containing text/plain and an invalid charset.

That is, Sup is able to gracefully handle an invalid charset for a text/plain MIME part when neither the Content-Disposition MIME header contains a filename, nor the Content-Type MIME header a name. This is normally the case for inline plain text. However, whenever we have at least one of these names, for a text/plain MIME part with an invalid charset, then the crash is reproducible always.

Attached issue-585-demo.txt - a full example email which triggers the crash when opened in Sup (latest version from git develop branch: sup v1.1-git-bb204e66).

When I have a bit more time, I'll dig into this a bit more, and see if I can create a patch (and test case to avoid future regressions).

IPv2 commented 3 years ago

I had time earlier than I thought. :-) I will raise a PR just now.