NeoMutt  2024-02-01-23-g345d7b
Teaching an old dog new tricks
No Matches
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.
int alias_function_dispatcher (struct MuttWindow *win, int op)
 Perform a Alias function - Implements function_dispatcher_t -.
bool alias_to_addrlist (struct AddressList *al, struct Alias *alias)
 Turn an Alias into an AddressList.
int query_run (const char *s, bool verbose, struct AliasList *al, const struct ConfigSubset *sub)
 Run an external program to find Addresses.

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 168 of file sort.c.

170 if (!ava || ARRAY_EMPTY(ava))
171 return;
173 const short c_sort_alias = cs_subset_sort(sub, "sort_alias");
174 bool sort_reverse = (c_sort_alias & SORT_REVERSE);
175 ARRAY_SORT(ava, alias_get_sort_function(c_sort_alias), &sort_reverse);
177 struct AliasView *avp = NULL;
178 ARRAY_FOREACH(avp, ava)
179 {
180 avp->num = ARRAY_FOREACH_IDX;
181 }
static sort_t alias_get_sort_function(short sort)
Sorting function decision logic.
Definition: sort.c:148
#define ARRAY_SORT(head, fn, sdata)
Sort an array.
Definition: array.h:279
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:74
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:267
Reverse the order of the sort.
Definition: sort2.h:71
GUI data wrapping an Alias.
Definition: gui.h:38
int num
Index number in list.
Definition: gui.h:39
+ 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 120 of file dlg_query.c.

122 if (!al || !TAILQ_EMPTY(al) || !alias)
123 return false;
125 mutt_addrlist_copy(al, &alias->addr, false);
126 if (!TAILQ_EMPTY(al))
127 {
128 struct Address *first = TAILQ_FIRST(al);
129 struct Address *second = TAILQ_NEXT(first, entries);
130 if (!second && !first->personal)
131 {
132 first->personal = buf_new(alias->name);
133 }
135 mutt_addrlist_to_intl(al, NULL);
136 }
138 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:765
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1297
struct Buffer * buf_new(const char *str)
Allocate a new Buffer.
Definition: buffer.c:321
#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
struct Buffer * personal
Real name of address.
Definition: address.h:37
char * name
Short name.
Definition: alias.h:36
struct AddressList addr
List of Addresses the Alias expands to.
Definition: alias.h:37
+ 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 269 of file dlg_query.c.

271 FILE *fp = NULL;
272 char *buf = NULL;
273 size_t buflen;
274 char *msg = NULL;
275 size_t msglen = 0;
276 char *p = NULL;
277 struct Buffer *cmd = buf_pool_get();
279 const char *const c_query_command = cs_subset_string(sub, "query_command");
280 buf_file_expand_fmt_quote(cmd, c_query_command, s);
282 pid_t pid = filter_create(buf_string(cmd), NULL, &fp, NULL, EnvList);
283 if (pid < 0)
284 {
285 mutt_debug(LL_DEBUG1, "unable to fork command: %s\n", buf_string(cmd));
286 buf_pool_release(&cmd);
287 return -1;
288 }
289 buf_pool_release(&cmd);
291 if (verbose)
292 mutt_message(_("Waiting for response..."));
294 /* The query protocol first reads one NL-terminated line. If an error
295 * occurs, this is assumed to be an error message. Otherwise it's ignored. */
296 msg = mutt_file_read_line(msg, &msglen, fp, NULL, MUTT_RL_NO_FLAGS);
297 while ((buf = mutt_file_read_line(buf, &buflen, fp, NULL, MUTT_RL_NO_FLAGS)))
298 {
299 p = strtok(buf, "\t\n");
300 if (p)
301 {
302 struct Alias *alias = alias_new();
304 mutt_addrlist_parse(&alias->addr, p);
305 p = strtok(NULL, "\t\n");
306 if (p)
307 {
308 alias->name = mutt_str_dup(p);
309 p = strtok(NULL, "\t\n");
310 parse_alias_comments(alias, p);
311 }
312 TAILQ_INSERT_TAIL(al, alias, entries);
313 }
314 }
315 FREE(&buf);
316 mutt_file_fclose(&fp);
317 if (filter_wait(pid))
318 {
319 mutt_debug(LL_DEBUG1, "Error: %s\n", msg);
320 if (verbose)
321 mutt_error("%s", msg);
322 }
323 else
324 {
325 if (verbose)
326 mutt_message("%s", msg);
327 }
328 FREE(&msg);
330 return 0;
int mutt_addrlist_parse(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition: address.c:480
void parse_alias_comments(struct Alias *alias, const char *com)
Parse the alias/query comment field.
Definition: commands.c:95
struct Alias * alias_new(void)
Create a new Alias.
Definition: alias.c:665
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:97
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
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:801
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:1497
#define mutt_file_fclose(FP)
Definition: file.h:148
No flags are set.
Definition: file.h:40
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:219
pid_t filter_create(const char *cmd, FILE **fp_in, FILE **fp_out, FILE **fp_err, char **envlist)
Set up filter program.
Definition: filter.c:208
char ** EnvList
Private copy of the environment variables.
Definition: globals.c:78
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_message(...)
Definition: logging2.h:91
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
Log at debug level 1.
Definition: logging2.h:43
#define FREE(x)
Definition: memory.h:45
#define _(a)
Definition: message.h:28
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
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:
+ Here is the caller graph for this function: