コード例 #1
0
ファイル: curl_imap.c プロジェクト: fquinto/curl
/* For the initial server greeting */
static CURLcode imap_state_servergreet_resp(struct connectdata *conn,
                                            int imapcode,
                                            imapstate instate)
{
  CURLcode result = CURLE_OK;
  struct SessionHandle *data = conn->data;

  (void)instate; /* no use for this yet */

  if(imapcode != 'O') {
    failf(data, "Got unexpected imap-server response");
    return CURLE_FTP_WEIRD_SERVER_REPLY;
  }

  if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) {
    /* We don't have a SSL/TLS connection yet, but SSL is requested. Switch
       to TLS connection now */
    const char *str = getcmdid(conn);
    result = imap_sendf(conn, str, "%s STARTTLS", str);
    state(conn, IMAP_STARTTLS);
  }
  else
    result = imap_state_login(conn);

  return result;
}
コード例 #2
0
ファイル: imap.c プロジェクト: arsenm/curl
static CURLcode imap_state_capability(struct connectdata *conn)
{
  CURLcode result = CURLE_OK;
  struct imap_conn *imapc = &conn->proto.imapc;
  const char *str;

  imapc->authmechs = 0;         /* No known authentication mechanisms yet */
  imapc->authused = 0;          /* Clear the authentication mechanism used */

  /* Check we have a username and password to authenticate with and end the
     connect phase if we don't */
  if(!conn->bits.user_passwd) {
    state(conn, IMAP_STOP);

    return result;
  }

  str = getcmdid(conn);

  /* Send the CAPABILITY command */
  result = imap_sendf(conn, str, "%s CAPABILITY", str);

  if(result)
    return result;

  state(conn, IMAP_CAPABILITY);

  return CURLE_OK;
}
コード例 #3
0
ファイル: imap.c プロジェクト: arsenm/curl
static CURLcode imap_authenticate(struct connectdata *conn)
{
  CURLcode result = CURLE_OK;
  struct imap_conn *imapc = &conn->proto.imapc;
  const char *mech = NULL;
  imapstate authstate = IMAP_STOP;

  /* Check supported authentication mechanisms by decreasing order of
     security */
#ifndef CURL_DISABLE_CRYPTO_AUTH
  if(imapc->authmechs & SASL_MECH_DIGEST_MD5) {
    mech = "DIGEST-MD5";
    authstate = IMAP_AUTHENTICATE_DIGESTMD5;
    imapc->authused = SASL_MECH_DIGEST_MD5;
  }
  else if(imapc->authmechs & SASL_MECH_CRAM_MD5) {
    mech = "CRAM-MD5";
    authstate = IMAP_AUTHENTICATE_CRAMMD5;
    imapc->authused = SASL_MECH_CRAM_MD5;
  }
  else
#endif
#ifdef USE_NTLM
  if(imapc->authmechs & SASL_MECH_NTLM) {
    mech = "NTLM";
    authstate = IMAP_AUTHENTICATE_NTLM;
    imapc->authused = SASL_MECH_NTLM;
  }
  else
#endif
  if(imapc->authmechs & SASL_MECH_LOGIN) {
    mech = "LOGIN";
    authstate = IMAP_AUTHENTICATE_LOGIN;
    imapc->authused = SASL_MECH_LOGIN;
  }
  else if(imapc->authmechs & SASL_MECH_PLAIN) {
    mech = "PLAIN";
    authstate = IMAP_AUTHENTICATE_PLAIN;
    imapc->authused = SASL_MECH_PLAIN;
  }
  else {
    infof(conn->data, "No known authentication mechanisms supported!\n");
    result = CURLE_LOGIN_DENIED; /* Other mechanisms not supported */
  }

  if(!result) {
    const char *str = getcmdid(conn);

    result = imap_sendf(conn, str, "%s AUTHENTICATE %s", str, mech);

    if(!result)
      state(conn, authstate);
  }

  return result;
}
コード例 #4
0
ファイル: curl_imap.c プロジェクト: fquinto/curl
/***********************************************************************
 *
 * imap_logout()
 *
 * This should be called before calling sclose().  We should then wait for the
 * response from the server before returning. The calling code should then try
 * to close the connection.
 *
 */
static CURLcode imap_logout(struct connectdata *conn)
{
  CURLcode result = CURLE_OK;
  const char *str = getcmdid(conn);

  result = imap_sendf(conn, str, "%s LOGOUT", str, NULL);
  if(result)
    return result;

  state(conn, IMAP_LOGOUT);

  result = imap_easy_statemach(conn);

  return result;
}
コード例 #5
0
ファイル: curl_imap.c プロジェクト: fquinto/curl
/* Start the DO phase */
static CURLcode imap_select(struct connectdata *conn)
{
  CURLcode result = CURLE_OK;
  struct imap_conn *imapc = &conn->proto.imapc;
  const char *str = getcmdid(conn);

  result = imap_sendf(conn, str, "%s SELECT %s", str,
                      imapc->mailbox?imapc->mailbox:"");
  if(result)
    return result;

  state(conn, IMAP_SELECT);

  return result;
}
コード例 #6
0
ファイル: curl_imap.c プロジェクト: fquinto/curl
static CURLcode imap_state_login(struct connectdata *conn)
{
  CURLcode result;
  struct FTP *imap = conn->data->state.proto.imap;
  const char *str = getcmdid(conn);
  char *user = imap_atom(imap->user);
  char *passwd = imap_atom(imap->passwd);

  /* send USER and password */
  result = imap_sendf(conn, str, "%s LOGIN %s %s", str,
                      user ? user : "", passwd ? passwd : "");

  Curl_safefree(user);
  Curl_safefree(passwd);

  if(result)
    return result;

  state(conn, IMAP_LOGIN);

  return CURLE_OK;
}
コード例 #7
0
ファイル: curl_imap.c プロジェクト: fquinto/curl
static CURLcode imap_fetch(struct connectdata *conn)
{
  CURLcode result = CURLE_OK;
  const char *str = getcmdid(conn);

  /* TODO: make this select the correct mail
   * Use "1 body[text]" to get the full mail body of mail 1
   */
  result = imap_sendf(conn, str, "%s FETCH 1 BODY[TEXT]", str);
  if(result)
    return result;

  /*
   * When issued, the server will respond with a single line similar to
   * '* 1 FETCH (BODY[TEXT] {2021}'
   *
   * Identifying the fetch and how many bytes of contents we can expect. We
   * must extract that number before continuing to "download as usual".
   */

  state(conn, IMAP_FETCH);

  return result;
}