*/
#include "mutt.h"
+#include "mailbox.h"
#include <limits.h>
#include <string.h>
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
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];
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;