diff options
author | thomascube <thomas@roundcube.net> | 2009-04-19 17:44:29 +0000 |
---|---|---|
committer | thomascube <thomas@roundcube.net> | 2009-04-19 17:44:29 +0000 |
commit | cc97ea0559af1a92a54dbcdf738ee4d95e67d3ff (patch) | |
tree | f9e18128e5a90abb06f079b09f8cd9ed92044faf /program/steps | |
parent | fb253ee9a89e2da779d11058f1f0c63c314b2840 (diff) |
Merged branch devel-api (from r2208 to r2387) back into trunk (omitting some sample plugins)
Diffstat (limited to 'program/steps')
-rw-r--r-- | program/steps/addressbook/func.inc | 36 | ||||
-rw-r--r-- | program/steps/mail/attachments.inc | 74 | ||||
-rw-r--r-- | program/steps/mail/compose.inc | 50 | ||||
-rw-r--r-- | program/steps/mail/func.inc | 176 | ||||
-rw-r--r-- | program/steps/mail/sendmail.inc | 87 | ||||
-rw-r--r-- | program/steps/mail/show.inc | 4 | ||||
-rw-r--r-- | program/steps/settings/func.inc | 12 | ||||
-rw-r--r-- | program/steps/settings/manage_folders.inc | 1 | ||||
-rw-r--r-- | program/steps/settings/save_prefs.inc | 3 |
9 files changed, 236 insertions, 207 deletions
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc index 33dfad646..e3d7606cb 100644 --- a/program/steps/addressbook/func.inc +++ b/program/steps/addressbook/func.inc @@ -42,18 +42,20 @@ $OUTPUT->set_env('readonly', $CONTACTS->readonly, false); $js_list = array(); if (strtolower($CONFIG['address_book_type']) != 'ldap') { // We are using the DB address book, add it. - $js_list = array("0" => array('id' => 0, 'readonly' => false)); + $js_list['0'] = array('id' => 0, 'name' => rcube_label('personaladrbook'), 'readonly' => false); } if (is_array($CONFIG['ldap_public'])) { foreach ($CONFIG['ldap_public'] as $id => $prop) - $js_list[$id] = array('id' => $id, 'readonly' => !$prop['writable']); + $js_list[$id] = array('id' => $id, 'name' => $prop['name'], 'readonly' => !$prop['writable']); } -$OUTPUT->set_env('address_sources', $js_list); + +$plugin = $RCMAIL->plugins->exec_hook('address_sources', array('sources' => $js_list)); +$OUTPUT->set_env('address_sources', $plugin['sources']); function rcmail_directory_list($attrib) { - global $CONFIG, $OUTPUT; + global $RCMAIL, $OUTPUT; if (!$attrib['id']) $attrib['id'] = 'rcmdirectorylist'; @@ -63,26 +65,24 @@ function rcmail_directory_list($attrib) $current = get_input_value('_source', RCUBE_INPUT_GPC); $line_templ = html::tag('li', array('id' => 'rcmli%s', 'class' => '%s'), html::a(array('href' => '%s', 'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s')); - - if (strtolower($CONFIG['address_book_type']) != 'ldap') { - $out .= sprintf($line_templ, $local_id, (!$current ? 'selected' : ''), - Q(rcmail_url(null, array('_source' => $local_id))), $local_id, rcube_label('personaladrbook')); - } // end if - else { + + if (!$current && strtolower($RCMAIL->config->get('address_book_type', 'sql')) != 'ldap') { + $current = '0'; + } + else if (!$current) { // DB address book not used, see if a source is set, if not use the // first LDAP directory. - if (!$current) { - $current = key((array)$CONFIG['ldap_public']); - } // end if - } // end else - - foreach ((array)$CONFIG['ldap_public'] as $id => $prop) { + $current = key((array)$RCMAIL->config->get('ldap_public', array())); + } + + foreach ((array)$OUTPUT->env['address_sources'] as $j => $source) { + $id = $source['id'] ? $source['id'] : $j; $js_id = JQ($id); $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id); $out .= sprintf($line_templ, $dom_id, ($current == $id ? 'selected' : ''), - Q(rcmail_url(null, array('_source' => $id))), $js_id, (!empty($prop['name']) ? Q($prop['name']) : Q($id))); + Q(rcmail_url(null, array('_source' => $id))), $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id))); } - + $OUTPUT->add_gui_object('folderlist', $attrib['id']); return html::tag('ul', $attrib, $out, html::$common_attrib); 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)).": </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)); } +} diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc index 3f0357717..6eda4dba3 100644 --- a/program/steps/settings/func.inc +++ b/program/steps/settings/func.inc @@ -159,6 +159,8 @@ function rcmail_user_prefs_block($part, $no_override, $attrib) } } + $RCMAIL->plugins->exec_hook('user_preferences', array('section' => $part, 'table' => $table)); + if ($table->size()) $out = html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('uisettings'))) . $table->show($attrib)); break; @@ -216,6 +218,8 @@ function rcmail_user_prefs_block($part, $no_override, $attrib) $table->add(null, $input_check_all->show($config['check_all_folders']?1:0)); } + $RCMAIL->plugins->exec_hook('user_preferences', array('section' => $part, 'table' => $table)); + if ($table->size()) $out = html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('mailboxview'))) . $table->show($attrib)); break; @@ -254,6 +258,8 @@ function rcmail_user_prefs_block($part, $no_override, $attrib) $table->add(null, $input_inline_images->show($config['inline_images']?1:0)); } + $RCMAIL->plugins->exec_hook('user_preferences', array('section' => $part, 'table' => $table)); + if ($table->size()) $out = html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('messagesdisplaying'))) . $table->show($attrib)); break; @@ -295,6 +301,8 @@ function rcmail_user_prefs_block($part, $no_override, $attrib) $table->add(null, $select_param_folding->show($config['mime_param_folding'])); } + $RCMAIL->plugins->exec_hook('user_preferences', array('section' => $part, 'table' => $table)); + if ($table->size()) $out = html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('messagescomposition'))) . $table->show($attrib)); break; @@ -329,6 +337,8 @@ function rcmail_user_prefs_block($part, $no_override, $attrib) $table->add(null, $select->show($config['trash_mbox'], array('name' => "_trash_mbox"))); } + $RCMAIL->plugins->exec_hook('user_preferences', array('section' => $part, 'table' => $table)); + $out = html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('specialfolders'))) . $table->show($attrib)); } break; @@ -381,6 +391,8 @@ function rcmail_user_prefs_block($part, $no_override, $attrib) $table->add(null, $input_expunge->show($config['logout_expunge']?1:0)); } + $RCMAIL->plugins->exec_hook('user_preferences', array('section' => $part, 'table' => $table)); + if ($table->size()) $out = html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('serversettings'))) . $table->show($attrib)); break; diff --git a/program/steps/settings/manage_folders.inc b/program/steps/settings/manage_folders.inc index 9affded98..79d313c37 100644 --- a/program/steps/settings/manage_folders.inc +++ b/program/steps/settings/manage_folders.inc @@ -256,6 +256,7 @@ function rcube_subscription_form($attrib) $a_js_folders['rcmrow'.$idx] = array($folder_utf8, $display_folder, $protected || $folder['virtual']); } + rcmail::get_instance()->plugins->exec_hook('manage_folders', array('table'=>$table)); $OUTPUT->add_gui_object('subscriptionlist', $attrib['id']); $OUTPUT->set_env('subscriptionrows', $a_js_folders); diff --git a/program/steps/settings/save_prefs.inc b/program/steps/settings/save_prefs.inc index 09cf63d6f..c5afd5b0c 100644 --- a/program/steps/settings/save_prefs.inc +++ b/program/steps/settings/save_prefs.inc @@ -48,6 +48,9 @@ $a_user_prefs = array( 'trash_mbox' => get_input_value('_trash_mbox', RCUBE_INPUT_POST), ); +$data = rcmail::get_instance()->plugins->exec_hook('save_preferences', array('prefs' => $a_user_prefs)); +$a_user_prefs = $data['prefs']; + // don't override these parameters foreach ((array)$CONFIG['dont_override'] as $p) $a_user_prefs[$p] = $CONFIG[$p]; |