email.utils.formataddr does not respect double spaces · Issue #91400 · python/cpython (original) (raw)

It seems that email.utils.formataddr and email.utils.parseaddr are not directly inverse from each other, because formataddr does not respect double spaces within the "realname" section.

from email.utils import formataddr, parseaddr

identity = '"foo  bar" <foo@example.com>'

print(formataddr(parseaddr(identity)))
# 'foo  bar <foo@example.com>'

print(formataddr(parseaddr(formataddr(parseaddr(identity)))))
# 'foo bar <foo@example.com>'

The first round trip strips the quotes, and the second round trip strips the double space in the "realname" section.

The utility function only seems to check for special characters, but it should also check for double spaces.