* Copyright (c) 2003-2010 Paul Lesniewski * Licensed under the GNU GPL. For full terms see the file COPYING. * * @package plugins * @subpackage quicksave * */ /** * Present user quicksave preferences on display/compose * options page for SquirrelMail 1.5.x * */ function quicksave_options_15_do() { // SquirrelMail 1.4? bail. // if (!check_sm_version(1, 5, 2)) return; quicksave_options(); } /** * Present user quicksave preferences on display/compose * options page for SquirrelMail 1.4.x * */ function quicksave_options_14_do() { // SquirrelMail 1.5? bail. // if (check_sm_version(1, 5, 2)) return; quicksave_options(); } /** * Present user quicksave preferences on display/compose * options page * */ function quicksave_options() { global $username, $data_dir, $default_save_frequency, $default_cookie_encryption, $default_save_frequency_units, $user_can_override_save_frequency, $user_can_override_save_frequency_units, $user_can_override_encryption; include_once(SM_PATH . 'plugins/quicksave/common_functions.php'); quicksave_init(); $frequency = $default_save_frequency; $units = $default_save_frequency_units; $encryption = $default_cookie_encryption; if ($user_can_override_save_frequency) { $frequency = getPref($data_dir, $username, 'quicksave_frequency', $frequency); if ($user_can_override_save_frequency_units) $units = getPref($data_dir, $username, 'quicksave_units', $units); } if ($user_can_override_encryption) $encryption = getPref($data_dir, $username, 'quicksave_encryption', $encryption); sq_change_text_domain('quicksave'); global $optpage_data; if ($user_can_override_save_frequency) { $optpage_data['vals']['quicksave'][] = array( 'name' => 'quicksave_frequency', 'caption' => _("Message Save Frequency"), 'trailing_text' => _("(set to zero to turn off)"), 'type' => SMOPT_TYPE_INTEGER, 'initial_value' => $frequency, 'refresh' => SMOPT_REFRESH_NONE, 'size' => SMOPT_SIZE_TINY, ); if ($user_can_override_save_frequency_units) $optpage_data['vals']['quicksave'][] = array( 'name' => 'quicksave_units', 'caption' => _("Message Save Units"), 'posvals' => array( 'seconds' => _("Seconds"), 'miliseconds' => _("Miliseconds"), ), 'type' => SMOPT_TYPE_STRLIST, 'initial_value' => $units, 'refresh' => SMOPT_REFRESH_NONE, ); } if ($user_can_override_encryption) $optpage_data['vals']['quicksave'][] = array( 'name' => 'quicksave_encryption', 'caption' => _("Cookie Encryption Level"), 'posvals' => array( 'none' => _("None"), 'low' => _("Low"), 'medium' => _("Medium"), 'moderate' => _("Moderate"), ), 'type' => SMOPT_TYPE_STRLIST, 'initial_value' => $encryption, 'refresh' => SMOPT_REFRESH_NONE, ); if (!empty($optpage_data['vals']['quicksave'])) $optpage_data['grps']['quicksave'] = _("Auto Message Save and Recovery"); sq_change_text_domain('squirrelmail'); } /** * Set flag indicating message was sent * */ function quicksave_message_sent_do($args) { global $javascript_on; if (!$javascript_on) return; $current_hook_name = get_current_hook_name($args); // only use compose_send_after hook when in SM 1.4.6+ // and only use compose_send hook when in SM 1.4.5- // if (check_sm_version(1, 4, 6)) { // even 1.4.6+ needs to work with drafts on the // compose_send hook // if ($current_hook_name == 'compose_send') { global $draft; if ($draft) sqsession_register('sent', 'quicksave_message_sent_status'); return; } // on compose_send_after hook, we have access to information // about whether or not the message was actually sent, // which is very helpful! // if (check_sm_version(1, 5, 2)) $result = $args[0]; else $result = $args[1]; if (!$result) return; } else { if ($current_hook_name == 'compose_send_after') return; } // set "message sent" status flag // sqsession_register('sent', 'quicksave_message_sent_status'); } /** * Turn off quicksave if "message sent" flag is set * */ function quicksave_clear_do() { global $javascript_on; if (!$javascript_on) return; // on compose screen, make sure html_mail has all its // compose_bottom code added before quicksave // global $PHP_SELF; if (stristr($PHP_SELF, 'src/compose.php')) reposition_plugin_on_hook('quicksave', 'compose_bottom', FALSE, 'html_mail'); //TODO: if SM core has $compose_messages purged, won't need qs_cancelled (see below) global $quicksave_message_sent_status, $qs_cancelled, $username; sqGetGlobalVar('quicksave_message_sent_status', $quicksave_message_sent_status, SQ_SESSION); //TODO: if SM core has $compose_messages purged, won't need qs_cancelled (see below) sqGetGlobalVar('qs_cancelled', $qs_cancelled, SQ_FORM); $qs_username = preg_replace('/[\.@_]/', '', $username); // now, deal with the message sent flag // if (!empty($quicksave_message_sent_status) && $quicksave_message_sent_status == 'sent') { $quicksave_message_sent_status = 'not_sent'; sqsession_register($quicksave_message_sent_status, 'quicksave_message_sent_status'); // SM 1.5.2+ no output has gone to browser yet, so // just use PHP to remove quicksave message cache // if (check_sm_version(1, 5, 2)) { sqsetcookie('QS' . $qs_username . 'is_active', 0, 0, '', '', false, false); //TODO: when AJAXified, here is were we can simply wipe message cache from our server-side store } // SM 1.4.x, manage the cookie in JavaScript // else { ?> 0) { $quick_save_return_url = 'read_body.php' . '?passed_id=' . (($forward_id > 0) ? $forward_id : $passed_id) . '&startMessage=' . $startMessage . '&mailbox=' . $urlMailbox . (isset($passed_ent_id) ? '&passed_ent_id=' . $passed_ent_id : '') //TODO: if SM core has $compose_messages purged, won't need qs_cancelled . '&qs_cancelled=1'; } // or if they're replyinging to an email... // elseif ( strpos($action, 'reply') !== FALSE || $reply_id > 0 ) { $quick_save_return_url = 'read_body.php' . '?passed_id=' . (($reply_id > 0) ? $reply_id : $passed_id) . '&startMessage=' . $startMessage . '&mailbox=' . $urlMailbox . (isset($passed_ent_id) ? '&passed_ent_id=' . $passed_ent_id : '') //TODO: if SM core has $compose_messages purged, won't need qs_cancelled . '&qs_cancelled=1'; } // or if they're just composing from anywhere else, we return to the list // else { $quick_save_return_url = 'right_main.php' . '?startMessage=' . $startMessage . '&mailbox=' . $urlMailbox //TODO: if SM core has $compose_messages purged, won't need qs_cancelled . '&qs_cancelled=1'; } sq_change_text_domain('quicksave'); // SM 1.5.2+, just add a button // if (check_sm_version(1, 5, 2)) { global $oTemplate; $nbsp = $oTemplate->fetch('non_breaking_space.tpl'); $output = addButton(_("Cancel"), 'qscancel', array('onclick' => 'quicksave_cancel_button(\'' . $quick_save_return_url . '\'); ' ) ) . $nbsp; sq_change_text_domain('squirrelmail'); return array('compose_button_row' => $output); } // SquirrelMail 1.4.x // else { echo ''; } sq_change_text_domain('squirrelmail'); } /** * Add the code that does all the work onto the compose page * */ function quicksave_compose_functions_do() { global $javascript_on; if (!$javascript_on) return; global $sigappend, $from_htmladdr_search, $restrict_senders_error_no_to_recipients, $restrict_senders_error_too_many_recipients, $compose_new_win, $mail_sent, $restrict_senders_error_too_many_emails_today, $banned_possible_spammer, $quicksave_message_sent_status, $censored, $session_expired; sqGetGlobalVar('sigappend', $sigappend, SQ_FORM); sqGetGlobalVar('from_htmladdr_search', $from_htmladdr_search, SQ_FORM); sqGetGlobalVar('restrict_senders_error_too_many_recipients', $restrict_senders_error_too_many_recipients, SQ_FORM); sqGetGlobalVar('restrict_senders_error_no_to_recipients', $restrict_senders_error_no_to_recipients, SQ_FORM); sqgetGlobalVar('restrict_senders_error_too_many_emails_today', $restrict_senders_error_too_many_emails_today, SQ_FORM); sqgetGlobalVar('banned_possible_spammer', $banned_possible_spammer, SQ_FORM); sqgetGlobalVar('censored', $censored, SQ_FORM); sqGetGlobalVar('mail_sent', $mail_sent, SQ_FORM); sqGetGlobalVar('quicksave_message_sent_status', $quicksave_message_sent_status, SQ_SESSION); sq_change_text_domain('quicksave'); // don't offer any recovery if user just clicked to add // a signature or upload a file or add addresses, etc // or if SquirrelMail's own compose session restore is // doing the job or if our "message has been sent" flag // is on (usually happens when in compose_in_new) // if ($sigappend != 'Signature' && $from_htmladdr_search != 'true' && !$session_expired && $restrict_senders_error_no_to_recipients != 1 && $restrict_senders_error_too_many_recipients != 1 && $restrict_senders_error_too_many_emails_today != 1 && $banned_possible_spammer != 1 && $censored != 1 && empty($_FILES['attachfile']) // NOTE: prior version of quicksave only did the following check if $compose_in_new is turned on or if $mail_sent is 'yes', but technically, if quicksave is working correctly, those are not useful... if this becomes a problem, they could be added back... && (empty($quicksave_message_sent_status) || $quicksave_message_sent_status != 'sent')) { $offer_recovery_OK = TRUE; } else { $offer_recovery_OK = FALSE; $quicksave_message_sent_status = 'not_sent'; // the below causes PHP error in 1.5.2 until 1.5.2 is fixed so compose.php // uses templates for all output; not sure if this happens in 1.4.x too... // plugin might work OK without this...? if (!headers_sent()) sqsession_register($quicksave_message_sent_status, 'quicksave_message_sent_status'); } // figure out where (for use in JavaScript code) the message // body is located - when using HTML_Mail plugin, it isn't // in regular text area // $message_body_location_test = 'if (document.compose.body)'; $message_body_location_restore_test = 'if (document.compose.body)'; $message_body_html = 'document.compose.body.value'; if (is_plugin_enabled('html_mail')) { include_once(SM_PATH . 'plugins/html_mail/functions.php'); if (html_area_is_on_and_is_supported_by_users_browser()) { global $editor_style, $allow_change_html_editor_style; hm_get_config(); if ($allow_change_html_editor_style) $editor_style = getPref($data_dir, $username, 'html_editor_style', $editor_style); list($browser, $browserVersion) = getBrowserType(); // FCKeditor // if ($editor_style == 1) { // IE // if ($browser == 'Explorer' && $browserVersion >= 5.5) { $message_body_location_test = 'if (document.frames[0].document.frames[0].document.body)'; $message_body_location_restore_test = 'if (document.frames[0].document.frames[0].document.body)'; $message_body_html = 'document.frames[0].document.frames[0].document.body.innerHTML'; } // Gecko // else if ($browser == 'Gecko' && $browserVersion >= 20030624) { $message_body_location_test = 'if (document.getElementsByTagName("iframe").item(0).contentDocument.getElementsByTagName("iframe").item(0).contentDocument.body)'; $message_body_location_restore_test = 'if (0)'; $message_body_html = 'document.getElementsByTagName("iframe").item(0).contentDocument.getElementsByTagName("iframe").item(0).contentDocument.body.innerHTML'; // supposedly these work for updated fckeditor versions // $message_body_location_test = 'if(document.getElementById("body___Frame").contentDocument.getElementById("xEditingArea").getElementsByTagName("iframe")[0].contentDocument.body)'; // $message_body_html = 'document.getElementById("body___Frame").contentDocument.getElementById("xEditingArea").getElementsByTagName("iframe")[0].contentDocument.body.innerHTML'; } } // HTMLArea editor // else if ($editor_style == 2) { // IE // if ($browser == 'Explorer' && $browserVersion >= 5.5) { $message_body_location_test = 'if (document.frames[0].document.body)'; $message_body_location_restore_test = 'if (0)'; $message_body_html = 'document.frames[0].document.body.innerHTML'; } // Gecko // else if ($browser == 'Gecko' && $browserVersion >= 20030624) { $message_body_location_test = 'if (document.getElementsByTagName("iframe").item(0).contentDocument.body)'; //FIXME: which is best? both the next two lines seem to work *sometimes*... shrug //$message_body_location_restore_test = 'if (document.getElementsByTagName("iframe").item(0).contentDocument.body)'; $message_body_location_restore_test = 'if (0)'; $message_body_html = 'document.getElementsByTagName("iframe").item(0).contentDocument.body.innerHTML'; } } } } global $quicksave_cookie_days, $quicksave_cookie_hours, $quicksave_cookie_minutes, $maxCookieLength, $maxCookies, $useMultipleCookies, $maxSingleCookieLength, $username, $data_dir, $plugins, $default_cookie_encryption, $user_can_override_encryption; $qs_username = preg_replace('/[\.@_]/', '', $username); include_once(SM_PATH . 'plugins/quicksave/common_functions.php'); quicksave_init(); $encryption = $default_cookie_encryption; if ($user_can_override_encryption) $encryption = getPref($data_dir, $username, 'quicksave_encryption', $encryption); $cookie_time_miliseconds = ($quicksave_cookie_days * 24 * 60 * 60 * 1000) + ($quicksave_cookie_hours * 60 * 60 * 1000) + ($quicksave_cookie_minutes * 60 * 1000); // begin building JavaScript output // $output = "\n\n" . "\n" . "\n\n"; // send output to browser // if (check_sm_version(1, 5, 2)) { // for now, there is no template needed because this // is all just javascript without formatting... also, // the compose_bottom hook in 1.5.2+ is such that it // currently is just like 1.4.x where output goes out // to browser right here (it's not an in-template hook // for example) // echo $output; } else echo $output; sq_change_text_domain('squirrelmail'); }