From 694e6ad09d77ee8e3ca5eebccbdefe6ff4fe827c Mon Sep 17 00:00:00 2001 From: Christian Weber Date: Thu, 8 Dec 2011 18:44:46 +0000 Subject: add_attachment() re-factored to take $p as 2nd arg, add support for specifying content disposition --- it_mail.class | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'it_mail.class') 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'])); } -- cgit v1.2.3