/**
  * @param Mirasvit_Helpdesk_Model_Gateway $gateway
  *
  * @return bool
  */
 public function connect($gateway)
 {
     $this->gateway = $gateway;
     $flags = sprintf('/%s', $gateway->getProtocol());
     if ($gateway->getEncryption() == 'ssl') {
         $flags .= '/ssl';
     }
     $flags .= '/novalidate-cert';
     // echo $flags;die;
     $server = new Mirasvit_Ddeboer_Imap_Server($gateway->getHost(), $gateway->getPort(), $flags);
     if (function_exists('imap_timeout')) {
         imap_timeout(1, 20);
     }
     if (!($this->connection = $server->authenticate($gateway->getLogin(), $gateway->getPassword()))) {
         return false;
     }
     $mailboxes = $this->connection->getMailboxNames();
     if (in_array('INBOX', $mailboxes)) {
         $mailboxName = 'INBOX';
     } elseif (in_array('Inbox', $mailboxes)) {
         $mailboxName = 'Inbox';
     } else {
         $mailboxName = $mailboxes[0];
     }
     $this->mailbox = $this->connection->getMailbox($mailboxName);
     return true;
 }
 public static function setUpBeforeClass()
 {
     $server = new Mirasvit_Ddeboer_Imap_Server('imap.gmail.com');
     static::$connection = $server->authenticate('*****@*****.**', '6Vl5gxZmxpeE');
 }