sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit b675cd3d9c8674390fd23c54ecc8f1ff001a6999
parent 3642ebecd7cb2f0ce2e3df882218235a2bd0c423
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date:   Thu,  8 Nov 2007 01:38:14 +0000

subscribe/unsubscribe functionality

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

Diffstat:
M lib/sup/mbox.rb | 4 +++-
M lib/sup/message.rb | 4 +++-
M lib/sup/modes/compose-mode.rb | 9 ++++-----
M lib/sup/modes/thread-view-mode.rb | 20 ++++++++++++++++++++
4 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/lib/sup/mbox.rb b/lib/sup/mbox.rb
@@ -30,6 +30,8 @@ module MBox
         /^(In-Reply-To):\s+(.*?)\s*$/i,
         /^(Reply-To):\s+(.*?)\s*$/i,
         /^(List-Post):\s+(.*?)\s*$/i,
+        /^(List-Subscribe):\s+(.*?)\s*$/i,
+        /^(List-Unsubscribe):\s+(.*?)\s*$/i,
         /^(Status):\s+(.*?)\s*$/i: header[last = $1] = $2
       when /^(Message-Id):\s+(.*?)\s*$/i: header[mid_field = last = $1] = $2
 
@@ -40,7 +42,7 @@ module MBox
         /^(Envelope-To):\s+(.*)$/i: header[last = $1] ||= $2
 
       when /^$/: break
-      when /:/: last = nil # some other header we don't care about
+      when /^\S+: /: last = nil # some other header we don't care about
       else
         header[last] += " " + line.chomp.gsub(/^\s+/, "") if last
       end
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
@@ -35,7 +35,7 @@ class Message
 
   attr_reader :id, :date, :from, :subj, :refs, :replytos, :to, :source,
               :cc, :bcc, :labels, :list_address, :recipient_email, :replyto,
-              :source_info, :chunks
+              :source_info, :chunks, :list_subscribe, :list_unsubscribe
 
   bool_reader :dirty, :source_marked_read
 
@@ -107,6 +107,8 @@ class Message
 
     @recipient_email = header["envelope-to"] || header["x-original-to"] || header["delivered-to"]
     @source_marked_read = header["status"] == "RO"
+    @list_subscribe = header["list-subscribe"]
+    @list_unsubscribe = header["list-unsubscribe"]
   end
   private :parse_header
 
diff --git a/lib/sup/modes/compose-mode.rb b/lib/sup/modes/compose-mode.rb
@@ -7,7 +7,7 @@ module CanSpawnComposeMode
     bcc = opts[:bcc] || BufferManager.ask_for_contacts(:people, "Bcc: ") or return if $config[:ask_for_bcc]
     subj = opts[:subj] || BufferManager.ask(:subject, "Subject: ") or return if $config[:ask_for_subject]
     
-    mode = ComposeMode.new :to => to, :cc => cc, :bcc => bcc, :subj => subj
+    mode = ComposeMode.new :from => opts[:from], :to => to, :cc => cc, :bcc => bcc, :subj => subj
     BufferManager.spawn "New Message", mode
     mode.edit_message
   end
@@ -15,10 +15,9 @@ end
 
 class ComposeMode < EditMessageMode
   def initialize opts={}
-    header = {
-      "From" => AccountManager.default_account.full_address,
-    }
-
+    header = {}
+    header["From"] = (opts[:from] || AccountManager.default_account).full_address
+    header["To"] = opts[:to].map { |p| p.full_address }.join(", ") if opts[:to]
     header["To"] = opts[:to].map { |p| p.full_address }.join(", ") if opts[:to]
     header["Cc"] = opts[:cc].map { |p| p.full_address }.join(", ") if opts[:cc]
     header["Bcc"] = opts[:bcc].map { |p| p.full_address }.join(", ") if opts[:bcc]
diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb
@@ -38,6 +38,8 @@ class ThreadViewMode < LineCursorMode
     k.add :compose, "Compose message to person", 'm'
     k.add :archive_and_kill, "Archive thread and kill buffer", 'a'
     k.add :delete_and_kill, "Delete thread and kill buffer", 'd'
+    k.add :subscribe_to_list, "Subscribe to/unsubscribe from mailing list", "("
+    k.add :unsubscribe_from_list, "Subscribe to/unsubscribe from mailing list", ")"
   end
 
   ## there are a couple important instance variables we hold to format
@@ -108,6 +110,24 @@ class ThreadViewMode < LineCursorMode
     BufferManager.spawn "Reply to #{m.subj}", mode
   end
 
+  def subscribe_to_list
+    m = @message_lines[curpos] or return
+    if m.list_subscribe && m.list_subscribe =~ /<mailto:(.*?)\?(subject=(.*?))>/
+      spawn_compose_mode :from => AccountManager.account_for(m.recipient_email), :to => [PersonManager.person_for($1)], :subj => $3
+    else
+      BufferManager.flash "Can't find List-Subscribe header for this message."
+    end
+  end
+
+  def unsubscribe_from_list
+    m = @message_lines[curpos] or return
+    if m.list_unsubscribe && m.list_unsubscribe =~ /<mailto:(.*?)\?(subject=(.*?))>/
+      spawn_compose_mode :from => AccountManager.account_for(m.recipient_email), :to => [PersonManager.person_for($1)], :subj => $3
+    else
+      BufferManager.flash "Can't find List-Unsubscribe header for this message."
+    end
+  end
+
   def forward
     m = @message_lines[curpos] or return
     spawn_forward_mode m