summaryrefslogtreecommitdiffabout
path: root/kmicromail/libetpan/generic/imapdriver.c
Side-by-side diff
Diffstat (limited to 'kmicromail/libetpan/generic/imapdriver.c') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libetpan/generic/imapdriver.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/kmicromail/libetpan/generic/imapdriver.c b/kmicromail/libetpan/generic/imapdriver.c
index 0d63319..b3e5982 100644
--- a/kmicromail/libetpan/generic/imapdriver.c
+++ b/kmicromail/libetpan/generic/imapdriver.c
@@ -39,185 +39,188 @@
#include "imapdriver_tools.h"
#include "mailmessage.h"
#include "imapdriver_message.h"
#include "imapdriver_types.h"
#include "maildriver.h"
#include "maildriver_tools.h"
#include "generic_cache.h"
#include <stdlib.h>
#include <string.h>
static int imapdriver_initialize(mailsession * session);
static void imapdriver_uninitialize(mailsession * session);
static int imapdriver_connect_stream(mailsession * session, mailstream * s);
static int imapdriver_starttls(mailsession * session);
static int imapdriver_login(mailsession * session,
char * userid, char * password);
static int imapdriver_logout(mailsession * session);
static int imapdriver_noop(mailsession * session);
static int imapdriver_build_folder_name(mailsession * session, char * mb,
char * name, char ** result);
static int imapdriver_create_folder(mailsession * session, char * mb);
static int imapdriver_delete_folder(mailsession * session, char * mb);
static int imapdriver_rename_folder(mailsession * session, char * mb,
char * new_name);
static int imapdriver_check_folder(mailsession * session);
static int imapdriver_examine_folder(mailsession * session, char * mb);
static int imapdriver_select_folder(mailsession * session, char * mb);
static int imapdriver_expunge_folder(mailsession * session);
static int imapdriver_status_folder(mailsession * session, char * mb,
uint32_t * result_messages, uint32_t * result_recent,
uint32_t * result_unseen);
static int imapdriver_messages_number(mailsession * session, char * mb,
uint32_t * result);
static int imapdriver_recent_number(mailsession * session, char * mb,
uint32_t * result);
static int imapdriver_unseen_number(mailsession * session, char * mb,
uint32_t * result);
static int imapdriver_list_folders(mailsession * session, char * mb,
struct mail_list ** result);
static int imapdriver_lsub_folders(mailsession * session, char * mb,
struct mail_list ** result);
static int imapdriver_subscribe_folder(mailsession * session, char * mb);
static int imapdriver_unsubscribe_folder(mailsession * session, char * mb);
static int imapdriver_append_message(mailsession * session,
char * message, size_t size);
+static int imapdriver_append_message_flags(mailsession * session,
+ char * message, size_t size, struct mail_flags * flags);
static int imapdriver_copy_message(mailsession * session,
uint32_t num, char * mb);
static int imapdriver_get_messages_list(mailsession * session,
struct mailmessage_list ** result);
static int
imapdriver_get_envelopes_list(mailsession * session,
struct mailmessage_list * env_list);
#if 0
static int imapdriver_search_messages(mailsession * session, char * charset,
struct mail_search_key * key,
struct mail_search_result ** result);
#endif
static int imapdriver_get_message(mailsession * session,
uint32_t num, mailmessage ** result);
static int imapdriver_get_message_by_uid(mailsession * session,
const char * uid,
mailmessage ** result);
static mailsession_driver local_imap_session_driver = {
.sess_name = "imap",
.sess_initialize = imapdriver_initialize,
.sess_uninitialize = imapdriver_uninitialize,
.sess_parameters = NULL,
.sess_connect_stream = imapdriver_connect_stream,
.sess_connect_path = NULL,
.sess_starttls = imapdriver_starttls,
.sess_login = imapdriver_login,
.sess_logout = imapdriver_logout,
.sess_noop = imapdriver_noop,
.sess_build_folder_name = imapdriver_build_folder_name,
.sess_create_folder = imapdriver_create_folder,
.sess_delete_folder = imapdriver_delete_folder,
.sess_rename_folder = imapdriver_rename_folder,
.sess_check_folder = imapdriver_check_folder,
.sess_examine_folder = imapdriver_examine_folder,
.sess_select_folder = imapdriver_select_folder,
.sess_expunge_folder = imapdriver_expunge_folder,
.sess_status_folder = imapdriver_status_folder,
.sess_messages_number = imapdriver_messages_number,
.sess_recent_number = imapdriver_recent_number,
.sess_unseen_number = imapdriver_unseen_number,
.sess_list_folders = imapdriver_list_folders,
.sess_lsub_folders = imapdriver_lsub_folders,
.sess_subscribe_folder = imapdriver_subscribe_folder,
.sess_unsubscribe_folder = imapdriver_unsubscribe_folder,
.sess_append_message = imapdriver_append_message,
+ .sess_append_message_flags = imapdriver_append_message_flags,
.sess_copy_message = imapdriver_copy_message,
.sess_move_message = NULL,
.sess_get_messages_list = imapdriver_get_messages_list,
.sess_get_envelopes_list = imapdriver_get_envelopes_list,
.sess_remove_message = NULL,
#if 0
.sess_search_messages = imapdriver_search_messages,
#endif
.sess_get_message = imapdriver_get_message,
.sess_get_message_by_uid = imapdriver_get_message_by_uid,
};
mailsession_driver * imap_session_driver = &local_imap_session_driver;
static inline struct imap_session_state_data * get_data(mailsession * session)
{
return session->sess_data;
}
static mailimap * get_imap_session(mailsession * session)
{
return get_data(session)->imap_session;
}
static int imapdriver_initialize(mailsession * session)
{
struct imap_session_state_data * data;
mailimap * imap;
struct mail_flags_store * flags_store;
imap = mailimap_new(0, NULL);
if (imap == NULL)
goto err;
flags_store = mail_flags_store_new();
if (flags_store == NULL)
goto free_session;
data = malloc(sizeof(* data));
if (data == NULL)
goto free_flags_store;
data->imap_mailbox = NULL;
data->imap_session = imap;
data->imap_flags_store = flags_store;
session->sess_data = data;
return MAIL_NO_ERROR;
free_flags_store:
mail_flags_store_free(flags_store);
free_session:
mailimap_free(imap);
err:
return MAIL_ERROR_MEMORY;
}
static void imap_flags_store_process(mailimap * imap,
struct mail_flags_store * flags_store)
{
unsigned int i;
@@ -710,128 +713,153 @@ static int imapdriver_list_lsub_folders(mailsession * session, int type,
r = imap_list_to_list(imap_list, &resp);
if (r != MAIL_NO_ERROR) {
mailimap_list_result_free(imap_list);
res = r;
goto err;
}
mailimap_list_result_free(imap_list);
* result = resp;
return MAIL_NO_ERROR;
err:
return res;
}
static int imapdriver_list_folders(mailsession * session, char * mb,
struct mail_list ** result)
{
return imapdriver_list_lsub_folders(session, IMAP_LIST, mb,
result);
}
static int imapdriver_lsub_folders(mailsession * session, char * mb,
struct mail_list ** result)
{
return imapdriver_list_lsub_folders(session, IMAP_LSUB, mb,
result);
}
static int imapdriver_subscribe_folder(mailsession * session, char * mb)
{
int r;
r = mailimap_subscribe(get_imap_session(session), mb);
return imap_error_to_mail_error(r);
}
static int imapdriver_unsubscribe_folder(mailsession * session, char * mb)
{
int r;
r = mailimap_unsubscribe(get_imap_session(session), mb);
return imap_error_to_mail_error(r);
}
/* messages operations */
static int imapdriver_append_message(mailsession * session,
char * message, size_t size)
{
int r;
r = mailimap_append_simple(get_imap_session(session),
get_data(session)->imap_mailbox,
message, size);
return imap_error_to_mail_error(r);
}
+static int imapdriver_append_message_flags(mailsession * session,
+ char * message, size_t size, struct mail_flags * flags)
+{
+ struct mailimap_flag_list * flag_list;
+ int r;
+
+ if (flags != NULL) {
+ r = imap_flags_to_imap_flags(flags, &flag_list);
+ if (r != MAIL_NO_ERROR)
+ return r;
+ }
+ else {
+ flag_list = NULL;
+ }
+
+ r = mailimap_append(get_imap_session(session),
+ get_data(session)->imap_mailbox,
+ flag_list, NULL, message, size);
+
+ if (flag_list != NULL)
+ mailimap_flag_list_free(flag_list);
+
+ return imap_error_to_mail_error(r);
+}
+
static int imapdriver_copy_message(mailsession * session,
uint32_t num, char * mb)
{
int r;
struct mailimap_set * set;
int res;
set = mailimap_set_new_single(num);
if (set == NULL) {
res = MAIL_ERROR_MEMORY;
goto err;
}
r = mailimap_uid_copy(get_imap_session(session), set, mb);
mailimap_set_free(set);
return imap_error_to_mail_error(r);
err:
return res;
}
static int imapdriver_get_messages_list(mailsession * session,
struct mailmessage_list ** result)
{
return imap_get_messages_list(get_imap_session(session),
session, imap_message_driver, 1,
result);
}
static int
imapdriver_get_envelopes_list(mailsession * session,
struct mailmessage_list * env_list)
{
struct mailimap_set * set;
struct mailimap_fetch_att * fetch_att;
struct mailimap_fetch_type * fetch_type;
int res;
clist * fetch_result;
int r;
uint32_t exists;
clist * msg_list;
if (get_imap_session(session)->imap_selection_info == NULL) {
res = MAIL_ERROR_BAD_STATE;
goto err;
}
imap_flags_store_process(get_imap_session(session),
get_data(session)->imap_flags_store);
exists = get_imap_session(session)->imap_selection_info->sel_exists;
if (exists == 0)
return MAIL_NO_ERROR;
fetch_type = mailimap_fetch_type_new_fetch_att_list_empty();
if (fetch_type == NULL) {
res = MAIL_ERROR_MEMORY;
goto err;
}