NeoMutt  2018-07-16 +952-a2da0a
Teaching an old dog new tricks
DOXYGEN
flags.c File Reference

Manipulate the flags in an email header. More...

#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include "mutt/mutt.h"
#include "config/lib.h"
#include "email/lib.h"
#include "mutt.h"
#include "context.h"
#include "curs_lib.h"
#include "globals.h"
#include "index.h"
#include "mailbox.h"
#include "menu.h"
#include "mutt_curses.h"
#include "mutt_window.h"
#include "mx.h"
#include "protos.h"
#include "sort.h"
+ Include dependency graph for flags.c:

Go to the source code of this file.

Functions

void mutt_set_flag_update (struct Mailbox *m, struct Email *e, int flag, bool bf, bool upd_mbox)
 Set a flag on an email. More...
 
void mutt_tag_set_flag (int flag, int bf)
 Set flag on tagged messages. More...
 
int mutt_thread_set_flag (struct Email *e, int flag, int bf, int subthread)
 Set a flag on an entire thread. More...
 
int mutt_change_flag (struct Email *e, int bf)
 Change the flag on a Message. More...
 

Detailed Description

Manipulate the flags in an email header.

Authors
  • Michael R. Elkins

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file flags.c.

Function Documentation

void mutt_set_flag_update ( struct Mailbox m,
struct Email e,
int  flag,
bool  bf,
bool  upd_mbox 
)

Set a flag on an email.

Parameters
mMailbox
eEmail
flagFlag to set, e.g. MUTT_DELETE
bftrue: set the flag; false: clear the flag
upd_mboxtrue: update the Context

Definition at line 56 of file flags.c.

57 {
58  if (!m || !e)
59  return;
60 
61  bool changed = e->changed;
62  int deleted = m->msg_deleted;
63  int tagged = m->msg_tagged;
64  int flagged = m->msg_flagged;
65  int update = false;
66 
67  if (m->readonly && flag != MUTT_TAG)
68  return; /* don't modify anything if we are read-only */
69 
70  switch (flag)
71  {
72  case MUTT_DELETE:
73 
75  return;
76 
77  if (bf)
78  {
79  if (!e->deleted && !m->readonly && (!e->flagged || !FlagSafe))
80  {
81  e->deleted = true;
82  update = true;
83  if (upd_mbox)
84  m->msg_deleted++;
85 #ifdef USE_IMAP
86  /* deleted messages aren't treated as changed elsewhere so that the
87  * purge-on-sync option works correctly. This isn't applicable here */
88  if (m->magic == MUTT_IMAP)
89  {
90  e->changed = true;
91  if (upd_mbox)
92  m->changed = true;
93  }
94 #endif
95  }
96  }
97  else if (e->deleted)
98  {
99  e->deleted = false;
100  update = true;
101  if (upd_mbox)
102  m->msg_deleted--;
103 #ifdef USE_IMAP
104  /* see my comment above */
105  if (m->magic == MUTT_IMAP)
106  {
107  e->changed = true;
108  if (upd_mbox)
109  m->changed = true;
110  }
111 #endif
112  /* If the user undeletes a message which is marked as
113  * "trash" in the maildir folder on disk, the folder has
114  * been changed, and is marked accordingly. However, we do
115  * _not_ mark the message itself changed, because trashing
116  * is checked in specific code in the maildir folder
117  * driver.
118  */
119  if (m->magic == MUTT_MAILDIR && upd_mbox && e->trash)
120  m->changed = true;
121  }
122  break;
123 
124  case MUTT_PURGE:
125 
127  return;
128 
129  if (bf)
130  {
131  if (!e->purge && !m->readonly)
132  e->purge = true;
133  }
134  else if (e->purge)
135  e->purge = false;
136  break;
137 
138  case MUTT_NEW:
139 
141  return;
142 
143  if (bf)
144  {
145  if (e->read || e->old)
146  {
147  update = true;
148  e->old = false;
149  if (upd_mbox)
150  m->msg_new++;
151  if (e->read)
152  {
153  e->read = false;
154  if (upd_mbox)
155  m->msg_unread++;
156  }
157  e->changed = true;
158  if (upd_mbox)
159  m->changed = true;
160  }
161  }
162  else if (!e->read)
163  {
164  update = true;
165  if (!e->old)
166  if (upd_mbox)
167  m->msg_new--;
168  e->read = true;
169  if (upd_mbox)
170  m->msg_unread--;
171  e->changed = true;
172  if (upd_mbox)
173  m->changed = true;
174  }
175  break;
176 
177  case MUTT_OLD:
178 
180  return;
181 
182  if (bf)
183  {
184  if (!e->old)
185  {
186  update = true;
187  e->old = true;
188  if (!e->read)
189  if (upd_mbox)
190  m->msg_new--;
191  e->changed = true;
192  if (upd_mbox)
193  m->changed = true;
194  }
195  }
196  else if (e->old)
197  {
198  update = true;
199  e->old = false;
200  if (!e->read)
201  if (upd_mbox)
202  m->msg_new++;
203  e->changed = true;
204  if (upd_mbox)
205  m->changed = true;
206  }
207  break;
208 
209  case MUTT_READ:
210 
212  return;
213 
214  if (bf)
215  {
216  if (!e->read)
217  {
218  update = true;
219  e->read = true;
220  if (upd_mbox)
221  m->msg_unread--;
222  if (!e->old)
223  if (upd_mbox)
224  m->msg_new--;
225  e->changed = true;
226  if (upd_mbox)
227  m->changed = true;
228  }
229  }
230  else if (e->read)
231  {
232  update = true;
233  e->read = false;
234  if (upd_mbox)
235  m->msg_unread++;
236  if (!e->old)
237  if (upd_mbox)
238  m->msg_new++;
239  e->changed = true;
240  if (upd_mbox)
241  m->changed = true;
242  }
243  break;
244 
245  case MUTT_REPLIED:
246 
248  return;
249 
250  if (bf)
251  {
252  if (!e->replied)
253  {
254  update = true;
255  e->replied = true;
256  if (!e->read)
257  {
258  e->read = true;
259  if (upd_mbox)
260  m->msg_unread--;
261  if (!e->old)
262  if (upd_mbox)
263  m->msg_new--;
264  }
265  e->changed = true;
266  if (upd_mbox)
267  m->changed = true;
268  }
269  }
270  else if (e->replied)
271  {
272  update = true;
273  e->replied = false;
274  e->changed = true;
275  if (upd_mbox)
276  m->changed = true;
277  }
278  break;
279 
280  case MUTT_FLAG:
281 
283  return;
284 
285  if (bf)
286  {
287  if (!e->flagged)
288  {
289  update = true;
290  e->flagged = bf;
291  if (upd_mbox)
292  m->msg_flagged++;
293  e->changed = true;
294  if (upd_mbox)
295  m->changed = true;
296  }
297  }
298  else if (e->flagged)
299  {
300  update = true;
301  e->flagged = false;
302  if (upd_mbox)
303  m->msg_flagged--;
304  e->changed = true;
305  if (upd_mbox)
306  m->changed = true;
307  }
308  break;
309 
310  case MUTT_TAG:
311  if (bf)
312  {
313  if (!e->tagged)
314  {
315  update = true;
316  e->tagged = true;
317  if (upd_mbox)
318  m->msg_tagged++;
319  }
320  }
321  else if (e->tagged)
322  {
323  update = true;
324  e->tagged = false;
325  if (upd_mbox)
326  m->msg_tagged--;
327  }
328  break;
329  }
330 
331  if (update)
332  {
333  mutt_set_header_color(m, e);
334 #ifdef USE_SIDEBAR
336 #endif
337  }
338 
339  /* if the message status has changed, we need to invalidate the cached
340  * search results so that any future search will match the current status
341  * of this message and not what it was at the time it was last searched.
342  */
343  if (e->searched && (changed != e->changed || deleted != m->msg_deleted ||
344  tagged != m->msg_tagged || flagged != m->msg_flagged))
345  {
346  e->searched = false;
347  }
348 }
#define mutt_bit_isset(v, n)
Definition: memory.h:39
int msg_deleted
number of deleted messages
Definition: mailbox.h:90
int msg_unread
number of unread messages
Definition: mailbox.h:87
unsigned char rights[(MUTT_ACL_MAX+7)/8]
ACL bits.
Definition: mailbox.h:115
int msg_flagged
number of flagged messages
Definition: mailbox.h:88
&#39;Maildir&#39; Mailbox type
Definition: magic.h:40
Messages to be deleted.
Definition: mutt.h:118
Old messages.
Definition: mutt.h:114
bool changed
Definition: email.h:46
void mutt_set_header_color(struct Mailbox *m, struct Email *curhdr)
Select a colour for a message.
Definition: index.c:3514
&#39;IMAP&#39; Mailbox type
Definition: magic.h:42
bool searched
Definition: email.h:68
delete a message
Definition: mailbox.h:61
WHERE bool FlagSafe
Config: Protect flagged messages from deletion.
Definition: globals.h:213
bool tagged
Definition: email.h:42
bool read
Definition: email.h:49
bool old
Definition: email.h:48
enum MailboxType magic
mailbox type
Definition: mailbox.h:99
bool readonly
don&#39;t allow changes to the mailbox
Definition: mailbox.h:113
Tagged messages.
Definition: mutt.h:123
bool trash
message is marked as trashed on disk.
Definition: email.h:58
Messages that have been replied to.
Definition: mutt.h:115
New messages.
Definition: mutt.h:113
Messages to be purged (bypass trash)
Definition: mutt.h:120
bool purge
skip trash folder when deleting
Definition: email.h:44
int msg_tagged
how many messages are tagged?
Definition: mailbox.h:91
Messages that have been read.
Definition: mutt.h:116
bool flagged
marked important?
Definition: email.h:41
change the &#39;seen&#39; status of a message
Definition: mailbox.h:68
int msg_new
number of new messages
Definition: mailbox.h:89
bool deleted
Definition: email.h:43
bool replied
Definition: email.h:52
Flagged messages.
Definition: mutt.h:122
write to a message (for flagging, or linking threads)
Definition: mailbox.h:69
bool changed
mailbox has been modified
Definition: mailbox.h:108

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_tag_set_flag ( int  flag,
int  bf 
)

Set flag on tagged messages.

Parameters
flagFlag to set, e.g. MUTT_DELETE
bftrue: set the flag; false: clear the flag

Definition at line 355 of file flags.c.

356 {
357  for (int i = 0; i < Context->mailbox->msg_count; i++)
358  if (message_is_tagged(Context, i))
359  mutt_set_flag(Context->mailbox, Context->mailbox->hdrs[i], flag, bf);
360 }
The "current" mailbox.
Definition: context.h:36
int msg_count
total number of messages
Definition: mailbox.h:86
struct Email ** hdrs
Definition: mailbox.h:93
struct Mailbox * mailbox
Definition: context.h:50
bool message_is_tagged(struct Context *ctx, int index)
Is a message in the index tagged (and within limit)
Definition: curs_lib.c:1236
#define mutt_set_flag(a, b, c, d)
Definition: protos.h:54

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mutt_thread_set_flag ( struct Email e,
int  flag,
int  bf,
int  subthread 
)

Set a flag on an entire thread.

Parameters
eEmail
flagFlag to set, e.g. MUTT_DELETE
bftrue: set the flag; false: clear the flag
subthreadIf true apply to all of the thread
Return values
0Success
-1Failure

Definition at line 371 of file flags.c.

372 {
373  struct MuttThread *start = NULL, *cur = e->thread;
374 
375  if ((Sort & SORT_MASK) != SORT_THREADS)
376  {
377  mutt_error(_("Threading is not enabled"));
378  return -1;
379  }
380 
381  if (!subthread)
382  while (cur->parent)
383  cur = cur->parent;
384  start = cur;
385 
386  if (cur->message && cur != e->thread)
387  mutt_set_flag(Context->mailbox, cur->message, flag, bf);
388 
389  cur = cur->child;
390  if (!cur)
391  goto done;
392 
393  while (true)
394  {
395  if (cur->message && cur != e->thread)
396  mutt_set_flag(Context->mailbox, cur->message, flag, bf);
397 
398  if (cur->child)
399  cur = cur->child;
400  else if (cur->next)
401  cur = cur->next;
402  else
403  {
404  while (!cur->next)
405  {
406  cur = cur->parent;
407  if (cur == start)
408  goto done;
409  }
410  cur = cur->next;
411  }
412  }
413 done:
414  cur = e->thread;
415  if (cur->message)
416  mutt_set_flag(Context->mailbox, cur->message, flag, bf);
417  return 0;
418 }
The "current" mailbox.
Definition: context.h:36
struct MuttThread * thread
Definition: email.h:96
#define _(a)
Definition: message.h:28
struct Mailbox * mailbox
Definition: context.h:50
#define SORT_THREADS
Sort by email threads.
Definition: sort.h:51
#define mutt_set_flag(a, b, c, d)
Definition: protos.h:54
An email conversation.
Definition: thread.h:34
WHERE short Sort
Config: Sort method for the index.
Definition: sort.h:58
#define mutt_error(...)
Definition: logging.h:88
#define SORT_MASK
Mask for the sort id.
Definition: sort.h:77

+ Here is the caller graph for this function:

int mutt_change_flag ( struct Email e,
int  bf 
)

Change the flag on a Message.

Parameters
eEmail
bftrue: set the flag; false: clear the flag
Return values
0Success
-1Failure

Definition at line 427 of file flags.c.

428 {
429  int i, flag;
430  struct Event event;
431 
433  "%s? (D/N/O/r/*/!): ", bf ? _("Set flag") : _("Clear flag"));
435  mutt_refresh();
436 
437  do
438  {
439  event = mutt_getch();
440  } while (event.ch == -2);
441  i = event.ch;
442  if (i < 0)
443  {
445  return -1;
446  }
447 
449 
450  switch (i)
451  {
452  case 'd':
453  case 'D':
454  if (!bf)
455  {
456  if (e)
458  else
460  }
461  flag = MUTT_DELETE;
462  break;
463 
464  case 'N':
465  case 'n':
466  flag = MUTT_NEW;
467  break;
468 
469  case 'o':
470  case 'O':
471  if (e)
473  else
475  flag = MUTT_OLD;
476  break;
477 
478  case 'r':
479  case 'R':
480  flag = MUTT_REPLIED;
481  break;
482 
483  case '*':
484  flag = MUTT_TAG;
485  break;
486 
487  case '!':
488  flag = MUTT_FLAG;
489  break;
490 
491  default:
492  BEEP();
493  return -1;
494  }
495 
496  if (e)
497  mutt_set_flag(Context->mailbox, e, flag, bf);
498  else
499  mutt_tag_set_flag(flag, bf);
500 
501  return 0;
502 }
The "current" mailbox.
Definition: context.h:36
Messages to be deleted.
Definition: mutt.h:118
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:81
Old messages.
Definition: mutt.h:114
#define _(a)
Definition: message.h:28
An event such as a keypress.
Definition: mutt_curses.h:107
struct Mailbox * mailbox
Definition: context.h:50
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:69
void mutt_tag_set_flag(int flag, int bf)
Set flag on tagged messages.
Definition: flags.c:355
Tagged messages.
Definition: mutt.h:123
Messages that have been replied to.
Definition: mutt.h:115
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:99
struct Event mutt_getch(void)
Read a character from the input buffer.
Definition: curs_lib.c:180
#define BEEP()
Definition: mutt_curses.h:79
New messages.
Definition: mutt.h:113
Messages to be purged (bypass trash)
Definition: mutt.h:120
#define mutt_set_flag(a, b, c, d)
Definition: protos.h:54
Messages that have been read.
Definition: mutt.h:116
Flagged messages.
Definition: mutt.h:122
int mutt_window_mvprintw(struct MuttWindow *win, int row, int col, const char *fmt,...)
Move the cursor and write a formatted string to a Window.
Definition: mutt_window.c:205
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:41

+ Here is the call graph for this function:

+ Here is the caller graph for this function: