]> granicus.if.org Git - neomutt/commitdiff
Add AUTOCRYPT header to imap fetch list
authorKevin McCarthy <kevin@8t8.us>
Sat, 27 Jul 2019 20:44:36 +0000 (13:44 -0700)
committerRichard Russon <rich@flatcap.org>
Mon, 19 Aug 2019 23:14:27 +0000 (00:14 +0100)
If $autocrypt is set, add the header to make IMAP behave the same as
other formats (parsing on initial mailbox opening).

This will also be useful if we perform an initial scan during account
creation, to make that work for IMAP too.

Co-authored-by: Richard Russon <rich@flatcap.org>
imap/message.c

index fdaa1a934b12b7c1a70678037bbe9b6c14f6f598..71c23d92c9ae85836aed6acac634b964a94c7fba 100644 (file)
@@ -1036,7 +1036,7 @@ static int read_headers_fetch_new(struct Mailbox *m, unsigned int msn_begin,
   char tempfile[_POSIX_PATH_MAX];
   FILE *fp = NULL;
   struct ImapHeader h;
-  struct Buffer *b = NULL;
+  struct Buffer *b = NULL, *hdr_list = NULL;
   static const char *const want_headers =
       "DATE FROM SENDER SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE "
       "CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL "
@@ -1049,15 +1049,28 @@ static int read_headers_fetch_new(struct Mailbox *m, unsigned int msn_begin,
   if (!adata || (adata->mailbox != m))
     return -1;
 
+  hdr_list = mutt_buffer_pool_get();
+  mutt_buffer_strcpy(hdr_list, want_headers);
+  if (C_ImapHeaders)
+  {
+    mutt_buffer_addch(hdr_list, ' ');
+    mutt_buffer_addstr(hdr_list, C_ImapHeaders);
+  }
+#ifdef USE_AUTOCRYPT
+  if (C_Autocrypt)
+  {
+    mutt_buffer_addch(hdr_list, ' ');
+    mutt_buffer_addstr(hdr_list, "AUTOCRYPT");
+  }
+#endif
+
   if (adata->capabilities & IMAP_CAP_IMAP4REV1)
   {
-    mutt_str_asprintf(&hdrreq, "BODY.PEEK[HEADER.FIELDS (%s%s%s)]", want_headers,
-                      C_ImapHeaders ? " " : "", NONULL(C_ImapHeaders));
+    mutt_str_asprintf(&hdrreq, "BODY.PEEK[HEADER.FIELDS (%s)]", mutt_b2s(hdr_list));
   }
   else if (adata->capabilities & IMAP_CAP_IMAP4)
   {
-    mutt_str_asprintf(&hdrreq, "RFC822.HEADER.LINES (%s%s%s)", want_headers,
-                      C_ImapHeaders ? " " : "", NONULL(C_ImapHeaders));
+    mutt_str_asprintf(&hdrreq, "RFC822.HEADER.LINES (%s)", mutt_b2s(hdr_list));
   }
   else
   { /* Unable to fetch headers for lower versions */
@@ -1065,6 +1078,8 @@ static int read_headers_fetch_new(struct Mailbox *m, unsigned int msn_begin,
     goto bail;
   }
 
+  mutt_buffer_pool_release(&hdr_list);
+
   /* instead of downloading all headers and then parsing them, we parse them
    * as they come in. */
   mutt_mktemp(tempfile, sizeof(tempfile));
@@ -1229,6 +1244,7 @@ static int read_headers_fetch_new(struct Mailbox *m, unsigned int msn_begin,
   retval = 0;
 
 bail:
+  mutt_buffer_pool_release(&hdr_list);
   mutt_buffer_pool_release(&b);
   mutt_file_fclose(&fp);
   FREE(&hdrreq);