b208e39e7312c8ca53f76b5392bd4745f0c0bb30
[squirrelmail.git] / src / move_messages.php
1 <?php
2 session_start();
3
4 if (!isset($config_php))
5 include("../config/config.php");
6 if (!isset($strings_php))
7 include("../functions/strings.php");
8 if (!isset($page_header_php))
9 include("../functions/page_header.php");
10 if (!isset($display_messages_php))
11 include("../functions/display_messages.php");
12 if (!isset($imap_php))
13 include("../functions/imap.php");
14
15 include("../src/load_prefs.php");
16
17 function putSelectedMessagesIntoString($msg) {
18 $j = 0;
19 $i = 0;
20 $firstLoop = true;
21
22 // If they have selected nothing msg is size one still, but will
23 // be an infinite loop because we never increment j. so check to
24 // see if msg[0] is set or not to fix this.
25 while (($j < count($msg)) && ($msg[0])) {
26 if ($msg[$i]) {
27 if ($firstLoop != true)
28 $selectedMessages .= "&";
29 else
30 $firstLoop = false;
31
32 $selectedMessages .= "selMsg[$j]=$msg[$i]";
33
34 $j++;
35 }
36 $i++;
37 }
38 }
39
40 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
41 sqimap_mailbox_select($imapConnection, $mailbox);
42
43 // If the delete button was pressed, the moveButton variable will not be set.
44 if (!$moveButton) {
45 if (is_array($msg) == 1) {
46 // Marks the selected messages ad 'Deleted'
47 $j = 0;
48 $i = 0;
49
50 // If they have selected nothing msg is size one still, but will be an infinite
51 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
52 while ($j < count($msg)) {
53 if ($msg[$i]) {
54 sqimap_messages_delete($imapConnection, $msg[$i], $msg[$i], $mailbox);
55 $j++;
56 }
57 $i++;
58 }
59 if ($auto_expunge) {
60 sqimap_mailbox_expunge($imapConnection, $mailbox);
61 }
62 if ($auto_forward) {
63 header ("Location: right_main.php");
64 } else {
65 displayPageHeader($color, $mailbox);
66 messages_deleted_message($mailbox, $sort, $startMessage, $color);
67 }
68 } else {
69 displayPageHeader($color, $mailbox);
70 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
71 }
72 } else { // Move messages
73 // lets check to see if they selected any messages
74 if (is_array($msg) == 1) {
75 $j = 0;
76 $i = 0;
77
78 // If they have selected nothing msg is size one still, but will be an infinite
79 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
80 while ($j < count($msg)) {
81 if ($msg[$i]) {
82 /** check if they would like to move it to the trash folder or not */
83 sqimap_messages_copy($imapConnection, $msg[$i], $msg[$i], $targetMailbox);
84 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Deleted");
85 $j++;
86 }
87 $i++;
88 }
89 if ($auto_expunge == true)
90 sqimap_mailbox_expunge($imapConnection, $mailbox);
91
92 if ($auto_forward) {
93 header ("Location: right_main.php");
94 } else {
95 displayPageHeader($color, $mailbox);
96 messages_moved_message($mailbox, $sort, $startMessage, $color);
97 }
98 } else {
99 displayPageHeader($color, $mailbox);
100 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
101 }
102 }
103
104 // Log out this session
105 sqimap_logout($imapConnection);
106
107 ?>
108 </BODY></HTML>