/**
  * init the test framework
  */
 public function initFramework()
 {
     $this->setWhiteAndBlacklists();
     // get config
     $configData = @(include 'phpunitconfig.inc.php');
     if ($configData === false) {
         $configData = (include 'config.inc.php');
     }
     if ($configData === false) {
         die('central configuration file config.inc.php not found in includepath: ' . get_include_path());
     }
     $config = new Zend_Config($configData);
     Zend_Registry::set('testConfig', $config);
     $_SERVER['DOCUMENT_ROOT'] = $config->docroot;
     $_SERVER['REQUEST_URI'] = '';
     Tinebase_Core::startCoreSession();
     Tinebase_Core::initFramework();
     // set default test mailer
     Tinebase_Smtp::setDefaultTransport(new Zend_Mail_Transport_Array());
     // set max execution time
     Tinebase_Core::setExecutionLifeTime(1200);
     if ($config->locale) {
         Tinebase_Core::setupUserLocale($config->locale);
     }
     // this is needed for session handling in unittests (deactivate Zend_Session::writeClose and others)
     Zend_Session::$_unitTestEnabled = TRUE;
 }
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  */
 public function setUp()
 {
     $smtpConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::SMTP, new Tinebase_Config_Struct())->toArray();
     if (empty($smtpConfig)) {
         $this->markTestSkipped('No SMTP config found: this is needed to send notifications.');
     }
     $this->_mailer = Tinebase_Smtp::getDefaultTransport();
 }
 /**
  * init the test framework
  */
 public function initFramework()
 {
     $this->setWhiteAndBlacklists();
     $config = $this->getConfig();
     // set some server vars. sabredav complains if REQUEST_URI is not set
     $_SERVER['DOCUMENT_ROOT'] = $config->docroot;
     $_SERVER['REQUEST_URI'] = '';
     Tinebase_Core::startCoreSession();
     Tinebase_Core::initFramework();
     // set default test mailer
     Tinebase_Smtp::setDefaultTransport(new Zend_Mail_Transport_Array());
     // set max execution time
     Tinebase_Core::setExecutionLifeTime(1200);
     if ($config->locale) {
         Tinebase_Core::setupUserLocale($config->locale);
     }
     // this is needed for session handling in unittests (deactivate Zend_Session::writeClose and others)
     Zend_Session::$_unitTestEnabled = TRUE;
     Tinebase_Core::set('frameworkInitialized', true);
 }
Пример #4
0
 /**
  * init the test framework
  *
  */
 public function initFramework()
 {
     // get config
     $configData = @(include 'phpunitconfig.inc.php');
     if ($configData === false) {
         $configData = (include 'config.inc.php');
     }
     if ($configData === false) {
         die('central configuration file config.inc.php not found in includepath: ' . get_include_path());
     }
     $config = new Zend_Config($configData);
     Zend_Registry::set('testConfig', $config);
     $_SERVER['DOCUMENT_ROOT'] = $config->docroot;
     Tinebase_Core::initFramework();
     // set default test mailer
     Tinebase_Smtp::setDefaultTransport(new Zend_Mail_Transport_Array());
     // set max execution time
     Tinebase_Core::setExecutionLifeTime(1200);
     // set default internal encoding
     iconv_set_encoding("internal_encoding", "UTF-8");
     Zend_Registry::set('locale', new Zend_Locale($config->locale));
 }
 /**
  * get mailer
  * 
  * @return Zend_Mail_Transport_Abstract
  */
 public static function getMailer()
 {
     if (!self::$_mailer) {
         self::$_mailer = Tinebase_Smtp::getDefaultTransport();
     }
     return self::$_mailer;
 }
 /**
  * send mail via transport (smtp)
  * 
  * @param Zend_Mail $_mail
  * @param Felamimail_Model_Account $_account
  * @param boolean $_saveInSent
  * @param Felamimail_Model_Message $_message
  * @param array $_nonPrivateRecipients
  */
 protected function _sendMailViaTransport(Zend_Mail $_mail, Felamimail_Model_Account $_account, Felamimail_Model_Message $_message = null, $_saveInSent = false, $_nonPrivateRecipients = array())
 {
     $smtpConfig = $_account->getSmtpConfig();
     if (!empty($smtpConfig) && (isset($smtpConfig['hostname']) || array_key_exists('hostname', $smtpConfig))) {
         $transport = new Felamimail_Transport($smtpConfig['hostname'], $smtpConfig);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             $debugConfig = $smtpConfig;
             $whiteList = array('hostname', 'username', 'port', 'auth', 'ssl');
             foreach ($debugConfig as $key => $value) {
                 if (!in_array($key, $whiteList)) {
                     unset($debugConfig[$key]);
                 }
             }
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' About to send message via SMTP with the following config: ' . print_r($debugConfig, true));
         }
         Tinebase_Smtp::getInstance()->sendMessage($_mail, $transport);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' successful.');
         }
         // append mail to sent folder
         if ($_saveInSent) {
             $this->_saveInSent($transport, $_account, $this->_getAdditionalHeaders($_message));
         }
         if ($_message !== null) {
             // add reply/forward flags if set
             if (!empty($_message->flags) && ($_message->flags == Zend_Mail_Storage::FLAG_ANSWERED || $_message->flags == Zend_Mail_Storage::FLAG_PASSED) && $_message->original_id instanceof Felamimail_Model_Message) {
                 Felamimail_Controller_Message_Flags::getInstance()->addFlags($_message->original_id, array($_message->flags));
             }
             // add email notes to contacts (only to/cc)
             if ($_message->note) {
                 $this->_addEmailNote($_nonPrivateRecipients, $_message->subject, $_message->getPlainTextBody());
             }
         }
     } else {
         Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not send message, no smtp config found.');
     }
 }
 /**
  * send mail via transport (smtp)
  *
  * @param Zend_Mail $_mail
  * @param Expressomail_Model_Account $_account
  * @param boolean $_saveInSent
  * @param Expressomail_Model_Message $_message
  */
 protected function _sendMailViaTransport(Zend_Mail $_mail, Expressomail_Model_Account $_account, Expressomail_Model_Message $_message = NULL, $_saveInSent = false)
 {
     $smtpConfig = $_account->getSmtpConfig();
     if (!empty($smtpConfig) && array_key_exists('hostname', $smtpConfig)) {
         $transport = new Expressomail_Transport($smtpConfig['hostname'], $smtpConfig);
         // send message via smtp
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' About to send message via SMTP ...');
         }
         Tinebase_Smtp::getInstance()->sendMessage($_mail, $transport);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' successful.');
         }
         // append mail to sent folder
         if ($_saveInSent) {
             $this->_selectSentFolder($_message, $_account);
             $this->_saveInSent($transport, $_account, $this->_getAdditionalHeaders($_message));
         }
         if ($_message !== NULL) {
             // add reply/forward flags if set
             if (!empty($_message->flags) && ($_message->flags == Zend_Mail_Storage::FLAG_ANSWERED || $_message->flags == Zend_Mail_Storage::FLAG_PASSED) && $_message->original_id instanceof Expressomail_Model_Message) {
                 Expressomail_Controller_Message_Flags::getInstance()->addFlags($_message->original_id, array($_message->flags));
             }
         }
     } else {
         Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not send message, no smtp config found.');
     }
 }
 /**
  * send a notification as email
  *
  * @param Tinebase_Model_FullUser   $_updater
  * @param Addressbook_Model_Contact $_recipient
  * @param string                    $_subject the subject
  * @param string                    $_messagePlain the message as plain text
  * @param string                    $_messageHtml the message as html
  * @param string|array              $_attachments
  */
 public function send($_updater, Addressbook_Model_Contact $_recipient, $_subject, $_messagePlain, $_messageHtml = NULL, $_attachments = NULL)
 {
     // create mail object
     $mail = new Tinebase_Mail('UTF-8');
     // this seems to break some subjects, removing it for the moment
     // -> see 0004070: sometimes we can't decode message subjects (calendar notifications?)
     //$mail->setHeaderEncoding(Zend_Mime::ENCODING_BASE64);
     $mail->setSubject($_subject);
     $mail->setBodyText($_messagePlain);
     if ($_messageHtml !== NULL) {
         $mail->setBodyHtml($_messageHtml);
     }
     // add header to identify mails sent by notification service / don't reply to this mail, dear autoresponder ... :)
     $mail->addHeader('X-Tine20-Type', 'Notification');
     $mail->addHeader('Precedence', 'bulk');
     $mail->addHeader('User-Agent', Tinebase_Core::getTineUserAgent('Notification Service'));
     if (empty($this->_fromAddress)) {
         Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' No notification service address set. Could not send notification.');
         return;
     }
     if ($_updater !== NULL && !empty($_updater->accountEmailAddress)) {
         $mail->setFrom($_updater->accountEmailAddress, $_updater->accountFullName);
         $mail->setSender($this->_fromAddress, $this->_fromName);
     } else {
         $mail->setFrom($this->_fromAddress, $this->_fromName);
     }
     // attachments
     if (is_array($_attachments)) {
         $attachments =& $_attachments;
     } elseif (is_string($_attachments)) {
         $attachments = array(&$_attachments);
     } else {
         $attachments = array();
     }
     foreach ($attachments as $attachment) {
         if ($attachment instanceof Zend_Mime_Part) {
             $mail->addAttachment($attachment);
         } else {
             if (isset($attachment['filename'])) {
                 $mail->createAttachment($attachment['rawdata'], Zend_Mime::TYPE_OCTETSTREAM, Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $attachment['filename']);
             } else {
                 $mail->createAttachment($attachment);
             }
         }
     }
     // send
     if (!empty($_recipient->email)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Send notification email to ' . $_recipient->email);
         }
         $mail->addTo($_recipient->email, $_recipient->n_fn);
         Tinebase_Smtp::getInstance()->sendMessage($mail);
     } else {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Not sending notification email to ' . $_recipient->n_fn . '. No email address available.');
     }
 }
 /**
  * testContainerNotification
  */
 public function testContainerNotification()
 {
     // prepare smtp transport
     $smtpConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::SMTP, new Tinebase_Config_Struct())->toArray();
     if (empty($smtpConfig)) {
         $this->markTestSkipped('No SMTP config found: this is needed to send notifications.');
     }
     $mailer = Tinebase_Smtp::getDefaultTransport();
     // make sure all messages are sent if queue is activated
     if (isset(Tinebase_Core::getConfig()->actionqueue)) {
         Tinebase_ActionQueue::getInstance()->processQueue(100);
     }
     $mailer->flush();
     // create and update container
     $container = $this->_saveContainer();
     $container['type'] = Tinebase_Model_Container::TYPE_PERSONAL;
     $container['note'] = 'changed to personal';
     $container['account_grants'] = $this->_getContainerGrants();
     $containerUpdated = $this->_json->saveContainer($container);
     // make sure messages are sent if queue is activated
     if (isset(Tinebase_Core::getConfig()->actionqueue)) {
         Tinebase_ActionQueue::getInstance()->processQueue();
     }
     // check notification message
     $messages = $mailer->getMessages();
     $this->assertGreaterThan(0, count($messages));
     $notification = $messages[0];
     $translate = Tinebase_Translation::getTranslation('Admin');
     $body = quoted_printable_decode($notification->getBodyText(TRUE));
     $this->assertContains($container['note'], $body, $body);
     $subject = $notification->getSubject();
     if (strpos($subject, 'UTF-8') !== FALSE) {
         $this->assertEquals(iconv_mime_encode('Subject', $translate->_('Your container has been changed'), array('scheme' => 'Q', 'line-length' => 500)), 'Subject: ' . $subject);
     } else {
         $this->assertEquals($translate->_('Your container has been changed'), $subject);
     }
     $this->assertTrue(in_array(Tinebase_Core::getUser()->accountEmailAddress, $notification->getRecipients()));
 }
 /**
  * testInternalInvitationReplyAutoProcess
  * 
  * an internal reply does not need to be processed of course
  */
 public function testInternalInvitationReplyAutoProcess()
 {
     // flush mailer
     if (isset(Tinebase_Core::getConfig()->actionqueue)) {
         Tinebase_ActionQueue::getInstance()->processQueue(10000);
     }
     Tinebase_Smtp::getDefaultTransport()->flush();
     $iMIP = $this->_getiMIP('REPLY', TRUE);
     $event = $iMIP->getEvent();
     try {
         $this->_iMIPFrontend->autoProcess($iMIP);
     } catch (Exception $e) {
         $this->assertContains('TOPROCESS', $e->getMessage());
         return;
     }
     $this->fail("autoProcess did not throw TOPROCESS Exception {$e}");
 }
Пример #11
0
 /**
  * sets default transport
  * @param  Zend_Mail_Transport_Abstract|NULL $_transport
  * @return void
  */
 public static function setDefaultTransport($_transport)
 {
     if ($_transport) {
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
             Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Setting SMTP transport: ' . get_class($_transport));
         }
         self::$_defaultTransport = $_transport;
     } else {
         self::$_defaultTransport = NULL;
         self::createDefaultTransport();
     }
 }
 /**
  * test alarm sending failure (with wrong stmp user/password)
  */
 public function testAlarmSendingFailure()
 {
     if (empty($this->_smtpConfig)) {
         $this->markTestSkipped('No SMTP config found.');
     }
     // send old alarms first
     $this->_sendAlarm();
     $task = $this->_getTaskWithAlarm();
     $persistentTaskData = $this->_backend->saveTask($task->toArray());
     // set wrong smtp user/password
     $wrongCredentialsConfig = $this->_smtpConfig;
     $wrongCredentialsConfig['password'] = '******';
     Tinebase_Config::getInstance()->set(Tinebase_Config::SMTP, $wrongCredentialsConfig);
     $this->_smtpConfigChanged = TRUE;
     Tinebase_Smtp::setDefaultTransport(NULL);
     $this->_sendAlarm();
     $loadedTaskData = $this->_backend->getTask($persistentTaskData['id']);
     $this->assertEquals(Tinebase_Model_Alarm::STATUS_FAILURE, $loadedTaskData['alarms'][0]['sent_status']);
     $this->assertContains('535 5.7.8 Error: authentication failed', $loadedTaskData['alarms'][0]['sent_message'], 'got: ' . $loadedTaskData['alarms'][0]['sent_message']);
 }
Пример #13
0
 /**
  * send mail via transport (smtp)
  * 
  * @param Zend_Mail $_mail
  * @param Felamimail_Model_Account $_account
  * @param boolean $_saveInSent
  * @param Felamimail_Model_Message $_message
  * @param array $_nonPrivateRecipients
  */
 protected function _sendMailViaTransport(Zend_Mail $_mail, Felamimail_Model_Account $_account, Felamimail_Model_Message $_message = NULL, $_saveInSent = false, $_nonPrivateRecipients = array())
 {
     $smtpConfig = $_account->getSmtpConfig();
     if (!empty($smtpConfig) && array_key_exists('hostname', $smtpConfig)) {
         $transport = new Felamimail_Transport($smtpConfig['hostname'], $smtpConfig);
         // send message via smtp
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' About to send message via SMTP ...');
         }
         Tinebase_Smtp::getInstance()->sendMessage($_mail, $transport);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' successful.');
         }
         // append mail to sent folder
         if ($_saveInSent) {
             $this->_saveInSent($transport, $_account, $_message !== NULL ? array('Bcc' => $_message->bcc) : array());
         }
         if ($_message !== NULL) {
             // add reply/forward flags if set
             if (!empty($_message->flags) && ($_message->flags == Zend_Mail_Storage::FLAG_ANSWERED || $_message->flags == Zend_Mail_Storage::FLAG_PASSED) && $_message->original_id instanceof Felamimail_Model_Message) {
                 Felamimail_Controller_Message_Flags::getInstance()->addFlags($_message->original_id, array($_message->flags));
             }
             // add email notes to contacts (only to/cc)
             if ($_message->note) {
                 $this->_addEmailNote($_nonPrivateRecipients, $_message->subject, $_message->getPlainTextBody());
             }
         }
     } else {
         Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not send message, no smtp config found.');
     }
 }