NeoMutt  2021-02-05-89-gabe350
Teaching an old dog new tricks
DOXYGEN
dlgautocrypt.c File Reference
#include "config.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "private.h"
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "autocrypt/lib.h"
#include "format_flags.h"
#include "keymap.h"
#include "mutt_globals.h"
#include "mutt_menu.h"
#include "muttlib.h"
#include "opcodes.h"
+ Include dependency graph for dlgautocrypt.c:

Go to the source code of this file.

Data Structures

struct  AccountEntry
 An entry in the Autocrypt account Menu. More...
 

Functions

static const char * account_format_str (char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
 Format a string for the Autocrypt account list - Implements format_t. More...
 
static void account_make_entry (struct Menu *menu, char *buf, size_t buflen, int num)
 Create a line for the Autocrypt account menu - Implements Menu::make_entry() More...
 
static struct Menucreate_menu (void)
 Create the Autocrypt account Menu. More...
 
static void menu_free (struct Menu **menu)
 Free the Autocrypt account Menu. More...
 
static void toggle_active (struct AccountEntry *entry)
 Toggle whether an Autocrypt account is active. More...
 
static void toggle_prefer_encrypt (struct AccountEntry *entry)
 Toggle whether an Autocrypt account prefers encryption. More...
 
void dlg_select_autocrypt_account (struct Mailbox *m)
 Display the Autocrypt account Menu. More...
 

Variables

static const struct Mapping AutocryptAcctHelp []
 Help Bar for the Autocrypt Account selection dialog. More...
 

Detailed Description

Autocrypt account menu

Authors
  • Kevin J. McCarthy

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file dlgautocrypt.c.

Function Documentation

◆ account_format_str()

static const char* account_format_str ( char *  buf,
size_t  buflen,
size_t  col,
int  cols,
char  op,
const char *  src,
const char *  prec,
const char *  if_str,
const char *  else_str,
intptr_t  data,
MuttFormatFlags  flags 
)
static

Format a string for the Autocrypt account list - Implements format_t.

Expando Description
%a Email address
%k Gpg keyid
%n Current entry number
%p Prefer-encrypt flag
%s Status flag (active/inactive)

Definition at line 96 of file dlgautocrypt.c.

100 {
101  struct AccountEntry *entry = (struct AccountEntry *) data;
102  char tmp[128];
103 
104  switch (op)
105  {
106  case 'a':
107  mutt_format_s(buf, buflen, prec, entry->addr->mailbox);
108  break;
109  case 'k':
110  mutt_format_s(buf, buflen, prec, entry->account->keyid);
111  break;
112  case 'n':
113  snprintf(tmp, sizeof(tmp), "%%%sd", prec);
114  snprintf(buf, buflen, tmp, entry->num);
115  break;
116  case 'p':
117  if (entry->account->prefer_encrypt)
118  {
119  /* L10N: Autocrypt Account menu.
120  flag that an account has prefer-encrypt set */
121  mutt_format_s(buf, buflen, prec, _("prefer encrypt"));
122  }
123  else
124  {
125  /* L10N: Autocrypt Account menu.
126  flag that an account has prefer-encrypt unset;
127  thus encryption will need to be manually enabled. */
128  mutt_format_s(buf, buflen, prec, _("manual encrypt"));
129  }
130  break;
131  case 's':
132  if (entry->account->enabled)
133  {
134  /* L10N: Autocrypt Account menu.
135  flag that an account is enabled/active */
136  mutt_format_s(buf, buflen, prec, _("active"));
137  }
138  else
139  {
140  /* L10N: Autocrypt Account menu.
141  flag that an account is disabled/inactive */
142  mutt_format_s(buf, buflen, prec, _("inactive"));
143  }
144  break;
145  }
146 
147  return (src);
148 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ account_make_entry()

static void account_make_entry ( struct Menu menu,
char *  buf,
size_t  buflen,
int  num 
)
static

Create a line for the Autocrypt account menu - Implements Menu::make_entry()

Definition at line 153 of file dlgautocrypt.c.

154 {
155  struct AccountEntry *entry = &((struct AccountEntry *) menu->mdata)[num];
156 
157  mutt_expando_format(buf, buflen, 0, menu->win_index->state.cols,
159  IP entry, MUTT_FORMAT_ARROWCURSOR);
160 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create_menu()

static struct Menu* create_menu ( void  )
static

Create the Autocrypt account Menu.

Return values
ptrNew Menu

Definition at line 166 of file dlgautocrypt.c.

167 {
168  struct AutocryptAccount **accounts = NULL;
169  int num_accounts = 0;
170 
171  if (mutt_autocrypt_db_account_get_all(&accounts, &num_accounts) < 0)
172  return NULL;
173 
174  struct Menu *menu = mutt_menu_new(MENU_AUTOCRYPT_ACCT);
176  /* menu->tag = account_tag; */
177  // L10N: Autocrypt Account Management Menu title
178  menu->title = _("Autocrypt Accounts");
179 
180  struct AccountEntry *entries =
181  mutt_mem_calloc(num_accounts, sizeof(struct AccountEntry));
182  menu->mdata = entries;
183  menu->max = num_accounts;
184 
185  for (int i = 0; i < num_accounts; i++)
186  {
187  entries[i].num = i + 1;
188  /* note: we are transferring the account pointer to the entries
189  * array, and freeing the accounts array below. the account
190  * will be freed in menu_free(). */
191  entries[i].account = accounts[i];
192 
193  entries[i].addr = mutt_addr_new();
194  entries[i].addr->mailbox = mutt_str_dup(accounts[i]->email_addr);
195  mutt_addr_to_local(entries[i].addr);
196  }
197  FREE(&accounts);
198 
200 
201  return menu;
202 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_free()

static void menu_free ( struct Menu **  menu)
static

Free the Autocrypt account Menu.

Parameters
menuMenu to free

Definition at line 208 of file dlgautocrypt.c.

209 {
210  struct AccountEntry *entries = (struct AccountEntry *) (*menu)->mdata;
211 
212  for (int i = 0; i < (*menu)->max; i++)
213  {
215  mutt_addr_free(&entries[i].addr);
216  }
217  FREE(&(*menu)->mdata);
218 
219  mutt_menu_pop_current(*menu);
220  mutt_menu_free(menu);
221 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toggle_active()

static void toggle_active ( struct AccountEntry entry)
static

Toggle whether an Autocrypt account is active.

Parameters
entryMenu Entry for the account

Definition at line 227 of file dlgautocrypt.c.

228 {
229  entry->account->enabled = !entry->account->enabled;
230  if (mutt_autocrypt_db_account_update(entry->account) != 0)
231  {
232  entry->account->enabled = !entry->account->enabled;
233  /* L10N: This error message is displayed if a database update of an
234  account record fails for some odd reason. */
235  mutt_error(_("Error updating account record"));
236  }
237 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toggle_prefer_encrypt()

static void toggle_prefer_encrypt ( struct AccountEntry entry)
static

Toggle whether an Autocrypt account prefers encryption.

Parameters
entryMenu Entry for the account

Definition at line 243 of file dlgautocrypt.c.

244 {
245  entry->account->prefer_encrypt = !entry->account->prefer_encrypt;
247  {
248  entry->account->prefer_encrypt = !entry->account->prefer_encrypt;
249  mutt_error(_("Error updating account record"));
250  }
251 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dlg_select_autocrypt_account()

void dlg_select_autocrypt_account ( struct Mailbox m)

Display the Autocrypt account Menu.

Parameters
mMailbox

Definition at line 257 of file dlgautocrypt.c.

258 {
259  if (!C_Autocrypt)
260  return;
261 
262  if (mutt_autocrypt_init(m, false))
263  return;
264 
265  struct Menu *menu = create_menu();
266  if (!menu)
267  return;
268 
272 
273  bool done = false;
274  while (!done)
275  {
276  switch (mutt_menu_loop(menu))
277  {
278  case OP_EXIT:
279  done = true;
280  break;
281 
282  case OP_AUTOCRYPT_CREATE_ACCT:
283  if (mutt_autocrypt_account_init(false))
284  break;
285 
286  menu_free(&menu);
288  menu = create_menu();
292  break;
293 
294  case OP_AUTOCRYPT_DELETE_ACCT:
295  {
296  if (!menu->mdata)
297  break;
298 
299  struct AccountEntry *entry = (struct AccountEntry *) (menu->mdata) + menu->current;
300  char msg[128];
301  snprintf(msg, sizeof(msg),
302  // L10N: Confirmation message when deleting an autocrypt account
303  _("Really delete account \"%s\"?"), entry->addr->mailbox);
304  if (mutt_yesorno(msg, MUTT_NO) != MUTT_YES)
305  break;
306 
308  {
309  menu_free(&menu);
311  menu = create_menu();
315  }
316  break;
317  }
318 
319  case OP_AUTOCRYPT_TOGGLE_ACTIVE:
320  {
321  if (!menu->mdata)
322  break;
323 
324  struct AccountEntry *entry = (struct AccountEntry *) (menu->mdata) + menu->current;
325  toggle_active(entry);
326  menu->redraw |= REDRAW_FULL;
327  break;
328  }
329 
330  case OP_AUTOCRYPT_TOGGLE_PREFER:
331  {
332  if (!menu->mdata)
333  break;
334 
335  struct AccountEntry *entry = (struct AccountEntry *) (menu->mdata) + menu->current;
336  toggle_prefer_encrypt(entry);
337  menu->redraw |= REDRAW_FULL;
338  break;
339  }
340  }
341  }
342 
343  menu_free(&menu);
345 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ AutocryptAcctHelp

const struct Mapping AutocryptAcctHelp[]
static
Initial value:
= {
{ N_("Exit"), OP_EXIT },
{ N_("Create"), OP_AUTOCRYPT_CREATE_ACCT },
{ N_("Delete"), OP_AUTOCRYPT_DELETE_ACCT },
{ N_("Tgl Active"), OP_AUTOCRYPT_TOGGLE_ACTIVE },
{ N_("Prf Encr"), OP_AUTOCRYPT_TOGGLE_PREFER },
{ N_("Help"), OP_HELP },
{ NULL, 0 }
}

Help Bar for the Autocrypt Account selection dialog.

Definition at line 59 of file dlgautocrypt.c.

IP
#define IP
Definition: set.h:54
dialog_create_simple_index
struct MuttWindow * dialog_create_simple_index(struct Menu *menu, enum WindowType type)
Create a simple index Dialog.
Definition: dialog.c:165
toggle_prefer_encrypt
static void toggle_prefer_encrypt(struct AccountEntry *entry)
Toggle whether an Autocrypt account prefers encryption.
Definition: dlgautocrypt.c:243
C_AutocryptAcctFormat
char * C_AutocryptAcctFormat
Config: Format of the autocrypt account menu.
Definition: config.c:39
mutt_mem_calloc
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
_
#define _(a)
Definition: message.h:28
NONULL
#define NONULL(x)
Definition: string2.h:37
AutocryptAccount
Autocrypt account.
Definition: lib.h:104
mutt_addr_to_local
bool mutt_addr_to_local(struct Address *a)
Convert an Address from Punycode.
Definition: address.c:1349
WT_DLG_AUTOCRYPT
@ WT_DLG_AUTOCRYPT
Autocrypt Dialog, dlg_select_autocrypt_account()
Definition: mutt_window.h:76
MUTT_FORMAT_ARROWCURSOR
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition: format_flags.h:35
mutt_autocrypt_account_init
int mutt_autocrypt_account_init(bool prompt)
Create a new Autocrypt account.
Definition: autocrypt.c:149
create_menu
static struct Menu * create_menu(void)
Create the Autocrypt account Menu.
Definition: dlgautocrypt.c:166
MuttWindow
A division of the screen.
Definition: mutt_window.h:115
mutt_autocrypt_db_account_free
void mutt_autocrypt_db_account_free(struct AutocryptAccount **ptr)
Free an AutocryptAccount.
Definition: db.c:241
MUTT_YES
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
Definition: quad.h:40
mutt_str_dup
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
FREE
#define FREE(x)
Definition: memory.h:40
C_Autocrypt
bool C_Autocrypt
Config: Enables the Autocrypt feature.
Definition: config.c:37
mutt_menu_new
struct Menu * mutt_menu_new(enum MenuType type)
Create a new Menu.
Definition: menu.c:956
MuttWindow::help_menu
int help_menu
Menu for key bindings, e.g. MENU_PAGER.
Definition: mutt_window.h:134
Menu::make_entry
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Format a item for a menu.
Definition: mutt_menu.h:88
AutocryptAccount::prefer_encrypt
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:109
AccountEntry::account
struct AutocryptAccount * account
Definition: dlgautocrypt.c:54
mutt_autocrypt_db_account_delete
int mutt_autocrypt_db_account_delete(struct AutocryptAccount *acct)
Delete an Account from the Autocrypt database.
Definition: db.c:416
AccountEntry
An entry in the Autocrypt account Menu.
Definition: dlgautocrypt.c:50
mutt_menu_push_current
void mutt_menu_push_current(struct Menu *menu)
Add a new Menu to the stack.
Definition: menu.c:1015
AccountEntry::num
int num
Definition: dlgautocrypt.c:53
AutocryptAcctHelp
static const struct Mapping AutocryptAcctHelp[]
Help Bar for the Autocrypt Account selection dialog.
Definition: dlgautocrypt.c:59
AutocryptAccount::keyid
char * keyid
Definition: lib.h:107
REDRAW_FULL
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:45
AutocryptAccount::enabled
bool enabled
Definition: lib.h:110
MUTT_NO
@ MUTT_NO
User answered 'No', or assume 'No'.
Definition: quad.h:39
Menu::title
const char * title
Title of this menu.
Definition: mutt_menu.h:54
mutt_addr_free
void mutt_addr_free(struct Address **ptr)
Free a single Address.
Definition: address.c:440
mutt_addr_new
struct Address * mutt_addr_new(void)
Create a new Address.
Definition: address.c:385
MuttWindow::help_data
const struct Mapping * help_data
Data for the Help Bar.
Definition: mutt_window.h:135
mutt_format_s
void mutt_format_s(char *buf, size_t buflen, const char *prec, const char *s)
Format a simple string.
Definition: curs_lib.c:1248
MENU_AUTOCRYPT_ACCT
@ MENU_AUTOCRYPT_ACCT
Autocrypt Account menu.
Definition: keymap.h:94
menu_free
static void menu_free(struct Menu **menu)
Free the Autocrypt account Menu.
Definition: dlgautocrypt.c:208
mutt_menu_loop
int mutt_menu_loop(struct Menu *menu)
Menu event loop.
Definition: menu.c:1309
MuttWindow::state
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:120
Address::mailbox
char * mailbox
Mailbox and host address.
Definition: address.h:37
mutt_menu_pop_current
void mutt_menu_pop_current(struct Menu *menu)
Remove a Menu from the stack.
Definition: menu.c:1027
mutt_autocrypt_init
int mutt_autocrypt_init(struct Mailbox *m, bool can_create)
Initialise Autocrypt.
Definition: autocrypt.c:95
Menu::mdata
void * mdata
Extra data for the current menu.
Definition: mutt_menu.h:55
mutt_expando_format
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t callback, intptr_t data, MuttFormatFlags flags)
Expand expandos (x) in a string.
Definition: muttlib.c:774
mutt_autocrypt_db_account_update
int mutt_autocrypt_db_account_update(struct AutocryptAccount *acct)
Update Account info in the Autocrypt database.
Definition: db.c:370
Menu::max
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
account_format_str
static const char * account_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
Format a string for the Autocrypt account list - Implements format_t.
Definition: dlgautocrypt.c:96
Menu::redraw
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
WindowState::cols
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:57
dialog_destroy_simple_index
void dialog_destroy_simple_index(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: dialog.c:209
Menu::current
int current
Current entry.
Definition: mutt_menu.h:56
toggle_active
static void toggle_active(struct AccountEntry *entry)
Toggle whether an Autocrypt account is active.
Definition: dlgautocrypt.c:227
mutt_yesorno
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
Definition: curs_lib.c:380
Menu::win_index
struct MuttWindow * win_index
Definition: mutt_menu.h:63
Menu
GUI selectable list of items.
Definition: mutt_menu.h:52
N_
#define N_(a)
Definition: message.h:32
AccountEntry::addr
struct Address * addr
Definition: dlgautocrypt.c:55
account_make_entry
static void account_make_entry(struct Menu *menu, char *buf, size_t buflen, int num)
Create a line for the Autocrypt account menu - Implements Menu::make_entry()
Definition: dlgautocrypt.c:153
mutt_autocrypt_db_account_get_all
int mutt_autocrypt_db_account_get_all(struct AutocryptAccount ***accounts, int *num_accounts)
Get all accounts from an Autocrypt database.
Definition: db.c:451
mutt_menu_free
void mutt_menu_free(struct Menu **ptr)
Destroy a menu.
Definition: menu.c:972
mutt_error
#define mutt_error(...)
Definition: logging.h:84