Source for file folders_delete.php

Documentation is available at folders_delete.php

  1. <?php
  2.  
  3. /**
  4.  * folders_delete.php
  5.  *
  6.  * Deletes folders from the IMAP server.
  7.  * Called from the folders.php
  8.  *
  9.  * @copyright 1999-2020 The SquirrelMail Project Team
  10.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11.  * @version $Id: folders_delete.php 14840 2020-01-07 07:42:38Z pdontthink $
  12.  * @package squirrelmail
  13.  */
  14.  
  15. /** This is the folders_delete page */
  16. define('PAGE_NAME''folders_delete');
  17.  
  18. /**
  19.  * Path for SquirrelMail required files.
  20.  * @ignore
  21.  */
  22. define('SM_PATH','../');
  23.  
  24. /* SquirrelMail required files. */
  25. require_once(SM_PATH 'include/validate.php');
  26. require_once(SM_PATH 'functions/global.php');
  27. require_once(SM_PATH 'functions/imap.php');
  28. require_once(SM_PATH 'functions/tree.php');
  29. require_once(SM_PATH 'functions/display_messages.php');
  30. require_once(SM_PATH 'functions/html.php');
  31. require_once(SM_PATH 'functions/forms.php');
  32.  
  33. /*
  34.  *  Incoming values:
  35.  *     $mailbox - selected mailbox from the form
  36.  */
  37.  
  38. /* globals */
  39. sqgetGlobalVar('key',       $key,           SQ_COOKIE);
  40. sqgetGlobalVar('username',  $username,      SQ_SESSION);
  41. sqgetGlobalVar('onetimepad',$onetimepad,    SQ_SESSION);
  42. sqgetGlobalVar('delimiter'$delimiter,     SQ_SESSION);
  43. sqgetGlobalVar('mailbox',   $mailbox,       SQ_POST);
  44. if (!sqgetGlobalVar('smtoken',$submitted_tokenSQ_POST)) {
  45.     $submitted_token '';
  46. }
  47. /* end globals */
  48.  
  49. if ($mailbox == ''{
  50.     displayPageHeader($color'None');
  51.  
  52.     plain_error_message(_("You have not selected a folder to delete. Please do so.").
  53.         '<br /><a href="../src/folders.php">'._("Click here to go back").'</a>.'$color);
  54.     exit;
  55. }
  56.  
  57. if sqgetGlobalVar('backingout'$tmpSQ_POST) ) {
  58.     $location get_location();
  59.     header ("Location: $location/folders.php");
  60.     exit;
  61. }
  62.  
  63. if!sqgetGlobalVar('confirmed'$tmpSQ_POST) ) {
  64.     displayPageHeader($color'None');
  65.  
  66.     // get displayable mailbox format
  67.     global $folder_prefix;
  68.     if (substr($mailbox,0,strlen($folder_prefix))==$folder_prefix{
  69.         $mailbox_unformatted_disp substr($mailboxstrlen($folder_prefix));
  70.     else {
  71.         $mailbox_unformatted_disp $mailbox;
  72.     }
  73.  
  74.     echo '<br />' .
  75.         html_tag'table''''center''''width="95%" border="0"' .
  76.         html_tag'tr',
  77.             html_tag'td''<b>' _("Delete Folder"'</b>''center'$color[0)
  78.         .
  79.         html_tag'tr' .
  80.         html_tag'td''''center'$color[4.
  81.         sprintf(_("Are you sure you want to delete %s?")str_replace(array(' ','<','>'),array('&nbsp;','&lt;','&gt;'),imap_utf7_decode_local($mailbox_unformatted_disp))).
  82.         addForm('folders_delete.php''post'''''''''TRUE)."<p>\n".
  83.         addHidden('mailbox'$mailbox).
  84.         addSubmit(_("Yes")'confirmed').
  85.         addSubmit(_("No")'backingout').
  86.         '</p></form><br /></td></tr></table>';
  87.  
  88.     exit;
  89. }
  90.  
  91. // first, validate security token
  92. sm_validate_security_token($submitted_token-1TRUE);
  93.  
  94. global $imap_stream_options// in case not defined in config
  95. $imap_stream sqimap_login($username$key$imapServerAddress$imapPort0$imap_stream_options);
  96.  
  97. $boxes sqimap_mailbox_list ($imap_stream);
  98. $numboxes count($boxes);
  99.  
  100. global $delete_folder;
  101.  
  102. if (substr($mailbox-1== $delimiter)
  103.     $mailbox_no_dm substr($mailbox0strlen($mailbox1);
  104. else
  105.     $mailbox_no_dm $mailbox;
  106.  
  107. /** lets see if we CAN move folders to the trash.. otherwise,
  108.     ** just delete them **/
  109.  
  110. if ((isset($delete_folder&& $delete_folder||
  111.     preg_match('/^' preg_quote($trash_folder'/''.+/i'$mailbox) ) {
  112.     $can_move_to_trash FALSE;
  113. }
  114.  
  115. /* Otherwise, check if trash folder exits and support sub-folders */
  116. else {
  117.     for ($i 0$i $numboxes$i++{
  118.         if ($boxes[$i]['unformatted'== $trash_folder{
  119.             $can_move_to_trash !in_array('noinferiors'$boxes[$i]['flags']);
  120.         }
  121.     }
  122. }
  123.  
  124. /** First create the top node in the tree **/
  125. for ($i 0$i $numboxes$i++{
  126.     if (($boxes[$i]['unformatted-dm'== $mailbox&& (strlen($boxes[$i]['unformatted-dm']== strlen($mailbox))) {
  127.         $foldersTree[0]['value'$mailbox;
  128.         $foldersTree[0]['doIHaveChildren'false;
  129.         continue;
  130.     }
  131. }
  132.  
  133. /* Now create the nodes for subfolders of the parent folder
  134.    You can tell that it is a subfolder by tacking the mailbox delimiter
  135.    on the end of the $mailbox string, and compare to that.  */
  136. for ($i 0$i $numboxes$i++{
  137.     if (substr($boxes[$i]['unformatted']0strlen($mailbox_no_dm $delimiter)) == ($mailbox_no_dm $delimiter)) {
  138.         addChildNodeToTree($boxes[$i]["unformatted"]$boxes[$i]['unformatted-dm']$foldersTree);
  139.     }
  140. }
  141.  
  142. /** Lets start removing the folders and messages **/
  143. if (($move_to_trash == true&& ($can_move_to_trash == true)) /** if they wish to move messages to the trash **/
  144.     walkTreeInPostOrderCreatingFoldersUnderTrash(0$imap_stream$foldersTree$mailbox);
  145.     walkTreeInPreOrderDeleteFolders(0$imap_stream$foldersTree);
  146. else /** if they do NOT wish to move messages to the trash (or cannot)**/
  147.     walkTreeInPreOrderDeleteFolders(0$imap_stream$foldersTree);
  148. }
  149.  
  150. /** Log out this session **/
  151. sqimap_logout($imap_stream);
  152.  
  153. $location get_location();
  154. header ("Location: $location/folders.php?success=delete");

Documentation generated on Mon, 13 Jan 2020 04:24:38 +0100 by phpDocumentor 1.4.3