diff --git a/libopendkim/dkim-types.h b/libopendkim/dkim-types.h
index b068dda..060f250 100644
--- a/libopendkim/dkim-types.h
+++ b/libopendkim/dkim-types.h
@@ -359,6 +359,7 @@ struct dkim_lib
 	void *			(*dkiml_malloc) (void *closure, size_t nbytes);
 	void			(*dkiml_free) (void *closure, void *p);
 	u_char **		dkiml_senderhdrs;
+	u_char **		dkiml_requiredhdrs;
 	u_char **		dkiml_alwayshdrs;
 	u_char **		dkiml_oversignhdrs;
 	u_char **		dkiml_mbs;
diff --git a/libopendkim/dkim.c b/libopendkim/dkim.c
index 0fe801c..11ba170 100644
--- a/libopendkim/dkim.c
+++ b/libopendkim/dkim.c
@@ -257,7 +257,7 @@ const u_char *dkim_should_not_signhdrs[] =
 };
 
 /* required list of headers to sign */
-const u_char *required_signhdrs[] =
+const u_char *dkim_required_signhdrs[] =
 {
 	"from",
 	NULL
@@ -1078,9 +1078,11 @@ dkim_check_requiredhdrs(DKIM *dkim)
 	int c;
 	size_t len;
 	struct dkim_header *hdr;
+	u_char **required_signhdrs;
 
 	assert(dkim != NULL);
 
+	required_signhdrs = dkim->dkim_libhandle->dkiml_requiredhdrs;
 	for (c = 0; required_signhdrs[c] != NULL; c++)
 	{
 		found = FALSE;
@@ -1432,7 +1434,7 @@ dkim_sig_hdrlistok(DKIM *dkim, u_char *hdrlist)
 	int d;
 	int nh;
 	u_char *p;
-	u_char **ptrs;
+	u_char **ptrs, **required_signhdrs;
 	u_char tmp[DKIM_MAXHEADER + 1];
 
 	assert(dkim != NULL);
@@ -1484,6 +1486,7 @@ dkim_sig_hdrlistok(DKIM *dkim, u_char *hdrlist)
 	}
 
 	/* verify that each required header was represented */
+	required_signhdrs = dkim->dkim_libhandle->dkiml_requiredhdrs;
 	for (d = 0; ; d++)
 	{
 		if (required_signhdrs[d] == NULL)
@@ -4341,6 +4344,7 @@ dkim_init(void *(*caller_mallocf)(void *closure, size_t nbytes),
 	libhandle->dkiml_flags = DKIM_LIBFLAGS_DEFAULT;
 	libhandle->dkiml_timeout = DEFTIMEOUT;
 	libhandle->dkiml_senderhdrs = (u_char **) dkim_default_senderhdrs;
+	libhandle->dkiml_requiredhdrs = (u_char **) dkim_required_signhdrs;
 	libhandle->dkiml_alwayshdrs = NULL;
 #ifdef _FFR_OVERSIGN
 	libhandle->dkiml_oversignhdrs = NULL;
@@ -4450,6 +4454,9 @@ dkim_close(DKIM_LIB *lib)
 	if (lib->dkiml_senderhdrs != (u_char **) dkim_default_senderhdrs)
 		dkim_clobber_array((char **) lib->dkiml_senderhdrs);
 
+	if (lib->dkiml_requiredhdrs != (u_char **) dkim_required_signhdrs)
+		dkim_clobber_array((char **) lib->dkiml_requiredhdrs);
+
 	if (lib->dkiml_alwayshdrs != NULL)
 		dkim_clobber_array((char **) lib->dkiml_alwayshdrs);
 
@@ -4689,6 +4696,36 @@ dkim_options(DKIM_LIB *lib, int op, dkim_opts_t opt, void *ptr, size_t len)
 		}
 		return DKIM_STAT_OK;
 
+	  case DKIM_OPTS_REQUIREDHDRS:
+		if (len != sizeof lib->dkiml_requiredhdrs)
+			return DKIM_STAT_INVALID;
+
+		if (op == DKIM_OP_GETOPT)
+		{
+			memcpy(ptr, &lib->dkiml_requiredhdrs, len);
+		}
+		else if (ptr == NULL)
+		{
+			if (lib->dkiml_requiredhdrs != (u_char **) dkim_required_signhdrs)
+				dkim_clobber_array((char **) lib->dkiml_requiredhdrs);
+
+			lib->dkiml_requiredhdrs = (u_char **) dkim_required_signhdrs;
+		}
+		else
+		{
+			const char **tmp;
+
+			tmp = dkim_copy_array(ptr);
+			if (tmp == NULL)
+				return DKIM_STAT_NORESOURCE;
+
+			if (lib->dkiml_requiredhdrs != (u_char **) dkim_required_signhdrs)
+				dkim_clobber_array((char **) lib->dkiml_requiredhdrs);
+
+			lib->dkiml_requiredhdrs = (u_char **) tmp;
+		}
+		return DKIM_STAT_OK;
+
 #ifdef _FFR_OVERSIGN
 	  case DKIM_OPTS_OVERSIGNHDRS:
 		if (len != sizeof lib->dkiml_oversignhdrs)
@@ -4792,7 +4829,7 @@ dkim_options(DKIM_LIB *lib, int op, dkim_opts_t opt, void *ptr, size_t len)
 		else
 		{
 			int status;
-			u_char **hdrs;
+			u_char **hdrs, **required_signhdrs;
 			char buf[BUFRSZ + 1];
 
 			if (lib->dkiml_signre)
@@ -4807,6 +4844,7 @@ dkim_options(DKIM_LIB *lib, int op, dkim_opts_t opt, void *ptr, size_t len)
 
 			(void) strlcpy(buf, "^(", sizeof buf);
 
+			required_signhdrs = lib->dkiml_requiredhdrs;
 			if (!dkim_hdrlist((u_char *) buf, sizeof buf,
 			                  (u_char **) required_signhdrs, TRUE))
 				return DKIM_STAT_INVALID;
@@ -6488,6 +6526,23 @@ dkim_eoh(DKIM *dkim)
 {
 	assert(dkim != NULL);
 
+	if (dkim->dkim_chunkstate == DKIM_CHUNKSTATE_HEADER)
+	{
+		/* reverse the order of the headers */
+		struct dkim_header *hdr, *next;
+
+		hdr = dkim->dkim_hhead;
+		dkim->dkim_hhead = NULL;
+		dkim->dkim_htail = hdr;
+		while (hdr != NULL)
+		{
+			next = hdr->hdr_next;
+			hdr->hdr_next = dkim->dkim_hhead;
+			dkim->dkim_hhead = hdr;
+			hdr = next;
+		}
+	}
+
 	if (dkim->dkim_mode == DKIM_MODE_VERIFY)
 		return dkim_eoh_verify(dkim);
 	else
diff --git a/libopendkim/dkim.h b/libopendkim/dkim.h
index a7b12d9..919c216 100644
--- a/libopendkim/dkim.h
+++ b/libopendkim/dkim.h
@@ -273,6 +273,7 @@ typedef int dkim_opts_t;
 #define	DKIM_OPTS_SIGNATURETTL	11
 #define	DKIM_OPTS_CLOCKDRIFT	12
 #define	DKIM_OPTS_MUSTBESIGNED	13
+#define	DKIM_OPTS_REQUIREDHDRS	14
 
 #define	DKIM_LIBFLAGS_NONE		0x0000
 #define	DKIM_LIBFLAGS_TMPFILES		0x0001

