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

Documentation generated on Wed, 30 Jul 2014 04:17:57 +0200 by phpDocumentor 1.4.3