- Create a generic function to empty a folder tree, thanks to
[squirrelmail.git] / src / delete_message.php
1 <?php
2
3 /**
4 * delete_message.php
5 *
6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Deletes a meesage from the IMAP server
10 *
11 * @version $Id$
12 * @package squirrelmail
13 */
14
15 /**
16 * Path for SquirrelMail required files.
17 * @ignore
18 */
19 define('SM_PATH','../');
20
21 /* SquirrelMail required files. */
22 require_once(SM_PATH . 'include/validate.php');
23 include_once(SM_PATH . 'functions/display_messages.php');
24 require_once(SM_PATH . 'functions/imap.php');
25
26 /* get globals */
27 sqgetGlobalVar('username', $username, SQ_SESSION);
28 sqgetGlobalVar('key', $key, SQ_COOKIE);
29 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
30
31 sqgetGlobalVar('message', $message, SQ_FORM);
32 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
33
34 sqgetGlobalVar('bypass_trash', $bypass_trash, SQ_FORM);
35
36 global $data_dir;
37 /* end globals */
38
39 /* get $compose_new_win */
40 $compose_new_win=getPref($data_dir,$username,'compose_new_win',0);
41
42 /**
43 * Script is used when draft is saved again or sent.
44 * browser should be redirected to compose.php (compose_new_win=1)
45 * or right_main.php
46 * Problem: drafts folder listing is not refreshed when
47 * compose_new_win=1.
48 */
49 if (sqGetGlobalVar('saved_draft', $tmp, SQ_GET)) {
50 $saved_draft = urlencode($tmp);
51 }
52 if (sqGetGlobalVar('mail_sent', $tmp, SQ_GET)) {
53 $mail_sent = urlencode($tmp);
54 }
55 /**
56 * Script is used in search page.
57 * browser should be redirected to search.php
58 * Is it really used in search page?
59 */
60 if (sqGetGlobalVar('where', $tmp, SQ_FORM)) {
61 $where = urlencode($tmp);
62 }
63 if (sqGetGlobalVar('what', $tmp, SQ_FORM)) {
64 $what = urlencode($tmp);
65 }
66 /**
67 * FIXME: which part of code uses it?
68 */
69 if (sqGetGlobalVar('sort', $tmp, SQ_FORM)) {
70 $sort = (int) $tmp;
71 }
72 if (sqGetGlobalVar('startMessage', $tmp, SQ_FORM)) {
73 $startMessage = (int) $tmp;
74 }
75
76 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
77
78 // FIXME: unchecked use of variables.
79 sqimap_mailbox_select($imapConnection, $mailbox);
80
81 // FIXME: unchecked use of variables.
82 sqimap_messages_delete($imapConnection, $message, $message, $mailbox,$bypass_trash);
83 if ($auto_expunge) {
84 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
85 }
86
87 $location = get_location();
88
89 /**
90 * FIXME: rg=on problems with $saved_drafts, $sent_mail, $where and $what
91 * FIXME: current version of squirrelmail contains only two
92 * delete_message.php calls. with saved_draft=yes (compose.php
93 * around line 360) and with mail_sent=yes (compose.php around line 434)
94 */
95 if (isset($saved_draft)) {
96 // process resumed and again saved draft
97 if ($compose_new_win == '1') {
98 header("Location: $location/compose.php?saved_draft=yes");
99 } else {
100 $draft_message = _("Draft Saved");
101 header("Location: $location/right_main.php?mailbox=" . urlencode($draft_folder) .
102 "&startMessage=1&note=".urlencode($draft_message));
103 }
104 } elseif (isset($mail_sent)) {
105 // process resumed and then sent draft
106 if ($compose_new_win == '1') {
107 header("Location: $location/compose.php?mail_sent=yes");
108 } else {
109 $draft_message = _("Your Message has been sent.");
110 header("Location: $location/right_main.php?mailbox=" . urlencode($draft_folder) .
111 "&startMessage=1&note=".urlencode($draft_message));
112 }
113 } elseif (isset($where) && isset($what)) {
114 // FIXME: I suspect that part of code is obsolete
115 header("Location: $location/search.php?where=" . $where .
116 '&what=' . $what . '&mailbox=' . urlencode($mailbox));
117 } else {
118 header("Location: $location/right_main.php?startMessage=$startMessage&mailbox=" .
119 urlencode($mailbox));
120 }
121 sqimap_logout($imapConnection);
122 ?>