summaryrefslogtreecommitdiffabout
path: root/kmicromail/libetpan/imap
Side-by-side diff
Diffstat (limited to 'kmicromail/libetpan/imap') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libetpan/imap/mailimap.c2
-rw-r--r--kmicromail/libetpan/imap/mailimap_keywords.c2
2 files changed, 2 insertions, 2 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);
}
diff --git a/kmicromail/libetpan/imap/mailimap_keywords.c b/kmicromail/libetpan/imap/mailimap_keywords.c
index b277aed..4ec156e 100644
--- a/kmicromail/libetpan/imap/mailimap_keywords.c
+++ b/kmicromail/libetpan/imap/mailimap_keywords.c
@@ -1,353 +1,353 @@
/*
* libEtPan! -- a mail stuff library
*
* Copyright (C) 2001, 2002 - DINH Viet Hoa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the libEtPan! project nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* $Id$
*/
#include "mailimap_keywords.h"
#include "mailimap_types.h"
#include <string.h>
#include <stdio.h>
#ifndef UNSTRICT_SYNTAX
#define UNSTRICT_SYNTAX
#endif
struct mailimap_token_value {
int value;
const char * str;
};
int mailimap_token_case_insensitive_parse(mailstream * fd,
MMAPString * buffer,
size_t * index,
const char * token)
{
int len;
- int cur_token;
+ size_t cur_token;
int r;
cur_token = * index;
len = strlen(token);
#ifdef UNSTRICT_SYNTAX
r = mailimap_space_parse(fd, buffer, &cur_token);
if ((r != MAILIMAP_NO_ERROR) && (r != MAILIMAP_ERROR_PARSE))
return r;
#endif
if (strncasecmp(buffer->str + cur_token, token, len) == 0) {
cur_token += len;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
else
return MAILIMAP_ERROR_PARSE;
}
static int is_space_or_tab(char ch)
{
return (ch == ' ') || (ch == '\t');
}
int mailimap_char_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char token)
{
int cur_token;
cur_token = * index;
if (buffer->str[cur_token] == token) {
cur_token ++;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
else
return MAILIMAP_ERROR_PARSE;
}
int mailimap_space_parse(mailstream * fd, MMAPString * buffer,
size_t * index)
{
#ifdef UNSTRICT_SYNTAX
/* can accept unstrict syntax */
size_t cur_token;
cur_token = * index;
while (is_space_or_tab(* (buffer->str + cur_token)))
cur_token ++;
if (cur_token == * index)
return MAILIMAP_ERROR_PARSE;
* index = cur_token;
return MAILIMAP_NO_ERROR;
#else
return mailimap_char_parse(fd, buffer, index, ' ');
#endif
}
#define mailimap_get_token_str(index, tab) \
mailimap_get_token_str_size(index, tab, \
sizeof(tab) / sizeof(struct mailimap_token_value))
#define mailimap_get_token_value(fd, buffer, index, tab) \
mailimap_get_token_value_size(fd, buffer, index, tab, \
sizeof(tab) / sizeof(struct mailimap_token_value))
static const char * mailimap_get_token_str_size(int index,
struct mailimap_token_value * tab,
size_t size)
{
size_t i;
for(i = 0 ; i < size ; i++)
if (index == tab[i].value)
return tab[i].str;
return NULL;
}
static int mailimap_get_token_value_size(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_token_value * tab,
size_t size)
{
size_t i;
int r;
#ifdef UNSTRICT_SYNTAX
/* can accept unstrict syntax */
r = mailimap_space_parse(fd, buffer, index);
if ((r != MAILIMAP_NO_ERROR) && (r != MAILIMAP_ERROR_PARSE))
return r;
#endif
for(i = 0 ; i < size ; i++) {
r = mailimap_token_case_insensitive_parse(fd, buffer, index, tab[i].str);
if (r == MAILIMAP_NO_ERROR)
return tab[i].value;
}
return -1;
}
static struct mailimap_token_value status_att_tab[] = {
{MAILIMAP_STATUS_ATT_MESSAGES, "MESSAGES"},
{MAILIMAP_STATUS_ATT_RECENT, "RECENT"},
{MAILIMAP_STATUS_ATT_UIDNEXT, "UIDNEXT"},
{MAILIMAP_STATUS_ATT_UIDVALIDITY, "UIDVALIDITY"},
{MAILIMAP_STATUS_ATT_UNSEEN, "UNSEEN"}
};
int mailimap_status_att_get_token_value(mailstream * fd, MMAPString * buffer,
size_t * index)
{
int r;
#ifdef UNSTRICT_SYNTAX
/* can accept unstrict syntax */
r = mailimap_space_parse(fd, buffer, index);
if ((r != MAILIMAP_NO_ERROR) && (r != MAILIMAP_ERROR_PARSE))
return r;
#endif
return mailimap_get_token_value(fd, buffer, index,
status_att_tab);
}
const char * mailimap_status_att_get_token_str(size_t index)
{
return mailimap_get_token_str(index, status_att_tab);
}
static struct mailimap_token_value month_tab[] = {
{1, "Jan"},
{2, "Feb"},
{3, "Mar"},
{4, "Apr"},
{5, "May"},
{6, "Jun"},
{7, "Jul"},
{8, "Aug"},
{9, "Sep"},
{10, "Oct"},
{11, "Nov"},
{12, "Dec"}
};
int mailimap_month_get_token_value(mailstream * fd, MMAPString * buffer,
size_t * index)
{
return mailimap_get_token_value(fd, buffer, index, month_tab);
}
const char * mailimap_month_get_token_str(size_t index)
{
return mailimap_get_token_str(index, month_tab);
}
static struct mailimap_token_value mailimap_flag_tab[] = {
{MAILIMAP_FLAG_ANSWERED, "\\Answered"},
{MAILIMAP_FLAG_FLAGGED, "\\Flagged"},
{MAILIMAP_FLAG_DELETED, "\\Deleted"},
{MAILIMAP_FLAG_SEEN, "\\Seen"},
{MAILIMAP_FLAG_DRAFT, "\\Draft"}
};
int mailimap_flag_get_token_value(mailstream * fd, MMAPString * buffer,
size_t * index)
{
return mailimap_get_token_value(fd, buffer, index,
mailimap_flag_tab);
}
const char * mailimap_flag_get_token_str(size_t index)
{
return mailimap_get_token_str(index, mailimap_flag_tab);
}
static struct mailimap_token_value encoding_tab[] = {
{MAILIMAP_BODY_FLD_ENC_7BIT, "7BIT"},
{MAILIMAP_BODY_FLD_ENC_8BIT, "8BIT"},
{MAILIMAP_BODY_FLD_ENC_BINARY, "BINARY"},
{MAILIMAP_BODY_FLD_ENC_BASE64, "BASE64"},
{MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE, "QUOTED-PRINTABLE"}
};
int mailimap_encoding_get_token_value(mailstream * fd, MMAPString * buffer,
size_t * index)
{
return mailimap_get_token_value(fd, buffer, index, encoding_tab);
}
static struct mailimap_token_value mbx_list_sflag_tab[] = {
{MAILIMAP_MBX_LIST_SFLAG_MARKED, "\\Marked"},
{MAILIMAP_MBX_LIST_SFLAG_NOSELECT, "\\Noselect"},
{MAILIMAP_MBX_LIST_SFLAG_UNMARKED, "\\Unmarked"}
};
int mailimap_mbx_list_sflag_get_token_value(mailstream * fd,
MMAPString * buffer,
size_t * index)
{
return mailimap_get_token_value(fd, buffer, index, mbx_list_sflag_tab);
}
static struct mailimap_token_value media_basic_tab[] = {
{MAILIMAP_MEDIA_BASIC_APPLICATION, "APPLICATION"},
{MAILIMAP_MEDIA_BASIC_AUDIO, "AUDIO"},
{MAILIMAP_MEDIA_BASIC_IMAGE, "IMAGE"},
{MAILIMAP_MEDIA_BASIC_MESSAGE, "MESSAGE"},
{MAILIMAP_MEDIA_BASIC_VIDEO, "VIDEO"}
};
int mailimap_media_basic_get_token_value(mailstream * fd, MMAPString * buffer,
size_t * index)
{
return mailimap_get_token_value(fd, buffer, index, media_basic_tab);
}
static struct mailimap_token_value resp_cond_state_tab[] = {
{MAILIMAP_RESP_COND_STATE_OK, "OK"},
{MAILIMAP_RESP_COND_STATE_NO, "NO"},
{MAILIMAP_RESP_COND_STATE_BAD, "BAD"}
};
int mailimap_resp_cond_state_get_token_value(mailstream * fd,
MMAPString * buffer,
size_t * index)
{
return mailimap_get_token_value(fd, buffer, index, resp_cond_state_tab);
}
static struct mailimap_token_value resp_text_code_1_tab[] = {
{MAILIMAP_RESP_TEXT_CODE_ALERT, "ALERT"},
{MAILIMAP_RESP_TEXT_CODE_PARSE, "PARSE"},
{MAILIMAP_RESP_TEXT_CODE_READ_ONLY, "READ-ONLY"},
{MAILIMAP_RESP_TEXT_CODE_READ_WRITE, "READ-WRITE"},
{MAILIMAP_RESP_TEXT_CODE_TRY_CREATE, "TRYCREATE"}
};
int mailimap_resp_text_code_1_get_token_value(mailstream * fd,
MMAPString * buffer,
size_t * index)
{
return mailimap_get_token_value(fd, buffer, index, resp_text_code_1_tab);
}
static struct mailimap_token_value resp_text_code_2_tab[] = {
{MAILIMAP_RESP_TEXT_CODE_UIDNEXT, "UIDNEXT"},
{MAILIMAP_RESP_TEXT_CODE_UIDVALIDITY, "UIDVALIDITY"},
{MAILIMAP_RESP_TEXT_CODE_UNSEEN, "UNSEEN"},
};
int mailimap_resp_text_code_2_get_token_value(mailstream * fd,
MMAPString * buffer,
size_t * index)
{
return mailimap_get_token_value(fd, buffer, index, resp_text_code_2_tab);
}
static struct mailimap_token_value section_msgtext_tab[] = {
{MAILIMAP_SECTION_MSGTEXT_HEADER_FIELDS_NOT, "HEADER.FIELDS.NOT"},
{MAILIMAP_SECTION_MSGTEXT_HEADER_FIELDS, "HEADER.FIELDS"},
{MAILIMAP_SECTION_MSGTEXT_HEADER, "HEADER"},
{MAILIMAP_SECTION_MSGTEXT_TEXT, "TEXT"}
};
int mailimap_section_msgtext_get_token_value(mailstream * fd,
MMAPString * buffer,
size_t * index)
{
return mailimap_get_token_value(fd, buffer, index, section_msgtext_tab);
}