0

I am using Laravel-imap package (https://github.com/Webklex/laravel-imap) to fetch emails using imap.

I'm able to make a successful connection, able to fetch folders and emails, all set in that part.

However, I need to ignore drafted emails but I'm not able to detect that if a message is draft using code because email objects seem to have similar properties. I am testing using my Gmail account imap settings.

Here is the code I'm using. Any kind of help would be appreciated. Thanks

$oClient->connect();

$aFolder = $oClient->getFolders();

foreach($aFolder as $oFolder){
    $aMessage = $oFolder->messages()->all()->get();
    
    /** @var \Webklex\IMAP\Message $oMessage */
    foreach($aMessage as $oMessage){
        print_r($oMessage);
    }
}
Sims
  • 51
  • 6
  • Having a look through the manual stuff, there seems to be something in the headers, have a look at [`imap_headerinfo()`](https://www.php.net/manual/en/function.imap-headerinfo.php). You may have to run it and see if the draft flag appears and then perhaps ask if you find it difficult to reliably extract it (with an example of the output). – Nigel Ren Jun 26 '20 at 07:03
  • @NigelRen right, as mentioned in the documentation it should return some flags. however Draft flag is coming '' in both cases. here is the output. When Inbox: `["Draft"]=> string(1) " "` and in case of Draft: `["Draft"]=> string(1) " "` – Sims Jun 26 '20 at 07:44
  • For most clients, Drafts is just a folder that conventionally contains drafts. Skip over the folder. If your server supports IMAP Special Use extension, it is the _folder_ marked \Drafts. Otherwise you have to guess based on the name. The message flag \Draft is rarely used. – Max Jun 26 '20 at 13:44

0 Answers0