return $result;
}
+/*
+ * Returns list of options (to be echoed into select statement
+ * based on available mailboxes and separators
+ * Caller should surround options with <SELECT..> </SELECT> and
+ * any formatting.
+ * $imap_stream - $imapConnection to query for mailboxes
+ * $show_selected - array containing list of mailboxes to pre-select (0 if none)
+ * $folder_skip - array of folders to keep out of option list (compared in lower)
+ * $boxes - list of already fetched boxes (for places like folder panel, where
+ * you know these options will be shown 3 times in a row.. (most often unset).
+ */
+function sqimap_mailbox_option_list($imap_stream, $show_selected = 0, $folder_skip = 0, $boxes = 0 ) {
+ global $username, $data_dir;
+ $mbox_options = '';
+
+ $shorten_box_names = getPref($data_dir, $username, 'mailbox_select_style', SMPREF_OFF);
+
+ if ( $boxes == 0 ) {
+ $boxes = sqimap_mailbox_list($imap_stream);
+ }
+ foreach ($boxes as $boxes_part) {
+ if (!in_array('noselect', $boxes_part['flags'])) {
+ $box = $boxes_part['unformatted'];
+ $lowerbox = strtolower($box);
+
+ if ( $folder_skip != 0 && in_array($lowerbox, $folder_skip) ) {
+ continue;
+ }
+ if ($lowerbox == 'inbox'){
+ $box2 = _("INBOX");
+ } else if ( $shorten_box_names == 2 ) { /* delimited, style = 2 */
+ $box2 = str_replace(' ', '. ', $boxes_part['formatted']);
+ } else if ( $shorten_box_names == 1 ) { /* indent, style = 1 */
+ $box2 = $boxes_part['formatted'];
+ } else { /* default, long names, style = 0 */
+ $box2 = str_replace(' ', ' ', imap_utf7_decode_local($boxes_part['unformatted-disp']));
+ }
+ if ($show_selected != 0 && in_array($lowerbox, $show_selected) ) {
+ $mbox_options .= '<OPTION VALUE="'.$box.'" SELECTED>'.$box2.'</OPTION>' . "\n";
+ } else {
+ $mbox_options .= '<OPTION VALUE="'.$box.'">'.$box2.'</OPTION>' . "\n";
+ }
+ }
+ }
+ return $mbox_options;
+}
/*
* Returns sorted mailbox lists in several different ways.
function getMbxList($imapConnection) {
global $lastTargetMailbox;
echo ' <small> <tt><select name="targetMailbox">';
- $boxes = sqimap_mailbox_list($imapConnection);
- foreach ($boxes as $boxes_part) {
- if (!in_array('noselect', $boxes_part['flags'])) {
- $box = $boxes_part['unformatted'];
- $box2 = str_replace(' ', ' ', imap_utf7_decode_local($boxes_part['unformatted-disp']));
- if($box2 == 'INBOX') {
- $box2 = _("INBOX");
- }
- if ($lastTargetMailbox == $box) {
- echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
- } else {
- echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
- }
- }
- }
+ echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)) );
echo ' </SELECT></TT> ';
}
define('SMOPT_TYPE_BOOLEAN', 5);
define('SMOPT_TYPE_HIDDEN', 6);
define('SMOPT_TYPE_COMMENT', 7);
+define('SMOPT_TYPE_FLDRLIST', 8);
/* Define constants for the options refresh levels. */
define('SMOPT_REFRESH_NONE', 0);
case SMOPT_TYPE_COMMENT:
$result = $this->createWidget_Comment();
break;
+ case SMOPT_TYPE_FLDRLIST:
+ $result = $this->createWidget_FolderList();
+ break;
default:
$result = '<font color="' . $color[2] . '">'
. sprintf(_("Option Type '%s' Not Found"), $this->type)
return ($result);
}
+ function createWidget_FolderList() {
+ $selected = array(strtolower($this->value));
+
+ /* Begin the select tag. */
+ $result = "<select name=\"new_$this->name\">";
+
+ /* Add each possible value to the select list. */
+ foreach ($this->possible_values as $real_value => $disp_value) {
+ if ( is_array($disp_value) ) {
+ /* For folder list, we passed in the array of boxes.. */
+ $new_option = sqimap_mailbox_option_list(0, $selected, 0, $disp_value);
+ } else {
+ /* Start the next new option string. */
+ $new_option = "<option value=\"$real_value\"";
+
+ /* If this value is the current value, select it. */
+ if ($real_value == $this->value) {
+ $new_option .= ' selected';
+ }
+
+ /* Add the display value to our option string. */
+ $new_option .= ">$disp_value</option>";
+ }
+ /* And add the new option string to our select tag. */
+ $result .= $new_option;
+ }
+ /* Close the select tag and return our happy result. */
+ $result .= '</select>';
+ return ($result);
+ }
+
+
function createWidget_TextArea() {
switch ($this->size) {
case SMOPT_SIZE_TINY: $rows = 3; $cols = 10; break;
$forward_cc = getPref($data_dir, $username, 'forward_cc', 0);
+$mailbox_select_style = getPref($data_dir, $username, 'mailbox_select_style', 0);
+
do_hook('loading_prefs');
?>
/* SquirrelMail required files. */
require_once(SM_PATH . 'functions/imap.php');
+require_once(SM_PATH . 'functions/imap_general.php');
/* Define the group constants for the folder options page. */
define('SMOPT_GRP_SPCFOLDER', 0);
define('SMOPT_GRP_FOLDERLIST', 1);
+define('SMOPT_GRP_FOLDERSELECT', 2);
/* Define the optpage load function for the folder options page. */
function load_optpage_data_folder() {
);
}
- $special_folder_values = array();
- foreach ($boxes as $folder) {
- if (strtolower($folder['unformatted']) != 'inbox') {
- $real_value = $folder['unformatted-dm'];
- $disp_value = str_replace(' ', ' ', $folder['formatted']);
- $special_folder_values[$real_value] = $disp_value;
- }
- }
-
- $trash_none = array(SMPREF_NONE => _("Do not use Trash"));
- $trash_folder_values = array_merge($trash_none, $special_folder_values);
+ $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_STRLIST,
+ 'type' => SMOPT_TYPE_FLDRLIST,
'refresh' => SMOPT_REFRESH_FOLDERLIST,
'posvals' => $trash_folder_values,
'save' => 'save_option_trash_folder'
);
- $sent_none = array(SMPREF_NONE => _("Do not use Sent"));
- $sent_folder_values = array_merge($sent_none, $special_folder_values);
+ $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_STRLIST,
+ 'type' => SMOPT_TYPE_FLDRLIST,
'refresh' => SMOPT_REFRESH_FOLDERLIST,
'posvals' => $sent_folder_values,
'save' => 'save_option_sent_folder'
);
- $draft_none = array(SMPREF_NONE => _("Do not use Drafts"));
- $draft_folder_values = array_merge($draft_none, $special_folder_values);
+ $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_STRLIST,
+ 'type' => SMOPT_TYPE_FLDRLIST,
'refresh' => SMOPT_REFRESH_FOLDERLIST,
'posvals' => $draft_folder_values,
'save' => 'save_option_draft_folder'
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();
+ $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"')
+ );
+
/* Assemble all this together and return it as our result. */
$result = array(
'grps' => $optgrps,
function get_move_target_list() {
global $imapConnection;
-
- $boxes = sqimap_mailbox_list($imapConnection);
- for ($i = 0; $i < count($boxes); $i++) {
- if (!in_array('noselect', $boxes[$i]['flags'])) {
- $box = $boxes[$i]['unformatted'];
- $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
- if ( $box2 == 'INBOX' ) {
- $box2 = _("INBOX");
- }
- echo "<option value=\"$box\">$box2</option>\n";
- }
- }
+ echo sqimap_mailbox_option_list($imapConnection);
}
function delete_move_next_moveNextForm($next) {
echo '<OPTION VALUE="">[ '._("None")." ]\n";
}
-for ($i = 0, $cnt=count($boxes); $i < $cnt; $i++) {
- if (!in_array('noinferiors', $boxes[$i]['flags'])) {
- if ((strtolower($boxes[$i]['unformatted']) == 'inbox') &&
- $default_sub_of_inbox) {
-
- $box = $boxes[$i]['unformatted'];
- $box2 = str_replace(' ', ' ',
- imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
- echo "<OPTION SELECTED VALUE=\"$box\">$box2</option>\n";
- } else {
- $box = $boxes[$i]['unformatted'];
- $box2 = str_replace(' ', ' ',
- imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
- if (strtolower($imap_server_type) != 'courier' ||
- strtolower($box) != "inbox.trash")
- echo "<OPTION VALUE=\"$box\">$box2</option>\n";
- }
- }
+$show_selected = 0;
+if ( $default_sub_of_inbox ) {
+ $show_selected = array('inbox');
}
+$skip_folders = 0;
+if ( strtolower($imap_server_type) == 'courier' ) {
+ $skip_folders = array('inbox.trash');
+}
+
+echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors');
+
echo "</SELECT></TT>\n";
if ($show_contain_subfolders_option) {
echo '<br><input type=CHECKBOX NAME="contain_subs"> '
echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n"
. "<TT><SELECT NAME=old>\n"
. ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
- for ($i = 0; $i < count($boxes); $i++) {
- $use_folder = true;
- if ((strtolower($boxes[$i]['unformatted']) != 'inbox') &&
- ($boxes[$i]['unformatted'] != $trash_folder) &&
- ($boxes[$i]['unformatted'] != $sent_folder) &&
- ($boxes[$i]['unformatted'] != $draft_folder)) {
- $box = $boxes[$i]['unformatted-dm'];
+ echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes);
- $box2 = str_replace(' ', ' ',
- imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
- if (strtolower($imap_server_type) != 'courier' || strtolower($box) != 'inbox.trash') {
- echo "<OPTION VALUE=\"$box\">$box2</option>\n";
- }
- }
- }
echo "</SELECT></TT>\n".
"<input type=SUBMIT VALUE=\"".
_("Rename").
echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n"
. "<TT><SELECT NAME=mailbox>\n"
. ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
- for ($i = 0; $i < count($boxes); $i++) {
- $use_folder = true;
- if ((strtolower($boxes[$i]['unformatted']) != 'inbox') &&
- ($boxes[$i]['unformatted'] != $trash_folder) &&
- ($boxes[$i]['unformatted'] != $sent_folder) &&
- ($boxes[$i]['unformatted'] != $draft_folder) &&
- (!in_array('noselect', $boxes[$i]['flags'])) &&
- ((strtolower($imap_server_type) != 'courier') ||
- (strtolower($boxes[$i]['unformatted']) != 'inbox.trash'))) {
- $box = $boxes[$i]['unformatted-dm'];
- $box2 = str_replace(' ', ' ',
- imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
- echo " <OPTION VALUE=\"$box\">$box2</option>\n";
- }
- }
+
+ echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes);
+
echo "</SELECT></TT>\n"
. '<input type=SUBMIT VALUE="'
. _("Delete")
. html_tag( 'table', '', '', '', 'width="95%" cellpadding="0" cellspacing="0" border="0"' )
. html_tag( 'tr' )
. html_tag( 'td', '', 'left' )
- . '<select name="mailbox">';
-for ($i = 0; $i < count($boxes); $i++) {
- if (!in_array('noselect', $boxes[$i]['flags'])) {
- $box = $boxes[$i]['unformatted'];
- $box2 = str_replace(' ', ' ',
- imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
- if( $box2 == 'INBOX' ) {
- $box2 = _("INBOX");
- }
- echo ' <option value="' . $box . '"';
- if ($mailbox == $box) { echo ' selected'; }
- echo '>' . $box2 . '</option>' . "\n";
- }
-}
- echo '<option value="All Folders"';
- if ($mailbox == 'All Folders') {
- echo ' selected';
- }
- echo ">All folders</option>\n";
-echo ' </select>'.
- " </td>\n";
+ . '<select name="mailbox">'
+ . '<option value="All Folders"';
+ if ($mailbox == 'All Folders') {
+ echo ' selected';
+ }
+ echo ">[ All Folders ]</option>\n";
+
+ $show_selected = array(strtolower($mailbox));
+ echo sqimap_mailbox_option_list($imapConnection, $show_selected, 0, $boxes);
+
+ echo ' </select>'.
+ " </td>\n";
if ( !isset( $what ) ) {
$what = '';
}