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 | |
35586184 |
14 | require_once('../src/validate.php'); |
15 | require_once('../functions/display_messages.php'); |
16 | require_once('../functions/imap.php'); |
d3cdb279 |
17 | |
acc28bac |
18 | global $compose_new_win; |
19 | |
65c3ec94 |
20 | function putSelectedMessagesIntoString($msg) { |
21 | $j = 0; |
22 | $i = 0; |
23 | $firstLoop = true; |
24 | |
25 | // If they have selected nothing msg is size one still, but will |
26 | // be an infinite loop because we never increment j. so check to |
27 | // see if msg[0] is set or not to fix this. |
28 | while (($j < count($msg)) && ($msg[0])) { |
29 | if ($msg[$i]) { |
5e9e90fd |
30 | if ($firstLoop != true) { |
31 | $selectedMessages .= "&"; |
32 | } else { |
33 | $firstLoop = false; |
34 | } |
dd88d31f |
35 | |
36 | $selectedMessages .= "selMsg[$j]=$msg[$i]"; |
65c3ec94 |
37 | |
05207a68 |
38 | $j++; |
65c3ec94 |
39 | } |
40 | $i++; |
41 | } |
42 | } |
43 | |
acc28bac |
44 | function attachSelectedMessages($msg, $imapConnection) { |
45 | |
5b8d68ca |
46 | global $mailbox, $username, $attachment_dir, $attachments, $identity, |
47 | $data_dir, $composesession, $lastTargetMailbox, $uid_support; |
acc28bac |
48 | |
49 | |
50 | if (!isset($attachments)) { |
21f3c131 |
51 | $attachments = array(); |
52 | session_register('attachments'); |
acc28bac |
53 | } |
54 | |
fee4465d |
55 | if (!isset($composesession) ) { |
21f3c131 |
56 | $composesession = 1; |
fee4465d |
57 | session_register('composesession'); |
acc28bac |
58 | } else { |
21f3c131 |
59 | $composesession++; |
acc28bac |
60 | } |
61 | |
21f3c131 |
62 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir, $composesession); |
acc28bac |
63 | |
64 | $rem_attachments = array(); |
65 | foreach ($attachments as $info) { |
21f3c131 |
66 | if ($info['session'] == $composesession) { |
acc28bac |
67 | $attached_file = "$hashed_attachment_dir/$info[localfilename]"; |
68 | if (file_exists($attached_file)) { |
21f3c131 |
69 | unlink($attached_file); |
acc28bac |
70 | } |
21f3c131 |
71 | } else { |
72 | $rem_attachments[] = $info; |
73 | } |
acc28bac |
74 | } |
75 | |
76 | $attachments = $rem_attachments; |
77 | |
78 | |
79 | $i = 0; |
80 | $j = 0; |
21f3c131 |
81 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
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') { |
87 | // get subject so we can set the remotefilename |
5b8d68ca |
88 | $read = sqimap_run_command ($imapConnection, "FETCH $id BODY.PEEK[HEADER.FIELDS (Subject)]", true, $response, $readmessage, $uid_support); |
21f3c131 |
89 | $subject = substr($read[1], strpos($read[1], ' ')); |
90 | $subject = trim($subject); |
91 | |
92 | if (isset($subject) && $subject != '') { |
93 | $subject = htmlentities($subject); |
94 | } else { |
95 | $subject = _("<No subject>"); |
96 | $subject = htmlentities($subject); |
97 | } |
98 | |
99 | array_shift($body_a); |
100 | $body = implode('', $body_a); |
101 | $body .= "\r\n"; |
102 | |
103 | $localfilename = GenerateRandomString(32, 'FILE', 7); |
104 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
105 | |
106 | $fp = fopen( $full_localfilename, 'w'); |
107 | fwrite ($fp, $body); |
108 | fclose($fp); |
109 | |
110 | $newAttachment = array(); |
111 | $newAttachment['localfilename'] = $localfilename; |
112 | $newAttachment['type'] = "message/rfc822"; |
fee4465d |
113 | $newAttachment['remotefilename'] = "$subject".".eml"; |
114 | $newAttachment['session'] = $composesession; |
21f3c131 |
115 | $attachments[] = $newAttachment; |
116 | flush(); |
acc28bac |
117 | } |
21f3c131 |
118 | $j++; |
119 | } |
120 | $i++; |
acc28bac |
121 | |
122 | } |
123 | return $composesession; |
124 | } |
125 | |
65c3ec94 |
126 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
127 | sqimap_mailbox_select($imapConnection, $mailbox); |
128 | |
cd885078 |
129 | /* remember changes to mailbox setting */ |
130 | if (!isset($lastTargetMailbox)) { |
131 | $lastTargetMailbox = 'INBOX'; |
132 | } |
133 | if ($targetMailbox != $lastTargetMailbox) { |
134 | $lastTargetMailbox = $targetMailbox; |
135 | session_register('lastTargetMailbox'); |
136 | } |
137 | |
65c3ec94 |
138 | // expunge-on-demand if user isn't using move_to_trash or auto_expunge |
139 | if(isset($expungeButton)) { |
140 | sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
141 | $location = get_location(); |
acc28bac |
142 | if (isset($where) && isset($what)) { |
fae72101 |
143 | header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where)); |
65c3ec94 |
144 | } else { |
fae72101 |
145 | header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox)); |
65c3ec94 |
146 | } |
147 | |
148 | } elseif(isset($undeleteButton)) { |
149 | // undelete messages if user isn't using move_to_trash or auto_expunge |
150 | |
151 | if (is_array($msg) == 1) { |
152 | // Removes \Deleted flag from selected messages |
153 | $j = 0; |
154 | $i = 0; |
155 | |
156 | // If they have selected nothing msg is size one still, but will be an infinite |
157 | // loop because we never increment j. so check to see if msg[0] is set or not to fix this. |
158 | while ($j < count($msg)) { |
f9b3e5d9 |
159 | if ($msg[$i]) { |
65c3ec94 |
160 | sqimap_messages_remove_flag ($imapConnection, $msg[$i], $msg[$i], "Deleted"); |
161 | $j++; |
f9b3e5d9 |
162 | } |
163 | $i++; |
65c3ec94 |
164 | } |
165 | $location = get_location(); |
f9b3e5d9 |
166 | |
65c3ec94 |
167 | if ($where && $what) |
fae72101 |
168 | header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where)); |
65c3ec94 |
169 | else |
fae72101 |
170 | header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox)); |
65c3ec94 |
171 | } else { |
172 | displayPageHeader($color, $mailbox); |
173 | error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color); |
174 | } |
175 | } elseif (!isset($moveButton)) { |
176 | // If the delete button was pressed, the moveButton variable will not be set. |
177 | if (is_array($msg) == 1) { |
178 | // Marks the selected messages as 'Deleted' |
179 | $j = 0; |
180 | $i = 0; |
181 | |
182 | // If they have selected nothing msg is size one still, but will be an infinite |
183 | // loop because we never increment j. so check to see if msg[0] is set or not to fix this. |
184 | while ($j < count($msg)) { |
23fd3c8e |
185 | if (isset($msg[$i])) { |
65c3ec94 |
186 | if (isset($markRead)) { |
187 | sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Seen"); |
188 | } else if (isset($markUnread)) { |
189 | sqimap_messages_remove_flag($imapConnection, $msg[$i], $msg[$i], "Seen"); |
acc28bac |
190 | } else if (isset($attache)) { |
191 | break; |
192 | } else { |
65c3ec94 |
193 | sqimap_messages_delete($imapConnection, $msg[$i], $msg[$i], $mailbox); |
194 | } |
195 | $j++; |
2d7d3c2a |
196 | } |
dd88d31f |
197 | $i++; |
65c3ec94 |
198 | } |
199 | if ($auto_expunge) { |
8cf653ad |
200 | sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
65c3ec94 |
201 | } |
202 | $location = get_location(); |
203 | if (isset($where) && isset($what)) { |
ef0ea59e |
204 | if (isset($attache)) { |
205 | $composesession = attachSelectedMessages($msg, $imapConnection); |
206 | if ($compose_new_win == '1') { |
207 | header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where)."&composenew=1&session=$composesession&attachedmessages=true"); |
208 | } else { |
209 | header ("Location: $location/compose.php?startMessage=$startMessage&mailbox=". urlencode($mailbox)."&session=$composesession&attachedmessages=true".$wherewhat); |
210 | } |
211 | } else { |
212 | header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where)); |
213 | } |
acc28bac |
214 | } elseif(isset($attache)) { |
215 | $composesession = attachSelectedMessages($msg, $imapConnection); |
216 | if ($compose_new_win == '1') { |
217 | header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox)."&composenew=1&session=$composesession&attachedmessages=true"); |
218 | } else { |
219 | header ("Location: $location/compose.php?startMessage=$startMessage&mailbox=". urlencode($mailbox)."&session=$composesession&attachedmessages=true"); |
220 | } |
65c3ec94 |
221 | } else { |
fae72101 |
222 | header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox)); |
65c3ec94 |
223 | } |
224 | } else { |
225 | displayPageHeader($color, $mailbox); |
226 | error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color); |
227 | } |
228 | } else { // Move messages |
229 | // lets check to see if they selected any messages |
230 | if (is_array($msg) == 1) { |
231 | $j = 0; |
232 | $i = 0; |
233 | |
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 | /** check if they would like to move it to the trash folder or not */ |
239 | sqimap_messages_copy($imapConnection, $msg[$i], $msg[$i], $targetMailbox); |
240 | sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Deleted"); |
241 | $j++; |
dd88d31f |
242 | } |
243 | $i++; |
65c3ec94 |
244 | } |
245 | if ($auto_expunge == true) |
8cf653ad |
246 | sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
de80e95e |
247 | |
65c3ec94 |
248 | $location = get_location(); |
249 | if (isset($where) && isset($what)) |
fae72101 |
250 | header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where)); |
65c3ec94 |
251 | else |
fae72101 |
252 | header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox)); |
65c3ec94 |
253 | } else { |
254 | displayPageHeader($color, $mailbox); |
255 | error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color); |
256 | } |
257 | } |
258 | |
259 | // Log out this session |
260 | sqimap_logout($imapConnection); |
b40316f9 |
261 | |
2aa12d5e |
262 | ?> |
6332704d |
263 | </BODY></HTML> |