# Maintainer: Schnouki <thomas.jost@gmail.com>
# Contributor: Hinrich Harms <arch@hinrich.de>
pkgname=enigmail
pkgver=1.1
pkgrel=1
_tb_ver=3.1rc1
_tb_libdir=thunderbird-3.1 # Adjust this to your thunderbird directory in /usr/lib
_comm_dir=comm-1.9.2
pkgdesc="OpenPGP security extension for Mozilla Thunderbird 3"
arch=('i686' 'x86_64')
url="http://enigmail.mozdev.org"
license=('MPL' 'GPL')
depends=('gnupg' 'thunderbird')
makedepends=('zip')
options=('!ccache' '!distcc')
source=("http://www.mozilla-enigmail.org/download/source/${pkgname}-${pkgver}.tar.gz"
"http://releases.mozilla.org/pub/mozilla.org/thunderbird/releases/${_tb_ver}/source/thunderbird-${_tb_ver}.source.tar.bz2"
"mozconfig")
md5sums=('6304088073928e22f08ab756894329f4'
'b47a9a014f10a383741bf2806990a796'
'ec786d343c0f951dfd71df0438c1f0ce')
sha1sums=('4d0d13913092dfd3f2600040d53d4d13edf4e555'
'0febfacf411e3428d94013910ed9fb77329e0a78'
'b2b9dcace7e54d6cbcaf34373a89bb80c131f241')
build() {
# The build guide is available online:
# http://enigmail.mozdev.org/download/source.php
# Compile needed parts of Thunderbird
cd $srcdir/$_comm_dir
export MOZCONFIG="$startdir/mozconfig"
make -f client.mk export || return 1
cd mozilla/modules/libreg
make || return 1
cd ../../xpcom/string
make || return 1
cd ..
make || return 1
cd obsolete
make || return 1
# Now Enigmail
mv $srcdir/enigmail $srcdir/$_comm_dir/mailnews/extensions/enigmail
cd $srcdir/$_comm_dir/mailnews/extensions/enigmail
./makemake -r || return 1
make || return 1
# Create XPI archive
make xpi || return 1
# Install to the Thunderbird lib directory
# If someone knows a better way to extract the em:id, please let me know :)
_emid=`grep em:id package/install.rdf | head -n1 | sed 's/.*>\(.*\)<.*/\1/'`
mkdir -p $pkgdir/usr/lib/$_tb_libdir/extensions/$_emid
cd $pkgdir/usr/lib/$_tb_libdir/extensions/$_emid
# Look for the current (highest) version number of the XPI
_xpidir=$srcdir/$_comm_dir/mozilla/dist/bin
_xpifullpath=`ls $_xpidir/enigmail-*-linux-$CARCH.xpi | sort | sed -n '$p'`
bsdtar -x -f $_xpifullpath || return 1
# Fix permissions
find -type d -exec chmod 0755 \{\} \+ || return 1
find -type f -exec chmod 0644 \{\} \+ || return 1
find -name '*.so' -exec chmod 0755 \{\} \+
}