NeoMutt  2025-01-09-117-gace867
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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 "mutt/lib.h"
47#include "config/lib.h"
48#include "email/lib.h"
49#include "core/lib.h"
50#include "mutt.h"
51#include "progress/lib.h"
52#include "copy.h"
53#include "errno.h"
54#include "mdata.h"
55#include "mhemail.h"
56#include "mx.h"
57#include "protos.h"
58#include "sequence.h"
59#include "shared.h"
60#ifdef USE_INOTIFY
61#include "monitor.h"
62#endif
63#ifdef USE_HCACHE
64#include "hcache/lib.h"
65#else
66struct HeaderCache;
67#endif
68
69struct Progress;
70
79static int mh_already_notified(struct Mailbox *m, int msgno)
80{
81 char path[PATH_MAX] = { 0 };
82 struct stat st = { 0 };
83
84 if ((snprintf(path, sizeof(path), "%s/%d", mailbox_path(m), msgno) < sizeof(path)) &&
85 (stat(path, &st) == 0))
86 {
88 }
89 return -1;
90}
91
101static bool mh_valid_message(const char *s)
102{
103 for (; *s; s++)
104 {
105 if (!isdigit((unsigned char) *s))
106 return false;
107 }
108 return true;
109}
110
118int mh_check_empty(struct Buffer *path)
119{
120 struct dirent *de = NULL;
121 int rc = 1; /* assume empty until we find a message */
122
124 if (!dir)
125 return -1;
126 while ((de = readdir(dir)))
127 {
128 if (mh_valid_message(de->d_name))
129 {
130 rc = 0;
131 break;
132 }
133 }
134 closedir(dir);
135
136 return rc;
137}
138
142static enum MxStatus mh_mbox_check_stats(struct Mailbox *m, uint8_t flags)
143{
144 struct MhSequences mhs = { 0 };
145 DIR *dir = NULL;
146 struct dirent *de = NULL;
147
148 /* when $mail_check_recent is set and the .mh_sequences file hasn't changed
149 * since the last m visit, there is no "new mail" */
150 const bool c_mail_check_recent = cs_subset_bool(NeoMutt->sub, "mail_check_recent");
151 if (c_mail_check_recent && (mh_seq_changed(m) <= 0))
152 {
153 return MX_STATUS_OK;
154 }
155
156 if (mh_seq_read(&mhs, mailbox_path(m)) < 0)
157 return MX_STATUS_ERROR;
158
159 m->msg_count = 0;
160 m->msg_unread = 0;
161 m->msg_flagged = 0;
162
163 enum MxStatus rc = MX_STATUS_OK;
164 bool check_new = true;
165 for (int i = mhs.max; i > 0; i--)
166 {
167 if ((mh_seq_check(&mhs, i) & MH_SEQ_FLAGGED))
168 m->msg_flagged++;
169 if (mh_seq_check(&mhs, i) & MH_SEQ_UNSEEN)
170 {
171 m->msg_unread++;
172 if (check_new)
173 {
174 /* if the first unseen message we encounter was in the m during the
175 * last visit, don't notify about it */
176 if (!c_mail_check_recent || (mh_already_notified(m, i) == 0))
177 {
178 m->has_new = true;
180 }
181 /* Because we are traversing from high to low, we can stop
182 * checking for new mail after the first unseen message.
183 * Whether it resulted in "new mail" or not. */
184 check_new = false;
185 }
186 }
187 }
188
189 mh_seq_free(&mhs);
190
192 if (dir)
193 {
194 while ((de = readdir(dir)))
195 {
196 if (*de->d_name == '.')
197 continue;
198 if (mh_valid_message(de->d_name))
199 m->msg_count++;
200 }
201 closedir(dir);
202 }
203
204 return rc;
205}
206
212static void mh_update_emails(struct MhEmailArray *mha, struct MhSequences *mhs)
213{
214 struct MhEmail *md = NULL;
215 struct MhEmail **mdp = NULL;
216 ARRAY_FOREACH(mdp, mha)
217 {
218 md = *mdp;
219 char *p = strrchr(md->email->path, '/');
220 if (p)
221 p++;
222 else
223 p = md->email->path;
224
225 int i = 0;
226 if (!mutt_str_atoi_full(p, &i))
227 continue;
228 MhSeqFlags flags = mh_seq_check(mhs, i);
229
230 md->email->read = !(flags & MH_SEQ_UNSEEN);
231 md->email->flagged = (flags & MH_SEQ_FLAGGED);
232 md->email->replied = (flags & MH_SEQ_REPLIED);
233 }
234}
235
245static int mh_commit_msg(struct Mailbox *m, struct Message *msg, struct Email *e, bool updseq)
246{
247 struct dirent *de = NULL;
248 char *cp = NULL, *dep = NULL;
249 unsigned int n, hi = 0;
250 char path[PATH_MAX] = { 0 };
251 char tmp[16] = { 0 };
252
253 if (mutt_file_fsync_close(&msg->fp))
254 {
255 mutt_perror(_("Could not flush message to disk"));
256 return -1;
257 }
258
260 if (!dir)
261 {
262 mutt_perror("%s", mailbox_path(m));
263 return -1;
264 }
265
266 /* figure out what the next message number is */
267 while ((de = readdir(dir)))
268 {
269 dep = de->d_name;
270 if (*dep == ',')
271 dep++;
272 cp = dep;
273 while (*cp)
274 {
275 if (!isdigit((unsigned char) *cp))
276 break;
277 cp++;
278 }
279 if (*cp == '\0')
280 {
281 if (!mutt_str_atoui(dep, &n))
282 mutt_debug(LL_DEBUG2, "Invalid MH message number '%s'\n", dep);
283 if (n > hi)
284 hi = n;
285 }
286 }
287 closedir(dir);
288
289 /* Now try to rename the file to the proper name.
290 * Note: We may have to try multiple times, until we find a free slot. */
291
292 while (true)
293 {
294 hi++;
295 snprintf(tmp, sizeof(tmp), "%u", hi);
296 snprintf(path, sizeof(path), "%s/%s", mailbox_path(m), tmp);
297 if (mutt_file_safe_rename(msg->path, path) == 0)
298 {
299 if (e)
300 mutt_str_replace(&e->path, tmp);
301 mutt_str_replace(&msg->committed_path, path);
302 FREE(&msg->path);
303 break;
304 }
305 else if (errno != EEXIST)
306 {
307 mutt_perror("%s", mailbox_path(m));
308 return -1;
309 }
310 }
311 if (updseq)
312 {
313 mh_seq_add_one(m, hi, !msg->flags.read, msg->flags.flagged, msg->flags.replied);
314 }
315 return 0;
316}
317
325static int mh_rewrite_message(struct Mailbox *m, struct Email *e)
326{
327 if (!m || !e)
328 return -1;
329
330 bool restore = true;
331
332 long old_body_offset = e->body->offset;
333 long old_body_length = e->body->length;
334 long old_hdr_lines = e->lines;
335
336 struct Message *src = mx_msg_open(m, e);
337 struct Message *dest = mx_msg_open_new(m, e, MUTT_MSG_NO_FLAGS);
338 if (!src || !dest)
339 return -1;
340
341 int rc = mutt_copy_message(dest->fp, e, src, MUTT_CM_UPDATE, CH_UPDATE | CH_UPDATE_LEN, 0);
342 if (rc == 0)
343 {
344 char oldpath[PATH_MAX] = { 0 };
345 char partpath[PATH_MAX] = { 0 };
346 snprintf(oldpath, sizeof(oldpath), "%s/%s", mailbox_path(m), e->path);
347 mutt_str_copy(partpath, e->path, sizeof(partpath));
348
349 rc = mh_commit_msg(m, dest, e, false);
350
351 if (rc == 0)
352 {
353 unlink(oldpath);
354 restore = false;
355 }
356
357 /* Try to move the new message to the old place.
358 * (MH only.)
359 *
360 * This is important when we are just updating flags.
361 *
362 * Note that there is a race condition against programs which
363 * use the first free slot instead of the maximum message
364 * number. NeoMutt does _not_ behave like this.
365 *
366 * Anyway, if this fails, the message is in the folder, so
367 * all what happens is that a concurrently running neomutt will
368 * lose flag modifications. */
369 if (rc == 0)
370 {
371 char newpath[PATH_MAX] = { 0 };
372 snprintf(newpath, sizeof(newpath), "%s/%s", mailbox_path(m), e->path);
373 rc = mutt_file_safe_rename(newpath, oldpath);
374 if (rc == 0)
375 mutt_str_replace(&e->path, partpath);
376 }
377 }
378 mx_msg_close(m, &src);
379 mx_msg_close(m, &dest);
380
381 if ((rc == -1) && restore)
382 {
383 e->body->offset = old_body_offset;
384 e->body->length = old_body_length;
385 e->lines = old_hdr_lines;
386 }
387
389 return rc;
390}
391
399static int mh_sync_message(struct Mailbox *m, struct Email *e)
400{
401 if (!m || !e)
402 return -1;
403
404 if (e->attach_del || e->env->changed)
405 {
406 if (mh_rewrite_message(m, e) != 0)
407 return -1;
408 e->env->changed = false;
409 }
410
411 return 0;
412}
413
418static void mh_update_mtime(struct Mailbox *m)
419{
420 char buf[PATH_MAX] = { 0 };
421 struct stat st = { 0 };
422 struct MhMboxData *mdata = mh_mdata_get(m);
423
424 snprintf(buf, sizeof(buf), "%s/.mh_sequences", mailbox_path(m));
425 if (stat(buf, &st) == 0)
427
428 mutt_str_copy(buf, mailbox_path(m), sizeof(buf));
429
430 if (stat(buf, &st) == 0)
432}
433
443static int mh_parse_dir(struct Mailbox *m, struct MhEmailArray *mha, struct Progress *progress)
444{
445 struct dirent *de = NULL;
446 int rc = 0;
447 struct MhEmail *entry = NULL;
448 struct Email *e = NULL;
449
450 struct Buffer *buf = buf_pool_get();
451 buf_strcpy(buf, mailbox_path(m));
452
454 if (!dir)
455 {
456 rc = -1;
457 goto cleanup;
458 }
459
460 while (((de = readdir(dir))) && !SigInt)
461 {
462 if (!mh_valid_message(de->d_name))
463 continue;
464
465 mutt_debug(LL_DEBUG2, "queueing %s\n", de->d_name);
466
467 e = email_new();
468
469 progress_update(progress, ARRAY_SIZE(mha) + 1, -1);
470
471 e->path = mutt_str_dup(de->d_name);
472
473 entry = mh_entry_new();
474 entry->email = e;
475 ARRAY_ADD(mha, entry);
476 }
477
478 closedir(dir);
479
480 if (SigInt)
481 {
482 SigInt = false;
483 return -2; /* action aborted */
484 }
485
486cleanup:
487 buf_pool_release(&buf);
488
489 return rc;
490}
491
495static int mh_sort_path(const void *a, const void *b, void *sdata)
496{
497 struct MhEmail const *pa = *(struct MhEmail const *const *) a;
498 struct MhEmail const *pb = *(struct MhEmail const *const *) b;
499 return mutt_str_cmp(pa->email->path, pb->email->path);
500}
501
511static struct Email *mh_parse_message(const char *fname, struct Email *e)
512{
513 FILE *fp = mutt_file_fopen(fname, "r");
514 if (!fp)
515 {
516 return NULL;
517 }
518
519 const long size = mutt_file_get_size_fp(fp);
520 if (size == 0)
521 {
522 mutt_file_fclose(&fp);
523 return NULL;
524 }
525
526 if (!e)
527 e = email_new();
528
529 e->env = mutt_rfc822_read_header(fp, e, false, false);
530
531 if (e->received != 0)
532 e->received = e->date_sent;
533
534 /* always update the length since we have fresh information available. */
535 e->body->length = size - e->body->offset;
536 e->index = -1;
537
538 mutt_file_fclose(&fp);
539 return e;
540}
541
548static void mh_delayed_parsing(struct Mailbox *m, struct MhEmailArray *mha,
549 struct Progress *progress)
550{
551 char fn[PATH_MAX] = { 0 };
552
553#ifdef USE_HCACHE
554 const char *const c_header_cache = cs_subset_path(NeoMutt->sub, "header_cache");
555 struct HeaderCache *hc = hcache_open(c_header_cache, mailbox_path(m), NULL, true);
556#endif
557
558 struct MhEmail *md = NULL;
559 struct MhEmail **mdp = NULL;
560 ARRAY_FOREACH(mdp, mha)
561 {
562 md = *mdp;
563 if (!md || !md->email || md->header_parsed)
564 continue;
565
566 progress_update(progress, ARRAY_FOREACH_IDX_mdp, -1);
567
568#ifdef USE_HCACHE
569 const char *key = md->email->path;
570 size_t keylen = strlen(key);
571 struct HCacheEntry hce = hcache_fetch_email(hc, key, keylen, 0);
572
573 if (hce.email)
574 {
575 hce.email->old = md->email->old;
576 hce.email->path = mutt_str_dup(md->email->path);
577 email_free(&md->email);
578 md->email = hce.email;
579 }
580 else
581#endif
582 {
583 snprintf(fn, sizeof(fn), "%s/%s", mailbox_path(m), md->email->path);
584
585 if (mh_parse_message(fn, md->email))
586 {
587 md->header_parsed = true;
588#ifdef USE_HCACHE
589 key = md->email->path;
590 keylen = strlen(key);
591 hcache_store_email(hc, key, keylen, md->email, 0);
592#endif
593 }
594 else
595 {
596 email_free(&md->email);
597 }
598 }
599 }
600#ifdef USE_HCACHE
601 hcache_close(&hc);
602#endif
603
604 const enum EmailSortType c_sort = cs_subset_sort(NeoMutt->sub, "sort");
605 if (m && mha && (ARRAY_SIZE(mha) > 0) && (c_sort == EMAIL_SORT_UNSORTED))
606 {
607 mutt_debug(LL_DEBUG3, "mh: sorting %s into natural order\n", mailbox_path(m));
608 ARRAY_SORT(mha, mh_sort_path, NULL);
609 }
610}
611
619static int mh_move_to_mailbox(struct Mailbox *m, const struct MhEmailArray *mha)
620{
621 if (!m)
622 return 0;
623
624 int oldmsgcount = m->msg_count;
625
626 struct MhEmail *md = NULL;
627 struct MhEmail **mdp = NULL;
628 ARRAY_FOREACH(mdp, mha)
629 {
630 md = *mdp;
631 mutt_debug(LL_DEBUG2, "Considering %s\n", NONULL(md->canon_fname));
632 if (!md->email)
633 continue;
634
635 mutt_debug(LL_DEBUG2, "Adding header structure. Flags: %s%s%s%s%s\n",
636 md->email->flagged ? "f" : "", md->email->deleted ? "D" : "",
637 md->email->replied ? "r" : "", md->email->old ? "O" : "",
638 md->email->read ? "R" : "");
640
641 m->emails[m->msg_count] = md->email;
642 m->emails[m->msg_count]->index = m->msg_count;
643 mailbox_size_add(m, md->email);
644
645 md->email = NULL;
646 m->msg_count++;
647 }
648
649 int num = 0;
650 if (m->msg_count > oldmsgcount)
651 num = m->msg_count - oldmsgcount;
652
653 return num;
654}
655
662static bool mh_read_dir(struct Mailbox *m)
663{
664 if (!m)
665 return false;
666
667 mutt_path_tidy(&m->pathbuf, true);
668
669 struct MhSequences mhs = { 0 };
670 struct Progress *progress = NULL;
671
672 if (m->verbose)
673 {
674 progress = progress_new(MUTT_PROGRESS_READ, 0);
675 progress_set_message(progress, _("Scanning %s..."), mailbox_path(m));
676 }
677
678 struct MhMboxData *mdata = mh_mdata_get(m);
679 if (!mdata)
680 {
682 m->mdata = mdata;
684 }
685
687
688 struct MhEmailArray mha = ARRAY_HEAD_INITIALIZER;
689 int rc = mh_parse_dir(m, &mha, progress);
690 progress_free(&progress);
691 if (rc < 0)
692 return false;
693
694 if (m->verbose)
695 {
696 progress = progress_new(MUTT_PROGRESS_READ, ARRAY_SIZE(&mha));
697 progress_set_message(progress, _("Reading %s..."), mailbox_path(m));
698 }
699 mh_delayed_parsing(m, &mha, progress);
700 progress_free(&progress);
701
702 if (mh_seq_read(&mhs, mailbox_path(m)) < 0)
703 {
704 mharray_clear(&mha);
705 return false;
706 }
707 mh_update_emails(&mha, &mhs);
708 mh_seq_free(&mhs);
709
710 mh_move_to_mailbox(m, &mha);
711 mharray_clear(&mha);
712
713 if (!mdata->umask)
714 mdata->umask = mh_umask(m);
715
716 return true;
717}
718
727int mh_sync_mailbox_message(struct Mailbox *m, struct Email *e, struct HeaderCache *hc)
728{
729 if (!m || !e)
730 return -1;
731
732 if (e->deleted)
733 {
734 char path[PATH_MAX] = { 0 };
735 snprintf(path, sizeof(path), "%s/%s", mailbox_path(m), e->path);
736 const bool c_mh_purge = cs_subset_bool(NeoMutt->sub, "mh_purge");
737 if (c_mh_purge)
738 {
739#ifdef USE_HCACHE
740 if (hc)
741 {
742 const char *key = e->path;
743 size_t keylen = strlen(key);
744 hcache_delete_email(hc, key, keylen);
745 }
746#endif
747 unlink(path);
748 }
749 else
750 {
751 /* MH just moves files out of the way when you delete them */
752 if (*e->path != ',')
753 {
754 char tmp[PATH_MAX] = { 0 };
755 snprintf(tmp, sizeof(tmp), "%s/,%s", mailbox_path(m), e->path);
756 unlink(tmp);
757 if (rename(path, tmp) != 0)
758 {
759 return -1;
760 }
761 }
762 }
763 }
764 else if (e->changed || e->attach_del)
765 {
766 if (mh_sync_message(m, e) == -1)
767 return -1;
768 }
769
770#ifdef USE_HCACHE
771 if (hc && e->changed)
772 {
773 const char *key = e->path;
774 size_t keylen = strlen(key);
775 hcache_store_email(hc, key, keylen, e, 0);
776 }
777#endif
778
779 return 0;
780}
781
785static int mh_msg_save_hcache(struct Mailbox *m, struct Email *e)
786{
787 int rc = 0;
788#ifdef USE_HCACHE
789 const char *const c_header_cache = cs_subset_path(NeoMutt->sub, "header_cache");
790 struct HeaderCache *hc = hcache_open(c_header_cache, mailbox_path(m), NULL, true);
791 rc = hcache_store_email(hc, e->path, strlen(e->path), e, 0);
792 hcache_close(&hc);
793#endif
794 return rc;
795}
796
800static bool mh_ac_owns_path(struct Account *a, const char *path)
801{
802 return true;
803}
804
808static bool mh_ac_add(struct Account *a, struct Mailbox *m)
809{
810 return true;
811}
812
816static enum MxOpenReturns mh_mbox_open(struct Mailbox *m)
817{
819}
820
824static bool mh_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags)
825{
826 if (!(flags & MUTT_APPENDNEW))
827 return true;
828
829 if (mutt_file_mkdir(mailbox_path(m), S_IRWXU))
830 {
831 mutt_perror("%s", mailbox_path(m));
832 return false;
833 }
834
835 char tmp[PATH_MAX] = { 0 };
836 snprintf(tmp, sizeof(tmp), "%s/.mh_sequences", mailbox_path(m));
837 const int i = creat(tmp, S_IRWXU);
838 if (i == -1)
839 {
840 mutt_perror("%s", tmp);
841 rmdir(mailbox_path(m));
842 return false;
843 }
844 close(i);
845
846 return true;
847}
848
857static bool mh_update_flags(struct Mailbox *m, struct Email *e_old, struct Email *e_new)
858{
859 if (!m)
860 return false;
861
862 /* save the global state here so we can reset it at the
863 * end of list block if required. */
864 bool context_changed = m->changed;
865
866 /* user didn't modify this message. alter the flags to match the
867 * current state on disk. This may not actually do
868 * anything. mutt_set_flag() will just ignore the call if the status
869 * bits are already properly set, but it is still faster not to pass
870 * through it */
871 if (e_old->flagged != e_new->flagged)
872 mutt_set_flag(m, e_old, MUTT_FLAG, e_new->flagged, true);
873 if (e_old->replied != e_new->replied)
874 mutt_set_flag(m, e_old, MUTT_REPLIED, e_new->replied, true);
875 if (e_old->read != e_new->read)
876 mutt_set_flag(m, e_old, MUTT_READ, e_new->read, true);
877 if (e_old->old != e_new->old)
878 mutt_set_flag(m, e_old, MUTT_OLD, e_new->old, true);
879
880 /* mutt_set_flag() will set this, but we don't need to
881 * sync the changes we made because we just updated the
882 * context to match the current on-disk state of the
883 * message. */
884 bool header_changed = e_old->changed;
885 e_old->changed = false;
886
887 /* if the mailbox was not modified before we made these
888 * changes, unset the changed flag since nothing needs to
889 * be synchronized. */
890 if (!context_changed)
891 m->changed = false;
892
893 return header_changed;
894}
895
908static enum MxStatus mh_check(struct Mailbox *m)
909{
910 char buf[PATH_MAX] = { 0 };
911 struct stat st = { 0 };
912 struct stat st_cur = { 0 };
913 bool modified = false, occult = false, flags_changed = false;
914 int num_new = 0;
915 struct MhSequences mhs = { 0 };
916 struct HashTable *fnames = NULL;
917 struct MhMboxData *mdata = mh_mdata_get(m);
918
919 const bool c_check_new = cs_subset_bool(NeoMutt->sub, "check_new");
920 if (!c_check_new)
921 return MX_STATUS_OK;
922
923 mutt_str_copy(buf, mailbox_path(m), sizeof(buf));
924 if (stat(buf, &st) == -1)
925 return MX_STATUS_ERROR;
926
927 /* create .mh_sequences when there isn't one. */
928 snprintf(buf, sizeof(buf), "%s/.mh_sequences", mailbox_path(m));
929 int rc = stat(buf, &st_cur);
930 if ((rc == -1) && (errno == ENOENT))
931 {
932 char *tmp = NULL;
933 FILE *fp = NULL;
934
935 if (mh_mkstemp(m, &fp, &tmp))
936 {
937 mutt_file_fclose(&fp);
938 if (mutt_file_safe_rename(tmp, buf) == -1)
939 unlink(tmp);
940 FREE(&tmp);
941 }
942 }
943
944 if ((rc == -1) && (stat(buf, &st_cur) == -1))
945 modified = true;
946
947 if ((mutt_file_stat_timespec_compare(&st, MUTT_STAT_MTIME, &mdata->mtime) > 0) ||
948 (mutt_file_stat_timespec_compare(&st_cur, MUTT_STAT_MTIME, &mdata->mtime_seq) > 0))
949 {
950 modified = true;
951 }
952
953 if (!modified)
954 return MX_STATUS_OK;
955
956 /* Update the modification times on the mailbox.
957 *
958 * The monitor code notices changes in the open mailbox too quickly.
959 * In practice, this sometimes leads to all the new messages not being
960 * noticed during the SAME group of mtime stat updates. To work around
961 * the problem, don't update the stat times for a monitor caused check. */
962#ifdef USE_INOTIFY
964 {
965 MonitorCurMboxChanged = false;
966 }
967 else
968#endif
969 {
972 }
973
974 struct MhEmailArray mha = ARRAY_HEAD_INITIALIZER;
975
976 mh_parse_dir(m, &mha, NULL);
977 mh_delayed_parsing(m, &mha, NULL);
978
979 if (mh_seq_read(&mhs, mailbox_path(m)) < 0)
980 return MX_STATUS_ERROR;
981 mh_update_emails(&mha, &mhs);
982 mh_seq_free(&mhs);
983
984 /* check for modifications and adjust flags */
986
987 struct MhEmail *md = NULL;
988 struct MhEmail **mdp = NULL;
989 ARRAY_FOREACH(mdp, &mha)
990 {
991 md = *mdp;
992 /* the hash key must survive past the header, which is freed below. */
994 mutt_hash_insert(fnames, md->canon_fname, md);
995 }
996
997 for (int i = 0; i < m->msg_count; i++)
998 {
999 struct Email *e = m->emails[i];
1000 if (!e)
1001 break;
1002
1003 md = mutt_hash_find(fnames, e->path);
1004 if (md && md->email && email_cmp_strict(e, md->email))
1005 {
1006 /* found the right message */
1007 if (!e->changed)
1008 if (mh_update_flags(m, e, md->email))
1009 flags_changed = true;
1010
1011 email_free(&md->email);
1012 }
1013 else /* message has disappeared */
1014 {
1015 occult = true;
1016 }
1017 }
1018
1019 /* destroy the file name hash */
1020
1021 mutt_hash_free(&fnames);
1022
1023 /* If we didn't just get new mail, update the tables. */
1024 if (occult)
1026
1027 /* Incorporate new messages */
1028 num_new = mh_move_to_mailbox(m, &mha);
1029 mharray_clear(&mha);
1030
1031 if (num_new > 0)
1032 {
1034 m->changed = true;
1035 }
1036
1037 ARRAY_FREE(&mha);
1038 if (occult)
1039 return MX_STATUS_REOPENED;
1040 if (num_new > 0)
1041 return MX_STATUS_NEW_MAIL;
1042 if (flags_changed)
1043 return MX_STATUS_FLAGS;
1044 return MX_STATUS_OK;
1045}
1046
1050static enum MxStatus mh_mbox_check(struct Mailbox *m)
1051{
1052 return mh_check(m);
1053}
1054
1064static enum MxStatus mh_mbox_sync(struct Mailbox *m)
1065{
1066 enum MxStatus check = mh_check(m);
1067 if (check == MX_STATUS_ERROR)
1068 return check;
1069
1070 struct HeaderCache *hc = NULL;
1071#ifdef USE_HCACHE
1072 const char *const c_header_cache = cs_subset_path(NeoMutt->sub, "header_cache");
1073 hc = hcache_open(c_header_cache, mailbox_path(m), NULL, true);
1074#endif
1075
1076 struct Progress *progress = NULL;
1077 if (m->verbose)
1078 {
1080 progress_set_message(progress, _("Writing %s..."), mailbox_path(m));
1081 }
1082
1083 for (int i = 0; i < m->msg_count; i++)
1084 {
1085 progress_update(progress, i, -1);
1086
1087 struct Email *e = m->emails[i];
1088 if (mh_sync_mailbox_message(m, e, hc) == -1)
1089 {
1090 progress_free(&progress);
1091 goto err;
1092 }
1093 }
1094 progress_free(&progress);
1095
1096#ifdef USE_HCACHE
1097 hcache_close(&hc);
1098#endif
1099
1100 mh_seq_update(m);
1101
1102 /* XXX race condition? */
1103
1104 mh_update_mtime(m);
1105
1106 /* adjust indices */
1107
1108 if (m->msg_deleted)
1109 {
1110 for (int i = 0, j = 0; i < m->msg_count; i++)
1111 {
1112 struct Email *e = m->emails[i];
1113 if (!e)
1114 break;
1115
1116 if (!e->deleted)
1117 e->index = j++;
1118 }
1119 }
1120
1121 return check;
1122
1123err:
1124#ifdef USE_HCACHE
1125 hcache_close(&hc);
1126#endif
1127 return MX_STATUS_ERROR;
1128}
1129
1134static enum MxStatus mh_mbox_close(struct Mailbox *m)
1135{
1136 return MX_STATUS_OK;
1137}
1138
1142static bool mh_msg_open(struct Mailbox *m, struct Message *msg, struct Email *e)
1143{
1144 char path[PATH_MAX] = { 0 };
1145
1146 snprintf(path, sizeof(path), "%s/%s", mailbox_path(m), e->path);
1147
1148 msg->fp = mutt_file_fopen(path, "r");
1149 if (!msg->fp)
1150 {
1151 mutt_perror("%s", path);
1152 return false;
1153 }
1154
1155 return true;
1156}
1157
1163static bool mh_msg_open_new(struct Mailbox *m, struct Message *msg, const struct Email *e)
1164{
1165 return mh_mkstemp(m, &msg->fp, &msg->path);
1166}
1167
1171static int mh_msg_commit(struct Mailbox *m, struct Message *msg)
1172{
1173 return mh_commit_msg(m, msg, NULL, true);
1174}
1175
1181static int mh_msg_close(struct Mailbox *m, struct Message *msg)
1182{
1183 return mutt_file_fclose(&msg->fp);
1184}
1185
1189static int mh_path_canon(struct Buffer *path)
1190{
1192 return 0;
1193}
1194
1198static enum MailboxType mh_path_probe(const char *path, const struct stat *st)
1199{
1200 if (!st || !S_ISDIR(st->st_mode))
1201 return MUTT_UNKNOWN;
1202
1203 char tmp[PATH_MAX] = { 0 };
1204
1205 snprintf(tmp, sizeof(tmp), "%s/.mh_sequences", path);
1206 if (access(tmp, F_OK) == 0)
1207 return MUTT_MH;
1208
1209 snprintf(tmp, sizeof(tmp), "%s/.xmhcache", path);
1210 if (access(tmp, F_OK) == 0)
1211 return MUTT_MH;
1212
1213 snprintf(tmp, sizeof(tmp), "%s/.mew_cache", path);
1214 if (access(tmp, F_OK) == 0)
1215 return MUTT_MH;
1216
1217 snprintf(tmp, sizeof(tmp), "%s/.mew-cache", path);
1218 if (access(tmp, F_OK) == 0)
1219 return MUTT_MH;
1220
1221 snprintf(tmp, sizeof(tmp), "%s/.sylpheed_cache", path);
1222 if (access(tmp, F_OK) == 0)
1223 return MUTT_MH;
1224
1225 /* ok, this isn't an mh folder, but mh mode can be used to read
1226 * Usenet news from the spool. */
1227
1228 snprintf(tmp, sizeof(tmp), "%s/.overview", path);
1229 if (access(tmp, F_OK) == 0)
1230 return MUTT_MH;
1231
1232 return MUTT_UNKNOWN;
1233}
1234
1238const struct MxOps MxMhOps = {
1239 // clang-format off
1240 .type = MUTT_MH,
1241 .name = "mh",
1242 .is_local = true,
1243 .ac_owns_path = mh_ac_owns_path,
1244 .ac_add = mh_ac_add,
1245 .mbox_open = mh_mbox_open,
1246 .mbox_open_append = mh_mbox_open_append,
1247 .mbox_check = mh_mbox_check,
1248 .mbox_check_stats = mh_mbox_check_stats,
1249 .mbox_sync = mh_mbox_sync,
1250 .mbox_close = mh_mbox_close,
1251 .msg_open = mh_msg_open,
1252 .msg_open_new = mh_msg_open_new,
1253 .msg_commit = mh_msg_commit,
1254 .msg_close = mh_msg_close,
1255 .msg_padding_size = NULL,
1256 .msg_save_hcache = mh_msg_save_hcache,
1257 .tags_edit = NULL,
1258 .tags_commit = NULL,
1259 .path_probe = mh_path_probe,
1260 .path_canon = mh_path_canon,
1261 .path_is_empty = mh_check_empty,
1262 // clang-format on
1263};
#define ARRAY_SORT(head, fn, sdata)
Sort an array.
Definition: array.h:335
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:156
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:214
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:87
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:204
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition: array.h:58
const char * mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
Definition: atoi.c:218
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:395
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:168
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:266
Convenience wrapper for the config headers.
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:911
Duplicate the structure of an entire email.
#define MUTT_CM_UPDATE
Update structs on sync.
Definition: copy.h:42
#define CH_UPDATE
Update the status and x-status fields?
Definition: copy.h:54
#define CH_UPDATE_LEN
Update Lines: and Content-Length:
Definition: copy.h:64
Convenience wrapper for the core headers.
void mailbox_size_add(struct Mailbox *m, const struct Email *e)
Add an email's size to the total size of a Mailbox.
Definition: mailbox.c:249
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:233
@ NT_MAILBOX_RESORT
Email list needs resorting.
Definition: mailbox.h:190
@ NT_MAILBOX_INVALID
Email list was changed.
Definition: mailbox.h:189
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:223
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 mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:58
bool email_cmp_strict(const struct Email *e1, const struct Email *e2)
Strictly compare message emails.
Definition: email.c:96
struct Email * email_new(void)
Create a new Email.
Definition: email.c:77
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:46
Structs that make up an email.
struct Envelope * mutt_rfc822_read_header(FILE *fp, struct Email *e, bool user_hdrs, bool weed)
Parses an RFC822 header.
Definition: parse.c:1205
EmailSortType
Methods for sorting Emails.
Definition: sort.h:53
@ EMAIL_SORT_UNSORTED
Sort by the order the messages appear in the mailbox.
Definition: sort.h:64
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:1472
int mutt_file_safe_rename(const char *src, const char *target)
NFS-safe renaming of files.
Definition: file.c:309
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
Definition: file.c:851
long mutt_file_get_size_fp(FILE *fp)
Get the size of a file.
Definition: file.c:1430
DIR * mutt_file_opendir(const char *path, enum MuttOpenDirMode mode)
Open a directory.
Definition: file.c:542
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:1512
int mutt_file_fsync_close(FILE **fp)
Flush the data, before closing a file (and NULL the pointer)
Definition: file.c:131
@ MUTT_OPENDIR_NONE
Plain opendir()
Definition: file.h:63
#define mutt_file_fclose(FP)
Definition: file.h:139
#define mutt_file_fopen(PATH, MODE)
Definition: file.h:138
@ MUTT_STAT_MTIME
File/dir's mtime - last modified time.
Definition: file.h:54
void mutt_set_flag(struct Mailbox *m, struct Email *e, enum MessageType flag, bool bf, bool upd_mbox)
Set a flag on an email.
Definition: flags.c:57
#define mutt_debug(LEVEL,...)
Definition: logging2.h:90
#define mutt_perror(...)
Definition: logging2.h:94
void mh_mdata_free(void **ptr)
Free the private Mailbox data - Implements Mailbox::mdata_free() -.
Definition: mdata.c:37
static bool mh_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Implements MxOps::ac_add() -.
Definition: mh.c:808
static bool mh_ac_owns_path(struct Account *a, const char *path)
Check whether an Account owns a Mailbox path - Implements MxOps::ac_owns_path() -.
Definition: mh.c:800
const struct MxOps MxMhOps
MH Mailbox - Implements MxOps -.
Definition: mh.c:1238
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:142
static enum MxStatus mh_mbox_check(struct Mailbox *m)
Check for new mail - Implements MxOps::mbox_check() -.
Definition: mh.c:1050
static enum MxStatus mh_mbox_close(struct Mailbox *m)
Close a Mailbox - Implements MxOps::mbox_close() -.
Definition: mh.c:1134
static bool mh_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags)
Open a Mailbox for appending - Implements MxOps::mbox_open_append() -.
Definition: mh.c:824
static enum MxOpenReturns mh_mbox_open(struct Mailbox *m)
Open a Mailbox - Implements MxOps::mbox_open() -.
Definition: mh.c:816
static enum MxStatus mh_mbox_sync(struct Mailbox *m)
Save changes to the Mailbox - Implements MxOps::mbox_sync() -.
Definition: mh.c:1064
static int mh_msg_close(struct Mailbox *m, struct Message *msg)
Close an email - Implements MxOps::msg_close() -.
Definition: mh.c:1181
static int mh_msg_commit(struct Mailbox *m, struct Message *msg)
Save changes to an email - Implements MxOps::msg_commit() -.
Definition: mh.c:1171
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:1163
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:1142
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:785
static int mh_path_canon(struct Buffer *path)
Canonicalise a Mailbox path - Implements MxOps::path_canon() -.
Definition: mh.c:1189
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:1198
static int mh_sort_path(const void *a, const void *b, void *sdata)
Compare two Mh Mailboxes by path - Implements sort_t -.
Definition: mh.c:495
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:111
struct HeaderCache * hcache_open(const char *path, const char *folder, hcache_namer_t namer, bool create)
Multiplexor for StoreOps::open.
Definition: hcache.c:471
int hcache_delete_email(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
Definition: hcache.c:739
void hcache_close(struct HeaderCache **ptr)
Multiplexor for StoreOps::close.
Definition: hcache.c:542
struct HCacheEntry hcache_fetch_email(struct HeaderCache *hc, const char *key, size_t keylen, uint32_t uidvalidity)
Multiplexor for StoreOps::fetch.
Definition: hcache.c:562
int hcache_store_email(struct HeaderCache *hc, const char *key, size_t keylen, struct Email *e, uint32_t uidvalidity)
Multiplexor for StoreOps::store.
Definition: hcache.c:670
Header cache multiplexor.
@ LL_DEBUG3
Log at debug level 3.
Definition: logging2.h:46
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:45
#define FREE(x)
Definition: memory.h:55
struct MhMboxData * mh_mdata_get(struct Mailbox *m)
Get the private data for this Mailbox.
Definition: mdata.c:59
struct MhMboxData * mh_mdata_new(void)
Create a new MhMboxData object.
Definition: mdata.c:49
bool mh_mkstemp(struct Mailbox *m, FILE **fp, char **tgt)
Create a temporary file.
Definition: shared.c:73
mode_t mh_umask(struct Mailbox *m)
Create a umask from the mailbox directory.
Definition: shared.c:49
MH shared functions.
static bool mh_update_flags(struct Mailbox *m, struct Email *e_old, struct Email *e_new)
Update the mailbox flags.
Definition: mh.c:857
static void mh_update_mtime(struct Mailbox *m)
Update our record of the mailbox modification time.
Definition: mh.c:418
int mh_check_empty(struct Buffer *path)
Is mailbox empty.
Definition: mh.c:118
static bool mh_valid_message(const char *s)
Is this a valid MH message filename.
Definition: mh.c:101
static int mh_parse_dir(struct Mailbox *m, struct MhEmailArray *mha, struct Progress *progress)
Read an Mh mailbox.
Definition: mh.c:443
static int mh_sync_message(struct Mailbox *m, struct Email *e)
Sync an email to an MH folder.
Definition: mh.c:399
static enum MxStatus mh_check(struct Mailbox *m)
Check for new mail.
Definition: mh.c:908
int mh_sync_mailbox_message(struct Mailbox *m, struct Email *e, struct HeaderCache *hc)
Save changes to the mailbox.
Definition: mh.c:727
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:245
static int mh_already_notified(struct Mailbox *m, int msgno)
Has the message changed.
Definition: mh.c:79
static void mh_delayed_parsing(struct Mailbox *m, struct MhEmailArray *mha, struct Progress *progress)
This function does the second parsing pass.
Definition: mh.c:548
static void mh_update_emails(struct MhEmailArray *mha, struct MhSequences *mhs)
Update our record of flags.
Definition: mh.c:212
static bool mh_read_dir(struct Mailbox *m)
Read an MH mailbox.
Definition: mh.c:662
static int mh_move_to_mailbox(struct Mailbox *m, const struct MhEmailArray *mha)
Copy the Mh list to the Mailbox.
Definition: mh.c:619
static struct Email * mh_parse_message(const char *fname, struct Email *e)
Actually parse an MH message.
Definition: mh.c:511
static int mh_rewrite_message(struct Mailbox *m, struct Email *e)
Sync a message in an MH folder.
Definition: mh.c:325
struct MhEmail * mh_entry_new(void)
Create a new Mh entry.
Definition: mhemail.c:39
void mharray_clear(struct MhEmailArray *mha)
Free a Mh array.
Definition: mhemail.c:64
Mh Email helper.
bool MonitorCurMboxChanged
Set to true when the current mailbox has changed.
Definition: monitor.c:55
Monitor files for changes.
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
bool mutt_path_tidy(struct Buffer *path, bool is_dir)
Remove unnecessary parts of a path.
Definition: path.c:169
bool mutt_path_canon(struct Buffer *path, const char *homedir, bool is_dir)
Create the canonical version of a path.
Definition: path.c:248
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:400
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:254
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:582
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:281
Many unsorted constants and some structs.
@ MUTT_READ
Messages that have been read.
Definition: mutt.h:73
@ MUTT_OLD
Old messages.
Definition: mutt.h:71
@ MUTT_FLAG
Flagged messages.
Definition: mutt.h:79
@ MUTT_REPLIED
Messages that have been replied to.
Definition: mutt.h:72
#define PATH_MAX
Definition: mutt.h:42
void mx_alloc_memory(struct Mailbox *m, int req_size)
Create storage for the emails.
Definition: mx.c:1211
int mx_msg_close(struct Mailbox *m, struct Message **ptr)
Close a message.
Definition: mx.c:1185
struct Message * mx_msg_open(struct Mailbox *m, struct Email *e)
Return a stream pointer for a message.
Definition: mx.c:1139
struct Message * mx_msg_open_new(struct Mailbox *m, const struct Email *e, MsgOpenFlags flags)
Open a new message.
Definition: mx.c:1044
API for mailboxes.
#define MUTT_MSG_NO_FLAGS
No flags are set.
Definition: mx.h:38
uint8_t OpenMailboxFlags
Flags for mutt_open_mailbox(), e.g. MUTT_NOSORT.
Definition: mxapi.h:39
MxOpenReturns
Return values for mbox_open()
Definition: mxapi.h:73
@ MX_OPEN_ERROR
Open failed with an error.
Definition: mxapi.h:75
@ MX_OPEN_OK
Open succeeded.
Definition: mxapi.h:74
#define MUTT_APPENDNEW
Set in mx_open_mailbox_append if the mailbox doesn't exist.
Definition: mxapi.h:46
MxStatus
Return values from mbox_check(), mbox_check_stats(), mbox_sync(), and mbox_close()
Definition: mxapi.h:60
@ MX_STATUS_ERROR
An error occurred.
Definition: mxapi.h:61
@ MX_STATUS_OK
No changes.
Definition: mxapi.h:62
@ MX_STATUS_FLAGS
Nondestructive flags change (IMAP)
Definition: mxapi.h:66
@ MX_STATUS_REOPENED
Mailbox was reopened.
Definition: mxapi.h:65
@ MX_STATUS_NEW_MAIL
New mail received in Mailbox.
Definition: mxapi.h:63
Notmuch-specific Mailbox data.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
Progress Bar.
@ MUTT_PROGRESS_READ
Progress tracks elements, according to $read_inc
Definition: lib.h:83
@ MUTT_PROGRESS_WRITE
Progress tracks elements, according to $write_inc
Definition: lib.h:84
struct Progress * progress_new(enum ProgressType type, size_t size)
Create a new Progress Bar.
Definition: progress.c:139
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition: progress.c:110
void progress_set_message(struct Progress *progress, const char *fmt,...) __attribute__((__format__(__printf__
bool progress_update(struct Progress *progress, size_t pos, int percent)
Update the state of the progress bar.
Definition: progress.c:80
Prototypes for many functions.
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:108
MhSeqFlags mh_seq_check(struct MhSequences *mhs, int i)
Get the flags for a given sequence.
Definition: sequence.c:79
void mh_seq_free(struct MhSequences *mhs)
Free some sequences.
Definition: sequence.c:68
int mh_seq_changed(struct Mailbox *m)
Has the mailbox changed.
Definition: sequence.c:439
void mh_seq_update(struct Mailbox *m)
Update sequence numbers.
Definition: sequence.c:234
int mh_seq_read(struct MhSequences *mhs, const char *path)
Read a set of MH sequences.
Definition: sequence.c:378
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
volatile sig_atomic_t SigInt
true after SIGINT is received
Definition: signal.c:69
#define NONULL(x)
Definition: string2.h:37
A group of associated Mailboxes.
Definition: account.h:36
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:73
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:36
The envelope/body of an email.
Definition: email.h:39
bool read
Email is read.
Definition: email.h:50
struct Envelope * env
Envelope information.
Definition: email.h:68
int lines
How many lines in the body of this message?
Definition: email.h:62
struct Body * body
List of MIME parts.
Definition: email.h:69
bool old
Email is seen, but unread.
Definition: email.h:49
bool changed
Email has been edited.
Definition: email.h:77
bool attach_del
Has an attachment marked for deletion.
Definition: email.h:99
bool flagged
Marked important?
Definition: email.h:47
time_t date_sent
Time when the message was sent (UTC)
Definition: email.h:60
bool replied
Email has been replied to.
Definition: email.h:51
char * path
Path of Email (for local Mailboxes)
Definition: email.h:70
bool deleted
Email is deleted.
Definition: email.h:78
int index
The absolute (unsorted) message number.
Definition: email.h:110
time_t received
Time when the message was placed in the mailbox.
Definition: email.h:61
unsigned char changed
Changed fields, e.g. MUTT_ENV_CHANGED_SUBJECT.
Definition: envelope.h:90
Wrapper for Email retrieved from the header cache.
Definition: lib.h:99
struct Email * email
Retrieved email.
Definition: lib.h:102
A Hash Table.
Definition: hash.h:99
Header Cache.
Definition: lib.h:86
A mailbox.
Definition: mailbox.h:79
void(* mdata_free)(void **ptr)
Definition: mailbox.h:143
bool changed
Mailbox has been modified.
Definition: mailbox.h:110
bool has_new
Mailbox has new mail.
Definition: mailbox.h:85
int msg_count
Total number of messages.
Definition: mailbox.h:88
void * mdata
Driver specific data.
Definition: mailbox.h:132
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
struct Buffer pathbuf
Path of the Mailbox.
Definition: mailbox.h:80
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:104
bool verbose
Display status messages?
Definition: mailbox.h:117
int msg_unread
Number of unread messages.
Definition: mailbox.h:89
A local copy of an email.
Definition: message.h:34
FILE * fp
pointer to the message data
Definition: message.h:35
char * path
path to temp file
Definition: message.h:36
bool replied
Message has been replied to.
Definition: message.h:43
char * committed_path
the final path generated by mx_msg_commit()
Definition: message.h:37
bool flagged
Message is flagged.
Definition: message.h:42
bool read
Message has been read.
Definition: message.h:41
struct Message::@0 flags
Flags for the Message.
A Mh Email helper.
Definition: mhemail.h:36
bool header_parsed
Has the Email header been parsed?
Definition: mhemail.h:39
struct Email * email
Temporary Email.
Definition: mhemail.h:37
char * canon_fname
Canonical filename for hashing.
Definition: mhemail.h:38
Mh-specific Mailbox data -.
Definition: mdata.h:35
mode_t umask
umask to use when creating files
Definition: mdata.h:38
Set of MH sequence numbers.
Definition: sequence.h:41
int max
Number of flags stored.
Definition: sequence.h:42
Definition: mxapi.h:88
enum MailboxType type
Mailbox type, e.g. MUTT_IMAP.
Definition: mxapi.h:89
Container for Accounts, Notifications.
Definition: neomutt.h:43
char * home_dir
User's home directory.
Definition: neomutt.h:53
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:47