sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 2be126416f39364326c10d6289367d4da61ff3d5
parent ecfd18f40356c0e97de80084a0612ff6578d32b2
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date:   Wed,  7 Nov 2007 01:56:27 +0000

four patches from marcus williams!

git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@673 5c8cc53c-5e98-4d25-b20a-d8db53a31250

Diffstat:
M lib/sup/imap.rb | 13 +++++++++++--
M lib/sup/maildir.rb | 9 +++++++++
M lib/sup/modes/edit-message-mode.rb | 2 ++
M lib/sup/modes/inbox-mode.rb | 4 +++-
M lib/sup/poll.rb | 2 +-
5 files changed, 26 insertions(+), 4 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -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
@@ -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