diff --git a/phpgwapi/inc/class.egw_mailer.inc.php b/phpgwapi/inc/class.egw_mailer.inc.php index ddf9656965..2a74331808 100644 --- a/phpgwapi/inc/class.egw_mailer.inc.php +++ b/phpgwapi/inc/class.egw_mailer.inc.php @@ -28,7 +28,7 @@ class egw_mailer extends PHPMailer parent::__construct(true); // throw exceptions instead of echoing errors // setting EGroupware specific path for PHPMailer lang files - list($lang,$nation) = explode('-',$GLOBALS['egw_info']['user']['preferences']['common']['lang']); + if (!empty($GLOBALS['egw_info']['user']['preferences']['common']['lang'])) list($lang,$nation) = explode('-',$GLOBALS['egw_info']['user']['preferences']['common']['lang']); $lang_path = EGW_SERVER_ROOT.'/phpgwapi/lang/'; if ($nation && file_exists($lang_path."phpmailer.lang-$nation.php")) // atm. only for pt-br => br { @@ -198,4 +198,33 @@ class egw_mailer extends PHPMailer return parent::AddBCC($address, $name); } + + /** + * Adds a string or binary attachment (non-filesystem) to the list. + * This method can be used to attach ascii or binary data, + * such as a BLOB record from a database. + * @param string $string String attachment data. + * @param string $filename Name of the attachment. We assume that this is NOT a path + * @param string $encoding File encoding (see $Encoding). + * @param string $type File extension (MIME) type. + * @return void + */ + public function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') + { + // Append to $attachment array + //already encoded? + //TODO: maybe add an parameter to AddStringAttachment to avoid using the basename + $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $filename, $matches); + $this->attachment[] = array( + 0 => $string, + 1 => $filename, + 2 => ($x?basename($filename):$filename), + 3 => $encoding, + 4 => $type, + 5 => true, // isStringAttachment + 6 => 'attachment', + 7 => 0 + ); + } + } diff --git a/phpgwapi/inc/class.phpmailer.inc.php b/phpgwapi/inc/class.phpmailer.inc.php index 2b8292cb33..45875b87db 100644 --- a/phpgwapi/inc/class.phpmailer.inc.php +++ b/phpgwapi/inc/class.phpmailer.inc.php @@ -345,7 +345,7 @@ class PHPMailer { private $bcc = array(); private $ReplyTo = array(); private $all_recipients = array(); - private $attachment = array(); + protected $attachment = array(); //this way extended classes may use this variable private $CustomHeader = array(); private $message_type = ''; private $boundary = array(); @@ -1265,7 +1265,7 @@ class PHPMailer { $body = ''; if ($this->sign_key_file) { - $body .= $this->GetMailMIME(); + $body .= $this->GetMailMIME()."\n"; } $this->SetWordWrap(); @@ -1330,8 +1330,8 @@ class PHPMailer { $signed = tempnam("", "signed"); if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) { @unlink($file); - @unlink($signed); $body = file_get_contents($signed); + @unlink($signed); } else { @unlink($file); @unlink($signed);