Patchwork [08,of,10,STABLE] py3: use stdlib's parseaddr() to get sender header in notify extension

login
register
mail settings
Submitter Denis Laxalde
Date Oct. 24, 2019, 3:30 p.m.
Message ID <ea82b3a69f6ae2e83ecf.1571931039@steppe.local>
Download mbox | patch
Permalink /patch/42572/
State Accepted
Headers show

Comments

Denis Laxalde - Oct. 24, 2019, 3:30 p.m.
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1571924776 -7200
#      Thu Oct 24 15:46:16 2019 +0200
# Branch stable
# Node ID ea82b3a69f6ae2e83ecf905c4f9123a778d12f5e
# Parent  187e1e54ef5cf5a30ea690d69369876004aef443
py3: use stdlib's parseaddr() to get sender header in notify extension

In Python 3, email headers are unicode string so using
stringutil.email() will not work as it compares with bytestring. So
let's use email.utils.parseaddr() from the stdlib which has a consistent
behavior across Python versions. The same is done in patchbomb
extension already.

Patch

diff --git a/hgext/notify.py b/hgext/notify.py
--- a/hgext/notify.py
+++ b/hgext/notify.py
@@ -148,6 +148,7 @@  web.baseurl
 from __future__ import absolute_import
 
 import email.errors as emailerrors
+import email.utils as emailutils
 import fnmatch
 import hashlib
 import socket
@@ -450,7 +451,7 @@  class notifier(object):
             )
             mail.sendmail(
                 self.ui,
-                stringutil.email(msg[r'From']),
+                emailutils.parseaddr(msg[r'From'])[1],
                 subs,
                 msgtext,
                 mbox=self.mbox,