summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--it_mail.class23
1 files changed, 8 insertions, 15 deletions
diff --git a/it_mail.class b/it_mail.class
index df40f27..b7f42bd 100644
--- a/it_mail.class
+++ b/it_mail.class
@@ -143,7 +143,7 @@ function add_body($text, $type = IT_MAIL_PLAIN)
* @param $p['name'] optional name of attached file
* @return 'cid:'.Content-ID of this attachment
*/
-function add_attachment($data, $p, $legacy_name = null)
+function add_attachment($data, $p = array(), $legacy_name = null)
{
if (!is_array($p)) # legacy mode: two scalars mime type / name
$p = array('mimetype' => $p) + ($legacy_name ? array('name' => $legacy_name) : array());
@@ -163,23 +163,16 @@ function add_attachment($data, $p, $legacy_name = null)
/**
* Add file attachment to this email message. Can be called repeatedly.
* @param $filename File to be attached
- * @param $name Name of attached file as stored in mail
- * @param $mimetype MIME-Type of attached file
+ * @param $p['dispositon'] optional Content-Disposition value: "inline" or "attachment"
+ * @param $p['mimetype'] MIME-Type of attached file
+ * @param $p['name'] Name of attached file as stored in mail
*/
-function add_file($filename, $mimetype = "application/octet-stream", $name = '')
+function add_file($filename, $p = array(), $legacy_name = null)
{
- if ($name == '')
- $name = basename($filename);
-
- if ($file = @fopen($filename, "r"))
- {
- if ($data = fread($file, @filesize($filename)))
- $result = $this->add_attachment($data, $mimetype, $name);
-
- fclose($file);
- }
+ if (!is_array($p)) # legacy mode: two scalars mime type / name
+ $p = array('mimetype' => $p) + ($legacy_name ? array('name' => $legacy_name) : array());
- return $result;
+ return $this->add_attachment(file_get_contents($filename), $p + array('name' => basename($filename)));
}