summaryrefslogtreecommitdiff
path: root/it_mail.class
diff options
context:
space:
mode:
Diffstat (limited to 'it_mail.class')
-rw-r--r--it_mail.class28
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']));
}