diff -brc mutt-0.58.1/Makefile.in mutt-0.58.1.1/Makefile.in
*** mutt-0.58.1/Makefile.in	Sun Jan 19 21:57:56 1997
--- mutt-0.58.1.1/Makefile.in	Mon Jan 20 11:28:02 1997
***************
*** 31,37 ****
  	parse.o pattern.o pgp.o pop.o postpone.o print.o \
  	resize.o \
  	recvattach.o \
! 	rfc1522.o \
  	rfc822.o send.o sendattach.o sendlib.o signal.o \
  	snprintf.o \
  	sort.o \
--- 31,37 ----
  	parse.o pattern.o pgp.o pop.o postpone.o print.o \
  	resize.o \
  	recvattach.o \
! 	rfc1522.o rfc1321.o rfc1864.o \
  	rfc822.o send.o sendattach.o sendlib.o signal.o \
  	snprintf.o \
  	sort.o \
diff -brc mutt-0.58.1/handler.c mutt-0.58.1.1/handler.c
*** mutt-0.58.1/handler.c	Sun Jan 12 19:14:48 1997
--- mutt-0.58.1.1/handler.c	Mon Jan 20 13:18:30 1997
***************
*** 21,26 ****
--- 21,27 ----
  #include <stdlib.h>
  #include <string.h>
  #include <unistd.h>
+ #include "rfc1864.h"
  
  typedef void handler (BODY *, STATE *);
  typedef handler *handler_t;
***************
*** 367,374 ****
--- 368,428 ----
    }
  }
  
+ #define MD5_FIRST 0
+ #define MD5_CHECKING 1
+ #define MD5_MATCHED 2
+ #define MD5_FAILED 3
+ 
+ void md5_handler (BODY *a, STATE *s)
+ {
+     STATE *md5_state;
+     char tfile[_POSIX_PATH_MAX] = "";
+     char *checked_md5;
+     char buffer[STRING];
+     FILE *fp;
+ 
+     if (s->displaying) {
+       if (a->md5_check == MD5_CHECKING) {
+       mutt_mktemp(tfile);
+       md5_state = mutt_new_state();
+       md5_state->fpin = s->fpin;
+       fp = fopen(tfile,"w");
+       md5_state->fpout = fp;
+       md5_state->displaying = FALSE;
+ 
+       dprint(1,(debugfile,"md5_handler: decoding body\n"));
+       mutt_body_handler(a, md5_state);
+       fclose(fp);
+       fp = fopen(tfile,"r");
+       checked_md5 = rfc1864_md5_file(fp);
+       fclose(fp);
+       unlink(tfile);
+       mutt_free_state(&md5_state);
+ 
+       if (!strcmp(checked_md5,a->md5))
+         a->md5_check = MD5_MATCHED;
+        else
+         a->md5_check = MD5_FAILED;
+       }
+ 
+       if (a->md5_check == MD5_MATCHED)
+         snprintf(buffer,sizeof(buffer),
+                "[ MD5 Checksum Matches: %s ]\n\n",a->md5);
+        else
+         snprintf(buffer,sizeof(buffer),
+                "[ MD5 Checksum Match Fails, Contents May Have Shifted ]\n\n");
+       state_puts(buffer, s);
+     }
+     mutt_body_handler(a,s);
+ }
+ 
  handler_t get_handler (BODY *a)
  {
+   /* Must check md5 handler first, since it is a superset */
+   if (a->md5 && a->md5_check == MD5_FIRST) {
+     a->md5_check = MD5_CHECKING;
+     return md5_handler;
+   }
    if (a->type == TYPETEXT)
    {
      if (strcasecmp("plain", a->subtype) == 0)
***************
*** 443,452 ****
    return (unsupported_handler);
  }
  
  void mutt_body_handler (BODY *a, STATE *s)
  {
!   handler_t h = get_handler (a);
  
    fseek (s->fpin, a->offset, 0);
    h (a, s);
  }
--- 497,523 ----
    return (unsupported_handler);
  }
  
+ static int handler_depth = 0;
+ 
  void mutt_body_handler (BODY *a, STATE *s)
  {
!   handler_t h;
      
+   handler_depth++;
+   if (handler_depth <= 1) {
+     BODY *parts= a->parts;
+     a->md5_check = 0;
+     if (a->parts) {
+       parts->md5_check = 0;
+       while (parts->next != NULL) {
+         parts = parts->next;
+         parts->md5_check = 0;
+       }
+     }
+   }
+   h = get_handler(a);
+ 
    fseek (s->fpin, a->offset, 0);
    h (a, s);
+   handler_depth--;
  }
diff -brc mutt-0.58.1/init.c mutt-0.58.1.1/init.c
*** mutt-0.58.1/init.c	Fri Jan 17 15:15:17 1997
--- mutt-0.58.1.1/init.c	Mon Jan 20 11:40:08 1997
***************
*** 66,71 ****
--- 66,72 ----
    { "confirmcreate",   DT_BOOL, OPTCONFIRMCREATE, NULL },
    { "confirmfiles",    DT_BOOL,  OPTCONFIRMFILES,  NULL },
    { "confirmfolders",  DT_BOOL, OPTCONFIRMFOLDERS, NULL },
+   { "content_md5",     DT_BOOL, OPTCONTENTMD5, NULL }, 
    { "domain",          DT_STR,  0, Fqdn },
  #ifdef USE_DSN
    { "dsn_notify",      DT_STR, 0, DsnNotify },
diff -brc mutt-0.58.1/lib.c mutt-0.58.1.1/lib.c
*** mutt-0.58.1/lib.c	Thu Jan 16 19:34:11 1997
--- mutt-0.58.1.1/lib.c	Mon Jan 20 11:28:02 1997
***************
*** 80,85 ****
--- 80,86 ----
      safe_free((void **)&b->content);
      safe_free((void **)&b->subtype);
      safe_free((void **)&b->description);
+     safe_free((void **)&b->md5);
  
      if (b->parts) mutt_free_body(&b->parts);
  
diff -brc mutt-0.58.1/main.c mutt-0.58.1.1/main.c
*** mutt-0.58.1/main.c	Sun Jan 19 18:47:30 1997
--- mutt-0.58.1.1/main.c	Mon Jan 20 13:19:08 1997
***************
*** 181,186 ****
--- 181,188 ----
    puts ("  -HAVE_COLOR");
  #endif
  
+   printf ("PATCH=\"%s\"\n", PATCH_CONTENTMD5);
+ 
    printf ("SENDMAIL=\"%s\"\n", SENDMAIL);
    printf ("MAILPATH=\"%s\"\n", MAILPATH);
    printf ("SYSMUTTRC=\"%s\"\n", SYSMUTTRC);
diff -brc mutt-0.58.1/muttlib.h mutt-0.58.1.1/muttlib.h
*** mutt-0.58.1/muttlib.h	Fri Jan 17 14:34:47 1997
--- mutt-0.58.1.1/muttlib.h	Mon Jan 20 11:50:48 1997
***************
*** 24,29 ****
--- 24,31 ----
  #include <limits.h>
  #include <stdarg.h>
  
+ #define PATCH_CONTENTMD5 "Content MD5 0.58.1"
+ 
  #define TRUE 1
  #define FALSE 0
  
***************
*** 270,275 ****
--- 272,278 ----
    OPTVERIFYSIG, /* pseudo option controlled by M_VERIFYSIG */
    OPTBATCHMODE,  /* pseudo option when sending in batch mode */
    OPTNEEDREDRAW, /* pseudo option to notify caller of a submenu */
+   OPTCONTENTMD5,
    OPTMAX
  };
  
***************
*** 360,365 ****
--- 363,370 ----
    char *subtype;                /* content-type subtype */
    PARAMETER *parameter;         /* parameters of the content-type */
    char *description;            /* content-description */
+   char *md5;                    /* content-md5 header (rfc1864) */
+   int md5_check;
    long hdr_offset;              /* offset in stream where the headers begin.
  				 * this info is used when invoking metamail,
  				 * where we need to send the headers of the
***************
*** 545,550 ****
--- 550,556 ----
  int mutt_check_key (const char *);
  int mutt_check_menu (const char *);
  int mutt_check_mime_type (const char *);
+ int mutt_check_encoding (const char *);
  int mutt_check_month (const char *);
  int mutt_check_pgp (HEADER *h);
  int mutt_compat_charset (const char *);
***************
*** 572,577 ****
--- 578,585 ----
  int mutt_write_mime_header (BODY *, FILE *);
  int mutt_write_rfc822_header (FILE *, ENVELOPE *, BODY *, int);
  int mutt_yesorno (const char *, int);
+ 
+ void mutt_content_md5(BODY *);
  
  time_t mutt_gmsecs (int, int, int, int, int, int);
  time_t mutt_gmtime (HEADER *);
diff -brc mutt-0.58.1/parse.c mutt-0.58.1.1/parse.c
*** mutt-0.58.1/parse.c	Wed Jan 15 19:28:58 1997
--- mutt-0.58.1.1/parse.c	Mon Jan 20 11:43:26 1997
***************
*** 354,359 ****
--- 354,363 ----
  	{
  	  if (!p->description) p->description = safe_strdup(c);
  	}
+ 	else if (!strncasecmp ("ontent-md5", line+1, sizeof("ontent-md5")-1))
+ 	{
+ 	  if (!p->md5) p->md5 = safe_strdup(c);
+ 	}
  	break;
      }
    }
***************
*** 844,849 ****
--- 848,858 ----
  	  else if (strncasecmp(line+8, "length:", 7) == 0)
  	  {
  	    content_length = atoi(p);
+ 	    matched = 1;
+ 	  }
+ 	  else if (strncasecmp(line+8, "md5:", 4) == 0)
+ 	  {
+ 	    if (hdr) hdr->content->md5 = safe_strdup(p);
  	    matched = 1;
  	  }
  	}
diff -brc mutt-0.58.1/sendlib.c mutt-0.58.1.1/sendlib.c
*** mutt-0.58.1/sendlib.c	Thu Jan 16 20:16:43 1997
--- mutt-0.58.1.1/sendlib.c	Mon Jan 20 11:28:12 1997
***************
*** 304,309 ****
--- 304,312 ----
      }
      fputc('\n', f);
    }
+   if (a->md5)
+     fprintf(f,"Content-Md5: %s\n", a->md5);
+ 
    /* Do NOT add the terminator here!!! */
    return 0;
  }
***************
*** 670,675 ****
--- 673,681 ----
      att->encoding = option(OPTALLOW8BIT) ? ENC8BIT : ENCQUOTEDPRINTABLE;
    else
      att->encoding = ENC7BIT;
+ 
+   if (option(OPTCONTENTMD5))
+     mutt_content_md5(att);
  
  #ifdef _PGPPATH
    /*
