summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2014-01-10 13:34:16 +0100
committerAndrey Andreev <narf@devilix.net>2014-01-10 13:34:16 +0100
commit2b21ee8dcf040d7c749e0010c46492d221d25552 (patch)
tree623ff905fa213482b6aad6920db0358fcf8d5ecb /system
parenta0a73c977ce25911f56948d89de817b3ca83adcb (diff)
parent9ad2fff4492e1e216aad0b03714ddfcb7a06d697 (diff)
Merge pull request #2807 from melounek/develop
Added Email::attach_cid() returning CID which enables to embed an attachment to html
Diffstat (limited to 'system')
-rw-r--r--system/libraries/Email.php89
1 files changed, 58 insertions, 31 deletions
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index efdbfd7c1..a41884f7d 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -718,14 +718,67 @@ class CI_Email {
*/
public function attach($filename, $disposition = '', $newname = NULL, $mime = '')
{
+ if ($mime === '')
+ {
+ if ( ! file_exists($filename))
+ {
+ $this->_set_error_message('lang:email_attachment_missing', $filename);
+ return FALSE;
+ }
+
+ if ( ! $fp = fopen($filename, FOPEN_READ))
+ {
+ $this->_set_error_message('lang:email_attachment_unreadable', $filename);
+ return FALSE;
+ }
+
+ $file_content = stream_get_contents($fp);
+ $mime = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION));
+ fclose($fp);
+ }
+ else
+ {
+ $file_content =& $filename; // buffered file
+ }
+
$this->_attachments[] = array(
'name' => array($filename, $newname),
'disposition' => empty($disposition) ? 'attachment' : $disposition, // Can also be 'inline' Not sure if it matters
- 'type' => $mime
+ 'type' => $mime,
+ 'content' => chunk_split(base64_encode($file_content))
);
return $this;
}
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Set and return id of attachment
+ *
+ * useful for attached inline pictures
+ *
+ * @param string $filename
+ * @return string
+ */
+ public function attach_cid($filename)
+ {
+ if ($this->multipart !== 'related')
+ {
+ $this->multipart = 'related'; // Thunderbird need this for inline images
+ }
+
+ for ($i = 0, $c = count($this->_attachments); $i < $c; $i++)
+ {
+ if ($this->_attachments[$i]['name'][0] === $filename)
+ {
+ $this->_attachments[$i]['cid'] = uniqid(basename($this->_attachments[$i]['name'][0]).'@');
+ return $this->_attachments[$i]['cid'];
+ }
+ }
+
+ return FALSE;
+ }
// --------------------------------------------------------------------
@@ -1361,41 +1414,15 @@ class CI_Email {
$filename = $this->_attachments[$i]['name'][0];
$basename = ($this->_attachments[$i]['name'][1] === NULL)
? basename($filename) : $this->_attachments[$i]['name'][1];
- $ctype = $this->_attachments[$i]['type'];
- $file_content = '';
-
- if ($ctype === '')
- {
- 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->_attachments[$i]['name'][0];
- }
$attachment[$z++] = '--'.$this->_atc_boundary.$this->newline
- .'Content-type: '.$ctype.'; '
+ .'Content-type: '.$this->_attachments[$i]['type'].'; '
.'name="'.$basename.'"'.$this->newline
.'Content-Disposition: '.$this->_attachments[$i]['disposition'].';'.$this->newline
- .'Content-Transfer-Encoding: base64'.$this->newline;
+ .'Content-Transfer-Encoding: base64'.$this->newline
+ .(empty($this->_attachments[$i]['cid']) ? '' : 'Content-ID: <'.$this->_attachments[$i]['cid'].'>'.$this->newline);
- $attachment[$z++] = chunk_split(base64_encode($file_content));
+ $attachment[$z++] = $this->_attachments[$i]['content'];
}
$body .= implode($this->newline, $attachment).$this->newline.'--'.$this->_atc_boundary.'--';