barbushin / php-imap

Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP)
MIT License
1.65k stars 459 forks source link

How to avoid multiple/duplicate attachments dowload? #693

Open oioix opened 1 year ago

oioix commented 1 year ago

PHP IMAP version: 5.0.1 PHP Version: 8.1 Type of execution: CLI or Web Server

I want to dowload the attachments but not multiple times.

Current situation: The attachments file informations like filename, path, mime type, etc. is requestable with $mail->getAttachments() but -as I learned- only if $mailbox->ignoreAttachments() (or equivalent in the connection settings) is NOT set to false. The problem with this is, that if $mailbox->ignoreAttachments() is set to true all the attachment files are transferred from new at every single connection, even if I already stored them, which slows down performance. It looks like the ignoreAttachments option can not be used for the single emails whithin a request.

My questions: Is there a way to retrieve the attachment file information with $mail->getAttachments() BUT without the mandatory need to transfer the entire file? I know that I can use/not use fileToDisk() to control if the attachment gets saved on disk or not. But I would like to init the file-transfer between the Servers only, if the file is really needed for storage.

In short I would like to ... 1) ... get E-Mail including detail-informations about exisiting attachments (no file transfer of attachments yet) 2) ... only if detail-information leads to decision to dowload the attachments -> init file transfer and store the attachments

(edited since I could solve a part of my prior question already)