From f25185f0b9af4a453280b2ed7640d53d52f477fa Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 23 Jun 2011 09:05:25 +0000 Subject: [PATCH] allow to add attachments by giving a path, instead of a string, eg. egw_vfs::PREFIX.$path for a vfs path in $path --- notifications/inc/class.notifications.inc.php | 31 +++++++++++-------- .../inc/class.notifications_email.inc.php | 24 +++++++++----- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/notifications/inc/class.notifications.inc.php b/notifications/inc/class.notifications.inc.php index e0b7a64b8e..e4adb9017e 100644 --- a/notifications/inc/class.notifications.inc.php +++ b/notifications/inc/class.notifications.inc.php @@ -298,11 +298,13 @@ final class notifications { $this->attachments = array(); // clear array if set foreach($_attachments as $attachment) { if(is_array($attachment)) { - $this->add_attachment( $attachment['string'], - $attachment['filename'], - $attachment['encoding'], - $attachment['type'] - ); + $this->add_attachment( + $attachment['string'], + $attachment['filename'], + $attachment['encoding'], + $attachment['type'], + $attachment['path'] + ); } } return true; @@ -313,18 +315,21 @@ final class notifications { * This method can be used to attach ascii or binary data, * such as a BLOB record from a database. * - * @param string $_string Attachment data. + * @param string $_string Attachment data or null to use $_path * @param string $_filename Name of the attachment. * @param string $_encoding File encoding (see $Encoding). * @param string $_type File extension (MIME) type. + * @param string $_path optional path to attachment, if !$_string */ - public function add_attachment($_string, $_filename, $_encoding = "base64", $_type = "application/octet-stream") { - if(!$_string || !$_filename) { return false; } - $this->attachments[] = (object)array( 'string' => $_string, - 'filename' => $_filename, - 'encoding' => $_encoding, - 'type' => $_type, - ); + public function add_attachment($_string, $_filename, $_encoding = "base64", $_type = "application/octet-stream", $_path=null) { + if(!$_string && (!$_path || !file_exists($_path)) || !$_filename) return false; + $this->attachments[] = (object)array( + 'string' => $_string, + 'filename' => $_filename, + 'encoding' => $_encoding ? $_encoding : "base64", + 'type' => $_type ? $_type : "application/octet-stream", + 'path' => $_path, + ); return true; } diff --git a/notifications/inc/class.notifications_email.inc.php b/notifications/inc/class.notifications_email.inc.php index a55534eca2..ca8ddd86c7 100644 --- a/notifications/inc/class.notifications_email.inc.php +++ b/notifications/inc/class.notifications_email.inc.php @@ -44,14 +44,14 @@ class notifications_email implements notifications_iface { /** * holds preferences object of user to notify * - * @var object + * @var preferences */ private $preferences; /** * holds mail object * - * @var object + * @var send */ private $mail; @@ -95,7 +95,7 @@ class notifications_email implements notifications_iface { $this->mail->AddCustomHeader('X-eGroupWare-type: notification-mail'); $this->mail->From = $this->sender->account_email; $this->mail->FromName = $this->sender->account_fullname; - $this->mail->Subject = $this->mail->encode_subject($_subject); + $this->mail->Subject = $_subject; //error_log(__METHOD__.__LINE__.array2string($_attachments)); if ($_attachments && stripos($_attachments[0]->type,"text/calendar; method=")!==false) { @@ -106,12 +106,22 @@ class notifications_email implements notifications_iface { $this->mail->IsHTML(true); $this->mail->Body = $body_html; $this->mail->AltBody = $body_plain; - if(is_array($_attachments) && count($_attachments) > 0) { - foreach($_attachments as $attachment) { - $this->mail->AddStringAttachment($attachment->string, $attachment->filename, $attachment->encoding, $attachment->type); + if(is_array($_attachments) && count($_attachments) > 0) + { + foreach($_attachments as $attachment) + { + if ($attachment->string) + { + $this->mail->AddStringAttachment($attachment->string, $attachment->filename, $attachment->encoding, $attachment->type); + } + elseif($attachment->path) + { + $this->mail->AddAttachment($attachment->path, $attachment->filename, $attachment->encoding, $attachment->type); + } } } - if(!$error=$this->mail->Send()) { + if(!$error=$this->mail->Send()) + { throw new Exception("Failed sending notification message via email.$error".print_r($this->mail->ErrorInfo,true)); } }