Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
* [sup-talk] [PATCH] Attachment filenames: RFC2184 and extension guessing
@ 2009-10-07 10:52 Gregor Hoffleit
  0 siblings, 0 replies; only message in thread
From: Gregor Hoffleit @ 2009-10-07 10:52 UTC (permalink / raw)
  To: sup-talk

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

I noticed sup has trouble handling attachments sent by Roundcube
webmail. Somehow, those mails use an alternative encoding of filenames,
specified in RFC2184:

    Content-Transfer-Encoding: base64
    Content-Type: image/jpeg;
     name*="UTF-8''20090912-i004232-gr000.jpg"; 
    Content-Disposition: attachment;
     filename*="UTF-8''20090912-i004232-gr000.jpg"; 

Bugs:

1. Sup fails to detect these filenames.

2. When trying to save these attachements, the filenames generated by
   sup have a trailing semicolon.

The attached patch is a quick and dirty fix for these specific problems.
There's probably a better way to implement this.

Regards,
    Gregor Hoffleit

[-- Attachment #2: rfc2184.diff --]
[-- Type: application/octet-stream, Size: 954 bytes --]

diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index f9f87de..4ad0b88 100644
--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -477,6 +477,10 @@ private
           $1
         elsif m.header["Content-Type"] && m.header["Content-Type"] =~ /name="?(.*?[^\\])("|;|$)/i
           $1
+        elsif m.header["Content-Disposition"] && m.header["Content-Disposition"] =~ /filename\*="?UTF-8''(.*?[^\\])("|;|$)/
+          $1
+        elsif m.header["Content-Type"] && m.header["Content-Type"] =~ /name\*="?UTF-8''(.*?[^\\])("|;|$)/i
+          $1
 
         ## haven't found one, but it's a non-text message. fake
         ## it.
@@ -486,7 +490,7 @@ private
           extension =
             case m.header["Content-Type"]
             when /text\/html/ then "html"
-            when /image\/(.*)/ then $1
+            when /image\/([^;]*)/ then $1
             end
 
           ["sup-attachment-#{Time.now.to_i}-#{rand 10000}", extension].join(".")

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

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-10-07 10:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-07 10:52 [sup-talk] [PATCH] Attachment filenames: RFC2184 and extension guessing Gregor Hoffleit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox