Commit bd507cf1 bd507cf116ad3a56e979f406fabe3d0cef5e05a8 by Alain Magloire

header.c header.h header0.h mailbox.c mailbox.h mailbox0.h

 	mbx_imap.c mbx_mbox.c mbx_mdir.c mbx_mh.c mbx_mmdf.c mbx_pop.c
 	mbx_unix.c

cleaning and pruning.
1 parent 3f2a7da5
......@@ -25,299 +25,44 @@
#include <stdlib.h>
#include <errno.h>
static int rfc822_parse (header_t h, const char *blurb, size_t len);
static int rfc822_set_value (header_t h, const char *fn, const char *fb,
size_t n, int replace);
static int rfc822_get_value (header_t h, const char *fn,
char *fb, size_t len, size_t *n);
static int rfc822_get_mvalue (header_t h, const char *fn,
char **fb, size_t *n);
struct _hdr
{
char *fn;
char *fb;
};
typedef struct _hdr *hdr_t;
struct _rfc822_data
{
char *blurb;
struct _hdr unixfrom; /* stupid hack for unix from */
size_t hdr_count;
struct _hdr *hdr;
};
typedef struct _rfc822_data *rfc822_t;
int
header_init (header_t *ph, const char *blurb, size_t len, int flag)
{
header_t h;
if (flag != MU_HDR_RFC822)
{
return ENOTSUP;
}
h = calloc (1, sizeof (*h));
if (h == NULL)
{
return ENOMEM;
}
h->_parse = rfc822_parse;
h->_get_value = rfc822_get_value;
h->_get_mvalue = rfc822_get_mvalue;
h->_set_value = rfc822_set_value;
h->_parse (h, blurb, len);
*ph = h;
return 0;
if (flag != MU_HEADER_RFC822)
return ENOTSUP;
return rfc822_init (ph, blurb, len);
}
void
header_destroy (header_t *ph)
{
if (ph && *ph)
{
header_t h = *ph;
if (h->data)
{
rfc822_t rfc = (rfc822_t)h->data;
if (rfc->hdr)
free (rfc->hdr);
if (rfc->blurb)
free (rfc->blurb);
free (rfc);
}
free (h);
*ph = NULL;
}
(*ph)->_destroy (ph);
}
/* stub functions */
int
header_gvalue (const char *blurb, size_t blurb_len, const char *fn, char *fb,
size_t len, size_t *n)
header_set_value (header_t h, const char *fn, const char *fb, size_t n,
int replace)
{
const char *header_end;
const char *header_start;
const char *colon;
size_t i = 0;
size_t j = 0;
size_t fn_len;
int status = EINVAL;
if (blurb == NULL || blurb_len < 5 || fn == NULL || len == 0)
{
return status;
}
*fb = '\0'; /* if we did find something, return empty */
for (fn_len = strlen (fn), header_start = blurb;;header_start = header_end)
{
header_end = memchr (header_start, '\n', blurb_len);
if (header_end == NULL)
{
break;
}
header_end++;
blurb_len -= header_end - header_start;
colon = memchr (header_start, ':', header_end - header_start);
if (colon == NULL)
{
continue;
}
/* check if is the header field name */
j = colon - header_start;
if (fn_len == j)
{
if (memcmp (fn, header_start, fn_len) == 0)
{
i = header_end - colon -1;
if (fb)
{
i = (len < i) ? len : i;
memcpy (fb, colon +1, i);
fb[i - 1] = '\0';
}
status = 0;
break;
}
}
}
if (n)
*n = i;
return status;
if (h == NULL)
return EINVAL;
return h->_set_value (h, fn, fb, n, replace);
}
int
header_gmvalue (const char *blurb, size_t blurb_ln, const char *fn,
char **fb, size_t *n)
{
size_t i;
if (blurb == NULL || blurb_ln == 0 || fn == NULL || fb == NULL
|| header_gvalue (blurb, blurb_ln, fn, NULL, 0, &i) != 0)
{
return EINVAL;
}
*fb = calloc (1, ++i);
if (*fb == NULL)
return ENOMEM;
return header_gvalue (blurb, blurb_ln, fn, *fb, i, n);
}
static int
rfc822_parse (header_t h, const char *blurb, size_t len)
header_get_value (header_t h, const char *fn, char *fb,
size_t len, size_t *n)
{
rfc822_t rfc;
char *header_end;
char *header_start;
char *header_start2;
char *colon;
struct _hdr *hdr;
if (h == NULL || blurb == NULL || len == 0)
{
return EINVAL;
}
rfc = calloc (1, sizeof (*rfc));
if (rfc == NULL)
{
return ENOMEM;
}
rfc->blurb = calloc (1, len);
if (rfc->blurb == NULL)
{
free (rfc);
return ENOMEM;
}
memcpy (rfc->blurb, blurb, len);
for (header_start = rfc->blurb;; header_start = ++header_end)
{
/* get a header, a header is :
field-name ':' field-body1
[ ' ' '\t' field-body2 ] '\r' '\n'
*/
for (header_start2 = header_start;;header_start2 = ++header_end)
{
header_end = memchr (header_start2, '\n', len);
if (header_end == NULL)
{
break;
}
else
{
len -= (header_end - header_start2 + 1);
if (len == 0)
{
header_end = NULL;
break;
}
if (header_end[1] != ' '
&& header_end[1] != '\t')
{
break; /* new header break the inner for */
}
}
/* *header_end = ' '; smash LF */
}
if (header_end == NULL)
{
break; /* bail out */
}
*header_end = '\0'; /* smash LF */
/* Treats unix "From " specially */
if ((header_end - header_start >= 5)
&& strncmp (header_start, "From ", 5) == 0)
{
rfc->unixfrom.fn = "From ";
rfc->unixfrom.fb = header_start + 6;
}
else
{
colon = memchr (header_start, ':', header_end - header_start);
if (colon == NULL)
{
/* Houston we have a problem */
free (rfc->blurb);
if (rfc->hdr)
free (rfc->hdr);
free (rfc);
return EINVAL;
}
hdr = realloc (rfc->hdr, (rfc->hdr_count + 1) * sizeof (*hdr));
if (hdr == NULL)
{
/* Houston we have another problem */
free (rfc->blurb);
if (rfc->hdr)
free (rfc->hdr);
free (rfc);
return ENOMEM;
}
rfc->hdr = hdr;
rfc->hdr_count++;
*colon = '\0'; /* smash colon */
rfc->hdr[rfc->hdr_count - 1].fn = header_start;
rfc->hdr[rfc->hdr_count - 1].fb = colon + 1;
}
}
h->data = rfc;
return 0;
}
static int
rfc822_set_value (header_t h, const char *fn, const char *fb,
size_t n, int replace)
{
(void)h; (void)fn; (void)fb; (void)n; (void)replace;
return ENOSYS;
}
static int
rfc822_get_value (header_t h, const char *fn, char *fb, size_t len, size_t *n)
{
size_t i = 0;
size_t j = 0;
rfc822_t rfc = (rfc822_t)h->data;
if (fb)
{
*fb = '\0'; /* if empty */
}
for (i = 0; i < rfc->hdr_count; i++)
{
if (strcmp (rfc->hdr[i].fn, fn) == 0)
{
j = strlen (rfc->hdr[i].fb);
j = (len < j) ? len : j;
if (fb)
{
memcpy (fb, rfc->hdr[i].fb, j);
}
break;
}
}
if (n)
*n = j;
return 0;
if (h == NULL)
return EINVAL;
return h->_get_value (h, fn, fb, len, n);
}
static int
rfc822_get_mvalue (header_t h, const char *fn, char **fb, size_t *n)
ssize_t
header_get_data (header_t h, char *data, size_t len, off_t off, int *err)
{
size_t i;
if (h == NULL || fn == NULL || fb == NULL
|| h->_get_value (h, fn, NULL, 0, &i) != 0)
{
return EINVAL;
}
*fb = calloc (1, ++i);
if (*fb == NULL)
return ENOMEM;
return h->_get_value (h, fn, *fb, i, n);
if (h == NULL)
return EINVAL;
return h->_get_data (h, data, len, off, err);
}
......
......@@ -32,34 +32,34 @@
extern "C" {
#endif
#define MU_HDR_RFC822 0
#define MU_HDR_UNIX_FROM "From "
#define MU_HDR_RETURN_PATH "Return-Path"
#define MU_HDR_RECEIVED "Received"
#define MU_HDR_DATE "Date"
#define MU_HDR_FROM "From"
#define MU_HDR_RESENT_FROM "Resent-From"
#define MU_HDR_SUBJECT "Subject"
#define MU_HDR_SENDER "Sender"
#define MU_HDR_RESENT_SENDER "Resent-SENDER"
#define MU_HDR_TO "To"
#define MU_HDR_RESENT_TO "Resent-To"
#define MU_HDR_CC "Cc"
#define MU_HDR_RESENT_CC "Resent-Cc"
#define MU_HDR_BCC "Bcc"
#define MU_HDR_RESENT_BCC "Resent-Bcc"
#define MU_HDR_REPLY_TO "Reply-To"
#define MU_HDR_RESENT_REPLY_TO "Resent-Reply-To"
#define MU_HDR_MESSAGE_ID "Message-ID"
#define MU_HDR_RESENT_MESSAGE_ID "Resent-Message-ID"
#define MU_HDR_IN_REPLY_TO "In-Reply-To"
#define MU_HDR_ENCRYPTED "Encrypted"
#define MU_HDR_PRECEDENCE "Precedence"
#define MU_HDR_STATUS "Status"
#define MU_HDR_CONTENT_LENGTH "Content-Length"
#define MU_HDR_CONTENT_TYPE "Content-Type"
#define MU_HDR_MIME_VERSION "MIME-Version"
#define MU_HEADER_RFC822 0
#define MU_HEADER_UNIX_FROM "From "
#define MU_HEADER_RETURN_PATH "Return-Path"
#define MU_HEADER_RECEIVED "Received"
#define MU_HEADER_DATE "Date"
#define MU_HEADER_FROM "From"
#define MU_HEADER_RESENT_FROM "Resent-From"
#define MU_HEADER_SUBJECT "Subject"
#define MU_HEADER_SENDER "Sender"
#define MU_HEADER_RESENT_SENDER "Resent-SENDER"
#define MU_HEADER_TO "To"
#define MU_HEADER_RESENT_TO "Resent-To"
#define MU_HEADER_CC "Cc"
#define MU_HEADER_RESENT_CC "Resent-Cc"
#define MU_HEADER_BCC "Bcc"
#define MU_HEADER_RESENT_BCC "Resent-Bcc"
#define MU_HEADER_REPLY_TO "Reply-To"
#define MU_HEADER_RESENT_REPLY_TO "Resent-Reply-To"
#define MU_HEADER_MESSAGE_ID "Message-ID"
#define MU_HEADER_RESENT_MESSAGE_ID "Resent-Message-ID"
#define MU_HEADER_IN_REPLY_TO "In-Reply-To"
#define MU_HEADER_ENCRYPTED "Encrypted"
#define MU_HEADER_PRECEDENCE "Precedence"
#define MU_HEADER_STATUS "Status"
#define MU_HEADER_CONTENT_LENGTH "Content-Length"
#define MU_HEADER_CONTENT_TYPE "Content-Type"
#define MU_HEADER_MIME_VERSION "MIME-Version"
/* Mime support header attribute */
......@@ -67,30 +67,16 @@ extern "C" {
struct _header;
typedef struct _header * header_t;
extern int header_init __P ((header_t *, const char *blurb,
size_t ln, int flag));
extern void header_destroy __P ((header_t *));
extern int header_gvalue __P ((const char *blurb, size_t bl, const char *fn,
char *fv, size_t len, size_t *n));
extern int header_gmvalue __P ((const char *blurb, size_t bl, const char *fn,
char **fv, size_t *nv));
#undef INLINE
#ifdef __GNUC__
#define INLINE __inline__
#else
#define INLINE
#endif
extern INLINE int header_set_value __P ((header_t, const char *fn,
const char *fv, size_t n,
int replace));
extern INLINE int header_get_value __P ((header_t, const char *fn, char *fv,
size_t len, size_t *n));
extern INLINE int header_get_mvalue __P ((header_t, const char *fn,
char **fv, size_t *n));
extern int header_init __P ((header_t *, const char *blurb,
size_t ln, int flag));
extern void header_destroy __P ((header_t *));
extern int header_set_value __P ((header_t, const char *fn,
const char *fv, size_t n, int replace));
extern int header_get_value __P ((header_t, const char *fn, char *fv,
size_t len, size_t *n));
extern ssize_t header_get_data __P ((header_t h, char *data,
size_t len, off_t off, int *err));
#ifdef _cpluscplus
}
#endif
......
......@@ -33,26 +33,36 @@
extern "C" {
#endif
struct _hdr
{
char *fn;
char *fn_end;
char *fv;
char *fv_end;
};
typedef struct _hdr *hdr_t;
struct _header
{
/* Data */
void *data;
/* owner ? */
void *message;
/* Functions */
int (*_set_value) __P ((header_t, const char *fn, const char *fv,
size_t n, int replace));
int (*_get_value) __P ((header_t, const char *fn, char *fv,
size_t len, size_t *n));
int (*_get_mvalue) __P ((header_t, const char *fn, char **fv, size_t *n));
int (*_parse) __P ((header_t, const char *blurb, size_t len));
int (*_init) __P ((header_t *, const char *, size_t));
void (*_destroy) __P ((header_t *));
int (*_set_value) __P ((header_t, const char *fn, const char *fv,
size_t n, int replace));
int (*_get_value) __P ((header_t, const char *fn, char *fv,
size_t len, size_t *n));
ssize_t (*_get_data) __P ((header_t h, char *data,
size_t len, off_t off, int *err));
int (*_parse) __P ((header_t, const char *blurb, size_t len));
} ;
#ifdef USE_MACROS
#define header_set_value(h, fn, fv, n, r) h->_set_value (h, fn, fv, n, r)
#define header_get_value(h, fn, fv, v, ln, n) h->_get_value (h, fn, fv, ln, n)
#define header_get_mvalue(h, fn, fv, v, n) h->_get_mvalue (h, fn, fv, n)
#endif
extern int rfc822_init __P ((header_t *ph, const char *blurb, size_t len));
extern void rfc822_destroy __P ((header_t *ph));
#ifdef _cpluscplus
}
#endif
......
......@@ -18,10 +18,12 @@
#ifndef _MAILBOX_H
# define _MAILBOX_H
#include <url.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <url.h>
#include <message.h>
#include <auth.h>
#include <locker.h>
#ifdef __cplusplus
extern "C" {
......@@ -39,109 +41,44 @@ extern "C" {
struct _mailbox;
typedef struct _mailbox *mailbox_t;
struct mailbox_type
{
char *name;
int id;
struct url_type *utype;
int (*_init) __P ((mailbox_t *, const char *name));
void (*_destroy) __P ((mailbox_t *));
};
/* constructor/destructor and possible types */
extern int mailbox_init __P ((mailbox_t *, const char *name, int id));
extern int mailbox_init __P ((mailbox_t *, const char *, int id));
extern void mailbox_destroy __P ((mailbox_t *));
/* mailbox registration */
extern int mailbox_list_type __P ((struct mailbox_type mtype[],
size_t len, size_t *n));
extern int mailbox_list_mtype __P ((struct mailbox_type **mtype, size_t *n));
extern int mailbox_add_type __P ((struct mailbox_type *mtype));
extern int mailbox_remove_type __P ((struct mailbox_type *mtype));
extern int mailbox_get_type __P ((struct mailbox_type **mtype, int id));
#ifndef INLINE
# ifdef __GNUC__
# define INLINE __inline__
# else
# define INLINE
# endif
#endif
/* flags for mailbox_open () */
#define MU_MB_RDONLY ((int)1)
#define MU_MB_WRONLY (MU_MB_RDONLY << 1)
#define MU_MB_RDWR (MU_MB_WRONLY << 1)
#define MU_MB_APPEND (MU_MB_RDWR << 1)
#define MU_MB_CREAT (MU_MB_APPEND << 1)
extern INLINE int mailbox_open __P ((mailbox_t, int flag));
extern INLINE int mailbox_close __P ((mailbox_t));
/* type */
extern INLINE int mailbox_get_name __P ((mailbox_t, int *id, char *name,
size_t len, size_t *n));
extern INLINE int mailbox_get_mname __P ((mailbox_t, int *id, char **name,
size_t *n));
/* passwd */
extern INLINE int mailbox_get_passwd __P ((mailbox_t, char *passwd,
size_t len, size_t *n));
extern INLINE int mailbox_get_mpasswd __P ((mailbox_t, char **passwd,
size_t *n));
extern INLINE int mailbox_set_passwd __P ((mailbox_t, const char *passwd,
size_t len));
/* deleting */
extern INLINE int mailbox_delete __P ((mailbox_t, size_t msgno));
extern INLINE int mailbox_undelete __P ((mailbox_t, size_t msgno));
extern INLINE int mailbox_expunge __P ((mailbox_t));
extern INLINE int mailbox_is_deleted __P ((mailbox_t, size_t msgno));
/* appending */
extern INLINE int mailbox_new_msg __P ((mailbox_t, size_t * msgno));
extern INLINE int mailbox_set_header __P ((mailbox_t, size_t msgno,
const char *h, size_t len,
int replace));
extern INLINE int mailbox_set_body __P ((mailbox_t, size_t msgno,
const char *b, size_t len,
int replace));
extern INLINE int mailbox_append __P ((mailbox_t, size_t msgno));
extern INLINE int mailbox_destroy_msg __P ((mailbox_t, size_t msgno));
/* reading */
extern INLINE int mailbox_get_body __P ((mailbox_t, size_t msgno,
off_t off, char *b,
size_t len, size_t *n));
extern INLINE int mailbox_get_mbody __P ((mailbox_t, size_t msgno, off_t off,
char **b, size_t *n));
extern INLINE int mailbox_get_header __P ((mailbox_t, size_t msgno, off_t off,
char *h, size_t len, size_t *n));
extern INLINE int mailbox_get_mheader __P ((mailbox_t, size_t msgno, off_t off,
char **h, size_t *n));
#define MU_MAILBOX_RDONLY ((int)1)
#define MU_MAILBOX_WRONLY (MU_MAILBOX_RDONLY << 1)
#define MU_MAILBOX_RDWR (MU_MAILBOX_WRONLY << 1)
#define MU_MAILBOX_APPEND (MU_MAILBOX_RDWR << 1)
#define MU_MAILBOX_CREAT (MU_MAILBOX_APPEND << 1)
#define MU_MAILBOX_NONBLOCK (MU_MAILBOX_CREAT << 1)
extern int mailbox_open __P ((mailbox_t, int flag));
extern int mailbox_close __P ((mailbox_t));
/* messages */
extern int mailbox_get_message __P ((mailbox_t, size_t msgno, message_t *msg));
extern int mailbox_append_message __P ((mailbox_t, message_t msg));
extern int mailbox_messages_count __P ((mailbox_t, size_t *num));
extern int mailbox_expunge __P ((mailbox_t));
/* Lock settings */
typedef enum { MB_RDLOCK, MB_WRLOCK } mailbox_lock_t;
extern INLINE int mailbox_lock __P ((mailbox_t, int flag));
extern INLINE int mailbox_unlock __P ((mailbox_t));
/* owner and group */
extern INLINE int mailbox_set_owner __P ((mailbox_t, uid_t uid));
extern INLINE int mailbox_set_group __P ((mailbox_t, gid_t gid));
/* miscellany */
extern INLINE int mailbox_scan __P ((mailbox_t, size_t *msgs));
extern INLINE int mailbox_is_updated __P ((mailbox_t));
extern INLINE int mailbox_get_timeout __P ((mailbox_t, size_t *timeout));
extern INLINE int mailbox_set_timeout __P ((mailbox_t, size_t timeout));
extern INLINE int mailbox_get_refresh __P ((mailbox_t, size_t *refresh));
extern INLINE int mailbox_set_refresh __P ((mailbox_t, size_t refresh));
extern INLINE int mailbox_get_size __P ((mailbox_t, size_t msgno,
size_t *header, size_t *body));
extern INLINE int mailbox_set_notification __P ((mailbox_t,
int (*notification)
__P ((mailbox_t, void *))));
extern int mailbox_get_locker __P ((mailbox_t, locker_t *locker));
extern int mailbox_set_locker __P ((mailbox_t, locker_t locker));
/* Authentication */
extern int mailbox_get_auth __P ((mailbox_t, auth_t *auth));
extern int mailbox_set_auth __P ((mailbox_t, auth_t auth));
/* update and scanning*/
extern int mailbox_progress __P ((mailbox_t, int (*progress)
__P ((int, void *)), void *arg));
extern int mailbox_is_updated __P ((mailbox_t));
/* mailbox size ? */
extern int mailbox_size __P ((mailbox_t, off_t size));
extern int mailbox_get_url __P ((mailbox_t, url_t *));
#ifdef __cplusplus
}
......
......@@ -16,13 +16,12 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _MAILBOX0_H
# define _MAILBOX0_H
#define _MAILBOX0_H
#include <url.h>
#include <mailbox.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
......@@ -36,176 +35,78 @@ extern "C" {
# endif
#endif /*__P */
/* forward declaration */
//struct _mailbox;
//typedef struct _mailbox *mailbox_t;
/* Lock settings */
//typedef enum { MB_ULOCK, MB_RLOCK, MB_WLOCK } mailbox_lock_t;
/*
struct mailbox_type
{
char *name;
int id;
struct url_type *utype;
int (*_init) __P ((mailbox_t *, const char *name));
void (*_destroy) __P ((mailbox_t *));
};
*/
struct _mailbox
{
/* Data */
char *name;
uid_t owner;
gid_t group;
size_t messages;
size_t num_deleted;
FILE *file;
message_t *messages;
size_t messages_num;
off_t size;
int lock;
size_t timeout;
size_t refresh;
int (*notification) __P ((mailbox_t, void *arg));
struct mailbox_type *mtype;
/* back pointer to the specific mailbox */
auth_t auth;
locker_t locker;
url_t url;
int (*_progress) __P ((int, void *arg));
void *progress_arg;
/* Back pointer to the specific mailbox */
void *data;
/* Functions */
/* Public methods */
#define MU_MB_RDONLY ((int)1)
#define MU_MB_WRONLY (MU_MB_RDONLY << 1)
#define MU_MB_RDWR (MU_MB_WRONLY << 1)
#define MU_MB_APPEND (MU_MB_RDWR << 1)
#define MU_MB_CREAT (MU_MB_APPEND << 1)
int (*_init) __P ((mailbox_t *, const char *));
void (*_destroy) __P ((mailbox_t *));
int (*_open) __P ((mailbox_t, int flag));
int (*_close) __P ((mailbox_t));
/* type */
int (*_get_name) __P ((mailbox_t, int *id, char *name,
size_t len, size_t *n));
int (*_get_mname) __P ((mailbox_t, int *id, char **name, size_t *n));
/* passwd if needed */
int (*_get_passwd) __P ((mailbox_t, char *passwd,
size_t len, size_t *n));
int (*_get_mpasswd) __P ((mailbox_t, char **passwd, size_t *n));
int (*_set_passwd) __P ((mailbox_t, const char *passwd, size_t len));
/* deleting mesgs */
int (*_is_deleted) __P ((mailbox_t, size_t msgno));
int (*_delete) __P ((mailbox_t, size_t msgno));
int (*_undelete) __P ((mailbox_t, size_t msgno));
/* messages */
int (*_get_message) __P ((mailbox_t, size_t msgno, message_t *msg));
int (*_append_message) __P ((mailbox_t, message_t msg));
int (*_messages_count) __P ((mailbox_t, size_t *num));
int (*_expunge) __P ((mailbox_t));
int (*_is_updated) __P ((mailbox_t));
int (*_scan) __P ((mailbox_t, size_t *msgs));
/* appending messages */
int (*_new_msg) __P ((mailbox_t, size_t *msgno));
int (*_set_header) __P ((mailbox_t, size_t msgno, const char *h,
size_t len, int replace));
int (*_set_body) __P ((mailbox_t, size_t msgno, const char *b,
size_t len, int replace));
int (*_append) __P ((mailbox_t, size_t msgno));
int (*_destroy_msg) __P ((mailbox_t, size_t msgno));
#define MU_MB_RDLOCK 0
#define MU_MB_WRLOCK 1
/* locking */
int (*_lock) __P ((mailbox_t, int flag));
int (*_unlock) __P ((mailbox_t));
int (*_ilock) __P ((mailbox_t, int flag));
int (*_iunlock) __P ((mailbox_t));
/* reading mesgs */
int (*_get_body) __P ((mailbox_t, size_t msgno, off_t off,
char *b, size_t len, size_t *n));
int (*_get_mbody) __P ((mailbox_t, size_t msgno, off_t off,
char **b, size_t *n));
int (*_get_header) __P ((mailbox_t, size_t msgno, off_t off,
char *h, size_t len, size_t *n));
int (*_get_mheader) __P ((mailbox_t, size_t msgno, off_t off,
char **h, size_t *n));
int (*_get_size) __P ((mailbox_t, size_t msgno,
size_t *h, size_t *b));
/* setting flags */
int (*_is_read) __P ((mailbox_t, size_t msgno));
int (*_set_read) __P ((mailbox_t, size_t msgno));
int (*_is_seen) __P ((mailbox_t, size_t msgno));
int (*_set_seen) __P ((mailbox_t, size_t msgno));
int (*_size) __P ((mailbox_t, off_t *size));
/* owner and group */
int (*_set_owner) __P ((mailbox_t, uid_t uid));
int (*_get_owner) __P ((mailbox_t, uid_t *uid));
int (*_set_group) __P ((mailbox_t, gid_t gid));
int (*_get_group) __P ((mailbox_t, gid_t *gid));
/* private */
int (*_delete) __P ((mailbox_t, size_t msgno));
int (*_undelete) __P ((mailbox_t, size_t msgno));
int (*_is_deleted) __P ((mailbox_t, size_t msgno));
int (*_num_deleted) __P ((mailbox_t, size_t *));
int (*_get_size) __P ((mailbox_t, size_t msgno,
size_t *h, size_t *b));
/* miscellany */
int (*_size) __P ((mailbox_t, off_t *size));
int (*_get_timeout) __P ((mailbox_t, size_t *timeout));
int (*_set_timeout) __P ((mailbox_t, size_t timeout));
int (*_get_refresh) __P ((mailbox_t, size_t *refresh));
int (*_set_refresh) __P ((mailbox_t, size_t refresh));
int (*_set_notification) __P ((mailbox_t,
int (*func) __P ((mailbox_t, void * arg))));
ssize_t (*_get_header) __P ((mailbox_t, size_t msgno, char *h,
size_t len, off_t off, int *err));
ssize_t (*_get_body) __P ((mailbox_t, size_t msgno, char *b,
size_t len, off_t off, int *err));
};
/* private */
extern int mailbox_delete __P ((mailbox_t, size_t msgno));
extern int mailbox_undelete __P ((mailbox_t, size_t msgno));
extern int mailbox_is_deleted __P ((mailbox_t, size_t msgno));
extern int mailbox_num_deleted __P ((mailbox_t, size_t *));
extern int mailbox_get_size __P ((mailbox_t, size_t msgno,
size_t *h, size_t *b));
extern ssize_t mailbox_get_header __P ((mailbox_t, size_t msgno, char *h,
size_t len, off_t off, int *err));
extern ssize_t mailbox_get_body __P ((mailbox_t, size_t msgno, char *b,
size_t len, off_t off, int *err));
extern int mailbox_get_auth __P ((mailbox_t mbox, auth_t *auth));
extern int mailbox_set_auth __P ((mailbox_t mbox, auth_t auth));
extern int mailbox_get_locker __P ((mailbox_t mbox, locker_t *locker));
extern int mailbox_set_locker __P ((mailbox_t mbox, locker_t locker));
extern int mailbox_progress __P ((mailbox_t mbox,
int (*progress) (int, void *arg),
void *arg));
#ifdef MU_USE_MACROS
#define mailbox_open(m, f) m->_open (m, f)
#define mailbox_close(m) m->_close (m)
/* type */
#define mailbox_get_name(m, t, d, l, n) m->_get_name (m, t, d, l, n)
#define mailbox_get_mtype(m, t, d, n) m->_get_mtype (m, t, d, n)
/* passwd */
#define mailbox_get_passwd(m, p, l, n) m->_get_passwd (m, p, l, n)
#define mailbox_get_mpasswd(m, p, n) m->_get_mpasswd (m, p, n)
#define mailbox_set_passwd(m, p, l) m->_set_passwd (m, p, l)
/* deleting */
#define mailbox_delete(m, mid) m->_delete (m, mid)
#define mailbox_undelete(m, mid) m->_undelete (m, mid)
#define mailbox_is_deleted(m, mid) m->_is_deleted (m, mid)
#define mailbox_expunge(m) m->_expunge (m)
/* appending */
#define mailbox_new_msg(m, mid) m->_new_msg (m, mid)
#define mailbox_set_header(m, mid, h, l, r) m->_set_header(m, mid, h, n, r)
#define mailbox_set_body(m, mid, b, l r) m->_set_body (m, mid, b, l, r)
#define mailbox_append(m, mid) m->_append (m, mid)
#define mailbox_destroy_msg(m, mid) m->_destroy_msg (m, mid)
/* locking */
#define mailbox_lock(m, f) m->_lock (m, f)
#define mailbox_unlock(m) m->_unlock (m)
/* reading */
#define mailbox_get_header(m, mid, h, l, n) m->_get_header (m, mid, h, o, n)
#define mailbox_get_mheader(m, mid, h, l) m->_get_header (m, mid, h, l)
#define mailbox_get_body(m, mid, b, l, n) m->_get_body (m, mid, b, l, n)
#define mailbox_get_mbody(m, mid, b, n) m->_get_body (m, mid, b, n)
/* owner and group */
#define mailbox_set_owner(m, uid) m->_set_owner(m, uid)
#define mailbox_get_owner(m, uid) m->_set_owner(m, uid)
#define mailbox_set_group(m, gid) m->_set_group(m, gid)
#define mailbox_get_group(m, gid) m->_set_group(m, gid)
/* miscellany */
#define mailbox_scan(m, t) m->_scan (m, t)
#define mailbox_is_updated(m) m->_is_updated (m)
#define mailbox_get_timeout(m, t) m->_get_timeout (m, t)
#define mailbox_set_timeout(m, t) m->_set_timeout (m, t)
#define mailbox_get_refresh(m, r) m->_get_refresh (m, r)
#define mailbox_set_refresh(m, r) m->_set_refresh (m, r)
#define mailbox_get_size(m, mid, sh, sb) m->_get_size(m, mid, sh, sb)
#define mailbox_set_notification(m, func) m->_set_notification (m, func)
#endif /* MU_USE_MACROS */
#ifdef __cplusplus
}
......
......@@ -15,15 +15,17 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <mbx_imap.h>
#include <url_imap.h>
#include <mailbox0.h>
#include <registrar0.h>
#include <errno.h>
struct mailbox_type _mailbox_imap_type =
static int mailbox_imap_init (mailbox_t *mbox, const char *name);
static void mailbox_imap_destroy (mailbox_t *mbox);
struct mailbox_registrar _mailbox_imap_registrar =
{
"IMAP4",
(int)&_url_imap_type, &_url_imap_type,
mailbox_imap_init, mailbox_imap_destroy
};
......
......@@ -15,24 +15,19 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <mailbox0.h>
#include <registrar0.h>
#include <url_mbox.h>
#include <mbx_mbox.h>
#include <mbx_unix.h>
#include <mbx_mdir.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
struct mailbox_type _mailbox_mbox_type =
static int mailbox_mbox_init (mailbox_t *mbox, const char *name);
static void mailbox_mbox_destroy (mailbox_t *mbox);
struct mailbox_registrar _mailbox_mbox_registrar =
{
"UNIX_MBOX/Maildir/MMDF",
(int)&_url_mbox_type, &_url_mbox_type,
mailbox_mbox_init, mailbox_mbox_destroy
};
......@@ -49,7 +44,7 @@ struct mailbox_type _mailbox_mbox_type =
mailbox.
*/
int
static int
mailbox_mbox_init (mailbox_t *mbox, const char *name)
{
struct stat st;
......@@ -65,9 +60,7 @@ mailbox_mbox_init (mailbox_t *mbox, const char *name)
What is the best course of action ??
*/
if (stat (name, &st) < 0)
{
return errno; /* errno set by stat () */
}
return _mailbox_unix_registrar._init (mbox, name);
if (S_ISREG (st.st_mode))
{
......@@ -99,7 +92,7 @@ mailbox_mbox_init (mailbox_t *mbox, const char *name)
if (count == 0) /*empty file*/
{
close (fd);
return mailbox_unix_init (mbox, name);
return _mailbox_unix_registrar._init (mbox, name);
}
if (count >= 5)
......@@ -108,27 +101,26 @@ mailbox_mbox_init (mailbox_t *mbox, const char *name)
{
/* This is Unix Mbox */
close (fd);
return mailbox_unix_init (mbox, name);
return _mailbox_unix_registrar._init (mbox, name);
}
}
/* Try MMDF */
close (fd);
#endif
return mailbox_unix_init (mbox, name);
return _mailbox_unix_registrar._init (mbox, name);
}
/* Is that true ? Are all directories Maildir ?? */
else if (S_ISDIR (st.st_mode))
{
/* Is that true ? Are all directories Maildir ?? */
return mailbox_maildir_init (mbox, name);
}
return _mailbox_maildir_registrar._init (mbox, name);
/* Why can't a mailbox be FIFO ? or a DOOR/Portal ? */
/* Why can't a mailbox be FIFO ? or a DOOR/Portal ??? */
return EINVAL;
}
void
mailbox_mbox_destroy (mailbox_t *mbox)
static void
mailbox_mbox_destroy (mailbox_t *pmbox)
{
(*mbox)->mtype->_destroy (mbox);
if (pmbox && *pmbox)
_mailbox_unix_registrar._destroy (pmbox);
}
......
......@@ -15,14 +15,16 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <url_mdir.h>
#include <mbx_mdir.h>
#include <mailbox0.h>
#include <registrar0.h>
#include <errno.h>
struct mailbox_type _mailbox_maildir_type =
static int mailbox_maildir_init (mailbox_t *mbox, const char *name);
static void mailbox_maildir_destroy (mailbox_t *mbox);
struct mailbox_registrar _mailbox_maildir_registrar =
{
"MAILDIR",
(int)&_url_maildir_type, &_url_maildir_type,
mailbox_maildir_init, mailbox_maildir_destroy
};
......
......@@ -10,15 +10,13 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
*
* You should have received a copy of the GNU Library General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <mailbox0.h>
#include <registrar0.h>
#include <dirent.h>
#include <errno.h>
......@@ -26,13 +24,15 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
typedef int _url_mh_type;
static int mailbox_mh_init (mailbox_t *pmbox, const char *name);
static void mailbox_mh_destroy (mailbox_t *pmbox);
struct mailbox_type _mailbox_mh_type =
struct mailbox_registrar _mailbox_mh_registrar =
{
"MH"
(int)&_url_mh_type, &_url_mh_type,
"MH",
mailbox_mh_init, mailbox_mh_destroy
};
......@@ -41,9 +41,12 @@ typedef struct _mh_data
time_t mtime; /* used for checking if mailbox was updated */
} mh_data;
static int mh_open (mailbox_t mbox, int flags);
static int mh_close (mailbox_t mbox);
static int mh_scan (mailbox_t mbox, size_t *msgs);
static int mh_sequence(const char *name);
int
static int
mailbox_mh_init (mailbox_t *pmbox, const char *name)
{
mailbox_t mbox;
......@@ -54,12 +57,16 @@ mailbox_mh_init (mailbox_t *pmbox, const char *name)
mbox->name = malloc(strlen(name) + 1);
strcpy(mbox->name, name);
mbox->data = data;
mbox->_init = mailbox_mh_init;
mbox->_destroy = mailbox_mh_destroy;
mbox->_open = mh_open;
mbox->_close = mh_close;
*pmbox = mbox;
return 0;
}
void
static void
mailbox_mh_destroy (mailbox_t *pmbox)
{
free((*pmbox)->data);
......@@ -77,6 +84,7 @@ mh_open (mailbox_t mbox, int flags)
struct stat st;
mh_data *data;
(void) flags;
if (stat(mbox->name, &st) == -1)
return errno;
......@@ -141,8 +149,9 @@ mh_scan (mailbox_t mbox, size_t *msgs)
closedir(maildir);
if(parse_sequence_file && count) {
FILE *fp;
char *path = malloc(strlen(mbox->name) + strlen(".mh_sequences") + 2);
sprintf(path, "%s/.mh_sequences", mbox->name);
sprintf(path, "%s/.mh_sequences", mbox->name);
fp = fopen(path, "r");
while(!feof(fp)) {
/* FIXME: parse the contents */
......@@ -159,7 +168,7 @@ mh_scan (mailbox_t mbox, size_t *msgs)
return 0;
}
/*
/*
* Local atoi()
* created this to guarantee that name is only digits, normal atoi allows
* whitespace
......@@ -167,7 +176,7 @@ mh_scan (mailbox_t mbox, size_t *msgs)
static int
mh_sequence(const char *name)
{
char *sequence;
const char *sequence;
int i;
for(i = 0, sequence = name; *sequence; sequence++) {
......
......@@ -15,25 +15,28 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <url_mmdf.h>
#include <mbx_mmdf.h>
#include <mailbox0.h>
#include <registrar0.h>
#include <errno.h>
struct mailbox_type _mailbox_mmdf_type =
static int mailbox_mmdf_init (mailbox_t *mbox, const char *name);
static void mailbox_mmdf_destroy (mailbox_t *mbox);
struct mailbox_registrar _mailbox_mmdf_registrar =
{
"MMDF",
(int)&_url_mmdf_type, &_url_mmdf_type,
mailbox_mmdf_init, mailbox_mmdf_destroy
};
int
static int
mailbox_mmdf_init (mailbox_t *mbox, const char *name)
{
(void)mbox; (void)name;
return ENOSYS;
}
void
static void
mailbox_mmdf_destroy (mailbox_t *mbox)
{
(void)mbox;
......
......@@ -15,25 +15,28 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <url_pop.h>
#include <mbx_pop.h>
#include <mailbox0.h>
#include <registrar0.h>
#include <errno.h>
struct mailbox_type _mailbox_pop_type =
static int mailbox_pop_init (mailbox_t *mbox, const char *name);
static void mailbox_pop_destroy (mailbox_t *mbox);
struct mailbox_registrar _mailbox_pop_registrar =
{
"POP3",
(int)&_url_pop_type, &_url_pop_type,
mailbox_pop_init, mailbox_pop_destroy
};
void
static void
mailbox_pop_destroy (mailbox_t *mbox)
{
(void)mbox;
return;
}
int
static int
mailbox_pop_init (mailbox_t *mbox, const char *name)
{
(void)mbox; (void)name;
......