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.
20 #include "mutt_curses.h"
25 #include "imap_private.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;
34 if (ctx->readonly && flag != M_TAG)
35 return; /* don't modify anything if we are read-only */
42 if (ctx && ctx->magic == M_IMAP)
43 if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \
44 && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_DELETE))
50 if (!h->deleted && !ctx->readonly)
53 if (upd_ctx) ctx->deleted++;
55 /* deleted messages aren't treated as changed elsewhere so that the
56 * purge-on-sync option works correctly. This isn't applicable here */
57 if (ctx && ctx->magic == M_IMAP)
60 if (upd_ctx) ctx->changed = 1;
74 h->appended = 0; /* when undeleting, also reset the appended flag */
76 /* see my comment above */
77 if (ctx->magic == M_IMAP)
80 if (upd_ctx) ctx->changed = 1;
84 * If the user undeletes a message which is marked as
85 * "trash" in the maildir folder on disk, the folder has
86 * been changed, and is marked accordingly. However, we do
87 * _not_ mark the message itself changed, because trashing
88 * is checked in specific code in the maildir folder
91 if (ctx->magic == M_MAILDIR && upd_ctx && h->trash)
102 if (upd_ctx) ctx->appended++;
120 if (ctx && ctx->magic == M_IMAP)
121 if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \
122 && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_SEEN))
128 if (h->read || h->old)
131 if (upd_ctx) ctx->new++;
135 if (upd_ctx) ctx->unread++;
138 if (upd_ctx) ctx->changed = 1;
144 if (upd_ctx) ctx->new--;
146 if (upd_ctx) ctx->unread--;
148 if (upd_ctx) ctx->changed = 1;
155 if (ctx && ctx->magic == M_IMAP)
156 if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \
157 && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_SEEN))
167 if (upd_ctx) ctx->new--;
169 if (upd_ctx) ctx->changed = 1;
176 if (upd_ctx) ctx->new++;
178 if (upd_ctx) ctx->changed = 1;
185 if (ctx && ctx->magic == M_IMAP)
186 if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \
187 && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_SEEN))
196 if (upd_ctx) ctx->unread--;
198 if (upd_ctx) ctx->new--;
200 if (upd_ctx) ctx->changed = 1;
206 if (upd_ctx) ctx->unread++;
208 if (upd_ctx) ctx->new++;
210 if (upd_ctx) ctx->changed = 1;
217 if (ctx && ctx->magic == M_IMAP)
218 if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \
219 && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_WRITE))
231 if (upd_ctx) ctx->unread--;
233 if (upd_ctx) ctx->new--;
236 if (upd_ctx) ctx->changed = 1;
243 if (upd_ctx) ctx->changed = 1;
250 if (ctx && ctx->magic == M_IMAP)
251 if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \
252 && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_WRITE))
261 if (upd_ctx) ctx->flagged++;
263 if (upd_ctx) ctx->changed = 1;
269 if (upd_ctx) ctx->flagged--;
271 if (upd_ctx) ctx->changed = 1;
281 if (upd_ctx) ctx->tagged++;
287 if (upd_ctx) ctx->tagged--;
292 mutt_set_header_color(ctx, h);
294 /* if the message status has changed, we need to invalidate the cached
295 * search results so that any future search will match the current status
296 * of this message and not what it was at the time it was last searched.
298 if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged))
302 void mutt_tag_set_flag (int flag, int bf)
306 for (j = 0; j < Context->vcount; j++)
307 if (Context->hdrs[Context->v2r[j]]->tagged)
308 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], flag, bf);
310 int mutt_thread_set_flag (HEADER *hdr, int flag, int bf, int subthread)
312 THREAD *start, *cur = hdr->thread;
314 if ((Sort & SORT_MASK) != SORT_THREADS)
316 mutt_error _("Threading is not enabled.");
326 mutt_set_flag (Context, cur->message, flag, bf);
328 if ((cur = cur->child) == NULL)
334 mutt_set_flag (Context, cur->message, flag, bf);
354 int mutt_change_flag (HEADER *h, int bf)
359 mvprintw (LINES - 1, 0, "%s? (D/N/O/r/*/!): ", bf ? _("Set flag") : _("Clear flag"));
362 event = mutt_getch();
387 mutt_set_flag (Context, h, M_READ, !bf);
389 mutt_tag_set_flag (M_READ, !bf);
412 mutt_set_flag (Context, h, flag, bf);
414 mutt_tag_set_flag (flag, bf);