NeoMutt  2021-10-29-43-g6b8931
Teaching an old dog new tricks
DOXYGEN
functions.c File Reference

Pager functions. More...

#include "config.h"
#include <stddef.h>
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <sys/stat.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "alias/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "functions.h"
#include "lib.h"
#include "attach/lib.h"
#include "color/lib.h"
#include "index/lib.h"
#include "menu/lib.h"
#include "ncrypt/lib.h"
#include "question/lib.h"
#include "send/lib.h"
#include "commands.h"
#include "context.h"
#include "display.h"
#include "keymap.h"
#include "mutt_globals.h"
#include "mutt_header.h"
#include "mutt_mailbox.h"
#include "muttlib.h"
#include "opcodes.h"
#include "options.h"
#include "private_data.h"
#include "protos.h"
#include "recvcmd.h"
#include "sidebar/lib.h"
#include "nntp/lib.h"
#include "nntp/mdata.h"
#include <libintl.h>
+ Include dependency graph for functions.c:

Go to the source code of this file.

Functions

static int op_search_next (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Search for next match - Implements pager_function_t -. More...
 
static bool assert_pager_mode (bool test)
 Check that pager is in correct mode. More...
 
static bool assert_mailbox_writable (struct Mailbox *mailbox)
 Checks that mailbox is writable. More...
 
static bool assert_attach_msg_mode (bool attach_msg)
 Check that attach message mode is on. More...
 
static bool assert_mailbox_permissions (struct Mailbox *m, AclFlags acl, char *action)
 Checks that mailbox is has requested acl flags set. More...
 
static int up_n_lines (int nlines, struct Line *info, int cur, bool hiding)
 Reposition the pager's view up by n lines. More...
 
bool jump_to_bottom (struct PagerPrivateData *priv, struct PagerView *pview)
 Make sure the bottom line is displayed. More...
 
static int op_bounce_message (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Remail a message to another user - Implements pager_function_t -. More...
 
static int op_check_stats (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Calculate message statistics for all mailboxes - Implements pager_function_t -. More...
 
static int op_check_traditional (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Check for classic PGP - Implements pager_function_t -. More...
 
static int op_compose_to_sender (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Compose new message to the current message sender - Implements pager_function_t -. More...
 
static int op_copy_message (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Copy a message to a file/mailbox - Implements pager_function_t -. More...
 
static int op_create_alias (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Create an alias from a message sender - Implements pager_function_t -. More...
 
static int op_delete (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Delete the current entry - Implements pager_function_t -. More...
 
static int op_delete_thread (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Delete all messages in thread - Implements pager_function_t -. More...
 
static int op_display_address (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Display full address of sender - Implements pager_function_t -. More...
 
static int op_edit_label (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Add, change, or delete a message's label - Implements pager_function_t -. More...
 
static int op_enter_command (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Enter a neomuttrc command - Implements pager_function_t -. More...
 
static int op_exit (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Exit this menu - Implements pager_function_t -. More...
 
static int op_extract_keys (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Extract supported public keys - Implements pager_function_t -. More...
 
static int op_flag_message (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Toggle a message's 'important' flag - Implements pager_function_t -. More...
 
static int op_forget_passphrase (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Wipe passphrases from memory - Implements pager_function_t -. More...
 
static int op_forward_message (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Forward a message with comments - Implements pager_function_t -. More...
 
static int op_half_down (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Scroll down 1/2 page - Implements pager_function_t -. More...
 
static int op_half_up (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Scroll up 1/2 page - Implements pager_function_t -. More...
 
static int op_help (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 This screen - Implements pager_function_t -. More...
 
static int op_mail (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Compose a new mail message - Implements pager_function_t -. More...
 
static int op_mailbox_list (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 List mailboxes with new mail - Implements pager_function_t -. More...
 
static int op_mail_key (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Mail a PGP public key - Implements pager_function_t -. More...
 
static int op_main_set_flag (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Set a status flag on a message - Implements pager_function_t -. More...
 
static int op_next_line (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Scroll down one line - Implements pager_function_t -. More...
 
static int op_next_page (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Move to the next page - Implements pager_function_t -. More...
 
static int op_pager_bottom (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Jump to the bottom of the message - Implements pager_function_t -. More...
 
static int op_pager_hide_quoted (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Toggle display of quoted text - Implements pager_function_t -. More...
 
static int op_pager_skip_headers (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Jump to first line after headers - Implements pager_function_t -. More...
 
static int op_pager_skip_quoted (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Skip beyond quoted text - Implements pager_function_t -. More...
 
static int op_pager_top (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Jump to the top of the message - Implements pager_function_t -. More...
 
static int op_pipe (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Pipe message/attachment to a shell command - Implements pager_function_t -. More...
 
static int op_prev_line (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Scroll up one line - Implements pager_function_t -. More...
 
static int op_prev_page (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Move to the previous page - Implements pager_function_t -. More...
 
static int op_print (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Print the current entry - Implements pager_function_t -. More...
 
static int op_quit (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Save changes to mailbox and quit - Implements pager_function_t -. More...
 
static int op_recall_message (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Recall a postponed message - Implements pager_function_t -. More...
 
static int op_redraw (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Clear and redraw the screen - Implements pager_function_t -. More...
 
static int op_reply (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Reply to a message - Implements pager_function_t -. More...
 
static int op_list_subscribe (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Subscribe to a mailing list - Implements pager_function_t -. More...
 
static int op_list_unsubscribe (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Unsubscribe from mailing list - Implements pager_function_t -. More...
 
static int op_resend (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Use the current message as a template for a new one - Implements pager_function_t -. More...
 
static int op_save (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Save message/attachment to a mailbox/file - Implements pager_function_t -. More...
 
static int op_search (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Search for a regular expression - Implements pager_function_t -. More...
 
static int op_search_toggle (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Toggle search pattern coloring - Implements pager_function_t -. More...
 
static int op_shell_escape (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Invoke a command in a subshell - Implements pager_function_t -. More...
 
static int op_sort (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Sort messages - Implements pager_function_t -. More...
 
static int op_tag (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Tag the current entry - Implements pager_function_t -. More...
 
static int op_toggle_new (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Toggle a message's 'new' flag - Implements pager_function_t -. More...
 
static int op_undelete (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Undelete the current entry - Implements pager_function_t -. More...
 
static int op_undelete_thread (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Undelete all messages in thread - Implements pager_function_t -. More...
 
static int op_version (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Show the NeoMutt version number and date - Implements pager_function_t -. More...
 
static int op_view_attachments (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Show MIME attachments - Implements pager_function_t -. More...
 
static int op_what_key (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Display the keycode for a key press - Implements pager_function_t -. More...
 
static int op_followup (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Followup to newsgroup - Implements pager_function_t -. More...
 
static int op_forward_to_group (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Forward to newsgroup - Implements pager_function_t -. More...
 
static int op_post (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Post message to newsgroup - Implements pager_function_t -. More...
 
static int op_sidebar_move (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Move the sidebar highlight - Implements pager_function_t -. More...
 
static int op_sidebar_toggle_visible (struct IndexSharedData *shared, struct PagerPrivateData *priv, int op)
 Make the sidebar (in)visible - Implements pager_function_t -. More...
 
int pager_function_dispatcher (struct MuttWindow *win_pager, int op)
 Perform a Pager function. More...
 

Variables

static const char * Not_available_in_this_menu
 
static const char * Mailbox_is_read_only = N_("Mailbox is read-only")
 
static const char * Function_not_permitted_in_attach_message_mode
 
struct PagerFunction PagerFunctions []
 All the NeoMutt functions that the Pager supports. More...
 

Detailed Description

Pager functions.

Authors
  • Richard Russon

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 functions.c.

Function Documentation

◆ assert_pager_mode()

static bool assert_pager_mode ( bool  test)
inlinestatic

Check that pager is in correct mode.

Parameters
testTest condition
Return values
trueExpected mode is set
falsePager is is some other mode
Note
On failure, the input will be flushed and an error message displayed

Definition at line 94 of file functions.c.

95 {
96  if (test)
97  return true;
98 
99  mutt_flushinp();
101  return false;
102 }
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:673
#define mutt_error(...)
Definition: logging.h:87
#define _(a)
Definition: message.h:28
static const char * Not_available_in_this_menu
Definition: functions.c:77
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ assert_mailbox_writable()

static bool assert_mailbox_writable ( struct Mailbox mailbox)
inlinestatic

Checks that mailbox is writable.

Parameters
mailboxmailbox to check
Return values
trueMailbox is writable
falseMailbox is not writable
Note
On failure, the input will be flushed and an error message displayed

Definition at line 112 of file functions.c.

113 {
114  assert(mailbox);
115  if (mailbox->readonly)
116  {
117  mutt_flushinp();
119  return false;
120  }
121  return true;
122 }
static const char * Mailbox_is_read_only
Definition: functions.c:79
bool readonly
Don't allow changes to the mailbox.
Definition: mailbox.h:119
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ assert_attach_msg_mode()

static bool assert_attach_msg_mode ( bool  attach_msg)
inlinestatic

Check that attach message mode is on.

Parameters
attach_msgGlobally-named boolean pseudo-option
Return values
trueAttach message mode in on
falseAttach message mode is off
Note
On true, the input will be flushed and an error message displayed

Definition at line 132 of file functions.c.

133 {
134  if (attach_msg)
135  {
136  mutt_flushinp();
138  return true;
139  }
140  return false;
141 }
static const char * Function_not_permitted_in_attach_message_mode
Definition: functions.c:80
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ assert_mailbox_permissions()

static bool assert_mailbox_permissions ( struct Mailbox m,
AclFlags  acl,
char *  action 
)
inlinestatic

Checks that mailbox is has requested acl flags set.

Parameters
mMailbox to check
aclAclFlags required to be set on a given mailbox
actionString to augment error message
Return values
trueMailbox has necessary flags set
falseMailbox does not have necessary flags set
Note
On failure, the input will be flushed and an error message displayed

Definition at line 153 of file functions.c.

154 {
155  assert(m);
156  assert(action);
157  if (m->rights & acl)
158  {
159  return true;
160  }
161  mutt_flushinp();
162  /* L10N: %s is one of the CHECK_ACL entries below. */
163  mutt_error(_("%s: Operation not permitted by ACL"), action);
164  return false;
165 }
AclFlags rights
ACL bits, see AclFlags.
Definition: mailbox.h:121
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ up_n_lines()

static int up_n_lines ( int  nlines,
struct Line info,
int  cur,
bool  hiding 
)
static

Reposition the pager's view up by n lines.

Parameters
nlinesNumber of lines to move
infoLine info array
curCurrent line number
hidingtrue if lines have been hidden
Return values
numNew current line number

Definition at line 175 of file functions.c.

176 {
177  while ((cur > 0) && (nlines > 0))
178  {
179  cur--;
180  if (!hiding || (info[cur].color != MT_COLOR_QUOTED))
181  nlines--;
182  }
183 
184  return cur;
185 }
@ MT_COLOR_QUOTED
Pager: quoted text.
Definition: color.h:57
+ Here is the caller graph for this function:

◆ jump_to_bottom()

bool jump_to_bottom ( struct PagerPrivateData priv,
struct PagerView pview 
)

Make sure the bottom line is displayed.

Parameters
privPrivate Pager data
pviewPagerView
Return values
trueSomething changed
falseBottom was already displayed

Definition at line 194 of file functions.c.

195 {
196  if (!(priv->lines[priv->cur_line].offset < (priv->st.st_size - 1)))
197  {
198  return false;
199  }
200 
201  int line_num = priv->cur_line;
202  /* make sure the types are defined to the end of file */
203  while (display_line(priv->fp, &priv->bytes_read, &priv->lines, line_num,
204  &priv->lines_used, &priv->lines_max,
205  priv->has_types | (pview->flags & MUTT_PAGER_NOWRAP),
206  &priv->quote_list, &priv->q_level, &priv->force_redraw,
207  &priv->search_re, priv->pview->win_pager) == 0)
208  {
209  line_num++;
210  }
211  priv->top_line = up_n_lines(priv->pview->win_pager->state.rows, priv->lines,
212  priv->lines_used, priv->hide_quoted);
213  notify_send(priv->notify, NT_PAGER, NT_PAGER_VIEW, priv);
214  return true;
215 }
int display_line(FILE *fp, LOFF_T *bytes_read, struct Line **lines, int line_num, int *lines_used, int *lines_max, PagerFlags flags, struct QuoteStyle **quote_list, int *q_level, bool *force_redraw, regex_t *search_re, struct MuttWindow *win_pager)
Print a line on screen.
Definition: display.c:1038
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:171
@ NT_PAGER
Pager data has changed, NotifyPager, PagerPrivateData.
Definition: notify_type.h:50
static int up_n_lines(int nlines, struct Line *info, int cur, bool hiding)
Reposition the pager's view up by n lines.
Definition: functions.c:175
#define NT_PAGER_VIEW
Pager View has changed.
Definition: lib.h:174
#define MUTT_PAGER_NOWRAP
Format for term width, ignore $wrap.
Definition: lib.h:72
LOFF_T offset
Offset into Email file (PagerPrivateData->fp)
Definition: display.h:72
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
PagerFlags hide_quoted
Set to MUTT_HIDE when quoted email is hidden <toggle-quoted>
Definition: private_data.h:62
int q_level
Number of unique quoting levels.
Definition: private_data.h:61
int cur_line
Current line (last line visible on screen)
Definition: private_data.h:53
int lines_used
Size of lines array (used entries)
Definition: private_data.h:51
int lines_max
Capacity of lines array (total entries)
Definition: private_data.h:52
bool force_redraw
Repaint is needed.
Definition: private_data.h:73
struct Line * lines
Array of text lines in pager.
Definition: private_data.h:50
int has_types
Set to MUTT_TYPES for PAGER_MODE_EMAIL or MUTT_SHOWCOLOR.
Definition: private_data.h:58
struct Notify * notify
Notifications: NotifyPager, PagerPrivateData.
Definition: private_data.h:75
LOFF_T bytes_read
Number of bytes read from file.
Definition: private_data.h:48
int top_line
First visible line on screen.
Definition: private_data.h:57
struct stat st
Stats about Email file.
Definition: private_data.h:47
struct QuoteStyle * quote_list
Tree of quoting levels.
Definition: private_data.h:60
struct PagerView * pview
Object to view in the pager.
Definition: private_data.h:44
regex_t search_re
Compiled search string.
Definition: private_data.h:67
FILE * fp
File containing decrypted/decoded/weeded Email.
Definition: private_data.h:46
PagerFlags flags
Additional settings to tweak pager's function.
Definition: lib.h:163
struct MuttWindow * win_pager
Pager Window.
Definition: lib.h:168
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pager_function_dispatcher()

int pager_function_dispatcher ( struct MuttWindow win_pager,
int  op 
)

Perform a Pager function.

Parameters
win_pagerWindow for the Index
opOperation to perform, e.g. OP_MAIN_LIMIT
Return values
numIndexRetval, e.g. IR_SUCCESS

Definition at line 1911 of file functions.c.

1912 {
1913  if (!win_pager)
1914  {
1916  return IR_ERROR;
1917  }
1918 
1919  struct PagerPrivateData *priv = win_pager->parent->wdata;
1920  if (!priv)
1921  return IR_ERROR;
1922 
1923  struct MuttWindow *dlg = dialog_find(win_pager);
1924  if (!dlg || !dlg->wdata)
1925  return IR_ERROR;
1926 
1927  int rc = IR_UNKNOWN;
1928  for (size_t i = 0; PagerFunctions[i].op != OP_NULL; i++)
1929  {
1930  const struct PagerFunction *fn = &PagerFunctions[i];
1931  if (fn->op == op)
1932  {
1933  struct IndexSharedData *shared = dlg->wdata;
1934  rc = fn->function(shared, priv, op);
1935  break;
1936  }
1937  }
1938 
1939  return rc;
1940 }
struct MuttWindow * dialog_find(struct MuttWindow *win)
Find the parent Dialog of a Window.
Definition: dialog.c:83
@ IR_UNKNOWN
Unknown key.
Definition: functions.h:35
@ IR_ERROR
Valid function - error occurred.
Definition: functions.h:40
struct PagerFunction PagerFunctions[]
All the NeoMutt functions that the Pager supports.
Definition: functions.c:1812
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:37
void * wdata
Private data.
Definition: mutt_window.h:145
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
A NeoMutt function.
Definition: functions.h:49
pager_function_t function
Function to call.
Definition: functions.h:51
int op
Op code, e.g. OP_MAIN_LIMIT.
Definition: functions.h:50
Private state data for the Pager.
Definition: private_data.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ Not_available_in_this_menu

const char* Not_available_in_this_menu
static
Initial value:
=
N_("Not available in this menu")
#define N_(a)
Definition: message.h:32

Definition at line 77 of file functions.c.

◆ Mailbox_is_read_only

const char* Mailbox_is_read_only = N_("Mailbox is read-only")
static

Definition at line 79 of file functions.c.

◆ Function_not_permitted_in_attach_message_mode

const char* Function_not_permitted_in_attach_message_mode
static
Initial value:
=
N_("Function not permitted in attach-message mode")

Definition at line 80 of file functions.c.

◆ PagerFunctions

struct PagerFunction PagerFunctions[]

All the NeoMutt functions that the Pager supports.

Definition at line 1797 of file functions.c.