]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/folders.inc
Imported Upstream version 0.3.1
[roundcube.git] / program / steps / mail / folders.inc
1 <?php
2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/mail/folders.inc                                        |
6  |                                                                       |
7  | This file is part of the RoundCube Webmail client                     |
8  | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland                 |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Implement folder operations line EXPUNGE and Clear                  |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
18  $Id: folders.inc 2959 2009-09-17 12:07:58Z alec $
19 */
20
21 // only process ajax requests
22 if (!$OUTPUT->ajax_call)
23   return;
24
25 $mbox_name = $IMAP->get_mailbox_name();
26
27 // send EXPUNGE command
28 if ($RCMAIL->action=='expunge' && ($mbox = get_input_value('_mbox', RCUBE_INPUT_POST)))
29 {
30   $success = $IMAP->expunge($mbox);
31
32   // reload message list if current mailbox  
33   if ($success && !empty($_REQUEST['_reload']))
34   {
35     $OUTPUT->command('message_list.clear');
36     $RCMAIL->action = 'list';
37     return;
38   }
39   else
40     $commands = "// expunged: $success\n";
41 }
42
43 // clear mailbox
44 else if ($RCMAIL->action=='purge' && ($mbox = get_input_value('_mbox', RCUBE_INPUT_POST)))
45 {
46   $delimiter = $IMAP->get_hierarchy_delimiter();
47   $trash_regexp = '/^' . preg_quote($CONFIG['trash_mbox'] . $delimiter, '/') . '/';
48   $junk_regexp = '/^' . preg_quote($CONFIG['junk_mbox'] . $delimiter, '/') . '/';                     
49
50   // we should only be purging trash and junk (or their subfolders)
51   if ($mbox == $CONFIG['trash_mbox'] || $mbox == $CONFIG['junk_mbox']
52     || preg_match($trash_regexp, $mbox) || preg_match($junk_regexp, $mbox))
53   {
54     $success = $IMAP->clear_mailbox($mbox);
55   
56     if ($success && !empty($_REQUEST['_reload']))
57     {
58       $OUTPUT->set_env('messagecount', 0);
59       $OUTPUT->set_env('pagecount', 0);
60       $OUTPUT->command('message_list.clear');
61       $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text());
62       $OUTPUT->command('set_unread_count', $mbox_name, 0);
63       $_SESSION['unseen_count'][$mbox_name] = 0;
64     }
65     else
66       $commands = "// purged: $success";
67   }
68 }
69
70 $OUTPUT->send($commands);
71
72 ?>