Ejemplo n.º 1
0
 /**
  * @return Horde_Imap_Client_Socket
  */
 public function getImapConnection()
 {
     if (is_null($this->client)) {
         $host = $this->account->getInboundHost();
         $user = $this->account->getInboundUser();
         $password = $this->account->getInboundPassword();
         $password = $this->crypto->decrypt($password);
         $port = $this->account->getInboundPort();
         $ssl_mode = $this->convertSslMode($this->account->getInboundSslMode());
         $params = ['username' => $user, 'password' => $password, 'hostspec' => $host, 'port' => $port, 'secure' => $ssl_mode, 'timeout' => 20];
         if ($this->config->getSystemValue('app.mail.imaplog.enabled', false)) {
             $params['debug'] = $this->config->getSystemValue('datadirectory') . '/horde.log';
         }
         if ($this->config->getSystemValue('app.mail.server-side-cache.enabled', false)) {
             if ($this->memcacheFactory->isAvailable()) {
                 $params['cache'] = ['backend' => new Cache(array('cacheob' => $this->memcacheFactory->create(md5($this->getId() . $this->getEMailAddress()))))];
             }
         }
         $this->client = new \Horde_Imap_Client_Socket($params);
         $this->client->login();
     }
     return $this->client;
 }
Ejemplo n.º 2
0
 /**
  * @NoAdminRequired
  *
  * @param string $accountName
  * @param string $emailAddress
  * @param string $password
  * @param string $imapHost
  * @param int $imapPort
  * @param string $imapSslMode
  * @param string $imapUser
  * @param string $imapPassword
  * @param string $smtpHost
  * @param int $smtpPort
  * @param string $smtpSslMode
  * @param string $smtpUser
  * @param string $smtpPassword
  * @param bool $autoDetect
  * @return JSONResponse
  */
 public function create($accountName, $emailAddress, $password, $imapHost, $imapPort, $imapSslMode, $imapUser, $imapPassword, $smtpHost, $smtpPort, $smtpSslMode, $smtpUser, $smtpPassword, $autoDetect)
 {
     try {
         if ($autoDetect) {
             $this->logger->info('setting up auto detected account');
             $newAccount = $this->autoConfig->createAutoDetected($emailAddress, $password, $accountName);
         } else {
             $this->logger->info('Setting up manually configured account');
             $newAccount = new MailAccount(['accountName' => $accountName, 'emailAddress' => $emailAddress, 'imapHost' => $imapHost, 'imapPort' => $imapPort, 'imapSslMode' => $imapSslMode, 'imapUser' => $imapUser, 'imapPassword' => $imapPassword, 'smtpHost' => $smtpHost, 'smtpPort' => $smtpPort, 'smtpSslMode' => $smtpSslMode, 'smtpUser' => $smtpUser, 'smtpPassword' => $smtpPassword]);
             $newAccount->setUserId($this->currentUserId);
             $newAccount->setInboundPassword($this->crypto->encrypt($newAccount->getInboundPassword()));
             $newAccount->setOutboundPassword($this->crypto->encrypt($newAccount->getOutboundPassword()));
             $a = new Account($newAccount);
             $this->logger->debug('Connecting to account {account}', ['account' => $newAccount->getEmail()]);
             $a->testConnectivity();
         }
         if ($newAccount) {
             $this->accountService->save($newAccount);
             $this->logger->debug("account created " . $newAccount->getId());
             return new JSONResponse(['data' => ['id' => $newAccount->getId()]], Http::STATUS_CREATED);
         }
     } catch (\Exception $ex) {
         $this->logger->error('Creating account failed: ' . $ex->getMessage());
         return new JSONResponse(array('message' => $this->l10n->t('Creating account failed: ') . $ex->getMessage()), HTTP::STATUS_BAD_REQUEST);
     }
     $this->logger->info('Auto detect failed');
     return new JSONResponse(array('message' => $this->l10n->t('Auto detect failed. Please use manual mode.')), HTTP::STATUS_BAD_REQUEST);
 }