NeoMutt  2018-07-16 +2225-8687db
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"

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 bool result_to_addr (struct AddressList *al, struct Query *r)
 Turn a Query into an AddressList. More...
 
static struct Queryquery_new (void)
 Create a new query. 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
  • Pietro Cerutti

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 bool result_to_addr ( struct AddressList *  al,
struct Query r 
)
static

Turn a Query into an AddressList.

Parameters
alAddressList to fill (must be empty)
rQuery to use
Return values
boolTrue on success

Definition at line 94 of file query.c.

95 {
96  if (!al || !TAILQ_EMPTY(al) || !r)
97  return false;
98 
99  mutt_addrlist_copy(al, &r->addr, false);
100  if (!TAILQ_EMPTY(al))
101  {
102  struct Address *first = TAILQ_FIRST(al);
103  struct Address *second = TAILQ_NEXT(first, entries);
104  if (!second && !first->personal)
105  first->personal = mutt_str_strdup(r->name);
106 
107  mutt_addrlist_to_intl(al, NULL);
108  }
109 
110  return true;
111 }
#define TAILQ_FIRST(head)
Definition: queue.h:717
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition: address.c:724
char * name
Definition: query.c:64
An email address.
Definition: address.h:34
char * personal
Real name of address.
Definition: address.h:36
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1186
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define TAILQ_NEXT(elm, field)
Definition: queue.h:816
#define TAILQ_EMPTY(head)
Definition: queue.h:715
struct AddressList addr
Definition: query.c:63
static struct Query* query_new ( void  )
static

Create a new query.

Return values
Anewly allocated query

Definition at line 117 of file query.c.

118 {
119  struct Query *query = mutt_mem_calloc(1, sizeof(struct Query));
120  TAILQ_INIT(&query->addr);
121  return query;
122 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define TAILQ_INIT(head)
Definition: queue.h:759
An entry from an external address-book.
Definition: query.c:60
struct AddressList addr
Definition: query.c:63
static void free_query ( struct Query **  query)
static

Free a Query.

Parameters
[out]queryQuery to free

Definition at line 128 of file query.c.

129 {
130  struct Query *p = NULL;
131 
132  if (!query)
133  return;
134 
135  while (*query)
136  {
137  p = *query;
138  *query = (*query)->next;
139 
141  FREE(&p->name);
142  FREE(&p->other);
143  FREE(&p);
144  }
145 }
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1351
char * name
Definition: query.c:64
struct Query * next
Definition: query.c:66
char * other
Definition: query.c:65
An entry from an external address-book.
Definition: query.c:60
#define FREE(x)
Definition: memory.h:40
struct AddressList addr
Definition: query.c:63
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 153 of file query.c.

154 {
155  FILE *fp = NULL;
156  struct Query *first = NULL;
157  struct Query *cur = NULL;
158  char *buf = NULL;
159  size_t buflen;
160  int dummy = 0;
161  char msg[256];
162  char *p = NULL;
163  pid_t pid;
164  struct Buffer *cmd = mutt_buffer_pool_get();
165 
167 
168  pid = mutt_create_filter(mutt_b2s(cmd), NULL, &fp, NULL);
169  if (pid < 0)
170  {
171  mutt_debug(LL_DEBUG1, "unable to fork command: %s\n", mutt_b2s(cmd));
173  return 0;
174  }
176 
177  if (!quiet)
178  mutt_message(_("Waiting for response..."));
179  fgets(msg, sizeof(msg), fp);
180  p = strrchr(msg, '\n');
181  if (p)
182  *p = '\0';
183  while ((buf = mutt_file_read_line(buf, &buflen, fp, &dummy, 0)))
184  {
185  p = strtok(buf, "\t\n");
186  if (p)
187  {
188  if (!first)
189  {
190  first = query_new();
191  cur = first;
192  }
193  else
194  {
195  cur->next = query_new();
196  cur = cur->next;
197  }
198 
199  mutt_addrlist_parse(&cur->addr, p);
200  p = strtok(NULL, "\t\n");
201  if (p)
202  {
203  cur->name = mutt_str_strdup(p);
204  p = strtok(NULL, "\t\n");
205  if (p)
206  cur->other = mutt_str_strdup(p);
207  }
208  }
209  }
210  FREE(&buf);
211  mutt_file_fclose(&fp);
212  if (mutt_wait_filter(pid))
213  {
214  mutt_debug(LL_DEBUG1, "Error: %s\n", msg);
215  if (!quiet)
216  mutt_error("%s", msg);
217  }
218  else
219  {
220  if (!quiet)
221  mutt_message("%s", msg);
222  }
223 
224  return first;
225 }
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 Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:75
int mutt_addrlist_parse(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition: address.c:454
#define mutt_message(...)
Definition: logging.h:83
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:86
String manipulation buffer.
Definition: buffer.h:33
char * name
Definition: query.c:64
#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:663
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:149
struct Query * next
Definition: query.c:66
#define mutt_b2s(buf)
Definition: buffer.h:42
char * other
Definition: query.c:65
An entry from an external address-book.
Definition: query.c:60
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:84
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:1418
#define FREE(x)
Definition: memory.h:40
static struct Query * query_new(void)
Create a new query.
Definition: query.c:117
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
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:54
struct AddressList addr
Definition: query.c:63
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 232 of file query.c.

233 {
234  struct Entry *table = menu->data;
235  struct Query *query = table[line].data;
236 
237  if (query->name && !regexec(rx, query->name, 0, NULL, 0))
238  return 0;
239  if (query->other && !regexec(rx, query->other, 0, NULL, 0))
240  return 0;
241  if (!TAILQ_EMPTY(&query->addr))
242  {
243  struct Address *addr = TAILQ_FIRST(&query->addr);
244  if (addr->personal && !regexec(rx, addr->personal, 0, NULL, 0))
245  {
246  return 0;
247  }
248  if (addr->mailbox && !regexec(rx, addr->mailbox, 0, NULL, 0))
249  {
250  return 0;
251  }
252  }
253 
254  return REG_NOMATCH;
255 }
#define TAILQ_FIRST(head)
Definition: queue.h:717
char * name
Definition: query.c:64
An email address.
Definition: address.h:34
char * mailbox
Mailbox and host address.
Definition: address.h:37
const char * line
Definition: common.c:36
char * other
Definition: query.c:65
An entry from an external address-book.
Definition: query.c:60
char * personal
Real name of address.
Definition: address.h:36
void * data
extra data for the current menu
Definition: mutt_menu.h:86
#define TAILQ_EMPTY(head)
Definition: queue.h:715
struct AddressList addr
Definition: query.c:63
An entry in a selectable list of Query&#39;s.
Definition: query.c:72
struct Query * data
Definition: query.c:75
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 268 of file query.c.

272 {
273  struct Entry *entry = (struct Entry *) data;
274  struct Query *query = entry->data;
275  char fmt[128];
276  char tmp[256] = { 0 };
277  int optional = (flags & MUTT_FORMAT_OPTIONAL);
278 
279  switch (op)
280  {
281  case 'a':
282  mutt_addrlist_write(tmp, sizeof(tmp), &query->addr, true);
283  mutt_format_s(buf, buflen, prec, tmp);
284  break;
285  case 'c':
286  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
287  snprintf(buf, buflen, fmt, query->num + 1);
288  break;
289  case 'e':
290  if (!optional)
291  mutt_format_s(buf, buflen, prec, NONULL(query->other));
292  else if (!query->other || !*query->other)
293  optional = 0;
294  break;
295  case 'n':
296  mutt_format_s(buf, buflen, prec, NONULL(query->name));
297  break;
298  case 't':
299  snprintf(fmt, sizeof(fmt), "%%%sc", prec);
300  snprintf(buf, buflen, fmt, entry->tagged ? '*' : ' ');
301  break;
302  default:
303  snprintf(fmt, sizeof(fmt), "%%%sc", prec);
304  snprintf(buf, buflen, fmt, op);
305  break;
306  }
307 
308  if (optional)
309  mutt_expando_format(buf, buflen, col, cols, if_str, query_format_str, data,
311  else if (flags & MUTT_FORMAT_OPTIONAL)
312  mutt_expando_format(buf, buflen, col, cols, else_str, query_format_str,
313  data, MUTT_FORMAT_NO_FLAGS);
314 
315  return src;
316 }
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:841
#define NONULL(x)
Definition: string2.h:37
char * name
Definition: query.c:64
size_t mutt_addrlist_write(char *buf, size_t buflen, const struct AddressList *al, bool display)
Write an Address to a buffer.
Definition: address.c:1134
#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:268
int num
Definition: query.c:62
char * other
Definition: query.c:65
An entry from an external address-book.
Definition: query.c:60
void mutt_format_s(char *buf, size_t buflen, const char *prec, const char *s)
Format a simple string.
Definition: curs_lib.c:1139
#define MUTT_FORMAT_OPTIONAL
Allow optional field processing.
Definition: format_flags.h:33
bool tagged
Definition: query.c:74
struct AddressList addr
Definition: query.c:63
An entry in a selectable list of Query&#39;s.
Definition: query.c:72
struct Query * data
Definition: query.c:75
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 321 of file query.c.

322 {
323  struct Entry *entry = &((struct Entry *) menu->data)[line];
324 
325  entry->data->num = line;
327  query_format_str, (unsigned long) entry, MUTT_FORMAT_ARROWCURSOR);
328 }
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:841
#define NONULL(x)
Definition: string2.h:37
#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:55
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:268
int num
Definition: query.c:62
const char * line
Definition: common.c:36
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:72
struct Query * data
Definition: query.c:75
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 333 of file query.c.

334 {
335  struct Entry *cur = &((struct Entry *) menu->data)[sel];
336  bool ot = cur->tagged;
337 
338  cur->tagged = ((act >= 0) ? act : !cur->tagged);
339  return cur->tagged - ot;
340 }
void * data
extra data for the current menu
Definition: mutt_menu.h:86
bool tagged
Definition: query.c:74
An entry in a selectable list of Query&#39;s.
Definition: query.c:72
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 349 of file query.c.

350 {
351  struct Menu *menu = NULL;
352  struct Entry *query_table = NULL;
353  struct Query *queryp = NULL;
354  char title[256];
355 
356  if (!results)
357  {
358  /* Prompt for Query */
359  if ((mutt_get_field(_("Query: "), buf, buflen, 0) == 0) && (buf[0] != '\0'))
360  {
361  results = run_query(buf, 0);
362  }
363  }
364 
365  if (results)
366  {
367  snprintf(title, sizeof(title), _("Query '%s'"), buf);
368 
369  menu = mutt_menu_new(MENU_QUERY);
371  menu->menu_search = query_search;
372  menu->menu_tag = query_tag;
373  menu->title = title;
374  char helpstr[1024];
375  menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_QUERY, QueryHelp);
377 
378  /* count the number of results */
379  for (queryp = results; queryp; queryp = queryp->next)
380  menu->max++;
381 
382  query_table = mutt_mem_calloc(menu->max, sizeof(struct Entry));
383  menu->data = query_table;
384 
385  queryp = results;
386  for (int i = 0; queryp; queryp = queryp->next, i++)
387  query_table[i].data = queryp;
388 
389  int done = 0;
390  while (done == 0)
391  {
392  const int op = mutt_menu_loop(menu);
393  switch (op)
394  {
395  case OP_QUERY_APPEND:
396  case OP_QUERY:
397  if ((mutt_get_field(_("Query: "), buf, buflen, 0) == 0) && (buf[0] != '\0'))
398  {
399  struct Query *newresults = run_query(buf, 0);
400 
401  menu->redraw = REDRAW_FULL;
402  if (newresults)
403  {
404  snprintf(title, sizeof(title), _("Query '%s'"), buf);
405 
406  if (op == OP_QUERY)
407  {
408  free_query(&results);
409  results = newresults;
410  FREE(&query_table);
411  }
412  else
413  {
414  /* append */
415  for (queryp = results; queryp->next; queryp = queryp->next)
416  ;
417 
418  queryp->next = newresults;
419  }
420 
421  menu->current = 0;
422  mutt_menu_pop_current(menu);
423  mutt_menu_destroy(&menu);
424  menu = mutt_menu_new(MENU_QUERY);
426  menu->menu_search = query_search;
427  menu->menu_tag = query_tag;
428  menu->title = title;
429  menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_QUERY, QueryHelp);
431 
432  /* count the number of results */
433  for (queryp = results; queryp; queryp = queryp->next)
434  menu->max++;
435 
436  if (op == OP_QUERY)
437  {
438  menu->data = query_table =
439  mutt_mem_calloc(menu->max, sizeof(struct Entry));
440 
441  queryp = results;
442  for (int i = 0; queryp; queryp = queryp->next, i++)
443  query_table[i].data = queryp;
444  }
445  else
446  {
447  bool clear = false;
448 
449  /* append */
450  mutt_mem_realloc(&query_table, menu->max * sizeof(struct Entry));
451 
452  menu->data = query_table;
453 
454  queryp = results;
455  for (int i = 0; queryp; queryp = queryp->next, i++)
456  {
457  /* once we hit new entries, clear/init the tag */
458  if (queryp == newresults)
459  clear = true;
460 
461  query_table[i].data = queryp;
462  if (clear)
463  query_table[i].tagged = false;
464  }
465  }
466  }
467  }
468  break;
469 
470  case OP_CREATE_ALIAS:
471  if (menu->tagprefix)
472  {
473  struct AddressList naddr = TAILQ_HEAD_INITIALIZER(naddr);
474 
475  for (int i = 0; i < menu->max; i++)
476  {
477  if (query_table[i].tagged)
478  {
479  struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
480  if (result_to_addr(&al, query_table[i].data))
481  {
482  mutt_addrlist_copy(&naddr, &al, false);
483  mutt_addrlist_clear(&al);
484  }
485  }
486  }
487 
488  mutt_alias_create(NULL, &naddr);
489  mutt_addrlist_clear(&naddr);
490  }
491  else
492  {
493  struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
494  if (result_to_addr(&al, query_table[menu->current].data))
495  {
496  mutt_alias_create(NULL, &al);
497  mutt_addrlist_clear(&al);
498  }
499  }
500  break;
501 
502  case OP_GENERIC_SELECT_ENTRY:
503  if (retbuf)
504  {
505  done = 2;
506  break;
507  }
508  /* fallthrough */
509  case OP_MAIL:
510  {
511  struct Email *e = mutt_email_new();
512  e->env = mutt_env_new();
513  if (!menu->tagprefix)
514  {
515  struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
516  if (result_to_addr(&al, query_table[menu->current].data))
517  {
518  mutt_addrlist_copy(&e->env->to, &al, false);
519  mutt_addrlist_clear(&al);
520  }
521  }
522  else
523  {
524  for (int i = 0; i < menu->max; i++)
525  {
526  if (query_table[i].tagged)
527  {
528  struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
529  if (result_to_addr(&al, query_table[i].data))
530  {
531  mutt_addrlist_copy(&e->env->to, &al, false);
532  mutt_addrlist_clear(&al);
533  }
534  }
535  }
536  }
537  ci_send_message(SEND_NO_FLAGS, e, NULL, Context, NULL);
538  menu->redraw = REDRAW_FULL;
539  break;
540  }
541 
542  case OP_EXIT:
543  done = 1;
544  break;
545  }
546  }
547 
548  /* if we need to return the selected entries */
549  if (retbuf && (done == 2))
550  {
551  bool tagged = false;
552  size_t curpos = 0;
553 
554  memset(buf, 0, buflen);
555 
556  /* check for tagged entries */
557  for (int i = 0; i < menu->max; i++)
558  {
559  if (query_table[i].tagged)
560  {
561  if (curpos == 0)
562  {
563  struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
564  if (result_to_addr(&al, query_table[i].data))
565  {
567  tagged = true;
568  mutt_addrlist_write(buf, buflen, &al, false);
569  curpos = mutt_str_strlen(buf);
570  mutt_addrlist_clear(&al);
571  }
572  }
573  else if (curpos + 2 < buflen)
574  {
575  struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
576  if (result_to_addr(&al, query_table[i].data))
577  {
579  strcat(buf, ", ");
580  mutt_addrlist_write(buf + curpos + 1, buflen - curpos - 1, &al, false);
581  curpos = mutt_str_strlen(buf);
582  mutt_addrlist_clear(&al);
583  }
584  }
585  }
586  }
587  /* then enter current message */
588  if (!tagged)
589  {
590  struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
591  if (result_to_addr(&al, query_table[menu->current].data))
592  {
594  mutt_addrlist_write(buf, buflen, &al, false);
595  mutt_addrlist_clear(&al);
596  }
597  }
598  }
599 
600  free_query(&results);
601  FREE(&query_table);
602  mutt_menu_pop_current(menu);
603  mutt_menu_destroy(&menu);
604  }
605 }
The "current" mailbox.
Definition: context.h:39
#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:50
The envelope/body of an email.
Definition: email.h:37
GUI selectable list of items.
Definition: mutt_menu.h:82
int mutt_addrlist_to_local(struct AddressList *al)
Convert an Address list from Punycode.
Definition: address.c:1268
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1351
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition: address.c:724
#define _(a)
Definition: message.h:28
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:666
int menu
menu definition for keymap entries.
Definition: mutt_menu.h:90
size_t mutt_addrlist_write(char *buf, size_t buflen, const struct AddressList *al, bool display)
Write an Address to a buffer.
Definition: address.c:1134
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
#define SEND_NO_FLAGS
No flags are set.
Definition: send.h:86
Select from results of external query.
Definition: keymap.h:79
struct Envelope * env
Envelope information.
Definition: email.h:89
struct Query * next
Definition: query.c:66
struct Envelope * mutt_env_new(void)
Create a new Envelope.
Definition: envelope.c:41
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
void mutt_alias_create(struct Envelope *cur, struct AddressList *al)
Create a new Alias from an Envelope or an Address.
Definition: alias.c:362
static void free_query(struct Query **query)
Free a Query.
Definition: query.c:128
bool tagprefix
Definition: mutt_menu.h:93
static const struct Mapping QueryHelp[]
Definition: query.c:78
int ci_send_message(SendFlags flags, struct Email *e_templ, const char *tempfile, struct Context *ctx, struct EmailList *el)
Send an email.
Definition: send.c:1830
static struct Query * run_query(char *s, int quiet)
Run an external program to find Addresses.
Definition: query.c:153
An entry from an external address-book.
Definition: query.c:60
static int query_search(struct Menu *menu, regex_t *rx, int line)
Search a Address menu item - Implements Menu::menu_search()
Definition: query.c:232
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:333
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:321
#define FREE(x)
Definition: memory.h:40
void * data
extra data for the current menu
Definition: mutt_menu.h:86
struct AddressList to
Email&#39;s &#39;To&#39; list.
Definition: envelope.h:44
static bool result_to_addr(struct AddressList *al, struct Query *r)
Turn a Query into an AddressList.
Definition: query.c:94
int current
current entry
Definition: mutt_menu.h:87
bool tagged
Definition: query.c:74
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:631
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:72
struct Query * data
Definition: query.c:75
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 613 of file query.c.

614 {
615  if (!C_QueryCommand)
616  {
617  mutt_error(_("Query command not defined"));
618  return 0;
619  }
620 
621  struct Query *results = run_query(buf, 1);
622  if (results)
623  {
624  /* only one response? */
625  if (!results->next)
626  {
627  struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
628  if (result_to_addr(&al, results))
629  {
631  buf[0] = '\0';
632  mutt_addrlist_write(buf, buflen, &al, false);
633  mutt_addrlist_clear(&al);
634  free_query(&results);
636  }
637  return 0;
638  }
639  /* multiple results, choose from query menu */
640  query_menu(buf, buflen, results, true);
641  }
642  return 0;
643 }
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:349
int mutt_addrlist_to_local(struct AddressList *al)
Convert an Address list from Punycode.
Definition: address.c:1268
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1351
#define _(a)
Definition: message.h:28
size_t mutt_addrlist_write(char *buf, size_t buflen, const struct AddressList *al, bool display)
Write an Address to a buffer.
Definition: address.c:1134
struct Query * next
Definition: query.c:66
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:141
static void free_query(struct Query **query)
Free a Query.
Definition: query.c:128
static struct Query * run_query(char *s, int quiet)
Run an external program to find Addresses.
Definition: query.c:153
An entry from an external address-book.
Definition: query.c:60
#define mutt_error(...)
Definition: logging.h:84
static bool result_to_addr(struct AddressList *al, struct Query *r)
Turn a Query into an AddressList.
Definition: query.c:94
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:631
char * C_QueryCommand
Config: External command to query and external address book.
Definition: query.c:54
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 650 of file query.c.

651 {
652  if (!C_QueryCommand)
653  {
654  mutt_error(_("Query command not defined"));
655  return;
656  }
657 
658  if (!buf)
659  {
660  char tmp[256] = { 0 };
661 
662  query_menu(tmp, sizeof(tmp), NULL, false);
663  }
664  else
665  {
666  query_menu(buf, buflen, NULL, true);
667  }
668 }
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:349
#define _(a)
Definition: message.h:28
#define mutt_error(...)
Definition: logging.h:84
char * C_QueryCommand
Config: External command to query and external address book.
Definition: query.c:54

Variable Documentation

char* C_QueryCommand

Config: External command to query and external address book.

Definition at line 54 of file query.c.

char* C_QueryFormat

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

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