Skip to content

bug/partition_signed_emails #3922

Closed

Description

@anotherthomas

testcase.txt

Describe the bug
I'm trying to partition emails. In some cases, the processing results in a KeyError: 'multipart/mixed'

>>> from unstructured.partition.email import partition_email
>>> partition_email("testcase.txt")

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/app/unstructured/partition/email.py", line 73, in partition_email
    return list(_EmailPartitioner.iter_elements(ctx=ctx))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/unstructured/partition/email.py", line 333, in _iter_elements
    yield from _AttachmentPartitioner.iter_elements(attachment, self._ctx)
  File "/app/unstructured/partition/email.py", line 388, in _iter_elements
    file = io.BytesIO(self._file_bytes)
                      ^^^^^^^^^^^^^^^^
  File "/app/unstructured/utils.py", line 154, in __get__
    value = self._fget(obj)
            ^^^^^^^^^^^^^^^
  File "/app/unstructured/partition/email.py", line 423, in _file_bytes
    content = self._attachment.get_content()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/email/message.py", line 1124, in get_content
    return content_manager.get_content(self, *args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/email/contentmanager.py", line 25, in get_content
    raise KeyError(content_type)
KeyError: 'multipart/mixed'

To Reproduce
The easiest way to reproduce the behavior for me is to try to partition a PGP signed but not encrypted email. I have attached an anonymized example.

Expected behavior
I expect the email to be parsed and partitioned into its parts.

Environment Info
docker image downloads.unstructured.io/unstructured-io/unstructured:0.16.20, also :0.15.14 and :latest

Additional context
Add any other context about the problem here.

Activity

  1. mittalpk commented on Aug 2, 2026

    @mittalpk
    Contributor

    Hi, I'd like to work on this. Root cause: email.contentmanager has no handler registered for any multipart/* content-type, so _file_bytes (unstructured/partition/email.py) raises KeyError when get_content() is called on a nested multipart sub-part (e.g. the PGP-signed attachment in the linked testcase) — and that error isn't caught, since it happens before the try/except meant to skip bad attachments, and KeyError isn't in EXPECTED_ATTACHMENT_ERRORS. Will open a PR shortly.

  2. added a commit that references this issue on Aug 7, 2026
    fe1517d
  3. added a commit that references this issue on Aug 15, 2026
    a18d771
  4. added a commit that references this issue on Oct 15, 2026
    911083b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions