a9fb476aabc4bda82783fba7ca11936ba4df6eb8
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 if (isset($_SESSION['composesession'])) {
26 $composesession = $_SESSION['composesession'];
31 function putSelectedMessagesIntoString($msg) {
35 // If they have selected nothing msg is size one still, but will
36 // be an infinite loop because we never increment j. so check to
37 // see if msg[0] is set or not to fix this.
38 while (($j < count($msg)) && ($msg[0])) {
40 if ($firstLoop != true) {
41 $selectedMessages .= "&";
45 $selectedMessages .= "selMsg[$j]=$msg[$i]";
52 function attachSelectedMessages($msg, $imapConnection) {
53 global $username, $attachment_dir,
54 $data_dir, $composesession, $uid_support,
55 $msgs, $thread_sort_messages, $allow_server_sort, $show_num,
59 if (!isset($compose_messages)) {
60 $compose_messages = array();
61 sqsession_register($compose_messages,'compose_messages');
64 if (!$composesession) {
66 sqsession_register($composesession,'composesession');
69 sqsession_register($composesession,'composesession');
72 $hashed_attachment_dir = getHashedDir($username, $attachment_dir, $composesession);
74 if ($thread_sort_messages ||
$allow_server_sort) {
77 $start_index = ($startMessage-1) * $show_num;
82 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
84 $composeMessage = new Message();
85 $rfc822_header = new Rfc822Header();
86 $composeMessage->rfc822_header
= $rfc822_header;
87 $composeMessage->reply_rfc822_header
= '';
89 while ($j < count($msg)) {
90 if (isset($msg[$i])) {
92 $body_a = sqimap_run_command($imapConnection, "FETCH $id RFC822",true, $response, $readmessage, $uid_support);
93 if ($response = 'OK') {
94 $k = $i +
$start_index;
95 $subject = $msgs[$k]['SUBJECT'];
98 $body = implode('', $body_a);
101 $localfilename = GenerateRandomString(32, 'FILE', 7);
102 $full_localfilename = "$hashed_attachment_dir/$localfilename";
104 $fp = fopen( $full_localfilename, 'wb');
107 $composeMessage->initAttachment('message/rfc822',$subject.'.eml',
108 $full_localfilename);
114 $compose_messages[$composesession] = $composeMessage;
115 sqsession_register($compose_messages,'compose_messages');
116 session_write_close();
117 return $composesession;
124 $username = $_SESSION['username'];
125 $key = $_COOKIE['key'];
126 $onetimepad = $_SESSION['onetimepad'];
127 $base_uri = $_SESSION['base_uri'];
128 $delimiter = $_SESSION['delimiter'];
129 if (isset($_GET['mailbox'])) {
130 $mailbox = $_GET['mailbox'];
132 if (isset($_GET['startMessage'])) {
133 $startMessage = $_GET['startMessage'];
135 if (isset($_POST['moveButton'])) {
136 $moveButton = $_POST['moveButton'];
138 if (isset($_POST['msg'])) {
139 $msg = $_POST['msg'];
141 elseif (isset($_GET['msg'])) {
145 if (isset($_SESSION['msgs'])) {
146 $msgs = $_SESSION['msgs'];
150 if (isset($_POST['expungeButton'])) {
151 $expungeButton = $_POST['expungeButton'];
153 if (isset($_POST['targetMailbox'])) {
154 $targetMailbox = $_POST['targetMailbox'];
156 if (isset($_SESSION['lastTargetMailbox'])) {
157 $lastTargetMailbox = $_SESSION['lastTargetMailbox'];
159 if (isset($_POST['expungeButton'])) {
160 $expungeButton = $_POST['expungeButton'];
162 if (isset($_POST['undeleteButton'])) {
163 $undeleteButton = $_POST['undeleteButton'];
165 if (isset($_POST['markRead'])) {
166 $markRead = $_POST['markRead'];
168 if (isset($_POST['markUnread'])) {
169 $markUnread = $_POST['markUnread'];
171 if (isset($_POST['attache'])) {
172 $attache = $_POST['attache'];
175 if (isset($_POST['location'])) {
176 $location = $_POST['location'];
179 if (isset($_SESSION['composesession'])) {
180 $composesession = $_SESSION['composesession'];
182 /* end of get globals */
184 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
185 $mbx_response=sqimap_mailbox_select($imapConnection, $mailbox);
187 $location = set_url_var($location,'composenew',0,false);
188 $location = set_url_var($location,'composesession',0,false);
189 $location = set_url_var($location,'session',0,false);
191 /* remember changes to mailbox setting */
192 if (!isset($lastTargetMailbox)) {
193 $lastTargetMailbox = 'INBOX';
195 if ($targetMailbox != $lastTargetMailbox) {
196 $lastTargetMailbox = $targetMailbox;
197 sqsession_register($lastTargetMailbox, 'lastTargetMailbox');
200 // expunge-on-demand if user isn't using move_to_trash or auto_expunge
201 if(isset($expungeButton)) {
202 $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true);
203 if (($startMessage+
$cnt-1) >= $mbx_response['EXISTS']) {
204 if ($startMessage > $show_num) {
205 $location = set_url_var($location,'startMessage',$startMessage-$show_num,false);
207 $location = set_url_var($location,'startMessage',1,false);
210 } elseif(isset($undeleteButton)) {
211 // undelete messages if user isn't using move_to_trash or auto_expunge
212 if (is_array($msg) == 1) {
213 // Removes \Deleted flag from selected messages
216 // If they have selected nothing msg is size one still, but will be an infinite
217 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
218 while ($j < count($msg)) {
220 sqimap_messages_remove_flag ($imapConnection, $msg[$i], $msg[$i], "Deleted", true);
228 } elseif (!isset($moveButton)) {
229 // If the delete button was pressed, the moveButton variable will not be set.
230 if (is_array($msg) == 1) {
231 // Marks the selected messages as 'Deleted'
234 // If they have selected nothing msg is size one still, but will be an infinite
235 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
236 while ($j < count($msg)) {
237 if (isset($msg[$i])) {
238 if (isset($markRead)) {
239 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Seen", true);
240 } else if (isset($markUnread)) {
241 sqimap_messages_remove_flag($imapConnection, $msg[$i], $msg[$i], "Seen", true);
242 } else if (isset($attache)) {
245 sqimap_messages_delete($imapConnection, $msg[$i], $msg[$i], $mailbox);
252 $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true);
256 if (isset($attache)) {
257 $composesession = attachSelectedMessages($msg, $imapConnection);
258 $location = set_url_var($location, 'session', $composesession, false);
259 if ($compose_new_win) {
260 $location = set_url_var($location, 'composenew', 1, false);
262 $location = str_replace('search.php','compose.php',$location);
263 $location = str_replace('right_main.php','compose.php',$location);
266 if (($startMessage+
$cnt-1) >= $mbx_response['EXISTS']) {
267 if ($startMessage > $show_num) {
268 $location = set_url_var($location,'startMessage',$startMessage-$show_num, false);
270 $location = set_url_var($location,'startMessage',1, false);
277 } else { // Move messages
278 // lets check to see if they selected any messages
279 if (is_array($msg) == 1) {
282 // If they have selected nothing msg is size one still, but will be an infinite
283 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
286 if (isset($msg[$i])) {
287 /** check if they would like to move it to the trash folder or not */
288 sqimap_messages_copy($imapConnection, $msg[$i], $msg[$i], $targetMailbox);
289 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Deleted", true);
295 $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true);
300 if (($startMessage+
$cnt-1) >= $mbx_response['EXISTS']) {
301 if ($startMessage > $show_num) {
302 $location = set_url_var($location,'startMessage',$startMessage-$show_num, false);
304 $location = set_url_var($location,'startMessage',1, false);
311 // Log out this session
312 sqimap_logout($imapConnection);
314 displayPageHeader($color, $mailbox);
315 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
317 header("Location: $location");