diff options
author | Andrey Andreev <narf@bofh.bg> | 2012-04-02 10:14:04 +0200 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2012-04-02 10:14:04 +0200 |
commit | a9572fa67e4778f7d0a42898c603fddcb64660f8 (patch) | |
tree | 48a7785021377dd3e7f8fcd3ff41f3cf650c327b /system/libraries/Email.php | |
parent | 2efd029d012fedd421540d14b8a5759032c0b5c6 (diff) | |
parent | d3891f4f50e3cb3cfd1b6491088d759d586e2302 (diff) |
Merge upstream branch
Diffstat (limited to 'system/libraries/Email.php')
-rw-r--r-- | system/libraries/Email.php | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 8f383c939..48c3bf3ab 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -407,11 +407,11 @@ class CI_Email { * @param string * @return object */ - public function attach($filename, $disposition = '', $newname = NULL) + public function attach($filename, $disposition = '', $newname = NULL, $mime = '') { $this->_attach_name[] = array($filename, $newname); - $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); $this->_attach_disp[] = empty($disposition) ? 'attachment' : $disposition; // Can also be 'inline' Not sure if it matters + $this->_attach_type[] = $mime; return $this; } @@ -1049,29 +1049,39 @@ class CI_Email { $filename = $this->_attach_name[$i][0]; $basename = (is_null($this->_attach_name[$i][1])) ? basename($filename) : $this->_attach_name[$i][1]; $ctype = $this->_attach_type[$i]; + $file_content = ''; - if ( ! file_exists($filename)) + if ($this->_attach_type[$i] == '') { - $this->_set_error_message('lang:email_attachment_missing', $filename); - return FALSE; - } + if ( ! file_exists($filename)) + { + $this->_set_error_message('lang:email_attachment_missing', $filename); + return FALSE; + } + + $file = filesize($filename) +1; + if ( ! $fp = fopen($filename, FOPEN_READ)) + { + $this->_set_error_message('lang:email_attachment_unreadable', $filename); + return FALSE; + } + + $ctype = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); + $file_content = fread($fp, $file); + fclose($fp); + } + else + { + $file_content =& $this->_attach_content[$i]; + } $attachment[$z++] = "--".$this->_atc_boundary.$this->newline . "Content-type: ".$ctype."; " . "name=\"".$basename."\"".$this->newline . "Content-Disposition: ".$this->_attach_disp[$i].";".$this->newline . "Content-Transfer-Encoding: base64".$this->newline; - $file = filesize($filename) +1; - - if ( ! $fp = fopen($filename, FOPEN_READ)) - { - $this->_set_error_message('lang:email_attachment_unreadable', $filename); - return FALSE; - } - - $attachment[$z++] = chunk_split(base64_encode(fread($fp, $file))); - fclose($fp); + $attachment[$z++] = chunk_split(base64_encode($file_content)); } $body .= implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--"; |