コード例 #1
0
ファイル: create.c プロジェクト: Distrotech/mailutils
/* FIXME: How do we do this ??????:
   IF a new mailbox is created with the same name as a mailbox which was
   deleted, its unique identifiers MUST be greater than any unique identifiers
   used in the previous incarnation of the mailbox.  */
int
imap4d_create (struct imap4d_session *session,
               struct imap4d_command *command, imap4d_tokbuf_t tok)
{
  char *name;
  int isdir = 0;
  int ns;
  int rc = RESP_OK;
  const char *msg = "Completed";

  if (imap4d_tokbuf_argc (tok) != 3)
    return io_completion_response (command, RESP_BAD, "Invalid arguments");

  name = imap4d_tokbuf_getarg (tok, IMAP4_ARG_1);

  if (*name == '\0')
    return io_completion_response (command, RESP_BAD, "Too few arguments");

  /* Creating, "Inbox" should always fail.  */
  if (mu_c_strcasecmp (name, "INBOX") == 0)
    return io_completion_response (command, RESP_BAD, "Already exist");

  /* RFC 3501:
         If the mailbox name is suffixed with the server's hierarchy
	 separator character, this is a declaration that the client intends
	 to create mailbox names under this name in the hierarchy.

     The trailing delimiter will be removed by namespace normalizer, so
     test for it now.
  */
  if (name[strlen (name) - 1] == MU_HIERARCHY_DELIMITER)
    isdir = 1;
  
  /* Allocates memory.  */
  name = namespace_getfullpath (name, &ns);

  if (!name)
    return io_completion_response (command, RESP_NO, "Cannot create mailbox");

  /* It will fail if the mailbox already exists.  */
  if (access (name, F_OK) != 0)
    {
      if (make_interdir (name, MU_HIERARCHY_DELIMITER, MKDIR_PERMISSIONS))
	{
	  rc = RESP_NO;
	  msg = "Cannot create mailbox";
	}
      
      if (rc == RESP_OK && !isdir)
	{
	  mu_mailbox_t mbox;
	  
	  rc = mu_mailbox_create_default (&mbox, name);
	  if (rc)
	    {
	      mu_diag_output (MU_DIAG_ERR,
			      _("Cannot create mailbox %s: %s"), name,
			      mu_strerror (rc));
	      rc = RESP_NO;
	      msg = "Cannot create mailbox";
	    }
	  else if ((rc = mu_mailbox_open (mbox,
					  MU_STREAM_RDWR | MU_STREAM_CREAT
					  | mailbox_mode[ns])))
	    {
	      mu_diag_output (MU_DIAG_ERR,
			      _("Cannot open mailbox %s: %s"),
			      name, mu_strerror (rc));
	      rc = RESP_NO;
	      msg = "Cannot create mailbox";
	    }
	  else
	    {
	      mu_mailbox_close (mbox);
	      mu_mailbox_destroy (&mbox);
	      rc = RESP_OK;
	    }
	}
    }
  else
    {
      rc = RESP_NO;
      msg = "already exists";
    }

  return io_completion_response (command, rc, "%s", msg);
}
コード例 #2
0
ファイル: select.c プロジェクト: aleeehaider825/hachi-roku
/* 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;
}