--- composer/e-msg-composer.c	2010-03-17 12:14:53.000000000 +0100
+++ composer/e-msg-composer.c	2010-04-17 19:05:51.000000000 +0200
@@ -113,6 +113,8 @@
 						 guint info,
 						 guint time);
 
+CamelCipherHash gpg_get_default_digest ();
+
 /**
  * emcu_part_to_html:
  * @part:
@@ -557,6 +559,82 @@
 	}
 }
 
+#include <sys/file.h>
+
+CamelCipherHash
+gpg_get_default_digest () {
+
+  const char* cmd = "echo|gpg --clearsign 2> /dev/null|head -n 2|tail -n 1|sed -e 's/Hash: //'>";
+  char* tempfilename;
+  char* cmd2x;
+  char* buf;
+  CamelCipherHash cch = CAMEL_CIPHER_HASH_SHA1;
+  int tempfile;
+  struct stat tempfile_stat;
+
+  printf("gpg_get_default_digest: ");
+  tempfilename = tempnam("", "ggdd.");
+  if ( tempfilename != NULL ) {
+	  cmd2x = malloc(75 + strlen(tempfilename));
+	  if ( cmd2x != NULL ) {
+		  cmd2x[0] = '\0';
+		  strcat(cmd2x, cmd);
+		  strcat(cmd2x, tempfilename);
+		  system(cmd2x);
+		  free(cmd2x);
+		  tempfile = open(tempfilename, O_RDONLY);
+		  if ( tempfile > -1 ) {
+			  if ( flock(tempfile, LOCK_EX) == 0 &&
+			       fstat(tempfile, &tempfile_stat) != -1 &&
+			       tempfile_stat.st_size > 0 ) {
+				  buf = malloc((size_t) tempfile_stat.st_size);
+				  if ( buf != NULL ) {
+					  lseek(tempfile, 0, SEEK_SET);
+					  read(tempfile, buf,  tempfile_stat.st_size - 1);
+					  buf[tempfile_stat.st_size - 1] = '\0';
+					  if (!strcasecmp (buf, "md2")) {
+						  cch = CAMEL_CIPHER_HASH_MD2;
+						  printf("MD2");
+					  } else if (!strcasecmp (buf, "md5")) {
+						  cch = CAMEL_CIPHER_HASH_MD5;
+						  printf("MD5");
+					  } else if (!strcasecmp (buf, "sha224")) {
+						  cch = CAMEL_CIPHER_HASH_SHA224;
+						  printf("SHA224");
+					  } else if (!strcasecmp (buf, "sha256")) {
+						  cch = CAMEL_CIPHER_HASH_SHA256;
+						  printf("SHA256");
+					  } else if (!strcasecmp (buf, "sha384")) {
+						  cch = CAMEL_CIPHER_HASH_SHA384;
+						  printf("SHA384");
+					  } else if (!strcasecmp (buf, "sha512")) {
+						  cch = CAMEL_CIPHER_HASH_SHA512;
+						  printf("SHA512");
+					  } else if (!strcasecmp (buf, "ripemd160")) {
+						  cch = CAMEL_CIPHER_HASH_RIPEMD160;
+						  printf("RIPEMD160");
+					  } else if (!strcasecmp (buf, "tiger192")) {
+						  cch = CAMEL_CIPHER_HASH_TIGER192;
+						  printf("TIGER192");
+					  } else if (!strcasecmp (buf, "haval-5-160")) {
+						  cch = CAMEL_CIPHER_HASH_HAVAL5160;
+						  printf("HAVAL-5-160");
+					  } else {
+						  printf("SHA1");
+					  }
+					  free(buf);		      
+				  }
+			  }
+			  close(tempfile);
+			  unlink(tempfilename);
+		  }
+	  }
+  }
+  printf("\n");
+
+  return cch;
+}
+
 static CamelMimeMessage *
 build_message (EMsgComposer *composer,
                gboolean html_content,
@@ -916,7 +994,7 @@
 					CAMEL_GPG_CONTEXT (cipher),
 					account->pgp_always_trust);
 			camel_cipher_sign (
-				cipher, pgp_userid, CAMEL_CIPHER_HASH_SHA1,
+				cipher, pgp_userid, gpg_get_default_digest(),
 				part, npart, &ex);
 			camel_object_unref (cipher);
 
