function newmail_plugin() { global $username, $key, $imapServerAddress, $imapPort, $newmail_media, $newmail_enable, $newmail_popup, $newmail_popup_height, $newmail_popup_width, $newmail_recent, $newmail_changetitle, $imapConnection; include_once SM_PATH . 'functions/display_messages.php'; if ($newmail_enable == 'on' || $newmail_popup == 'on' || $newmail_changetitle) { // open a connection on the imap port (143) $boxes = sqimap_mailbox_list($imapConnection); $delimeter = sqimap_get_delimiter($imapConnection); $status = 0; $totalNew = 0; for ($i = 0; $i < count($boxes); $i++) { $line = ''; $mailbox = $boxes[$i]['formatted']; if (!isset($boxes[$i]['unseen'])) { $boxes[$i]['unseen'] = ''; } if ($boxes[$i]['flags']) { $noselect = false; for ($h = 0; $h < count($boxes[$i]['flags']); $h++) { if (strtolower($boxes[$i]["flags"][$h]) == 'noselect') { $noselect = TRUE; } } if (!$noselect) { $status += CheckNewMailboxSound($imapConnection, $mailbox, $boxes[$i]['unformatted'], $delimeter, $boxes[$i]['unseen'], $totalNew); } } else { $status += CheckNewMailboxSound($imapConnection, $mailbox, $boxes[$i]['unformatted'], $delimeter, $boxes[$i]['unseen'], $totalNew); } } // sqimap_logout($imapConnection); // If we found unseen messages, then we // will play the sound as follows: if ($newmail_changetitle) { echo "<script language=\"javascript\" type=\"text/javascript\">\n" . "function ChangeTitleLoad() {\n"; if ($totalNew > 1 || $totalNew == 0) { echo 'window.parent.document.title = "' . sprintf(_("%s New Messages"), $totalNew) . "\";\n"; } else { echo 'window.parent.document.title = "' . sprintf(_("%s New Message"), $totalNew) . "\";\n"; } echo "if (BeforeChangeTitle != null)\n" . "BeforeChangeTitle();\n" . "}\n" . "BeforeChangeTitle = window.onload;\n" . "window.onload = ChangeTitleLoad;\n" . "</script>\n"; } if ($totalNew > 0 && $newmail_enable == 'on' && $newmail_media != '' && $newmail_media != '(none)') { $newmail_media = sqm_baseuri() . 'plugins/newmail/sounds/' . basename($newmail_media); echo '<embed src="' . htmlspecialchars($newmail_media) . "\" hidden=\"true\" autostart=\"true\" width=\"2\" height=\"2\">\n"; } if ($totalNew > 0 && $newmail_popup == 'on') { echo "<script language=\"JavaScript\">\n" . "<!--\n" . "function PopupScriptLoad() {\n" . 'window.open("' . sqm_baseuri() . 'plugins/newmail/newmail.php?numnew=' . $totalNew . '", "SMPopup",' . "\"width=" . (int) $newmail_popup_width . ",height=" . (int) $newmail_popup_height . ",scrollbars=no\");\n" . "if (BeforePopupScript != null)\n" . "BeforePopupScript();\n" . "}\n" . "BeforePopupScript = window.onload;\n" . "window.onload = PopupScriptLoad;\n" . "// End -->\n" . "</script>\n"; } } }
// (such as HTTPOnly, if necessary - PHP doesn't do this itself sqsetcookie(session_name(), session_id(), false, $base_uri); } $onetimepad = OneTimePadCreate(strlen($secretkey)); $key = OneTimePadEncrypt($secretkey, $onetimepad); sqsession_register($onetimepad, 'onetimepad'); /* remove redundant spaces */ $login_username = trim($login_username); /* Verify that username and password are correct. */ if ($force_username_lowercase) { $login_username = strtolower($login_username); } $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0); $sqimap_capabilities = sqimap_capability($imapConnection); sqsession_register($sqimap_capabilities, 'sqimap_capabilities'); $delimiter = sqimap_get_delimiter($imapConnection); sqimap_logout($imapConnection); sqsession_register($delimiter, 'delimiter'); $username = $login_username; sqsession_register($username, 'username'); sqsetcookie('key', $key, 0, $base_uri); do_hook('login_verified'); } /* Set the login variables. */ $user_is_logged_in = true; $just_logged_in = true; /* And register with them with the session. */ sqsession_register($user_is_logged_in, 'user_is_logged_in'); sqsession_register($just_logged_in, 'just_logged_in'); /* parse the accepted content-types of the client */ $attachment_common_types = array();
/** * This function builds an array with all the information about * the options available to the user, and returns it. The options * are grouped by the groups in which they are displayed. * For each option, the following information is stored: * - name: the internal (variable) name * - caption: the description of the option in the UI * - type: one of SMOPT_TYPE_* * - refresh: one of SMOPT_REFRESH_* * - size: one of SMOPT_SIZE_* * - save: the name of a function to call when saving this option * @return array all option information */ function load_optpage_data_folder() { global $username, $key, $imapServerAddress, $imapPort; global $folder_prefix, $default_folder_prefix, $show_prefix_option; /* Get some imap data we need later. */ $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); $boxes = sqimap_mailbox_list($imapConnection); /* Build a simple array into which we will build options. */ $optgrps = array(); $optvals = array(); /******************************************************/ /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */ /******************************************************/ /*** Load the General Options into the array ***/ $optgrps[SMOPT_GRP_SPCFOLDER] = _("Special Folder Options"); $optvals[SMOPT_GRP_SPCFOLDER] = array(); if (!isset($folder_prefix)) { $folder_prefix = $default_folder_prefix; } if ($show_prefix_option) { $optvals[SMOPT_GRP_SPCFOLDER][] = array('name' => 'folder_prefix', 'caption' => _("Folder Path"), 'type' => SMOPT_TYPE_STRING, 'refresh' => SMOPT_REFRESH_FOLDERLIST, 'size' => SMOPT_SIZE_LARGE); } $trash_folder_values = array(SMPREF_NONE => '[ ' . _("Do not use Trash") . ' ]', 'whatever' => $boxes); $optvals[SMOPT_GRP_SPCFOLDER][] = array('name' => 'trash_folder', 'caption' => _("Trash Folder"), 'type' => SMOPT_TYPE_FLDRLIST, 'refresh' => SMOPT_REFRESH_FOLDERLIST, 'posvals' => $trash_folder_values, 'save' => 'save_option_trash_folder'); $draft_folder_values = array(SMPREF_NONE => '[ ' . _("Do not use Drafts") . ' ]', 'whatever' => $boxes); $optvals[SMOPT_GRP_SPCFOLDER][] = array('name' => 'draft_folder', 'caption' => _("Draft Folder"), 'type' => SMOPT_TYPE_FLDRLIST, 'refresh' => SMOPT_REFRESH_FOLDERLIST, 'posvals' => $draft_folder_values, 'save' => 'save_option_draft_folder'); $sent_folder_values = array(SMPREF_NONE => '[ ' . _("Do not use Sent") . ' ]', 'whatever' => $boxes); $optvals[SMOPT_GRP_SPCFOLDER][] = array('name' => 'sent_folder', 'caption' => _("Sent Folder"), 'type' => SMOPT_TYPE_FLDRLIST, 'refresh' => SMOPT_REFRESH_FOLDERLIST, 'posvals' => $sent_folder_values, 'save' => 'save_option_sent_folder'); /*** Load the General Options into the array ***/ $optgrps[SMOPT_GRP_FOLDERLIST] = _("Folder List Options"); $optvals[SMOPT_GRP_FOLDERLIST] = array(); $optvals[SMOPT_GRP_FOLDERLIST][] = array('name' => 'location_of_bar', 'caption' => _("Location of Folder List"), 'type' => SMOPT_TYPE_STRLIST, 'refresh' => SMOPT_REFRESH_ALL, 'posvals' => array(SMPREF_LOC_LEFT => _("Left"), SMPREF_LOC_RIGHT => _("Right"))); $left_size_values = array(); for ($lsv = 100; $lsv <= 300; $lsv += 10) { $left_size_values[$lsv] = "{$lsv} " . _("pixels"); } $optvals[SMOPT_GRP_FOLDERLIST][] = array('name' => 'left_size', 'caption' => _("Width of Folder List"), 'type' => SMOPT_TYPE_STRLIST, 'refresh' => SMOPT_REFRESH_ALL, 'posvals' => $left_size_values); $minute_str = _("Minutes"); $left_refresh_values = array(SMPREF_NONE => _("Never")); foreach (array(30, 60, 120, 180, 300, 600, 1200) as $lr_val) { if ($lr_val < 60) { $left_refresh_values[$lr_val] = "{$lr_val} " . _("Seconds"); } else { if ($lr_val == 60) { $left_refresh_values[$lr_val] = "1 " . _("Minute"); } else { $left_refresh_values[$lr_val] = $lr_val / 60 . " {$minute_str}"; } } } $optvals[SMOPT_GRP_FOLDERLIST][] = array('name' => 'left_refresh', 'caption' => _("Auto Refresh Folder List"), 'type' => SMOPT_TYPE_STRLIST, 'refresh' => SMOPT_REFRESH_FOLDERLIST, 'posvals' => $left_refresh_values); $optvals[SMOPT_GRP_FOLDERLIST][] = array('name' => 'unseen_notify', 'caption' => _("Enable Unread Message Notification"), 'type' => SMOPT_TYPE_STRLIST, 'refresh' => SMOPT_REFRESH_FOLDERLIST, 'posvals' => array(SMPREF_UNSEEN_NONE => _("No Notification"), SMPREF_UNSEEN_INBOX => _("Only INBOX"), SMPREF_UNSEEN_ALL => _("All Folders"))); $optvals[SMOPT_GRP_FOLDERLIST][] = array('name' => 'unseen_type', 'caption' => _("Unread Message Notification Type"), 'type' => SMOPT_TYPE_STRLIST, 'refresh' => SMOPT_REFRESH_FOLDERLIST, 'posvals' => array(SMPREF_UNSEEN_ONLY => _("Only Unseen"), SMPREF_UNSEEN_TOTAL => _("Unseen and Total"))); $optvals[SMOPT_GRP_FOLDERLIST][] = array('name' => 'collapse_folders', 'caption' => _("Enable Collapsable Folders"), 'type' => SMOPT_TYPE_BOOLEAN, 'refresh' => SMOPT_REFRESH_FOLDERLIST); $optvals[SMOPT_GRP_FOLDERLIST][] = array('name' => 'unseen_cum', 'caption' => _("Enable Cumulative Unread Message Notification"), 'type' => SMOPT_TYPE_BOOLEAN, 'refresh' => SMOPT_REFRESH_FOLDERLIST); $optvals[SMOPT_GRP_FOLDERLIST][] = array('name' => 'date_format', 'caption' => _("Show Clock on Folders Panel"), 'type' => SMOPT_TYPE_STRLIST, 'refresh' => SMOPT_REFRESH_FOLDERLIST, 'posvals' => array('0' => _("International date and time"), '1' => _("American date and time"), '2' => _("European date and time"), '3' => _("Show weekday and time"), '4' => _("Show time with seconds"), '5' => _("Show time"), '6' => _("No Clock"))); $optvals[SMOPT_GRP_FOLDERLIST][] = array('name' => 'hour_format', 'caption' => _("Hour Format"), 'type' => SMOPT_TYPE_STRLIST, 'refresh' => SMOPT_REFRESH_FOLDERLIST, 'posvals' => array(SMPREF_TIME_12HR => _("12-hour clock"), SMPREF_TIME_24HR => _("24-hour clock"))); $optvals[SMOPT_GRP_FOLDERLIST][] = array('name' => 'search_memory', 'caption' => _("Memory Search"), 'type' => SMOPT_TYPE_STRLIST, 'refresh' => SMOPT_REFRESH_NONE, 'posvals' => array(0 => _("Disabled"), 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9')); /*** Load the General Options into the array ***/ $optgrps[SMOPT_GRP_FOLDERSELECT] = _("Folder Selection Options"); $optvals[SMOPT_GRP_FOLDERSELECT] = array(); $delim = sqimap_get_delimiter($imapConnection); $optvals[SMOPT_GRP_FOLDERSELECT][] = array('name' => 'mailbox_select_style', 'caption' => _("Selection List Style"), 'type' => SMOPT_TYPE_STRLIST, 'refresh' => SMOPT_REFRESH_NONE, 'posvals' => array(0 => _("Long:") . ' "' . _("Folder") . $delim . _("Subfolder") . '"', 1 => _("Indented:") . ' " ' . _("Subfolder") . '"', 2 => _("Delimited:") . ' ". ' . _("Subfolder") . '"'), 'htmlencoded' => true); /* Assemble all this together and return it as our result. */ $result = array('grps' => $optgrps, 'vals' => $optvals); sqimap_logout($imapConnection); return $result; }
/** * Returns an array of mailboxes available. Separated from sqimap_mailbox_option_list() * below for template development. * * @author Steve Brown * @since 1.5.2 */ function sqimap_mailbox_option_array($imap_stream, $folder_skip = 0, $boxes = 0, $flag = 'noselect', $use_long_format = false) { global $username, $data_dir, $translate_special_folders, $sent_folder, $trash_folder, $draft_folder; $delimiter = sqimap_get_delimiter($imap_stream); $mbox_options = ''; if ($use_long_format) { $shorten_box_names = 0; } else { $shorten_box_names = getPref($data_dir, $username, 'mailbox_select_style', SMPREF_MAILBOX_SELECT_INDENTED); } if ($boxes == 0) { $boxes = sqimap_mailbox_list($imap_stream); } $a = array(); foreach ($boxes as $boxes_part) { if ($flag == NULL || is_array($boxes_part['flags']) && !in_array($flag, $boxes_part['flags'])) { $box = $boxes_part['unformatted']; if ($folder_skip != 0 && in_array($box, $folder_skip)) { continue; } $lowerbox = strtolower($box); // mailboxes are casesensitive => inbox.sent != inbox.Sent // nevermind, to many dependencies this should be fixed! if (strtolower($box) == 'inbox') { // inbox is special and not casesensitive $box2 = _("INBOX"); } else { switch ($shorten_box_names) { case SMPREF_MAILBOX_SELECT_DELIMITED: if ($translate_special_folders && $boxes_part['unformatted-dm'] == $sent_folder) { /* * calculate pad level from number of delimiters. do it inside if control in order * to reduce number of calculations. Other folders don't need it. */ $pad = str_pad('', 7 * (count(explode($delimiter, $boxes_part['unformatted-dm'])) - 1), '. '); // i18n: Name of Sent folder $box2 = $pad . _("Sent"); } elseif ($translate_special_folders && $boxes_part['unformatted-dm'] == $trash_folder) { $pad = str_pad('', 7 * (count(explode($delimiter, $boxes_part['unformatted-dm'])) - 1), '. '); // i18n: Name of Trash folder $box2 = $pad . _("Trash"); } elseif ($translate_special_folders && $boxes_part['unformatted-dm'] == $draft_folder) { $pad = str_pad('', 7 * (count(explode($delimiter, $boxes_part['unformatted-dm'])) - 1), '. '); // i18n: Name of Drafts folder $box2 = $pad . _("Drafts"); } else { $box2 = str_replace('&nbsp;&nbsp;', '. ', sm_encode_html_special_chars($boxes_part['formatted'])); } break; case SMPREF_MAILBOX_SELECT_INDENTED: if ($translate_special_folders && $boxes_part['unformatted-dm'] == $sent_folder) { $pad = str_pad('', 12 * (count(explode($delimiter, $boxes_part['unformatted-dm'])) - 1), ' '); $box2 = $pad . _("Sent"); } elseif ($translate_special_folders && $boxes_part['unformatted-dm'] == $trash_folder) { $pad = str_pad('', 12 * (count(explode($delimiter, $boxes_part['unformatted-dm'])) - 1), ' '); $box2 = $pad . _("Trash"); } elseif ($translate_special_folders && $boxes_part['unformatted-dm'] == $draft_folder) { $pad = str_pad('', 12 * (count(explode($delimiter, $boxes_part['unformatted-dm'])) - 1), ' '); $box2 = $pad . _("Drafts"); } else { $box2 = str_replace('&nbsp;&nbsp;', ' ', sm_encode_html_special_chars($boxes_part['formatted'])); } break; default: /* default, long names, style = 0 */ $box2 = str_replace(' ', ' ', sm_encode_html_special_chars(imap_utf7_decode_local($boxes_part['unformatted-disp']))); break; } } $a[sm_encode_html_special_chars($box)] = $box2; } } return $a; }