mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	This library was absolutely essential as part of our Python 2->3
migration process, but all of its calls should be either no-ops or
encode/decode operations.
Note also that the library has been wrong since the incorrect
refactoring in 1f9244e060.
Fixes #10807.
		
	
		
			
				
	
	
		
			24 lines
		
	
	
		
			897 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			897 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(
 | 
						|
                "%s.passwd.ns.athena.mit.edu" % (match_user.group(1),),
 | 
						|
                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("Error getting fullname for %s:" % (email,))
 | 
						|
        traceback.print_exc()
 | 
						|
    return email.lower()
 |