Bug#849586: reportbug incorrectly short-circuits From address escaping with non-ASCII characters

2017-01-04 Thread Sandro Tosi
control: forcemerge 848692 -1


On Wed, Dec 28, 2016 at 5:53 PM, Russ Allbery  wrote:
>
> if re.match(r'[\w\s]+$', realname):
> return '%s <%s>' % (realname, email)
>
> addr = email.utils.formataddr((realname, email))
>
> I suspect this worked fine in Python 2, since this regex doesn't use
> the UNICODE flag.  However, in Python 3, I believe regexes are str
> types by default and therefore Unicode by default, so this will match
> non-ASCII characters, short-circuit this logic, and never call
> formataddr.
>
> I'm not sure the original motivation for the short-circuit here, but
> I suspect just removing the re.match conditional and unconditionally
> calling email.utils.formataddr will produce the correct behavior.

i just did exactly that as part of 848692 (hence the merge)


-- 
Sandro "morph" Tosi
My website: http://sandrotosi.me/
Me at Debian: http://wiki.debian.org/SandroTosi
G+: https://plus.google.com/u/0/+SandroTosi



Bug#849586: reportbug incorrectly short-circuits From address escaping with non-ASCII characters

2017-01-03 Thread Frédéric Brière
On Wed, Dec 28, 2016 at 02:53:17PM -0800, Russ Allbery wrote:
> According to a thread on debian-devel, reportbug generated a From header
> looking like:
> 
> From: =?utf-8?b?VG9tYXMgTWFydGnFoWl1cyA8dG9tYXNAcHVnYS52ZHUubHQ+?=

I was also bitten by this bug this morning.  Thank you for the bug
report; this spared me quite a bit of head-scratching.

> addr = email.utils.formataddr((realname, email))
> 
> I suspect just removing the re.match conditional and unconditionally
> calling email.utils.formataddr will produce the correct behavior.

You might run into a conflict over the "email" name, though:

  addr = email.utils.formataddr((realname, email))
  AttributeError: 'str' object has no attribute 'utils'

Other than that, your fix seems to do the trick for me:

  >>> import reportbug.utils
  >>> reportbug.utils.get_user_id()
  '=?utf-8?b?RnLDqWTDqXJpYyBCcmnDqHJl?= '

Thanks!



Bug#849586: reportbug incorrectly short-circuits From address escaping with non-ASCII characters

2016-12-28 Thread Russ Allbery
Package: reportbug
Version: 7.1.1
Severity: important

According to a thread on debian-devel, reportbug generated a From header
looking like:

From: =?utf-8?b?VG9tYXMgTWFydGnFoWl1cyA8dG9tYXNAcHVnYS52ZHUubHQ+?=

I believe the problem may have been introduced in the Python 3 port.
reportbug.utils.get_user_id contains the following code, which knows
about correct From header formatting using email.utils.formataddr:

if re.match(r'[\w\s]+$', realname):
return '%s <%s>' % (realname, email)

addr = email.utils.formataddr((realname, email))

I suspect this worked fine in Python 2, since this regex doesn't use
the UNICODE flag.  However, in Python 3, I believe regexes are str
types by default and therefore Unicode by default, so this will match
non-ASCII characters, short-circuit this logic, and never call
formataddr.

I'm not sure the original motivation for the short-circuit here, but
I suspect just removing the re.match conditional and unconditionally
calling email.utils.formataddr will produce the correct behavior.

-- Package-specific info:
** Environment settings:
EDITOR="vi"
PAGER="less"
VISUAL="vi"
DEBEMAIL="r...@debian.org"
DEBFULLNAME="Russ Allbery"
INTERFACE="text"

** /home/eagle/.reportbugrc:
reportbug_version "6.4.4"
mode expert
ui text
no-cc
header "X-Debbugs-CC: r...@debian.org"
smtphost reportbug.debian.org

-- System Information:
Debian Release: stretch/sid
  APT prefers unstable
  APT policy: (990, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.8.0-2-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages reportbug depends on:
ii  apt1.4~beta2
ii  python3-reportbug  7.1.1
pn  python3:any

reportbug recommends no packages.

Versions of packages reportbug suggests:
pn  claws-mail  
ii  debconf-utils   1.5.59
pn  debsums 
pn  dlocate 
ii  emacs24-bin-common  24.5+1-7.1
ii  file1:5.29-2
ii  gir1.2-gtk-3.0  3.22.5-1
pn  gir1.2-vte-2.91 
ii  gnupg   2.1.17-2
ii  postfix [mail-transport-agent]  3.1.3-6
ii  python3-gi  3.22.0-2
pn  python3-gtkspellcheck   
pn  python3-urwid   
ii  xdg-utils   1.1.1-1

-- no debconf information