11d498649b755eef040e21fc54ed8ddc11923a52
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 /* Path for SquirrelMail required files. */
15 define('SM_PATH','../');
17 /* SquirrelMail required files. */
18 require_once(SM_PATH
. 'include/validate.php');
19 require_once(SM_PATH
. 'functions/display_messages.php');
20 require_once(SM_PATH
. 'functions/imap.php');
21 require_once(SM_PATH
. 'functions/html.php');
23 global $compose_new_win;
25 function putSelectedMessagesIntoString($msg) {
29 // If they have selected nothing msg is size one still, but will
30 // be an infinite loop because we never increment j. so check to
31 // see if msg[0] is set or not to fix this.
32 while (($j < count($msg)) && ($msg[0])) {
34 if ($firstLoop != true) {
35 $selectedMessages .= "&";
39 $selectedMessages .= "selMsg[$j]=$msg[$i]";
46 function attachSelectedMessages($msg, $imapConnection) {
47 global $username, $attachment_dir,
48 $data_dir, $composesession, $uid_support,
49 $msgs, $thread_sort_messages, $allow_server_sort, $show_num,
53 if (!isset($compose_messages)) {
54 $compose_messages = array();
55 sqsession_register($compose_messages,'compose_messages');
58 if (!isset($composesession) ) {
60 sqsession_register($composesession,'composesession');
65 $hashed_attachment_dir = getHashedDir($username, $attachment_dir, $composesession);
67 if ($thread_sort_messages ||
$allow_server_sort) {
70 $start_index = ($startMessage-1) * $show_num;
75 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
77 $composeMessage = new Message();
78 $rfc822_header = new Rfc822Header();
79 $composeMessage->rfc822_header
= $rfc822_header;
80 $composeMessage->reply_rfc822_header
= '';
82 while ($j < count($msg)) {
83 if (isset($msg[$i])) {
85 $body_a = sqimap_run_command($imapConnection, "FETCH $id RFC822",true, $response, $readmessage, $uid_support);
86 if ($response = 'OK') {
87 $k = $i +
$start_index;
88 $subject = $msgs[$k]['SUBJECT'];
91 $body = implode('', $body_a);
94 $localfilename = GenerateRandomString(32, 'FILE', 7);
95 $full_localfilename = "$hashed_attachment_dir/$localfilename";
97 $fp = fopen( $full_localfilename, 'wb');
100 $composeMessage->initAttachment('message/rfc822',$subject.'.eml',
101 $full_localfilename);
107 $compose_messages[$composesession] = $composeMessage;
108 sqsession_register($compose_messages,'compose_messages');
109 return $composesession;
116 $username = $_SESSION['username'];
117 $key = $_COOKIE['key'];
118 $onetimepad = $_SESSION['onetimepad'];
119 $base_uri = $_SESSION['base_uri'];
120 $delimiter = $_SESSION['delimiter'];
121 if (isset($_GET['mailbox'])) {
122 $mailbox = $_GET['mailbox'];
124 if (isset($_GET['startMessage'])) {
125 $startMessage = $_GET['startMessage'];
127 if (isset($_POST['moveButton'])) {
128 $moveButton = $_POST['moveButton'];
130 if (isset($_POST['msg'])) {
131 $msg = $_POST['msg'];
133 elseif (isset($_GET['msg'])) {
137 if (isset($_SESSION['msgs'])) {
138 $msgs = $_SESSION['msgs'];
142 if (isset($_POST['expungeButton'])) {
143 $expungeButton = $_POST['expungeButton'];
145 if (isset($_POST['targetMailbox'])) {
146 $targetMailbox = $_POST['targetMailbox'];
148 if (isset($_SESSION['lastTargetMailbox'])) {
149 $lastTargetMailbox = $_SESSION['lastTargetMailbox'];
151 if (isset($_POST['expungeButton'])) {
152 $expungeButton = $_POST['expungeButton'];
154 if (isset($_POST['undeleteButton'])) {
155 $undeleteButton = $_POST['undeleteButton'];
157 if (isset($_POST['markRead'])) {
158 $markRead = $_POST['markRead'];
160 if (isset($_POST['markUnread'])) {
161 $markUnread = $_POST['markUnread'];
163 if (isset($_POST['attache'])) {
164 $attache = $_POST['attache'];
167 if (isset($_POST['location'])) {
168 $location = $_POST['location'];
171 if (isset($_SESSION['composesession'])) {
172 $composesession = $_SESSION['composesession'];
174 /* end of get globals */
176 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
177 $mbx_response=sqimap_mailbox_select($imapConnection, $mailbox);
179 $location = set_url_var($location,'composenew');
180 $location = set_url_var($location,'composesession');
181 $location = set_url_var($location,'session');
183 /* remember changes to mailbox setting */
184 if (!isset($lastTargetMailbox)) {
185 $lastTargetMailbox = 'INBOX';
187 if ($targetMailbox != $lastTargetMailbox) {
188 $lastTargetMailbox = $targetMailbox;
189 sqsession_register($lastTargetMailbox, 'lastTargetMailbox');
192 // expunge-on-demand if user isn't using move_to_trash or auto_expunge
193 if(isset($expungeButton)) {
194 $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true);
195 if (($startMessage+
$cnt-1) >= $mbx_response['EXISTS']) {
196 if ($startMessage > $show_num) {
197 $location = set_url_var($location,'startMessage',$startMessage-$show_num);
199 $location = set_url_var($location,'startMessage',1);
202 header("Location: $location");
204 } elseif(isset($undeleteButton)) {
205 // undelete messages if user isn't using move_to_trash or auto_expunge
206 if (is_array($msg) == 1) {
207 // Removes \Deleted flag from selected messages
210 // If they have selected nothing msg is size one still, but will be an infinite
211 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
212 while ($j < count($msg)) {
214 sqimap_messages_remove_flag ($imapConnection, $msg[$i], $msg[$i], "Deleted", true);
219 header ("Location: $location");
222 displayPageHeader($color, $mailbox);
223 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
225 } elseif (!isset($moveButton)) {
226 // If the delete button was pressed, the moveButton variable will not be set.
227 if (is_array($msg) == 1) {
228 // Marks the selected messages as 'Deleted'
231 // If they have selected nothing msg is size one still, but will be an infinite
232 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
233 while ($j < count($msg)) {
234 if (isset($msg[$i])) {
235 if (isset($markRead)) {
236 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Seen", true);
237 } else if (isset($markUnread)) {
238 sqimap_messages_remove_flag($imapConnection, $msg[$i], $msg[$i], "Seen", true);
239 } else if (isset($attache)) {
242 sqimap_messages_delete($imapConnection, $msg[$i], $msg[$i], $mailbox);
249 $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true);
253 if (isset($attache)) {
254 $composesession = attachSelectedMessages($msg, $imapConnection);
255 if ($compose_new_win) {
256 header ("Location: $location&composenew=1&session=$composesession");
259 $location = str_replace('search.php','compose.php',$location);
260 $location = str_replace('right_main.php','compose.php',$location);
261 header ("Location: $location&session=$composesession");
265 if (($startMessage+
$cnt-1) >= $mbx_response['EXISTS']) {
266 if ($startMessage > $show_num) {
267 $location = set_url_var($location,'startMessage',$startMessage-$show_num);
269 $location = set_url_var($location,'startMessage',1);
272 header ("Location: $location");
276 displayPageHeader($color, $mailbox);
277 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
279 } else { // Move messages
280 // lets check to see if they selected any messages
281 if (is_array($msg) == 1) {
284 // If they have selected nothing msg is size one still, but will be an infinite
285 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
288 if (isset($msg[$i])) {
289 /** check if they would like to move it to the trash folder or not */
290 sqimap_messages_copy($imapConnection, $msg[$i], $msg[$i], $targetMailbox);
291 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Deleted", true);
297 $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true);
302 if (($startMessage+
$cnt-1) >= $mbx_response['EXISTS']) {
303 if ($startMessage > $show_num) {
304 $location = set_url_var($location,'startMessage',$startMessage-$show_num);
306 $location = set_url_var($location,'startMessage',1);
309 header ("Location: $location");
312 displayPageHeader($color, $mailbox);
313 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
316 // Log out this session
317 sqimap_logout($imapConnection);