sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit a17f15d4f69004f566beda66527476e4e097e874
parent d2c5e0953e00a6a2f560e6db722e0e5b3ef854da
Author: William Morgan <wmorgan-sup@masanjin.net>
Date:   Wed, 25 Mar 2009 08:49:22 -0700

properly parse email addresses store in index

See comments in code. Email addresses are stored in the index in a bizarre
format, but we can re-parse them.

Diffstat:
M lib/sup/person.rb | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/lib/sup/person.rb b/lib/sup/person.rb
@@ -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