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"
22 #include "mutt_menu.h"
35 #include "imap_private.h"
38 #include "mutt_crypt.h"
53 static const char *No_mailbox_is_open = N_("No mailbox is open.");
54 static const char *There_are_no_messages = N_("There are no messages.");
55 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
56 static const char *Function_not_permitted_in_attach_message_mode = N_("Function not permitted in attach-message mode.");
57 static const char *No_visible = N_("No visible messages.");
59 #define CHECK_MSGCOUNT if (!Context) \
62 mutt_error _(No_mailbox_is_open); \
65 else if (!Context->msgcount) \
68 mutt_error _(There_are_no_messages); \
72 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
75 mutt_error _(No_visible); \
80 #define CHECK_READONLY if (Context->readonly) \
83 mutt_error _(Mailbox_is_read_only); \
88 /* the error message returned here could be better. */
89 #define CHECK_IMAP_ACL(aclbit) if (Context->magic == M_IMAP) \
90 if (mutt_bit_isset (((IMAP_DATA *)Context->data)->capabilities, ACL) \
91 && !mutt_bit_isset(((IMAP_DATA *)Context->data)->rights,aclbit)){ \
93 mutt_error ("Operation not permitted by the IMAP ACL for this mailbox"); \
98 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
101 mutt_error _(Function_not_permitted_in_attach_message_mode); \
105 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
106 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
107 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
109 extern const char *ReleaseDate;
110 extern size_t UngetCount;
112 static void set_xterm_title_bar(char *title)
114 fputs("\033]2;", stdout);
115 fputs(title, stdout);
116 fputs("\007", stdout);
120 static void set_xterm_icon_name(char *name)
122 fputs("\033]1;", stdout);
124 fputs("\007", stdout);
128 void index_make_entry (char *s, size_t l, MUTTMENU *menu, int num)
130 format_flag flag = M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
131 int edgemsgno, reverse = Sort & SORT_REVERSE;
132 HEADER *h = Context->hdrs[Context->v2r[num]];
135 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree)
137 flag |= M_FORMAT_TREE; /* display the thread tree */
138 if (h->display_subject)
139 flag |= M_FORMAT_FORCESUBJ;
144 if (menu->top + menu->pagelen > menu->max)
145 edgemsgno = Context->v2r[menu->max - 1];
147 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
150 edgemsgno = Context->v2r[menu->top];
152 for (tmp = h->thread->parent; tmp; tmp = tmp->parent)
157 /* if no ancestor is visible on current screen, provisionally force
159 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno < edgemsgno)
161 flag |= M_FORMAT_FORCESUBJ;
164 else if (tmp->message->virtual >= 0)
167 if (flag & M_FORMAT_FORCESUBJ)
169 for (tmp = h->thread->prev; tmp; tmp = tmp->prev)
174 /* ...but if a previous sibling is available, don't force it */
175 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno < edgemsgno)
177 else if (tmp->message->virtual >= 0)
179 flag &= ~M_FORMAT_FORCESUBJ;
187 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
190 int index_color (int index_no)
192 HEADER *h = Context->hdrs[Context->v2r[index_no]];
197 mutt_set_header_color (Context, h);
201 static int ci_next_undeleted (int msgno)
205 for (i=msgno+1; i < Context->vcount; i++)
206 if (! Context->hdrs[Context->v2r[i]]->deleted)
211 static int ci_previous_undeleted (int msgno)
215 for (i=msgno-1; i>=0; i--)
216 if (! Context->hdrs[Context->v2r[i]]->deleted)
221 /* Return the index of the first new message, or failing that, the first
224 static int ci_first_message (void)
228 if (Context && Context->msgcount)
230 for (i=0; i < Context->vcount; i++)
232 if (! Context->hdrs[Context->v2r[i]]->read &&
233 ! Context->hdrs[Context->v2r[i]]->deleted)
235 if (! Context->hdrs[Context->v2r[i]]->old)
244 /* If Sort is reverse and not threaded, the latest message is first.
245 * If Sort is threaded, the latest message is first iff exactly one
246 * of Sort and SortAux are reverse.
248 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
249 ((Sort & SORT_MASK) == SORT_THREADS &&
250 ((Sort ^ SortAux) & SORT_REVERSE)))
253 return (Context->vcount ? Context->vcount - 1 : 0);
258 /* This should be in mx.c, but it only gets used here. */
259 static int mx_toggle_write (CONTEXT *ctx)
266 mutt_error _("Cannot toggle write on a readonly mailbox!");
273 mutt_message _("Changes to folder will be written on folder exit.");
278 mutt_message _("Changes to folder will not be written.");
284 static void update_index (MUTTMENU *menu, CONTEXT *ctx, int check,
285 int oldcount, int index_hint)
287 /* store pointers to the newly added messages */
288 HEADER **save_new = NULL;
291 /* take note of the current message */
294 if (menu->current < Context->vcount)
295 menu->oldcurrent = index_hint;
297 oldcount = 0; /* invalid message number! */
300 /* We are in a limited view. Check if the new message(s) satisfy
301 * the limit criteria. If they do, set their virtual msgno so that
302 * they will be visible in the limited view */
303 if (Context->pattern)
305 #define THIS_BODY Context->hdrs[j]->content
306 if (oldcount || check == M_REOPENED)
308 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++)
310 if (mutt_pattern_exec (Context->limit_pattern,
311 M_MATCH_FULL_ADDRESS,
312 Context, Context->hdrs[j]))
314 Context->hdrs[j]->virtual = Context->vcount;
315 Context->v2r[Context->vcount] = j;
316 Context->hdrs[j]->limited = 1;
318 Context->vsize += THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
325 /* save the list of new messages */
326 if (oldcount && check != M_REOPENED
327 && ((Sort & SORT_MASK) == SORT_THREADS))
329 save_new = (HEADER **) safe_malloc (sizeof (HEADER *) * (Context->msgcount - oldcount));
330 for (j = oldcount; j < Context->msgcount; j++)
331 save_new[j-oldcount] = Context->hdrs[j];
334 /* if the mailbox was reopened, need to rethread from scratch */
335 mutt_sort_headers (Context, (check == M_REOPENED));
337 /* uncollapse threads with new mail */
338 if ((Sort & SORT_MASK) == SORT_THREADS)
340 if (check == M_REOPENED)
344 Context->collapsed = 0;
346 for (h = Context->tree; h; h = h->next)
348 for (j = h; !j->message; j = j->child)
350 mutt_uncollapse_thread (Context, j->message);
352 mutt_set_virtual (Context);
356 for (j = 0; j < Context->msgcount - oldcount; j++)
360 for (k = 0; k < Context->msgcount; k++)
362 HEADER *h = Context->hdrs[k];
363 if (h == save_new[j] && (!Context->pattern || h->limited))
364 mutt_uncollapse_thread (Context, h);
368 mutt_set_virtual (Context);
375 /* restore the current message to the message it was pointing to */
376 for (j = 0; j < Context->vcount; j++)
378 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent)
386 if (menu->current < 0)
387 menu->current = ci_first_message ();
391 static void resort_index (MUTTMENU *menu)
394 HEADER *current = CURHDR;
397 mutt_sort_headers (Context, 0);
398 /* Restore the current message */
400 for (i = 0; i < Context->vcount; i++)
402 if (Context->hdrs[Context->v2r[i]] == current)
409 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
410 menu->current = mutt_parent_message (Context, current);
412 if (menu->current < 0)
413 menu->current = ci_first_message ();
415 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
418 struct mapping_t IndexHelp[] = {
419 { N_("Quit"), OP_QUIT },
420 { N_("Del"), OP_DELETE },
421 { N_("Undel"), OP_UNDELETE },
422 { N_("Save"), OP_SAVE },
423 { N_("Mail"), OP_MAIL },
424 { N_("Reply"), OP_REPLY },
425 { N_("Group"), OP_GROUP_REPLY },
426 { N_("Help"), OP_HELP },
431 struct mapping_t IndexNewsHelp[] = {
432 { N_("Quit"), OP_QUIT },
433 { N_("Del"), OP_DELETE },
434 { N_("Undel"), OP_UNDELETE },
435 { N_("Save"), OP_SAVE },
436 { N_("Post"), OP_POST },
437 { N_("Followup"), OP_FOLLOWUP },
438 { N_("Catchup"), OP_CATCHUP },
439 { N_("Help"), OP_HELP },
444 /* This function handles the message index window as well as commands returned
445 * from the pager (MENU_PAGER).
447 int mutt_index_menu (void)
449 char buf[LONG_STRING], helpstr[SHORT_STRING];
452 int done = 0; /* controls when to exit the "event" loop */
454 int tag = 0; /* has the tag-prefix command been pressed? */
459 char *cp; /* temporary variable. */
460 int index_hint; /* used to restore cursor position */
461 int do_buffy_notify = 1;
462 int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
463 int attach_msg = option(OPTATTACHMSG);
465 menu = mutt_new_menu ();
466 menu->menu = MENU_MAIN;
468 menu->pagelen = LINES - 3;
469 menu->make_entry = index_make_entry;
470 menu->color = index_color;
471 menu->current = ci_first_message ();
472 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
474 (Context && (Context->magic == M_NNTP)) ? IndexNewsHelp :
479 mutt_buffy_check(1); /* force the buffy check after we enter the folder */
483 tag = 0; /* clear the tag-prefix */
485 menu->max = Context ? Context->vcount : 0;
486 oldcount = Context ? Context->msgcount : 0;
488 /* check if we need to resort the index because just about
489 * any 'op' below could do mutt_enter_command(), either here or
490 * from any new menu launched, and change $sort/$sort_aux
492 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
495 if (option (OPTREDRAWTREE) && Context && Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
497 mutt_draw_tree (Context);
498 menu->redraw |= REDRAW_STATUS;
499 unset_option (OPTREDRAWTREE);
502 if (Context && !attach_msg)
505 /* check for new mail in the mailbox. If nonzero, then something has
506 * changed about the file (either we got new mail or the file was
507 * modified underneath us.)
511 imap_allow_reopen (Context);
514 index_hint = (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ? CURHDR->index : 0;
516 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0)
520 /* fatal error occurred */
522 menu->redraw = REDRAW_FULL;
525 set_option (OPTSEARCHINVALID);
527 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS)
529 update_index (menu, Context, check, oldcount, index_hint);
531 /* notify the user of new mail */
532 if (check == M_REOPENED)
533 mutt_error _("Mailbox was externally modified. Flags may be wrong.");
534 else if (check == M_NEW_MAIL)
536 mutt_message _("New mail in this mailbox.");
537 if (option (OPTBEEPNEW))
539 } else if (check == M_FLAGS)
540 mutt_message _("Mailbox was externally modified.");
542 /* avoid the message being overwritten by buffy */
545 menu->redraw = REDRAW_FULL;
546 menu->max = Context->vcount;
548 set_option (OPTSEARCHINVALID);
554 imap_disallow_reopen (Context);
559 /* check for new mail in the incoming folders */
561 if ((newcount = mutt_buffy_check (0)) != oldcount)
562 menu->redraw |= REDRAW_STATUS;
565 if (mutt_buffy_notify () && option (OPTBEEPNEW))
575 if (menu->redraw & REDRAW_FULL)
577 menu_redraw_full (menu);
578 draw_sidebar(menu->menu);
582 if (menu->menu == MENU_MAIN)
584 if (Context && Context->hdrs && !(menu->current >= Context->vcount))
586 menu_check_recenter (menu);
588 if (menu->redraw & REDRAW_INDEX)
590 menu_redraw_index (menu);
591 menu->redraw |= REDRAW_STATUS;
593 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
594 menu_redraw_motion (menu);
595 else if (menu->redraw & REDRAW_CURRENT)
596 menu_redraw_current (menu);
599 if (menu->redraw & REDRAW_STATUS)
602 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
604 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
605 SETCOLOR (MT_COLOR_STATUS);
606 mutt_paddstr (COLS, buf);
607 SETCOLOR (MT_COLOR_NORMAL);
608 menu->redraw &= ~REDRAW_STATUS;
609 if (option(OPTXTERMSETTITLES))
611 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
612 set_xterm_title_bar(buf);
613 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
614 set_xterm_icon_name(buf);
619 if (menu->current < menu->max)
620 menu->oldcurrent = menu->current;
622 menu->oldcurrent = -1;
624 if (option (OPTARROWCURSOR))
625 move (menu->current - menu->top + menu->offset, 2);
627 move (menu->current - menu->top + menu->offset, COLS - 1);
630 op = km_dokey (MENU_MAIN);
632 dprint(4, (debugfile, "mutt_index_menu[%d]: Got op %d\n", __LINE__, op));
634 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
638 mutt_resize_screen ();
639 menu->redraw = REDRAW_FULL;
640 menu->menu = MENU_MAIN;
642 menu->top = 0; /* so we scroll the right amount */
644 * force a real complete redraw. clrtobot() doesn't seem to be able
645 * to handle every case without this.
647 clearok(stdscr,TRUE);
653 continue; /* either user abort or timeout */
657 /* special handling for the tag-prefix function */
658 if (op == OP_TAG_PREFIX)
662 mutt_error _("No mailbox is open.");
666 if (!Context->tagged)
668 mutt_error _("No tagged messages.");
673 /* give visual indication that the next command is a tag- command */
674 mvaddstr (LINES - 1, 0, "tag-");
677 /* get the real command */
678 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX)
680 /* abort tag sequence */
685 else if (option (OPTAUTOTAG) && Context && Context->tagged)
688 if (op == OP_TAG_PREFIX_COND)
692 mutt_error _("No mailbox is open.");
696 if (!Context->tagged)
702 if(tmp.op==OP_END_COND)break;
704 mutt_message _("Nothing to do.");
709 /* give visual indication that the next command is a tag- command */
710 mvaddstr (LINES - 1, 0, "tag-");
713 /* get the real command */
714 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX)
716 /* abort tag sequence */
726 if (menu->current < menu->max)
727 menu->oldcurrent = menu->current;
729 menu->oldcurrent = -1;
731 mutt_curs_set (1); /* fallback from the pager */
735 unset_option (OPTNEWS); /* for any case */
741 /* ----------------------------------------------------------------------
746 menu_bottom_page (menu);
749 menu_first_entry (menu);
752 menu_middle_page (menu);
758 menu_half_down (menu);
761 menu_next_line (menu);
764 menu_prev_line (menu);
767 menu_next_page (menu);
770 menu_prev_page (menu);
773 menu_last_entry (menu);
776 menu_top_page (menu);
779 menu_current_top (menu);
781 case OP_CURRENT_MIDDLE:
782 menu_current_middle (menu);
784 case OP_CURRENT_BOTTOM:
785 menu_current_bottom (menu);
792 if (Context->magic == M_NNTP)
796 if (op == OP_GET_MESSAGE)
799 if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0) != 0
805 LIST *ref = CURHDR->env->references;
808 mutt_error _("Article has no parent reference!");
811 strfcpy (buf, ref->data, sizeof (buf));
813 if (!Context->id_hash)
814 Context->id_hash = mutt_make_id_hash (Context);
815 if ((h = hash_find (Context->id_hash, buf)))
817 if (h->virtual != -1)
819 menu->current = h->virtual;
820 menu->redraw = REDRAW_MOTION_RESYNCH;
822 else if (h->collapsed)
824 mutt_uncollapse_thread (Context, h);
825 mutt_set_virtual (Context);
826 menu->current = h->virtual;
827 menu->redraw = REDRAW_MOTION_RESYNCH;
830 mutt_error _("Message not visible in limited view.");
834 if (nntp_check_msgid (Context, buf) == 0)
836 h = Context->hdrs[Context->msgcount-1];
837 mutt_sort_headers (Context, 0);
838 menu->current = h->virtual;
839 menu->redraw = REDRAW_FULL;
842 mutt_error (_("Article %s not found on server"), buf);
847 case OP_GET_CHILDREN:
848 case OP_RECONSTRUCT_THREAD:
850 if (Context->magic == M_NNTP)
853 int old = CURHDR->index, i;
855 if (!CURHDR->env->message_id)
857 mutt_error _("No Message-Id. Unable to perform operation");
861 if (!Context->id_hash)
862 Context->id_hash = mutt_make_id_hash (Context);
863 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
865 if (op == OP_RECONSTRUCT_THREAD)
867 LIST *ref = CURHDR->env->references;
870 nntp_check_msgid (Context, ref->data);
871 /* the last msgid in References is the root message */
873 strfcpy (buf, ref->data, sizeof (buf));
877 mutt_message _("Check for children of message...");
878 if (nntp_check_children (Context, buf) == 0)
880 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
881 h = hash_find (Context->id_hash, buf);
882 /* if the root message was retrieved, move to it */
884 menu->current = h->virtual;
885 else /* try to restore old position */
886 for (i = 0; i < Context->msgcount; i++)
887 if (Context->hdrs[i]->index == old)
889 menu->current = Context->hdrs[i]->virtual;
890 /* As an added courtesy, recenter the menu
891 * with the current entry at the middle of the screen */
892 menu_check_recenter (menu);
893 menu_current_middle (menu);
896 menu->redraw = REDRAW_FULL;
906 if (isdigit (LastKey)) mutt_ungetch (LastKey, 0);
908 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
912 if (! isdigit ((unsigned char) buf[0]))
914 mutt_error _("Argument must be a message number.");
919 if (i > 0 && i <= Context->msgcount)
921 for (j = i-1; j < Context->msgcount; j++)
923 if (Context->hdrs[j]->virtual != -1)
926 if (j >= Context->msgcount)
928 for (j = i-2; j >= 0; j--)
930 if (Context->hdrs[j]->virtual != -1)
937 menu->current = Context->hdrs[j]->virtual;
938 if (menu->menu == MENU_PAGER)
940 op = OP_DISPLAY_MESSAGE;
944 menu->redraw = REDRAW_MOTION;
947 mutt_error _("That message is not visible.");
950 mutt_error _("Invalid message number.");
954 /* --------------------------------------------------------------------
955 * `index' specific commands
958 case OP_MAIN_DELETE_PATTERN:
965 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
969 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
970 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
974 case OP_MAIN_FETCH_MAIL:
978 menu->redraw = REDRAW_FULL;
984 mutt_help (MENU_MAIN);
985 menu->redraw = REDRAW_FULL;
988 case OP_MAIN_SHOW_LIMIT:
990 if (!Context->pattern)
991 mutt_message _("No limit pattern is in effect.");
995 /* i18n: ask for a limit to apply */
996 snprintf (buf, sizeof(buf), _("Limit: %s"),Context->pattern);
997 mutt_message ("%s", buf);
1002 case OP_TOGGLE_READ:
1005 menu->oldcurrent = (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ?
1007 if (op == OP_TOGGLE_READ)
1009 char buf[LONG_STRING];
1011 if (!Context->pattern || strncmp (Context->pattern, "!~R!~D~s", 8) != 0)
1013 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
1014 Context->pattern ? Context->pattern : ".*");
1015 set_option (OPTHIDEREAD);
1019 strfcpy (buf, Context->pattern + 8, sizeof(buf));
1020 if (!*buf || strncmp (buf, ".*", 2) == 0)
1021 snprintf (buf, sizeof(buf), "~A");
1022 unset_option (OPTHIDEREAD);
1024 FREE (&Context->pattern);
1025 Context->pattern = safe_strdup (buf);
1027 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
1028 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
1030 if (menu->oldcurrent >= 0)
1032 /* try to find what used to be the current message */
1034 for (i = 0; i < Context->vcount; i++)
1035 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent)
1040 if (menu->current < 0) menu->current = 0;
1044 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1045 if ((Sort & SORT_MASK) == SORT_THREADS)
1046 mutt_draw_tree (Context);
1047 menu->redraw = REDRAW_FULL;
1060 if (query_quadoption (OPT_QUIT, _("Quit Mutt?")) == M_YES)
1064 oldcount = Context ? Context->msgcount : 0;
1066 if (!Context || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1070 if (check == M_NEW_MAIL || check == M_REOPENED)
1071 update_index (menu, Context, check, oldcount, index_hint);
1073 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1074 set_option (OPTSEARCHINVALID);
1081 clearok (stdscr, TRUE);
1082 menu->redraw = REDRAW_FULL;
1086 case OP_SEARCH_REVERSE:
1087 case OP_SEARCH_NEXT:
1088 case OP_SEARCH_OPPOSITE:
1092 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1093 menu->current = menu->oldcurrent;
1095 menu->redraw = REDRAW_MOTION;
1099 case OP_SORT_REVERSE:
1101 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0)
1103 if (Context && Context->msgcount)
1105 resort_index (menu);
1106 set_option (OPTSEARCHINVALID);
1115 if (tag && !option (OPTAUTOTAG))
1117 for (j = 0; j < Context->vcount; j++)
1118 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1119 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1123 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1124 Context->last_tag = CURHDR->tagged ? CURHDR :
1125 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1126 ? NULL : Context->last_tag);
1127 menu->redraw = REDRAW_STATUS;
1128 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1)
1131 menu->redraw |= REDRAW_MOTION_RESYNCH;
1134 menu->redraw |= REDRAW_CURRENT;
1138 case OP_MAIN_TAG_PATTERN:
1142 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1143 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1146 case OP_MAIN_UNDELETE_PATTERN:
1153 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
1156 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) == 0)
1157 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1160 case OP_MAIN_UNTAG_PATTERN:
1164 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1165 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1168 /* --------------------------------------------------------------------
1169 * The following operations can be performed inside of the pager.
1173 case OP_MAIN_IMAP_FETCH:
1174 if (Context->magic == M_IMAP)
1175 imap_check_mailbox (Context, &index_hint, 1);
1179 case OP_MAIN_SYNC_FOLDER:
1181 if (Context && !Context->msgcount)
1188 int oldvcount = Context->vcount;
1189 int oldcount = Context->msgcount;
1193 /* calculate the number of messages _above_ the cursor,
1194 * so we can keep the cursor on the current message
1196 for (j = 0; j <= menu->current; j++)
1198 if (Context->hdrs[Context->v2r[j]]->deleted)
1202 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0)
1204 if (Context->vcount != oldvcount)
1205 menu->current -= dcount;
1206 set_option (OPTSEARCHINVALID);
1208 else if (check == M_NEW_MAIL || check == M_REOPENED)
1209 update_index (menu, Context, check, oldcount, index_hint);
1212 * do a sanity check even if mx_sync_mailbox failed.
1215 if (menu->current < 0 || menu->current >= Context->vcount)
1216 menu->current = ci_first_message ();
1219 /* check for a fatal error, or all messages deleted */
1223 /* if we were in the pager, redisplay the message */
1224 if (menu->menu == MENU_PAGER)
1226 op = OP_DISPLAY_MESSAGE;
1230 menu->redraw = REDRAW_FULL;
1233 case OP_SIDEBAR_OPEN:
1234 case OP_MAIN_CHANGE_FOLDER:
1235 case OP_MAIN_CHANGE_FOLDER_READONLY:
1237 case OP_MAIN_CHANGE_GROUP:
1238 case OP_MAIN_CHANGE_GROUP_READONLY:
1240 if (attach_msg || option (OPTREADONLY) ||
1242 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1244 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1250 cp = _("Open mailbox in read-only mode");
1252 cp = _("Open mailbox");
1256 unset_option (OPTNEWS);
1257 if (op == OP_MAIN_CHANGE_GROUP ||
1258 op == OP_MAIN_CHANGE_GROUP_READONLY)
1260 set_option (OPTNEWS);
1261 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1264 cp = _("Open newsgroup in read-only mode");
1266 cp = _("Open newsgroup");
1271 mutt_buffy (buf, sizeof (buf));
1273 if ( op == OP_SIDEBAR_OPEN ) {
1276 strncpy( buf, CurBuffy->path, sizeof(buf) );
1277 } else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
1281 CLEARLINE (LINES-1);
1286 if (option (OPTNEWS))
1288 unset_option (OPTNEWS);
1289 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1293 mutt_expand_path (buf, sizeof (buf));
1295 if (mx_get_magic (buf) <= 0)
1297 mutt_error (_("%s is not a mailbox."), buf);
1305 #ifdef USE_COMPRESSED
1306 if (Context->compressinfo && Context->realpath)
1307 mutt_str_replace (&LastFolder, Context->realpath);
1311 mutt_str_replace (&LastFolder, Context->path);
1312 oldcount = Context ? Context->msgcount : 0;
1314 if ((check = mx_close_mailbox (Context, &index_hint)) != 0)
1316 if (check == M_NEW_MAIL || check == M_REOPENED)
1317 update_index (menu, Context, check, oldcount, index_hint);
1319 set_option (OPTSEARCHINVALID);
1320 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1328 /* Set CurrentMenu to MENU_MAIN before executing any folder
1329 * hooks so that all the index menu functions are available to
1333 CurrentMenu = MENU_MAIN;
1334 mutt_folder_hook (buf);
1336 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL)
1338 menu->current = ci_first_message ();
1344 /* mutt_buffy_check() must be done with mail-reader mode! */
1345 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1346 (Context && (Context->magic == M_NNTP)) ? IndexNewsHelp : IndexHelp);
1348 mutt_clear_error ();
1349 mutt_buffy_check(1); /* force the buffy check after we have changed
1351 menu->redraw = REDRAW_FULL;
1352 set_option (OPTSEARCHINVALID);
1355 case OP_DISPLAY_MESSAGE:
1356 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1361 * toggle the weeding of headers so that a user can press the key
1362 * again while reading the message.
1364 if (op == OP_DISPLAY_HEADERS)
1365 toggle_option (OPTWEED);
1367 unset_option (OPTNEEDRESORT);
1369 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed)
1371 mutt_uncollapse_thread (Context, CURHDR);
1372 mutt_set_virtual (Context);
1373 if (option (OPTUNCOLLAPSEJUMP))
1374 menu->current = mutt_thread_next_unread (Context, CURHDR);
1377 if ((op = mutt_display_message (CURHDR)) == -1)
1379 unset_option (OPTNEEDRESORT);
1383 menu->menu = MENU_PAGER;
1384 menu->oldcurrent = menu->current;
1390 if (menu->menu == MENU_MAIN && attach_msg)
1396 if ((menu->menu == MENU_MAIN)
1397 && (query_quadoption (OPT_QUIT,
1398 _("Exit Mutt without saving?")) == M_YES))
1402 mx_fastclose_mailbox (Context);
1414 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1415 /* if we were in the pager, redisplay the message */
1416 if (menu->menu == MENU_PAGER)
1418 op = OP_DISPLAY_MESSAGE;
1422 menu->redraw = REDRAW_CURRENT;
1425 case OP_MAIN_NEXT_UNDELETED:
1429 if (menu->current >= Context->vcount - 1)
1431 if (menu->menu == MENU_MAIN)
1432 mutt_error _("You are on the last message.");
1435 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1437 menu->current = menu->oldcurrent;
1438 if (menu->menu == MENU_MAIN)
1439 mutt_error _("No undeleted messages.");
1441 else if (menu->menu == MENU_PAGER)
1443 op = OP_DISPLAY_MESSAGE;
1447 menu->redraw = REDRAW_MOTION;
1454 if (menu->current >= Context->vcount - 1)
1456 if (menu->menu == MENU_MAIN)
1457 mutt_error _("You are on the last message.");
1461 if (menu->menu == MENU_PAGER)
1463 op = OP_DISPLAY_MESSAGE;
1467 menu->redraw = REDRAW_MOTION;
1470 case OP_MAIN_PREV_UNDELETED:
1474 if (menu->current < 1)
1476 mutt_error _("You are on the first message.");
1479 if ((menu->current = ci_previous_undeleted (menu->current)) == -1)
1481 menu->current = menu->oldcurrent;
1482 if (menu->menu == MENU_MAIN)
1483 mutt_error _("No undeleted messages.");
1485 else if (menu->menu == MENU_PAGER)
1487 op = OP_DISPLAY_MESSAGE;
1491 menu->redraw = REDRAW_MOTION;
1498 if (menu->current < 1)
1500 if (menu->menu == MENU_MAIN) mutt_error _("You are on the first message.");
1504 if (menu->menu == MENU_PAGER)
1506 op = OP_DISPLAY_MESSAGE;
1510 menu->redraw = REDRAW_MOTION;
1513 case OP_DECRYPT_COPY:
1514 case OP_DECRYPT_SAVE:
1518 case OP_COPY_MESSAGE:
1520 case OP_DECODE_COPY:
1521 case OP_DECODE_SAVE:
1524 if (mutt_save_message (tag ? NULL : CURHDR,
1525 (op == OP_DECRYPT_SAVE) ||
1526 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1527 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1528 (op == OP_DECRYPT_SAVE) || (op == OP_DECRYPT_COPY) ||
1530 &menu->redraw) == 0 &&
1531 (op == OP_SAVE || op == OP_DECODE_SAVE || op == OP_DECRYPT_SAVE)
1535 menu->redraw |= REDRAW_INDEX;
1536 else if (option (OPTRESOLVE))
1538 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1540 menu->current = menu->oldcurrent;
1541 menu->redraw |= REDRAW_CURRENT;
1544 menu->redraw |= REDRAW_MOTION_RESYNCH;
1547 menu->redraw |= REDRAW_CURRENT;
1551 case OP_MAIN_NEXT_NEW:
1552 case OP_MAIN_NEXT_UNREAD:
1553 case OP_MAIN_PREV_NEW:
1554 case OP_MAIN_PREV_UNREAD:
1555 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1556 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1559 int first_unread = -1;
1567 for (j = 0; j != Context->vcount; j++)
1569 #define CURHDRi Context->hdrs[Context->v2r[i]]
1570 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_NEXT_NEW_THEN_UNREAD)
1573 if (i > Context->vcount - 1)
1575 mutt_message _("Search wrapped to top.");
1584 mutt_message _("Search wrapped to bottom.");
1585 i = Context->vcount - 1;
1589 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS)
1591 if (UNREAD (CURHDRi) && first_unread == -1)
1593 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1596 else if ((!CURHDRi->deleted && !CURHDRi->read))
1598 if (first_unread == -1)
1600 if ((!CURHDRi->old) && first_new == -1)
1604 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1607 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1608 op == OP_MAIN_NEXT_NEW_THEN_UNREAD || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1613 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1614 op == OP_MAIN_NEXT_NEW_THEN_UNREAD || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1616 menu->current = first_new;
1617 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1618 op == OP_MAIN_NEXT_NEW_THEN_UNREAD || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1619 && first_unread != -1)
1620 menu->current = first_unread;
1622 if (menu->current == -1)
1624 menu->current = menu->oldcurrent;
1625 mutt_error ("%s%s.", (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW) ? _("No new messages") : _("No unread messages"),
1626 Context->pattern ? _(" in this limited view") : "");
1628 else if (menu->menu == MENU_PAGER)
1630 op = OP_DISPLAY_MESSAGE;
1634 menu->redraw = REDRAW_MOTION;
1637 case OP_FLAG_MESSAGE:
1644 if (Context->magic == M_POP)
1647 mutt_error _("Can't change 'important' flag on POP server.");
1653 CHECK_IMAP_ACL(IMAP_ACL_WRITE);
1657 if (Context->magic == M_NNTP)
1660 mutt_error _("Can't change 'important' flag on NNTP server.");
1667 for (j = 0; j < Context->vcount; j++)
1669 if (Context->hdrs[Context->v2r[j]]->tagged)
1670 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1671 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1674 menu->redraw |= REDRAW_INDEX;
1678 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1679 if (option (OPTRESOLVE))
1681 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1683 menu->current = menu->oldcurrent;
1684 menu->redraw = REDRAW_CURRENT;
1687 menu->redraw = REDRAW_MOTION_RESYNCH;
1690 menu->redraw = REDRAW_CURRENT;
1692 menu->redraw |= REDRAW_STATUS;
1702 CHECK_IMAP_ACL(IMAP_ACL_SEEN);
1707 for (j = 0; j < Context->vcount; j++)
1709 if (Context->hdrs[Context->v2r[j]]->tagged)
1711 if (Context->hdrs[Context->v2r[j]]->read ||
1712 Context->hdrs[Context->v2r[j]]->old)
1713 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW, 1);
1715 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ, 1);
1718 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1722 if (CURHDR->read || CURHDR->old)
1723 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1725 mutt_set_flag (Context, CURHDR, M_READ, 1);
1727 if (option (OPTRESOLVE))
1729 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1731 menu->current = menu->oldcurrent;
1732 menu->redraw = REDRAW_CURRENT;
1735 menu->redraw = REDRAW_MOTION_RESYNCH;
1738 menu->redraw = REDRAW_CURRENT;
1739 menu->redraw |= REDRAW_STATUS;
1743 case OP_TOGGLE_WRITE:
1746 if (mx_toggle_write (Context) == 0)
1747 menu->redraw |= REDRAW_STATUS;
1750 case OP_MAIN_NEXT_THREAD:
1751 case OP_MAIN_NEXT_SUBTHREAD:
1752 case OP_MAIN_PREV_THREAD:
1753 case OP_MAIN_PREV_SUBTHREAD:
1759 case OP_MAIN_NEXT_THREAD:
1760 menu->current = mutt_next_thread (CURHDR);
1763 case OP_MAIN_NEXT_SUBTHREAD:
1764 menu->current = mutt_next_subthread (CURHDR);
1767 case OP_MAIN_PREV_THREAD:
1768 menu->current = mutt_previous_thread (CURHDR);
1771 case OP_MAIN_PREV_SUBTHREAD:
1772 menu->current = mutt_previous_subthread (CURHDR);
1776 if (menu->current < 0)
1778 menu->current = menu->oldcurrent;
1779 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1780 mutt_error _("No more threads.");
1782 mutt_error _("You are on the first thread.");
1784 else if (menu->menu == MENU_PAGER)
1786 op = OP_DISPLAY_MESSAGE;
1790 menu->redraw = REDRAW_MOTION;
1793 case OP_MAIN_PARENT_MESSAGE:
1798 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0)
1800 menu->current = menu->oldcurrent;
1802 else if (menu->menu == MENU_PAGER)
1804 op = OP_DISPLAY_MESSAGE;
1808 menu->redraw = REDRAW_MOTION;
1811 case OP_MAIN_SET_FLAG:
1812 case OP_MAIN_CLEAR_FLAG:
1819 CHECK_IMAP_ACL(IMAP_ACL_WRITE);
1822 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) == 0)
1824 menu->redraw = REDRAW_STATUS;
1826 menu->redraw |= REDRAW_INDEX;
1827 else if (option (OPTRESOLVE))
1829 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1831 menu->current = menu->oldcurrent;
1832 menu->redraw |= REDRAW_CURRENT;
1835 menu->redraw |= REDRAW_MOTION_RESYNCH;
1838 menu->redraw |= REDRAW_CURRENT;
1842 case OP_MAIN_COLLAPSE_THREAD:
1846 if ((Sort & SORT_MASK) != SORT_THREADS)
1848 mutt_error _("Threading is not enabled.");
1852 if (CURHDR->collapsed)
1854 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1855 mutt_set_virtual (Context);
1856 if (option (OPTUNCOLLAPSEJUMP))
1857 menu->current = mutt_thread_next_unread (Context, CURHDR);
1859 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1861 menu->current = mutt_collapse_thread (Context, CURHDR);
1862 mutt_set_virtual (Context);
1866 mutt_error _("Thread contains unread messages.");
1870 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1874 case OP_MAIN_COLLAPSE_ALL:
1878 if ((Sort & SORT_MASK) != SORT_THREADS)
1880 mutt_error _("Threading is not enabled.");
1886 THREAD *thread, *top;
1889 if (CURHDR->collapsed)
1890 final = mutt_uncollapse_thread (Context, CURHDR);
1891 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1892 final = mutt_collapse_thread (Context, CURHDR);
1894 final = CURHDR->virtual;
1896 base = Context->hdrs[Context->v2r[final]];
1898 top = Context->tree;
1899 Context->collapsed = !Context->collapsed;
1900 while ((thread = top) != NULL)
1902 while (!thread->message)
1903 thread = thread->child;
1904 h = thread->message;
1906 if (h->collapsed != Context->collapsed)
1909 mutt_uncollapse_thread (Context, h);
1910 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1911 mutt_collapse_thread (Context, h);
1916 mutt_set_virtual (Context);
1917 for (j = 0; j < Context->vcount; j++)
1919 if (Context->hdrs[Context->v2r[j]]->index == base->index)
1926 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1930 /* --------------------------------------------------------------------
1931 * These functions are invoked directly from the internal-pager
1934 case OP_BOUNCE_MESSAGE:
1939 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1942 case OP_CREATE_ALIAS:
1944 mutt_create_alias (Context && Context->vcount ? CURHDR->env : NULL, NULL);
1945 MAYBE_REDRAW (menu->redraw);
1946 menu->redraw |= REDRAW_CURRENT;
1951 mutt_query_menu (NULL, 0);
1952 MAYBE_REDRAW (menu->redraw);
1955 case OP_PURGE_MESSAGE:
1963 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
1968 mutt_tag_set_flag (M_DELETE, 1);
1969 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1970 if (option (OPTDELETEUNTAG))
1971 mutt_tag_set_flag (M_TAG, 0);
1972 menu->redraw = REDRAW_INDEX;
1976 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1977 mutt_set_flag (Context, CURHDR, M_PURGED,
1978 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1979 if (option (OPTDELETEUNTAG))
1980 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1981 if (option (OPTRESOLVE))
1983 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1985 menu->current = menu->oldcurrent;
1986 menu->redraw = REDRAW_CURRENT;
1988 else if (menu->menu == MENU_PAGER)
1990 op = OP_DISPLAY_MESSAGE;
1994 menu->redraw |= REDRAW_MOTION_RESYNCH;
1997 menu->redraw = REDRAW_CURRENT;
1999 menu->redraw |= REDRAW_STATUS;
2002 case OP_DELETE_THREAD:
2003 case OP_DELETE_SUBTHREAD:
2010 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
2013 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
2014 op == OP_DELETE_THREAD ? 0 : 1);
2018 if (option (OPTDELETEUNTAG))
2019 mutt_thread_set_flag (CURHDR, M_TAG, 0,
2020 op == OP_DELETE_THREAD ? 0 : 1);
2021 if (option (OPTRESOLVE))
2022 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
2023 menu->current = menu->oldcurrent;
2024 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2030 if (Context && Context->magic == M_NNTP)
2032 if (mutt_newsgroup_catchup (CurrentNewsSrv,
2033 ((NNTP_DATA *)Context->data)->group))
2034 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2039 case OP_DISPLAY_ADDRESS:
2043 mutt_display_address (CURHDR->env);
2046 case OP_ENTER_COMMAND:
2048 CurrentMenu = MENU_MAIN;
2049 mutt_enter_command ();
2050 mutt_check_rescore (Context);
2051 if (option (OPTFORCEREDRAWINDEX))
2052 menu->redraw = REDRAW_FULL;
2053 unset_option (OPTFORCEREDRAWINDEX);
2054 unset_option (OPTFORCEREDRAWPAGER);
2057 case OP_EDIT_MESSAGE:
2065 if (Context->magic == M_POP)
2068 mutt_error _("Can't edit message on POP server.");
2074 CHECK_IMAP_ACL(IMAP_ACL_INSERT);
2078 if (Context->magic == M_NNTP)
2081 mutt_error _("Can't edit message on newsserver.");
2086 mutt_edit_message (Context, tag ? NULL : CURHDR);
2087 menu->redraw = REDRAW_FULL;
2091 case OP_FORWARD_MESSAGE:
2096 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2097 menu->redraw = REDRAW_FULL;
2101 case OP_FORGET_PASSPHRASE:
2102 crypt_forget_passphrase ();
2105 case OP_GROUP_REPLY:
2110 ci_send_message (SENDREPLY|SENDGROUPREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2111 menu->redraw = REDRAW_FULL;
2119 ci_send_message (SENDREPLY|SENDLISTREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2120 menu->redraw = REDRAW_FULL;
2126 ci_send_message (0, NULL, NULL, Context, NULL);
2127 menu->redraw = REDRAW_FULL;
2131 if (!(WithCrypto & APPLICATION_PGP))
2134 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2135 menu->redraw = REDRAW_FULL;
2139 case OP_EXTRACT_KEYS:
2144 crypt_extract_keys_from_messages(tag ? NULL : CURHDR);
2145 menu->redraw = REDRAW_FULL;
2149 case OP_CHECK_TRADITIONAL:
2150 if (!(WithCrypto & APPLICATION_PGP))
2154 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2155 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2157 if (menu->menu == MENU_PAGER)
2159 op = OP_DISPLAY_MESSAGE;
2168 mutt_pipe_message (tag ? NULL : CURHDR);
2169 MAYBE_REDRAW (menu->redraw);
2176 mutt_print_message (tag ? NULL : CURHDR);
2179 case OP_MAIN_READ_THREAD:
2180 case OP_MAIN_READ_SUBTHREAD:
2187 CHECK_IMAP_ACL(IMAP_ACL_SEEN);
2190 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2191 op == OP_MAIN_READ_THREAD ? 0 : 1);
2195 if (option (OPTRESOLVE))
2197 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2198 mutt_next_thread (CURHDR) : mutt_next_subthread (CURHDR))) == -1)
2199 menu->current = menu->oldcurrent;
2201 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2205 case OP_RECALL_MESSAGE:
2208 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2209 menu->redraw = REDRAW_FULL;
2220 for (j = 0; j < Context->vcount; j++)
2222 if (Context->hdrs[Context->v2r[j]]->tagged)
2223 mutt_resend_message (NULL, Context, Context->hdrs[Context->v2r[j]]);
2227 mutt_resend_message (NULL, Context, CURHDR);
2229 menu->redraw = REDRAW_FULL;
2235 case OP_FORWARD_TO_GROUP:
2238 if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2239 mutt_strcasecmp (CURHDR->env->followup_to, "poster") ||
2240 query_quadoption (OPT_FOLLOWUPTOPOSTER,_("Reply by mail as poster prefers?")) != M_YES)
2242 if (Context && Context->magic == M_NNTP &&
2243 !((NNTP_DATA *)Context->data)->allowed &&
2244 query_quadoption (OPT_TOMODERATED, _("Posting to this group not allowed, may be moderated. Continue?")) != M_YES)
2247 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2251 if (op == OP_FOLLOWUP)
2252 ci_send_message (SENDNEWS|SENDREPLY, NULL, NULL, Context,
2253 tag ? NULL : CURHDR);
2255 ci_send_message (SENDNEWS|SENDFORWARD, NULL, NULL, Context,
2256 tag ? NULL : CURHDR);
2258 menu->redraw = REDRAW_FULL;
2268 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2269 menu->redraw = REDRAW_FULL;
2272 case OP_SHELL_ESCAPE:
2274 mutt_shell_escape ();
2275 MAYBE_REDRAW (menu->redraw);
2279 case OP_TAG_SUBTHREAD:
2283 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2284 op == OP_TAG_THREAD ? 0 : 1);
2288 if (option (OPTRESOLVE))
2290 menu->current = mutt_next_thread (CURHDR);
2292 if (menu->current == -1)
2293 menu->current = menu->oldcurrent;
2295 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2306 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
2311 mutt_tag_set_flag (M_DELETE, 0);
2312 mutt_tag_set_flag (M_PURGED, 0);
2313 menu->redraw = REDRAW_INDEX;
2317 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2318 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2319 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1)
2322 menu->redraw = REDRAW_MOTION_RESYNCH;
2325 menu->redraw = REDRAW_CURRENT;
2327 menu->redraw |= REDRAW_STATUS;
2330 case OP_UNDELETE_THREAD:
2331 case OP_UNDELETE_SUBTHREAD:
2338 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
2341 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2342 op == OP_UNDELETE_THREAD ? 0 : 1)
2343 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2344 op == OP_UNDELETE_THREAD ? 0 : 1);
2348 if (option (OPTRESOLVE))
2350 if (op == OP_UNDELETE_THREAD)
2351 menu->current = mutt_next_thread (CURHDR);
2353 menu->current = mutt_next_subthread (CURHDR);
2355 if (menu->current == -1)
2356 menu->current = menu->oldcurrent;
2358 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2370 case OP_VIEW_ATTACHMENTS:
2373 mutt_view_attachments (CURHDR);
2374 if (CURHDR->attach_del)
2375 Context->changed = 1;
2376 menu->redraw = REDRAW_FULL;
2386 case OP_SIDEBAR_SCROLL_UP:
2387 case OP_SIDEBAR_SCROLL_DOWN:
2388 case OP_SIDEBAR_NEXT:
2389 case OP_SIDEBAR_PREV:
2390 scroll_sidebar(op, menu->menu);
2393 if (menu->menu == MENU_MAIN)
2394 km_error_key (MENU_MAIN);
2397 if (menu->menu == MENU_PAGER)
2399 menu->menu = MENU_MAIN;
2400 menu->redraw = REDRAW_FULL;
2402 set_option (OPTWEED); /* turn header weeding back on. */
2410 /* Close all open IMAP connections */
2415 /* Close all open NNTP connections */
2420 mutt_menuDestroy (&menu);
2424 void mutt_set_header_color (CONTEXT *ctx, HEADER *curhdr)
2431 for (color = ColorIndexList; color; color = color->next)
2432 if (mutt_pattern_exec (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr))
2434 curhdr->pair = color->pair;
2437 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];