Overview

Packages

  • Push

Classes

  • Horde_Push
  • Horde_Push_Cli
  • Horde_Push_Exception
  • Horde_Push_Factory_Push
  • Horde_Push_Factory_Recipients
  • Horde_Push_Recipient_Base
  • Horde_Push_Recipient_Blogger
  • Horde_Push_Recipient_Facebook
  • Horde_Push_Recipient_Mail
  • Horde_Push_Recipient_Mock
  • Horde_Push_Recipient_Twitter
  • Horde_Push_Translation

Interfaces

  • Horde_Push_Recipient
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * E-mail recipients.
  4:  *
  5:  * PHP version 5
  6:  *
  7:  * @category Horde
  8:  * @package  Push
  9:  * @author   Gunnar Wrobel <wrobel@pardus.de>
 10:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 11:  * @link     http://www.horde.org/libraries/Horde_Push
 12:  */
 13: 
 14: /**
 15:  * E-mail recipients.
 16:  *
 17:  * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
 18:  *
 19:  * See the enclosed file COPYING for license information (LGPL). If you did not
 20:  * receive this file, see http://www.horde.org/licenses/lgpl21.
 21:  *
 22:  * @category Horde
 23:  * @package  Push
 24:  * @author   Gunnar Wrobel <wrobel@pardus.de>
 25:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 26:  * @link     http://www.horde.org/libraries/Horde_Push
 27:  */
 28: class Horde_Push_Recipient_Mail
 29: extends Horde_Push_Recipient_Base
 30: {
 31:     /**
 32:      * The mail transport.
 33:      *
 34:      * @var Horde_Mail_Transport
 35:      */
 36:     private $_mail;
 37: 
 38:     /**
 39:      * Mail parameters.
 40:      *
 41:      * @var array
 42:      */
 43:     private $_params;
 44: 
 45:     /**
 46:      * Constructor.
 47:      *
 48:      * @param Horde_Mail_Transport $mail   The mail transport.
 49:      * @param array                $params Parameters for the mail transport.
 50:      */
 51:     public function __construct(Horde_Mail_Transport $mail, $params = array())
 52:     {
 53:         $this->_mail = $mail;
 54:         $this->_params = $params;
 55:     }
 56: 
 57:     /**
 58:      * Push content to the recipient.
 59:      *
 60:      * @param Horde_Push $content The content element.
 61:      * @param array      $options Additional options.
 62:      *
 63:      * @return NULL
 64:      */
 65:     public function push(Horde_Push $content, $options = array())
 66:     {
 67:         $contents = $content->getContent();
 68:         $types = $content->getMimeTypes();
 69:         $mail = new Horde_Mime_Mail();
 70:         // @todo Append references
 71:         if (isset($types['text/plain'])) {
 72:             $mail->setBody($content->getStringContent($types['text/plain'][0]));
 73:             unset($contents[$types['text/plain'][0]]);
 74:         }
 75:         if (isset($types['text/html'])) {
 76:             $mail->setHtmlBody(
 77:                 $content->getStringContent($types['text/html'][0]),
 78:                 'UTF-8',
 79:                 !isset($types['text/plain'])
 80:             );
 81:             unset($contents[$types['text/html'][0]]);
 82:         }
 83:         foreach ($contents as $part) {
 84:             $mail->addPart(
 85:                 $part['mime_type'],
 86:                 $part['content'],
 87:                 'UTF-8'
 88:             );
 89:         }
 90:         $mail->addRecipients(explode(',', $this->getAcl()));
 91:         $mail->addHeader('subject', $content->getSummary());
 92:         if (!empty($this->_params['from'])) {
 93:             $mail->addHeader('from', $this->_params['from']);
 94:         }
 95:         $mail->addHeader('to', $this->getAcl());
 96: 
 97:         if (!empty($options['pretend'])) {
 98:             $mock = new Horde_Mail_Transport_Mock();
 99:             $mail->send($mock);
100:             return sprintf(
101:                 "Would push mail \n\n%s\n\n%s\n to %s.",
102:                 $mock->sentMessages[0]['header_text'],
103:                 $mock->sentMessages[0]['body'],
104:                 $this->getAcl()
105:             );
106:         }
107: 
108:         $mail->send($this->_mail);
109:         return sprintf(
110:             'Pushed mail to %s.', $this->getAcl()
111:         );
112:     }
113: }
114: 
API documentation generated by ApiGen