apache/airflow

IMAP hook silently overwrites attachments with identical filenames

Open

#65,870 建立於 2026年4月26日

在 GitHub 查看
 (1 留言) (0 反應) (0 負責人)Python (44,809 star) (16,781 fork)batch import
area:providersgood first issuekind:bugprovider:imap

描述

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

  1. Receive multiple emails with attachments sharing the same filename (e.g. report.xlsx)
  2. Call imap_hook.download_mail_attachments
  3. Inspect the output directory
  4. 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

貢獻者指南