Skip to content

Provide callers a way to write directly to tmp/ - #46

Merged
staktrace merged 1 commit into
staktrace:masterfrom
jmibanez:feature/caller-write-to-tmp-direct
Aug 2, 2026
Merged

Provide callers a way to write directly to tmp/#46
staktrace merged 1 commit into
staktrace:masterfrom
jmibanez:feature/caller-write-to-tmp-direct

Conversation

@jmibanez

Copy link
Copy Markdown
Contributor

Some callers may want to stream bytes into a new mail file directly vs. buffering the entire message blob in memory. To do so, provide a way to return a handle to a file in the maildir tmp/ while allowing cleanup when the handle goes out of scope if it hasn't been renamed into cur/ or new/.

Some callers may want to stream bytes into a new mail file directly
vs. buffering the entire message blob in memory. To do so, provide a
way to return a handle to a file in the maildir tmp/ while allowing
cleanup when the handle goes out of scope if it hasn't been renamed
into cur/ or new/.
@jmibanez
jmibanez force-pushed the feature/caller-write-to-tmp-direct branch from 5fc859d to 224f4d4 Compare May 20, 2026 18:03
@staktrace

Copy link
Copy Markdown
Owner

Based on your stated intent of allowing callers to stream bytes, I made an alternate PR at #48. Would that solve your problem? The idea is that you pass in a Read impl which can provide the bytes on-demand instead of having to buffer them in memory.

@jmibanez

jmibanez commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Unfortunately, that doesn't work for my use case. I'm async, and I have to stream HTTP chunks from an async Stream, so I don't have a single Read object that I can pass in. For me to use #48, I'd have to spin up a separate thread to basically feed between the async source and a Read pipe I hand to e.g. store_new_read(), whereas with the TemporaryMailFile I'm proposing I can simply write_all() each chunk to disk immediately as it arrives.

Additionally, the TemporaryMailFile abstraction does match the whole purpose of having the tmp/ directory in a maildir, and in fact IIRC is why the spec requires it, so that mail arrives "atomically": we can stream bytes to disk first, and then make the mail visible to MUAs by moving it to cur/new when done with a move_tmp_to_{new, cur}() call.

The Read API you propose though is good for callers who already hold a blocking byte source, so it's probably orthogonal to my proposal.

@staktrace

Copy link
Copy Markdown
Owner

Ok, sorry for the delay. After looking at this again I think it's a good addition. Merging!

@staktrace
staktrace merged commit e56ac40 into staktrace:master Aug 2, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants