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']; |
121 | |
122 | if (isset($_GET['mailbox'])) { |
123 | $mailbox = $_GET['mailbox']; |
124 | } |
125 | if (isset($_GET['startMessage'])) { |
126 | $startMessage = $_GET['startMessage']; |
127 | } |
128 | if (isset($_POST['moveButton'])) { |
129 | $moveButton = $_POST['moveButton']; |
130 | } |
131 | if (isset($_POST['msg'])) { |
132 | $msg = $_POST['msg']; |
133 | } |
134 | elseif (isset($_GET['msg'])) { |
135 | $msg = $_GET['msg']; |
136 | } |
137 | if (isset($_POST['expungeButton'])) { |
138 | $expungeButton = $_POST['expungeButton']; |
139 | } |
140 | if (isset($_POST['targetMailbox'])) { |
141 | $targetMailbox = $_POST['targetMailbox']; |
142 | } |
143 | if (isset($_SESSION['lastTargetMailbox'])) { |
144 | $lastTargetMailbox = $_SESSION['lastTargetMailbox']; |
145 | } |
146 | if (isset($_POST['expungeButton'])) { |
147 | $expungeButton = $_POST['expungeButton']; |
148 | } |
149 | if (isset($_POST['undeleteButton'])) { |
150 | $undeleteButton = $_POST['undeleteButton']; |
151 | } |
152 | if (isset($_POST['markRead'])) { |
153 | $markRead = $_POST['markRead']; |
154 | } |
155 | if (isset($_POST['markUnread'])) { |
156 | $markUnread = $_POST['markUnread']; |
157 | } |
158 | if (isset($_POST['attache'])) { |
159 | $attache = $_POST['attache']; |
160 | } |
161 | |
162 | /* end of get globals */ |
163 | |
65c3ec94 |
164 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
9c22eb94 |
165 | $mbx_response=sqimap_mailbox_select($imapConnection, $mailbox); |
65c3ec94 |
166 | |
8c33aaf7 |
167 | $location = set_url_var($location,'composenew'); |
168 | $location = set_url_var($location,'composesession'); |
169 | $location = set_url_var($location,'session'); |
170 | |
cd885078 |
171 | /* remember changes to mailbox setting */ |
172 | if (!isset($lastTargetMailbox)) { |
173 | $lastTargetMailbox = 'INBOX'; |
174 | } |
175 | if ($targetMailbox != $lastTargetMailbox) { |
176 | $lastTargetMailbox = $targetMailbox; |
9837b0a5 |
177 | sqsession_register($lastTargetMailbox, 'lastTargetMailbox'); |
cd885078 |
178 | } |
179 | |
65c3ec94 |
180 | // expunge-on-demand if user isn't using move_to_trash or auto_expunge |
181 | if(isset($expungeButton)) { |
9c22eb94 |
182 | $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
183 | if (($startMessage+$cnt-1) >= $mbx_response['EXISTS']) { |
184 | if ($startMessage > $show_num) { |
185 | $location = set_url_var($location,'startMessage',$startMessage-$show_num); |
186 | } else { |
187 | $location = set_url_var($location,'startMessage',1); |
188 | } |
189 | } |
8c33aaf7 |
190 | header("Location: $location"); |
65c3ec94 |
191 | } elseif(isset($undeleteButton)) { |
192 | // undelete messages if user isn't using move_to_trash or auto_expunge |
65c3ec94 |
193 | if (is_array($msg) == 1) { |
194 | // Removes \Deleted flag from selected messages |
195 | $j = 0; |
196 | $i = 0; |
65c3ec94 |
197 | // If they have selected nothing msg is size one still, but will be an infinite |
198 | // loop because we never increment j. so check to see if msg[0] is set or not to fix this. |
199 | while ($j < count($msg)) { |
f9b3e5d9 |
200 | if ($msg[$i]) { |
d8a8203a |
201 | sqimap_messages_remove_flag ($imapConnection, $msg[$i], $msg[$i], "Deleted", true); |
8c33aaf7 |
202 | $j++; |
f9b3e5d9 |
203 | } |
204 | $i++; |
65c3ec94 |
205 | } |
8c33aaf7 |
206 | header ("Location: $location"); |
65c3ec94 |
207 | } else { |
208 | displayPageHeader($color, $mailbox); |
209 | error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color); |
210 | } |
211 | } elseif (!isset($moveButton)) { |
212 | // If the delete button was pressed, the moveButton variable will not be set. |
213 | if (is_array($msg) == 1) { |
214 | // Marks the selected messages as 'Deleted' |
215 | $j = 0; |
216 | $i = 0; |
65c3ec94 |
217 | // If they have selected nothing msg is size one still, but will be an infinite |
218 | // loop because we never increment j. so check to see if msg[0] is set or not to fix this. |
219 | while ($j < count($msg)) { |
23fd3c8e |
220 | if (isset($msg[$i])) { |
65c3ec94 |
221 | if (isset($markRead)) { |
d8a8203a |
222 | sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Seen", true); |
65c3ec94 |
223 | } else if (isset($markUnread)) { |
d8a8203a |
224 | sqimap_messages_remove_flag($imapConnection, $msg[$i], $msg[$i], "Seen", true); |
acc28bac |
225 | } else if (isset($attache)) { |
226 | break; |
227 | } else { |
65c3ec94 |
228 | sqimap_messages_delete($imapConnection, $msg[$i], $msg[$i], $mailbox); |
229 | } |
230 | $j++; |
2d7d3c2a |
231 | } |
dd88d31f |
232 | $i++; |
65c3ec94 |
233 | } |
234 | if ($auto_expunge) { |
9c22eb94 |
235 | $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
236 | } else { |
237 | $cnt = 0; |
238 | } |
8c33aaf7 |
239 | if (isset($attache)) { |
acc28bac |
240 | $composesession = attachSelectedMessages($msg, $imapConnection); |
8c33aaf7 |
241 | if ($compose_new_win) { |
242 | header ("Location: $location&composenew=1&session=$composesession"); |
acc28bac |
243 | } else { |
8c33aaf7 |
244 | $location = str_replace('search.php','compose.php',$location); |
245 | $location = str_replace('right_main.php','compose.php',$location); |
246 | header ("Location: $location&session=$composesession"); |
acc28bac |
247 | } |
8c33aaf7 |
248 | } else { |
9c22eb94 |
249 | if (($startMessage+$cnt-1) >= $mbx_response['EXISTS']) { |
250 | if ($startMessage > $show_num) { |
251 | $location = set_url_var($location,'startMessage',$startMessage-$show_num); |
252 | } else { |
253 | $location = set_url_var($location,'startMessage',1); |
254 | } |
255 | } |
8c33aaf7 |
256 | header ("Location: $location"); |
257 | } |
65c3ec94 |
258 | } else { |
259 | displayPageHeader($color, $mailbox); |
260 | error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color); |
261 | } |
262 | } else { // Move messages |
263 | // lets check to see if they selected any messages |
264 | if (is_array($msg) == 1) { |
265 | $j = 0; |
266 | $i = 0; |
65c3ec94 |
267 | // If they have selected nothing msg is size one still, but will be an infinite |
268 | // loop because we never increment j. so check to see if msg[0] is set or not to fix this. |
9c22eb94 |
269 | $cnt = count($msg); |
270 | while ($j < $cnt) { |
23fd3c8e |
271 | if (isset($msg[$i])) { |
65c3ec94 |
272 | /** check if they would like to move it to the trash folder or not */ |
273 | sqimap_messages_copy($imapConnection, $msg[$i], $msg[$i], $targetMailbox); |
d8a8203a |
274 | sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Deleted", true); |
65c3ec94 |
275 | $j++; |
dd88d31f |
276 | } |
277 | $i++; |
65c3ec94 |
278 | } |
8c33aaf7 |
279 | if ($auto_expunge) { |
9c22eb94 |
280 | $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
281 | } else { |
282 | $cnt = 0; |
283 | } |
284 | |
285 | if (($startMessage+$cnt-1) >= $mbx_response['EXISTS']) { |
286 | if ($startMessage > $show_num) { |
287 | $location = set_url_var($location,'startMessage',$startMessage-$show_num); |
288 | } else { |
289 | $location = set_url_var($location,'startMessage',1); |
290 | } |
8c33aaf7 |
291 | } |
292 | header ("Location: $location"); |
65c3ec94 |
293 | } else { |
294 | displayPageHeader($color, $mailbox); |
295 | error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color); |
296 | } |
297 | } |
65c3ec94 |
298 | // Log out this session |
299 | sqimap_logout($imapConnection); |
b40316f9 |
300 | |
2aa12d5e |
301 | ?> |
6332704d |
302 | </BODY></HTML> |