@@ -834,6 +834,30 @@ public function markMailsAsImportant(array $mailId): void
834834 $ this ->setFlag ($ mailId , '\\Flagged ' );
835835 }
836836
837+ /**
838+ * Check, if the specified flag for the mail is set or not.
839+ *
840+ * @param int $mailsId A single mail ID
841+ * @param string $flag Which you can get are \Seen, \Answered, \Flagged, \Deleted, and \Draft as defined by RFC2060
842+ *
843+ * @return bool True, when the flag is set, false when not
844+ *
845+ * @psalm-param list<int> $mailId
846+ */
847+ public function flagIsSet (int $ mailId , string $ flag ): bool
848+ {
849+ $ flag = str_replace ('\\' , '' , strtolower ($ flag ));
850+
851+ $ overview = Imap::fetch_overview ($ this ->getImapStream (), $ mailId , ST_UID );
852+
853+ if ($ overview [0 ]->$ flag == 1 )
854+ {
855+ return true ;
856+ }
857+
858+ return false ;
859+ }
860+
837861 /**
838862 * Causes a store to add the specified flag to the flags set for the mails in the specified sequence.
839863 *
@@ -1141,7 +1165,12 @@ public function getMailHeader(int $mailId): IncomingMailHeader
11411165 $ header ->id = $ mailId ;
11421166 $ header ->imapPath = $ this ->imapPath ;
11431167 $ header ->mailboxFolder = $ this ->mailboxFolder ;
1144- $ header ->isDraft = (!isset ($ head ->date )) ? true : false ;
1168+ $ header ->isSeen = ($ this ->flagIsSet ($ mailId , '\Seen ' )) ? true : false ;
1169+ $ header ->isAnswered = ($ this ->flagIsSet ($ mailId , '\Answered ' )) ? true : false ;
1170+ $ header ->isRecent = ($ this ->flagIsSet ($ mailId , '\Recent ' )) ? true : false ;
1171+ $ header ->isFlagged = ($ this ->flagIsSet ($ mailId , '\Flagged ' )) ? true : false ;
1172+ $ header ->isDeleted = ($ this ->flagIsSet ($ mailId , '\Deleted ' )) ? true : false ;
1173+ $ header ->isDraft = ($ this ->flagIsSet ($ mailId , '\Draft ' )) ? true : false ;
11451174 $ header ->mimeVersion = $ this ->getMailHeaderFieldValue ($ headersRaw , 'MIME-Version ' );
11461175 $ header ->xVirusScanned = $ this ->getMailHeaderFieldValue ($ headersRaw , 'X-Virus-Scanned ' );
11471176 $ header ->organization = $ this ->getMailHeaderFieldValue ($ headersRaw , 'Organization ' );
0 commit comments