NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_pgp.c
Go to the documentation of this file.
1
24
69
70#include "config.h"
71#include <stdbool.h>
72#include <stdio.h>
73#include "private.h"
74#include "mutt/lib.h"
75#include "address/lib.h"
76#include "config/lib.h"
77#include "core/lib.h"
78#include "gui/lib.h"
79#include "lib.h"
80#include "expando/lib.h"
81#include "key/lib.h"
82#include "menu/lib.h"
83#include "expando_pgp.h"
84#include "module_data.h"
85#include "mutt_logging.h"
86#include "pgp_functions.h"
87#include "pgplib.h"
88#include "sort.h"
89
91static const struct Mapping PgpHelp[] = {
92 // clang-format off
93 { N_("Exit"), OP_EXIT },
94 { N_("Select"), OP_GENERIC_SELECT_ENTRY },
95 { N_("Check key"), OP_VERIFY_KEY },
96 { N_("Help"), OP_HELP },
97 { NULL, 0 },
98 // clang-format on
99};
100
106static int pgp_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
107{
108 struct PgpData *pd = menu->mdata;
109 struct PgpUid **puid = ARRAY_GET(pd->key_table, line);
110 if (!*puid)
111 return 0;
112
113 struct PgpEntry entry = { line + 1, *puid };
114
115 const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
116 if (c_arrow_cursor)
117 {
118 const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
119 if (max_cols > 0)
120 max_cols -= (mutt_strwidth(c_arrow_string) + 1);
121 }
122
123 const struct Expando *c_pgp_entry_format = cs_subset_expando(NeoMutt->sub, "pgp_entry_format");
124 return expando_filter(c_pgp_entry_format, PgpEntryRenderCallbacks, &entry,
125 MUTT_FORMAT_ARROWCURSOR, max_cols, NeoMutt->env, buf);
126}
127
132{
133 if (nc->event_type != NT_CONFIG)
134 return 0;
135 if (!nc->global_data || !nc->event_data)
136 return -1;
137
138 struct EventConfig *ev_c = nc->event_data;
139
140 if (!mutt_str_equal(ev_c->name, "pgp_entry_format") &&
141 !mutt_str_equal(ev_c->name, "pgp_key_sort"))
142 {
143 return 0;
144 }
145
146 struct Menu *menu = nc->global_data;
148 mutt_debug(LL_DEBUG5, "config done, request WA_RECALC, MENU_REDRAW_FULL\n");
149
150 return 0;
151}
152
161{
162 if (nc->event_type != NT_WINDOW)
163 return 0;
164 if (!nc->global_data || !nc->event_data)
165 return -1;
167 return 0;
168
169 struct MuttWindow *win_menu = nc->global_data;
170 struct EventWindow *ev_w = nc->event_data;
171 if (ev_w->win != win_menu)
172 return 0;
173
174 struct Menu *menu = win_menu->wdata;
175
178
179 mutt_debug(LL_DEBUG5, "window delete done\n");
180 return 0;
181}
182
192struct PgpKeyInfo *dlg_pgp(struct PgpKeyInfo *keys, struct Address *p, const char *s)
193{
194 struct Menu *menu = NULL;
195 char buf[1024] = { 0 };
196 bool unusable = false;
197 struct PgpUidArray pua = ARRAY_HEAD_INITIALIZER;
198
199 const bool c_pgp_show_unusable = cs_subset_bool(NeoMutt->sub, "pgp_show_unusable");
200 for (struct PgpKeyInfo *kp = keys; kp; kp = kp->next)
201 {
202 if (!c_pgp_show_unusable && (kp->flags & KEYFLAG_CANTUSE))
203 {
204 unusable = true;
205 continue;
206 }
207
208 for (struct PgpUid *a = kp->address; a; a = a->next)
209 {
210 if (!c_pgp_show_unusable && (a->flags & KEYFLAG_CANTUSE))
211 {
212 unusable = true;
213 continue;
214 }
215
216 ARRAY_ADD(&pua, a);
217 }
218 }
219
220 if ((ARRAY_SIZE(&pua) == 0) && unusable)
221 {
222 mutt_error(_("All matching keys are expired, revoked, or disabled"));
223 return NULL;
224 }
225
226 pgp_sort_keys(&pua);
227
229 ASSERT(mod_data);
230
232 menu = sdw.menu;
233 struct PgpData pd = { false, menu, &pua, NULL };
234
235 menu->max = ARRAY_SIZE(&pua);
237 menu->mdata = &pd;
238 menu->mdata_free = NULL; // Menu doesn't own the data
239
240 // NT_COLOR is handled by the SimpleDialog
243
244 if (p)
245 snprintf(buf, sizeof(buf), _("PGP keys matching <%s>"), buf_string(p->mailbox));
246 else
247 snprintf(buf, sizeof(buf), _("PGP keys matching \"%s\""), s);
248
249 sbar_set_title(sdw.sbar, buf);
250
252
253 struct MuttWindow *old_focus = window_set_focus(menu->win);
254 // ---------------------------------------------------------------------------
255 // Event Loop
256 int op = OP_NULL;
257 struct KeyEvent event = { 0, OP_NULL };
258 do
259 {
260 menu_tagging_dispatcher(menu->win, &event);
261 window_redraw(NULL);
262
263 event = km_dokey(mod_data->menu_pgp, GETCH_NONE);
264 op = event.op;
265 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
266 if (op < 0)
267 continue;
268 if (op == OP_NULL)
269 {
270 km_error_key(mod_data->menu_pgp);
271 continue;
272 }
274
275 int rc = pgp_function_dispatcher(sdw.dlg, &event);
276
277 if (rc == FR_UNKNOWN)
278 rc = menu_function_dispatcher(menu->win, &event);
279 if (rc == FR_UNKNOWN)
280 rc = global_function_dispatcher(menu->win, &event);
281 } while (!pd.done);
282 // ---------------------------------------------------------------------------
283
284 ARRAY_FREE(&pua);
285 window_set_focus(old_focus);
287 return pd.key;
288}
Email Address Handling.
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
#define ARRAY_GET(head, idx)
Return the element at index.
Definition array.h:109
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition array.h:58
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition helpers.c:291
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando config item by name.
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
Definition curs_lib.c:446
@ FR_UNKNOWN
Unknown function.
Definition dispatcher.h:34
static const struct Mapping PgpHelp[]
Help Bar for the PGP key selection dialog.
Definition dlg_pgp.c:91
int expando_filter(const struct Expando *exp, const struct ExpandoRenderCallback *erc, void *data, MuttFormatFlags flags, int max_cols, char **env_list, struct Buffer *buf)
Render an Expando and run the result through a filter.
Definition filter.c:139
Parse Expando string.
const struct ExpandoRenderCallback PgpEntryRenderCallbacks[]
PgpEntryRenderCallbacks- Callbacks for PGP Key Expandos.
Ncrypt PGP Expando definitions.
struct KeyEvent km_dokey(const struct MenuDefinition *md, GetChFlags flags)
Determine what a keypress should do.
Definition get.c:518
void km_error_key(const struct MenuDefinition *md)
Handle an unbound key sequence.
Definition get.c:328
@ GETCH_NONE
No flags are set.
Definition get.h:38
int menu_tagging_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition tagging.c:239
int pgp_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Pgp function - Implements function_dispatcher_t -.
int global_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Global function - Implements function_dispatcher_t -.
Definition global.c:182
int menu_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Menu function - Implements function_dispatcher_t -.
Definition functions.c:366
struct PgpKeyInfo * dlg_pgp(struct PgpKeyInfo *keys, struct Address *p, const char *s)
Let the user select a key to use -.
Definition dlg_pgp.c:192
#define mutt_error(...)
Definition logging2.h:94
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
static int pgp_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Format a PGP Key for the Menu - Implements Menu::make_entry() -.
Definition dlg_pgp.c:106
static int pgp_key_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition dlg_pgp.c:160
static int pgp_key_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition dlg_pgp.c:131
Convenience wrapper for the gui headers.
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition simple.c:169
struct SimpleDialogWindows simple_dialog_new(const struct MenuDefinition *md, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition simple.c:132
Manage keymappings.
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
GUI present the user with a selectable list.
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition menu.c:179
@ MENU_REDRAW_FULL
Redraw everything.
Definition lib.h:64
@ MODULE_ID_NCRYPT
ModuleNcrypt, Ncrypt
Definition module_api.h:80
Convenience wrapper for the library headers.
#define N_(a)
Definition message.h:32
#define _(a)
Definition message.h:28
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition notify.c:230
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:191
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
NeoMutt Logging.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
struct MuttWindow * window_set_focus(struct MuttWindow *win)
Set the Window focus.
@ WT_DLG_PGP
Pgp Dialog, dlg_pgp()
Definition mutt_window.h:89
@ NT_WINDOW_DELETE
Window is about to be deleted.
API for encryption/signing of emails.
#define KEYFLAG_CANTUSE
Definition lib.h:161
Ncrypt private Module data.
Shared constants/structs that are private to libconn.
Crypto Key sorting functions.
void pgp_sort_keys(struct PgpUidArray *pua)
Sort an array of PGP keys.
Definition sort_pgp.c:142
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition notify_type.h:58
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition notify_type.h:43
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition opcodes.c:48
Pgp functions.
Misc PGP helper routines.
@ MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition render.h:41
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition sbar.c:227
#define ASSERT(COND)
Definition signal2.h:59
An email address.
Definition address.h:35
struct Buffer * mailbox
Mailbox and host address.
Definition address.h:37
String manipulation buffer.
Definition buffer.h:36
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition subset.h:51
A config-change event.
Definition subset.h:70
const char * name
Name of config item that changed.
Definition subset.h:72
An Event that happened to a Window.
struct MuttWindow * win
Window that changed.
Parsed Expando trees.
Definition expando.h:41
An event such as a keypress.
Definition get.h:75
int op
Function opcode, e.g. OP_HELP.
Definition get.h:77
Mapping between user-readable string and a constant.
Definition mapping.h:33
Definition lib.h:86
struct MuttWindow * win
Window holding the Menu.
Definition lib.h:94
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition lib.h:169
int(* make_entry)(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Definition lib.h:114
struct ConfigSubset * sub
Inherited config items.
Definition lib.h:95
void * mdata
Private data.
Definition lib.h:155
int max
Number of entries in the menu.
Definition lib.h:88
void * wdata
Private data.
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Ncrypt private Module data.
Definition module_data.h:38
struct MenuDefinition * menu_pgp
PGP menu definition.
Definition module_data.h:40
Container for Accounts, Notifications.
Definition neomutt.h:41
char ** env
Private copy of the environment variables.
Definition neomutt.h:57
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
Data passed to a notification function.
Definition observer.h:34
void * event_data
Data from notify_send()
Definition observer.h:38
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition observer.h:36
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition observer.h:37
void * global_data
Data from notify_observer_add()
Definition observer.h:39
Data to pass to the Pgp Functions.
struct Menu * menu
Pgp Menu.
bool done
Should we close the Dialog?
struct PgpUidArray * key_table
Array of Keys.
struct PgpKeyInfo * key
Selected Key.
An entry in a PGP key menu.
Definition private.h:38
Information about a PGP key.
Definition pgplib.h:49
struct PgpKeyInfo * next
Linked list.
Definition pgplib.h:59
PGP User ID.
Definition pgplib.h:36
struct PgpUid * next
Linked list.
Definition pgplib.h:41
Tuple for the results of simple_dialog_new()
Definition simple.h:35
struct MuttWindow * sbar
Simple Bar.
Definition simple.h:37
struct Menu * menu
Menu.
Definition simple.h:38
struct MuttWindow * dlg
Main Dialog Window.
Definition simple.h:36