shashbha14 opened a new pull request, #65876:
URL: https://github.com/apache/airflow/pull/65876

   Closes #65870
   
   ## Problem
   
   `ImapHook.download_mail_attachments` silently overwrites existing files when 
a downloaded attachment shares the same filename as a file already present in 
the output directory. There is no way for callers to opt out of this behaviour.
   
   ## Change
   
   Added `overwrite: bool = True` parameter to `download_mail_attachments` (and 
the internal `_create_files` / `_create_file` helpers).
   
   - `overwrite=True` (default): existing behaviour is preserved — files are 
overwritten without warning. This keeps the change fully backward-compatible.
   - `overwrite=False`: if the target path already exists, a numeric counter 
suffix is appended (`report.csv` → `report_1.csv`, `report_2.csv`, …) until a 
free path is found.
   
   ## Tests
   
   Two unit tests added to `test_imap.py`:
   - `test_download_mail_attachments_overwrite_true_does_not_rename` — confirms 
that `overwrite=True` writes directly and never calls `os.path.exists`
   - `test_download_mail_attachments_no_overwrite_renames_file` — confirms that 
`overwrite=False` renames to the `_1` suffix when the file already exists
   
   ---
   
   > ⚠️ I used Claude (claude.ai) as an AI assistant to help identify the fix 
and generate the initial implementation. I reviewed, tested, and verified all 
changes myself before submitting.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to