end
def start
- Redwood::PersonManager.new
Redwood::SentManager.new Redwood::SENT_FN
Redwood::ContactManager.new Redwood::CONTACT_FN
Redwood::LabelManager.new Redwood::LABEL_FN
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
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
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
@from =
if header["from"]
- PersonManager.person_for header["from"]
+ Person.from_address header["from"]
else
fakename = "Sup Auto-generated Fake Sender <sup@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
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
@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
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
## 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
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
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
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
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
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
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