From 27fb76829df0d6bd9246091936694db88efd42df Mon Sep 17 00:00:00 2001 From: Rob Mayhue Date: Thu, 8 May 2014 10:17:28 -0400 Subject: [PATCH] Add alias filename for email attachemnt Added a new $alias param to the SMTP attach method which will allow to set the filename of the attachment to a different filename other then the file system filename. This is useful in cases where the file system filename is hashed and/or versioned in some way and the attachment filename needs to be different. --- lib/smtp.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/smtp.php b/lib/smtp.php index d9041b5e1..5eb66fac5 100644 --- a/lib/smtp.php +++ b/lib/smtp.php @@ -130,10 +130,13 @@ protected function dialog($cmd=NULL,$log=TRUE) { * Add e-mail attachment * @return NULL * @param $file + * @param $alias **/ - function attach($file) { + function attach($file,$alias=NULL) { if (!is_file($file)) user_error(sprintf(self::E_Attach,$file)); + if (is_string($alias)) + $file=array($alias=>$file); $this->attachments[]=$file; } @@ -217,11 +220,19 @@ function send($message,$log=TRUE) { $out.=$eol; $out.=$message.$eol; foreach ($this->attachments as $attachment) { + if (is_array($attachment)) { + list($alias, $file) = each($attachment); + $filename = $alias; + $attachment = $file; + } + else { + $filename = basename($attachment); + } $out.='--'.$hash.$eol; $out.='Content-Type: application/octet-stream'.$eol; $out.='Content-Transfer-Encoding: base64'.$eol; $out.='Content-Disposition: attachment; '. - 'filename="'.basename($attachment).'"'.$eol; + 'filename="'.$filename.'"'.$eol; $out.=$eol; $out.=chunk_split( base64_encode(file_get_contents($attachment))).$eol;