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);
160 /* mx_access: Wrapper for access, checks permissions on a given mailbox.
161 * We may be interested in using ACL-style flags at some point, currently
162 * we use the normal access() flags. */
163 int mx_access (const char *path, int flags)
167 if ((i = mx_get_idx (path)) >= 0 && mxfmts[i]->mx_access)
168 return (mxfmts[i]->mx_access(path,flags));
172 static int mx_open_mailbox_append (CONTEXT * ctx, int flags)
176 /* special case for appending to compressed folders -
177 * even if we can not open them for reading */
178 if (mutt_can_append_compressed (ctx->path))
179 mutt_open_append_compressed (ctx);
183 if (mx_get_magic (ctx->path) == M_IMAP)
184 return imap_open_mailbox_append (ctx);
186 if (stat (ctx->path, &sb) == 0) {
187 ctx->magic = mx_get_magic (ctx->path);
189 switch (ctx->magic) {
191 mutt_error (_("%s is not a mailbox."), ctx->path);
197 else if (errno == ENOENT) {
198 int len = m_strlen(ctx->path);
199 if (len > 0 && ctx->path[len - 1] == '/') {
200 char tmp[_POSIX_PATH_MAX];
202 if (mkdir (ctx->path, S_IRWXU)) {
203 mutt_perror (ctx->path);
207 snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
208 if (mkdir (tmp, S_IRWXU)) {
214 snprintf (tmp, sizeof (tmp), "%s/new", ctx->path);
215 if (mkdir (tmp, S_IRWXU)) {
217 snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
222 snprintf (tmp, sizeof (tmp), "%s/tmp", ctx->path);
223 if (mkdir (tmp, S_IRWXU)) {
225 snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
227 snprintf (tmp, sizeof (tmp), "%s/new", ctx->path);
232 ctx->magic = M_MAILDIR;
237 mutt_perror (ctx->path);
241 switch (ctx->magic) {
244 safe_fopen (ctx->path, flags & M_NEWFOLDER ? "w" : "a")) == NULL
245 || mbox_lock_mailbox(ctx, 1, 1) != 0) {
247 mutt_perror (ctx->path);
249 mutt_error (_("Couldn't lock %s\n"), ctx->path);
254 fseeko (ctx->fp, 0, 2);
270 * open a mailbox and parse it
273 * flags M_NOSORT do not sort mailbox
274 * M_APPEND open mailbox for appending
275 * M_READONLY open mailbox in read-only mode
276 * M_QUIET only print error messages
277 * ctx if non-null, context struct to use
279 CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT * pctx)
285 ctx = p_new(CONTEXT, 1);
287 ctx->path = m_strdup(path);
289 ctx->msgnotreadyet = -1;
294 if (flags & M_READONLY)
299 if (flags & (M_APPEND | M_NEWFOLDER)) {
300 if (mx_open_mailbox_append (ctx, flags) != 0) {
301 mx_fastclose_mailbox (ctx);
309 if (!MX_IDX(ctx->magic-1))
310 ctx->magic = mx_get_magic (path);
312 if (ctx->magic == M_COMPRESSED)
313 mutt_open_read_compressed (ctx);
316 mutt_error (_("%s is not a mailbox."), path);
318 if (ctx->magic == -1)
321 if (ctx->magic <= 0) {
322 mx_fastclose_mailbox (ctx);
328 /* if the user has a `push' command in their .muttrc, or in a folder-hook,
329 * it will cause the progress messages not to be displayed because
330 * mutt_refresh() will think we are in the middle of a macro. so set a
331 * flag to indicate that we should really refresh the screen.
333 set_option (OPTFORCEREFRESH);
336 mutt_message (_("Reading %s..."), ctx->path);
338 rc = mxfmts[ctx->magic-1]->mx_open_mailbox(ctx);
341 if ((flags & M_NOSORT) == 0) {
342 /* avoid unnecessary work since the mailbox is completely unthreaded
344 unset_option (OPTSORTSUBTHREADS);
345 unset_option (OPTNEEDRESCORE);
346 mutt_sort_headers (ctx, 1);
352 mx_fastclose_mailbox (ctx);
357 unset_option (OPTFORCEREFRESH);
361 /* free up memory associated with the mailbox context */
362 void mx_fastclose_mailbox (CONTEXT * ctx)
369 if (MX_IDX(ctx->magic-1) && mxfmts[ctx->magic-1]->mx_fastclose_mailbox)
370 mxfmts[ctx->magic-1]->mx_fastclose_mailbox(ctx);
372 hash_delete (&ctx->subj_hash, NULL);
374 hash_delete (&ctx->id_hash, NULL);
375 mutt_clear_threads (ctx);
376 for (i = 0; i < ctx->msgcount; i++)
377 header_delete(&ctx->hdrs[i]);
378 p_delete(&ctx->hdrs);
382 mutt_fast_close_compressed (ctx);
384 p_delete(&ctx->path);
385 p_delete(&ctx->pattern);
386 pattern_list_wipe(&ctx->limit_pattern);
391 /* save changes to disk */
392 static int sync_mailbox (CONTEXT * ctx, int *index_hint)
397 mutt_message (_("Writing %s..."), ctx->path);
399 if (MX_IDX(ctx->magic-1))
400 /* the 1 is only of interest for IMAP and means EXPUNGE */
401 rc = mxfmts[ctx->magic-1]->mx_sync_mailbox(ctx,1,index_hint);
403 if (rc == 0 && ctx->cinfo)
404 return mutt_sync_compressed (ctx);
409 /* move deleted mails to the trash folder */
410 static int trash_append (CONTEXT * ctx)
416 if (!TrashPath || !ctx->deleted ||
417 (ctx->magic == M_MAILDIR && option (OPTMAILDIRTRASH)))
420 for (; i < ctx->msgcount && (!ctx->hdrs[i]->deleted ||
421 ctx->hdrs[i]->appended); i++);
422 if (i == ctx->msgcount)
423 return 0; /* nothing to be done */
425 if (mutt_save_confirm (TrashPath, &st) != 0) {
426 mutt_error _("message(s) not deleted");
431 if (lstat (ctx->path, &stc) == 0 && stc.st_ino == st.st_ino
432 && stc.st_dev == st.st_dev && stc.st_rdev == st.st_rdev)
433 return 0; /* we are in the trash folder: simple sync */
435 if ((ctx_trash = mx_open_mailbox (TrashPath, M_APPEND, NULL)) != NULL) {
436 for (i = 0; i < ctx->msgcount; i++)
437 if (ctx->hdrs[i]->deleted && !ctx->hdrs[i]->appended
438 && !ctx->hdrs[i]->purged
439 && mutt_append_message (ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1) {
440 mx_close_mailbox (ctx_trash, NULL);
444 mx_close_mailbox (ctx_trash, NULL);
447 mutt_error _("Can't open trash folder");
455 /* save changes and close mailbox */
456 static int _mx_close_mailbox (CONTEXT * ctx, int *index_hint)
458 int i, move_messages = 0, purge = 1, read_msgs = 0;
462 char mbox[_POSIX_PATH_MAX];
470 if (ctx->readonly || ctx->dontwrite) {
471 /* mailbox is readonly or we don't want to write */
472 mx_fastclose_mailbox (ctx);
477 /* mailbox was opened in write-mode */
478 if (ctx->magic == M_MBOX)
479 mbox_close_mailbox (ctx);
481 mx_fastclose_mailbox (ctx);
485 for (i = 0; i < ctx->msgcount; i++) {
486 if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->read
487 && !(ctx->hdrs[i]->flagged && option (OPTKEEPFLAGGED)))
491 if (read_msgs && quadoption (OPT_MOVE) != M_NO) {
492 m_strcpy(mbox, sizeof(mbox), NONULL(Inbox));
493 isSpool = mutt_is_spool (ctx->path) && !mutt_is_spool (mbox);
494 mutt_expand_path (mbox, sizeof (mbox));
497 snprintf (buf, sizeof (buf), _("Move read messages to %s?"), mbox);
498 if ((move_messages = query_quadoption (OPT_MOVE, buf)) == -1) {
506 * There is no point in asking whether or not to purge if we are
507 * just marking messages as "trash".
509 if (ctx->deleted && !(ctx->magic == M_MAILDIR && option (OPTMAILDIRTRASH))) {
510 snprintf (buf, sizeof (buf), ctx->deleted == 1
511 ? _("Purge %d deleted message?") :
512 _("Purge %d deleted messages?"), ctx->deleted);
513 if ((purge = query_quadoption (OPT_DELETE, buf)) < 0) {
519 /* IMAP servers manage the OLD flag themselves */
520 if (ctx->magic != M_IMAP)
521 if (option (OPTMARKOLD)) {
522 for (i = 0; i < ctx->msgcount; i++) {
523 if (!ctx->hdrs[i]->deleted && !ctx->hdrs[i]->old)
524 mutt_set_flag (ctx, ctx->hdrs[i], M_OLD, 1);
529 mutt_message (_("Moving read messages to %s..."), mbox);
531 /* try to use server-side copy first */
534 if (ctx->magic == M_IMAP && imap_is_magic (mbox, NULL) == M_IMAP) {
535 /* tag messages for moving, and clear old tags, if any */
536 for (i = 0; i < ctx->msgcount; i++)
537 if (ctx->hdrs[i]->read && !ctx->hdrs[i]->deleted
538 && !(ctx->hdrs[i]->flagged && option (OPTKEEPFLAGGED)))
539 ctx->hdrs[i]->tagged = 1;
541 ctx->hdrs[i]->tagged = 0;
543 i = imap_copy_messages (ctx, NULL, mbox, 1);
546 if (i == 0) /* success */
548 else if (i == -1) { /* horrible error, bail */
552 else /* use regular append-copy mode */
554 if (mx_open_mailbox (mbox, M_APPEND, &f) == NULL) {
559 for (i = 0; i < ctx->msgcount; i++) {
560 if (ctx->hdrs[i]->read && !ctx->hdrs[i]->deleted
561 && !(ctx->hdrs[i]->flagged && option (OPTKEEPFLAGGED))) {
562 if (mutt_append_message (&f, ctx, ctx->hdrs[i], 0, CH_UPDATE_LEN) ==
564 mutt_set_flag (ctx, ctx->hdrs[i], M_DELETE, 1);
565 mutt_set_flag (ctx, ctx->hdrs[i], M_APPENDED, 1);
568 mx_close_mailbox (&f, NULL);
575 mx_close_mailbox (&f, NULL);
579 else if (!ctx->changed && ctx->deleted == 0) {
580 mutt_message _("Mailbox is unchanged.");
582 mx_fastclose_mailbox (ctx);
586 /* copy mails to the trash before expunging */
587 if (purge && ctx->deleted)
588 if (trash_append (ctx) != 0) {
593 /* allow IMAP to preserve the deleted flag across sessions */
594 if (ctx->magic == M_IMAP) {
595 if ((check = imap_sync_mailbox (ctx, purge, index_hint)) != 0) {
603 for (i = 0; i < ctx->msgcount; i++)
604 ctx->hdrs[i]->deleted = 0;
608 if (ctx->changed || ctx->deleted) {
609 if ((check = sync_mailbox (ctx, index_hint)) != 0) {
617 mutt_message (_("%d kept, %d moved, %d deleted."),
618 ctx->msgcount - ctx->deleted, read_msgs, ctx->deleted);
620 mutt_message (_("%d kept, %d deleted."),
621 ctx->msgcount - ctx->deleted, ctx->deleted);
623 if (ctx->cinfo && mutt_slow_close_compressed (ctx))
626 mx_fastclose_mailbox (ctx);
631 int mx_close_mailbox (CONTEXT * ctx, int *index_hint) {
635 ret = _mx_close_mailbox (ctx, index_hint);
636 sidebar_set_buffystats (ctx);
640 /* update a Context structure's internal tables. */
642 void mx_update_tables (CONTEXT * ctx, int committing)
646 /* update memory to reflect the new state of the mailbox */
655 #define this_body ctx->hdrs[j]->content
656 for (i = 0, j = 0; i < ctx->msgcount; i++) {
657 if ((committing && (!ctx->hdrs[i]->deleted ||
658 (ctx->magic == M_MAILDIR
659 && option (OPTMAILDIRTRASH)))) || (!committing
663 ctx->hdrs[j] = ctx->hdrs[i];
666 ctx->hdrs[j]->msgno = j;
667 if (ctx->hdrs[j]->virtual != -1) {
668 ctx->v2r[ctx->vcount] = j;
669 ctx->hdrs[j]->virtual = ctx->vcount++;
670 ctx->vsize += this_body->length + this_body->offset -
671 this_body->hdr_offset;
675 ctx->hdrs[j]->changed = 0;
676 else if (ctx->hdrs[j]->changed)
680 || (ctx->magic == M_MAILDIR && option (OPTMAILDIRTRASH))) {
681 if (ctx->hdrs[j]->deleted)
685 if (ctx->hdrs[j]->tagged)
687 if (ctx->hdrs[j]->flagged)
689 if (!ctx->hdrs[j]->read) {
691 if (!ctx->hdrs[j]->old)
698 if (ctx->magic == M_MH || ctx->magic == M_MAILDIR)
699 ctx->size -= (ctx->hdrs[i]->content->length +
700 ctx->hdrs[i]->content->offset -
701 ctx->hdrs[i]->content->hdr_offset);
702 /* remove message from the hash tables */
703 if (ctx->subj_hash && ctx->hdrs[i]->env->real_subj)
704 hash_remove (ctx->subj_hash, ctx->hdrs[i]->env->real_subj,
706 if (ctx->id_hash && ctx->hdrs[i]->env->message_id)
707 hash_remove (ctx->id_hash, ctx->hdrs[i]->env->message_id,
709 header_delete(&ctx->hdrs[i]);
715 /* update sidebar count */
716 sidebar_set_buffystats (ctx);
720 /* save changes to mailbox
726 static int _mx_sync_mailbox (CONTEXT * ctx, int *index_hint)
730 int msgcount, deleted;
732 if (ctx->dontwrite) {
733 char buf[STRING], tmp[STRING];
735 if (km_expand_key (buf, sizeof (buf),
736 km_find_func (MENU_MAIN, OP_TOGGLE_WRITE)))
737 snprintf (tmp, sizeof (tmp), _(" Press '%s' to toggle write"), buf);
739 m_strcpy(tmp, sizeof(tmp), _("Use 'toggle-write' to re-enable write!"));
741 mutt_error (_("Mailbox is marked unwritable. %s"), tmp);
744 else if (ctx->readonly) {
745 mutt_error _("Mailbox is read-only.");
750 if (!ctx->changed && !ctx->deleted) {
751 mutt_message _("Mailbox is unchanged.");
759 snprintf (buf, sizeof (buf), ctx->deleted == 1
760 ? _("Purge %d deleted message?") :
761 _("Purge %d deleted messages?"), ctx->deleted);
762 if ((purge = query_quadoption (OPT_DELETE, buf)) < 0)
764 else if (purge == M_NO) {
766 return 0; /* nothing to do! */
767 /* let IMAP servers hold on to D flags */
768 if (ctx->magic != M_IMAP)
770 for (i = 0; i < ctx->msgcount; i++)
771 ctx->hdrs[i]->deleted = 0;
775 else if (ctx->last_tag && ctx->last_tag->deleted)
776 ctx->last_tag = NULL; /* reset last tagged msg now useless */
779 /* really only for IMAP - imap_sync_mailbox results in a call to
780 * mx_update_tables, so ctx->deleted is 0 when it comes back */
781 msgcount = ctx->msgcount;
782 deleted = ctx->deleted;
784 if (purge && ctx->deleted) {
785 if (trash_append (ctx) == -1)
789 if (ctx->magic == M_IMAP)
790 rc = imap_sync_mailbox (ctx, purge, index_hint);
792 rc = sync_mailbox (ctx, index_hint);
794 if (ctx->magic == M_IMAP && !purge)
795 mutt_message (_("Mailbox checkpointed."));
797 mutt_message (_("%d kept, %d deleted."), msgcount - deleted, deleted);
801 /* if we haven't deleted any messages, we don't need to resort */
802 /* ... except for certain folder formats which need "unsorted"
803 * sort order in order to synchronize folders.
805 * MH and maildir are safe. mbox-style seems to need re-sorting,
806 * at least with the new threading code.
808 if (purge || (ctx->magic != M_MAILDIR && ctx->magic != M_MH)) {
809 /* IMAP does this automatically after handling EXPUNGE */
810 if (ctx->magic != M_IMAP)
812 mx_update_tables (ctx, 1);
813 mutt_sort_headers (ctx, 1); /* rethread from scratch */
821 int mx_sync_mailbox (CONTEXT* ctx, int* index_hint) {
822 int ret = _mx_sync_mailbox (ctx, index_hint);
823 sidebar_set_buffystats (ctx);
828 * dest destintation mailbox
829 * hdr message being copied (required for maildir support, because
830 * the filename depends on the message flags)
832 MESSAGE *mx_open_new_message (CONTEXT * dest, HEADER * hdr, int flags)
837 if (!MX_IDX(dest->magic-1)) {
841 msg = p_new(MESSAGE, 1);
842 msg->magic = dest->magic;
846 msg->flags.flagged = hdr->flagged;
847 msg->flags.replied = hdr->replied;
848 msg->flags.read = hdr->read;
849 msg->received = hdr->received;
852 if (msg->received == 0)
853 time (&msg->received);
855 if (mxfmts[dest->magic-1]->mx_open_new_message(msg, dest, hdr) == 0) {
856 if (msg->magic == M_MBOX && flags & M_ADD_FROM) {
858 if (hdr->env->return_path)
859 p = hdr->env->return_path;
860 else if (hdr->env->sender)
861 p = hdr->env->sender;
866 fprintf (msg->fp, "From %s %s", p ? p->mailbox : NONULL(mod_core.username),
867 ctime (&msg->received));
876 /* check for new mail */
877 int mx_check_mailbox (CONTEXT * ctx, int *index_hint, int lock) {
879 return mutt_check_mailbox_compressed (ctx);
884 if (MX_IDX(ctx->magic-1) && mxfmts[ctx->magic-1]->mx_check_mailbox)
885 return (mxfmts[ctx->magic-1]->mx_check_mailbox(ctx, index_hint, lock));
891 /* return a stream pointer for a message */
892 MESSAGE *mx_open_message (CONTEXT * ctx, int msgno)
896 msg = p_new(MESSAGE, 1);
897 switch (msg->magic = ctx->magic) {
905 HEADER *cur = ctx->hdrs[msgno];
906 char path[_POSIX_PATH_MAX];
908 snprintf (path, sizeof (path), "%s/%s", ctx->path, cur->path);
910 if ((msg->fp = fopen (path, "r")) == NULL && errno == ENOENT &&
911 ctx->magic == M_MAILDIR)
912 msg->fp = maildir_open_find_message (ctx->path, cur->path);
914 if (msg->fp == NULL) {
923 if (imap_fetch_message (msg, ctx, msgno) != 0)
930 if (pop_fetch_message (msg, ctx, msgno) != 0)
942 /* commit a message to a folder */
944 int mx_commit_message (MESSAGE * msg, CONTEXT * ctx) {
945 if (!(msg->write && ctx->append)) {
948 if (!ctx || !MX_IDX(ctx->magic-1) || !mxfmts[ctx->magic-1]->mx_commit_message)
950 return (mxfmts[ctx->magic-1]->mx_commit_message (msg, ctx));
953 /* close a pointer to a message */
954 int mx_close_message (MESSAGE ** msg)
958 if ((*msg)->magic == M_MH || (*msg)->magic == M_MAILDIR
959 || (*msg)->magic == M_IMAP || (*msg)->magic == M_POP)
961 r = m_fclose(&(*msg)->fp);
967 unlink ((*msg)->path);
968 p_delete(&(*msg)->path);
975 void mx_alloc_memory (CONTEXT * ctx)
979 p_realloc(&ctx->hdrs, ctx->hdrmax);
980 p_realloc(&ctx->v2r, ctx->hdrmax);
981 p_clear(ctx->hdrs + ctx->msgcount, ctx->hdrmax - ctx->msgcount);
982 p_clear(ctx->v2r + ctx->msgcount, ctx->hdrmax - ctx->msgcount);
985 /* this routine is called to update the counts in the context structure for
986 * the last message header parsed.
988 void mx_update_context (CONTEXT * ctx, int new_messages)
993 for (msgno = ctx->msgcount - new_messages; msgno < ctx->msgcount; msgno++) {
994 h = ctx->hdrs[msgno];
996 /* NOTE: this _must_ be done before the check for mailcap! */
997 h->security = crypt_query (h->content);
1000 ctx->v2r[ctx->vcount] = msgno;
1001 h->virtual = ctx->vcount++;
1007 if (h->env->supersedes) {
1011 ctx->id_hash = mutt_make_id_hash (ctx);
1013 h2 = hash_find (ctx->id_hash, h->env->supersedes);
1015 /* p_delete(&h->env->supersedes); should I ? */
1018 if (!ctx->counting && mod_score.enable)
1019 mutt_score_message (ctx, h2, 1);
1023 /* add this message to the hash tables */
1024 if (ctx->id_hash && h->env->message_id)
1025 hash_insert (ctx->id_hash, h->env->message_id, h);
1026 if (!ctx->counting) {
1027 if (ctx->subj_hash && h->env->real_subj)
1028 hash_insert (ctx->subj_hash, h->env->real_subj, h);
1030 if (mod_score.enable)
1031 mutt_score_message (ctx, h, 0);
1046 /* update sidebar count */
1047 sidebar_set_buffystats (ctx);
1052 * 1 if the specified mailbox contains 0 messages.
1053 * 0 if the mailbox contains messages
1056 int mx_check_empty (const char *path)
1059 if ((i = mx_get_idx (path)) >= 0 && mxfmts[i]->mx_check_empty)
1060 return (mxfmts[i]->mx_check_empty(path));
1065 int mx_acl_check(CONTEXT *ctx, int flag)
1067 if (!mxfmts[ctx->magic-1]->mx_acl_check)
1069 return mxfmts[ctx->magic-1]->mx_acl_check(ctx,flag);
1072 void mutt_parse_mime_message (CONTEXT * ctx, HEADER * cur)
1078 if (cur->content->type != TYPEMESSAGE
1079 && cur->content->type != TYPEMULTIPART)
1080 break; /* nothing to do */
1082 if (cur->content->parts)
1083 break; /* The message was parsed earlier. */
1085 if ((msg = mx_open_message (ctx, cur->msgno))) {
1086 mutt_parse_part (msg->fp, cur->content);
1088 cur->security = crypt_query (cur->content);
1090 mx_close_message (&msg);
1093 mutt_count_body_parts (cur, flags | M_PARTS_RECOUNT);