removing help translations. bg_BG
[squirrelmail.git] / src / move_messages.php
... / ...
CommitLineData
1<?php
2
3/**
4 * move_messages.php
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
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 */
13
14/* Path for SquirrelMail required files. */
15define('SM_PATH','../');
16
17/* SquirrelMail required files. */
18require_once(SM_PATH . 'include/validate.php');
19require_once(SM_PATH . 'functions/global.php');
20require_once(SM_PATH . 'functions/display_messages.php');
21require_once(SM_PATH . 'functions/imap.php');
22require_once(SM_PATH . 'functions/html.php');
23
24global $compose_new_win;
25
26if ( !sqgetGlobalVar('composesession', $composesession, SQ_SESSION) ) {
27 $composesession = 0;
28}
29
30function attachSelectedMessages($msg, $imapConnection) {
31 global $username, $attachment_dir, $startMessage,
32 $data_dir, $composesession, $uid_support,
33 $msgs, $show_num, $compose_messages;
34
35 if (!isset($compose_messages)) {
36 $compose_messages = array();
37 sqsession_register($compose_messages,'compose_messages');
38 }
39
40 if (!$composesession) {
41 $composesession = 1;
42 sqsession_register($composesession,'composesession');
43 } else {
44 $composesession++;
45 sqsession_register($composesession,'composesession');
46 }
47
48 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
49
50 $composeMessage = new Message();
51 $rfc822_header = new Rfc822Header();
52 $composeMessage->rfc822_header = $rfc822_header;
53 $composeMessage->reply_rfc822_header = '';
54
55 foreach($msg as $id) {
56 $body_a = sqimap_run_command($imapConnection, "FETCH $id RFC822", true, $response, $readmessage, $uid_support);
57
58 if ($response == 'OK') {
59
60 // fetch the subject for the message with $id from msgs.
61 // is there a more efficient way to do this?
62 foreach($msgs as $k => $vals) {
63 if($vals['ID'] == $id) {
64 $subject = $msgs[$k]['SUBJECT'];
65 break;
66 }
67 }
68
69 array_shift($body_a);
70 array_pop($body_a);
71 $body = implode('', $body_a);
72 $body .= "\r\n";
73
74 $localfilename = GenerateRandomString(32, 'FILE', 7);
75 $full_localfilename = "$hashed_attachment_dir/$localfilename";
76
77 $fp = fopen( $full_localfilename, 'wb');
78 fwrite ($fp, $body);
79 fclose($fp);
80 $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
81 $full_localfilename);
82 }
83 }
84
85 $compose_messages[$composesession] = $composeMessage;
86 sqsession_register($compose_messages,'compose_messages');
87 session_write_close();
88 return $composesession;
89}
90
91
92
93/* get globals */
94sqgetGlobalVar('key', $key, SQ_COOKIE);
95sqgetGlobalVar('username', $username, SQ_SESSION);
96sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
97sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
98sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
99
100sqgetGlobalVar('mailbox', $mailbox);
101sqgetGlobalVar('startMessage', $startMessage);
102sqgetGlobalVar('msg', $msg);
103
104sqgetGlobalVar('msgs', $msgs, SQ_SESSION);
105sqgetGlobalVar('composesession', $composesession, SQ_SESSION);
106sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
107
108sqgetGlobalVar('moveButton', $moveButton, SQ_POST);
109sqgetGlobalVar('expungeButton', $expungeButton, SQ_POST);
110sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_POST);
111sqgetGlobalVar('expungeButton', $expungeButton, SQ_POST);
112sqgetGlobalVar('undeleteButton', $undeleteButton, SQ_POST);
113sqgetGlobalVar('markRead', $markRead, SQ_POST);
114sqgetGlobalVar('markUnread', $markUnread, SQ_POST);
115sqgetGlobalVar('attache', $attache, SQ_POST);
116sqgetGlobalVar('location', $location, SQ_POST);
117sqgetGlobalVar('bypass_trash', $bypass_trash, SQ_POST);
118
119/* end of get globals */
120
121$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
122$mbx_response=sqimap_mailbox_select($imapConnection, $mailbox);
123
124$location = set_url_var($location,'composenew',0,false);
125$location = set_url_var($location,'composesession',0,false);
126$location = set_url_var($location,'session',0,false);
127
128/* remember changes to mailbox setting */
129if (!isset($lastTargetMailbox)) {
130 $lastTargetMailbox = 'INBOX';
131}
132if ($targetMailbox != $lastTargetMailbox) {
133 $lastTargetMailbox = $targetMailbox;
134 sqsession_register($lastTargetMailbox, 'lastTargetMailbox');
135}
136$exception = false;
137
138do_hook('move_before_move');
139
140
141/*
142 Move msg list sorting up here, as it is used several times,
143 makes it more efficient to do it in one place for the code
144*/
145$id = array();
146if (isset($msg) && is_array($msg)) {
147 foreach( $msg as $key=>$uid ) {
148 // using foreach removes the risk of infinite loops that was there //
149 $id[] = $uid;
150 }
151}
152
153// expunge-on-demand if user isn't using move_to_trash or auto_expunge
154if(isset($expungeButton)) {
155 $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true);
156 if (($startMessage+$cnt-1) >= $mbx_response['EXISTS']) {
157 if ($startMessage > $show_num) {
158 $location = set_url_var($location,'startMessage',$startMessage-$show_num,false);
159 } else {
160 $location = set_url_var($location,'startMessage',1,false);
161 }
162 }
163} elseif(isset($undeleteButton)) {
164 // undelete messages if user isn't using move_to_trash or auto_expunge
165 // Removes \Deleted flag from selected messages
166 if (count($id)) {
167 sqimap_toggle_flag($imapConnection, $id, '\\Deleted',false,true);
168 } else {
169 $exception = true;
170 }
171} elseif (!isset($moveButton)) {
172 if (count($id)) {
173 $cnt = count($id);
174 if (!isset($attache)) {
175 $button_action = concat_hook_function('move_messages_button_action');
176 if (isset($markRead)) {
177 sqimap_toggle_flag($imapConnection, $id, '\\Seen',true,true);
178 } else if (isset($markUnread)) {
179 sqimap_toggle_flag($imapConnection, $id, '\\Seen',false,true);
180 } else {
181 if (!$button_action) {
182 sqimap_msgs_list_delete($imapConnection, $mailbox, $id,$bypass_trash);
183 if ($auto_expunge) {
184 $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true);
185 }
186 }
187 }
188 }
189 if (isset($attache)) {
190 $composesession = attachSelectedMessages($id, $imapConnection);
191 $location = set_url_var($location, 'session', $composesession, false);
192 if ($compose_new_win) {
193 $location = set_url_var($location, 'composenew', 1, false);
194 } else {
195 $location = str_replace('search.php','compose.php',$location);
196 $location = str_replace('right_main.php','compose.php',$location);
197 }
198 } else {
199 if (($startMessage+$cnt-1) >= $mbx_response['EXISTS']) {
200 if ($startMessage > $show_num) {
201 $location = set_url_var($location,'startMessage',$startMessage-$show_num, false);
202 } else {
203 $location = set_url_var($location,'startMessage',1, false);
204 }
205 }
206 }
207 } else {
208 $exception = true;
209 }
210} else { // Move messages
211
212 if (count($id)) {
213 sqimap_msgs_list_move($imapConnection,$id,$targetMailbox);
214 if ($auto_expunge) {
215 $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true);
216 } else {
217 $cnt = 0;
218 }
219
220 if (($startMessage+$cnt-1) >= $mbx_response['EXISTS']) {
221 if ($startMessage > $show_num) {
222 $location = set_url_var($location,'startMessage',$startMessage-$show_num, false);
223 } else {
224 $location = set_url_var($location,'startMessage',1, false);
225 }
226 }
227 } else {
228 $exception = true;
229 }
230}
231// Log out this session
232sqimap_logout($imapConnection);
233if ($exception) {
234 displayPageHeader($color, $mailbox);
235 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
236} else {
237 header("Location: $location");
238 exit;
239}
240?>
241</BODY></HTML>