Getting ready for 1.2.0 release.
[squirrelmail.git] / src / move_messages.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * move_messages.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
35586184 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 */
ef870322 13
35586184 14/*****************************************************************/
15/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
16/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
17/*** + Base level indent should begin at left margin, as ***/
18/*** the require_once below looks. ***/
19/*** + All identation should consist of four space blocks ***/
20/*** + Tab characters are evil. ***/
21/*** + all comments should use "slash-star ... star-slash" ***/
22/*** style -- no pound characters, no slash-slash style ***/
23/*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
24/*** ALWAYS USE { AND } CHARACTERS!!! ***/
25/*** + Please use ' instead of ", when possible. Note " ***/
26/*** should always be used in _( ) function calls. ***/
27/*** Thank you for your help making the SM code more readable. ***/
28/*****************************************************************/
29
30require_once('../src/validate.php');
31require_once('../functions/display_messages.php');
32require_once('../functions/imap.php');
d3cdb279 33
dd88d31f 34 function putSelectedMessagesIntoString($msg) {
05207a68 35 $j = 0;
36 $i = 0;
dd88d31f 37 $firstLoop = true;
2d7d3c2a 38
d068c0ec 39 // If they have selected nothing msg is size one still, but will
40 // be an infinite loop because we never increment j. so check to
41 // see if msg[0] is set or not to fix this.
2d7d3c2a 42 while (($j < count($msg)) && ($msg[0])) {
05207a68 43 if ($msg[$i]) {
dd88d31f 44 if ($firstLoop != true)
45 $selectedMessages .= "&";
46 else
47 $firstLoop = false;
48
49 $selectedMessages .= "selMsg[$j]=$msg[$i]";
50
05207a68 51 $j++;
b40316f9 52 }
05207a68 53 $i++;
b40316f9 54 }
dd88d31f 55 }
e2370222 56
e1469126 57 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
813eba2f 58 sqimap_mailbox_select($imapConnection, $mailbox);
dd88d31f 59
f9b3e5d9 60 // expunge-on-demand if user isn't using move_to_trash or auto_expunge
245a6892 61 if(isset($expungeButton)) {
8cf653ad 62 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
f9b3e5d9 63 $location = get_location();
64 if ($where && $what)
65 header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
66 else
67 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
68 }
69 // undelete messages if user isn't using move_to_trash or auto_expunge
245a6892 70 elseif(isset($undeleteButton)) {
f9b3e5d9 71 if (is_array($msg) == 1) {
72 // Removes \Deleted flag from selected messages
73 $j = 0;
74 $i = 0;
75
76 // If they have selected nothing msg is size one still, but will be an infinite
77 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
78 while ($j < count($msg)) {
79 if ($msg[$i]) {
80 sqimap_messages_remove_flag ($imapConnection, $msg[$i], $msg[$i], "Deleted");
81 $j++;
82 }
83 $i++;
84 }
85 $location = get_location();
86
87 if ($where && $what)
88 header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
89 else
90 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
91 } else {
92 displayPageHeader($color, $mailbox);
93 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
94 }
95 }
dd88d31f 96 // If the delete button was pressed, the moveButton variable will not be set.
245a6892 97 elseif (!isset($moveButton)) {
dd88d31f 98 if (is_array($msg) == 1) {
f265cfe8 99 // Marks the selected messages as 'Deleted'
dd88d31f 100 $j = 0;
101 $i = 0;
2d7d3c2a 102
dd88d31f 103 // If they have selected nothing msg is size one still, but will be an infinite
104 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
105 while ($j < count($msg)) {
23fd3c8e 106 if (isset($msg[$i])) {
6332704d 107 if (isset($markRead)) {
108 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Seen");
37faa781 109 } else if (isset($markUnread)) {
6332704d 110 sqimap_messages_remove_flag($imapConnection, $msg[$i], $msg[$i], "Seen");
111 } else {
112 sqimap_messages_delete($imapConnection, $msg[$i], $msg[$i], $mailbox);
113 }
dd88d31f 114 $j++;
2d7d3c2a 115 }
dd88d31f 116 $i++;
2d7d3c2a 117 }
acaa9842 118 if ($auto_expunge) {
8cf653ad 119 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
acaa9842 120 }
1195c340 121 $location = get_location();
23fd3c8e 122 if (isset($where) && isset($what))
1809bad8 123 header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
124 else
125 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
dd88d31f 126 } else {
5479d709 127 displayPageHeader($color, $mailbox);
a6668eb2 128 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
dd88d31f 129 }
130 } else { // Move messages
dd88d31f 131 // lets check to see if they selected any messages
132 if (is_array($msg) == 1) {
133 $j = 0;
134 $i = 0;
135
136 // If they have selected nothing msg is size one still, but will be an infinite
137 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
138 while ($j < count($msg)) {
23fd3c8e 139 if (isset($msg[$i])) {
dd88d31f 140 /** check if they would like to move it to the trash folder or not */
8b673ac1 141 sqimap_messages_copy($imapConnection, $msg[$i], $msg[$i], $targetMailbox);
142 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Deleted");
dd88d31f 143 $j++;
144 }
145 $i++;
146 }
147 if ($auto_expunge == true)
8cf653ad 148 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
de80e95e 149
1195c340 150 $location = get_location();
23fd3c8e 151 if (isset($where) && isset($what))
1809bad8 152 header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
153 else
154 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
dd88d31f 155 } else {
5479d709 156 displayPageHeader($color, $mailbox);
a6668eb2 157 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
2d7d3c2a 158 }
b40316f9 159 }
160
b40316f9 161 // Log out this session
813eba2f 162 sqimap_logout($imapConnection);
b40316f9 163
2aa12d5e 164?>
6332704d 165</BODY></HTML>