sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 195012cef85b40e9c384a5c8ea5253e18a8558f1
parent ed3d3f0998f24ab990440a74397da59202636c01
Author: William Morgan <wmorgan-sup@masanjin.net>
Date:   Sat, 26 Sep 2009 07:55:28 -0700

make all content-type comparisons case-insensitive

Diffstat:
M lib/sup/message-chunks.rb | 19 +++++++++----------
M lib/sup/message.rb | 18 +++++++++---------
2 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/lib/sup/message-chunks.rb b/lib/sup/message-chunks.rb
@@ -85,7 +85,7 @@ EOS
     bool_reader :quotable
 
     def initialize content_type, filename, encoded_content, sibling_types
-      @content_type = content_type
+      @content_type = content_type.downcase
       @filename = filename
       @quotable = false # changed to true if we can parse it through the
                         # mime-decode hook, or if it's plain text
@@ -96,15 +96,14 @@ EOS
           "For some bizarre reason, RubyMail was unable to parse this attachment.\n"
         end
 
-      text =
-        case @content_type
-        when /^text\/plain\b/
-          Iconv.easy_decode $encoding, encoded_content.charset || $encoding, @raw_content
-        else
-          HookManager.run "mime-decode", :content_type => content_type,
-                          :filename => lambda { write_to_disk },
-                          :sibling_types => sibling_types
-        end
+      text = case @content_type
+      when /^text\/plain\b/
+        Iconv.easy_decode $encoding, encoded_content.charset || $encoding, @raw_content
+      else
+        HookManager.run "mime-decode", :content_type => content_type,
+                        :filename => lambda { write_to_disk },
+                        :sibling_types => sibling_types
+      end
 
       @lines = nil
       if text
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
@@ -374,12 +374,12 @@ private
     end
 
     ## this probably will never happen
-    if payload.header.content_type == "application/pgp-signature"
+    if payload.header.downcase.content_type == "application/pgp-signature"
       warn "multipart/signed with payload content type #{payload.header.content_type}"
       return
     end
 
-    if signature.header.content_type != "application/pgp-signature"
+    if signature.header.downcase.content_type != "application/pgp-signature"
       ## unknown signature type; just ignore.
       #warn "multipart/signed with signature content type #{signature.header.content_type}"
       return
@@ -400,12 +400,12 @@ private
       return
     end
 
-    if payload.header.content_type != "application/octet-stream"
+    if payload.header.downcase.content_type != "application/octet-stream"
       warn "multipart/encrypted with payload content type #{payload.header.content_type}"
       return
     end
 
-    if control.header.content_type != "application/pgp-encrypted"
+    if control.header.downcase.content_type != "application/pgp-encrypted"
       warn "multipart/encrypted with control content type #{signature.header.content_type}"
       return
     end
@@ -423,7 +423,7 @@ private
   def message_to_chunks m, encrypted=false, sibling_types=[]
     if m.multipart?
       chunks =
-        case m.header.content_type
+        case m.header.content_type.downcase
         when "multipart/signed"
           multipart_signed_to_chunks m
         when "multipart/encrypted"
@@ -436,7 +436,7 @@ private
       end
 
       chunks
-    elsif m.header.content_type == "message/rfc822"
+    elsif m.header.content_type.downcase == "message/rfc822"
       if m.body
         payload = RMail::Parser.read(m.body)
         from = payload.header.from.first ? payload.header.from.first.format : ""
@@ -461,14 +461,14 @@ private
         ## first, paw through the headers looking for a filename
         if m.header["Content-Disposition"] && m.header["Content-Disposition"] =~ /filename="?(.*?[^\\])("|;|$)/
           $1
-        elsif m.header["Content-Type"] && m.header["Content-Type"] =~ /name="?(.*?[^\\])("|;|$)/
+        elsif m.header["Content-Type"] && m.header["Content-Type"] =~ /name="?(.*?[^\\])("|;|$)/i
           $1
 
         ## haven't found one, but it's a non-text message. fake
         ## it.
         ##
         ## TODO: make this less lame.
-        elsif m.header["Content-Type"] && m.header["Content-Type"] !~ /^text\/plain/
+        elsif m.header["Content-Type"] && m.header["Content-Type"] !~ /^text\/plain/i
           extension =
             case m.header["Content-Type"]
             when /text\/html/ then "html"
@@ -485,7 +485,7 @@ private
         # Lowercase the filename because searches are easier that way 
         @attachments.push filename.downcase unless filename =~ /^sup-attachment-/
         add_label :attachment unless filename =~ /^sup-attachment-/
-        content_type = m.header.content_type || "application/unknown" # sometimes RubyMail gives us nil
+        content_type = m.header.content_type.downcase || "application/unknown" # sometimes RubyMail gives us nil
         [Chunk::Attachment.new(content_type, filename, m, sibling_types)]
 
       ## otherwise, it's body text