summaryrefslogtreecommitdiffabout
path: root/kmicromail/libetpan/imap/mailimap.c
authorzautrix <zautrix>2004-09-01 10:23:29 (UTC)
committer zautrix <zautrix>2004-09-01 10:23:29 (UTC)
commit6cefbdc9c8f3f3001373f10715361e2740c45395 (patch) (side-by-side diff)
treecb2c36f57620e698913c27ca4ebe59e4a7c9d46e /kmicromail/libetpan/imap/mailimap.c
parentb9257cb225cd29bab5d96fcdaf557926603ee587 (diff)
downloadkdepimpi-6cefbdc9c8f3f3001373f10715361e2740c45395.zip
kdepimpi-6cefbdc9c8f3f3001373f10715361e2740c45395.tar.gz
kdepimpi-6cefbdc9c8f3f3001373f10715361e2740c45395.tar.bz2
Mail fixes and libetpan updated
Diffstat (limited to 'kmicromail/libetpan/imap/mailimap.c') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libetpan/imap/mailimap.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/kmicromail/libetpan/imap/mailimap.c b/kmicromail/libetpan/imap/mailimap.c
index c8fbfee..76d9454 100644
--- a/kmicromail/libetpan/imap/mailimap.c
+++ b/kmicromail/libetpan/imap/mailimap.c
@@ -1142,1020 +1142,1020 @@ int mailimap_create(mailimap * session, const char * mb)
return MAILIMAP_ERROR_CREATE;
}
}
int mailimap_delete(mailimap * session, const char * mb)
{
struct mailimap_response * response;
int r;
int error_code;
if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) &&
(session->imap_state != MAILIMAP_STATE_SELECTED))
return MAILIMAP_ERROR_BAD_STATE;
r = send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_delete_send(session->imap_stream, mb);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_crlf_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
r = parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
return MAILIMAP_ERROR_DELETE;
}
}
int mailimap_examine(mailimap * session, const char * mb)
{
struct mailimap_response * response;
int r;
int error_code;
if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) &&
(session->imap_state != MAILIMAP_STATE_SELECTED))
return MAILIMAP_ERROR_BAD_STATE;
r = send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_examine_send(session->imap_stream, mb);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_crlf_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
if (session->imap_selection_info != NULL)
mailimap_selection_info_free(session->imap_selection_info);
session->imap_selection_info = mailimap_selection_info_new();
r = parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
session->imap_state = MAILIMAP_STATE_SELECTED;
return MAILIMAP_NO_ERROR;
default:
mailimap_selection_info_free(session->imap_selection_info);
session->imap_selection_info = NULL;
session->imap_state = MAILIMAP_STATE_AUTHENTICATED;
return MAILIMAP_ERROR_EXAMINE;
}
}
int
mailimap_fetch(mailimap * session, struct mailimap_set * set,
struct mailimap_fetch_type * fetch_type, clist ** result)
{
struct mailimap_response * response;
int r;
int error_code;
if (session->imap_state != MAILIMAP_STATE_SELECTED)
return MAILIMAP_ERROR_BAD_STATE;
r = send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_fetch_send(session->imap_stream, set, fetch_type);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_crlf_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
r = parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
* result = session->imap_response_info->rsp_fetch_list;
session->imap_response_info->rsp_fetch_list = NULL;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
return MAILIMAP_ERROR_FETCH;
}
}
void mailimap_fetch_list_free(clist * fetch_list)
{
clist_foreach(fetch_list, (clist_func) mailimap_msg_att_free, NULL);
clist_free(fetch_list);
}
int
mailimap_uid_fetch(mailimap * session,
struct mailimap_set * set,
struct mailimap_fetch_type * fetch_type, clist ** result)
{
struct mailimap_response * response;
int r;
int error_code;
if (session->imap_state != MAILIMAP_STATE_SELECTED)
return MAILIMAP_ERROR_BAD_STATE;
r = send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_uid_fetch_send(session->imap_stream, set, fetch_type);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_crlf_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
r = parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
* result = session->imap_response_info->rsp_fetch_list;
session->imap_response_info->rsp_fetch_list = NULL;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
return MAILIMAP_ERROR_UID_FETCH;
}
}
int mailimap_list(mailimap * session, const char * mb,
const char * list_mb, clist ** result)
{
struct mailimap_response * response;
int r;
int error_code;
if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) &&
(session->imap_state != MAILIMAP_STATE_SELECTED))
return MAILIMAP_ERROR_BAD_STATE;
r = send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_list_send(session->imap_stream, mb, list_mb);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_crlf_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
r = parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
* result = session->imap_response_info->rsp_mailbox_list;
session->imap_response_info->rsp_mailbox_list = NULL;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
return MAILIMAP_ERROR_LIST;
}
}
int mailimap_login(mailimap * session,
const char * userid, const char * password)
{
struct mailimap_response * response;
int r;
int error_code;
if (session->imap_state != MAILIMAP_STATE_NON_AUTHENTICATED)
return MAILIMAP_ERROR_BAD_STATE;
r = send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_login_send(session->imap_stream, userid, password);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_crlf_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
r = parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
session->imap_state = MAILIMAP_STATE_AUTHENTICATED;
return MAILIMAP_NO_ERROR;
default:
return MAILIMAP_ERROR_LOGIN;
}
}
int mailimap_lsub(mailimap * session, const char * mb,
const char * list_mb, clist ** result)
{
struct mailimap_response * response;
int r;
int error_code;
if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) &&
(session->imap_state != MAILIMAP_STATE_SELECTED))
return MAILIMAP_ERROR_BAD_STATE;
r = send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_lsub_send(session->imap_stream, mb, list_mb);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_crlf_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
r = parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
* result = session->imap_response_info->rsp_mailbox_lsub;
session->imap_response_info->rsp_mailbox_lsub = NULL;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
return MAILIMAP_ERROR_LSUB;
}
}
void mailimap_list_result_free(clist * list)
{
clist_foreach(list, (clist_func) mailimap_mailbox_list_free, NULL);
clist_free(list);
}
int mailimap_rename(mailimap * session,
const char * mb, const char * new_name)
{
struct mailimap_response * response;
int r;
int error_code;
if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) &&
(session->imap_state != MAILIMAP_STATE_SELECTED))
return MAILIMAP_ERROR_BAD_STATE;
r = send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_rename_send(session->imap_stream, mb, new_name);
if (r != MAILIMAP_NO_ERROR)
return r;
if (!mailimap_crlf_send(session->imap_stream))
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
r = parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
return MAILIMAP_ERROR_RENAME;
}
}
int
mailimap_search(mailimap * session, const char * charset,
struct mailimap_search_key * key, clist ** result)
{
struct mailimap_response * response;
int r;
int error_code;
if (session->imap_state != MAILIMAP_STATE_SELECTED)
return MAILIMAP_ERROR_BAD_STATE;
r = send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_search_send(session->imap_stream, charset, key);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_crlf_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
r = parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
* result = session->imap_response_info->rsp_search_result;
session->imap_response_info->rsp_search_result = NULL;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
return MAILIMAP_ERROR_SEARCH;
}
}
int
mailimap_uid_search(mailimap * session, const char * charset,
struct mailimap_search_key * key, clist ** result)
{
struct mailimap_response * response;
int r;
int error_code;
if (session->imap_state != MAILIMAP_STATE_SELECTED)
return MAILIMAP_ERROR_BAD_STATE;
r = send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_uid_search_send(session->imap_stream, charset, key);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_crlf_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
r = parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
* result = session->imap_response_info->rsp_search_result;
session->imap_response_info->rsp_search_result = NULL;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
return MAILIMAP_ERROR_UID_SEARCH;
}
}
void mailimap_search_result_free(clist * search_result)
{
clist_foreach(search_result, (clist_func) free, NULL);
clist_free(search_result);
}
int
mailimap_select(mailimap * session, const char * mb)
{
struct mailimap_response * response;
int r;
int error_code;
if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) &&
(session->imap_state != MAILIMAP_STATE_SELECTED))
return MAILIMAP_ERROR_BAD_STATE;
r = send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_select_send(session->imap_stream, mb);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_crlf_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
if (session->imap_selection_info != NULL)
mailimap_selection_info_free(session->imap_selection_info);
session->imap_selection_info = mailimap_selection_info_new();
r = parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
session->imap_state = MAILIMAP_STATE_SELECTED;
return MAILIMAP_NO_ERROR;
default:
mailimap_selection_info_free(session->imap_selection_info);
session->imap_selection_info = NULL;
session->imap_state = MAILIMAP_STATE_AUTHENTICATED;
return MAILIMAP_ERROR_SELECT;
}
}
int
mailimap_status(mailimap * session, const char * mb,
struct mailimap_status_att_list * status_att_list,
struct mailimap_mailbox_data_status ** result)
{
struct mailimap_response * response;
int r;
int error_code;
if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) &&
(session->imap_state != MAILIMAP_STATE_SELECTED))
return MAILIMAP_ERROR_BAD_STATE;
r = send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_status_send(session->imap_stream, mb, status_att_list);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_crlf_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
r = parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
* result = session->imap_response_info->rsp_status;
session->imap_response_info->rsp_status = NULL;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
return MAILIMAP_ERROR_STATUS;
}
}
int
mailimap_store(mailimap * session,
struct mailimap_set * set,
struct mailimap_store_att_flags * store_att_flags)
{
struct mailimap_response * response;
int r;
int error_code;
if (session->imap_state != MAILIMAP_STATE_SELECTED)
return MAILIMAP_ERROR_BAD_STATE;
r = send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_store_send(session->imap_stream, set, store_att_flags);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_crlf_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
r = parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
return MAILIMAP_ERROR_STORE;
}
}
int
mailimap_uid_store(mailimap * session,
struct mailimap_set * set,
struct mailimap_store_att_flags * store_att_flags)
{
struct mailimap_response * response;
int r;
int error_code;
if (session->imap_state != MAILIMAP_STATE_SELECTED)
return MAILIMAP_ERROR_BAD_STATE;
r = send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_uid_store_send(session->imap_stream, set, store_att_flags);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_crlf_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
r = parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
return MAILIMAP_ERROR_UID_STORE;
}
}
int mailimap_subscribe(mailimap * session, const char * mb)
{
struct mailimap_response * response;
int r;
int error_code;
if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) &&
(session->imap_state != MAILIMAP_STATE_SELECTED))
return MAILIMAP_ERROR_BAD_STATE;
r = send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_subscribe_send(session->imap_stream, mb);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_crlf_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
r = parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
return MAILIMAP_ERROR_SUBSCRIBE;
}
}
int mailimap_unsubscribe(mailimap * session, const char * mb)
{
struct mailimap_response * response;
int r;
int error_code;
if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) &&
(session->imap_state != MAILIMAP_STATE_SELECTED))
return MAILIMAP_ERROR_BAD_STATE;
r = send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
- r = mailimap_subscribe_send(session->imap_stream, mb);
+ r = mailimap_unsubscribe_send(session->imap_stream, mb);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_crlf_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
r = parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
return MAILIMAP_ERROR_UNSUBSCRIBE;
}
}
int mailimap_starttls(mailimap * session)
{
struct mailimap_response * response;
int r;
int error_code;
r = send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_starttls_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_crlf_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
r = parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
return MAILIMAP_ERROR_STARTTLS;
}
}
static char * read_line(mailimap * session)
{
return mailstream_read_line(session->imap_stream, session->imap_stream_buffer);
}
static int send_current_tag(mailimap * session)
{
char tag_str[15];
int r;
session->imap_tag ++;
snprintf(tag_str, 15, "%i", session->imap_tag);
r = mailimap_tag_send(session->imap_stream, tag_str);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_space_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
return MAILIMAP_NO_ERROR;
}
static int parse_response(mailimap * session,
struct mailimap_response ** result)
{
size_t index;
struct mailimap_response * response;
char tag_str[15];
int r;
index = 0;
session->imap_response = NULL;
r = mailimap_response_parse(session->imap_stream,
session->imap_stream_buffer,
&index, &response,
session->imap_progr_rate, session->imap_progr_fun);
if (r != MAILIMAP_NO_ERROR)
return r;
#if 0
mailimap_response_print(response);
#endif
response_store(session, response);
if (mmap_string_assign(session->imap_response_buffer,
response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_text->rsp_text)
== NULL)
return MAILIMAP_ERROR_MEMORY;
session->imap_response = session->imap_response_buffer->str;
if (response->rsp_resp_done->rsp_type == MAILIMAP_RESP_DONE_TYPE_FATAL)
return MAILIMAP_ERROR_FATAL;
snprintf(tag_str, 15, "%i", session->imap_tag);
if (strcmp(response->rsp_resp_done->rsp_data.rsp_tagged->rsp_tag, tag_str) != 0)
return MAILIMAP_ERROR_PROTOCOL;
if (response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type ==
MAILIMAP_RESP_COND_STATE_BAD)
return MAILIMAP_ERROR_PROTOCOL;
* result = response;
return MAILIMAP_NO_ERROR;
}
static int parse_greeting(mailimap * session,
struct mailimap_greeting ** result)
{
size_t index;
struct mailimap_greeting * greeting;
int r;
index = 0;
session->imap_response = NULL;
r = mailimap_greeting_parse(session->imap_stream,
session->imap_stream_buffer,
&index, &greeting, session->imap_progr_rate,
session->imap_progr_fun);
if (r != MAILIMAP_NO_ERROR)
return r;
#if 0
mailimap_greeting_print(greeting);
#endif
greeting_store(session, greeting);
if (greeting->gr_type == MAILIMAP_GREETING_RESP_COND_BYE) {
if (mmap_string_assign(session->imap_response_buffer,
greeting->gr_data.gr_bye->rsp_text->rsp_text) == NULL)
return MAILIMAP_ERROR_MEMORY;
session->imap_response = session->imap_response_buffer->str;
return MAILIMAP_ERROR_DONT_ACCEPT_CONNECTION;
}
if (mmap_string_assign(session->imap_response_buffer,
greeting->gr_data.gr_auth->rsp_text->rsp_text) == NULL)
return MAILIMAP_ERROR_MEMORY;
session->imap_response = session->imap_response_buffer->str;
* result = greeting;
return MAILIMAP_NO_ERROR;
}
mailimap * mailimap_new(size_t imap_progr_rate,
progress_function * imap_progr_fun)
{
mailimap * f;
f = malloc(sizeof(* f));
if (f == NULL)
goto err;
f->imap_response = NULL;
f->imap_stream = NULL;
f->imap_progr_rate = imap_progr_rate;
f->imap_progr_fun = imap_progr_fun;
f->imap_stream_buffer = mmap_string_new("");
if (f->imap_stream_buffer == NULL)
goto free_f;
f->imap_response_buffer = mmap_string_new("");
if (f->imap_response_buffer == NULL)
goto free_stream_buffer;
f->imap_state = MAILIMAP_STATE_DISCONNECTED;
f->imap_tag = 0;
f->imap_selection_info = NULL;
f->imap_response_info = NULL;
f->imap_connection_info = NULL;
return f;
free_stream_buffer:
mmap_string_free(f->imap_stream_buffer);
free_f:
free(f);
err:
return NULL;
}
void mailimap_free(mailimap * session)
{
if (session->imap_stream)
mailimap_logout(session);
mmap_string_free(session->imap_response_buffer);
mmap_string_free(session->imap_stream_buffer);
if (session->imap_response_info)
mailimap_response_info_free(session->imap_response_info);
if (session->imap_selection_info)
mailimap_selection_info_free(session->imap_selection_info);
if (session->imap_connection_info)
mailimap_connection_info_free(session->imap_connection_info);
free(session);
}