Skip to content

Commit 487ddd2

Browse files
committed
Flag collection added
1 parent ad12170 commit 487ddd2

File tree

2 files changed

+48
-22
lines changed

2 files changed

+48
-22
lines changed

src/IMAP/Message.php

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use Carbon\Carbon;
1616
use Webklex\IMAP\Support\AttachmentCollection;
17+
use Webklex\IMAP\Support\FlagCollection;
1718

1819
/**
1920
* Class Message
@@ -111,16 +112,17 @@ class Message {
111112
public $reply_to = [];
112113
public $in_reply_to = '';
113114
public $sender = [];
114-
public $flags = [];
115115

116116
/**
117117
* Message body components
118118
*
119119
* @var array $bodies
120-
* @var AttachmentCollection|array $attachments
120+
* @var AttachmentCollection|array $attachments
121+
* @var FlagCollection|array $flags
121122
*/
122123
public $bodies = [];
123124
public $attachments = [];
125+
public $flags = [];
124126

125127
/**
126128
* Message const
@@ -154,6 +156,7 @@ class Message {
154156
* @param integer|null $fetch_options
155157
* @param boolean $fetch_body
156158
* @param boolean $fetch_attachment
159+
* @param boolean $fetch_flags
157160
*/
158161
public function __construct($uid, $msglist, Client $client, $fetch_options = null, $fetch_body = false, $fetch_attachment = false, $fetch_flags = false) {
159162
$this->setFetchOption($fetch_options);
@@ -162,7 +165,8 @@ public function __construct($uid, $msglist, Client $client, $fetch_options = nul
162165
$this->setFetchFlagsOption($fetch_flags);
163166

164167
$this->attachments = AttachmentCollection::make([]);
165-
168+
$this->flags = FlagCollection::make([]);
169+
166170
$this->msglist = $msglist;
167171
$this->client = $client;
168172
$this->uid = ($this->fetch_options == FT_UID) ? $uid : imap_msgno($this->client->getConnection(), $uid);
@@ -247,7 +251,7 @@ public function getHTMLBody($replaceImages = false) {
247251

248252
$body = $this->bodies['html']->content;
249253
if ($replaceImages) {
250-
$this->attachments->each(function($oAttachment) use(&$body){
254+
$this->attachments->each(function($oAttachment) use(&$body) {
251255
if ($oAttachment->id && isset($oAttachment->img_src)) {
252256
$body = str_replace('cid:'.$oAttachment->id, $oAttachment->img_src, $body);
253257
}
@@ -351,22 +355,22 @@ private function parseFlags() {
351355
$flags = imap_fetch_overview($this->client->getConnection(), $this->uid, $this->fetch_options);
352356
if (is_array($flags) && isset($flags[0])) {
353357
if (property_exists($flags[0], 'recent')) {
354-
$this->flags['recent'] = $flags[0]->recent;
358+
$this->flags->put('recent', $flags[0]->recent);
355359
}
356360
if (property_exists($flags[0], 'flagged')) {
357-
$this->flags['flagged'] = $flags[0]->flagged;
361+
$this->flags->put('flagged', $flags[0]->flagged);
358362
}
359363
if (property_exists($flags[0], 'answered')) {
360-
$this->flags['answered'] = $flags[0]->answered;
364+
$this->flags->put('answered', $flags[0]->answered);
361365
}
362366
if (property_exists($flags[0], 'deleted')) {
363-
$this->flags['deleted'] = $flags[0]->deleted;
367+
$this->flags->put('deleted', $flags[0]->deleted);
364368
}
365369
if (property_exists($flags[0], 'seen')) {
366-
$this->flags['seen'] = $flags[0]->seen;
370+
$this->flags->put('seen', $flags[0]->seen);
367371
}
368372
if (property_exists($flags[0], 'draft')) {
369-
$this->flags['draft'] = $flags[0]->draft;
373+
$this->flags->put('draft', $flags[0]->draft);
370374
}
371375
}
372376
}
@@ -379,7 +383,7 @@ private function parseFlags() {
379383
public function getHeaderInfo() {
380384
if ($this->header_info == null) {
381385
$this->header_info =
382-
$this->header_info = imap_headerinfo($this->client->getConnection(), $this->getMessageNo()); ;
386+
$this->header_info = imap_headerinfo($this->client->getConnection(), $this->getMessageNo());
383387
}
384388

385389
return $this->header_info;
@@ -427,13 +431,15 @@ private function parseAddresses($list) {
427431
public function parseBody() {
428432
$structure = imap_fetchstructure($this->client->getConnection(), $this->uid, $this->fetch_options);
429433

430-
$parts = $structure->parts;
434+
if(property_exists($structure, 'parts')){
435+
$parts = $structure->parts;
431436

432-
foreach ($parts as $part) {
433-
foreach ($part->parameters as $parameter) {
434-
if($parameter->attribute == "charset") {
435-
$encoding = $parameter->value;
436-
$parameter->value = preg_replace('/Content-Transfer-Encoding/', '', $encoding);
437+
foreach ($parts as $part) {
438+
foreach ($part->parameters as $parameter) {
439+
if($parameter->attribute == "charset") {
440+
$encoding = $parameter->value;
441+
$parameter->value = preg_replace('/Content-Transfer-Encoding/', '', $encoding);
442+
}
437443
}
438444
}
439445
}
@@ -668,8 +674,7 @@ private function getEncoding($structure) {
668674
* @param null|Folder $folder where to start searching from (top-level inbox by default)
669675
* @return null|Folder
670676
*/
671-
public function getContainingFolder(Folder $folder = null)
672-
{
677+
public function getContainingFolder(Folder $folder = null) {
673678
$folder = $folder ?: $this->client->getFolders()->first();
674679
$this->client->checkConnection();
675680

@@ -936,7 +941,7 @@ public function getBodies() {
936941
}
937942

938943
/**
939-
* @return array
944+
* @return FlagCollection
940945
*/
941946
public function getFlags() {
942947
return $this->flags;
@@ -950,8 +955,7 @@ public function getFlags() {
950955
* @param null|static $message
951956
* @return boolean
952957
*/
953-
public function is(Message $message = null)
954-
{
958+
public function is(Message $message = null) {
955959
if (is_null($message)) {
956960
return false;
957961
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/*
3+
* File: FlagCollection.php
4+
* Category: Collection
5+
* Author: M. Goldenbaum
6+
* Created: 21.07.18 23:10
7+
* Updated: -
8+
*
9+
* Description:
10+
* -
11+
*/
12+
13+
namespace Webklex\IMAP\Support;
14+
15+
/**
16+
* Class FlagCollection
17+
*
18+
* @package Webklex\IMAP\Support
19+
*/
20+
class FlagCollection extends PaginatedCollection {
21+
22+
}

0 commit comments

Comments
 (0)