From: wmorgan Date: Thu, 4 Jan 2007 02:03:35 +0000 (+0000) Subject: updated source_marked_read? to work for imap X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=5d8d680d00988d4b0acf0a128effa023c3247a44;p=sup updated source_marked_read? to work for imap git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@164 5c8cc53c-5e98-4d25-b20a-d8db53a31250 --- diff --git a/bin/sup-import b/bin/sup-import index 9b27887..da34483 100644 --- a/bin/sup-import +++ b/bin/sup-import @@ -178,7 +178,7 @@ begin found[m.id] = true end - m.remove_label :unread if m.status == "RO" unless force_read + m.remove_label :unread if m.source_marked_read? unless force_read puts "# message at #{offset}, labels: #{labels * ', '}" unless rebuild if (rebuild || force_rebuild) && (docid, entry = index.load_entry_for_id(m.id)) && entry diff --git a/lib/sup/imap.rb b/lib/sup/imap.rb index 97c4a86..5aeac17 100644 --- a/lib/sup/imap.rb +++ b/lib/sup/imap.rb @@ -86,7 +86,7 @@ class IMAP < Source Redwood::reporting_thread do begin #raise Net::IMAP::ByeResponseError, "simulated imap failure" - @imap = Net::IMAP.new host, ssl? ? 993 : 143, ssl? + @imap = Net::IMAP.new host, port, ssl? say "Logging in..." @imap.authenticate 'LOGIN', @username, @password say "Sizing mailbox..." @@ -117,8 +117,10 @@ class IMAP < Source end private :connect + ## build a fake unique id def make_id imap_stuff - msize, mdate = imap_stuff.attr['RFC822.SIZE'], Time.parse(imap_stuff.attr["INTERNALDATE"]) + # use 7 digits for the size. why 7? seems nice. + msize, mdate = imap_stuff.attr['RFC822.SIZE'] % 10000000, Time.parse(imap_stuff.attr["INTERNALDATE"]) sprintf("%d%07d", mdate.to_i, msize).to_i end private :make_id @@ -139,27 +141,28 @@ class IMAP < Source RMail::Parser.read raw_full_message(id) end - ## load the full header text def raw_header id @mutex.synchronize do connect or raise SourceError, broken_msg - get_imap_field(id, 'RFC822.HEADER').gsub(/\r\n/, "\n") + header, flags = get_imap_fields id, 'RFC822.HEADER', 'FLAGS' + header = "Status: RO\n" + header if flags.include? :Seen # fake an mbox-style read header + header.gsub(/\r\n/, "\n") end end def raw_full_message id @mutex.synchronize do connect or raise SourceError, broken_msg - get_imap_field(id, 'RFC822').gsub(/\r\n/, "\n") + get_imap_fields(id, 'RFC822').first.gsub(/\r\n/, "\n") end end - def get_imap_field id, field + def get_imap_fields id, *fields retries = 0 f = nil imap_id = @imap_ids[id] or raise SourceError, "Unknown message id #{id}. #@recover_msg" begin - f = @imap.fetch imap_id, [field, 'RFC822.SIZE', 'INTERNALDATE'] + f = @imap.fetch imap_id, (fields + ['RFC822.SIZE', 'INTERNALDATE']).uniq got_id = make_id f[0] raise SourceError, "IMAP message mismatch: requested #{id}, got #{got_id}. #@recover_msg" unless got_id == id rescue Net::IMAP::Error => e @@ -173,9 +176,9 @@ class IMAP < Source end raise SourceError, "null IMAP field '#{field}' for message with id #{id} imap id #{imap_id}" if f.nil? - f[0].attr[field] + fields.map { |field| f[0].attr[field] } end - private :get_imap_field + private :get_imap_fields def each @mutex.synchronize { connect or raise SourceError, broken_msg } diff --git a/lib/sup/message.rb b/lib/sup/message.rb index efa2e73..fe98794 100644 --- a/lib/sup/message.rb +++ b/lib/sup/message.rb @@ -82,9 +82,9 @@ class Message attr_reader :id, :date, :from, :subj, :refs, :replytos, :to, :source, :cc, :bcc, :labels, :list_address, :recipient_email, :replyto, - :source_info, :status + :source_info - bool_reader :dirty + bool_reader :dirty, :source_marked_read ## if you specify a :header, will use values from that. otherwise, will try and ## load the header from the source. @@ -130,7 +130,7 @@ class Message end @recipient_email = header["delivered-to"] - @status = header["status"] + @source_marked_read = header["status"] == "RO" end private :read_header @@ -177,7 +177,7 @@ class Message [Text.new(error_message(@source.broken_msg.split("\n")))] else begin - read_header @source.load_header(@source_info) +# read_header @source.load_header(@source_info) ##XXXX is this ok? message_to_chunks @source.load_message(@source_info) rescue SourceError, SocketError => e [Text.new(error_message(e.message))]