NeoMutt  2025-12-11-769-g906513
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
smime_functions.c
Go to the documentation of this file.
1
22
28
29#include "config.h"
30#include <stdio.h>
31#include "mutt/lib.h"
32#include "config/lib.h"
33#include "core/lib.h"
34#include "gui/lib.h"
35#include "smime_functions.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
45static int op_exit(struct SmimeData *sd, const struct KeyEvent *event)
46{
47 sd->done = true;
48 return FR_SUCCESS;
49}
50
54static int op_generic_select_entry(struct SmimeData *sd, const struct KeyEvent *event)
55{
56 const int index = menu_get_index(sd->menu);
57 struct SmimeKey **pkey = ARRAY_GET(sd->ska, index);
58 if (!pkey)
59 return FR_NO_ACTION;
60
61 if ((*pkey)->trust != 't')
62 {
63 const char *s = "";
64 switch ((*pkey)->trust)
65 {
66 case 'e':
67 case 'i':
68 case 'r':
69 s = _("ID is expired/disabled/revoked. Do you really want to use the key?");
70 break;
71 case 'u':
72 s = _("ID has undefined validity. Do you really want to use the key?");
73 break;
74 case 'v':
75 s = _("ID is not trusted. Do you really want to use the key?");
76 break;
77 }
78
79 char buf[1024] = { 0 };
80 snprintf(buf, sizeof(buf), "%s", s);
81
82 if (query_yesorno(buf, MUTT_NO) != MUTT_YES)
83 {
85 return FR_NO_ACTION;
86 }
87 }
88
89 sd->key = *pkey;
90 sd->done = true;
91 return FR_SUCCESS;
92}
93
94// -----------------------------------------------------------------------------
95
99static const struct SmimeFunction SmimeFunctions[] = {
100 // clang-format off
101 { OP_EXIT, op_exit },
102 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
103 { 0, NULL },
104 // clang-format on
105};
106
110int smime_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
111{
112 // The Dispatcher may be called on any Window in the Dialog
113 struct MuttWindow *dlg = dialog_find(win);
114 if (!event || !dlg || !dlg->wdata)
115 return FR_ERROR;
116
117 const int op = event->op;
118 struct Menu *menu = dlg->wdata;
119 struct SmimeData *sd = menu->mdata;
120 if (!sd)
121 return FR_ERROR;
122
123 int rc = FR_UNKNOWN;
124 for (size_t i = 0; SmimeFunctions[i].op != OP_NULL; i++)
125 {
126 const struct SmimeFunction *fn = &SmimeFunctions[i];
127 if (fn->op == op)
128 {
129 rc = fn->function(sd, event);
130 break;
131 }
132 }
133
134 if (rc == FR_UNKNOWN) // Not our function
135 return rc;
136
137 const char *result = dispatcher_get_retval_name(rc);
138 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
139
140 return rc;
141}
#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:54
@ 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 int op_exit(struct AliasFunctionData *fdata, const struct KeyEvent *event)
exit this menu - Implements alias_function_t -
Definition functions.c:235
static int op_generic_select_entry(struct AliasFunctionData *fdata, const struct KeyEvent *event)
select the current entry - Implements alias_function_t -
Definition functions.c:249
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_exit(struct SmimeData *sd, const struct KeyEvent *event)
Exit this menu - 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:165
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.
static const struct SmimeFunction SmimeFunctions[]
All the NeoMutt functions that the Smime supports.
Smime functions.
#define NONULL(x)
Definition string2.h:44
An event such as a keypress.
Definition get.h:50
Definition lib.h:80
void * mdata
Private data.
Definition lib.h:149
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:42