2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2002 Michael R. Elkins <me@mutt.org>
4 * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
6 * This file is part of mutt-ng, see http://www.muttng.org/.
7 * It's licensed under the GNU General Public License,
8 * please see the file GPL in the top level source directory.
11 #include <lib-lib/lib-lib.h>
15 #include <lib-lua/lib-lua.h>
16 #include <lib-sys/unix.h>
17 #include <lib-mime/mime.h>
18 #include <lib-ui/lib-ui.h>
33 #include <imap/imap.h>
36 #define MAXLOCKATTEMPT 5
39 static mx_t const *mxfmts[] = {
48 #define MX_IDX(idx) (idx >= 0 && idx < countof(mxfmts))
49 #define mutt_is_spool(s) (m_strcmp(Spoolfile, s) == 0)
51 static int dotlock_file(const char *path, int retry)
53 char lockfile[_POSIX_PATH_MAX];
54 snprintf(lockfile, sizeof(lockfile), "%s.lock", path);
56 if (lockfile_create(lockfile, retry ? 1 : 0, 0)) {
58 mutt_error (_("Can't dotlock %s.\n"), lockfile);
63 static int undotlock_file (const char *path)
65 char lockfile[_POSIX_PATH_MAX];
66 snprintf(lockfile, sizeof(lockfile), "%s.lock", path);
67 return lockfile_remove(lockfile);
70 /* looks up index of type for path in mxfmts */
71 static int mx_get_idx (const char* path) {
75 /* first, test all non-local folders to avoid stat() call */
76 for (i = 0; i < countof(mxfmts); i++) {
77 if (!mxfmts[i]->local)
78 t = mxfmts[i]->mx_is_magic(path, NULL);
82 if (stat (path, &st) == 0) {
83 /* if stat() succeeded, keep testing until success and
84 * pass stat() info so that we only need to do it once */
85 for (i = 0; i < countof(mxfmts); i++) {
87 t = mxfmts[i]->mx_is_magic(path, &st);
96 * excl if excl != 0, request an exclusive lock
97 * time_out should retry locking?
99 int mx_lock_file(const char *path, int fd, int excl, int time_out)
101 int count = 0, attempt = 0;
103 .l_type = excl ? F_WRLCK : F_RDLCK,
104 .l_whence = SEEK_SET,
107 if (dotlock_file(path, time_out) < 0)
110 while (fcntl(fd, F_SETLK, &lck) == -1) {
111 if (errno != EAGAIN && errno != EACCES) {
112 mutt_perror("fcntl");
116 if (++count >= (time_out ? MAXLOCKATTEMPT : 0)) {
118 mutt_error _("Timeout exceeded while attempting fcntl lock!");
121 mutt_message(_("Waiting for fcntl lock... %d"), ++attempt);
127 undotlock_file(path);
131 int mx_unlock_file(const char *path, int fd)
133 struct flock unlockit;
135 p_clear(&unlockit, 1);
136 unlockit.l_type = F_UNLCK;
137 unlockit.l_whence = SEEK_SET;
138 fcntl(fd, F_SETLK, &unlockit);
139 undotlock_file(path);
143 /* try to figure out what type of mailbox ``path'' is */
144 int mx_get_magic (const char *path) {
147 if (m_strlen(path) == 0)
149 if ((i = mx_get_idx (path)) >= 0)
150 return (mxfmts[i]->type);
154 int mx_is_local (int m) {
157 return (mxfmts[m]->local);
161 * set DefaultMagic to the given value
163 int mx_set_magic (const char *s)
165 if (ascii_strcasecmp (s, "mbox") == 0)
166 DefaultMagic = M_MBOX;
167 else if (ascii_strcasecmp (s, "mh") == 0)
169 else if (ascii_strcasecmp (s, "maildir") == 0)
170 DefaultMagic = M_MAILDIR;
177 /* mx_access: Wrapper for access, checks permissions on a given mailbox.
178 * We may be interested in using ACL-style flags at some point, currently
179 * we use the normal access() flags. */
180 int mx_access (const char *path, int flags)
184 if ((i = mx_get_idx (path)) >= 0 && mxfmts[i]->mx_access)
185 return (mxfmts[i]->mx_access(path,flags));
189 static int mx_open_mailbox_append (CONTEXT * ctx, int flags)
193 /* special case for appending to compressed folders -
194 * even if we can not open them for reading */
195 if (mutt_can_append_compressed (ctx->path))
196 mutt_open_append_compressed (ctx);
200 if (mx_get_magic (ctx->path) == M_IMAP)
201 return imap_open_mailbox_append (ctx);
203 if (stat (ctx->path, &sb) == 0) {
204 ctx->magic = mx_get_magic (ctx->path);
206 switch (ctx->magic) {
208 mutt_error (_("%s is not a mailbox."), ctx->path);
214 else if (errno == ENOENT) {
215 ctx->magic = DefaultMagic;
217 if (ctx->magic == M_MH || ctx->magic == M_MAILDIR) {
218 char tmp[_POSIX_PATH_MAX];
220 if (mkdir (ctx->path, S_IRWXU)) {
221 mutt_perror (ctx->path);
225 if (ctx->magic == M_MAILDIR) {
226 snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
227 if (mkdir (tmp, S_IRWXU)) {
233 snprintf (tmp, sizeof (tmp), "%s/new", ctx->path);
234 if (mkdir (tmp, S_IRWXU)) {
236 snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
241 snprintf (tmp, sizeof (tmp), "%s/tmp", ctx->path);
242 if (mkdir (tmp, S_IRWXU)) {
244 snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
246 snprintf (tmp, sizeof (tmp), "%s/new", ctx->path);
255 snprintf (tmp, sizeof (tmp), "%s/.mh_sequences", ctx->path);
256 if ((i = creat (tmp, S_IRWXU)) == -1) {
266 mutt_perror (ctx->path);
270 switch (ctx->magic) {
273 safe_fopen (ctx->path, flags & M_NEWFOLDER ? "w" : "a")) == NULL
274 || mbox_lock_mailbox(ctx, 1, 1) != 0) {
276 mutt_perror (ctx->path);
278 mutt_error (_("Couldn't lock %s\n"), ctx->path);
283 fseeko (ctx->fp, 0, 2);
299 * open a mailbox and parse it
302 * flags M_NOSORT do not sort mailbox
303 * M_APPEND open mailbox for appending
304 * M_READONLY open mailbox in read-only mode
305 * M_QUIET only print error messages
306 * ctx if non-null, context struct to use
308 CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT * pctx)
314 ctx = p_new(CONTEXT, 1);
316 ctx->path = m_strdup(path);
318 ctx->msgnotreadyet = -1;
323 if (flags & M_READONLY)
328 if (flags & (M_APPEND | M_NEWFOLDER)) {
329 if (mx_open_mailbox_append (ctx, flags) != 0) {
330 mx_fastclose_mailbox (ctx);
338 if (!MX_IDX(ctx->magic-1))
339 ctx->magic = mx_get_magic (path);
341 if (ctx->magic == M_COMPRESSED)
342 mutt_open_read_compressed (ctx);
345 mutt_error (_("%s is not a mailbox."), path);
347 if (ctx->magic == -1)
350 if (ctx->magic <= 0) {
351 mx_fastclose_mailbox (ctx);
357 /* if the user has a `push' command in their .muttrc, or in a folder-hook,
358 * it will cause the progress messages not to be displayed because
359 * mutt_refresh() will think we are in the middle of a macro. so set a
360 * flag to indicate that we should really refresh the screen.
362 set_option (OPTFORCEREFRESH);
365 mutt_message (_("Reading %s..."), ctx->path);
367 rc = mxfmts[ctx->magic-1]->mx_open_mailbox(ctx);
370 if ((flags & M_NOSORT) == 0) {
371 /* avoid unnecessary work since the mailbox is completely unthreaded
373 unset_option (OPTSORTSUBTHREADS);
374 unset_option (OPTNEEDRESCORE);
375 mutt_sort_headers (ctx, 1);
381 mx_fastclose_mailbox (ctx);
386 unset_option (OPTFORCEREFRESH);
390 /* free up memory associated with the mailbox context */
391 void mx_fastclose_mailbox (CONTEXT * ctx)
398 if (MX_IDX(ctx->magic-1) && mxfmts[ctx->magic-1]->mx_fastclose_mailbox)
399 mxfmts[ctx->magic-1]->mx_fastclose_mailbox(ctx);
401 hash_delete (&ctx->subj_hash, NULL);
403 hash_delete (&ctx->id_hash, NULL);
404 mutt_clear_threads (ctx);
405 for (i = 0; i < ctx->msgcount; i++)
406 header_delete(&ctx->hdrs[i]);
407 p_delete(&ctx->hdrs);
411 mutt_fast_close_compressed (ctx);
413 p_delete(&ctx->path);
414 p_delete(&ctx->pattern);
415 pattern_list_wipe(&ctx->limit_pattern);
420 /* save changes to disk */
421 static int sync_mailbox (CONTEXT * ctx, int *index_hint)
426 mutt_message (_("Writing %s..."), ctx->path);
428 if (MX_IDX(ctx->magic-1))
429 /* the 1 is only of interest for IMAP and means EXPUNGE */
430 rc = mxfmts[ctx->magic-1]->mx_sync_mailbox(ctx,1,index_hint);
432 if (rc == 0 && ctx->cinfo)
433 return mutt_sync_compressed (ctx);
438 /* move deleted mails to the trash folder */
439 static int trash_append (CONTEXT * ctx)
445 if (!TrashPath || !ctx->deleted ||
446 (ctx->magic == M_MAILDIR && option (OPTMAILDIRTRASH)))
449 for (; i < ctx->msgcount && (!ctx->hdrs[i]->deleted ||
450 ctx->hdrs[i]->appended); i++);
451 if (i == ctx->msgcount)
452 return 0; /* nothing to be done */
454 if (mutt_save_confirm (TrashPath, &st) != 0) {
455 mutt_error _("message(s) not deleted");
460 if (lstat (ctx->path, &stc) == 0 && stc.st_ino == st.st_ino
461 && stc.st_dev == st.st_dev && stc.st_rdev == st.st_rdev)
462 return 0; /* we are in the trash folder: simple sync */
464 if ((ctx_trash = mx_open_mailbox (TrashPath, M_APPEND, NULL)) != NULL) {
465 for (i = 0; i < ctx->msgcount; i++)
466 if (ctx->hdrs[i]->deleted && !ctx->hdrs[i]->appended
467 && !ctx->hdrs[i]->purged
468 && mutt_append_message (ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1) {
469 mx_close_mailbox (ctx_trash, NULL);
473 mx_close_mailbox (ctx_trash, NULL);
476 mutt_error _("Can't open trash folder");
484 /* save changes and close mailbox */
485 static int _mx_close_mailbox (CONTEXT * ctx, int *index_hint)
487 int i, move_messages = 0, purge = 1, read_msgs = 0;
491 char mbox[_POSIX_PATH_MAX];
499 if (ctx->readonly || ctx->dontwrite) {
500 /* mailbox is readonly or we don't want to write */
501 mx_fastclose_mailbox (ctx);
506 /* mailbox was opened in write-mode */
507 if (ctx->magic == M_MBOX)
508 mbox_close_mailbox (ctx);
510 mx_fastclose_mailbox (ctx);
514 for (i = 0; i < ctx->msgcount; i++) {
515 if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->read
516 && !(ctx->hdrs[i]->flagged && option (OPTKEEPFLAGGED)))
520 if (read_msgs && quadoption (OPT_MOVE) != M_NO) {
523 if ((p = mutt_find_hook (M_MBOXHOOK, ctx->path))) {
525 m_strcpy(mbox, sizeof(mbox), p);
528 m_strcpy(mbox, sizeof(mbox), NONULL(Inbox));
529 isSpool = mutt_is_spool (ctx->path) && !mutt_is_spool (mbox);
531 mutt_expand_path (mbox, sizeof (mbox));
534 snprintf (buf, sizeof (buf), _("Move read messages to %s?"), mbox);
535 if ((move_messages = query_quadoption (OPT_MOVE, buf)) == -1) {
543 * There is no point in asking whether or not to purge if we are
544 * just marking messages as "trash".
546 if (ctx->deleted && !(ctx->magic == M_MAILDIR && option (OPTMAILDIRTRASH))) {
547 snprintf (buf, sizeof (buf), ctx->deleted == 1
548 ? _("Purge %d deleted message?") :
549 _("Purge %d deleted messages?"), ctx->deleted);
550 if ((purge = query_quadoption (OPT_DELETE, buf)) < 0) {
556 /* IMAP servers manage the OLD flag themselves */
557 if (ctx->magic != M_IMAP)
558 if (option (OPTMARKOLD)) {
559 for (i = 0; i < ctx->msgcount; i++) {
560 if (!ctx->hdrs[i]->deleted && !ctx->hdrs[i]->old)
561 mutt_set_flag (ctx, ctx->hdrs[i], M_OLD, 1);
566 mutt_message (_("Moving read messages to %s..."), mbox);
568 /* try to use server-side copy first */
571 if (ctx->magic == M_IMAP && imap_is_magic (mbox, NULL) == M_IMAP) {
572 /* tag messages for moving, and clear old tags, if any */
573 for (i = 0; i < ctx->msgcount; i++)
574 if (ctx->hdrs[i]->read && !ctx->hdrs[i]->deleted
575 && !(ctx->hdrs[i]->flagged && option (OPTKEEPFLAGGED)))
576 ctx->hdrs[i]->tagged = 1;
578 ctx->hdrs[i]->tagged = 0;
580 i = imap_copy_messages (ctx, NULL, mbox, 1);
583 if (i == 0) /* success */
585 else if (i == -1) { /* horrible error, bail */
589 else /* use regular append-copy mode */
591 if (mx_open_mailbox (mbox, M_APPEND, &f) == NULL) {
596 for (i = 0; i < ctx->msgcount; i++) {
597 if (ctx->hdrs[i]->read && !ctx->hdrs[i]->deleted
598 && !(ctx->hdrs[i]->flagged && option (OPTKEEPFLAGGED))) {
599 if (mutt_append_message (&f, ctx, ctx->hdrs[i], 0, CH_UPDATE_LEN) ==
601 mutt_set_flag (ctx, ctx->hdrs[i], M_DELETE, 1);
602 mutt_set_flag (ctx, ctx->hdrs[i], M_APPENDED, 1);
605 mx_close_mailbox (&f, NULL);
612 mx_close_mailbox (&f, NULL);
616 else if (!ctx->changed && ctx->deleted == 0) {
617 mutt_message _("Mailbox is unchanged.");
619 mx_fastclose_mailbox (ctx);
623 /* copy mails to the trash before expunging */
624 if (purge && ctx->deleted)
625 if (trash_append (ctx) != 0) {
630 /* allow IMAP to preserve the deleted flag across sessions */
631 if (ctx->magic == M_IMAP) {
632 if ((check = imap_sync_mailbox (ctx, purge, index_hint)) != 0) {
640 for (i = 0; i < ctx->msgcount; i++)
641 ctx->hdrs[i]->deleted = 0;
645 if (ctx->changed || ctx->deleted) {
646 if ((check = sync_mailbox (ctx, index_hint)) != 0) {
654 mutt_message (_("%d kept, %d moved, %d deleted."),
655 ctx->msgcount - ctx->deleted, read_msgs, ctx->deleted);
657 mutt_message (_("%d kept, %d deleted."),
658 ctx->msgcount - ctx->deleted, ctx->deleted);
660 if (ctx->cinfo && mutt_slow_close_compressed (ctx))
663 mx_fastclose_mailbox (ctx);
668 int mx_close_mailbox (CONTEXT * ctx, int *index_hint) {
672 ret = _mx_close_mailbox (ctx, index_hint);
673 sidebar_set_buffystats (ctx);
677 /* update a Context structure's internal tables. */
679 void mx_update_tables (CONTEXT * ctx, int committing)
683 /* update memory to reflect the new state of the mailbox */
692 #define this_body ctx->hdrs[j]->content
693 for (i = 0, j = 0; i < ctx->msgcount; i++) {
694 if ((committing && (!ctx->hdrs[i]->deleted ||
695 (ctx->magic == M_MAILDIR
696 && option (OPTMAILDIRTRASH)))) || (!committing
700 ctx->hdrs[j] = ctx->hdrs[i];
703 ctx->hdrs[j]->msgno = j;
704 if (ctx->hdrs[j]->virtual != -1) {
705 ctx->v2r[ctx->vcount] = j;
706 ctx->hdrs[j]->virtual = ctx->vcount++;
707 ctx->vsize += this_body->length + this_body->offset -
708 this_body->hdr_offset;
712 ctx->hdrs[j]->changed = 0;
713 else if (ctx->hdrs[j]->changed)
717 || (ctx->magic == M_MAILDIR && option (OPTMAILDIRTRASH))) {
718 if (ctx->hdrs[j]->deleted)
722 if (ctx->hdrs[j]->tagged)
724 if (ctx->hdrs[j]->flagged)
726 if (!ctx->hdrs[j]->read) {
728 if (!ctx->hdrs[j]->old)
735 if (ctx->magic == M_MH || ctx->magic == M_MAILDIR)
736 ctx->size -= (ctx->hdrs[i]->content->length +
737 ctx->hdrs[i]->content->offset -
738 ctx->hdrs[i]->content->hdr_offset);
739 /* remove message from the hash tables */
740 if (ctx->subj_hash && ctx->hdrs[i]->env->real_subj)
741 hash_remove (ctx->subj_hash, ctx->hdrs[i]->env->real_subj,
743 if (ctx->id_hash && ctx->hdrs[i]->env->message_id)
744 hash_remove (ctx->id_hash, ctx->hdrs[i]->env->message_id,
746 header_delete(&ctx->hdrs[i]);
752 /* update sidebar count */
753 sidebar_set_buffystats (ctx);
757 /* save changes to mailbox
763 static int _mx_sync_mailbox (CONTEXT * ctx, int *index_hint)
767 int msgcount, deleted;
769 if (ctx->dontwrite) {
770 char buf[STRING], tmp[STRING];
772 if (km_expand_key (buf, sizeof (buf),
773 km_find_func (MENU_MAIN, OP_TOGGLE_WRITE)))
774 snprintf (tmp, sizeof (tmp), _(" Press '%s' to toggle write"), buf);
776 m_strcpy(tmp, sizeof(tmp), _("Use 'toggle-write' to re-enable write!"));
778 mutt_error (_("Mailbox is marked unwritable. %s"), tmp);
781 else if (ctx->readonly) {
782 mutt_error _("Mailbox is read-only.");
787 if (!ctx->changed && !ctx->deleted) {
788 mutt_message _("Mailbox is unchanged.");
796 snprintf (buf, sizeof (buf), ctx->deleted == 1
797 ? _("Purge %d deleted message?") :
798 _("Purge %d deleted messages?"), ctx->deleted);
799 if ((purge = query_quadoption (OPT_DELETE, buf)) < 0)
801 else if (purge == M_NO) {
803 return 0; /* nothing to do! */
804 /* let IMAP servers hold on to D flags */
805 if (ctx->magic != M_IMAP)
807 for (i = 0; i < ctx->msgcount; i++)
808 ctx->hdrs[i]->deleted = 0;
812 else if (ctx->last_tag && ctx->last_tag->deleted)
813 ctx->last_tag = NULL; /* reset last tagged msg now useless */
816 /* really only for IMAP - imap_sync_mailbox results in a call to
817 * mx_update_tables, so ctx->deleted is 0 when it comes back */
818 msgcount = ctx->msgcount;
819 deleted = ctx->deleted;
821 if (purge && ctx->deleted) {
822 if (trash_append (ctx) == -1)
826 if (ctx->magic == M_IMAP)
827 rc = imap_sync_mailbox (ctx, purge, index_hint);
829 rc = sync_mailbox (ctx, index_hint);
831 if (ctx->magic == M_IMAP && !purge)
832 mutt_message (_("Mailbox checkpointed."));
834 mutt_message (_("%d kept, %d deleted."), msgcount - deleted, deleted);
838 /* if we haven't deleted any messages, we don't need to resort */
839 /* ... except for certain folder formats which need "unsorted"
840 * sort order in order to synchronize folders.
842 * MH and maildir are safe. mbox-style seems to need re-sorting,
843 * at least with the new threading code.
845 if (purge || (ctx->magic != M_MAILDIR && ctx->magic != M_MH)) {
846 /* IMAP does this automatically after handling EXPUNGE */
847 if (ctx->magic != M_IMAP)
849 mx_update_tables (ctx, 1);
850 mutt_sort_headers (ctx, 1); /* rethread from scratch */
858 int mx_sync_mailbox (CONTEXT* ctx, int* index_hint) {
859 int ret = _mx_sync_mailbox (ctx, index_hint);
860 sidebar_set_buffystats (ctx);
865 * dest destintation mailbox
866 * hdr message being copied (required for maildir support, because
867 * the filename depends on the message flags)
869 MESSAGE *mx_open_new_message (CONTEXT * dest, HEADER * hdr, int flags)
874 if (!MX_IDX(dest->magic-1)) {
878 msg = p_new(MESSAGE, 1);
879 msg->magic = dest->magic;
883 msg->flags.flagged = hdr->flagged;
884 msg->flags.replied = hdr->replied;
885 msg->flags.read = hdr->read;
886 msg->received = hdr->received;
889 if (msg->received == 0)
890 time (&msg->received);
892 if (mxfmts[dest->magic-1]->mx_open_new_message(msg, dest, hdr) == 0) {
893 if (msg->magic == M_MBOX && flags & M_ADD_FROM) {
895 if (hdr->env->return_path)
896 p = hdr->env->return_path;
897 else if (hdr->env->sender)
898 p = hdr->env->sender;
903 fprintf (msg->fp, "From %s %s", p ? p->mailbox : NONULL(mod_core.username),
904 ctime (&msg->received));
913 /* check for new mail */
914 int mx_check_mailbox (CONTEXT * ctx, int *index_hint, int lock) {
916 return mutt_check_mailbox_compressed (ctx);
921 if (MX_IDX(ctx->magic-1) && mxfmts[ctx->magic-1]->mx_check_mailbox)
922 return (mxfmts[ctx->magic-1]->mx_check_mailbox(ctx, index_hint, lock));
928 /* return a stream pointer for a message */
929 MESSAGE *mx_open_message (CONTEXT * ctx, int msgno)
933 msg = p_new(MESSAGE, 1);
934 switch (msg->magic = ctx->magic) {
942 HEADER *cur = ctx->hdrs[msgno];
943 char path[_POSIX_PATH_MAX];
945 snprintf (path, sizeof (path), "%s/%s", ctx->path, cur->path);
947 if ((msg->fp = fopen (path, "r")) == NULL && errno == ENOENT &&
948 ctx->magic == M_MAILDIR)
949 msg->fp = maildir_open_find_message (ctx->path, cur->path);
951 if (msg->fp == NULL) {
960 if (imap_fetch_message (msg, ctx, msgno) != 0)
967 if (pop_fetch_message (msg, ctx, msgno) != 0)
979 /* commit a message to a folder */
981 int mx_commit_message (MESSAGE * msg, CONTEXT * ctx) {
982 if (!(msg->write && ctx->append)) {
985 if (!ctx || !MX_IDX(ctx->magic-1) || !mxfmts[ctx->magic-1]->mx_commit_message)
987 return (mxfmts[ctx->magic-1]->mx_commit_message (msg, ctx));
990 /* close a pointer to a message */
991 int mx_close_message (MESSAGE ** msg)
995 if ((*msg)->magic == M_MH || (*msg)->magic == M_MAILDIR
996 || (*msg)->magic == M_IMAP || (*msg)->magic == M_POP)
998 r = m_fclose(&(*msg)->fp);
1004 unlink ((*msg)->path);
1005 p_delete(&(*msg)->path);
1012 void mx_alloc_memory (CONTEXT * ctx)
1016 p_realloc(&ctx->hdrs, ctx->hdrmax);
1017 p_realloc(&ctx->v2r, ctx->hdrmax);
1018 p_clear(ctx->hdrs + ctx->msgcount, ctx->hdrmax - ctx->msgcount);
1019 p_clear(ctx->v2r + ctx->msgcount, ctx->hdrmax - ctx->msgcount);
1022 /* this routine is called to update the counts in the context structure for
1023 * the last message header parsed.
1025 void mx_update_context (CONTEXT * ctx, int new_messages)
1030 for (msgno = ctx->msgcount - new_messages; msgno < ctx->msgcount; msgno++) {
1031 h = ctx->hdrs[msgno];
1033 /* NOTE: this _must_ be done before the check for mailcap! */
1034 h->security = crypt_query (h->content);
1036 if (!ctx->pattern) {
1037 ctx->v2r[ctx->vcount] = msgno;
1038 h->virtual = ctx->vcount++;
1044 if (h->env->supersedes) {
1048 ctx->id_hash = mutt_make_id_hash (ctx);
1050 h2 = hash_find (ctx->id_hash, h->env->supersedes);
1052 /* p_delete(&h->env->supersedes); should I ? */
1055 if (!ctx->counting && mod_score.enable)
1056 mutt_score_message (ctx, h2, 1);
1060 /* add this message to the hash tables */
1061 if (ctx->id_hash && h->env->message_id)
1062 hash_insert (ctx->id_hash, h->env->message_id, h);
1063 if (!ctx->counting) {
1064 if (ctx->subj_hash && h->env->real_subj)
1065 hash_insert (ctx->subj_hash, h->env->real_subj, h);
1067 if (mod_score.enable)
1068 mutt_score_message (ctx, h, 0);
1083 /* update sidebar count */
1084 sidebar_set_buffystats (ctx);
1089 * 1 if the specified mailbox contains 0 messages.
1090 * 0 if the mailbox contains messages
1093 int mx_check_empty (const char *path)
1096 if ((i = mx_get_idx (path)) >= 0 && mxfmts[i]->mx_check_empty)
1097 return (mxfmts[i]->mx_check_empty(path));
1102 int mx_acl_check(CONTEXT *ctx, int flag)
1104 if (!mxfmts[ctx->magic-1]->mx_acl_check)
1106 return mxfmts[ctx->magic-1]->mx_acl_check(ctx,flag);
1109 void mutt_parse_mime_message (CONTEXT * ctx, HEADER * cur)
1115 if (cur->content->type != TYPEMESSAGE
1116 && cur->content->type != TYPEMULTIPART)
1117 break; /* nothing to do */
1119 if (cur->content->parts)
1120 break; /* The message was parsed earlier. */
1122 if ((msg = mx_open_message (ctx, cur->msgno))) {
1123 mutt_parse_part (msg->fp, cur->content);
1125 cur->security = crypt_query (cur->content);
1127 mx_close_message (&msg);
1130 mutt_count_body_parts (cur, flags | M_PARTS_RECOUNT);