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