NeoMutt  2023-03-22-27-g3cb248
Teaching an old dog new tricks
DOXYGEN
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 "menu/lib.h"
66#include "keymap.h"
67#include "mutt_logging.h"
68#include "opcodes.h"
69#include "smime.h"
70#include "smime_functions.h"
71
73static const struct Mapping SmimeHelp[] = {
74 // clang-format off
75 { N_("Exit"), OP_EXIT },
76 { N_("Select"), OP_GENERIC_SELECT_ENTRY },
77 { N_("Help"), OP_HELP },
78 { NULL, 0 },
79 // clang-format on
80};
81
89static char *smime_key_flags(KeyFlags flags)
90{
91 static char buf[3];
92
93 if (!(flags & KEYFLAG_CANENCRYPT))
94 buf[0] = '-';
95 else
96 buf[0] = 'e';
97
98 if (!(flags & KEYFLAG_CANSIGN))
99 buf[1] = '-';
100 else
101 buf[1] = 's';
102
103 buf[2] = '\0';
104
105 return buf;
106}
107
111static void smime_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
112{
113 struct SmimeKey **table = menu->mdata;
114 struct SmimeKey *key = table[line];
115 char *truststate = NULL;
116 switch (key->trust)
117 {
118 case 'e':
119 /* L10N: Describes the trust state of a S/MIME key.
120 This translation must be padded with spaces to the right such that it
121 has the same length as the other translations.
122 The translation strings which need to be padded are:
123 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
124 truststate = _("Expired ");
125 break;
126 case 'i':
127 /* L10N: Describes the trust state of a S/MIME key.
128 This translation must be padded with spaces to the right such that it
129 has the same length as the other translations.
130 The translation strings which need to be padded are:
131 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
132 truststate = _("Invalid ");
133 break;
134 case 'r':
135 /* L10N: Describes the trust state of a S/MIME key.
136 This translation must be padded with spaces to the right such that it
137 has the same length as the other translations.
138 The translation strings which need to be padded are:
139 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
140 truststate = _("Revoked ");
141 break;
142 case 't':
143 /* L10N: Describes the trust state of a S/MIME key.
144 This translation must be padded with spaces to the right such that it
145 has the same length as the other translations.
146 The translation strings which need to be padded are:
147 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
148 truststate = _("Trusted ");
149 break;
150 case 'u':
151 /* L10N: Describes the trust state of a S/MIME key.
152 This translation must be padded with spaces to the right such that it
153 has the same length as the other translations.
154 The translation strings which need to be padded are:
155 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
156 truststate = _("Unverified");
157 break;
158 case 'v':
159 /* L10N: Describes the trust state of a S/MIME key.
160 This translation must be padded with spaces to the right such that it
161 has the same length as the other translations.
162 The translation strings which need to be padded are:
163 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
164 truststate = _("Verified ");
165 break;
166 default:
167 /* L10N: Describes the trust state of a S/MIME key.
168 This translation must be padded with spaces to the right such that it
169 has the same length as the other translations.
170 The translation strings which need to be padded are:
171 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
172 truststate = _("Unknown ");
173 }
174 snprintf(buf, buflen, " 0x%s %s %s %-35.35s %s", key->hash,
175 smime_key_flags(key->flags), truststate, key->email, key->label);
176}
177
183static void smime_key_table_free(struct Menu *menu, void **ptr)
184{
185 FREE(ptr);
186}
187
194struct SmimeKey *dlg_select_smime_key(struct SmimeKey *keys, const char *query)
195{
196 struct SmimeKey **table = NULL;
197 int table_size = 0;
198 int table_index = 0;
199 struct SmimeKey *key = NULL;
200
201 for (table_index = 0, key = keys; key; key = key->next)
202 {
203 if (table_index == table_size)
204 {
205 table_size += 5;
206 mutt_mem_realloc(&table, sizeof(struct SmimeKey *) * table_size);
207 }
208
209 table[table_index++] = key;
210 }
211
213
214 struct Menu *menu = dlg->wdata;
215 menu->max = table_index;
217 menu->mdata = table;
219 /* sorting keys might be done later - TODO */
220
221 struct SmimeData sd = { false, menu, table, NULL };
222 dlg->wdata = &sd;
223
224 char title[256] = { 0 };
225 struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
226 snprintf(title, sizeof(title), _("S/MIME certificates matching \"%s\""), query);
227 sbar_set_title(sbar, title);
228
230
231 // ---------------------------------------------------------------------------
232 // Event Loop
233 int op = OP_NULL;
234 do
235 {
236 menu_tagging_dispatcher(menu->win, op);
237 window_redraw(NULL);
238
239 op = km_dokey(MENU_SMIME);
240 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
241 if (op < 0)
242 continue;
243 if (op == OP_NULL)
244 {
246 continue;
247 }
249
250 int rc = smime_function_dispatcher(dlg, op);
251
252 if (rc == FR_UNKNOWN)
253 rc = menu_function_dispatcher(menu->win, op);
254 if (rc == FR_UNKNOWN)
255 rc = global_function_dispatcher(NULL, op);
256 } while (!sd.done);
257
258 simple_dialog_free(&dlg);
259 return sd.key;
260}
Convenience wrapper for the core headers.
@ FR_UNKNOWN
Unknown function.
Definition: dispatcher.h:33
struct SmimeKey * dlg_select_smime_key(struct SmimeKey *keys, const char *query)
Get the user to select a key.
Definition: dlg_smime.c:194
static const struct Mapping SmimeHelp[]
Help Bar for the Smime key selection dialog.
Definition: dlg_smime.c:73
static char * smime_key_flags(KeyFlags flags)
Turn SMIME key flags into a string.
Definition: dlg_smime.c:89
int menu_tagging_dispatcher(struct MuttWindow *win, int op)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition: tagging.c:223
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:164
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:320
int smime_function_dispatcher(struct MuttWindow *win, int op)
Perform a Smime function - Implements function_dispatcher_t -.
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
static void smime_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
Format a menu item for the smime key list - Implements Menu::make_entry() -.
Definition: dlg_smime.c:111
static void smime_key_table_free(struct Menu *menu, void **ptr)
Free the key table - Implements Menu::mdata_free() -.
Definition: dlg_smime.c:183
Convenience wrapper for the gui headers.
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:166
struct MuttWindow * simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:129
int km_dokey(enum MenuType mtype)
Determine what a keypress should do.
Definition: keymap.c:797
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: keymap.c:1065
Manage keymappings.
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
#define FREE(x)
Definition: memory.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:73
NeoMutt Logging.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:605
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:523
@ WT_DLG_SMIME
Smime Dialog, dlg_select_smime_key()
Definition: mutt_window.h:92
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
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:46
All user-callable functions.
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:224
GUI display the mailboxes in a side panel.
SMIME helper routines.
Smime functions.
Key value store.
Mapping between user-readable string and a constant.
Definition: mapping.h:32
Definition: lib.h:70
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:77
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:97
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:152
void * mdata
Private data.
Definition: lib.h:138
int max
Number of entries in the menu.
Definition: lib.h:72
void * wdata
Private data.
Definition: mutt_window.h:145
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 SmimeKey ** table
Array of Keys.
An SIME key.
Definition: smime.h:44
KeyFlags flags
Definition: smime.h:50
char * hash
Definition: smime.h:46
struct SmimeKey * next
Definition: smime.h:51
char * email
Definition: smime.h:45
char * label
Definition: smime.h:47
char trust
i=Invalid r=revoked e=expired u=unverified v=verified t=trusted
Definition: smime.h:49
@ MENU_SMIME
SMIME encryption menu.
Definition: type.h:58