2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
5 * This file is part of mutt-ng, see http://www.muttng.org/.
6 * It's licensed under the GNU General Public License,
7 * please see the file GPL in the top level source directory.
10 #include <lib-lib/lib-lib.h>
12 #include <lib-ui/lib-ui.h>
13 #include <lib-ui/menu.h>
14 #include <lib-mx/mx.h>
19 #include <imap/imap_private.h>
22 void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx)
24 int changed = h->changed;
25 int deleted = ctx->deleted;
26 int tagged = ctx->tagged;
27 int flagged = ctx->flagged;
29 if (ctx->readonly && flag != M_TAG)
30 return; /* don't modify anything if we are read-only */
35 if (!mx_acl_check (ctx, ACL_DELETE))
39 if (!h->deleted && !ctx->readonly) {
43 /* deleted messages aren't treated as changed elsewhere so that the
44 * purge-on-sync option works correctly. This isn't applicable here */
45 if (ctx && ctx->magic == M_IMAP) {
52 else if (h->deleted) {
59 h->appended = 0; /* when undeleting, also reset the appended flag */
60 /* see my comment above */
61 if (ctx->magic == M_IMAP) {
67 * If the user undeletes a message which is marked as
68 * "trash" in the maildir folder on disk, the folder has
69 * been changed, and is marked accordingly. However, we do
70 * _not_ mark the message itself changed, because trashing
71 * is checked in specific code in the maildir folder
74 if (ctx->magic == M_MAILDIR && upd_ctx && h->trash)
100 if (!mx_acl_check (ctx, ACL_SEEN))
104 if (h->read || h->old) {
133 if (!mx_acl_check (ctx, ACL_SEEN))
160 if (!mx_acl_check (ctx, ACL_SEEN))
191 if (!mx_acl_check (ctx, ACL_WRITE))
210 else if (h->replied) {
220 if (!mx_acl_check (ctx, ACL_WRITE))
233 else if (h->flagged) {
251 else if (h->tagged) {
259 mutt_set_header_color (ctx, h);
261 /* if the message status has changed, we need to invalidate the cached
262 * search results so that any future search will match the current status
263 * of this message and not what it was at the time it was last searched.
265 if (h->searched && (changed != h->changed || deleted != ctx->deleted ||
266 tagged != ctx->tagged || flagged != ctx->flagged))
271 void mutt_tag_set_flag (int flag, int bf)
275 for (j = 0; j < Context->vcount; j++)
276 if (Context->hdrs[Context->v2r[j]]->tagged)
277 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], flag, bf);
279 int mutt_thread_set_flag (HEADER * hdr, int flag, int bf, int subthread)
281 THREAD *start, *cur = hdr->thread;
283 if ((Sort & SORT_MASK) != SORT_THREADS) {
284 mutt_error _("Threading is not enabled.");
295 mutt_set_flag (Context, cur->message, flag, bf);
297 if ((cur = cur->child) == NULL)
302 mutt_set_flag (Context, cur->message, flag, bf);
320 int mutt_change_flag(HEADER * h, int bf)
323 const char letters[] = "dDnNoOrR*!";
324 static char const actions[] = {
325 ['d'] = M_DELETE, ['D'] = M_DELETE,
326 ['n'] = M_NEW, ['N'] = M_NEW,
327 ['o'] = M_OLD, ['O'] = M_OLD,
328 ['r'] = M_REPLIED, ['R'] = M_REPLIED,
335 snprintf(buf, sizeof(buf), "%s? (D/N/O/r/*/!): ",
336 bf ? _("Set flag") : _("Clear flag"));
337 c = mutt_multi_choice(buf, letters);
341 if (actions[c] == M_OLD) {
343 mutt_set_flag(Context, h, M_READ, !bf);
345 mutt_tag_set_flag(M_READ, !bf);
350 mutt_set_flag(Context, h, actions[c], bf);
352 mutt_tag_set_flag(actions[c], bf);