f5acbb9cd2e1e7d4db69f645614d19f098b99a1e
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;
113 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
114 $mbx_response=sqimap_mailbox_select($imapConnection, $mailbox);
116 $location = set_url_var($location,'composenew');
117 $location = set_url_var($location,'composesession');
118 $location = set_url_var($location,'session');
120 /* remember changes to mailbox setting */
121 if (!isset($lastTargetMailbox)) {
122 $lastTargetMailbox = 'INBOX';
124 if ($targetMailbox != $lastTargetMailbox) {
125 $lastTargetMailbox = $targetMailbox;
126 session_register('lastTargetMailbox');
129 // expunge-on-demand if user isn't using move_to_trash or auto_expunge
130 if(isset($expungeButton)) {
131 $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true);
132 if (($startMessage+
$cnt-1) >= $mbx_response['EXISTS']) {
133 if ($startMessage > $show_num) {
134 $location = set_url_var($location,'startMessage',$startMessage-$show_num);
136 $location = set_url_var($location,'startMessage',1);
139 header("Location: $location");
140 } elseif(isset($undeleteButton)) {
141 // undelete messages if user isn't using move_to_trash or auto_expunge
142 if (is_array($msg) == 1) {
143 // Removes \Deleted flag from selected messages
146 // If they have selected nothing msg is size one still, but will be an infinite
147 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
148 while ($j < count($msg)) {
150 sqimap_messages_remove_flag ($imapConnection, $msg[$i], $msg[$i], "Deleted", true);
155 header ("Location: $location");
157 displayPageHeader($color, $mailbox);
158 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
160 } elseif (!isset($moveButton)) {
161 // If the delete button was pressed, the moveButton variable will not be set.
162 if (is_array($msg) == 1) {
163 // Marks the selected messages as 'Deleted'
166 // If they have selected nothing msg is size one still, but will be an infinite
167 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
168 while ($j < count($msg)) {
169 if (isset($msg[$i])) {
170 if (isset($markRead)) {
171 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Seen", true);
172 } else if (isset($markUnread)) {
173 sqimap_messages_remove_flag($imapConnection, $msg[$i], $msg[$i], "Seen", true);
174 } else if (isset($attache)) {
177 sqimap_messages_delete($imapConnection, $msg[$i], $msg[$i], $mailbox);
184 $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true);
188 if (isset($attache)) {
189 $composesession = attachSelectedMessages($msg, $imapConnection);
190 if ($compose_new_win) {
191 header ("Location: $location&composenew=1&session=$composesession");
193 $location = str_replace('search.php','compose.php',$location);
194 $location = str_replace('right_main.php','compose.php',$location);
195 header ("Location: $location&session=$composesession");
198 if (($startMessage+
$cnt-1) >= $mbx_response['EXISTS']) {
199 if ($startMessage > $show_num) {
200 $location = set_url_var($location,'startMessage',$startMessage-$show_num);
202 $location = set_url_var($location,'startMessage',1);
205 header ("Location: $location");
208 displayPageHeader($color, $mailbox);
209 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
211 } else { // Move messages
212 // lets check to see if they selected any messages
213 if (is_array($msg) == 1) {
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.
220 if (isset($msg[$i])) {
221 /** check if they would like to move it to the trash folder or not */
222 sqimap_messages_copy($imapConnection, $msg[$i], $msg[$i], $targetMailbox);
223 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Deleted", true);
229 $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true);
234 if (($startMessage+
$cnt-1) >= $mbx_response['EXISTS']) {
235 if ($startMessage > $show_num) {
236 $location = set_url_var($location,'startMessage',$startMessage-$show_num);
238 $location = set_url_var($location,'startMessage',1);
241 header ("Location: $location");
243 displayPageHeader($color, $mailbox);
244 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
247 // Log out this session
248 sqimap_logout($imapConnection);