* Got bored and copied all the validate.php and define() stuff to 1.1
[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 ** $Id$
11 **/
12
13 include('../src/validate.php');
14 include("../functions/strings.php");
15 include("../config/config.php");
16 include("../functions/page_header.php");
17 include("../functions/display_messages.php");
18 include("../functions/imap.php");
19 include("../src/load_prefs.php");
20
21 function putSelectedMessagesIntoString($msg) {
22 $j = 0;
23 $i = 0;
24 $firstLoop = true;
25
26 // If they have selected nothing msg is size one still, but will
27 // be an infinite loop because we never increment j. so check to
28 // see if msg[0] is set or not to fix this.
29 while (($j < count($msg)) && ($msg[0])) {
30 if ($msg[$i]) {
31 if ($firstLoop != true)
32 $selectedMessages .= "&";
33 else
34 $firstLoop = false;
35
36 $selectedMessages .= "selMsg[$j]=$msg[$i]";
37
38 $j++;
39 }
40 $i++;
41 }
42 }
43
44 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
45 sqimap_mailbox_select($imapConnection, $mailbox);
46
47 // expunge-on-demand if user isn't using move_to_trash or auto_expunge
48 if(isset($expungeButton)) {
49 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
50 $location = get_location();
51 if ($where && $what)
52 header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
53 else
54 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
55 }
56 // undelete messages if user isn't using move_to_trash or auto_expunge
57 elseif(isset($undeleteButton)) {
58 if (is_array($msg) == 1) {
59 // Removes \Deleted flag from selected messages
60 $j = 0;
61 $i = 0;
62
63 // If they have selected nothing msg is size one still, but will be an infinite
64 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
65 while ($j < count($msg)) {
66 if ($msg[$i]) {
67 sqimap_messages_remove_flag ($imapConnection, $msg[$i], $msg[$i], "Deleted");
68 $j++;
69 }
70 $i++;
71 }
72 $location = get_location();
73
74 if ($where && $what)
75 header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
76 else
77 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
78 } else {
79 displayPageHeader($color, $mailbox);
80 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
81 }
82 }
83 // If the delete button was pressed, the moveButton variable will not be set.
84 elseif (!isset($moveButton)) {
85 if (is_array($msg) == 1) {
86 // Marks the selected messages as 'Deleted'
87 $j = 0;
88 $i = 0;
89
90 // If they have selected nothing msg is size one still, but will be an infinite
91 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
92 while ($j < count($msg)) {
93 if (isset($msg[$i])) {
94 sqimap_messages_delete($imapConnection, $msg[$i], $msg[$i], $mailbox);
95 $j++;
96 }
97 $i++;
98 }
99 if ($auto_expunge) {
100 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
101 }
102 $location = get_location();
103 if (isset($where) && isset($what))
104 header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
105 else
106 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
107 } else {
108 displayPageHeader($color, $mailbox);
109 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
110 }
111 } else { // Move messages
112 // lets check to see if they selected any messages
113 if (is_array($msg) == 1) {
114 $j = 0;
115 $i = 0;
116
117 // If they have selected nothing msg is size one still, but will be an infinite
118 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
119 while ($j < count($msg)) {
120 if (isset($msg[$i])) {
121 /** check if they would like to move it to the trash folder or not */
122 sqimap_messages_copy($imapConnection, $msg[$i], $msg[$i], $targetMailbox);
123 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Deleted");
124 $j++;
125 }
126 $i++;
127 }
128 if ($auto_expunge == true)
129 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
130
131 $location = get_location();
132 if (isset($where) && isset($what))
133 header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
134 else
135 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
136 } else {
137 displayPageHeader($color, $mailbox);
138 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
139 }
140 }
141
142 // Log out this session
143 sqimap_logout($imapConnection);
144
145 ?>
146 </BODY></HTML>