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"
29 #include "imap_private.h"
32 void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
34 int changed = h->changed;
35 int deleted = ctx->deleted;
36 int tagged = ctx->tagged;
37 int flagged = ctx->flagged;
40 if (ctx->readonly && flag != M_TAG)
41 return; /* don't modify anything if we are read-only */
47 if (!mutt_bit_isset(ctx->rights,M_ACL_DELETE))
52 if (!h->deleted && !ctx->readonly)
56 if (upd_ctx) ctx->deleted++;
58 /* deleted messages aren't treated as changed elsewhere so that the
59 * purge-on-sync option works correctly. This isn't applicable here */
60 if (ctx && ctx->magic == M_IMAP)
63 if (upd_ctx) ctx->changed = 1;
72 if (upd_ctx) ctx->deleted--;
74 /* see my comment above */
75 if (ctx->magic == M_IMAP)
78 if (upd_ctx) ctx->changed = 1;
82 * If the user undeletes a message which is marked as
83 * "trash" in the maildir folder on disk, the folder has
84 * been changed, and is marked accordingly. However, we do
85 * _not_ mark the message itself changed, because trashing
86 * is checked in specific code in the maildir folder
89 if (ctx->magic == M_MAILDIR && upd_ctx && h->trash)
96 if (!mutt_bit_isset(ctx->rights,M_ACL_SEEN))
101 if (h->read || h->old)
105 if (upd_ctx) ctx->new++;
109 if (upd_ctx) ctx->unread++;
112 if (upd_ctx) ctx->changed = 1;
119 if (upd_ctx) ctx->new--;
121 if (upd_ctx) ctx->unread--;
123 if (upd_ctx) ctx->changed = 1;
129 if (!mutt_bit_isset(ctx->rights,M_ACL_SEEN))
139 if (upd_ctx) ctx->new--;
141 if (upd_ctx) ctx->changed = 1;
149 if (upd_ctx) ctx->new++;
151 if (upd_ctx) ctx->changed = 1;
157 if (!mutt_bit_isset(ctx->rights,M_ACL_SEEN))
166 if (upd_ctx) ctx->unread--;
168 if (upd_ctx) ctx->new--;
170 if (upd_ctx) ctx->changed = 1;
177 if (upd_ctx) ctx->unread++;
179 if (upd_ctx) ctx->new++;
181 if (upd_ctx) ctx->changed = 1;
187 if (!mutt_bit_isset(ctx->rights,M_ACL_WRITE))
199 if (upd_ctx) ctx->unread--;
201 if (upd_ctx) ctx->new--;
204 if (upd_ctx) ctx->changed = 1;
212 if (upd_ctx) ctx->changed = 1;
218 if (!mutt_bit_isset(ctx->rights,M_ACL_WRITE))
227 if (upd_ctx) ctx->flagged++;
229 if (upd_ctx) ctx->changed = 1;
236 if (upd_ctx) ctx->flagged--;
238 if (upd_ctx) ctx->changed = 1;
249 if (upd_ctx) ctx->tagged++;
256 if (upd_ctx) ctx->tagged--;
262 mutt_set_header_color(ctx, h);
264 /* if the message status has changed, we need to invalidate the cached
265 * search results so that any future search will match the current status
266 * of this message and not what it was at the time it was last searched.
268 if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged || flagged != ctx->flagged))
272 void mutt_tag_set_flag (int flag, int bf)
276 for (j = 0; j < Context->vcount; j++)
277 if (Context->hdrs[Context->v2r[j]]->tagged)
278 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], flag, bf);
280 int mutt_thread_set_flag (HEADER *hdr, int flag, int bf, int subthread)
282 THREAD *start, *cur = hdr->thread;
284 if ((Sort & SORT_MASK) != SORT_THREADS)
286 mutt_error _("Threading is not enabled.");
296 mutt_set_flag (Context, cur->message, flag, bf);
298 if ((cur = cur->child) == NULL)
304 mutt_set_flag (Context, cur->message, flag, bf);
324 int mutt_change_flag (HEADER *h, int bf)
329 mvprintw (LINES - 1, 0, "%s? (D/N/O/r/*/!): ", bf ? _("Set flag") : _("Clear flag"));
332 event = mutt_getch();
357 mutt_set_flag (Context, h, M_READ, !bf);
359 mutt_tag_set_flag (M_READ, !bf);
382 mutt_set_flag (Context, h, flag, bf);
384 mutt_tag_set_flag (flag, bf);