Commit e4dc7185 e4dc7185c62a3042b9a05828be83c1f1ca308dcb by Sergey Poznyakoff

Implement imap mailbox (read-only, so far).

* include/mailutils/sys/imap.h (_mu_imap_mailbox_init): New proto.
(_mu_imap_message,_mu_imap_mailbox): New structures.
* libproto/imap/mbox.c: New file.
* libproto/imap/Makefile.am (libmu_imap_la_SOURCES): Put back mbox.c
* libproto/imap/fetch.c: Fix body/bodystructure parsing.
* libproto/imap/folder.c (_mu_imap_folder_destroy): Close folder.
(_mu_imap_folder_open): Implement STARTTLS.
(_imap_record): Accept parameters in URL, use _mu_imap_mailbox_init
to initialize mailbox.
1 parent 22ec4913
......@@ -235,9 +235,46 @@ int _mu_imap_url_init (mu_url_t url);
int _mu_imaps_url_init (mu_url_t url);
/* ----------------------------- */
/* Folder interface */
/* Mailbox interface */
/* ----------------------------- */
int _mu_imap_mailbox_init (mu_mailbox_t mailbox);
#define _MU_IMAP_MSG_SCANNED 0x01
#define _MU_IMAP_MSG_CACHED 0x02
#define _MU_IMAP_MSG_LINES 0x04
struct _mu_imap_message
{
int flags;
size_t uid; /* Message UID */
int attr_flags; /* Attributes */
mu_off_t offset; /* Offset in the message cache stream */
mu_off_t body_start; /* Start of message, relative to offset */
mu_off_t body_end; /* End of message, relative to offset */
size_t header_lines; /* Number of lines in the header */
size_t body_lines; /* Number of lines in the body */
size_t message_size; /* Message size */
size_t message_lines; /* Number of lines in the message */
struct mu_imapenvelope *env; /* IMAP envelope */
mu_message_t message; /* Pointer to the message structure */
struct _mu_imap_mailbox *imbx; /* Back pointer. */
};
#define _MU_IMAP_MBX_UPTODATE 0x01
struct _mu_imap_mailbox
{
int flags;
mu_off_t total_size; /* Total mailbox size. */
struct mu_imap_stat stats; /* Mailbox statistics */
struct _mu_imap_message *msgs; /* Array of messages */
size_t msgs_cnt; /* Number of used slots in msgs */
size_t msgs_max; /* Number of slots in msgs */
mu_stream_t cache; /* Message cache stream */
int last_error; /* Last error code */
mu_mailbox_t mbox;
};
# ifdef __cplusplus
}
......
......@@ -23,8 +23,6 @@ libmu_imap_la_LIBADD = ${MU_LIB_AUTH} ${MU_LIB_MAILUTILS} @INTLLIBS@
SUBDIRS = . tests
# FIXME: Put this back when ready
# mbox.c
libmu_imap_la_SOURCES = \
appmsg.c\
appstr.c\
......@@ -68,4 +66,5 @@ libmu_imap_la_SOURCES = \
unselect.c\
unsubscribe.c\
folder.c\
mbox.c\
url.c
......
......@@ -618,7 +618,7 @@ _parse_bodystructure_simple (struct imap_list_element *elt,
struct body_field_map *map;
mu_list_count (elt->v.list, &n);
if (n < 8)
if (n < 7)
return MU_ERR_PARSE;
tok = _mu_imap_list_at (elt->v.list, BSTOK_BODY_TYPE);
......@@ -976,6 +976,7 @@ _extract_string (void **itmv, size_t itmc, void *call_data)
static int
_fetch_fold (void *item, void *data)
{
int rc;
struct imap_list_element *elt = item;
struct parse_response_env *env = data;
......@@ -983,7 +984,6 @@ _fetch_fold (void *item, void *data)
{
case resp_kw:
{
int rc;
char *kw;
size_t kwlen;
struct mapper_tab *mt;
......@@ -1020,6 +1020,26 @@ _fetch_fold (void *item, void *data)
break;
}
case resp_body:
if (_mu_imap_list_element_is_string (elt, "["))
{
env->state = resp_body_section;
break;
}
else
{
env->mapper = _bodystructure_mapper;
_free_fetch_response (env->resp);
rc = alloc_response (&env->resp, MU_IMAP_FETCH_BODYSTRUCTURE);
if (rc)
{
env->status = rc;
return MU_ERR_FAILURE;
}
env->state = resp_val;
}
/* fall through */
case resp_val:
if (env->mapper)
{
......@@ -1034,16 +1054,6 @@ _fetch_fold (void *item, void *data)
env->state = resp_kw;
break;
case resp_body:
if (_mu_imap_list_element_is_string (elt, "["))
env->state = resp_body_section;
else
{
env->mapper = _bodystructure_mapper;
env->state = resp_val;
}
break;
case resp_body_section:
if (elt->type != imap_eltype_string)
{
......
......@@ -39,21 +39,13 @@
#include <mailutils/sys/imap.h>
#include <mailutils/sys/folder.h>
/* Placeholders. */
#define _mu_imap_mailbox_init NULL
#define _mu_imaps_mailbox_init NULL
static void
_mu_imap_folder_destroy (mu_folder_t folder)
{
mu_imap_t imap = folder->data;
if (imap)
{
/*
mu_imap_logout (imap);
mu_imap_disconnect (imap);
*/
mu_folder_close (folder);
mu_imap_destroy (&imap);
folder->data = imap;
}
......@@ -90,13 +82,6 @@ _mu_folder_bad_callback (void *data, int code, size_t sdat, void *pdat)
mu_error (_("This probably indicates a bug in Mailutils client code."));
mu_error (_("Please, report that to <%s>."), PACKAGE_BUGREPORT);
}
#if 0
static void
_mu_folder_fetch_callback (void *data, int code, size_t sdat, void *pdat)
{
mu_folder_t folder = data;
}
#endif
/* Set up an IMAP(S) connection for this folder */
static int
......@@ -187,11 +172,6 @@ _mu_imap_folder_open (mu_folder_t folder, int flags)
mu_imap_register_callback_function (imap, MU_IMAP_CB_BAD,
_mu_folder_bad_callback,
folder);
#if 0
mu_imap_register_callback_function (imap, MU_IMAP_CB_FETCH,
_mu_folder_fetch_callback,
folder);
#endif
rc = mu_imap_connect (imap);
if (rc)
{
......@@ -206,6 +186,32 @@ _mu_imap_folder_open (mu_folder_t folder, int flags)
return rc;
}
#ifdef WITH_TLS
if (!tls && mu_imap_capability_test (imap, "STARTTLS", NULL) == 0)
{
size_t parmc = 0;
char **parmv = NULL;
tls = 1;
if (mu_url_sget_fvpairs (folder->url, &parmc, &parmv) == 0)
{
size_t i;
for (i = 0; i < parmc; i++)
{
if (strcmp (parmv[i], "notls") == 0)
tls = 0;
/*FIXME:
else if (strncmp (parmv[i], "auth=", 5) == 0)
*/
/* unrecognized arguments silently ignored */
}
}
if (tls)
mu_imap_starttls (imap);
}
#endif
if (mu_imap_session_state (imap) == MU_IMAP_SESSION_NONAUTH)
{
rc = mu_authority_authenticate (folder->authority);
......@@ -217,7 +223,7 @@ _mu_imap_folder_open (mu_folder_t folder, int flags)
mu_folder_close (folder);
}
}
return rc;
}
......@@ -551,7 +557,7 @@ static struct _mu_record _imap_record =
MU_IMAP_PRIO,
MU_IMAP_SCHEME,
MU_RECORD_DEFAULT,
MU_URL_SCHEME | MU_URL_CRED | MU_URL_INET | MU_URL_PATH,
MU_URL_SCHEME | MU_URL_CRED | MU_URL_INET | MU_URL_PATH | MU_URL_PARAM,
MU_URL_HOST,
_mu_imap_url_init, /* url entry. */
_mu_imap_mailbox_init, /* Mailbox entry. */
......@@ -576,7 +582,7 @@ static struct _mu_record _imaps_record =
MU_URL_SCHEME | MU_URL_CRED | MU_URL_INET | MU_URL_PATH | MU_URL_PARAM,
MU_URL_HOST,
_mu_imaps_url_init, /* url entry. */
_mu_imaps_mailbox_init, /* Mailbox entry. */
_mu_imap_mailbox_init, /* Mailbox entry. */
NULL, /* Mailer entry. */
_mu_imap_folder_init, /* Folder entry. */
NULL, /* No need for a back pointer. */
......