sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 36e8fbc5985b482669a597e23845f6b2343015f4
parent dd2fac234674278ded48b2a3af669649fe3d1059
Author: Michael Stapelberg <michael@stapelberg.de>
Date:   Sun, 10 Oct 2010 22:30:46 +0200

Bugfix: fix regexp for detecting filename in Content-Disposition header

In a message written in some Microsoft mail program (the only header is
"X-MimeOLE: Produced By Microsoft Exchange V6.5"), the filename part of
the Content-Disposition header spans multiple lines (due to the filename
being very long and encoded in base64 due to the use of UTF-8):

Content-Disposition: attachment;
        filename="=?utf-8?B?VGFnIGRlciBPZmZlbmVuIFTDvHIgZGVzIFByb2pla3Rl?=
        =?utf-8?B?cyBMZXJucGF0ZW5zY2hhZnRlbiBpbSBFbW1lcnRzZ3I=?=
        =?utf-8?B?dW5kLmRvY3g=?="

The previous regexp did not properly match the whole string, but only the
first line. This is fixed by adding the 'm' option (to match newlines as
characters) and using \z instead of $ ("end of string" instead of "end of
line").

The same fix is also applied to the Content-Type header one line below.

Diffstat:
M lib/sup/message.rb | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
@@ -475,10 +475,12 @@ private
       end
     else
       filename =
-        ## first, paw through the headers looking for a filename
-        if m.header["Content-Disposition"] && m.header["Content-Disposition"] =~ /filename="?(.*?[^\\])("|;|$)/
+        ## first, paw through the headers looking for a filename.
+        ## RFC 2183 (Content-Disposition) specifies that disposition-parms are
+        ## separated by ";". So, we match everything up to " and ; (if present).
+        if m.header["Content-Disposition"] && m.header["Content-Disposition"] =~ /filename="?(.*?[^\\])("|;|\z)/m
           $1
-        elsif m.header["Content-Type"] && m.header["Content-Type"] =~ /name="?(.*?[^\\])("|;|$)/i
+        elsif m.header["Content-Type"] && m.header["Content-Type"] =~ /name="?(.*?[^\\])("|;|\z)/im
           $1
 
         ## haven't found one, but it's a non-text message. fake