Revert back some name/mail processing for cases where the uid is not strictly an email
This commit is contained in:
parent
de3dda922b
commit
755a2dc5ea
1 changed files with 40 additions and 14 deletions
|
@ -53,14 +53,39 @@ def _get_keyrings():
|
|||
keyrings.sort()
|
||||
return keyrings
|
||||
|
||||
|
||||
def _parse_uid(uid):
|
||||
"""
|
||||
Parse a uid of the form 'Real Name <email@example.com>' into email
|
||||
and realname parts.
|
||||
"""
|
||||
(uid, mail) = email.utils.parseaddr(uid)
|
||||
return (uid, mail)
|
||||
|
||||
# First try with the Python library, but it doesn't always catch everything
|
||||
(name, mail) = email.utils.parseaddr(uid)
|
||||
if (not name) and (not mail):
|
||||
logging.warning("malformed uid %s", uid)
|
||||
if (not name) or (not mail):
|
||||
logging.debug("strange uid %s: '%s' - <%s>", uid, name, mail)
|
||||
# Try and do better than the python library
|
||||
if not '@' in mail:
|
||||
uid = uid.strip()
|
||||
# First, strip comment
|
||||
s = uid.find('(')
|
||||
e = uid.find(')')
|
||||
if s >= 0 and e >= 0:
|
||||
uid = uid[:s] + uid[e + 1:]
|
||||
s = uid.find('<')
|
||||
e = uid.find('>')
|
||||
mail = None
|
||||
if s >= 0 and e >= 0:
|
||||
mail = uid[s + 1:e]
|
||||
uid = uid[:s] + uid[e + 1:]
|
||||
uid = uid.strip()
|
||||
if not mail and uid.find('@') >= 0:
|
||||
mail, uid = uid, mail
|
||||
|
||||
name = uid
|
||||
logging.debug("corrected: '%s' - <%s>", name, mail)
|
||||
return (name, mail)
|
||||
|
||||
resultdict = {}
|
||||
|
||||
|
@ -107,19 +132,20 @@ def process_keyrings():
|
|||
else:
|
||||
continue
|
||||
# Do stuff with 'uid'
|
||||
uid, email = _parse_uid(uid)
|
||||
if email:
|
||||
if email.endswith('@debian.org'):
|
||||
login = email[0:-len('@debian.org')]
|
||||
_add_to_result('login:email:%s' % email, login)
|
||||
_add_to_result('login:fpr:%s' % fpr, login)
|
||||
_add_to_result('fpr:login:%s' % login, fpr)
|
||||
_add_to_result('fpr:email:%s' % email, fpr)
|
||||
_add_to_result('email:fpr:%s' % fpr, email)
|
||||
if uid:
|
||||
(uid, mail) = _parse_uid(uid)
|
||||
if mail:
|
||||
if mail.endswith('@debian.org'):
|
||||
login = mail[0:-len('@debian.org')]
|
||||
_add_to_result('login:email:%s' % mail, login)
|
||||
_add_to_result('login:fpr:%s' % fpr, login)
|
||||
_add_to_result('fpr:login:%s' % login, fpr)
|
||||
_add_to_result('fpr:email:%s' % mail, fpr)
|
||||
_add_to_result('email:fpr:%s' % fpr, mail)
|
||||
if uid:
|
||||
_add_to_result('name:fpr:%s' % fpr, uid)
|
||||
if email:
|
||||
_add_to_result('name:email:%s' % email, uid)
|
||||
if mail:
|
||||
_add_to_result('name:email:%s' % mail, uid)
|
||||
retcode = proc.wait()
|
||||
if retcode != 0:
|
||||
logging.error("subprocess ended with return code %d", retcode)
|
||||
|
|
Loading…
Reference in a new issue