From 1af6293146bf5457d254a739536f1b7816a3429d Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Mon, 19 Feb 2001 11:05:23 +0000 Subject: Brendan Cully's generic access() wrapper which know about IMAP. --- imap/imap.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ imap/imap.h | 1 + 2 files changed, 45 insertions(+) (limited to 'imap') 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); -- cgit v1.2.3