NeoMutt  2018-07-16 +1783-b00bd9
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 "address/lib.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 92 of file query.c.

93 {
94  static struct Address *tmp = NULL;
95 
96  tmp = mutt_addr_copy_list(r->addr, false);
97  if (!tmp)
98  return NULL;
99 
100  if (!tmp->next && !tmp->personal)
101  tmp->personal = mutt_str_strdup(r->name);
102 
103  mutt_addrlist_to_intl(tmp, NULL);
104  return tmp;
105 }
struct Address * addr
Definition: query.c:62
char * name
Definition: query.c:63
struct Address * mutt_addr_copy_list(struct Address *addr, bool prune)
Copy a list of addresses.
Definition: address.c:750
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:1249
char * personal
real name of address
Definition: address.h:34
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
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 111 of file query.c.

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

+ 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 136 of file query.c.

137 {
138  FILE *fp = NULL;
139  struct Query *first = NULL;
140  struct Query *cur = NULL;
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  struct Buffer *cmd = mutt_buffer_pool_get();
148 
150 
151  pid = mutt_create_filter(mutt_b2s(cmd), NULL, &fp, NULL);
152  if (pid < 0)
153  {
154  mutt_debug(LL_DEBUG1, "unable to fork command: %s\n", mutt_b2s(cmd));
156  return 0;
157  }
159 
160  if (!quiet)
161  mutt_message(_("Waiting for response..."));
162  fgets(msg, sizeof(msg), fp);
163  p = strrchr(msg, '\n');
164  if (p)
165  *p = '\0';
166  while ((buf = mutt_file_read_line(buf, &buflen, fp, &dummy, 0)))
167  {
168  p = strtok(buf, "\t\n");
169  if (p)
170  {
171  if (!first)
172  {
173  first = mutt_mem_calloc(1, sizeof(struct Query));
174  cur = first;
175  }
176  else
177  {
178  cur->next = mutt_mem_calloc(1, sizeof(struct Query));
179  cur = cur->next;
180  }
181 
182  cur->addr = mutt_addr_parse_list(cur->addr, p);
183  p = strtok(NULL, "\t\n");
184  if (p)
185  {
186  cur->name = mutt_str_strdup(p);
187  p = strtok(NULL, "\t\n");
188  if (p)
189  cur->other = mutt_str_strdup(p);
190  }
191  }
192  }
193  FREE(&buf);
194  mutt_file_fclose(&fp);
195  if (mutt_wait_filter(pid))
196  {
197  mutt_debug(LL_DEBUG1, "Error: %s\n", msg);
198  if (!quiet)
199  mutt_error("%s", msg);
200  }
201  else
202  {
203  if (!quiet)
204  mutt_message("%s", msg);
205  }
206 
207  return first;
208 }
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:62
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
#define mutt_message(...)
Definition: logging.h:82
String manipulation buffer.
Definition: buffer.h:33
char * name
Definition: query.c:63
#define _(a)
Definition: message.h:28
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:657
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:149
struct Query * next
Definition: query.c:65
#define mutt_b2s(buf)
Definition: buffer.h:42
char * other
Definition: query.c:64
An entry from an external address-book.
Definition: query.c:59
Log at debug level 1.
Definition: logging.h:56
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define mutt_error(...)
Definition: logging.h:83
void mutt_buffer_file_expand_fmt_quote(struct Buffer *dest, const char *fmt, const char *src)
Replace s in a string with a filename.
Definition: file.c:1393
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:80
struct Address * mutt_addr_parse_list(struct Address *top, const char *s)
Parse a list of email addresses.
Definition: address.c:473
int mutt_wait_filter(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:227
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: buffer.c:409
char * C_QueryCommand
Config: External command to query and external address book.
Definition: query.c:53
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: buffer.c:398

+ 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 215 of file query.c.

216 {
217  struct Entry *table = menu->data;
218 
219  if (table[line].data->name && !regexec(rx, table[line].data->name, 0, NULL, 0))
220  return 0;
221  if (table[line].data->other && !regexec(rx, table[line].data->other, 0, NULL, 0))
222  return 0;
223  if (table[line].data->addr)
224  {
225  if (table[line].data->addr->personal &&
226  !regexec(rx, table[line].data->addr->personal, 0, NULL, 0))
227  {
228  return 0;
229  }
230  if (table[line].data->addr->mailbox &&
231  !regexec(rx, table[line].data->addr->mailbox, 0, NULL, 0))
232  {
233  return 0;
234  }
235  }
236 
237  return REG_NOMATCH;
238 }
struct Address * addr
Definition: query.c:62
char * name
Definition: query.c:63
char * mailbox
mailbox and host address
Definition: address.h:35
const char * line
Definition: common.c:35
char * other
Definition: query.c:64
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:71
struct Query * data
Definition: query.c:74

+ 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 251 of file query.c.

255 {
256  struct Entry *entry = (struct Entry *) data;
257  struct Query *query = entry->data;
258  char fmt[128];
259  char tmp[256] = "";
260  int optional = (flags & MUTT_FORMAT_OPTIONAL);
261 
262  switch (op)
263  {
264  case 'a':
265  mutt_addr_write(tmp, sizeof(tmp), query->addr, true);
266  mutt_format_s(buf, buflen, prec, tmp);
267  break;
268  case 'c':
269  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
270  snprintf(buf, buflen, fmt, query->num + 1);
271  break;
272  case 'e':
273  if (!optional)
274  mutt_format_s(buf, buflen, prec, NONULL(query->other));
275  else if (!query->other || !*query->other)
276  optional = 0;
277  break;
278  case 'n':
279  mutt_format_s(buf, buflen, prec, NONULL(query->name));
280  break;
281  case 't':
282  snprintf(fmt, sizeof(fmt), "%%%sc", prec);
283  snprintf(buf, buflen, fmt, entry->tagged ? '*' : ' ');
284  break;
285  default:
286  snprintf(fmt, sizeof(fmt), "%%%sc", prec);
287  snprintf(buf, buflen, fmt, op);
288  break;
289  }
290 
291  if (optional)
292  mutt_expando_format(buf, buflen, col, cols, if_str, query_format_str, data,
294  else if (flags & MUTT_FORMAT_OPTIONAL)
295  mutt_expando_format(buf, buflen, col, cols, else_str, query_format_str,
296  data, MUTT_FORMAT_NO_FLAGS);
297 
298  return src;
299 }
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:836
struct Address * addr
Definition: query.c:62
#define NONULL(x)
Definition: string2.h:36
char * name
Definition: query.c:63
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: format_flags.h:30
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:251
size_t mutt_addr_write(char *buf, size_t buflen, struct Address *addr, bool display)
Write an Address to a buffer.
Definition: address.c:1184
int num
Definition: query.c:61
char * other
Definition: query.c:64
An entry from an external address-book.
Definition: query.c:59
void mutt_format_s(char *buf, size_t buflen, const char *prec, const char *s)
Format a simple string.
Definition: curs_lib.c:1124
#define MUTT_FORMAT_OPTIONAL
Allow optional field processing.
Definition: format_flags.h:33
bool tagged
Definition: query.c:73
An entry in a selectable list of Query&#39;s.
Definition: query.c:71
struct Query * data
Definition: query.c:74

+ 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 304 of file query.c.

305 {
306  struct Entry *entry = &((struct Entry *) menu->data)[line];
307 
308  entry->data->num = line;
310  query_format_str, (unsigned long) entry, MUTT_FORMAT_ARROWCURSOR);
311 }
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:836
#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:54
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:251
int num
Definition: query.c:61
const char * line
Definition: common.c:35
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:71
struct Query * data
Definition: query.c:74

+ 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 316 of file query.c.

317 {
318  struct Entry *cur = &((struct Entry *) menu->data)[sel];
319  bool ot = cur->tagged;
320 
321  cur->tagged = ((act >= 0) ? act : !cur->tagged);
322  return cur->tagged - ot;
323 }
void * data
extra data for the current menu
Definition: mutt_menu.h:86
bool tagged
Definition: query.c:73
An entry in a selectable list of Query&#39;s.
Definition: query.c:71

+ 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 332 of file query.c.

333 {
334  struct Menu *menu = NULL;
335  struct Entry *query_table = NULL;
336  struct Query *queryp = NULL;
337  char title[256];
338 
339  if (!results)
340  {
341  /* Prompt for Query */
342  if ((mutt_get_field(_("Query: "), buf, buflen, 0) == 0) && (buf[0] != '\0'))
343  {
344  results = run_query(buf, 0);
345  }
346  }
347 
348  if (results)
349  {
350  snprintf(title, sizeof(title), _("Query '%s'"), buf);
351 
352  menu = mutt_menu_new(MENU_QUERY);
354  menu->menu_search = query_search;
355  menu->menu_tag = query_tag;
356  menu->title = title;
357  char helpstr[1024];
358  menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_QUERY, QueryHelp);
360 
361  /* count the number of results */
362  for (queryp = results; queryp; queryp = queryp->next)
363  menu->max++;
364 
365  query_table = mutt_mem_calloc(menu->max, sizeof(struct Entry));
366  menu->data = query_table;
367 
368  queryp = results;
369  for (int i = 0; queryp; queryp = queryp->next, i++)
370  query_table[i].data = queryp;
371 
372  int done = 0;
373  while (done == 0)
374  {
375  const int op = mutt_menu_loop(menu);
376  switch (op)
377  {
378  case OP_QUERY_APPEND:
379  case OP_QUERY:
380  if ((mutt_get_field(_("Query: "), buf, buflen, 0) == 0) && (buf[0] != '\0'))
381  {
382  struct Query *newresults = run_query(buf, 0);
383 
384  menu->redraw = REDRAW_FULL;
385  if (newresults)
386  {
387  snprintf(title, sizeof(title), _("Query '%s'"), buf);
388 
389  if (op == OP_QUERY)
390  {
391  free_query(&results);
392  results = newresults;
393  FREE(&query_table);
394  }
395  else
396  {
397  /* append */
398  for (queryp = results; queryp->next; queryp = queryp->next)
399  ;
400 
401  queryp->next = newresults;
402  }
403 
404  menu->current = 0;
405  mutt_menu_pop_current(menu);
406  mutt_menu_destroy(&menu);
407  menu = mutt_menu_new(MENU_QUERY);
409  menu->menu_search = query_search;
410  menu->menu_tag = query_tag;
411  menu->title = title;
412  menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_QUERY, QueryHelp);
414 
415  /* count the number of results */
416  for (queryp = results; queryp; queryp = queryp->next)
417  menu->max++;
418 
419  if (op == OP_QUERY)
420  {
421  menu->data = query_table =
422  mutt_mem_calloc(menu->max, sizeof(struct Entry));
423 
424  queryp = results;
425  for (int i = 0; queryp; queryp = queryp->next, i++)
426  query_table[i].data = queryp;
427  }
428  else
429  {
430  bool clear = false;
431 
432  /* append */
433  mutt_mem_realloc(&query_table, menu->max * sizeof(struct Entry));
434 
435  menu->data = query_table;
436 
437  queryp = results;
438  for (int i = 0; queryp; queryp = queryp->next, i++)
439  {
440  /* once we hit new entries, clear/init the tag */
441  if (queryp == newresults)
442  clear = true;
443 
444  query_table[i].data = queryp;
445  if (clear)
446  query_table[i].tagged = false;
447  }
448  }
449  }
450  }
451  break;
452 
453  case OP_CREATE_ALIAS:
454  if (menu->tagprefix)
455  {
456  struct Address *naddr = NULL;
457 
458  for (int i = 0; i < menu->max; i++)
459  {
460  if (query_table[i].tagged)
461  {
462  struct Address *a = result_to_addr(query_table[i].data);
463  mutt_addr_append(&naddr, a, false);
464  mutt_addr_free(&a);
465  }
466  }
467 
468  mutt_alias_create(NULL, naddr);
469  mutt_addr_free(&naddr);
470  }
471  else
472  {
473  struct Address *a = result_to_addr(query_table[menu->current].data);
474  mutt_alias_create(NULL, a);
475  mutt_addr_free(&a);
476  }
477  break;
478 
479  case OP_GENERIC_SELECT_ENTRY:
480  if (retbuf)
481  {
482  done = 2;
483  break;
484  }
485  /* fallthrough */
486  case OP_MAIL:
487  {
488  struct Email *msg = mutt_email_new();
489  msg->env = mutt_env_new();
490  if (!menu->tagprefix)
491  {
492  msg->env->to = result_to_addr(query_table[menu->current].data);
493  }
494  else
495  {
496  for (int i = 0; i < menu->max; i++)
497  {
498  if (query_table[i].tagged)
499  {
500  struct Address *a = result_to_addr(query_table[i].data);
501  mutt_addr_append(&msg->env->to, a, false);
502  mutt_addr_free(&a);
503  }
504  }
505  }
506  ci_send_message(SEND_NO_FLAGS, msg, NULL, Context, NULL);
507  menu->redraw = REDRAW_FULL;
508  break;
509  }
510 
511  case OP_EXIT:
512  done = 1;
513  break;
514  }
515  }
516 
517  /* if we need to return the selected entries */
518  if (retbuf && (done == 2))
519  {
520  bool tagged = false;
521  size_t curpos = 0;
522 
523  memset(buf, 0, buflen);
524 
525  /* check for tagged entries */
526  for (int i = 0; i < menu->max; i++)
527  {
528  if (query_table[i].tagged)
529  {
530  if (curpos == 0)
531  {
532  struct Address *tmpa = result_to_addr(query_table[i].data);
534  tagged = true;
535  mutt_addr_write(buf, buflen, tmpa, false);
536  curpos = mutt_str_strlen(buf);
537  mutt_addr_free(&tmpa);
538  }
539  else if (curpos + 2 < buflen)
540  {
541  struct Address *tmpa = result_to_addr(query_table[i].data);
543  strcat(buf, ", ");
544  mutt_addr_write((char *) buf + curpos + 1, buflen - curpos - 1, tmpa, false);
545  curpos = mutt_str_strlen(buf);
546  mutt_addr_free(&tmpa);
547  }
548  }
549  }
550  /* then enter current message */
551  if (!tagged)
552  {
553  struct Address *tmpa = result_to_addr(query_table[menu->current].data);
555  mutt_addr_write(buf, buflen, tmpa, false);
556  mutt_addr_free(&tmpa);
557  }
558  }
559 
560  free_query(&results);
561  FREE(&query_table);
562  mutt_menu_pop_current(menu);
563  mutt_menu_destroy(&menu);
564  }
565 }
The "current" mailbox.
Definition: context.h:38
#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
#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:669
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:122
#define mutt_get_field(field, buf, buflen, complete)
Definition: curs_lib.h:86
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:1845
#define SEND_NO_FLAGS
No flags are set.
Definition: send.h:85
bool tagged
Definition: email.h:44
int mutt_addrlist_to_local(struct Address *a)
Convert an Address list from Punycode.
Definition: address.c:1290
Select from results of external query.
Definition: keymap.h:79
struct Envelope * env
envelope information
Definition: email.h:92
struct Query * next
Definition: query.c:65
size_t mutt_addr_write(char *buf, size_t buflen, struct Address *addr, bool display)
Write an Address to a buffer.
Definition: address.c:1184
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:121
static void free_query(struct Query **query)
Free a Query.
Definition: query.c:111
bool tagprefix
Definition: mutt_menu.h:93
static const struct Mapping QueryHelp[]
Definition: query.c:77
static struct Query * run_query(char *s, int quiet)
Run an external program to find Addresses.
Definition: query.c:136
An entry from an external address-book.
Definition: query.c:59
static int query_search(struct Menu *menu, regex_t *rx, int line)
Search a Address menu item - Implements Menu::menu_search()
Definition: query.c:215
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:139
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:131
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:316
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:304
#define FREE(x)
Definition: memory.h:40
void * data
extra data for the current menu
Definition: mutt_menu.h:86
void mutt_addr_free(struct Address **p)
Free a list of Addresses.
Definition: address.c:451
void mutt_alias_create(struct Envelope *cur, struct Address *iaddr)
Create a new Alias from an Envelope or an Address.
Definition: alias.c:369
static struct Address * result_to_addr(struct Query *r)
Turn a Query into an Address.
Definition: query.c:92
struct Address * mutt_addr_append(struct Address **a, struct Address *b, bool prune)
Append one list of addresses onto another.
Definition: address.c:783
int current
current entry
Definition: mutt_menu.h:87
bool tagged
Definition: query.c:73
char * help
quickref for the current menu
Definition: mutt_menu.h:85
static const char clear[]
An entry in a selectable list of Query&#39;s.
Definition: query.c:71
struct Query * data
Definition: query.c:74

+ 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 573 of file query.c.

574 {
575  struct Query *results = NULL;
576  struct Address *tmpa = NULL;
577 
578  if (!C_QueryCommand)
579  {
580  mutt_error(_("Query command not defined"));
581  return 0;
582  }
583 
584  results = run_query(buf, 1);
585  if (results)
586  {
587  /* only one response? */
588  if (!results->next)
589  {
590  tmpa = result_to_addr(results);
592  buf[0] = '\0';
593  mutt_addr_write(buf, buflen, tmpa, false);
594  mutt_addr_free(&tmpa);
595  free_query(&results);
597  return 0;
598  }
599  /* multiple results, choose from query menu */
600  query_menu(buf, buflen, results, true);
601  }
602  return 0;
603 }
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:332
#define _(a)
Definition: message.h:28
An email address.
Definition: address.h:32
int mutt_addrlist_to_local(struct Address *a)
Convert an Address list from Punycode.
Definition: address.c:1290
struct Query * next
Definition: query.c:65
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:141
size_t mutt_addr_write(char *buf, size_t buflen, struct Address *addr, bool display)
Write an Address to a buffer.
Definition: address.c:1184
static void free_query(struct Query **query)
Free a Query.
Definition: query.c:111
static struct Query * run_query(char *s, int quiet)
Run an external program to find Addresses.
Definition: query.c:136
An entry from an external address-book.
Definition: query.c:59
#define mutt_error(...)
Definition: logging.h:83
void mutt_addr_free(struct Address **p)
Free a list of Addresses.
Definition: address.c:451
static struct Address * result_to_addr(struct Query *r)
Turn a Query into an Address.
Definition: query.c:92
char * C_QueryCommand
Config: External command to query and external address book.
Definition: query.c:53

+ 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 610 of file query.c.

611 {
612  if (!C_QueryCommand)
613  {
614  mutt_error(_("Query command not defined"));
615  return;
616  }
617 
618  if (!buf)
619  {
620  char tmp[256] = "";
621 
622  query_menu(tmp, sizeof(tmp), NULL, false);
623  }
624  else
625  {
626  query_menu(buf, buflen, NULL, true);
627  }
628 }
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:332
#define _(a)
Definition: message.h:28
#define mutt_error(...)
Definition: logging.h:83
char * C_QueryCommand
Config: External command to query and external address book.
Definition: query.c:53

+ 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 53 of file query.c.

char* C_QueryFormat

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

Definition at line 54 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 77 of file query.c.