NeoMutt  2025-12-11-596-g7cc1dd
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 AliasMenuData *mdata, const struct KeyEvent *event)
 create an alias from a message sender - Implements alias_function_t -
 
static int op_delete (struct AliasMenuData *mdata, const struct KeyEvent *event)
 delete the current entry - Implements alias_function_t -
 
static int op_exit (struct AliasMenuData *mdata, const struct KeyEvent *event)
 exit this menu - Implements alias_function_t -
 
static int op_generic_select_entry (struct AliasMenuData *mdata, const struct KeyEvent *event)
 select the current entry - Implements alias_function_t -
 
static int op_main_limit (struct AliasMenuData *mdata, const struct KeyEvent *event)
 show only messages matching a pattern - Implements alias_function_t -
 
static int op_main_tag_pattern (struct AliasMenuData *mdata, const struct KeyEvent *event)
 Tag messages matching a pattern - Implements alias_function_t -.
 
static int op_main_untag_pattern (struct AliasMenuData *mdata, const struct KeyEvent *event)
 Untag messages matching a pattern - Implements alias_function_t -.
 
static int op_query (struct AliasMenuData *mdata, const struct KeyEvent *event)
 query external program for addresses - Implements alias_function_t -
 
static int op_search (struct AliasMenuData *mdata, const struct KeyEvent *event)
 search for a regular expression - Implements alias_function_t -
 
static int op_sort (struct AliasMenuData *mdata, const struct KeyEvent *event)
 sort aliases - Implements alias_function_t -
 

Detailed Description

Prototype for a Alias Function.

Parameters
wdataAlias Window data
eventEvent to process
Return values
enumFunctionRetval
Precondition
wdata is not NULL
event is not NULL

Function Documentation

◆ op_create_alias()

static int op_create_alias ( struct AliasMenuData * mdata,
const struct KeyEvent * event )
static

create an alias from a message sender - Implements alias_function_t -

Definition at line 153 of file functions.c.

154{
155 struct Menu *menu = mdata->menu;
156
157 if (menu->tag_prefix)
158 {
159 struct AddressList naddr = TAILQ_HEAD_INITIALIZER(naddr);
160
161 struct AliasView *avp = NULL;
162 ARRAY_FOREACH(avp, &mdata->ava)
163 {
164 if (!avp->is_tagged)
165 continue;
166
167 struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
168 if (alias_to_addrlist(&al, avp->alias))
169 {
170 mutt_addrlist_copy(&naddr, &al, false);
172 }
173 }
174
175 alias_create(&naddr, mdata->sub);
176 mutt_addrlist_clear(&naddr);
177 }
178 else
179 {
180 struct AliasView *av = ARRAY_GET(&mdata->ava, menu_get_index(menu));
181 if (!av)
182 return FR_NO_ACTION;
183
184 struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
185 if (alias_to_addrlist(&al, av->alias))
186 {
187 alias_create(&al, mdata->sub);
189 }
190 }
191 return FR_SUCCESS;
192}
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition address.c:774
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition address.c:1469
void alias_create(struct AddressList *al, const struct ConfigSubset *sub)
Create a new Alias from an Address.
Definition alias.c:368
#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:118
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition menu.c:164
#define TAILQ_HEAD_INITIALIZER(head)
Definition queue.h:694
struct AliasViewArray ava
All Aliases/Queries.
Definition gui.h:55
struct ConfigSubset * sub
Config items.
Definition gui.h:57
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:80
void * mdata
Private data.
Definition lib.h:149
bool tag_prefix
User has pressed <tag-prefix>
Definition lib.h:86
+ Here is the call graph for this function:

◆ op_delete()

static int op_delete ( struct AliasMenuData * mdata,
const struct KeyEvent * event )
static

delete the current entry - Implements alias_function_t -

Definition at line 197 of file functions.c.

198{
199 struct Menu *menu = mdata->menu;
200 const int op = event->op;
201
202 if (menu->tag_prefix)
203 {
204 struct AliasView *avp = NULL;
205 ARRAY_FOREACH(avp, &mdata->ava)
206 {
207 if (avp->is_tagged)
208 avp->is_deleted = (op == OP_DELETE);
209 }
211 }
212 else
213 {
214 int index = menu_get_index(menu);
215 struct AliasView *av = ARRAY_GET(&mdata->ava, index);
216 if (!av)
217 return FR_NO_ACTION;
218
219 av->is_deleted = (op == OP_DELETE);
221 const bool c_resolve = cs_subset_bool(mdata->sub, "resolve");
222 if (c_resolve && (index < (menu->max - 1)))
223 {
224 menu_set_index(menu, index + 1);
226 }
227 }
228 return FR_SUCCESS;
229}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
#define MENU_REDRAW_INDEX
Redraw the index.
Definition lib.h:57
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition menu.c:188
#define MENU_REDRAW_CURRENT
Redraw the current line of the menu.
Definition lib.h:59
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition menu.c:178
bool is_deleted
Is it deleted?
Definition gui.h:44
int max
Number of entries in the menu.
Definition lib.h:82
+ Here is the call graph for this function:

◆ op_exit()

static int op_exit ( struct AliasMenuData * mdata,
const struct KeyEvent * event )
static

exit this menu - Implements alias_function_t -

Definition at line 234 of file functions.c.

235{
236 return FR_DONE;
237}
@ FR_DONE
Exit the Dialog.
Definition dispatcher.h:36
+ Here is the caller graph for this function:

◆ op_generic_select_entry()

static int op_generic_select_entry ( struct AliasMenuData * mdata,
const struct KeyEvent * event )
static

select the current entry - Implements alias_function_t -

This function handles:

  • OP_GENERIC_SELECT_ENTRY
  • OP_MAIL
Note
AliasMenuData.is_tagged will show the user's selection

Definition at line 248 of file functions.c.

249{
250 struct Menu *menu = mdata->menu;
251 if (menu->tag_prefix)
252 {
253 // Untag any non-visible aliases
254 struct AliasView *avp = NULL;
255 ARRAY_FOREACH(avp, &mdata->ava)
256 {
257 if (avp->is_tagged && !avp->is_visible)
258 avp->is_tagged = false;
259 }
260 }
261 else
262 {
263 // Untag all but the current alias
264 struct AliasView *avp = NULL;
265 const int idx = menu_get_index(menu);
266 ARRAY_FOREACH(avp, &mdata->ava)
267 {
268 avp->is_tagged = (ARRAY_FOREACH_IDX_avp == idx);
269 }
270 }
271
272 return FR_CONTINUE;
273}
@ FR_CONTINUE
Remain in the Dialog.
Definition dispatcher.h:35
bool is_visible
Is visible?
Definition gui.h:45
+ Here is the call graph for this function:

◆ op_main_limit()

static int op_main_limit ( struct AliasMenuData * mdata,
const struct KeyEvent * event )
static

show only messages matching a pattern - Implements alias_function_t -

Definition at line 278 of file functions.c.

279{
280 struct Menu *menu = mdata->menu;
281 int rc = mutt_pattern_alias_func(_("Limit to addresses matching: "), mdata,
282 PAA_VISIBLE, menu);
283 if (rc != 0)
284 return FR_NO_ACTION;
285
286 alias_array_sort(&mdata->ava, mdata->sub);
287 alias_set_title(mdata->sbar, mdata->title, mdata->limit);
289 window_redraw(NULL);
290
291 return FR_SUCCESS;
292}
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
#define MENU_REDRAW_FULL
Redraw everything.
Definition lib.h:60
#define _(a)
Definition message.h:28
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:191
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:186
+ Here is the call graph for this function:

◆ op_main_tag_pattern()

static int op_main_tag_pattern ( struct AliasMenuData * mdata,
const struct KeyEvent * event )
static

Tag messages matching a pattern - Implements alias_function_t -.

Definition at line 297 of file functions.c.

298{
299 struct Menu *menu = mdata->menu;
300 int rc = mutt_pattern_alias_func(_("Tag addresses matching: "), mdata, PAA_TAG, menu);
301 if (rc != 0)
302 return FR_NO_ACTION;
303
305 window_redraw(NULL);
306
307 return FR_SUCCESS;
308}
@ PAA_TAG
Set AliasView.is_tagged, but don't touch the others.
Definition lib.h:189
+ Here is the call graph for this function:

◆ op_main_untag_pattern()

static int op_main_untag_pattern ( struct AliasMenuData * mdata,
const struct KeyEvent * event )
static

Untag messages matching a pattern - Implements alias_function_t -.

Definition at line 313 of file functions.c.

314{
315 struct Menu *menu = mdata->menu;
316 int rc = mutt_pattern_alias_func(_("Untag addresses matching: "), mdata, PAA_UNTAG, menu);
317 if (rc != 0)
318 return FR_NO_ACTION;
319
321 window_redraw(NULL);
322
323 return FR_SUCCESS;
324}
@ PAA_UNTAG
Unset AliasView.is_tagged, but don't touch the others.
Definition lib.h:190
+ Here is the call graph for this function:

◆ op_query()

static int op_query ( struct AliasMenuData * mdata,
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 333 of file functions.c.

334{
335 struct Buffer *buf = mdata->query;
336 if ((mw_get_field(_("Query: "), buf, MUTT_COMP_NO_FLAGS, HC_OTHER, NULL, NULL) != 0) ||
337 buf_is_empty(buf))
338 {
339 return FR_NO_ACTION;
340 }
341
342 const int op = event->op;
343 if (op == OP_QUERY)
344 {
345 ARRAY_FREE(&mdata->ava);
346 aliaslist_clear(mdata->aa);
347 }
348
349 struct Menu *menu = mdata->menu;
350 struct AliasArray aa = ARRAY_HEAD_INITIALIZER;
351
352 query_run(buf_string(buf), true, &aa, mdata->sub);
354 char title[256] = { 0 };
355 snprintf(title, sizeof(title), "%s%s", _("Query: "), buf_string(buf));
356 sbar_set_title(mdata->sbar, title);
357
358 if (ARRAY_EMPTY(&aa))
359 {
360 if (op == OP_QUERY)
361 menu->max = 0;
362 return FR_NO_ACTION;
363 }
364
365 struct Alias **ap = NULL;
366 ARRAY_FOREACH(ap, &aa)
367 {
368 alias_array_alias_add(&mdata->ava, *ap);
369 ARRAY_ADD(mdata->aa, *ap); // Transfer
370 }
371 ARRAY_FREE(&aa); // Free the array structure but not the aliases
372 alias_array_sort(&mdata->ava, mdata->sub);
373 menu->max = ARRAY_SIZE(&mdata->ava);
374 return FR_SUCCESS;
375}
void aliaslist_clear(struct AliasArray *aa)
Empty a List of Aliases.
Definition alias.c:698
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
#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 buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:291
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:187
#define MUTT_COMP_NO_FLAGS
No flags are set.
Definition wdata.h:42
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:463
@ HC_OTHER
Miscellaneous strings.
Definition lib.h:60
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:56
struct MuttWindow * sbar
Status Bar.
Definition gui.h:61
struct Buffer * query
Query string.
Definition gui.h:59
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()

static int op_search ( struct AliasMenuData * mdata,
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 386 of file functions.c.

387{
389 switch (event->op)
390 {
391 case OP_SEARCH:
392 flags |= SEARCH_PROMPT;
393 mdata->search_state->reverse = false;
394 break;
395 case OP_SEARCH_REVERSE:
396 flags |= SEARCH_PROMPT;
397 mdata->search_state->reverse = true;
398 break;
399 case OP_SEARCH_NEXT:
400 break;
401 case OP_SEARCH_OPPOSITE:
402 flags |= SEARCH_OPPOSITE;
403 break;
404 }
405
406 struct Menu *menu = mdata->menu;
407 int index = menu_get_index(menu);
408 index = mutt_search_alias_command(menu, index, mdata->search_state, flags);
409 if (index == -1)
410 return FR_NO_ACTION;
411
412 menu_set_index(menu, index);
413 return FR_SUCCESS;
414}
int mutt_search_alias_command(struct Menu *menu, int cur, struct SearchState *state, SearchFlags flags)
Perform a search.
Definition pattern.c:635
#define SEARCH_OPPOSITE
Search in the opposite direction.
uint8_t SearchFlags
Flags for a specific search, e.g. SEARCH_PROMPT.
#define SEARCH_NO_FLAGS
No flags are set.
#define SEARCH_PROMPT
Ask for search input.
struct SearchState * search_state
State of the current search.
Definition gui.h:63
int op
Function opcode, e.g. OP_HELP.
Definition get.h:52
bool reverse
search backwards
+ Here is the call graph for this function:

◆ op_sort()

static int op_sort ( struct AliasMenuData * mdata,
const struct KeyEvent * event )
static

sort aliases - Implements alias_function_t -

This function handles:

  • OP_SORT
  • OP_SORT_REVERSE

Definition at line 423 of file functions.c.

424{
425 int sort = cs_subset_sort(mdata->sub, "alias_sort");
426 bool resort = true;
427 const int op = event->op;
428 bool reverse = (op == OP_SORT_REVERSE);
429
430 switch (mw_multi_choice(reverse ?
431 /* L10N: The highlighted letters must match the "Sort" options */
432 _("Rev-Sort (a)lias, (n)ame, (e)mail or (u)nsorted?") :
433 /* L10N: The highlighted letters must match the "Rev-Sort" options */
434 _("Sort (a)lias, (n)ame, (e)mail or (u)nsorted?"),
435 /* L10N: These must match the highlighted letters from "Sort" and "Rev-Sort" */
436 _("aneu")))
437 {
438 case -1: /* abort */
439 resort = false;
440 break;
441
442 case 1: /* (a)lias */
443 sort = ALIAS_SORT_ALIAS;
444 break;
445
446 case 2: /* (n)ame */
447 sort = ALIAS_SORT_NAME;
448 break;
449
450 case 3: /* (e)mail */
451 sort = ALIAS_SORT_EMAIL;
452 break;
453
454 case 4: /* (u)nsorted */
455 sort = ALIAS_SORT_UNSORTED;
456 break;
457 }
458
459 if (resort)
460 {
461 sort |= reverse ? SORT_REVERSE : 0;
462
463 // This will trigger a WA_RECALC
464 cs_subset_str_native_set(mdata->sub, "alias_sort", sort, NULL);
465 }
466
467 return FR_SUCCESS;
468}
@ 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: