/***********************************************************************
 *
 * imap_perform_custom()
 *
 * Redirects a custom command to the corresponding imap_perform function.
 */
static CURLcode imap_perform_custom(struct connectdata *conn)
{
  CURLcode result = CURLE_OK;
  struct SessionHandle *data = conn->data;
  struct IMAP *imap = data->req.protop;
  char *mailbox;
  char *cmd = NULL;

  /* IMAP commands come in plain and UID variants. */
  if(Curl_raw_nequal(imap->custom, "UID", strlen("UID"))) {
    /* The actual command is in imap->custom_params */
    for(cmd = imap->custom_params; cmd && '\0' != *cmd; cmd++) {
      if((65 <= *cmd && 90 >= *cmd) ||
         (97 <= *cmd && 122 >= *cmd))
        break;
    }
  }
  else 
    cmd = imap->custom;

  result = imap_sendf(conn, "%s%s", imap->custom,
                      imap->custom_params ? imap->custom_params : "");

  if(!result) {
    if(Curl_raw_nequal(cmd, "LIST", strlen("LIST")))
      state(conn, IMAP_LIST);
    if (Curl_raw_nequal(cmd, "SELECT", strlen("SELECT")))
      state(conn, IMAP_SELECT);
    if (Curl_raw_nequal(cmd, "FETCH", strlen("FETCH")))
      state(conn, IMAP_FETCH);
    if (Curl_raw_nequal(cmd, "APPEND", strlen("APPEND")))
      state(conn, IMAP_APPEND);
    if (Curl_raw_nequal(cmd, "SEARCH", strlen("SEARCH")))
      state(conn, IMAP_SEARCH);
  }

  return result;
}

