Session save part 2
[squirrelmail.git] / src / move_messages.php
1 <?php
2
3 /**
4 * move_messages.php
5 *
6 * Copyright (c) 1999-2002 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 /*****************************************************************/
15 /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
16 /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
17 /*** + Base level indent should begin at left margin, as ***/
18 /*** the require_once below looks. ***/
19 /*** + All identation should consist of four space blocks ***/
20 /*** + Tab characters are evil. ***/
21 /*** + all comments should use "slash-star ... star-slash" ***/
22 /*** style -- no pound characters, no slash-slash style ***/
23 /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
24 /*** ALWAYS USE { AND } CHARACTERS!!! ***/
25 /*** + Please use ' instead of ", when possible. Note " ***/
26 /*** should always be used in _( ) function calls. ***/
27 /*** Thank you for your help making the SM code more readable. ***/
28 /*****************************************************************/
29
30 require_once('../src/validate.php');
31 require_once('../functions/display_messages.php');
32 require_once('../functions/imap.php');
33
34 function putSelectedMessagesIntoString($msg) {
35 $j = 0;
36 $i = 0;
37 $firstLoop = true;
38
39 // If they have selected nothing msg is size one still, but will
40 // be an infinite loop because we never increment j. so check to
41 // see if msg[0] is set or not to fix this.
42 while (($j < count($msg)) && ($msg[0])) {
43 if ($msg[$i]) {
44 if ($firstLoop != true)
45 $selectedMessages .= "&";
46 else
47 $firstLoop = false;
48
49 $selectedMessages .= "selMsg[$j]=$msg[$i]";
50
51 $j++;
52 }
53 $i++;
54 }
55 }
56
57 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
58 sqimap_mailbox_select($imapConnection, $mailbox);
59
60 // expunge-on-demand if user isn't using move_to_trash or auto_expunge
61 if(isset($expungeButton)) {
62 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
63 $location = get_location();
64 if ($where && $what)
65 header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
66 else
67 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
68 }
69 // undelete messages if user isn't using move_to_trash or auto_expunge
70 elseif(isset($undeleteButton)) {
71 if (is_array($msg) == 1) {
72 // Removes \Deleted flag from selected messages
73 $j = 0;
74 $i = 0;
75
76 // If they have selected nothing msg is size one still, but will be an infinite
77 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
78 while ($j < count($msg)) {
79 if ($msg[$i]) {
80 sqimap_messages_remove_flag ($imapConnection, $msg[$i], $msg[$i], "Deleted");
81 $j++;
82 }
83 $i++;
84 }
85 $location = get_location();
86
87 if ($where && $what)
88 header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
89 else
90 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
91 } else {
92 displayPageHeader($color, $mailbox);
93 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
94 }
95 }
96 // If the delete button was pressed, the moveButton variable will not be set.
97 elseif (!isset($moveButton)) {
98 if (is_array($msg) == 1) {
99 // Marks the selected messages as 'Deleted'
100 $j = 0;
101 $i = 0;
102
103 // If they have selected nothing msg is size one still, but will be an infinite
104 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
105 while ($j < count($msg)) {
106 if (isset($msg[$i])) {
107 if (isset($markRead)) {
108 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Seen");
109 } else if (isset($markUnread)) {
110 sqimap_messages_remove_flag($imapConnection, $msg[$i], $msg[$i], "Seen");
111 } else {
112 sqimap_messages_delete($imapConnection, $msg[$i], $msg[$i], $mailbox);
113 }
114 $j++;
115 }
116 $i++;
117 }
118 if ($auto_expunge) {
119 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
120 }
121 $location = get_location();
122 if (isset($where) && isset($what))
123 header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
124 else
125 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
126 } else {
127 displayPageHeader($color, $mailbox);
128 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
129 }
130 } else { // Move messages
131 // lets check to see if they selected any messages
132 if (is_array($msg) == 1) {
133 $j = 0;
134 $i = 0;
135
136 // If they have selected nothing msg is size one still, but will be an infinite
137 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
138 while ($j < count($msg)) {
139 if (isset($msg[$i])) {
140 /** check if they would like to move it to the trash folder or not */
141 sqimap_messages_copy($imapConnection, $msg[$i], $msg[$i], $targetMailbox);
142 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Deleted");
143 $j++;
144 }
145 $i++;
146 }
147 if ($auto_expunge == true)
148 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
149
150 $location = get_location();
151 if (isset($where) && isset($what))
152 header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
153 else
154 header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
155 } else {
156 displayPageHeader($color, $mailbox);
157 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
158 }
159 }
160
161 // Log out this session
162 sqimap_logout($imapConnection);
163
164 ?>
165 </BODY></HTML>