commit 1b8a9a5f7d5926bc40b798d2426496e959c769fa
parent 6d6909aaff8c9111de2103b61ac069e6701a5912
Author: William Morgan <wmorgan-sup@masanjin.net>
Date: Sat, 26 Sep 2009 10:40:19 -0700
Merge branch 'master' into next
Diffstat:
4 files changed, 34 insertions(+), 34 deletions(-)
diff --git a/lib/sup/message-chunks.rb b/lib/sup/message-chunks.rb
@@ -50,7 +50,8 @@ directly in Sup. For attachments that you wish to use a separate program
to view (e.g. images), you should use the mime-view hook instead.
Variables:
- content_type: the content-type of the message
+ content_type: the content-type of the attachment
+ charset: the charset of the attachment, if applicable
filename: the filename of the attachment as saved to disk
sibling_types: if this attachment is part of a multipart MIME attachment,
an array of content-types for all attachments. Otherwise,
@@ -85,7 +86,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 +97,15 @@ 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 },
+ :charset => encoded_content.charset,
+ :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
@@ -413,7 +413,7 @@ private
notice, sig, decryptedm = CryptoManager.decrypt payload
if decryptedm # managed to decrypt
children = message_to_chunks(decryptedm, true)
- [notice, sig, children]
+ [notice, sig] + children
else
[notice]
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 : ""
@@ -453,21 +453,22 @@ private
cc_people = cc ? Person.from_address_list(cc) : nil
[Chunk::EnclosedMessage.new(from_person, to_people, cc_people, msgdate, subj)] + message_to_chunks(payload, encrypted)
else
- [Chunk::EnclosedMessage.new(nil, "")]
+ debug "no body for message/rfc822 enclosure; skipping"
+ []
end
else
filename =
## 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"
@@ -484,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
diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb
@@ -174,8 +174,8 @@ EOS
def subscribe_to_list
m = @message_lines[curpos] or return
- if m.list_subscribe && m.list_subscribe =~ /<mailto:(.*?)\?(subject=(.*?))>/
- ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [Person.from_address($1)], :subj => $3
+ if m.list_subscribe && m.list_subscribe =~ /<mailto:(.*?)(\?subject=(.*?))?>/
+ ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [Person.from_address($1)], :subj => ($3 || "subscribe")
else
BufferManager.flash "Can't find List-Subscribe header for this message."
end
@@ -183,8 +183,8 @@ EOS
def unsubscribe_from_list
m = @message_lines[curpos] or return
- if m.list_unsubscribe && m.list_unsubscribe =~ /<mailto:(.*?)\?(subject=(.*?))>/
- ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [Person.from_address($1)], :subj => $3
+ if m.list_unsubscribe && m.list_unsubscribe =~ /<mailto:(.*?)(\?subject=(.*?))?>/
+ ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [Person.from_address($1)], :subj => ($3 || "unsubscribe")
else
BufferManager.flash "Can't find List-Unsubscribe header for this message."
end
diff --git a/lib/sup/person.rb b/lib/sup/person.rb
@@ -1,19 +1,17 @@
module Redwood
-class Person
+class Person
attr_accessor :name, :email
def initialize name, email
raise ArgumentError, "email can't be nil" unless email
-
- if name
- @name = name.gsub(/^\s+|\s+$/, "").gsub(/\s+/, " ")
- if @name =~ /^(['"]\s*)(.*?)(\s*["'])$/
- @name = $2
- end
+
+ @name = if name
+ name = name.strip.gsub(/\s+/, " ")
+ name =~ /^(['"]\s*)(.*?)(\s*["'])$/ ? $2 : name
end
- @email = email.gsub(/^\s+|\s+$/, "").gsub(/\s+/, " ").downcase
+ @email = email.strip.gsub(/\s+/, " ").downcase
end
def to_s; "#@name <#@email>" end