Index: com_err/et/com_err.c
--- com_err/et/com_err.c.orig	2012-04-19 11:39:51.000000000 +0200
+++ com_err/et/com_err.c	2012-06-03 13:41:16.000000000 +0200
@@ -52,7 +52,7 @@
 #include <string.h>
 #include "mit-sipb-copyright.h"
 
-#if defined(HAVE_STDARG_H) || defined(_WINDOWS)
+#if defined(HAVE_STDARG_H) || defined(__STDC__) || defined(_WINDOWS)
 #include <stdarg.h>
 #else
 #include <varargs.h>
Index: com_err/et/com_err.h
--- com_err/et/com_err.h.orig	2012-04-19 11:39:51.000000000 +0200
+++ com_err/et/com_err.h	2012-06-03 13:41:16.000000000 +0200
@@ -104,5 +104,7 @@
 extern void (*reset_com_err_hook ()) ();
 #endif
 
+struct et_list;
+
 #define __COM_ERR_H
 #endif /* ! defined(__COM_ERR_H) */
Index: imap/fud.c
--- imap/fud.c.orig	2012-04-19 11:39:51.000000000 +0200
+++ imap/fud.c	2012-06-03 13:41:16.000000000 +0200
@@ -102,23 +102,23 @@
 
 char who[16];
 
-#define MAXLOGNAME 16		/* should find out for real */
-#define MAXDOMNAME 20		/* should find out for real */
+#define MY_MAXLOGNAME 16		/* should find out for real */
+#define MY_MAXDOMNAME 20		/* should find out for real */
 
 int begin_handling(void)
 {
         struct sockaddr_storage sfrom;
         socklen_t sfromsiz = sizeof(sfrom);
         int r;
-        char    buf[MAXLOGNAME + MAXDOMNAME + MAX_MAILBOX_BUFFER];
-        char    username[MAXLOGNAME + MAXDOMNAME + 1];
+        char    buf[MY_MAXLOGNAME + MY_MAXDOMNAME + MAX_MAILBOX_BUFFER];
+        char    username[MY_MAXLOGNAME + MY_MAXDOMNAME + 1];
         char    mbox[MAX_MAILBOX_BUFFER];
         char    *q;
         int     off;
-	int     maxuserlen = MAXLOGNAME;
+	int     maxuserlen = MY_MAXLOGNAME;
 
 	if (config_virtdomains) 
-	    maxuserlen += MAXDOMNAME + 1; /* @ + DOM */
+	    maxuserlen += MY_MAXDOMNAME + 1; /* @ + DOM */
 
         while(1) {
             /* For safety */
Index: imap/idled.c
--- imap/idled.c.orig	2012-04-19 11:39:51.000000000 +0200
+++ imap/idled.c	2012-06-03 13:41:16.000000000 +0200
@@ -52,6 +52,7 @@
 #include <syslog.h>
 #include <sys/stat.h>
 #include <stdlib.h>
+#include <string.h>
 #include <errno.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
Index: imap/mboxname.c
--- imap/mboxname.c.orig	2012-04-19 11:39:51.000000000 +0200
+++ imap/mboxname.c	2012-06-03 13:41:16.000000000 +0200
@@ -385,7 +385,11 @@
 		sprintf(result, "%s!", cp);
 	    }
 	}
+#ifdef ATVDOM /* allow '@' being a regular character in mboxname even when using virtual domains */
+	else if ((cp = strrchr(name, '@'))) {
+#else
 	if ((cp = strrchr(name, '@'))) {
+#endif /* ATVDOM */
 	    /* mailbox specified as mbox@domain */
 	    namelen = cp - name;
 
Index: imap/sync_log.c
--- imap/sync_log.c.orig	2012-04-19 11:39:51.000000000 +0200
+++ imap/sync_log.c	2012-06-03 13:41:16.000000000 +0200
@@ -58,6 +58,7 @@
 #include <varargs.h>
 #endif
 #include <stdlib.h>
+#include <string.h>
 #include <stdio.h>
 #include <string.h>
 #include <syslog.h>
Index: lib/cyrusdb_berkeley.c
--- lib/cyrusdb_berkeley.c.orig	2012-04-19 11:39:51.000000000 +0200
+++ lib/cyrusdb_berkeley.c	2012-06-03 13:41:16.000000000 +0200
@@ -172,6 +172,7 @@
 
     dbenv->set_lk_detect(dbenv, CONFIG_DEADLOCK_DETECTION);
 
+#if (DB_VERSION_MAJOR < 4) || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 5)
     if ((opt = libcyrus_config_getint(CYRUSOPT_BERKELEY_LOCKS_MAX)) < 0) {
 	syslog(LOG_WARNING,
 	       "DBERROR: invalid berkeley_locks_max value, using internal default");
@@ -191,6 +192,7 @@
 	    abort();
 	}
     }
+#endif
 
     if ((opt = libcyrus_config_getint(CYRUSOPT_BERKELEY_TXNS_MAX)) < 0) {
 	syslog(LOG_WARNING,
Index: lib/cyrusdb_skiplist.c
--- lib/cyrusdb_skiplist.c.orig	2012-04-19 11:39:51.000000000 +0200
+++ lib/cyrusdb_skiplist.c	2012-06-03 13:41:16.000000000 +0200
@@ -75,6 +75,13 @@
 
 #define PROB (0.5)
 
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+/* #define fdatasync(fd) fsync(fd) */
+#ifndef O_DSYNC
+#define O_DSYNC 0
+#endif
+#endif
+
 /* 
  *
  * disk format; all numbers in network byte order
Index: lib/prot.h
--- lib/prot.h.orig	2012-04-19 11:39:51.000000000 +0200
+++ lib/prot.h	2012-06-03 13:41:16.000000000 +0200
@@ -49,6 +49,7 @@
 #include <time.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/time.h>
 
 #include <sasl/sasl.h>
 
Index: lib/util.c
--- lib/util.c.orig	2012-04-19 11:39:51.000000000 +0200
+++ lib/util.c	2012-06-03 14:01:39.000000000 +0200
@@ -45,6 +45,7 @@
 #include <config.h>
 
 #include <stdio.h>
+#include <limits.h>
 #include <ctype.h>
 #include <errno.h>
 #include <grp.h>
@@ -281,7 +282,7 @@
 	pt = (unsigned char *)name;
 	while (*pt && *pt != '.') {
 	    n = ((n << DIR_X) ^ (n >> DIR_Y)) ^ *pt;
-	    n &= UINT32_MAX;
+	    n &= 0xffffffffL;
 	    ++pt;
 	}
 	c = DIR_A + (n % DIR_P);
Index: lib/util.h
--- lib/util.h.orig	2012-04-19 11:39:51.000000000 +0200
+++ lib/util.h	2012-06-03 13:41:16.000000000 +0200
@@ -99,6 +99,8 @@
 #define MIN(x, y) ((x) < (y) ? (x) : (y))
 #endif
 
+#include <sys/stat.h>
+
 typedef struct keyvalue {
     char *key, *value;
 } keyvalue;
Index: perl/Makefile.in
--- perl/Makefile.in.orig	2012-04-19 11:39:51.000000000 +0200
+++ perl/Makefile.in	2012-06-03 13:41:16.000000000 +0200
@@ -86,7 +86,8 @@
 			   BDB_LIB="$(BDB_LIB)" BDB_INC="$(BDB_INC)" \
 			   OPENSSL_LIB="$(OPENSSL_LIB)" OPENSSL_INC="$(OPENSSL_INC)" \
 			   SASL_LIB="$(SASL_LIB)" SASL_INC="$(SASL_INC)" CC="$(CC)" \
-			     $(PERL) Makefile.PL PREFIX=$(prefix); \
+			     $(PERL) Makefile.PL PREFIX=$(prefix) \
+			         INSTALLDIRS="vendor" INSTALLMAN3DIR="none" INSTALLSITEMAN3DIR="none" INSTALLVENDORMAN3DIR="none"; \
 			fi; \
 			$(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) all) || exit 1; \
 	done
Index: perl/sieve/Makefile.in
--- perl/sieve/Makefile.in.orig	2012-04-19 11:39:51.000000000 +0200
+++ perl/sieve/Makefile.in	2012-06-03 13:41:16.000000000 +0200
@@ -86,7 +86,8 @@
 			   BDB_LIB="$(BDB_LIB)" BDB_INC="$(BDB_INC)" \
 			   OPENSSL_LIB="$(OPENSSL_LIB)" OPENSSL_INC="$(OPENSSL_INC)" \
 			   SASL_LIB="$(SASL_LIB)" SASL_INC="$(SASL_INC)" CC="$(CC)" \
-			     $(PERL) Makefile.PL PREFIX=$(prefix); \
+			     $(PERL) Makefile.PL PREFIX=$(prefix) \
+			         INSTALLDIRS="vendor" INSTALLMAN3DIR="none" INSTALLSITEMAN3DIR="none" INSTALLVENDORMAN3DIR="none"; \
 			fi; \
 			$(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) all) || exit 1; \
 	done
Index: perl/sieve/lib/isieve.c
--- perl/sieve/lib/isieve.c.orig	2012-04-19 11:39:51.000000000 +0200
+++ perl/sieve/lib/isieve.c	2012-06-03 13:41:16.000000000 +0200
@@ -41,9 +41,7 @@
  * $Id: isieve.c,v 1.37 2010/01/06 17:01:56 murch Exp $
  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "../../../config.h"
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
