mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
Fixes #2665. Regenerated by tabbott with `lint --fix` after a rebase and change in parameters. Note from tabbott: In a few cases, this converts technical debt in the form of unsorted imports into different technical debt in the form of our largest files having very long, ugly import sequences at the start. I expect this change will increase pressure for us to split those files, which isn't a bad thing. Signed-off-by: Anders Kaseorg <anders@zulip.com>
26 lines
889 B
Python
26 lines
889 B
Python
import re
|
|
import traceback
|
|
|
|
import DNS
|
|
|
|
|
|
def compute_mit_user_fullname(email: str) -> str:
|
|
try:
|
|
# Input is either e.g. username@mit.edu or user|CROSSREALM.INVALID@mit.edu
|
|
match_user = re.match(r'^([a-zA-Z0-9_.-]+)(\|.+)?@mit\.edu$', email.lower())
|
|
if match_user and match_user.group(2) is None:
|
|
answer = DNS.dnslookup(
|
|
f"{match_user.group(1)}.passwd.ns.athena.mit.edu",
|
|
DNS.Type.TXT)
|
|
hesiod_name = answer[0][0].split(':')[4].split(',')[0].strip()
|
|
if hesiod_name != "":
|
|
return hesiod_name
|
|
elif match_user:
|
|
return match_user.group(1).lower() + "@" + match_user.group(2).upper()[1:]
|
|
except DNS.Base.ServerError:
|
|
pass
|
|
except Exception:
|
|
print(f"Error getting fullname for {email}:")
|
|
traceback.print_exc()
|
|
return email.lower()
|