# Maintainer: Markus M. May <triplem@tu.archserver.org>
# Contributor: Paul Mattal <paul@archlinux.org>

pkgname=mailman
pkgver=2.1.14
pkgrel=2
pkgdesc="Mailing list manager with built in web access"
arch=('i686' 'x86_64')
license=('GPL')
url="http://www.list.org/"
depends=('python' 'smtp-server')
backup=('usr/lib/mailman/Mailman/mm_cfg.py')
install=$pkgname.install
source=("http://ftp.gnu.org/gnu/$pkgname/$pkgname-$pkgver.tgz"
        'mailman-2.1-build.patch'
        'rc.mailman'
        'xss-CVE-2011-0707.patch')
md5sums=('9ea163871ceccbd33fee4c9e335fcf7b'
         'ed04d062379eb21e39ce1e70e6b1ade2'
         '3d83d06d0ec3319bf3c7d9df5d18e89f'
         '8c7fd1c49c1817cb6f3b6643762f3e38')

# Dont forget to update install script if changing the UID/GID
_mailman_uid='80'
_mailman_gid='80'
_apache_uid='33'
_apache_gid='33'

build() {
  export LANG=C
  cd $srcdir/$pkgname-$pkgver

  # fix calls to /usr/bin/python
  find . -name '*.py' | xargs sed -i 's@^#!.*python$@#!/usr/bin/python@'

  # fix directory permissions to satisfy check_perms
  patch -Np1 -i ${srcdir}/mailman-2.1-build.patch
  patch -Np1 -i ${srcdir}/xss-CVE-2011-0707.patch
  
  ./configure --without-permcheck \
              --prefix=/usr/lib/mailman \
              --with-var-prefix=/var/lib/mailman \
              --with-mail-gid=$_mailman_uid \
              --with-username=$_mailman_uid \
              --with-groupname=$_mailman_gid \
              --with-cgi-gid=$_apache_gid \
              --with-python=/usr/bin/python2

  make
}

package() {
  cd $srcdir/$pkgname-$pkgver
  make DESTDIR=$pkgdir install

  # let's follow Fedora FHS way; Gentoo does it the other way round

  # Create a link so that the config file mm_cfg.py appears in config
  # directory /etc/mailman. We don't put mm_cfg.py in the config directory
  # because its executable code (python file) and the security policy wants
  # to keep executable code out of /etc and inside of a lib directory instead,
  # and because traditionally mm_cfg.py was in the Mailman subdirectory and
  # experienced mailman admins will expect to find it there. But having it
  # "appear" in the config directory is good practice and heading in the
  # right direction for FHS compliance.
  install -d -m755 ${pkgdir}/etc/${pkgname}
  ln -sv /usr/lib/mailman/Mailman/mm_cfg.py ${pkgdir}/etc/${pkgname}/mm_cfg.py

  # fix some permissions to satisfy check_perms
  chown -R $_mailman_uid:$_mailman_gid $pkgdir/{usr/lib/mailman,var/lib/mailman,etc/mailman/*}
  chown $_apache_uid:$_mailman_gid ${pkgdir}/var/lib/mailman/archives/private
  chmod 2770 ${pkgdir}/var/lib/mailman/archives/private
  chmod 2755 ${pkgdir}/usr/lib/mailman/cgi-bin/* 
  chmod 2755 ${pkgdir}/usr/lib/mailman/mail/mailman
  
  # install the launch script
  install -D -m755 $srcdir/rc.mailman $pkgdir/etc/rc.d/mailman
}

# vim:set ts=2 sw=2 et:
