bug: partition_email() raises io.UnsupportedOperation on a file-like object that cannot seek

Open Beginner friendly
#4,864 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 6 days

@Bensonluo is already working on this.

Since Nov 26, 2026.

  • #4866 by @Bensonluo — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Read unstructured/partition/email.py, especially EmailPartitioningContext._validate() and the msg property, then compare how partition_json() and partition_ndjson() handle non-seekable streams as described in #4643 and #4649. Reproduce with a readable pipe or another non-seekable file-like object and compare its output with io.BytesIO containing the same email bytes. Done when partition_email(file=...) returns the same elements for both inputs.

Written by the indexing model from the issue text.

Description

Describe the bug

partition_email(file=...) raises io.UnsupportedOperation: File or stream is not seekable. when the file-like object is readable but cannot seek back, such as the read end of a pipe. An unbuffered handle (open(fd, "rb", buffering=0)) fails the same way with OSError: [Errno 29] Illegal seek.

EmailPartitioningContext._validate() rewinds file unconditionally with self._file.seek(0) (unstructured/partition/email.py), before the message is parsed. The partitioner reads the message once after that (self._file.read() in the msg property), so the rewind is the only thing such a stream cannot provide.

The sibling partitioners accept the same kind of stream when called directly: partition_text(), partition_html() and partition_xml() read it as it stands, partition_json() / partition_ndjson() skip the rewind for a stream that reports seekable() as False (#4643, fixed by #4649), and partition_tsv() copies it once to a temporary file.

To Reproduce

import io
import os

from unstructured.partition.email import partition_email

with open("example-docs/eml/fake-email.eml", "rb") as f:
    eml_bytes = f.read()

reader_fd, writer_fd = os.pipe()
with os.fdopen(writer_fd, "wb") as writer:
    writer.write(eml_bytes)

with os.fdopen(reader_fd, "rb") as reader:
    print(partition_email(file=reader))
    # io.UnsupportedOperation: File or stream is not seekable.

print(partition_email(file=io.BytesIO(eml_bytes)))  # the same bytes, seekable: works

Expected behavior

partition_email(file=...) partitions a stream that cannot seek the way the sibling partitioners do, returning the same elements as the same bytes read from a seekable object.

Environment Info

  • unstructured 0.27.38 (main at 2653935)
  • Python 3.12, macOS arm64

Additional context

This report is about calling partition_email(file=...) directly. #4677 describes the same error on the generic partition(file=...) entry point, where it comes from file-type detection; #4678 addresses that path.

Dominant language
HTML
Stars
15.8k
Forks
1.4k
Avg merge
8d 4h
Merged PRs (30d)
40

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Unstructured-IO/unstructured

All issues in Unstructured-IO/unstructured

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.