]> granicus.if.org Git - mutt/commitdiff
Brendan Cully's generic access() wrapper which know about IMAP.
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 19 Feb 2001 11:05:23 +0000 (11:05 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 19 Feb 2001 11:05:23 +0000 (11:05 +0000)
hook.c
imap/imap.c
imap/imap.h
mailbox.h
mx.c

diff --git a/hook.c b/hook.c
index 8bf7b1fea34f4d6a907d53433bb4fbe001b4c46f..a171e41dd7bdb587bc44b20d8a8182a83f0a96a6 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -17,6 +17,7 @@
  */
 
 #include "mutt.h"
+#include "mailbox.h"
 
 #include <limits.h>
 #include <string.h>
@@ -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
index 3d8437d162159bd00536087bc0c88014b535d611..80e4c73ae5fb80b189c362127417fddee380f9cc 100644 (file)
@@ -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];
index b05dc18270f4e2053ea966a3ec9742e7a227f7f2..3cefa694b1776ae7521b13a2f6a0e1ab421520f0 100644 (file)
@@ -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);
index d442a61feb73cda2a734ce9fc31b3e38ef6e9d9e..7355eb51b3225d252a6dcdf8e964fe9c4209cbbd 100644 (file)
--- 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 fd42a9167fbab7b3791a463b47f7e47580ef296a..cea83385bc115838e709fa0ec21474692645a860 100644 (file)
--- 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;