Blame view

imap4d/close.c 1.75 KB
1
/* GNU Mailutils -- a suite of utilities for electronic mail
2
   Copyright (C) 1999, 2001, 2004 Free Software Foundation, Inc.
Jakob Kaivo authored
3

4
   GNU Mailutils is free software; you can redistribute it and/or modify
Jakob Kaivo authored
5 6 7 8
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

9
   GNU Mailutils is distributed in the hope that it will be useful,
Jakob Kaivo authored
10 11 12 13 14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
15
   along with GNU Mailutils; if not, write to the Free Software
Wojciech Polak authored
16
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
Jakob Kaivo authored
17 18 19 20 21 22

#include "imap4d.h"

/*
 */

23 24 25
/* The CLOSE command permanently removes from the currently selected
   mailbox all messages that have the \\Deleted flag set, and returns
   to authenticated state from selected state.  */
Jakob Kaivo authored
26
int
27
imap4d_close (struct imap4d_command *command, char *arg ARG_UNUSED)
Jakob Kaivo authored
28
{
29 30 31 32 33 34 35 36 37
  const char *msg = NULL;
  int status = mailbox_flush (mbox, 1);
  if (status)
    {
      syslog (LOG_ERR, _("flushing mailbox failed: %s"), mu_strerror (status));
      msg = "flushing mailbox failed";
    }
  
  /* No messages are removed, and no error is given, if the mailbox is
38
     selected by an EXAMINE command or is otherwise selected read-only.  */
39 40 41 42 43 44
  status = mailbox_close (mbox);
  if (status)
    {
      syslog (LOG_ERR, _("closing mailbox failed: %s"), mu_strerror (status));
      msg = "closing mailbox failed";
    }
45
  mailbox_destroy (&mbox);
46 47 48

  if (msg)
    util_finish (command, RESP_NO, msg);
49
  return util_finish (command, RESP_OK, "Completed");
Jakob Kaivo authored
50
}