NeoMutt  2025-12-11-1039-g550ac6
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
Alias Function API

Prototype for a Alias Function. More...

Collaboration diagram for Alias Function API:

Functions

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 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 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 -

Detailed Description

Prototype for a Alias Function.

Parameters
fdataAlias Function context data
eventEvent to process
Return values
enumFunctionRetval
Precondition
fdata is not NULL
event is not NULL

Function Documentation

◆ op_create_alias()

int op_create_alias ( struct AliasFunctionData * fdata,
const struct KeyEvent * event )
static

create an alias from a message sender - Implements alias_function_t -

Definition at line 148 of file functions.c.

149{
150 struct AliasMenuData *mdata = fdata->wdata;
151 struct Menu *menu = mdata->menu;
152
153 if (menu->tag_prefix)
154 {
155 struct AddressList naddr = TAILQ_HEAD_INITIALIZER(naddr);
156
157 struct AliasView *avp = NULL;
158 ARRAY_FOREACH(avp, &mdata->ava)
159 {
160 if (!avp->is_tagged)
161 continue;
162
163 struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
164 if (alias_to_addrlist(&al, avp->alias))
165 {
166 mutt_addrlist_copy(&naddr, &al, false);
168 }
169 }
170
171 alias_create(&naddr, mdata->sub);
172 mutt_addrlist_clear(&naddr);
173 }
174 else
175 {
176 struct AliasView *av = ARRAY_GET(&mdata->ava, menu_get_index(menu));
177 if (!av)
178 return FR_NO_ACTION;
179
180 struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
181 if (alias_to_addrlist(&al, av->alias))
182 {
183 alias_create(&al, mdata->sub);
185 }
186 }
187 return FR_SUCCESS;
188}
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition address.c:776
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition address.c:1473
void alias_create(struct AddressList *al, const struct ConfigSubset *sub)
Create a new Alias from an Address.
Definition alias.c:369
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
#define ARRAY_GET(head, idx)
Return the element at index.
Definition array.h:109
@ FR_SUCCESS
Valid function - successfully performed.
Definition dispatcher.h:40
@ FR_NO_ACTION
Valid function - no action performed.
Definition dispatcher.h:38
bool alias_to_addrlist(struct AddressList *al, struct Alias *alias)
Turn an Alias into an AddressList.
Definition dlg_query.c:119
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition menu.c:153
#define TAILQ_HEAD_INITIALIZER(head)
Definition queue.h:694
struct AliasMenuData * wdata
Alias menu data.
Definition functions.h:42
AliasView array wrapper with Pattern information -.
Definition gui.h:55
struct AliasViewArray ava
All Aliases/Queries.
Definition gui.h:56
struct ConfigSubset * sub
Config items.
Definition gui.h:58
GUI data wrapping an Alias.
Definition gui.h:38
struct Alias * alias
Alias.
Definition gui.h:46
bool is_tagged
Is it tagged?
Definition gui.h:43
Definition lib.h:86
void * mdata
Private data.
Definition lib.h:155
bool tag_prefix
User has pressed <tag-prefix>.
Definition lib.h:92
Here is the call graph for this function:

◆ op_delete()

int op_delete ( struct AliasFunctionData * fdata,
const struct KeyEvent * event )
static

delete the current entry - Implements alias_function_t -

This function handles:

  • OP_DELETE
  • OP_UNDELETE

Supports repeat-count: 5<delete-entry> deletes the current entry and the next 4. Overruns are silently capped at the end of the visible list.

Definition at line 270 of file functions.c.

271{
272 struct AliasMenuData *mdata = fdata->wdata;
273 struct Menu *menu = mdata->menu;
274 const bool deleted = (event->op == OP_DELETE);
275
276 struct AliasViewPtrArray avpa = ARRAY_HEAD_INITIALIZER;
277 alias_add_selection(&avpa, mdata, menu->tag_prefix, event->count);
278 if (ARRAY_EMPTY(&avpa))
279 {
280 ARRAY_FREE(&avpa);
281 return FR_NO_ACTION;
282 }
283 alias_apply_set_deleted(&avpa, deleted);
284 const int num = ARRAY_SIZE(&avpa);
285 ARRAY_FREE(&avpa);
286
287 if (menu->tag_prefix)
288 {
290 }
291 else
292 {
293 const int index = menu_get_index(menu);
295 const bool c_resolve = cs_subset_bool(mdata->sub, "resolve");
296 if (c_resolve && ((index + num) < menu->max))
297 {
298 menu_set_index(menu, index + num);
300 }
301 }
302 return FR_SUCCESS;
303}
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
static void alias_apply_set_deleted(struct AliasViewPtrArray *avpa, bool deleted)
Apply the deleted flag to a working set of AliasViews.
Definition functions.c:247
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition array.h:74
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition array.h:58
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition menu.c:177
@ MENU_REDRAW_INDEX
Redraw the index.
Definition lib.h:61
@ MENU_REDRAW_CURRENT
Redraw the current line of the menu.
Definition lib.h:63
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition menu.c:167
int count
Optional count prefix, e.g. 3 for 3j.
Definition get.h:78
int max
Number of entries in the menu.
Definition lib.h:88
Here is the call graph for this function:

◆ op_quit()

int op_quit ( struct AliasFunctionData * fdata,
const struct KeyEvent * event )
static

Save changes and exit this dialog - Implements alias_function_t -.

Definition at line 308 of file functions.c.

309{
310 return FR_DONE;
311}
@ FR_DONE
Exit the Dialog.
Definition dispatcher.h:36
Here is the caller graph for this function:

◆ op_jump()

int op_jump ( struct AliasFunctionData * fdata,
const struct KeyEvent * event )
static

Jump to an index number - Implements alias_function_t -.

Definition at line 316 of file functions.c.

317{
318 int num = event->count;
319
320 if (num == 0)
321 return FR_NO_ACTION;
322
323 struct AliasMenuData *mdata = fdata->wdata;
324 struct Menu *menu = mdata->menu;
325
326 if ((num < 1) || (num > menu->max))
327 {
328 mutt_warning(_("Invalid message number"));
329 return FR_ERROR;
330 }
331
332 menu_set_index(menu, num - 1); // Num is 1-based
333 return FR_SUCCESS;
334}
@ FR_ERROR
Valid function - error occurred.
Definition dispatcher.h:39
#define mutt_warning(...)
Definition logging2.h:92
#define _(a)
Definition message.h:28
Here is the call graph for this function:
Here is the caller graph for this function:

◆ op_generic_select_entry()

int op_generic_select_entry ( struct AliasFunctionData * fdata,
const struct KeyEvent * event )
static

select the current entry - Implements alias_function_t -

Definition at line 388 of file functions.c.

389{
390 if (event->count > 0)
391 return op_jump(fdata, event);
392
393 return alias_select_entries(fdata->wdata, 0);
394}
static int alias_select_entries(struct AliasMenuData *mdata, int count)
Select entries to return from the Alias Dialog.
Definition functions.c:343
static int op_jump(struct AliasFunctionData *fdata, const struct KeyEvent *event)
Jump to an index number - Implements alias_function_t -.
Definition functions.c:316
Here is the call graph for this function:

◆ op_mail()

int op_mail ( struct AliasFunctionData * fdata,
const struct KeyEvent * event )
static

mail the selected entries - Implements alias_function_t -

Definition at line 399 of file functions.c.

400{
401 return alias_select_entries(fdata->wdata, event->count);
402}
Here is the call graph for this function:

◆ op_main_limit()

int op_main_limit ( struct AliasFunctionData * fdata,
const struct KeyEvent * event )
static

show only messages matching a pattern - Implements alias_function_t -

Definition at line 407 of file functions.c.

408{
409 struct AliasMenuData *mdata = fdata->wdata;
410 struct Menu *menu = mdata->menu;
411 int rc = mutt_pattern_alias_func(_("Limit to addresses matching: "), mdata,
412 PAA_VISIBLE, menu);
413 if (rc != 0)
414 return FR_NO_ACTION;
415
416 alias_array_sort(&mdata->ava, mdata->sub);
417 alias_set_title(mdata->sbar, mdata->title, mdata->limit);
419 window_redraw(NULL);
420
421 return FR_SUCCESS;
422}
void alias_array_sort(struct AliasViewArray *ava, const struct ConfigSubset *sub)
Sort and reindex an AliasViewArray.
Definition sort.c:235
void alias_set_title(struct MuttWindow *sbar, char *menu_name, char *limit)
Create a title string for the Menu.
Definition gui.c:72
@ MENU_REDRAW_FULL
Redraw everything.
Definition lib.h:64
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
@ PAA_VISIBLE
Set AliasView.is_visible and hide the rest.
Definition lib.h:203
int mutt_pattern_alias_func(char *prompt, struct AliasMenuData *mdata, enum PatternAlias action, struct Menu *menu)
Perform some Pattern matching for Alias.
Definition pattern.c:170
Here is the call graph for this function:

◆ op_main_tag_pattern()

int op_main_tag_pattern ( struct AliasFunctionData * fdata,
const struct KeyEvent * event )
static

Tag messages matching a pattern - Implements alias_function_t -.

Definition at line 427 of file functions.c.

428{
429 struct AliasMenuData *mdata = fdata->wdata;
430 struct Menu *menu = mdata->menu;
431 int rc = mutt_pattern_alias_func(_("Tag addresses matching: "), mdata, PAA_TAG, menu);
432 if (rc != 0)
433 return FR_NO_ACTION;
434
436 window_redraw(NULL);
437
438 return FR_SUCCESS;
439}
@ PAA_TAG
Set AliasView.is_tagged, but don't touch the others.
Definition lib.h:201
Here is the call graph for this function:

◆ op_main_untag_pattern()

int op_main_untag_pattern ( struct AliasFunctionData * fdata,
const struct KeyEvent * event )
static

Untag messages matching a pattern - Implements alias_function_t -.

Definition at line 444 of file functions.c.

445{
446 struct AliasMenuData *mdata = fdata->wdata;
447 struct Menu *menu = mdata->menu;
448 int rc = mutt_pattern_alias_func(_("Untag addresses matching: "), mdata, PAA_UNTAG, menu);
449 if (rc != 0)
450 return FR_NO_ACTION;
451
453 window_redraw(NULL);
454
455 return FR_SUCCESS;
456}
@ PAA_UNTAG
Unset AliasView.is_tagged, but don't touch the others.
Definition lib.h:202
Here is the call graph for this function:

◆ op_query()

int op_query ( struct AliasFunctionData * fdata,
const struct KeyEvent * event )
static

query external program for addresses - Implements alias_function_t -

This function handles:

  • OP_QUERY
  • OP_QUERY_APPEND

Definition at line 465 of file functions.c.

466{
467 struct AliasMenuData *mdata = fdata->wdata;
468 struct Buffer *buf = mdata->query;
469 if ((mw_get_field(_("Query: "), buf, MUTT_COMP_NONE, HC_OTHER, NULL, NULL) != 0) ||
470 buf_is_empty(buf))
471 {
472 return FR_NO_ACTION;
473 }
474
475 const int op = event->op;
476 if (op == OP_QUERY)
477 {
478 ARRAY_FREE(&mdata->ava);
479 aliaslist_clear(mdata->aa);
480 }
481
482 struct Menu *menu = mdata->menu;
483 struct AliasArray aa = ARRAY_HEAD_INITIALIZER;
484
485 query_run(buf_string(buf), true, &aa, mdata->sub);
487 char title[256] = { 0 };
488 snprintf(title, sizeof(title), "%s%s", _("Query: "), buf_string(buf));
489 sbar_set_title(mdata->sbar, title);
490
491 if (ARRAY_EMPTY(&aa))
492 {
493 if (op == OP_QUERY)
494 menu->max = 0;
495 return FR_NO_ACTION;
496 }
497
498 struct Alias **ap = NULL;
499 ARRAY_FOREACH(ap, &aa)
500 {
501 alias_array_alias_add(&mdata->ava, *ap);
502 ARRAY_ADD(mdata->aa, *ap); // Transfer
503 }
504 ARRAY_FREE(&aa); // Free the array structure but not the aliases
505 alias_array_sort(&mdata->ava, mdata->sub);
506 menu->max = ARRAY_SIZE(&mdata->ava);
507 return FR_SUCCESS;
508}
void aliaslist_clear(struct AliasArray *aa)
Empty a List of Aliases.
Definition alias.c:699
int alias_array_alias_add(struct AliasViewArray *ava, struct Alias *alias)
Add an Alias to the AliasViewArray.
Definition array.c:47
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:298
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
int query_run(const char *s, bool verbose, struct AliasArray *aa, const struct ConfigSubset *sub)
Run an external program to find Addresses.
Definition dlg_query.c:188
@ MUTT_COMP_NONE
No flags are set.
Definition wdata.h:46
int mw_get_field(const char *prompt, struct Buffer *buf, CompletionFlags complete, enum HistoryClass hclass, const struct CompleteOps *comp_api, void *cdata)
Ask the user for a string -.
Definition window.c:502
@ HC_OTHER
Miscellaneous strings.
Definition lib.h:61
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition sbar.c:227
struct AliasArray * aa
Alias data.
Definition gui.h:57
struct MuttWindow * sbar
Status Bar.
Definition gui.h:62
struct Buffer * query
Query string.
Definition gui.h:60
A shortcut for an email address or addresses.
Definition alias.h:35
String manipulation buffer.
Definition buffer.h:36
Here is the call graph for this function:

◆ op_search()

int op_search ( struct AliasFunctionData * fdata,
const struct KeyEvent * event )
static

search for a regular expression - Implements alias_function_t -

This function handles:

  • OP_SEARCH
  • OP_SEARCH_NEXT
  • OP_SEARCH_OPPOSITE
  • OP_SEARCH_REVERSE

Definition at line 519 of file functions.c.

520{
521 struct AliasMenuData *mdata = fdata->wdata;
522 SearchFlags flags = SEARCH_NONE;
523 switch (event->op)
524 {
525 case OP_SEARCH:
526 flags |= SEARCH_PROMPT;
527 mdata->search_state->reverse = false;
528 break;
529 case OP_SEARCH_REVERSE:
530 flags |= SEARCH_PROMPT;
531 mdata->search_state->reverse = true;
532 break;
533 case OP_SEARCH_NEXT:
534 break;
535 case OP_SEARCH_OPPOSITE:
536 flags |= SEARCH_OPPOSITE;
537 break;
538 default:
539 break;
540 }
541
542 struct Menu *menu = mdata->menu;
543 int index = menu_get_index(menu);
544 index = mutt_search_alias_command(menu, index, mdata->search_state, flags);
545 if (index == -1)
546 return FR_NO_ACTION;
547
548 menu_set_index(menu, index);
549 return FR_SUCCESS;
550}
int mutt_search_alias_command(struct Menu *menu, int cur, struct SearchState *state, SearchFlags flags)
Perform a search.
Definition pattern.c:622
uint8_t SearchFlags
@ SEARCH_NONE
No flags are set.
@ SEARCH_PROMPT
Ask for search input.
@ SEARCH_OPPOSITE
Search in the opposite direction.
int op
Function opcode, e.g. OP_HELP.
Definition get.h:77
Here is the call graph for this function:

◆ op_sort()

int op_sort ( struct AliasFunctionData * fdata,
const struct KeyEvent * event )
static

sort aliases - Implements alias_function_t -

This function handles:

  • OP_SORT
  • OP_SORT_REVERSE

Definition at line 559 of file functions.c.

560{
561 struct AliasMenuData *mdata = fdata->wdata;
562 int sort = cs_subset_sort(mdata->sub, "alias_sort");
563 bool resort = true;
564 const int op = event->op;
565 bool reverse = (op == OP_SORT_REVERSE);
566
567 switch (mw_multi_choice(reverse ?
568 /* L10N: The highlighted letters must match the "Sort" options */
569 _("Rev-Sort (a)lias, (n)ame, (e)mail or (u)nsorted?") :
570 /* L10N: The highlighted letters must match the "Rev-Sort" options */
571 _("Sort (a)lias, (n)ame, (e)mail or (u)nsorted?"),
572 /* L10N: These must match the highlighted letters from "Sort" and "Rev-Sort" */
573 _("aneu")))
574 {
575 case -1: /* abort */
576 resort = false;
577 break;
578
579 case 1: /* (a)lias */
580 sort = ALIAS_SORT_ALIAS;
581 break;
582
583 case 2: /* (n)ame */
584 sort = ALIAS_SORT_NAME;
585 break;
586
587 case 3: /* (e)mail */
588 sort = ALIAS_SORT_EMAIL;
589 break;
590
591 case 4: /* (u)nsorted */
592 sort = ALIAS_SORT_UNSORTED;
593 break;
594
595 default:
596 resort = false;
597 break;
598 }
599
600 if (resort)
601 {
602 sort |= reverse ? SORT_REVERSE : 0;
603
604 // This will trigger a WA_RECALC
605 cs_subset_str_native_set(mdata->sub, "alias_sort", sort, NULL);
606 }
607
608 return FR_SUCCESS;
609}
@ ALIAS_SORT_UNSORTED
Sort by the order the Aliases were configured.
Definition sort.h:34
@ ALIAS_SORT_NAME
Sort by Real Name.
Definition sort.h:33
@ ALIAS_SORT_EMAIL
Sort by Email Address.
Definition sort.h:32
@ ALIAS_SORT_ALIAS
Sort by Alias short name.
Definition sort.h:31
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition helpers.c:266
#define SORT_REVERSE
Reverse the order of the sort.
Definition sort.h:40
int mw_multi_choice(const char *prompt, const char *letters)
Offer the user a multiple choice question -.
Definition question.c:62
int cs_subset_str_native_set(const struct ConfigSubset *sub, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.
Definition subset.c:303
Here is the call graph for this function: