get notifications working again with new egw_mailer

This commit is contained in:
Ralf Becker 2014-11-25 14:22:16 +00:00
parent 9c534850be
commit 51c4e0e580
4 changed files with 42 additions and 49 deletions

View File

@ -96,7 +96,6 @@ class notifications_ajax {
$this->config = (object)config::read(self::_appname); $this->config = (object)config::read(self::_appname);
$prefs = new preferences($this->recipient->account_id); $prefs = new preferences($this->recipient->account_id);
$preferences = $prefs->read();
$this->preferences = $prefs->read(); $this->preferences = $prefs->read();
$this->db = $GLOBALS['egw']->db; $this->db = $GLOBALS['egw']->db;

View File

@ -74,7 +74,7 @@ class notifications_email implements notifications_iface {
{ {
unset($this->mail); unset($this->mail);
} }
$this->mail = new send(); $this->mail = new egw_mailer();
} }
/** /**
@ -85,52 +85,26 @@ class notifications_email implements notifications_iface {
* @param array $_links * @param array $_links
* @param array $_attachments * @param array $_attachments
*/ */
public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false) { public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false)
//$_messages['plain'] = $_messages['plain']."\nSent By:".php_uname(); {
//$_messages['html'] = $_messages['html']."\n<hr>\n Sent by:".php_uname();
$body_plain = $_messages['plain'].$this->render_links($_links, false, $this->preferences->external_mailclient); $body_plain = $_messages['plain'].$this->render_links($_links, false, $this->preferences->external_mailclient);
$body_html = "<html><body>\n".$_messages['html'].$this->render_links($_links, true, $this->preferences->external_mailclient)."</body>\n</html>\n"; $body_html = "<html><body>\n".$_messages['html'].$this->render_links($_links, true, $this->preferences->external_mailclient)."</body>\n</html>\n";
$this->mail->ClearAddresses(); $this->mail->ClearAddresses();
$this->mail->ClearAttachments(); $this->mail->ClearAttachments();
$this->mail->AddAddress($this->recipient->account_email, $this->recipient->account_fullname); $this->mail->addAddress($this->recipient->account_email, $this->recipient->account_fullname);
$this->mail->AddCustomHeader('X-EGroupware-type: notification-mail'); $this->mail->addHeader('X-EGroupware-Type', 'notification-mail');
$this->mail->AddCustomHeader('X-EGroupware-Install: '.$GLOBALS['egw_info']['server']['install_id'].'@'.$GLOBALS['egw_info']['server']['default_domain']); $this->mail->addHeader('X-EGroupware-Install', $GLOBALS['egw_info']['server']['install_id'].'@'.$GLOBALS['egw_info']['server']['default_domain']);
//$this->mail->AddCustomHeader('X-EGroupware-URL: notification-mail'); //$this->mail->AddHeader('X-EGroupware-URL', 'notification-mail');
//$this->mail->AddCustomHeader('X-EGroupware-Tracker: notification-mail'); //$this->mail->AddHeader('X-EGroupware-Tracker', 'notification-mail');
//error_log(__METHOD__.__LINE__."preparing notification message via email.".array2string($this->mail)); //error_log(__METHOD__.__LINE__."preparing notification message via email.".array2string($this->mail));
if (!$this->mail->From)
{ $this->mail->setFrom($this->sender->account_email, $this->sender->account_fullname);
$this->mail->From = $this->sender->account_email;
$this->mail->FromName = $this->sender->account_fullname; $this->mail->addHeader('Subject', $_subject);
} $this->mail->setHtmlBody($body_html, null, false); // no automatic alternativ
else $this->mail->setBody($body_plain);
{
if ($this->sender->account_email)
{
$this->mail->ClearReplyTos();
$this->mail->AddReplyTo($this->sender->account_email,$this->sender->account_fullname);
// as we set the replyTo, we set (fake) the FromName accordingly
if ($this->sender->account_fullname) $this->mail->FromName = $this->sender->account_fullname;
}
}
//error_log(__METHOD__.__LINE__."preparing notification message via email.".array2string($this->mail));
$this->mail->Subject = $_subject;
// add iCal invitation as mulitpart alternative for calendar notifications
if ($_attachments && stripos($_attachments[0]->type,"text/calendar; method=")!==false)
{
$this->mail->AltExtended = $_attachments[0]->string;
$this->mail->AltExtendedContentType = $_attachments[0]->type;
unset($_attachments[0]);
$this->mail->Body = $body_plain;
}
else
{
$this->mail->IsHTML();
$this->mail->Body = $body_html;
$this->mail->AltBody = $body_plain;
}
if(is_array($_attachments) && count($_attachments) > 0) if(is_array($_attachments) && count($_attachments) > 0)
{ {
foreach($_attachments as $attachment) foreach($_attachments as $attachment)
@ -146,11 +120,7 @@ class notifications_email implements notifications_iface {
} }
} }
//error_log(__METHOD__.__LINE__."about sending notification message via email.".array2string($this->mail)); //error_log(__METHOD__.__LINE__."about sending notification message via email.".array2string($this->mail));
if(!$error=$this->mail->Send()) $this->mail->send();
{
//error_log(__METHOD__.__LINE__." Failed sending notification message via email.$error".array2string($this->mail->ErrorInfo));
throw new Exception("Failed sending notification message via email.$error".print_r($this->mail->ErrorInfo,true));
}
} }
/** /**
@ -174,9 +144,8 @@ class notifications_email implements notifications_iface {
$rendered_links = array(); $rendered_links = array();
foreach($_links as $link) { foreach($_links as $link) {
if($_render_external || ! $link->popup) { $link->view['no_popup'] = 1; } if($_render_external || ! $link->popup) { $link->view['no_popup'] = 1; }
$url = html::link('/index.php', $link->view);
// do not expose sensitive data // do not expose sensitive data
$url = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',$url); $url = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',html::link('/index.php', $link->view));
// complete missing protocol and domain part if needed // complete missing protocol and domain part if needed
if ($url{0} == '/' && $_render_external) { if ($url{0} == '/' && $_render_external) {
$url = ($_SERVER['HTTPS'] || $GLOBALS['egw_info']['server']['enforce_ssl'] ? 'https://' : 'http://'). $url = ($_SERVER['HTTPS'] || $GLOBALS['egw_info']['server']['enforce_ssl'] ? 'https://' : 'http://').

View File

@ -45,6 +45,9 @@ class egw_mailer extends Horde_Mime_Mail
*/ */
function __construct($account=null) function __construct($account=null)
{ {
// Horde use locale for translation of error messages
common::setlocale(LC_MESSAGES);
parent::__construct(); parent::__construct();
$this->_headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']); $this->_headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
@ -299,6 +302,8 @@ class egw_mailer extends Horde_Mime_Mail
* Send mail, injecting mail transport from account * Send mail, injecting mail transport from account
* *
* @ToDo hooks port hook from SmtpSend * @ToDo hooks port hook from SmtpSend
* @throws egw_exception_not_found for no smtp account available
* @throws Horde_Mime_Exception
*/ */
function send() function send()
{ {
@ -313,6 +318,17 @@ class egw_mailer extends Horde_Mime_Mail
$this->__construct($this->account); $this->__construct($this->account);
} }
/**
* Get value of a header set with addHeader()
*
* @param string $header
* @return string
*/
function getHeader($header)
{
return $this->_headers->getString($header);
}
/** /**
* Get the raw email data sent by this object. * Get the raw email data sent by this object.
* *

View File

@ -824,4 +824,13 @@ if (!function_exists('_')) {
{ {
} }
function dgettext($domain, $message)
{
return $message;
}
function ngettext($singular, $plural, $number)
{
return $number > 1 ? $plural : $singular;
}
} }