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