--- uip/mhshowsbr.c- Wed Apr 5 20:11:50 2000 +++ uip/mhshowsbr.c Sun Nov 10 21:13:48 2002 @@ -33,6 +33,8 @@ extern int errno; extern int debugsw; +extern char *types[NTYPES + 1]; +extern int ntype; int pausesw = 1; int serialsw = 0; @@ -687,6 +689,71 @@ return NOTOK; } +/* + * sort a msg's alternate parts according to + * their order of appearance in the types array + * given on the cmd line (better to use the list + * in mhn.defaults, but what the heck) + */ +static void +sort_alt_parts (struct multipart *m) +{ + struct part **hd, *p, *next, *prev; + char buffer[BUFSIZ], **t; + CI ci; + + if (ntype == 0) + return; + + if (debugsw) { + fputs("types are:\n", stderr); + for (t = types; *t; t++) + fprintf(stderr, "\t%s\n", *t); + fputs("order was:\n", stderr); + for (p = m->mp_parts; p; p = p->mp_next) { + ci = &p->mp_part->c_ctinfo; + fprintf(stderr, "\t%p -> %s/%s\n", p, ci->ci_type, ci->ci_subtype); + } + } + + hd = &m->mp_parts; + t = types; + while (*t && *hd) { + /* drag all msg parts of type *t to front of list */ + prev = NULL; + for (p = *hd; p; prev = p, p = p->mp_next) { + ci = &p->mp_part->c_ctinfo; + snprintf (buffer, sizeof(buffer), + "%s/%s", ci->ci_type, ci->ci_subtype); + if (strcasecmp (*t, ci->ci_type) && strcasecmp (*t, buffer)) + continue; + + /* move p to front of list */ + if (prev != NULL) { + /* remove p */ + prev->mp_next = p->mp_next; + + /* insert p at head */ + next = *hd; + *hd = p; + (*hd)->mp_next = next; + } + + /* skip past new head, as we never want to move it again */ + hd = &(*hd)->mp_next; + } + + t++; + } + + if (debugsw) { + fputs("order is:\n", stderr); + for (p = m->mp_parts; p; p = p->mp_next) { + ci = &p->mp_part->c_ctinfo; + fprintf(stderr, "\t%p -> %s/%s\n", p, ci->ci_type, ci->ci_subtype); + } + } +} /* * show message body of subtypes of multipart that @@ -708,6 +775,7 @@ if (ct->c_subtype == MULTI_PARALLEL) { nowserial = serialsw; } else if (ct->c_subtype == MULTI_ALTERNATE) { + sort_alt_parts(m); nowalternate = 1; alternating = 1; nowserial = serial;