6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * Enables message moving between folders on the IMAP server.
14 require_once('../src/validate.php');
15 require_once('../functions/display_messages.php');
16 require_once('../functions/imap.php');
18 function putSelectedMessagesIntoString($msg) {
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])) {
28 if ($firstLoop != true) {
29 $selectedMessages .= "&";
34 $selectedMessages .= "selMsg[$j]=$msg[$i]";
42 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
43 sqimap_mailbox_select($imapConnection, $mailbox);
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));
52 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
55 } elseif(isset($undeleteButton)) {
56 // undelete messages if user isn't using move_to_trash or auto_expunge
58 if (is_array($msg) == 1) {
59 // Removes \Deleted flag from selected messages
63 // If they have selected nothing msg is size one still, but will be an infinite
64 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
65 while ($j < count($msg)) {
67 sqimap_messages_remove_flag ($imapConnection, $msg[$i], $msg[$i], "Deleted");
72 $location = get_location();
75 header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
77 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
79 displayPageHeader($color, $mailbox);
80 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
82 } elseif (!isset($moveButton)) {
83 // If the delete button was pressed, the moveButton variable will not be set.
84 if (is_array($msg) == 1) {
85 // Marks the selected messages as 'Deleted'
89 // If they have selected nothing msg is size one still, but will be an infinite
90 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
91 while ($j < count($msg)) {
92 if (isset($msg[$i])) {
93 if (isset($markRead)) {
94 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Seen");
95 } else if (isset($markUnread)) {
96 sqimap_messages_remove_flag($imapConnection, $msg[$i], $msg[$i], "Seen");
98 sqimap_messages_delete($imapConnection, $msg[$i], $msg[$i], $mailbox);
105 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
107 $location = get_location();
108 if (isset($where) && isset($what)) {
109 header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
111 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
114 displayPageHeader($color, $mailbox);
115 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
117 } else { // Move messages
118 // lets check to see if they selected any messages
119 if (is_array($msg) == 1) {
123 // If they have selected nothing msg is size one still, but will be an infinite
124 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
125 while ($j < count($msg)) {
126 if (isset($msg[$i])) {
127 /** check if they would like to move it to the trash folder or not */
128 sqimap_messages_copy($imapConnection, $msg[$i], $msg[$i], $targetMailbox);
129 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Deleted");
134 if ($auto_expunge == true)
135 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
137 $location = get_location();
138 if (isset($where) && isset($what))
139 header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
141 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
143 displayPageHeader($color, $mailbox);
144 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
148 // Log out this session
149 sqimap_logout($imapConnection);