From 2be126416f39364326c10d6289367d4da61ff3d5 Mon Sep 17 00:00:00 2001 From: wmorgan Date: Wed, 7 Nov 2007 01:56:27 +0000 Subject: [PATCH] four patches from marcus williams! git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@673 5c8cc53c-5e98-4d25-b20a-d8db53a31250 --- lib/sup/imap.rb | 13 +++++++++++-- lib/sup/maildir.rb | 9 +++++++++ lib/sup/modes/edit-message-mode.rb | 2 ++ lib/sup/modes/inbox-mode.rb | 4 +++- lib/sup/poll.rb | 2 +- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/sup/imap.rb b/lib/sup/imap.rb index c74b0e5..290ae2a 100644 --- a/lib/sup/imap.rb +++ b/lib/sup/imap.rb @@ -109,6 +109,10 @@ class IMAP < Source def load_message id RMail::Parser.read raw_message(id) end + + def each_raw_message_line id + StringIO.new(raw_message(id)).each { |l| yield l } + end def raw_header id unsynchronized_scan_mailbox @@ -164,13 +168,14 @@ class IMAP < Source id = ids[i] state = @mutex.synchronize { @imap_state[id] } or next self.cur_offset = id - labels = { :Seen => :unread, - :Flagged => :starred, + labels = { :Flagged => :starred, :Deleted => :deleted }.inject(@labels) do |cur, (imap, sup)| cur + (state[:flags].include?(imap) ? [sup] : []) end + labels += [:unread] unless state[:flags].include?(:Seen) + yield id, labels end end @@ -228,10 +233,12 @@ private ## fails with a NO response, the client may try another", in ## practice it seems like they can also send a BAD response. begin + raise Net::IMAP::NoResponseError unless @imap.capability().member? "AUTH=CRAM-MD5" @imap.authenticate 'CRAM-MD5', @username, @password rescue Net::IMAP::BadResponseError, Net::IMAP::NoResponseError => e Redwood::log "CRAM-MD5 authentication failed: #{e.class}. Trying LOGIN auth..." begin + raise Net::IMAP::NoResponseError unless @imap.capability().member? "AUTH=LOGIN" @imap.authenticate 'LOGIN', @username, @password rescue Net::IMAP::BadResponseError, Net::IMAP::NoResponseError => e Redwood::log "LOGIN authentication failed: #{e.class}. Trying plain-text LOGIN..." @@ -246,6 +253,8 @@ private end end.join + + raise exception if exception end diff --git a/lib/sup/maildir.rb b/lib/sup/maildir.rb index 6020c86..ba9da00 100644 --- a/lib/sup/maildir.rb +++ b/lib/sup/maildir.rb @@ -39,6 +39,15 @@ class Maildir < Source start = @ids.index(cur_offset || start_offset) or raise OutOfSyncSourceError, "Unknown message id #{cur_offset || start_offset}." # couldn't find the most recent email end + + def each_raw_message_line id + scan_mailbox + with_file_for(id) do |f| + until f.eof? + yield f.gets + end + end + end def load_header id scan_mailbox diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb index 3ae0eeb..52447e8 100644 --- a/lib/sup/modes/edit-message-mode.rb +++ b/lib/sup/modes/edit-message-mode.rb @@ -127,6 +127,8 @@ protected header, @header_lines = format_headers(@header - NON_EDITABLE_HEADERS) + [""] @text = header + [""] + @body @text += sig_lines unless $config[:edit_signature] + + @attachment_lines_offset = 0 unless @attachments.empty? @text += [""] diff --git a/lib/sup/modes/inbox-mode.rb b/lib/sup/modes/inbox-mode.rb index aa40318..66b7379 100644 --- a/lib/sup/modes/inbox-mode.rb +++ b/lib/sup/modes/inbox-mode.rb @@ -14,7 +14,9 @@ class InboxMode < ThreadIndexMode @@instance = self end - def is_relevant? m; m.has_label? :inbox; end + def is_relevant? m + m.has_label? :inbox && ([:spam, :deleted, :killed] & m.labels).length == 0 + end ## label-list-mode wants to be able to raise us if the user selects ## the "inbox" label, so we need to keep our singletonness around diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb index e124af1..fb7b546 100644 --- a/lib/sup/poll.rb +++ b/lib/sup/poll.rb @@ -153,8 +153,8 @@ EOS end docid, entry = Index.load_entry_for_id m.id - m = yield(m, offset, entry) or next HookManager.run "before-add-message", :message => m + m = yield(m, offset, entry) or next Index.sync_message m, docid, entry UpdateManager.relay self, :add, m unless entry rescue MessageFormatError => e -- 2.45.2