# Makefile for filtercmd, part of serversidefilter
# See README for background information
#

### GENERAL OPTIONS ###

# change this to match the group your HTTPD server runs as.
# The resulting binary will be owned by this group.
HTTPD_GROUP=http

# If you are having problems connecting, recompile with this 
# flag changed and send the output to the mailing list.
CFLAGS=
#CFLAGS=-DDEBUG

# Use the following argument to tell the linker to make
# a statically linked binary
#LFLAGS=
LFLAGS=-static 

# Edit the location of the squirrelmail config file here.
SQUIRRELMAILCONFIGFILE=/etc/squirrelmail/config.php
FILTERCMD_CFLAGS=-DSQUIRRELMAILCONFIGFILE='"$(SQUIRRELMAILCONFIGFILE)"'

# The default location for the serversidefilter directory should work. 
# Uncomment the line below, and change the test.sh file, if you want to 
# change it.
SERVERSIDEFILTERHOME=../plugins/serversidefilter
#FILTERCMD_CFLAGS=$(FILTERCMD_CFLAGS) -DSERVERSIDEFILTERHOME='"$(SERVERSIDEFILTERHOME)"'

### C-CLIENT OPTIONS ###

# filtercmd validates usernames and passwords with the c-client library from
# UW. This library is part of pine and UW IMAP and is installed separately
# on many Linux systems.  See http://www.washington.edu/imap/ for more
# information.

# This line selects c-client credentials checking. This is currently the
# only option. 
CHECKCREDS=checkcreds_cclient.o

# You may need to adjust the following line.
LIBS=/usr/lib/c-client.a -lssl -lpam -L/usr/kerberos/lib/ -lgssapi_krb5 -lcrypt -lkrb5 -lresolv -lcom_err -ldl -lz -lcrypto -lk5crypto 

# This directory should contain a file named mail.h
I=/usr/include/imap

# These settings should work fine.
CCLIENT_CFLAGS=-I$I '-DMAIL_H="mail.h"' '-DLINKAGE_C="linkage.c"' -DIMAP_TIMEOUT=2

# filtercmd uses c-client's mailbox naming conventions to control how the 
# connection to the IMAP server will happen. The standard mailbox name will 
# look like: {localhost/imap4/user=.../norsh}
# See http://www.washington.edu/imap/documentation/naming.txt.html for more details.
# You can add more flags, and/or remove the /norsh flag, by uncommenting the 
# line below.

# The default settings (uncomment and edit)
#CCLIENT_CFLAGS=$(CCLIENT_CFLAGS) -DMAILBOXFLAGS=/norsh

# The /notls flag will work around SSL problems. 
#CCLIENT_CFLAGS=$(CCLIENT_CFLAGS) -DMAILBOXFLAGS=/norsh/notls

### END OF C-CLIENT OPTIONS ###

### END OF CONFIGURABLE OPTIONS ###

all: filtercmd

filtercmd: filtercmd.o Makefile $(CHECKCREDS)
	gcc -o filtercmd filtercmd.o $(CHECKCREDS) $(LIBS) $(LFLAGS) 
	chmod 4750 filtercmd
	chown root:$(HTTPD_GROUP) filtercmd

filtercmd.o: filtercmd.c Makefile
	gcc -c filtercmd.c $(CFLAGS) $(FILTERCMD_CFLAGS)

checkcreds_cclient.o: checkcreds_cclient.c Makefile
	gcc -c checkcreds_cclient.c $(CFLAGS) $(CCLIENT_CFLAGS)

test: test.sh filtercmd
	sh test.sh

clean:
	-rm *.o *~ test_creds filter
