Skip to content

Commit c5e199a

Browse files
author
Sebastian Krätzig
committed
#529: Add email flags as properties
1 parent 6332a9c commit c5e199a

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/PhpImap/IncomingMailHeader.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ class IncomingMailHeader
2020
/** @var string|null */
2121
public $mailboxFolder;
2222

23+
/** @var bool */
24+
public $isSeen = false;
25+
26+
/** @var bool */
27+
public $isAnswered = false;
28+
29+
/** @var bool */
30+
public $isRecent = false;
31+
32+
/** @var bool */
33+
public $isFlagged = false;
34+
35+
/** @var bool */
36+
public $isDeleted = false;
37+
2338
/** @var bool */
2439
public $isDraft = false;
2540

src/PhpImap/Mailbox.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)