/** * send email * * @param resource $inputStream * @param boolean $saveInSent * @throws Syncroton_Exception */ public function sendEmail($inputStream, $saveInSent) { $defaultAccountId = Tinebase_Core::getPreference('Expressomail')->{Expressomail_Preference::DEFAULTACCOUNT}; try { $account = Expressomail_Controller_Account::getInstance()->get($defaultAccountId); } catch (Tinebase_Exception_NotFound $ten) { if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . " no email account configured"); } throw new Syncroton_Exception('no email account configured'); } if (empty(Tinebase_Core::getUser()->accountEmailAddress)) { throw new Syncroton_Exception('no email address set for current user'); } if (!is_resource($inputStream)) { $stream = fopen("php://temp", 'r+'); fwrite($stream, $inputStream); $inputStream = $stream; rewind($inputStream); } if ($this->_debugEmail == true) { $debugStream = fopen("php://temp", 'r+'); stream_copy_to_stream($inputStream, $debugStream); rewind($debugStream); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " email to send:" . stream_get_contents($debugStream)); } //replace original stream wirh debug stream, as php://input can't be rewinded $inputStream = $debugStream; rewind($inputStream); } $incomingMessage = new Zend_Mail_Message(array('file' => $inputStream)); $subject = $incomingMessage->headerExists('subject') ? $incomingMessage->getHeader('subject') : null; if (Tinebase_Mail::isiMIPMail($incomingMessage)) { if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Do not send iMIP message with subject "' . $subject . '". The server should handle those.'); } } else { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Send Message with subject " . $subject . " (saveInSent: " . $saveInSent . ")"); } $mail = Tinebase_Mail::createFromZMM($incomingMessage); Expressomail_Controller_Message_Send::getInstance()->sendZendMail($account, $mail, (bool) $saveInSent); } }