php-imap
php-imap copied to clipboard
Flags collection is empty
I fetch only unseen messages with the following fetch option. Messages are marked as seen in the mail client, but the flags collection of the message instance is empty. Is this behaviour intended? I use the current version.
Used config
'options' => [
'fetch' => \Webklex\PHPIMAP\IMAP::FT_UID,
],
Hi @chWagnr , thanks for your report.
Please provide a bit more information such as:
- Used config
- Code to Reproduce
- A clear and concise description of what you expected to happen.
- Used software versions
- Any other context about the problem
Best regards,
Hi @Webklex , sorry for my less informative post. I hope this will be better:
I use this package with the Laravel wrapper webklex/laravel-imap.
My config:
return [
'default' => env('IMAP_DEFAULT_ACCOUNT', 'default'),
'date_format' => 'd-M-Y',
'accounts' => [
'default' => [// account identifier
'host' => env('IMAP_HOST', 'localhost'),
'port' => env('IMAP_PORT', 993),
'protocol' => env('IMAP_PROTOCOL', 'imap'), //might also use imap, [pop3 or nntp (untested)]
'encryption' => env('IMAP_ENCRYPTION', 'ssl'), // Supported: false, 'ssl', 'tls', 'notls', 'starttls'
'validate_cert' => env('IMAP_VALIDATE_CERT', true),
'username' => env('IMAP_USERNAME', '[email protected]'),
'password' => env('IMAP_PASSWORD', ''),
'authentication' => env('IMAP_AUTHENTICATION', null),
'proxy' => [
'socket' => null,
'request_fulluri' => false,
'username' => null,
'password' => null,
],
],
],
'options' => [
'delimiter' => '/',
'fetch' => \Webklex\PHPIMAP\IMAP::FT_UID,
'sequence' => \Webklex\PHPIMAP\IMAP::ST_MSGN,
'fetch_body' => true,
'fetch_attachment' => true,
'fetch_flags' => true,
'message_key' => 'list',
'fetch_order' => 'asc',
'dispositions' => ['attachment', 'inline'],
'common_folders' => [
'root' => 'INBOX',
'junk' => 'INBOX/Junk',
'draft' => 'INBOX/Drafts',
'sent' => 'INBOX/Sent',
'trash' => 'INBOX/Trash',
],
'open' => [
// 'DISABLE_AUTHENTICATOR' => 'PLAIN'
],
'decoder' => [
'message' => 'utf-8', // mimeheader
'attachment' => 'utf-8', // mimeheader
],
],
'events' => [
'message' => [
'new' => \Webklex\IMAP\Events\MessageNewEvent::class,
'moved' => \Webklex\IMAP\Events\MessageMovedEvent::class,
'copied' => \Webklex\IMAP\Events\MessageCopiedEvent::class,
'deleted' => \Webklex\IMAP\Events\MessageDeletedEvent::class,
'restored' => \Webklex\IMAP\Events\MessageRestoredEvent::class,
],
'folder' => [
'new' => \Webklex\IMAP\Events\FolderNewEvent::class,
'moved' => \Webklex\IMAP\Events\FolderMovedEvent::class,
'deleted' => \Webklex\IMAP\Events\FolderDeletedEvent::class,
],
'flag' => [
'new' => \Webklex\IMAP\Events\FlagNewEvent::class,
'deleted' => \Webklex\IMAP\Events\FlagDeletedEvent::class,
],
],
'masks' => [
'message' => \Webklex\PHPIMAP\Support\Masks\MessageMask::class,
'attachment' => \Webklex\PHPIMAP\Support\Masks\AttachmentMask::class,
],
];
My code:
$client = Client::account();
$client->connect();
$inbox = $client->getFolder('INBOX');
$mails = $inbox->messages()->unseen()->limit(1)->get();
dd($mails->first()->getFlags());
As you can see, I just want the next unseen message. With the fetch option IMAP::FT_UID the message will automatically set as seen. In my email clients the message is flagged as seen. The FlagCollection in the code above is empty. Shouldn't it contain the seen flag? Am I wrong? I can remember in a previous version the seen flag was in the collection.
Output of the dd()
Webklex\PHPIMAP\Support\FlagCollection {#1541 ▼
#total: null
#items: []
}
I use
- php-imap v2.4.4
- laravel-imap v2.4.0
- PHP 7.4.11
- laravel/framework v8.25.0
Best regards
Hi @chWagnr , thank you very much for the awesome report :)
Please try to update two config parameters:
- set
options.fetchto\Webklex\PHPIMAP\IMAP::FT_PEEK - (optional) set
options.sequenceto\Webklex\PHPIMAP\IMAP::ST_UID
Best regards,
Hi @Webklex , thanks for your reply. I changed the config parameters as mentioned but sadly it didn't work.
$inbox->getStatus() returns
{
"flags": [
[
"\\Answered",
"\\Flagged",
"\\Deleted",
"\\Seen",
"\\Draft",
"nonjunk",
"$Forwarded"
]
],
"exists": "54",
"recent": "0",
"uidvalidity": 1606405297,
"uidnext": 55
}
But Message::getFlags() is still empty.
Best regards
Please update to v5.1 and give it another try. If you are currently using an older version below v5.0, please read the breaking changes leading up to v5.1 before upgrading.
Best regards,