NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
functions.c File Reference

Alias functions. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "functions.h"
#include "lib.h"
#include "editor/lib.h"
#include "history/lib.h"
#include "key/lib.h"
#include "menu/lib.h"
#include "pattern/lib.h"
#include "question/lib.h"
#include "alias.h"
#include "gui.h"
#include "module_data.h"
#include "sort.h"
+ Include dependency graph for functions.c:

Go to the source code of this file.

Functions

void alias_init_keys (struct NeoMutt *n, struct SubMenu *sm_generic)
 Initialise the Alias Keybindings - Implements ::init_keys_api.
 
static int op_create_alias (struct AliasFunctionData *fdata, const struct KeyEvent *event)
 create an alias from a message sender - Implements alias_function_t -
 
static int alias_add_selection (struct AliasViewPtrArray *avpa, struct AliasMenuData *mdata, bool tagged, int count)
 Build a working set of AliasView pointers for an action.
 
static void alias_apply_set_deleted (struct AliasViewPtrArray *avpa, bool deleted)
 Apply the deleted flag to a working set of AliasViews.
 
static int op_delete (struct AliasFunctionData *fdata, const struct KeyEvent *event)
 delete the current entry - Implements alias_function_t -
 
static int op_exit (struct AliasFunctionData *fdata, const struct KeyEvent *event)
 exit this menu - Implements alias_function_t -
 
static int op_jump (struct AliasFunctionData *fdata, const struct KeyEvent *event)
 Jump to an index number - Implements alias_function_t -.
 
static int alias_select_entries (struct AliasMenuData *mdata, int count)
 Select entries to return from the Alias Dialog.
 
static int op_generic_select_entry (struct AliasFunctionData *fdata, const struct KeyEvent *event)
 select the current entry - Implements alias_function_t -
 
static int op_mail (struct AliasFunctionData *fdata, const struct KeyEvent *event)
 mail the selected entries - Implements alias_function_t -
 
static int op_main_limit (struct AliasFunctionData *fdata, const struct KeyEvent *event)
 show only messages matching a pattern - Implements alias_function_t -
 
static int op_main_tag_pattern (struct AliasFunctionData *fdata, const struct KeyEvent *event)
 Tag messages matching a pattern - Implements alias_function_t -.
 
static int op_main_untag_pattern (struct AliasFunctionData *fdata, const struct KeyEvent *event)
 Untag messages matching a pattern - Implements alias_function_t -.
 
static int op_query (struct AliasFunctionData *fdata, const struct KeyEvent *event)
 query external program for addresses - Implements alias_function_t -
 
static int op_search (struct AliasFunctionData *fdata, const struct KeyEvent *event)
 search for a regular expression - Implements alias_function_t -
 
static int op_sort (struct AliasFunctionData *fdata, const struct KeyEvent *event)
 sort aliases - Implements alias_function_t -
 
int alias_function_dispatcher (struct MuttWindow *win, const struct KeyEvent *event)
 Perform a Alias function - Implements function_dispatcher_t -.
 

Variables

static const struct MenuFuncOp OpAlias []
 Functions for the Alias Menu.
 
const struct MenuFuncOp OpQuery []
 Functions for the external Query Menu.
 
static const struct MenuOpSeq AliasDefaultBindings []
 Key bindings for the Alias Menu.
 
static const struct MenuOpSeq QueryDefaultBindings []
 Key bindings for the external Query Menu.
 
static const struct AliasFunction AliasFunctions []
 All the NeoMutt functions that the Alias supports.
 

Detailed Description

Alias functions.

Authors
  • Richard Russon
  • Dennis Schön

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

◆ alias_init_keys()

void alias_init_keys ( struct NeoMutt * n,
struct SubMenu * sm_generic )

Initialise the Alias Keybindings - Implements ::init_keys_api.

Definition at line 124 of file functions.c.

125{
127 ASSERT(mod_data);
128
129 struct MenuDefinition *md = NULL;
130 struct SubMenu *sm = NULL;
131
133 md = km_register_menu(MENU_ALIAS, "alias");
134 km_menu_add_submenu(md, sm);
135 km_menu_add_submenu(md, sm_generic);
137
138 mod_data->menu_alias = md;
139
141 md = km_register_menu(MENU_QUERY, "query");
142 km_menu_add_submenu(md, sm);
143 km_menu_add_submenu(md, sm_generic);
145
146 mod_data->menu_query = md;
147}
const struct MenuFuncOp OpQuery[]
Functions for the external Query Menu.
Definition functions.c:71
static const struct MenuOpSeq QueryDefaultBindings[]
Key bindings for the external Query Menu.
Definition functions.c:105
static const struct MenuOpSeq AliasDefaultBindings[]
Key bindings for the Alias Menu.
Definition functions.c:88
static const struct MenuFuncOp OpAlias[]
Functions for the Alias Menu.
Definition functions.c:55
void km_menu_add_submenu(struct MenuDefinition *md, struct SubMenu *sm)
Add a SubMenu to a Menu Definition.
Definition init.c:121
struct SubMenu * km_register_submenu(const struct MenuFuncOp functions[])
Register a submenu.
Definition init.c:87
struct MenuDefinition * km_register_menu(int menu, const char *name)
Register a menu.
Definition init.c:104
void km_menu_add_bindings(struct MenuDefinition *md, const struct MenuOpSeq bindings[])
Add Keybindings to a Menu.
Definition init.c:134
@ MODULE_ID_ALIAS
ModuleAlias, Alias
Definition module_api.h:48
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
#define ASSERT(COND)
Definition signal2.h:59
Alias private Module data.
Definition module_data.h:33
struct MenuDefinition * menu_query
Query menu definition.
Definition module_data.h:43
struct MenuDefinition * menu_alias
Alias menu definition.
Definition module_data.h:42
Functions for a Dialog or Window.
Definition menu.h:77
Collection of related functions.
Definition menu.h:65
@ MENU_QUERY
Select from results of external query.
Definition type.h:49
@ MENU_ALIAS
Select an email address by its alias.
Definition type.h:34
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ alias_add_selection()

static int alias_add_selection ( struct AliasViewPtrArray * avpa,
struct AliasMenuData * mdata,
bool tagged,
int count )
static

Build a working set of AliasView pointers for an action.

Parameters
avpaAliasView Array to populate
mdataAlias Menu data
taggedUse tagged AliasViews (tag-prefix)
countRepeat-count (0 or 1 == just the current selection)
Return values
numNumber of AliasViews added

If tagged is true, the array is filled with the tagged AliasViews and count is ignored.

Otherwise the array is filled with the current selection and the next count - 1 visible AliasViews. Overruns are silently capped at the end of the visible list.

Definition at line 209 of file functions.c.

211{
212 if (!avpa || !mdata)
213 return 0;
214
215 if (tagged)
216 {
217 struct AliasView *avp = NULL;
218 ARRAY_FOREACH(avp, &mdata->ava)
219 {
220 if (avp->is_tagged)
221 ARRAY_ADD(avpa, avp);
222 }
223 }
224 else
225 {
226 struct Menu *menu = mdata->menu;
227 const int index = menu_get_index(menu);
228 if ((index < 0) || (index >= menu->max))
229 return 0;
230
231 int n = (count > 1) ? count : 1;
232 if ((index + n) > menu->max)
233 n = menu->max - index;
234
235 for (int i = 0; i < n; i++)
236 {
237 struct AliasView *av = ARRAY_GET(&mdata->ava, index + i);
238 if (av)
239 ARRAY_ADD(avpa, av);
240 }
241 }
242
243 return ARRAY_SIZE(avpa);
244}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
#define ARRAY_GET(head, idx)
Return the element at index.
Definition array.h:109
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition menu.c:155
struct AliasViewArray ava
All Aliases/Queries.
Definition gui.h:56
GUI data wrapping an Alias.
Definition gui.h:38
bool is_tagged
Is it tagged?
Definition gui.h:43
Definition lib.h:86
void * mdata
Private data.
Definition lib.h:155
int max
Number of entries in the menu.
Definition lib.h:88
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ alias_apply_set_deleted()

static void alias_apply_set_deleted ( struct AliasViewPtrArray * avpa,
bool deleted )
static

Apply the deleted flag to a working set of AliasViews.

Parameters
avpaWorking set of AliasView pointers
deletedtrue to mark as deleted, false to undelete

Definition at line 251 of file functions.c.

252{
253 if (!avpa)
254 return;
255
256 struct AliasView **avpp = NULL;
257 ARRAY_FOREACH(avpp, avpa)
258 {
259 if (*avpp)
260 (*avpp)->is_deleted = deleted;
261 }
262}
bool is_deleted
Is it deleted?
Definition gui.h:44
+ Here is the caller graph for this function:

◆ alias_select_entries()

static int alias_select_entries ( struct AliasMenuData * mdata,
int count )
static

Select entries to return from the Alias Dialog.

Parameters
mdataAlias Menu data
countRepeat-count (0 or 1 == just the current selection)
Return values
enumFunctionRetval
Note
AliasMenuData.is_tagged will show the user's selection

Definition at line 347 of file functions.c.

348{
349 struct Menu *menu = mdata->menu;
350 if (menu->tag_prefix)
351 {
352 // Untag any non-visible aliases
353 struct AliasView *avp = NULL;
354 ARRAY_FOREACH(avp, &mdata->ava)
355 {
356 if (avp->is_tagged && !avp->is_visible)
357 avp->is_tagged = false;
358 }
359 }
360 else
361 {
362 struct AliasViewPtrArray avpa = ARRAY_HEAD_INITIALIZER;
363 alias_add_selection(&avpa, mdata, false, count);
364 if (ARRAY_EMPTY(&avpa))
365 {
366 ARRAY_FREE(&avpa);
367 return FR_NO_ACTION;
368 }
369
370 // Untag all but the selected alias(es)
371 struct AliasView *avp = NULL;
372 ARRAY_FOREACH(avp, &mdata->ava)
373 {
374 avp->is_tagged = false;
375 }
376
377 struct AliasView **avpp = NULL;
378 ARRAY_FOREACH(avpp, &avpa)
379 {
380 if (*avpp)
381 (*avpp)->is_tagged = true;
382 }
383 ARRAY_FREE(&avpa);
384 }
385
386 return FR_CONTINUE;
387}
static int alias_add_selection(struct AliasViewPtrArray *avpa, struct AliasMenuData *mdata, bool tagged, int count)
Build a working set of AliasView pointers for an action.
Definition functions.c:209
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition array.h:74
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition array.h:58
@ FR_CONTINUE
Remain in the Dialog.
Definition dispatcher.h:35
@ FR_NO_ACTION
Valid function - no action performed.
Definition dispatcher.h:38
bool is_visible
Is visible?
Definition gui.h:45
bool tag_prefix
User has pressed <tag-prefix>
Definition lib.h:92
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ OpAlias

const struct MenuFuncOp OpAlias[]
static
Initial value:
= {
{ "delete-entry", OP_DELETE },
{ "exit", OP_EXIT },
{ "limit", OP_MAIN_LIMIT },
{ "mail", OP_MAIL },
{ "sort-alias", OP_SORT },
{ "sort-alias-reverse", OP_SORT_REVERSE },
{ "tag-pattern", OP_MAIN_TAG_PATTERN },
{ "undelete-entry", OP_UNDELETE },
{ "untag-pattern", OP_MAIN_UNTAG_PATTERN },
{ NULL, 0 },
}

Functions for the Alias Menu.

Definition at line 55 of file functions.c.

55 { /* map: alias */
56 { "delete-entry", OP_DELETE },
57 { "exit", OP_EXIT },
58 { "limit", OP_MAIN_LIMIT },
59 { "mail", OP_MAIL },
60 { "sort-alias", OP_SORT },
61 { "sort-alias-reverse", OP_SORT_REVERSE },
62 { "tag-pattern", OP_MAIN_TAG_PATTERN },
63 { "undelete-entry", OP_UNDELETE },
64 { "untag-pattern", OP_MAIN_UNTAG_PATTERN },
65 { NULL, 0 },
66};

◆ OpQuery

const struct MenuFuncOp OpQuery[]
Initial value:
= {
{ "create-alias", OP_CREATE_ALIAS },
{ "exit", OP_EXIT },
{ "limit", OP_MAIN_LIMIT },
{ "mail", OP_MAIL },
{ "query", OP_QUERY },
{ "query-append", OP_QUERY_APPEND },
{ "sort", OP_SORT },
{ "sort-reverse", OP_SORT_REVERSE },
{ "tag-pattern", OP_MAIN_TAG_PATTERN },
{ "untag-pattern", OP_MAIN_UNTAG_PATTERN },
{ NULL, 0 },
}

Functions for the external Query Menu.

Definition at line 71 of file functions.c.

71 { /* map: query */
72 { "create-alias", OP_CREATE_ALIAS },
73 { "exit", OP_EXIT },
74 { "limit", OP_MAIN_LIMIT },
75 { "mail", OP_MAIL },
76 { "query", OP_QUERY },
77 { "query-append", OP_QUERY_APPEND },
78 { "sort", OP_SORT },
79 { "sort-reverse", OP_SORT_REVERSE },
80 { "tag-pattern", OP_MAIN_TAG_PATTERN },
81 { "untag-pattern", OP_MAIN_UNTAG_PATTERN },
82 { NULL, 0 },
83};

◆ AliasDefaultBindings

const struct MenuOpSeq AliasDefaultBindings[]
static
Initial value:
= {
{ OP_DELETE, "d" },
{ OP_EXIT, "q" },
{ OP_MAIL, "m" },
{ OP_MAIN_LIMIT, "l" },
{ OP_MAIN_TAG_PATTERN, "T" },
{ OP_MAIN_UNTAG_PATTERN, "\024" },
{ OP_SORT, "o" },
{ OP_SORT_REVERSE, "O" },
{ OP_TAG, "<space>" },
{ OP_UNDELETE, "u" },
{ 0, NULL },
}

Key bindings for the Alias Menu.

Definition at line 88 of file functions.c.

88 { /* map: alias */
89 { OP_DELETE, "d" },
90 { OP_EXIT, "q" },
91 { OP_MAIL, "m" },
92 { OP_MAIN_LIMIT, "l" },
93 { OP_MAIN_TAG_PATTERN, "T" },
94 { OP_MAIN_UNTAG_PATTERN, "\024" }, // <Ctrl-T>
95 { OP_SORT, "o" },
96 { OP_SORT_REVERSE, "O" },
97 { OP_TAG, "<space>" },
98 { OP_UNDELETE, "u" },
99 { 0, NULL },
100};

◆ QueryDefaultBindings

const struct MenuOpSeq QueryDefaultBindings[]
static
Initial value:
= {
{ OP_CREATE_ALIAS, "a" },
{ OP_EXIT, "q" },
{ OP_MAIL, "m" },
{ OP_MAIN_LIMIT, "l" },
{ OP_MAIN_TAG_PATTERN, "T" },
{ OP_MAIN_UNTAG_PATTERN, "\024" },
{ OP_QUERY, "Q" },
{ OP_QUERY_APPEND, "A" },
{ OP_SORT, "o" },
{ OP_SORT_REVERSE, "O" },
{ OP_TAG, "<space>" },
{ 0, NULL },
}

Key bindings for the external Query Menu.

Definition at line 105 of file functions.c.

105 { /* map: query */
106 { OP_CREATE_ALIAS, "a" },
107 { OP_EXIT, "q" },
108 { OP_MAIL, "m" },
109 { OP_MAIN_LIMIT, "l" },
110 { OP_MAIN_TAG_PATTERN, "T" },
111 { OP_MAIN_UNTAG_PATTERN, "\024" }, // <Ctrl-T>
112 { OP_QUERY, "Q" },
113 { OP_QUERY_APPEND, "A" },
114 { OP_SORT, "o" },
115 { OP_SORT_REVERSE, "O" },
116 { OP_TAG, "<space>" },
117 { 0, NULL },
118};

◆ AliasFunctions

const struct AliasFunction AliasFunctions[]
static
Initial value:
= {
{ OP_CREATE_ALIAS, op_create_alias },
{ OP_DELETE, op_delete },
{ OP_EXIT, op_exit },
{ OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
{ OP_MAIL, op_mail },
{ OP_MAIN_LIMIT, op_main_limit },
{ OP_MAIN_TAG_PATTERN, op_main_tag_pattern },
{ OP_MAIN_UNTAG_PATTERN, op_main_untag_pattern },
{ OP_QUERY, op_query },
{ OP_QUERY_APPEND, op_query },
{ OP_SEARCH, op_search },
{ OP_SEARCH_NEXT, op_search },
{ OP_SEARCH_OPPOSITE, op_search },
{ OP_SEARCH_REVERSE, op_search },
{ OP_SORT, op_sort },
{ OP_SORT_REVERSE, op_sort },
{ OP_UNDELETE, op_delete },
{ 0, NULL },
}
static int op_main_limit(struct AliasFunctionData *fdata, const struct KeyEvent *event)
show only messages matching a pattern - Implements alias_function_t -
Definition functions.c:411
static int op_query(struct AliasFunctionData *fdata, const struct KeyEvent *event)
query external program for addresses - Implements alias_function_t -
Definition functions.c:469
static int op_create_alias(struct AliasFunctionData *fdata, const struct KeyEvent *event)
create an alias from a message sender - Implements alias_function_t -
Definition functions.c:152
static int op_main_untag_pattern(struct AliasFunctionData *fdata, const struct KeyEvent *event)
Untag messages matching a pattern - Implements alias_function_t -.
Definition functions.c:448
static int op_main_tag_pattern(struct AliasFunctionData *fdata, const struct KeyEvent *event)
Tag messages matching a pattern - Implements alias_function_t -.
Definition functions.c:431
static int op_exit(struct AliasFunctionData *fdata, const struct KeyEvent *event)
exit this menu - Implements alias_function_t -
Definition functions.c:312
static int op_mail(struct AliasFunctionData *fdata, const struct KeyEvent *event)
mail the selected entries - Implements alias_function_t -
Definition functions.c:403
static int op_delete(struct AliasFunctionData *fdata, const struct KeyEvent *event)
delete the current entry - Implements alias_function_t -
Definition functions.c:274
static int op_search(struct AliasFunctionData *fdata, const struct KeyEvent *event)
search for a regular expression - Implements alias_function_t -
Definition functions.c:523
static int op_generic_select_entry(struct AliasFunctionData *fdata, const struct KeyEvent *event)
select the current entry - Implements alias_function_t -
Definition functions.c:392
static int op_sort(struct AliasFunctionData *fdata, const struct KeyEvent *event)
sort aliases - Implements alias_function_t -
Definition functions.c:561

All the NeoMutt functions that the Alias supports.

Definition at line 614 of file functions.c.

614 {
615 // clang-format off
616 { OP_CREATE_ALIAS, op_create_alias },
617 { OP_DELETE, op_delete },
618 { OP_EXIT, op_exit },
619 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
620 { OP_MAIL, op_mail },
621 { OP_MAIN_LIMIT, op_main_limit },
622 { OP_MAIN_TAG_PATTERN, op_main_tag_pattern },
623 { OP_MAIN_UNTAG_PATTERN, op_main_untag_pattern },
624 { OP_QUERY, op_query },
625 { OP_QUERY_APPEND, op_query },
626 { OP_SEARCH, op_search },
627 { OP_SEARCH_NEXT, op_search },
628 { OP_SEARCH_OPPOSITE, op_search },
629 { OP_SEARCH_REVERSE, op_search },
630 { OP_SORT, op_sort },
631 { OP_SORT_REVERSE, op_sort },
632 { OP_UNDELETE, op_delete },
633 { 0, NULL },
634 // clang-format on
635};