Skip to content

writing nested multipart messages does not work correctly #1525

Closed
@terencehonles

Description

Long story short

Write the following multipart message:

from aiohttp.multipart import MultipartWriter
with MultipartWriter('mixed') as root:
  with MultipartWriter('mixed') as subwriter1:
    subwriter1.append('first message')
  root.append(subwriter1)

  with MultipartWriter('mixed') as subwriter2:
    subwriter2.append('second message')
  root.append(subwriter2)

print(b''.join(root.serialize()).decode('ascii'))

Expected behaviour

--0d20b463316a462d839e93130150f5ef
Content-Type: multipart/mixed; boundary="05af9536a8374279a8bccc2ea099c82b"

--05af9536a8374279a8bccc2ea099c82b
Content-Type: text/plain; charset=utf-8
Content-Length: 13

first message
--05af9536a8374279a8bccc2ea099c82b--

--0d20b463316a462d839e93130150f5ef
Content-Type: multipart/mixed; boundary="1d4fdf1ddf8e46019da125c22c247649"

--1d4fdf1ddf8e46019da125c22c247649
Content-Type: text/plain; charset=utf-8
Content-Length: 14

second message
--1d4fdf1ddf8e46019da125c22c247649--

--0d20b463316a462d839e93130150f5ef--

Actual behaviour

--d3b608e9626a4f3cb2329fa01ebb1fce
Content-Type: application/octet-stream

--9310b9861e56425daf7ef0773fd2ae54
Content-Type: text/plain; charset=utf-8
Content-Length: 13

first message
--9310b9861e56425daf7ef0773fd2ae54--

--d3b608e9626a4f3cb2329fa01ebb1fce
Content-Type: application/octet-stream

--6fa9c511ee2d4a36bec615b15da6f1b2
Content-Type: text/plain; charset=utf-8
Content-Length: 14

second message
--6fa9c511ee2d4a36bec615b15da6f1b2--

--d3b608e9626a4f3cb2329fa01ebb1fce--

Steps to reproduce

Writer a nested multipart message as shown in the documentation.

"Fix": append(subwriter, headers=subwriter.headers)

I'll try to commit a patch, but just reporting the issue right now

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions