mirror of
https://github.com/andrewyng/openworker.git
synced 2026-09-03 04:49:26 +00:00
Fix attachment de-dup stripping real digits from the filename
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 commit is contained in:
@@ -555,7 +555,7 @@ def make_email_tools(
|
||||
while target.exists():
|
||||
target = (
|
||||
scratch.path
|
||||
/ f"{target.stem.rstrip('-0123456789') or 'attachment'}-{counter}{target.suffix}"
|
||||
/ f"{re.sub(r'-[0-9]+$', '', target.stem) or 'attachment'}-{counter}{target.suffix}"
|
||||
)
|
||||
counter += 1
|
||||
target.write_bytes(payload)
|
||||
|
||||
Reference in New Issue
Block a user