/** * 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()); }
public function testAddPart() { $mail = new Horde_Mime_Mail(array('Subject' => 'My Subject', 'body' => "This is\nthe body", 'To' => '*****@*****.**', 'From' => '*****@*****.**', 'charset' => 'iso-8859-15')); $mail->addPart('text/plain', 'This is a plain text', 'iso-8859-1', 'inline'); $mail->addPart('application/octet-stream', file_get_contents(__DIR__ . '/fixtures/attachment.bin'), null, 'attachment'); $dummy = new Horde_Mail_Transport_Mock(); $mail->send($dummy); $sent = str_replace("\r\n", "\n", $dummy->sentMessages[0]); $this->assertStringMatchesFormat('Subject: My Subject To: recipient@example.com From: sender@example.com Message-ID: <*****@*****.**> User-Agent: Horde Application Framework %d Date: %s, %d %s %d %d:%d:%d %s%d Content-Type: multipart/mixed; boundary="=_%s" MIME-Version: 1.0', $sent['header_text']); $this->assertStringMatchesFormat("This message is in MIME format.\n\n--=_%s\nContent-Type: text/plain; charset=iso-8859-15; format=flowed; DelSp=Yes\n\nThis is\nthe body\n\n--=_%s\nContent-Type: text/plain; charset=iso-8859-1\nContent-Disposition: inline\n\nThis is a plain text\n--=_%s\nContent-Type: application/octet-stream\nContent-Disposition: attachment\nContent-Transfer-Encoding: base64\n\nWnfDtmxmIEJveGvDpG1wZmVyIGphZ2VuIFZpa3RvciBxdWVyIMO8YmVyIGRlbiBncm/Dn2VuIFN5\nbHRlciBEZWljaC4K\n--=_%s--\n", $sent['body']); $this->assertEquals(array('*****@*****.**'), $sent['recipients']); }