diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2023-01-19 14:06:44 -0500 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2023-01-19 14:06:44 -0500 |
commit | 0305b5cb8a115c0fcaebc0ff7d7406c29ce7f41e (patch) | |
tree | e6274faa57e69c2b2226b2cfe511885124c4f211 | |
parent | f2ef36c93d8edbc993e83caca10aeca95987f184 (diff) | |
download | b4-0305b5cb8a115c0fcaebc0ff7d7406c29ce7f41e.tar.gz |
Improve compatibility for name quoting in addresses
Use actual list of special characters that require quoting in the name
part of name <address> pairs.
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r-- | b4/__init__.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/b4/__init__.py b/b4/__init__.py index 428a8eb..e1b88fc 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -40,6 +40,10 @@ charset.add_charset('utf-8', None) # Policy we use for saving mail locally emlpolicy = email.policy.EmailPolicy(utf8=True, cte_type='8bit', max_line_length=None) +# Presence of these characters requires quoting of the name in the header +# adapted from email._parseaddr +qspecials = re.compile(r'[()<>@,:;.\"\[\]]') + try: import dkim can_dkim = True @@ -2968,8 +2972,9 @@ def format_addrs(pairs, clean=True): # Remove any quoted-printable header junk from the name pair = (LoreMessage.clean_header(pair[0]), pair[1]) # Work around https://github.com/python/cpython/issues/100900 - if not pair[0].startswith('=?') and not pair[0].startswith('"') and re.search(r'[^\w\s]', pair[0]): - addrs.append(f'"{pair[0]}" <{pair[1]}>') + if not pair[0].startswith('=?') and not pair[0].startswith('"') and qspecials.search(pair[0]): + quoted = email.utils.quote(pair[0]) + addrs.append(f'"{quoted}" <{pair[1]}>') continue addrs.append(email.utils.formataddr(pair)) return ', '.join(addrs) |