diff -ruN simscan-1.4.0-factory/configure simscan-1.4.0-patched-4/configure
--- simscan-1.4.0-factory/configure	2007-10-29 10:14:25.000000000 -0400
+++ simscan-1.4.0-patched-4/configure	2008-10-07 21:47:14.000000000 -0400
@@ -4686,6 +4686,14 @@
           then
             clamavdb=$f
             break
+          elif test -f "$f/daily.cld"
+          then
+            clamavdb=$f
+            break
+          elif test -f "$f/daily.inc/daily.info"
+          then
+            clamavdb=$f
+            break
           fi
         done
 
diff -ruN simscan-1.4.0-factory/configure.in simscan-1.4.0-patched-4/configure.in
--- simscan-1.4.0-factory/configure.in	2007-10-29 10:13:40.000000000 -0400
+++ simscan-1.4.0-patched-4/configure.in	2008-10-07 21:47:14.000000000 -0400
@@ -622,6 +622,14 @@
           then
             clamavdb=$f
             break
+          elif test -f "$f/daily.cld"
+          then
+            clamavdb=$f
+            break
+          elif test -f "$f/daily.inc/daily.info"
+          then
+            clamavdb=$f
+            break
           fi
         done
 
diff -ruN simscan-1.4.0-factory/simscan.c simscan-1.4.0-patched-4/simscan.c
--- simscan-1.4.0-factory/simscan.c	2007-10-29 10:15:05.000000000 -0400
+++ simscan-1.4.0-patched-4/simscan.c	2008-10-07 21:47:14.000000000 -0400
@@ -102,6 +102,7 @@
 int str_rstr(register char *h,register char *n);
 char *replace(char *string, char *oldpiece, char *newpiece);
 int DebugFlag = 0;
+int DebugFiles = 0;
 
 /* To/From address processing globals */
 #define MAX_RCPT_TO 255
@@ -168,6 +169,7 @@
 int InClamHeaders;
 int check_clam();
 int is_clam(char *clambuf);
+void log_clam(char *clambuf);
 #endif
 
 /* Attachment scanning globals */
@@ -266,6 +268,11 @@
   if ( (tmpstr=getenv("SIMSCAN_DEBUG"))!=NULL ) {
     DebugFlag = atoi(tmpstr);
   }
+
+  /* Set the "leave temp files alone" flag */
+  if ( (tmpstr=getenv("SIMSCAN_DEBUG_FILES"))!=NULL ) {
+    DebugFiles = atoi(tmpstr);
+  }
   
 #ifdef ENABLE_ATTACH
   init_attach();
@@ -283,6 +290,7 @@
   }
 
   /* create the working directory, allow group access too */
+  umask ( 027 ) ;
   if ( mkdir(workdir, 0750) == -1 ) {
     if ( DebugFlag > 0 ) {
       fprintf(stderr, "simscan: error making work dir, exit 400, errno: %d\n",
@@ -811,10 +819,12 @@
   }
 
   /* remove the working files */
-  if ( remove_files(workdir) == -1 ) {
-    exit_clean(EXIT_400);
+  if ( DebugFiles < 2 ) {
+    if ( remove_files(workdir) == -1 ) {
+      exit_clean(EXIT_400);
+    }
   }
-  
+
   /* pass qmail-queue's exit status on */
   _exit(WEXITSTATUS(qstat));
 
@@ -967,6 +977,7 @@
   InClamHeaders = 1;
   memset(buffer,0,sizeof(buffer));
   while((file_count=read(0,buffer,BUFFER_SIZE))>0) {
+    if ( DebugFlag > 2 ) log_clam(buffer) ;
     if ( InClamHeaders == 1 ) {
       is_clam(buffer);
     }
@@ -993,6 +1004,35 @@
   return(-1);
 }
 
+void log_clam(char *clambuf)
+{
+	char *p ;
+	int needh = 1 ;
+
+	p = clambuf ;
+	while ( *p )
+	{
+		if ( *p != '\r' )
+		{
+			if ( needh )
+			{
+				fputs ( "simscan: clamdscan: " , stderr ) ;
+				needh = 0 ;
+			}
+
+			fputc ( *p , stderr ) ;
+
+			if ( *p == '\n' )
+				needh = 1 ;
+		}
+
+		p++ ;
+	}
+
+	if ( ! needh )
+		fputc ( '\n' , stderr ) ;
+}
+
 int is_clam(char *clambuf)
 {
  int i,j,k;
@@ -1608,7 +1648,8 @@
  */
 void exit_clean( int error_code )
 {
-  remove_files(workdir);
+  if ( DebugFiles < 1 )
+    remove_files(workdir);
   if ( DebugFlag > 0 ) {
     fprintf(stderr, "simscan: exit error code: %d\n", error_code); 
   }
diff -ruN simscan-1.4.0-factory/simscanmk.c simscan-1.4.0-patched-4/simscanmk.c
--- simscan-1.4.0-factory/simscanmk.c	2006-10-10 19:15:17.000000000 -0400
+++ simscan-1.4.0-patched-4/simscanmk.c	2008-10-07 21:47:22.000000000 -0400
@@ -123,6 +123,7 @@
   char input[MAX_LINE];
   char dbpath[MAX_LINE];
   char *pos;
+  int rv;
 #if ENABLE_SPAM==1 || ENABLE_TROPHIE==1
   int fnd_vsvers;
 #endif
@@ -179,6 +180,11 @@
           Initializing    : Pattern version 218 (pattern number 51417)
         and we want 6.150-1001/218/51417 in the string at the end */
 
+      if(r == -1){
+        printf("error reading trophie pipe: %s\n", strerror(errno));
+        break;
+      }
+
       input[r]='\0';
       if ( (pos=strstr(input,"version ")) && (!fnd_vsvers || !fnd_patvers)){
         if (!fnd_vsvers && !fnd_patvers){
@@ -229,6 +235,12 @@
           SpamAssassin version 2.63
           and have 2.63 as version
         */
+
+      if(r == -1){
+        printf("error reading spamassassin pipe: %s\n", strerror(errno));
+        break;
+      }
+
       input[r]='\0';
       if ( (pos=strstr(input,"version ")) && !fnd_vsvers ){
         /* this line is the sa version */
@@ -265,6 +277,12 @@
       /* we are looking for this line:
          Version: 27
         */
+
+      if(r == -1){
+        printf("error reading clamdscan pipe: %s\n", strerror(errno));
+        break;
+      }
+
       input[r]='\0';
       if ( (pos=strstr(input,"ClamAV "))){
         /* this line is the db version */
@@ -276,8 +294,18 @@
     waitpid(pid,&rmstat,0);
     close(pin[0]); close(pin[1]);
   }
-  strncpy(dbpath,CLAMAVDBPATH,MAX_DATA);
-  strcat(dbpath,"/main.cvd");
+  strncpy(dbpath,CLAMAVDBPATH,MAX_LINE);
+  strncat(dbpath,"/main.inc/main.info",(MAX_LINE-sizeof(CLAMAVDBPATH)-1));
+  rv=access(dbpath,F_OK);
+  if(rv) {
+    strncpy(dbpath,CLAMAVDBPATH,MAX_LINE);
+    strncat(dbpath,"/main.cld",(MAX_LINE-sizeof(CLAMAVDBPATH)-1));
+  }
+  rv=access(dbpath,F_OK);
+  if(rv) {
+    strncpy(dbpath,CLAMAVDBPATH,MAX_LINE);
+    strncat(dbpath,"/main.cvd",(MAX_LINE-sizeof(CLAMAVDBPATH)-1));
+  }
   strcat(data,"m:");
   if (pipe(pin)){
     printf("error opening pipe for sigtool\n");
@@ -297,6 +325,12 @@
       /* we are looking for this line:
          Version: 27
         */
+
+      if(r == -1){
+        printf("error reading sigtool pipe: %s\n", strerror(errno));
+        break;
+      }
+
       input[r]='\0';
       if ( (pos=strstr(input,"Version: "))){
         /* this line is the db version */
@@ -306,8 +340,18 @@
     }
     waitpid(pid,&rmstat,0);
     close(pin[0]); close(pin[1]);
-    strncpy(dbpath,CLAMAVDBPATH,MAX_DATA);
-    strcat(dbpath,"/daily.cvd");
+    strncpy(dbpath,CLAMAVDBPATH,MAX_LINE);
+    strncat(dbpath,"/daily.inc/daily.info",(MAX_LINE-sizeof(CLAMAVDBPATH)-1));
+    rv=access(dbpath,F_OK);
+    if(rv) {
+      strncpy(dbpath,CLAMAVDBPATH,MAX_LINE);
+      strncat(dbpath,"/daily.cld",(MAX_LINE-sizeof(CLAMAVDBPATH)-1));
+    }
+    rv=access(dbpath,F_OK);
+    if(rv) {
+      strncpy(dbpath,CLAMAVDBPATH,MAX_LINE);
+      strncat(dbpath,"/daily.cvd",(MAX_LINE-sizeof(CLAMAVDBPATH)-1));
+    }
     if (pipe(pin)){
      printf("error opening pipe for sigtool\n");
     }
@@ -326,6 +370,12 @@
         /* we are looking for this line:
            Version: 27
           */
+
+        if(r == -1){
+          printf("error reading sigtool pipe: %s\n", strerror(errno));
+          break;
+        }
+
         input[r]='\0';
         if ( (pos=strstr(input,"Version: "))){
           /* this line is the db version */
