NeoMutt  2023-05-17-33-gce4425
Teaching an old dog new tricks
functions.h File Reference

Alias functions. More...

#include <stdbool.h>
+ Include dependency graph for functions.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  AliasFunction
 A NeoMutt function. More...


typedef int(* alias_function_t) (struct AliasMenuData *wdata, int op)


void alias_array_sort (struct AliasViewArray *ava, const struct ConfigSubset *sub)
 Sort and reindex an AliasViewArray. More...
int alias_function_dispatcher (struct MuttWindow *win, int op)
 Perform a Alias function - Implements function_dispatcher_t -. More...
bool alias_to_addrlist (struct AddressList *al, struct Alias *alias)
 Turn an Alias into an AddressList. More...
int query_run (const char *s, bool verbose, struct AliasList *al, const struct ConfigSubset *sub)
 Run an external program to find Addresses. More...

Detailed Description

Alias functions.

  • Richard Russon

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

Definition in file functions.h.

Typedef Documentation

◆ alias_function_t

typedef int(* alias_function_t) (struct AliasMenuData *wdata, int op)

Definition at line 46 of file functions.h.

Function Documentation

◆ alias_array_sort()

void alias_array_sort ( struct AliasViewArray *  ava,
const struct ConfigSubset sub 

Sort and reindex an AliasViewArray.

avaArray of Aliases
subConfig items

Definition at line 169 of file sort.c.

171 if (!ava || ARRAY_EMPTY(ava))
172 return;
174 SortAlias = cs_subset_sort(sub, "sort_alias");
177 struct AliasView *avp = NULL;
178 ARRAY_FOREACH(avp, ava)
179 {
180 avp->num = ARRAY_FOREACH_IDX;
181 }
static short SortAlias
Current value of $sort_alias used by the sorting functions.
Definition: sort.c:41
static sort_t alias_get_sort_function(short sort)
Sorting function decision logic.
Definition: sort.c:149
#define ARRAY_SORT(head, fn)
Sort an array.
Definition: array.h:277
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:211
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:73
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:292
GUI data wrapping an Alias.
Definition: gui.h:36
int num
Index number in list.
Definition: gui.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ alias_to_addrlist()

bool alias_to_addrlist ( struct AddressList *  al,
struct Alias alias 

Turn an Alias into an AddressList.

alAddressList to fill (must be empty)
aliasAlias to use
Return values

Definition at line 118 of file dlg_query.c.

120 if (!al || !TAILQ_EMPTY(al) || !alias)
121 return false;
123 mutt_addrlist_copy(al, &alias->addr, false);
124 if (!TAILQ_EMPTY(al))
125 {
126 struct Address *first = TAILQ_FIRST(al);
127 struct Address *second = TAILQ_NEXT(first, entries);
128 if (!second && !first->personal)
129 first->personal = mutt_str_dup(alias->name);
131 mutt_addrlist_to_intl(al, NULL);
132 }
134 return true;
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition: address.c:752
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1285
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
#define TAILQ_FIRST(head)
Definition: queue.h:723
#define TAILQ_NEXT(elm, field)
Definition: queue.h:832
#define TAILQ_EMPTY(head)
Definition: queue.h:721
An email address.
Definition: address.h:36
char * personal
Real name of address.
Definition: address.h:37
char * name
Short name.
Definition: alias.h:35
struct AddressList addr
List of Addresses the Alias expands to.
Definition: alias.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ query_run()

int query_run ( const char *  s,
bool  verbose,
struct AliasList *  al,
const struct ConfigSubset sub 

Run an external program to find Addresses.

sString to match
verboseIf true, print progress messages
alAlias list to fill
subConfig items
Return values

Definition at line 256 of file dlg_query.c.

258 FILE *fp = NULL;
259 char *buf = NULL;
260 size_t buflen;
261 char *msg = NULL;
262 size_t msglen = 0;
263 char *p = NULL;
264 struct Buffer *cmd = buf_pool_get();
266 const char *const c_query_command = cs_subset_string(sub, "query_command");
267 buf_file_expand_fmt_quote(cmd, c_query_command, s);
269 pid_t pid = filter_create(buf_string(cmd), NULL, &fp, NULL);
270 if (pid < 0)
271 {
272 mutt_debug(LL_DEBUG1, "unable to fork command: %s\n", buf_string(cmd));
273 buf_pool_release(&cmd);
274 return -1;
275 }
276 buf_pool_release(&cmd);
278 if (verbose)
279 mutt_message(_("Waiting for response..."));
281 /* The query protocol first reads one NL-terminated line. If an error
282 * occurs, this is assumed to be an error message. Otherwise it's ignored. */
283 msg = mutt_file_read_line(msg, &msglen, fp, NULL, MUTT_RL_NO_FLAGS);
284 while ((buf = mutt_file_read_line(buf, &buflen, fp, NULL, MUTT_RL_NO_FLAGS)))
285 {
286 p = strtok(buf, "\t\n");
287 if (p)
288 {
289 struct Alias *alias = alias_new();
291 mutt_addrlist_parse(&alias->addr, p);
292 p = strtok(NULL, "\t\n");
293 if (p)
294 {
295 alias->name = mutt_str_dup(p);
296 p = strtok(NULL, "\t\n");
297 alias->comment = mutt_str_dup(p);
298 }
299 TAILQ_INSERT_TAIL(al, alias, entries);
300 }
301 }
302 FREE(&buf);
303 mutt_file_fclose(&fp);
304 if (filter_wait(pid))
305 {
306 mutt_debug(LL_DEBUG1, "Error: %s\n", msg);
307 if (verbose)
308 mutt_error("%s", msg);
309 }
310 else
311 {
312 if (verbose)
313 mutt_message("%s", msg);
314 }
315 FREE(&msg);
317 return 0;
int mutt_addrlist_parse(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition: address.c:470
struct Alias * alias_new(void)
Create a new Alias.
Definition: alias.c:625
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:78
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, ReadLineFlags flags)
Read a line from a file.
Definition: file.c:738
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:150
void buf_file_expand_fmt_quote(struct Buffer *dest, const char *fmt, const char *src)
Replace s in a string with a filename.
Definition: file.c:1475
No flags are set.
Definition: file.h:39
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:217
pid_t filter_create(const char *cmd, FILE **fp_in, FILE **fp_out, FILE **fp_err)
Set up filter program.
Definition: filter.c:206
#define mutt_error(...)
Definition: logging2.h:87
#define mutt_message(...)
Definition: logging2.h:86
#define mutt_debug(LEVEL,...)
Definition: logging2.h:84
Log at debug level 1.
Definition: logging2.h:40
#define FREE(x)
Definition: memory.h:43
#define _(a)
Definition: message.h:28
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:106
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:119
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
A shortcut for an email address or addresses.
Definition: alias.h:34
char * comment
Free-form comment string.
Definition: alias.h:37
String manipulation buffer.
Definition: buffer.h:34
+ Here is the call graph for this function:
+ Here is the caller graph for this function: