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 | |
86725763 |
14 | /* Path for SquirrelMail required files. */ |
15 | define('SM_PATH','../'); |
16 | |
17 | /* SquirrelMail required files. */ |
08185f2a |
18 | require_once(SM_PATH . 'include/validate.php'); |
86725763 |
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'); |
22 | |
acc28bac |
23 | global $compose_new_win; |
24 | |
65c3ec94 |
25 | function putSelectedMessagesIntoString($msg) { |
26 | $j = 0; |
27 | $i = 0; |
28 | $firstLoop = true; |
65c3ec94 |
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])) { |
33 | if ($msg[$i]) { |
5e9e90fd |
34 | if ($firstLoop != true) { |
35 | $selectedMessages .= "&"; |
36 | } else { |
37 | $firstLoop = false; |
38 | } |
dd88d31f |
39 | $selectedMessages .= "selMsg[$j]=$msg[$i]"; |
05207a68 |
40 | $j++; |
65c3ec94 |
41 | } |
42 | $i++; |
43 | } |
44 | } |
45 | |
acc28bac |
46 | function attachSelectedMessages($msg, $imapConnection) { |
a2a30ee7 |
47 | global $username, $attachment_dir, |
48 | $data_dir, $composesession, $uid_support, |
49 | $msgs, $thread_sort_messages, $allow_server_sort, $show_num, |
50 | $compose_messages; |
51 | |
52 | |
53 | if (!isset($compose_messages)) { |
54 | $compose_messages = array(); |
55 | sqsession_register($compose_messages,'compose_messages'); |
acc28bac |
56 | } |
57 | |
fee4465d |
58 | if (!isset($composesession) ) { |
21f3c131 |
59 | $composesession = 1; |
a2a30ee7 |
60 | sqsession_register($composesession,'composesession'); |
acc28bac |
61 | } else { |
21f3c131 |
62 | $composesession++; |
acc28bac |
63 | } |
64 | |
21f3c131 |
65 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir, $composesession); |
acc28bac |
66 | |
8c33aaf7 |
67 | if ($thread_sort_messages || $allow_server_sort) { |
68 | $start_index=0; |
69 | } else { |
70 | $start_index = ($startMessage-1) * $show_num; |
71 | } |
acc28bac |
72 | |
73 | $i = 0; |
74 | $j = 0; |
21f3c131 |
75 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
a2a30ee7 |
76 | |
77 | $composeMessage = new Message(); |
78 | $rfc822_header = new Rfc822Header(); |
79 | $composeMessage->rfc822_header = $rfc822_header; |
80 | $composeMessage->reply_rfc822_header = ''; |
81 | |
acc28bac |
82 | while ($j < count($msg)) { |
83 | if (isset($msg[$i])) { |
21f3c131 |
84 | $id = $msg[$i]; |
5b8d68ca |
85 | $body_a = sqimap_run_command($imapConnection, "FETCH $id RFC822",true, $response, $readmessage, $uid_support); |
21f3c131 |
86 | if ($response = 'OK') { |
8c33aaf7 |
87 | $k = $i + $start_index; |
88 | $subject = $msgs[$k]['SUBJECT']; |
21f3c131 |
89 | |
8c33aaf7 |
90 | array_shift($body_a); |
91 | $body = implode('', $body_a); |
92 | $body .= "\r\n"; |
21f3c131 |
93 | |
8c33aaf7 |
94 | $localfilename = GenerateRandomString(32, 'FILE', 7); |
95 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
96 | |
81d79073 |
97 | $fp = fopen( $full_localfilename, 'wb'); |
8c33aaf7 |
98 | fwrite ($fp, $body); |
99 | fclose($fp); |
a2a30ee7 |
100 | $composeMessage->initAttachment('message/rfc822',$subject.'.eml', |
101 | $full_localfilename); |
acc28bac |
102 | } |
8c33aaf7 |
103 | $j++; |
104 | } |
105 | $i++; |
acc28bac |
106 | } |
a2a30ee7 |
107 | $compose_messages[$composesession] = $composeMessage; |
108 | sqsession_register($compose_messages,'compose_messages'); |
acc28bac |
109 | return $composesession; |
110 | } |
111 | |
9c22eb94 |
112 | |
9837b0a5 |
113 | |
114 | /* get globals */ |
115 | |
116 | $username = $_SESSION['username']; |
117 | $key = $_COOKIE['key']; |
118 | $onetimepad = $_SESSION['onetimepad']; |
119 | $base_uri = $_SESSION['base_uri']; |
120 | $delimiter = $_SESSION['delimiter']; |
2e716bd9 |
121 | if (isset($_GET['mailbox'])) { |
122 | $mailbox = $_GET['mailbox']; |
9837b0a5 |
123 | } |
2e716bd9 |
124 | if (isset($_GET['startMessage'])) { |
125 | $startMessage = $_GET['startMessage']; |
9837b0a5 |
126 | } |
127 | if (isset($_POST['moveButton'])) { |
128 | $moveButton = $_POST['moveButton']; |
129 | } |
130 | if (isset($_POST['msg'])) { |
131 | $msg = $_POST['msg']; |
132 | } |
2e716bd9 |
133 | elseif (isset($_GET['msg'])) { |
134 | $msg = $_GET['msg']; |
135 | } |
882cd908 |
136 | |
137 | if (isset($_SESSION['msgs'])) { |
138 | $msgs = $_SESSION['msgs']; |
139 | } |
140 | |
141 | |
9837b0a5 |
142 | if (isset($_POST['expungeButton'])) { |
143 | $expungeButton = $_POST['expungeButton']; |
144 | } |
145 | if (isset($_POST['targetMailbox'])) { |
146 | $targetMailbox = $_POST['targetMailbox']; |
147 | } |
148 | if (isset($_SESSION['lastTargetMailbox'])) { |
149 | $lastTargetMailbox = $_SESSION['lastTargetMailbox']; |
150 | } |
151 | if (isset($_POST['expungeButton'])) { |
152 | $expungeButton = $_POST['expungeButton']; |
153 | } |
154 | if (isset($_POST['undeleteButton'])) { |
155 | $undeleteButton = $_POST['undeleteButton']; |
156 | } |
157 | if (isset($_POST['markRead'])) { |
158 | $markRead = $_POST['markRead']; |
159 | } |
160 | if (isset($_POST['markUnread'])) { |
161 | $markUnread = $_POST['markUnread']; |
162 | } |
163 | if (isset($_POST['attache'])) { |
164 | $attache = $_POST['attache']; |
165 | } |
166 | |
c083ce9a |
167 | if (isset($_POST['location'])) { |
168 | $location = $_POST['location']; |
169 | } |
170 | |
882cd908 |
171 | if (isset($_SESSION['composesession'])) { |
172 | $composesession = $_SESSION['composesession']; |
173 | } |
9837b0a5 |
174 | /* end of get globals */ |
175 | |
65c3ec94 |
176 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
9c22eb94 |
177 | $mbx_response=sqimap_mailbox_select($imapConnection, $mailbox); |
65c3ec94 |
178 | |
8c33aaf7 |
179 | $location = set_url_var($location,'composenew'); |
180 | $location = set_url_var($location,'composesession'); |
181 | $location = set_url_var($location,'session'); |
182 | |
cd885078 |
183 | /* remember changes to mailbox setting */ |
184 | if (!isset($lastTargetMailbox)) { |
185 | $lastTargetMailbox = 'INBOX'; |
186 | } |
187 | if ($targetMailbox != $lastTargetMailbox) { |
188 | $lastTargetMailbox = $targetMailbox; |
9837b0a5 |
189 | sqsession_register($lastTargetMailbox, 'lastTargetMailbox'); |
cd885078 |
190 | } |
191 | |
65c3ec94 |
192 | // expunge-on-demand if user isn't using move_to_trash or auto_expunge |
193 | if(isset($expungeButton)) { |
9c22eb94 |
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); |
198 | } else { |
199 | $location = set_url_var($location,'startMessage',1); |
200 | } |
201 | } |
8c33aaf7 |
202 | header("Location: $location"); |
c083ce9a |
203 | exit; |
65c3ec94 |
204 | } elseif(isset($undeleteButton)) { |
205 | // undelete messages if user isn't using move_to_trash or auto_expunge |
65c3ec94 |
206 | if (is_array($msg) == 1) { |
207 | // Removes \Deleted flag from selected messages |
208 | $j = 0; |
209 | $i = 0; |
65c3ec94 |
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)) { |
f9b3e5d9 |
213 | if ($msg[$i]) { |
d8a8203a |
214 | sqimap_messages_remove_flag ($imapConnection, $msg[$i], $msg[$i], "Deleted", true); |
8c33aaf7 |
215 | $j++; |
f9b3e5d9 |
216 | } |
217 | $i++; |
65c3ec94 |
218 | } |
8c33aaf7 |
219 | header ("Location: $location"); |
c083ce9a |
220 | exit; |
65c3ec94 |
221 | } else { |
222 | displayPageHeader($color, $mailbox); |
223 | error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color); |
224 | } |
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' |
229 | $j = 0; |
230 | $i = 0; |
65c3ec94 |
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)) { |
23fd3c8e |
234 | if (isset($msg[$i])) { |
65c3ec94 |
235 | if (isset($markRead)) { |
d8a8203a |
236 | sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Seen", true); |
65c3ec94 |
237 | } else if (isset($markUnread)) { |
d8a8203a |
238 | sqimap_messages_remove_flag($imapConnection, $msg[$i], $msg[$i], "Seen", true); |
acc28bac |
239 | } else if (isset($attache)) { |
240 | break; |
241 | } else { |
65c3ec94 |
242 | sqimap_messages_delete($imapConnection, $msg[$i], $msg[$i], $mailbox); |
243 | } |
244 | $j++; |
2d7d3c2a |
245 | } |
dd88d31f |
246 | $i++; |
65c3ec94 |
247 | } |
248 | if ($auto_expunge) { |
9c22eb94 |
249 | $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
250 | } else { |
251 | $cnt = 0; |
252 | } |
8c33aaf7 |
253 | if (isset($attache)) { |
acc28bac |
254 | $composesession = attachSelectedMessages($msg, $imapConnection); |
8c33aaf7 |
255 | if ($compose_new_win) { |
256 | header ("Location: $location&composenew=1&session=$composesession"); |
c083ce9a |
257 | exit; |
acc28bac |
258 | } else { |
8c33aaf7 |
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"); |
c083ce9a |
262 | exit; |
acc28bac |
263 | } |
8c33aaf7 |
264 | } else { |
9c22eb94 |
265 | if (($startMessage+$cnt-1) >= $mbx_response['EXISTS']) { |
266 | if ($startMessage > $show_num) { |
267 | $location = set_url_var($location,'startMessage',$startMessage-$show_num); |
268 | } else { |
269 | $location = set_url_var($location,'startMessage',1); |
270 | } |
271 | } |
8c33aaf7 |
272 | header ("Location: $location"); |
c083ce9a |
273 | exit; |
8c33aaf7 |
274 | } |
65c3ec94 |
275 | } else { |
276 | displayPageHeader($color, $mailbox); |
277 | error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color); |
278 | } |
279 | } else { // Move messages |
280 | // lets check to see if they selected any messages |
281 | if (is_array($msg) == 1) { |
282 | $j = 0; |
283 | $i = 0; |
65c3ec94 |
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. |
9c22eb94 |
286 | $cnt = count($msg); |
287 | while ($j < $cnt) { |
23fd3c8e |
288 | if (isset($msg[$i])) { |
65c3ec94 |
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); |
d8a8203a |
291 | sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Deleted", true); |
65c3ec94 |
292 | $j++; |
dd88d31f |
293 | } |
294 | $i++; |
65c3ec94 |
295 | } |
8c33aaf7 |
296 | if ($auto_expunge) { |
9c22eb94 |
297 | $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
298 | } else { |
299 | $cnt = 0; |
300 | } |
301 | |
302 | if (($startMessage+$cnt-1) >= $mbx_response['EXISTS']) { |
303 | if ($startMessage > $show_num) { |
304 | $location = set_url_var($location,'startMessage',$startMessage-$show_num); |
305 | } else { |
306 | $location = set_url_var($location,'startMessage',1); |
307 | } |
8c33aaf7 |
308 | } |
c083ce9a |
309 | header ("Location: $location"); |
310 | exit; |
65c3ec94 |
311 | } else { |
312 | displayPageHeader($color, $mailbox); |
313 | error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color); |
314 | } |
315 | } |
65c3ec94 |
316 | // Log out this session |
317 | sqimap_logout($imapConnection); |
2aa12d5e |
318 | ?> |
6332704d |
319 | </BODY></HTML> |