use folder list instead of string list in order to follow 'mailbox_select_style'
[squirrelmail.git] / plugins / sent_subfolders / setup.php
index 882b9d784222de67b7732d08370478348006da76..93b7eb5a38b3982e580843054fa90d2e1fa0617b 100644 (file)
@@ -3,20 +3,28 @@
 /**
  * setup.php -- Sent Subfolders Setup File
  *
- * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Copyright (c) 1999-2004 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * This is a standard Squirrelmail-1.2 API for plugins.
  *
  * $Id$
+ * @package plugins
+ * @subpackage sent_subfolders
  */
 
+/** 
+ * 
+ */
 define('SMPREF_SENT_SUBFOLDERS_DISABLED',  0);
 define('SMPREF_SENT_SUBFOLDERS_YEARLY',    1);
 define('SMPREF_SENT_SUBFOLDERS_QUARTERLY', 2);
 define('SMPREF_SENT_SUBFOLDERS_MONTHLY',   3);
 define('SMOPT_GRP_SENT_SUBFOLDERS','SENT_SUBFOLDERS');
 
+/**
+ * Adds plugin to squirrelmail hooks
+ */
 function squirrelmail_plugin_init_sent_subfolders() {
     /* Standard initialization API. */
     global $squirrelmail_plugin_hooks;
@@ -44,13 +52,20 @@ function squirrelmail_plugin_init_sent_subfolders() {
     $squirrelmail_plugin_hooks
     ['optpage_loadhook_folder']['sent_subfolders'] =
         'sent_subfolders_optpage_loadhook_folders';
+
+    /* mark base sent folder as special mailbox */
+    $squirrelmail_plugin_hooks
+    ['special_mailbox']['sent_subfolders'] = 
+       'sent_subfolders_special_mailbox';
 }
 
 function sent_subfolders_check_handleAsSent() {
     global $handleAsSent_result, $sent_subfolders_base,
-           $use_sent_subfolders, $delimiter;
+           $use_sent_subfolders;
+
     $sent_subfolders_base = 'INBOX.Sent';
     $args = func_get_arg(0);
+    sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
 
     /* Only check the folder string if we have been passed a mailbox. */
     if ($use_sent_subfolders && (count($args) > 1)) {
@@ -67,6 +82,9 @@ function sent_subfolders_check_handleAsSent() {
     }
 }
 
+/**
+ * Loads sent_subfolders settings
+ */
 function sent_subfolders_load_prefs() {
     global $use_sent_subfolders, $data_dir, $username,
            $sent_subfolders_setting, $sent_subfolders_base;
@@ -81,8 +99,14 @@ function sent_subfolders_load_prefs() {
     ($data_dir, $username, 'sent_subfolders_base', SMPREF_NONE);
 }
 
+/**
+ * Adds sent_subfolders options in folder preferences
+ */
 function sent_subfolders_optpage_loadhook_folders() {
-    global $optpage_data, $username, $key, $imapServerAddress, $imapPort;
+    global $optpage_data, $imapServerAddress, $imapPort;
+
+    sqgetGlobalVar('username', $username, SQ_SESSION);
+    sqgetGlobalVar('key', $key, SQ_COOKIE);
 
     /* Get some imap data we need later. */
     $imapConnection =
@@ -106,19 +130,13 @@ function sent_subfolders_optpage_loadhook_folders() {
         'save'    => 'save_option_sent_subfolders_setting'
     );
 
-    $sent_subfolders_base_values = array();
-    foreach ($boxes as $folder) {
-        if (strtolower($folder['unformatted']) != 'inbox') {
-            $real_value = $folder['unformatted-dm'];
-            $disp_value = str_replace(' ', ' ', $folder['formatted']);
-            $sent_subfolders_base_values[$real_value] = $disp_value;
-        }
-    }
+    $filtered_folders=array_filter($boxes, "filter_folders");
+    $sent_subfolders_base_values = array('whatever'=>$filtered_folders);
 
     $optvals[] = array(
         'name'    => 'sent_subfolders_base',
         'caption' => _("Base Sent Folder"),
-        'type'    => SMOPT_TYPE_STRLIST,
+        'type'    => SMOPT_TYPE_FLDRLIST,
         'refresh' => SMOPT_REFRESH_FOLDERLIST,
         'posvals' => $sent_subfolders_base_values
     );
@@ -128,6 +146,21 @@ function sent_subfolders_optpage_loadhook_folders() {
     $optpage_data['vals'][SMOPT_GRP_SENT_SUBFOLDERS] = $optvals;
 }
 
+/**
+ * Defines folder filtering rules
+ *
+ * Callback function that should exclude some folders from folder listing.
+ * @param array $fldr list of folders. See sqimap_mailbox_list
+ * @return boolean returns true, if folder has to included in folder listing
+ * @access private 
+ */
+function filter_folders($fldr) {
+    return strtolower($fldr['unformatted'])!='inbox';
+}
+
+/**
+ * Saves sent_subfolder_options
+ */
 function save_option_sent_subfolders_setting($option) {
     global $data_dir, $username, $use_sent_subfolders;
 
@@ -143,12 +176,22 @@ function save_option_sent_subfolders_setting($option) {
     save_option($option);
 }
 
+/**
+ * Update sent_subfolders settings
+ *
+ * function updates default sent folder value and 
+ * creates required imap folders
+ */
 function sent_subfolders_update_sentfolder() {
-    global $sent_folder, $delimiter, $auto_create_special, $auto_create_done;
+    global $sent_folder, $auto_create_special, $auto_create_done;
     global $sent_subfolders_base, $sent_subfolders_setting;
-    global $username, $data_dir, $key, $imapServerAddress, $imapPort;
+    global $data_dir, $imapServerAddress, $imapPort;
     global $use_sent_subfolders, $move_to_sent, $imap_server_type;
 
+    sqgetGlobalVar('username', $username, SQ_SESSION);
+    sqgetGlobalVar('key', $key, SQ_COOKIE);
+    sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
+    
     if ($use_sent_subfolders || $move_to_sent) {
         $year = date('Y');
         $month = date('m');
@@ -233,6 +276,12 @@ function sent_subfolders_update_sentfolder() {
     }
 }
 
+/**
+ * Sets quarter subfolder names
+ *
+ * @param string $month numeric month
+ * @return string quarter name (Q + number)
+ */
 function sent_subfolder_getQuarter($month) {
     switch ($month) {
         case '01':
@@ -263,4 +312,23 @@ function sent_subfolder_getQuarter($month) {
     return ('Q' . $result);
 }
 
+/**
+ * detects if mailbox is part of sent_subfolders
+ *
+ * @param string $mb imap folder name
+ * @return boolean 1 - is part of sent_subfolders, 0 - is not part of sent_subfolders
+ */
+function sent_subfolders_special_mailbox($mb) {
+    global $data_dir, $username;
+
+    $use_sent_subfolders = getPref
+        ($data_dir, $username, 'use_sent_subfolders', SMPREF_OFF);
+    $sent_subfolders_base = getPref($data_dir, $username, 'sent_subfolders_base', 'na');
+
+    if ($use_sent_subfolders == SMPREF_ON && 
+    ($mb == $sent_subfolders_base || stristr($mb,$sent_subfolders_base) ) ) {
+       return 1;
+    }
+    return 0;
+}
 ?>