Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
From: Michael Stapelberg <michael+sup@stapelberg.de>
To: Rich Lane <rlane@club.cc.cmu.edu>
Cc: sup-devel <sup-devel@rubyforge.org>
Subject: [sup-devel] [PATCH] Bugfix: fix regexp for detecting filename in Content-Disposition header
Date: Sun, 10 Oct 2010 23:02:28 +0200	[thread overview]
Message-ID: <1286744439-sup-1534@midna.zekjur.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 917 bytes --]

Hi,

quote from the commit message:

    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.


Best regards,
Michael

[-- Attachment #2: 0001-Bugfix-fix-regexp-for-detecting-filename-in-Content-.patch --]
[-- Type: application/octet-stream, Size: 2162 bytes --]

From 8b34ae2c2ac7af0647c8aa5c0ad135f0eae42cdc Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael@stapelberg.de>
Date: Sun, 10 Oct 2010 22:30:46 +0200
Subject: [PATCH] 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.
---
 lib/sup/message.rb |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index 69669bd..cf0e505 100644
--- 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
-- 
1.7.1


[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel

             reply	other threads:[~2010-10-10 21:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-10 21:02 Michael Stapelberg [this message]
2010-10-12  1:37 ` Rich Lane

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1286744439-sup-1534@midna.zekjur.net \
    --to=michael+sup@stapelberg.de \
    --cc=rlane@club.cc.cmu.edu \
    --cc=sup-devel@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox