diff options
author | Christian Weber | 2011-12-08 18:44:46 +0000 |
---|---|---|
committer | Christian Weber | 2011-12-08 18:44:46 +0000 |
commit | 694e6ad09d77ee8e3ca5eebccbdefe6ff4fe827c (patch) | |
tree | cff0d452ecc791aff5d9a00c30a239451ae13a0d | |
parent | e79ea1263b41976cb53ebba155f6d0b541e69602 (diff) | |
download | itools-694e6ad09d77ee8e3ca5eebccbdefe6ff4fe827c.tar.gz itools-694e6ad09d77ee8e3ca5eebccbdefe6ff4fe827c.tar.bz2 itools-694e6ad09d77ee8e3ca5eebccbdefe6ff4fe827c.zip |
add_attachment() re-factored to take $p as 2nd arg, add support for specifying content disposition
-rw-r--r-- | it_mail.class | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/it_mail.class b/it_mail.class index 81c9a67..df40f27 100644 --- a/it_mail.class +++ b/it_mail.class @@ -138,19 +138,25 @@ function add_body($text, $type = IT_MAIL_PLAIN) /** * Add attachment to this email message. Can be called repeatedly. * @param $data Data to be attached - * @param $name Name of attached file - * @param $mimetype MIME-Type of attached file + * @param $p['dispositon'] optional Content-Disposition value: "inline" or "attachment" + * @param $p['mimetype'] optional MIME-Type of attached file + * @param $p['name'] optional name of attached file * @return 'cid:'.Content-ID of this attachment */ -function add_attachment($data, $mimetype = "application/octet-stream", $name = '') +function add_attachment($data, $p, $legacy_name = null) { - if ($name == '') - $name = 'Attachment' . (count($this->attachments) + 1); - - $cid = md5(uniqid(rand())); - $this->attachments[] = array ('mimetype' => $mimetype, 'data' => $data, 'name' => $name, 'cid' => $cid); - - return 'cid:'.$cid; + if (!is_array($p)) # legacy mode: two scalars mime type / name + $p = array('mimetype' => $p) + ($legacy_name ? array('name' => $legacy_name) : array()); + + $this->attachments[] = $p + array( + 'cid' => $cid = md5(uniqid(rand())), + 'data' => $data, + 'disposition' => "inline", + 'mimetype' => "application/octet-stream", + 'name' => "Attachment" . (count($this->attachments) + 1), + ); + + return "cid:$cid"; } @@ -277,7 +283,7 @@ function send($p = array()) foreach ($this->attachments as $attachment) { - $text .= "\n--$boundary\nContent-Type: {$attachment['mimetype']}; name=\"{$attachment['name']}\"\nContent-Transfer-Encoding: base64\nContent-ID: <{$attachment['cid']}>\nContent-Disposition: inline; filename=\"{$attachment['name']}\"\n\n"; + $text .= "\n--$boundary\nContent-Type: {$attachment['mimetype']}; name=\"{$attachment['name']}\"\nContent-Transfer-Encoding: base64\nContent-ID: <{$attachment['cid']}>\nContent-Disposition: {$attachment['disposition']}; filename=\"{$attachment['name']}\"\n\n"; $text .= chunk_split(base64_encode($attachment['data'])); } |