* [sup-talk] [PATCH] Remove the people.txt mapping.
@ 2009-03-16 18:37 Nicolas Pouillard
0 siblings, 0 replies; only message in thread
From: Nicolas Pouillard @ 2009-03-16 18:37 UTC (permalink / raw)
Resent...
---
lib/sup.rb | 4 +--
lib/sup/account.rb | 5 +--
lib/sup/contact.rb | 2 +-
lib/sup/person.rb | 66 +++++----------------------------------------------
4 files changed, 11 insertions(+), 66 deletions(-)
diff --git a/lib/sup.rb b/lib/sup.rb
index 93369a5..d833dff 100644
--- a/lib/sup.rb
+++ b/lib/sup.rb
@@ -53,7 +53,6 @@ module Redwood
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")
@@ -115,7 +114,7 @@ module Redwood
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
@@ -130,7 +129,6 @@ module Redwood
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
diff --git a/lib/sup/account.rb b/lib/sup/account.rb
index f8ac0fc..6f86129 100644
--- a/lib/sup/account.rb
+++ b/lib/sup/account.rb
@@ -5,8 +5,8 @@ class Account < Person
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
@@ -42,7 +42,6 @@ class AccountManager
hash[:alternates] ||= []
a = Account.new hash
- PersonManager.register a
@accounts[a] = true
if default
diff --git a/lib/sup/contact.rb b/lib/sup/contact.rb
index b0c272e..bbb872f 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, :definitive => true
+ p = PersonManager.person_for addr
@p2a[p] = aalias
@a2p[aalias] = p unless aalias.nil? || aalias.empty?
end
diff --git a/lib/sup/person.rb b/lib/sup/person.rb
index fb58f23..995620b 100644
--- a/lib/sup/person.rb
+++ b/lib/sup/person.rb
@@ -3,60 +3,24 @@ module Redwood
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
@@ -67,26 +31,10 @@ class Person
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
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-03-16 18:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-16 18:37 [sup-talk] [PATCH] Remove the people.txt mapping Nicolas Pouillard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox