Source for file folders.php

Documentation is available at folders.php

  1. <?php
  2. /**
  3.  * folders.php
  4.  *
  5.  * Handles all interaction between the user and the other folder
  6.  * scripts which do most of the work. Also handles the Special
  7.  * Folders.
  8.  *
  9.  * @copyright &copy; 1999-2006 The SquirrelMail Project Team
  10.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11.  * @version $Id: folders.php,v 1.149 2006/08/09 18:01:21 stevetruckstuff Exp $
  12.  * @package squirrelmail
  13.  */
  14.  
  15. /**
  16.  * Include the SquirrelMail initialization file.
  17.  */
  18. require('../include/init.php');
  19.  
  20. /* SquirrelMail required files. */
  21. require_once(SM_PATH 'functions/imap_general.php');
  22. require_once(SM_PATH 'functions/folder_manip.php');
  23. require_once(SM_PATH 'functions/forms.php');
  24.  
  25. displayPageHeader($color'None');
  26.  
  27. /* get globals we may need */
  28. sqgetGlobalVar('delimiter'$delimiterSQ_SESSION);
  29. sqgetGlobalVar('smaction'$actionSQ_POST);
  30.  
  31. /* end of get globals */
  32.  
  33. $imapConnection sqimap_login ($usernamefalse$imapServerAddress$imapPort0);
  34.  
  35. /* switch to the right function based on what the user selected */
  36. if sqgetGlobalVar('smaction'$actionSQ_POST) ) {
  37.     switch ($action)
  38.     {
  39.         case 'create':
  40.             sqgetGlobalVar('folder_name',  $folder_name,  SQ_POST);
  41.             sqgetGlobalVar('subfolder',    $subfolder,    SQ_POST);
  42.             sqgetGlobalVar('contain_subs'$contain_subsSQ_POST);
  43.             folders_create($imapConnection$delimiter$folder_name$subfolder$contain_subs);
  44.             $td_str =  _("Created folder successfully.");
  45.             break;
  46.         case 'rename':
  47.             if sqgetGlobalVar('cancelbutton'$dummySQ_POST) ) {
  48.                 break;
  49.             }
  50.             if sqgetGlobalVar('new_name'$new_nameSQ_POST) ) {
  51.                 sqgetGlobalVar('old_name',    $old_nameSQ_POST);
  52.                 folders_rename_getname($imapConnection$delimiter$old_name);
  53.             else {
  54.                 sqgetGlobalVar('orig',        $orig,     SQ_POST);
  55.                 sqgetGlobalVar('old_name',    $old_nameSQ_POST);
  56.                 folders_rename_do($imapConnection$delimiter$orig$old_name$new_name);
  57.                 $td_str =  _("Renamed successfully.");
  58.             }
  59.             break;
  60.         case 'delete':
  61.             if sqgetGlobalVar('cancelbutton'$dummySQ_POST) ) {
  62.                 break;
  63.             }
  64.             sqgetGlobalVar('folder_name',  $folder_name,  SQ_POST);
  65.             if sqgetGlobalVar('confirmed'$dummySQ_POST) ) {
  66.                 folders_delete_do($imapConnection$delimiter$folder_name);
  67.                 $td_str =  _("Deleted folder successfully.");
  68.             else {
  69.                 folders_delete_ask($imapConnection$folder_name);
  70.             }
  71.             break;
  72.         case 'subscribe':
  73.             sqgetGlobalVar('folder_names',  $folder_names,  SQ_POST);
  74.             folders_subscribe($imapConnection$folder_names);
  75.             $td_str =  _("Subscribed successfully.");
  76.             break;
  77.         case 'unsubscribe':
  78.             sqgetGlobalVar('folder_names',  $folder_names,  SQ_POST);
  79.             folders_unsubscribe($imapConnection$folder_names);
  80.             $td_str =  _("Unsubscribed successfully.");
  81.             break;
  82.         default:
  83.             // TODO: add hook for plugin action processing.
  84.                         $td_str '';
  85.             break;
  86.     }
  87.  
  88. }
  89.  
  90. if (isset($td_str)) {
  91.     $oTemplate->assign('note'htmlspecialchars($td_str));
  92.     $oTemplate->display('note.tpl');
  93. }
  94.  
  95. $boxes sqimap_mailbox_list($imapConnection,true);
  96.  
  97. /** CREATING FOLDERS **/
  98.  
  99. $show_selected array();
  100. $skip_folders array();
  101. $server_type strtolower($imap_server_type);
  102.  
  103. // Special handling for courier
  104. if $server_type == 'courier' {
  105.     if $default_folder_prefix == 'INBOX.' {
  106.         // We don't need INBOX, since it is top folder
  107.                 array_push($skip_folders'INBOX');
  108.     }
  109. elseif $server_type == 'bincimap' {
  110.     if $default_folder_prefix == 'INBOX/' {
  111.         // We don't need INBOX, since it is top folder
  112.                 array_push($skip_folders'INBOX');
  113.     }
  114. }
  115.  
  116. if $default_sub_of_inbox == false {
  117.     $mbx_option_list '<option selected="selected" value="">[ '._("None")." ]</option>\n";
  118. else {
  119.     $mbx_option_list '<option value="">[ '._("None")." ]</option>\n";
  120.     $show_selected array('inbox');
  121. }
  122.  
  123. // Call sqimap_mailbox_option_list, using existing connection to IMAP server,
  124. // the arrays of folders to include or skip (assembled above),
  125. // use 'noinferiors' as a mailbox filter to leave out folders that can not contain other folders.
  126. // use the long format to show subfolders in an intelligible way if parent is missing (special folder)
  127. $mbx_option_list .= sqimap_mailbox_option_list($imapConnection$show_selected$skip_folders$boxes'noinferiors'true);
  128.  
  129.  
  130. /** count special folders **/
  131. foreach ($boxes as $index => $aBoxData{
  132.     if (isSpecialMailbox($aBoxData['unformatted'],false&&
  133.         in_array($aBoxData['unformatted'],$skip_folders)) {
  134.         $skip_folders[$aBoxData['unformatted'];
  135.     }
  136. }
  137.  
  138. /**
  139.  * Retrieve list of folders when special folders are excluded. Special folders
  140.  * should be unavailable in rename/delete/unsubscribe. Theoretically user can
  141.  * modify form and perform these operations with special folders, but if user
  142.  * manages to delete/rename/unsubscribe special folder by hacking form...
  143.  *
  144.  * If script or program depends on special folder, they should not assume that
  145.  * folder is available.
  146.  *
  147.  * $filtered_folders contains empty string or html formated option list.
  148.  */
  149. $rendel_folder_list sqimap_mailbox_option_list($imapConnection0$skip_folders$boxesNULLtrue);
  150.  
  151.  
  152. $subbox_option_list array();
  153.  
  154. if ($show_only_subscribed_folders && !$no_list_for_subscribe{
  155.     // FIXME: fix subscription options when top folder is not subscribed and sub folder is subscribed
  156.  
  157.     // TODO: use checkboxes instead of select options.
  158.     // DONE Steve Brown 2006-08-08
  159.  
  160.     
  161.     /** SUBSCRIBE TO FOLDERS **/
  162.     $boxes_all sqimap_mailbox_list_all ($imapConnection);
  163.  
  164.     // here we filter out all boxes we're already subscribed to,
  165.     // so we keep only the unsubscribed ones.
  166.         foreach ($boxes_all as $box_a{
  167.  
  168.         $use_folder true;
  169.         foreach $boxes as $box {
  170.             if ($box_a['unformatted'== $box['unformatted'||
  171.             $box_a['unformatted-dm'== $folder_prefix {
  172.             $use_folder false;
  173.             }
  174.         }
  175.     
  176.         if ($use_folder{
  177.             $box_enc  htmlspecialchars($box_a['unformatted-dm']);
  178.             $box_disp htmlspecialchars(imap_utf7_decode_local($box_a['unformatted-disp']));
  179.             $subbox_option_list[array'Value' => $box_enc'Display' => $box_disp);
  180.         }
  181.     }
  182. }
  183.  
  184. sqimap_logout($imapConnection);
  185.  
  186. $oTemplate->assign('show_subfolders_option'$show_contain_subfolders_option);
  187. $oTemplate->assign('show_only_subscribed_folders'$show_only_subscribed_folders==1);
  188. $oTemplate->assign('no_list_for_subscribe'$no_list_for_subscribe);
  189.  
  190. $oTemplate->assign('mbx_option_list'$mbx_option_list);
  191. $oTemplate->assign('rendel_folder_list'$rendel_folder_list);
  192. $oTemplate->assign('subbox_option_list'$subbox_option_list);
  193.  
  194. $oTemplate->display('folder_manip.tpl');
  195.  
  196. $oTemplate->display('footer.tpl');
  197. ?>

Documentation generated on Sat, 07 Oct 2006 16:11:03 +0300 by phpDocumentor 1.3.0RC6