summaryrefslogtreecommitdiff
path: root/program/steps/mail
diff options
context:
space:
mode:
Diffstat (limited to 'program/steps/mail')
-rw-r--r--program/steps/mail/attachments.inc74
-rw-r--r--program/steps/mail/compose.inc50
-rw-r--r--program/steps/mail/func.inc176
-rw-r--r--program/steps/mail/sendmail.inc87
-rw-r--r--program/steps/mail/show.inc4
5 files changed, 202 insertions, 189 deletions
diff --git a/program/steps/mail/attachments.inc b/program/steps/mail/attachments.inc
index f6e29f9d7..6d58edc8e 100644
--- a/program/steps/mail/attachments.inc
+++ b/program/steps/mail/attachments.inc
@@ -28,46 +28,45 @@ if (!$_SESSION['compose']) {
// remove an attachment
if ($RCMAIL->action=='remove-attachment')
{
- if (preg_match('/^rcmfile([0-9]+)$/', $_POST['_file'], $regs))
- {
+ $id = 'undefined';
+ if (preg_match('/^rcmfile(\w+)$/', $_POST['_file'], $regs))
$id = $regs[1];
- if (is_array($_SESSION['compose']['attachments'][$id]))
- {
- @unlink($_SESSION['compose']['attachments'][$id]['path']);
+ if ($attachment = $_SESSION['compose']['attachments'][$id])
+ $attachment = $RCMAIL->plugins->exec_hook('remove_attachment', $attachment);
+ if ($attachment['status']) {
+ if (is_array($_SESSION['compose']['attachments'][$id])) {
unset($_SESSION['compose']['attachments'][$id]);
$OUTPUT->command('remove_from_attachment_list', "rcmfile$id");
- $OUTPUT->send();
}
}
+
+ $OUTPUT->send();
exit;
}
if ($RCMAIL->action=='display-attachment')
{
- if (preg_match('/^rcmfile([0-9]+)$/', $_GET['_file'], $regs))
- {
+ $id = 'undefined';
+ if (preg_match('/^rcmfile(\w+)$/', $_GET['_file'], $regs))
$id = $regs[1];
- if (is_array($_SESSION['compose']['attachments'][$id]))
- {
- $apath = $_SESSION['compose']['attachments'][$id]['path'];
- header('Content-Type: ' . $_SESSION['compose']['attachments'][$id]['mimetype']);
- header('Content-Length: ' . filesize($apath));
- readfile($apath);
- }
+ if ($attachment = $_SESSION['compose']['attachments'][$id])
+ $attachment = $RCMAIL->plugins->exec_hook('display_attachment', $attachment);
+
+ if ($attachment['status']) {
+ $size = $attachment['data'] ? strlen($attachment['data']) : @filesize($attachment['path']);
+ header('Content-Type: ' . $attachment['mimetype']);
+ header('Content-Length: ' . $size);
+
+ if ($attachment['data'])
+ echo $attachment['data'];
+ else if ($attachment['path'])
+ readfile($attachment['path']);
}
exit;
}
// attachment upload action
-// use common temp dir for file uploads
-$temp_dir = unslashify($CONFIG['temp_dir']);
-
-// #1484529: we need absolute path on Windows for move_uploaded_file()
-if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
- $temp_dir = realpath($temp_dir);
-}
-
if (!is_array($_SESSION['compose']['attachments'])) {
$_SESSION['compose']['attachments'] = array();
}
@@ -77,15 +76,20 @@ $OUTPUT->reset();
if (is_array($_FILES['_attachments']['tmp_name'])) {
foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath) {
- $tmpfname = tempnam($temp_dir, 'rcmAttmnt');
- if (move_uploaded_file($filepath, $tmpfname) && file_exists($tmpfname)) {
- $id = count($_SESSION['compose']['attachments']);
- $_SESSION['compose']['attachments'][] = array(
- 'name' => $_FILES['_attachments']['name'][$i],
- 'mimetype' => rc_mime_content_type($tmpfname, $_FILES['_attachments']['name'][$i], $_FILES['_attachments']['type'][$i]),
- 'path' => $tmpfname,
- );
-
+ $attachment = array(
+ 'path' => $filepath,
+ 'name' => $_FILES['_attachments']['name'][$i],
+ 'mimetype' => rc_mime_content_type($tmpfname, $_FILES['_attachments']['type'][$i])
+ );
+
+ $attachment = $RCMAIL->plugins->exec_hook('upload_attachment', $attachment);
+ if ($attachment['status']) {
+ $id = $attachment['id'];
+
+ // store new attachment in session
+ unset($attachment['status']);
+ $_SESSION['compose']['attachments'][$id] = $attachment;
+
if (is_file($icon = $CONFIG['skin_path'] . '/images/icons/remove-attachment.png')) {
$button = html::img(array(
'src' => $icon,
@@ -99,11 +103,11 @@ if (is_array($_FILES['_attachments']['tmp_name'])) {
$content = html::a(array(
'href' => "#delete",
- 'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%d', this)", JS_OBJECT_NAME, $id),
+ 'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%s', this)", JS_OBJECT_NAME, $id),
'title' => rcube_label('delete'),
), $button);
-
- $content .= Q($_FILES['_attachments']['name'][$i]);
+
+ $content .= Q($attachment['name']);
$OUTPUT->command('add2attachment_list', "rcmfile$id", $content);
}
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 49c4c3011..c93fa9be2 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -594,8 +594,6 @@ function rcmail_write_compose_attachments(&$message, $bodyIsHtml)
global $OUTPUT;
$cid_map = array();
- $id = 0;
-
foreach ((array)$message->mime_parts as $pid => $part)
{
if (($part->ctype_primary != 'message' || !$bodyIsHtml) &&
@@ -603,16 +601,14 @@ function rcmail_write_compose_attachments(&$message, $bodyIsHtml)
|| (empty($part->disposition) && $part->filename)))
{
if ($attachment = rcmail_save_attachment($message, $pid)) {
- $_SESSION['compose']['attachments'][$id] = $attachment;
- if ($bodyIsHtml && $part->filename && $part->content_id) {
- $cid_map['cid:'.$part->content_id] =
- $OUTPUT->app->comm_path.'&_action=display-attachment&_file=rcmfile'.$id;
+ $_SESSION['compose']['attachments'][$attachment['id']] = $attachment;
+ if ($bodyIsHtml && $part->filename && $part->content_id) {
+ $cid_map['cid:'.$part->content_id] = $OUTPUT->app->comm_path.'&_action=display-attachment&_file=rcmfile'.$attachment['id'];
}
- $id++;
}
}
}
-
+
$_SESSION['compose']['forward_attachments'] = true;
return $cid_map;
@@ -624,15 +620,11 @@ function rcmail_write_inline_attachments(&$message)
global $OUTPUT;
$cid_map = array();
- $id = 0;
-
foreach ((array)$message->mime_parts as $pid => $part) {
if ($part->content_id && $part->filename) {
if ($attachment = rcmail_save_attachment($message, $pid)) {
- $_SESSION['compose']['attachments'][$id] = $attachment;
- $cid_map['cid:'.$part->content_id] =
- $OUTPUT->app->comm_path.'&_action=display-attachment&_file=rcmfile'.$id;
- $id++;
+ $_SESSION['compose']['attachments'][$attachment['id']] = $attachment;
+ $cid_map['cid:'.$part->content_id] = $OUTPUT->app->comm_path.'&_action=display-attachment&_file=rcmfile'.$attachment['id'];
}
}
}
@@ -642,24 +634,22 @@ function rcmail_write_inline_attachments(&$message)
function rcmail_save_attachment(&$message, $pid)
{
- global $RCMAIL;
-
- $temp_dir = unslashify($RCMAIL->config->get('temp_dir'));
- $tmp_path = tempnam($temp_dir, 'rcmAttmnt');
$part = $message->mime_parts[$pid];
- if ($fp = fopen($tmp_path, 'w'))
- {
- $message->get_part_content($pid, $fp);
- fclose($fp);
-
- return array(
- 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
- 'name' => $part->filename,
- 'path' => $tmp_path,
- 'content_id' => $part->content_id
- );
+ $attachment = array(
+ 'name' => $part->filename,
+ 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
+ 'content_id' => $part->content_id,
+ 'data' => $message->get_part_content($pid),
+ );
+
+ $attachment = rcmail::get_instance()->plugins->exec_hook('save_attachment', $attachment);
+ if ($attachment['status']) {
+ unset($attachment['data'], $attachment['status']);
+ return $attachment;
}
+
+ return false;
}
@@ -739,7 +729,7 @@ function rcmail_compose_attachment_list($attrib)
html::a(array(
'href' => "#delete",
'title' => rcube_label('delete'),
- 'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%d', this)", JS_OBJECT_NAME, $id)),
+ 'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%s', this)", JS_OBJECT_NAME, $id)),
$button) . Q($a_prop['name']));
}
}
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 8931cfa4e..28ae70ca3 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -730,71 +730,86 @@ function rcmail_wash_html($html, $p = array(), $cid_replaces)
*/
function rcmail_print_body($part, $p = array())
{
- $p += array('safe' => false, 'plain' => false, 'inline_html' => true);
+ global $RCMAIL;
+
+ // trigger plugin hook
+ $data = $RCMAIL->plugins->exec_hook('message_part_before',
+ array('type' => $part->ctype_secondary, 'body' => $part->body) + $p + array('safe' => false, 'plain' => false, 'inline_html' => true));
// convert html to text/plain
- if ($part->ctype_secondary == 'html' && $p['plain']) {
- $txt = new html2text($part->body, false, true);
+ if ($data['type'] == 'html' && $data['plain']) {
+ $txt = new html2text($data['body'], false, true);
$body = $txt->get_text();
$part->ctype_secondary = 'plain';
}
// text/html
- else if ($part->ctype_secondary == 'html') {
- return rcmail_wash_html($part->body, $p, $part->replaces);
+ else if ($data['type'] == 'html') {
+ $body = rcmail_wash_html($data['body'], $data, $part->replaces);
+ $part->ctype_secondary = $data['type'];
}
// text/enriched
- else if ($part->ctype_secondary=='enriched') {
+ else if ($data['type'] == 'enriched') {
$part->ctype_secondary = 'html';
require_once('lib/enriched.inc');
- return Q(enriched_to_html($part->body), 'show');
+ $body = Q(enriched_to_html($data['body']), 'show');
}
- else
+ else {
+ // assert plaintext
$body = $part->body;
+ $part->ctype_secondary = $data['type'] = 'plain';
+ }
+
+ // free some memory (hopefully)
+ unset($data['body']);
- /**** assert plaintext ****/
-
- // make links and email-addresses clickable
- $replacements = new rcube_string_replacer;
-
- $url_chars = 'a-z0-9_\-\+\*\$\/&%=@#:;';
- $url_chars_within = '\?\.~,!';
-
- // search for patterns like links and e-mail addresses
- $body = preg_replace_callback("/([\w]+):\/\/([a-z0-9\-\.]+[a-z]{2,4}([$url_chars$url_chars_within]*[$url_chars])?)/i", array($replacements, 'link_callback'), $body);
- $body = preg_replace_callback("/([^\/:]|\s)(www\.)([a-z0-9\-]{2,}[a-z]{2,4}([$url_chars$url_chars_within]*[$url_chars])?)/i", array($replacements, 'link_callback'), $body);
- $body = preg_replace_callback('/([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9]\\.[a-z]{2,5})/i', array($replacements, 'mailto_callback'), $body);
-
- // split body into single lines
- $a_lines = preg_split('/\r?\n/', $body);
- $quote_level = 0;
-
- // colorize quoted parts
- for ($n=0; $n < sizeof($a_lines); $n++) {
- $line = $a_lines[$n];
- $quotation = '';
- $q = 0;
+ // plaintext postprocessing
+ if ($part->ctype_secondary == 'plain') {
+ // make links and email-addresses clickable
+ $replacements = new rcube_string_replacer;
+
+ $url_chars = 'a-z0-9_\-\+\*\$\/&%=@#:;';
+ $url_chars_within = '\?\.~,!';
+
+ // search for patterns like links and e-mail addresses
+ $body = preg_replace_callback("/([\w]+):\/\/([a-z0-9\-\.]+[a-z]{2,4}([$url_chars$url_chars_within]*[$url_chars])?)/i", array($replacements, 'link_callback'), $body);
+ $body = preg_replace_callback("/([^\/:]|\s)(www\.)([a-z0-9\-]{2,}[a-z]{2,4}([$url_chars$url_chars_within]*[$url_chars])?)/i", array($replacements, 'link_callback'), $body);
+ $body = preg_replace_callback('/([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9]\\.[a-z]{2,5})/i', array($replacements, 'mailto_callback'), $body);
+
+ // split body into single lines
+ $a_lines = preg_split('/\r?\n/', $body);
+ $quote_level = 0;
+
+ // colorize quoted parts
+ for ($n=0; $n < count($a_lines); $n++) {
+ $line = $a_lines[$n];
+ $quotation = '';
+ $q = 0;
- if (preg_match('/^(>+\s*)+/', $line, $regs)) {
- $q = strlen(preg_replace('/\s/', '', $regs[0]));
- $line = substr($line, strlen($regs[0]));
-
- if ($q > $quote_level)
- $quotation = str_repeat('<blockquote>', $q - $quote_level);
- else if ($q < $quote_level)
- $quotation = str_repeat("</blockquote>", $quote_level - $q);
+ if (preg_match('/^(>+\s*)+/', $line, $regs)) {
+ $q = strlen(preg_replace('/\s/', '', $regs[0]));
+ $line = substr($line, strlen($regs[0]));
+
+ if ($q > $quote_level)
+ $quotation = str_repeat('<blockquote>', $q - $quote_level);
+ else if ($q < $quote_level)
+ $quotation = str_repeat("</blockquote>", $quote_level - $q);
+ }
+ else if ($quote_level > 0)
+ $quotation = str_repeat("</blockquote>", $quote_level);
+
+ $quote_level = $q;
+ $a_lines[$n] = $quotation . Q($line, 'replace', false); // htmlquote plaintext
}
- else if ($quote_level > 0)
- $quotation = str_repeat("</blockquote>", $quote_level);
- $quote_level = $q;
- $a_lines[$n] = $quotation . Q($line, 'replace', false); // htmlquote plaintext
+ // insert the links for urls and mailtos
+ $body = $replacements->resolve(join("\n", $a_lines));
}
+
+ // allow post-processing of the message body
+ $data = $RCMAIL->plugins->exec_hook('message_part_after', array('type' => $part->ctype_secondary, 'body' => $body) + $data);
- // insert the links for urls and mailtos
- $body = $replacements->resolve(join("\n", $a_lines));
-
- return html::tag('pre', array(), $body);
+ return $data['type'] == 'html' ? $data['body'] : html::tag('pre', array(), $data['body']);
}
@@ -842,7 +857,7 @@ function rcmail_washtml_callback($tagname, $attrib, $content)
*/
function rcmail_message_headers($attrib, $headers=NULL)
{
- global $IMAP, $OUTPUT, $MESSAGE, $PRINT_MODE, $CONFIG;
+ global $IMAP, $OUTPUT, $MESSAGE, $PRINT_MODE, $RCMAIL;
static $sa_attrib;
// keep header table attrib
@@ -851,7 +866,6 @@ function rcmail_message_headers($attrib, $headers=NULL)
else if (!is_array($attrib) && is_array($sa_attrib))
$attrib = $sa_attrib;
-
if (!isset($MESSAGE))
return FALSE;
@@ -859,58 +873,55 @@ function rcmail_message_headers($attrib, $headers=NULL)
if (!$headers)
$headers = is_object($MESSAGE->headers) ? get_object_vars($MESSAGE->headers) : $MESSAGE->headers;
- $header_count = 0;
-
- // allow the following attributes to be added to the <table> tag
- $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary'));
- $out = '<table' . $attrib_str . ">\n";
-
// show these headers
$standard_headers = array('subject', 'from', 'to', 'cc', 'bcc', 'replyto', 'date');
+ $output_headers = array();
- foreach ($standard_headers as $hkey)
- {
+ foreach ($standard_headers as $hkey) {
if (!$headers[$hkey])
continue;
- if ($hkey == 'date')
- {
+ if ($hkey == 'date') {
if ($PRINT_MODE)
- $header_value = format_date($headers[$hkey], $CONFIG['date_long'] ? $CONFIG['date_long'] : 'x');
+ $header_value = format_date($headers[$hkey], $RCMAIL->config->get('date_long', 'x'));
else
$header_value = format_date($headers[$hkey]);
- }
- else if ($hkey == 'replyto')
- {
+ }
+ else if ($hkey == 'replyto') {
if ($headers['replyto'] != $headers['from'])
- $header_value = Q(rcmail_address_string($headers['replyto'], null, true, $attrib['addicon']), 'show');
+ $header_value = rcmail_address_string($headers['replyto'], null, true, $attrib['addicon']);
else
continue;
- }
+ }
else if (in_array($hkey, array('from', 'to', 'cc', 'bcc')))
- $header_value = Q(rcmail_address_string($headers[$hkey], null, true, $attrib['addicon']), 'show');
+ $header_value = rcmail_address_string($headers[$hkey], null, true, $attrib['addicon']);
else if ($hkey == 'subject' && empty($headers[$hkey]))
- $header_value = Q(rcube_label('nosubject'));
+ $header_value = rcube_label('nosubject');
else
- $header_value = Q(trim($IMAP->decode_header($headers[$hkey])));
-
- $out .= "\n<tr>\n";
- $out .= '<td class="header-title">'.Q(rcube_label($hkey)).":&nbsp;</td>\n";
- $out .= '<td class="'.$hkey.'" width="90%">'.$header_value."</td>\n</tr>";
- $header_count++;
- }
+ $header_value = trim($IMAP->decode_header($headers[$hkey]));
+
+ $output_headers[$hkey] = array('title' => rcube_label($hkey), 'value' => $header_value, 'raw' => $headers[$hkey]);
+ }
+
+ $plugin = $RCMAIL->plugins->exec_hook('message_headers_output', array('output' => $output_headers, 'headers' => $MESSAGE->headers));
+
+ // compose html table
+ $table = new html_table(array('cols' => 2));
+
+ foreach ($plugin['output'] as $hkey => $row) {
+ $table->add(array('class' => 'header-title'), Q($row['title']));
+ $table->add(array('class' => $hkey, 'width' => "90%"), Q($row['value'], ($hkey == 'subject' ? 'strict' : 'show')));
+ }
// all headers division
- $out .= "\n".'<tr><td colspan="2" class="more-headers show-headers"
- onclick="return '.JS_OBJECT_NAME.'.command(\'load-headers\', \'\', this)"></td></tr>';
- $out .= "\n".'<tr id="all-headers"><td colspan="2" class="all"><div id="headers-source"></div></td></tr>';
-
+ $table->add(array('colspan' => 2, 'class' => "more-headers show-headers", 'onclick' => "return ".JS_OBJECT_NAME.".command('load-headers','',this)"), '');
+ $table->add_row(array('id' => "all-headers"));
+ $table->add(array('colspan' => 2, 'class' => "all"), html::div(array('id' => 'headers-source'), ''));
+
$OUTPUT->add_gui_object('all_headers_row', 'all-headers');
$OUTPUT->add_gui_object('all_headers_box', 'headers-source');
- $out .= "\n</table>\n\n";
-
- return $header_count ? $out : '';
+ return $table->show($attrib);
}
@@ -1251,10 +1262,7 @@ function rcmail_compose_cleanup()
if (!isset($_SESSION['compose']))
return;
- // remove attachment files from temp dir
- if (is_array($_SESSION['compose']['attachments']))
- foreach ($_SESSION['compose']['attachments'] as $attachment)
- @unlink($attachment['path']);
+ rcmail::get_instance()->plugins->exec_hook('cleanup_attachments',array());
unset($_SESSION['compose']);
}
diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc
index 9607619e9..34e2c0904 100644
--- a/program/steps/mail/sendmail.inc
+++ b/program/steps/mail/sendmail.inc
@@ -297,86 +297,92 @@ $MAIL_MIME = new rcube_mail_mime($RCMAIL->config->header_delimiter());
// For HTML-formatted messages, construct the MIME message with both
// the HTML part and the plain-text part
-if ($isHtml)
- {
- $MAIL_MIME->setHTMLBody($message_body . ($footer ? "\r\n<pre>".$footer.'</pre>' : ''));
+if ($isHtml) {
+ $plugin = $RCMAIL->plugins->exec_hook('outgoing_message_body', array('body' => $message_body, 'type' => 'html', 'message' => $MAIL_MIME));
+ $MAIL_MIME->setHTMLBody($plugin['body'] . ($footer ? "\r\n<pre>".$footer.'</pre>' : ''));
// add a plain text version of the e-mail as an alternative part.
- $h2t = new html2text($message_body, false, true, 0);
- $plainTextPart = rc_wordwrap($h2t->get_text(), 75, "\r\n"). ($footer ? "\r\n".$footer : '');
+ $h2t = new html2text($plugin['body'], false, true, 0);
+ $plainTextPart = rc_wordwrap($h2t->get_text(), 75, "\r\n") . ($footer ? "\r\n".$footer : '');
$plainTextPart = wordwrap($plainTextPart, 998, "\r\n", true);
- if (!strlen($plainTextPart))
- {
+ if (!strlen($plainTextPart)) {
// empty message body breaks attachment handling in drafts
$plainTextPart = "\r\n";
- }
- $MAIL_MIME->setTXTBody($plainTextPart);
+ }
+ $plugin = $RCMAIL->plugins->exec_hook('outgoing_message_body', array('body' => $plainTextPart, 'type' => 'alternative', 'message' => $MAIL_MIME));
+ $MAIL_MIME->setTXTBody($plugin['body']);
// look for "emoticon" images from TinyMCE and copy into message as attachments
$message_body = rcmail_attach_emoticons($MAIL_MIME);
- }
+}
else
{
$message_body = rc_wordwrap($message_body, 75, "\r\n");
if ($footer)
$message_body .= "\r\n" . $footer;
$message_body = wordwrap($message_body, 998, "\r\n", true);
- if (!strlen($message_body))
- {
+ if (!strlen($message_body)) {
// empty message body breaks attachment handling in drafts
$message_body = "\r\n";
- }
- $MAIL_MIME->setTXTBody($message_body, FALSE, TRUE);
}
+ $plugin = $RCMAIL->plugins->exec_hook('outgoing_message_body', array('body' => $message_body, 'type' => 'plain', 'message' => $MAIL_MIME));
+ $MAIL_MIME->setTXTBody($plugin['body'], false, true);
+}
// chose transfer encoding
$charset_7bit = array('ASCII', 'ISO-2022-JP', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-15');
$transfer_encoding = in_array(strtoupper($message_charset), $charset_7bit) ? '7bit' : '8bit';
// add stored attachments, if any
-if (is_array($_SESSION['compose']['attachments']))
- foreach ($_SESSION['compose']['attachments'] as $id => $attachment)
- {
- $dispurl = '/\ssrc\s*=\s*[\'"]*\S+display-attachment\S+file=rcmfile' . $id . '[\s\'"]\s*/';
- $match = preg_match($dispurl, $message_body, $matches);
- if ($isHtml && ($match > 0))
- {
+if (is_array($_SESSION['compose']['attachments'])) {
+ foreach ($_SESSION['compose']['attachments'] as $id => $attachment) {
+ // This hook retrieves the attachment contents from the file storage backend
+ $attachment = $RCMAIL->plugins->exec_hook('get_attachment', $attachment);
+
+ $dispurl = '/\ssrc\s*=\s*[\'"]*\S+display-attachment\S+file=rcmfile' . preg_quote($attachment['id']) . '[\s\'"]\s*/';
+ $message_body = $MAIL_MIME->getHTMLBody();
+ if ($isHtml && (preg_match($dispurl, $message_body) > 0)) {
$message_body = preg_replace($dispurl, ' src="'.$attachment['name'].'" ', $message_body);
$MAIL_MIME->setHTMLBody($message_body);
- $MAIL_MIME->addHTMLImage($attachment['path'], $attachment['mimetype'], $attachment['name']);
+
+ if ($attachment['data'])
+ $MAIL_MIME->addHTMLImage($attachment['data'], $attachment['mimetype'], $attachment['name'], false);
+ else
+ $MAIL_MIME->addHTMLImage($attachment['path'], $attachment['mimetype'], $attachment['name'], true);
}
- else
- {
+ else {
$ctype = str_replace('image/pjpeg', 'image/jpeg', $attachment['mimetype']); // #1484914
+ $file = $attachment['data'] ? $attachment['data'] : $attachment['path'];
// .eml attachments send inline
- $MAIL_MIME->addAttachment($attachment['path'],
+ $MAIL_MIME->addAttachment($file,
$ctype,
- $attachment['name'], true,
+ $attachment['name'],
+ ($attachment['data'] ? false : true),
($ctype == 'message/rfc822' ? $transfer_encoding : 'base64'),
($ctype == 'message/rfc822' ? 'inline' : 'attachment'),
$message_charset, '', '',
- $CONFIG['mime_param_folding'] ? 'quoted-printable' : NULL,
- $CONFIG['mime_param_folding'] == 2 ? 'quoted-printable' : NULL
- );
+ $CONFIG['mime_param_folding'] ? 'quoted-printable' : NULL,
+ $CONFIG['mime_param_folding'] == 2 ? 'quoted-printable' : NULL
+ );
}
}
+}
// add submitted attachments
-if (is_array($_FILES['_attachments']['tmp_name']))
- foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath)
- {
+if (is_array($_FILES['_attachments']['tmp_name'])) {
+ foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath) {
$ctype = $files['type'][$i];
$ctype = str_replace('image/pjpeg', 'image/jpeg', $ctype); // #1484914
$MAIL_MIME->addAttachment($filepath, $ctype, $files['name'][$i], true,
- $ctype == 'message/rfc822' ? $transfer_encoding : 'base64',
- 'attachment', $message_charset, '', '',
- $CONFIG['mime_param_folding'] ? 'quoted-printable' : NULL,
- $CONFIG['mime_param_folding'] == 2 ? 'quoted-printable' : NULL
- );
- }
-
+ $ctype == 'message/rfc822' ? $transfer_encoding : 'base64',
+ 'attachment', $message_charset, '', '',
+ $CONFIG['mime_param_folding'] ? 'quoted-printable' : NULL,
+ $CONFIG['mime_param_folding'] == 2 ? 'quoted-printable' : NULL
+ );
+ }
+}
// encoding settings for mail composing
$MAIL_MIME->setParam(array(
@@ -388,6 +394,9 @@ $MAIL_MIME->setParam(array(
'text_charset' => $message_charset,
));
+$data = $RCMAIL->plugins->exec_hook('outgoing_message_headers', array('headers' => $headers));
+$headers = $data['headers'];
+
// encoding subject header with mb_encode provides better results with asian characters
if (function_exists("mb_encode_mimeheader"))
{
diff --git a/program/steps/mail/show.inc b/program/steps/mail/show.inc
index fd31fa91c..9beb42521 100644
--- a/program/steps/mail/show.inc
+++ b/program/steps/mail/show.inc
@@ -135,9 +135,11 @@ if ($_GET['_uid']) {
}
// mark message as read
- if (!$MESSAGE->headers->seen)
+ if (!$MESSAGE->headers->seen) {
$IMAP->set_flag($MESSAGE->uid, 'SEEN');
+ $RCMAIL->plugins->exec_hook('message_read', array('uid' => $MESSAGE->uid, 'mailbox' => $IMAP->mailbox, 'message' => $MESSAGE));
}
+}