Пример #1
0
 /**
  * Check connections to ALL mailbox servers.
  * 
  * @return string json
  */
 public function checkMailboxes()
 {
     $res = array();
     $manager = JModel::getInstance('Mailboxprofiles', 'NewsletterModel');
     $mailboxes = $manager->getAllItems();
     if (!empty($mailboxes)) {
         jimport('migur.library.mailer.mailbox');
         foreach ($mailboxes as $mailboxSettings) {
             $text = JText::sprintf('COM_NEWSLETTER_MAINTAINANCE_CHECKMAILBOX', $mailboxSettings->mailbox_profile_name) . '...';
             $mailboxSettings = (array) $mailboxSettings;
             $mailbox = new MigurMailerMailbox($mailboxSettings);
             $errors = array();
             if ($mailbox->connect()) {
                 $mailbox->close();
             } else {
                 $errors[] = JText::_('COM_NEWSLETTER_UNABLE_TO_CONNECT');
                 $errors[] = $mailbox->getLastError();
                 if (!$mailbox->protocol->getOption('noValidateCert')) {
                     $mailbox->protocol->setOption('noValidateCert', true);
                     $errors[] = JText::_('COM_NEWSLETTER_TRYING_TO_CONNECT_WITHOUT_CERT');
                     if ($mailbox->connect()) {
                         $mailbox->close();
                         $errors[] = JText::_('COM_NEWSLETTER_OK_CHECK_YOUR_CERT');
                     } else {
                         $errors[] = JText::_('COM_NEWSLETTER_FAILED') . '. ' . $mailbox->getLastError();
                     }
                 }
             }
             if (count($errors) > 0) {
                 $text .= '<br/>' . implode('<br/>', $errors);
             }
             imap_errors();
             imap_alerts();
             $res[] = array('text' => $text, 'type' => count($errors) == 0);
         }
     } else {
         $res[] = array('text' => JText::sprintf('COM_NEWSLETTER_MAINTAINANCE_NO_MAILBOXES'), 'type' => false);
     }
     // Return data
     NewsletterHelper::jsonMessage('checkMailboxes', $res);
 }
Пример #2
0
 public function checkConnection()
 {
     $options = JRequest::getVar('jform');
     $mailbox = new MigurMailerMailbox($options);
     $errors = array();
     if ($mailbox->connect()) {
         $mailbox->close();
     } else {
         $errors[] = JText::_('COM_NEWSLETTER_UNABLE_TO_CONNECT');
         $errors[] = $mailbox->getLastError();
         if (!$mailbox->protocol->getOption('noValidateCert')) {
             $mailbox->protocol->setOption('noValidateCert', true);
             $errors[] = JText::_('COM_NEWSLETTER_TRYING_TO_CONNECT_WITHOUT_CERT');
             if ($mailbox->connect()) {
                 $mailbox->close();
                 $errors[] = JText::_('COM_NEWSLETTER_OK_CHECK_YOUR_CERT');
             } else {
                 $errors[] = JText::_('COM_NEWSLETTER_FAILED') . '. ' . $mailbox->getLastError();
             }
         }
     }
     if (count($errors) == 0) {
         $status = 'ok';
     } else {
         $status = '';
         foreach ($errors as $error) {
             $status .= "\n" . $error;
         }
     }
     imap_errors();
     imap_alerts();
     echo json_encode(array('status' => $status));
     jexit();
 }