Permalink
Browse files

Merge pull request #6 from Wiakowe/create-mailbox-method

Added methods for checking if a mailbox exists and to create a mailbox.
  • Loading branch information...
2 parents 7484ff1 + ebeacf6 commit 17b57c53ecc38cc29f930a895023b0e072ff909b @tedivm tedivm committed Oct 4, 2012
Showing with 46 additions and 7 deletions.
  1. +46 −7 src/Fetch/Server.php
View
@@ -236,24 +236,35 @@ public function getImapStream()
*/
public function getServerString()
{
+ $mailboxPath = $this->getServerSpecification();
+
+ if(isset($this->mailbox))
+ $mailboxPath .= $this->mailbox;
+
+ return $mailboxPath;
+ }
+
+ /**
+ * Returns the server specification, without adding any mailbox.
+ *
+ * @return string
+ */
+ protected function getServerSpecification()
+ {
$mailboxPath = '{' . $this->serverPath;
- if(isset($this->port))
+ if (isset($this->port))
$mailboxPath .= ':' . $this->port;
- if($this->service != 'imap')
+ if ($this->service != 'imap')
$mailboxPath .= '/' . $this->service;
- foreach($this->flags as $flag)
- {
+ foreach ($this->flags as $flag) {
$mailboxPath .= '/' . $flag;
}
$mailboxPath .= '}';
- if(isset($this->mailbox))
- $mailboxPath .= $this->mailbox;
-
return $mailboxPath;
}
@@ -364,4 +375,32 @@ public function expunge()
{
return imap_expunge($this->getImapStream());
}
+
+ /**
+ * Checks if the given mailbox exists.
+ *
+ * @param $mailbox
+ *
+ * @return bool
+ */
+ public function hasMailBox($mailbox)
+ {
+ return (boolean) imap_getmailboxes(
+ $this->getImapStream(),
+ $this->getServerString(),
+ $this->getServerSpecification() . $mailbox
+ );
+ }
+
+ /**
+ * Creates the given mailbox.
+ *
+ * @param $mailbox
+ *
+ * @return bool
+ */
+ public function createMailBox($mailbox)
+ {
+ return imap_createmailbox($this->getImapStream(), $this->getServerSpecification() . $mailbox);
+ }
}

0 comments on commit 17b57c5

Please sign in to comment.