# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 84550 2011-09-27 21:05:11Z snc@macports.org $

PortSystem      1.0

name				vpopmail
version				5.4.25
categories			mail
maintainers			yahoo.com:compconsultant
platforms			darwin

description			Manage multiple virtual domains with Qmail

long_description	        Vpopmail is a set of programs for creating and managing multiple virtual domains on a qmail server, with full support for many POP/IMAP servers.

variant onchange description {Enable use on the ONCHANGE script} {
	configure.args-append	--enable-onchange-script
}

variant mysql5 description {Store vpopmail users and more in MySQL5} {
	configure.args-append	--enable-auth-module=mysql \
				--enable-auth-logging \
				--enable-sql-logging \
				--enable-incdir=${prefix}/include/mysql5/mysql \
				--enable-libdir=${prefix}/lib/mysql5/mysql \
				--enable-valias
	depends_lib-append	path:bin/mysql_config5:mysql5
}

variant roaming description {Enable POP before SMTP functionality} {
	configure.args-append	--enable-roaming-users \
				--enable-tcpserver-file=${prefix}/var/${name}/etc/tcp.smtp
}

variant noclearpasswords description {Do not store a cleartext version of the password} {
	configure.args-append	--disable-clear-passwd
}

variant learnpasswords description {If user password is not set, learn it the first time they authenticate} {
	configure.args-append	--enable-learn-passwords
}

variant spamassassin description {Enable spamassassin integration} {
	configure.args-append	--enable=spamassassin \
				--enable-spamc-prog=${prefix}/bin/spamc
	depends_lib-append	port:p5-mail-spamassassin
}

variant maildrop description {Enable maildrop integration} {
	configure.args-append	--enable-maildrop \
				--enable-maildrop-prog=${prefix}/bin/maildrop
	depends_lib-append	port:maildrop
}

variant logverbose conflicts logpwds logall description {Enables verbose logging of all attempts, with passwords} {
	configure.args-append	--enable-logging=v
}

variant logpwds conflicts logverbose logall description {Log errors with passwords} {
	configure.args-append	--enable-logging=p
}

variant logall conflicts logpwds logverbose description {Log all attempts, no passwords} {
	configure.args-append	--enable-logging=y
}

homepage			http://www.inter7.com/index.php?page=vpopmail

depends_lib			port:qmail-spamcontrol \
				port:ucspi-tcp

master_sites		        sourceforge
				
checksums			md5 273c2c25906aed5206e97b01a2593aa6 \
				sha1 ce62415fbd338b80f1962a477d94276f622756d0 \
				rmd160 57142cca0617bd95ef2e5f4aa74ab5fa0844d6df

patchfiles			patch-configure.diff

configure.args			--enable-qmaildir=${prefix}/var/qmail \
				--enable-tcprules-prog=${prefix}/bin/tcprules \
				--enable-qmail-ext \
				--prefix=${prefix} \
				--exec-prefix=${prefix}

build.target

destroot.target		install-strip
destroot.keepdirs	${destroot}${prefix}/var/${name}/domains

pre-configure {

	# The vpopmail users and groups are required before compilation
	addgroup vchkpw gid=2109
	adduser vpopmail uid=7797 gid=[existsgroup vchkpw] realname=vpopmail home=${prefix}/var/${name} shell=/usr/bin/true
}

post-destroot {
	if {[variant_isset roaming]} {
		system "echo \"127.:allow,RELAYCLIENT=''\" > ${destroot}${prefix}/var/${name}/etc/tcp.smtp.sample"
		system "echo \"localhost|0|user|password|database\" >${destroot}${prefix}/var/${name}/etc/tcp.smtp.sample"
		system "chown vpopmail:vchkpw ${destroot}${prefix}/var/${name}/etc/tcp.smtp.sample"
                xinstall -m 644 -W ${worksrcpath} README.roamingusers ${destroot}${prefix}/var/${name}/doc
	}
	if {[variant_isset mysql5]} {
		file rename ${destroot}${prefix}/var/${name}/etc/vpopmail.mysql ${destroot}${prefix}/var/${name}/etc/vpopmail.mysql.sample
                xinstall -m 644 -W ${worksrcpath} README.mysql ${destroot}${prefix}/var/${name}/doc
	}
	if {[variant_isset maildrop]} {
                xinstall -m 644 -W ${worksrcpath} README.maildrop ${destroot}${prefix}/var/${name}/doc
	}
	if {[variant_isset onchange]} {
                xinstall -m 644 -W ${worksrcpath} README.onchange ${destroot}${prefix}/var/${name}/doc
	}
	if {[variant_isset spamassassin]} {
                xinstall -m 644 -W ${worksrcpath} README.spamassassin ${destroot}${prefix}/var/${name}/doc
	}
}

post-activate {
	if {[variant_isset roaming]} {
		ui_msg "
Because you used the roaming variant, you must set up the tcpserver file
${prefix}/var/${name}/etc/tcp.smtp, please copy the sample file from
${prefix}/var/${name}/etc/tcp.smtp.sample
"
	}
	if {[variant_isset onchange]} {
		ui_msg "
Because you used the onchange variant, you must set up a script file at
${prefix}/var/${name}/etc/onchange before you can use VPOPMAIL commands
"
	}
	if {[variant_isset mysql5]} {
		ui_msg "
Because you used the MySQL5 variant, you must set up a file called
${prefix}/var/${name}/etc/vpopmail.mysql so that it points to your database.
A sample has been created for you at ${prefix}/var/${name}/etc/vpopmail.mysql.sample
"
	}
	ui_msg "Please review the doc in ${prefix}/var/${name}/doc\n"
}

livecheck.distname	${name}-stable
