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