Fix attachment de-dup stripping real digits from the filename#214
Open
Osamaali313 wants to merge 1 commit into
Open
Fix attachment de-dup stripping real digits from the filename#214Osamaali313 wants to merge 1 commit into
Osamaali313 wants to merge 1 commit into
Conversation
The collision-rename loop in email_download_attachment used
`target.stem.rstrip('-0123456789')`, which strips every trailing digit and
dash, not just a previously-appended `-N` suffix. So saving a second
`invoice_2024.pdf` produced `invoice_-1.pdf`, `IMG_20240115.jpg` became
`IMG_-1.jpg`, and Outlook's `image001.png` became `image-1.png`.
Strip only a trailing `-<number>` suffix with a regex, preserving the
original digits (and still incrementing correctly on repeated collisions).
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.
What
email_download_attachmentcorrupts the filename when it de-duplicates a name collision. The rename loop:str.rstrip('-0123456789')removes every trailing digit/dash, including digits that are part of the real name. It was only meant to strip a previously-appended-Nsuffix before adding the next one.Why it matters
Downloading two attachments with the same digit-ending name into one session folder mangles the filename:
invoice_2024.pdfinvoice_-1.pdfinvoice_2024-1.pdfIMG_20240115.jpgIMG_-1.jpgIMG_20240115-1.jpgimage001.png(Outlook auto-name)image-1.pngimage001-1.pngreport.pdf(no digits)report-1.pdfreport-1.pdfThe wrong name is written to disk and returned as
pathin the tool result.How
Strip only a trailing
-<number>suffix:reis already imported. Verified this preserves the original digits and still increments correctly on repeated collisions (invoice_2024.pdf→invoice_2024-1.pdf→invoice_2024-2.pdf). Names without a trailing-Nare unchanged.