2 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "mutt_curses.h"
28 void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
30 int changed = h->changed;
31 int deleted = ctx->deleted;
32 int tagged = ctx->tagged;
33 int flagged = ctx->flagged;
36 if (ctx->readonly && flag != M_TAG)
37 return; /* don't modify anything if we are read-only */
43 if (!mutt_bit_isset(ctx->rights,M_ACL_DELETE))
48 if (!h->deleted && !ctx->readonly)
52 if (upd_ctx) ctx->deleted++;
54 /* deleted messages aren't treated as changed elsewhere so that the
55 * purge-on-sync option works correctly. This isn't applicable here */
56 if (ctx && ctx->magic == M_IMAP)
59 if (upd_ctx) ctx->changed = 1;
68 if (upd_ctx) ctx->deleted--;
70 /* see my comment above */
71 if (ctx->magic == M_IMAP)
74 if (upd_ctx) ctx->changed = 1;
78 * If the user undeletes a message which is marked as
79 * "trash" in the maildir folder on disk, the folder has
80 * been changed, and is marked accordingly. However, we do
81 * _not_ mark the message itself changed, because trashing
82 * is checked in specific code in the maildir folder
85 if (ctx->magic == M_MAILDIR && upd_ctx && h->trash)
92 if (!mutt_bit_isset(ctx->rights,M_ACL_SEEN))
97 if (h->read || h->old)
101 if (upd_ctx) ctx->new++;
105 if (upd_ctx) ctx->unread++;
108 if (upd_ctx) ctx->changed = 1;
115 if (upd_ctx) ctx->new--;
117 if (upd_ctx) ctx->unread--;
119 if (upd_ctx) ctx->changed = 1;
125 if (!mutt_bit_isset(ctx->rights,M_ACL_SEEN))
135 if (upd_ctx) ctx->new--;
137 if (upd_ctx) ctx->changed = 1;
145 if (upd_ctx) ctx->new++;
147 if (upd_ctx) ctx->changed = 1;
153 if (!mutt_bit_isset(ctx->rights,M_ACL_SEEN))
162 if (upd_ctx) ctx->unread--;
164 if (upd_ctx) ctx->new--;
166 if (upd_ctx) ctx->changed = 1;
173 if (upd_ctx) ctx->unread++;
175 if (upd_ctx) ctx->new++;
177 if (upd_ctx) ctx->changed = 1;
183 if (!mutt_bit_isset(ctx->rights,M_ACL_WRITE))
195 if (upd_ctx) ctx->unread--;
197 if (upd_ctx) ctx->new--;
200 if (upd_ctx) ctx->changed = 1;
208 if (upd_ctx) ctx->changed = 1;
214 if (!mutt_bit_isset(ctx->rights,M_ACL_WRITE))
223 if (upd_ctx) ctx->flagged++;
225 if (upd_ctx) ctx->changed = 1;
232 if (upd_ctx) ctx->flagged--;
234 if (upd_ctx) ctx->changed = 1;
245 if (upd_ctx) ctx->tagged++;
252 if (upd_ctx) ctx->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 || tagged != ctx->tagged || flagged != ctx->flagged))
268 void mutt_tag_set_flag (int flag, int bf)
272 for (j = 0; j < Context->vcount; j++)
273 if (Context->hdrs[Context->v2r[j]]->tagged)
274 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], flag, bf);
276 int mutt_thread_set_flag (HEADER *hdr, int flag, int bf, int subthread)
278 THREAD *start, *cur = hdr->thread;
280 if ((Sort & SORT_MASK) != SORT_THREADS)
282 mutt_error _("Threading is not enabled.");
292 mutt_set_flag (Context, cur->message, flag, bf);
294 if ((cur = cur->child) == NULL)
300 mutt_set_flag (Context, cur->message, flag, bf);
320 int mutt_change_flag (HEADER *h, int bf)
325 mvprintw (LINES - 1, 0, "%s? (D/N/O/r/*/!): ", bf ? _("Set flag") : _("Clear flag"));
328 event = mutt_getch();
353 mutt_set_flag (Context, h, M_READ, !bf);
355 mutt_tag_set_flag (M_READ, !bf);
378 mutt_set_flag (Context, h, flag, bf);
380 mutt_tag_set_flag (flag, bf);