NeoMutt  2018-07-16 +952-a2da0a
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 "menu.h"
#include "mutt_logging.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, enum FormatFlag 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 * QueryCommand
 Config: External command to query and external address book. More...
 
char * 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:384
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
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:46
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[HUGE_STRING];
141  char *buf = NULL;
142  size_t buflen;
143  int dummy = 0;
144  char msg[STRING];
145  char *p = NULL;
146  pid_t thepid;
147 
148  mutt_file_expand_fmt_quote(cmd, sizeof(cmd), QueryCommand, s);
149 
150  thepid = mutt_create_filter(cmd, NULL, &fp, NULL);
151  if (thepid < 0)
152  {
153  mutt_debug(1, "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(thepid))
192  {
193  mutt_debug(1, "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 }
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:632
#define mutt_message(...)
Definition: logging.h:87
char * name
Definition: query.c:62
#define _(a)
Definition: message.h:28
char * QueryCommand
Config: External command to query and external address book.
Definition: query.c:52
struct Query * next
Definition: query.c:64
#define HUGE_STRING
Definition: string2.h:37
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 STRING
Definition: string2.h:35
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:384
int mutt_file_fclose(FILE **f)
Close a FILE handle (and NULL the pointer)
Definition: file.c:149
#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:1323
#define FREE(x)
Definition: memory.h:46
pid_t mutt_create_filter(const char *s, FILE **in, FILE **out, FILE **err)
Set up filter program.
Definition: filter.c:216
#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

+ 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: menu.h:60
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,
enum FormatFlag  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[SHORT_STRING];
255  char tmp[STRING] = "";
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 }
struct Address * addr
Definition: query.c:61
#define NONULL(x)
Definition: string2.h:39
#define SHORT_STRING
Definition: string2.h:34
char * name
Definition: query.c:62
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
allow optional field processing
Definition: format_flags.h:36
int num
Definition: query.c:60
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, enum FormatFlag flags)
Format a string for the query menu - Implements format_t.
Definition: query.c:247
char * other
Definition: query.c:63
An entry from an external address-book.
Definition: query.c:58
#define STRING
Definition: string2.h:35
void mutt_format_s(char *buf, size_t buflen, const char *prec, const char *s)
Format a simple string.
Definition: curs_lib.c:1061
bool tagged
Definition: query.c:72
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, enum FormatFlag flags)
Expand expandos (x) in a string.
Definition: muttlib.c:816
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 }
#define NONULL(x)
Definition: string2.h:39
const char * line
Definition: common.c:35
int num
Definition: query.c:60
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, enum FormatFlag flags)
Format a string for the query menu - Implements format_t.
Definition: query.c:247
struct MuttWindow * MuttIndexWindow
Index Window.
Definition: mutt_window.c:39
reserve space for arrow_cursor
Definition: format_flags.h:38
char * QueryFormat
Config: printf-like format string for the query menu (address book)
Definition: query.c:53
void * data
extra data for the current menu
Definition: menu.h:60
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, enum FormatFlag flags)
Expand expandos (x) in a string.
Definition: muttlib.c:816
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: menu.h:60
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 Email *msg = NULL;
330  struct Entry *QueryTable = NULL;
331  struct Query *queryp = NULL;
332  char title[STRING];
333 
334  if (!results)
335  {
336  /* Prompt for Query */
337  if (mutt_get_field(_("Query: "), buf, buflen, 0) == 0 && buf[0])
338  {
339  results = run_query(buf, 0);
340  }
341  }
342 
343  if (results)
344  {
345  snprintf(title, sizeof(title), _("Query '%s'"), buf);
346 
347  menu = mutt_menu_new(MENU_QUERY);
349  menu->menu_search = query_search;
350  menu->menu_tag = query_tag;
351  menu->title = title;
352  char helpstr[LONG_STRING];
353  menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_QUERY, QueryHelp);
355 
356  /* count the number of results */
357  for (queryp = results; queryp; queryp = queryp->next)
358  menu->max++;
359 
360  QueryTable = mutt_mem_calloc(menu->max, sizeof(struct Entry));
361  menu->data = QueryTable;
362 
363  int i;
364  for (i = 0, queryp = results; queryp; queryp = queryp->next, i++)
365  QueryTable[i].data = queryp;
366 
367  int done = 0;
368  while (!done)
369  {
370  const int op = mutt_menu_loop(menu);
371  switch (op)
372  {
373  case OP_QUERY_APPEND:
374  case OP_QUERY:
375  if (mutt_get_field(_("Query: "), buf, buflen, 0) == 0 && buf[0])
376  {
377  struct Query *newresults = run_query(buf, 0);
378 
379  menu->redraw = REDRAW_FULL;
380  if (newresults)
381  {
382  snprintf(title, sizeof(title), _("Query '%s'"), buf);
383 
384  if (op == OP_QUERY)
385  {
386  free_query(&results);
387  results = newresults;
388  FREE(&QueryTable);
389  }
390  else
391  {
392  /* append */
393  for (queryp = results; queryp->next; queryp = queryp->next)
394  ;
395 
396  queryp->next = newresults;
397  }
398 
399  menu->current = 0;
400  mutt_menu_pop_current(menu);
401  mutt_menu_destroy(&menu);
402  menu = mutt_menu_new(MENU_QUERY);
404  menu->menu_search = query_search;
405  menu->menu_tag = query_tag;
406  menu->title = title;
407  menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_QUERY, QueryHelp);
409 
410  /* count the number of results */
411  for (queryp = results; queryp; queryp = queryp->next)
412  menu->max++;
413 
414  if (op == OP_QUERY)
415  {
416  menu->data = QueryTable =
417  mutt_mem_calloc(menu->max, sizeof(struct Entry));
418 
419  for (i = 0, queryp = results; queryp; queryp = queryp->next, i++)
420  QueryTable[i].data = queryp;
421  }
422  else
423  {
424  bool clear = false;
425 
426  /* append */
427  mutt_mem_realloc(&QueryTable, menu->max * sizeof(struct Entry));
428 
429  menu->data = QueryTable;
430 
431  for (i = 0, queryp = results; queryp; queryp = queryp->next, i++)
432  {
433  /* once we hit new entries, clear/init the tag */
434  if (queryp == newresults)
435  clear = true;
436 
437  QueryTable[i].data = queryp;
438  if (clear)
439  QueryTable[i].tagged = false;
440  }
441  }
442  }
443  }
444  break;
445 
446  case OP_CREATE_ALIAS:
447  if (menu->tagprefix)
448  {
449  struct Address *naddr = NULL;
450 
451  for (i = 0; i < menu->max; i++)
452  {
453  if (QueryTable[i].tagged)
454  {
455  struct Address *a = result_to_addr(QueryTable[i].data);
456  mutt_addr_append(&naddr, a, false);
457  mutt_addr_free(&a);
458  }
459  }
460 
461  mutt_alias_create(NULL, naddr);
462  mutt_addr_free(&naddr);
463  }
464  else
465  {
466  struct Address *a = result_to_addr(QueryTable[menu->current].data);
467  mutt_alias_create(NULL, a);
468  mutt_addr_free(&a);
469  }
470  break;
471 
472  case OP_GENERIC_SELECT_ENTRY:
473  if (retbuf)
474  {
475  done = 2;
476  break;
477  }
478  /* fallthrough */
479  case OP_MAIL:
480  msg = mutt_email_new();
481  msg->env = mutt_env_new();
482  if (!menu->tagprefix)
483  {
484  msg->env->to = result_to_addr(QueryTable[menu->current].data);
485  }
486  else
487  {
488  for (i = 0; i < menu->max; i++)
489  {
490  if (QueryTable[i].tagged)
491  {
492  struct Address *a = result_to_addr(QueryTable[i].data);
493  mutt_addr_append(&msg->env->to, a, false);
494  mutt_addr_free(&a);
495  }
496  }
497  }
498  ci_send_message(0, msg, NULL, Context, NULL);
499  menu->redraw = REDRAW_FULL;
500  break;
501 
502  case OP_EXIT:
503  done = 1;
504  break;
505  }
506  }
507 
508  /* if we need to return the selected entries */
509  if (retbuf && (done == 2))
510  {
511  bool tagged = false;
512  size_t curpos = 0;
513 
514  memset(buf, 0, buflen);
515 
516  /* check for tagged entries */
517  for (i = 0; i < menu->max; i++)
518  {
519  if (QueryTable[i].tagged)
520  {
521  if (curpos == 0)
522  {
523  struct Address *tmpa = result_to_addr(QueryTable[i].data);
525  tagged = true;
526  mutt_addr_write(buf, buflen, tmpa, false);
527  curpos = mutt_str_strlen(buf);
528  mutt_addr_free(&tmpa);
529  }
530  else if (curpos + 2 < buflen)
531  {
532  struct Address *tmpa = result_to_addr(QueryTable[i].data);
534  strcat(buf, ", ");
535  mutt_addr_write((char *) buf + curpos + 1, buflen - curpos - 1, tmpa, false);
536  curpos = mutt_str_strlen(buf);
537  mutt_addr_free(&tmpa);
538  }
539  }
540  }
541  /* then enter current message */
542  if (!tagged)
543  {
544  struct Address *tmpa = result_to_addr(QueryTable[menu->current].data);
546  mutt_addr_write(buf, buflen, tmpa, false);
547  mutt_addr_free(&tmpa);
548  }
549  }
550 
551  free_query(&results);
552  FREE(&QueryTable);
553  mutt_menu_pop_current(menu);
554  mutt_menu_destroy(&menu);
555  }
556 }
Select from results of external query.
Definition: keymap.h:76
The "current" mailbox.
Definition: context.h:36
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
int redraw
when to redraw the screen
Definition: menu.h:63
The envelope/body of an email.
Definition: email.h:35
GUI selectable list of items.
Definition: menu.h:56
struct Address * to
Definition: envelope.h:36
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:663
int menu
menu definition for keymap entries.
Definition: menu.h:64
#define LONG_STRING
Definition: string2.h:36
void(* menu_make_entry)(char *buf, size_t buflen, struct Menu *menu, int line)
Format a item for a menu.
Definition: menu.h:96
struct Address * mutt_addr_append(struct Address **a, struct Address *b, bool prune)
Append one list of addresses onto another.
Definition: address.c:763
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
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 Envelope * env
envelope information
Definition: email.h:91
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: menu.h:67
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
#define mutt_get_field(A, B, C, D)
Definition: curs_lib.h:78
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: menu.h:62
int(* menu_tag)(struct Menu *menu, int sel, int act)
Tag some menu items.
Definition: menu.h:113
int(* menu_search)(struct Menu *menu, regex_t *rx, int line)
Search a menu for a item matching a regex.
Definition: menu.h:105
char * title
the title of this menu
Definition: menu.h:58
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
#define STRING
Definition: string2.h:35
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
int ci_send_message(int flags, struct Email *msg, char *tempfile, struct Context *ctx, struct Email *cur)
Send an email.
Definition: send.c:1530
#define FREE(x)
Definition: memory.h:46
void * data
extra data for the current menu
Definition: menu.h:60
void mutt_alias_create(struct Envelope *cur, struct Address *iaddr)
Create a new Alias from an Envelope or an Address.
Definition: alias.c:367
static struct Address * result_to_addr(struct Query *r)
Turn a Query into an Address.
Definition: query.c:91
int current
current entry
Definition: menu.h:61
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: menu.h:59
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 564 of file query.c.

565 {
566  struct Query *results = NULL;
567  struct Address *tmpa = NULL;
568 
569  if (!QueryCommand)
570  {
571  mutt_error(_("Query command not defined"));
572  return 0;
573  }
574 
575  results = run_query(buf, 1);
576  if (results)
577  {
578  /* only one response? */
579  if (!results->next)
580  {
581  tmpa = result_to_addr(results);
583  buf[0] = '\0';
584  mutt_addr_write(buf, buflen, tmpa, false);
585  mutt_addr_free(&tmpa);
586  free_query(&results);
588  return 0;
589  }
590  /* multiple results, choose from query menu */
591  query_menu(buf, buflen, results, true);
592  }
593  return 0;
594 }
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
char * QueryCommand
Config: External command to query and external address book.
Definition: query.c:52
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

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

602 {
603  if (!QueryCommand)
604  {
605  mutt_error(_("Query command not defined"));
606  return;
607  }
608 
609  if (!buf)
610  {
611  char buffer[STRING] = "";
612 
613  query_menu(buffer, sizeof(buffer), NULL, false);
614  }
615  else
616  {
617  query_menu(buf, buflen, NULL, true);
618  }
619 }
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
char * QueryCommand
Config: External command to query and external address book.
Definition: query.c:52
#define STRING
Definition: string2.h:35
#define mutt_error(...)
Definition: logging.h:88

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

char* QueryCommand

Config: External command to query and external address book.

Definition at line 52 of file query.c.

char* 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.