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 .= "&";
33 $selectedMessages .= "selMsg[$j]=$msg[$i]";
41 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
42 sqimap_mailbox_select($imapConnection, $mailbox);
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));
51 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
54 } elseif(isset($undeleteButton)) {
55 // undelete messages if user isn't using move_to_trash or auto_expunge
57 if (is_array($msg) == 1) {
58 // Removes \Deleted flag from selected messages
62 // If they have selected nothing msg is size one still, but will be an infinite
63 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
64 while ($j < count($msg)) {
66 sqimap_messages_remove_flag ($imapConnection, $msg[$i], $msg[$i], "Deleted");
71 $location = get_location();
74 header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
76 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
78 displayPageHeader($color, $mailbox);
79 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
81 } elseif (!isset($moveButton)) {
82 // If the delete button was pressed, the moveButton variable will not be set.
83 if (is_array($msg) == 1) {
84 // Marks the selected messages as 'Deleted'
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 if (isset($markRead)) {
93 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Seen");
94 } else if (isset($markUnread)) {
95 sqimap_messages_remove_flag($imapConnection, $msg[$i], $msg[$i], "Seen");
97 sqimap_messages_delete($imapConnection, $msg[$i], $msg[$i], $mailbox);
104 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
106 $location = get_location();
107 if (isset($where) && isset($what)) {
108 header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
110 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
113 displayPageHeader($color, $mailbox);
114 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
116 } else { // Move messages
117 // lets check to see if they selected any messages
118 if (is_array($msg) == 1) {
122 // If they have selected nothing msg is size one still, but will be an infinite
123 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
124 while ($j < count($msg)) {
125 if (isset($msg[$i])) {
126 /** check if they would like to move it to the trash folder or not */
127 sqimap_messages_copy($imapConnection, $msg[$i], $msg[$i], $targetMailbox);
128 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Deleted");
133 if ($auto_expunge == true)
134 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
136 $location = get_location();
137 if (isset($where) && isset($what))
138 header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
140 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
142 displayPageHeader($color, $mailbox);
143 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
147 // Log out this session
148 sqimap_logout($imapConnection);