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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 #include "mutt_curses.h"
25 #include "mutt_menu.h"
31 #include "imap_private.h"
34 void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
36 int changed = h->changed;
37 int deleted = ctx->deleted;
38 int tagged = ctx->tagged;
40 if (ctx->readonly && flag != M_TAG)
41 return; /* don't modify anything if we are read-only */
48 if (ctx && ctx->magic == M_IMAP)
49 if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \
50 && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_DELETE))
56 if (!h->deleted && !ctx->readonly)
59 if (upd_ctx) ctx->deleted++;
61 /* deleted messages aren't treated as changed elsewhere so that the
62 * purge-on-sync option works correctly. This isn't applicable here */
63 if (ctx && ctx->magic == M_IMAP)
66 if (upd_ctx) ctx->changed = 1;
80 h->appended = 0; /* when undeleting, also reset the appended flag */
82 /* see my comment above */
83 if (ctx->magic == M_IMAP)
86 if (upd_ctx) ctx->changed = 1;
90 * If the user undeletes a message which is marked as
91 * "trash" in the maildir folder on disk, the folder has
92 * been changed, and is marked accordingly. However, we do
93 * _not_ mark the message itself changed, because trashing
94 * is checked in specific code in the maildir folder
97 if (ctx->magic == M_MAILDIR && upd_ctx && h->trash)
108 if (upd_ctx) ctx->appended++;
126 if (ctx && ctx->magic == M_IMAP)
127 if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \
128 && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_SEEN))
134 if (h->read || h->old)
137 if (upd_ctx) ctx->new++;
141 if (upd_ctx) ctx->unread++;
144 if (upd_ctx) ctx->changed = 1;
150 if (upd_ctx) ctx->new--;
152 if (upd_ctx) ctx->unread--;
154 if (upd_ctx) ctx->changed = 1;
161 if (ctx && ctx->magic == M_IMAP)
162 if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \
163 && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_SEEN))
173 if (upd_ctx) ctx->new--;
175 if (upd_ctx) ctx->changed = 1;
182 if (upd_ctx) ctx->new++;
184 if (upd_ctx) ctx->changed = 1;
191 if (ctx && ctx->magic == M_IMAP)
192 if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \
193 && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_SEEN))
202 if (upd_ctx) ctx->unread--;
204 if (upd_ctx) ctx->new--;
206 if (upd_ctx) ctx->changed = 1;
212 if (upd_ctx) ctx->unread++;
214 if (upd_ctx) ctx->new++;
216 if (upd_ctx) ctx->changed = 1;
223 if (ctx && ctx->magic == M_IMAP)
224 if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \
225 && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_WRITE))
237 if (upd_ctx) ctx->unread--;
239 if (upd_ctx) ctx->new--;
242 if (upd_ctx) ctx->changed = 1;
249 if (upd_ctx) ctx->changed = 1;
256 if (ctx && ctx->magic == M_IMAP)
257 if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \
258 && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_WRITE))
267 if (upd_ctx) ctx->flagged++;
269 if (upd_ctx) ctx->changed = 1;
275 if (upd_ctx) ctx->flagged--;
277 if (upd_ctx) ctx->changed = 1;
287 if (upd_ctx) ctx->tagged++;
293 if (upd_ctx) ctx->tagged--;
298 mutt_set_header_color(ctx, h);
300 /* if the message status has changed, we need to invalidate the cached
301 * search results so that any future search will match the current status
302 * of this message and not what it was at the time it was last searched.
304 if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged))
309 void mutt_tag_set_flag (int flag, int bf)
313 for (j = 0; j < Context->vcount; j++)
314 if (Context->hdrs[Context->v2r[j]]->tagged)
315 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], flag, bf);
317 int mutt_thread_set_flag (HEADER *hdr, int flag, int bf, int subthread)
319 THREAD *start, *cur = hdr->thread;
321 if ((Sort & SORT_MASK) != SORT_THREADS)
323 mutt_error _("Threading is not enabled.");
333 mutt_set_flag (Context, cur->message, flag, bf);
335 if ((cur = cur->child) == NULL)
341 mutt_set_flag (Context, cur->message, flag, bf);
361 int mutt_change_flag (HEADER *h, int bf)
366 mvprintw (LINES - 1, 0, "%s? (D/N/O/r/*/!): ", bf ? _("Set flag") : _("Clear flag"));
369 event = mutt_getch();
394 mutt_set_flag (Context, h, M_READ, !bf);
396 mutt_tag_set_flag (M_READ, !bf);
419 mutt_set_flag (Context, h, flag, bf);
421 mutt_tag_set_flag (flag, bf);