Source for file folders_delete.php

Documentation is available at folders_delete.php

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

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