From 4027b05fc6677c8df27008b9bca8bb80a08a1866 Mon Sep 17 00:00:00 2001 From: Geoffray Date: Sat, 1 Nov 2014 09:03:49 +0100 Subject: [PATCH 1/3] using class constants in stead of raw strings --- src/Fetch/Message.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index d5aef7a..e68fccd 100755 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -77,7 +77,7 @@ class Message * * @var string */ - protected static $flagTypes = array('recent', 'flagged', 'answered', 'deleted', 'seen', 'draft'); + protected static $flagTypes = array(self::FLAG_RECENT, self::FLAG_FLAGGED, self::FLAG_ANSWERED, self::FLAG_DELETED, self::FLAG_SEEN, self::FLAG_DRAFT); /** * This holds the plantext email message. @@ -671,7 +671,7 @@ class Message * @param string $flag Recent, Flagged, Answered, Deleted, Seen, Draft * @return bool */ - public function checkFlag($flag = 'flagged') + public function checkFlag($flag = self::FLAG_FLAGGED) { return (isset($this->status[$flag]) && $this->status[$flag] === true); } @@ -686,7 +686,7 @@ class Message */ public function setFlag($flag, $enable = true) { - if (!in_array($flag, self::$flagTypes) || $flag == 'recent') + if (!in_array($flag, self::$flagTypes) || $flag == self::FLAG_RECENT) throw new \InvalidArgumentException('Unable to set invalid flag "' . $flag . '"'); $imapifiedFlag = '\\' . ucfirst($flag); From 56983f0365f5944d9145ef45f0b6611343a46875 Mon Sep 17 00:00:00 2001 From: Geoffray Date: Sat, 1 Nov 2014 09:11:38 +0100 Subject: [PATCH 2/3] allow setFlags() to set multiple flags as an array --- src/Fetch/Message.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index e68fccd..abf6abd 100755 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -677,27 +677,36 @@ class Message } /** - * This function is used to enable or disable a flag on the imap message. + * This function is used to enable or disable one or more flags on the imap message. * - * @param string $flag Flagged, Answered, Deleted, Seen, Draft + * @param string|array $flag Flagged, Answered, Deleted, Seen, Draft * @param bool $enable * @throws \InvalidArgumentException * @return bool */ public function setFlag($flag, $enable = true) { - if (!in_array($flag, self::$flagTypes) || $flag == self::FLAG_RECENT) - throw new \InvalidArgumentException('Unable to set invalid flag "' . $flag . '"'); + $flags = (is_array($flag)) ? $flag : array($flag); - $imapifiedFlag = '\\' . ucfirst($flag); + foreach ($flags as $i => $flag) { + $flag = ltrim(strtolower($flag), '\\'); + if (!in_array($flag, self::$flagTypes) || $flag == self::FLAG_RECENT) + throw new \InvalidArgumentException('Unable to set invalid flag "' . $flag . '"'); + + if ($enable) { + $this->status[$flag] = true; + } else { + unset($this->status[$flag]); + } + + $flags[$i] = $flag; + } + + $imapifiedFlag = '\\'.implode(' \\', array_map('ucfirst', $flags)); if ($enable === true) { - $this->status[$flag] = true; - return imap_setflag_full($this->imapStream, $this->uid, $imapifiedFlag, ST_UID); } else { - unset($this->status[$flag]); - return imap_clearflag_full($this->imapStream, $this->uid, $imapifiedFlag, ST_UID); } } From 928d37c25fa0d13d45c61e12dd0f5e87b7ec8c23 Mon Sep 17 00:00:00 2001 From: Geoffray Date: Sat, 1 Nov 2014 09:35:31 +0100 Subject: [PATCH 3/3] minor regex optimization to convert br to eol --- src/Fetch/Message.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index abf6abd..212f5fd 100755 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -351,7 +351,7 @@ class Message } } else { if (!isset($this->plaintextMessage) && isset($this->htmlMessage)) { - $output = preg_replace('/\/i', PHP_EOL, trim($this->htmlMessage) ); + $output = preg_replace('/\s*\/i', PHP_EOL, trim($this->htmlMessage) ); $output = strip_tags($output); return $output;