NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
dlgpgp.c File Reference

PGP Key Selection Dialog. More...

#include "config.h"
#include <ctype.h>
#include <locale.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "private.h"
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "menu/lib.h"
#include "pager/lib.h"
#include "question/lib.h"
#include "format_flags.h"
#include "mutt_logging.h"
#include "muttlib.h"
#include "opcodes.h"
#include "options.h"
#include "pgp.h"
#include "pgpinvoke.h"
#include "pgpkey.h"
#include "pgplib.h"
+ Include dependency graph for dlgpgp.c:

Go to the source code of this file.

Data Structures

struct  PgpEntry
 An entry in a PGP key menu. More...
 

Functions

static int pgp_compare_key_address (const void *a, const void *b)
 Compare Key addresses and IDs for sorting. More...
 
static int pgp_compare_address_qsort (const void *a, const void *b)
 Compare the addresses of two PGP keys. More...
 
static int pgp_compare_key_date (const void *a, const void *b)
 Compare Key dates for sorting. More...
 
static int pgp_compare_date_qsort (const void *a, const void *b)
 Compare the dates of two PGP keys. More...
 
static int pgp_compare_keyid (const void *a, const void *b)
 Compare Key IDs and addresses for sorting. More...
 
static int pgp_compare_keyid_qsort (const void *a, const void *b)
 Compare key IDs. More...
 
static int pgp_compare_key_trust (const void *a, const void *b)
 Compare the trust of keys for sorting. More...
 
static int pgp_compare_trust_qsort (const void *a, const void *b)
 Compare the trust levels of two PGP keys. More...
 
static char * pgp_key_abilities (KeyFlags flags)
 Turn PGP key abilities into a string. More...
 
static char pgp_flags (KeyFlags flags)
 Turn PGP key flags into a string. More...
 
static const char * pgp_entry_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, intptr_t data, MuttFormatFlags flags)
 Format an entry on the PGP key selection menu - Implements format_t -
Expando Description
%n Number
%t Trust/validity of the key-uid association
%u User id
%[fmt] Date of key using strftime(3)

| | | %a | Algorithm | %c | Capabilities | %f | Flags | %k | Key id | %l | Length | | | %A | Algorithm of the principal key | %C | Capabilities of the principal key | %F | Flags of the principal key | %K | Key id of the principal key | %L | Length of the principal key. More...

 
static void pgp_make_entry (struct Menu *menu, char *buf, size_t buflen, int line)
 Format a menu item for the pgp key list - Implements Menu::make_entry() -. More...
 
static void pgp_key_table_free (struct Menu *menu, void **ptr)
 Free the key table - Implements Menu::mdata_free() -. More...
 
static int pgp_key_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t. More...
 
static int pgp_key_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t. More...
 
struct PgpKeyInfodlg_select_pgp_key (struct PgpKeyInfo *keys, struct Address *p, const char *s)
 Let the user select a key to use. More...
 

Variables

static const struct Mapping PgpHelp []
 Help Bar for the PGP key selection dialog. More...
 
static const char trust_flags [] = "?- +"
 

Detailed Description

PGP Key Selection Dialog.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file dlgpgp.c.

Function Documentation

◆ pgp_compare_key_address()

static int pgp_compare_key_address ( const void *  a,
const void *  b 
)
static

Compare Key addresses and IDs for sorting.

Parameters
aFirst key
bSecond key
Return values
-1a precedes b
0a and b are identical
1b precedes a

Definition at line 127 of file dlgpgp.c.

128 {
129  struct PgpUid const *const *s = (struct PgpUid const *const *) a;
130  struct PgpUid const *const *t = (struct PgpUid const *const *) b;
131 
132  int r = mutt_istr_cmp((*s)->addr, (*t)->addr);
133  if (r != 0)
134  return (r > 0);
135 
136  return mutt_istr_cmp(pgp_fpr_or_lkeyid((*s)->parent), pgp_fpr_or_lkeyid((*t)->parent)) > 0;
137 }
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:580
PGP User ID.
Definition: pgplib.h:34
char * pgp_fpr_or_lkeyid(struct PgpKeyInfo *k)
Get the fingerprint or long keyid.
Definition: pgp.c:227
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_compare_address_qsort()

static int pgp_compare_address_qsort ( const void *  a,
const void *  b 
)
static

Compare the addresses of two PGP keys.

Parameters
aFirst address
bSecond address
Return values
-1a precedes b
0a and b are identical
1b precedes a

Definition at line 147 of file dlgpgp.c.

148 {
149  const short c_pgp_sort_keys = cs_subset_sort(NeoMutt->sub, "pgp_sort_keys");
150  return (c_pgp_sort_keys & SORT_REVERSE) ? !pgp_compare_key_address(a, b) :
152 }
Container for Accounts, Notifications.
Definition: neomutt.h:36
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:292
static int pgp_compare_key_address(const void *a, const void *b)
Compare Key addresses and IDs for sorting.
Definition: dlgpgp.c:127
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:79
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_compare_key_date()

static int pgp_compare_key_date ( const void *  a,
const void *  b 
)
static

Compare Key dates for sorting.

Parameters
aFirst key ID
bSecond key ID
Return values
-1a precedes b
0a and b are identical
1b precedes a

Definition at line 162 of file dlgpgp.c.

163 {
164  struct PgpUid const *const *s = (struct PgpUid const *const *) a;
165  struct PgpUid const *const *t = (struct PgpUid const *const *) b;
166 
167  int r = ((*s)->parent->gen_time - (*t)->parent->gen_time);
168  if (r != 0)
169  return r > 0;
170  return mutt_istr_cmp((*s)->addr, (*t)->addr) > 0;
171 }
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:580
PGP User ID.
Definition: pgplib.h:34
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_compare_date_qsort()

static int pgp_compare_date_qsort ( const void *  a,
const void *  b 
)
static

Compare the dates of two PGP keys.

Parameters
aFirst key
bSecond key
Return values
-1a precedes b
0a and b are identical
1b precedes a

Definition at line 181 of file dlgpgp.c.

182 {
183  const short c_pgp_sort_keys = cs_subset_sort(NeoMutt->sub, "pgp_sort_keys");
184  return (c_pgp_sort_keys & SORT_REVERSE) ? !pgp_compare_key_date(a, b) :
185  pgp_compare_key_date(a, b);
186 }
Container for Accounts, Notifications.
Definition: neomutt.h:36
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:292
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
static int pgp_compare_key_date(const void *a, const void *b)
Compare Key dates for sorting.
Definition: dlgpgp.c:162
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:79
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_compare_keyid()

static int pgp_compare_keyid ( const void *  a,
const void *  b 
)
static

Compare Key IDs and addresses for sorting.

Parameters
aFirst key ID
bSecond key ID
Return values
-1a precedes b
0a and b are identical
1b precedes a

Definition at line 196 of file dlgpgp.c.

197 {
198  struct PgpUid const *const *s = (struct PgpUid const *const *) a;
199  struct PgpUid const *const *t = (struct PgpUid const *const *) b;
200 
201  int r = mutt_istr_cmp(pgp_fpr_or_lkeyid((*s)->parent), pgp_fpr_or_lkeyid((*t)->parent));
202  if (r != 0)
203  return (r > 0);
204  return mutt_istr_cmp((*s)->addr, (*t)->addr) > 0;
205 }
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:580
PGP User ID.
Definition: pgplib.h:34
char * pgp_fpr_or_lkeyid(struct PgpKeyInfo *k)
Get the fingerprint or long keyid.
Definition: pgp.c:227
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_compare_keyid_qsort()

static int pgp_compare_keyid_qsort ( const void *  a,
const void *  b 
)
static

Compare key IDs.

Parameters
aFirst key ID
bSecond key ID
Return values
-1a precedes b
0a and b are identical
1b precedes a

Definition at line 215 of file dlgpgp.c.

216 {
217  const short c_pgp_sort_keys = cs_subset_sort(NeoMutt->sub, "pgp_sort_keys");
218  return (c_pgp_sort_keys & SORT_REVERSE) ? !pgp_compare_keyid(a, b) :
219  pgp_compare_keyid(a, b);
220 }
Container for Accounts, Notifications.
Definition: neomutt.h:36
static int pgp_compare_keyid(const void *a, const void *b)
Compare Key IDs and addresses for sorting.
Definition: dlgpgp.c:196
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:292
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:79
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_compare_key_trust()

static int pgp_compare_key_trust ( const void *  a,
const void *  b 
)
static

Compare the trust of keys for sorting.

Parameters
aFirst key
bSecond key
Return values
-1a precedes b
0a and b are identical
1b precedes a

Compare two trust values, the key length, the creation dates. the addresses and the key IDs.

Definition at line 233 of file dlgpgp.c.

234 {
235  struct PgpUid const *const *s = (struct PgpUid const *const *) a;
236  struct PgpUid const *const *t = (struct PgpUid const *const *) b;
237 
238  int r = (((*s)->parent->flags & KEYFLAG_RESTRICTIONS) -
239  ((*t)->parent->flags & KEYFLAG_RESTRICTIONS));
240  if (r != 0)
241  return r > 0;
242  r = ((*s)->trust - (*t)->trust);
243  if (r != 0)
244  return r < 0;
245  r = ((*s)->parent->keylen - (*t)->parent->keylen);
246  if (r != 0)
247  return r < 0;
248  r = ((*s)->parent->gen_time - (*t)->parent->gen_time);
249  if (r != 0)
250  return r < 0;
251  r = mutt_istr_cmp((*s)->addr, (*t)->addr);
252  if (r != 0)
253  return r > 0;
254  return mutt_istr_cmp(pgp_fpr_or_lkeyid((*s)->parent), pgp_fpr_or_lkeyid((*t)->parent)) > 0;
255 }
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:580
PGP User ID.
Definition: pgplib.h:34
#define KEYFLAG_RESTRICTIONS
Definition: lib.h:137
char * pgp_fpr_or_lkeyid(struct PgpKeyInfo *k)
Get the fingerprint or long keyid.
Definition: pgp.c:227
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_compare_trust_qsort()

static int pgp_compare_trust_qsort ( const void *  a,
const void *  b 
)
static

Compare the trust levels of two PGP keys.

Parameters
aFirst key
bSecond key
Return values
-1a precedes b
0a and b are identical
1b precedes a

Definition at line 265 of file dlgpgp.c.

266 {
267  const short c_pgp_sort_keys = cs_subset_sort(NeoMutt->sub, "pgp_sort_keys");
268  return (c_pgp_sort_keys & SORT_REVERSE) ? !pgp_compare_key_trust(a, b) :
269  pgp_compare_key_trust(a, b);
270 }
Container for Accounts, Notifications.
Definition: neomutt.h:36
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:292
static int pgp_compare_key_trust(const void *a, const void *b)
Compare the trust of keys for sorting.
Definition: dlgpgp.c:233
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:79
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_key_abilities()

static char* pgp_key_abilities ( KeyFlags  flags)
static

Turn PGP key abilities into a string.

Parameters
flagsFlags, see KeyFlags
Return values
ptrAbilities string
Note
This returns a pointer to a static buffer

Definition at line 279 of file dlgpgp.c.

280 {
281  static char buf[3];
282 
283  if (!(flags & KEYFLAG_CANENCRYPT))
284  buf[0] = '-';
285  else if (flags & KEYFLAG_PREFER_SIGNING)
286  buf[0] = '.';
287  else
288  buf[0] = 'e';
289 
290  if (!(flags & KEYFLAG_CANSIGN))
291  buf[1] = '-';
292  else if (flags & KEYFLAG_PREFER_ENCRYPTION)
293  buf[1] = '.';
294  else
295  buf[1] = 's';
296 
297  buf[2] = '\0';
298 
299  return buf;
300 }
#define KEYFLAG_PREFER_ENCRYPTION
Key&#39;s owner prefers encryption.
Definition: lib.h:133
#define KEYFLAG_CANENCRYPT
Key is suitable for encryption.
Definition: lib.h:125
#define KEYFLAG_PREFER_SIGNING
Key&#39;s owner prefers signing.
Definition: lib.h:134
#define KEYFLAG_CANSIGN
Key is suitable for signing.
Definition: lib.h:124
int flags
Definition: pgplib.h:38
+ Here is the caller graph for this function:

◆ pgp_flags()

static char pgp_flags ( KeyFlags  flags)
static

Turn PGP key flags into a string.

Parameters
flagsFlags, see KeyFlags
Return values
charFlag character

Definition at line 307 of file dlgpgp.c.

308 {
309  if (flags & KEYFLAG_REVOKED)
310  return 'R';
311  if (flags & KEYFLAG_EXPIRED)
312  return 'X';
313  if (flags & KEYFLAG_DISABLED)
314  return 'd';
315  if (flags & KEYFLAG_CRITICAL)
316  return 'c';
317 
318  return ' ';
319 }
#define KEYFLAG_EXPIRED
Key is expired.
Definition: lib.h:128
#define KEYFLAG_DISABLED
Key is marked disabled.
Definition: lib.h:130
#define KEYFLAG_CRITICAL
Key is marked critical.
Definition: lib.h:132
#define KEYFLAG_REVOKED
Key is revoked.
Definition: lib.h:129
int flags
Definition: pgplib.h:38
+ Here is the caller graph for this function:

◆ pgp_key_config_observer()

static int pgp_key_config_observer ( struct NotifyCallback nc)
static

Notification that a Config Variable has changed - Implements observer_t.

Definition at line 530 of file dlgpgp.c.

531 {
532  if ((nc->event_type != NT_CONFIG) || !nc->global_data || !nc->event_data)
533  return -1;
534 
535  struct EventConfig *ev_c = nc->event_data;
536 
537  if (!mutt_str_equal(ev_c->name, "pgp_entry_format") &&
538  !mutt_str_equal(ev_c->name, "pgp_sort_keys"))
539  {
540  return 0;
541  }
542 
543  struct Menu *menu = nc->global_data;
545  mutt_debug(LL_DEBUG5, "config done, request WA_RECALC, MENU_REDRAW_FULL\n");
546 
547  return 0;
548 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
Definition: lib.h:67
A config-change event.
Definition: subset.h:69
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
Log at debug level 5.
Definition: logging.h:44
const char * name
Name of config item that changed.
Definition: subset.h:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_key_window_observer()

static int pgp_key_window_observer ( struct NotifyCallback nc)
static

Notification that a Window has changed - Implements observer_t.

This function is triggered by changes to the windows.

  • Delete (this window): clean up the resources held by the Help Bar

Definition at line 557 of file dlgpgp.c.

558 {
559  if ((nc->event_type != NT_WINDOW) || !nc->global_data || !nc->event_data)
560  return -1;
561 
562  if (nc->event_subtype != NT_WINDOW_DELETE)
563  return 0;
564 
565  struct MuttWindow *win_menu = nc->global_data;
566  struct EventWindow *ev_w = nc->event_data;
567  if (ev_w->win != win_menu)
568  return 0;
569 
570  struct Menu *menu = win_menu->wdata;
571 
574 
575  mutt_debug(LL_DEBUG5, "window delete done\n");
576  return 0;
577 }
Definition: lib.h:67
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
An Event that happened to a Window.
Definition: mutt_window.h:215
Window is about to be deleted.
Definition: mutt_window.h:206
Container for Accounts, Notifications.
Definition: neomutt.h:36
static int pgp_key_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: dlgpgp.c:557
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:43
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
static int pgp_key_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t.
Definition: dlgpgp.c:530
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:228
Log at debug level 5.
Definition: logging.h:44
void * wdata
Private data.
Definition: mutt_window.h:145
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dlg_select_pgp_key()

struct PgpKeyInfo* dlg_select_pgp_key ( struct PgpKeyInfo keys,
struct Address p,
const char *  s 
)

Let the user select a key to use.

Parameters
keysList of PGP keys
pAddress to match
sString to match
Return values
ptrSelected PGP key

Definition at line 586 of file dlgpgp.c.

588 {
589  struct PgpUid **key_table = NULL;
590  struct Menu *menu = NULL;
591  int i;
592  bool done = false;
593  char buf[1024], tmpbuf[256];
594  struct PgpKeyInfo *kp = NULL;
595  struct PgpUid *a = NULL;
596  struct Buffer *tempfile = NULL;
597 
598  bool unusable = false;
599 
600  int keymax = 0;
601 
602  const bool c_pgp_show_unusable =
603  cs_subset_bool(NeoMutt->sub, "pgp_show_unusable");
604  for (i = 0, kp = keys; kp; kp = kp->next)
605  {
606  if (!c_pgp_show_unusable && (kp->flags & KEYFLAG_CANTUSE))
607  {
608  unusable = true;
609  continue;
610  }
611 
612  for (a = kp->address; a; a = a->next)
613  {
614  if (!c_pgp_show_unusable && (a->flags & KEYFLAG_CANTUSE))
615  {
616  unusable = true;
617  continue;
618  }
619 
620  if (i == keymax)
621  {
622  keymax += 5;
623  mutt_mem_realloc(&key_table, sizeof(struct PgpUid *) * keymax);
624  }
625 
626  key_table[i++] = a;
627  }
628  }
629 
630  if ((i == 0) && unusable)
631  {
632  mutt_error(_("All matching keys are expired, revoked, or disabled"));
633  return NULL;
634  }
635 
636  int (*f)(const void *, const void *);
637  const short c_pgp_sort_keys = cs_subset_sort(NeoMutt->sub, "pgp_sort_keys");
638  switch (c_pgp_sort_keys & SORT_MASK)
639  {
640  case SORT_ADDRESS:
642  break;
643  case SORT_DATE:
645  break;
646  case SORT_KEYID:
648  break;
649  case SORT_TRUST:
650  default:
652  break;
653  }
654  qsort(key_table, i, sizeof(struct PgpUid *), f);
655 
657 
658  menu = dlg->wdata;
659  menu->max = i;
660  menu->make_entry = pgp_make_entry;
661  menu->mdata = key_table;
663 
664  struct MuttWindow *win_menu = menu->win;
665 
666  // NT_COLOR is handled by the SimpleDialog
669 
670  if (p)
671  snprintf(buf, sizeof(buf), _("PGP keys matching <%s>"), p->mailbox);
672  else
673  snprintf(buf, sizeof(buf), _("PGP keys matching \"%s\""), s);
674 
675  struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
676  sbar_set_title(sbar, buf);
677 
678  kp = NULL;
679 
681 
682  while (!done)
683  {
684  switch (menu_loop(menu))
685  {
686  case OP_VERIFY_KEY:
687  {
688  FILE *fp_null = fopen("/dev/null", "w");
689  if (!fp_null)
690  {
691  mutt_perror(_("Can't open /dev/null"));
692  break;
693  }
694  tempfile = mutt_buffer_pool_get();
695  mutt_buffer_mktemp(tempfile);
696  FILE *fp_tmp = mutt_file_fopen(mutt_buffer_string(tempfile), "w");
697  if (!fp_tmp)
698  {
699  mutt_perror(_("Can't create temporary file"));
700  mutt_file_fclose(&fp_null);
701  mutt_buffer_pool_release(&tempfile);
702  break;
703  }
704 
705  mutt_message(_("Invoking PGP..."));
706 
707  const int index = menu_get_index(menu);
708  struct PgpUid *cur_key = key_table[index];
709  snprintf(tmpbuf, sizeof(tmpbuf), "0x%s",
711 
712  pid_t pid = pgp_invoke_verify_key(NULL, NULL, NULL, -1, fileno(fp_tmp),
713  fileno(fp_null), tmpbuf);
714  if (pid == -1)
715  {
716  mutt_perror(_("Can't create filter"));
717  unlink(mutt_buffer_string(tempfile));
718  mutt_file_fclose(&fp_tmp);
719  mutt_file_fclose(&fp_null);
720  }
721 
722  filter_wait(pid);
723  mutt_file_fclose(&fp_tmp);
724  mutt_file_fclose(&fp_null);
726  char title[1024];
727  snprintf(title, sizeof(title), _("Key ID: 0x%s"),
728  pgp_keyid(pgp_principal_key(cur_key->parent)));
729 
730  struct PagerData pdata = { 0 };
731  struct PagerView pview = { &pdata };
732 
733  pdata.fname = mutt_buffer_string(tempfile);
734 
735  pview.banner = title;
736  pview.flags = MUTT_PAGER_NO_FLAGS;
737  pview.mode = PAGER_MODE_OTHER;
738 
739  mutt_do_pager(&pview, NULL);
740  mutt_buffer_pool_release(&tempfile);
742  break;
743  }
744 
745  case OP_VIEW_ID:
746  {
747  const int index = menu_get_index(menu);
748  struct PgpUid *cur_key = key_table[index];
749  mutt_message("%s", NONULL(cur_key->addr));
750  break;
751  }
752 
753  case OP_GENERIC_SELECT_ENTRY:
754  {
755  /* XXX make error reporting more verbose */
756 
757  const int index = menu_get_index(menu);
758  struct PgpUid *cur_key = key_table[index];
759  if (OptPgpCheckTrust)
760  {
761  if (!pgp_key_is_valid(cur_key->parent))
762  {
763  mutt_error(_("This key can't be used: expired/disabled/revoked"));
764  break;
765  }
766  }
767 
768  if (OptPgpCheckTrust && (!pgp_id_is_valid(cur_key) || !pgp_id_is_strong(cur_key)))
769  {
770  const char *str = "";
771  char buf2[1024];
772 
773  if (cur_key->flags & KEYFLAG_CANTUSE)
774  {
775  str = _("ID is expired/disabled/revoked. Do you really want to use "
776  "the key?");
777  }
778  else
779  {
780  switch (cur_key->trust & 0x03)
781  {
782  case 0:
783  str = _("ID has undefined validity. Do you really want to use "
784  "the key?");
785  break;
786  case 1:
787  str = _("ID is not valid. Do you really want to use the key?");
788  break;
789  case 2:
790  str = _("ID is only marginally valid. Do you really want to "
791  "use the key?");
792  break;
793  }
794  }
795 
796  snprintf(buf2, sizeof(buf2), "%s", str);
797 
798  if (mutt_yesorno(buf2, MUTT_NO) != MUTT_YES)
799  {
801  break;
802  }
803  }
804 
805  kp = cur_key->parent;
806  done = true;
807  break;
808  }
809 
810  case OP_EXIT:
811 
812  kp = NULL;
813  done = true;
814  break;
815  }
816  }
817 
818  simple_dialog_free(&dlg);
819  return kp;
820 }
struct PgpKeyInfo * next
Definition: pgplib.h:57
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:550
#define mutt_buffer_mktemp(buf)
Definition: muttlib.h:74
#define NONULL(x)
Definition: string2.h:37
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:165
Definition: lib.h:67
struct PgpUid * next
Definition: pgplib.h:40
PGP encryption menu.
Definition: type.h:55
#define mutt_error(...)
Definition: logging.h:88
char * pgp_keyid(struct PgpKeyInfo *k)
Get the ID of the main (parent) key.
Definition: pgp.c:197
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
Pgp Dialog, dlg_select_pgp_key()
Definition: mutt_window.h:88
String manipulation buffer.
Definition: buffer.h:33
static int pgp_compare_address_qsort(const void *a, const void *b)
Compare the addresses of two PGP keys.
Definition: dlgpgp.c:147
Paged view into some data.
Definition: lib.h:154
#define _(a)
Definition: message.h:28
Sort by email address.
Definition: sort2.h:54
PGP User ID.
Definition: pgplib.h:34
char * mailbox
Mailbox and host address.
Definition: address.h:38
KeyFlags flags
Definition: pgplib.h:51
bool pgp_key_is_valid(struct PgpKeyInfo *k)
Is a PGP key valid?
Definition: pgpkey.c:101
static int pgp_compare_date_qsort(const void *a, const void *b)
Compare the dates of two PGP keys.
Definition: dlgpgp.c:181
#define mutt_perror(...)
Definition: logging.h:89
Container for Accounts, Notifications.
Definition: neomutt.h:36
static int pgp_key_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: dlgpgp.c:557
struct PgpKeyInfo * pgp_principal_key(struct PgpKeyInfo *key)
Get the main (parent) PGP key.
Definition: pgpkey.c:89
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
char * addr
Definition: pgplib.h:36
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:105
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
Information about a PGP key.
Definition: pgplib.h:46
Data to be displayed by PagerView.
Definition: lib.h:143
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
static void pgp_key_table_free(struct Menu *menu, void **ptr)
Free the key table - Implements Menu::mdata_free() -.
Definition: dlgpgp.c:522
short trust
Definition: pgplib.h:37
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:112
static int pgp_compare_trust_qsort(const void *a, const void *b)
Compare the trust levels of two PGP keys.
Definition: dlgpgp.c:265
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:189
#define KEYFLAG_CANTUSE
Definition: lib.h:136
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
enum PagerMode mode
Pager mode.
Definition: lib.h:157
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:292
Sort by encryption key&#39;s trust level.
Definition: sort2.h:56
void * mdata
Private data.
Definition: lib.h:155
int mutt_do_pager(struct PagerView *pview, struct Email *e)
Display some page-able text to the user (help or attachment)
Definition: do_pager.c:120
struct PgpUid * address
Definition: pgplib.h:50
pid_t pgp_invoke_verify_key(FILE **fp_pgp_in, FILE **fp_pgp_out, FILE **fp_pgp_err, int fd_pgp_in, int fd_pgp_out, int fd_pgp_err, const char *uids)
Use PGP to verify a key.
Definition: pgpinvoke.c:531
WHERE bool OptPgpCheckTrust
(pseudo) used by dlg_select_pgp_key()
Definition: options.h:48
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:221
struct PgpKeyInfo * parent
Definition: pgplib.h:39
PagerFlags flags
Additional settings to tweak pager&#39;s function.
Definition: lib.h:158
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
Definition: question.c:180
int max
Number of entries in the menu.
Definition: lib.h:71
char * pgp_fpr_or_lkeyid(struct PgpKeyInfo *k)
Get the fingerprint or long keyid.
Definition: pgp.c:227
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:170
static const struct Mapping PgpHelp[]
Help Bar for the PGP key selection dialog.
Definition: dlgpgp.c:98
bool pgp_id_is_valid(struct PgpUid *uid)
Is a PGP key valid.
Definition: pgpkey.c:130
static int pgp_key_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t.
Definition: dlgpgp.c:530
#define mutt_message(...)
Definition: logging.h:87
static int pgp_compare_keyid_qsort(const void *a, const void *b)
Compare key IDs.
Definition: dlgpgp.c:215
static void pgp_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
Format a menu item for the pgp key list - Implements Menu::make_entry() -.
Definition: dlgpgp.c:502
User answered &#39;No&#39;, or assume &#39;No&#39;.
Definition: quad.h:38
bool pgp_id_is_strong(struct PgpUid *uid)
Is a PGP key strong?
Definition: pgpkey.c:117
Sort by the encryption key&#39;s ID.
Definition: sort2.h:55
struct MuttWindow * simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:128
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
const char * fname
Name of the file to read.
Definition: lib.h:148
Sort by the date the email was sent.
Definition: sort2.h:43
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:589
#define MUTT_PAGER_NO_FLAGS
No flags are set.
Definition: lib.h:54
const char * banner
Title to display in status bar.
Definition: lib.h:159
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:217
Pager is invoked via 3rd path. Non-email content is likely to be shown.
Definition: lib.h:135
void * wdata
Private data.
Definition: mutt_window.h:145
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:78
int flags
Definition: pgplib.h:38
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ PgpHelp

const struct Mapping PgpHelp[]
static
Initial value:
= {
{ N_("Exit"), OP_EXIT },
{ N_("Select"), OP_GENERIC_SELECT_ENTRY },
{ N_("Check key"), OP_VERIFY_KEY },
{ N_("Help"), OP_HELP },
{ NULL, 0 },
}
#define N_(a)
Definition: message.h:32

Help Bar for the PGP key selection dialog.

Definition at line 98 of file dlgpgp.c.

◆ trust_flags

const char trust_flags[] = "?- +"
static

Definition at line 117 of file dlgpgp.c.