static int imap4d_close0 (struct imap4d_command *command, imap4d_tokbuf_t tok, int expunge) { const char *msg = NULL; int status, flags; if (imap4d_tokbuf_argc (tok) != 2) return io_completion_response (command, RESP_BAD, "Invalid arguments"); mu_mailbox_get_flags (mbox, &flags); if (flags & MU_STREAM_WRITE) { silent_expunge = expunge; imap4d_enter_critical (); status = mu_mailbox_flush (mbox, expunge); imap4d_leave_critical (); silent_expunge = 0; if (status) { mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_flush", NULL, status); msg = "flushing mailbox failed"; } } /* No messages are removed, and no error is given, if the mailbox is selected by an EXAMINE command or is otherwise selected read-only. */ imap4d_enter_critical (); status = mu_mailbox_close (mbox); imap4d_leave_critical (); if (status) { mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_close", NULL, status); msg = "closing mailbox failed"; } manlock_unlock (mbox); mu_mailbox_destroy (&mbox); if (msg) return io_completion_response (command, RESP_NO, "%s", msg); return io_completion_response (command, RESP_OK, "Completed"); }
/* This code is shared with EXAMINE. */ int imap4d_select0 (struct imap4d_command *command, const char *mboxname, int flags) { int status; char *mailbox_name; /* FIXME: Check state. */ /* Even if a mailbox is selected, a SELECT EXAMINE or LOGOUT command MAY be issued without previously issuing a CLOSE command. The SELECT, EXAMINE, and LOGUT commands implictly close the currently selected mailbox without doing an expunge. */ if (mbox) { imap4d_enter_critical (); mu_mailbox_sync (mbox); mu_mailbox_close (mbox); manlock_unlock (mbox); imap4d_leave_critical (); mu_mailbox_destroy (&mbox); /* Destroy the old uid table. */ imap4d_sync (); } if (strcmp (mboxname, "INBOX") == 0) flags |= MU_STREAM_CREAT; mailbox_name = namespace_getfullpath (mboxname, NULL); if (!mailbox_name) return io_completion_response (command, RESP_NO, "Couldn't open mailbox"); if (flags & MU_STREAM_RDWR) { status = manlock_open_mailbox (&mbox, mailbox_name, 1, flags); } else { status = mu_mailbox_create_default (&mbox, mailbox_name); if (status) mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_create_default", mailbox_name, status); else { status = mu_mailbox_open (mbox, flags); if (status) { mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_open", mailbox_name, status); mu_mailbox_destroy (&mbox); } } } if (status == 0) { select_flags = flags; state = STATE_SEL; imap4d_set_observer (mbox); if ((status = imap4d_select_status ()) == 0) { free (mailbox_name); /* Need to set the state explicitely for select. */ return io_sendf ("%s OK [%s] %s Completed\n", command->tag, ((flags & MU_STREAM_RDWR) == MU_STREAM_RDWR) ? "READ-WRITE" : "READ-ONLY", command->name); } } mu_mailbox_destroy (&mbox); status = io_completion_response (command, RESP_NO, "Could not open %s: %s", mboxname, mu_strerror (status)); free (mailbox_name); return status; }