NeoMutt  2024-02-01-23-g345d7b
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
command.c
Go to the documentation of this file.
1
37#include "config.h"
38#include <ctype.h>
39#include <errno.h>
40#include <limits.h>
41#include <stdbool.h>
42#include <stdint.h>
43#include <stdio.h>
44#include <stdlib.h>
45#include <string.h>
46#include "private.h"
47#include "mutt/lib.h"
48#include "config/lib.h"
49#include "email/lib.h"
50#include "core/lib.h"
51#include "conn/lib.h"
52#include "parse/lib.h"
53#include "adata.h"
54#include "edata.h"
55#include "mdata.h"
56#include "msn.h"
57#include "mutt_account.h"
58#include "mutt_logging.h"
59#include "mx.h"
60
61#define IMAP_CMD_BUFSIZE 512
62
68static const char *const Capabilities[] = {
69 "IMAP4",
70 "IMAP4rev1",
71 "STATUS",
72 "ACL",
73 "NAMESPACE",
74 "AUTH=CRAM-MD5",
75 "AUTH=GSSAPI",
76 "AUTH=ANONYMOUS",
77 "AUTH=OAUTHBEARER",
78 "AUTH=XOAUTH2",
79 "STARTTLS",
80 "LOGINDISABLED",
81 "IDLE",
82 "SASL-IR",
83 "ENABLE",
84 "CONDSTORE",
85 "QRESYNC",
86 "LIST-EXTENDED",
87 "COMPRESS=DEFLATE",
88 "X-GM-EXT-1",
89 "ID",
90 NULL,
91};
92
98static bool cmd_queue_full(struct ImapAccountData *adata)
99{
100 if (((adata->nextcmd + 1) % adata->cmdslots) == adata->lastcmd)
101 return true;
102
103 return false;
104}
105
112static struct ImapCommand *cmd_new(struct ImapAccountData *adata)
113{
114 struct ImapCommand *cmd = NULL;
115
116 if (cmd_queue_full(adata))
117 {
118 mutt_debug(LL_DEBUG3, "IMAP command queue full\n");
119 return NULL;
120 }
121
122 cmd = adata->cmds + adata->nextcmd;
123 adata->nextcmd = (adata->nextcmd + 1) % adata->cmdslots;
124
125 snprintf(cmd->seq, sizeof(cmd->seq), "%c%04u", adata->seqid, adata->seqno++);
126 if (adata->seqno > 9999)
127 adata->seqno = 0;
128
129 cmd->state = IMAP_RES_NEW;
130
131 return cmd;
132}
133
144static int cmd_queue(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags)
145{
146 if (cmd_queue_full(adata))
147 {
148 mutt_debug(LL_DEBUG3, "Draining IMAP command pipeline\n");
149
150 const int rc = imap_exec(adata, NULL, flags & IMAP_CMD_POLL);
151
152 if (rc == IMAP_EXEC_ERROR)
153 return IMAP_RES_BAD;
154 }
155
156 struct ImapCommand *cmd = cmd_new(adata);
157 if (!cmd)
158 return IMAP_RES_BAD;
159
160 if (buf_add_printf(&adata->cmdbuf, "%s %s\r\n", cmd->seq, cmdstr) < 0)
161 return IMAP_RES_BAD;
162
163 return 0;
164}
165
170static void cmd_handle_fatal(struct ImapAccountData *adata)
171{
172 adata->status = IMAP_FATAL;
173
174 if (!adata->mailbox)
175 return;
176
177 struct ImapMboxData *mdata = adata->mailbox->mdata;
178
179 if ((adata->state >= IMAP_SELECTED) && (mdata->reopen & IMAP_REOPEN_ALLOW))
180 {
181 mx_fastclose_mailbox(adata->mailbox, true);
182 mutt_error(_("Mailbox %s@%s closed"), adata->conn->account.user,
183 adata->conn->account.host);
184 }
185
187 if (!adata->recovering)
188 {
189 adata->recovering = true;
190 if (imap_login(adata))
192 adata->recovering = false;
193 }
194}
195
204static int cmd_start(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags)
205{
206 int rc;
207
208 if (adata->status == IMAP_FATAL)
209 {
210 cmd_handle_fatal(adata);
211 return -1;
212 }
213
214 if (cmdstr && ((rc = cmd_queue(adata, cmdstr, flags)) < 0))
215 return rc;
216
217 if (flags & IMAP_CMD_QUEUE)
218 return 0;
219
220 if (buf_is_empty(&adata->cmdbuf))
221 return IMAP_RES_BAD;
222
223 rc = mutt_socket_send_d(adata->conn, adata->cmdbuf.data,
225 buf_reset(&adata->cmdbuf);
226
227 /* unidle when command queue is flushed */
228 if (adata->state == IMAP_IDLE)
229 adata->state = IMAP_SELECTED;
230
231 return (rc < 0) ? IMAP_RES_BAD : 0;
232}
233
240static int cmd_status(const char *s)
241{
242 s = imap_next_word((char *) s);
243
244 if (mutt_istr_startswith(s, "OK"))
245 return IMAP_RES_OK;
246 if (mutt_istr_startswith(s, "NO"))
247 return IMAP_RES_NO;
248
249 return IMAP_RES_BAD;
250}
251
260static void cmd_parse_expunge(struct ImapAccountData *adata, const char *s)
261{
262 unsigned int exp_msn;
263 struct Email *e = NULL;
264
265 mutt_debug(LL_DEBUG2, "Handling EXPUNGE\n");
266
267 struct ImapMboxData *mdata = adata->mailbox->mdata;
268
269 if (!mutt_str_atoui(s, &exp_msn) || (exp_msn < 1) ||
270 (exp_msn > imap_msn_highest(&mdata->msn)))
271 {
272 return;
273 }
274
275 e = imap_msn_get(&mdata->msn, exp_msn - 1);
276 if (e)
277 {
278 /* imap_expunge_mailbox() will rewrite e->index.
279 * It needs to resort using SORT_ORDER anyway, so setting to INT_MAX
280 * makes the code simpler and possibly more efficient. */
281 e->index = INT_MAX;
282 imap_edata_get(e)->msn = 0;
283 }
284
285 /* decrement seqno of those above. */
286 const size_t max_msn = imap_msn_highest(&mdata->msn);
287 for (unsigned int cur = exp_msn; cur < max_msn; cur++)
288 {
289 e = imap_msn_get(&mdata->msn, cur);
290 if (e)
291 imap_edata_get(e)->msn--;
292 imap_msn_set(&mdata->msn, cur - 1, e);
293 }
294 imap_msn_shrink(&mdata->msn, 1);
295
296 mdata->reopen |= IMAP_EXPUNGE_PENDING;
297}
298
307static void cmd_parse_vanished(struct ImapAccountData *adata, char *s)
308{
309 bool earlier = false;
310 int rc;
311 unsigned int uid = 0;
312
313 struct ImapMboxData *mdata = adata->mailbox->mdata;
314
315 mutt_debug(LL_DEBUG2, "Handling VANISHED\n");
316
317 if (mutt_istr_startswith(s, "(EARLIER)"))
318 {
319 /* The RFC says we should not decrement msns with the VANISHED EARLIER tag.
320 * My experimentation says that's crap. */
321 earlier = true;
322 s = imap_next_word(s);
323 }
324
325 char *end_of_seqset = s;
326 while (*end_of_seqset)
327 {
328 if (!strchr("0123456789:,", *end_of_seqset))
329 *end_of_seqset = '\0';
330 else
331 end_of_seqset++;
332 }
333
335 if (!iter)
336 {
337 mutt_debug(LL_DEBUG2, "VANISHED: empty seqset [%s]?\n", s);
338 return;
339 }
340
341 while ((rc = mutt_seqset_iterator_next(iter, &uid)) == 0)
342 {
343 struct Email *e = mutt_hash_int_find(mdata->uid_hash, uid);
344 if (!e)
345 continue;
346
347 unsigned int exp_msn = imap_edata_get(e)->msn;
348
349 /* imap_expunge_mailbox() will rewrite e->index.
350 * It needs to resort using SORT_ORDER anyway, so setting to INT_MAX
351 * makes the code simpler and possibly more efficient. */
352 e->index = INT_MAX;
353 imap_edata_get(e)->msn = 0;
354
355 if ((exp_msn < 1) || (exp_msn > imap_msn_highest(&mdata->msn)))
356 {
357 mutt_debug(LL_DEBUG1, "VANISHED: msn for UID %u is incorrect\n", uid);
358 continue;
359 }
360 if (imap_msn_get(&mdata->msn, exp_msn - 1) != e)
361 {
362 mutt_debug(LL_DEBUG1, "VANISHED: msn_index for UID %u is incorrect\n", uid);
363 continue;
364 }
365
366 imap_msn_remove(&mdata->msn, exp_msn - 1);
367
368 if (!earlier)
369 {
370 /* decrement seqno of those above. */
371 const size_t max_msn = imap_msn_highest(&mdata->msn);
372 for (unsigned int cur = exp_msn; cur < max_msn; cur++)
373 {
374 e = imap_msn_get(&mdata->msn, cur);
375 if (e)
376 imap_edata_get(e)->msn--;
377 imap_msn_set(&mdata->msn, cur - 1, e);
378 }
379
380 imap_msn_shrink(&mdata->msn, 1);
381 }
382 }
383
384 if (rc < 0)
385 mutt_debug(LL_DEBUG1, "VANISHED: illegal seqset %s\n", s);
386
388
390}
391
401static void cmd_parse_fetch(struct ImapAccountData *adata, char *s)
402{
403 unsigned int msn, uid;
404 struct Email *e = NULL;
405 char *flags = NULL;
406 int uid_checked = 0;
407 bool server_changes = false;
408
409 struct ImapMboxData *mdata = imap_mdata_get(adata->mailbox);
410
411 mutt_debug(LL_DEBUG3, "Handling FETCH\n");
412
413 if (!mutt_str_atoui(s, &msn))
414 {
415 mutt_debug(LL_DEBUG3, "Skipping FETCH response - illegal MSN\n");
416 return;
417 }
418
419 if ((msn < 1) || (msn > imap_msn_highest(&mdata->msn)))
420 {
421 mutt_debug(LL_DEBUG3, "Skipping FETCH response - MSN %u out of range\n", msn);
422 return;
423 }
424
425 e = imap_msn_get(&mdata->msn, msn - 1);
426 if (!e || !e->active)
427 {
428 mutt_debug(LL_DEBUG3, "Skipping FETCH response - MSN %u not in msn_index\n", msn);
429 return;
430 }
431
432 mutt_debug(LL_DEBUG2, "Message UID %u updated\n", imap_edata_get(e)->uid);
433 /* skip FETCH */
434 s = imap_next_word(s);
435 s = imap_next_word(s);
436
437 if (*s != '(')
438 {
439 mutt_debug(LL_DEBUG1, "Malformed FETCH response\n");
440 return;
441 }
442 s++;
443
444 while (*s)
445 {
446 SKIPWS(s);
447 size_t plen = mutt_istr_startswith(s, "FLAGS");
448 if (plen != 0)
449 {
450 flags = s;
451 if (uid_checked)
452 break;
453
454 s += plen;
455 SKIPWS(s);
456 if (*s != '(')
457 {
458 mutt_debug(LL_DEBUG1, "bogus FLAGS response: %s\n", s);
459 return;
460 }
461 s++;
462 while (*s && (*s != ')'))
463 s++;
464 if (*s == ')')
465 {
466 s++;
467 }
468 else
469 {
470 mutt_debug(LL_DEBUG1, "Unterminated FLAGS response: %s\n", s);
471 return;
472 }
473 }
474 else if ((plen = mutt_istr_startswith(s, "UID")))
475 {
476 s += plen;
477 SKIPWS(s);
478 if (!mutt_str_atoui(s, &uid))
479 {
480 mutt_debug(LL_DEBUG1, "Illegal UID. Skipping update\n");
481 return;
482 }
483 if (uid != imap_edata_get(e)->uid)
484 {
485 mutt_debug(LL_DEBUG1, "UID vs MSN mismatch. Skipping update\n");
486 return;
487 }
488 uid_checked = 1;
489 if (flags)
490 break;
491 s = imap_next_word(s);
492 }
493 else if ((plen = mutt_istr_startswith(s, "MODSEQ")))
494 {
495 s += plen;
496 SKIPWS(s);
497 if (*s != '(')
498 {
499 mutt_debug(LL_DEBUG1, "bogus MODSEQ response: %s\n", s);
500 return;
501 }
502 s++;
503 while (*s && (*s != ')'))
504 s++;
505 if (*s == ')')
506 {
507 s++;
508 }
509 else
510 {
511 mutt_debug(LL_DEBUG1, "Unterminated MODSEQ response: %s\n", s);
512 return;
513 }
514 }
515 else if (*s == ')')
516 {
517 break; /* end of request */
518 }
519 else if (*s)
520 {
521 mutt_debug(LL_DEBUG2, "Only handle FLAGS updates\n");
522 break;
523 }
524 }
525
526 if (flags)
527 {
528 imap_set_flags(adata->mailbox, e, flags, &server_changes);
529 if (server_changes)
530 {
531 /* If server flags could conflict with NeoMutt's flags, reopen the mailbox. */
532 if (e->changed)
533 mdata->reopen |= IMAP_EXPUNGE_PENDING;
534 else
535 mdata->check_status |= IMAP_FLAGS_PENDING;
536 }
537 }
538}
539
545static void cmd_parse_capability(struct ImapAccountData *adata, char *s)
546{
547 mutt_debug(LL_DEBUG3, "Handling CAPABILITY\n");
548
549 s = imap_next_word(s);
550 char *bracket = strchr(s, ']');
551 if (bracket)
552 *bracket = '\0';
553 FREE(&adata->capstr);
554 adata->capstr = mutt_str_dup(s);
555 adata->capabilities = 0;
556
557 while (*s)
558 {
559 for (size_t i = 0; Capabilities[i]; i++)
560 {
561 size_t len = mutt_istr_startswith(s, Capabilities[i]);
562 if (len != 0 && ((s[len] == '\0') || isspace(s[len])))
563 {
564 adata->capabilities |= (1 << i);
565 mutt_debug(LL_DEBUG3, " Found capability \"%s\": %zu\n", Capabilities[i], i);
566 break;
567 }
568 }
569 s = imap_next_word(s);
570 }
571}
572
578static void cmd_parse_list(struct ImapAccountData *adata, char *s)
579{
580 struct ImapList *list = NULL;
581 struct ImapList lb = { 0 };
582 char delimbuf[5] = { 0 }; /* worst case: "\\"\0 */
583 unsigned int litlen;
584
585 if (adata->cmdresult)
586 list = adata->cmdresult;
587 else
588 list = &lb;
589
590 memset(list, 0, sizeof(struct ImapList));
591
592 /* flags */
593 s = imap_next_word(s);
594 if (*s != '(')
595 {
596 mutt_debug(LL_DEBUG1, "Bad LIST response\n");
597 return;
598 }
599 s++;
600 while (*s)
601 {
602 if (mutt_istr_startswith(s, "\\NoSelect"))
603 list->noselect = true;
604 else if (mutt_istr_startswith(s, "\\NonExistent")) /* rfc5258 */
605 list->noselect = true;
606 else if (mutt_istr_startswith(s, "\\NoInferiors"))
607 list->noinferiors = true;
608 else if (mutt_istr_startswith(s, "\\HasNoChildren")) /* rfc5258*/
609 list->noinferiors = true;
610
611 s = imap_next_word(s);
612 if (*(s - 2) == ')')
613 break;
614 }
615
616 /* Delimiter */
617 if (!mutt_istr_startswith(s, "NIL"))
618 {
619 delimbuf[0] = '\0';
620 mutt_str_cat(delimbuf, 5, s);
621 imap_unquote_string(delimbuf);
622 list->delim = delimbuf[0];
623 }
624
625 /* Name */
626 s = imap_next_word(s);
627 /* Notes often responds with literals here. We need a real tokenizer. */
628 if (imap_get_literal_count(s, &litlen) == 0)
629 {
630 if (imap_cmd_step(adata) != IMAP_RES_CONTINUE)
631 {
632 adata->status = IMAP_FATAL;
633 return;
634 }
635
636 if (strlen(adata->buf) < litlen)
637 {
638 mutt_debug(LL_DEBUG1, "Error parsing LIST mailbox\n");
639 return;
640 }
641
642 list->name = adata->buf;
643 s = list->name + litlen;
644 if (s[0] != '\0')
645 {
646 s[0] = '\0';
647 s++;
648 SKIPWS(s);
649 }
650 }
651 else
652 {
653 list->name = s;
654 /* Exclude rfc5258 RECURSIVEMATCH CHILDINFO suffix */
655 s = imap_next_word(s);
656 if (s[0] != '\0')
657 s[-1] = '\0';
658 imap_unmunge_mbox_name(adata->unicode, list->name);
659 }
660
661 if (list->name[0] == '\0')
662 {
663 adata->delim = list->delim;
664 mutt_debug(LL_DEBUG3, "Root delimiter: %c\n", adata->delim);
665 }
666}
667
673static void cmd_parse_lsub(struct ImapAccountData *adata, char *s)
674{
675 if (adata->cmdresult)
676 {
677 /* caller will handle response itself */
678 cmd_parse_list(adata, s);
679 return;
680 }
681
682 const bool c_imap_check_subscribed = cs_subset_bool(NeoMutt->sub, "imap_check_subscribed");
683 if (!c_imap_check_subscribed)
684 return;
685
686 struct ImapList list = { 0 };
687
688 adata->cmdresult = &list;
689 cmd_parse_list(adata, s);
690 adata->cmdresult = NULL;
691 /* noselect is for a gmail quirk */
692 if (!list.name || list.noselect)
693 return;
694
695 mutt_debug(LL_DEBUG3, "Subscribing to %s\n", list.name);
696
697 char buf[256] = { 0 };
698 char quoted_name[256] = { 0 };
699 struct Buffer *err = buf_pool_get();
700 struct Url url = { 0 };
701
702 mutt_str_copy(buf, "mailboxes \"", sizeof(buf));
703 mutt_account_tourl(&adata->conn->account, &url);
704 /* escape \ and " */
705 imap_quote_string(quoted_name, sizeof(quoted_name), list.name, true);
706 url.path = quoted_name + 1;
707 url.path[strlen(url.path) - 1] = '\0';
708 const char *const c_imap_user = cs_subset_string(NeoMutt->sub, "imap_user");
709 if (mutt_str_equal(url.user, c_imap_user))
710 url.user = NULL;
711 url_tostring(&url, buf + 11, sizeof(buf) - 11, U_NO_FLAGS);
712 mutt_str_cat(buf, sizeof(buf), "\"");
713 if (parse_rc_line(buf, err))
714 mutt_debug(LL_DEBUG1, "Error adding subscribed mailbox: %s\n", buf_string(err));
715 buf_pool_release(&err);
716}
717
723static void cmd_parse_myrights(struct ImapAccountData *adata, const char *s)
724{
725 mutt_debug(LL_DEBUG2, "Handling MYRIGHTS\n");
726
727 s = imap_next_word((char *) s);
728 s = imap_next_word((char *) s);
729
730 /* zero out current rights set */
731 adata->mailbox->rights = 0;
732
733 while (*s && !isspace((unsigned char) *s))
734 {
735 switch (*s)
736 {
737 case 'a':
738 adata->mailbox->rights |= MUTT_ACL_ADMIN;
739 break;
740 case 'e':
742 break;
743 case 'i':
744 adata->mailbox->rights |= MUTT_ACL_INSERT;
745 break;
746 case 'k':
747 adata->mailbox->rights |= MUTT_ACL_CREATE;
748 break;
749 case 'l':
750 adata->mailbox->rights |= MUTT_ACL_LOOKUP;
751 break;
752 case 'p':
753 adata->mailbox->rights |= MUTT_ACL_POST;
754 break;
755 case 'r':
756 adata->mailbox->rights |= MUTT_ACL_READ;
757 break;
758 case 's':
759 adata->mailbox->rights |= MUTT_ACL_SEEN;
760 break;
761 case 't':
762 adata->mailbox->rights |= MUTT_ACL_DELETE;
763 break;
764 case 'w':
765 adata->mailbox->rights |= MUTT_ACL_WRITE;
766 break;
767 case 'x':
768 adata->mailbox->rights |= MUTT_ACL_DELMX;
769 break;
770
771 /* obsolete rights */
772 case 'c':
774 break;
775 case 'd':
777 break;
778 default:
779 mutt_debug(LL_DEBUG1, "Unknown right: %c\n", *s);
780 }
781 s++;
782 }
783}
784
791static struct Mailbox *find_mailbox(struct ImapAccountData *adata, const char *name)
792{
793 if (!adata || !adata->account || !name)
794 return NULL;
795
796 struct MailboxNode *np = NULL;
797 STAILQ_FOREACH(np, &adata->account->mailboxes, entries)
798 {
800 if (mutt_str_equal(name, mdata->name))
801 return np->mailbox;
802 }
803
804 return NULL;
805}
806
815static void cmd_parse_status(struct ImapAccountData *adata, char *s)
816{
817 unsigned int litlen = 0;
818
819 char *mailbox = imap_next_word(s);
820
821 /* We need a real tokenizer. */
822 if (imap_get_literal_count(mailbox, &litlen) == 0)
823 {
824 if (imap_cmd_step(adata) != IMAP_RES_CONTINUE)
825 {
826 adata->status = IMAP_FATAL;
827 return;
828 }
829
830 if (strlen(adata->buf) < litlen)
831 {
832 mutt_debug(LL_DEBUG1, "Error parsing STATUS mailbox\n");
833 return;
834 }
835
836 mailbox = adata->buf;
837 s = mailbox + litlen;
838 s[0] = '\0';
839 s++;
840 SKIPWS(s);
841 }
842 else
843 {
844 s = imap_next_word(mailbox);
845 s[-1] = '\0';
846 imap_unmunge_mbox_name(adata->unicode, mailbox);
847 }
848
849 struct Mailbox *m = find_mailbox(adata, mailbox);
850 struct ImapMboxData *mdata = imap_mdata_get(m);
851 if (!mdata)
852 {
853 mutt_debug(LL_DEBUG3, "Received status for an unexpected mailbox: %s\n", mailbox);
854 return;
855 }
856 uint32_t olduv = mdata->uidvalidity;
857 unsigned int oldun = mdata->uid_next;
858
859 if (*s++ != '(')
860 {
861 mutt_debug(LL_DEBUG1, "Error parsing STATUS\n");
862 return;
863 }
864 while ((s[0] != '\0') && (s[0] != ')'))
865 {
866 char *value = imap_next_word(s);
867
868 errno = 0;
869 const unsigned long ulcount = strtoul(value, &value, 10);
870 const bool truncated = ((errno == ERANGE) && (ulcount == ULONG_MAX)) ||
871 ((unsigned int) ulcount != ulcount);
872 const unsigned int count = (unsigned int) ulcount;
873
874 // we accept truncating a larger value only for UIDVALIDITY, to accommodate
875 // IMAP servers that use 64-bits for it. This seems to be what Thunderbird
876 // is also doing, see #3830
877 if (mutt_str_startswith(s, "UIDVALIDITY"))
878 {
879 if (truncated)
880 {
882 "UIDVALIDITY [%lu] exceeds 32 bits, "
883 "truncated to [%u]\n",
884 ulcount, count);
885 }
886 mdata->uidvalidity = count;
887 }
888 else
889 {
890 if (truncated)
891 {
892 mutt_debug(LL_DEBUG1, "Number in [%s] exceeds 32 bits\n", s);
893 return;
894 }
895 else
896 {
897 if (mutt_str_startswith(s, "MESSAGES"))
898 mdata->messages = count;
899 else if (mutt_str_startswith(s, "RECENT"))
900 mdata->recent = count;
901 else if (mutt_str_startswith(s, "UIDNEXT"))
902 mdata->uid_next = count;
903 else if (mutt_str_startswith(s, "UNSEEN"))
904 mdata->unseen = count;
905 }
906 }
907
908 s = value;
909 if ((s[0] != '\0') && (*s != ')'))
910 s = imap_next_word(s);
911 }
912 mutt_debug(LL_DEBUG3, "%s (UIDVALIDITY: %u, UIDNEXT: %u) %d messages, %d recent, %d unseen\n",
913 mdata->name, mdata->uidvalidity, mdata->uid_next, mdata->messages,
914 mdata->recent, mdata->unseen);
915
916 mutt_debug(LL_DEBUG3, "Running default STATUS handler\n");
917
918 mutt_debug(LL_DEBUG3, "Found %s in mailbox list (OV: %u ON: %u U: %d)\n",
919 mailbox, olduv, oldun, mdata->unseen);
920
921 bool new_mail = false;
922 const bool c_mail_check_recent = cs_subset_bool(NeoMutt->sub, "mail_check_recent");
923 if (c_mail_check_recent)
924 {
925 if ((olduv != 0) && (olduv == mdata->uidvalidity))
926 {
927 if (oldun < mdata->uid_next)
928 new_mail = (mdata->unseen > 0);
929 }
930 else if ((olduv == 0) && (oldun == 0))
931 {
932 /* first check per session, use recent. might need a flag for this. */
933 new_mail = (mdata->recent > 0);
934 }
935 else
936 {
937 new_mail = (mdata->unseen > 0);
938 }
939 }
940 else
941 {
942 new_mail = (mdata->unseen > 0);
943 }
944
945 m->has_new = new_mail;
946 m->msg_count = mdata->messages;
947 m->msg_unread = mdata->unseen;
948
949 // force back to keep detecting new mail until the mailbox is opened
950 if (m->has_new)
951 mdata->uid_next = oldun;
952
953 struct EventMailbox ev_m = { m };
955}
956
962static void cmd_parse_enabled(struct ImapAccountData *adata, const char *s)
963{
964 mutt_debug(LL_DEBUG2, "Handling ENABLED\n");
965
966 while ((s = imap_next_word((char *) s)) && (*s != '\0'))
967 {
968 if (mutt_istr_startswith(s, "UTF8=ACCEPT") || mutt_istr_startswith(s, "UTF8=ONLY"))
969 {
970 adata->unicode = true;
971 }
972 if (mutt_istr_startswith(s, "QRESYNC"))
973 adata->qresync = true;
974 }
975}
976
982static void cmd_parse_exists(struct ImapAccountData *adata, const char *pn)
983{
984 unsigned int count = 0;
985 mutt_debug(LL_DEBUG2, "Handling EXISTS\n");
986
987 if (!mutt_str_atoui(pn, &count))
988 {
989 mutt_debug(LL_DEBUG1, "Malformed EXISTS: '%s'\n", pn);
990 return;
991 }
992
993 struct ImapMboxData *mdata = adata->mailbox->mdata;
994
995 /* new mail arrived */
996 if (count < imap_msn_highest(&mdata->msn))
997 {
998 /* Notes 6.0.3 has a tendency to report fewer messages exist than
999 * it should. */
1000 mutt_debug(LL_DEBUG1, "Message count is out of sync\n");
1001 }
1002 else if (count == imap_msn_highest(&mdata->msn))
1003 {
1004 /* at least the InterChange server sends EXISTS messages freely,
1005 * even when there is no new mail */
1006 mutt_debug(LL_DEBUG3, "superfluous EXISTS message\n");
1007 }
1008 else
1009 {
1010 mutt_debug(LL_DEBUG2, "New mail in %s - %d messages total\n", mdata->name, count);
1011 mdata->reopen |= IMAP_NEWMAIL_PENDING;
1012 mdata->new_mail_count = count;
1013 }
1014}
1015
1022static int cmd_handle_untagged(struct ImapAccountData *adata)
1023{
1024 char *s = imap_next_word(adata->buf);
1025 char *pn = imap_next_word(s);
1026
1027 const bool c_imap_server_noise = cs_subset_bool(NeoMutt->sub, "imap_server_noise");
1028 if ((adata->state >= IMAP_SELECTED) && isdigit((unsigned char) *s))
1029 {
1030 /* pn vs. s: need initial seqno */
1031 pn = s;
1032 s = imap_next_word(s);
1033
1034 /* EXISTS, EXPUNGE, FETCH are always related to the SELECTED mailbox */
1035 if (mutt_istr_startswith(s, "EXISTS"))
1036 cmd_parse_exists(adata, pn);
1037 else if (mutt_istr_startswith(s, "EXPUNGE"))
1038 cmd_parse_expunge(adata, pn);
1039 else if (mutt_istr_startswith(s, "FETCH"))
1040 cmd_parse_fetch(adata, pn);
1041 }
1042 else if ((adata->state >= IMAP_SELECTED) && mutt_istr_startswith(s, "VANISHED"))
1043 {
1044 cmd_parse_vanished(adata, pn);
1045 }
1046 else if (mutt_istr_startswith(s, "CAPABILITY"))
1047 {
1048 cmd_parse_capability(adata, s);
1049 }
1050 else if (mutt_istr_startswith(s, "OK [CAPABILITY"))
1051 {
1052 cmd_parse_capability(adata, pn);
1053 }
1054 else if (mutt_istr_startswith(pn, "OK [CAPABILITY"))
1055 {
1057 }
1058 else if (mutt_istr_startswith(s, "LIST"))
1059 {
1060 cmd_parse_list(adata, s);
1061 }
1062 else if (mutt_istr_startswith(s, "LSUB"))
1063 {
1064 cmd_parse_lsub(adata, s);
1065 }
1066 else if (mutt_istr_startswith(s, "MYRIGHTS"))
1067 {
1068 cmd_parse_myrights(adata, s);
1069 }
1070 else if (mutt_istr_startswith(s, "SEARCH"))
1071 {
1072 cmd_parse_search(adata, s);
1073 }
1074 else if (mutt_istr_startswith(s, "STATUS"))
1075 {
1076 cmd_parse_status(adata, s);
1077 }
1078 else if (mutt_istr_startswith(s, "ENABLED"))
1079 {
1080 cmd_parse_enabled(adata, s);
1081 }
1082 else if (mutt_istr_startswith(s, "BYE"))
1083 {
1084 mutt_debug(LL_DEBUG2, "Handling BYE\n");
1085
1086 /* check if we're logging out */
1087 if (adata->status == IMAP_BYE)
1088 return 0;
1089
1090 /* server shut down our connection */
1091 s += 3;
1092 SKIPWS(s);
1093 mutt_error("%s", s);
1094 cmd_handle_fatal(adata);
1095
1096 return -1;
1097 }
1098 else if (c_imap_server_noise && mutt_istr_startswith(s, "NO"))
1099 {
1100 mutt_debug(LL_DEBUG2, "Handling untagged NO\n");
1101
1102 /* Display the warning message from the server */
1103 mutt_error("%s", s + 2);
1104 }
1105
1106 return 0;
1107}
1108
1118int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr)
1119{
1120 return cmd_start(adata, cmdstr, IMAP_CMD_NO_FLAGS);
1121}
1122
1133{
1134 if (!adata)
1135 return -1;
1136
1137 size_t len = 0;
1138 int c;
1139 int rc;
1140 int stillrunning = 0;
1141 struct ImapCommand *cmd = NULL;
1142
1143 if (adata->status == IMAP_FATAL)
1144 {
1145 cmd_handle_fatal(adata);
1146 return IMAP_RES_BAD;
1147 }
1148
1149 /* read into buffer, expanding buffer as necessary until we have a full
1150 * line */
1151 do
1152 {
1153 if (len == adata->blen)
1154 {
1155 mutt_mem_realloc(&adata->buf, adata->blen + IMAP_CMD_BUFSIZE);
1156 adata->blen = adata->blen + IMAP_CMD_BUFSIZE;
1157 mutt_debug(LL_DEBUG3, "grew buffer to %zu bytes\n", adata->blen);
1158 }
1159
1160 /* back up over '\0' */
1161 if (len)
1162 len--;
1163 c = mutt_socket_readln_d(adata->buf + len, adata->blen - len, adata->conn, MUTT_SOCK_LOG_FULL);
1164 if (c <= 0)
1165 {
1166 mutt_debug(LL_DEBUG1, "Error reading server response\n");
1167 cmd_handle_fatal(adata);
1168 return IMAP_RES_BAD;
1169 }
1170
1171 len += c;
1172 }
1173 /* if we've read all the way to the end of the buffer, we haven't read a
1174 * full line (mutt_socket_readln strips the \r, so we always have at least
1175 * one character free when we've read a full line) */
1176 while (len == adata->blen);
1177
1178 /* don't let one large string make cmd->buf hog memory forever */
1179 if ((adata->blen > IMAP_CMD_BUFSIZE) && (len <= IMAP_CMD_BUFSIZE))
1180 {
1182 adata->blen = IMAP_CMD_BUFSIZE;
1183 mutt_debug(LL_DEBUG3, "shrank buffer to %zu bytes\n", adata->blen);
1184 }
1185
1186 adata->lastread = mutt_date_now();
1187
1188 /* handle untagged messages. The caller still gets its shot afterwards. */
1189 if ((mutt_str_startswith(adata->buf, "* ") ||
1190 mutt_str_startswith(imap_next_word(adata->buf), "OK [")) &&
1191 cmd_handle_untagged(adata))
1192 {
1193 return IMAP_RES_BAD;
1194 }
1195
1196 /* server demands a continuation response from us */
1197 if (adata->buf[0] == '+')
1198 return IMAP_RES_RESPOND;
1199
1200 /* Look for tagged command completions.
1201 *
1202 * Some response handlers can end up recursively calling
1203 * imap_cmd_step() and end up handling all tagged command
1204 * completions.
1205 * (e.g. FETCH->set_flag->set_header_color->~h pattern match.)
1206 *
1207 * Other callers don't even create an adata->cmds entry.
1208 *
1209 * For both these cases, we default to returning OK */
1210 rc = IMAP_RES_OK;
1211 c = adata->lastcmd;
1212 do
1213 {
1214 cmd = &adata->cmds[c];
1215 if (cmd->state == IMAP_RES_NEW)
1216 {
1217 if (mutt_str_startswith(adata->buf, cmd->seq))
1218 {
1219 if (!stillrunning)
1220 {
1221 /* first command in queue has finished - move queue pointer up */
1222 adata->lastcmd = (adata->lastcmd + 1) % adata->cmdslots;
1223 }
1224 cmd->state = cmd_status(adata->buf);
1225 rc = cmd->state;
1226 if (cmd->state == IMAP_RES_NO || cmd->state == IMAP_RES_BAD)
1227 {
1228 mutt_message(_("IMAP command failed: %s"), adata->buf);
1229 }
1230 }
1231 else
1232 {
1233 stillrunning++;
1234 }
1235 }
1236
1237 c = (c + 1) % adata->cmdslots;
1238 } while (c != adata->nextcmd);
1239
1240 if (stillrunning)
1241 {
1242 rc = IMAP_RES_CONTINUE;
1243 }
1244 else
1245 {
1246 mutt_debug(LL_DEBUG3, "IMAP queue drained\n");
1247 imap_cmd_finish(adata);
1248 }
1249
1250 return rc;
1251}
1252
1259bool imap_code(const char *s)
1260{
1261 return cmd_status(s) == IMAP_RES_OK;
1262}
1263
1270const char *imap_cmd_trailer(struct ImapAccountData *adata)
1271{
1272 static const char *notrailer = "";
1273 const char *s = adata->buf;
1274
1275 if (!s)
1276 {
1277 mutt_debug(LL_DEBUG2, "not a tagged response\n");
1278 return notrailer;
1279 }
1280
1281 s = imap_next_word((char *) s);
1282 if (!s || (!mutt_istr_startswith(s, "OK") && !mutt_istr_startswith(s, "NO") &&
1283 !mutt_istr_startswith(s, "BAD")))
1284 {
1285 mutt_debug(LL_DEBUG2, "not a command completion: %s\n", adata->buf);
1286 return notrailer;
1287 }
1288
1289 s = imap_next_word((char *) s);
1290 if (!s)
1291 return notrailer;
1292
1293 return s;
1294}
1295
1307int imap_exec(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags)
1308{
1309 int rc;
1310
1311 if (flags & IMAP_CMD_SINGLE)
1312 {
1313 // Process any existing commands
1314 if (adata->nextcmd != adata->lastcmd)
1315 imap_exec(adata, NULL, IMAP_CMD_POLL);
1316 }
1317
1318 rc = cmd_start(adata, cmdstr, flags);
1319 if (rc < 0)
1320 {
1321 cmd_handle_fatal(adata);
1322 return IMAP_EXEC_FATAL;
1323 }
1324
1325 if (flags & IMAP_CMD_QUEUE)
1326 return IMAP_EXEC_SUCCESS;
1327
1328 const short c_imap_poll_timeout = cs_subset_number(NeoMutt->sub, "imap_poll_timeout");
1329 if ((flags & IMAP_CMD_POLL) && (c_imap_poll_timeout > 0) &&
1330 ((mutt_socket_poll(adata->conn, c_imap_poll_timeout)) == 0))
1331 {
1332 mutt_error(_("Connection to %s timed out"), adata->conn->account.host);
1333 cmd_handle_fatal(adata);
1334 return IMAP_EXEC_FATAL;
1335 }
1336
1337 /* Allow interruptions, particularly useful if there are network problems. */
1339 do
1340 {
1341 rc = imap_cmd_step(adata);
1342 // The queue is empty, so the single command has been processed
1343 if ((flags & IMAP_CMD_SINGLE) && (adata->nextcmd == adata->lastcmd))
1344 break;
1345 } while (rc == IMAP_RES_CONTINUE);
1347
1348 if (rc == IMAP_RES_NO)
1349 return IMAP_EXEC_ERROR;
1350 if (rc != IMAP_RES_OK)
1351 {
1352 if (adata->status != IMAP_FATAL)
1353 return IMAP_EXEC_ERROR;
1354
1355 mutt_debug(LL_DEBUG1, "command failed: %s\n", adata->buf);
1356 return IMAP_EXEC_FATAL;
1357 }
1358
1359 return IMAP_EXEC_SUCCESS;
1360}
1361
1373{
1374 if (!adata)
1375 return;
1376
1377 if (adata->status == IMAP_FATAL)
1378 {
1379 adata->closing = false;
1380 cmd_handle_fatal(adata);
1381 return;
1382 }
1383
1384 if (!(adata->state >= IMAP_SELECTED) || (adata->mailbox && adata->closing))
1385 {
1386 adata->closing = false;
1387 return;
1388 }
1389
1390 adata->closing = false;
1391
1392 struct ImapMboxData *mdata = imap_mdata_get(adata->mailbox);
1393
1394 if (mdata && mdata->reopen & IMAP_REOPEN_ALLOW)
1395 {
1396 // First remove expunged emails from the msn_index
1397 if (mdata->reopen & IMAP_EXPUNGE_PENDING)
1398 {
1399 mutt_debug(LL_DEBUG2, "Expunging mailbox\n");
1400 imap_expunge_mailbox(adata->mailbox, true);
1401 /* Detect whether we've gotten unexpected EXPUNGE messages */
1402 if (!(mdata->reopen & IMAP_EXPUNGE_EXPECTED))
1403 mdata->check_status |= IMAP_EXPUNGE_PENDING;
1405 }
1406
1407 // Then add new emails to it
1408 if (mdata->reopen & IMAP_NEWMAIL_PENDING)
1409 {
1410 const size_t max_msn = imap_msn_highest(&mdata->msn);
1411 if (mdata->new_mail_count > max_msn)
1412 {
1413 if (!(mdata->reopen & IMAP_EXPUNGE_PENDING))
1414 mdata->check_status |= IMAP_NEWMAIL_PENDING;
1415
1416 mutt_debug(LL_DEBUG2, "Fetching new mails from %zd to %u\n",
1417 max_msn + 1, mdata->new_mail_count);
1418 imap_read_headers(adata->mailbox, max_msn + 1, mdata->new_mail_count, false);
1419 }
1420 }
1421
1422 // And to finish inform about MUTT_REOPEN if needed
1423 if (mdata->reopen & IMAP_EXPUNGE_PENDING && !(mdata->reopen & IMAP_EXPUNGE_EXPECTED))
1424 mdata->check_status |= IMAP_EXPUNGE_PENDING;
1425
1426 if (mdata->reopen & IMAP_EXPUNGE_PENDING)
1428 }
1429
1430 adata->status = 0;
1431}
1432
1440{
1441 int rc;
1442
1443 if (cmd_start(adata, "IDLE", IMAP_CMD_POLL) < 0)
1444 {
1445 cmd_handle_fatal(adata);
1446 return -1;
1447 }
1448
1449 const short c_imap_poll_timeout = cs_subset_number(NeoMutt->sub, "imap_poll_timeout");
1450 if ((c_imap_poll_timeout > 0) &&
1451 ((mutt_socket_poll(adata->conn, c_imap_poll_timeout)) == 0))
1452 {
1453 mutt_error(_("Connection to %s timed out"), adata->conn->account.host);
1454 cmd_handle_fatal(adata);
1455 return -1;
1456 }
1457
1458 do
1459 {
1460 rc = imap_cmd_step(adata);
1461 } while (rc == IMAP_RES_CONTINUE);
1462
1463 if (rc == IMAP_RES_RESPOND)
1464 {
1465 /* successfully entered IDLE state */
1466 adata->state = IMAP_IDLE;
1467 /* queue automatic exit when next command is issued */
1468 buf_addstr(&adata->cmdbuf, "DONE\r\n");
1469 rc = IMAP_RES_OK;
1470 }
1471 if (rc != IMAP_RES_OK)
1472 {
1473 mutt_debug(LL_DEBUG1, "error starting IDLE\n");
1474 return -1;
1475 }
1476
1477 return 0;
1478}
const char * mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
Definition: atoi.c:214
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:221
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:93
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:308
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:243
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:97
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:144
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
Convenience wrapper for the config headers.
Connection Library.
Convenience wrapper for the core headers.
#define MUTT_ACL_CREATE
Create a mailbox.
Definition: mailbox.h:62
@ NT_MAILBOX_CHANGE
Mailbox has been changed.
Definition: mailbox.h:173
#define MUTT_ACL_DELMX
Delete a mailbox.
Definition: mailbox.h:64
#define MUTT_ACL_POST
Post (submit messages to the server)
Definition: mailbox.h:68
#define MUTT_ACL_LOOKUP
Lookup mailbox (visible to 'list')
Definition: mailbox.h:67
#define MUTT_ACL_INSERT
Add/copy into the mailbox (used when editing a message)
Definition: mailbox.h:66
#define MUTT_ACL_DELETE
Delete a message.
Definition: mailbox.h:63
#define MUTT_ACL_EXPUNGE
Expunge messages.
Definition: mailbox.h:65
#define MUTT_ACL_WRITE
Write to a message (for flagging or linking threads)
Definition: mailbox.h:71
#define MUTT_ACL_SEEN
Change the 'seen' status of a message.
Definition: mailbox.h:70
#define MUTT_ACL_ADMIN
Administer the account (get/set permissions)
Definition: mailbox.h:61
#define MUTT_ACL_READ
Read the mailbox.
Definition: mailbox.h:69
Structs that make up an email.
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_message(...)
Definition: logging2.h:91
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
void * mutt_hash_int_find(const struct HashTable *table, unsigned int intkey)
Find the HashElem data in a Hash Table element using a key.
Definition: hash.c:392
static void cmd_parse_list(struct ImapAccountData *adata, char *s)
Parse a server LIST command (list mailboxes)
Definition: command.c:578
int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr)
Given an IMAP command, send it to the server.
Definition: command.c:1118
static void cmd_parse_capability(struct ImapAccountData *adata, char *s)
Set capability bits according to CAPABILITY response.
Definition: command.c:545
static void cmd_parse_lsub(struct ImapAccountData *adata, char *s)
Parse a server LSUB (list subscribed mailboxes)
Definition: command.c:673
static void cmd_parse_status(struct ImapAccountData *adata, char *s)
Parse status from server.
Definition: command.c:815
static int cmd_handle_untagged(struct ImapAccountData *adata)
Fallback parser for otherwise unhandled messages.
Definition: command.c:1022
static struct Mailbox * find_mailbox(struct ImapAccountData *adata, const char *name)
Find a Mailbox by its name.
Definition: command.c:791
static void cmd_parse_exists(struct ImapAccountData *adata, const char *pn)
Parse EXISTS message from serer.
Definition: command.c:982
static const char *const Capabilities[]
Server capabilities strings that we understand.
Definition: command.c:68
const char * imap_cmd_trailer(struct ImapAccountData *adata)
Extra information after tagged command response if any.
Definition: command.c:1270
static void cmd_parse_myrights(struct ImapAccountData *adata, const char *s)
Set rights bits according to MYRIGHTS response.
Definition: command.c:723
int imap_cmd_idle(struct ImapAccountData *adata)
Enter the IDLE state.
Definition: command.c:1439
int imap_cmd_step(struct ImapAccountData *adata)
Reads server responses from an IMAP command.
Definition: command.c:1132
static int cmd_status(const char *s)
Parse response line for tagged OK/NO/BAD.
Definition: command.c:240
static int cmd_start(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags)
Start a new IMAP command.
Definition: command.c:204
static void cmd_parse_expunge(struct ImapAccountData *adata, const char *s)
Parse expunge command.
Definition: command.c:260
static void cmd_parse_enabled(struct ImapAccountData *adata, const char *s)
Record what the server has enabled.
Definition: command.c:962
static int cmd_queue(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags)
Add a IMAP command to the queue.
Definition: command.c:144
static void cmd_parse_vanished(struct ImapAccountData *adata, char *s)
Parse vanished command.
Definition: command.c:307
bool imap_code(const char *s)
Was the command successful.
Definition: command.c:1259
static bool cmd_queue_full(struct ImapAccountData *adata)
Is the IMAP command queue full?
Definition: command.c:98
int imap_exec(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags)
Execute a command and wait for the response from the server.
Definition: command.c:1307
static void cmd_handle_fatal(struct ImapAccountData *adata)
When ImapAccountData is in fatal state, do what we can.
Definition: command.c:170
static void cmd_parse_fetch(struct ImapAccountData *adata, char *s)
Load fetch response into ImapAccountData.
Definition: command.c:401
static struct ImapCommand * cmd_new(struct ImapAccountData *adata)
Create and queue a new command control block.
Definition: command.c:112
#define IMAP_CMD_BUFSIZE
Definition: command.c:61
void imap_cmd_finish(struct ImapAccountData *adata)
Attempt to perform cleanup.
Definition: command.c:1372
struct ImapEmailData * imap_edata_get(struct Email *e)
Get the private data for this Email.
Definition: edata.c:67
struct ImapMboxData * imap_mdata_get(struct Mailbox *m)
Get the Mailbox data for this mailbox.
Definition: mdata.c:60
char * imap_set_flags(struct Mailbox *m, struct Email *e, char *s, bool *server_changes)
Fill the message header according to the server flags.
Definition: message.c:1918
int imap_read_headers(struct Mailbox *m, unsigned int msn_begin, unsigned int msn_end, bool initial_download)
Read headers from the server.
Definition: message.c:1341
void imap_unmunge_mbox_name(bool unicode, char *s)
Remove quoting from a mailbox name.
Definition: util.c:938
#define IMAP_CMD_NO_FLAGS
No flags are set.
Definition: private.h:71
#define IMAP_RES_RESPOND
+
Definition: private.h:57
@ IMAP_IDLE
Connection is idle.
Definition: private.h:111
@ IMAP_SELECTED
Mailbox is selected.
Definition: private.h:108
#define IMAP_EXPUNGE_PENDING
Messages on the server have been expunged.
Definition: private.h:66
int imap_get_literal_count(const char *buf, unsigned int *bytes)
Write number of bytes in an IMAP literal into bytes.
Definition: util.c:741
#define IMAP_RES_OK
<tag> OK ...
Definition: private.h:55
#define IMAP_EXPUNGE_EXPECTED
Messages will be expunged from the server.
Definition: private.h:65
#define IMAP_CMD_POLL
Poll the tcp connection before running the imap command.
Definition: private.h:74
#define IMAP_REOPEN_ALLOW
Allow re-opening a folder upon expunge.
Definition: private.h:64
struct SeqsetIterator * mutt_seqset_iterator_new(const char *seqset)
Create a new Sequence Set Iterator.
Definition: util.c:1086
void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick)
Quote string according to IMAP rules.
Definition: util.c:847
void imap_unquote_string(char *s)
Equally stupid unquoting routine.
Definition: util.c:884
#define IMAP_CMD_PASS
Command contains a password. Suppress logging.
Definition: private.h:72
int mutt_seqset_iterator_next(struct SeqsetIterator *iter, unsigned int *next)
Get the next UID from a Sequence Set.
Definition: util.c:1107
@ IMAP_EXEC_SUCCESS
Imap command executed or queued successfully.
Definition: private.h:82
@ IMAP_EXEC_ERROR
Imap command failure.
Definition: private.h:83
@ IMAP_EXEC_FATAL
Imap connection failure.
Definition: private.h:84
void mutt_seqset_iterator_free(struct SeqsetIterator **ptr)
Free a Sequence Set Iterator.
Definition: util.c:1166
#define IMAP_LOG_PASS
Definition: private.h:50
#define IMAP_NEWMAIL_PENDING
New mail is waiting on the server.
Definition: private.h:67
#define IMAP_FLAGS_PENDING
Flags have changed on the server.
Definition: private.h:68
@ IMAP_BYE
Logged out from server.
Definition: private.h:96
@ IMAP_FATAL
Unrecoverable error occurred.
Definition: private.h:95
#define IMAP_RES_NEW
ImapCommand.state additions.
Definition: private.h:58
#define IMAP_RES_NO
<tag> NO ...
Definition: private.h:53
void cmd_parse_search(struct ImapAccountData *adata, const char *s)
Store SEARCH response for later use.
Definition: search.c:256
#define IMAP_CMD_SINGLE
Run a single command.
Definition: private.h:75
#define IMAP_RES_CONTINUE
* ...
Definition: private.h:56
char * imap_next_word(char *s)
Find where the next IMAP word begins.
Definition: util.c:785
#define IMAP_RES_BAD
<tag> BAD ...
Definition: private.h:54
uint8_t ImapCmdFlags
Flags for imap_exec(), e.g. IMAP_CMD_PASS.
Definition: private.h:70
#define IMAP_LOG_CMD
Definition: private.h:48
#define IMAP_CMD_QUEUE
Queue a command, do not execute.
Definition: private.h:73
void imap_close_connection(struct ImapAccountData *adata)
Close an IMAP connection.
Definition: imap.c:850
void imap_expunge_mailbox(struct Mailbox *m, bool resort)
Purge messages from the server.
Definition: imap.c:670
int imap_login(struct ImapAccountData *adata)
Open an IMAP connection.
Definition: imap.c:1776
@ LL_DEBUG3
Log at debug level 3.
Definition: logging2.h:45
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
#define FREE(x)
Definition: memory.h:45
size_t imap_msn_shrink(struct MSNArray *msn, size_t num)
Remove a number of entries from the end of the cache.
Definition: msn.c:104
size_t imap_msn_highest(const struct MSNArray *msn)
Return the highest MSN in use.
Definition: msn.c:70
struct Email * imap_msn_get(const struct MSNArray *msn, size_t idx)
Return the Email associated with an msn.
Definition: msn.c:81
void imap_msn_set(struct MSNArray *msn, size_t idx, struct Email *e)
Cache an Email into a given position.
Definition: msn.c:93
void imap_msn_remove(struct MSNArray *msn, size_t idx)
Remove an entry from the cache.
Definition: msn.c:114
IMAP MSN helper functions.
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:455
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:173
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:709
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:230
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:630
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:242
char * mutt_str_cat(char *buf, size_t buflen, const char *s)
Concatenate two strings.
Definition: string.c:268
void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:80
ConnAccount object used by POP and IMAP.
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
NeoMutt Logging.
void mx_fastclose_mailbox(struct Mailbox *m, bool keep_account)
Free up memory associated with the Mailbox.
Definition: mx.c:412
API for mailboxes.
@ NT_MAILBOX
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition: notify_type.h:49
Notmuch-specific Mailbox data.
Text parsing functions.
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
Pop-specific Account data.
Pop-specific Email data.
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
enum CommandResult parse_rc_line(const char *line, struct Buffer *err)
Parse a line of user config.
Definition: rc.c:104
GUI display the mailboxes in a side panel.
void mutt_sig_allow_interrupt(bool allow)
Allow/disallow Ctrl-C (SIGINT)
Definition: signal.c:254
int mutt_socket_poll(struct Connection *conn, time_t wait_secs)
Checks whether reads would block.
Definition: socket.c:182
int mutt_socket_readln_d(char *buf, size_t buflen, struct Connection *conn, int dbg)
Read a line from a socket.
Definition: socket.c:238
#define MUTT_SOCK_LOG_FULL
Definition: socket.h:54
#define mutt_socket_send_d(conn, buf, dbg)
Definition: socket.h:58
#define SKIPWS(ch)
Definition: string2.h:45
struct MailboxList mailboxes
List of Mailboxes.
Definition: account.h:40
String manipulation buffer.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:37
char user[128]
Username.
Definition: connaccount.h:56
char host[128]
Server to login to.
Definition: connaccount.h:54
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:49
The envelope/body of an email.
Definition: email.h:39
bool active
Message is not to be removed.
Definition: email.h:76
bool changed
Email has been edited.
Definition: email.h:77
int index
The absolute (unsorted) message number.
Definition: email.h:113
An Event that happened to a Mailbox.
Definition: mailbox.h:187
IMAP-specific Account data -.
Definition: adata.h:40
char delim
Path delimiter.
Definition: adata.h:75
bool qresync
true, if QRESYNC is successfully ENABLE'd
Definition: adata.h:63
struct ImapList * cmdresult
Definition: adata.h:66
int lastcmd
Last command in the queue.
Definition: adata.h:72
bool closing
If true, we are waiting for CLOSE completion.
Definition: adata.h:43
time_t lastread
last time we read a command for the server
Definition: adata.h:58
unsigned char seqid
tag sequence prefix
Definition: adata.h:56
bool unicode
If true, we can send UTF-8, and the server will use UTF8 rather than mUTF7.
Definition: adata.h:62
ImapCapFlags capabilities
Capability flags.
Definition: adata.h:55
struct Account * account
Parent Account.
Definition: adata.h:78
size_t blen
Definition: adata.h:60
int nextcmd
Next command to be sent.
Definition: adata.h:71
unsigned char state
ImapState, e.g. IMAP_AUTHENTICATED.
Definition: adata.h:44
struct Mailbox * mailbox
Current selected mailbox.
Definition: adata.h:76
char * capstr
Capability string from the server.
Definition: adata.h:54
struct ImapCommand * cmds
Queue of commands for the server.
Definition: adata.h:69
unsigned char status
ImapFlags, e.g. IMAP_FATAL.
Definition: adata.h:45
int cmdslots
Size of the command queue.
Definition: adata.h:70
char * buf
Definition: adata.h:59
unsigned int seqno
tag sequence number, e.g. '{seqid}0001'
Definition: adata.h:57
bool recovering
Definition: adata.h:42
struct Connection * conn
Connection to IMAP server.
Definition: adata.h:41
struct Buffer cmdbuf
Definition: adata.h:73
IMAP command structure.
Definition: private.h:160
int state
Command state, e.g. IMAP_RES_NEW.
Definition: private.h:162
char seq[SEQ_LEN+1]
Command tag, e.g. 'a0001'.
Definition: private.h:161
unsigned int msn
Message Sequence Number.
Definition: edata.h:46
Items in an IMAP browser.
Definition: private.h:149
bool noselect
Definition: private.h:152
bool noinferiors
Definition: private.h:153
char * name
Definition: private.h:150
char delim
Definition: private.h:151
IMAP-specific Mailbox data -.
Definition: mdata.h:40
ImapOpenFlags reopen
Flags, e.g. IMAP_REOPEN_ALLOW.
Definition: mdata.h:45
unsigned int uid_next
Definition: mdata.h:52
struct ListHead flags
Definition: mdata.h:50
struct HashTable * uid_hash
Hash Table: "uid" -> Email.
Definition: mdata.h:59
char * name
Mailbox name.
Definition: mdata.h:41
List of Mailboxes.
Definition: mailbox.h:154
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:155
A mailbox.
Definition: mailbox.h:79
bool has_new
Mailbox has new mail.
Definition: mailbox.h:85
int msg_count
Total number of messages.
Definition: mailbox.h:88
AclFlags rights
ACL bits, see AclFlags.
Definition: mailbox.h:119
void * mdata
Driver specific data.
Definition: mailbox.h:132
char * name
A short name for the Mailbox.
Definition: mailbox.h:82
struct Notify * notify
Notifications: NotifyMailbox, EventMailbox.
Definition: mailbox.h:145
int msg_unread
Number of unread messages.
Definition: mailbox.h:89
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
UID Sequence Set Iterator.
Definition: private.h:169
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:69
char * user
Username.
Definition: url.h:71
char * path
Path.
Definition: url.h:75
int url_tostring(struct Url *url, char *dest, size_t len, uint8_t flags)
Output the URL string for a given Url object.
Definition: url.c:423
#define U_NO_FLAGS
Definition: url.h:49