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>
15 #include <imap/imap.h>
21 void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx)
23 int changed = h->changed;
24 int deleted = ctx->deleted;
25 int tagged = ctx->tagged;
26 int flagged = ctx->flagged;
28 if (ctx->readonly && flag != M_TAG)
29 return; /* don't modify anything if we are read-only */
34 if (!mx_acl_check (ctx, ACL_DELETE))
38 if (!h->deleted && !ctx->readonly) {
42 /* deleted messages aren't treated as changed elsewhere so that the
43 * purge-on-sync option works correctly. This isn't applicable here */
44 if (ctx && ctx->magic == M_IMAP) {
51 else if (h->deleted) {
58 h->appended = 0; /* when undeleting, also reset the appended flag */
59 /* see my comment above */
60 if (ctx->magic == M_IMAP) {
66 * If the user undeletes a message which is marked as
67 * "trash" in the maildir folder on disk, the folder has
68 * been changed, and is marked accordingly. However, we do
69 * _not_ mark the message itself changed, because trashing
70 * is checked in specific code in the maildir folder
73 if (ctx->magic == M_MAILDIR && upd_ctx && h->trash)
99 if (!mx_acl_check (ctx, ACL_SEEN))
103 if (h->read || h->old) {
132 if (!mx_acl_check (ctx, ACL_SEEN))
159 if (!mx_acl_check (ctx, ACL_SEEN))
190 if (!mx_acl_check (ctx, ACL_WRITE))
209 else if (h->replied) {
219 if (!mx_acl_check (ctx, ACL_WRITE))
232 else if (h->flagged) {
250 else if (h->tagged) {
258 mutt_set_header_color (ctx, h);
260 /* if the message status has changed, we need to invalidate the cached
261 * search results so that any future search will match the current status
262 * of this message and not what it was at the time it was last searched.
264 if (h->searched && (changed != h->changed || deleted != ctx->deleted ||
265 tagged != ctx->tagged || flagged != ctx->flagged))
270 void mutt_tag_set_flag (int flag, int bf)
274 for (j = 0; j < Context->vcount; j++)
275 if (Context->hdrs[Context->v2r[j]]->tagged)
276 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], flag, bf);
278 int mutt_thread_set_flag (HEADER * hdr, int flag, int bf, int subthread)
280 THREAD *start, *cur = hdr->thread;
282 if ((Sort & SORT_MASK) != SORT_THREADS) {
283 mutt_error _("Threading is not enabled.");
294 mutt_set_flag (Context, cur->message, flag, bf);
296 if ((cur = cur->child) == NULL)
301 mutt_set_flag (Context, cur->message, flag, bf);
319 int mutt_change_flag(HEADER * h, int bf)
322 const char letters[] = "dDnNoOrR*!";
323 static char const actions[] = {
324 ['d'] = M_DELETE, ['D'] = M_DELETE,
325 ['n'] = M_NEW, ['N'] = M_NEW,
326 ['o'] = M_OLD, ['O'] = M_OLD,
327 ['r'] = M_REPLIED, ['R'] = M_REPLIED,
334 snprintf(buf, sizeof(buf), "%s? (D/N/O/r/*/!): ",
335 bf ? _("Set flag") : _("Clear flag"));
336 c = mutt_multi_choice(buf, letters);
340 if (actions[c] == M_OLD) {
342 mutt_set_flag(Context, h, M_READ, !bf);
344 mutt_tag_set_flag(M_READ, !bf);
349 mutt_set_flag(Context, h, actions[c], bf);
351 mutt_tag_set_flag(actions[c], bf);