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