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