From: Pierre Habouzit Date: Sat, 18 Nov 2006 18:15:58 +0000 (+0100) Subject: remove mx_{pop,nntp,imap}.[hc] X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=ac1ea3143e61def7fc9000bee6d0d59d56c5b997 remove mx_{pop,nntp,imap}.[hc] those prevented good modularization. Signed-off-by: Pierre Habouzit --- diff --git a/browser.c b/browser.c index 8ff73d8..676aca9 100644 --- a/browser.c +++ b/browser.c @@ -26,7 +26,6 @@ #include "attach.h" #include -#include #ifdef USE_NNTP #include "nntp.h" #endif diff --git a/imap/Makefile.am b/imap/Makefile.am index dda0b6a..8396aac 100644 --- a/imap/Makefile.am +++ b/imap/Makefile.am @@ -9,9 +9,9 @@ EXTRA_DIST = BUGS README TODO auth_anon.c auth_cram.c auth_gss.c auth_sasl.c INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/intl noinst_LIBRARIES = libimap.a -noinst_HEADERS = auth.h imap_private.h message.h mx_imap.h +noinst_HEADERS = auth.h imap_private.h message.h -libimap_a_SOURCES = auth.c auth_login.c browse.c command.c imap.c imap.h mx_imap.h \ - message.c utf7.c util.c mx_imap.c $(AUTHENTICATORS) auth_gss.c +libimap_a_SOURCES = auth.c auth_login.c browse.c command.c imap.c imap.h \ + message.c utf7.c util.c $(AUTHENTICATORS) auth_gss.c -include ../cflags.mk diff --git a/imap/imap.c b/imap/imap.c index fe99c06..dcaccd1 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -36,7 +36,7 @@ static void imap_set_flag (IMAP_DATA * idata, int aclbit, int flag, /* imap_access: Check permissions on an IMAP mailbox. * TODO: ACL checks. Right now we assume if it exists we can * mess with it. */ -int imap_access (const char *path, int flags __attribute__ ((unused))) +static int imap_access (const char *path, int flags __attribute__ ((unused))) { IMAP_DATA *idata; IMAP_MBOX mx; @@ -488,7 +488,7 @@ static char *imap_get_flags (string_list_t ** hflags, char *s) return s; } -int imap_open_mailbox (CONTEXT * ctx) +static int imap_open_mailbox (CONTEXT * ctx) { CONNECTION *conn; IMAP_DATA *idata; @@ -992,7 +992,7 @@ out: } /* imap_close_mailbox: clean up IMAP data in CONTEXT */ -void imap_close_mailbox (CONTEXT * ctx) +static void imap_close_mailbox (CONTEXT * ctx) { IMAP_DATA *idata; int i; @@ -1580,3 +1580,62 @@ int imap_reconnect (CONTEXT * ctx) mx_open_mailbox (ctx->path, 0, ctx); return 0; } + +int imap_is_magic (const char* path, struct stat* st __attribute__ ((unused))) { + url_scheme_t s; + if (!path || !*path) + return (-1); + s = url_check_scheme (NONULL (path)); + return ((s == U_IMAP || s == U_IMAPS) ? M_IMAP : -1); +} + +static int acl_check_imap (CONTEXT* ctx, int bit) { + return (!mutt_bit_isset (((IMAP_DATA*) ctx->data)->capabilities, ACL) || + mutt_bit_isset (((IMAP_DATA*) ctx->data)->rights, bit)); +} + +static int imap_open_new_message (MESSAGE * msg, + CONTEXT * dest __attribute__ ((unused)), + HEADER * hdr __attribute__ ((unused))) +{ + char tmp[_POSIX_PATH_MAX]; + + mutt_mktemp (tmp); + if ((msg->fp = safe_fopen (tmp, "w")) == NULL) { + mutt_perror (tmp); + return (-1); + } + msg->path = m_strdup(tmp); + return 0; +} + +/* this ugly kludge is required since the last int to + * imap_check_mailbox() doesn't mean 'lock' but 'force'... */ +static int _imap_check_mailbox (CONTEXT* ctx, + int* index_hint, + int lock __attribute__ ((unused))) { + return (imap_check_mailbox (ctx, index_hint, 0)); +} + +static int imap_commit_message (MESSAGE* msg, CONTEXT* ctx) { + int r = 0; + + if ((r = safe_fclose (&msg->fp)) == 0) + r = imap_append_message (ctx, msg); + return (r); +} + +mx_t const imap_mx = { + M_IMAP, + 0, + imap_is_magic, + NULL, + imap_access, + imap_open_mailbox, + imap_open_new_message, + acl_check_imap, + _imap_check_mailbox, + imap_close_mailbox, + imap_sync_mailbox, + imap_commit_message, +}; diff --git a/imap/imap.h b/imap/imap.h index 6d661e6..3b634e0 100644 --- a/imap/imap.h +++ b/imap/imap.h @@ -15,6 +15,8 @@ #include "browser.h" #include "mx.h" +extern mx_t const imap_mx; + /* -- data structures -- */ typedef struct { ACCOUNT account; @@ -22,14 +24,12 @@ typedef struct { } IMAP_MBOX; /* imap.c */ -int imap_access (const char *, int); +int imap_is_magic(const char*, struct stat*); + int imap_check_mailbox (CONTEXT * ctx, int *index_hint, int force); int imap_delete_mailbox (CONTEXT * idata, IMAP_MBOX mx); -int imap_open_mailbox (CONTEXT * ctx); int imap_open_mailbox_append (CONTEXT * ctx); int imap_sync_mailbox (CONTEXT * ctx, int expunge, int *index_hint); -void imap_close_mailbox (CONTEXT * ctx); -int imap_buffy_check (char *path); int imap_mailbox_check (char *path, int new); int imap_search (CONTEXT* ctx, const pattern_t* pat); int imap_subscribe (char *path, int subscribe); @@ -52,7 +52,6 @@ int imap_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno); void imap_logout_all (void); /* util.c */ -int imap_expand_path (char *path, size_t len); int imap_parse_path (const char *path, IMAP_MBOX * mx); void imap_pretty_mailbox (char *path); diff --git a/imap/mx_imap.c b/imap/mx_imap.c deleted file mode 100644 index 17147e5..0000000 --- a/imap/mx_imap.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This file is part of mutt-ng, see http://www.muttng.org/. - * It's licensed under the GNU General Public License, - * please see the file GPL in the top level source directory. - */ - -#include - -#include "mutt.h" -#include "imap_private.h" - -#include "mx.h" -#include "mx_imap.h" - -int imap_is_magic (const char* path, struct stat* st __attribute__ ((unused))) { - url_scheme_t s; - if (!path || !*path) - return (-1); - s = url_check_scheme (NONULL (path)); - return ((s == U_IMAP || s == U_IMAPS) ? M_IMAP : -1); -} - -static int acl_check_imap (CONTEXT* ctx, int bit) { - return (!mutt_bit_isset (((IMAP_DATA*) ctx->data)->capabilities, ACL) || - mutt_bit_isset (((IMAP_DATA*) ctx->data)->rights, bit)); -} - -static int imap_open_new_message (MESSAGE * msg, - CONTEXT * dest __attribute__ ((unused)), - HEADER * hdr __attribute__ ((unused))) -{ - char tmp[_POSIX_PATH_MAX]; - - mutt_mktemp (tmp); - if ((msg->fp = safe_fopen (tmp, "w")) == NULL) { - mutt_perror (tmp); - return (-1); - } - msg->path = m_strdup(tmp); - return 0; -} - -/* this ugly kludge is required since the last int to - * imap_check_mailbox() doesn't mean 'lock' but 'force'... */ -static int _imap_check_mailbox (CONTEXT* ctx, - int* index_hint, - int lock __attribute__ ((unused))) { - return (imap_check_mailbox (ctx, index_hint, 0)); -} - -static int imap_commit_message (MESSAGE* msg, CONTEXT* ctx) { - int r = 0; - - if ((r = safe_fclose (&msg->fp)) == 0) - r = imap_append_message (ctx, msg); - return (r); -} - -mx_t const imap_mx = { - M_IMAP, - 0, - imap_is_magic, - NULL, - imap_access, - imap_open_mailbox, - imap_open_new_message, - acl_check_imap, - _imap_check_mailbox, - imap_close_mailbox, - imap_sync_mailbox, - imap_commit_message, -}; diff --git a/imap/mx_imap.h b/imap/mx_imap.h deleted file mode 100644 index f2e5ddd..0000000 --- a/imap/mx_imap.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * This file is part of mutt-ng, see http://www.muttng.org/. - * It's licensed under the GNU General Public License, - * please see the file GPL in the top level source directory. - */ - -/* - * interface of mx_t implementation for IMAP - */ - -#ifndef _IMAP_MX_H -#define _IMAP_MX_H - -#include "mx.h" - -extern mx_t const imap_mx; - -int imap_is_magic(const char*, struct stat*); - -#endif /* !_IMAP_MX_H */ diff --git a/imap/util.c b/imap/util.c index d7837e1..abcbe2b 100644 --- a/imap/util.c +++ b/imap/util.c @@ -22,31 +22,6 @@ /* -- public functions -- */ -/* imap_expand_path: IMAP implementation of mutt_expand_path. Rewrite - * an IMAP path in canonical and absolute form. - * Inputs: a buffer containing an IMAP path, and the number of bytes in - * that buffer. - * Outputs: The buffer is rewritten in place with the canonical IMAP path. - * Returns 0 on success, or -1 if imap_parse_path chokes or url_ciss_tostring - * fails, which it might if there isn't enough room in the buffer. */ -int imap_expand_path (char *path, size_t len) -{ - IMAP_MBOX mx; - ciss_url_t url; - int rc; - - if (imap_parse_path (path, &mx) < 0) - return -1; - - mutt_account_tourl (&mx.account, &url); - url.path = mx.mbox; - - rc = url_ciss_tostring (&url, path, len, U_DECODE_PASSWD); - p_delete(&mx.mbox); - - return rc; -} - /* imap_parse_path: given an IMAP mailbox name, return host, port * and a path IMAP servers will recognise. * mx.mbox is malloc'd, caller must free it */ diff --git a/muttlib.c b/muttlib.c index efb991b..caf5fd9 100644 --- a/muttlib.c +++ b/muttlib.c @@ -29,7 +29,6 @@ #include "version.h" #include -#include #include diff --git a/mx.c b/mx.c index 88537ab..6ee2be7 100644 --- a/mx.c +++ b/mx.c @@ -29,14 +29,10 @@ #include "dotlock.h" #include -#include - #include -#include #ifdef USE_NNTP -#include "nntp/nntp.h" -#include "nntp/mx_nntp.h" +#include #endif #include @@ -280,7 +276,6 @@ int mx_unlock_file (const char *path, int fd, int dot) static void mx_unlink_empty (const char *path) { int fd; - struct stat sb; if ((fd = open (path, O_RDWR)) == -1) return; diff --git a/nntp/Makefile.am b/nntp/Makefile.am index 8f3d7da..ca6d65b 100644 --- a/nntp/Makefile.am +++ b/nntp/Makefile.am @@ -7,9 +7,8 @@ AUTOMAKE_OPTIONS = foreign INCLUDES = -I$(top_srcdir) -I../intl noinst_LIBRARIES = libnntp.a -noinst_HEADERS = nntp.h mx_nntp.h +noinst_HEADERS = nntp.h -libnntp_a_SOURCES = nntp.h mx_nntp.h \ - nntp.c mx_nntp.c newsrc.c +libnntp_a_SOURCES = nntp.h nntp.c newsrc.c -include ../cflags.mk diff --git a/nntp/mx_nntp.c b/nntp/mx_nntp.c deleted file mode 100644 index 08eee9a..0000000 --- a/nntp/mx_nntp.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of mutt-ng, see http://www.muttng.org/. - * It's licensed under the GNU General Public License, - * please see the file GPL in the top level source directory. - */ - -#include - -#include "mutt.h" -#include "nntp.h" - -#include "mx.h" -#include "mx_nntp.h" - -static int nntp_is_magic (const char* path, struct stat* st) { - url_scheme_t s = url_check_scheme (NONULL (path)); - return ((s == U_NNTP || s == U_NNTPS) ? M_NNTP : -1); -} - -static int acl_check_nntp (CONTEXT* ctx, int bit) { - switch (bit) { - case ACL_INSERT: /* editing messages */ - case ACL_WRITE: /* change importance */ - return (0); - case ACL_DELETE: /* (un)deletion */ - case ACL_SEEN: /* mark as read */ - return (1); - default: - return (0); - } -} - -mx_t const nntp_mx = { - M_NNTP, - 0, - nntp_is_magic, - NULL, - NULL, - nntp_open_mailbox, - NULL, - acl_check_nntp, - nntp_check_mailbox, - nntp_fastclose_mailbox, - nntp_sync_mailbox, - NULL, -}; diff --git a/nntp/mx_nntp.h b/nntp/mx_nntp.h deleted file mode 100644 index 9e44ca1..0000000 --- a/nntp/mx_nntp.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * This file is part of mutt-ng, see http://www.muttng.org/. - * It's licensed under the GNU General Public License, - * please see the file GPL in the top level source directory. - */ - -/* - * interface of mx_t implementation for NNTP - */ - -#ifndef _NNTP_MX_H -#define _NNTP_MX_H - -#include "mx.h" - -extern mx_t const nntp_mx; - -#endif /* !_NNTP_MX_H */ diff --git a/nntp/nntp.c b/nntp/nntp.c index 32f40c6..e24857a 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -18,7 +18,6 @@ #include "mutt.h" #include "sort.h" #include "mx.h" -#include "mx_nntp.h" #include "nntp.h" #include "buffy.h" @@ -802,7 +801,7 @@ static int nntp_fetch_headers (CONTEXT * ctx, unsigned int first, /* * currently, nntp "mailbox" is "newsgroup" */ -int nntp_open_mailbox (CONTEXT * ctx) +static int nntp_open_mailbox (CONTEXT * ctx) { NNTP_DATA *nntp_data; NNTP_SERVER *serv; @@ -1089,7 +1088,7 @@ void nntp_delete_data (void *p) p_delete(&data); } -int nntp_sync_mailbox (CONTEXT * ctx, int unused1, int* unused2) +static int nntp_sync_mailbox (CONTEXT * ctx, int unused1, int* unused2) { NNTP_DATA *data = ctx->data; @@ -1102,7 +1101,7 @@ int nntp_sync_mailbox (CONTEXT * ctx, int unused1, int* unused2) return 0; } -void nntp_fastclose_mailbox (CONTEXT * ctx) +static void nntp_fastclose_mailbox (CONTEXT * ctx) { NNTP_DATA *data = (NNTP_DATA *) ctx->data, *tmp; @@ -1204,7 +1203,7 @@ static int _nntp_check_mailbox (CONTEXT * ctx, NNTP_DATA * nntp_data) return 0; } -int nntp_check_mailbox (CONTEXT * ctx, int* unused1, int unused2) +static int nntp_check_mailbox (CONTEXT * ctx, int* unused1, int unused2) { return _nntp_check_mailbox (ctx, (NNTP_DATA *) ctx->data); } @@ -1501,3 +1500,36 @@ int nntp_check_children (CONTEXT * ctx, const char *msgid) p_delete(&cc.child); return ret; } + +static int nntp_is_magic (const char* path, struct stat* st) { + url_scheme_t s = url_check_scheme (NONULL (path)); + return ((s == U_NNTP || s == U_NNTPS) ? M_NNTP : -1); +} + +static int acl_check_nntp (CONTEXT* ctx, int bit) { + switch (bit) { + case ACL_INSERT: /* editing messages */ + case ACL_WRITE: /* change importance */ + return (0); + case ACL_DELETE: /* (un)deletion */ + case ACL_SEEN: /* mark as read */ + return (1); + default: + return (0); + } +} + +mx_t const nntp_mx = { + M_NNTP, + 0, + nntp_is_magic, + NULL, + NULL, + nntp_open_mailbox, + NULL, + acl_check_nntp, + nntp_check_mailbox, + nntp_fastclose_mailbox, + nntp_sync_mailbox, + NULL, +}; diff --git a/nntp/nntp.h b/nntp/nntp.h index 3e89c39..90e2bf1 100644 --- a/nntp/nntp.h +++ b/nntp/nntp.h @@ -15,6 +15,8 @@ #include #include "mx.h" +extern mx_t const nntp_mx; + #define NNTP_PORT 119 #define NNTP_SSL_PORT 563 @@ -100,11 +102,7 @@ NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER *, char *); NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER *, char *); void nntp_clear_cacheindex (NNTP_SERVER *); int mutt_newsrc_update (NNTP_SERVER *); -int nntp_open_mailbox (CONTEXT *); -int nntp_sync_mailbox (CONTEXT *, int, int*); -int nntp_check_mailbox (CONTEXT *, int*, int); int nntp_close_mailbox (CONTEXT *); -void nntp_fastclose_mailbox (CONTEXT *); int nntp_fetch_message (MESSAGE *, CONTEXT *, int); int nntp_post (const char *); int nntp_check_msgid (CONTEXT *, const char *); diff --git a/pop/Makefile.am b/pop/Makefile.am index 48cb078..1467447 100644 --- a/pop/Makefile.am +++ b/pop/Makefile.am @@ -7,8 +7,8 @@ AUTOMAKE_OPTIONS = foreign INCLUDES = -I$(top_srcdir) -I../intl noinst_LIBRARIES = libpop.a -noinst_HEADERS = pop.h mx_pop.h +noinst_HEADERS = pop.h -libpop_a_SOURCES = pop.c pop_auth.c pop_lib.c pop.h mx_pop.h mx_pop.c +libpop_a_SOURCES = pop.c pop_auth.c pop_lib.c pop.h -include ../cflags.mk diff --git a/pop/mx_pop.c b/pop/mx_pop.c deleted file mode 100644 index b75ba14..0000000 --- a/pop/mx_pop.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is part of mutt-ng, see http://www.muttng.org/. - * It's licensed under the GNU General Public License, - * please see the file GPL in the top level source directory. - */ - -#include - -#include "mutt.h" -#include "pop.h" -#include "mx.h" -#include "mx_pop.h" - -static int pop_is_magic (const char* path, struct stat* st __attribute__ ((unused))) { - url_scheme_t s = url_check_scheme (NONULL (path)); - return ((s == U_POP || s == U_POPS) ? M_POP : -1); -} - -static int acl_check_pop (CONTEXT* ctx __attribute__ ((unused)), int bit) { - switch (bit) { - case ACL_INSERT: /* editing messages */ - case ACL_WRITE: /* change importance */ - return (0); - case ACL_DELETE: /* (un)deletion */ - case ACL_SEEN: /* mark as read */ - return (1); - default: - return (0); - } -} - -mx_t const pop_mx = { - M_POP, - 0, - pop_is_magic, - NULL, - NULL, - pop_open_mailbox, - NULL, - acl_check_pop, - pop_check_mailbox, - pop_close_mailbox, - pop_sync_mailbox, - NULL, -}; diff --git a/pop/mx_pop.h b/pop/mx_pop.h deleted file mode 100644 index 0c75157..0000000 --- a/pop/mx_pop.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * This file is part of mutt-ng, see http://www.muttng.org/. - * It's licensed under the GNU General Public License, - * please see the file GPL in the top level source directory. - */ - -/* - * interface of mx_t implementation for POP - */ - -#ifndef _POP_MX_H -#define _POP_MX_H - -#include "mx.h" - -extern mx_t const pop_mx; - -#endif /* !_POP_MX_H */ diff --git a/pop/pop.c b/pop/pop.c index b00274a..a6e1fd8 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -206,7 +206,7 @@ static int pop_fetch_headers (CONTEXT * ctx) } /* open POP mailbox - fetch only headers */ -int pop_open_mailbox (CONTEXT * ctx) +static int pop_open_mailbox (CONTEXT * ctx) { int ret; char buf[LONG_STRING]; @@ -277,7 +277,7 @@ static void pop_clear_cache (POP_DATA * pop_data) } /* close POP mailbox */ -void pop_close_mailbox (CONTEXT * ctx) +static void pop_close_mailbox (CONTEXT * ctx) { POP_DATA *pop_data = (POP_DATA *) ctx->data; @@ -409,9 +409,9 @@ int pop_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno) } /* update POP mailbox - delete messages from server */ -pop_query_status pop_sync_mailbox (CONTEXT * ctx, - int unused __attribute__ ((unused)), - int *index_hint __attribute__ ((unused))) +static pop_query_status +pop_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused)), + int *index_hint __attribute__ ((unused))) { int i; pop_query_status ret; @@ -454,9 +454,9 @@ pop_query_status pop_sync_mailbox (CONTEXT * ctx, } /* Check for new messages and fetch headers */ -int pop_check_mailbox (CONTEXT * ctx, - int *index_hint __attribute__ ((unused)), - int unused __attribute__ ((unused))) +static int pop_check_mailbox (CONTEXT * ctx, + int *index_hint __attribute__ ((unused)), + int unused __attribute__ ((unused))) { int ret; POP_DATA *pop_data = (POP_DATA *) ctx->data; @@ -640,3 +640,36 @@ fail: mutt_socket_close (conn); p_delete(&pop_data); } + +static int pop_is_magic (const char* path, struct stat* st __attribute__ ((unused))) { + url_scheme_t s = url_check_scheme (NONULL (path)); + return ((s == U_POP || s == U_POPS) ? M_POP : -1); +} + +static int acl_check_pop (CONTEXT* ctx __attribute__ ((unused)), int bit) { + switch (bit) { + case ACL_INSERT: /* editing messages */ + case ACL_WRITE: /* change importance */ + return (0); + case ACL_DELETE: /* (un)deletion */ + case ACL_SEEN: /* mark as read */ + return (1); + default: + return (0); + } +} + +mx_t const pop_mx = { + M_POP, + 0, + pop_is_magic, + NULL, + NULL, + pop_open_mailbox, + NULL, + acl_check_pop, + pop_check_mailbox, + pop_close_mailbox, + pop_sync_mailbox, + NULL, +}; diff --git a/pop/pop.h b/pop/pop.h index 6e857c0..a6c9049 100644 --- a/pop/pop.h +++ b/pop/pop.h @@ -15,6 +15,9 @@ #include "mx.h" +extern mx_t const pop_mx; + + #define POP_PORT 110 #define POP_SSL_PORT 995 @@ -103,11 +106,7 @@ void pop_logout (CONTEXT *); void pop_error (POP_DATA *, char *); /* pop.c */ -int pop_check_mailbox (CONTEXT *, int *, int); -int pop_open_mailbox (CONTEXT *); -pop_query_status pop_sync_mailbox (CONTEXT *, int, int *); int pop_fetch_message (MESSAGE *, CONTEXT *, int); -void pop_close_mailbox (CONTEXT *); void pop_fetch_mail (void); #endif diff --git a/postpone.c b/postpone.c index 42889e3..7198d53 100644 --- a/postpone.c +++ b/postpone.c @@ -26,7 +26,6 @@ #include #include -#include static struct mapping_t PostponeHelp[] = { {N_("Exit"), OP_EXIT},