NeoMutt  2022-04-29-249-gaae397
Teaching an old dog new tricks
DOXYGEN
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 - More...
 
static int op_delete (struct AliasMenuData *mdata, int op)
 delete the current entry - Implements alias_function_t - More...
 
static int op_exit (struct AliasMenuData *mdata, int op)
 exit this menu - Implements alias_function_t - More...
 
static int op_generic_select_entry (struct AliasMenuData *mdata, int op)
 select the current entry - Implements alias_function_t - More...
 
static int op_main_limit (struct AliasMenuData *mdata, int op)
 show only messages matching a pattern - Implements alias_function_t - More...
 
static int op_query (struct AliasMenuData *mdata, int op)
 query external program for addresses - Implements alias_function_t - More...
 
static int op_search (struct AliasMenuData *mdata, int op)
 search for a regular expression - Implements alias_function_t - More...
 
static int op_sort (struct AliasMenuData *mdata, int op)
 sort aliases - Implements alias_function_t - More...
 

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 52 of file functions.c.

53{
54 struct Menu *menu = mdata->menu;
55
56 if (menu->tag_prefix)
57 {
58 struct AddressList naddr = TAILQ_HEAD_INITIALIZER(naddr);
59
60 struct AliasView *avp = NULL;
61 ARRAY_FOREACH(avp, &mdata->ava)
62 {
63 if (!avp->is_tagged)
64 continue;
65
66 struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
67 if (alias_to_addrlist(&al, avp->alias))
68 {
69 mutt_addrlist_copy(&naddr, &al, false);
71 }
72 }
73
74 alias_create(&naddr, mdata->sub);
75 mutt_addrlist_clear(&naddr);
76 }
77 else
78 {
79 struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
80 if (alias_to_addrlist(&al, ARRAY_GET(&mdata->ava, menu_get_index(menu))->alias))
81 {
82 alias_create(&al, mdata->sub);
84 }
85 }
86 return FR_SUCCESS;
87}
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition: address.c:737
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1470
void alias_create(struct AddressList *al, const struct ConfigSubset *sub)
Create a new Alias from an Address.
Definition: alias.c:370
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:211
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:108
@ 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:118
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:154
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:637
struct AliasViewArray ava
All Aliases/Queries.
Definition: gui.h:53
struct ConfigSubset * sub
Config items.
Definition: gui.h:55
GUI data wrapping an Alias.
Definition: gui.h:36
struct Alias * alias
Alias.
Definition: gui.h:44
bool is_tagged
Is it tagged?
Definition: gui.h:41
Definition: lib.h:69
void * mdata
Private data.
Definition: lib.h:137
bool tag_prefix
User has pressed <tag-prefix>
Definition: lib.h:75
+ 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 92 of file functions.c.

93{
94 struct Menu *menu = mdata->menu;
95
96 if (menu->tag_prefix)
97 {
98 struct AliasView *avp = NULL;
99 ARRAY_FOREACH(avp, &mdata->ava)
100 {
101 if (avp->is_tagged)
102 avp->is_deleted = (op == OP_DELETE);
103 }
105 }
106 else
107 {
108 int index = menu_get_index(menu);
109 ARRAY_GET(&mdata->ava, index)->is_deleted = (op == OP_DELETE);
111 const bool c_resolve = cs_subset_bool(mdata->sub, "resolve");
112 if (c_resolve && (index < (menu->max - 1)))
113 {
114 menu_set_index(menu, index + 1);
116 }
117 }
118 return FR_SUCCESS;
119}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
#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:178
#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:168
bool is_deleted
Is it deleted?
Definition: gui.h:42
int max
Number of entries in the menu.
Definition: lib.h:71
+ 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 124 of file functions.c.

125{
126 return FR_DONE;
127}
@ FR_DONE
Exit the Dialog.
Definition: dispatcher.h:35

◆ 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 138 of file functions.c.

139{
140 struct Menu *menu = mdata->menu;
141 if (menu->tag_prefix)
142 {
143 // Untag any non-visible aliases
144 struct AliasView *avp = NULL;
145 ARRAY_FOREACH(avp, &mdata->ava)
146 {
147 if (avp->is_tagged && !avp->is_visible)
148 avp->is_tagged = false;
149 }
150 }
151 else
152 {
153 // Untag all but the current alias
154 struct AliasView *avp = NULL;
155 const int idx = menu_get_index(menu);
156 ARRAY_FOREACH(avp, &mdata->ava)
157 {
158 avp->is_tagged = (ARRAY_FOREACH_IDX == idx);
159 }
160 }
161
162 return FR_CONTINUE;
163}
@ FR_CONTINUE
Remain in the Dialog.
Definition: dispatcher.h:34
bool is_visible
Is visible?
Definition: gui.h:43
+ 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 168 of file functions.c.

169{
170 struct Menu *menu = mdata->menu;
171 int rc = mutt_pattern_alias_func(_("Limit to addresses matching: "), mdata, menu);
172 if (rc != 0)
173 return FR_NO_ACTION;
174
175 alias_array_sort(&mdata->ava, mdata->sub);
176 alias_set_title(mdata->sbar, mdata->title, mdata->limit);
178 window_redraw(NULL);
179
180 return FR_SUCCESS;
181}
void alias_array_sort(struct AliasViewArray *ava, const struct ConfigSubset *sub)
Sort and reindex an AliasViewArray.
Definition: sort.c:156
@ 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:69
#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:604
int mutt_pattern_alias_func(char *prompt, struct AliasMenuData *mdata, struct Menu *menu)
Perform some Pattern matching for Alias.
Definition: pattern.c:243
+ 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 190 of file functions.c.

191{
192 struct Buffer *buf = mdata->query;
193 if ((mutt_buffer_get_field(_("Query: "), buf, MUTT_COMP_NO_FLAGS, false, NULL,
194 NULL, NULL) != 0) ||
196 {
197 return FR_NO_ACTION;
198 }
199
200 if (op == OP_QUERY)
201 {
202 ARRAY_FREE(&mdata->ava);
203 aliaslist_free(mdata->al);
204 }
205
206 struct Menu *menu = mdata->menu;
207 struct AliasList al = TAILQ_HEAD_INITIALIZER(al);
208
209 query_run(mutt_buffer_string(buf), true, &al, mdata->sub);
211 char title[256] = { 0 };
212 snprintf(title, sizeof(title), "%s%s", _("Query: "), mutt_buffer_string(buf));
213 sbar_set_title(mdata->sbar, title);
214
215 if (TAILQ_EMPTY(&al))
216 {
217 if (op == OP_QUERY)
218 menu->max = 0;
219 return FR_NO_ACTION;
220 }
221
222 struct Alias *np = NULL;
223 struct Alias *tmp = NULL;
224 TAILQ_FOREACH_SAFE(np, &al, entries, tmp)
225 {
226 alias_array_alias_add(&mdata->ava, np);
227 TAILQ_REMOVE(&al, np, entries);
228 TAILQ_INSERT_TAIL(mdata->al, np, entries); // Transfer
229 }
230 alias_array_sort(&mdata->ava, mdata->sub);
231 menu->max = ARRAY_SIZE(&mdata->ava);
232 return FR_SUCCESS;
233}
void aliaslist_free(struct AliasList *al)
Free a List of Aliases.
Definition: alias.c:662
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:86
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:203
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:260
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
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:251
int mutt_buffer_get_field(const char *field, struct Buffer *buf, CompletionFlags complete, bool multiple, struct Mailbox *m, char ***files, int *numfiles)
Ask the user for a string.
Definition: window.c:180
#define MUTT_COMP_NO_FLAGS
No flags are set.
Definition: mutt.h:52
#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:224
struct MuttWindow * sbar
Status Bar.
Definition: gui.h:59
struct Buffer * query
Query string.
Definition: gui.h:57
struct AliasList * al
Alias data.
Definition: gui.h:54
A shortcut for an email address or addresses.
Definition: alias.h:34
String manipulation buffer.
Definition: buffer.h:34
+ 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 244 of file functions.c.

245{
246 struct Menu *menu = mdata->menu;
247 int index = mutt_search_alias_command(menu, menu_get_index(menu), op);
248 if (index == -1)
249 return FR_NO_ACTION;
250
251 menu_set_index(menu, index);
252 return FR_SUCCESS;
253}
int mutt_search_alias_command(struct Menu *menu, int cur, int op)
Perform a search.
Definition: pattern.c:654
+ 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 262 of file functions.c.

263{
264 int sort = cs_subset_sort(mdata->sub, "sort_alias");
265 bool resort = true;
266 bool reverse = (op == OP_SORT_REVERSE);
267
268 switch (mutt_multi_choice(reverse ?
269 /* L10N: The highlighted letters must match the "Sort" options */
270 _("Rev-Sort (a)lias, a(d)dress or (u)nsorted?") :
271 /* L10N: The highlighted letters must match the "Rev-Sort" options */
272 _("Sort (a)lias, a(d)dress or (u)nsorted?"),
273 /* L10N: These must match the highlighted letters from "Sort" and "Rev-Sort" */
274 _("adu")))
275 {
276 case -1: /* abort */
277 resort = false;
278 break;
279
280 case 1: /* (a)lias */
281 sort = SORT_ALIAS;
282 break;
283
284 case 2: /* a(d)dress */
285 sort = SORT_ADDRESS;
286 break;
287
288 case 3: /* (u)nsorted */
289 sort = SORT_ORDER;
290 break;
291 }
292
293 if (resort)
294 {
295 sort |= reverse ? SORT_REVERSE : 0;
296
297 // This will trigger a WA_RECALC
298 cs_subset_str_native_set(mdata->sub, "sort_alias", sort, NULL);
299 }
300
301 return FR_SUCCESS;
302}
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:292
int mutt_multi_choice(const char *prompt, const char *letters)
Offer the user a multiple choice question.
Definition: question.c:54
@ SORT_ORDER
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:48
@ SORT_ALIAS
Sort by email alias.
Definition: sort2.h:53
@ SORT_ADDRESS
Sort by email address.
Definition: sort2.h:54
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:79
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:305
+ Here is the call graph for this function: