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"
21 #include "mutt_menu.h"
27 #include "imap_private.h"
30 void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
32 int changed = h->changed;
33 int deleted = ctx->deleted;
34 int tagged = ctx->tagged;
36 if (ctx->readonly && flag != M_TAG)
37 return; /* don't modify anything if we are read-only */
44 if (ctx && ctx->magic == M_IMAP)
45 if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \
46 && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_DELETE))
52 if (!h->deleted && !ctx->readonly)
55 if (upd_ctx) ctx->deleted++;
57 /* deleted messages aren't treated as changed elsewhere so that the
58 * purge-on-sync option works correctly. This isn't applicable here */
59 if (ctx && ctx->magic == M_IMAP)
62 if (upd_ctx) ctx->changed = 1;
76 h->appended = 0; /* when undeleting, also reset the appended flag */
78 /* see my comment above */
79 if (ctx->magic == M_IMAP)
82 if (upd_ctx) ctx->changed = 1;
86 * If the user undeletes a message which is marked as
87 * "trash" in the maildir folder on disk, the folder has
88 * been changed, and is marked accordingly. However, we do
89 * _not_ mark the message itself changed, because trashing
90 * is checked in specific code in the maildir folder
93 if (ctx->magic == M_MAILDIR && upd_ctx && h->trash)
104 if (upd_ctx) ctx->appended++;
122 if (ctx && ctx->magic == M_IMAP)
123 if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \
124 && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_SEEN))
130 if (h->read || h->old)
133 if (upd_ctx) ctx->new++;
137 if (upd_ctx) ctx->unread++;
140 if (upd_ctx) ctx->changed = 1;
146 if (upd_ctx) ctx->new--;
148 if (upd_ctx) ctx->unread--;
150 if (upd_ctx) ctx->changed = 1;
157 if (ctx && ctx->magic == M_IMAP)
158 if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \
159 && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_SEEN))
169 if (upd_ctx) ctx->new--;
171 if (upd_ctx) ctx->changed = 1;
178 if (upd_ctx) ctx->new++;
180 if (upd_ctx) ctx->changed = 1;
187 if (ctx && ctx->magic == M_IMAP)
188 if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \
189 && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_SEEN))
198 if (upd_ctx) ctx->unread--;
200 if (upd_ctx) ctx->new--;
202 if (upd_ctx) ctx->changed = 1;
208 if (upd_ctx) ctx->unread++;
210 if (upd_ctx) ctx->new++;
212 if (upd_ctx) ctx->changed = 1;
219 if (ctx && ctx->magic == M_IMAP)
220 if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \
221 && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_WRITE))
233 if (upd_ctx) ctx->unread--;
235 if (upd_ctx) ctx->new--;
238 if (upd_ctx) ctx->changed = 1;
245 if (upd_ctx) ctx->changed = 1;
252 if (ctx && ctx->magic == M_IMAP)
253 if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \
254 && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_WRITE))
263 if (upd_ctx) ctx->flagged++;
265 if (upd_ctx) ctx->changed = 1;
271 if (upd_ctx) ctx->flagged--;
273 if (upd_ctx) ctx->changed = 1;
283 if (upd_ctx) ctx->tagged++;
289 if (upd_ctx) ctx->tagged--;
294 mutt_set_header_color(ctx, h);
296 /* if the message status has changed, we need to invalidate the cached
297 * search results so that any future search will match the current status
298 * of this message and not what it was at the time it was last searched.
300 if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged))
305 void mutt_tag_set_flag (int flag, int bf)
309 for (j = 0; j < Context->vcount; j++)
310 if (Context->hdrs[Context->v2r[j]]->tagged)
311 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], flag, bf);
313 int mutt_thread_set_flag (HEADER *hdr, int flag, int bf, int subthread)
315 THREAD *start, *cur = hdr->thread;
317 if ((Sort & SORT_MASK) != SORT_THREADS)
319 mutt_error _("Threading is not enabled.");
329 mutt_set_flag (Context, cur->message, flag, bf);
331 if ((cur = cur->child) == NULL)
337 mutt_set_flag (Context, cur->message, flag, bf);
357 int mutt_change_flag (HEADER *h, int bf)
362 mvprintw (LINES - 1, 0, "%s? (D/N/O/r/*/!): ", bf ? _("Set flag") : _("Clear flag"));
365 event = mutt_getch();
390 mutt_set_flag (Context, h, M_READ, !bf);
392 mutt_tag_set_flag (M_READ, !bf);
415 mutt_set_flag (Context, h, flag, bf);
417 mutt_tag_set_flag (flag, bf);