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