workaround for php3 dealing with optional arguments to function loginToImapServer
[squirrelmail.git] / src / move_messages.php
1 <?
2 include("../config/config.php");
3 include("../functions/mailbox.php");
4 include("../functions/strings.php");
5 include("../functions/page_header.php");
6 include("../functions/display_messages.php");
7 include("../functions/imap.php");
8
9 include("../src/load_prefs.php");
10
11 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
12
13 function putSelectedMessagesIntoString($msg) {
14 $j = 0;
15 $i = 0;
16 $firstLoop = true;
17
18 // If they have selected nothing msg is size one still, but will be an infinite
19 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
20 while (($j < count($msg)) && ($msg[0])) {
21 if ($msg[$i]) {
22 if ($firstLoop != true)
23 $selectedMessages .= "&";
24 else
25 $firstLoop = false;
26
27 $selectedMessages .= "selMsg[$j]=$msg[$i]";
28
29 $j++;
30 }
31 $i++;
32 }
33 }
34
35 $imapConnection = loginToImapServer($username, $key, $imapServerAddress, 0);
36
37 // switch to the mailbox, and get the number of messages in it.
38 selectMailbox($imapConnection, $mailbox, $numMessages, $imapServerAddress);
39
40 // If the delete button was pressed, the moveButton variable will not be set.
41 if (!$moveButton) {
42 displayPageHeader($color, $mailbox);
43 if (is_array($msg) == 1) {
44 // Marks the selected messages ad 'Deleted'
45 $j = 0;
46 $i = 0;
47
48 // If they have selected nothing msg is size one still, but will be an infinite
49 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
50 while ($j < count($msg)) {
51 if ($msg[$i]) {
52 deleteMessages($imapConnection, $msg[$i], $msg[$i], $numMessages, $trash_folder, $move_to_trash, $auto_expunge, $mailbox);
53 $j++;
54 }
55 $i++;
56 }
57 messages_deleted_message($mailbox, $sort, $startMessage, $color);
58 } else {
59 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
60 }
61 } else { // Move messages
62 displayPageHeader($color, $mailbox);
63 // lets check to see if they selected any messages
64 if (is_array($msg) == 1) {
65 $j = 0;
66 $i = 0;
67
68 // If they have selected nothing msg is size one still, but will be an infinite
69 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
70 while ($j < count($msg)) {
71 if ($msg[$i]) {
72 /** check if they would like to move it to the trash folder or not */
73 $success = copyMessages($imapConnection, $msg[$i], $msg[$i], $targetMailbox);
74 if ($success == true)
75 setMessageFlag($imapConnection, $msg[$i], $msg[$i], "Deleted");
76 $j++;
77 }
78 $i++;
79 }
80 if ($auto_expunge == true)
81 expungeBox($imapConnection, $mailbox, $numMessages);
82
83 messages_moved_message($mailbox, $sort, $startMessage, $color);
84 } else {
85 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
86 }
87 }
88
89 // Log out this session
90 fputs($imapConnection, "1 logout");
91
92 ?>
93 </BODY></HTML>