NeoMutt  2025-12-11-949-g4870ee
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
functions_smime.c
Go to the documentation of this file.
1
22
28
29#include "config.h"
30#include <stdbool.h>
31#include <stdio.h>
32#include "mutt/lib.h"
33#include "config/lib.h"
34#include "core/lib.h"
35#include "gui/lib.h"
36#include "key/lib.h"
37#include "menu/lib.h"
38#include "question/lib.h"
39#include "mutt_logging.h"
40#include "smime.h"
41#include "smime_functions.h"
42
46static int op_quit(struct SmimeData *sd, const struct KeyEvent *event)
47{
48 sd->done = true;
49 return FR_SUCCESS;
50}
51
55static int op_generic_select_entry(struct SmimeData *sd, const struct KeyEvent *event)
56{
57 const int index = menu_get_index(sd->menu);
58 struct SmimeKey **pkey = ARRAY_GET(sd->ska, index);
59 if (!pkey)
60 return FR_NO_ACTION;
61
62 if ((*pkey)->trust != 't')
63 {
64 const char *s = "";
65 switch ((*pkey)->trust)
66 {
67 case 'e':
68 case 'i':
69 case 'r':
70 s = _("ID is expired/disabled/revoked. Do you really want to use the key?");
71 break;
72 case 'u':
73 s = _("ID has undefined validity. Do you really want to use the key?");
74 break;
75 case 'v':
76 s = _("ID is not trusted. Do you really want to use the key?");
77 break;
78 }
79
80 char buf[1024] = { 0 };
81 snprintf(buf, sizeof(buf), "%s", s);
82
83 if (query_yesorno(buf, MUTT_NO) != MUTT_YES)
84 {
86 return FR_NO_ACTION;
87 }
88 }
89
90 sd->key = *pkey;
91 sd->done = true;
92 return FR_SUCCESS;
93}
94
95// -----------------------------------------------------------------------------
96
100static const struct SmimeFunction SmimeFunctions[] = {
101 // clang-format off
102 { OP_EXIT, op_quit },
103 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
104 { OP_QUIT, op_quit },
105 { 0, NULL },
106 // clang-format on
107};
108
112int smime_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
113{
114 // The Dispatcher may be called on any Window in the Dialog
115 struct MuttWindow *dlg = dialog_find(win);
116 if (!event || !dlg || !dlg->wdata)
117 {
119 return FR_ERROR;
120 }
121
122 const int op = event->op;
123 struct Menu *menu = dlg->wdata;
124 struct SmimeData *sd = menu->mdata;
125 if (!sd)
126 {
128 return FR_ERROR;
129 }
130
131 int rc = FR_UNKNOWN;
132 for (size_t i = 0; SmimeFunctions[i].op != OP_NULL; i++)
133 {
134 const struct SmimeFunction *fn = &SmimeFunctions[i];
135 if (fn->op == op)
136 {
137 rc = fn->function(sd, event);
138 break;
139 }
140 }
141
142 if (rc == FR_UNKNOWN) // Not our function
143 return rc;
144
145 const char *result = dispatcher_get_retval_name(rc);
146 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
147
149 return rc;
150}
#define ARRAY_GET(head, idx)
Return the element at index.
Definition array.h:109
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
struct MuttWindow * dialog_find(struct MuttWindow *win)
Find the parent Dialog of a Window.
Definition dialog.c:89
const char * dispatcher_get_retval_name(int rv)
Get the name of a return value.
Definition dispatcher.c:55
void dispatcher_flush_on_error(int rv)
Flush pending keys after a dispatch error.
Definition dispatcher.c:65
@ FR_SUCCESS
Valid function - successfully performed.
Definition dispatcher.h:40
@ FR_UNKNOWN
Unknown function.
Definition dispatcher.h:34
@ FR_ERROR
Valid function - error occurred.
Definition dispatcher.h:39
@ FR_NO_ACTION
Valid function - no action performed.
Definition dispatcher.h:38
static const struct SmimeFunction SmimeFunctions[]
All the NeoMutt functions that the Smime supports.
static int op_quit(struct AliasFunctionData *fdata, const struct KeyEvent *event)
Save changes and exit this dialog - Implements alias_function_t -.
Definition functions.c:308
static int op_generic_select_entry(struct AliasFunctionData *fdata, const struct KeyEvent *event)
select the current entry - Implements alias_function_t -
Definition functions.c:388
int smime_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Smime function - Implements function_dispatcher_t -.
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
static int op_quit(struct SmimeData *sd, const struct KeyEvent *event)
Save changes and exit this dialog - Implements smime_function_t -.
static int op_generic_select_entry(struct SmimeData *sd, const struct KeyEvent *event)
Select the current entry - Implements smime_function_t -.
Convenience wrapper for the gui headers.
Manage keymappings.
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
GUI present the user with a selectable list.
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition menu.c:153
Convenience wrapper for the library headers.
#define _(a)
Definition message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
NeoMutt Logging.
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition opcodes.c:48
@ MUTT_NO
User answered 'No', or assume 'No'.
Definition quad.h:38
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
Definition quad.h:39
Ask the user a question.
enum QuadOption query_yesorno(const char *prompt, enum QuadOption def)
Ask the user a Yes/No question.
Definition question.c:329
SMIME helper routines.
Smime functions.
#define NONULL(x)
Definition string2.h:44
An event such as a keypress.
Definition get.h:75
Definition lib.h:86
void * mdata
Private data.
Definition lib.h:155
void * wdata
Private data.
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.
A NeoMutt function.
smime_function_t function
Function to call.
int op
Op code, e.g. OP_GENERIC_SELECT_ENTRY.
An SIME key.
Definition smime.h:43