%define USE_DRACD 0

Summary: POP3 daemon from Qualcomm
Summary(ja): POP3 デーモン
Name: qpopper
Version: 4.0.19
Release: 1%{?_dist_release}
License: BSD
Group: System Environment/Daemons
URL: http://www.eudora.com/qpopper/
Source0: ftp://ftp.qualcomm.com/eudora/servers/unix/popper/%{name}%{version}.tar.gz
Source2: qpopper.xinetd.vine
Source10: qpopper.pamd_vl4
Source11: qpopper.pamd

%if %{_dist_release}=="vl4"
# for Vine 4.x
Requires: pam >= 0.59
BuildRequires: pam-devel >= 0.59
%else
Requires: pam >= 1.0
BuildRequires: pam-devel >= 1.0
%endif

Requires: gdbm, openssl
BuildRequires: gdbm-devel, openssl-devel

%if %{USE_DRACD}
Requires: dracd
BuildRequires: dracd
%endif

BuildRequires: sendmail

Requires(pre): gawk grep shadow-utils
BuildRoot: %{_tmppath}/%{name}-%{version}-root
Distribution: Vine Linux
Vendor: Project Vine

%description
POP3 server from QUALCOMM, with the following features: lower memory
requirements, thus faster UIDL assists POP clients which "leave mail
on server" in determining which messages are new. Implements some
other extended POP3 commands. 

%prep
%setup -q -n %{name}%{version}

%build
%if %{USE_DRACD}
CFLAGS="$RPM_OPT_FLAGS" ./configure \
    --prefix=/usr \
    --enable-bulletins=/var/spool/mail/bulletins \
    --enable-specialauth \
    --with-pam=qpopper \
    --with-openssl=/usr/share/ssl \
    --with-popuid=pop \
    --enable-drac \
    --enable-apop=/etc/pop.auth
%else
CFLAGS="$RPM_OPT_FLAGS" ./configure \
    --prefix=/usr \
    --enable-bulletins=/var/spool/mail/bulletins \
    --enable-specialauth \
    --with-pam=qpopper \
    --with-openssl=/usr/share/ssl \
    --with-popuid=pop \
    --enable-apop=/etc/pop.auth
%endif
# smp flag makes make trouble...
# make %{?_smp_mflags}
make

%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT%{_sbindir}
mkdir -p $RPM_BUILD_ROOT%{_mandir}/man8
install -d -m 755 $RPM_BUILD_ROOT%{_sysconfdir}/pam.d/
install -m 755 -s popper/popper $RPM_BUILD_ROOT%{_sbindir}/in.qpopper
sed -e 's#/usr/local/lib/popper#%{_sbindir}/in.qpopper#g' < man/popper.8 > $RPM_BUILD_ROOT%{_mandir}/man8/in.qpopper.8
chmod 644 $RPM_BUILD_ROOT%{_mandir}/man8/in.qpopper.8
install -m 755 -s popper/popauth $RPM_BUILD_ROOT%{_sbindir}/popauth
install -m 644 man/popauth.8 $RPM_BUILD_ROOT%{_mandir}/man8/popauth.8
install -m 755 -d $RPM_BUILD_ROOT%{_var}/spool/mail/bulletins
install -m 755 -d $RPM_BUILD_ROOT%{_sysconfdir}/xinetd.d
install -m 644 %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/xinetd.d/qpopper

%if %{_dist_release}=="vl4"
# for Vine 4.x
install -m 664 %{SOURCE10} $RPM_BUILD_ROOT%{_sysconfdir}/pam.d/qpopper
%else
install -m 664 %{SOURCE11} $RPM_BUILD_ROOT%{_sysconfdir}/pam.d/qpopper
%endif



%pre
# Add the "pop" user
/usr/sbin/useradd -c "Pop Account" -u 110 \
    -s /bin/false -r -d /var/spool/mail pop 2> /dev/null || :
exit 0

%post
chown pop /usr/sbin/popauth
chmod u+s /usr/sbin/popauth

%postun
inetdconf_del () {
if [ -f /etc/inetd.conf ]; then
    TMP=`echo "$*" | sed 's/[ 	]\+/\[ 	]\\\+/g'`
    if !(grep  "^[ ]*$TMP" /etc/inetd.conf > /dev/null) then
	return 0;
    fi

    cp /etc/inetd.conf /etc/inetd.conf.rpmsave
    echo "create backup /etc/inetd.conf.rpmsave"

    LANG=C awk -vline="$TMP" '
    BEGIN {
	state = 0;
	key = "^[#]*[ ]*" line;
    }
    {
	if ($0 ~ /^# Added by rpm install script of /) {
	    state = 1;
	    comment = $0;
	    next;
	}
	if ($0 ~ key)
	    next;
	if (state == 1) {
	    print comment;
	    state = 0;
	}
	print $0;
    }
    ' < /etc/inetd.conf.rpmsave > /etc/inetd.conf
fi
}
if [ $1 = 0 ] ; then
  inetdconf_del "pop-3   stream  tcp     nowait  root    /usr/sbin/tcpd	in.qpopper"
fi

%triggerin -- inetd
inetdconf_add () {
if [ -f /etc/inetd.conf ]; then
    TMP=`echo "$*" | sed 's/[ 	]\+/\[ 	]\\\+/g'`
    if (grep  "^[ ]*$TMP" /etc/inetd.conf > /dev/null) then
	return 0;
    fi

    cp /etc/inetd.conf /etc/inetd.conf.rpmsave
    echo "create backup /etc/inetd.conf.rpmsave"

    LANG=C awk -vline="$*" -vpackage=%{name} '
    BEGIN {
	done = 0;
	split(line, field);
	key = "^[#]*[ ]*" field[1];
	lastline = "";
    }
    {
	if (($0 ~ key)) {
	    if ($0 !~ /^#/)
		printf("#");
	    printf($0 "\n");
            if (done == 0) { 
		printf(line "\n");
		done = 1;
	    }
	} else {
	    print $0;
	    lastline = $0;
        }
    }
    END {
	if (done == 0) {
	    if (lastline != "")
		printf("\n");
	    printf("# Added by rpm install script of " package " at " strftime() "\n");
	    printf(line "\n");
	}
    }
    ' < /etc/inetd.conf.rpmsave > /etc/inetd.conf
fi
}
echo "Added pop3 entry to inetd.conf by qpopper package"
inetdconf_add "pop-3   stream  tcp     nowait  root    /usr/sbin/tcpd	in.qpopper"

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)
%doc GUIDE.pdf License.txt README doc
%attr(-,root,mail) %dir %{_var}/spool/mail/bulletins
%{_sbindir}/in.qpopper
%{_sbindir}/popauth
%{_mandir}/man*/*
%defattr(644,root,root)
%config(noreplace) %{_sysconfdir}/xinetd.d/qpopper
%config %{_sysconfdir}/pam.d/qpopper

%changelog 
* Sun Mar 20 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 4.0.19-1
- update to 4.0.19
- add BuildRequires: sendmail

* Thu Aug 20 2009 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.0.18-3
- merge spec for Vine4.x and Vine5.x
- disable smp flag

* Wed Aug 19 2009 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.0.18-2
- update pam.d/qpopper again

* Tue Aug 18 2009 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.0.18-1
- new upstream release. 
- fix pam.d/qpopper file & module path in x86_64 env.
- change R:/BR: pam >= 1.0
- use smp_flag in make section

* Wed Oct 22 2008 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.0.14-1
- new upstream release.

* Fri Aug 15 2008 Shu KONNO <owa@bg.wakwak.com> 4.0.9-1vl5
- applied new versioning policy, spec in utf-8

* Sun May 27 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.0.9-0vl6
- rebuilt with new toolchain

* Sun Mar 11 2007 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.0.9-0vl5
- fix qpopper.xinetd again

* Wed Feb 07 2007 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.0.9-0vl4
- fix qpopper.xinetd
- add %triggerin -- inetd section
- remove inetdconf_add function from %post section
- add LANG=C into inetdconf_add/del function

* Sun Sep 17 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 4.0.9-0vl3
- add xinetd config file.
- check /etc/inetd.conf availability in %%post/%%postun script.

* Sun Sep 17 2006 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.0.9-0vl2
- Build for Vine 4.0/Seed
- disable dracd for POP before SMTP

* Mon Mar 27 2006 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.0.9-0vl1
- new upstream release.
- Build for Vine 3.2
- enable dracd for POP before SMTP
- enable openssl for pop3s

* Wed Aug 17 2005 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.0.8-0vl1
- new upstream release fix security bug.

* Sat May 28 2005 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 4.0.5-0vl2
- add Patch1 for fix CAN-2005-1151
- add Patch2 for fix CAN-2005-1152
- add Patch3 for fix compilers warnings "tempnam() are unsafe"

* Sat Mar 15 2003 Daisuke SUZUKI <daisuke@linux.or.jp> 4.0.5-0vl1
- new upstream release fix security bug.
  - http://archives.neohapsis.com/archives/bugtraq/2003-03/0152.html

* Sun Sep 29 2002 Daisuke SUZUKI <daisuke@linux.or.jp> 4.0.4-0vl1
- new upstream release
- use more rpmmacros

* Wed Mar 13 2002 Toru Sagami <sagami@vinelinux.org> 4.0.3-0vl2
- modify %%pre to create "pop" user as system account with uid 110 (< 500)
- add shadow-utils(/usr/sbin/useradd) for PreReq

* Sat Aug  4 2001 Jun Nishii <jun@vinelinux.org> 4.0.3-0vl1
- ver.up

* Tue Jul 10 2001 Jun Nishii <jun@vinelinux.org> 3.1.2-0vl2
- add pop account for apop

* Sun May 27 2001 <sagami@vinelinux.org>
- 3.1.2-0vl1: install manpage into %%{_mandir}

* Sun Jul 09 2000 MATSUBAYASHI 'Shaolin' Kohji <shaolin@rhythmaning.org>
- 3.0.2-0vl3
- fixed %files section to handle compressed man pages

* Mon May 29 2000 Yasuyuki Furukawa <furukawa@vinelinux.org>
- fixed postun for upgrade.

* Fri May 19 2000 Yasuyuki Furukawa <furukawa@vinelinux.org>
- updated to 3.0.2

* Wed May 10 2000 Yasuyuki Furukawa <furukawa@vinelinux.org>
- rewrite SPEC for Vine.
- add %post and unpost to modify /etc/inetd.conf

* Sat May 6 2000 Kazutoshi Morioka <aab36830@pop07.odn.ne.jp>
- Upgrade to qpopper-3.0.1

* Thu Feb 24 2000 Shingo Akagaki <dora@kondara.org>
- check spec file

* Sun Nov 7 1999 Toru Hoshina <t@kondara.org>
- be a NoSrc :-P

* Sun Aug 1 1999 Norihito Ohmori <ohmori@flatout.org>
- rebuild for glibc-2.1.x

* Fri Jul 9 1999 Norihito Ohmori <ohmori@flatout.org>
- fix APOP bug
