php-imap
php-imap copied to clipboard
Get Message without Attachments
Is your feature request related to a problem? Please describe. To improve the retrieval of the message list, it would be useful to have a function to retrieve the message without attachments. And retrieve attachments only if necessary. In the first place, one only needs the body
Describe the solution you'd like A getMessageNoAttachments methods
Hi @epocci , many thanks for the suggestion. Unfortunately that isn't possible. Attachments are part of the message body itself and therefor can't be fetched separately. However you can currently fetch messages without a body, but depending on your use-case this might not be an option for you.
Best regards & happy coding,
i read and test that if i send command BODY.PEEK[TEXT] if possibile. but if i call command like this: $result = $this->fetch(["BODY.PEEK[TEXT]"], $uids, null, $uid); in debug i see only body part Text return by stream, but the $result variable in empty. So fetch not parse response, but i don't be able to modify fetch for reading response. Also with command bodystructure we can read structure of message without download all, and with this we can read with PEEK[1.2] for example part 1 subpart 2.
Hi @epocci ,
I'm sorry, but I don't understand what you are asking. Are you looking for PEEK support? It's currently not supported - at least not directly. You are right, you can always use ImapProtocol::fetch()
to fetch what ever you want. If the entered command doesn't work, perhaps the provider doesn't support it?
Please feel free to create a pull request if you want to add peek support.
Best regards & happy coding,
P.s.: I'm not sure how BODY.PEEK[TEXT]
operates and whats excluded / included. E.g. how are inline attachments handled or html / encoded texts? What are the limitations?
one way to achieve what you asking @epocci if you are trying to optimize for processing via laravel queues.
$message->setAttachments($message->attachments()->transform(
function (Attachment $attachment) use ($message) {
$storagePath = sprintf(config('mailhandler.storage_dir'), $this->mailJob->id) . DIRECTORY_SEPARATOR . $filename;
Storage::setVisibility($storagePath, 'private');
$fileSaveStatus = Storage::put($storagePath, $attachment->getContent());
if ($fileSaveStatus) {
Log::info('file saved at path: ' . $storagePath);
// NOTE: we set the content of the file to blank so that we don't need to pass
// it around after files were saved to disk
$attachment->setContent('');
} else {
Log::info('unable to save file at path: ' . $storagePath);
}
return $attachment;
}));
My request was to speed up the download of the emails with a preview of the text, but without downloading the whole message. I don't have a saving problem. The php standard did this, but since I don't have outh2, I can't use it anymore.