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