NeoMutt  2024-12-12-14-g7b49f7
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 235 of file sort.c.

236{
237 if (!ava || ARRAY_EMPTY(ava))
238 return;
239
240 short c_sort_alias = cs_subset_sort(sub, "alias_sort");
241 if (c_sort_alias == ALIAS_SORT_ALIAS)
242 {
243 struct AliasView *av = ARRAY_GET(ava, 0);
244 struct Alias *a = av->alias;
245
246 if (!a->name) // We've got a Query
247 c_sort_alias = ALIAS_SORT_NAME;
248 }
249
250 bool sort_reverse = (c_sort_alias & SORT_REVERSE);
251 ARRAY_SORT(ava, alias_get_sort_function(c_sort_alias), &sort_reverse);
252
253 struct AliasView *avp = NULL;
254 ARRAY_FOREACH(avp, ava)
255 {
256 avp->num = ARRAY_FOREACH_IDX;
257 }
258}
static sort_t alias_get_sort_function(short sort)
Sorting function decision logic.
Definition: sort.c:209
@ ALIAS_SORT_NAME
Sort by Real Name.
Definition: sort.h:33
@ ALIAS_SORT_ALIAS
Sort by Alias short name.
Definition: sort.h:31
#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
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:109
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: sort.h:39
GUI data wrapping an Alias.
Definition: gui.h:38
struct Alias * alias
Alias.
Definition: gui.h:46
int num
Index number in list.
Definition: gui.h:39
A shortcut for an email address or addresses.
Definition: alias.h:35
char * name
Short name.
Definition: alias.h:36
+ 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 120 of file dlg_query.c.

121{
122 if (!al || !TAILQ_EMPTY(al) || !alias)
123 return false;
124
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 }
134
135 mutt_addrlist_to_intl(al, NULL);
136 }
137
138 return true;
139}
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:741
#define TAILQ_NEXT(elm, field)
Definition: queue.h:850
#define TAILQ_EMPTY(head)
Definition: queue.h:739
An email address.
Definition: address.h:36
struct Buffer * personal
Real name of address.
Definition: address.h:37
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 189 of file dlg_query.c.

190{
191 FILE *fp = NULL;
192 char *buf = NULL;
193 size_t buflen;
194 char *msg = NULL;
195 size_t msglen = 0;
196 char *tok = NULL;
197 char *next_tok = NULL;
198 struct Buffer *cmd = buf_pool_get();
199
200 const char *const c_query_command = cs_subset_string(sub, "query_command");
201 buf_file_expand_fmt_quote(cmd, c_query_command, s);
202
203 pid_t pid = filter_create(buf_string(cmd), NULL, &fp, NULL, EnvList);
204 if (pid < 0)
205 {
206 mutt_debug(LL_DEBUG1, "unable to fork command: %s\n", buf_string(cmd));
207 buf_pool_release(&cmd);
208 return -1;
209 }
210 buf_pool_release(&cmd);
211
212 if (verbose)
213 mutt_message(_("Waiting for response..."));
214
215 struct Buffer *addr = buf_pool_get();
216 /* The query protocol first reads one NL-terminated line. If an error
217 * occurs, this is assumed to be an error message. Otherwise it's ignored. */
218 msg = mutt_file_read_line(msg, &msglen, fp, NULL, MUTT_RL_NO_FLAGS);
219 while ((buf = mutt_file_read_line(buf, &buflen, fp, NULL, MUTT_RL_NO_FLAGS)))
220 {
221 tok = buf;
222 next_tok = strchr(tok, '\t');
223 if (next_tok)
224 *next_tok++ = '\0';
225
226 if (*tok == '\0')
227 continue;
228
229 struct Alias *alias = alias_new();
230
231 if (next_tok)
232 {
233 tok = next_tok;
234 next_tok = strchr(tok, '\t');
235 if (next_tok)
236 *next_tok++ = '\0';
237
238 buf_printf(addr, "%s <%s>", tok, buf);
240
241 parse_alias_comments(alias, next_tok);
242 }
243 else
244 {
245 mutt_addrlist_parse(&alias->addr, buf); // Email address
246 }
247
248 TAILQ_INSERT_TAIL(al, alias, entries);
249 }
251
252 FREE(&buf);
253 mutt_file_fclose(&fp);
254 if (filter_wait(pid))
255 {
256 mutt_debug(LL_DEBUG1, "Error: %s\n", msg);
257 if (verbose)
258 mutt_error("%s", msg);
259 }
260 else
261 {
262 if (verbose)
263 mutt_message("%s", msg);
264 }
265 FREE(&msg);
266
267 return 0;
268}
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
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
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
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:827
String manipulation buffer.
Definition: buffer.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function: