fix bug regarding certain russian filenames when forwarding/compose as new, as AddStringAttachment is using basename to make sure only a filename will be used for the namepart; some fixes backported from phpmailer5.2.1

This commit is contained in:
Klaus Leithoff 2012-08-14 13:56:02 +00:00
parent 73f26d2432
commit 22a5fbb4b3
2 changed files with 48 additions and 19 deletions

View File

@ -28,7 +28,7 @@ class egw_mailer extends PHPMailer
parent::__construct(true); // throw exceptions instead of echoing errors parent::__construct(true); // throw exceptions instead of echoing errors
// setting EGroupware specific path for PHPMailer lang files // 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/'; $lang_path = EGW_SERVER_ROOT.'/phpgwapi/lang/';
if ($nation && file_exists($lang_path."phpmailer.lang-$nation.php")) // atm. only for pt-br => br if ($nation && file_exists($lang_path."phpmailer.lang-$nation.php")) // atm. only for pt-br => br
{ {
@ -176,4 +176,33 @@ class egw_mailer extends PHPMailer
return parent::AddBCC($address, $name); 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
);
}
} }

View File

@ -312,7 +312,7 @@ class PHPMailer {
private $bcc = array(); private $bcc = array();
private $ReplyTo = array(); private $ReplyTo = array();
private $all_recipients = array(); private $all_recipients = array();
private $attachment = array(); protected $attachment = array(); //this way extended classes may use this variable
private $CustomHeader = array(); private $CustomHeader = array();
private $message_type = ''; private $message_type = '';
private $boundary = array(); private $boundary = array();
@ -1199,7 +1199,7 @@ class PHPMailer {
$body = ''; $body = '';
if ($this->sign_key_file) { if ($this->sign_key_file) {
$body .= $this->GetMailMIME(); $body .= $this->GetMailMIME()."\n";
} }
$this->SetWordWrap(); $this->SetWordWrap();
@ -1262,8 +1262,8 @@ class PHPMailer {
$signed = tempnam("", "signed"); $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)) { 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($file);
@unlink($signed);
$body = file_get_contents($signed); $body = file_get_contents($signed);
@unlink($signed);
} else { } else {
@unlink($file); @unlink($file);
@unlink($signed); @unlink($signed);