/** * Sends the email represented by the rfc822 string received by the PIM. * * @param mixed $rfc822 The rfc822 mime message, a string or * stream resource. * @param integer|boolean $forward The UID of the message, if forwarding or * true if forwarding and EAS >= 14.0 * @param integer|boolean $reply The UID of the message if replying or * true if replying and EAS >= 14.0 * @param string $parent The collection id of parent message if * forwarding/replying. * @param boolean $save Save in sent messages. * @param Horde_ActiveSync_Message_SendMail $message The entire message * object for EAS 14+ requests. @since 2.5.0 * @todo H6 - Either make this take an options array or break it into two * separate methods - one for EAS < 14 and one for EAS > 14. * * @return boolean * @throws Horde_ActiveSync_Exception */ public function sendMail($rfc822, $forward = false, $reply = false, $parent = false, $save = true, Horde_ActiveSync_Message_SendMail $message = null) { ob_start(); $mailer = new Horde_Core_ActiveSync_Mail($this->_imap, $this->_user, $this->_version); $raw_message = !empty($message) ? new Horde_ActiveSync_Rfc822($message->mime) : new Horde_ActiveSync_Rfc822($rfc822); $mailer->setRawMessage($raw_message); // Replace the entire original MIME part? Save in sent? if (!empty($message)) { $mailer->replacemime = $message->replacemime; $save = $message->saveinsent; } // [Smart]Reply/[Smart]Forward? if ($forward || $reply) { $source = $message->source; if ($source->longid) { list($folderid, $itemid) = each(explode(':', $source, 2)); } elseif ($forward === true || $reply === true) { $folderid = $source->folderid; $itemid = $source->itemid; } try { if ($forward === true) { $mailer->setForward($folderid, $itemid); } elseif (!empty($forward)) { $mailer->setForward($parent, $forward); } if ($reply === true) { $mailer->setReply($folderid, $itemid); } elseif (!empty($reply)) { $mailer->setReply($parent, $reply); } } catch (Horde_ActiveSync_Exception $e) { $this->_logger->err($e->getMessage()); $this->_endBuffer(); throw $e; } } try { $mailer->send(); } catch (Horde_ActiveSync_Exception $e) { $this->_logger->err($e->getMessage()); $this->_endBuffer(); throw $e; } if ($save) { $sf = $this->getSpecialFolderNameByType(self::SPECIAL_SENT); if (!empty($sf)) { $this->_logger->info(sprintf("[%s] Preparing to copy to '%s'", $this->_pid, $sf)); $flags = array(Horde_Imap_Client::FLAG_SEEN); // Ignore issues sending to sent, in case the folder isn't // available. try { $this->_imap->appendMessage($sf, $mailer->getSentMail(), $flags); } catch (Horde_ActiveSync_Exception $e) { $this->_logger->err($e->getMessage()); } } } // Attempt to write forward/reply state. if ($this->_version > Horde_ActiveSync::VERSION_TWELVEONE && $mailer->id) { $this->_logger->info(sprintf('Logging LASTVERBEXECUTED to Maillog: %s, %s, %s', $mailer->reply ? 'reply' : 'forward', $mailer->imapMessage->getHeaders()->getValue('Message-ID'), $mailer->headers->getValue('To'))); $this->_connector->mail_logMaillog($mailer->reply ? 'reply' : 'forward', $mailer->imapMessage->getHeaders()->getValue('Message-ID'), $mailer->forward ? $mailer->headers->getValue('To') : null); $this->_imap->setImapFlag($mailer->parentFolder, $mailer->id, $mailer->reply ? Horde_ActiveSync::IMAP_FLAG_REPLY : Horde_ActiveSync::IMAP_FLAG_FORWARD); } // Attempt to log the recipient. $this->_logger->info('Logging recipients for RI.'); $action = $mailer->reply ? 'reply' : ($mailer->forward ? 'forward' : 'new'); try { $this->_connector->mail_logRecipient($action, $mailer->headers->getValue('To'), $mailer->headers->getValue('Message-ID')); } catch (Horde_Exception $e) { $this->_logger->err($e->getMessage()); } $this->_endBuffer(); return true; }