Changeset 5068 for trunk/services/class.mail.php
- Timestamp:
- 09/06/11 17:30:57 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/services/class.mail.php
r4445 r5068 1 1 <?php 2 /** 3 * 4 * Copyright (C) 2011 Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 5 * 6 * This program is free software; you can redistribute it and/or modify it under 7 * the terms of the GNU Affero General Public License version 3 as published by 8 * the Free Software Foundation with the addition of the following permission 9 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED 10 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 11 * WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. 12 * 13 * This program is distributed in the hope that it will be useful, but WITHOUT 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 * details. 17 * 18 * You should have received a copy of the GNU Affero General Public License 19 * along with this program; if not, see www.gnu.org/licenses or write to 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 21 * MA 02110-1301 USA. 22 * 23 * This code is based on the OpenXchange Connector and on the Prognus pSync 24 * Connector both developed by the community and licensed under the GPL 25 * version 2 or above as published by the Free Software Foundation. 26 * 27 * You can contact Prognus Software Livre headquarters at Av. Tancredo Neves, 28 * 6731, PTI, Bl. 05, Esp. 02, Sl. 10, Foz do Iguaçu - PR - Brasil or at 29 * e-mail address prognus@prognus.com.br. 30 * 31 * Serviço de email 32 * 33 * @package Services 34 * @license http://www.gnu.org/copyleft/gpl.html GPL 35 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 36 * @version 1.0 37 * @sponsor Caixa Econômica Federal 38 */ 39 2 40 3 41 if( !function_exists( 'zend_include' ) ) … … 14 52 zend_include( 'Zend/Mail.php' ); 15 53 54 55 /** 56 * Serviço de email 57 * 58 * Classe responsável pelas operações de email 59 * 60 * @package Service 61 * @license http://www.gnu.org/copyleft/gpl.html GPL 62 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 63 * @sponsor Caixa Econômica Federal 64 * @version 1.0 65 */ 16 66 class MailService extends Zend_Mail /*implements ConfigurationService, HookableService*/ 17 67 { 18 68 static $configuration = array( 'host' => '', 'port' => '', 'username' => '', 'password' => '' ); 19 69 20 public function __construct( $config = null) 21 { 22 if( !$config ) 23 { 24 require_once ( ROOT.'/header.inc.php' ); 25 26 $boemailadmin = CreateObject('emailadmin.bo'); 27 $emailadmin = $boemailadmin->getProfileList(); 28 $emailadmin = $boemailadmin->getProfile($emailadmin[0]['profileID']); 29 30 self::$configuration['host'] = $emailadmin['smtpServer']; 31 self::$configuration['port'] = $emailadmin['smtpPort']; 32 33 // self::$configuration['username'] = $emailadmin['user']; 34 // self::$configuration['password'] = $emailadmin['pass']; 35 // self::$configuration['name'] = $emailadmin['name']; 36 // self::$configuration['type'] = 'SMTP'; 37 38 // array_merge( $configuration, array( 'auth' => 'login' ) ); 39 40 zend_include( 'Zend/Mail/Transport/Smtp.php' ); 41 zend_include( 'Zend/Mail/Part.php' ); 42 set_include_path(LIBRARY); 43 parent::setDefaultTransport( new Zend_Mail_Transport_Smtp( self::$configuration['host'], self::$configuration ) ); 44 restore_include_path(); 45 } 46 47 else 48 $this->configure( $config ); 49 } 50 51 public function send( $to, $from, $subject, $body, $bcc = null, $cc = null, $isHTML = true ) 70 71 /** 72 * Construtor da classe 73 * 74 * @license http://www.gnu.org/copyleft/gpl.html GPL 75 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 76 * @sponsor Caixa Econômica Federal 77 * @param string $config 78 */ 79 public function __construct( $config = null) 80 { 81 if( !$config ) 82 { 83 require_once ( ROOT.'/header.inc.php' ); 84 85 $boemailadmin = CreateObject('emailadmin.bo'); 86 $emailadmin = $boemailadmin->getProfileList(); 87 $emailadmin = $boemailadmin->getProfile($emailadmin[0]['profileID']); 88 89 self::$configuration['host'] = $emailadmin['smtpServer']; 90 self::$configuration['port'] = $emailadmin['smtpPort']; 91 92 // self::$configuration['username'] = $emailadmin['user']; 93 // self::$configuration['password'] = $emailadmin['pass']; 94 // self::$configuration['name'] = $emailadmin['name']; 95 // self::$configuration['type'] = 'SMTP'; 96 97 // array_merge( $configuration, array( 'auth' => 'login' ) ); 98 99 zend_include( 'Zend/Mail/Transport/Smtp.php' ); 100 zend_include( 'Zend/Mail/Part.php' ); 101 set_include_path(LIBRARY); 102 parent::setDefaultTransport( new Zend_Mail_Transport_Smtp( self::$configuration['host'], self::$configuration ) ); 103 restore_include_path(); 104 } 105 106 else 107 $this->configure( $config ); 108 } 109 110 111 /** 112 * Método que envia a mensagem 113 * 114 * @license http://www.gnu.org/copyleft/gpl.html GPL 115 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 116 * @sponsor Caixa Econômica Federal 117 * @param string $to 118 * @param string $from 119 * @param string $subject 120 * @param string $body 121 * @param string $bcc 122 * @param string $cc 123 * @param string $isHTML 124 */ 125 public function send( $to, $from, $subject, $body, $bcc = null, $cc = null, $isHTML = true ) 52 126 { 53 127 set_include_path( LIBRARY ); 54 if( $body ) 55 { 56 if( $isHTML ) 57 parent::setBodyHtml( $body ); 58 59 else 60 parent::setBodyText( $body ); 61 } 62 63 if( $subject ) 64 parent::setSubject( $subject ); 65 66 if( !$from ) 67 $from = $GLOBALS['phpgw']->preferences->values['email']; 68 69 parent::setFrom( $from, self::getNameByMail( $from ) ); 70 71 //pra nao ter que fazer os ifs acima... 72 $destTypes = array( 'to', 'bcc', 'cc' ); 73 74 foreach( $destTypes as $destination ) 75 { 76 $dest = $$destination; 77 78 if( $dest ) 79 { 80 if( !is_array( $dest ) ) 81 $dest = array( $dest ); 82 83 foreach( $dest as $d ) 84 { 85 $addDestination = 'add'.ucfirst($destination); 86 87 parent::$addDestination( $d, self::getNameByMail( $d ) ); 88 } 89 } 90 } 91 92 parent::send(); 93 restore_include_path(); 94 } 95 96 public function configure( $config ) 97 { 98 if( !$config ) return( false ); 99 100 foreach( $config as $key => $value ) 101 { 102 if( $value && isset( self::$configuration[$key] ) ) 103 { 104 self::$configuration[$key] = $value; 105 } 106 } 128 if( $body ) 129 { 130 if( $isHTML ) 131 parent::setBodyHtml( $body ); 132 133 else 134 parent::setBodyText( $body ); 135 } 136 137 if( $subject ) 138 parent::setSubject( $subject ); 139 140 if( !$from ) 141 $from = $GLOBALS['phpgw']->preferences->values['email']; 142 143 parent::setFrom( $from, self::getNameByMail( $from ) ); 144 145 //pra nao ter que fazer os ifs acima... 146 $destTypes = array( 'to', 'bcc', 'cc' ); 147 148 foreach( $destTypes as $destination ) 149 { 150 $dest = $$destination; 151 152 if( $dest ) 153 { 154 if( !is_array( $dest ) ) 155 $dest = array( $dest ); 156 157 foreach( $dest as $d ) 158 { 159 $addDestination = 'add'.ucfirst($destination); 160 161 parent::$addDestination( $d, self::getNameByMail( $d ) ); 162 } 163 } 164 } 165 166 parent::send(); 167 restore_include_path(); 168 } 169 170 171 /** 172 * Método de configuração 173 * 174 * @license http://www.gnu.org/copyleft/gpl.html GPL 175 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 176 * @sponsor Caixa Econômica Federal 177 * @param string $config 178 */ 179 public function configure( $config ) 180 { 181 if( !$config ) return( false ); 182 183 foreach( $config as $key => $value ) 184 { 185 if( $value && isset( self::$configuration[$key] ) ) 186 { 187 self::$configuration[$key] = $value; 188 } 189 } 107 190 } 108 191 … … 110 193 public function getNameByMail( $mail ) 111 194 { 112 return( null );195 return( null ); 113 196 } 114 197 115 198 public function getAttachment( $attachment ) 116 199 { 117 return( null );200 return( null ); 118 201 } 119 202
Note: See TracChangeset
for help on using the changeset viewer.