NeoMutt
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 void smime_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
111{
112 struct SmimeKey **table = menu->mdata;
113 struct SmimeKey *key = table[line];
114 char *truststate = NULL;
115 switch (key->trust)
116 {
117 case 'e':
118 /* L10N: Describes the trust state of a S/MIME key.
119 This translation must be padded with spaces to the right such that it
120 has the same length as the other translations.
121 The translation strings which need to be padded are:
122 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
123 truststate = _("Expired ");
124 break;
125 case 'i':
126 /* L10N: Describes the trust state of a S/MIME key.
127 This translation must be padded with spaces to the right such that it
128 has the same length as the other translations.
129 The translation strings which need to be padded are:
130 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
131 truststate = _("Invalid ");
132 break;
133 case 'r':
134 /* L10N: Describes the trust state of a S/MIME key.
135 This translation must be padded with spaces to the right such that it
136 has the same length as the other translations.
137 The translation strings which need to be padded are:
138 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
139 truststate = _("Revoked ");
140 break;
141 case 't':
142 /* L10N: Describes the trust state of a S/MIME key.
143 This translation must be padded with spaces to the right such that it
144 has the same length as the other translations.
145 The translation strings which need to be padded are:
146 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
147 truststate = _("Trusted ");
148 break;
149 case 'u':
150 /* L10N: Describes the trust state of a S/MIME key.
151 This translation must be padded with spaces to the right such that it
152 has the same length as the other translations.
153 The translation strings which need to be padded are:
154 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
155 truststate = _("Unverified");
156 break;
157 case 'v':
158 /* L10N: Describes the trust state of a S/MIME key.
159 This translation must be padded with spaces to the right such that it
160 has the same length as the other translations.
161 The translation strings which need to be padded are:
162 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
163 truststate = _("Verified ");
164 break;
165 default:
166 /* L10N: Describes the trust state of a S/MIME key.
167 This translation must be padded with spaces to the right such that it
168 has the same length as the other translations.
169 The translation strings which need to be padded are:
170 Expired, Invalid, Revoked, Trusted, Unverified, Verified, and Unknown. */
171 truststate = _("Unknown ");
172 }
173 snprintf(buf, buflen, " 0x%s %s %s %-35.35s %s", key->hash,
174 smime_key_flags(key->flags), truststate, key->email, key->label);
175}
176
182static void smime_key_table_free(struct Menu *menu, void **ptr)
183{
184 FREE(ptr);
185}
186
195struct SmimeKey *dlg_smime(struct SmimeKey *keys, const char *query)
196{
197 struct SmimeKey **table = NULL;
198 int table_size = 0;
199 int table_index = 0;
200 struct SmimeKey *key = NULL;
201
202 for (table_index = 0, key = keys; key; key = key->next)
203 {
204 if (table_index == table_size)
205 {
206 table_size += 5;
207 mutt_mem_realloc(&table, sizeof(struct SmimeKey *) * table_size);
208 }
209
210 table[table_index++] = key;
211 }
212
214
215 struct Menu *menu = dlg->wdata;
216 menu->max = table_index;
218 menu->mdata = table;
220 /* sorting keys might be done later - TODO */
221
222 struct SmimeData sd = { false, menu, table, NULL };
223 dlg->wdata = &sd;
224
225 char title[256] = { 0 };
226 struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
227 snprintf(title, sizeof(title), _("S/MIME certificates matching \"%s\""), query);
228 sbar_set_title(sbar, title);
229
231
232 struct MuttWindow *old_focus = window_set_focus(menu->win);
233 // ---------------------------------------------------------------------------
234 // Event Loop
235 int op = OP_NULL;
236 do
237 {
238 menu_tagging_dispatcher(menu->win, op);
239 window_redraw(NULL);
240
242 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
243 if (op < 0)
244 continue;
245 if (op == OP_NULL)
246 {
248 continue;
249 }
251
252 int rc = smime_function_dispatcher(dlg, op);
253
254 if (rc == FR_UNKNOWN)
255 rc = menu_function_dispatcher(menu->win, op);
256 if (rc == FR_UNKNOWN)
257 rc = global_function_dispatcher(NULL, op);
258 } while (!sd.done);
259
260 window_set_focus(old_focus);
261 simple_dialog_free(&dlg);
262 return sd.key;
263}
Convenience wrapper for the core headers.
@ 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:475
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: get.c:305
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:166
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:317
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:195
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
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:110
static void smime_key_table_free(struct Menu *menu, void **ptr)
Free the key table - Implements Menu::mdata_free() -.
Definition: dlg_smime.c:182
Convenience wrapper for the gui headers.
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:168
struct MuttWindow * 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:52
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
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:45
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:634
struct MuttWindow * window_set_focus(struct MuttWindow *win)
Set the Window focus.
Definition: mutt_window.c:684
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:533
@ WT_DLG_SMIME
Smime Dialog, dlg_smime()
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:126
#define KEYFLAG_CANENCRYPT
Key is suitable for encryption.
Definition: lib.h:129
#define KEYFLAG_CANSIGN
Key is suitable for signing.
Definition: lib.h:128
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.
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:96
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:151
void * mdata
Private data.
Definition: lib.h:137
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:59