allow to add attachments by giving a path, instead of a string, eg. egw_vfs::PREFIX.$path for a vfs path in $path

This commit is contained in:
Ralf Becker 2011-06-23 09:05:25 +00:00
parent 3d09b732e3
commit f25185f0b9
2 changed files with 35 additions and 20 deletions

View File

@ -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;
}

View File

@ -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));
}
}