From 992824dfb5a0779d6f5397bdcfa96fd64f27e4d6 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Thu, 6 Sep 2018 17:40:59 +0100 Subject: [PATCH] move Context.rights --- context.h | 27 --------------------------- curs_main.c | 4 ++-- flags.c | 14 +++++++------- imap/command.c | 32 ++++++++++++++++---------------- imap/imap.c | 41 +++++++++++++++++++++-------------------- mailbox.h | 24 ++++++++++++++++++++++++ mx.c | 2 +- nntp/nntp.c | 6 +++--- pager.c | 2 +- pop/pop.c | 8 ++++---- 10 files changed, 79 insertions(+), 81 deletions(-) diff --git a/context.h b/context.h index bf0be6d1b..1e3e009dc 100644 --- a/context.h +++ b/context.h @@ -28,31 +28,6 @@ #include #include -/** - * enum AclRights - ACL Rights - * - * These permissions come from the 'MYRIGHTS' command from RFC4314. - * The quoted letter is the code returned by the server. - * - * These show permission to... - */ -enum AclRights -{ - MUTT_ACL_ADMIN = 0, ///< 'a' administer the account (get/set permissions) - MUTT_ACL_CREATE, ///< 'k' create a mailbox - MUTT_ACL_DELETE, ///< 't' delete a message - MUTT_ACL_DELMX, ///< 'x' delete a mailbox - MUTT_ACL_EXPUNGE, ///< 'e' expunge messages - MUTT_ACL_INSERT, ///< 'i' add/copy into the mailbox (used when editing a message) - MUTT_ACL_LOOKUP, ///< 'l' lookup mailbox (visible to 'list') - MUTT_ACL_POST, ///< 'p' post (submit messages to the server) - MUTT_ACL_READ, ///< 'r' read the mailbox - MUTT_ACL_SEEN, ///< 's' change the 'seen' status of a message - MUTT_ACL_WRITE, ///< 'w' write to a message (for flagging, or linking threads) - - RIGHTSMAX -}; - /** * struct Context - The "current" mailbox */ @@ -77,8 +52,6 @@ struct Context struct Menu *menu; /**< needed for pattern compilation */ - unsigned char rights[(RIGHTSMAX + 7) / 8]; /**< ACL bits */ - bool dontwrite : 1; /**< don't write the mailbox on close */ bool append : 1; /**< mailbox is opened in append mode */ bool collapsed : 1; /**< are all threads collapsed? */ diff --git a/curs_main.c b/curs_main.c index 424919f4c..5ed63927f 100644 --- a/curs_main.c +++ b/curs_main.c @@ -145,7 +145,7 @@ static const char *NoVisible = N_("No visible messages"); } #define CHECK_ACL(aclbit, action) \ - if (!mutt_bit_isset(Context->rights, aclbit)) \ + if (!mutt_bit_isset(Context->mailbox->rights, aclbit)) \ { \ mutt_flushinp(); \ /* L10N: %s is one of the CHECK_ACL entries below. */ \ @@ -3047,7 +3047,7 @@ int mutt_index_menu(void) } else if (op == OP_EDIT_OR_VIEW_RAW_MESSAGE) edit = !Context->mailbox->readonly && - mutt_bit_isset(Context->rights, MUTT_ACL_INSERT); + mutt_bit_isset(Context->mailbox->rights, MUTT_ACL_INSERT); else edit = false; diff --git a/flags.c b/flags.c index 0c228c0e7..4e9521a3b 100644 --- a/flags.c +++ b/flags.c @@ -71,7 +71,7 @@ void mutt_set_flag_update(struct Context *ctx, struct Header *h, int flag, bool { case MUTT_DELETE: - if (!mutt_bit_isset(ctx->rights, MUTT_ACL_DELETE)) + if (!mutt_bit_isset(ctx->mailbox->rights, MUTT_ACL_DELETE)) return; if (bf) @@ -123,7 +123,7 @@ void mutt_set_flag_update(struct Context *ctx, struct Header *h, int flag, bool case MUTT_PURGE: - if (!mutt_bit_isset(ctx->rights, MUTT_ACL_DELETE)) + if (!mutt_bit_isset(ctx->mailbox->rights, MUTT_ACL_DELETE)) return; if (bf) @@ -137,7 +137,7 @@ void mutt_set_flag_update(struct Context *ctx, struct Header *h, int flag, bool case MUTT_NEW: - if (!mutt_bit_isset(ctx->rights, MUTT_ACL_SEEN)) + if (!mutt_bit_isset(ctx->mailbox->rights, MUTT_ACL_SEEN)) return; if (bf) @@ -176,7 +176,7 @@ void mutt_set_flag_update(struct Context *ctx, struct Header *h, int flag, bool case MUTT_OLD: - if (!mutt_bit_isset(ctx->rights, MUTT_ACL_SEEN)) + if (!mutt_bit_isset(ctx->mailbox->rights, MUTT_ACL_SEEN)) return; if (bf) @@ -208,7 +208,7 @@ void mutt_set_flag_update(struct Context *ctx, struct Header *h, int flag, bool case MUTT_READ: - if (!mutt_bit_isset(ctx->rights, MUTT_ACL_SEEN)) + if (!mutt_bit_isset(ctx->mailbox->rights, MUTT_ACL_SEEN)) return; if (bf) @@ -244,7 +244,7 @@ void mutt_set_flag_update(struct Context *ctx, struct Header *h, int flag, bool case MUTT_REPLIED: - if (!mutt_bit_isset(ctx->rights, MUTT_ACL_WRITE)) + if (!mutt_bit_isset(ctx->mailbox->rights, MUTT_ACL_WRITE)) return; if (bf) @@ -279,7 +279,7 @@ void mutt_set_flag_update(struct Context *ctx, struct Header *h, int flag, bool case MUTT_FLAG: - if (!mutt_bit_isset(ctx->rights, MUTT_ACL_WRITE)) + if (!mutt_bit_isset(ctx->mailbox->rights, MUTT_ACL_WRITE)) return; if (bf) diff --git a/imap/command.c b/imap/command.c index 933a0e2c3..4adbfd866 100644 --- a/imap/command.c +++ b/imap/command.c @@ -680,54 +680,54 @@ static void cmd_parse_myrights(struct ImapData *idata, const char *s) s = imap_next_word((char *) s); /* zero out current rights set */ - memset(idata->ctx->rights, 0, sizeof(idata->ctx->rights)); + memset(idata->ctx->mailbox->rights, 0, sizeof(idata->ctx->mailbox->rights)); while (*s && !isspace((unsigned char) *s)) { switch (*s) { case 'a': - mutt_bit_set(idata->ctx->rights, MUTT_ACL_ADMIN); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_ADMIN); break; case 'e': - mutt_bit_set(idata->ctx->rights, MUTT_ACL_EXPUNGE); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_EXPUNGE); break; case 'i': - mutt_bit_set(idata->ctx->rights, MUTT_ACL_INSERT); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_INSERT); break; case 'k': - mutt_bit_set(idata->ctx->rights, MUTT_ACL_CREATE); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_CREATE); break; case 'l': - mutt_bit_set(idata->ctx->rights, MUTT_ACL_LOOKUP); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_LOOKUP); break; case 'p': - mutt_bit_set(idata->ctx->rights, MUTT_ACL_POST); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_POST); break; case 'r': - mutt_bit_set(idata->ctx->rights, MUTT_ACL_READ); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_READ); break; case 's': - mutt_bit_set(idata->ctx->rights, MUTT_ACL_SEEN); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_SEEN); break; case 't': - mutt_bit_set(idata->ctx->rights, MUTT_ACL_DELETE); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_DELETE); break; case 'w': - mutt_bit_set(idata->ctx->rights, MUTT_ACL_WRITE); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_WRITE); break; case 'x': - mutt_bit_set(idata->ctx->rights, MUTT_ACL_DELMX); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_DELMX); break; /* obsolete rights */ case 'c': - mutt_bit_set(idata->ctx->rights, MUTT_ACL_CREATE); - mutt_bit_set(idata->ctx->rights, MUTT_ACL_DELMX); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_CREATE); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_DELMX); break; case 'd': - mutt_bit_set(idata->ctx->rights, MUTT_ACL_DELETE); - mutt_bit_set(idata->ctx->rights, MUTT_ACL_EXPUNGE); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_DELETE); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_EXPUNGE); break; default: mutt_debug(1, "Unknown right: %c\n", *s); diff --git a/imap/imap.c b/imap/imap.c index ee02b6b9b..ddc9b1232 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -159,7 +159,7 @@ static char *get_flags(struct ListHead *hflags, char *s) static void set_flag(struct ImapData *idata, int aclbit, int flag, const char *str, char *flags, size_t flsize) { - if (mutt_bit_isset(idata->ctx->rights, aclbit)) + if (mutt_bit_isset(idata->ctx->mailbox->rights, aclbit)) if (flag && imap_has_flag(&idata->flags, str)) mutt_str_strcat(flags, flsize, str); } @@ -301,7 +301,7 @@ static int sync_helper(struct ImapData *idata, int right, int flag, const char * if (!idata->ctx) return -1; - if (!mutt_bit_isset(idata->ctx->rights, right)) + if (!mutt_bit_isset(idata->ctx->mailbox->rights, right)) return 0; if (right == MUTT_ACL_WRITE && !imap_has_flag(&idata->flags, name)) @@ -1290,7 +1290,7 @@ int imap_sync_message_for_copy(struct ImapData *idata, struct Header *hdr, set_flag(idata, MUTT_ACL_DELETE, HEADER_DATA(hdr)->deleted, "\\Deleted ", flags, sizeof(flags)); - if (mutt_bit_isset(idata->ctx->rights, MUTT_ACL_WRITE)) + if (mutt_bit_isset(idata->ctx->mailbox->rights, MUTT_ACL_WRITE)) { /* restore system flags */ if (HEADER_DATA(hdr)->flags_system) @@ -1318,7 +1318,8 @@ int imap_sync_message_for_copy(struct ImapData *idata, struct Header *hdr, flags, sizeof(flags)); /* erase custom flags */ - if (mutt_bit_isset(idata->ctx->rights, MUTT_ACL_WRITE) && HEADER_DATA(hdr)->flags_remote) + if (mutt_bit_isset(idata->ctx->mailbox->rights, MUTT_ACL_WRITE) && + HEADER_DATA(hdr)->flags_remote) mutt_str_strcat(flags, sizeof(flags), HEADER_DATA(hdr)->flags_remote); mutt_str_remove_trailing_ws(flags); @@ -2038,7 +2039,7 @@ static int imap_mbox_open(struct Context *ctx) /* clear mailbox status */ idata->status = false; - memset(idata->ctx->rights, 0, sizeof(idata->ctx->rights)); + memset(idata->ctx->mailbox->rights, 0, sizeof(idata->ctx->mailbox->rights)); idata->new_mail_count = 0; idata->max_msn = 0; @@ -2054,14 +2055,14 @@ static int imap_mbox_open(struct Context *ctx) /* assume we have all rights if ACL is unavailable */ else { - mutt_bit_set(idata->ctx->rights, MUTT_ACL_LOOKUP); - mutt_bit_set(idata->ctx->rights, MUTT_ACL_READ); - mutt_bit_set(idata->ctx->rights, MUTT_ACL_SEEN); - mutt_bit_set(idata->ctx->rights, MUTT_ACL_WRITE); - mutt_bit_set(idata->ctx->rights, MUTT_ACL_INSERT); - mutt_bit_set(idata->ctx->rights, MUTT_ACL_POST); - mutt_bit_set(idata->ctx->rights, MUTT_ACL_CREATE); - mutt_bit_set(idata->ctx->rights, MUTT_ACL_DELETE); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_LOOKUP); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_READ); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_SEEN); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_WRITE); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_INSERT); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_POST); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_CREATE); + mutt_bit_set(idata->ctx->mailbox->rights, MUTT_ACL_DELETE); } /* pipeline the postponed count if possible */ pmx.mbox = NULL; @@ -2209,10 +2210,10 @@ static int imap_mbox_open(struct Context *ctx) } } - if (!(mutt_bit_isset(idata->ctx->rights, MUTT_ACL_DELETE) || - mutt_bit_isset(idata->ctx->rights, MUTT_ACL_SEEN) || - mutt_bit_isset(idata->ctx->rights, MUTT_ACL_WRITE) || - mutt_bit_isset(idata->ctx->rights, MUTT_ACL_INSERT))) + if (!(mutt_bit_isset(idata->ctx->mailbox->rights, MUTT_ACL_DELETE) || + mutt_bit_isset(idata->ctx->mailbox->rights, MUTT_ACL_SEEN) || + mutt_bit_isset(idata->ctx->mailbox->rights, MUTT_ACL_WRITE) || + mutt_bit_isset(idata->ctx->mailbox->rights, MUTT_ACL_INSERT))) { ctx->mailbox->readonly = true; } @@ -2420,7 +2421,7 @@ int imap_sync_mailbox(struct Context *ctx, bool expunge) return rc; /* if we are expunging anyway, we can do deleted messages very quickly... */ - if (expunge && mutt_bit_isset(ctx->rights, MUTT_ACL_DELETE)) + if (expunge && mutt_bit_isset(ctx->mailbox->rights, MUTT_ACL_DELETE)) { rc = imap_exec_msgset(idata, "UID STORE", "+FLAGS.SILENT (\\Deleted)", MUTT_DELETED, true, false); @@ -2558,7 +2559,7 @@ int imap_sync_mailbox(struct Context *ctx, bool expunge) ctx->mailbox->changed = false; /* We must send an EXPUNGE command if we're not closing. */ - if (expunge && !(ctx->mailbox->closing) && mutt_bit_isset(ctx->rights, MUTT_ACL_DELETE)) + if (expunge && !(ctx->mailbox->closing) && mutt_bit_isset(ctx->mailbox->rights, MUTT_ACL_DELETE)) { mutt_message(_("Expunging messages from server...")); /* Set expunge bit so we don't get spurious reopened messages */ @@ -2692,7 +2693,7 @@ static int imap_tags_commit(struct Context *ctx, struct Header *hdr, char *buf) if (*buf == '\0') buf = NULL; - if (!mutt_bit_isset(idata->ctx->rights, MUTT_ACL_WRITE)) + if (!mutt_bit_isset(idata->ctx->mailbox->rights, MUTT_ACL_WRITE)) return 0; snprintf(uid, sizeof(uid), "%u", HEADER_DATA(hdr)->uid); diff --git a/mailbox.h b/mailbox.h index 7c572db53..7c33bdffd 100644 --- a/mailbox.h +++ b/mailbox.h @@ -47,6 +47,28 @@ extern bool MaildirCheckCur; #define MB_NORMAL 0 #define MB_HIDDEN 1 +/** + * enum AclRights - ACL Rights + * + * These show permission to... + */ +enum AclRights +{ + MUTT_ACL_ADMIN = 0, ///< administer the account (get/set permissions) + MUTT_ACL_CREATE, ///< create a mailbox + MUTT_ACL_DELETE, ///< delete a message + MUTT_ACL_DELMX, ///< delete a mailbox + MUTT_ACL_EXPUNGE, ///< expunge messages + MUTT_ACL_INSERT, ///< add/copy into the mailbox (used when editing a message) + MUTT_ACL_LOOKUP, ///< lookup mailbox (visible to 'list') + MUTT_ACL_POST, ///< post (submit messages to the server) + MUTT_ACL_READ, ///< read the mailbox + MUTT_ACL_SEEN, ///< change the 'seen' status of a message + MUTT_ACL_WRITE, ///< write to a message (for flagging, or linking threads) + + RIGHTSMAX +}; + /** * struct Mailbox - A mailbox */ @@ -82,6 +104,8 @@ struct Mailbox bool quiet : 1; /**< inhibit status messages? */ bool closing : 1; /**< mailbox is being closed */ + unsigned char rights[(RIGHTSMAX + 7) / 8]; /**< ACL bits */ + int flags; /**< e.g. #MB_NORMAL */ }; diff --git a/mx.c b/mx.c index 58eef6d7d..93ac1bb48 100644 --- a/mx.c +++ b/mx.c @@ -264,7 +264,7 @@ struct Context *mx_mbox_open(const char *path, int flags) ctx->collapsed = false; for (rc = 0; rc < RIGHTSMAX; rc++) - mutt_bit_set(ctx->rights, rc); + mutt_bit_set(ctx->mailbox->rights, rc); if (flags & MUTT_QUIET) ctx->mailbox->quiet = true; diff --git a/nntp/nntp.c b/nntp/nntp.c index bc6d9105e..73b263843 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -1546,7 +1546,7 @@ static int nntp_mbox_open(struct Context *ctx) return -1; } - mutt_bit_unset(ctx->rights, MUTT_ACL_INSERT); + mutt_bit_unset(ctx->mailbox->rights, MUTT_ACL_INSERT); if (!nntp_data->newsrc_ent && !nntp_data->subscribed && !SaveUnsubscribed) ctx->mailbox->readonly = true; @@ -1623,8 +1623,8 @@ static int nntp_mbox_open(struct Context *ctx) #endif if (!hc) { - mutt_bit_unset(ctx->rights, MUTT_ACL_WRITE); - mutt_bit_unset(ctx->rights, MUTT_ACL_DELETE); + mutt_bit_unset(ctx->mailbox->rights, MUTT_ACL_WRITE); + mutt_bit_unset(ctx->mailbox->rights, MUTT_ACL_DELETE); } nntp_newsrc_close(nserv); rc = nntp_fetch_headers(ctx, hc, first, nntp_data->last_message, 0); diff --git a/pager.c b/pager.c index 50083655c..4df8f4e06 100644 --- a/pager.c +++ b/pager.c @@ -128,7 +128,7 @@ static struct Header *OldHdr = NULL; } #define CHECK_ACL(aclbit, action) \ - if (!Context || !mutt_bit_isset(Context->rights, aclbit)) \ + if (!Context || !mutt_bit_isset(Context->mailbox->rights, aclbit)) \ { \ mutt_flushinp(); \ /* L10N: %s is one of the CHECK_ACL entries below. */ \ diff --git a/pop/pop.c b/pop/pop.c index 23e277fc9..e2db60627 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -517,13 +517,13 @@ static int pop_mbox_open(struct Context *ctx) pop_data->bcache = mutt_bcache_open(&acct, NULL); /* init (hard-coded) ACL rights */ - memset(ctx->rights, 0, sizeof(ctx->rights)); - mutt_bit_set(ctx->rights, MUTT_ACL_SEEN); - mutt_bit_set(ctx->rights, MUTT_ACL_DELETE); + memset(ctx->mailbox->rights, 0, sizeof(ctx->mailbox->rights)); + mutt_bit_set(ctx->mailbox->rights, MUTT_ACL_SEEN); + mutt_bit_set(ctx->mailbox->rights, MUTT_ACL_DELETE); #ifdef USE_HCACHE /* flags are managed using header cache, so it only makes sense to * enable them in that case */ - mutt_bit_set(ctx->rights, MUTT_ACL_WRITE); + mutt_bit_set(ctx->mailbox->rights, MUTT_ACL_WRITE); #endif while (true) -- 2.40.0