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