diff -pruN mutt-1.3.20.orig/thread.c mutt-1.3.20/thread.c --- mutt-1.3.20.orig/thread.c Thu Apr 26 00:06:58 2001 +++ mutt-1.3.20/thread.c Thu Oct 11 17:00:59 2001 @@ -999,3 +999,76 @@ int mutt_msgno_in_thread (HEADER *cur) } /* not reached */ } + +static void clean_references (HEADER *brk, HEADER *cur) +{ + HEADER *p; + LIST *ref = NULL; + int done = 0; + + for (; cur; cur = cur->next, done = 0) + { + /* parse subthread recursively */ + clean_references (brk, cur->child); + + /* Looking for the first bad reference according to the new threading. + * Optimal since Mutt stores the references in reverse order, and the + * first loop should match immediatly for mails respecting RFC2822. */ + for (p = brk; !done && p; p = p->parent) + for (ref = cur->env->references; ref; ref = ref->next) + if (!mutt_strcasecmp (ref->data, p->env->message_id)) + { + done = 1; + break; + } + + if (done) + { + /* clearing the References: header from obsolete Message-Id(s) */ + mutt_free_list (&ref->next); + + cur->refs_changed = cur->changed = 1; + } + } +} + +void mutt_break_thread (HEADER *hdr) +{ + mutt_free_list (&hdr->env->in_reply_to); + mutt_free_list (&hdr->env->references); + hdr->irt_changed = hdr->refs_changed = hdr->changed = 1; + + clean_references (hdr, hdr->child); +} + +static int link_threads (HEADER *parent, HEADER *child, CONTEXT *ctx) +{ + if (child == parent) + return 0; + + mutt_break_thread (child); + + child->env->in_reply_to = mutt_new_list (); + child->env->in_reply_to->data = safe_strdup (parent->env->message_id); + + mutt_set_flag (ctx, child, M_TAG, 0); + + child->irt_changed = child->changed = 1; + return 1; +} + +int mutt_link_threads (HEADER *cur, HEADER *last, CONTEXT *ctx) +{ + int i, changed = 0; + + if (!last) + { + for (i = 0; i < ctx->vcount; i++) + if (ctx->hdrs[Context->v2r[i]]->tagged) + changed |= link_threads (cur, ctx->hdrs[Context->v2r[i]], ctx); + } + else + changed = link_threads (cur, last, ctx); + + return changed; +} diff -pruN mutt-1.3.20.orig/OPS mutt-1.3.20/OPS --- mutt-1.3.20.orig/OPS Sat Jan 27 14:07:59 2001 +++ mutt-1.3.20/OPS Thu Oct 11 17:00:59 2001 @@ -94,6 +94,7 @@ OP_LAST_ENTRY "move to the last entry" OP_LIST_REPLY "reply to specified mailing list" OP_MACRO "execute a macro" OP_MAIL "compose a new mail message" +OP_MAIN_BREAK_THREAD "break the thread in two" OP_MAIN_CHANGE_FOLDER "open a different folder" OP_MAIN_CHANGE_FOLDER_READONLY "open a different folder in read only mode" OP_MAIN_CLEAR_FLAG "clear a status flag from a message" @@ -103,6 +104,7 @@ OP_MAIN_FETCH_MAIL "retrieve mail from P OP_MAIN_FIRST_MESSAGE "move to the first message" OP_MAIN_LAST_MESSAGE "move to the last message" OP_MAIN_LIMIT "show only messages matching a pattern" +OP_MAIN_LINK_THREADS "link tagged message to the current one" OP_MAIN_NEXT_NEW "jump to the next new message" OP_MAIN_NEXT_SUBTHREAD "jump to the next subthread" OP_MAIN_NEXT_THREAD "jump to the next thread" diff -pruN mutt-1.3.20.orig/copy.c mutt-1.3.20/copy.c --- mutt-1.3.20.orig/copy.c Fri May 11 16:04:24 2001 +++ mutt-1.3.20/copy.c Thu Oct 11 17:00:59 2001 @@ -91,6 +91,13 @@ mutt_copy_hdr (FILE *in, FILE *out, long (ascii_strncasecmp ("Content-Length:", buf, 15) == 0 || ascii_strncasecmp ("Lines:", buf, 6) == 0)) continue; + if ((flags & CH_UPDATE_REFS) && + ascii_strncasecmp ("References:", buf, 11) == 0) + continue; + if ((flags & CH_UPDATE_IRT) && + (ascii_strncasecmp ("In-Reply-To:", buf, 12) == 0 || + ascii_strncasecmp ("X-Mutt-Rethreaded:", buf, 18) == 0)) + continue; ignore = 0; } @@ -167,6 +174,13 @@ mutt_copy_hdr (FILE *in, FILE *out, long ascii_strncasecmp ("type:", buf + 8, 5) == 0)) || ascii_strncasecmp ("mime-version:", buf, 13) == 0)) continue; + if ((flags & CH_UPDATE_REFS) && + ascii_strncasecmp ("References:", buf, 11) == 0) + continue; + if ((flags & CH_UPDATE_IRT) && + (ascii_strncasecmp ("In-Reply-To:", buf, 12) == 0 || + ascii_strncasecmp ("X-Mutt-Rethreaded:", buf, 18) == 0)) + continue; /* Find x -- the array entry where this header is to be saved */ if (flags & CH_REORDER) @@ -276,6 +290,8 @@ mutt_copy_hdr (FILE *in, FILE *out, long CH_UPDATE_LEN write new Content-Length: and Lines: CH_XMIT ignore Lines: and Content-Length: CH_WEED do header weeding + CH_UPDATE_IRT update the In-Reply-To: header + CH_UPDATE_REFS update the References: header prefix string to use if CH_PREFIX is set @@ -285,6 +301,9 @@ int mutt_copy_header (FILE *in, HEADER *h, FILE *out, int flags, const char *prefix) { char buffer[SHORT_STRING]; + + flags |= (h->irt_changed ? CH_UPDATE_IRT : 0) + | (h->refs_changed ? CH_UPDATE_REFS : 0); if (mutt_copy_hdr (in, out, h->offset, h->content->offset, flags, prefix) == -1) return (-1); @@ -309,6 +328,49 @@ mutt_copy_header (FILE *in, HEADER *h, F { if ((flags & CH_NOSTATUS) == 0) { + if (h->irt_changed && h->env->in_reply_to) + { + LIST *listp = h->env->in_reply_to; + + if (fputs ("In-Reply-To: ", out) == EOF) + return (-1); + + for (; listp; listp = listp->next) + if ((fputs (listp->data, out) == EOF) || (fputc (' ', out) == EOF)) + return (-1); + + if (fputs ("\nX-Mutt-Rethreaded: Yes\n", out) == EOF) + return (-1); + } + + if (h->refs_changed && h->env->references) + { + LIST *listp = h->env->references, *refs = NULL, *t; + + if (fputs ("References: ", out) == EOF) + return (-1); + + /* Mutt stores references in reverse order, thus we create + * a reordered refs list that we can put in the headers */ + for (; listp; listp = listp->next, refs = t) + { + t = (LIST *)safe_malloc (sizeof (LIST)); + t->data = listp->data; + t->next = refs; + } + + for (; refs; refs = refs->next) + if ((fputs (refs->data, out) == EOF) || (fputc (' ', out) == EOF)) + return (-1); + + /* clearing refs from memory */ + for (t = refs; refs; refs = t->next, t = refs) + safe_free ((void **)&refs); + + if (fputc ('\n', out) == EOF) + return (-1); + } + if (h->old || h->read) { if (fputs ("Status: ", out) == EOF) diff -pruN mutt-1.3.20.orig/curs_main.c mutt-1.3.20/curs_main.c --- mutt-1.3.20.orig/curs_main.c Thu Jul 19 16:49:51 2001 +++ mutt-1.3.20/curs_main.c Thu Oct 11 17:00:59 2001 @@ -854,6 +854,11 @@ int mutt_index_menu (void) else { mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged); + + Context->last_tag = CURHDR->tagged ? CURHDR : + ((Context->last_tag == CURHDR && !CURHDR->tagged) + ? NULL : Context->last_tag); + menu->redraw = REDRAW_STATUS; if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) { @@ -1074,6 +1079,78 @@ int mutt_index_menu (void) } done = 1; } + break; + + case OP_MAIN_BREAK_THREAD: + + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_READONLY; + + if (Context->magic != M_MBOX && Context->magic != M_MMDF) + { + mutt_error ("break-thread: only for mbox and mmdf mailbox formats"); + break; + } + + { + HEADER *oldcur = CURHDR; + + mutt_break_thread (CURHDR); + mutt_sort_headers (Context, 1); + menu->current = oldcur->virtual; + } + + Context->changed = 1; + mutt_message _("Thread broken"); + + if (menu->menu == MENU_PAGER) + { + op = OP_DISPLAY_MESSAGE; + continue; + } + else + menu->redraw |= REDRAW_INDEX; + + break; + + case OP_MAIN_LINK_THREADS: + + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_READONLY; + + if (Context->magic != M_MBOX && Context->magic != M_MMDF) + mutt_error ("link-threads: only for mbox and mmdf mailbox formats"); + else if (!CURHDR->env->message_id) + mutt_error _("No Message-ID: header available to link thread"); + else if (!tag && (!Context->last_tag || !Context->last_tag->tagged)) + mutt_error _("First, please tag a message to be linked here"); + else + { + HEADER *oldcur = CURHDR; + + if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag, + Context)) + { + mutt_sort_headers (Context, 1); + menu->current = oldcur->virtual; + + Context->changed = 1; + mutt_message _("Threads linked"); + } + else + mutt_error _("No thread linked"); + } + + if (menu->menu == MENU_PAGER) + { + op = OP_DISPLAY_MESSAGE; + continue; + } + else + menu->redraw |= REDRAW_STATUS | REDRAW_INDEX; + break; case OP_EDIT_TYPE: diff -pruN mutt-1.3.20.orig/doc/manual.sgml.head mutt-1.3.20/doc/manual.sgml.head --- mutt-1.3.20.orig/doc/manual.sgml.head Mon Jul 2 16:18:40 2001 +++ mutt-1.3.20/doc/manual.sgml.head Thu Oct 11 17:00:59 2001 @@ -2087,8 +2087,40 @@ used a threaded news client, this is the with large volume mailing lists easier because you can easily delete uninteresting threads and quickly find topics of value. +Editing threads +

+Mutt has the ability to dynamically restructure threads that are broken +either by misconfigured software or bad behaviour from some +correspondents. This allows to clean your mailboxes (Linking threads +

+ +Some mailers tend to "forget" to correctly set the "In-Reply-To:" and +"References:" headers when replying to a message. This results in broken +discussions because Mutt has not enough information to guess the correct +threading. +You can fix this by tagging the reply to a mail, then go onto this mail +and use the ``link-threads'' function (bound to & by default). The +reply will then be connected to its "parent" message. + +You can also connect multiple childs at once, tagging them and using the +tag-prefix command (';') or the auto_tag option. + +Breaking threads +

+ +On mailing lists, some people are in the bad habit of starting a new +discussion by hitting "reply" to any message from the list and changing +the subject to a totally unrelated one. +You can fix such threads by using the ``break-thread'' function (bound +by default to #), which will turn the subthread starting from the +current message into a whole different thread. + Delivery Status Notification (DSN) Support

+ RFC1894 defines a set of MIME content types for relaying information about the status of electronic mail messages. These can be thought of as ``return receipts.'' Berkeley sendmail 8.8.x currently has some command diff -pruN mutt-1.3.20.orig/functions.h mutt-1.3.20/functions.h --- mutt-1.3.20.orig/functions.h Tue Feb 13 16:00:26 2001 +++ mutt-1.3.20/functions.h Thu Oct 11 17:00:59 2001 @@ -66,6 +66,7 @@ struct binding_t OpGeneric[] = { struct binding_t OpMain[] = { { "create-alias", OP_CREATE_ALIAS, "a" }, { "bounce-message", OP_BOUNCE_MESSAGE, "b" }, + { "break-thread", OP_MAIN_BREAK_THREAD, "#" }, { "change-folder", OP_MAIN_CHANGE_FOLDER, "c" }, { "change-folder-readonly", OP_MAIN_CHANGE_FOLDER_READONLY, "\033c" }, { "collapse-thread", OP_MAIN_COLLAPSE_THREAD, "\033v" }, @@ -92,6 +93,7 @@ struct binding_t OpMain[] = { { "next-undeleted", OP_MAIN_NEXT_UNDELETED, "j" }, { "previous-undeleted", OP_MAIN_PREV_UNDELETED, "k" }, { "limit", OP_MAIN_LIMIT, "l" }, + { "link-threads", OP_MAIN_LINK_THREADS, "&" }, { "list-reply", OP_LIST_REPLY, "L" }, { "mail", OP_MAIL, "m" }, { "toggle-new", OP_TOGGLE_NEW, "N" }, @@ -150,6 +152,7 @@ struct binding_t OpMain[] = { }; struct binding_t OpPager[] = { + { "break-thread", OP_MAIN_BREAK_THREAD, "#" }, { "create-alias", OP_CREATE_ALIAS, "a" }, { "bounce-message", OP_BOUNCE_MESSAGE, "b" }, { "change-folder", OP_MAIN_CHANGE_FOLDER, "c" }, @@ -172,6 +175,7 @@ struct binding_t OpPager[] = { { "next-entry", OP_NEXT_ENTRY, "J" }, { "previous-undeleted",OP_MAIN_PREV_UNDELETED, "k" }, { "previous-entry", OP_PREV_ENTRY, "K" }, + { "link-threads", OP_MAIN_LINK_THREADS, "&" }, { "list-reply", OP_LIST_REPLY, "L" }, { "redraw-screen", OP_REDRAW, "\014" }, { "mail", OP_MAIL, "m" }, diff -pruN mutt-1.3.20.orig/mutt.h mutt-1.3.20/mutt.h --- mutt-1.3.20.orig/mutt.h Fri Jun 29 12:05:50 2001 +++ mutt-1.3.20/mutt.h Thu Oct 11 17:00:59 2001 @@ -81,6 +81,8 @@ #define CH_NOLEN (1<<12) /* don't write Content-Length: and Lines: */ #define CH_WEED_DELIVERED (1<<13) /* weed eventual Delivered-To headers */ #define CH_FORCE_FROM (1<<14) /* give CH_FROM precedence over CH_WEED? */ +#define CH_UPDATE_IRT (1<<15) /* update In-Reply-To: */ +#define CH_UPDATE_REFS (1<<16) /* update References: */ /* flags for mutt_enter_string() */ #define M_ALIAS 1 /* do alias "completion" by calling up the alias-menu */ @@ -616,6 +618,8 @@ typedef struct header unsigned int display_subject : 1; /* used for threading */ unsigned int fake_thread : 1; /* no ref matched, but subject did */ unsigned int threaded : 1; /* message has been threaded */ + unsigned int irt_changed : 1; /* In-Reply-To changed to link/break threads */ + unsigned int refs_changed : 1; /* References changed to break thread */ unsigned int recip_valid : 1; /* is_recipient is valid */ unsigned int active : 1; /* message is not to be removed */ @@ -703,6 +707,7 @@ typedef struct pattern_t *limit_pattern; /* compiled limit pattern */ HEADER **hdrs; HEADER *tree; /* top of thread tree */ + HEADER *last_tag; /* last tagged msg. used to link threads */ HASH *id_hash; /* hash table by msg id */ HASH *subj_hash; /* hash table by subject */ int *v2r; /* mapping from virtual to real msgno */ diff -pruN mutt-1.3.20.orig/mx.c mutt-1.3.20/mx.c --- mutt-1.3.20.orig/mx.c Wed Jun 27 12:09:24 2001 +++ mutt-1.3.20/mx.c Thu Oct 11 17:00:59 2001 @@ -1155,6 +1155,8 @@ int mx_sync_mailbox (CONTEXT *ctx, int * ctx->deleted = 0; } } + else if (ctx->last_tag && ctx->last_tag->deleted) + ctx->last_tag = NULL; /* reset last tagged msg now useless */ } /* really only for IMAP - imap_sync_mailbox results in a call to diff -pruN mutt-1.3.20.orig/pager.c mutt-1.3.20/pager.c --- mutt-1.3.20.orig/pager.c Thu May 17 20:37:01 2001 +++ mutt-1.3.20/pager.c Thu Oct 11 17:00:59 2001 @@ -2352,6 +2352,11 @@ mutt_pager (const char *banner, const ch case OP_TAG: CHECK_MODE(IsHeader (extra)); mutt_set_flag (Context, extra->hdr, M_TAG, !extra->hdr->tagged); + + Context->last_tag = extra->hdr->tagged ? extra->hdr : + ((Context->last_tag == extra->hdr && !extra->hdr->tagged) + ? NULL : Context->last_tag); + redraw = REDRAW_STATUS | REDRAW_INDEX; if (option (OPTRESOLVE)) { diff -pruN mutt-1.3.20.orig/parse.c mutt-1.3.20/parse.c --- mutt-1.3.20.orig/parse.c Mon Apr 30 00:00:19 2001 +++ mutt-1.3.20/parse.c Thu Oct 11 17:00:59 2001 @@ -1163,6 +1163,11 @@ int mutt_parse_rfc822_line (ENVELOPE *e, e->x_label = safe_strdup(p); matched = 1; } + else if (ascii_strcasecmp (line+1, "-Mutt-Rethreaded") == 0) + { + hdr->irt_changed = 1; + matched = 1; + } default: break; diff -pruN mutt-1.3.20.orig/protos.h mutt-1.3.20/protos.h --- mutt-1.3.20.orig/protos.h Tue Jul 3 21:31:16 2001 +++ mutt-1.3.20/protos.h Thu Oct 11 17:00:59 2001 @@ -96,7 +96,7 @@ BODY *mutt_read_mime_header (FILE *, int CONTENT *mutt_get_content_info (const char *fname, BODY *b); -LIST *mutt_make_references(ENVELOPE *e); +LIST *mutt_make_references(HEADER *h); ENVELOPE *mutt_read_rfc822_header (FILE *, HEADER *, short, short); HEADER *mutt_dup_header (HEADER *); @@ -146,6 +146,7 @@ void mutt_block_signals (void); void mutt_block_signals_system (void); void mutt_body_handler (BODY *, STATE *); void mutt_bounce_message (FILE *fp, HEADER *, ADDRESS *); +void mutt_break_thread (HEADER *); void mutt_buffy (char *, size_t); void mutt_canonical_charset (char *, size_t, const char *); void mutt_check_rescore (CONTEXT *); @@ -280,6 +281,7 @@ int mutt_is_list_recipient (int, ADDRESS int mutt_is_subscribed_list (ADDRESS *); int mutt_is_text_type (int, char *); int mutt_is_valid_mailbox (const char *); +int mutt_link_threads (HEADER *, HEADER *, CONTEXT *); int mutt_messages_in_thread (HEADER *); int mutt_msgno_in_thread (HEADER *); int mutt_multi_choice (char *prompt, char *letters); diff -pruN mutt-1.3.20.orig/recvcmd.c mutt-1.3.20/recvcmd.c --- mutt-1.3.20.orig/recvcmd.c Fri May 11 16:53:50 2001 +++ mutt-1.3.20/recvcmd.c Thu Oct 11 17:00:59 2001 @@ -711,7 +711,7 @@ attach_reply_envelope_defaults (ENVELOPE mutt_make_misc_reply_headers (env, Context, curhdr, curenv); if (parent) - env->references = mutt_make_references (curenv); + env->references = mutt_make_references (curhdr); else { LIST **p; diff -pruN mutt-1.3.20.orig/send.c mutt-1.3.20/send.c --- mutt-1.3.20.orig/send.c Wed May 30 18:54:14 2001 +++ mutt-1.3.20/send.c Thu Oct 11 17:00:59 2001 @@ -540,19 +540,19 @@ int mutt_fetch_recips (ENVELOPE *out, EN return 0; } -LIST *mutt_make_references(ENVELOPE *e) +LIST *mutt_make_references(HEADER *h) { LIST *t = NULL, *l = NULL; - if (e->references) - l = mutt_copy_list (e->references); - else - l = mutt_copy_list (e->in_reply_to); + if (h->env->references) + l = mutt_copy_list (h->env->references); + else if (!h->irt_changed) /* don't impose our rethreading to the world ! */ + l = mutt_copy_list (h->env->in_reply_to); - if(e->message_id) + if(h->env->message_id) { t = mutt_new_list(); - t->data = safe_strdup(e->message_id); + t->data = safe_strdup(h->env->message_id); t->next = l; l = t; } @@ -600,13 +600,13 @@ void mutt_make_misc_reply_headers (ENVEL } static void -mutt_make_reference_headers (ENVELOPE *curenv, ENVELOPE *env, CONTEXT *ctx) +mutt_make_reference_headers (HEADER *curhdr, ENVELOPE *env, CONTEXT *ctx) { HEADER *h; LIST **p, **q; int i; - if (!curenv) + if (!curhdr) { env->references = NULL; env->in_reply_to = NULL; @@ -621,7 +621,7 @@ mutt_make_reference_headers (ENVELOPE *c h = ctx->hdrs[ctx->v2r[i]]; if(h->tagged) { - *p = mutt_make_references(h->env); + *p = mutt_make_references(h); if (h->env->message_id) { *q = mutt_new_list (); @@ -632,11 +632,11 @@ mutt_make_reference_headers (ENVELOPE *c } else { - env->references = mutt_make_references (curenv); - if (curenv->message_id) + env->references = mutt_make_references (curhdr); + if (curhdr->env->message_id) { env->in_reply_to = mutt_new_list (); - env->in_reply_to->data = safe_strdup (curenv->message_id); + env->in_reply_to->data = safe_strdup (curhdr->env->message_id); } } } @@ -694,7 +694,7 @@ envelope_defaults (ENVELOPE *env, CONTEX mutt_fix_reply_recipients (env); mutt_make_misc_reply_headers (env, ctx, cur, curenv); - mutt_make_reference_headers (tag ? NULL : curenv, env, ctx); + mutt_make_reference_headers (tag ? NULL : cur, env, ctx); } else if (flags & SENDFORWARD) mutt_make_forward_subject (env, ctx, cur);