New submission from Guillaume Gauvrit <guilla...@gauvr.it>:

I am currently refactoring code and use the EmailMessage api
to build message.

I encountered weird behavior while building an email.
The `as_string()` method is fixing the `make_alternative` method.

So, to me their is two bug here: a `as_string` method should not mutate 
internal state,
and the `make_alternative` should create a correct internal state.


It may be resume in the following program:


```
𝝿 python
Python 3.8.3 (default, May 17 2020, 18:15:42)
[GCC 10.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import email
>>> from email.message import EmailMessage, MIMEPart
>>>
>>> msg = EmailMessage()
>>> msg.make_alternative()
>>> print(msg.get_boundary())
None
>>> print(msg._headers)
[('Content-Type', 'multipart/alternative')]
>>> _ = msg.as_string()
>>> print(msg.get_boundary())
===============3171625413581695247==
>>> print(msg._headers)
[('Content-Type', 'multipart/alternative; 
boundary="===============3171625413581695247=="')]
```

----------
files: bug.py
messages: 372508
nosy: mardiros
priority: normal
severity: normal
status: open
title: EmailMessage.as_string is altering the message state and actually fix 
bugs
type: resource usage
versions: Python 3.7, Python 3.8
Added file: https://bugs.python.org/file49271/bug.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41145>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to