Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
From: nicolas.pouillard@gmail.com (Nicolas Pouillard)
Subject: [sup-talk] [PATCH] Remove the now useless PersonManager
Date: Mon, 16 Mar 2009 19:38:17 +0100	[thread overview]
Message-ID: <1237228691-sup-735@ausone.local> (raw)
In-Reply-To: <ea2d84848a9fed1fbceb3837aacf8bcf86bd0602.1227456947.git.nicolas.pouillard@gmail.com>

Resent..

Replace PersonManager.person_for by Person.from_address
and PersonManager.people_for by Person.from_address_list
---
 lib/sup.rb                         |    1 -
 lib/sup/buffer.rb                  |    2 +-
 lib/sup/contact.rb                 |    2 +-
 lib/sup/index.rb                   |    4 ++--
 lib/sup/message.rb                 |   16 ++++++++--------
 lib/sup/modes/edit-message-mode.rb |    6 +++---
 lib/sup/modes/reply-mode.rb        |    2 +-
 lib/sup/modes/thread-view-mode.rb  |    4 ++--
 lib/sup/person.rb                  |   22 +++++-----------------
 9 files changed, 23 insertions(+), 36 deletions(-)

diff --git a/lib/sup.rb b/lib/sup.rb
index d833dff..b3ebd38 100644
--- a/lib/sup.rb
+++ b/lib/sup.rb
@@ -114,7 +114,6 @@ module Redwood
   end
 
   def start
-    Redwood::PersonManager.new
     Redwood::SentManager.new Redwood::SENT_FN
     Redwood::ContactManager.new Redwood::CONTACT_FN
     Redwood::LabelManager.new Redwood::LABEL_FN
diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb
index 0447f61..657027d 100644
--- a/lib/sup/buffer.rb
+++ b/lib/sup/buffer.rb
@@ -506,7 +506,7 @@ EOS
     answer = BufferManager.ask_many_emails_with_completions domain, question, completions, default
 
     if answer
-      answer.split_on_commas.map { |x| ContactManager.contact_for(x) || PersonManager.person_for(x) }
+      answer.split_on_commas.map { |x| ContactManager.contact_for(x) || Person.from_address(x) }
     end
   end
 
diff --git a/lib/sup/contact.rb b/lib/sup/contact.rb
index bbb872f..51fd0e9 100644
--- a/lib/sup/contact.rb
+++ b/lib/sup/contact.rb
@@ -17,7 +17,7 @@ class ContactManager
       IO.foreach(fn) do |l|
         l =~ /^([^:]*): (.*)$/ or raise "can't parse #{fn} line #{l.inspect}"
         aalias, addr = $1, $2
-        p = PersonManager.person_for addr
+        p = Person.from_address addr
         @p2a[p] = aalias
         @a2p[aalias] = p unless aalias.nil? || aalias.empty?
       end
diff --git a/lib/sup/index.rb b/lib/sup/index.rb
index cda5cee..d2e58ce 100644
--- a/lib/sup/index.rb
+++ b/lib/sup/index.rb
@@ -447,9 +447,9 @@ EOS
         t = @index[docid][:to]
 
         if AccountManager.is_account_email? f
-          t.split(" ").each { |e| contacts[PersonManager.person_for(e)] = true }
+          t.split(" ").each { |e| contacts[Person.from_address(e)] = true }
         else
-          contacts[PersonManager.person_for(f)] = true
+          contacts[Person.from_address(f)] = true
         end
       end
     end
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index e01e245..88d9ce3 100644
--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -78,10 +78,10 @@ class Message
     
     @from =
       if header["from"]
-        PersonManager.person_for header["from"]
+        Person.from_address header["from"]
       else
         fakename = "Sup Auto-generated Fake Sender <sup at fake.sender.example.com>"
-        PersonManager.person_for fakename
+        Person.from_address fakename
       end
 
     Redwood::log "faking message-id for message from #@from: #{id}" if fakeid
@@ -105,9 +105,9 @@ class Message
       end
 
     @subj = header.member?("subject") ? header["subject"].gsub(/\s+/, " ").gsub(/\s+$/, "") : DEFAULT_SUBJECT
-    @to = PersonManager.people_for header["to"]
-    @cc = PersonManager.people_for header["cc"]
-    @bcc = PersonManager.people_for header["bcc"]
+    @to = Person.from_address_list header["to"]
+    @cc = Person.from_address_list header["cc"]
+    @bcc = Person.from_address_list header["bcc"]
 
     ## before loading our full header from the source, we can actually
     ## have some extra refs set by the UI. (this happens when the user
@@ -117,10 +117,10 @@ class Message
     @refs = (@refs + refs).uniq
     @replytos = (header["in-reply-to"] || "").scan(/<(.+?)>/).map { |x| sanitize_message_id x.first }
 
-    @replyto = PersonManager.person_for header["reply-to"]
+    @replyto = Person.from_address header["reply-to"]
     @list_address =
       if header["list-post"]
-        @list_address = PersonManager.person_for header["list-post"].gsub(/^<mailto:|>$/, "")
+        @list_address = Person.from_address header["list-post"].gsub(/^<mailto:|>$/, "")
       else
         nil
       end
@@ -391,7 +391,7 @@ private
     elsif m.header.content_type == "message/rfc822"
       payload = RMail::Parser.read(m.body)
       from = payload.header.from.first
-      from_person = from ? PersonManager.person_for(from.format) : nil
+      from_person = from ? Person.from_address(from.format) : nil
       [Chunk::EnclosedMessage.new(from_person, payload.to_s)] +
         message_to_chunks(payload, encrypted)
     else
diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb
index cc6e7af..31aa897 100644
--- a/lib/sup/modes/edit-message-mode.rb
+++ b/lib/sup/modes/edit-message-mode.rb
@@ -321,8 +321,8 @@ protected
 
     ## do whatever crypto transformation is necessary
     if @crypto_selector && @crypto_selector.val != :none
-      from_email = PersonManager.person_for(@header["From"]).email
-      to_email = [@header["To"], @header["Cc"], @header["Bcc"]].flatten.compact.map { |p| PersonManager.person_for(p).email }
+      from_email = Person.from_address(@header["From"]).email
+      to_email = [@header["To"], @header["Cc"], @header["Bcc"]].flatten.compact.map { |p| Person.from_address(p).email }
 
       m = CryptoManager.send @crypto_selector.val, from_email, to_email, m
     end
@@ -412,7 +412,7 @@ private
   end
 
   def sig_lines
-    p = PersonManager.person_for(@header["From"])
+    p = Person.from_address(@header["From"])
     from_email = p && p.email
 
     ## first run the hook
diff --git a/lib/sup/modes/reply-mode.rb b/lib/sup/modes/reply-mode.rb
index 4e08e8e..c1c542b 100644
--- a/lib/sup/modes/reply-mode.rb
+++ b/lib/sup/modes/reply-mode.rb
@@ -63,7 +63,7 @@ EOS
       if hook_reply_from
         hook_reply_from
       elsif @m.recipient_email && AccountManager.is_account_email?(@m.recipient_email)
-        PersonManager.person_for(@m.recipient_email)
+        Person.from_address(@m.recipient_email)
       elsif(b = (@m.to + @m.cc).find { |p| AccountManager.is_account? p })
         b
       else
diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb
index 5f578d3..45c1247 100644
--- a/lib/sup/modes/thread-view-mode.rb
+++ b/lib/sup/modes/thread-view-mode.rb
@@ -148,7 +148,7 @@ EOS
   def subscribe_to_list
     m = @message_lines[curpos] or return
     if m.list_subscribe && m.list_subscribe =~ /<mailto:(.*?)\?(subject=(.*?))>/
-      ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [PersonManager.person_for($1)], :subj => $3
+      ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [Person.from_address($1)], :subj => $3
     else
       BufferManager.flash "Can't find List-Subscribe header for this message."
     end
@@ -157,7 +157,7 @@ EOS
   def unsubscribe_from_list
     m = @message_lines[curpos] or return
     if m.list_unsubscribe && m.list_unsubscribe =~ /<mailto:(.*?)\?(subject=(.*?))>/
-      ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [PersonManager.person_for($1)], :subj => $3
+      ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [Person.from_address($1)], :subj => $3
     else
       BufferManager.flash "Can't find List-Unsubscribe header for this message."
     end
diff --git a/lib/sup/person.rb b/lib/sup/person.rb
index 995620b..ca70351 100644
--- a/lib/sup/person.rb
+++ b/lib/sup/person.rb
@@ -1,22 +1,5 @@
 module Redwood
 
-class PersonManager
-  include Singleton
-
-  def initialize
-    self.class.i_am_the_instance self
-  end
-
-  def self.people_for s
-    return [] if s.nil?
-    s.split_on_commas.map { |ss| self.person_for ss }
-  end
-
-  def self.person_for s
-    Person.from_address(s)
-  end
-end
-
 class Person 
   attr_accessor :name, :email
 
@@ -110,6 +93,11 @@ class Person
     Person.new name, email
   end
 
+  def self.from_address_list ss
+    return [] if ss.nil?
+    ss.split_on_commas.map { |s| self.from_address s }
+  end
+
   def indexable_content
     [name, email, email.split(/@/).first].join(" ")
   end

-- 
Nicolas Pouillard


  parent reply	other threads:[~2009-03-16 18:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <ea2d84848a9fed1fbceb3837aacf8bcf86bd0602.1227456947.git.nicolas.pouillard@gmail.com>
2009-03-16 18:38 ` [sup-talk] [PATCH] Close the "remove email->name mapping" issue Nicolas Pouillard
2009-03-16 18:38 ` Nicolas Pouillard [this message]
2009-03-25 16:00   ` [sup-talk] [PATCH] Remove the now useless PersonManager William Morgan
2009-03-25 18:03     ` Nicolas Pouillard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1237228691-sup-735@ausone.local \
    --to=nicolas.pouillard@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox