From 330e12131e499cd8f9c2ea6215fd6d0fb687e3ed Mon Sep 17 00:00:00 2001 From: Osamaali313 Date: Sun, 26 Jul 2026 23:40:00 +0300 Subject: [PATCH] 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 `-` suffix with a regex, preserving the original digits (and still incrementing correctly on repeated collisions). --- coworker/connectors/email_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coworker/connectors/email_tools.py b/coworker/connectors/email_tools.py index 3682b1da..7be4e1f9 100644 --- a/coworker/connectors/email_tools.py +++ b/coworker/connectors/email_tools.py @@ -555,7 +555,7 @@ def email_download_attachment( 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)