NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_smime.c
Go to the documentation of this file.
1
57#include "config.h"
58#include <stdbool.h>
59#include <stdio.h>
60#include "private.h"
61#include "mutt/lib.h"
62#include "core/lib.h"
63#include "gui/lib.h"
64#include "lib.h"
65#include "key/lib.h"
66#include "menu/lib.h"
67#include "mutt_logging.h"
68#include "smime.h"
69#include "smime_functions.h"
70
72static const struct Mapping SmimeHelp[] = {
73 // clang-format off
74 { N_("Exit"), OP_EXIT },
75 { N_("Select"), OP_GENERIC_SELECT_ENTRY },
76 { N_("Help"), OP_HELP },
77 { NULL, 0 },
78 // clang-format on
79};
80
88static char *smime_key_flags(KeyFlags flags)
89{
90 static char buf[3];
91
92 if (!(flags & KEYFLAG_CANENCRYPT))
93 buf[0] = '-';
94 else
95 buf[0] = 'e';
96
97 if (!(flags & KEYFLAG_CANSIGN))
98 buf[1] = '-';
99 else
100 buf[1] = 's';
101
102 buf[2] = '\0';
103
104 return buf;
105}
106
110static int smime_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
111{
112 struct SmimeData *sd = menu->mdata;
113 struct SmimeKey **pkey = ARRAY_GET(sd->ska, line);
114 if (!pkey)
115 return 0;
116
117 char *truststate = NULL;
118 switch ((*pkey)->trust)
119 {
120 case 'e':
121 /* L10N: Describes the trust state of a S/MIME key.
122 This translation must be padded with spaces to the right such that it
123 has the same length as the other translations.
124 The translation strings which need to be padded are:
125 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
126 truststate = _("Expired ");
127 break;
128 case 'i':
129 /* L10N: Describes the trust state of a S/MIME key.
130 This translation must be padded with spaces to the right such that it
131 has the same length as the other translations.
132 The translation strings which need to be padded are:
133 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
134 truststate = _("Invalid ");
135 break;
136 case 'r':
137 /* L10N: Describes the trust state of a S/MIME key.
138 This translation must be padded with spaces to the right such that it
139 has the same length as the other translations.
140 The translation strings which need to be padded are:
141 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
142 truststate = _("Revoked ");
143 break;
144 case 't':
145 /* L10N: Describes the trust state of a S/MIME key.
146 This translation must be padded with spaces to the right such that it
147 has the same length as the other translations.
148 The translation strings which need to be padded are:
149 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
150 truststate = _("Trusted ");
151 break;
152 case 'u':
153 /* L10N: Describes the trust state of a S/MIME key.
154 This translation must be padded with spaces to the right such that it
155 has the same length as the other translations.
156 The translation strings which need to be padded are:
157 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
158 truststate = _("Unverified");
159 break;
160 case 'v':
161 /* L10N: Describes the trust state of a S/MIME key.
162 This translation must be padded with spaces to the right such that it
163 has the same length as the other translations.
164 The translation strings which need to be padded are:
165 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
166 truststate = _("Verified ");
167 break;
168 default:
169 /* L10N: Describes the trust state of a S/MIME key.
170 This translation must be padded with spaces to the right such that it
171 has the same length as the other translations.
172 The translation strings which need to be padded are:
173 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
174 truststate = _("Unknown ");
175 }
176
177 int bytes = buf_printf(buf, " 0x%s %s %s %-35.35s %s", (*pkey)->hash,
178 smime_key_flags((*pkey)->flags), truststate,
179 (*pkey)->email, (*pkey)->label);
180 if (bytes < 0)
181 bytes = 0;
182
183 return mutt_strnwidth(buf_string(buf), bytes);
184}
185
194struct SmimeKey *dlg_smime(struct SmimeKey *keys, const char *query)
195{
196 struct SmimeKeyArray ska = ARRAY_HEAD_INITIALIZER;
197 for (struct SmimeKey *key = keys; key; key = key->next)
198 {
199 ARRAY_ADD(&ska, key);
200 }
201 /* sorting keys might be done later - TODO */
202
204 struct Menu *menu = sdw.menu;
205
206 struct SmimeData sd = { false, menu, &ska, NULL };
207
208 menu->max = ARRAY_SIZE(&ska);
210 menu->mdata = &sd;
211 menu->mdata_free = NULL; // Menu doesn't own the data
212
213 char title[256] = { 0 };
214 snprintf(title, sizeof(title), _("S/MIME certificates matching \"%s\""), query);
215 sbar_set_title(sdw.sbar, title);
216
218
219 struct MuttWindow *old_focus = window_set_focus(menu->win);
220 // ---------------------------------------------------------------------------
221 // Event Loop
222 int op = OP_NULL;
223 do
224 {
225 menu_tagging_dispatcher(menu->win, op);
226 window_redraw(NULL);
227
229 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
230 if (op < 0)
231 continue;
232 if (op == OP_NULL)
233 {
235 continue;
236 }
238
239 int rc = smime_function_dispatcher(sdw.dlg, op);
240
241 if (rc == FR_UNKNOWN)
242 rc = menu_function_dispatcher(menu->win, op);
243 if (rc == FR_UNKNOWN)
244 rc = global_function_dispatcher(NULL, op);
245 } while (!sd.done);
246
247 window_set_focus(old_focus);
249 return sd.key;
250}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:156
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:87
#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
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
Convenience wrapper for the core headers.
size_t mutt_strnwidth(const char *s, size_t n)
Measure a string's width in screen cells.
Definition: curs_lib.c:456
@ FR_UNKNOWN
Unknown function.
Definition: dispatcher.h:33
static const struct Mapping SmimeHelp[]
Help Bar for the Smime key selection dialog.
Definition: dlg_smime.c:72
static char * smime_key_flags(KeyFlags flags)
Turn SMIME key flags into a string.
Definition: dlg_smime.c:88
int km_dokey(enum MenuType mtype, GetChFlags flags)
Determine what a keypress should do.
Definition: get.c:464
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: get.c:294
int menu_tagging_dispatcher(struct MuttWindow *win, int op)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition: tagging.c:230
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:172
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:318
int smime_function_dispatcher(struct MuttWindow *win, int op)
Perform a Smime function - Implements function_dispatcher_t -.
struct SmimeKey * dlg_smime(struct SmimeKey *keys, const char *query)
Get the user to select a key -.
Definition: dlg_smime.c:194
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
static int smime_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Format an S/MIME Key for the Menu - Implements Menu::make_entry() -.
Definition: dlg_smime.c:110
Convenience wrapper for the gui headers.
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:168
struct SimpleDialogWindows simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:132
Manage keymappings.
#define GETCH_NO_FLAGS
No flags are set.
Definition: lib.h:51
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
GUI present the user with a selectable list.
Convenience wrapper for the library headers.
#define N_(a)
Definition: message.h:32
#define _(a)
Definition: message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
NeoMutt Logging.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:633
struct MuttWindow * window_set_focus(struct MuttWindow *win)
Set the Window focus.
Definition: mutt_window.c:683
@ WT_DLG_SMIME
Smime Dialog, dlg_smime()
Definition: mutt_window.h:91
uint16_t KeyFlags
Flags describing PGP/SMIME keys, e.g. KEYFLAG_CANSIGN.
Definition: lib.h:125
#define KEYFLAG_CANENCRYPT
Key is suitable for encryption.
Definition: lib.h:128
#define KEYFLAG_CANSIGN
Key is suitable for signing.
Definition: lib.h:127
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:48
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:227
GUI display the mailboxes in a side panel.
SMIME helper routines.
Smime functions.
Key value store.
String manipulation buffer.
Definition: buffer.h:36
Mapping between user-readable string and a constant.
Definition: mapping.h:33
Definition: lib.h:79
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:86
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:161
int(* make_entry)(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Definition: lib.h:106
void * mdata
Private data.
Definition: lib.h:147
int max
Number of entries in the menu.
Definition: lib.h:81
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
Data to pass to the Smime Functions.
struct SmimeKey * key
Selected Key.
bool done
Should we close the Dialog?
struct Menu * menu
Smime Menu.
struct SmimeKeyArray * ska
Array of Keys.
An SIME key.
Definition: smime.h:44
struct SmimeKey * next
Definition: smime.h:51
@ MENU_SMIME
SMIME encryption menu.
Definition: type.h:56