Page MenuHomePhorge

No OneTemporary

Authored By
Unknown
Size
59 KB
Referenced Files
None
Subscribers
None
diff --git a/program/actions/contacts/import.php b/program/actions/contacts/import.php
index 2c4d25d9d..295d377cc 100644
--- a/program/actions/contacts/import.php
+++ b/program/actions/contacts/import.php
@@ -1,486 +1,486 @@
<?php
/**
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| |
| Copyright (C) The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Import contacts from a vCard or CSV file |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
| Author: Aleksander Machniak <machniak@kolabsys.com> |
+-----------------------------------------------------------------------+
*/
class rcmail_action_contacts_import extends rcmail_action_contacts_index
{
const UPLOAD_ERR_CSV_FIELDS = 101;
protected static $stats;
/**
* Request handler.
*
* @param array $args Arguments from the previous step(s)
*/
public function run($args = [])
{
$rcmail = rcmail::get_instance();
$importstep = 'import_form';
$has_map = isset($_POST['_map']) && is_array($_POST['_map']);
if ($has_map || (isset($_FILES['_file']) && is_array($_FILES['_file']))) {
$replace = (bool) rcube_utils::get_input_string('_replace', rcube_utils::INPUT_GPC);
$target = rcube_utils::get_input_string('_target', rcube_utils::INPUT_GPC);
$with_groups = (int) rcube_utils::get_input_string('_groups', rcube_utils::INPUT_GPC);
// reload params for CSV field mapping screen
if ($has_map && !empty($_SESSION['contactcsvimport']['params'])) {
$params = $_SESSION['contactcsvimport']['params'];
$replace = $params['replace'];
$target = $params['target'];
$with_groups = $params['with_groups'];
}
$vcards = [];
$csvs = [];
$map = [];
$upload_error = null;
$CONTACTS = $rcmail->get_address_book($target, true);
if (!$CONTACTS->groups) {
$with_groups = false;
}
if ($CONTACTS->readonly) {
$rcmail->output->show_message('addresswriterror', 'error');
}
else {
$filepaths = [];
if ($has_map) {
$filepaths = $_SESSION['contactcsvimport']['files'];
}
else {
foreach ((array) $_FILES['_file']['tmp_name'] as $i => $filepath) {
// Process uploaded file if there is no error
$err = $_FILES['_file']['error'][$i];
if ($err) {
$upload_error = $err;
}
else {
$filepaths[] = $filepath;
}
}
}
foreach ($filepaths as $filepath) {
$file_content = file_get_contents($filepath);
// let rcube_vcard do the hard work :-)
$vcard_o = new rcube_vcard();
$vcard_o->extend_fieldmap($CONTACTS->vcard_map);
$v_list = $vcard_o->import($file_content);
if (!empty($v_list)) {
$vcards = array_merge($vcards, $v_list);
continue;
}
// no vCards found, try CSV
$csv = new rcube_csv2vcard($_SESSION['language']);
if ($has_map) {
$skip_head = isset($_POST['_skip_header']);
$map = rcube_utils::get_input_value('_map', rcube_utils::INPUT_GPC);
$map = array_filter($map);
$csv->set_map($map);
$csv->import($file_content, false, $skip_head);
unlink($filepath);
}
else {
// save uploaded file for the real import in the next step
$temp_csv = rcube_utils::temp_filename('csvimpt');
if (move_uploaded_file($filepath, $temp_csv) && file_exists($temp_csv)) {
$fields = $csv->get_fields();
$last_map = $map;
$map = $csv->import($file_content, true);
// when multiple CSV files are uploaded check they all have the same structure
if ($last_map && $last_map !== $map) {
$csvs = [];
$upload_error = self::UPLOAD_ERR_CSV_FIELDS;
break;
}
$csvs[] = $temp_csv;
}
else {
$upload_error = UPLOAD_ERR_CANT_WRITE;
}
continue;
}
$v_list = $csv->export();
if (!empty($v_list)) {
$vcards = array_merge($vcards, $v_list);
}
}
}
if (count($csvs) > 0) {
// csv import, show field mapping options
$importstep = 'import_map';
$_SESSION['contactcsvimport']['files'] = $csvs;
$_SESSION['contactcsvimport']['params'] = [
'replace' => $replace,
'target' => $target,
'with_groups' => $with_groups,
'fields' => !empty($fields) ? $fields : [],
];
// Stored separately due to nested array limitations in session
$_SESSION['contactcsvimport']['map'] = $map;
// Re-enable the import button
$rcmail->output->command('parent.import_state_set', 'error');
}
elseif (count($vcards) > 0) {
// import vcards
self::$stats = new stdClass;
self::$stats->names = [];
self::$stats->skipped_names = [];
self::$stats->count = count($vcards);
self::$stats->inserted = 0;
self::$stats->skipped = 0;
self::$stats->invalid = 0;
self::$stats->errors = 0;
if ($replace) {
$CONTACTS->delete_all($CONTACTS->groups && $with_groups < 2);
}
if ($with_groups) {
$import_groups = $CONTACTS->list_groups();
}
foreach ($vcards as $vcard) {
$a_record = $vcard->get_assoc();
// Generate contact's display name (must be before validation), the same we do in save.inc
if (empty($a_record['name'])) {
$a_record['name'] = rcube_addressbook::compose_display_name($a_record, true);
// Reset it if equals to email address (from compose_display_name())
- if ($a_record['name'] == $a_record['email'][0]) {
+ if ($a_record['name'] == ($a_record['email'][0] ?? null)) {
$a_record['name'] = '';
}
}
// skip invalid (incomplete) entries
if (!$CONTACTS->validate($a_record, true)) {
self::$stats->invalid++;
continue;
}
// We're using UTF8 internally
$email = null;
if (isset($vcard->email[0])) {
$email = $vcard->email[0];
$email = rcube_utils::idn_to_utf8($email);
}
if (!$replace) {
$existing = null;
// compare e-mail address
if ($email) {
$existing = $CONTACTS->search('email', $email, 1, false);
}
// compare display name if email not found
if ((!$existing || !$existing->count) && $vcard->displayname) {
$existing = $CONTACTS->search('name', $vcard->displayname, 1, false);
}
if ($existing && $existing->count) {
self::$stats->skipped++;
self::$stats->skipped_names[] = $vcard->displayname ?: $email;
continue;
}
}
$a_record['vcard'] = $vcard->export();
$plugin = $rcmail->plugins->exec_hook('contact_create', ['record' => $a_record, 'source' => null]);
$a_record = $plugin['record'];
// insert record and send response
if (empty($plugin['abort'])) {
$success = $CONTACTS->insert($a_record);
}
else {
$success = $plugin['result'];
}
if ($success) {
// assign groups for this contact (if enabled)
if ($with_groups && !empty($a_record['groups'])) {
foreach (explode(',', $a_record['groups'][0]) as $group_name) {
if ($group_id = self::import_group_id($group_name, $CONTACTS, $with_groups == 1, $import_groups)) {
$CONTACTS->add_to_group($group_id, $success);
}
}
}
self::$stats->inserted++;
self::$stats->names[] = $a_record['name'] ?: $email;
}
else {
self::$stats->errors++;
}
}
$importstep = 'import_confirm';
$_SESSION['contactcsvimport'] = null;
$rcmail->output->command('parent.import_state_set', self::$stats->inserted ? 'reload' : 'ok');
}
else {
if ($upload_error == self::UPLOAD_ERR_CSV_FIELDS) {
$rcmail->output->show_message('csvfilemismatch', 'error');
}
else {
self::upload_error($upload_error);
}
$rcmail->output->command('parent.import_state_set', 'error');
}
}
$rcmail->output->set_pagetitle($rcmail->gettext('importcontacts'));
$rcmail->output->add_handlers([
'importstep' => [$this, $importstep],
]);
// render page
if ($rcmail->output->template_exists('contactimport')) {
$rcmail->output->send('contactimport');
}
else {
$rcmail->output->send('importcontacts'); // deprecated
}
}
/**
* Handler function to display the import/upload form
*/
public static function import_form($attrib)
{
$rcmail = rcmail::get_instance();
$target = rcube_utils::get_input_string('_target', rcube_utils::INPUT_GPC);
$attrib += ['id' => 'rcmImportForm'];
$writable_books = $rcmail->get_address_sources(true, true);
$max_filesize = self::upload_init();
$form = '';
$hint = $rcmail->gettext(['id' => 'importfile', 'name' => 'maxuploadsize', 'vars' => ['size' => $max_filesize]]);
$table = new html_table(['cols' => 2]);
$upload = new html_inputfield([
'type' => 'file',
'name' => '_file[]',
'id' => 'rcmimportfile',
'size' => 40,
'multiple' => 'multiple',
'class' => 'form-control-file',
]);
$table->add('title', html::label('rcmimportfile', $rcmail->gettext('importfromfile')));
$table->add(null, $upload->show() . html::div('hint', $hint));
// addressbook selector
if (count($writable_books) > 1) {
$select = new html_select([
'name' => '_target',
'id' => 'rcmimporttarget',
'is_escaped' => true,
'class' => 'custom-select'
]);
foreach ($writable_books as $book) {
$select->add($book['name'], $book['id']);
}
$table->add('title', html::label('rcmimporttarget', $rcmail->gettext('importtarget')));
$table->add(null, $select->show($target));
}
else {
$abook = new html_hiddenfield(['name' => '_target', 'value' => key($writable_books)]);
$form .= $abook->show();
}
$form .= html::tag('input', ['type' => 'hidden', 'name' => '_unlock', 'value' => '']);
// selector for group import options
if (count($writable_books) >= 1 || $writable_books[0]->groups) {
$select = new html_select([
'name' => '_groups',
'id' => 'rcmimportgroups',
'is_escaped' => true,
'class' => 'custom-select'
]);
$select->add($rcmail->gettext('none'), '0');
$select->add($rcmail->gettext('importgroupsall'), '1');
$select->add($rcmail->gettext('importgroupsexisting'), '2');
$table->add('title', html::label('rcmimportgroups', $rcmail->gettext('importgroups')));
$table->add(null, $select->show(rcube_utils::get_input_value('_groups', rcube_utils::INPUT_GPC)));
}
// checkbox to replace the entire address book
$check_replace = new html_checkbox(['name' => '_replace', 'value' => 1, 'id' => 'rcmimportreplace']);
$table->add('title', html::label('rcmimportreplace', $rcmail->gettext('importreplace')));
$table->add(null, $check_replace->show(rcube_utils::get_input_string('_replace', rcube_utils::INPUT_GPC)));
$form .= $table->show(['id' => null] + $attrib);
// remove any info left over info from previous import attempts
$_SESSION['contactcsvimport'] = null;
$rcmail->output->set_env('writable_source', !empty($writable_books));
$rcmail->output->add_label('selectimportfile','importwait');
$rcmail->output->add_gui_object('importform', $attrib['id']);
$attrib = [
'action' => $rcmail->url('import'),
'method' => 'post',
'enctype' => 'multipart/form-data'
] + $attrib;
return html::p(null, rcube::Q($rcmail->gettext('importdesc'), 'show'))
. $rcmail->output->form_tag($attrib, $form);
}
/**
* Render the field mapping page for the CSV import process
*/
public static function import_map($attrib)
{
$rcmail = rcmail::get_instance();
$params = $_SESSION['contactcsvimport']['params'];
// hide groups field from list when group import disabled
if (empty($params['with_groups'])) {
unset($params['fields']['groups']);
}
$fieldlist = new html_select(['name' => '_map[]']);
$fieldlist->add($rcmail->gettext('fieldnotmapped'), '');
foreach ($params['fields'] as $id => $name) {
$fieldlist->add($name, $id);
}
$field_table = new html_table(['cols' => 2] + $attrib);
if ($classes = $attrib['table-header-class']) {
$field_table->set_header_attribs($classes);
}
$field_table->add_header($attrib['table-col-source-class'] ?: null, $rcmail->gettext('source'));
$field_table->add_header($attrib['table-col-destination-class'] ?: null, $rcmail->gettext('destination'));
$map = $_SESSION['contactcsvimport']['map'];
foreach ($map['source'] as $i => $name) {
$field_table->add('title', html::label('rcmimportmap' . $i, rcube::Q($name)));
$field_table->add(null, $fieldlist->show(array_key_exists($i, $map['destination']) ? $map['destination'][$i] : '', ['id' => 'rcmimportmap' . $i]));
}
$form = '';
$form .= html::tag('input', ['type' => 'hidden', 'name' => '_unlock', 'value' => '']);
// show option to import data from first line of the file
$check_header = new html_checkbox(['name' => '_skip_header', 'value' => 1, 'id' => 'rcmskipheader']);
$form .= html::p(null, html::label('rcmskipheader', $check_header->show(1) . $rcmail->gettext('skipheader')));
$form .= $field_table->show();
$attrib = ['action' => $rcmail->url('import'), 'method' => 'post'] + $attrib + ['id' => 'rcmImportFormMap'];
$rcmail->output->add_gui_object('importformmap', $attrib['id']);
return html::p(null, rcube::Q($rcmail->gettext('importmapdesc'), 'show'))
. $rcmail->output->form_tag($attrib, $form);
}
/**
* Render the confirmation page for the import process
*/
public static function import_confirm($attrib)
{
$rcmail = rcmail::get_instance();
$vars = get_object_vars(self::$stats);
$vars['names'] = $vars['skipped_names'] = '';
$content = html::p(null, $rcmail->gettext([
'name' => 'importconfirm',
'nr' => self::$stats->inserted,
'vars' => $vars,
]) . (self::$stats->names ? ':' : '.')
);
if (self::$stats->names) {
$content .= html::p('em', join(', ', array_map(['rcube', 'Q'], self::$stats->names)));
}
if (self::$stats->skipped) {
$content .= html::p(null, $rcmail->gettext([
'name' => 'importconfirmskipped',
'nr' => self::$stats->skipped,
'vars' => $vars,
]) . ':')
. html::p('em', join(', ', array_map(['rcube', 'Q'], self::$stats->skipped_names)));
}
return html::div($attrib, $content);
}
/**
* Returns the matching group id. If group doesn't exist, it'll be created if allowed.
*/
public static function import_group_id($group_name, $contacts, $create, &$import_groups)
{
$group_id = 0;
foreach ($import_groups as $group) {
if (strtolower($group['name']) === strtolower($group_name)) {
$group_id = $group['ID'];
break;
}
}
// create a new group
if (!$group_id && $create) {
$new_group = $contacts->create_group($group_name);
if (empty($new_group['ID'])) {
$new_group['ID'] = $new_group['id'];
}
$import_groups[] = $new_group;
$group_id = $new_group['ID'];
}
return $group_id;
}
}
diff --git a/program/actions/mail/show.php b/program/actions/mail/show.php
index 16be9e023..ff798b817 100644
--- a/program/actions/mail/show.php
+++ b/program/actions/mail/show.php
@@ -1,947 +1,953 @@
<?php
/**
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| |
| Copyright (C) The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Display a mail message similar as a usual mail application does |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
+-----------------------------------------------------------------------+
*/
class rcmail_action_mail_show extends rcmail_action_mail_index
{
protected static $MESSAGE;
protected static $CLIENT_MIMETYPES = [];
/**
* Request handler.
*
* @param array $args Arguments from the previous step(s)
*/
public function run($args = [])
{
$rcmail = rcmail::get_instance();
self::$PRINT_MODE = $rcmail->action == 'print';
// Read browser capabilities and store them in session
if ($caps = rcube_utils::get_input_string('_caps', rcube_utils::INPUT_GET)) {
$browser_caps = [];
foreach (explode(',', $caps) as $cap) {
$cap = explode('=', $cap);
$browser_caps[$cap[0]] = $cap[1];
}
$_SESSION['browser_caps'] = $browser_caps;
}
$msg_id = rcube_utils::get_input_string('_uid', rcube_utils::INPUT_GET);
$uid = preg_replace('/\.[0-9.]+$/', '', $msg_id);
$mbox_name = $rcmail->storage->get_folder();
// similar code as in program/steps/mail/get.inc
if ($uid) {
// set message format (need to be done before rcube_message construction)
if (!empty($_GET['_format'])) {
$prefer_html = $_GET['_format'] == 'html';
$rcmail->config->set('prefer_html', $prefer_html);
$_SESSION['msg_formats'][$mbox_name.':'.$uid] = $prefer_html;
}
else if (isset($_SESSION['msg_formats'][$mbox_name.':'.$uid])) {
$rcmail->config->set('prefer_html', $_SESSION['msg_formats'][$mbox_name.':'.$uid]);
}
$MESSAGE = new rcube_message($msg_id, $mbox_name, !empty($_GET['_safe']));
self::$MESSAGE = $MESSAGE;
// if message not found (wrong UID)...
if (empty($MESSAGE->headers)) {
self::message_error();
}
self::$CLIENT_MIMETYPES = self::supported_mimetypes();
// show images?
self::check_safe($MESSAGE);
// set message charset as default
if (!empty($MESSAGE->headers->charset)) {
$rcmail->storage->set_charset($MESSAGE->headers->charset);
}
if (!isset($_SESSION['writeable_abook'])) {
$_SESSION['writeable_abook'] = $rcmail->get_address_sources(true) ? true : false;
}
$rcmail->output->set_pagetitle(abbreviate_string($MESSAGE->subject, 128, '...', true));
// set environment
$rcmail->output->set_env('uid', $msg_id);
$rcmail->output->set_env('safemode', $MESSAGE->is_safe);
$rcmail->output->set_env('message_context', $MESSAGE->context);
$rcmail->output->set_env('message_flags', array_keys(array_change_key_case((array) $MESSAGE->headers->flags)));
$rcmail->output->set_env('sender', !empty($MESSAGE->sender) ? $MESSAGE->sender['string'] : '');
$rcmail->output->set_env('mailbox', $mbox_name);
$rcmail->output->set_env('username', $rcmail->get_user_name());
$rcmail->output->set_env('permaurl', $rcmail->url(['_action' => 'show', '_uid' => $msg_id, '_mbox' => $mbox_name]));
$rcmail->output->set_env('has_writeable_addressbook', $_SESSION['writeable_abook']);
$rcmail->output->set_env('delimiter', $rcmail->storage->get_hierarchy_delimiter());
$rcmail->output->set_env('mimetypes', self::$CLIENT_MIMETYPES);
if ($MESSAGE->headers->get('list-post', false)) {
$rcmail->output->set_env('list_post', true);
}
// set configuration
self::set_env_config(['delete_junk', 'flag_for_deletion', 'read_when_deleted',
'skip_deleted', 'display_next', 'forward_attachment', 'mailvelope_main_keyring']);
// set special folders
foreach (['drafts', 'trash', 'junk'] as $mbox) {
if ($folder = $rcmail->config->get($mbox . '_mbox')) {
$rcmail->output->set_env($mbox . '_mailbox', $folder);
}
}
if ($MESSAGE->has_html_part()) {
$prefer_html = $rcmail->config->get('prefer_html');
$rcmail->output->set_env('optional_format', $prefer_html ? 'text' : 'html');
}
$rcmail->output->add_label('checkingmail', 'deletemessage', 'movemessagetotrash',
'movingmessage', 'deletingmessage', 'markingmessage', 'replyall', 'replylist',
'bounce', 'bouncemsg', 'sendingmessage');
// check for unset disposition notification
self::mdn_request_handler($MESSAGE);
if (empty($MESSAGE->headers->flags['SEEN']) && $MESSAGE->context === null) {
$v = intval($rcmail->config->get('mail_read_time'));
if ($v > 0) {
$rcmail->output->set_env('mail_read_time', $v);
}
else if ($v == 0) {
$rcmail->output->command('set_unread_message', $MESSAGE->uid, $mbox_name);
$rcmail->plugins->exec_hook('message_read', [
'uid' => $MESSAGE->uid,
'mailbox' => $mbox_name,
'message' => $MESSAGE,
]);
$set_seen_flag = true;
}
}
}
$rcmail->output->add_handlers([
'mailboxname' => [$this, 'mailbox_name_display'],
'messageattachments' => [$this, 'message_attachments'],
'messageobjects' => [$this, 'message_objects'],
'messagesummary' => [$this, 'message_summary'],
'messageheaders' => [$this, 'message_headers'],
'messagefullheaders' => [$this, 'message_full_headers'],
'messagebody' => [$this, 'message_body'],
'contactphoto' => [$this, 'message_contactphoto'],
]);
if ($rcmail->action == 'print' && $rcmail->output->template_exists('messageprint')) {
$rcmail->output->send('messageprint', false);
}
else if ($rcmail->action == 'preview' && $rcmail->output->template_exists('messagepreview')) {
$rcmail->output->send('messagepreview', false);
}
else {
$rcmail->output->send('message', false);
}
// mark message as read
if (!empty($set_seen_flag)) {
if ($rcmail->storage->set_flag(self::$MESSAGE->uid, 'SEEN', $mbox_name)) {
if ($count = self::get_unseen_count($mbox_name)) {
self::set_unseen_count($mbox_name, $count - 1);
}
}
}
exit;
}
/**
* Handler for the template object 'messageattachments'.
*
* @param array $attrib Named parameters
*
* @return string HTML content showing the message attachments list
*/
public static function message_attachments($attrib)
{
if (empty(self::$MESSAGE->attachments)) {
return '';
}
$rcmail = rcmail::get_instance();
$out =
$ol = '';
$attachments = [];
foreach (self::$MESSAGE->attachments as $attach_prop) {
$filename = self::attachment_name($attach_prop, true);
$filesize = self::message_part_size($attach_prop);
$mimetype = rcube_mime::fix_mimetype($attach_prop->mimetype);
$class = rcube_utils::file2class($mimetype, $filename);
$id = 'attach' . $attach_prop->mime_id;
if ($mimetype == 'application/octet-stream' && ($type = rcube_mime::file_ext_type($filename))) {
$mimetype = $type;
}
// Skip inline images
if (strpos($mimetype, 'image/') === 0 && !self::is_attachment(self::$MESSAGE, $attach_prop)) {
continue;
}
if (!empty($attrib['maxlength']) && mb_strlen($filename) > $attrib['maxlength']) {
$title = $filename;
$filename = abbreviate_string($filename, $attrib['maxlength']);
}
else {
$title = '';
}
$item = html::span('attachment-name', rcube::Q($filename))
. html::span('attachment-size', '(' . rcube::Q($filesize) . ')');
$li_class = $class;
if (!self::$PRINT_MODE) {
$link_attrs = [
'href' => self::$MESSAGE->get_part_url($attach_prop->mime_id, false),
'onclick' => sprintf('%s.command(\'load-attachment\',\'%s\',this); return false',
rcmail_output::JS_OBJECT_NAME, $attach_prop->mime_id),
'onmouseover' => $title ? '' : 'rcube_webmail.long_subject_title_ex(this, 0)',
'title' => $title,
'class' => 'filename',
];
if ($mimetype != 'message/rfc822' && empty($attach_prop->size)) {
$li_class .= ' no-menu';
$link_attrs['onclick'] = sprintf('%s.alert_dialog(%s.get_label(\'emptyattachment\')); return false',
rcmail_output::JS_OBJECT_NAME, rcmail_output::JS_OBJECT_NAME);
$rcmail->output->add_label('emptyattachment');
}
$item = html::a($link_attrs, $item);
$attachments[$attach_prop->mime_id] = $mimetype;
}
$ol .= html::tag('li', ['class' => $li_class, 'id' => $id], $item);
}
$out = html::tag('ul', $attrib, $ol, html::$common_attrib);
$rcmail->output->set_env('attachments', $attachments);
$rcmail->output->add_gui_object('attachments', $attrib['id']);
return $out;
}
public static function remote_objects_msg()
{
$rcmail = rcmail::get_instance();
$attrib['id'] = 'remote-objects-message';
$attrib['class'] = 'notice';
$attrib['style'] = 'display: none';
$msg = html::span(null, rcube::Q($rcmail->gettext('blockedresources')));
$buttons = html::a([
'href' => "#loadremote",
'onclick' => rcmail_output::JS_OBJECT_NAME . ".command('load-remote')"
],
rcube::Q($rcmail->gettext('allow'))
);
// add link to save sender in addressbook and reload message
$show_images = $rcmail->config->get('show_images');
if (!empty(self::$MESSAGE->sender['mailto']) && ($show_images == 1 || $show_images == 3)) {
$arg = $show_images == 3 ? rcube_addressbook::TYPE_TRUSTED_SENDER : 'true';
$buttons .= ' ' . html::a([
'href' => "#loadremotealways",
'onclick' => rcmail_output::JS_OBJECT_NAME . ".command('load-remote', $arg)",
'style' => "white-space:nowrap"
],
rcube::Q($rcmail->gettext(['name' => 'alwaysallow', 'vars' => ['sender' => self::$MESSAGE->sender['mailto']]]))
);
}
$rcmail->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
return html::div($attrib, $msg . '&nbsp;' . html::span('boxbuttons', $buttons));
}
/**
* Display a warning whenever a suspicious email address has been found in the message.
*
* @return string HTML content of the warning element
*/
public static function suspicious_content_warning()
{
if (empty(self::$SUSPICIOUS_EMAIL)) {
return '';
}
$rcmail = rcmail::get_instance();
$attrib = [
'id' => 'suspicious-content-message',
'class' => 'notice',
];
$msg = html::span(null, rcube::Q($rcmail->gettext('suspiciousemail')));
return html::div($attrib, $msg);
}
public static function message_buttons()
{
$rcmail = rcmail::get_instance();
$delim = $rcmail->storage->get_hierarchy_delimiter();
$dbox = $rcmail->config->get('drafts_mbox');
// the message is not a draft
- if (self::$MESSAGE->context
- || (self::$MESSAGE->folder != $dbox && strpos(self::$MESSAGE->folder, $dbox.$delim) !== 0)
+ if (!empty(self::$MESSAGE->context)
+ || (
+ !empty(self::$MESSAGE->folder)
+ && (self::$MESSAGE->folder != $dbox && strpos(self::$MESSAGE->folder, $dbox.$delim) !== 0)
+ )
) {
return '';
}
$attrib['id'] = 'message-buttons';
$attrib['class'] = 'information notice';
$msg = html::span(null, rcube::Q($rcmail->gettext('isdraft')))
. '&nbsp;'
. html::a([
'href' => "#edit",
'onclick' => rcmail_output::JS_OBJECT_NAME.".command('edit')"
],
rcube::Q($rcmail->gettext('edit'))
);
return html::div($attrib, $msg);
}
/**
* Handler for the template object 'messageobjects' that contains
* warning/info boxes, buttons, etc. related to the displayed message.
*
* @param array $attrib Named parameters
*
* @return string HTML content showing the message objects
*/
public static function message_objects($attrib)
{
if (empty($attrib['id'])) {
$attrib['id'] = 'message-objects';
}
$rcmail = rcmail::get_instance();
$content = [
self::message_buttons(),
self::remote_objects_msg(),
self::suspicious_content_warning(),
];
$plugin = $rcmail->plugins->exec_hook('message_objects',
['content' => $content, 'message' => self::$MESSAGE]);
$content = implode("\n", $plugin['content']);
return html::div($attrib, $content);
}
/**
* Handler for the template object 'contactphoto'.
*
* @param array $attrib Named parameters
*
* @return string HTML content for the IMG tag
*/
public static function message_contactphoto($attrib)
{
$rcmail = rcmail::get_instance();
$error_handler = false;
$placeholder = 'data:image/gif;base64,' . rcmail_output::BLANK_GIF;
if (!empty($attrib['placeholder'])) {
$placeholder = $rcmail->output->abs_url($attrib['placeholder'], true);
$placeholder = $rcmail->output->asset_url($placeholder);
// set error handler on <img>
$error_handler = true;
$attrib['onerror'] = "this.onerror = null; this.src = '$placeholder';";
}
- if (self::$MESSAGE->sender) {
+ if (!empty(self::$MESSAGE->sender)) {
$photo_img = $rcmail->url([
'_task' => 'addressbook',
'_action' => 'photo',
'_email' => self::$MESSAGE->sender['mailto'],
'_error' => $error_handler ? 1 : null,
'_bgcolor' => $attrib['bg-color'] ?? null
]);
}
else {
$photo_img = $placeholder;
}
return html::img(['src' => $photo_img, 'alt' => $rcmail->gettext('contactphoto')] + $attrib);
}
/**
* Returns table with message headers
*/
public static function message_headers($attrib, $headers = null)
{
static $sa_attrib;
// keep header table attrib
if (is_array($attrib) && !$sa_attrib && empty($attrib['valueof'])) {
$sa_attrib = $attrib;
}
else if (!is_array($attrib) && is_array($sa_attrib)) {
$attrib = $sa_attrib;
}
if (!isset(self::$MESSAGE)) {
return false;
}
$rcmail = rcmail::get_instance();
// get associative array of headers object
if (!$headers) {
$headers_obj = self::$MESSAGE->headers;
$headers = get_object_vars(self::$MESSAGE->headers);
}
else if (is_object($headers)) {
$headers_obj = $headers;
$headers = get_object_vars($headers_obj);
}
else {
$headers_obj = rcube_message_header::from_array($headers);
}
// show these headers
$standard_headers = ['subject', 'from', 'sender', 'to', 'cc', 'bcc', 'replyto',
'mail-reply-to', 'mail-followup-to', 'date', 'priority'];
$exclude_headers = !empty($attrib['exclude']) ? explode(',', $attrib['exclude']) : [];
$output_headers = [];
$attr_max = $attrib['max'] ?? null;
$attr_addicon = $attrib['addicon'] ?? null;
$charset = !empty($headers['charset']) ? $headers['charset'] : null;
foreach ($standard_headers as $hkey) {
$value = null;
if (!empty($headers[$hkey])) {
$value = $headers[$hkey];
}
else if (!empty($headers['others'][$hkey])) {
$value = $headers['others'][$hkey];
}
else if (empty($attrib['valueof'])) {
continue;
}
if (in_array($hkey, $exclude_headers)) {
continue;
}
$ishtml = false;
$header_title = $rcmail->gettext(preg_replace('/(^mail-|-)/', '', $hkey));
$header_value = null;
if ($hkey == 'date') {
$header_value = $rcmail->format_date($value,
self::$PRINT_MODE ? $rcmail->config->get('date_long', 'x') : null);
}
else if ($hkey == 'priority') {
$header_value = html::span('prio' . $value, rcube::Q(self::localized_priority($value)));
$ishtml = true;
}
else if ($hkey == 'replyto') {
if ($value != $headers['from']) {
$header_value = self::address_string($value, $attr_max, true, $attr_addicon, $charset, $header_title);
$ishtml = true;
}
}
else if ($hkey == 'mail-reply-to') {
if ((!isset($headers['replyto']) || $value != $headers['replyto']) && $value != $headers['from']) {
$header_value = self::address_string($value, $attr_max, true, $attr_addicon, $charset, $header_title);
$ishtml = true;
}
}
else if ($hkey == 'sender') {
if ($value != $headers['from']) {
$header_value = self::address_string($value, $attr_max, true, $attr_addicon, $charset, $header_title);
$ishtml = true;
}
}
else if ($hkey == 'mail-followup-to') {
$header_value = self::address_string($value, $attr_max, true, $attr_addicon, $charset, $header_title);
$ishtml = true;
}
else if (in_array($hkey, ['from', 'to', 'cc', 'bcc'])) {
$header_value = self::address_string($value, $attr_max, true, $attr_addicon, $charset, $header_title);
$ishtml = true;
}
else if ($hkey == 'subject' && empty($value)) {
$header_value = $rcmail->gettext('nosubject');
}
else {
$value = is_array($value) ? implode(' ', $value) : $value;
$header_value = trim(rcube_mime::decode_header($value, $charset));
}
if (empty($header_value)) {
continue;
}
$output_headers[$hkey] = [
'title' => $header_title,
'value' => $header_value,
'raw' => $value,
'html' => $ishtml,
];
}
$plugin = $rcmail->plugins->exec_hook('message_headers_output', [
'output' => $output_headers,
'headers' => $headers_obj,
'exclude' => $exclude_headers, // readonly
'folder' => self::$MESSAGE->folder, // readonly
'uid' => self::$MESSAGE->uid, // readonly
]);
// single header value is requested
if (!empty($attrib['valueof'])) {
if (empty($plugin['output'][$attrib['valueof']])) {
return '';
}
$row = $plugin['output'][$attrib['valueof']];
return !empty($row['html']) ? $row['value'] : rcube::SQ($row['value']);
}
// compose html table
$table = new html_table(['cols' => 2]);
foreach ($plugin['output'] as $hkey => $row) {
$val = !empty($row['html']) ? $row['value'] : rcube::SQ($row['value']);
$table->add(['class' => 'header-title'], rcube::SQ($row['title']));
$table->add(['class' => 'header ' . $hkey], $val);
}
return $table->show($attrib);
}
/**
* Returns element with "From|To <sender|recipient> on <date>"
*/
public static function message_summary($attrib)
{
if (!isset(self::$MESSAGE) || empty(self::$MESSAGE->headers)) {
return;
}
$rcmail = rcmail::get_instance();
$header = self::$MESSAGE->context ? 'from' : self::message_list_smart_column_name();
$label = 'shortheader' . $header;
$date = $rcmail->format_date(self::$MESSAGE->headers->date, $rcmail->config->get('date_long', 'x'));
$user = self::$MESSAGE->headers->$header;
if (!$user && $header == 'to' && !empty(self::$MESSAGE->headers->cc)) {
$user = self::$MESSAGE->headers->cc;
}
if (!$user && $header == 'to' && !empty(self::$MESSAGE->headers->bcc)) {
$user = self::$MESSAGE->headers->bcc;
}
$vars[$header] = self::address_string($user, 1, true, $attrib['addicon'], self::$MESSAGE->headers->charset);
$vars['date'] = html::span('text-nowrap', $date);
if (empty($user)) {
$label = 'shortheaderdate';
}
$out = html::span(null, $rcmail->gettext(['name' => $label, 'vars' => $vars]));
return html::div($attrib, $out);
}
/**
* Convert Priority header value into a localized string
*/
public static function localized_priority($value)
{
$labels_map = [
'1' => 'highest',
'2' => 'high',
'3' => 'normal',
'4' => 'low',
'5' => 'lowest',
];
if ($value && !empty($labels_map[$value])) {
return rcmail::get_instance()->gettext($labels_map[$value]);
}
return '';
}
/**
* Returns block to show full message headers
*/
public static function message_full_headers($attrib)
{
$rcmail = rcmail::get_instance();
$html = html::div(['id' => "all-headers", 'class' => "all", 'style' => 'display:none'],
html::div(['id' => 'headers-source'], ''));
$html .= html::div([
'class' => "more-headers show-headers",
'onclick' => "return ".rcmail_output::JS_OBJECT_NAME.".command('show-headers','',this)",
'title' => $rcmail->gettext('togglefullheaders')
], '');
$rcmail->output->add_gui_object('all_headers_row', 'all-headers');
$rcmail->output->add_gui_object('all_headers_box', 'headers-source');
return html::div($attrib, $html);
}
/**
* Handler for the 'messagebody' GUI object
*
* @param array $attrib Named parameters
*
* @return string HTML content showing the message body
*/
public static function message_body($attrib)
{
- if (!is_array(self::$MESSAGE->parts) && empty(self::$MESSAGE->body)) {
+ if (
+ empty(self::$MESSAGE)
+ || (!is_array(self::$MESSAGE->parts) && empty(self::$MESSAGE->body))
+ ) {
return '';
}
if (empty($attrib['id'])) {
$attrib['id'] = 'rcmailMsgBody';
}
$rcmail = rcmail::get_instance();
$safe_mode = self::$MESSAGE->is_safe || !empty($_GET['_safe']);
$out = '';
$part_no = 0;
$header_attrib = [];
foreach ($attrib as $attr => $value) {
if (preg_match('/^headertable([a-z]+)$/i', $attr, $regs)) {
$header_attrib[$regs[1]] = $value;
}
}
if (!empty(self::$MESSAGE->parts)) {
foreach (self::$MESSAGE->parts as $part) {
if ($part->type == 'headers') {
$out .= html::div('message-partheaders', self::message_headers(count($header_attrib) ? $header_attrib : null, $part->headers));
}
else if ($part->type == 'content') {
// unsupported (e.g. encrypted)
if (!empty($part->realtype)) {
if ($part->realtype == 'multipart/encrypted' || $part->realtype == 'application/pkcs7-mime') {
if (
!empty($_SESSION['browser_caps']['pgpmime'])
&& ($pgp_mime_part = self::$MESSAGE->get_multipart_encrypted_part())
) {
$out .= html::span('part-notice', $rcmail->gettext('externalmessagedecryption'));
$rcmail->output->set_env('pgp_mime_part', $pgp_mime_part->mime_id);
$rcmail->output->set_env('pgp_mime_container', '#' . $attrib['id']);
$rcmail->output->add_label('loadingdata');
}
if (!self::$MESSAGE->encrypted_part) {
$out .= html::span('part-notice', $rcmail->gettext('encryptedmessage'));
}
}
continue;
}
else if (!$part->size) {
continue;
}
// Check if we have enough memory to handle the message in it
// #1487424: we need up to 10x more memory than the body
else if (!rcube_utils::mem_check($part->size * 10)) {
$out .= self::part_too_big_message(self::$MESSAGE, $part->mime_id);
continue;
}
// fetch part body
$body = self::$MESSAGE->get_part_body($part->mime_id, true);
// message is cached but not exists (#1485443), or other error
if ($body === false) {
// Don't bail out if it is only one-of-many part of the message (#6854)
if (strlen($out)) {
$out .= html::span('part-notice', $rcmail->gettext('messageopenerror'));
continue;
}
self::message_error();
}
$plugin = $rcmail->plugins->exec_hook('message_body_prefix',
['part' => $part, 'prefix' => '', 'message' => self::$MESSAGE]);
// Set attributes of the part container
$container_class = $part->ctype_secondary == 'html' ? 'message-htmlpart' : 'message-part';
$container_id = $container_class . (++$part_no);
$container_attrib = ['class' => $container_class, 'id' => $container_id];
$body_args = [
'safe' => $safe_mode,
'plain' => !$rcmail->config->get('prefer_html'),
'css_prefix' => 'v' . $part_no,
'body_class' => 'rcmBody',
'container_id' => $container_id,
'container_attrib' => $container_attrib,
];
// Parse the part content for display
$body = self::print_body($body, $part, $body_args);
// check if the message body is PGP encrypted
if (strpos($body, '-----BEGIN PGP MESSAGE-----') !== false) {
$rcmail->output->set_env('is_pgp_content', '#' . $container_id);
}
if ($part->ctype_secondary == 'html') {
$body = self::html4inline($body, $body_args);
}
$out .= html::div($body_args['container_attrib'], $plugin['prefix'] . $body);
}
}
}
else {
// Check if we have enough memory to handle the message in it
// #1487424: we need up to 10x more memory than the body
if (isset(self::$MESSAGE->body) && !rcube_utils::mem_check(strlen(self::$MESSAGE->body) * 10)) {
$out .= self::part_too_big_message(self::$MESSAGE, 0);
}
else {
$plugin = $rcmail->plugins->exec_hook('message_body_prefix',
['part' => self::$MESSAGE, 'prefix' => '']);
$out .= html::div('message-part',
$plugin['prefix'] . self::plain_body(self::$MESSAGE->body));
}
}
// list images after mail body
if ($rcmail->config->get('inline_images', true) && !empty(self::$MESSAGE->attachments)) {
$thumbnail_size = $rcmail->config->get('image_thumbnail_size', 240);
$show_label = rcube::Q($rcmail->gettext('showattachment'));
$download_label = rcube::Q($rcmail->gettext('download'));
foreach (self::$MESSAGE->attachments as $attach_prop) {
// Content-Type: image/*...
if ($mimetype = self::part_image_type($attach_prop)) {
// Skip inline images
if (!self::is_attachment(self::$MESSAGE, $attach_prop)) {
continue;
}
// display thumbnails
if ($thumbnail_size) {
$supported = in_array($mimetype, self::$CLIENT_MIMETYPES);
$show_link_attr = [
'href' => self::$MESSAGE->get_part_url($attach_prop->mime_id, false),
'onclick' => sprintf(
'%s.command(\'load-attachment\',\'%s\',this); return false',
rcmail_output::JS_OBJECT_NAME,
$attach_prop->mime_id
)
];
$download_link_attr = [
'href' => $show_link_attr['href'] . '&_download=1',
];
$show_link = html::a($show_link_attr + ['class' => 'open'], $show_label);
$download_link = html::a($download_link_attr + ['class' => 'download'], $download_label);
$out .= html::p(['class' => 'image-attachment', 'style' => $supported ? '' : 'display:none'],
html::a($show_link_attr + ['class' => 'image-link', 'style' => sprintf('width:%dpx', $thumbnail_size)],
html::img([
'class' => 'image-thumbnail',
'src' => self::$MESSAGE->get_part_url($attach_prop->mime_id, 'image') . '&_thumb=1',
'title' => $attach_prop->filename,
'alt' => $attach_prop->filename,
'style' => sprintf('max-width:%dpx; max-height:%dpx', $thumbnail_size, $thumbnail_size),
'onload' => $supported ? '' : '$(this).parents(\'p.image-attachment\').show()',
])
) .
html::span('image-filename', rcube::Q($attach_prop->filename)) .
html::span('image-filesize', rcube::Q(self::message_part_size($attach_prop))) .
html::span('attachment-links', ($supported ? $show_link . '&nbsp;' : '') . $download_link) .
html::br(['style' => 'clear:both'])
);
}
else {
$out .= html::tag('fieldset', 'image-attachment',
html::tag('legend', 'image-filename', rcube::Q($attach_prop->filename)) .
html::p(['align' => 'center'],
html::img([
'src' => self::$MESSAGE->get_part_url($attach_prop->mime_id, 'image'),
'title' => $attach_prop->filename,
'alt' => $attach_prop->filename,
])
)
);
}
}
}
}
// tell client that there are blocked remote objects
if (self::$REMOTE_OBJECTS && !$safe_mode) {
$rcmail->output->set_env('blockedobjects', true);
}
$rcmail->output->add_gui_object('messagebody', $attrib['id']);
return html::div($attrib, $out);
}
/**
* Returns a HTML notice element for too big message parts
*
* @param rcube_message $message Email message object
* @param string $part_id Message part identifier
*
* @return string HTML content
*/
public static function part_too_big_message($message, $part_id)
{
$rcmail = rcmail::get_instance();
$token = $rcmail->get_request_token();
$url = $rcmail->url([
'task' => 'mail',
'action' => 'get',
'download' => 1,
'uid' => $message->uid,
'part' => $part_id,
'mbox' => $message->folder,
'token' => $token,
]);
return html::span('part-notice', $rcmail->gettext('messagetoobig')
. '&nbsp;' . html::a($url, $rcmail->gettext('download')));
}
/**
* Handle disposition notification requests
*
* @param rcube_message $message Email message object
*/
public static function mdn_request_handler($message)
{
$rcmail = rcmail::get_instance();
if ($message->headers->mdn_to
&& $message->context === null
&& !empty($message->sender['mailto'])
&& empty($message->headers->flags['MDNSENT'])
&& empty($message->headers->flags['SEEN'])
&& ($rcmail->storage->check_permflag('MDNSENT') || $rcmail->storage->check_permflag('*'))
&& $message->folder != $rcmail->config->get('drafts_mbox')
&& $message->folder != $rcmail->config->get('sent_mbox')
) {
$mdn_cfg = intval($rcmail->config->get('mdn_requests'));
$exists = $mdn_cfg == 1;
// Check sender existence in contacts
// 3 and 4 = my contacts, 5 and 6 = trusted senders
if ($mdn_cfg == 3 || $mdn_cfg == 4 || $mdn_cfg == 5 || $mdn_cfg == 6) {
$type = rcube_addressbook::TYPE_TRUSTED_SENDER;
if ($mdn_cfg == 3 || $mdn_cfg == 4) {
$type |= rcube_addressbook::TYPE_WRITEABLE | rcube_addressbook::TYPE_RECIPIENT;
}
if ($rcmail->contact_exists($message->sender['mailto'], $type)) {
$exists = 1;
}
}
if ($exists) {
// Send MDN
if (rcmail_action_mail_sendmdn::send_mdn($message, $smtp_error)) {
$rcmail->output->show_message('receiptsent', 'confirmation');
}
else if ($smtp_error && is_string($smtp_error)) {
$rcmail->output->show_message($smtp_error, 'error');
}
else if ($smtp_error && !empty($smtp_error['label'])) {
$rcmail->output->show_message($smtp_error['label'], 'error', $smtp_error['vars']);
}
else {
$rcmail->output->show_message('errorsendingreceipt', 'error');
}
}
else if ($mdn_cfg != 2 && $mdn_cfg != 4 && $mdn_cfg != 6) {
// Ask the user
$rcmail->output->add_label('sendreceipt', 'mdnrequest', 'send', 'sendalwaysto', 'ignore');
$rcmail->output->set_env('mdn_request_save', $mdn_cfg == 3 || $mdn_cfg == 5 ? $mdn_cfg : 0);
$rcmail->output->set_env('mdn_request_sender', $message->sender);
$rcmail->output->set_env('mdn_request', true);
}
}
}
/**
* Check whether the message part is a normal attachment
*
* @param rcube_message $message Message object
* @param rcube_message_part $part Message part
*
* @return bool
*/
protected static function is_attachment($message, $part)
{
// Inline attachment with Content-Id specified
if (!empty($part->content_id) && $part->disposition == 'inline') {
return false;
}
// Any image attached to multipart/related message (#7184)
$parent_id = preg_replace('/\.[0-9]+$/', '', $part->mime_id);
$parent = $message->mime_parts[$parent_id] ?? null;
if ($parent && $parent->mimetype == 'multipart/related') {
return false;
}
return true;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Apr 5 2026, 9:10 PM (4 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18831186
Default Alt Text
(59 KB)

Event Timeline