From 77b5d7ee304a688a2eb115ce04b460b43c0dd700 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak <alec@alec.pl> Date: Sun, 22 May 2016 08:43:54 -0400 Subject: [PATCH] Fix priority icon(s) position --- program/steps/settings/save_identity.inc | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 45 insertions(+), 6 deletions(-) diff --git a/program/steps/settings/save_identity.inc b/program/steps/settings/save_identity.inc index 1584c5f..8ffe39e 100644 --- a/program/steps/settings/save_identity.inc +++ b/program/steps/settings/save_identity.inc @@ -1,6 +1,6 @@ <?php -/* +/** +-----------------------------------------------------------------------+ | program/steps/settings/save_identity.inc | | | @@ -26,8 +26,8 @@ $updated = $default_id = false; // check input -if (IDENTITIES_LEVEL != 4 && (empty($_POST['_name']) || (empty($_POST['_email']) && IDENTITIES_LEVEL != 1 && IDENTITIES_LEVEL != 3))) { - $OUTPUT->show_message('formincomplete', 'warning'); +if (empty($_POST['_email']) && (IDENTITIES_LEVEL == 0 || IDENTITIES_LEVEL == 2)) { + $OUTPUT->show_message('noemailwarning', 'warning'); $RCMAIL->overwrite_action('edit-identity'); return; } @@ -47,6 +47,11 @@ if (!isset($_POST[$fname])) { $save_data[$col] = 0; } +} + +// make the identity a "default" if only one identity is allowed +if (IDENTITIES_LEVEL > 1) { + $save_data['standard'] = 1; } // unset email address if user has no rights to change it @@ -79,8 +84,11 @@ } } -// XSS protection in HTML signature (#1489251) if (!empty($save_data['signature']) && !empty($save_data['html_signature'])) { + // replace uploaded images with data URIs + $save_data['signature'] = rcmail_attach_images($save_data['signature']); + + // XSS protection in HTML signature (#1489251) $save_data['signature'] = rcmail_wash_html($save_data['signature']); // clear POST data of signature, we want to use safe content @@ -127,7 +135,7 @@ } else { // show error message - $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false); + $OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error', null, false); $RCMAIL->overwrite_action('edit-identity'); return; } @@ -151,6 +159,8 @@ $insert_id = $plugin['result']; if ($insert_id) { + $RCMAIL->plugins->exec_hook('identity_create_after', array('id' => $insert_id, 'record' => $save_data)); + $OUTPUT->show_message('successfullysaved', 'confirmation', null, false); $_GET['_iid'] = $insert_id; @@ -167,7 +177,7 @@ } else { // show error message - $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false); + $OUTPUT->show_message($plugin['message'] ?: 'errorsaving', 'error', null, false); $RCMAIL->overwrite_action('edit-identity'); return; } @@ -191,6 +201,35 @@ /** + * Attach uploaded images into signature as data URIs + */ +function rcmail_attach_images($html) +{ + global $RCMAIL; + + $offset = 0; + $regexp = '/\s(poster|src)\s*=\s*[\'"]*\S+upload-display\S+file=rcmfile(\w+)[\s\'"]*/'; + + while (preg_match($regexp, $html, $matches, 0, $offset)) { + $file_id = $matches[2]; + $data_uri = ' '; + + if ($file_id && ($file = $_SESSION['identity']['files'][$file_id])) { + $file = $RCMAIL->plugins->exec_hook('attachment_get', $file); + + $data_uri .= 'src="data:' . $file['mimetype'] . ';base64,'; + $data_uri .= base64_encode($file['data'] ?: file_get_contents($file['path'])); + $data_uri .= '" '; + } + + $html = str_replace($matches[0], $data_uri, $html); + $offset += strlen($data_uri) - strlen($matches[0]) + 1; + } + + return $html; +} + +/** * Sanity checks/cleanups on HTML body of signature */ function rcmail_wash_html($html) -- Gitblit v1.9.1