NeoMutt  2024-04-25-115-gb99441
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
autocrypt.c
Go to the documentation of this file.
1
32#include "config.h"
33#include <errno.h>
34#include <stdbool.h>
35#include <stdint.h>
36#include <stdio.h>
37#include <string.h>
38#include <sys/stat.h>
39#include "private.h"
40#include "mutt/lib.h"
41#include "address/lib.h"
42#include "config/lib.h"
43#include "email/lib.h"
44#include "core/lib.h"
45#include "gui/lib.h"
46#include "lib.h"
47#include "browser/lib.h"
48#include "index/lib.h"
49#include "ncrypt/lib.h"
50#include "question/lib.h"
51#include "send/lib.h"
52#include "muttlib.h"
53#include "mx.h"
54
61static int autocrypt_dir_init(bool can_create)
62{
63 int rc = 0;
64 struct stat st = { 0 };
65
66 const char *const c_autocrypt_dir = cs_subset_path(NeoMutt->sub, "autocrypt_dir");
67 if (stat(c_autocrypt_dir, &st) == 0)
68 return 0;
69
70 if (!can_create)
71 return -1;
72
73 struct Buffer *prompt = buf_pool_get();
74 /* L10N: s is a directory. NeoMutt is looking for a directory it needs
75 for some reason (e.g. autocrypt, header cache, bcache), but it
76 doesn't exist. The prompt is asking whether to create the directory */
77 buf_printf(prompt, _("%s does not exist. Create it?"), c_autocrypt_dir);
79 {
80 if (mutt_file_mkdir(c_autocrypt_dir, S_IRWXU) < 0)
81 {
82 /* L10N: mkdir() on the directory %s failed. The second %s is the
83 error message returned by libc */
84 mutt_error(_("Can't create %s: %s"), c_autocrypt_dir, strerror(errno));
85 rc = -1;
86 }
87 }
88
89 buf_pool_release(&prompt);
90 return rc;
91}
92
99int mutt_autocrypt_init(bool can_create)
100{
101 if (AutocryptDB)
102 return 0;
103
104 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
105 const char *const c_autocrypt_dir = cs_subset_path(NeoMutt->sub, "autocrypt_dir");
106 if (!c_autocrypt || !c_autocrypt_dir)
107 return -1;
108
109 if (autocrypt_dir_init(can_create))
110 goto bail;
111
113 goto bail;
114
115 if (mutt_autocrypt_db_init(can_create))
116 goto bail;
117
118 return 0;
119
120bail:
121 cs_subset_str_native_set(NeoMutt->sub, "autocrypt", false, NULL);
123 return -1;
124}
125
130{
132}
133
144{
145 struct Address *addr = NULL;
146 struct AutocryptAccount *account = NULL;
147 bool done = false;
148 int rc = -1;
149 bool prefer_encrypt = false;
150
151 if (prompt)
152 {
153 /* L10N: The first time NeoMutt is started with $autocrypt set, it will
154 create $autocrypt_dir and then prompt to create an autocrypt account
155 with this message. */
156 if (query_yesorno_ignore_macro(_("Create an initial autocrypt account?"), MUTT_YES) != MUTT_YES)
157 return 0;
158 }
159
160 struct Buffer *keyid = buf_pool_get();
161 struct Buffer *keydata = buf_pool_get();
162
163 const struct Address *c_from = cs_subset_address(NeoMutt->sub, "from");
164 if (c_from)
165 {
166 addr = mutt_addr_copy(c_from);
167 const char *const c_real_name = cs_subset_string(NeoMutt->sub, "real_name");
168 if (!addr->personal && c_real_name)
169 addr->personal = buf_new(c_real_name);
170 }
171
172 struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
173 mutt_addrlist_append(&al, addr);
174
175 do
176 {
177 /* L10N: Autocrypt is asking for the email address to use for the
178 autocrypt account. This will generate a key and add a record
179 to the database for use in autocrypt operations. */
180 if (mutt_edit_address(&al, _("Autocrypt account address: "), false) != 0)
181 goto cleanup;
182
183 addr = TAILQ_FIRST(&al);
184 if (!addr || !addr->mailbox || TAILQ_NEXT(addr, entries))
185 {
186 /* L10N: Autocrypt prompts for an account email address, and requires
187 a single address. This is shown if they entered something invalid,
188 nothing, or more than one address for some reason. */
189 mutt_error(_("Please enter a single email address"));
190 done = false;
191 }
192 else
193 {
194 done = true;
195 }
196 } while (!done);
197
198 addr = TAILQ_FIRST(&al);
199 if (mutt_autocrypt_db_account_get(addr, &account) < 0)
200 goto cleanup;
201 if (account)
202 {
203 /* L10N: When creating an autocrypt account, this message will be displayed
204 if there is already an account in the database with the email address
205 they just entered. */
206 mutt_error(_("That email address already has an autocrypt account"));
207 goto cleanup;
208 }
209
210 if (mutt_autocrypt_gpgme_select_or_create_key(addr, keyid, keydata))
211 goto cleanup;
212
213 /* L10N: Autocrypt has a setting "prefer-encrypt".
214 When the recommendation algorithm returns "available" and BOTH sender and
215 recipient choose "prefer-encrypt", encryption will be automatically
216 enabled.
217 Otherwise the UI will show encryption is "available" but the user
218 will be required to enable encryption manually. */
219 if (query_yesorno_ignore_macro(_("Prefer encryption?"), MUTT_NO) == MUTT_YES)
220 prefer_encrypt = true;
221
222 if (mutt_autocrypt_db_account_insert(addr, buf_string(keyid), buf_string(keydata), prefer_encrypt))
223 {
224 goto cleanup;
225 }
226
227 rc = 0;
228
229cleanup:
230 if (rc == 0)
231 {
232 /* L10N: Message displayed after an autocrypt account is successfully created. */
233 mutt_message(_("Autocrypt account creation succeeded"));
234 }
235 else
236 {
237 /* L10N: Error message displayed if creating an autocrypt account failed
238 or was aborted by the user. */
239 mutt_error(_("Autocrypt account creation aborted"));
240 }
241
244 buf_pool_release(&keyid);
245 buf_pool_release(&keydata);
246 return rc;
247}
248
257{
258 struct AutocryptHeader *valid_ac_hdr = NULL;
259 struct AutocryptPeer *peer = NULL;
260 struct AutocryptPeerHistory *peerhist = NULL;
261 struct Buffer *keyid = NULL;
262 bool update_db = false, insert_db = false, insert_db_history = false, import_gpg = false;
263 int rc = -1;
264
265 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
266 if (!c_autocrypt)
267 return 0;
268
269 if (mutt_autocrypt_init(false))
270 return -1;
271
272 if (!e || !e->body || !env)
273 return 0;
274
275 /* 1.1 spec says to skip emails with more than one From header */
276 struct Address *from = TAILQ_FIRST(&env->from);
277 if (!from || TAILQ_NEXT(from, entries))
278 return 0;
279
280 /* 1.1 spec also says to skip multipart/report emails */
281 if ((e->body->type == TYPE_MULTIPART) && mutt_istr_equal(e->body->subtype, "report"))
282 {
283 return 0;
284 }
285
286 /* Ignore emails that appear to be more than a week in the future,
287 * since they can block all future updates during that time. */
288 if (e->date_sent > (mutt_date_now() + (7 * 24 * 60 * 60)))
289 return 0;
290
291 for (struct AutocryptHeader *ac_hdr = env->autocrypt; ac_hdr; ac_hdr = ac_hdr->next)
292 {
293 if (ac_hdr->invalid)
294 continue;
295
296 /* NOTE: this assumes the processing is occurring right after
297 * mutt_parse_rfc822_line() and the from ADDR is still in the same
298 * form (intl) as the autocrypt header addr field */
299 if (!mutt_istr_equal(buf_string(from->mailbox), ac_hdr->addr))
300 continue;
301
302 /* 1.1 spec says ignore all, if more than one valid header is found. */
303 if (valid_ac_hdr)
304 {
305 valid_ac_hdr = NULL;
306 break;
307 }
308 valid_ac_hdr = ac_hdr;
309 }
310
311 if (mutt_autocrypt_db_peer_get(from, &peer) < 0)
312 goto cleanup;
313
314 if (peer)
315 {
316 if (e->date_sent <= peer->autocrypt_timestamp)
317 {
318 rc = 0;
319 goto cleanup;
320 }
321
322 if (e->date_sent > peer->last_seen)
323 {
324 update_db = true;
325 peer->last_seen = e->date_sent;
326 }
327
328 if (valid_ac_hdr)
329 {
330 update_db = true;
332 peer->prefer_encrypt = valid_ac_hdr->prefer_encrypt;
333 if (!mutt_str_equal(peer->keydata, valid_ac_hdr->keydata))
334 {
335 import_gpg = true;
336 insert_db_history = true;
337 mutt_str_replace(&peer->keydata, valid_ac_hdr->keydata);
338 }
339 }
340 }
341 else if (valid_ac_hdr)
342 {
343 import_gpg = true;
344 insert_db = true;
345 insert_db_history = true;
346 }
347
348 if (!(import_gpg || insert_db || update_db))
349 {
350 rc = 0;
351 goto cleanup;
352 }
353
354 if (!peer)
355 {
357 peer->last_seen = e->date_sent;
359 peer->keydata = mutt_str_dup(valid_ac_hdr->keydata);
360 peer->prefer_encrypt = valid_ac_hdr->prefer_encrypt;
361 }
362
363 if (import_gpg)
364 {
365 keyid = buf_pool_get();
367 goto cleanup;
368 mutt_str_replace(&peer->keyid, buf_string(keyid));
369 }
370
371 if (insert_db && mutt_autocrypt_db_peer_insert(from, peer))
372 goto cleanup;
373
374 if (update_db && mutt_autocrypt_db_peer_update(peer))
375 goto cleanup;
376
377 if (insert_db_history)
378 {
380 peerhist->email_msgid = mutt_str_dup(env->message_id);
381 peerhist->timestamp = e->date_sent;
382 peerhist->keydata = mutt_str_dup(peer->keydata);
383 if (mutt_autocrypt_db_peer_history_insert(from, peerhist))
384 goto cleanup;
385 }
386
387 rc = 0;
388
389cleanup:
392 buf_pool_release(&keyid);
393
394 return rc;
395}
396
404int mutt_autocrypt_process_gossip_header(struct Email *e, struct Envelope *prot_headers)
405{
406 struct AutocryptPeer *peer = NULL;
407 struct AutocryptGossipHistory *gossip_hist = NULL;
408 struct Address *peer_addr = NULL;
409 struct Address ac_hdr_addr = { 0 };
410 bool update_db = false, insert_db = false, insert_db_history = false, import_gpg = false;
411 int rc = -1;
412
413 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
414 if (!c_autocrypt)
415 return 0;
416
417 if (mutt_autocrypt_init(false))
418 return -1;
419
420 if (!e || !e->env || !prot_headers)
421 return 0;
422
423 struct Envelope *env = e->env;
424
425 struct Address *from = TAILQ_FIRST(&env->from);
426 if (!from)
427 return 0;
428
429 /* Ignore emails that appear to be more than a week in the future,
430 * since they can block all future updates during that time. */
431 if (e->date_sent > (mutt_date_now() + (7 * 24 * 60 * 60)))
432 return 0;
433
434 struct Buffer *keyid = buf_pool_get();
435
436 struct AddressList recips = TAILQ_HEAD_INITIALIZER(recips);
437
438 /* Normalize the recipient list for comparison */
439 mutt_addrlist_copy(&recips, &env->to, false);
440 mutt_addrlist_copy(&recips, &env->cc, false);
441 mutt_addrlist_copy(&recips, &env->reply_to, false);
443
444 for (struct AutocryptHeader *ac_hdr = prot_headers->autocrypt_gossip; ac_hdr;
445 ac_hdr = ac_hdr->next)
446 {
447 if (ac_hdr->invalid)
448 continue;
449
450 /* normalize for comparison against recipient list */
451 buf_strcpy(ac_hdr_addr.mailbox, ac_hdr->addr);
452 ac_hdr_addr.is_intl = true;
453 ac_hdr_addr.intl_checked = true;
455
456 /* Check to make sure the address is in the recipient list. */
457 TAILQ_FOREACH(peer_addr, &recips, entries)
458 {
459 if (buf_str_equal(peer_addr->mailbox, ac_hdr_addr.mailbox))
460 break;
461 }
462
463 if (!peer_addr)
464 continue;
465
466 if (mutt_autocrypt_db_peer_get(peer_addr, &peer) < 0)
467 goto cleanup;
468
469 if (peer)
470 {
471 if (e->date_sent <= peer->gossip_timestamp)
472 {
474 continue;
475 }
476
477 update_db = true;
478 peer->gossip_timestamp = e->date_sent;
479 /* This is slightly different from the autocrypt 1.1 spec.
480 * Avoid setting an empty peer.gossip_keydata with a value that matches
481 * the current peer.keydata. */
482 if ((peer->gossip_keydata && !mutt_str_equal(peer->gossip_keydata, ac_hdr->keydata)) ||
483 (!peer->gossip_keydata && !mutt_str_equal(peer->keydata, ac_hdr->keydata)))
484 {
485 import_gpg = true;
486 insert_db_history = true;
487 mutt_str_replace(&peer->gossip_keydata, ac_hdr->keydata);
488 }
489 }
490 else
491 {
492 import_gpg = true;
493 insert_db = true;
494 insert_db_history = true;
495 }
496
497 if (!peer)
498 {
500 peer->gossip_timestamp = e->date_sent;
501 peer->gossip_keydata = mutt_str_dup(ac_hdr->keydata);
502 }
503
504 if (import_gpg)
505 {
507 goto cleanup;
509 }
510
511 if (insert_db && mutt_autocrypt_db_peer_insert(peer_addr, peer))
512 goto cleanup;
513
514 if (update_db && mutt_autocrypt_db_peer_update(peer))
515 goto cleanup;
516
517 if (insert_db_history)
518 {
520 gossip_hist->sender_email_addr = buf_strdup(from->mailbox);
521 gossip_hist->email_msgid = mutt_str_dup(env->message_id);
522 gossip_hist->timestamp = e->date_sent;
523 gossip_hist->gossip_keydata = mutt_str_dup(peer->gossip_keydata);
524 if (mutt_autocrypt_db_gossip_history_insert(peer_addr, gossip_hist))
525 goto cleanup;
526 }
527
530 buf_reset(keyid);
531 update_db = false;
532 insert_db = false;
533 insert_db_history = false;
534 import_gpg = false;
535 }
536
537 rc = 0;
538
539cleanup:
540 FREE(&ac_hdr_addr.mailbox);
541 mutt_addrlist_clear(&recips);
544 buf_pool_release(&keyid);
545
546 return rc;
547}
548
558enum AutocryptRec mutt_autocrypt_ui_recommendation(const struct Email *e, char **keylist)
559{
561 struct AutocryptAccount *account = NULL;
562 struct AutocryptPeer *peer = NULL;
563 struct Address *recip = NULL;
564 bool all_encrypt = true, has_discourage = false;
565 const char *matching_key = NULL;
566 struct AddressList recips = TAILQ_HEAD_INITIALIZER(recips);
567 struct Buffer *keylist_buf = NULL;
568
569 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
570 if (!c_autocrypt || mutt_autocrypt_init(false) || !e)
571 {
572 if (keylist)
573 {
574 /* L10N: Error displayed if the user tries to force sending an Autocrypt
575 email when the engine is not available. */
576 mutt_message(_("Autocrypt is not available"));
577 }
578 return AUTOCRYPT_REC_OFF;
579 }
580
581 struct Address *from = TAILQ_FIRST(&e->env->from);
582 if (!from || TAILQ_NEXT(from, entries))
583 {
584 if (keylist)
585 mutt_message(_("Autocrypt is not available"));
586 return AUTOCRYPT_REC_OFF;
587 }
588
590 {
591 if (keylist)
592 mutt_message(_("Autocrypt is not available"));
593 return AUTOCRYPT_REC_OFF;
594 }
595
596 if ((mutt_autocrypt_db_account_get(from, &account) <= 0) || !account->enabled)
597 {
598 if (keylist)
599 {
600 /* L10N: Error displayed if the user tries to force sending an Autocrypt
601 email when the account does not exist or is not enabled.
602 %s is the From email address used to look up the Autocrypt account.
603 */
604 mutt_message(_("Autocrypt is not enabled for %s"), buf_string(from->mailbox));
605 }
606 goto cleanup;
607 }
608
609 keylist_buf = buf_pool_get();
610 buf_addstr(keylist_buf, account->keyid);
611
612 mutt_addrlist_copy(&recips, &e->env->to, false);
613 mutt_addrlist_copy(&recips, &e->env->cc, false);
614 mutt_addrlist_copy(&recips, &e->env->bcc, false);
615
616 rc = AUTOCRYPT_REC_NO;
617 if (TAILQ_EMPTY(&recips))
618 goto cleanup;
619
620 TAILQ_FOREACH(recip, &recips, entries)
621 {
622 if (mutt_autocrypt_db_peer_get(recip, &peer) <= 0)
623 {
624 if (keylist)
625 {
626 /* L10N: s is an email address. Autocrypt is scanning for the keyids
627 to use to encrypt, but it can't find a valid keyid for this address.
628 The message is printed and they are returned to the compose menu. */
629 mutt_message(_("No (valid) autocrypt key found for %s"),
630 buf_string(recip->mailbox));
631 }
632 goto cleanup;
633 }
634
636 {
637 matching_key = peer->keyid;
638
639 if (!(peer->last_seen && peer->autocrypt_timestamp) ||
640 (peer->last_seen - peer->autocrypt_timestamp > (35 * 24 * 60 * 60)))
641 {
642 has_discourage = true;
643 all_encrypt = false;
644 }
645
646 if (!account->prefer_encrypt || !peer->prefer_encrypt)
647 all_encrypt = false;
648 }
650 {
651 matching_key = peer->gossip_keyid;
652
653 has_discourage = true;
654 all_encrypt = false;
655 }
656 else
657 {
658 if (keylist)
659 {
660 mutt_message(_("No (valid) autocrypt key found for %s"),
661 buf_string(recip->mailbox));
662 }
663 goto cleanup;
664 }
665
666 if (!buf_is_empty(keylist_buf))
667 buf_addch(keylist_buf, ' ');
668 buf_addstr(keylist_buf, matching_key);
669
671 }
672
673 if (all_encrypt)
675 else if (has_discourage)
677 else
679
680 if (keylist)
681 mutt_str_replace(keylist, buf_string(keylist_buf));
682
683cleanup:
685 mutt_addrlist_clear(&recips);
687 buf_pool_release(&keylist_buf);
688 return rc;
689}
690
698{
699 int rc = -1;
700 struct AutocryptAccount *account = NULL;
701
702 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
703 if (!c_autocrypt || mutt_autocrypt_init(false) || !e)
704 return -1;
705
706 struct Address *from = TAILQ_FIRST(&e->env->from);
707 if (!from || TAILQ_NEXT(from, entries))
708 return -1;
709
710 if (mutt_autocrypt_db_account_get(from, &account) <= 0)
711 goto cleanup;
712 if (!account->keyid)
713 goto cleanup;
714 if (!account->enabled)
715 goto cleanup;
716
719
720 rc = 0;
721
722cleanup:
724 return rc;
725}
726
734static void write_autocrypt_header_line(FILE *fp, const char *addr,
735 bool prefer_encrypt, const char *keydata)
736{
737 fprintf(fp, "addr=%s; ", addr);
738 if (prefer_encrypt)
739 fputs("prefer-encrypt=mutual; ", fp);
740 fputs("keydata=\n", fp);
741
742 while (*keydata)
743 {
744 int count = 0;
745 fputs("\t", fp);
746 while (*keydata && count < 75)
747 {
748 fputc(*keydata, fp);
749 count++;
750 keydata++;
751 }
752 fputs("\n", fp);
753 }
754}
755
764{
765 int rc = -1;
766 struct AutocryptAccount *account = NULL;
767
768 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
769 if (!c_autocrypt || mutt_autocrypt_init(false) || !env)
770 return -1;
771
772 struct Address *from = TAILQ_FIRST(&env->from);
773 if (!from || TAILQ_NEXT(from, entries))
774 return -1;
775
776 if (mutt_autocrypt_db_account_get(from, &account) <= 0)
777 goto cleanup;
778 if (!account->keydata)
779 goto cleanup;
780 if (!account->enabled)
781 goto cleanup;
782
783 fputs("Autocrypt: ", fp);
785 account->keydata);
786
787 rc = 0;
788
789cleanup:
791 return rc;
792}
793
802{
803 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
804 if (!c_autocrypt || mutt_autocrypt_init(false) || !env)
805 return -1;
806
807 for (struct AutocryptHeader *gossip = env->autocrypt_gossip; gossip;
808 gossip = gossip->next)
809 {
810 fputs("Autocrypt-Gossip: ", fp);
811 write_autocrypt_header_line(fp, gossip->addr, 0, gossip->keydata);
812 }
813
814 return 0;
815}
816
824{
825 int rc = -1;
826 struct AutocryptPeer *peer = NULL;
827 struct AutocryptAccount *account = NULL;
828 struct Address *recip = NULL;
829
830 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
831 if (!c_autocrypt || mutt_autocrypt_init(false) || !e)
832 return -1;
833
834 struct Envelope *mime_headers = e->body->mime_headers;
835 if (!mime_headers)
836 mime_headers = e->body->mime_headers = mutt_env_new();
838
839 struct AddressList recips = TAILQ_HEAD_INITIALIZER(recips);
840
841 mutt_addrlist_copy(&recips, &e->env->to, false);
842 mutt_addrlist_copy(&recips, &e->env->cc, false);
843
844 TAILQ_FOREACH(recip, &recips, entries)
845 {
846 /* At this point, we just accept missing keys and include what we can. */
847 if (mutt_autocrypt_db_peer_get(recip, &peer) <= 0)
848 continue;
849
850 const char *keydata = NULL;
852 keydata = peer->keydata;
854 keydata = peer->gossip_keydata;
855
856 if (keydata)
857 {
858 struct AutocryptHeader *gossip = mutt_autocrypthdr_new();
859 gossip->addr = mutt_str_dup(peer->email_addr);
860 gossip->keydata = mutt_str_dup(keydata);
861 gossip->next = mime_headers->autocrypt_gossip;
862 mime_headers->autocrypt_gossip = gossip;
863 }
864
866 }
867
868 TAILQ_FOREACH(recip, &e->env->reply_to, entries)
869 {
870 const char *addr = NULL;
871 const char *keydata = NULL;
872 if (mutt_autocrypt_db_account_get(recip, &account) > 0)
873 {
874 addr = account->email_addr;
875 keydata = account->keydata;
876 }
877 else if (mutt_autocrypt_db_peer_get(recip, &peer) > 0)
878 {
879 addr = peer->email_addr;
881 keydata = peer->keydata;
883 keydata = peer->gossip_keydata;
884 }
885
886 if (keydata)
887 {
888 struct AutocryptHeader *gossip = mutt_autocrypthdr_new();
889 gossip->addr = mutt_str_dup(addr);
890 gossip->keydata = mutt_str_dup(keydata);
891 gossip->next = mime_headers->autocrypt_gossip;
892 mime_headers->autocrypt_gossip = gossip;
893 }
896 }
897
898 mutt_addrlist_clear(&recips);
901 return rc;
902}
903
915{
916#ifdef USE_HCACHE
917 const char *c_header_cache = cs_subset_path(NeoMutt->sub, "header_cache");
918 char *old_hdrcache = mutt_str_dup(c_header_cache);
919 cs_subset_str_native_set(NeoMutt->sub, "header_cache", 0, NULL);
920#endif
921
922 struct Buffer *folderbuf = buf_pool_get();
923
924 /* L10N: The first time autocrypt is enabled, NeoMutt will ask to scan
925 through one or more mailboxes for Autocrypt: headers. Those headers are
926 then captured in the database as peer records and used for encryption.
927 If this is answered yes, they will be prompted for a mailbox. */
928 enum QuadOption scan = query_yesorno_ignore_macro(_("Scan a mailbox for autocrypt headers?"), MUTT_YES);
929 while (scan == MUTT_YES)
930 {
931 struct Mailbox *m_cur = get_current_mailbox();
932 // L10N: The prompt for a mailbox to scan for Autocrypt: headers
933 if ((!mw_enter_fname(_("Scan mailbox"), folderbuf, true, m_cur, false, NULL,
934 NULL, MUTT_SEL_NO_FLAGS)) &&
935 (!buf_is_empty(folderbuf)))
936 {
937 buf_expand_path_regex(folderbuf, false);
938 struct Mailbox *m_ac = mx_path_resolve(buf_string(folderbuf));
939 /* NOTE: I am purposely *not* executing folder hooks here,
940 * as they can do all sorts of things like push into the getch() buffer.
941 * Authentication should be in account-hooks. */
942 if (mx_mbox_open(m_ac, MUTT_READONLY))
943 {
944 mx_mbox_close(m_ac);
945 }
946 buf_reset(folderbuf);
947 }
948
949 /* L10N: This is the second prompt to see if the user would like
950 to scan more than one mailbox for Autocrypt headers.
951 I'm purposely being extra verbose; asking first then prompting
952 for a mailbox. This is because this is a one-time operation
953 and I don't want them to accidentally ctrl-g and abort it. */
954 scan = query_yesorno_ignore_macro(_("Scan another mailbox for autocrypt headers?"), MUTT_YES);
955 }
956
957#ifdef USE_HCACHE
958 cs_subset_str_native_set(NeoMutt->sub, "header_cache", (intptr_t) old_hdrcache, NULL);
959 old_hdrcache = NULL;
960#endif
961 buf_pool_release(&folderbuf);
962}
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition: address.c:765
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1460
void mutt_addrlist_append(struct AddressList *al, struct Address *a)
Append an Address to an AddressList.
Definition: address.c:1480
struct Address * mutt_addr_copy(const struct Address *addr)
Copy the real address.
Definition: address.c:745
const struct Address * cs_subset_address(const struct ConfigSubset *sub, const char *name)
Get an Address config item by name.
Definition: config_type.c:272
Email Address Handling.
char * AutocryptSignAs
Autocrypt Key id to sign as.
Definition: config.c:37
char * AutocryptDefaultKey
Autocrypt default key id (used for postponing messages)
Definition: config.c:38
void mutt_autocrypt_db_normalize_addrlist(struct AddressList *al)
Normalise a list of Email Addresses.
Definition: db.c:179
struct AutocryptPeer * mutt_autocrypt_db_peer_new(void)
Create a new AutocryptPeer.
Definition: db.c:528
int mutt_autocrypt_db_peer_insert(struct Address *addr, struct AutocryptPeer *peer)
Insert a peer into the Autocrypt database.
Definition: db.c:627
struct AutocryptGossipHistory * mutt_autocrypt_db_gossip_history_new(void)
Create a new AutocryptGossipHistory.
Definition: db.c:830
void mutt_autocrypt_db_close(void)
Close the Autocrypt SQLite database connection.
Definition: db.c:133
sqlite3 * AutocryptDB
Handle to the open Autocrypt database.
Definition: db.c:56
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:859
int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
Get Autocrypt Account data from the database.
Definition: db.c:266
int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
Get peer info from the Autocrypt database.
Definition: db.c:559
int mutt_autocrypt_db_peer_update(struct AutocryptPeer *peer)
Update the peer info in an Autocrypt database.
Definition: db.c:693
int mutt_autocrypt_db_account_insert(struct Address *addr, const char *keyid, const char *keydata, bool prefer_encrypt)
Insert an Account into the Autocrypt database.
Definition: db.c:328
void mutt_autocrypt_db_account_free(struct AutocryptAccount **ptr)
Free an AutocryptAccount.
Definition: db.c:247
void mutt_autocrypt_db_normalize_addr(struct Address *a)
Normalise an Email Address.
Definition: db.c:168
void mutt_autocrypt_db_peer_history_free(struct AutocryptPeerHistory **ptr)
Free an AutocryptPeerHistory.
Definition: db.c:758
void mutt_autocrypt_db_peer_free(struct AutocryptPeer **ptr)
Free an AutocryptPeer.
Definition: db.c:537
void mutt_autocrypt_db_gossip_history_free(struct AutocryptGossipHistory **ptr)
Free an AutocryptGossipHistory.
Definition: db.c:839
struct AutocryptPeerHistory * mutt_autocrypt_db_peer_history_new(void)
Create a new AutocryptPeerHistory.
Definition: db.c:749
int mutt_autocrypt_db_init(bool can_create)
Initialise the Autocrypt SQLite database.
Definition: db.c:83
int mutt_autocrypt_db_peer_history_insert(struct Address *addr, struct AutocryptPeerHistory *peerhist)
Insert peer history into the Autocrypt database.
Definition: db.c:777
AutocryptRec
Recommendation.
Definition: lib.h:158
@ AUTOCRYPT_REC_DISCOURAGE
Prefer not to use Autocrypt.
Definition: lib.h:161
@ AUTOCRYPT_REC_NO
Do no use Autocrypt.
Definition: lib.h:160
@ AUTOCRYPT_REC_OFF
No recommendations.
Definition: lib.h:159
@ AUTOCRYPT_REC_AVAILABLE
Autocrypt is available.
Definition: lib.h:162
@ AUTOCRYPT_REC_YES
Autocrypt should be used.
Definition: lib.h:163
int mutt_autocrypt_process_autocrypt_header(struct Email *e, struct Envelope *env)
Parse an Autocrypt email header.
Definition: autocrypt.c:256
int mutt_autocrypt_generate_gossip_list(struct Email *e)
Create the gossip list headers.
Definition: autocrypt.c:823
static int autocrypt_dir_init(bool can_create)
Initialise an Autocrypt directory.
Definition: autocrypt.c:61
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:734
void mutt_autocrypt_cleanup(void)
Shutdown Autocrypt.
Definition: autocrypt.c:129
int mutt_autocrypt_write_gossip_headers(struct Envelope *env, FILE *fp)
Write the Autocrypt gossip headers to a file.
Definition: autocrypt.c:801
enum AutocryptRec mutt_autocrypt_ui_recommendation(const struct Email *e, char **keylist)
Get the recommended action for an Email.
Definition: autocrypt.c:558
int mutt_autocrypt_account_init(bool prompt)
Create a new Autocrypt account.
Definition: autocrypt.c:143
int mutt_autocrypt_init(bool can_create)
Initialise Autocrypt.
Definition: autocrypt.c:99
int mutt_autocrypt_write_autocrypt_header(struct Envelope *env, FILE *fp)
Write the Autocrypt header to a file.
Definition: autocrypt.c:763
int mutt_autocrypt_set_sign_as_default_key(struct Email *e)
Set the Autocrypt default key for signing.
Definition: autocrypt.c:697
void mutt_autocrypt_scan_mailboxes(void)
Scan mailboxes for Autocrypt headers.
Definition: autocrypt.c:914
int mutt_autocrypt_process_gossip_header(struct Email *e, struct Envelope *prot_headers)
Parse an Autocrypt email gossip header.
Definition: autocrypt.c:404
Select a Mailbox from a list.
#define MUTT_SEL_NO_FLAGS
No flags are set.
Definition: lib.h:57
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:76
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:291
struct Buffer * buf_new(const char *str)
Allocate a new Buffer.
Definition: buffer.c:304
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:241
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:226
bool buf_str_equal(const struct Buffer *a, const struct Buffer *b)
Return if two buffers are equal.
Definition: buffer.c:685
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:395
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:571
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:291
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:168
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
Structs that make up an email.
struct Envelope * mutt_env_new(void)
Create a new Envelope.
Definition: envelope.c:46
struct AutocryptHeader * mutt_autocrypthdr_new(void)
Create a new AutocryptHeader.
Definition: envelope.c:95
void mutt_autocrypthdr_free(struct AutocryptHeader **ptr)
Free an AutocryptHeader.
Definition: envelope.c:104
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
Definition: file.c:974
bool mutt_autocrypt_gpgme_is_valid_key(const char *keyid)
Is a key id valid?
Definition: gpgme.c:361
int mutt_autocrypt_gpgme_init(void)
Initialise GPGME.
Definition: gpgme.c:70
int mutt_autocrypt_gpgme_import_key(const char *keydata, struct Buffer *keyid)
Read a key from GPGME.
Definition: gpgme.c:320
int mutt_autocrypt_gpgme_select_or_create_key(struct Address *addr, struct Buffer *keyid, struct Buffer *keydata)
Ask the user to select or create an Autocrypt key.
Definition: gpgme.c:279
int mw_enter_fname(const char *prompt, struct Buffer *fname, bool mailbox, struct Mailbox *m, bool multiple, char ***files, int *numfiles, SelectFileFlags flags)
Ask the user to select a file -.
Definition: curs_lib.c:236
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_message(...)
Definition: logging2.h:91
Convenience wrapper for the gui headers.
GUI manage the main index (list of emails)
struct Mailbox * get_current_mailbox(void)
Get the current Mailbox.
Definition: index.c:715
#define FREE(x)
Definition: memory.h:45
@ TYPE_MULTIPART
Type: 'multipart/*'.
Definition: mime.h:37
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:456
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:672
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:280
void buf_expand_path_regex(struct Buffer *buf, bool regex)
Create the canonical path (with regex char escaping)
Definition: muttlib.c:122
Some miscellaneous functions.
bool mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
Definition: mx.c:288
struct Mailbox * mx_path_resolve(const char *path)
Get a Mailbox for a path.
Definition: mx.c:1636
enum MxStatus mx_mbox_close(struct Mailbox *m)
Save changes and close mailbox.
Definition: mx.c:598
API for mailboxes.
#define MUTT_READONLY
Open in read-only mode.
Definition: mxapi.h:43
API for encryption/signing of emails.
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:91
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
QuadOption
Possible values for a quad-option.
Definition: quad.h:36
@ 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_ignore_macro(const char *prompt, enum QuadOption def)
Ask the user a Yes/No question ignoring the macro buffer.
Definition: question.c:340
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
#define TAILQ_FIRST(head)
Definition: queue.h:723
#define TAILQ_NEXT(elm, field)
Definition: queue.h:832
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:637
#define TAILQ_EMPTY(head)
Definition: queue.h:721
Convenience wrapper for the send headers.
int mutt_edit_address(struct AddressList *al, const char *field, bool expand_aliases)
Edit an email address.
Definition: send.c:191
GUI display the mailboxes in a side panel.
Key value store.
An email address.
Definition: address.h:36
struct Buffer * personal
Real name of address.
Definition: address.h:37
struct Buffer * mailbox
Mailbox and host address.
Definition: address.h:38
bool intl_checked
Checked for IDN?
Definition: address.h:41
bool is_intl
International Domain Name.
Definition: address.h:40
Autocrypt account.
Definition: lib.h:107
char * email_addr
Email address.
Definition: lib.h:108
char * keydata
PGP Key data.
Definition: lib.h:110
char * keyid
PGP Key id.
Definition: lib.h:109
bool enabled
Is this account enabled.
Definition: lib.h:112
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:111
Autocrypt gossip history.
Definition: lib.h:146
char * email_msgid
Sender's email's message id.
Definition: lib.h:149
char * sender_email_addr
Sender's email address.
Definition: lib.h:148
char * gossip_keydata
Gossip Key data.
Definition: lib.h:151
sqlite3_int64 timestamp
Timestamp of sender's email.
Definition: lib.h:150
Parse Autocrypt header info.
Definition: envelope.h:44
struct AutocryptHeader * next
Linked list.
Definition: envelope.h:49
char * keydata
PGP Key data.
Definition: envelope.h:46
bool prefer_encrypt
User prefers encryption.
Definition: envelope.h:47
char * addr
Email address.
Definition: envelope.h:45
Autocrypt peer history.
Definition: lib.h:135
char * email_msgid
Message id of the email.
Definition: lib.h:137
char * keydata
PGP Key data.
Definition: lib.h:139
sqlite3_int64 timestamp
Timestamp of email.
Definition: lib.h:138
Autocrypt peer.
Definition: lib.h:119
sqlite3_int64 autocrypt_timestamp
When the email was sent.
Definition: lib.h:122
char * gossip_keydata
Gossip Key data.
Definition: lib.h:128
char * keyid
PGP Key id.
Definition: lib.h:123
char * gossip_keyid
Gossip Key id.
Definition: lib.h:127
char * keydata
PGP Key data.
Definition: lib.h:124
char * email_addr
Email address.
Definition: lib.h:120
sqlite3_int64 last_seen
When was the peer last seen.
Definition: lib.h:121
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:125
sqlite3_int64 gossip_timestamp
Timestamp of Gossip header.
Definition: lib.h:126
struct Envelope * mime_headers
Memory hole protected headers.
Definition: body.h:76
char * subtype
content-type subtype
Definition: body.h:61
unsigned int type
content-type primary type, ContentType
Definition: body.h:40
String manipulation buffer.
Definition: buffer.h:36
The envelope/body of an email.
Definition: email.h:39
struct Envelope * env
Envelope information.
Definition: email.h:68
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
Definition: email.h:43
struct Body * body
List of MIME parts.
Definition: email.h:69
time_t date_sent
Time when the message was sent (UTC)
Definition: email.h:60
The header of an Email.
Definition: envelope.h:57
struct AddressList to
Email's 'To' list.
Definition: envelope.h:60
struct AddressList reply_to
Email's 'reply-to'.
Definition: envelope.h:64
char * message_id
Message ID.
Definition: envelope.h:73
struct AutocryptHeader * autocrypt_gossip
Autocrypt Gossip header.
Definition: envelope.h:88
struct AddressList cc
Email's 'Cc' list.
Definition: envelope.h:61
struct AutocryptHeader * autocrypt
Autocrypt header.
Definition: envelope.h:87
struct AddressList bcc
Email's 'Bcc' list.
Definition: envelope.h:62
struct AddressList from
Email's 'From' list.
Definition: envelope.h:59
A mailbox.
Definition: mailbox.h:79
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
int cs_subset_str_native_set(const struct ConfigSubset *sub, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.
Definition: subset.c:297