| 1 | <?php |
| 2 | /** |
| 3 | ** move_messages.php |
| 4 | ** |
| 5 | ** Copyright (c) 1999-2000 The SquirrelMail development team |
| 6 | ** Licensed under the GNU GPL. For full terms see the file COPYING. |
| 7 | ** |
| 8 | ** Enables message moving between folders on the IMAP server. |
| 9 | ** |
| 10 | ** $Id$ |
| 11 | **/ |
| 12 | |
| 13 | session_start(); |
| 14 | |
| 15 | if (!isset($strings_php)) |
| 16 | include("../functions/strings.php"); |
| 17 | if (!isset($config_php)) |
| 18 | include("../config/config.php"); |
| 19 | if (!isset($page_header_php)) |
| 20 | include("../functions/page_header.php"); |
| 21 | if (!isset($display_messages_php)) |
| 22 | include("../functions/display_messages.php"); |
| 23 | if (!isset($imap_php)) |
| 24 | include("../functions/imap.php"); |
| 25 | |
| 26 | include("../src/load_prefs.php"); |
| 27 | |
| 28 | function putSelectedMessagesIntoString($msg) { |
| 29 | $j = 0; |
| 30 | $i = 0; |
| 31 | $firstLoop = true; |
| 32 | |
| 33 | // If they have selected nothing msg is size one still, but will |
| 34 | // be an infinite loop because we never increment j. so check to |
| 35 | // see if msg[0] is set or not to fix this. |
| 36 | while (($j < count($msg)) && ($msg[0])) { |
| 37 | if ($msg[$i]) { |
| 38 | if ($firstLoop != true) |
| 39 | $selectedMessages .= "&"; |
| 40 | else |
| 41 | $firstLoop = false; |
| 42 | |
| 43 | $selectedMessages .= "selMsg[$j]=$msg[$i]"; |
| 44 | |
| 45 | $j++; |
| 46 | } |
| 47 | $i++; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
| 52 | sqimap_mailbox_select($imapConnection, $mailbox); |
| 53 | |
| 54 | // expunge-on-demand if user isn't using move_to_trash or auto_expunge |
| 55 | if(isset($expungeButton)) { |
| 56 | sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
| 57 | $location = get_location(); |
| 58 | if ($where && $what) |
| 59 | header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where)); |
| 60 | else |
| 61 | header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox)); |
| 62 | } |
| 63 | // undelete messages if user isn't using move_to_trash or auto_expunge |
| 64 | elseif(isset($undeleteButton)) { |
| 65 | if (is_array($msg) == 1) { |
| 66 | // Removes \Deleted flag from selected messages |
| 67 | $j = 0; |
| 68 | $i = 0; |
| 69 | |
| 70 | // If they have selected nothing msg is size one still, but will be an infinite |
| 71 | // loop because we never increment j. so check to see if msg[0] is set or not to fix this. |
| 72 | while ($j < count($msg)) { |
| 73 | if ($msg[$i]) { |
| 74 | sqimap_messages_remove_flag ($imapConnection, $msg[$i], $msg[$i], "Deleted"); |
| 75 | $j++; |
| 76 | } |
| 77 | $i++; |
| 78 | } |
| 79 | $location = get_location(); |
| 80 | |
| 81 | if ($where && $what) |
| 82 | header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where)); |
| 83 | else |
| 84 | header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox)); |
| 85 | } else { |
| 86 | displayPageHeader($color, $mailbox); |
| 87 | error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color); |
| 88 | } |
| 89 | } |
| 90 | // If the delete button was pressed, the moveButton variable will not be set. |
| 91 | elseif (!isset($moveButton)) { |
| 92 | if (is_array($msg) == 1) { |
| 93 | // Marks the selected messages ad 'Deleted' |
| 94 | $j = 0; |
| 95 | $i = 0; |
| 96 | |
| 97 | // If they have selected nothing msg is size one still, but will be an infinite |
| 98 | // loop because we never increment j. so check to see if msg[0] is set or not to fix this. |
| 99 | while ($j < count($msg)) { |
| 100 | if ($msg[$i]) { |
| 101 | sqimap_messages_delete($imapConnection, $msg[$i], $msg[$i], $mailbox); |
| 102 | $j++; |
| 103 | } |
| 104 | $i++; |
| 105 | } |
| 106 | if ($auto_expunge) { |
| 107 | sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
| 108 | } |
| 109 | $location = get_location(); |
| 110 | if ($where && $what) |
| 111 | header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where)); |
| 112 | else |
| 113 | header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox)); |
| 114 | } else { |
| 115 | displayPageHeader($color, $mailbox); |
| 116 | error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color); |
| 117 | } |
| 118 | } else { // Move messages |
| 119 | // lets check to see if they selected any messages |
| 120 | if (is_array($msg) == 1) { |
| 121 | $j = 0; |
| 122 | $i = 0; |
| 123 | |
| 124 | // If they have selected nothing msg is size one still, but will be an infinite |
| 125 | // loop because we never increment j. so check to see if msg[0] is set or not to fix this. |
| 126 | while ($j < count($msg)) { |
| 127 | if ($msg[$i]) { |
| 128 | /** check if they would like to move it to the trash folder or not */ |
| 129 | sqimap_messages_copy($imapConnection, $msg[$i], $msg[$i], $targetMailbox); |
| 130 | sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Deleted"); |
| 131 | $j++; |
| 132 | } |
| 133 | $i++; |
| 134 | } |
| 135 | if ($auto_expunge == true) |
| 136 | sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
| 137 | |
| 138 | $location = get_location(); |
| 139 | if ($where && $what) |
| 140 | header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where)); |
| 141 | else |
| 142 | header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox)); |
| 143 | } else { |
| 144 | displayPageHeader($color, $mailbox); |
| 145 | error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | // Log out this session |
| 150 | sqimap_logout($imapConnection); |
| 151 | |
| 152 | ?> |
| 153 | </BODY></HTML> |