/** * Push content to the recipient. * * @param Horde_Push $content The content element. * @param array $options Additional options. * * @return NULL */ public function push(Horde_Push $content, $options = array()) { $contents = $content->getContent(); $types = $content->getMimeTypes(); $mail = new Horde_Mime_Mail(); // @todo Append references if (isset($types['text/plain'])) { $mail->setBody($content->getStringContent($types['text/plain'][0])); unset($contents[$types['text/plain'][0]]); } if (isset($types['text/html'])) { $mail->setHtmlBody($content->getStringContent($types['text/html'][0]), 'UTF-8', !isset($types['text/plain'])); unset($contents[$types['text/html'][0]]); } foreach ($contents as $part) { $mail->addPart($part['mime_type'], $part['content'], 'UTF-8'); } $mail->addRecipients(explode(',', $this->getAcl())); $mail->addHeader('subject', $content->getSummary()); if (!empty($this->_params['from'])) { $mail->addHeader('from', $this->_params['from']); } $mail->addHeader('to', $this->getAcl()); if (!empty($options['pretend'])) { $mock = new Horde_Mail_Transport_Mock(); $mail->send($mock); return sprintf("Would push mail \n\n%s\n\n%s\n to %s.", $mock->sentMessages[0]['header_text'], $mock->sentMessages[0]['body'], $this->getAcl()); } $mail->send($this->_mail); return sprintf('Pushed mail to %s.', $this->getAcl()); }
/** * Sends a SMART response. * * @throws Horde_ActiveSync_Exception */ protected function _sendSmart() { $mime_message = $this->_raw->getMimeObject(); // Need to remove content-type header from the incoming raw message // since in a smart request, we actually construct the full MIME msg // ourselves and the content-type in _headers only applies to the reply // text sent from the client, not the fully generated MIME message. $this->_headers->removeHeader('Content-Type'); $this->_headers->removeHeader('Content-Transfer-Encoding'); $mail = new Horde_Mime_Mail($this->_headers->toArray(array('charset' => 'UTF-8'))); $base_part = $this->imapMessage->getStructure(); $plain_id = $base_part->findBody('plain'); $html_id = $base_part->findBody('html'); try { $body_data = $this->imapMessage->getMessageBodyData(array('protocolversion' => $this->_version, 'bodyprefs' => array(Horde_ActiveSync::BODYPREF_TYPE_MIME => true))); } catch (Horde_Exception_NotFound $e) { throw new Horde_ActiveSync_Exception($e->getMessage()); } if (!empty($html_id)) { $mail->setHtmlBody($this->_getHtmlPart($html_id, $mime_message, $body_data, $base_part)); } elseif (!empty($plain_id)) { $mail->setBody($this->_getPlainPart($plain_id, $mime_message, $body_data, $base_part)); } if ($this->_forward) { foreach ($base_part->contentTypeMap() as $mid => $type) { if ($this->imapMessage->isAttachment($mid, $type)) { $mail->addMimePart($this->imapMessage->getMimePart($mid)); } } } foreach ($mime_message->contentTypeMap() as $mid => $type) { if ($mid != 0 && $mid != $mime_message->findBody('plain') && $mid != $mime_message->findBody('html')) { $mail->addMimePart($mime_message->getPart($mid)); } } try { $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); $this->_mailer = $mail; } catch (Horde_Mime_Exception $e) { throw new Horde_ActiveSync_Exception($e); } }
/** * Sends a SMART request. * * @throws Horde_ActiveSync_Exception */ protected function _sendSmart() { $mime_message = $this->_raw->getMimeObject(); $mail = new Horde_Mime_Mail($this->_headers->toArray(array('charset' => 'UTF-8'))); $base_part = $this->imapMessage->getStructure(); $plain_id = $base_part->findBody('plain'); $html_id = $base_part->findBody('html'); try { $body_data = $this->imapMessage->getMessageBodyData(array('protocolversion' => $this->_version, 'bodyprefs' => array(Horde_ActiveSync::BODYPREF_TYPE_MIME => true))); } catch (Horde_Exception_NotFound $e) { throw new Horde_ActiveSync_Exception($e->getMessage()); } if (!empty($html_id)) { $mail->setHtmlBody($this->_getHtmlPart($html_id, $mime_message, $body_data, $base_part)); } if (!empty($plain_id)) { $mail->setBody($this->_getPlainPart($plain_id, $mime_message, $body_data, $base_part)); } if ($this->_forward) { foreach ($base_part->contentTypeMap() as $mid => $type) { if ($this->imapMessage->isAttachment($mid, $type)) { $mail->addMimePart($this->imapMessage->getMimePart($mid)); } } } foreach ($mime_message->contentTypeMap() as $mid => $type) { if ($mid != 0 && $mid != $mime_message->findBody('plain') && $mid != $mime_message->findBody('html')) { $mail->addMimePart($mime_message->getPart($mid)); } } try { $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); $this->_mailer = $mail; } catch (Horde_Mime_Exception $e) { throw new Horde_ActiveSync_Exception($e); } }