NeoMutt  2024-11-14-34-g5aaf0d
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 275 of file dlg_query.c.

276{
277 FILE *fp = NULL;
278 char *buf = NULL;
279 size_t buflen;
280 char *msg = NULL;
281 size_t msglen = 0;
282 char *tok = NULL;
283 char *next_tok = NULL;
284 struct Buffer *cmd = buf_pool_get();
285
286 const char *const c_query_command = cs_subset_string(sub, "query_command");
287 buf_file_expand_fmt_quote(cmd, c_query_command, s);
288
289 pid_t pid = filter_create(buf_string(cmd), NULL, &fp, NULL, EnvList);
290 if (pid < 0)
291 {
292 mutt_debug(LL_DEBUG1, "unable to fork command: %s\n", buf_string(cmd));
293 buf_pool_release(&cmd);
294 return -1;
295 }
296 buf_pool_release(&cmd);
297
298 if (verbose)
299 mutt_message(_("Waiting for response..."));
300
301 /* The query protocol first reads one NL-terminated line. If an error
302 * occurs, this is assumed to be an error message. Otherwise it's ignored. */
303 msg = mutt_file_read_line(msg, &msglen, fp, NULL, MUTT_RL_NO_FLAGS);
304 while ((buf = mutt_file_read_line(buf, &buflen, fp, NULL, MUTT_RL_NO_FLAGS)))
305 {
306 tok = buf;
307 next_tok = strchr(tok, '\t');
308 if (next_tok)
309 *next_tok++ = '\0';
310
311 if (*tok == '\0')
312 continue;
313
314 struct Alias *alias = alias_new();
315
316 mutt_addrlist_parse(&alias->addr, tok);
317
318 if (next_tok)
319 {
320 tok = next_tok;
321 next_tok = strchr(tok, '\t');
322 if (next_tok)
323 *next_tok++ = '\0';
324
325 alias->name = mutt_str_dup(tok);
326 parse_alias_comments(alias, next_tok);
327 }
328
329 TAILQ_INSERT_TAIL(al, alias, entries);
330 }
331
332 FREE(&buf);
333 mutt_file_fclose(&fp);
334 if (filter_wait(pid))
335 {
336 mutt_debug(LL_DEBUG1, "Error: %s\n", msg);
337 if (verbose)
338 mutt_error("%s", msg);
339 }
340 else
341 {
342 if (verbose)
343 mutt_message("%s", msg);
344 }
345 FREE(&msg);
346
347 return 0;
348}
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:75
#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:55
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: