Index: camel/camel.c
===================================================================
--- camel/camel.c	(revision 10220)
+++ camel/camel.c	(working copy)
@@ -67,7 +67,7 @@
 
 #ifdef HAVE_NSS
 	if (nss_init) {
-		char *nss_configdir;
+		char *nss_configdir, *nss_sql_configdir;
 		PRUint16 indx;
 
 		PR_Init (PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 10);
@@ -77,15 +77,42 @@
 #else
 		nss_configdir = g_win32_locale_filename_from_utf8 (configdir);
 #endif
+		/* Currently we store the new shared NSS database in the same location
+		 * we kept the original NSS databases in, but at least we have safe shared
+		 * access between e-d-s and evo s/mime. Once f.d.o comes up with a user-wide
+		 * shared location, we should use that instead.
+		 */
+		nss_sql_configdir = g_strconcat("sql:", nss_configdir, NULL);
 
-		if (NSS_InitReadWrite (nss_configdir) == SECFailure) {
-			/* fall back on using volatile dbs? */
-			if (NSS_NoDB_Init (nss_configdir) == SECFailure) {
-				g_free (nss_configdir);
-				g_warning ("Failed to initialize NSS");
-				return -1;
-			}
+#if NSS_VMAJOR > 3 || (NSS_VMAJOR == 3 && NSS_VMINOR >= 12)
+		/* See: https://wiki.mozilla.org/NSS_Shared_DB 
+		 * particularly "Mode 3A" */
+		/* Note that the target directory MUST EXIST */
+		if (NSS_InitWithMerge (	nss_sql_configdir, /* Dest dir */
+					"", "", /* NEw DB key and cert name prefixes */
+					"secmod.db", /* Secmod name */
+					nss_configdir, /* Old DB dir */
+					"", "", /* Old DB key and cert db name prefixes */
+					nss_configdir, /* Unique ID for old DB */
+					"Evolution S/MIME", /* UI name for old DB */
+					0 /* Flags */
+					) == SECFailure)
+		{
+			g_free (nss_configdir);
+			g_free (nss_sql_configdir);
+			g_warning ("Failed to initialize NSS");
+			return -1;
 		}
+#else
+		/* Support old versions of libnss, pre-sqlite support */
+		if (NSS_InitReadWrite (	nss_configdir ))
+		{
+			g_free (nss_configdir);
+			g_free (nss_sql_configdir);
+			g_warning ("Failed to initialize NSS");
+			return -1;
+		}
+#endif
 
 		NSS_SetDomesticPolicy ();
 		/* we must enable all ciphersuites */
@@ -100,6 +127,7 @@
 		SSL_OptionSetDefault (SSL_V2_COMPATIBLE_HELLO, PR_TRUE /* maybe? */);
 
 		g_free (nss_configdir);
+		g_free(nss_sql_configdir);
 	}
 #endif /* HAVE_NSS */
 	
