NeoMutt  2024-04-25-127-g771158
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
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...
 

Typedefs

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

Functions

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.

Authors
  • 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 http://www.gnu.org/licenses/.

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.

Parameters
avaArray of Aliases
subConfig items

Definition at line 168 of file sort.c.

169{
170 if (!ava || ARRAY_EMPTY(ava))
171 return;
172
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);
176
177 struct AliasView *avp = NULL;
178 ARRAY_FOREACH(avp, ava)
179 {
180 avp->num = ARRAY_FOREACH_IDX;
181 }
182}
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:266
#define SORT_REVERSE
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.

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

Definition at line 121 of file dlg_query.c.

122{
123 if (!al || !TAILQ_EMPTY(al) || !alias)
124 return false;
125
126 mutt_addrlist_copy(al, &alias->addr, false);
127 if (!TAILQ_EMPTY(al))
128 {
129 struct Address *first = TAILQ_FIRST(al);
130 struct Address *second = TAILQ_NEXT(first, entries);
131 if (!second && !first->personal)
132 {
133 first->personal = buf_new(alias->name);
134 }
135
136 mutt_addrlist_to_intl(al, NULL);
137 }
138
139 return true;
140}
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:1293
struct Buffer * buf_new(const char *str)
Allocate a new Buffer.
Definition: buffer.c:304
#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.

Parameters
sString to match
verboseIf true, print progress messages
alAlias list to fill
subConfig items
Return values
0Success
-1Error

Definition at line 273 of file dlg_query.c.

274{
275 FILE *fp = NULL;
276 char *buf = NULL;
277 size_t buflen;
278 char *msg = NULL;
279 size_t msglen = 0;
280 char *tok = NULL;
281 char *next_tok = NULL;
282 struct Buffer *cmd = buf_pool_get();
283
284 const char *const c_query_command = cs_subset_string(sub, "query_command");
285 buf_file_expand_fmt_quote(cmd, c_query_command, s);
286
287 pid_t pid = filter_create(buf_string(cmd), NULL, &fp, NULL, EnvList);
288 if (pid < 0)
289 {
290 mutt_debug(LL_DEBUG1, "unable to fork command: %s\n", buf_string(cmd));
291 buf_pool_release(&cmd);
292 return -1;
293 }
294 buf_pool_release(&cmd);
295
296 if (verbose)
297 mutt_message(_("Waiting for response..."));
298
299 /* The query protocol first reads one NL-terminated line. If an error
300 * occurs, this is assumed to be an error message. Otherwise it's ignored. */
301 msg = mutt_file_read_line(msg, &msglen, fp, NULL, MUTT_RL_NO_FLAGS);
302 while ((buf = mutt_file_read_line(buf, &buflen, fp, NULL, MUTT_RL_NO_FLAGS)))
303 {
304 tok = buf;
305 next_tok = strchr(tok, '\t');
306 if (next_tok)
307 *next_tok++ = '\0';
308
309 if (*tok == '\0')
310 continue;
311
312 struct Alias *alias = alias_new();
313
314 mutt_addrlist_parse(&alias->addr, tok);
315
316 if (next_tok)
317 {
318 tok = next_tok;
319 next_tok = strchr(tok, '\t');
320 if (next_tok)
321 *next_tok++ = '\0';
322
323 alias->name = mutt_str_dup(tok);
324 parse_alias_comments(alias, next_tok);
325 }
326
327 TAILQ_INSERT_TAIL(al, alias, entries);
328 }
329
330 FREE(&buf);
331 mutt_file_fclose(&fp);
332 if (filter_wait(pid))
333 {
334 mutt_debug(LL_DEBUG1, "Error: %s\n", msg);
335 if (verbose)
336 mutt_error("%s", msg);
337 }
338 else
339 {
340 if (verbose)
341 mutt_message("%s", msg);
342 }
343 FREE(&msg);
344
345 return 0;
346}
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:660
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:291
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:808
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:1456
#define mutt_file_fclose(FP)
Definition: file.h:138
#define MUTT_RL_NO_FLAGS
No flags are set.
Definition: file.h:40
char ** EnvList
Private copy of the environment variables.
Definition: globals.c:76
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_message(...)
Definition: logging2.h:91
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
#define FREE(x)
Definition: memory.h:45
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:220
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:209
#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: