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

Detailed Description

Prototype for a Alias Function.

Parameters
wdataAlias Window data
opOperation to perform, e.g. OP_ALIAS_NEXT
Return values
enumFunctionRetval

Function Documentation

◆ op_create_alias()

static int op_create_alias ( struct AliasMenuData mdata,
int  op 
)
static

create an alias from a message sender - Implements alias_function_t -

Definition at line 128 of file functions.c.

129{
130 struct Menu *menu = mdata->menu;
131
132 if (menu->tag_prefix)
133 {
134 struct AddressList naddr = TAILQ_HEAD_INITIALIZER(naddr);
135
136 struct AliasView *avp = NULL;
137 ARRAY_FOREACH(avp, &mdata->ava)
138 {
139 if (!avp->is_tagged)
140 continue;
141
142 struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
143 if (alias_to_addrlist(&al, avp->alias))
144 {
145 mutt_addrlist_copy(&naddr, &al, false);
147 }
148 }
149
150 alias_create(&naddr, mdata->sub);
151 mutt_addrlist_clear(&naddr);
152 }
153 else
154 {
155 struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
156 if (alias_to_addrlist(&al, ARRAY_GET(&mdata->ava, menu_get_index(menu))->alias))
157 {
158 alias_create(&al, mdata->sub);
160 }
161 }
162 return FR_SUCCESS;
163}
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition: address.c:765
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1460
void alias_create(struct AddressList *al, const struct ConfigSubset *sub)
Create a new Alias from an Address.
Definition: alias.c:367
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:109
@ FR_SUCCESS
Valid function - successfully performed.
Definition: dispatcher.h:39
bool alias_to_addrlist(struct AddressList *al, struct Alias *alias)
Turn an Alias into an AddressList.
Definition: dlg_query.c:121
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:160
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:637
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:79
void * mdata
Private data.
Definition: lib.h:147
bool tag_prefix
User has pressed <tag-prefix>
Definition: lib.h:85
+ Here is the call graph for this function:

◆ op_delete()

static int op_delete ( struct AliasMenuData mdata,
int  op 
)
static

delete the current entry - Implements alias_function_t -

Definition at line 168 of file functions.c.

169{
170 struct Menu *menu = mdata->menu;
171
172 if (menu->tag_prefix)
173 {
174 struct AliasView *avp = NULL;
175 ARRAY_FOREACH(avp, &mdata->ava)
176 {
177 if (avp->is_tagged)
178 avp->is_deleted = (op == OP_DELETE);
179 }
181 }
182 else
183 {
184 int index = menu_get_index(menu);
185 ARRAY_GET(&mdata->ava, index)->is_deleted = (op == OP_DELETE);
187 const bool c_resolve = cs_subset_bool(mdata->sub, "resolve");
188 if (c_resolve && (index < (menu->max - 1)))
189 {
190 menu_set_index(menu, index + 1);
192 }
193 }
194 return FR_SUCCESS;
195}
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:56
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:184
#define MENU_REDRAW_CURRENT
Redraw the current line of the menu.
Definition: lib.h:58
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:174
bool is_deleted
Is it deleted?
Definition: gui.h:44
int max
Number of entries in the menu.
Definition: lib.h:81
+ Here is the call graph for this function:

◆ op_exit()

static int op_exit ( struct AliasMenuData mdata,
int  op 
)
static

exit this menu - Implements alias_function_t -

Definition at line 200 of file functions.c.

201{
202 return FR_DONE;
203}
@ FR_DONE
Exit the Dialog.
Definition: dispatcher.h:35
+ Here is the caller graph for this function:

◆ op_generic_select_entry()

static int op_generic_select_entry ( struct AliasMenuData mdata,
int  op 
)
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 214 of file functions.c.

215{
216 struct Menu *menu = mdata->menu;
217 if (menu->tag_prefix)
218 {
219 // Untag any non-visible aliases
220 struct AliasView *avp = NULL;
221 ARRAY_FOREACH(avp, &mdata->ava)
222 {
223 if (avp->is_tagged && !avp->is_visible)
224 avp->is_tagged = false;
225 }
226 }
227 else
228 {
229 // Untag all but the current alias
230 struct AliasView *avp = NULL;
231 const int idx = menu_get_index(menu);
232 ARRAY_FOREACH(avp, &mdata->ava)
233 {
234 avp->is_tagged = (ARRAY_FOREACH_IDX == idx);
235 }
236 }
237
238 return FR_CONTINUE;
239}
@ FR_CONTINUE
Remain in the Dialog.
Definition: dispatcher.h:34
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,
int  op 
)
static

show only messages matching a pattern - Implements alias_function_t -

Definition at line 244 of file functions.c.

245{
246 struct Menu *menu = mdata->menu;
247 int rc = mutt_pattern_alias_func(_("Limit to addresses matching: "), mdata,
248 PAA_VISIBLE, menu);
249 if (rc != 0)
250 return FR_NO_ACTION;
251
252 alias_array_sort(&mdata->ava, mdata->sub);
253 alias_set_title(mdata->sbar, mdata->title, mdata->limit);
255 window_redraw(NULL);
256
257 return FR_SUCCESS;
258}
void alias_array_sort(struct AliasViewArray *ava, const struct ConfigSubset *sub)
Sort and reindex an AliasViewArray.
Definition: sort.c:168
@ FR_NO_ACTION
Valid function - no action performed.
Definition: dispatcher.h:37
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:59
#define _(a)
Definition: message.h:28
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:633
@ PAA_VISIBLE
Set AliasView.is_visible and hide the rest.
Definition: lib.h:189
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:191
+ Here is the call graph for this function:

◆ op_main_tag_pattern()

static int op_main_tag_pattern ( struct AliasMenuData mdata,
int  op 
)
static

Tag messages matching a pattern - Implements alias_function_t -.

Definition at line 263 of file functions.c.

264{
265 struct Menu *menu = mdata->menu;
266 int rc = mutt_pattern_alias_func(_("Tag addresses matching: "), mdata, PAA_TAG, menu);
267 if (rc != 0)
268 return FR_NO_ACTION;
269
271 window_redraw(NULL);
272
273 return FR_SUCCESS;
274}
@ PAA_TAG
Set AliasView.is_tagged, but don't touch the others.
Definition: lib.h:187
+ Here is the call graph for this function:

◆ op_main_untag_pattern()

static int op_main_untag_pattern ( struct AliasMenuData mdata,
int  op 
)
static

Untag messages matching a pattern - Implements alias_function_t -.

Definition at line 279 of file functions.c.

280{
281 struct Menu *menu = mdata->menu;
282 int rc = mutt_pattern_alias_func(_("Untag addresses matching: "), mdata, PAA_UNTAG, menu);
283 if (rc != 0)
284 return FR_NO_ACTION;
285
287 window_redraw(NULL);
288
289 return FR_SUCCESS;
290}
@ PAA_UNTAG
Unset AliasView.is_tagged, but don't touch the others.
Definition: lib.h:188
+ Here is the call graph for this function:

◆ op_query()

static int op_query ( struct AliasMenuData mdata,
int  op 
)
static

query external program for addresses - Implements alias_function_t -

This function handles:

  • OP_QUERY
  • OP_QUERY_APPEND

Definition at line 299 of file functions.c.

300{
301 struct Buffer *buf = mdata->query;
302 if ((mw_get_field(_("Query: "), buf, MUTT_COMP_NO_FLAGS, HC_OTHER, NULL, NULL) != 0) ||
303 buf_is_empty(buf))
304 {
305 return FR_NO_ACTION;
306 }
307
308 if (op == OP_QUERY)
309 {
310 ARRAY_FREE(&mdata->ava);
311 aliaslist_clear(mdata->al);
312 }
313
314 struct Menu *menu = mdata->menu;
315 struct AliasList al = TAILQ_HEAD_INITIALIZER(al);
316
317 query_run(buf_string(buf), true, &al, mdata->sub);
319 char title[256] = { 0 };
320 snprintf(title, sizeof(title), "%s%s", _("Query: "), buf_string(buf));
321 sbar_set_title(mdata->sbar, title);
322
323 if (TAILQ_EMPTY(&al))
324 {
325 if (op == OP_QUERY)
326 menu->max = 0;
327 return FR_NO_ACTION;
328 }
329
330 struct Alias *np = NULL;
331 struct Alias *tmp = NULL;
332 TAILQ_FOREACH_SAFE(np, &al, entries, tmp)
333 {
334 alias_array_alias_add(&mdata->ava, np);
335 TAILQ_REMOVE(&al, np, entries);
336 TAILQ_INSERT_TAIL(mdata->al, np, entries); // Transfer
337 }
338 alias_array_sort(&mdata->ava, mdata->sub);
339 menu->max = ARRAY_SIZE(&mdata->ava);
340 return FR_SUCCESS;
341}
void aliaslist_clear(struct AliasList *al)
Empty a List of Aliases.
Definition: alias.c:697
int alias_array_alias_add(struct AliasViewArray *ava, struct Alias *alias)
Add an Alias to the AliasViewArray.
Definition: array.c:47
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:87
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:204
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 AliasList *al, const struct ConfigSubset *sub)
Run an external program to find Addresses.
Definition: dlg_query.c:275
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:274
@ HC_OTHER
Miscellaneous strings.
Definition: lib.h:59
#define MUTT_COMP_NO_FLAGS
No flags are set.
Definition: mutt.h:56
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:735
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
#define TAILQ_EMPTY(head)
Definition: queue.h:721
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:227
struct MuttWindow * sbar
Status Bar.
Definition: gui.h:61
struct Buffer * query
Query string.
Definition: gui.h:59
struct AliasList * al
Alias data.
Definition: gui.h:56
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,
int  op 
)
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 352 of file functions.c.

353{
355 switch (op)
356 {
357 case OP_SEARCH:
358 flags |= SEARCH_PROMPT;
359 mdata->search_state->reverse = false;
360 break;
361 case OP_SEARCH_REVERSE:
362 flags |= SEARCH_PROMPT;
363 mdata->search_state->reverse = true;
364 break;
365 case OP_SEARCH_NEXT:
366 break;
367 case OP_SEARCH_OPPOSITE:
368 flags |= SEARCH_OPPOSITE;
369 break;
370 }
371
372 struct Menu *menu = mdata->menu;
373 int index = menu_get_index(menu);
374 index = mutt_search_alias_command(menu, index, mdata->search_state, flags);
375 if (index == -1)
376 return FR_NO_ACTION;
377
378 menu_set_index(menu, index);
379 return FR_SUCCESS;
380}
int mutt_search_alias_command(struct Menu *menu, int cur, struct SearchState *state, SearchFlags flags)
Perform a search.
Definition: pattern.c:636
#define SEARCH_OPPOSITE
Search in the opposite direction.
Definition: search_state.h:46
uint8_t SearchFlags
Flags for a specific search, e.g. SEARCH_PROMPT.
Definition: search_state.h:43
#define SEARCH_NO_FLAGS
No flags are set.
Definition: search_state.h:44
#define SEARCH_PROMPT
Ask for search input.
Definition: search_state.h:45
struct SearchState * search_state
State of the current search.
Definition: gui.h:63
bool reverse
search backwards
Definition: search_state.h:40
+ Here is the call graph for this function:

◆ op_sort()

static int op_sort ( struct AliasMenuData mdata,
int  op 
)
static

sort aliases - Implements alias_function_t -

This function handles:

  • OP_SORT
  • OP_SORT_REVERSE

Definition at line 389 of file functions.c.

390{
391 int sort = cs_subset_sort(mdata->sub, "sort_alias");
392 bool resort = true;
393 bool reverse = (op == OP_SORT_REVERSE);
394
395 switch (mw_multi_choice(reverse ?
396 /* L10N: The highlighted letters must match the "Sort" options */
397 _("Rev-Sort (a)lias, a(d)dress or (u)nsorted?") :
398 /* L10N: The highlighted letters must match the "Rev-Sort" options */
399 _("Sort (a)lias, a(d)dress or (u)nsorted?"),
400 /* L10N: These must match the highlighted letters from "Sort" and "Rev-Sort" */
401 _("adu")))
402 {
403 case -1: /* abort */
404 resort = false;
405 break;
406
407 case 1: /* (a)lias */
408 sort = SORT_ALIAS;
409 break;
410
411 case 2: /* a(d)dress */
412 sort = SORT_ADDRESS;
413 break;
414
415 case 3: /* (u)nsorted */
416 sort = SORT_ORDER;
417 break;
418 }
419
420 if (resort)
421 {
422 sort |= reverse ? SORT_REVERSE : 0;
423
424 // This will trigger a WA_RECALC
425 cs_subset_str_native_set(mdata->sub, "sort_alias", sort, NULL);
426 }
427
428 return FR_SUCCESS;
429}
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:266
int mw_multi_choice(const char *prompt, const char *letters)
Offer the user a multiple choice question -.
Definition: question.c:63
@ SORT_ORDER
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:40
@ SORT_ALIAS
Sort by email alias.
Definition: sort2.h:45
@ SORT_ADDRESS
Sort by email address.
Definition: sort2.h:46
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:71
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:297
+ Here is the call graph for this function: