]> git.cworth.org Git - sup/commitdiff
properly parse email addresses store in index
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 25 Mar 2009 15:49:22 +0000 (08:49 -0700)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 25 Mar 2009 15:49:22 +0000 (08:49 -0700)
See comments in code. Email addresses are stored in the index in a bizarre
format, but we can re-parse them.

lib/sup/person.rb

index ca703519031dfb6fc539e0f934a11843cf39a96b..c4f40a523e77907590d6eb1e546a37905fef6576 100644 (file)
@@ -77,8 +77,20 @@ class Person
     return nil if s.nil?
 
     ## try and parse an email address and name
-    name, email =
-      case s
+    name, email = case s
+      when /(.+?) ((\S+?)@\S+) \3/
+        ## ok, this first match cause is insane, but bear with me.  email
+        ## addresses are stored in the to/from/etc fields of the index in a
+        ## weird format: "name address first-part-of-address", i.e.  spaces
+        ## separating those three bits, and no <>'s. this is the output of
+        ## #indexable_content. here, we reverse-engineer that format to extract
+        ## a valid address.
+        ##
+        ## we store things this way to allow searches on a to/from/etc field to
+        ## match any of those parts. a more robust solution would be to store a
+        ## separate, non-indexed field with the proper headers. but this way we
+        ## save precious bits, and it's backwards-compatible with older indexes.
+        [$1, $2]
       when /["'](.*?)["'] <(.*?)>/, /([^,]+) <(.*?)>/
         a, b = $1, $2
         [a.gsub('\"', '"'), b]
@@ -98,6 +110,7 @@ class Person
     ss.split_on_commas.map { |s| self.from_address s }
   end
 
+  ## see comments in self.from_address
   def indexable_content
     [name, email, email.split(/@/).first].join(" ")
   end