|
3 | 3 | module ASF |
4 | 4 | # Convenience functions related to emails or mailing lists. |
5 | 5 | class Mail |
6 | | - # return a Hash containing complete list of all known emails, and the |
7 | | - # ASF::Person that is associated with that email. |
8 | | - def self.list |
9 | | - begin |
10 | | - return @list.to_h if @list |
11 | | - rescue NoMethodError, WeakRef::RefError |
12 | | - end |
| 6 | + # return a hash containing down-cased email names, together with a Set of people with whom |
| 7 | + # they are associated. In almost all cases there is only a single associated person. |
| 8 | + # The emails are sourced from LDAP, and optionally members.txt and iclas.txt |
| 9 | + def self.listall |
| 10 | + # Note: no point currently caching the list in memory, as this method is only used by cgi scripts |
13 | 11 |
|
14 | | - list = {} |
| 12 | + list = Hash.new{|h,k| h[k] = Set.new} # this creates a default Proc, which we remove later |
15 | 13 |
|
16 | 14 | # load info from LDAP |
17 | | - people = ASF::Person.preload(['mail', 'asf-altEmail']) |
| 15 | + people = ASF::Person.preload(['mail', 'asf-altEmail', 'cn']) |
18 | 16 | people.each do |person| |
19 | 17 | (person.mail + person.alt_email).each do |mail| |
20 | | - list[mail.downcase] = person |
| 18 | + list[mail.downcase] << person # there may be more that one person associated with a single email |
21 | 19 | end |
22 | 20 | end |
23 | 21 |
|
24 | 22 | # load all member emails in one pass |
25 | 23 | ASF::Member.each do |id, text| |
26 | 24 | Member.emails(text).each do |mail| |
27 | | - list[mail.downcase] ||= Person.find(id) |
| 25 | + list[mail.downcase] << Person.find(id) # this should find one of the pre-loads |
28 | 26 | end |
29 | 27 | end |
30 | 28 |
|
31 | 29 | # load all ICLA emails in one pass |
32 | 30 | ASF::ICLA.each do |icla| |
33 | 31 | person = Person.find(icla.id) |
34 | 32 | icla.emails.each do |email| |
35 | | - list[email.downcase] ||= person |
| 33 | + list[email.downcase] << person |
36 | 34 | end |
37 | 35 | next if icla.noId? |
38 | 36 |
|
39 | | - list["#{icla.id.downcase}@apache.org"] ||= person |
| 37 | + list["#{icla.id.downcase}@apache.org"] << person # is this needed? |
40 | 38 | end |
41 | 39 |
|
42 | | - @list = WeakRef.new(list) |
| 40 | + list.default_proc = nil # no longer create an empty set when a key is missing |
43 | 41 | list |
44 | 42 | end |
45 | 43 |
|
| 44 | + # Allow for trailing +- suffix in emails. |
| 45 | + # e.g. |
| 46 | + # username-test@apache.org => username@apache.org |
| 47 | + # username+test@gmail.com => username@gmail.com |
| 48 | + def self.remove_email_suffix(email) |
| 49 | + # TODO: may need to tighten this to avoid ambiguities |
| 50 | + # e.g. selectively apply '-xxx' or '+xxx' removal, depending on domain |
| 51 | + email.downcase.sub(/[-+]\w+@/,'@') # drop suffix |
| 52 | + end |
| 53 | + |
46 | 54 | # return a list of people ids, their public-name, whether they are an ASF member, and email addresses |
47 | 55 | def self.people_mails |
48 | 56 | member_statuses = ASF::Member.member_statuses # cache the statuses. TODO: should be done in ASF.Member |
|
0 commit comments