Hi All,
After being a little frustrated with the PersonManager machinery and
what it did to mail from our ticketing system, I decided to go in a
rip out that code (as William mentioned might be worthwhile some time
back). I did this but wasn't thrilled with the result...all threads
in the index are initially displayed without the 'proper' names on
them. In most cases, the PersonManager code was doing the right thing
(at least in my view) and I like the functionality overall.
In light of this I decided to add a hook instead that lets the user
determine on the fly whether or not to cache display names in the
PersonManager. The attached patch adds the filter-person hook to
accomplish this. The hook is passed a person object and should return
a boolean value. A true value indicates that the person object for
the specific piece of mail should be returned, thus giving sup the
name attached to the individual piece of mail. False indicates that
the 'best' name as cached by PersonManager will be used. I've been
running this patch for about a week and am happy with it. A colleague
has also been using it.
I hope you'll find it useful as well. I think it's a "best of both
worlds" type approach!
-Ben
--
---------------------------------------------------------------------------------------------------------------------------
Ben Walton <[EMAIL PROTECTED]>
When one person suffers from a delusion, it is called insanity. When
many people suffer from a delusion it is called Religion.
Robert M. Pirsig, Zen and the Art of Motorcycle Maintenance
---------------------------------------------------------------------------------------------------------------------------
From 6b2fceaf58df63785d34ac22da5d2f647796de4b Mon Sep 17 00:00:00 2001
From: Ben Walton <[EMAIL PROTECTED]>
Date: Mon, 9 Jun 2008 13:12:49 -0400
Subject: [PATCH] Added filter-person hook
This hook allows a user to selectively bypass the registration of 'best'
names for email addresses. The use case is a ticketting system that
legitimately has multiple correct names for a single email address.
---
lib/sup/person.rb | 37 +++++++++++++++++++++++++++++++------
1 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/lib/sup/person.rb b/lib/sup/person.rb
index fb58f23..15f13cd 100644
--- a/lib/sup/person.rb
+++ b/lib/sup/person.rb
@@ -3,6 +3,24 @@ module Redwood
class PersonManager
include Singleton
+ HookManager.register "filter-person", <<EOS
+Executes when loading previously seen 'people' from file (to prevent re-storing
+newly filtered people) and before storing new people.
+
+This hook allows you to prevent storing a 'best' reference to a person, which
+is handy for things like ticketing systems where the Name on an address may
+change frequently depending on the ticket, while the address stays the same.
+By filtering these addresses out, you will see the name specific to that
+message instead of the 'best' name.
+
+Variables:
+ person: a person object (person.name and person.email are handy)
+Return Value:
+ boolean: false => store this object normally
+ true => skip storing this object. always use the name on the
+ current piece of mail.
+EOS
+
def initialize fn
@fn = fn
@@people = {}
@@ -11,7 +29,10 @@ class PersonManager
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
+ p = Person.new name, email, time, false
+ #calling the hook here allows filtering people that were stored before
+ #this hook was available/used.
+ @@people[email] = p unless HookManager.run "filter-person", :person => p
end if File.exists? fn
self.class.i_am_the_instance self
@@ -41,12 +62,16 @@ class PersonManager
def self.register p
oldp = @@people[p.email]
- if oldp.nil? || p.better_than?(oldp)
- @@people[p.email] = p
+ if HookManager.run "filter-person", :person => p
+ p
+ else
+ if oldp.nil? || p.better_than?(oldp)
+ @@people[p.email] = p
+ end
+
+ @@people[p.email].touch!
+ @@people[p.email]
end
-
- @@people[p.email].touch!
- @@people[p.email]
end
end
--
1.5.5.1
_______________________________________________
sup-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/sup-talk