NeoMutt  2018-07-16 +1360-3df4a2
Teaching an old dog new tricks
DOXYGEN
query.c File Reference

Routines for querying and external address book. More...

#include "config.h"
#include <regex.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include "mutt/mutt.h"
#include "email/lib.h"
#include "mutt.h"
#include "alias.h"
#include "curs_lib.h"
#include "filter.h"
#include "format_flags.h"
#include "globals.h"
#include "keymap.h"
#include "mutt_logging.h"
#include "mutt_menu.h"
#include "mutt_window.h"
#include "muttlib.h"
#include "opcodes.h"
#include "send.h"
+ Include dependency graph for query.c:

Go to the source code of this file.

Data Structures

struct  Query
 An entry from an external address-book. More...
 
struct  Entry
 An entry in a selectable list of Query's. More...
 

Functions

static struct Addressresult_to_addr (struct Query *r)
 Turn a Query into an Address. More...
 
static void free_query (struct Query **query)
 Free a Query. More...
 
static struct Queryrun_query (char *s, int quiet)
 Run an external program to find Addresses. More...
 
static int query_search (struct Menu *menu, regex_t *rx, int line)
 Search a Address menu item - Implements Menu::menu_search() More...
 
static const char * query_format_str (char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, unsigned long data, MuttFormatFlags flags)
 Format a string for the query menu - Implements format_t. More...
 
static void query_make_entry (char *buf, size_t buflen, struct Menu *menu, int line)
 Format a menu item for the query list - Implements Menu::menu_make_entry() More...
 
static int query_tag (struct Menu *menu, int sel, int act)
 Tag an entry in the Query Menu - Implements Menu::menu_tag() More...
 
static void query_menu (char *buf, size_t buflen, struct Query *results, bool retbuf)
 Get the user to enter an Address Query. More...
 
int mutt_query_complete (char *buf, size_t buflen)
 Perform auto-complete using an Address Query. More...
 
void mutt_query_menu (char *buf, size_t buflen)
 Show the user the results of a Query. More...
 

Variables

char * C_QueryCommand
 Config: External command to query and external address book. More...
 
char * C_QueryFormat
 Config: printf-like format string for the query menu (address book) More...
 
static const struct Mapping QueryHelp []
 

Detailed Description

Routines for querying and external address book.

Authors
  • Michael R. Elkins

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 query.c.

Function Documentation

static struct Address* result_to_addr ( struct Query r)
static

Turn a Query into an Address.

Parameters
rQuery to use
Return values
ptrNewly allocaated Address

Definition at line 91 of file query.c.

92 {
93  static struct Address *tmp = NULL;
94 
95  tmp = mutt_addr_copy_list(r->addr, false);
96  if (!tmp)
97  return NULL;
98 
99  if (!tmp->next && !tmp->personal)
100  tmp->personal = mutt_str_strdup(r->name);
101 
102  mutt_addrlist_to_intl(tmp, NULL);
103  return tmp;
104 }
struct Address * addr
Definition: query.c:61
char * name
Definition: query.c:62
An email address.
Definition: address.h:32
int mutt_addrlist_to_intl(struct Address *a, char **err)
Convert an Address list to Punycode.
Definition: address.c:1208
char * personal
real name of address
Definition: address.h:34
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:383
struct Address * mutt_addr_copy_list(struct Address *addr, bool prune)
Copy a list of addresses.
Definition: address.c:730
struct Address * next
Definition: address.h:39

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void free_query ( struct Query **  query)
static

Free a Query.

Parameters
[out]queryQuery to free

Definition at line 110 of file query.c.

111 {
112  struct Query *p = NULL;
113 
114  if (!query)
115  return;
116 
117  while (*query)
118  {
119  p = *query;
120  *query = (*query)->next;
121 
122  mutt_addr_free(&p->addr);
123  FREE(&p->name);
124  FREE(&p->other);
125  FREE(&p);
126  }
127 }
struct Address * addr
Definition: query.c:61
char * name
Definition: query.c:62
struct Query * next
Definition: query.c:64
char * other
Definition: query.c:63
An entry from an external address-book.
Definition: query.c:58
#define FREE(x)
Definition: memory.h:40
void mutt_addr_free(struct Address **p)
Free a list of Addresses.
Definition: address.c:446

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static struct Query* run_query ( char *  s,
int  quiet 
)
static

Run an external program to find Addresses.

Parameters
sString to match
quietIf true, don't print progress messages
Return values
ptrQuery List of results

Definition at line 135 of file query.c.

136 {
137  FILE *fp = NULL;
138  struct Query *first = NULL;
139  struct Query *cur = NULL;
140  char cmd[STR_COMMAND];
141  char *buf = NULL;
142  size_t buflen;
143  int dummy = 0;
144  char msg[256];
145  char *p = NULL;
146  pid_t pid;
147 
148  mutt_file_expand_fmt_quote(cmd, sizeof(cmd), C_QueryCommand, s);
149 
150  pid = mutt_create_filter(cmd, NULL, &fp, NULL);
151  if (pid < 0)
152  {
153  mutt_debug(LL_DEBUG1, "unable to fork command: %s\n", cmd);
154  return 0;
155  }
156  if (!quiet)
157  mutt_message(_("Waiting for response..."));
158  fgets(msg, sizeof(msg), fp);
159  p = strrchr(msg, '\n');
160  if (p)
161  *p = '\0';
162  while ((buf = mutt_file_read_line(buf, &buflen, fp, &dummy, 0)))
163  {
164  p = strtok(buf, "\t\n");
165  if (p)
166  {
167  if (!first)
168  {
169  first = mutt_mem_calloc(1, sizeof(struct Query));
170  cur = first;
171  }
172  else
173  {
174  cur->next = mutt_mem_calloc(1, sizeof(struct Query));
175  cur = cur->next;
176  }
177 
178  cur->addr = mutt_addr_parse_list(cur->addr, p);
179  p = strtok(NULL, "\t\n");
180  if (p)
181  {
182  cur->name = mutt_str_strdup(p);
183  p = strtok(NULL, "\t\n");
184  if (p)
185  cur->other = mutt_str_strdup(p);
186  }
187  }
188  }
189  FREE(&buf);
190  mutt_file_fclose(&fp);
191  if (mutt_wait_filter(pid))
192  {
193  mutt_debug(LL_DEBUG1, "Error: %s\n", msg);
194  if (!quiet)
195  mutt_error("%s", msg);
196  }
197  else
198  {
199  if (!quiet)
200  mutt_message("%s", msg);
201  }
202 
203  return first;
204 }
pid_t mutt_create_filter(const char *s, FILE **fp_in, FILE **fp_out, FILE **fp_err)
Set up filter program.
Definition: filter.c:216
struct Address * addr
Definition: query.c:61
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, int flags)
Read a line from a file.
Definition: file.c:630
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:149
#define mutt_message(...)
Definition: logging.h:87
char * name
Definition: query.c:62
#define _(a)
Definition: message.h:28
struct Query * next
Definition: query.c:64
struct Address * mutt_addr_parse_list(struct Address *top, const char *s)
Parse a list of email addresses.
Definition: address.c:465
char * other
Definition: query.c:63
An entry from an external address-book.
Definition: query.c:58
#define STR_COMMAND
Enough space for a long command line.
Definition: string2.h:34
Log at debug level 1.
Definition: logging.h:56
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:383
#define mutt_error(...)
Definition: logging.h:88
void mutt_file_expand_fmt_quote(char *dest, size_t destlen, const char *fmt, const char *src)
Replace s in a string with a filename.
Definition: file.c:1320
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
int mutt_wait_filter(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:227
char * C_QueryCommand
Config: External command to query and external address book.
Definition: query.c:52

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int query_search ( struct Menu menu,
regex_t *  rx,
int  line 
)
static

Search a Address menu item - Implements Menu::menu_search()

Try to match various Address fields.

Definition at line 211 of file query.c.

212 {
213  struct Entry *table = menu->data;
214 
215  if (table[line].data->name && !regexec(rx, table[line].data->name, 0, NULL, 0))
216  return 0;
217  if (table[line].data->other && !regexec(rx, table[line].data->other, 0, NULL, 0))
218  return 0;
219  if (table[line].data->addr)
220  {
221  if (table[line].data->addr->personal &&
222  !regexec(rx, table[line].data->addr->personal, 0, NULL, 0))
223  {
224  return 0;
225  }
226  if (table[line].data->addr->mailbox &&
227  !regexec(rx, table[line].data->addr->mailbox, 0, NULL, 0))
228  {
229  return 0;
230  }
231  }
232 
233  return REG_NOMATCH;
234 }
struct Address * addr
Definition: query.c:61
char * name
Definition: query.c:62
char * mailbox
mailbox and host address
Definition: address.h:35
const char * line
Definition: common.c:35
char * other
Definition: query.c:63
char * personal
real name of address
Definition: address.h:34
void * data
extra data for the current menu
Definition: mutt_menu.h:86
An entry in a selectable list of Query&#39;s.
Definition: query.c:70
struct Query * data
Definition: query.c:73

+ Here is the caller graph for this function:

static const char* query_format_str ( char *  buf,
size_t  buflen,
size_t  col,
int  cols,
char  op,
const char *  src,
const char *  prec,
const char *  if_str,
const char *  else_str,
unsigned long  data,
MuttFormatFlags  flags 
)
static

Format a string for the query menu - Implements format_t.

Expando Description
%a Destination address
%c Current entry number
%e Extra information
%n Destination name
%t '*' if current entry is tagged, a space otherwise

Definition at line 247 of file query.c.

251 {
252  struct Entry *entry = (struct Entry *) data;
253  struct Query *query = entry->data;
254  char fmt[128];
255  char tmp[256] = "";
256  int optional = (flags & MUTT_FORMAT_OPTIONAL);
257 
258  switch (op)
259  {
260  case 'a':
261  mutt_addr_write(tmp, sizeof(tmp), query->addr, true);
262  mutt_format_s(buf, buflen, prec, tmp);
263  break;
264  case 'c':
265  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
266  snprintf(buf, buflen, fmt, query->num + 1);
267  break;
268  case 'e':
269  if (!optional)
270  mutt_format_s(buf, buflen, prec, NONULL(query->other));
271  else if (!query->other || !*query->other)
272  optional = 0;
273  break;
274  case 'n':
275  mutt_format_s(buf, buflen, prec, NONULL(query->name));
276  break;
277  case 't':
278  snprintf(fmt, sizeof(fmt), "%%%sc", prec);
279  snprintf(buf, buflen, fmt, entry->tagged ? '*' : ' ');
280  break;
281  default:
282  snprintf(fmt, sizeof(fmt), "%%%sc", prec);
283  snprintf(buf, buflen, fmt, op);
284  break;
285  }
286 
287  if (optional)
288  mutt_expando_format(buf, buflen, col, cols, if_str, query_format_str, data, 0);
289  else if (flags & MUTT_FORMAT_OPTIONAL)
290  mutt_expando_format(buf, buflen, col, cols, else_str, query_format_str, data, 0);
291 
292  return src;
293 }
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, MuttFormatFlags flags)
Expand expandos (x) in a string.
Definition: muttlib.c:811
struct Address * addr
Definition: query.c:61
#define NONULL(x)
Definition: string2.h:36
char * name
Definition: query.c:62
static const char * query_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, unsigned long data, MuttFormatFlags flags)
Format a string for the query menu - Implements format_t.
Definition: query.c:247
size_t mutt_addr_write(char *buf, size_t buflen, struct Address *addr, bool display)
Write an Address to a buffer.
Definition: address.c:1146
int num
Definition: query.c:60
char * other
Definition: query.c:63
An entry from an external address-book.
Definition: query.c:58
void mutt_format_s(char *buf, size_t buflen, const char *prec, const char *s)
Format a simple string.
Definition: curs_lib.c:1061
#define MUTT_FORMAT_OPTIONAL
Allow optional field processing.
Definition: format_flags.h:33
bool tagged
Definition: query.c:72
An entry in a selectable list of Query&#39;s.
Definition: query.c:70
struct Query * data
Definition: query.c:73

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void query_make_entry ( char *  buf,
size_t  buflen,
struct Menu menu,
int  line 
)
static

Format a menu item for the query list - Implements Menu::menu_make_entry()

Definition at line 298 of file query.c.

299 {
300  struct Entry *entry = &((struct Entry *) menu->data)[line];
301 
302  entry->data->num = line;
304  query_format_str, (unsigned long) entry, MUTT_FORMAT_ARROWCURSOR);
305 }
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, MuttFormatFlags flags)
Expand expandos (x) in a string.
Definition: muttlib.c:811
#define NONULL(x)
Definition: string2.h:36
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition: format_flags.h:35
char * C_QueryFormat
Config: printf-like format string for the query menu (address book)
Definition: query.c:53
static const char * query_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, unsigned long data, MuttFormatFlags flags)
Format a string for the query menu - Implements format_t.
Definition: query.c:247
const char * line
Definition: common.c:35
int num
Definition: query.c:60
struct MuttWindow * MuttIndexWindow
Index Window.
Definition: mutt_window.c:39
void * data
extra data for the current menu
Definition: mutt_menu.h:86
An entry in a selectable list of Query&#39;s.
Definition: query.c:70
struct Query * data
Definition: query.c:73

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int query_tag ( struct Menu menu,
int  sel,
int  act 
)
static

Tag an entry in the Query Menu - Implements Menu::menu_tag()

Definition at line 310 of file query.c.

311 {
312  struct Entry *cur = &((struct Entry *) menu->data)[sel];
313  bool ot = cur->tagged;
314 
315  cur->tagged = ((act >= 0) ? act : !cur->tagged);
316  return cur->tagged - ot;
317 }
void * data
extra data for the current menu
Definition: mutt_menu.h:86
bool tagged
Definition: query.c:72
An entry in a selectable list of Query&#39;s.
Definition: query.c:70

+ Here is the caller graph for this function:

static void query_menu ( char *  buf,
size_t  buflen,
struct Query results,
bool  retbuf 
)
static

Get the user to enter an Address Query.

Parameters
bufBuffer for the query
buflenLength of buffer
resultsQuery List
retbufIf true, populate the results

Definition at line 326 of file query.c.

327 {
328  struct Menu *menu = NULL;
329  struct Entry *query_table = NULL;
330  struct Query *queryp = NULL;
331  char title[256];
332 
333  if (!results)
334  {
335  /* Prompt for Query */
336  if ((mutt_get_field(_("Query: "), buf, buflen, 0) == 0) && (buf[0] != '\0'))
337  {
338  results = run_query(buf, 0);
339  }
340  }
341 
342  if (results)
343  {
344  snprintf(title, sizeof(title), _("Query '%s'"), buf);
345 
346  menu = mutt_menu_new(MENU_QUERY);
348  menu->menu_search = query_search;
349  menu->menu_tag = query_tag;
350  menu->title = title;
351  char helpstr[1024];
352  menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_QUERY, QueryHelp);
354 
355  /* count the number of results */
356  for (queryp = results; queryp; queryp = queryp->next)
357  menu->max++;
358 
359  query_table = mutt_mem_calloc(menu->max, sizeof(struct Entry));
360  menu->data = query_table;
361 
362  queryp = results;
363  for (int i = 0; queryp; queryp = queryp->next, i++)
364  query_table[i].data = queryp;
365 
366  int done = 0;
367  while (done == 0)
368  {
369  const int op = mutt_menu_loop(menu);
370  switch (op)
371  {
372  case OP_QUERY_APPEND:
373  case OP_QUERY:
374  if ((mutt_get_field(_("Query: "), buf, buflen, 0) == 0) && (buf[0] != '\0'))
375  {
376  struct Query *newresults = run_query(buf, 0);
377 
378  menu->redraw = REDRAW_FULL;
379  if (newresults)
380  {
381  snprintf(title, sizeof(title), _("Query '%s'"), buf);
382 
383  if (op == OP_QUERY)
384  {
385  free_query(&results);
386  results = newresults;
387  FREE(&query_table);
388  }
389  else
390  {
391  /* append */
392  for (queryp = results; queryp->next; queryp = queryp->next)
393  ;
394 
395  queryp->next = newresults;
396  }
397 
398  menu->current = 0;
399  mutt_menu_pop_current(menu);
400  mutt_menu_destroy(&menu);
401  menu = mutt_menu_new(MENU_QUERY);
403  menu->menu_search = query_search;
404  menu->menu_tag = query_tag;
405  menu->title = title;
406  menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_QUERY, QueryHelp);
408 
409  /* count the number of results */
410  for (queryp = results; queryp; queryp = queryp->next)
411  menu->max++;
412 
413  if (op == OP_QUERY)
414  {
415  menu->data = query_table =
416  mutt_mem_calloc(menu->max, sizeof(struct Entry));
417 
418  queryp = results;
419  for (int i = 0; queryp; queryp = queryp->next, i++)
420  query_table[i].data = queryp;
421  }
422  else
423  {
424  bool clear = false;
425 
426  /* append */
427  mutt_mem_realloc(&query_table, menu->max * sizeof(struct Entry));
428 
429  menu->data = query_table;
430 
431  queryp = results;
432  for (int i = 0; queryp; queryp = queryp->next, i++)
433  {
434  /* once we hit new entries, clear/init the tag */
435  if (queryp == newresults)
436  clear = true;
437 
438  query_table[i].data = queryp;
439  if (clear)
440  query_table[i].tagged = false;
441  }
442  }
443  }
444  }
445  break;
446 
447  case OP_CREATE_ALIAS:
448  if (menu->tagprefix)
449  {
450  struct Address *naddr = NULL;
451 
452  for (int i = 0; i < menu->max; i++)
453  {
454  if (query_table[i].tagged)
455  {
456  struct Address *a = result_to_addr(query_table[i].data);
457  mutt_addr_append(&naddr, a, false);
458  mutt_addr_free(&a);
459  }
460  }
461 
462  mutt_alias_create(NULL, naddr);
463  mutt_addr_free(&naddr);
464  }
465  else
466  {
467  struct Address *a = result_to_addr(query_table[menu->current].data);
468  mutt_alias_create(NULL, a);
469  mutt_addr_free(&a);
470  }
471  break;
472 
473  case OP_GENERIC_SELECT_ENTRY:
474  if (retbuf)
475  {
476  done = 2;
477  break;
478  }
479  /* fallthrough */
480  case OP_MAIL:
481  {
482  struct Email *msg = mutt_email_new();
483  msg->env = mutt_env_new();
484  if (!menu->tagprefix)
485  {
486  msg->env->to = result_to_addr(query_table[menu->current].data);
487  }
488  else
489  {
490  for (int i = 0; i < menu->max; i++)
491  {
492  if (query_table[i].tagged)
493  {
494  struct Address *a = result_to_addr(query_table[i].data);
495  mutt_addr_append(&msg->env->to, a, false);
496  mutt_addr_free(&a);
497  }
498  }
499  }
500  ci_send_message(0, msg, NULL, Context, NULL);
501  menu->redraw = REDRAW_FULL;
502  break;
503  }
504 
505  case OP_EXIT:
506  done = 1;
507  break;
508  }
509  }
510 
511  /* if we need to return the selected entries */
512  if (retbuf && (done == 2))
513  {
514  bool tagged = false;
515  size_t curpos = 0;
516 
517  memset(buf, 0, buflen);
518 
519  /* check for tagged entries */
520  for (int i = 0; i < menu->max; i++)
521  {
522  if (query_table[i].tagged)
523  {
524  if (curpos == 0)
525  {
526  struct Address *tmpa = result_to_addr(query_table[i].data);
528  tagged = true;
529  mutt_addr_write(buf, buflen, tmpa, false);
530  curpos = mutt_str_strlen(buf);
531  mutt_addr_free(&tmpa);
532  }
533  else if (curpos + 2 < buflen)
534  {
535  struct Address *tmpa = result_to_addr(query_table[i].data);
537  strcat(buf, ", ");
538  mutt_addr_write((char *) buf + curpos + 1, buflen - curpos - 1, tmpa, false);
539  curpos = mutt_str_strlen(buf);
540  mutt_addr_free(&tmpa);
541  }
542  }
543  }
544  /* then enter current message */
545  if (!tagged)
546  {
547  struct Address *tmpa = result_to_addr(query_table[menu->current].data);
549  mutt_addr_write(buf, buflen, tmpa, false);
550  mutt_addr_free(&tmpa);
551  }
552  }
553 
554  free_query(&results);
555  FREE(&query_table);
556  mutt_menu_pop_current(menu);
557  mutt_menu_destroy(&menu);
558  }
559 }
The "current" mailbox.
Definition: context.h:37
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:47
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
The envelope/body of an email.
Definition: email.h:37
GUI selectable list of items.
Definition: mutt_menu.h:82
struct Address * to
Definition: envelope.h:42
static const char clear[]
Definition: base64.c:8
#define _(a)
Definition: message.h:28
An email address.
Definition: address.h:32
struct Email * mutt_email_new(void)
Create a new Email.
Definition: email.c:63
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:662
int menu
menu definition for keymap entries.
Definition: mutt_menu.h:90
void(* menu_make_entry)(char *buf, size_t buflen, struct Menu *menu, int line)
Format a item for a menu.
Definition: mutt_menu.h:121
struct Address * mutt_addr_append(struct Address **a, struct Address *b, bool prune)
Append one list of addresses onto another.
Definition: address.c:763
#define mutt_get_field(field, buf, buflen, complete)
Definition: curs_lib.h:77
char * mutt_compile_help(char *buf, size_t buflen, int menu, const struct Mapping *items)
Create the text for the help menu.
Definition: help.c:115
int ci_send_message(SendFlags flags, struct Email *msg, const char *tempfile, struct Context *ctx, struct EmailList *el)
Send an email.
Definition: send.c:1726
size_t mutt_addr_write(char *buf, size_t buflen, struct Address *addr, bool display)
Write an Address to a buffer.
Definition: address.c:1146
bool tagged
Definition: email.h:44
Select from results of external query.
Definition: keymap.h:77
struct Envelope * env
envelope information
Definition: email.h:92
struct Query * next
Definition: query.c:64
struct Envelope * mutt_env_new(void)
Create a new Envelope.
Definition: envelope.c:40
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:124
int mutt_addrlist_to_local(struct Address *a)
Convert an Address list from Punycode.
Definition: address.c:1249
static void free_query(struct Query **query)
Free a Query.
Definition: query.c:110
bool tagprefix
Definition: mutt_menu.h:93
static const struct Mapping QueryHelp[]
Definition: query.c:76
static struct Query * run_query(char *s, int quiet)
Run an external program to find Addresses.
Definition: query.c:135
An entry from an external address-book.
Definition: query.c:58
static int query_search(struct Menu *menu, regex_t *rx, int line)
Search a Address menu item - Implements Menu::menu_search()
Definition: query.c:211
int max
the number of entries in the menu
Definition: mutt_menu.h:88
int(* menu_tag)(struct Menu *menu, int sel, int act)
Tag some menu items.
Definition: mutt_menu.h:138
MuttRedrawFlags redraw
when to redraw the screen
Definition: mutt_menu.h:89
int(* menu_search)(struct Menu *menu, regex_t *rx, int line)
Search a menu for a item matching a regex.
Definition: mutt_menu.h:130
char * title
the title of this menu
Definition: mutt_menu.h:84
static int query_tag(struct Menu *menu, int sel, int act)
Tag an entry in the Query Menu - Implements Menu::menu_tag()
Definition: query.c:310
static void query_make_entry(char *buf, size_t buflen, struct Menu *menu, int line)
Format a menu item for the query list - Implements Menu::menu_make_entry()
Definition: query.c:298
#define FREE(x)
Definition: memory.h:40
void * data
extra data for the current menu
Definition: mutt_menu.h:86
void mutt_alias_create(struct Envelope *cur, struct Address *iaddr)
Create a new Alias from an Envelope or an Address.
Definition: alias.c:368
static struct Address * result_to_addr(struct Query *r)
Turn a Query into an Address.
Definition: query.c:91
int current
current entry
Definition: mutt_menu.h:87
bool tagged
Definition: query.c:72
void mutt_addr_free(struct Address **p)
Free a list of Addresses.
Definition: address.c:446
char * help
quickref for the current menu
Definition: mutt_menu.h:85
An entry in a selectable list of Query&#39;s.
Definition: query.c:70
struct Query * data
Definition: query.c:73

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mutt_query_complete ( char *  buf,
size_t  buflen 
)

Perform auto-complete using an Address Query.

Parameters
bufBuffer for completion
buflenLength of buffer
Return values
0Always

Definition at line 567 of file query.c.

568 {
569  struct Query *results = NULL;
570  struct Address *tmpa = NULL;
571 
572  if (!C_QueryCommand)
573  {
574  mutt_error(_("Query command not defined"));
575  return 0;
576  }
577 
578  results = run_query(buf, 1);
579  if (results)
580  {
581  /* only one response? */
582  if (!results->next)
583  {
584  tmpa = result_to_addr(results);
586  buf[0] = '\0';
587  mutt_addr_write(buf, buflen, tmpa, false);
588  mutt_addr_free(&tmpa);
589  free_query(&results);
591  return 0;
592  }
593  /* multiple results, choose from query menu */
594  query_menu(buf, buflen, results, true);
595  }
596  return 0;
597 }
static void query_menu(char *buf, size_t buflen, struct Query *results, bool retbuf)
Get the user to enter an Address Query.
Definition: query.c:326
#define _(a)
Definition: message.h:28
An email address.
Definition: address.h:32
size_t mutt_addr_write(char *buf, size_t buflen, struct Address *addr, bool display)
Write an Address to a buffer.
Definition: address.c:1146
struct Query * next
Definition: query.c:64
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:141
int mutt_addrlist_to_local(struct Address *a)
Convert an Address list from Punycode.
Definition: address.c:1249
static void free_query(struct Query **query)
Free a Query.
Definition: query.c:110
static struct Query * run_query(char *s, int quiet)
Run an external program to find Addresses.
Definition: query.c:135
An entry from an external address-book.
Definition: query.c:58
#define mutt_error(...)
Definition: logging.h:88
static struct Address * result_to_addr(struct Query *r)
Turn a Query into an Address.
Definition: query.c:91
void mutt_addr_free(struct Address **p)
Free a list of Addresses.
Definition: address.c:446
char * C_QueryCommand
Config: External command to query and external address book.
Definition: query.c:52

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_query_menu ( char *  buf,
size_t  buflen 
)

Show the user the results of a Query.

Parameters
bufBuffer for the query
buflenLength of buffer

Definition at line 604 of file query.c.

605 {
606  if (!C_QueryCommand)
607  {
608  mutt_error(_("Query command not defined"));
609  return;
610  }
611 
612  if (!buf)
613  {
614  char tmp[256] = "";
615 
616  query_menu(tmp, sizeof(tmp), NULL, false);
617  }
618  else
619  {
620  query_menu(buf, buflen, NULL, true);
621  }
622 }
static void query_menu(char *buf, size_t buflen, struct Query *results, bool retbuf)
Get the user to enter an Address Query.
Definition: query.c:326
#define _(a)
Definition: message.h:28
#define mutt_error(...)
Definition: logging.h:88
char * C_QueryCommand
Config: External command to query and external address book.
Definition: query.c:52

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

char* C_QueryCommand

Config: External command to query and external address book.

Definition at line 52 of file query.c.

char* C_QueryFormat

Config: printf-like format string for the query menu (address book)

Definition at line 53 of file query.c.

const struct Mapping QueryHelp[]
static
Initial value:
= {
{ N_("Exit"), OP_EXIT },
{ N_("Mail"), OP_MAIL },
{ N_("New Query"), OP_QUERY },
{ N_("Make Alias"), OP_CREATE_ALIAS },
{ N_("Search"), OP_SEARCH },
{ N_("Help"), OP_HELP },
{ NULL, 0 },
}
#define N_(a)
Definition: message.h:32

Definition at line 76 of file query.c.