diff -r 5b37998e522e -r 162c1de6545a web/lib/Zend/Application/Resource/Mail.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/lib/Zend/Application/Resource/Mail.php Fri Mar 11 15:05:35 2011 +0100 @@ -0,0 +1,146 @@ +getMail(); + } + + /** + * + * @return Zend_Mail_Transport_Abstract|null + */ + public function getMail() + { + if (null === $this->_transport) { + $options = $this->getOptions(); + foreach($options as $key => $option) { + $options[strtolower($key)] = $option; + } + $this->setOptions($options); + + if(isset($options['transport']) && + !is_numeric($options['transport'])) + { + $this->_transport = $this->_setupTransport($options['transport']); + if(!isset($options['transport']['register']) || + $options['transport']['register'] == '1' || + (isset($options['transport']['register']) && + !is_numeric($options['transport']['register']) && + (bool) $options['transport']['register'] == true)) + { + Zend_Mail::setDefaultTransport($this->_transport); + } + } + + $this->_setDefaults('from'); + $this->_setDefaults('replyTo'); + } + + return $this->_transport; + } + + protected function _setDefaults($type) { + $key = strtolower('default' . $type); + $options = $this->getOptions(); + + if(isset($options[$key]['email']) && + !is_numeric($options[$key]['email'])) + { + $method = array('Zend_Mail', 'setDefault' . ucfirst($type)); + if(isset($options[$key]['name']) && + !is_numeric($options[$key]['name'])) + { + call_user_func($method, $options[$key]['email'], + $options[$key]['name']); + } else { + call_user_func($method, $options[$key]['email']); + } + } + } + + protected function _setupTransport($options) + { + if(!isset($options['type'])) { + $options['type'] = 'sendmail'; + } + + $transportName = $options['type']; + if(!Zend_Loader_Autoloader::autoload($transportName)) + { + $transportName = ucfirst(strtolower($transportName)); + + if(!Zend_Loader_Autoloader::autoload($transportName)) + { + $transportName = 'Zend_Mail_Transport_' . $transportName; + if(!Zend_Loader_Autoloader::autoload($transportName)) { + throw new Zend_Application_Resource_Exception( + "Specified Mail Transport '{$transportName}'" + . 'could not be found' + ); + } + } + } + + unset($options['type']); + + switch($transportName) { + case 'Zend_Mail_Transport_Smtp': + if(!isset($options['host'])) { + throw new Zend_Application_Resource_Exception( + 'A host is necessary for smtp transport,' + .' but none was given'); + } + + $transport = new $transportName($options['host'], $options); + break; + case 'Zend_Mail_Transport_Sendmail': + default: + $transport = new $transportName($options); + break; + } + + return $transport; + } +}