]> git.cworth.org Git - sup/commitdiff
subscribe/unsubscribe functionality
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Thu, 8 Nov 2007 01:38:14 +0000 (01:38 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Thu, 8 Nov 2007 01:38:14 +0000 (01:38 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@682 5c8cc53c-5e98-4d25-b20a-d8db53a31250

lib/sup/mbox.rb
lib/sup/message.rb
lib/sup/modes/compose-mode.rb
lib/sup/modes/thread-view-mode.rb

index a40af24de10a8f432ccfb4b8ecfb951146f90940..0ce52fe24fd9ff8bbba19bea2141dfd8e4d4625d 100644 (file)
@@ -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
index 791890a7e319e6c26174d68d5438ff6e119fc7b5..ca7efad4cd0d4d25d734978abe61d6414decca80 100644 (file)
@@ -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
 
index cb971da016bc4c53bc90c0297d51a82bedd037c3..abd4dd175f82e7e6fcd79509011f6b229661b976 100644 (file)
@@ -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]
index 5f3cd6f9e8315df5b904b3f4e00024d0626dfc66..88c512529f148bb9a2b9e5c4e3635cc587b997e1 100644 (file)
@@ -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