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

Documentation generated on Tue, 21 May 2013 04:19:16 +0200 by phpDocumentor 1.4.3