lib/sup/message.rb in sup-0.12.1 vs lib/sup/message.rb in sup-0.13.0
- old
+ new
@@ -501,11 +501,11 @@
if filename
## filename could be 2047 encoded
filename = Rfc2047.decode_to $encoding, filename
# add this to the attachments list if its not a generated html
# attachment (should we allow images with generated names?).
- # Lowercase the filename because searches are easier that way
+ # 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").downcase # sometimes RubyMail gives us nil
[Chunk::Attachment.new(content_type, filename, m, sibling_types)]
@@ -588,13 +588,24 @@
## into the classes themselves.
def text_to_chunks lines, encrypted
state = :text # one of :text, :quote, or :sig
chunks = []
chunk_lines = []
+ nextline_index = -1
lines.each_with_index do |line, i|
- nextline = lines[(i + 1) ... lines.length].find { |l| l !~ /^\s*$/ } # skip blank lines
+ if i >= nextline_index
+ # look for next nonblank line only when needed to avoid O(n²)
+ # behavior on sequences of blank lines
+ if nextline_index = lines[(i+1)..-1].index { |l| l !~ /^\s*$/ } # skip blank lines
+ nextline_index += i + 1
+ nextline = lines[nextline_index]
+ else
+ nextline_index = lines.length
+ nextline = nil
+ end
+ end
case state
when :text
newstate = nil
@@ -602,10 +613,10 @@
## start of a quote. this is split into two regexen because the
## original regex /\w.*:$/ had very poor behavior on long lines
## like ":a:a:a:a:a" that occurred in certain emails.
if line =~ QUOTE_PATTERN || (line =~ /:$/ && line =~ /\w/ && nextline =~ QUOTE_PATTERN)
newstate = :quote
- elsif line =~ SIG_PATTERN && (lines.length - i) < MAX_SIG_DISTANCE
+ elsif line =~ SIG_PATTERN && (lines.length - i) < MAX_SIG_DISTANCE && !lines[(i+1)..-1].index { |l| l =~ /^-- $/ }
newstate = :sig
elsif line =~ BLOCK_QUOTE_PATTERN
newstate = :block_quote
end