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