NeoMutt  2025-12-11-980-ge38c27
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_quit (struct AliasFunctionData *fdata, const struct KeyEvent *event)
 Save changes and exit this dialog - 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 120 of file functions.c.

121{
123 ASSERT(mod_data);
124
125 struct MenuDefinition *md = NULL;
126 struct SubMenu *sm = NULL;
127
129 md = km_register_menu(MENU_ALIAS, "alias");
130 km_menu_add_submenu(md, sm);
131 km_menu_add_submenu(md, sm_generic);
133
134 mod_data->menu_alias = md;
135
137 md = km_register_menu(MENU_QUERY, "query");
138 km_menu_add_submenu(md, sm);
139 km_menu_add_submenu(md, sm_generic);
141
142 mod_data->menu_query = md;
143}
const struct MenuFuncOp OpQuery[]
Functions for the external Query Menu.
Definition functions.c:70
static const struct MenuOpSeq QueryDefaultBindings[]
Key bindings for the external Query Menu.
Definition functions.c:102
static const struct MenuOpSeq AliasDefaultBindings[]
Key bindings for the Alias Menu.
Definition functions.c:86
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:123
struct SubMenu * km_register_submenu(const struct MenuFuncOp functions[])
Register a submenu.
Definition init.c:88
struct MenuDefinition * km_register_menu(int menu, const char *name)
Register a menu.
Definition init.c:105
void km_menu_add_bindings(struct MenuDefinition *md, const struct MenuOpSeq bindings[])
Add Keybindings to a Menu.
Definition init.c:136
@ 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:666
#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 menudef.h:44
Collection of related functions.
Definition menudef.h:33
@ MENU_QUERY
Select from results of external query.
Definition type.h:50
@ 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 205 of file functions.c.

207{
208 if (!avpa || !mdata)
209 return 0;
210
211 if (tagged)
212 {
213 struct AliasView *avp = NULL;
214 ARRAY_FOREACH(avp, &mdata->ava)
215 {
216 if (avp->is_tagged)
217 ARRAY_ADD(avpa, avp);
218 }
219 }
220 else
221 {
222 struct Menu *menu = mdata->menu;
223 const int index = menu_get_index(menu);
224 if ((index < 0) || (index >= menu->max))
225 return 0;
226
227 int n = (count > 1) ? count : 1;
228 if ((index + n) > menu->max)
229 n = menu->max - index;
230
231 for (int i = 0; i < n; i++)
232 {
233 struct AliasView *av = ARRAY_GET(&mdata->ava, index + i);
234 if (av)
235 ARRAY_ADD(avpa, av);
236 }
237 }
238
239 return ARRAY_SIZE(avpa);
240}
#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:153
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 247 of file functions.c.

248{
249 if (!avpa)
250 return;
251
252 struct AliasView **avpp = NULL;
253 ARRAY_FOREACH(avpp, avpa)
254 {
255 if (*avpp)
256 (*avpp)->is_deleted = deleted;
257 }
258}
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 343 of file functions.c.

344{
345 struct Menu *menu = mdata->menu;
346 if (menu->tag_prefix)
347 {
348 // Untag any non-visible aliases
349 struct AliasView *avp = NULL;
350 ARRAY_FOREACH(avp, &mdata->ava)
351 {
352 if (avp->is_tagged && !avp->is_visible)
353 avp->is_tagged = false;
354 }
355 }
356 else
357 {
358 struct AliasViewPtrArray avpa = ARRAY_HEAD_INITIALIZER;
359 alias_add_selection(&avpa, mdata, false, count);
360 if (ARRAY_EMPTY(&avpa))
361 {
362 ARRAY_FREE(&avpa);
363 return FR_NO_ACTION;
364 }
365
366 // Untag all but the selected alias(es)
367 struct AliasView *avp = NULL;
368 ARRAY_FOREACH(avp, &mdata->ava)
369 {
370 avp->is_tagged = false;
371 }
372
373 struct AliasView **avpp = NULL;
374 ARRAY_FOREACH(avpp, &avpa)
375 {
376 if (*avpp)
377 (*avpp)->is_tagged = true;
378 }
379 ARRAY_FREE(&avpa);
380 }
381
382 return FR_CONTINUE;
383}
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:205
#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 },
{ "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 { "limit", OP_MAIN_LIMIT },
58 { "mail", OP_MAIL },
59 { "sort-alias", OP_SORT },
60 { "sort-alias-reverse", OP_SORT_REVERSE },
61 { "tag-pattern", OP_MAIN_TAG_PATTERN },
62 { "undelete-entry", OP_UNDELETE },
63 { "untag-pattern", OP_MAIN_UNTAG_PATTERN },
64 { NULL, 0 },
65};

◆ OpQuery

const struct MenuFuncOp OpQuery[]
Initial value:
= {
{ "create-alias", OP_CREATE_ALIAS },
{ "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 70 of file functions.c.

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

◆ AliasDefaultBindings

const struct MenuOpSeq AliasDefaultBindings[]
static
Initial value:
= {
{ OP_DELETE, "d" },
{ 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 86 of file functions.c.

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

◆ QueryDefaultBindings

const struct MenuOpSeq QueryDefaultBindings[]
static
Initial value:
= {
{ OP_CREATE_ALIAS, "a" },
{ 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 102 of file functions.c.

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

◆ AliasFunctions

const struct AliasFunction AliasFunctions[]
static
Initial value:
= {
{ OP_CREATE_ALIAS, op_create_alias },
{ OP_DELETE, op_delete },
{ OP_EXIT, op_quit },
{ 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_QUIT, op_quit },
{ 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_quit(struct AliasFunctionData *fdata, const struct KeyEvent *event)
Save changes and exit this dialog - Implements alias_function_t -.
Definition functions.c:308
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:407
static int op_query(struct AliasFunctionData *fdata, const struct KeyEvent *event)
query external program for addresses - Implements alias_function_t -
Definition functions.c:465
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:148
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:444
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:427
static int op_mail(struct AliasFunctionData *fdata, const struct KeyEvent *event)
mail the selected entries - Implements alias_function_t -
Definition functions.c:399
static int op_delete(struct AliasFunctionData *fdata, const struct KeyEvent *event)
delete the current entry - Implements alias_function_t -
Definition functions.c:270
static int op_search(struct AliasFunctionData *fdata, const struct KeyEvent *event)
search for a regular expression - Implements alias_function_t -
Definition functions.c:519
static int op_generic_select_entry(struct AliasFunctionData *fdata, const struct KeyEvent *event)
select the current entry - Implements alias_function_t -
Definition functions.c:388
static int op_sort(struct AliasFunctionData *fdata, const struct KeyEvent *event)
sort aliases - Implements alias_function_t -
Definition functions.c:557

All the NeoMutt functions that the Alias supports.

Definition at line 610 of file functions.c.

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