* Got bored and copied all the validate.php and define() stuff to 1.1
[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
f740c049 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");
d3cdb279 19 include("../src/load_prefs.php");
20
dd88d31f 21 function putSelectedMessagesIntoString($msg) {
05207a68 22 $j = 0;
23 $i = 0;
dd88d31f 24 $firstLoop = true;
2d7d3c2a 25
d068c0ec 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.
2d7d3c2a 29 while (($j < count($msg)) && ($msg[0])) {
05207a68 30 if ($msg[$i]) {
dd88d31f 31 if ($firstLoop != true)
32 $selectedMessages .= "&";
33 else
34 $firstLoop = false;
35
36 $selectedMessages .= "selMsg[$j]=$msg[$i]";
37
05207a68 38 $j++;
b40316f9 39 }
05207a68 40 $i++;
b40316f9 41 }
dd88d31f 42 }
e2370222 43
e1469126 44 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
813eba2f 45 sqimap_mailbox_select($imapConnection, $mailbox);
dd88d31f 46
f9b3e5d9 47 // expunge-on-demand if user isn't using move_to_trash or auto_expunge
245a6892 48 if(isset($expungeButton)) {
8cf653ad 49 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
f9b3e5d9 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
245a6892 57 elseif(isset($undeleteButton)) {
f9b3e5d9 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 }
dd88d31f 83 // If the delete button was pressed, the moveButton variable will not be set.
245a6892 84 elseif (!isset($moveButton)) {
dd88d31f 85 if (is_array($msg) == 1) {
f265cfe8 86 // Marks the selected messages as 'Deleted'
dd88d31f 87 $j = 0;
88 $i = 0;
2d7d3c2a 89
dd88d31f 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)) {
23fd3c8e 93 if (isset($msg[$i])) {
813eba2f 94 sqimap_messages_delete($imapConnection, $msg[$i], $msg[$i], $mailbox);
dd88d31f 95 $j++;
2d7d3c2a 96 }
dd88d31f 97 $i++;
2d7d3c2a 98 }
acaa9842 99 if ($auto_expunge) {
8cf653ad 100 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
acaa9842 101 }
1195c340 102 $location = get_location();
23fd3c8e 103 if (isset($where) && isset($what))
1809bad8 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));
dd88d31f 107 } else {
5479d709 108 displayPageHeader($color, $mailbox);
a6668eb2 109 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
dd88d31f 110 }
111 } else { // Move messages
dd88d31f 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)) {
23fd3c8e 120 if (isset($msg[$i])) {
dd88d31f 121 /** check if they would like to move it to the trash folder or not */
8b673ac1 122 sqimap_messages_copy($imapConnection, $msg[$i], $msg[$i], $targetMailbox);
123 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Deleted");
dd88d31f 124 $j++;
125 }
126 $i++;
127 }
128 if ($auto_expunge == true)
8cf653ad 129 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
de80e95e 130
1195c340 131 $location = get_location();
23fd3c8e 132 if (isset($where) && isset($what))
1809bad8 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));
dd88d31f 136 } else {
5479d709 137 displayPageHeader($color, $mailbox);
a6668eb2 138 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
2d7d3c2a 139 }
b40316f9 140 }
141
b40316f9 142 // Log out this session
813eba2f 143 sqimap_logout($imapConnection);
b40316f9 144
2aa12d5e 145?>
aa32c5e4 146</BODY></HTML>