This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: In subject line email library inserts unwanted space after a thousands comma in a number
Type: behavior Stage: resolved
Components: email Versions: Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Matthew Jacobi, SegundoBob, ZackerySpytz, barry, medmunds, r.david.murray
Priority: normal Keywords:

Created on 2015-09-28 18:19 by SegundoBob, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (8)
msg251782 - (view) Author: Bob Hossley (SegundoBob) Date: 2015-09-28 18:19
In my function makeMsg(), there is:

    msg = email.mime.nonmultipart.MIMENonMultipart('text',
        'plain', charset='utf-8')
    msg['Subject'] = email.header.Header(subject, 'utf-8')

subject has no space after the thousands comma:

u'1,010 words - "The Blackmail Caucus, a.k.a. the Republican Party" By Paul Krugman'


But

msg['Subject'].__str__()

'1, 010 words - "The Blackmail Caucus,\n a.k.a. the Republican Party" By Paul Krugman'

has a space after the thousands comma and the email message later generated has a space after the thousands comma.

This is objectionable.

Note that the email library also inserts a newline after the comma that is followed by a space.  Since I see no effect of this newline on the email generated, I have no objection to the newline.
msg251788 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-09-28 19:06
This is fixed in Python3.  The fix was part of a large change to the header folding algorithm, and I'm not sure it is appropriate to backport it.  I'm guessing we would, though, if someone wants to do the work for the backport.  The relevant issue is issue 11492.
msg251799 - (view) Author: Bob Hossley (SegundoBob) Date: 2015-09-28 20:46
Thank you R. David Murray.

I look forward to being able to move my application to Python 3.
msg275296 - (view) Author: Matthew Jacobi (Matthew Jacobi) Date: 2016-09-09 09:47
Is there a workaround for this for people on python2? 
Would installing https://pypi.python.org/pypi/email/6.0.0a1 fix it?

> testing release of email6

> This is a standalone version of the version of email package that will ship with Python 3.3. This version can be installed and run under Python3.2. It is intended as a platform for testing the new code, but its final release should also be useable to get the features of the new package under Python 3.2.
msg275338 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-09-09 16:43
No, that is python3 code, it doesn't work on python2.  There's no workaround other than to back port the fix.
msg314544 - (view) Author: Mike Edmunds (medmunds) Date: 2018-03-27 18:30
Here's a workaround for Python 2.7:

```
class HeaderBugWorkaround(email.header.Header):
    def encode(self, splitchars=' ', **kwargs):  # only split on spaces, rather than splitchars=';, '
        return email.header.Header.encode(self, splitchars, **kwargs)

# and then...

msg['Subject'] = HeaderBugWorkaround(subject, 'utf-8', header_name='Subject')

```

(If you have the option, you're almost certainly better off moving to Python 3 for anything email related. But if you're maintaining code that has to be Python 2.7 compatible, this might help.)
msg314545 - (view) Author: Bob Hossley (SegundoBob) Date: 2018-03-27 18:43
Mike,

Thank you.

I moved to Python 3 some time ago.  I confirm that Python 3 does not
have the problem.  But I can't conveniently verify your workaround for
Python 2.

Regards,
Bob
bhossley@ieee.org

On 2018-03-27 11:30 AM, Mike Edmunds wrote:
> 
> Mike Edmunds <medmunds@gmail.com> added the comment:
> 
> Here's a workaround for Python 2.7:
> 
> ```
> class HeaderBugWorkaround(email.header.Header):
>     def encode(self, splitchars=' ', **kwargs):  # only split on spaces, rather than splitchars=';, '
>         return email.header.Header.encode(self, splitchars, **kwargs)
> 
> # and then...
> 
> msg['Subject'] = HeaderBugWorkaround(subject, 'utf-8', header_name='Subject')
> 
> ```
> 
> (If you have the option, you're almost certainly better off moving to Python 3 for anything email related. But if you're maintaining code that has to be Python 2.7 compatible, this might help.)
> 
> ----------
> nosy: +medmunds
> 
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue25257>
> _______________________________________
>
msg372180 - (view) Author: Zackery Spytz (ZackerySpytz) * (Python triager) Date: 2020-06-23 15:39
Python 2 is EOL, so I think this issue should be closed.
History
Date User Action Args
2022-04-11 14:58:21adminsetgithub: 69444
2020-06-23 15:58:21SilentGhostsetstatus: open -> closed
resolution: out of date
stage: resolved
2020-06-23 15:39:25ZackerySpytzsetnosy: + ZackerySpytz
messages: + msg372180
2018-03-27 18:43:40SegundoBobsetmessages: + msg314545
2018-03-27 18:30:07medmundssetnosy: + medmunds
messages: + msg314544
2016-09-09 16:43:02r.david.murraysetmessages: + msg275338
2016-09-09 09:47:10Matthew Jacobisetnosy: + Matthew Jacobi
messages: + msg275296
2015-09-28 20:46:19SegundoBobsetmessages: + msg251799
2015-09-28 19:06:16r.david.murraysetmessages: + msg251788
2015-09-28 18:19:52SegundoBobcreate