From: William Morgan Date: Wed, 25 Mar 2009 15:49:22 +0000 (-0700) Subject: properly parse email addresses store in index X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=a17f15d4f69004f566beda66527476e4e097e874;p=sup 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. --- diff --git a/lib/sup/person.rb b/lib/sup/person.rb index ca70351..c4f40a5 100644 --- 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