X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lib%2Fsup%2Fmbox.rb;h=0d941b1d8ae341b86bcf6303e752c3c4bb1c36e5;hb=5bf815cacd0bd5b5b3b5e42a85fed9b03326269a;hp=223bb7cfbb394070b056d00308178991c3e867b8;hpb=6af3b3fc7fa791b4e253078747cd6d146c8cdb6a;p=sup diff --git a/lib/sup/mbox.rb b/lib/sup/mbox.rb index 223bb7c..0d941b1 100644 --- a/lib/sup/mbox.rb +++ b/lib/sup/mbox.rb @@ -5,49 +5,21 @@ require "sup/rfc2047" module Redwood -## some utility functions. actually these are not mbox-specific at all -## and should be moved somewhere else. -## -## TODO: move functionality to somewhere better, like message.rb module MBox - BREAK_RE = /^From \S+/ ######### TODO REMOVE ME + BREAK_RE = /^From \S+ (.+)$/ - ## WARNING! THIS IS A SPEED-CRITICAL SECTION. Everything you do here will have - ## a significant effect on Sup's processing speed of email from ALL sources. - ## Little things like string interpolation, regexp interpolation, += vs <<, - ## all have DRAMATIC effects. BE CAREFUL WHAT YOU DO! - def read_header f - header = {} - last = nil - - while(line = f.gets) - case line - ## these three can occur multiple times, and we want the first one - when /^(Delivered-To|X-Original-To|Envelope-To):\s*(.*?)\s*$/i; header[last = $1.downcase] ||= $2 - ## mark this guy specially. not sure why i care. - when /^([^:\s]+):\s*(.*?)\s*$/i; header[last = $1.downcase] = $2 - when /^\r*$/; break - else - if last - header[last] << " " unless header[last].empty? - header[last] << line.strip - end - end - end - - %w(subject from to cc bcc).each do |k| - v = header[k] or next - next unless Rfc2047.is_encoded? v - header[k] = begin - Rfc2047.decode_to $encoding, v - rescue Errno::EINVAL, Iconv::InvalidEncoding, Iconv::IllegalSequence => e - Redwood::log "warning: error decoding RFC 2047 header (#{e.class.name}): #{e.message}" - v - end + def is_break_line? l + l =~ BREAK_RE or return false + time = $1 + begin + ## hack -- make Time.parse fail when trying to substitute values from Time.now + Time.parse time, 0 + true + rescue NoMethodError + Redwood::log "found invalid date in potential mbox split line, not splitting: #{l.inspect}" + false end - header end - - module_function :read_header + module_function :is_break_line? end end