vaefremov95 opened a new issue, #65871:
URL: https://github.com/apache/airflow/issues/65871

   ### Under which category would you file this issue?
   
   Providers
   
   ### Apache Airflow version
   
   3.2.1
   
   ### What happened and how to reproduce it?
   
   **Problem**
   
   When retrieving email attachments using the IMAP hook, filenames containing 
non-ASCII characters (e.g. Cyrillic) are not properly decoded.
   
   As a result, attachment filenames are returned in encoded MIME format (e.g. 
RFC 2047 encoded words), instead of properly decoded Unicode strings.
   
   **Example** 
   _Found attachment: =
   
?UTF-8?B?0J/QtdGA0LXRh9C10L3RjCDRgtC+0YfQtdC6INC/0YDQvtC00LDQtl8yMDI2LTA0LTIxLnhsc3g=?=_
   
   Expected:
   Перечень точек продаж_2026-04-21.xlsx
   
   This makes it difficult to correctly filter or identify files by name.
   
   To work around this limitation, it is necessary to:
   
   1. Retrieve all attachments using a broad pattern (e.g. name='(.*)')
   2. Manually decode filenames using decode_header
   3. Reconstruct UTF-8 strings manually
   4. Then apply filtering logic on decoded names
   
   Example workaround:
   ```
   files = imap_hook.retrieve_mail_attachments(name='(.*)')
   
   for file in files:
       raw_filename = file[0]
       parts = decode_header(raw_filename)
   
       decoded_filename = "".join(
           p.decode(enc or "utf-8") if isinstance(p, bytes) else p
           for p, enc in parts
       )
   
       if decoded_filename.endswith('.xlsx') and 'Перечень точек продаж' in 
decoded_filename:
           ...
   ```
   
   This issue significantly complicates working with real-world email data, 
especially in environments where:
   
   - filenames are localized (Cyrillic / non-Latin scripts)
   - attachments are generated by external systems (banks, ERP, reporting tools)
   - filtering by filename is required for pipeline logic
   
   ### What you think should happen instead?
   
   Attachment filenames should be automatically and correctly decoded into 
Unicode strings when retrieved from IMAP, including support for:
   
   - Cyrillic characters
   - other non-ASCII encodings (RFC 2047 / MIME encoded words)
   
   This would allow users to directly filter attachments by filename without 
manual decoding logic.
   
   ### 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?
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
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