# File lib/sup/person.rb, line 74 def self.from_address s return nil if s.nil? ## try and parse an email address and name name, email = case s when %r(.+?) ((\S+?)@\S+) \33// ## 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 %r["'](.*?)["'] <(.*?)>/, %r([^,]+) <(.*?)>/ a, b = $1, $2 [a.gsub('\"', '"'), b] when %r<((\S+?)@\S+?)>/ [$2, $1] when %r((\S+?)@\S+)/ [$2, $1] else [nil, s] end Person.new name, email end
# File lib/sup/person.rb, line 106 def self.from_address_list ss return [] if ss.nil? ss.split_on_commas.map { |s| self.from_address s } end
# File lib/sup/person.rb, line 6 def initialize name, email raise ArgumentError, "email can't be nil" unless email @name = if name name = name.strip.gsub(%r\s+/, " ") name =~ %r^(['"]\s*)(.*?)(\s*["'])$/ ? $2 : name end @email = email.strip.gsub(%r\s+/, " ").downcase end
# File lib/sup/person.rb, line 116 def eql? o; email.eql? o.email end
# File lib/sup/person.rb, line 46 def full_address if @name && @email if @name =~ %r[",@]/ "#{@name.inspect} <#{@email}>" # escape quotes else "#{@name} <#{@email}>" end else email end end
# File lib/sup/person.rb, line 117 def hash; email.hash end
see comments in self.from_address
# File lib/sup/person.rb, line 112 def indexable_content [name, email, email.split(%r@/).first].join(" ") end
# File lib/sup/person.rb, line 36 def longname if @name && @email "#@name <#@email>" else @email end end
# File lib/sup/person.rb, line 44 def mediumname; @name || @email; end
def == o; o && o.email == email; end alias :eql? :== def hash; [name, email].hash; end
# File lib/sup/person.rb, line 23 def shortname case @name when %r\S+, (\S+)/ $1 when %r(\S+) \S+/ $1 when nil @email else @name end end
when sorting addresses, sort by this
# File lib/sup/person.rb, line 59 def sort_by_me case @name when %r^(\S+), \S+/ $1 when %r^\S+ \S+ (\S+)/ $1 when %r^\S+ (\S+)/ $1 when nil @email else @name end.downcase end
# File lib/sup/person.rb, line 17 def to_s; "#@name <#@email>" end