NeoMutt  2023-05-17-56-ga67199
Teaching an old dog new tricks
DOXYGEN
mh.c
Go to the documentation of this file.
1
34#include "config.h"
35#include <ctype.h>
36#include <dirent.h>
37#include <errno.h>
38#include <fcntl.h>
39#include <inttypes.h>
40#include <limits.h>
41#include <stdbool.h>
42#include <stdio.h>
43#include <string.h>
44#include <sys/stat.h>
45#include <unistd.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 "lib.h"
52#include "progress/lib.h"
53#include "copy.h"
54#include "edata.h"
55#include "errno.h"
56#include "globals.h" // IWYU pragma: keep
57#include "mdata.h"
58#include "mdemail.h"
59#include "mx.h"
60#include "sequence.h"
61#ifdef USE_INOTIFY
62#include "monitor.h"
63#endif
64#ifdef USE_HCACHE
65#include "hcache/lib.h"
66#endif
67
68struct Progress;
69
78bool mh_mkstemp(struct Mailbox *m, FILE **fp, char **tgt)
79{
80 int fd;
81 char path[PATH_MAX] = { 0 };
82
83 mode_t omask = umask(mh_umask(m));
84 while (true)
85 {
86 snprintf(path, sizeof(path), "%s/.neomutt-%s-%d-%" PRIu64, mailbox_path(m),
87 NONULL(ShortHostname), (int) getpid(), mutt_rand64());
88 fd = open(path, O_WRONLY | O_EXCL | O_CREAT, 0666);
89 if (fd == -1)
90 {
91 if (errno != EEXIST)
92 {
93 mutt_perror(path);
94 umask(omask);
95 return false;
96 }
97 }
98 else
99 {
100 *tgt = mutt_str_dup(path);
101 break;
102 }
103 }
104 umask(omask);
105
106 *fp = fdopen(fd, "w");
107 if (!*fp)
108 {
109 FREE(tgt);
110 close(fd);
111 unlink(path);
112 return false;
113 }
114
115 return true;
116}
117
126static int mh_already_notified(struct Mailbox *m, int msgno)
127{
128 char path[PATH_MAX] = { 0 };
129 struct stat st = { 0 };
130
131 if ((snprintf(path, sizeof(path), "%s/%d", mailbox_path(m), msgno) < sizeof(path)) &&
132 (stat(path, &st) == 0))
133 {
135 }
136 return -1;
137}
138
149static bool mh_valid_message(const char *s)
150{
151 for (; *s; s++)
152 {
153 if (!isdigit((unsigned char) *s))
154 return false;
155 }
156 return true;
157}
158
166int mh_check_empty(const char *path)
167{
168 struct dirent *de = NULL;
169 int rc = 1; /* assume empty until we find a message */
170
171 DIR *dir = mutt_file_opendir(path, MUTT_OPENDIR_NONE);
172 if (!dir)
173 return -1;
174 while ((de = readdir(dir)))
175 {
176 if (mh_valid_message(de->d_name))
177 {
178 rc = 0;
179 break;
180 }
181 }
182 closedir(dir);
183
184 return rc;
185}
186
190static enum MxStatus mh_mbox_check_stats(struct Mailbox *m, uint8_t flags)
191{
192 struct MhSequences mhs = { 0 };
193 DIR *dir = NULL;
194 struct dirent *de = NULL;
195
196 /* when $mail_check_recent is set and the .mh_sequences file hasn't changed
197 * since the last m visit, there is no "new mail" */
198 const bool c_mail_check_recent = cs_subset_bool(NeoMutt->sub, "mail_check_recent");
199 if (c_mail_check_recent && (mh_seq_changed(m) <= 0))
200 {
201 return MX_STATUS_OK;
202 }
203
204 if (mh_seq_read(&mhs, mailbox_path(m)) < 0)
205 return MX_STATUS_ERROR;
206
207 m->msg_count = 0;
208 m->msg_unread = 0;
209 m->msg_flagged = 0;
210
211 enum MxStatus rc = MX_STATUS_OK;
212 bool check_new = true;
213 for (int i = mhs.max; i > 0; i--)
214 {
215 if ((mh_seq_check(&mhs, i) & MH_SEQ_FLAGGED))
216 m->msg_flagged++;
217 if (mh_seq_check(&mhs, i) & MH_SEQ_UNSEEN)
218 {
219 m->msg_unread++;
220 if (check_new)
221 {
222 /* if the first unseen message we encounter was in the m during the
223 * last visit, don't notify about it */
224 if (!c_mail_check_recent || (mh_already_notified(m, i) == 0))
225 {
226 m->has_new = true;
228 }
229 /* Because we are traversing from high to low, we can stop
230 * checking for new mail after the first unseen message.
231 * Whether it resulted in "new mail" or not. */
232 check_new = false;
233 }
234 }
235 }
236
237 mh_seq_free(&mhs);
238
240 if (dir)
241 {
242 while ((de = readdir(dir)))
243 {
244 if (*de->d_name == '.')
245 continue;
246 if (mh_valid_message(de->d_name))
247 m->msg_count++;
248 }
249 closedir(dir);
250 }
251
252 return rc;
253}
254
260static void mh_update_maildir(struct MdEmailArray *mda, struct MhSequences *mhs)
261{
262 struct MdEmail *md = NULL;
263 struct MdEmail **mdp = NULL;
264 ARRAY_FOREACH(mdp, mda)
265 {
266 md = *mdp;
267 char *p = strrchr(md->email->path, '/');
268 if (p)
269 p++;
270 else
271 p = md->email->path;
272
273 int i = 0;
274 if (!mutt_str_atoi_full(p, &i))
275 continue;
276 MhSeqFlags flags = mh_seq_check(mhs, i);
277
278 md->email->read = !(flags & MH_SEQ_UNSEEN);
279 md->email->flagged = (flags & MH_SEQ_FLAGGED);
280 md->email->replied = (flags & MH_SEQ_REPLIED);
281 }
282}
283
293static int mh_commit_msg(struct Mailbox *m, struct Message *msg, struct Email *e, bool updseq)
294{
295 struct dirent *de = NULL;
296 char *cp = NULL, *dep = NULL;
297 unsigned int n, hi = 0;
298 char path[PATH_MAX] = { 0 };
299 char tmp[16] = { 0 };
300
301 if (mutt_file_fsync_close(&msg->fp))
302 {
303 mutt_perror(_("Could not flush message to disk"));
304 return -1;
305 }
306
308 if (!dir)
309 {
311 return -1;
312 }
313
314 /* figure out what the next message number is */
315 while ((de = readdir(dir)))
316 {
317 dep = de->d_name;
318 if (*dep == ',')
319 dep++;
320 cp = dep;
321 while (*cp)
322 {
323 if (!isdigit((unsigned char) *cp))
324 break;
325 cp++;
326 }
327 if (*cp == '\0')
328 {
329 if (!mutt_str_atoui(dep, &n))
330 mutt_debug(LL_DEBUG2, "Invalid MH message number '%s'\n", dep);
331 if (n > hi)
332 hi = n;
333 }
334 }
335 closedir(dir);
336
337 /* Now try to rename the file to the proper name.
338 * Note: We may have to try multiple times, until we find a free slot. */
339
340 while (true)
341 {
342 hi++;
343 snprintf(tmp, sizeof(tmp), "%u", hi);
344 snprintf(path, sizeof(path), "%s/%s", mailbox_path(m), tmp);
345 if (mutt_file_safe_rename(msg->path, path) == 0)
346 {
347 if (e)
348 mutt_str_replace(&e->path, tmp);
349 mutt_str_replace(&msg->committed_path, path);
350 FREE(&msg->path);
351 break;
352 }
353 else if (errno != EEXIST)
354 {
356 return -1;
357 }
358 }
359 if (updseq)
360 {
361 mh_seq_add_one(m, hi, !msg->flags.read, msg->flags.flagged, msg->flags.replied);
362 }
363 return 0;
364}
365
373static int mh_rewrite_message(struct Mailbox *m, struct Email *e)
374{
375 if (!m || !e)
376 return -1;
377
378 bool restore = true;
379
380 long old_body_offset = e->body->offset;
381 long old_body_length = e->body->length;
382 long old_hdr_lines = e->lines;
383
384 struct Message *src = mx_msg_open(m, e);
385 struct Message *dest = mx_msg_open_new(m, e, MUTT_MSG_NO_FLAGS);
386 if (!src || !dest)
387 return -1;
388
389 int rc = mutt_copy_message(dest->fp, e, src, MUTT_CM_UPDATE, CH_UPDATE | CH_UPDATE_LEN, 0);
390 if (rc == 0)
391 {
392 char oldpath[PATH_MAX] = { 0 };
393 char partpath[PATH_MAX] = { 0 };
394 snprintf(oldpath, sizeof(oldpath), "%s/%s", mailbox_path(m), e->path);
395 mutt_str_copy(partpath, e->path, sizeof(partpath));
396
397 rc = mh_commit_msg(m, dest, e, false);
398
399 if (rc == 0)
400 {
401 unlink(oldpath);
402 restore = false;
403 }
404
405 /* Try to move the new message to the old place.
406 * (MH only.)
407 *
408 * This is important when we are just updating flags.
409 *
410 * Note that there is a race condition against programs which
411 * use the first free slot instead of the maximum message
412 * number. NeoMutt does _not_ behave like this.
413 *
414 * Anyway, if this fails, the message is in the folder, so
415 * all what happens is that a concurrently running neomutt will
416 * lose flag modifications. */
417 if (rc == 0)
418 {
419 char newpath[PATH_MAX] = { 0 };
420 snprintf(newpath, sizeof(newpath), "%s/%s", mailbox_path(m), e->path);
421 rc = mutt_file_safe_rename(newpath, oldpath);
422 if (rc == 0)
423 mutt_str_replace(&e->path, partpath);
424 }
425 }
426 mx_msg_close(m, &src);
427 mx_msg_close(m, &dest);
428
429 if ((rc == -1) && restore)
430 {
431 e->body->offset = old_body_offset;
432 e->body->length = old_body_length;
433 e->lines = old_hdr_lines;
434 }
435
437 return rc;
438}
439
447static int mh_sync_message(struct Mailbox *m, struct Email *e)
448{
449 if (!m || !e)
450 return -1;
451
452 /* TODO: why the e->env check? */
453 if (e->attach_del || (e->env && e->env->changed))
454 {
455 if (mh_rewrite_message(m, e) != 0)
456 return -1;
457 /* TODO: why the env check? */
458 if (e->env)
459 e->env->changed = 0;
460 }
461
462 return 0;
463}
464
469static void mh_update_mtime(struct Mailbox *m)
470{
471 char buf[PATH_MAX] = { 0 };
472 struct stat st = { 0 };
474
475 snprintf(buf, sizeof(buf), "%s/.mh_sequences", mailbox_path(m));
476 if (stat(buf, &st) == 0)
478
479 mutt_str_copy(buf, mailbox_path(m), sizeof(buf));
480
481 if (stat(buf, &st) == 0)
483}
484
494static int mh_parse_dir(struct Mailbox *m, struct MdEmailArray *mda, struct Progress *progress)
495{
496 struct dirent *de = NULL;
497 int rc = 0;
498 struct MdEmail *entry = NULL;
499 struct Email *e = NULL;
500
501 struct Buffer *buf = buf_pool_get();
502 buf_strcpy(buf, mailbox_path(m));
503
505 if (!dir)
506 {
507 rc = -1;
508 goto cleanup;
509 }
510
511 while (((de = readdir(dir))) && !SigInt)
512 {
513 if (!mh_valid_message(de->d_name))
514 continue;
515
516 mutt_debug(LL_DEBUG2, "queueing %s\n", de->d_name);
517
518 e = email_new();
521
522 if (m->verbose && progress)
523 progress_update(progress, ARRAY_SIZE(mda) + 1, -1);
524
525 e->path = mutt_str_dup(de->d_name);
526
527 entry = maildir_entry_new();
528 entry->email = e;
529 ARRAY_ADD(mda, entry);
530 }
531
532 closedir(dir);
533
534 if (SigInt)
535 {
536 SigInt = false;
537 return -2; /* action aborted */
538 }
539
540cleanup:
541 buf_pool_release(&buf);
542
543 return rc;
544}
545
549static int mh_sort_path(const void *a, const void *b)
550{
551 struct MdEmail const *const *pa = (struct MdEmail const *const *) a;
552 struct MdEmail const *const *pb = (struct MdEmail const *const *) b;
553 return mutt_str_cmp((*pa)->email->path, (*pb)->email->path);
554}
555
565static struct Email *mh_parse_message(const char *fname, struct Email *e)
566{
567 FILE *fp = fopen(fname, "r");
568 if (!fp)
569 {
570 return NULL;
571 }
572
573 const long size = mutt_file_get_size_fp(fp);
574 if (size == 0)
575 {
576 mutt_file_fclose(&fp);
577 return NULL;
578 }
579
580 if (!e)
581 {
582 e = email_new();
585 }
586 e->env = mutt_rfc822_read_header(fp, e, false, false);
587
588 if (e->received != 0)
589 e->received = e->date_sent;
590
591 /* always update the length since we have fresh information available. */
592 e->body->length = size - e->body->offset;
593 e->index = -1;
594
595 mutt_file_fclose(&fp);
596 return e;
597}
598
605static void mh_delayed_parsing(struct Mailbox *m, struct MdEmailArray *mda,
606 struct Progress *progress)
607{
608 char fn[PATH_MAX] = { 0 };
609
610#ifdef USE_HCACHE
611 const char *const c_header_cache = cs_subset_path(NeoMutt->sub, "header_cache");
612 struct HeaderCache *hc = mutt_hcache_open(c_header_cache, mailbox_path(m), NULL);
613#endif
614
615 struct MdEmail *md = NULL;
616 struct MdEmail **mdp = NULL;
617 ARRAY_FOREACH(mdp, mda)
618 {
619 md = *mdp;
620 if (!md || !md->email || md->header_parsed)
621 continue;
622
623 if (m->verbose && progress)
624 progress_update(progress, ARRAY_FOREACH_IDX, -1);
625
626 snprintf(fn, sizeof(fn), "%s/%s", mailbox_path(m), md->email->path);
627
628#ifdef USE_HCACHE
629 struct stat st_lastchanged = { 0 };
630 int rc = 0;
631 const bool c_maildir_header_cache_verify = cs_subset_bool(NeoMutt->sub, "maildir_header_cache_verify");
632 if (c_maildir_header_cache_verify)
633 {
634 rc = stat(fn, &st_lastchanged);
635 }
636
637 const char *key = md->email->path;
638 size_t keylen = strlen(key);
639 struct HCacheEntry hce = mutt_hcache_fetch(hc, key, keylen, 0);
640
641 if (hce.email && (rc == 0) && (st_lastchanged.st_mtime <= hce.uidvalidity))
642 {
645 hce.email->old = md->email->old;
646 hce.email->path = mutt_str_dup(md->email->path);
647 email_free(&md->email);
648 md->email = hce.email;
649 }
650 else
651#endif
652 {
653 if (mh_parse_message(fn, md->email))
654 {
655 md->header_parsed = true;
656#ifdef USE_HCACHE
657 key = md->email->path;
658 keylen = strlen(key);
659 mutt_hcache_store(hc, key, keylen, md->email, 0);
660#endif
661 }
662 else
663 {
664 email_free(&md->email);
665 }
666 }
667 }
668#ifdef USE_HCACHE
670#endif
671
672 const enum SortType c_sort = cs_subset_sort(NeoMutt->sub, "sort");
673 if (m && mda && (ARRAY_SIZE(mda) > 0) && (c_sort == SORT_ORDER))
674 {
675 mutt_debug(LL_DEBUG3, "maildir: sorting %s into natural order\n", mailbox_path(m));
677 }
678}
679
686static bool mh_read_dir(struct Mailbox *m)
687{
688 if (!m)
689 return false;
690
691 struct MhSequences mhs = { 0 };
692 struct Progress *progress = NULL;
693
694 if (m->verbose)
695 {
696 char msg[PATH_MAX] = { 0 };
697 snprintf(msg, sizeof(msg), _("Scanning %s..."), mailbox_path(m));
698 progress = progress_new(msg, MUTT_PROGRESS_READ, 0);
699 }
700
702 if (!mdata)
703 {
705 m->mdata = mdata;
707 }
708
710
711 struct MdEmailArray mda = ARRAY_HEAD_INITIALIZER;
712 int rc = mh_parse_dir(m, &mda, progress);
713 progress_free(&progress);
714 if (rc < 0)
715 return false;
716
717 if (m->verbose)
718 {
719 char msg[PATH_MAX] = { 0 };
720 snprintf(msg, sizeof(msg), _("Reading %s..."), mailbox_path(m));
721 progress = progress_new(msg, MUTT_PROGRESS_READ, ARRAY_SIZE(&mda));
722 }
723 mh_delayed_parsing(m, &mda, progress);
724 progress_free(&progress);
725
726 if (mh_seq_read(&mhs, mailbox_path(m)) < 0)
727 {
728 maildirarray_clear(&mda);
729 return false;
730 }
731 mh_update_maildir(&mda, &mhs);
732 mh_seq_free(&mhs);
733
735
736 if (!mdata->mh_umask)
737 mdata->mh_umask = mh_umask(m);
738
739 return true;
740}
741
750int mh_sync_mailbox_message(struct Mailbox *m, struct Email *e, struct HeaderCache *hc)
751{
752 if (!m || !e)
753 return -1;
754
755 if (e->deleted)
756 {
757 char path[PATH_MAX] = { 0 };
758 snprintf(path, sizeof(path), "%s/%s", mailbox_path(m), e->path);
759 const bool c_mh_purge = cs_subset_bool(NeoMutt->sub, "mh_purge");
760 if (c_mh_purge)
761 {
762#ifdef USE_HCACHE
763 if (hc)
764 {
765 const char *key = e->path;
766 size_t keylen = strlen(key);
767 mutt_hcache_delete_record(hc, key, keylen);
768 }
769#endif
770 unlink(path);
771 }
772 else
773 {
774 /* MH just moves files out of the way when you delete them */
775 if (*e->path != ',')
776 {
777 char tmp[PATH_MAX] = { 0 };
778 snprintf(tmp, sizeof(tmp), "%s/,%s", mailbox_path(m), e->path);
779 unlink(tmp);
780 if (rename(path, tmp) != 0)
781 {
782 return -1;
783 }
784 }
785 }
786 }
787 else if (e->changed || e->attach_del)
788 {
789 if (mh_sync_message(m, e) == -1)
790 return -1;
791 }
792
793#ifdef USE_HCACHE
794 if (hc && e->changed)
795 {
796 const char *key = e->path;
797 size_t keylen = strlen(key);
798 mutt_hcache_store(hc, key, keylen, e, 0);
799 }
800#endif
801
802 return 0;
803}
804
808static int mh_msg_save_hcache(struct Mailbox *m, struct Email *e)
809{
810 int rc = 0;
811#ifdef USE_HCACHE
812 const char *const c_header_cache = cs_subset_path(NeoMutt->sub, "header_cache");
813 struct HeaderCache *hc = mutt_hcache_open(c_header_cache, mailbox_path(m), NULL);
814 rc = mutt_hcache_store(hc, e->path, strlen(e->path), e, 0);
816#endif
817 return rc;
818}
819
823static bool mh_ac_owns_path(struct Account *a, const char *path)
824{
825 return true;
826}
827
831static bool mh_ac_add(struct Account *a, struct Mailbox *m)
832{
833 return true;
834}
835
839static enum MxOpenReturns mh_mbox_open(struct Mailbox *m)
840{
842}
843
847static bool mh_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags)
848{
849 if (!(flags & (MUTT_APPENDNEW | MUTT_NEWFOLDER)))
850 return true;
851
852 if (mutt_file_mkdir(mailbox_path(m), S_IRWXU))
853 {
855 return false;
856 }
857
858 char tmp[PATH_MAX] = { 0 };
859 snprintf(tmp, sizeof(tmp), "%s/.mh_sequences", mailbox_path(m));
860 const int i = creat(tmp, S_IRWXU);
861 if (i == -1)
862 {
863 mutt_perror(tmp);
864 rmdir(mailbox_path(m));
865 return false;
866 }
867 close(i);
868
869 return true;
870}
871
882static enum MxStatus mh_mbox_check(struct Mailbox *m)
883{
884 char buf[PATH_MAX] = { 0 };
885 struct stat st = { 0 };
886 struct stat st_cur = { 0 };
887 bool modified = false, occult = false, flags_changed = false;
888 int num_new = 0;
889 struct MhSequences mhs = { 0 };
890 struct HashTable *fnames = NULL;
892
893 const bool c_check_new = cs_subset_bool(NeoMutt->sub, "check_new");
894 if (!c_check_new)
895 return MX_STATUS_OK;
896
897 mutt_str_copy(buf, mailbox_path(m), sizeof(buf));
898 if (stat(buf, &st) == -1)
899 return MX_STATUS_ERROR;
900
901 /* create .mh_sequences when there isn't one. */
902 snprintf(buf, sizeof(buf), "%s/.mh_sequences", mailbox_path(m));
903 int rc = stat(buf, &st_cur);
904 if ((rc == -1) && (errno == ENOENT))
905 {
906 char *tmp = NULL;
907 FILE *fp = NULL;
908
909 if (mh_mkstemp(m, &fp, &tmp))
910 {
911 mutt_file_fclose(&fp);
912 if (mutt_file_safe_rename(tmp, buf) == -1)
913 unlink(tmp);
914 FREE(&tmp);
915 }
916 }
917
918 if ((rc == -1) && (stat(buf, &st_cur) == -1))
919 modified = true;
920
922 (mutt_file_stat_timespec_compare(&st_cur, MUTT_STAT_MTIME, &mdata->mtime_cur) > 0))
923 {
924 modified = true;
925 }
926
927 if (!modified)
928 return MX_STATUS_OK;
929
930 /* Update the modification times on the mailbox.
931 *
932 * The monitor code notices changes in the open mailbox too quickly.
933 * In practice, this sometimes leads to all the new messages not being
934 * noticed during the SAME group of mtime stat updates. To work around
935 * the problem, don't update the stat times for a monitor caused check. */
936#ifdef USE_INOTIFY
938 MonitorContextChanged = false;
939 else
940#endif
941 {
944 }
945
946 struct MdEmailArray mda = ARRAY_HEAD_INITIALIZER;
947
948 mh_parse_dir(m, &mda, NULL);
949 mh_delayed_parsing(m, &mda, NULL);
950
951 if (mh_seq_read(&mhs, mailbox_path(m)) < 0)
952 return MX_STATUS_ERROR;
953 mh_update_maildir(&mda, &mhs);
954 mh_seq_free(&mhs);
955
956 /* check for modifications and adjust flags */
958
959 struct MdEmail *md = NULL;
960 struct MdEmail **mdp = NULL;
961 ARRAY_FOREACH(mdp, &mda)
962 {
963 md = *mdp;
964 /* the hash key must survive past the header, which is freed below. */
966 mutt_hash_insert(fnames, md->canon_fname, md);
967 }
968
969 for (int i = 0; i < m->msg_count; i++)
970 {
971 struct Email *e = m->emails[i];
972 if (!e)
973 break;
974
975 e->active = false;
976
977 md = mutt_hash_find(fnames, e->path);
978 if (md && md->email && email_cmp_strict(e, md->email))
979 {
980 e->active = true;
981 /* found the right message */
982 if (!e->changed)
983 if (maildir_update_flags(m, e, md->email))
984 flags_changed = true;
985
986 email_free(&md->email);
987 }
988 else /* message has disappeared */
989 {
990 occult = true;
991 }
992 }
993
994 /* destroy the file name hash */
995
996 mutt_hash_free(&fnames);
997
998 /* If we didn't just get new mail, update the tables. */
999 if (occult)
1001
1002 /* Incorporate new messages */
1003 num_new = maildir_move_to_mailbox(m, &mda);
1004 if (num_new > 0)
1005 {
1007 m->changed = true;
1008 }
1009
1010 ARRAY_FREE(&mda);
1011 if (occult)
1012 return MX_STATUS_REOPENED;
1013 if (num_new > 0)
1014 return MX_STATUS_NEW_MAIL;
1015 if (flags_changed)
1016 return MX_STATUS_FLAGS;
1017 return MX_STATUS_OK;
1018}
1019
1029static enum MxStatus mh_mbox_sync(struct Mailbox *m)
1030{
1031 enum MxStatus check = mh_mbox_check(m);
1032 if (check == MX_STATUS_ERROR)
1033 return check;
1034
1035 struct HeaderCache *hc = NULL;
1036#ifdef USE_HCACHE
1037 const char *const c_header_cache = cs_subset_path(NeoMutt->sub, "header_cache");
1038 if (m->type == MUTT_MH)
1039 hc = mutt_hcache_open(c_header_cache, mailbox_path(m), NULL);
1040#endif
1041
1042 struct Progress *progress = NULL;
1043 if (m->verbose)
1044 {
1045 char msg[PATH_MAX] = { 0 };
1046 snprintf(msg, sizeof(msg), _("Writing %s..."), mailbox_path(m));
1047 progress = progress_new(msg, MUTT_PROGRESS_WRITE, m->msg_count);
1048 }
1049
1050 for (int i = 0; i < m->msg_count; i++)
1051 {
1052 if (m->verbose)
1053 progress_update(progress, i, -1);
1054
1055 struct Email *e = m->emails[i];
1056 if (mh_sync_mailbox_message(m, e, hc) == -1)
1057 {
1058 progress_free(&progress);
1059 goto err;
1060 }
1061 }
1062 progress_free(&progress);
1063
1064#ifdef USE_HCACHE
1065 if (m->type == MUTT_MH)
1067#endif
1068
1069 mh_seq_update(m);
1070
1071 /* XXX race condition? */
1072
1073 mh_update_mtime(m);
1074
1075 /* adjust indices */
1076
1077 if (m->msg_deleted)
1078 {
1079 for (int i = 0, j = 0; i < m->msg_count; i++)
1080 {
1081 struct Email *e = m->emails[i];
1082 if (!e)
1083 break;
1084
1085 if (!e->deleted)
1086 e->index = j++;
1087 }
1088 }
1089
1090 return check;
1091
1092err:
1093#ifdef USE_HCACHE
1094 if (m->type == MUTT_MH)
1096#endif
1097 return MX_STATUS_ERROR;
1098}
1099
1104static enum MxStatus mh_mbox_close(struct Mailbox *m)
1105{
1106 return MX_STATUS_OK;
1107}
1108
1112static bool mh_msg_open(struct Mailbox *m, struct Message *msg, struct Email *e)
1113{
1114 char path[PATH_MAX] = { 0 };
1115
1116 snprintf(path, sizeof(path), "%s/%s", mailbox_path(m), e->path);
1117
1118 msg->fp = fopen(path, "r");
1119 if (!msg->fp)
1120 {
1122 mutt_debug(LL_DEBUG1, "fopen: %s: %s (errno %d)\n", path, strerror(errno), errno);
1123 return false;
1124 }
1125
1126 return true;
1127}
1128
1134static bool mh_msg_open_new(struct Mailbox *m, struct Message *msg, const struct Email *e)
1135{
1136 return mh_mkstemp(m, &msg->fp, &msg->path);
1137}
1138
1142static int mh_msg_commit(struct Mailbox *m, struct Message *msg)
1143{
1144 return mh_commit_msg(m, msg, NULL, true);
1145}
1146
1152static int mh_msg_close(struct Mailbox *m, struct Message *msg)
1153{
1154 return mutt_file_fclose(&msg->fp);
1155}
1156
1160static int mh_path_canon(char *buf, size_t buflen)
1161{
1162 mutt_path_canon(buf, buflen, HomeDir, true);
1163 return 0;
1164}
1165
1169static int mh_path_parent(char *buf, size_t buflen)
1170{
1171 if (mutt_path_parent(buf))
1172 return 0;
1173
1174 if (buf[0] == '~')
1175 mutt_path_canon(buf, buflen, HomeDir, true);
1176
1177 if (mutt_path_parent(buf))
1178 return 0;
1179
1180 return -1;
1181}
1182
1186static int mh_path_pretty(char *buf, size_t buflen, const char *folder)
1187{
1188 if (mutt_path_abbr_folder(buf, folder))
1189 return 0;
1190
1191 if (mutt_path_pretty(buf, buflen, HomeDir, false))
1192 return 0;
1193
1194 return -1;
1195}
1196
1200static enum MailboxType mh_path_probe(const char *path, const struct stat *st)
1201{
1202 if (!st || !S_ISDIR(st->st_mode))
1203 return MUTT_UNKNOWN;
1204
1205 char tmp[PATH_MAX] = { 0 };
1206
1207 snprintf(tmp, sizeof(tmp), "%s/.mh_sequences", path);
1208 if (access(tmp, F_OK) == 0)
1209 return MUTT_MH;
1210
1211 snprintf(tmp, sizeof(tmp), "%s/.xmhcache", path);
1212 if (access(tmp, F_OK) == 0)
1213 return MUTT_MH;
1214
1215 snprintf(tmp, sizeof(tmp), "%s/.mew_cache", path);
1216 if (access(tmp, F_OK) == 0)
1217 return MUTT_MH;
1218
1219 snprintf(tmp, sizeof(tmp), "%s/.mew-cache", path);
1220 if (access(tmp, F_OK) == 0)
1221 return MUTT_MH;
1222
1223 snprintf(tmp, sizeof(tmp), "%s/.sylpheed_cache", path);
1224 if (access(tmp, F_OK) == 0)
1225 return MUTT_MH;
1226
1227 /* ok, this isn't an mh folder, but mh mode can be used to read
1228 * Usenet news from the spool. */
1229
1230 snprintf(tmp, sizeof(tmp), "%s/.overview", path);
1231 if (access(tmp, F_OK) == 0)
1232 return MUTT_MH;
1233
1234 return MUTT_UNKNOWN;
1235}
1236
1240const struct MxOps MxMhOps = {
1241 // clang-format off
1242 .type = MUTT_MH,
1243 .name = "mh",
1244 .is_local = true,
1245 .ac_owns_path = mh_ac_owns_path,
1246 .ac_add = mh_ac_add,
1247 .mbox_open = mh_mbox_open,
1248 .mbox_open_append = mh_mbox_open_append,
1249 .mbox_check = mh_mbox_check,
1250 .mbox_check_stats = mh_mbox_check_stats,
1251 .mbox_sync = mh_mbox_sync,
1252 .mbox_close = mh_mbox_close,
1253 .msg_open = mh_msg_open,
1254 .msg_open_new = mh_msg_open_new,
1255 .msg_commit = mh_msg_commit,
1256 .msg_close = mh_msg_close,
1257 .msg_padding_size = NULL,
1258 .msg_save_hcache = mh_msg_save_hcache,
1259 .tags_edit = NULL,
1260 .tags_commit = NULL,
1261 .path_probe = mh_path_probe,
1262 .path_canon = mh_path_canon,
1263 .path_pretty = mh_path_pretty,
1264 .path_parent = mh_path_parent,
1265 .path_is_empty = mh_check_empty,
1266 // clang-format on
1267};
#define ARRAY_SORT(head, fn)
Sort an array.
Definition: array.h:277
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:155
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:211
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:86
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:203
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition: array.h:57
const char * mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
Definition: atoi.c:203
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:401
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:90
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:194
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:292
Convenience wrapper for the config headers.
char * HomeDir
User's home directory.
Definition: globals.c:39
int mutt_copy_message(FILE *fp_out, struct Email *e, struct Message *msg, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
Copy a message from a Mailbox.
Definition: copy.c:884
Duplicate the structure of an entire email.
#define MUTT_CM_UPDATE
Update structs on sync.
Definition: copy.h:40
#define CH_UPDATE
Update the status and x-status fields?
Definition: copy.h:52
#define CH_UPDATE_LEN
Update Lines: and Content-Length:
Definition: copy.h:62
Convenience wrapper for the core headers.
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:57
bool email_cmp_strict(const struct Email *e1, const struct Email *e2)
Strictly compare message emails.
Definition: email.c:100
struct Email * email_new(void)
Create a new Email.
Definition: email.c:78
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:44
Structs that make up an email.
void mutt_file_get_stat_timespec(struct timespec *dest, struct stat *st, enum MuttStatType type)
Read the stat() time into a time value.
Definition: file.c:1598
int mutt_file_safe_rename(const char *src, const char *target)
NFS-safe renaming of files.
Definition: file.c:344
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:150
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
Definition: file.c:952
long mutt_file_get_size_fp(FILE *fp)
Get the size of a file.
Definition: file.c:1556
DIR * mutt_file_opendir(const char *path, enum MuttOpenDirMode mode)
Open a directory.
Definition: file.c:614
int mutt_file_stat_timespec_compare(struct stat *st, enum MuttStatType type, struct timespec *b)
Compare stat info with a time value.
Definition: file.c:1638
int mutt_file_fsync_close(FILE **fp)
Flush the data, before closing a file (and NULL the pointer)
Definition: file.c:166
@ MUTT_OPENDIR_NONE
Plain opendir()
Definition: file.h:73
@ MUTT_STAT_MTIME
File/dir's mtime - last modified time.
Definition: file.h:64
char * ShortHostname
Short version of the hostname.
Definition: globals.c:40
SIG_ATOMIC_VOLATILE_T SigInt
true after SIGINT is received
Definition: globals.c:59
#define mutt_debug(LEVEL,...)
Definition: logging2.h:87
#define mutt_perror(...)
Definition: logging2.h:91
static bool mh_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Implements MxOps::ac_add() -.
Definition: mh.c:831
static bool mh_ac_owns_path(struct Account *a, const char *path)
Check whether an Account own a Mailbox path - Implements MxOps::ac_owns_path() -.
Definition: mh.c:823
const struct MxOps MxMhOps
MH Mailbox - Implements MxOps -.
Definition: mh.c:1240
static enum MxStatus mh_mbox_check_stats(struct Mailbox *m, uint8_t flags)
Check the Mailbox statistics - Implements MxOps::mbox_check_stats() -.
Definition: mh.c:190
static enum MxStatus mh_mbox_check(struct Mailbox *m)
Check for new mail - Implements MxOps::mbox_check() -.
Definition: mh.c:882
static enum MxStatus mh_mbox_close(struct Mailbox *m)
Close a Mailbox - Implements MxOps::mbox_close() -.
Definition: mh.c:1104
static bool mh_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags)
Open a Mailbox for appending - Implements MxOps::mbox_open_append() -.
Definition: mh.c:847
static enum MxOpenReturns mh_mbox_open(struct Mailbox *m)
Open a Mailbox - Implements MxOps::mbox_open() -.
Definition: mh.c:839
static enum MxStatus mh_mbox_sync(struct Mailbox *m)
Save changes to the Mailbox - Implements MxOps::mbox_sync() -.
Definition: mh.c:1029
static int mh_msg_close(struct Mailbox *m, struct Message *msg)
Close an email - Implements MxOps::msg_close() -.
Definition: mh.c:1152
static int mh_msg_commit(struct Mailbox *m, struct Message *msg)
Save changes to an email - Implements MxOps::msg_commit() -.
Definition: mh.c:1142
static bool mh_msg_open_new(struct Mailbox *m, struct Message *msg, const struct Email *e)
Open a new message in a Mailbox - Implements MxOps::msg_open_new() -.
Definition: mh.c:1134
static bool mh_msg_open(struct Mailbox *m, struct Message *msg, struct Email *e)
Open an email message in a Mailbox - Implements MxOps::msg_open() -.
Definition: mh.c:1112
static int mh_msg_save_hcache(struct Mailbox *m, struct Email *e)
Save message to the header cache - Implements MxOps::msg_save_hcache() -.
Definition: mh.c:808
static int mh_path_canon(char *buf, size_t buflen)
Canonicalise a Mailbox path - Implements MxOps::path_canon() -.
Definition: mh.c:1160
static int mh_path_parent(char *buf, size_t buflen)
Find the parent of a Mailbox path - Implements MxOps::path_parent() -.
Definition: mh.c:1169
static int mh_path_pretty(char *buf, size_t buflen, const char *folder)
Abbreviate a Mailbox path - Implements MxOps::path_pretty() -.
Definition: mh.c:1186
static enum MailboxType mh_path_probe(const char *path, const struct stat *st)
Is this an mh Mailbox? - Implements MxOps::path_probe() -.
Definition: mh.c:1200
static int mh_sort_path(const void *a, const void *b)
Compare two Maildirs by path - Implements sort_t -.
Definition: mh.c:549
struct HashElem * mutt_hash_insert(struct HashTable *table, const char *strkey, void *data)
Add a new element to the Hash Table (with string keys)
Definition: hash.c:335
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
Definition: hash.c:362
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys)
Definition: hash.c:259
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:457
#define MUTT_HASH_NO_FLAGS
No flags are set.
Definition: hash.h:110
Header cache multiplexor.
int mutt_hcache_store(struct HeaderCache *hc, const char *key, size_t keylen, struct Email *e, uint32_t uidvalidity)
Multiplexor for StoreOps::store.
Definition: hcache.c:616
void mutt_hcache_close(struct HeaderCache *hc)
Multiplexor for StoreOps::close.
Definition: hcache.c:489
struct HeaderCache * mutt_hcache_open(const char *path, const char *folder, hcache_namer_t namer)
Multiplexor for StoreOps::open.
Definition: hcache.c:379
int mutt_hcache_delete_record(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
Definition: hcache.c:695
struct HCacheEntry mutt_hcache_fetch(struct HeaderCache *hc, const char *key, size_t keylen, uint32_t uidvalidity)
Multiplexor for StoreOps::fetch.
Definition: hcache.c:513
@ 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 mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:223
@ NT_MAILBOX_RESORT
Email list needs resorting.
Definition: mailbox.h:176
@ NT_MAILBOX_INVALID
Email list was changed.
Definition: mailbox.h:175
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:209
MailboxType
Supported mailbox formats.
Definition: mailbox.h:41
@ MUTT_MH
'MH' Mailbox type
Definition: mailbox.h:47
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition: mailbox.h:44
void maildir_edata_free(void **ptr)
Free the private Email data - Implements Email::edata_free()
Definition: edata.c:38
struct MaildirEmailData * maildir_edata_new(void)
Create a new MaildirEmailData object.
Definition: edata.c:53
bool maildir_update_flags(struct Mailbox *m, struct Email *e_old, struct Email *e_new)
Update the mailbox flags.
Definition: shared.c:121
void maildir_mdata_free(void **ptr)
Free the private Mailbox data - Implements Mailbox::mdata_free()
Definition: mdata.c:37
struct MaildirMboxData * maildir_mdata_get(struct Mailbox *m)
Get the private data for this Mailbox.
Definition: mdata.c:57
struct MaildirMboxData * maildir_mdata_new(void)
Create a new MaildirMboxData object.
Definition: mdata.c:46
mode_t mh_umask(struct Mailbox *m)
Create a umask from the mailbox directory.
Definition: shared.c:52
int maildir_move_to_mailbox(struct Mailbox *m, struct MdEmailArray *mda)
Copy the Maildir list to the Mailbox.
Definition: shared.c:75
struct MdEmail * maildir_entry_new(void)
Create a new Maildir entry.
Definition: mdemail.c:39
void maildirarray_clear(struct MdEmailArray *mda)
Free a Maildir array.
Definition: mdemail.c:64
Maildir Email helper.
#define FREE(x)
Definition: memory.h:43
int mh_check_empty(const char *path)
Is mailbox empty.
Definition: mh.c:166
static void mh_update_mtime(struct Mailbox *m)
Update our record of the Maildir modification time.
Definition: mh.c:469
static void mh_delayed_parsing(struct Mailbox *m, struct MdEmailArray *mda, struct Progress *progress)
This function does the second parsing pass.
Definition: mh.c:605
static bool mh_valid_message(const char *s)
Is this a valid MH message filename.
Definition: mh.c:149
static void mh_update_maildir(struct MdEmailArray *mda, struct MhSequences *mhs)
Update our record of flags.
Definition: mh.c:260
bool mh_mkstemp(struct Mailbox *m, FILE **fp, char **tgt)
Create a temporary file.
Definition: mh.c:78
static int mh_sync_message(struct Mailbox *m, struct Email *e)
Sync an email to an MH folder.
Definition: mh.c:447
int mh_sync_mailbox_message(struct Mailbox *m, struct Email *e, struct HeaderCache *hc)
Save changes to the mailbox.
Definition: mh.c:750
static int mh_parse_dir(struct Mailbox *m, struct MdEmailArray *mda, struct Progress *progress)
Read a Maildir mailbox.
Definition: mh.c:494
static int mh_commit_msg(struct Mailbox *m, struct Message *msg, struct Email *e, bool updseq)
Commit a message to an MH folder.
Definition: mh.c:293
static int mh_already_notified(struct Mailbox *m, int msgno)
Has the message changed.
Definition: mh.c:126
static bool mh_read_dir(struct Mailbox *m)
Read an MH mailbox.
Definition: mh.c:686
static struct Email * mh_parse_message(const char *fname, struct Email *e)
Actually parse an MH message.
Definition: mh.c:565
static int mh_rewrite_message(struct Mailbox *m, struct Email *e)
Sync a message in an MH folder.
Definition: mh.c:373
bool MonitorContextChanged
Set to true when the current mailbox has changed.
Definition: monitor.c:52
Monitor files for changes.
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
bool mutt_path_abbr_folder(char *buf, const char *folder)
Create a folder abbreviation.
Definition: path.c:490
bool mutt_path_pretty(char *buf, size_t buflen, const char *homedir, bool is_dir)
Tidy a filesystem path.
Definition: path.c:186
bool mutt_path_canon(char *buf, size_t buflen, const char *homedir, bool is_dir)
Create the canonical version of a path.
Definition: path.c:285
bool mutt_path_parent(char *buf)
Find the parent of a path.
Definition: path.c:458
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:471
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
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:653
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:327
#define PATH_MAX
Definition: mutt.h:41
int mx_msg_close(struct Mailbox *m, struct Message **msg)
Close a message.
Definition: mx.c:1210
struct Message * mx_msg_open(struct Mailbox *m, struct Email *e)
Return a stream pointer for a message.
Definition: mx.c:1164
struct Message * mx_msg_open_new(struct Mailbox *m, const struct Email *e, MsgOpenFlags flags)
Open a new message.
Definition: mx.c:1072
API for mailboxes.
#define MUTT_MSG_NO_FLAGS
No flags are set.
Definition: mx.h:40
uint8_t OpenMailboxFlags
Flags for mutt_open_mailbox(), e.g. MUTT_NOSORT.
Definition: mxapi.h:60
#define MUTT_NEWFOLDER
Create a new folder - same as MUTT_APPEND, but uses mutt_file_fopen() with mode "w" for mbox-style fo...
Definition: mxapi.h:66
MxOpenReturns
Return values for mbox_open()
Definition: mxapi.h:97
@ MX_OPEN_ERROR
Open failed with an error.
Definition: mxapi.h:99
@ MX_OPEN_OK
Open succeeded.
Definition: mxapi.h:98
#define MUTT_APPENDNEW
Set in mx_open_mailbox_append if the mailbox doesn't exist.
Definition: mxapi.h:70
MxStatus
Return values from mbox_check(), mbox_check_stats(), mbox_snc(), and mbox_close()
Definition: mxapi.h:84
@ MX_STATUS_ERROR
An error occurred.
Definition: mxapi.h:85
@ MX_STATUS_OK
No changes.
Definition: mxapi.h:86
@ MX_STATUS_FLAGS
Nondestructive flags change (IMAP)
Definition: mxapi.h:90
@ MX_STATUS_REOPENED
Mailbox was reopened.
Definition: mxapi.h:89
@ MX_STATUS_NEW_MAIL
New mail received in Mailbox.
Definition: mxapi.h:87
Notmuch-specific Mailbox data.
struct Envelope * mutt_rfc822_read_header(FILE *fp, struct Email *e, bool user_hdrs, bool weed)
Parses an RFC822 header.
Definition: parse.c:1169
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 Email data.
Progress bar.
@ MUTT_PROGRESS_READ
Progress tracks elements, according to $read_inc
Definition: lib.h:49
@ MUTT_PROGRESS_WRITE
Progress tracks elements, according to $write_inc
Definition: lib.h:50
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition: progress.c:89
bool progress_update(struct Progress *progress, size_t pos, int percent)
Update the state of the progress bar.
Definition: progress.c:73
struct Progress * progress_new(const char *msg, enum ProgressType type, size_t size)
Create a new Progress Bar.
Definition: progress.c:121
uint64_t mutt_rand64(void)
Create a 64-bit random number.
Definition: random.c:131
void mh_seq_add_one(struct Mailbox *m, int n, bool unseen, bool flagged, bool replied)
Update the flags for one sequence.
Definition: sequence.c:107
MhSeqFlags mh_seq_check(struct MhSequences *mhs, int i)
Get the flags for a given sequence.
Definition: sequence.c:78
void mh_seq_free(struct MhSequences *mhs)
Free some sequences.
Definition: sequence.c:67
int mh_seq_changed(struct Mailbox *m)
Has the mailbox changed.
Definition: sequence.c:438
void mh_seq_update(struct Mailbox *m)
Update sequence numbers.
Definition: sequence.c:233
int mh_seq_read(struct MhSequences *mhs, const char *path)
Read a set of MH sequences.
Definition: sequence.c:377
MH Mailbox Sequences.
#define MH_SEQ_UNSEEN
Email hasn't been read.
Definition: sequence.h:33
#define MH_SEQ_REPLIED
Email has been replied to.
Definition: sequence.h:34
uint8_t MhSeqFlags
Flags, e.g. MH_SEQ_UNSEEN.
Definition: sequence.h:31
#define MH_SEQ_FLAGGED
Email is flagged.
Definition: sequence.h:35
GUI display the mailboxes in a side panel.
SortType
Methods for sorting.
Definition: sort2.h:38
@ SORT_ORDER
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:44
Key value store.
#define NONULL(x)
Definition: string2.h:37
A group of associated Mailboxes.
Definition: account.h:37
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:72
LOFF_T offset
offset where the actual data begins
Definition: body.h:52
LOFF_T length
length (in bytes) of attachment
Definition: body.h:53
String manipulation buffer.
Definition: buffer.h:34
The envelope/body of an email.
Definition: email.h:37
bool read
Email is read.
Definition: email.h:48
struct Envelope * env
Envelope information.
Definition: email.h:66
void * edata
Driver-specific data.
Definition: email.h:72
int lines
How many lines in the body of this message?
Definition: email.h:60
struct Body * body
List of MIME parts.
Definition: email.h:67
bool active
Message is not to be removed.
Definition: email.h:74
bool old
Email is seen, but unread.
Definition: email.h:47
void(* edata_free)(void **ptr)
Free the private data attached to the Email.
Definition: email.h:86
bool changed
Email has been edited.
Definition: email.h:75
bool attach_del
Has an attachment marked for deletion.
Definition: email.h:98
bool flagged
Marked important?
Definition: email.h:45
time_t date_sent
Time when the message was sent (UTC)
Definition: email.h:58
bool replied
Email has been replied to.
Definition: email.h:49
char * path
Path of Email (for local Mailboxes)
Definition: email.h:68
bool deleted
Email is deleted.
Definition: email.h:76
int index
The absolute (unsorted) message number.
Definition: email.h:109
time_t received
Time when the message was placed in the mailbox.
Definition: email.h:59
unsigned char changed
Changed fields, e.g. MUTT_ENV_CHANGED_SUBJECT.
Definition: envelope.h:92
Wrapper for Email retrieved from the header cache.
Definition: lib.h:99
uint32_t uidvalidity
IMAP-specific UIDVALIDITY.
Definition: lib.h:100
struct Email * email
Retrieved email.
Definition: lib.h:102
A Hash Table.
Definition: hash.h:98
Header cache structure.
Definition: lib.h:88
A mailbox.
Definition: mailbox.h:79
void(* mdata_free)(void **ptr)
Free the private data attached to the Mailbox.
Definition: mailbox.h:141
bool changed
Mailbox has been modified.
Definition: mailbox.h:110
bool has_new
Mailbox has new mail.
Definition: mailbox.h:85
struct timespec mtime
Time Mailbox was last changed.
Definition: mailbox.h:104
int msg_count
Total number of messages.
Definition: mailbox.h:88
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
void * mdata
Driver specific data.
Definition: mailbox.h:132
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
int msg_deleted
Number of deleted messages.
Definition: mailbox.h:93
int msg_flagged
Number of flagged messages.
Definition: mailbox.h:90
struct timespec last_visited
Time of last exit from this mailbox.
Definition: mailbox.h:105
bool verbose
Display status messages?
Definition: mailbox.h:114
int msg_unread
Number of unread messages.
Definition: mailbox.h:89
Maildir-specific Mailbox data -.
Definition: mdata.h:35
mode_t mh_umask
umask to use when creating files
Definition: mdata.h:37
A Maildir Email helper.
Definition: mdemail.h:34
bool header_parsed
Definition: mdemail.h:37
char * canon_fname
Definition: mdemail.h:36
struct Email * email
Definition: mdemail.h:35
A local copy of an email.
Definition: mxapi.h:43
FILE * fp
pointer to the message data
Definition: mxapi.h:44
char * path
path to temp file
Definition: mxapi.h:45
bool replied
Message has been replied to.
Definition: mxapi.h:52
char * committed_path
the final path generated by mx_msg_commit()
Definition: mxapi.h:46
bool flagged
Message is flagged.
Definition: mxapi.h:51
bool read
Message has been read.
Definition: mxapi.h:50
struct Message::@0 flags
Flags for the Message.
Set of MH sequence numbers.
Definition: sequence.h:41
int max
Number of flags stored.
Definition: sequence.h:42
Definition: mxapi.h:112
enum MailboxType type
Mailbox type, e.g. MUTT_IMAP.
Definition: mxapi.h:113
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39