hostname = $hostname; $this->port = $port; $this->flags = '/'.ltrim($flags, '/'); } /** * Authenticate connection * * @param string $username Username * @param string $password Password * * @return \Mirasvit_Ddeboer\Imap\Connection * @throws AuthenticationFailedException */ public function authenticate($username, $password) { $resource = @imap_open($this->getServerString(), $username, $password, null, 1); if (false === $resource) { throw new Mirasvit_Ddeboer_Imap_Exception_AuthenticationFailedException($username); } $check = imap_check($resource); $mailbox = $check->Mailbox; $this->connection = substr($mailbox, 0, strpos($mailbox, '}')+1); // These are necessary to get rid of PHP throwing IMAP errors imap_errors(); imap_alerts(); return new Mirasvit_Ddeboer_Imap_Connection($resource, $this->connection); } /** * Glues hostname, port and flags and returns result * * @return string */ protected function getServerString() { return "{{$this->hostname}:{$this->port}{$this->flags}}"; } }