$OpenBSD: patch-uip_mhparse_c,v 1.3 2013/11/14 15:04:02 bentley Exp $

This is a merge of two upstream commits:

Fix decoding of attachments on BE arches
http://git.savannah.gnu.org/cgit/nmh.git/commit/?id=436e6b477fa6dabe40404c84334e148b49682708

Fix for mhshow-charset- directives in .mh_profile being broken
http://git.savannah.gnu.org/cgit/nmh.git/commit/?id=b5f46f4ba364af010a7ef5afb20b667fcbe9b136


--- uip/mhparse.c.orig	Sun Jun  3 15:37:11 2012
+++ uip/mhparse.c	Wed Nov  6 22:01:10 2013
@@ -48,11 +48,7 @@ struct k2v SubText[] = {
     { NULL,       TEXT_UNKNOWN }    /* this one must be last! */
 };
 
-struct k2v Charset[] = {
-    { "us-ascii",   CHARSET_USASCII },
-    { "iso-8859-1", CHARSET_LATIN },
-    { NULL,         CHARSET_UNKNOWN }  /* this one must be last! */
-};
+/* Charset[] removed -- yozo.  Mon Oct  8 01:03:41 JST 2012 */
 
 /*
  * Structures for MULTIPART messages
@@ -1079,14 +1075,8 @@ InitText (CT ct)
 
     /* check if content specified a character set */
     if (*ap) {
-	/* match character set or set to CHARSET_UNKNOWN */
-	for (kv = Charset; kv->kv_key; kv++) {
-	    if (!mh_strcasecmp (*ep, kv->kv_key)) {
-		chset = *ep;
-		break;
-	    }
-	}
-	t->tx_charset = kv->kv_value;
+	chset = *ep;
+	t->tx_charset = CHARSET_SPECIFIED;
     } else {
 	t->tx_charset = CHARSET_UNSPECIFIED;
     }
@@ -1737,10 +1727,15 @@ openBase64 (CT ct, char **file)
     CE ce;
     MD5_CTX mdContext;
 
+    /* the decoder works on the least-significant three bytes of the bits integer,
+       but their position in memory depend on both endian-ness and size of 
+       long int... for little-endian architectures the size is irrelevant, for
+       big-endian archs it's crucial... ideally we'd adopt posix and use a64l instead
+       of this mess. */
     b  = (unsigned char *) &bits;
-    b1 = &b[endian > 0 ? 1 : 2];
-    b2 = &b[endian > 0 ? 2 : 1];
-    b3 = &b[endian > 0 ? 3 : 0];
+    b1 = &b[endian > 0 ? sizeof(bits)==8?5:1 : 2];
+    b2 = &b[endian > 0 ? sizeof(bits)==8?6:2 : 1];
+    b3 = &b[endian > 0 ? sizeof(bits)==8?7:3 : 0];
 
     ce = ct->c_cefile;
     if (ce->ce_fp) {
@@ -2825,10 +2820,16 @@ readDigest (CT ct, char *cp)
     unsigned char *dp, value, *ep;
     unsigned char *b, *b1, *b2, *b3;
 
-    b  = (unsigned char *) &bits,
-    b1 = &b[endian > 0 ? 1 : 2],
-    b2 = &b[endian > 0 ? 2 : 1],
-    b3 = &b[endian > 0 ? 3 : 0];
+    /* the decoder works on the least-significant three bytes of the bits integer,
+       but their position in memory depend on both endian-ness and size of 
+       long int... for little-endian architectures the size is irrelevant, for
+       big-endian archs it's crucial... ideally we'd adopt posix and use a64l instead
+       of this mess. */
+    b  = (unsigned char *) &bits;
+    b1 = &b[endian > 0 ? sizeof(bits)==8?5:1 : 2];
+    b2 = &b[endian > 0 ? sizeof(bits)==8?6:2 : 1];
+    b3 = &b[endian > 0 ? sizeof(bits)==8?7:3 : 0];
+
     bitno = 18;
     bits = 0L;
     skip = 0;
