Initial checkin of spamoptions.php
[squirrelmail.git] / src / move_messages.php
CommitLineData
59177427 1<?php
895905c0 2
ef870322 3 /**
4 ** move_messages.php
5 **
895905c0 6 ** Copyright (c) 1999-2001 The SquirrelMail development team
ef870322 7 ** Licensed under the GNU GPL. For full terms see the file COPYING.
8 **
9 ** Enables message moving between folders on the IMAP server.
245a6892 10 **
11 ** $Id$
ef870322 12 **/
13
ff8a98e7 14 require_once('../src/validate.php');
15 require_once('../functions/display_messages.php');
16 require_once('../functions/imap.php');
d3cdb279 17
dd88d31f 18 function putSelectedMessagesIntoString($msg) {
05207a68 19 $j = 0;
20 $i = 0;
dd88d31f 21 $firstLoop = true;
2d7d3c2a 22
d068c0ec 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.
2d7d3c2a 26 while (($j < count($msg)) && ($msg[0])) {
05207a68 27 if ($msg[$i]) {
dd88d31f 28 if ($firstLoop != true)
29 $selectedMessages .= "&";
30 else
31 $firstLoop = false;
32
33 $selectedMessages .= "selMsg[$j]=$msg[$i]";
34
05207a68 35 $j++;
b40316f9 36 }
05207a68 37 $i++;
b40316f9 38 }
dd88d31f 39 }
e2370222 40
e1469126 41 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
813eba2f 42 sqimap_mailbox_select($imapConnection, $mailbox);
dd88d31f 43
f9b3e5d9 44 // expunge-on-demand if user isn't using move_to_trash or auto_expunge
245a6892 45 if(isset($expungeButton)) {
8cf653ad 46 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
f9b3e5d9 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
245a6892 54 elseif(isset($undeleteButton)) {
f9b3e5d9 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 }
dd88d31f 80 // If the delete button was pressed, the moveButton variable will not be set.
245a6892 81 elseif (!isset($moveButton)) {
dd88d31f 82 if (is_array($msg) == 1) {
f265cfe8 83 // Marks the selected messages as 'Deleted'
dd88d31f 84 $j = 0;
85 $i = 0;
2d7d3c2a 86
dd88d31f 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)) {
23fd3c8e 90 if (isset($msg[$i])) {
6332704d 91 if (isset($markRead)) {
92 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Seen");
37faa781 93 } else if (isset($markUnread)) {
6332704d 94 sqimap_messages_remove_flag($imapConnection, $msg[$i], $msg[$i], "Seen");
95 } else {
96 sqimap_messages_delete($imapConnection, $msg[$i], $msg[$i], $mailbox);
97 }
dd88d31f 98 $j++;
2d7d3c2a 99 }
dd88d31f 100 $i++;
2d7d3c2a 101 }
acaa9842 102 if ($auto_expunge) {
8cf653ad 103 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
acaa9842 104 }
1195c340 105 $location = get_location();
23fd3c8e 106 if (isset($where) && isset($what))
1809bad8 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));
dd88d31f 110 } else {
5479d709 111 displayPageHeader($color, $mailbox);
a6668eb2 112 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
dd88d31f 113 }
114 } else { // Move messages
dd88d31f 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)) {
23fd3c8e 123 if (isset($msg[$i])) {
dd88d31f 124 /** check if they would like to move it to the trash folder or not */
8b673ac1 125 sqimap_messages_copy($imapConnection, $msg[$i], $msg[$i], $targetMailbox);
126 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Deleted");
dd88d31f 127 $j++;
128 }
129 $i++;
130 }
131 if ($auto_expunge == true)
8cf653ad 132 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
de80e95e 133
1195c340 134 $location = get_location();
23fd3c8e 135 if (isset($where) && isset($what))
1809bad8 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));
dd88d31f 139 } else {
5479d709 140 displayPageHeader($color, $mailbox);
a6668eb2 141 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
2d7d3c2a 142 }
b40316f9 143 }
144
b40316f9 145 // Log out this session
813eba2f 146 sqimap_logout($imapConnection);
b40316f9 147
2aa12d5e 148?>
6332704d 149</BODY></HTML>