de17ca937dfc12b213684b0d2b7cdabeb0da1930
[squirrelmail.git] / src / move_messages.php
1 <?php
2 /**
3 ** move_messages.php
4 **
5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 **
8 ** Enables message moving between folders on the IMAP server.
9 **/
10
11 session_start();
12
13 if (!isset($config_php))
14 include("../config/config.php");
15 if (!isset($strings_php))
16 include("../functions/strings.php");
17 if (!isset($page_header_php))
18 include("../functions/page_header.php");
19 if (!isset($display_messages_php))
20 include("../functions/display_messages.php");
21 if (!isset($imap_php))
22 include("../functions/imap.php");
23
24 include("../src/load_prefs.php");
25
26 function putSelectedMessagesIntoString($msg) {
27 $j = 0;
28 $i = 0;
29 $firstLoop = true;
30
31 // If they have selected nothing msg is size one still, but will
32 // be an infinite loop because we never increment j. so check to
33 // see if msg[0] is set or not to fix this.
34 while (($j < count($msg)) && ($msg[0])) {
35 if ($msg[$i]) {
36 if ($firstLoop != true)
37 $selectedMessages .= "&";
38 else
39 $firstLoop = false;
40
41 $selectedMessages .= "selMsg[$j]=$msg[$i]";
42
43 $j++;
44 }
45 $i++;
46 }
47 }
48
49 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
50 sqimap_mailbox_select($imapConnection, $mailbox);
51
52 // If the delete button was pressed, the moveButton variable will not be set.
53 if (!$moveButton) {
54 if (is_array($msg) == 1) {
55 // Marks the selected messages ad 'Deleted'
56 $j = 0;
57 $i = 0;
58
59 // If they have selected nothing msg is size one still, but will be an infinite
60 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
61 while ($j < count($msg)) {
62 if ($msg[$i]) {
63 sqimap_messages_delete($imapConnection, $msg[$i], $msg[$i], $mailbox);
64 $j++;
65 }
66 $i++;
67 }
68 if ($auto_expunge) {
69 sqimap_mailbox_expunge($imapConnection, $mailbox);
70 }
71 if ($auto_forward) {
72 header ("Location: right_main.php");
73 } else {
74 displayPageHeader($color, $mailbox);
75 messages_deleted_message($mailbox, $sort, $startMessage, $color);
76 }
77 } else {
78 displayPageHeader($color, $mailbox);
79 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
80 }
81 } else { // Move messages
82 // lets check to see if they selected any messages
83 if (is_array($msg) == 1) {
84 $j = 0;
85 $i = 0;
86
87 // If they have selected nothing msg is size one still, but will be an infinite
88 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
89 while ($j < count($msg)) {
90 if ($msg[$i]) {
91 /** check if they would like to move it to the trash folder or not */
92 sqimap_messages_copy($imapConnection, $msg[$i], $msg[$i], $targetMailbox);
93 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Deleted");
94 $j++;
95 }
96 $i++;
97 }
98 if ($auto_expunge == true)
99 sqimap_mailbox_expunge($imapConnection, $mailbox);
100
101 if ($auto_forward) {
102 header ("Location: right_main.php");
103 } else {
104 displayPageHeader($color, $mailbox);
105 messages_moved_message($mailbox, $sort, $startMessage, $color);
106 }
107 } else {
108 displayPageHeader($color, $mailbox);
109 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
110 }
111 }
112
113 // Log out this session
114 sqimap_logout($imapConnection);
115
116 ?>
117 </BODY></HTML>