NeoMutt  2023-03-22-27-g3cb248
Teaching an old dog new tricks
DOXYGEN
functions.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stdio.h>
31#include "private.h"
32#include "mutt/lib.h"
33#include "address/lib.h"
34#include "config/lib.h"
35#include "core/lib.h"
36#include "gui/lib.h"
37#include "functions.h"
38#include "lib.h"
39#include "menu/lib.h"
40#include "question/lib.h"
41#include "opcodes.h"
42
47static void toggle_active(struct AccountEntry *entry)
48{
49 entry->account->enabled = !entry->account->enabled;
51 {
52 entry->account->enabled = !entry->account->enabled;
53 /* L10N: This error message is displayed if a database update of an
54 account record fails for some odd reason. */
55 mutt_error(_("Error updating account record"));
56 }
57}
58
63static void toggle_prefer_encrypt(struct AccountEntry *entry)
64{
67 {
69 mutt_error(_("Error updating account record"));
70 }
71}
72
73// -----------------------------------------------------------------------------
74
78static int op_autocrypt_create_acct(struct AutocryptData *ad, int op)
79{
80 if (mutt_autocrypt_account_init(false) == 0)
82
83 return FR_SUCCESS;
84}
85
89static int op_autocrypt_delete_acct(struct AutocryptData *ad, int op)
90{
91 if (!ad->menu->mdata)
92 return FR_ERROR;
93
94 const int index = menu_get_index(ad->menu);
95 struct AccountEntry *entry = ((struct AccountEntry *) ad->menu->mdata) + index;
96 char msg[128] = { 0 };
97 snprintf(msg, sizeof(msg),
98 // L10N: Confirmation message when deleting an autocrypt account
99 _("Really delete account \"%s\"?"), entry->addr->mailbox);
100 if (mutt_yesorno(msg, MUTT_NO) != MUTT_YES)
101 return FR_NO_ACTION;
102
104 populate_menu(ad->menu);
105
106 return FR_SUCCESS;
107}
108
112static int op_autocrypt_toggle_active(struct AutocryptData *ad, int op)
113{
114 if (!ad->menu->mdata)
115 return FR_ERROR;
116
117 const int index = menu_get_index(ad->menu);
118 struct AccountEntry *entry = ((struct AccountEntry *) ad->menu->mdata) + index;
119 toggle_active(entry);
121
122 return FR_SUCCESS;
123}
124
128static int op_autocrypt_toggle_prefer(struct AutocryptData *ad, int op)
129{
130 if (!ad->menu->mdata)
131 return FR_ERROR;
132
133 const int index = menu_get_index(ad->menu);
134 struct AccountEntry *entry = (struct AccountEntry *) (ad->menu->mdata) + index;
137
138 return FR_SUCCESS;
139}
140
144static int op_exit(struct AutocryptData *ad, int op)
145{
146 ad->done = true;
147 return FR_SUCCESS;
148}
149
150// -----------------------------------------------------------------------------
151
156 // clang-format off
157 { OP_AUTOCRYPT_CREATE_ACCT, op_autocrypt_create_acct },
158 { OP_AUTOCRYPT_DELETE_ACCT, op_autocrypt_delete_acct },
159 { OP_AUTOCRYPT_TOGGLE_ACTIVE, op_autocrypt_toggle_active },
160 { OP_AUTOCRYPT_TOGGLE_PREFER, op_autocrypt_toggle_prefer },
161 { OP_EXIT, op_exit },
162 { 0, NULL },
163 // clang-format on
164};
165
170{
171 if (!win || !win->wdata)
172 return FR_UNKNOWN;
173
174 struct MuttWindow *dlg = dialog_find(win);
175 if (!dlg)
176 return FR_ERROR;
177
178 struct AutocryptData *ad = dlg->wdata;
179
180 int rc = FR_UNKNOWN;
181 for (size_t i = 0; AutocryptFunctions[i].op != OP_NULL; i++)
182 {
183 const struct AutocryptFunction *fn = &AutocryptFunctions[i];
184 if (fn->op == op)
185 {
186 rc = fn->function(ad, op);
187 break;
188 }
189 }
190
191 if (rc == FR_UNKNOWN) // Not our function
192 return rc;
193
194 const char *result = dispacher_get_retval_name(rc);
195 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
196
197 return rc;
198}
Email Address Handling.
int mutt_autocrypt_db_account_delete(struct AutocryptAccount *acct)
Delete an Account from the Autocrypt database.
Definition: db.c:419
int mutt_autocrypt_db_account_update(struct AutocryptAccount *acct)
Update Account info in the Autocrypt database.
Definition: db.c:373
static void toggle_active(struct AccountEntry *entry)
Toggle whether an Autocrypt account is active.
Definition: functions.c:47
struct AutocryptFunction AutocryptFunctions[]
All the NeoMutt functions that the Autocrypt supports.
Definition: functions.c:155
static void toggle_prefer_encrypt(struct AccountEntry *entry)
Toggle whether an Autocrypt account prefers encryption.
Definition: functions.c:63
int mutt_autocrypt_account_init(bool prompt)
Create a new Autocrypt account.
Definition: autocrypt.c:153
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:83
const char * dispacher_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:39
@ FR_UNKNOWN
Unknown function.
Definition: dispatcher.h:33
@ FR_ERROR
Valid function - error occurred.
Definition: dispatcher.h:38
@ FR_NO_ACTION
Valid function - no action performed.
Definition: dispatcher.h:37
bool populate_menu(struct Menu *menu)
Add the Autocrypt data to a Menu.
static int op_autocrypt_toggle_prefer(struct AutocryptData *ad, int op)
Toggle the current account prefer-encrypt flag - Implements autocrypt_function_t -.
Definition: functions.c:128
static int op_autocrypt_delete_acct(struct AutocryptData *ad, int op)
Delete the current account - Implements autocrypt_function_t -.
Definition: functions.c:89
static int op_autocrypt_toggle_active(struct AutocryptData *ad, int op)
Toggle the current account active/inactive - Implements autocrypt_function_t -.
Definition: functions.c:112
static int op_autocrypt_create_acct(struct AutocryptData *ad, int op)
Create a new autocrypt account - Implements autocrypt_function_t -.
Definition: functions.c:78
static int op_exit(struct AutocryptData *ad, int op)
Exit this menu - Implements autocrypt_function_t -.
Definition: functions.c:144
int autocrypt_function_dispatcher(struct MuttWindow *win, int op)
Perform a Autocrypt function - Implements function_dispatcher_t -.
Definition: functions.c:169
#define mutt_error(...)
Definition: logging.h:87
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
Convenience wrapper for the gui headers.
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
GUI present the user with a selectable list.
#define MENU_REDRAW_FULL
Redraw everything.
Definition: lib.h:60
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:178
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:154
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:46
All user-callable functions.
@ 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 mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
Definition: question.c:194
Sidebar functions.
GUI display the mailboxes in a side panel.
Key value store.
#define NONULL(x)
Definition: string2.h:37
An entry in the Autocrypt account Menu.
Definition: private.h:44
struct Address * addr
Email address associated with the account.
Definition: private.h:47
struct AutocryptAccount * account
Account details.
Definition: private.h:46
char * mailbox
Mailbox and host address.
Definition: address.h:38
bool enabled
Is this account enabled.
Definition: lib.h:111
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:110
Data to pass to the Autocrypt Functions.
Definition: functions.h:34
bool done
Should we close the Dialog?
Definition: functions.h:35
struct Menu * menu
Autocrypt Menu.
Definition: functions.h:36
A NeoMutt function.
Definition: functions.h:55
autocrypt_function_t function
Function to call.
Definition: functions.h:57
int op
Op code, e.g. OP_AUTOCRYPT_CREATE_ACCT.
Definition: functions.h:56
void * mdata
Private data.
Definition: lib.h:138
void * wdata
Private data.
Definition: mutt_window.h:145