From: Thomas Roessler Date: Mon, 19 Feb 2001 11:05:23 +0000 (+0000) Subject: Brendan Cully's generic access() wrapper which know about IMAP. X-Git-Tag: mutt-1-3-16-rel~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1af6293146bf5457d254a739536f1b7816a3429d;p=mutt Brendan Cully's generic access() wrapper which know about IMAP. --- diff --git a/hook.c b/hook.c index 8bf7b1fe..a171e41d 100644 --- a/hook.c +++ b/hook.c @@ -17,6 +17,7 @@ */ #include "mutt.h" +#include "mailbox.h" #include #include @@ -385,7 +386,7 @@ void mutt_select_fcc (char *path, size_t pathlen, HEADER *hdr) adr = env->to ? env->to : (env->cc ? env->cc : env->bcc); mutt_safe_path (buf, sizeof (buf), adr); snprintf (path, pathlen, "%s/%s", NONULL (Maildir), buf); - if (!option (OPTFORCENAME) && access (path, W_OK) != 0) + if (!option (OPTFORCENAME) && mx_access (path, W_OK) != 0) strfcpy (path, NONULL (Outbox), pathlen); } else diff --git a/imap/imap.c b/imap/imap.c index 3d8437d1..80e4c73a 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -48,6 +48,50 @@ static int imap_check_capabilities (IMAP_DATA* idata); static void imap_set_flag (IMAP_DATA* idata, int aclbit, int flag, const char* str, char* flags, size_t flsize); +/* imap_access: Check permissions on an IMAP mailbox. */ +int imap_access (const char* path, int flags) +{ + IMAP_DATA* idata; + IMAP_MBOX mx; + char buf[LONG_STRING]; + char mailbox[LONG_STRING]; + char mbox[LONG_STRING]; + + if (imap_parse_path (path, &mx)) + return -1; + + if (!(idata = imap_conn_find (&mx.account, + option (OPTIMAPPASSIVE) ? M_IMAP_CONN_NONEW : 0))) + { + FREE (&mx.mbox); + return -1; + } + + + imap_fix_path (idata, mx.mbox, mailbox, sizeof (mailbox)); + FREE (&mx.mbox); + imap_munge_mbox_name (mbox, sizeof (mbox), mailbox); + + /* TODO: ACL checks. Right now we assume if it exists we can mess with it. */ + if (mutt_bit_isset (idata->capabilities, IMAP4REV1)) + snprintf (buf, sizeof (buf), "STATUS %s (UIDVALIDITY)", mbox); + else if (mutt_bit_isset (idata->capabilities, STATUS)) + snprintf (buf, sizeof (buf), "STATUS %s (UID-VALIDITY)", mbox); + else + { + dprint (2, (debugfile, "imap_access: STATUS not supported?\n")); + return -1; + } + + if (imap_exec (idata, buf, IMAP_CMD_FAIL_OK) < 0) + { + dprint (1, (debugfile, "imap_access: Can't check STATUS of %s\n", mbox)); + return -1; + } + + return 0; +} + int imap_create_mailbox (IMAP_DATA* idata, char* mailbox) { char buf[LONG_STRING], mbox[LONG_STRING]; diff --git a/imap/imap.h b/imap/imap.h index b05dc182..3cefa694 100644 --- a/imap/imap.h +++ b/imap/imap.h @@ -32,6 +32,7 @@ typedef struct } IMAP_MBOX; /* imap.c */ +int imap_access (const char*, int); int imap_check_mailbox (CONTEXT *ctx, int *index_hint); int imap_close_connection (CONTEXT *ctx); int imap_delete_mailbox (CONTEXT* idata, char* mailbox); diff --git a/mailbox.h b/mailbox.h index d442a61f..7355eb51 100644 --- a/mailbox.h +++ b/mailbox.h @@ -65,5 +65,6 @@ int mx_is_imap (const char *); int mx_is_pop (const char *); #endif +int mx_access (const char*, int); #endif diff --git a/mx.c b/mx.c index fd42a916..cea83385 100644 --- a/mx.c +++ b/mx.c @@ -468,6 +468,19 @@ int mx_set_magic (const char *s) return 0; } +/* mx_access: Wrapper for access, checks permissions on a given mailbox. + * We may be interested in using ACL-style flags at some point, currently + * we use the normal access() flags. */ +int mx_access (const char* path, int flags) +{ +#ifdef USE_IMAP + if (mx_is_imap (path)) + return imap_access (path, flags); +#endif + + return access (path, flags); +} + static int mx_open_mailbox_append (CONTEXT *ctx) { struct stat sb;