--- coolmail-1.3.orig/Makefile
+++ coolmail-1.3/Makefile
@@ -22,9 +22,9 @@
 # your linker where to find the libraries it will need, and BINDIR and
 # MANDIR specify the places to install the binary executable and manpage
 # files for coolmail when you type `make install'.
-CFLAGS   = 
+#CFLAGS   =
 LINK     = $(CC)
-INCLUDES = -I/usr/X11R5/include
+INCLUDES = -I/usr/X11R6/include
 LIB_DIRS = -L/usr/X11R6/lib
 BINDIR   = /usr/local/bin
 MANDIR   = /usr/local/man/man1
@@ -34,10 +34,17 @@ MANDIR   = /usr/local/man/man1
 AUDIO        = -DAUDIO
 AUDIO_MODULE = audio.o
 
+# Comment these out if you don't want Maildir support
+MAILDIR = -DSUPPORT_MAILDIR
+# for debugging:
+#MAILDIR = $(MAILDIR) -DSUPPORT_MAILDIR_DEBUG
+# normally ignores non-regular files in the Maildir; uncomment to change
+#MAILDIR = $(MAILDIR) -DSUPPORT_MAILDIR_STRICTER
+
 #### You really don't need to read past this point. ####
 
-LIBS  = $(LIB_DIRS) -lXt -lX11 -lm -lXext
-COPTS = $(CFLAGS) $(AUDIO)
+LIBS  = $(LIB_DIRS) -lXt -lX11 -lm
+COPTS = $(CFLAGS) $(AUDIO) $(MAILDIR)
 
 all: coolmail
 	# Done.
@@ -74,7 +81,7 @@ install:
 	fi;
 
 coolmail: coolmail.o display_list.o render1.o colors.o $(AUDIO_MODULE)
-	$(LINK) coolmail.o display_list.o render1.o  colors.o $(AUDIO_MODULE)\
+	$(LINK) $(LDFLAGS) coolmail.o display_list.o render1.o  colors.o $(AUDIO_MODULE)\
                 $(LIBS) -o coolmail 
 
 display_list.o: system/X11/display_list.c display_list.h render1.h \
--- coolmail-1.3.orig/audio.c
+++ coolmail-1.3/audio.c
@@ -63,8 +63,13 @@ typedef struct {
 	u_32		channels;	/* number of interleaved channels */
 } Audio_filehdr;
 
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD_kernel__)
+
+#if defined(linux)
 #include <linux/soundcard.h>
+#else
+#include <sys/soundcard.h>
+#endif
 
 #define DEV_MIXER		"/dev/mixer"
 #define MAX_VOLUME		100
@@ -101,7 +106,7 @@ void setvolume(int which, unsigned char
 
 #define CLOSE_FD(afd)	{ if (afd > -1) close(afd); afd = -1; }
 
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD_kernel__)
 #define INIT_FD	{ audiofd = filefd = mixer_fd = -1; }
 #define END_FD	{ CLOSE_FD(audiofd); CLOSE_FD(filefd); CLOSE_FD(mixer_fd); return; }
 #else
@@ -117,7 +122,7 @@ void audio_beep (void)
 	unsigned char	buf[256];
 	Audio_filehdr	*au_hdr;
 
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD_kernel__)
 	StereoVolume origVol, volume;
 	int				mixer_fd;
 #else
@@ -125,14 +130,18 @@ void audio_beep (void)
 	int				origVol;	
 #endif
 
+	/* NOP if requested volume is zero. */
+	if (cool_vol <= 0) return;
+
 	INIT_FD;
 	audiofd = open( "/dev/audio", O_WRONLY | O_NDELAY ); 
 	if (audiofd < 0) {
+	        perror("/dev/audio");
 		fprintf(stderr, "%s: Problem opening /dev/audio.\n",
 				"Coolmail");
 		END_FD;
 	}
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD_kernel__)
 	if ( (mixer_fd=open(DEV_MIXER, O_RDWR, 0)) < 0 ) {
 		fprintf(stderr, "Can't open %s: ", DEV_MIXER);
 		END_FD;
@@ -185,7 +194,7 @@ void audio_beep (void)
 
 	/* Strip the header */
 	au_hdr = (Audio_filehdr *)buf;
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD_kernel__)
 	rn = ntohl(au_hdr->hdr_size) - sizeof(Audio_filehdr); 	
 #else
 	rn = au_hdr->hdr_size - sizeof(Audio_filehdr);
@@ -217,7 +226,7 @@ void audio_beep (void)
 			usleep(1000);
 		}
 	}
-#ifdef linux
+#if defined(linux) || defined(__FreeBSD_kernel__)
 	CLOSE_FD(audiofd);
 
 	if ( ioctl(mixer_fd, MIXER_WRITE(SOUND_MIXER_VOLUME), &origVol) < 0 ) {
--- coolmail-1.3.orig/coolmail.c
+++ coolmail-1.3/coolmail.c
@@ -26,6 +26,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <pwd.h>
 
 #ifdef AUDIO
 #include <string.h>
@@ -96,7 +97,7 @@ void cool_usage(void);
 int main(int argc, char *argv[])
 {
    int reason;
-   char username[L_cuserid];
+   struct passwd *uid;
 
    /* Quickly scan for the -h option -- if it is present don't do anything
     * but print out some help and exit. */
@@ -104,7 +105,11 @@ int main(int argc, char *argv[])
       return(0);
 
    /* Get the username and use it to create a default mailfile name */
-   strcat(mailfile_str, cuserid(username));
+   if (!(uid = getpwuid(geteuid()))) {
+      printf("Couldn't determine your username. Exiting.\n");
+      return 1;
+   }
+   strcat(mailfile_str, uid->pw_name);
 
    /* Initialize the renderer */
    rend_init(&argc, argv, (float)150.0);
--- coolmail-1.3.orig/system/X11/display_list.c
+++ coolmail-1.3/system/X11/display_list.c
@@ -306,9 +306,9 @@ void disp_bell(void)
       /* play the soundfile */
       audio_beep();
    else	/* no sound file chosen then use system bell */
-      XBell(XtDisplay(main_gfx_w), cool_vol);
+      XBell(XtDisplay(main_gfx_w), (2*cool_vol)-100);
 #else
-   XBell(XtDisplay(main_gfx_w), 50);
+   XBell(XtDisplay(main_gfx_w), 0);
 #endif
 }
 
