lib/sup/message.rb in sup-0.5 vs lib/sup/message.rb in sup-0.6

- old
+ new

@@ -35,11 +35,11 @@ MAX_SIG_DISTANCE = 15 # lines from the end DEFAULT_SUBJECT = "" DEFAULT_SENDER = "(missing sender)" attr_reader :id, :date, :from, :subj, :refs, :replytos, :to, :source, - :cc, :bcc, :labels, :list_address, :recipient_email, :replyto, + :cc, :bcc, :labels, :attachments, :list_address, :recipient_email, :replyto, :source_info, :list_subscribe, :list_unsubscribe bool_reader :dirty, :source_marked_read, :snippet_contains_encrypted_content ## if you specify a :header, will use values from that. otherwise, @@ -52,10 +52,11 @@ @have_snippet = !(opts[:snippet].nil? || opts[:snippet].empty?) @labels = [] + (opts[:labels] || []) @dirty = false @encrypted = false @chunks = nil + @attachments = [] ## we need to initialize this. see comments in parse_header as to ## why. @refs = [] @@ -146,11 +147,22 @@ def draft_filename raise "not a draft" unless is_draft? @source.fn_for_offset @source_info end - def sanitize_message_id mid; mid.gsub(/\s+/, "")[0..254] end + ## sanitize message ids by removing spaces and non-ascii characters. + ## also, truncate to 255 characters. all these steps are necessary + ## to make ferret happy. of course, we probably fuck up a couple + ## valid message ids as well. as long as we're consistent, this + ## should be fine, though. + ## + ## also, mostly the message ids that are changed by this belong to + ## spam email. + ## + ## an alternative would be to SHA1 or MD5 all message ids on a regular basis. + ## don't tempt me. + def sanitize_message_id mid; mid.gsub(/(\s|[^\000-\177])+/, "")[0..254] end def save index return unless @dirty index.sync_message self @dirty = false @@ -403,10 +415,15 @@ ["sup-attachment-#{Time.now.to_i}-#{rand 10000}", extension].join(".") end ## if there's a filename, we'll treat it as an attachment. if 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 + @attachments.push filename.downcase unless filename =~ /^sup-attachment-/ + add_label :attachment unless filename =~ /^sup-attachment-/ [Chunk::Attachment.new(m.header.content_type, filename, m, sibling_types)] ## otherwise, it's body text else body = Message.convert_from m.decode, m.charset if m.body @@ -421,10 +438,10 @@ raise MessageFormatError, "RubyMail decode returned a null body" unless body return body unless charset Iconv.iconv($encoding + "//IGNORE", charset, body + " ").join[0 .. -2] rescue Errno::EINVAL, Iconv::InvalidEncoding, Iconv::IllegalSequence, MessageFormatError => e Redwood::log "warning: error (#{e.class.name}) decoding message body from #{charset}: #{e.message}" - File.open("sup-unable-to-decode.txt", "w") { |f| f.write body } + File.open(File.join(BASE_DIR,"unable-to-decode.txt"), "w") { |f| f.write body } body end end ## parse the lines of text into chunk objects. the heuristics here