fix(mail): restore lost IMAP draft attachments when spool is empty#391
Open
tobias-weiss-ai-xr wants to merge 1 commit into
Open
fix(mail): restore lost IMAP draft attachments when spool is empty#391tobias-weiss-ai-xr wants to merge 1 commit into
tobias-weiss-ai-xr wants to merge 1 commit into
Conversation
When reopening a previously saved draft for editing, the MIME message during 'save' is generated by reading attachment files from the spool directory only. If the spool directory is empty (server restart, cache cleanup, or fresh editing session), bodyPartsForAllAttachments returns zero files and the draft is saved to IMAP without its attachments — silently losing them. This fix checks whether the spool has any attachment files before generating the MIME message. If it finds none and the draft has a valid IMAP4ID (was previously saved to IMAP), it downloads the attachments from the existing IMAP draft back into the spool directory via the existing _fetchAttachmentsFromMail:onlyImages: method, then retries the spool read. This ensures attachments are preserved across editing sessions. The fix only triggers when count == 0 (spool empty) and IMAP4ID > -1 (draft exists in IMAP), so it never affects new drafts or drafts with files already in spool. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When reopening a previously saved draft for editing and then saving again, attachments are silently lost. The MIME message during
[SOGoDraftObject save]is generated by reading attachment files from the spool directory viabodyPartsForAllAttachments→fetchAttachmentAttrs. If the spool is empty (server restart, cache cleanup, or a fresh editing session), the method returns zero files and the draft is saved to IMAP without any attachments.Root Cause
bodyPartsForAllAttachmentsonly reads from the spool directory on disk. It has no fallback to the existing IMAP message, which still holds the original attachment data. When the spool and IMAP are out of sync, attachments are silently dropped during MIME generation.Fix
Added a guard at the beginning of
bodyPartsForAllAttachmentsinSoObjects/Mailer/SOGoDraftObject.m:fetchAttachmentAttrsreturns 0 files (count == 0), AND the draft has a validIMAP4ID > -1(was previously saved to IMAP)...SOGoMailObjectfrom the existing IMAP message, download all its attachments to the spool directory via the existing_fetchAttachmentsFromMail:onlyImages:method, then re-read the spool.This ensures attachments are restored from IMAP before MIME generation, without affecting new drafts or drafts that already have files in spool.
Impact
IMAP4ID == -1)count > 0)See #6046 for related draft attachment handling.