COLOR_FN = File.join(BASE_DIR, "colors.yaml")
SOURCE_FN = File.join(BASE_DIR, "sources.yaml")
LABEL_FN = File.join(BASE_DIR, "labels.txt")
- PERSON_FN = File.join(BASE_DIR, "people.txt")
CONTACT_FN = File.join(BASE_DIR, "contacts.txt")
DRAFT_DIR = File.join(BASE_DIR, "drafts")
SENT_FN = File.join(BASE_DIR, "sent.mbox")
end
def start
- Redwood::PersonManager.new Redwood::PERSON_FN
+ Redwood::PersonManager.new
Redwood::SentManager.new Redwood::SENT_FN
Redwood::ContactManager.new Redwood::CONTACT_FN
Redwood::LabelManager.new Redwood::LABEL_FN
def finish
Redwood::LabelManager.save if Redwood::LabelManager.instantiated?
Redwood::ContactManager.save if Redwood::ContactManager.instantiated?
- Redwood::PersonManager.save if Redwood::PersonManager.instantiated?
Redwood::BufferManager.deinstantiate! if Redwood::BufferManager.instantiated?
end
def initialize h
raise ArgumentError, "no name for account" unless h[:name]
- raise ArgumentError, "no name for email" unless h[:name]
- super h[:name], h[:email], 0, true
+ raise ArgumentError, "no email for account" unless h[:email]
+ super h[:name], h[:email]
@sendmail = h[:sendmail]
@signature = h[:signature]
end
hash[:alternates] ||= []
a = Account.new hash
- PersonManager.register a
@accounts[a] = true
if default
class PersonManager
include Singleton
- def initialize fn
- @fn = fn
- @@people = {}
-
- ## read in stored people
- IO.readlines(fn).map do |l|
- l =~ /^(.*)?:\s+(\d+)\s+(.*)$/ or next
- email, time, name = $1, $2, $3
- @@people[email] = Person.new name, email, time, false
- end if File.exists? fn
-
+ def initialize
self.class.i_am_the_instance self
end
- def save
- File.open(@fn, "w") do |f|
- @@people.each do |email, p|
- next if p.email == p.name
- next if p.name =~ /=/ # drop rfc2047-encoded, and lots of other useless emails. definitely a heuristic.
- f.puts "#{p.email}: #{p.timestamp} #{p.name}"
- end
- end
- end
-
- def self.people_for s, opts={}
+ def self.people_for s
return [] if s.nil?
- s.split_on_commas.map { |ss| self.person_for ss, opts }
+ s.split_on_commas.map { |ss| self.person_for ss }
end
- def self.person_for s, opts={}
- p = Person.from_address(s) or return nil
- p.definitive = true if opts[:definitive]
- register p
- end
-
- def self.register p
- oldp = @@people[p.email]
-
- if oldp.nil? || p.better_than?(oldp)
- @@people[p.email] = p
- end
-
- @@people[p.email].touch!
- @@people[p.email]
+ def self.person_for s
+ Person.from_address(s)
end
end
-## don't create these by hand. rather, go through personmanager, to
-## ensure uniqueness and overriding.
class Person
- attr_accessor :name, :email, :timestamp
- bool_accessor :definitive
+ attr_accessor :name, :email
- def initialize name, email, timestamp=0, definitive=false
+ def initialize name, email
raise ArgumentError, "email can't be nil" unless email
if name
end
@email = email.gsub(/^\s+|\s+$/, "").gsub(/\s+/, " ").downcase
- @definitive = definitive
- @timestamp = timestamp
- end
-
- ## heuristic: whether the name attached to this email is "real", i.e.
- ## we should bother to store it.
- def generic?
- @email =~ /no\-?reply/
- end
-
- def better_than? o
- return false if o.definitive? || generic?
- return true if definitive?
- o.name.nil? || (name && name.length > o.name.length && name =~ /[a-z]/)
end
def to_s; "#@name <#@email>" end
- def touch!; @timestamp = Time.now.to_i end
-
# def == o; o && o.email == email; end
# alias :eql? :==
# def hash; [name, email].hash; end