IMAP hook silently overwrites attachments with identical filenames
#65870 opened on Apr 26, 2026
Description
Under which category would you file this issue?
Providers
Apache Airflow version
3.2.1
What happened and how to reproduce it?
Problem
When using imap_hook.download_mail_attachments, attachments with identical filenames are saved to disk using the same name, which leads to silent overwriting of previously downloaded files.
This results in data loss without any warning, and there is currently no option to control this behavior.
How to reproduce
- Receive multiple emails with attachments sharing the same filename (e.g. report.xlsx)
- Call imap_hook.download_mail_attachments
- Inspect the output directory
- Observe that only one file is present, as earlier files were overwritten
What you think should happen instead?
There should be a configurable way to control how filename collisions are handled when saving attachments, for example:
- either allow overwriting existing files
- or preserve all files by automatically renaming them.
The current behavior should not be hardcoded without user control.
Possible improvement
Introduce a configurable parameter (e.g. overwrite_file or similar) that controls collision handling behavior:
- overwrite_file=True → overwrite existing files (current behavior)
- overwrite_file=False → preserve all files
This would make the behavior explicit and safe for different use cases.
Operating System
No response
Deployment
Official Apache Airflow Helm Chart
Apache Airflow Provider(s)
imap
Versions of Apache Airflow Providers
apache-airflow-providers-imap==3.11.0
Official Helm Chart version
Not Applicable
Kubernetes Version
No response
Helm Chart configuration
No response
Docker Image customizations
No response
Anything else?
A previous implementation attempt and discussion can be found here:
https://github.com/apache/airflow/pull/62321
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct