mirror of
https://github.com/retailcrm/Fetch.git
synced 2025-02-11 12:39:26 +03:00
Added methods for checking if a mailbox exists and to create a mailbox.
This commit is contained in:
parent
812e4eb048
commit
ebeacf6edf
@ -230,25 +230,36 @@ class Server
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getServerString()
|
protected 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;
|
$mailboxPath = '{' . $this->serverPath;
|
||||||
|
|
||||||
if(isset($this->port))
|
if (isset($this->port))
|
||||||
$mailboxPath .= ':' . $this->port;
|
$mailboxPath .= ':' . $this->port;
|
||||||
|
|
||||||
if($this->service != 'imap')
|
if ($this->service != 'imap')
|
||||||
$mailboxPath .= '/' . $this->service;
|
$mailboxPath .= '/' . $this->service;
|
||||||
|
|
||||||
foreach($this->flags as $flag)
|
foreach ($this->flags as $flag) {
|
||||||
{
|
|
||||||
$mailboxPath .= '/' . $flag;
|
$mailboxPath .= '/' . $flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mailboxPath .= '}';
|
$mailboxPath .= '}';
|
||||||
|
|
||||||
if(isset($this->mailbox))
|
|
||||||
$mailboxPath .= $this->mailbox;
|
|
||||||
|
|
||||||
return $mailboxPath;
|
return $mailboxPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,4 +370,32 @@ class Server
|
|||||||
{
|
{
|
||||||
return imap_expunge($this->getImapStream());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user