NeoMutt  2020-06-26-30-g76c339
Teaching an old dog new tricks
DOXYGEN
lib.h File Reference

Autocrypt end-to-end encryption. More...

#include <sqlite3.h>
#include <stdbool.h>
#include <stdio.h>
+ Include dependency graph for lib.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  AutocryptAccount
 Autocrypt account. More...
 
struct  AutocryptPeer
 Autocrypt peer. More...
 
struct  AutocryptPeerHistory
 Autocrypt peer history. More...
 
struct  AutocryptGossipHistory
 Autocrypt gossip history. More...
 

Enumerations

enum  AutocryptRec {
  AUTOCRYPT_REC_OFF, AUTOCRYPT_REC_NO, AUTOCRYPT_REC_DISCOURAGE, AUTOCRYPT_REC_AVAILABLE,
  AUTOCRYPT_REC_YES
}
 Recommendation. More...
 

Functions

void mutt_autocrypt_account_menu (void)
 Display the Autocrypt account Menu. More...
 
void mutt_autocrypt_cleanup (void)
 Shutdown Autocrypt. More...
 
int mutt_autocrypt_generate_gossip_list (struct Email *e)
 Create the gossip list headers. More...
 
int mutt_autocrypt_init (bool can_create)
 Initialise Autocrypt. More...
 
int mutt_autocrypt_process_autocrypt_header (struct Email *e, struct Envelope *env)
 Parse an Autocrypt email header. More...
 
int mutt_autocrypt_process_gossip_header (struct Email *e, struct Envelope *prot_headers)
 Parse an Autocrypt email gossip header. More...
 
int mutt_autocrypt_set_sign_as_default_key (struct Email *e)
 Set the Autocrypt default key for signing. More...
 
enum AutocryptRec mutt_autocrypt_ui_recommendation (struct Email *e, char **keylist)
 Get the recommended action for an Email. More...
 
int mutt_autocrypt_write_autocrypt_header (struct Envelope *env, FILE *fp)
 Write the Autocrypt header to a file. More...
 
int mutt_autocrypt_write_gossip_headers (struct Envelope *env, FILE *fp)
 Write the Autocrypt gossip headers to a file. More...
 

Detailed Description

Autocrypt end-to-end encryption.

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 lib.h.

Enumeration Type Documentation

◆ AutocryptRec

Recommendation.

Enumerator
AUTOCRYPT_REC_OFF 

No recommendations.

AUTOCRYPT_REC_NO 

Do no use Autocrypt.

AUTOCRYPT_REC_DISCOURAGE 

Prefer not to use Autocrypt.

AUTOCRYPT_REC_AVAILABLE 

Autocrypt is available.

AUTOCRYPT_REC_YES 

Autocrypt should be used.

Definition at line 152 of file lib.h.

153 {
159 };
Autocrypt should be used.
Definition: lib.h:158
No recommendations.
Definition: lib.h:154
Do no use Autocrypt.
Definition: lib.h:155
Prefer not to use Autocrypt.
Definition: lib.h:156
Autocrypt is available.
Definition: lib.h:157

Function Documentation

◆ mutt_autocrypt_account_menu()

void mutt_autocrypt_account_menu ( void  )

Display the Autocrypt account Menu.

Definition at line 260 of file acct_menu.c.

261 {
262  if (!C_Autocrypt)
263  return;
264 
265  if (mutt_autocrypt_init(false))
266  return;
267 
268  struct MuttWindow *dlg =
271 
272  struct MuttWindow *index =
275  index->notify = notify_new();
276  notify_set_parent(index->notify, dlg->notify);
277 
278  struct MuttWindow *ibar =
281  ibar->notify = notify_new();
282  notify_set_parent(ibar->notify, dlg->notify);
283 
284  if (C_StatusOnTop)
285  {
286  mutt_window_add_child(dlg, ibar);
287  mutt_window_add_child(dlg, index);
288  }
289  else
290  {
291  mutt_window_add_child(dlg, index);
292  mutt_window_add_child(dlg, ibar);
293  }
294 
295  dialog_push(dlg);
296 
297  struct Menu *menu = create_menu();
298  if (!menu)
299  return;
300 
301  menu->pagelen = index->state.rows;
302  menu->win_index = index;
303  menu->win_ibar = ibar;
304 
305  bool done = false;
306  while (!done)
307  {
308  switch (mutt_menu_loop(menu))
309  {
310  case OP_EXIT:
311  done = true;
312  break;
313 
314  case OP_AUTOCRYPT_CREATE_ACCT:
315  if (mutt_autocrypt_account_init(false))
316  break;
317 
318  menu_free(&menu);
319  menu = create_menu();
320  menu->pagelen = index->state.rows;
321  menu->win_index = index;
322  menu->win_ibar = ibar;
323  break;
324 
325  case OP_AUTOCRYPT_DELETE_ACCT:
326  {
327  if (!menu->mdata)
328  break;
329 
330  struct AccountEntry *entry = (struct AccountEntry *) (menu->mdata) + menu->current;
331  char msg[128];
332  snprintf(msg, sizeof(msg),
333  // L10N: Confirmation message when deleting an autocrypt account
334  _("Really delete account \"%s\"?"), entry->addr->mailbox);
335  if (mutt_yesorno(msg, MUTT_NO) != MUTT_YES)
336  break;
337 
339  {
340  menu_free(&menu);
341  menu = create_menu();
342  menu->pagelen = index->state.rows;
343  menu->win_index = index;
344  menu->win_ibar = ibar;
345  }
346  break;
347  }
348 
349  case OP_AUTOCRYPT_TOGGLE_ACTIVE:
350  {
351  if (!menu->mdata)
352  break;
353 
354  struct AccountEntry *entry = (struct AccountEntry *) (menu->mdata) + menu->current;
355  toggle_active(entry);
356  menu->redraw |= REDRAW_FULL;
357  break;
358  }
359 
360  case OP_AUTOCRYPT_TOGGLE_PREFER:
361  {
362  if (!menu->mdata)
363  break;
364 
365  struct AccountEntry *entry = (struct AccountEntry *) (menu->mdata) + menu->current;
366  toggle_prefer_encrypt(entry);
367  menu->redraw |= REDRAW_FULL;
368  break;
369  }
370  }
371  }
372 
373  menu_free(&menu);
374  dialog_pop();
375  mutt_window_free(&dlg);
376 }
int mutt_autocrypt_init(bool can_create)
Initialise Autocrypt.
Definition: autocrypt.c:92
WHERE bool C_StatusOnTop
Config: Display the status bar at the top.
Definition: globals.h:247
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:45
WHERE bool C_Autocrypt
Config: Enables the Autocrypt feature.
Definition: globals.h:195
GUI selectable list of items.
Definition: mutt_menu.h:80
Window uses all available vertical space.
Definition: mutt_window.h:35
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:40
void dialog_pop(void)
Hide a Window from the user.
Definition: mutt_window.c:722
void dialog_push(struct MuttWindow *dlg)
Display a Window to the user.
Definition: mutt_window.c:697
#define _(a)
Definition: message.h:28
char * mailbox
Mailbox and host address.
Definition: address.h:37
A division of the screen.
Definition: mutt_window.h:108
static void menu_free(struct Menu **menu)
Free the Autocrypt account Menu.
Definition: acct_menu.c:211
int mutt_autocrypt_account_init(bool prompt)
Create a new Autocrypt account.
Definition: autocrypt.c:146
An Index Window containing a selection list.
Definition: mutt_window.h:93
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:150
int mutt_autocrypt_db_account_delete(struct AutocryptAccount *acct)
Delete an Account from the Autocrypt database.
Definition: db.c:415
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
Definition: curs_lib.c:377
struct Notify * notify
Notifications system.
Definition: mutt_window.h:123
An entry in the Autocrypt account Menu.
Definition: acct_menu.c:50
struct MuttWindow * win_ibar
Definition: mutt_menu.h:93
static struct Menu * create_menu(void)
Create the Autocrypt account Menu.
Definition: acct_menu.c:167
static void toggle_active(struct AccountEntry *entry)
Toggle whether an Autocrypt account is active.
Definition: acct_menu.c:231
Window has a fixed size.
Definition: mutt_window.h:44
Autocrypt Dialog, mutt_autocrypt_account_menu()
Definition: mutt_window.h:76
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:49
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:113
void * mdata
Extra data for the current menu.
Definition: mutt_menu.h:84
User answered &#39;No&#39;, or assume &#39;No&#39;.
Definition: quad.h:39
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:49
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:58
struct Address * addr
Definition: acct_menu.c:55
static void toggle_prefer_encrypt(struct AccountEntry *entry)
Toggle whether an Autocrypt account prefers encryption.
Definition: acct_menu.c:247
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:89
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:564
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:87
struct AutocryptAccount * account
Definition: acct_menu.c:54
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
Definition: mutt_window.c:131
int current
Current entry.
Definition: mutt_menu.h:85
struct MuttWindow * win_index
Definition: mutt_menu.h:92
Window wants as much space as possible.
Definition: mutt_window.h:45
Index Bar containing status info about the Index.
Definition: mutt_window.h:94
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_cleanup()

void mutt_autocrypt_cleanup ( void  )

Shutdown Autocrypt.

Definition at line 132 of file autocrypt.c.

133 {
135 }
void mutt_autocrypt_db_close(void)
Close the Autocrypt SQLite database connection.
Definition: db.c:126
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_generate_gossip_list()

int mutt_autocrypt_generate_gossip_list ( struct Email e)

Create the gossip list headers.

Parameters
eEmail
Return values
0Success
-1Error

Definition at line 783 of file autocrypt.c.

784 {
785  int rc = -1;
786  struct AutocryptPeer *peer = NULL;
787  struct AutocryptAccount *account = NULL;
788  struct Address *recip = NULL;
789 
790  if (!C_Autocrypt || mutt_autocrypt_init(false) || !e)
791  return -1;
792 
793  struct Envelope *mime_headers = e->content->mime_headers;
794  if (!mime_headers)
795  mime_headers = e->content->mime_headers = mutt_env_new();
797 
798  struct AddressList recips = TAILQ_HEAD_INITIALIZER(recips);
799 
800  mutt_addrlist_copy(&recips, &e->env->to, false);
801  mutt_addrlist_copy(&recips, &e->env->cc, false);
802 
803  TAILQ_FOREACH(recip, &recips, entries)
804  {
805  /* At this point, we just accept missing keys and include what we can. */
806  if (mutt_autocrypt_db_peer_get(recip, &peer) <= 0)
807  continue;
808 
809  const char *keydata = NULL;
811  keydata = peer->keydata;
813  keydata = peer->gossip_keydata;
814 
815  if (keydata)
816  {
817  struct AutocryptHeader *gossip = mutt_autocrypthdr_new();
818  gossip->addr = mutt_str_dup(peer->email_addr);
819  gossip->keydata = mutt_str_dup(keydata);
820  gossip->next = mime_headers->autocrypt_gossip;
821  mime_headers->autocrypt_gossip = gossip;
822  }
823 
825  }
826 
827  TAILQ_FOREACH(recip, &e->env->reply_to, entries)
828  {
829  const char *addr = NULL;
830  const char *keydata = NULL;
831  if (mutt_autocrypt_db_account_get(recip, &account) > 0)
832  {
833  addr = account->email_addr;
834  keydata = account->keydata;
835  }
836  else if (mutt_autocrypt_db_peer_get(recip, &peer) > 0)
837  {
838  addr = peer->email_addr;
840  keydata = peer->keydata;
842  keydata = peer->gossip_keydata;
843  }
844 
845  if (keydata)
846  {
847  struct AutocryptHeader *gossip = mutt_autocrypthdr_new();
848  gossip->addr = mutt_str_dup(addr);
849  gossip->keydata = mutt_str_dup(keydata);
850  gossip->next = mime_headers->autocrypt_gossip;
851  mime_headers->autocrypt_gossip = gossip;
852  }
855  }
856 
857  mutt_addrlist_clear(&recips);
860  return rc;
861 }
int mutt_autocrypt_init(bool can_create)
Initialise Autocrypt.
Definition: autocrypt.c:92
WHERE bool C_Autocrypt
Config: Enables the Autocrypt feature.
Definition: globals.h:195
struct Envelope * mime_headers
Memory hole protected headers.
Definition: body.h:63
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
struct AutocryptHeader * autocrypt_gossip
Definition: envelope.h:86
void mutt_autocrypt_db_account_free(struct AutocryptAccount **ptr)
Free an AutocryptAccount.
Definition: db.c:240
struct AddressList reply_to
Email&#39;s &#39;reply-to&#39;.
Definition: envelope.h:62
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1414
char * keydata
Definition: lib.h:119
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition: address.c:737
struct Body * content
List of MIME parts.
Definition: email.h:90
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:375
An email address.
Definition: address.h:34
struct AutocryptHeader * mutt_autocrypthdr_new(void)
Create a new AutocryptHeader.
Definition: envelope.c:65
char * email_addr
Definition: lib.h:103
char * gossip_keydata
Definition: lib.h:123
Autocrypt peer.
Definition: lib.h:113
char * keydata
Definition: envelope.h:44
struct Envelope * env
Envelope information.
Definition: email.h:89
struct AddressList cc
Email&#39;s &#39;Cc&#39; list.
Definition: envelope.h:59
char * email_addr
Definition: lib.h:115
struct Envelope * mutt_env_new(void)
Create a new Envelope.
Definition: envelope.c:42
bool mutt_autocrypt_gpgme_is_valid_key(const char *keyid)
Is a key id valid?
Definition: gpgme.c:352
struct AutocryptHeader * next
Definition: envelope.h:47
char * gossip_keyid
Definition: lib.h:122
char * addr
Definition: envelope.h:43
Parse Autocrypt header info.
Definition: envelope.h:41
int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
Get Autocrypt Account data from the database.
Definition: db.c:259
Autocrypt account.
Definition: lib.h:101
void mutt_autocrypthdr_free(struct AutocryptHeader **p)
Free an AutocryptHeader.
Definition: envelope.c:74
char * keydata
Definition: lib.h:105
void mutt_autocrypt_db_peer_free(struct AutocryptPeer **ptr)
Free an AutocryptPeer.
Definition: db.c:524
struct AddressList to
Email&#39;s &#39;To&#39; list.
Definition: envelope.h:58
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:630
char * keyid
Definition: lib.h:118
int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
Get peer info from the Autocrypt database.
Definition: db.c:546
The header of an Email.
Definition: envelope.h:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_init()

int mutt_autocrypt_init ( bool  can_create)

Initialise Autocrypt.

Parameters
can_createIf true, directories may be created
Return values
0Success
-1Error

Definition at line 92 of file autocrypt.c.

93 {
94  if (AutocryptDB)
95  return 0;
96 
97  if (!C_Autocrypt || !C_AutocryptDir)
98  return -1;
99 
100  OptIgnoreMacroEvents = true;
101  /* The init process can display menus at various points
102  *(e.g. browser, pgp key selection). This allows the screen to be
103  * autocleared after each menu, so the subsequent prompts can be
104  * read. */
105  OptMenuPopClearScreen = true;
106 
107  if (autocrypt_dir_init(can_create))
108  goto bail;
109 
111  goto bail;
112 
113  if (mutt_autocrypt_db_init(can_create))
114  goto bail;
115 
116  OptIgnoreMacroEvents = false;
117  OptMenuPopClearScreen = false;
118 
119  return 0;
120 
121 bail:
122  OptIgnoreMacroEvents = false;
123  OptMenuPopClearScreen = false;
124  C_Autocrypt = false;
126  return -1;
127 }
void mutt_autocrypt_db_close(void)
Close the Autocrypt SQLite database connection.
Definition: db.c:126
sqlite3 * AutocryptDB
Definition: db.c:51
WHERE bool C_Autocrypt
Config: Enables the Autocrypt feature.
Definition: globals.h:195
int mutt_autocrypt_gpgme_init(void)
Initialise GPGME.
Definition: gpgme.c:65
static int autocrypt_dir_init(bool can_create)
Initialise an Autocrypt directory.
Definition: autocrypt.c:55
WHERE bool OptIgnoreMacroEvents
(pseudo) don&#39;t process macro/push/exec events while set
Definition: options.h:38
int mutt_autocrypt_db_init(bool can_create)
Initialise the Autocrypt SQLite database.
Definition: db.c:78
WHERE bool OptMenuPopClearScreen
(pseudo) clear the screen when popping the last menu
Definition: options.h:40
WHERE char * C_AutocryptDir
Config: Location of autocrypt files, including the GPG keyring and SQLite database.
Definition: globals.h:102
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_process_autocrypt_header()

int mutt_autocrypt_process_autocrypt_header ( struct Email e,
struct Envelope env 
)

Parse an Autocrypt email header.

Parameters
eEmail
envEnvelope
Return values
0Success
-1Error

Definition at line 249 of file autocrypt.c.

250 {
251  struct AutocryptHeader *valid_ac_hdr = NULL;
252  struct AutocryptPeer *peer = NULL;
253  struct AutocryptPeerHistory *peerhist = NULL;
254  struct Buffer *keyid = NULL;
255  bool update_db = false, insert_db = false, insert_db_history = false, import_gpg = false;
256  int rc = -1;
257 
258  if (!C_Autocrypt)
259  return 0;
260 
261  if (mutt_autocrypt_init(false))
262  return -1;
263 
264  if (!e || !e->content || !env)
265  return 0;
266 
267  /* 1.1 spec says to skip emails with more than one From header */
268  struct Address *from = TAILQ_FIRST(&env->from);
269  if (!from || TAILQ_NEXT(from, entries))
270  return 0;
271 
272  /* 1.1 spec also says to skip multipart/report emails */
273  if ((e->content->type == TYPE_MULTIPART) && mutt_istr_equal(e->content->subtype, "report"))
274  {
275  return 0;
276  }
277 
278  /* Ignore emails that appear to be more than a week in the future,
279  * since they can block all future updates during that time. */
280  if (e->date_sent > (mutt_date_epoch() + (7 * 24 * 60 * 60)))
281  return 0;
282 
283  for (struct AutocryptHeader *ac_hdr = env->autocrypt; ac_hdr; ac_hdr = ac_hdr->next)
284  {
285  if (ac_hdr->invalid)
286  continue;
287 
288  /* NOTE: this assumes the processing is occurring right after
289  * mutt_parse_rfc822_line() and the from ADDR is still in the same
290  * form (intl) as the autocrypt header addr field */
291  if (!mutt_istr_equal(from->mailbox, ac_hdr->addr))
292  continue;
293 
294  /* 1.1 spec says ignore all, if more than one valid header is found. */
295  if (valid_ac_hdr)
296  {
297  valid_ac_hdr = NULL;
298  break;
299  }
300  valid_ac_hdr = ac_hdr;
301  }
302 
303  if (mutt_autocrypt_db_peer_get(from, &peer) < 0)
304  goto cleanup;
305 
306  if (peer)
307  {
308  if (e->date_sent <= peer->autocrypt_timestamp)
309  {
310  rc = 0;
311  goto cleanup;
312  }
313 
314  if (e->date_sent > peer->last_seen)
315  {
316  update_db = true;
317  peer->last_seen = e->date_sent;
318  }
319 
320  if (valid_ac_hdr)
321  {
322  update_db = true;
323  peer->autocrypt_timestamp = e->date_sent;
324  peer->prefer_encrypt = valid_ac_hdr->prefer_encrypt;
325  if (!mutt_str_equal(peer->keydata, valid_ac_hdr->keydata))
326  {
327  import_gpg = true;
328  insert_db_history = true;
329  mutt_str_replace(&peer->keydata, valid_ac_hdr->keydata);
330  }
331  }
332  }
333  else if (valid_ac_hdr)
334  {
335  import_gpg = true;
336  insert_db = true;
337  insert_db_history = true;
338  }
339 
340  if (!(import_gpg || insert_db || update_db))
341  {
342  rc = 0;
343  goto cleanup;
344  }
345 
346  if (!peer)
347  {
349  peer->last_seen = e->date_sent;
350  peer->autocrypt_timestamp = e->date_sent;
351  peer->keydata = mutt_str_dup(valid_ac_hdr->keydata);
352  peer->prefer_encrypt = valid_ac_hdr->prefer_encrypt;
353  }
354 
355  if (import_gpg)
356  {
357  keyid = mutt_buffer_pool_get();
358  if (mutt_autocrypt_gpgme_import_key(peer->keydata, keyid))
359  goto cleanup;
360  mutt_str_replace(&peer->keyid, mutt_b2s(keyid));
361  }
362 
363  if (insert_db && mutt_autocrypt_db_peer_insert(from, peer))
364  goto cleanup;
365 
366  if (update_db && mutt_autocrypt_db_peer_update(peer))
367  goto cleanup;
368 
369  if (insert_db_history)
370  {
372  peerhist->email_msgid = mutt_str_dup(env->message_id);
373  peerhist->timestamp = e->date_sent;
374  peerhist->keydata = mutt_str_dup(peer->keydata);
375  if (mutt_autocrypt_db_peer_history_insert(from, peerhist))
376  goto cleanup;
377  }
378 
379  rc = 0;
380 
381 cleanup:
384  mutt_buffer_pool_release(&keyid);
385 
386  return rc;
387 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:879
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:414
int mutt_autocrypt_init(bool can_create)
Initialise Autocrypt.
Definition: autocrypt.c:92
WHERE bool C_Autocrypt
Config: Enables the Autocrypt feature.
Definition: globals.h:195
struct AutocryptPeerHistory * mutt_autocrypt_db_peer_history_new(void)
Create a new AutocryptPeerHistory.
Definition: db.c:730
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define TAILQ_FIRST(head)
Definition: queue.h:716
bool prefer_encrypt
Definition: envelope.h:45
char * email_msgid
Definition: lib.h:132
char * keydata
Definition: lib.h:119
sqlite3_int64 timestamp
Definition: lib.h:133
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
struct Body * content
List of MIME parts.
Definition: email.h:90
struct AutocryptPeer * mutt_autocrypt_db_peer_new(void)
Create a new AutocryptPeer.
Definition: db.c:515
String manipulation buffer.
Definition: buffer.h:33
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:375
An email address.
Definition: address.h:34
struct AutocryptHeader * autocrypt
Definition: envelope.h:85
char * mailbox
Mailbox and host address.
Definition: address.h:37
sqlite3_int64 autocrypt_timestamp
Definition: lib.h:117
char * message_id
Message ID.
Definition: envelope.h:69
Autocrypt peer.
Definition: lib.h:113
char * keydata
Definition: envelope.h:44
struct AddressList from
Email&#39;s &#39;From&#39; list.
Definition: envelope.h:57
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:891
char * subtype
content-type subtype
Definition: body.h:37
time_t date_sent
Time when the message was sent (UTC)
Definition: email.h:81
#define mutt_b2s(buf)
Definition: buffer.h:41
sqlite3_int64 last_seen
Definition: lib.h:116
int mutt_autocrypt_db_peer_insert(struct Address *addr, struct AutocryptPeer *peer)
Insert a peer into the Autocrypt database.
Definition: db.c:611
struct AutocryptHeader * next
Definition: envelope.h:47
Autocrypt peer history.
Definition: lib.h:129
Parse Autocrypt header info.
Definition: envelope.h:41
void mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:450
unsigned int type
content-type primary type, ContentType
Definition: body.h:65
int mutt_autocrypt_db_peer_history_insert(struct Address *addr, struct AutocryptPeerHistory *peerhist)
Insert peer history into the Autocrypt database.
Definition: db.c:758
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:120
char * keydata
Definition: lib.h:134
int mutt_autocrypt_db_peer_update(struct AutocryptPeer *peer)
Update the peer info in an Autocrypt database.
Definition: db.c:674
Type: &#39;multipart/*&#39;.
Definition: mime.h:37
void mutt_autocrypt_db_peer_free(struct AutocryptPeer **ptr)
Free an AutocryptPeer.
Definition: db.c:524
#define TAILQ_NEXT(elm, field)
Definition: queue.h:825
void mutt_autocrypt_db_peer_history_free(struct AutocryptPeerHistory **ptr)
Free an AutocryptPeerHistory.
Definition: db.c:739
char * keyid
Definition: lib.h:118
int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
Get peer info from the Autocrypt database.
Definition: db.c:546
int mutt_autocrypt_gpgme_import_key(const char *keydata, struct Buffer *keyid)
Read a key from GPGME.
Definition: gpgme.c:314

◆ mutt_autocrypt_process_gossip_header()

int mutt_autocrypt_process_gossip_header ( struct Email e,
struct Envelope prot_headers 
)

Parse an Autocrypt email gossip header.

Parameters
eEmail
prot_headersEnvelope with protected headers
Return values
0Success
-1Error

Definition at line 396 of file autocrypt.c.

397 {
398  struct AutocryptPeer *peer = NULL;
399  struct AutocryptGossipHistory *gossip_hist = NULL;
400  struct Address *peer_addr = NULL;
401  struct Address ac_hdr_addr = { 0 };
402  bool update_db = false, insert_db = false, insert_db_history = false, import_gpg = false;
403  int rc = -1;
404 
405  if (!C_Autocrypt)
406  return 0;
407 
408  if (mutt_autocrypt_init(false))
409  return -1;
410 
411  if (!e || !e->env || !prot_headers)
412  return 0;
413 
414  struct Envelope *env = e->env;
415 
416  struct Address *from = TAILQ_FIRST(&env->from);
417  if (!from)
418  return 0;
419 
420  /* Ignore emails that appear to be more than a week in the future,
421  * since they can block all future updates during that time. */
422  if (e->date_sent > (mutt_date_epoch() + (7 * 24 * 60 * 60)))
423  return 0;
424 
425  struct Buffer *keyid = mutt_buffer_pool_get();
426 
427  struct AddressList recips = TAILQ_HEAD_INITIALIZER(recips);
428 
429  /* Normalize the recipient list for comparison */
430  mutt_addrlist_copy(&recips, &env->to, false);
431  mutt_addrlist_copy(&recips, &env->cc, false);
432  mutt_addrlist_copy(&recips, &env->reply_to, false);
434 
435  for (struct AutocryptHeader *ac_hdr = prot_headers->autocrypt_gossip; ac_hdr;
436  ac_hdr = ac_hdr->next)
437  {
438  if (ac_hdr->invalid)
439  continue;
440 
441  /* normalize for comparison against recipient list */
442  mutt_str_replace(&ac_hdr_addr.mailbox, ac_hdr->addr);
443  ac_hdr_addr.is_intl = true;
444  ac_hdr_addr.intl_checked = true;
445  mutt_autocrypt_db_normalize_addr(&ac_hdr_addr);
446 
447  /* Check to make sure the address is in the recipient list. */
448  TAILQ_FOREACH(peer_addr, &recips, entries)
449  {
450  if (mutt_str_equal(peer_addr->mailbox, ac_hdr_addr.mailbox))
451  break;
452  }
453 
454  if (!peer_addr)
455  continue;
456 
457  if (mutt_autocrypt_db_peer_get(peer_addr, &peer) < 0)
458  goto cleanup;
459 
460  if (peer)
461  {
462  if (e->date_sent <= peer->gossip_timestamp)
463  {
465  continue;
466  }
467 
468  update_db = true;
469  peer->gossip_timestamp = e->date_sent;
470  /* This is slightly different from the autocrypt 1.1 spec.
471  * Avoid setting an empty peer.gossip_keydata with a value that matches
472  * the current peer.keydata. */
473  if ((peer->gossip_keydata && !mutt_str_equal(peer->gossip_keydata, ac_hdr->keydata)) ||
474  (!peer->gossip_keydata && !mutt_str_equal(peer->keydata, ac_hdr->keydata)))
475  {
476  import_gpg = true;
477  insert_db_history = true;
478  mutt_str_replace(&peer->gossip_keydata, ac_hdr->keydata);
479  }
480  }
481  else
482  {
483  import_gpg = true;
484  insert_db = true;
485  insert_db_history = true;
486  }
487 
488  if (!peer)
489  {
491  peer->gossip_timestamp = e->date_sent;
492  peer->gossip_keydata = mutt_str_dup(ac_hdr->keydata);
493  }
494 
495  if (import_gpg)
496  {
498  goto cleanup;
499  mutt_str_replace(&peer->gossip_keyid, mutt_b2s(keyid));
500  }
501 
502  if (insert_db && mutt_autocrypt_db_peer_insert(peer_addr, peer))
503  goto cleanup;
504 
505  if (update_db && mutt_autocrypt_db_peer_update(peer))
506  goto cleanup;
507 
508  if (insert_db_history)
509  {
510  gossip_hist = mutt_autocrypt_db_gossip_history_new();
511  gossip_hist->sender_email_addr = mutt_str_dup(from->mailbox);
512  gossip_hist->email_msgid = mutt_str_dup(env->message_id);
513  gossip_hist->timestamp = e->date_sent;
514  gossip_hist->gossip_keydata = mutt_str_dup(peer->gossip_keydata);
515  if (mutt_autocrypt_db_gossip_history_insert(peer_addr, gossip_hist))
516  goto cleanup;
517  }
518 
521  mutt_buffer_reset(keyid);
522  update_db = false;
523  insert_db = false;
524  insert_db_history = false;
525  import_gpg = false;
526  }
527 
528  rc = 0;
529 
530 cleanup:
531  FREE(&ac_hdr_addr.mailbox);
532  mutt_addrlist_clear(&recips);
535  mutt_buffer_pool_release(&keyid);
536 
537  return rc;
538 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:879
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:414
int mutt_autocrypt_init(bool can_create)
Initialise Autocrypt.
Definition: autocrypt.c:92
void mutt_autocrypt_db_normalize_addr(struct Address *a)
Normalise an Email Address.
Definition: db.c:161
WHERE bool C_Autocrypt
Config: Enables the Autocrypt feature.
Definition: globals.h:195
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define TAILQ_FIRST(head)
Definition: queue.h:716
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
struct AutocryptHeader * autocrypt_gossip
Definition: envelope.h:86
struct AddressList reply_to
Email&#39;s &#39;reply-to&#39;.
Definition: envelope.h:62
void mutt_autocrypt_db_gossip_history_free(struct AutocryptGossipHistory **ptr)
Free an AutocryptGossipHistory.
Definition: db.c:815
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1414
char * keydata
Definition: lib.h:119
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition: address.c:737
struct AutocryptPeer * mutt_autocrypt_db_peer_new(void)
Create a new AutocryptPeer.
Definition: db.c:515
String manipulation buffer.
Definition: buffer.h:33
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:375
An email address.
Definition: address.h:34
char * mailbox
Mailbox and host address.
Definition: address.h:37
char * gossip_keydata
Definition: lib.h:123
bool is_intl
International Domain Name.
Definition: address.h:39
sqlite3_int64 gossip_timestamp
Definition: lib.h:121
char * sender_email_addr
Definition: lib.h:143
char * message_id
Message ID.
Definition: envelope.h:69
Autocrypt peer.
Definition: lib.h:113
char * email_msgid
Definition: lib.h:144
struct AddressList from
Email&#39;s &#39;From&#39; list.
Definition: envelope.h:57
struct Envelope * env
Envelope information.
Definition: email.h:89
struct AddressList cc
Email&#39;s &#39;Cc&#39; list.
Definition: envelope.h:59
bool intl_checked
Checked for IDN?
Definition: address.h:40
time_t date_sent
Time when the message was sent (UTC)
Definition: email.h:81
#define mutt_b2s(buf)
Definition: buffer.h:41
Autocrypt gossip history.
Definition: lib.h:140
int mutt_autocrypt_db_peer_insert(struct Address *addr, struct AutocryptPeer *peer)
Insert a peer into the Autocrypt database.
Definition: db.c:611
struct AutocryptHeader * next
Definition: envelope.h:47
char * gossip_keyid
Definition: lib.h:122
struct AutocryptGossipHistory * mutt_autocrypt_db_gossip_history_new(void)
Create a new AutocryptGossipHistory.
Definition: db.c:806
Parse Autocrypt header info.
Definition: envelope.h:41
void mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:450
void mutt_autocrypt_db_normalize_addrlist(struct AddressList *al)
Normalise a list of Email Addresses.
Definition: db.c:172
int mutt_autocrypt_db_peer_update(struct AutocryptPeer *peer)
Update the peer info in an Autocrypt database.
Definition: db.c:674
#define FREE(x)
Definition: memory.h:40
void mutt_autocrypt_db_peer_free(struct AutocryptPeer **ptr)
Free an AutocryptPeer.
Definition: db.c:524
struct AddressList to
Email&#39;s &#39;To&#39; list.
Definition: envelope.h:58
char * gossip_keydata
Definition: lib.h:146
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:630
int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
Get peer info from the Autocrypt database.
Definition: db.c:546
int mutt_autocrypt_db_gossip_history_insert(struct Address *addr, struct AutocryptGossipHistory *gossip_hist)
Insert a gossip history into the Autocrypt database.
Definition: db.c:835
sqlite3_int64 timestamp
Definition: lib.h:145
The header of an Email.
Definition: envelope.h:54
int mutt_autocrypt_gpgme_import_key(const char *keydata, struct Buffer *keyid)
Read a key from GPGME.
Definition: gpgme.c:314
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_set_sign_as_default_key()

int mutt_autocrypt_set_sign_as_default_key ( struct Email e)

Set the Autocrypt default key for signing.

Parameters
eEmail
Return values
0Success
-1Error

Definition at line 660 of file autocrypt.c.

661 {
662  int rc = -1;
663  struct AutocryptAccount *account = NULL;
664 
665  if (!C_Autocrypt || mutt_autocrypt_init(false) || !e)
666  return -1;
667 
668  struct Address *from = TAILQ_FIRST(&e->env->from);
669  if (!from || TAILQ_NEXT(from, entries))
670  return -1;
671 
672  if (mutt_autocrypt_db_account_get(from, &account) <= 0)
673  goto cleanup;
674  if (!account->keyid)
675  goto cleanup;
676  if (!account->enabled)
677  goto cleanup;
678 
681 
682  rc = 0;
683 
684 cleanup:
686  return rc;
687 }
int mutt_autocrypt_init(bool can_create)
Initialise Autocrypt.
Definition: autocrypt.c:92
WHERE bool C_Autocrypt
Config: Enables the Autocrypt feature.
Definition: globals.h:195
#define TAILQ_FIRST(head)
Definition: queue.h:716
void mutt_autocrypt_db_account_free(struct AutocryptAccount **ptr)
Free an AutocryptAccount.
Definition: db.c:240
WHERE char * AutocryptDefaultKey
Autocrypt default key id (used for postponing messages)
Definition: globals.h:86
An email address.
Definition: address.h:34
char * keyid
Definition: lib.h:104
bool enabled
Definition: lib.h:107
struct AddressList from
Email&#39;s &#39;From&#39; list.
Definition: envelope.h:57
struct Envelope * env
Envelope information.
Definition: email.h:89
void mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:450
int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
Get Autocrypt Account data from the database.
Definition: db.c:259
Autocrypt account.
Definition: lib.h:101
#define TAILQ_NEXT(elm, field)
Definition: queue.h:825
WHERE char * AutocryptSignAs
Autocrypt Key id to sign as.
Definition: globals.h:85
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_ui_recommendation()

enum AutocryptRec mutt_autocrypt_ui_recommendation ( struct Email e,
char **  keylist 
)

Get the recommended action for an Email.

Parameters
[in]eEmail
[out]keylistList of Autocrypt key ids
Return values
numRecommendation, e.g. AUTOCRYPT_REC_AVAILABLE

If the recommendataion is > NO and keylist is not NULL, keylist will be populated with the autocrypt keyids.

Definition at line 549 of file autocrypt.c.

550 {
552  struct AutocryptAccount *account = NULL;
553  struct AutocryptPeer *peer = NULL;
554  struct Address *recip = NULL;
555  bool all_encrypt = true, has_discourage = false;
556  const char *matching_key = NULL;
557  struct AddressList recips = TAILQ_HEAD_INITIALIZER(recips);
558  struct Buffer *keylist_buf = NULL;
559 
560  if (!C_Autocrypt || mutt_autocrypt_init(false) || !e)
561  return AUTOCRYPT_REC_OFF;
562 
563  struct Address *from = TAILQ_FIRST(&e->env->from);
564  if (!from || TAILQ_NEXT(from, entries))
565  return AUTOCRYPT_REC_OFF;
566 
567  if (e->security & APPLICATION_SMIME)
568  return AUTOCRYPT_REC_OFF;
569 
570  if (mutt_autocrypt_db_account_get(from, &account) <= 0)
571  goto cleanup;
572 
573  if (!account->enabled)
574  goto cleanup;
575 
576  keylist_buf = mutt_buffer_pool_get();
577  mutt_buffer_addstr(keylist_buf, account->keyid);
578 
579  mutt_addrlist_copy(&recips, &e->env->to, false);
580  mutt_addrlist_copy(&recips, &e->env->cc, false);
581  mutt_addrlist_copy(&recips, &e->env->bcc, false);
582 
583  rc = AUTOCRYPT_REC_NO;
584  if (TAILQ_EMPTY(&recips))
585  goto cleanup;
586 
587  TAILQ_FOREACH(recip, &recips, entries)
588  {
589  if (mutt_autocrypt_db_peer_get(recip, &peer) <= 0)
590  {
591  if (keylist)
592  {
593  /* L10N: s is an email address. Autocrypt is scanning for the keyids
594  to use to encrypt, but it can't find a valid keyid for this address.
595  The message is printed and they are returned to the compose menu. */
596  mutt_message(_("No (valid) autocrypt key found for %s"), recip->mailbox);
597  }
598  goto cleanup;
599  }
600 
602  {
603  matching_key = peer->keyid;
604 
605  if (!(peer->last_seen && peer->autocrypt_timestamp) ||
606  (peer->last_seen - peer->autocrypt_timestamp > (35 * 24 * 60 * 60)))
607  {
608  has_discourage = true;
609  all_encrypt = false;
610  }
611 
612  if (!account->prefer_encrypt || !peer->prefer_encrypt)
613  all_encrypt = false;
614  }
616  {
617  matching_key = peer->gossip_keyid;
618 
619  has_discourage = true;
620  all_encrypt = false;
621  }
622  else
623  {
624  if (keylist)
625  mutt_message(_("No (valid) autocrypt key found for %s"), recip->mailbox);
626  goto cleanup;
627  }
628 
629  if (!mutt_buffer_is_empty(keylist_buf))
630  mutt_buffer_addch(keylist_buf, ' ');
631  mutt_buffer_addstr(keylist_buf, matching_key);
632 
634  }
635 
636  if (all_encrypt)
637  rc = AUTOCRYPT_REC_YES;
638  else if (has_discourage)
640  else
642 
643  if (keylist)
644  mutt_str_replace(keylist, mutt_b2s(keylist_buf));
645 
646 cleanup:
648  mutt_addrlist_clear(&recips);
650  mutt_buffer_pool_release(&keylist_buf);
651  return rc;
652 }
int mutt_autocrypt_init(bool can_create)
Initialise Autocrypt.
Definition: autocrypt.c:92
AutocryptRec
Recommendation.
Definition: lib.h:152
WHERE bool C_Autocrypt
Config: Enables the Autocrypt feature.
Definition: globals.h:195
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define TAILQ_FIRST(head)
Definition: queue.h:716
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
void mutt_autocrypt_db_account_free(struct AutocryptAccount **ptr)
Free an AutocryptAccount.
Definition: db.c:240
#define mutt_message(...)
Definition: logging.h:83
Autocrypt should be used.
Definition: lib.h:158
struct AddressList bcc
Email&#39;s &#39;Bcc&#39; list.
Definition: envelope.h:60
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1414
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition: address.c:737
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
An email address.
Definition: address.h:34
char * mailbox
Mailbox and host address.
Definition: address.h:37
No recommendations.
Definition: lib.h:154
char * keyid
Definition: lib.h:104
Do no use Autocrypt.
Definition: lib.h:155
sqlite3_int64 autocrypt_timestamp
Definition: lib.h:117
bool enabled
Definition: lib.h:107
Autocrypt peer.
Definition: lib.h:113
struct AddressList from
Email&#39;s &#39;From&#39; list.
Definition: envelope.h:57
struct Envelope * env
Envelope information.
Definition: email.h:89
struct AddressList cc
Email&#39;s &#39;Cc&#39; list.
Definition: envelope.h:59
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:106
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
#define mutt_b2s(buf)
Definition: buffer.h:41
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:138
bool mutt_autocrypt_gpgme_is_valid_key(const char *keyid)
Is a key id valid?
Definition: gpgme.c:352
sqlite3_int64 last_seen
Definition: lib.h:116
char * gossip_keyid
Definition: lib.h:122
Prefer not to use Autocrypt.
Definition: lib.h:156
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:240
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib...
Definition: email.h:39
void mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:450
int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
Get Autocrypt Account data from the database.
Definition: db.c:259
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:120
Autocrypt account.
Definition: lib.h:101
void mutt_autocrypt_db_peer_free(struct AutocryptPeer **ptr)
Free an AutocryptPeer.
Definition: db.c:524
Autocrypt is available.
Definition: lib.h:157
struct AddressList to
Email&#39;s &#39;To&#39; list.
Definition: envelope.h:58
#define TAILQ_NEXT(elm, field)
Definition: queue.h:825
#define TAILQ_EMPTY(head)
Definition: queue.h:714
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:252
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:630
char * keyid
Definition: lib.h:118
int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
Get peer info from the Autocrypt database.
Definition: db.c:546
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_write_autocrypt_header()

int mutt_autocrypt_write_autocrypt_header ( struct Envelope env,
FILE *  fp 
)

Write the Autocrypt header to a file.

Parameters
envEnvelope
fpFile to write to
Return values
0Success
-1Error

Definition at line 725 of file autocrypt.c.

726 {
727  int rc = -1;
728  struct AutocryptAccount *account = NULL;
729 
730  if (!C_Autocrypt || mutt_autocrypt_init(false) || !env)
731  return -1;
732 
733  struct Address *from = TAILQ_FIRST(&env->from);
734  if (!from || TAILQ_NEXT(from, entries))
735  return -1;
736 
737  if (mutt_autocrypt_db_account_get(from, &account) <= 0)
738  goto cleanup;
739  if (!account->keydata)
740  goto cleanup;
741  if (!account->enabled)
742  goto cleanup;
743 
744  fputs("Autocrypt: ", fp);
746  account->keydata);
747 
748  rc = 0;
749 
750 cleanup:
752  return rc;
753 }
int mutt_autocrypt_init(bool can_create)
Initialise Autocrypt.
Definition: autocrypt.c:92
WHERE bool C_Autocrypt
Config: Enables the Autocrypt feature.
Definition: globals.h:195
#define TAILQ_FIRST(head)
Definition: queue.h:716
void mutt_autocrypt_db_account_free(struct AutocryptAccount **ptr)
Free an AutocryptAccount.
Definition: db.c:240
An email address.
Definition: address.h:34
char * email_addr
Definition: lib.h:103
bool enabled
Definition: lib.h:107
struct AddressList from
Email&#39;s &#39;From&#39; list.
Definition: envelope.h:57
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:106
int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
Get Autocrypt Account data from the database.
Definition: db.c:259
Autocrypt account.
Definition: lib.h:101
static void write_autocrypt_header_line(FILE *fp, const char *addr, bool prefer_encrypt, const char *keydata)
Write an Autocrypt header to a file.
Definition: autocrypt.c:696
char * keydata
Definition: lib.h:105
#define TAILQ_NEXT(elm, field)
Definition: queue.h:825
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_write_gossip_headers()

int mutt_autocrypt_write_gossip_headers ( struct Envelope env,
FILE *  fp 
)

Write the Autocrypt gossip headers to a file.

Parameters
envEnvelope
fpFile to write to
Return values
0Success
-1Error

Definition at line 762 of file autocrypt.c.

763 {
764  if (!C_Autocrypt || mutt_autocrypt_init(false) || !env)
765  return -1;
766 
767  for (struct AutocryptHeader *gossip = env->autocrypt_gossip; gossip;
768  gossip = gossip->next)
769  {
770  fputs("Autocrypt-Gossip: ", fp);
771  write_autocrypt_header_line(fp, gossip->addr, 0, gossip->keydata);
772  }
773 
774  return 0;
775 }
int mutt_autocrypt_init(bool can_create)
Initialise Autocrypt.
Definition: autocrypt.c:92
WHERE bool C_Autocrypt
Config: Enables the Autocrypt feature.
Definition: globals.h:195
struct AutocryptHeader * autocrypt_gossip
Definition: envelope.h:86
struct AutocryptHeader * next
Definition: envelope.h:47
Parse Autocrypt header info.
Definition: envelope.h:41
static void write_autocrypt_header_line(FILE *fp, const char *addr, bool prefer_encrypt, const char *keydata)
Write an Autocrypt header to a file.
Definition: autocrypt.c:696
+ Here is the call graph for this function:
+ Here is the caller graph for this function: