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