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/sidebar.h>
33 #include <imap/imap.h>
36 static mx_t const *mxfmts[] = {
45 #define MX_IDX(idx) (idx >= 0 && idx < countof(mxfmts))
46 #define mutt_is_spool(s) (m_strcmp(Spoolfile, s) == 0)
48 static int dotlock_file(const char *path, int retry)
50 char lockfile[_POSIX_PATH_MAX];
51 snprintf(lockfile, sizeof(lockfile), "%s.lock", path);
53 if (lockfile_create(lockfile, retry ? 1 : 0, 0)) {
55 mutt_error (_("Can't dotlock %s.\n"), lockfile);
60 static int undotlock_file (const char *path)
62 char lockfile[_POSIX_PATH_MAX];
63 snprintf(lockfile, sizeof(lockfile), "%s.lock", path);
64 return lockfile_remove(lockfile);
67 /* looks up index of type for path in mxfmts */
68 static int mx_get_idx (const char* path) {
72 /* first, test all non-local folders to avoid stat() call */
73 for (i = 0; i < countof(mxfmts); i++) {
74 if (!mxfmts[i]->local)
75 t = mxfmts[i]->mx_is_magic(path, NULL);
79 if (stat (path, &st) == 0) {
80 /* if stat() succeeded, keep testing until success and
81 * pass stat() info so that we only need to do it once */
82 for (i = 0; i < countof(mxfmts); i++) {
84 t = mxfmts[i]->mx_is_magic(path, &st);
93 * excl if excl != 0, request an exclusive lock
94 * dot if dot != 0, try to dotlock the file
95 * time_out should retry locking?
97 int mx_lock_file (const char *path, int fd, int excl, int dot, int time_out)
99 #if defined (USE_FCNTL) || defined (USE_FLOCK)
110 lck.l_type = excl ? F_WRLCK : F_RDLCK;
111 lck.l_whence = SEEK_SET;
116 while (fcntl (fd, F_SETLK, &lck) == -1) {
119 if (errno != EAGAIN && errno != EACCES) {
120 mutt_perror ("fcntl");
124 if (fstat (fd, &sb) != 0)
130 /* only unlock file if it is unchanged */
131 if (prev_sb.st_size == sb.st_size
132 && ++count >= (time_out ? MAXLOCKATTEMPT : 0)) {
134 mutt_error _("Timeout exceeded while attempting fcntl lock!");
141 mutt_message (_("Waiting for fcntl lock... %d"), ++attempt);
144 #endif /* USE_FCNTL */
149 while (flock (fd, (excl ? LOCK_EX : LOCK_SH) | LOCK_NB) == -1) {
152 if (errno != EWOULDBLOCK) {
153 mutt_perror ("flock");
158 if (fstat (fd, &sb) != 0)
164 /* only unlock file if it is unchanged */
165 if (prev_sb.st_size == sb.st_size
166 && ++count >= (time_out ? MAXLOCKATTEMPT : 0)) {
168 mutt_error _("Timeout exceeded while attempting flock lock!");
176 mutt_message (_("Waiting for flock attempt... %d"), ++attempt);
179 #endif /* USE_FLOCK */
182 r = dotlock_file(path, time_out);
185 /* release any other locks obtained in this routine */
188 lck.l_type = F_UNLCK;
189 fcntl (fd, F_SETLK, &lck);
190 #endif /* USE_FCNTL */
194 #endif /* USE_FLOCK */
202 int mx_unlock_file (const char *path, int fd, int dot)
205 struct flock unlockit;
207 p_clear(&unlockit, 1);
208 unlockit.l_type = F_UNLCK;
209 unlockit.l_whence = SEEK_SET;
210 fcntl (fd, F_SETLK, &unlockit);
218 undotlock_file (path);
223 /* try to figure out what type of mailbox ``path'' is */
224 int mx_get_magic (const char *path) {
227 if (m_strlen(path) == 0)
229 if ((i = mx_get_idx (path)) >= 0)
230 return (mxfmts[i]->type);
234 int mx_is_local (int m) {
237 return (mxfmts[m]->local);
241 * set DefaultMagic to the given value
243 int mx_set_magic (const char *s)
245 if (ascii_strcasecmp (s, "mbox") == 0)
246 DefaultMagic = M_MBOX;
247 else if (ascii_strcasecmp (s, "mh") == 0)
249 else if (ascii_strcasecmp (s, "maildir") == 0)
250 DefaultMagic = M_MAILDIR;
257 /* mx_access: Wrapper for access, checks permissions on a given mailbox.
258 * We may be interested in using ACL-style flags at some point, currently
259 * we use the normal access() flags. */
260 int mx_access (const char *path, int flags)
264 if ((i = mx_get_idx (path)) >= 0 && mxfmts[i]->mx_access)
265 return (mxfmts[i]->mx_access(path,flags));
269 static int mx_open_mailbox_append (CONTEXT * ctx, int flags)
273 /* special case for appending to compressed folders -
274 * even if we can not open them for reading */
275 if (mutt_can_append_compressed (ctx->path))
276 mutt_open_append_compressed (ctx);
280 if (mx_get_magic (ctx->path) == M_IMAP)
281 return imap_open_mailbox_append (ctx);
283 if (stat (ctx->path, &sb) == 0) {
284 ctx->magic = mx_get_magic (ctx->path);
286 switch (ctx->magic) {
288 mutt_error (_("%s is not a mailbox."), ctx->path);
294 else if (errno == ENOENT) {
295 ctx->magic = DefaultMagic;
297 if (ctx->magic == M_MH || ctx->magic == M_MAILDIR) {
298 char tmp[_POSIX_PATH_MAX];
300 if (mkdir (ctx->path, S_IRWXU)) {
301 mutt_perror (ctx->path);
305 if (ctx->magic == M_MAILDIR) {
306 snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
307 if (mkdir (tmp, S_IRWXU)) {
313 snprintf (tmp, sizeof (tmp), "%s/new", ctx->path);
314 if (mkdir (tmp, S_IRWXU)) {
316 snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
321 snprintf (tmp, sizeof (tmp), "%s/tmp", ctx->path);
322 if (mkdir (tmp, S_IRWXU)) {
324 snprintf (tmp, sizeof (tmp), "%s/cur", ctx->path);
326 snprintf (tmp, sizeof (tmp), "%s/new", ctx->path);
335 snprintf (tmp, sizeof (tmp), "%s/.mh_sequences", ctx->path);
336 if ((i = creat (tmp, S_IRWXU)) == -1) {
346 mutt_perror (ctx->path);
350 switch (ctx->magic) {
353 safe_fopen (ctx->path, flags & M_NEWFOLDER ? "w" : "a")) == NULL
354 || mbox_lock_mailbox (ctx, 1, 1) != 0) {
356 mutt_perror (ctx->path);
358 mutt_error (_("Couldn't lock %s\n"), ctx->path);
363 fseeko (ctx->fp, 0, 2);
379 * open a mailbox and parse it
382 * flags M_NOSORT do not sort mailbox
383 * M_APPEND open mailbox for appending
384 * M_READONLY open mailbox in read-only mode
385 * M_QUIET only print error messages
386 * ctx if non-null, context struct to use
388 CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT * pctx)
394 ctx = p_new(CONTEXT, 1);
396 ctx->path = m_strdup(path);
398 ctx->msgnotreadyet = -1;
403 if (flags & M_READONLY)
408 if (flags & (M_APPEND | M_NEWFOLDER)) {
409 if (mx_open_mailbox_append (ctx, flags) != 0) {
410 mx_fastclose_mailbox (ctx);
418 if (!MX_IDX(ctx->magic-1))
419 ctx->magic = mx_get_magic (path);
421 if (ctx->magic == M_COMPRESSED)
422 mutt_open_read_compressed (ctx);
425 mutt_error (_("%s is not a mailbox."), path);
427 if (ctx->magic == -1)
430 if (ctx->magic <= 0) {
431 mx_fastclose_mailbox (ctx);
437 /* if the user has a `push' command in their .muttrc, or in a folder-hook,
438 * it will cause the progress messages not to be displayed because
439 * mutt_refresh() will think we are in the middle of a macro. so set a
440 * flag to indicate that we should really refresh the screen.
442 set_option (OPTFORCEREFRESH);
445 mutt_message (_("Reading %s..."), ctx->path);
447 rc = mxfmts[ctx->magic-1]->mx_open_mailbox(ctx);
450 if ((flags & M_NOSORT) == 0) {
451 /* avoid unnecessary work since the mailbox is completely unthreaded
453 unset_option (OPTSORTSUBTHREADS);
454 unset_option (OPTNEEDRESCORE);
455 mutt_sort_headers (ctx, 1);
461 mx_fastclose_mailbox (ctx);
466 unset_option (OPTFORCEREFRESH);
470 /* free up memory associated with the mailbox context */
471 void mx_fastclose_mailbox (CONTEXT * ctx)
478 if (MX_IDX(ctx->magic-1) && mxfmts[ctx->magic-1]->mx_fastclose_mailbox)
479 mxfmts[ctx->magic-1]->mx_fastclose_mailbox(ctx);
481 hash_delete (&ctx->subj_hash, NULL);
483 hash_delete (&ctx->id_hash, NULL);
484 mutt_clear_threads (ctx);
485 for (i = 0; i < ctx->msgcount; i++)
486 header_delete(&ctx->hdrs[i]);
487 p_delete(&ctx->hdrs);
491 mutt_fast_close_compressed (ctx);
493 p_delete(&ctx->path);
494 p_delete(&ctx->pattern);
495 pattern_list_wipe(&ctx->limit_pattern);
500 /* save changes to disk */
501 static int sync_mailbox (CONTEXT * ctx, int *index_hint)
506 mutt_message (_("Writing %s..."), ctx->path);
508 if (MX_IDX(ctx->magic-1))
509 /* the 1 is only of interest for IMAP and means EXPUNGE */
510 rc = mxfmts[ctx->magic-1]->mx_sync_mailbox(ctx,1,index_hint);
512 if (rc == 0 && ctx->cinfo)
513 return mutt_sync_compressed (ctx);
518 /* move deleted mails to the trash folder */
519 static int trash_append (CONTEXT * ctx)
525 if (!TrashPath || !ctx->deleted ||
526 (ctx->magic == M_MAILDIR && option (OPTMAILDIRTRASH)))
529 for (; i < ctx->msgcount && (!ctx->hdrs[i]->deleted ||
530 ctx->hdrs[i]->appended); i++);
531 if (i == ctx->msgcount)
532 return 0; /* nothing to be done */
534 if (mutt_save_confirm (TrashPath, &st) != 0) {
535 mutt_error _("message(s) not deleted");
540 if (lstat (ctx->path, &stc) == 0 && stc.st_ino == st.st_ino
541 && stc.st_dev == st.st_dev && stc.st_rdev == st.st_rdev)
542 return 0; /* we are in the trash folder: simple sync */
544 if ((ctx_trash = mx_open_mailbox (TrashPath, M_APPEND, NULL)) != NULL) {
545 for (i = 0; i < ctx->msgcount; i++)
546 if (ctx->hdrs[i]->deleted && !ctx->hdrs[i]->appended
547 && !ctx->hdrs[i]->purged
548 && mutt_append_message (ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1) {
549 mx_close_mailbox (ctx_trash, NULL);
553 mx_close_mailbox (ctx_trash, NULL);
556 mutt_error _("Can't open trash folder");
564 /* save changes and close mailbox */
565 static int _mx_close_mailbox (CONTEXT * ctx, int *index_hint)
567 int i, move_messages = 0, purge = 1, read_msgs = 0;
571 char mbox[_POSIX_PATH_MAX];
579 if (ctx->readonly || ctx->dontwrite) {
580 /* mailbox is readonly or we don't want to write */
581 mx_fastclose_mailbox (ctx);
586 /* mailbox was opened in write-mode */
587 if (ctx->magic == M_MBOX)
588 mbox_close_mailbox (ctx);
590 mx_fastclose_mailbox (ctx);
594 for (i = 0; i < ctx->msgcount; i++) {
595 if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->read
596 && !(ctx->hdrs[i]->flagged && option (OPTKEEPFLAGGED)))
600 if (read_msgs && quadoption (OPT_MOVE) != M_NO) {
603 if ((p = mutt_find_hook (M_MBOXHOOK, ctx->path))) {
605 m_strcpy(mbox, sizeof(mbox), p);
608 m_strcpy(mbox, sizeof(mbox), NONULL(Inbox));
609 isSpool = mutt_is_spool (ctx->path) && !mutt_is_spool (mbox);
611 mutt_expand_path (mbox, sizeof (mbox));
614 snprintf (buf, sizeof (buf), _("Move read messages to %s?"), mbox);
615 if ((move_messages = query_quadoption (OPT_MOVE, buf)) == -1) {
623 * There is no point in asking whether or not to purge if we are
624 * just marking messages as "trash".
626 if (ctx->deleted && !(ctx->magic == M_MAILDIR && option (OPTMAILDIRTRASH))) {
627 snprintf (buf, sizeof (buf), ctx->deleted == 1
628 ? _("Purge %d deleted message?") :
629 _("Purge %d deleted messages?"), ctx->deleted);
630 if ((purge = query_quadoption (OPT_DELETE, buf)) < 0) {
636 /* IMAP servers manage the OLD flag themselves */
637 if (ctx->magic != M_IMAP)
638 if (option (OPTMARKOLD)) {
639 for (i = 0; i < ctx->msgcount; i++) {
640 if (!ctx->hdrs[i]->deleted && !ctx->hdrs[i]->old)
641 mutt_set_flag (ctx, ctx->hdrs[i], M_OLD, 1);
646 mutt_message (_("Moving read messages to %s..."), mbox);
648 /* try to use server-side copy first */
651 if (ctx->magic == M_IMAP && imap_is_magic (mbox, NULL) == M_IMAP) {
652 /* tag messages for moving, and clear old tags, if any */
653 for (i = 0; i < ctx->msgcount; i++)
654 if (ctx->hdrs[i]->read && !ctx->hdrs[i]->deleted
655 && !(ctx->hdrs[i]->flagged && option (OPTKEEPFLAGGED)))
656 ctx->hdrs[i]->tagged = 1;
658 ctx->hdrs[i]->tagged = 0;
660 i = imap_copy_messages (ctx, NULL, mbox, 1);
663 if (i == 0) /* success */
665 else if (i == -1) { /* horrible error, bail */
669 else /* use regular append-copy mode */
671 if (mx_open_mailbox (mbox, M_APPEND, &f) == NULL) {
676 for (i = 0; i < ctx->msgcount; i++) {
677 if (ctx->hdrs[i]->read && !ctx->hdrs[i]->deleted
678 && !(ctx->hdrs[i]->flagged && option (OPTKEEPFLAGGED))) {
679 if (mutt_append_message (&f, ctx, ctx->hdrs[i], 0, CH_UPDATE_LEN) ==
681 mutt_set_flag (ctx, ctx->hdrs[i], M_DELETE, 1);
682 mutt_set_flag (ctx, ctx->hdrs[i], M_APPENDED, 1);
685 mx_close_mailbox (&f, NULL);
692 mx_close_mailbox (&f, NULL);
696 else if (!ctx->changed && ctx->deleted == 0) {
697 mutt_message _("Mailbox is unchanged.");
699 mx_fastclose_mailbox (ctx);
703 /* copy mails to the trash before expunging */
704 if (purge && ctx->deleted)
705 if (trash_append (ctx) != 0) {
710 /* allow IMAP to preserve the deleted flag across sessions */
711 if (ctx->magic == M_IMAP) {
712 if ((check = imap_sync_mailbox (ctx, purge, index_hint)) != 0) {
720 for (i = 0; i < ctx->msgcount; i++)
721 ctx->hdrs[i]->deleted = 0;
725 if (ctx->changed || ctx->deleted) {
726 if ((check = sync_mailbox (ctx, index_hint)) != 0) {
734 mutt_message (_("%d kept, %d moved, %d deleted."),
735 ctx->msgcount - ctx->deleted, read_msgs, ctx->deleted);
737 mutt_message (_("%d kept, %d deleted."),
738 ctx->msgcount - ctx->deleted, ctx->deleted);
740 if (ctx->cinfo && mutt_slow_close_compressed (ctx))
743 mx_fastclose_mailbox (ctx);
748 int mx_close_mailbox (CONTEXT * ctx, int *index_hint) {
752 ret = _mx_close_mailbox (ctx, index_hint);
753 sidebar_set_buffystats (ctx);
757 /* update a Context structure's internal tables. */
759 void mx_update_tables (CONTEXT * ctx, int committing)
763 /* update memory to reflect the new state of the mailbox */
772 #define this_body ctx->hdrs[j]->content
773 for (i = 0, j = 0; i < ctx->msgcount; i++) {
774 if ((committing && (!ctx->hdrs[i]->deleted ||
775 (ctx->magic == M_MAILDIR
776 && option (OPTMAILDIRTRASH)))) || (!committing
780 ctx->hdrs[j] = ctx->hdrs[i];
783 ctx->hdrs[j]->msgno = j;
784 if (ctx->hdrs[j]->virtual != -1) {
785 ctx->v2r[ctx->vcount] = j;
786 ctx->hdrs[j]->virtual = ctx->vcount++;
787 ctx->vsize += this_body->length + this_body->offset -
788 this_body->hdr_offset;
792 ctx->hdrs[j]->changed = 0;
793 else if (ctx->hdrs[j]->changed)
797 || (ctx->magic == M_MAILDIR && option (OPTMAILDIRTRASH))) {
798 if (ctx->hdrs[j]->deleted)
802 if (ctx->hdrs[j]->tagged)
804 if (ctx->hdrs[j]->flagged)
806 if (!ctx->hdrs[j]->read) {
808 if (!ctx->hdrs[j]->old)
815 if (ctx->magic == M_MH || ctx->magic == M_MAILDIR)
816 ctx->size -= (ctx->hdrs[i]->content->length +
817 ctx->hdrs[i]->content->offset -
818 ctx->hdrs[i]->content->hdr_offset);
819 /* remove message from the hash tables */
820 if (ctx->subj_hash && ctx->hdrs[i]->env->real_subj)
821 hash_remove (ctx->subj_hash, ctx->hdrs[i]->env->real_subj,
823 if (ctx->id_hash && ctx->hdrs[i]->env->message_id)
824 hash_remove (ctx->id_hash, ctx->hdrs[i]->env->message_id,
826 header_delete(&ctx->hdrs[i]);
832 /* update sidebar count */
833 sidebar_set_buffystats (ctx);
837 /* save changes to mailbox
843 static int _mx_sync_mailbox (CONTEXT * ctx, int *index_hint)
847 int msgcount, deleted;
849 if (ctx->dontwrite) {
850 char buf[STRING], tmp[STRING];
852 if (km_expand_key (buf, sizeof (buf),
853 km_find_func (MENU_MAIN, OP_TOGGLE_WRITE)))
854 snprintf (tmp, sizeof (tmp), _(" Press '%s' to toggle write"), buf);
856 m_strcpy(tmp, sizeof(tmp), _("Use 'toggle-write' to re-enable write!"));
858 mutt_error (_("Mailbox is marked unwritable. %s"), tmp);
861 else if (ctx->readonly) {
862 mutt_error _("Mailbox is read-only.");
867 if (!ctx->changed && !ctx->deleted) {
868 mutt_message _("Mailbox is unchanged.");
876 snprintf (buf, sizeof (buf), ctx->deleted == 1
877 ? _("Purge %d deleted message?") :
878 _("Purge %d deleted messages?"), ctx->deleted);
879 if ((purge = query_quadoption (OPT_DELETE, buf)) < 0)
881 else if (purge == M_NO) {
883 return 0; /* nothing to do! */
884 /* let IMAP servers hold on to D flags */
885 if (ctx->magic != M_IMAP)
887 for (i = 0; i < ctx->msgcount; i++)
888 ctx->hdrs[i]->deleted = 0;
892 else if (ctx->last_tag && ctx->last_tag->deleted)
893 ctx->last_tag = NULL; /* reset last tagged msg now useless */
896 /* really only for IMAP - imap_sync_mailbox results in a call to
897 * mx_update_tables, so ctx->deleted is 0 when it comes back */
898 msgcount = ctx->msgcount;
899 deleted = ctx->deleted;
901 if (purge && ctx->deleted) {
902 if (trash_append (ctx) == -1)
906 if (ctx->magic == M_IMAP)
907 rc = imap_sync_mailbox (ctx, purge, index_hint);
909 rc = sync_mailbox (ctx, index_hint);
911 if (ctx->magic == M_IMAP && !purge)
912 mutt_message (_("Mailbox checkpointed."));
914 mutt_message (_("%d kept, %d deleted."), msgcount - deleted, deleted);
918 /* if we haven't deleted any messages, we don't need to resort */
919 /* ... except for certain folder formats which need "unsorted"
920 * sort order in order to synchronize folders.
922 * MH and maildir are safe. mbox-style seems to need re-sorting,
923 * at least with the new threading code.
925 if (purge || (ctx->magic != M_MAILDIR && ctx->magic != M_MH)) {
926 /* IMAP does this automatically after handling EXPUNGE */
927 if (ctx->magic != M_IMAP)
929 mx_update_tables (ctx, 1);
930 mutt_sort_headers (ctx, 1); /* rethread from scratch */
938 int mx_sync_mailbox (CONTEXT* ctx, int* index_hint) {
939 int ret = _mx_sync_mailbox (ctx, index_hint);
940 sidebar_set_buffystats (ctx);
945 * dest destintation mailbox
946 * hdr message being copied (required for maildir support, because
947 * the filename depends on the message flags)
949 MESSAGE *mx_open_new_message (CONTEXT * dest, HEADER * hdr, int flags)
954 if (!MX_IDX(dest->magic-1)) {
958 msg = p_new(MESSAGE, 1);
959 msg->magic = dest->magic;
963 msg->flags.flagged = hdr->flagged;
964 msg->flags.replied = hdr->replied;
965 msg->flags.read = hdr->read;
966 msg->received = hdr->received;
969 if (msg->received == 0)
970 time (&msg->received);
972 if (mxfmts[dest->magic-1]->mx_open_new_message(msg, dest, hdr) == 0) {
973 if (msg->magic == M_MBOX && flags & M_ADD_FROM) {
975 if (hdr->env->return_path)
976 p = hdr->env->return_path;
977 else if (hdr->env->sender)
978 p = hdr->env->sender;
983 fprintf (msg->fp, "From %s %s", p ? p->mailbox : NONULL(mod_core.username),
984 ctime (&msg->received));
993 /* check for new mail */
994 int mx_check_mailbox (CONTEXT * ctx, int *index_hint, int lock) {
996 return mutt_check_mailbox_compressed (ctx);
1001 if (MX_IDX(ctx->magic-1) && mxfmts[ctx->magic-1]->mx_check_mailbox)
1002 return (mxfmts[ctx->magic-1]->mx_check_mailbox(ctx, index_hint, lock));
1008 /* return a stream pointer for a message */
1009 MESSAGE *mx_open_message (CONTEXT * ctx, int msgno)
1013 msg = p_new(MESSAGE, 1);
1014 switch (msg->magic = ctx->magic) {
1022 HEADER *cur = ctx->hdrs[msgno];
1023 char path[_POSIX_PATH_MAX];
1025 snprintf (path, sizeof (path), "%s/%s", ctx->path, cur->path);
1027 if ((msg->fp = fopen (path, "r")) == NULL && errno == ENOENT &&
1028 ctx->magic == M_MAILDIR)
1029 msg->fp = maildir_open_find_message (ctx->path, cur->path);
1031 if (msg->fp == NULL) {
1040 if (imap_fetch_message (msg, ctx, msgno) != 0)
1047 if (pop_fetch_message (msg, ctx, msgno) != 0)
1059 /* commit a message to a folder */
1061 int mx_commit_message (MESSAGE * msg, CONTEXT * ctx) {
1062 if (!(msg->write && ctx->append)) {
1065 if (!ctx || !MX_IDX(ctx->magic-1) || !mxfmts[ctx->magic-1]->mx_commit_message)
1067 return (mxfmts[ctx->magic-1]->mx_commit_message (msg, ctx));
1070 /* close a pointer to a message */
1071 int mx_close_message (MESSAGE ** msg)
1075 if ((*msg)->magic == M_MH || (*msg)->magic == M_MAILDIR
1076 || (*msg)->magic == M_IMAP || (*msg)->magic == M_POP)
1078 r = m_fclose(&(*msg)->fp);
1084 unlink ((*msg)->path);
1085 p_delete(&(*msg)->path);
1092 void mx_alloc_memory (CONTEXT * ctx)
1096 p_realloc(&ctx->hdrs, ctx->hdrmax);
1097 p_realloc(&ctx->v2r, ctx->hdrmax);
1098 p_clear(ctx->hdrs + ctx->msgcount, ctx->hdrmax - ctx->msgcount);
1099 p_clear(ctx->v2r + ctx->msgcount, ctx->hdrmax - ctx->msgcount);
1102 /* this routine is called to update the counts in the context structure for
1103 * the last message header parsed.
1105 void mx_update_context (CONTEXT * ctx, int new_messages)
1110 for (msgno = ctx->msgcount - new_messages; msgno < ctx->msgcount; msgno++) {
1111 h = ctx->hdrs[msgno];
1113 /* NOTE: this _must_ be done before the check for mailcap! */
1114 h->security = crypt_query (h->content);
1116 if (!ctx->pattern) {
1117 ctx->v2r[ctx->vcount] = msgno;
1118 h->virtual = ctx->vcount++;
1124 if (h->env->supersedes) {
1128 ctx->id_hash = mutt_make_id_hash (ctx);
1130 h2 = hash_find (ctx->id_hash, h->env->supersedes);
1132 /* p_delete(&h->env->supersedes); should I ? */
1135 if (!ctx->counting && mod_score.enable)
1136 mutt_score_message (ctx, h2, 1);
1140 /* add this message to the hash tables */
1141 if (ctx->id_hash && h->env->message_id)
1142 hash_insert (ctx->id_hash, h->env->message_id, h);
1143 if (!ctx->counting) {
1144 if (ctx->subj_hash && h->env->real_subj)
1145 hash_insert (ctx->subj_hash, h->env->real_subj, h);
1147 if (mod_score.enable)
1148 mutt_score_message (ctx, h, 0);
1163 /* update sidebar count */
1164 sidebar_set_buffystats (ctx);
1169 * 1 if the specified mailbox contains 0 messages.
1170 * 0 if the mailbox contains messages
1173 int mx_check_empty (const char *path)
1176 if ((i = mx_get_idx (path)) >= 0 && mxfmts[i]->mx_check_empty)
1177 return (mxfmts[i]->mx_check_empty(path));
1182 int mx_acl_check(CONTEXT *ctx, int flag)
1184 if (!mxfmts[ctx->magic-1]->mx_acl_check)
1186 return mxfmts[ctx->magic-1]->mx_acl_check(ctx,flag);
1189 void mutt_parse_mime_message (CONTEXT * ctx, HEADER * cur)
1195 if (cur->content->type != TYPEMESSAGE
1196 && cur->content->type != TYPEMULTIPART)
1197 break; /* nothing to do */
1199 if (cur->content->parts)
1200 break; /* The message was parsed earlier. */
1202 if ((msg = mx_open_message (ctx, cur->msgno))) {
1203 mutt_parse_part (msg->fp, cur->content);
1205 cur->security = crypt_query (cur->content);
1207 mx_close_message (&msg);
1210 mutt_count_body_parts (cur, flags | M_PARTS_RECOUNT);