Commit e6bd6bed e6bd6bed52a1036ae5ca1a5df962e1ce99b5dca7 by Alain Magloire

mailbox.c mailbox.h mbx_imap.c mbx_imap.h mbx_pop.c mbx_pop.h

cleanup.
 Added Files:
 	mbx_mbox.c mbx_mbox.h
cleanup.
1 parent 42040290
......@@ -19,7 +19,7 @@
#include <config.h>
#endif
#include <mbx_unix.h>
#include <mbx_mbox.h>
#include <mbx_pop.h>
#include <mbx_imap.h>
......@@ -70,7 +70,9 @@ static int mbx_get_timeout (mailbox_t, int *timeout);
static int mbx_set_timeout (mailbox_t, int timeout);
static int mbx_get_refresh (mailbox_t, int *refresh);
static int mbx_set_refresh (mailbox_t, int refresh);
static int mbx_set_notification (mailbox_t, int (*notif) (mailbox_t));
static int mbx_get_size (mailbox_t, int id, size_t *size);
static int mbx_set_notification (mailbox_t,
int (*func) (mailbox_t, void *arg));
/* init all the functions to a default value */
static void mbx_check_struct (mailbox_t);
......@@ -82,12 +84,12 @@ static void mbx_check_struct (mailbox_t);
FIXME: not thread-safe. */
static struct mailbox_builtin
{
const struct mailbox_type *mtype;
struct mailbox_type *mtype;
int is_malloc;
struct mailbox_builtin * next;
} mailbox_builtin [] = {
{ NULL, 0, &url_builtin[1] }, /* sentinel, head list */
{ &_mailbox_unix_type, 0, &mailbox_builtin[2] },
{ NULL, 0, &mailbox_builtin[1] }, /* sentinel, head list */
{ &_mailbox_mbox_type, 0, &mailbox_builtin[2] },
{ &_mailbox_pop_type, 0, &mailbox_builtin[3] },
{ &_mailbox_imap_type, 0, &mailbox_builtin[0] },
};
......@@ -105,7 +107,7 @@ malibox_add_type (struct mailbox_type *mtype)
free (current);
return -1;
}
mtype->id = url_get_id (mtype->utype); /* same ID as the url_tupe */
mtype->id = mtype->utype->id; /* same ID as the url_type */
}
else
{
......@@ -119,7 +121,7 @@ malibox_add_type (struct mailbox_type *mtype)
}
int
mailbox_remove_type (const struct mailbox_type *mtype)
mailbox_remove_type (struct mailbox_type *mtype)
{
struct mailbox_builtin *current, *previous;
for (previous = mailbox_builtin, current = mailbox_builtin->next;
......@@ -153,7 +155,7 @@ mailbox_list_type (struct mailbox_type *list, int n)
}
int
mailbox_list_mtype (struct url_type **mlist, int *n)
mailbox_list_mtype (struct mailbox_type **mlist, int *n)
{
struct mailbox_type *mtype;
int i;
......@@ -167,13 +169,13 @@ mailbox_list_mtype (struct url_type **mlist, int *n)
}
int
mailbox_get_type (struct mailbox_type * const *mtype, int id)
mailbox_get_type (struct mailbox_type **mtype, int id)
{
struct mailbox_builtin *current;
for (current = mailbox_builtin->next; current != mailbox_builtin;
current = current->next)
{
if (current->mtype->type == type)
if (current->mtype->id == id)
{
*mtype = current->mtype;
return 0;;
......@@ -218,7 +220,7 @@ mailbox_init (mailbox_t *mbox, const char *name, int id)
if (status == 0)
mbx_check_struct (*mbox);
}
url_destroy (url);
url_destroy (&url);
}
}
......@@ -226,7 +228,7 @@ mailbox_init (mailbox_t *mbox, const char *name, int id)
this should take care of the case where the filename is use */
if (status != 0 )
{
status = mailbox_unix_init (mbox, name);
status = mailbox_mbox_init (mbox, name);
if (status == 0)
mbx_check_struct (*mbox);
}
......@@ -234,9 +236,10 @@ mailbox_init (mailbox_t *mbox, const char *name, int id)
}
void
mailbox_destroy (mailbox_t * mbox)
mailbox_destroy (mailbox_t *mbox)
{
return mbox->_destroy (mbox);
struct mailbox_type *mtype = (*mbox)->mtype;
return mtype->_destroy (mbox);
}
/* -------------- stub functions ------------------- */
......@@ -244,22 +247,22 @@ static void
mbx_check_struct (mailbox_t mbox)
{
if (mbox->_open == NULL)
mbox->open = mbx_open;
mbox->_open = mbx_open;
if (mbox->_close == NULL)
mbox->close = mbx_close;
mbox->_close = mbx_close;
if (mbox->_get_name == NULL)
mbox->_get_name = mbx_get_name;
if (mbox->_get_passwd == NULL)
mbox->_get_passw = mbx_get_passwd;
mbox->_get_passwd = mbx_get_passwd;
if (mbox->_get_mpasswd == NULL)
mbox->_get_mpasswd = mbx_getmpasswd;
mbox->_get_mpasswd = mbx_get_mpasswd;
if (mbox->_set_passwd == NULL)
mbox->_set_passwd == mbx_set_passwd;
mbox->_set_passwd = mbx_set_passwd;
if (mbox->_delete == NULL)
mbox->_delete = mbx_delete;
......@@ -324,6 +327,9 @@ mbx_check_struct (mailbox_t mbox)
if (mbox->_set_refresh == NULL)
mbox->_set_refresh = mbx_set_refresh;
if (mbox->_get_size == NULL)
mbox->_get_size = mbx_get_size;
if (mbox->_set_notification == NULL)
mbox->_set_notification = mbx_set_notification;
......@@ -365,7 +371,8 @@ mbx_get_mpasswd (mailbox_t mbox, char **passwd, int *len)
{
int i;
char *p;
if ((i = mbox->_get_passwd (NULL, 0)) <= 0 || (p = malloc (i)) == NULL)
if ((i = mbox->_get_passwd (mbox, NULL, 0, 0)) <= 0
|| (p = malloc (i)) == NULL)
{
return -1;
}
......@@ -461,7 +468,8 @@ mbx_get_mbody (mailbox_t mbox, int id, char **body, int *len)
{
int i;
char *b;
if ((i = mbox->_get_body (NULL, 0)) <= 0 || (b = malloc (i)) == NULL)
if ((i = mbox->_get_body (mbox, id, NULL, 0, 0)) <= 0
|| (b = malloc (i)) == NULL)
{
return -1;
}
......@@ -481,7 +489,8 @@ mbx_get_mheader (mailbox_t mbox, int id, char **header, int *len)
{
int i;
char *h;
if ((i = mbox->_get_header (NULL, 0)) <= 0 || (h = malloc (i)) == NULL)
if ((i = mbox->_get_header (mbox, id, NULL, 0, 0)) <= 0
|| (h = malloc (i)) == NULL)
{
return -1;
}
......@@ -548,6 +557,13 @@ mbx_set_refresh (mailbox_t mbox, int refresh)
}
static int
mbx_get_size (mailbox_t mbox, int id, size_t *size)
{
errno = ENOSYS;
return -1;
}
static int
mbx_set_notification (mailbox_t mbox, int (*func) (mailbox_t, void *arg))
{
errno = ENOSYS;
......
......@@ -19,6 +19,7 @@
# define _MAILBOX_H
#include <url.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
......@@ -44,8 +45,8 @@ struct mailbox_type
char *name;
int id;
struct url_type *utype;
int (*_init) __P ((mailbox_t *, const char *name, int id));
int (*_destroy) __P ((mailbox_t *);
int (*_init) __P ((mailbox_t *, const char *name));
void (*_destroy) __P ((mailbox_t *));
};
struct _mailbox
......@@ -58,27 +59,27 @@ struct _mailbox
int timeout;
int refresh;
mailbox_lock_t lock;
int (*notif) __P ((mailbox_t));
int (*func) __P ((mailbox_t));
void *data;
struct mailbox_type *mtype;
/* Functions */
void (*_destroy) __P ((maibox_t *));
//void (*_destroy) __P ((mailbox_t *));
int (*_open) __P ((mailbox_t, int flag));
int (*_close) __P ((mailbox_t, int flag));
/* type */
int (*_get_name) __P ((mailbox_t, int *type, char *desc,
int (*_get_name) __P ((mailbox_t, int *id, char *name,
int offset, int len));
int (*_get_mtype) __P ((mailbox_t, int *type, char **desc,
int (*_get_mname) __P ((mailbox_t, int *id, char **name,
int *len));
/* passwd if needed */
int (*_get_passwd) __P ((mailbox_t, char * passwd, int offset, int n));
int (*_get_mpasswd) __P ((mailbox_t, char ** passwd, int *n));
int (*_get_mpasswd) __P ((mailbox_t, char **passwd, int *n));
int (*_set_passwd) __P ((mailbox_t, const char * passwd,
int offset, int n));
/* deleting mesgs */
......@@ -108,15 +109,22 @@ struct _mailbox
int offset, int n));
int (*_get_mheader) __P ((mailbox_t, int id, char **h, int *n));
/* misc */
/* setting flags */
int (*_msg_is_read) __P ((mailbox_t, int id));
int (*_msg_set_read) __P ((mailbox_t, int id));
int (*_msg_is_seen) __P ((mailbox_t, int id));
int (*_msg_set_seen) __P ((mailbox_t, int id));
/* miscellany */
int (*_scan) __P ((mailbox_t, int *msgs));
int (*_is_updated) __P ((mailbox_t));
int (*_get_timeout) __P ((mailbox_t, int *timeout));
int (*_set_timeout) __P ((mailbox_t, int timeout));
int (*_get_size) __P ((mailbox_t, int id, long *size));
int (*_get_size) __P ((mailbox_t, int id, size_t *size));
int (*_get_refresh) __P ((mailbox_t, int *refresh));
int (*_set_refresh) __P ((mailbox_t, int refresh));
int (*_set_notification) __P ((mailbox_t, int (*notif) __P ((mailbox_t))));
int (*_set_notification) __P ((mailbox_t,
int (*func) __P ((mailbox_t, void * arg))));
};
/* constructor/destructor and possible types */
......@@ -125,11 +133,10 @@ extern void mailbox_destroy __P ((mailbox_t *));
/* mailbox registration */
extern int mailbox_list_type __P ((struct mailbox_type mtype[], int size));
extern int mailbox_list_mtype __P ((struct mailbox_type **mtype, int *size));
extern int mailbox_add_type __P ((struct mailbox_type *mlist));
extern int mailbox_remove_type __P ((const struct mailbox_type *mlist));
extern int mailbox_get_type __P ((struct mailbox_type * const *mtype,
int id));
extern int mailbox_list_mtype __P ((struct mailbox_type *mtype[], int *size));
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__
......@@ -143,17 +150,17 @@ extern INLINE int mailbox_open __P ((mailbox_t, int flag));
extern INLINE int mailbox_close __P ((mailbox_t, int flag));
/* type */
extern INLINE int mailbox_get_name __P ((mailbox_t, int *type, char *desc,
extern INLINE int mailbox_get_name __P ((mailbox_t, int *id, char *name,
int offset, int len));
extern INLINE int mailbox_get_mname __P ((mailbox_t, int *type, char **desc,
extern INLINE int mailbox_get_mname __P ((mailbox_t, int *id, char **name,
int *len));
/* passwd */
extern INLINE int mailbox_get_passwd __P ((mailbox_t, char * passwd,
extern INLINE int mailbox_get_passwd __P ((mailbox_t, char *passwd,
int offset, int len));
extern INLINE int mailbox_get_mpasswd __P ((mailbox_t, char ** passwd,
extern INLINE int mailbox_get_mpasswd __P ((mailbox_t, char **passwd,
int *len));
extern INLINE int mailbox_set_passwd __P ((mailbox_t, const char * passwd,
extern INLINE int mailbox_set_passwd __P ((mailbox_t, const char *passwd,
int offset, int len));
/* deleting */
......@@ -185,15 +192,16 @@ extern INLINE int mailbox_get_mheader __P ((mailbox_t, int id, char **h,
extern INLINE int mailbox_lock __P ((mailbox_t, int flag));
extern INLINE int mailbox_unlock __P ((mailbox_t));
/* misc */
/* miscellany */
extern INLINE int mailbox_scan __P ((mailbox_t, int *msgs));
extern INLINE int mailbox_is_updated __P ((mailbox_t));
extern INLINE int mailbox_get_timeout __P ((mailbox_t, int *timeout));
extern INLINE int mailbox_set_timeout __P ((mailbox_t, int timeout));
extern INLINE int mailbox_get_refresh __P ((mailbox_t, int *refresh));
extern INLINE int mailbox_set_refresh __P ((mailbox_t, int refresh));
extern INLINE int mailbox_get_size __P ((mailbox_t, int id, size_t *size));
extern INLINE int mailbox_set_notification __P ((mailbox_t, int
(*notif) __P ((mailbox_t))));
(*func) __P ((mailbox_t))));
#ifdef MU_USE_MACROS
#define mailbox_open(m, f) m->_open (m, f)
......@@ -231,14 +239,15 @@ extern INLINE int mailbox_set_notification __P ((mailbox_t, int
#define mailbox_get_body(m, id, b, o, n) m->_get_body (m, id, b, o, n)
#define mailbox_get_mbody(m, id, b, n) m->_get_body (m, id, b, n)
/* misc */
/* 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_set_notification(m, notif) m->_set_notification (m, notif)
#define mailbox_get_size(m, id, size) m->_get_size(m, id, size)
#define mailbox_set_notification(m, func) m->_set_notification (m, func)
#endif /* MU_USE_MACROS */
#ifdef __cplusplus
......
......@@ -16,16 +16,17 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <mbx_imap.h>
#include <url_imap.h>
struct mailbox_type _mailbox_imap_type =
{
"IMAP",
"IMAP4",
(int)&_url_imap_type, &_url_imap_type,
mailbox_imap_init, mailbox_imap_destroy
};
int
void
mailbox_imap_destroy (mailbox_t *mbox)
{
return;
......
......@@ -21,7 +21,7 @@
#include <mailbox.h>
extern int mailbox_imap_init __P ((mailbox_t *mbox, const char *name));
extern int mailbox_imap_destroy __P ((mailbox_t *mbox));
extern void mailbox_imap_destroy __P ((mailbox_t *mbox));
extern struct mailbox_type _mailbox_imap_type;
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
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 <url_mbox.h>
#include <mbx_mbox.h>
#include <mbx_unix.h>
#include <mbx_mdir.h>
struct mailbox_type _mailbox_mbox_type =
{
"UNIX MBOX",
(int)&_url_mbox_type, &_url_mbox_type,
mailbox_mbox_init, mailbox_mbox_destroy
};
/*
There is no specific URL for file mailbox, until we
come up with a url for each like :
maildir://
mmdf://
ubox://
they all share the same url which is
file://<path_name> */
int
mailbox_mbox_init (mailbox_t *mbox, const char *name)
{
return -1;
}
void
mailbox_mbox_destroy (mailbox_t *mbox)
{
return ;
}
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
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. */
#ifndef _MBX_UNIX_H
#define _MBX_UNIX_H 1
#include <mailbox.h>
#include <stdlib.h>
#include <stdio.h>
extern int mailbox_mbox_init __P ((mailbox_t *mbox, const char *name));
extern void mailbox_mbox_destroy __P ((mailbox_t *mbox));
extern struct mailbox_type _mailbox_mbox_type;
#endif /* _MBX_UNIX_H */
......@@ -15,11 +15,12 @@
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>
struct mailbox_type _mailbox_pop_type =
{
"POP",
"POP3",
(int)&_url_pop_type, &_url_pop_type,
mailbox_pop_init, mailbox_pop_destroy
};
......@@ -31,7 +32,7 @@ mailbox_pop_destroy (mailbox_t *mbox)
}
int
mailbox_pop_init (mailbox_t *mbox)
mailbox_pop_init (mailbox_t *mbox, const char *name)
{
return -1;
}
......
......@@ -21,7 +21,7 @@
#include <mailbox.h>
extern int mailbox_pop_init __P ((mailbox_t *mbox, const char *name));
extern int mailbox_pop_destroy __P ((mailbox_t *mbox));
extern void mailbox_pop_destroy __P ((mailbox_t *mbox));
extern struct mailbox_type _mailbox_pop_type;
......