From 53e7e08da96bfcaa3f8f1d081ab5fd772c7f8242 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 12 Dec 2013 21:34:26 +0100
Subject: [PATCH] mailx: sync patches with Fedora; cross build support.

---
 .../mailx/patches/mailx-12.5-collect.patch    | 13 +++++
 .../mailx/patches/mailx-12.5-fname-null.patch | 12 +++++
 srcpkgs/mailx/patches/mailx-12.5-lzw.patch    | 12 +++++
 srcpkgs/mailx/patches/mailx-12.5-usage.patch  | 12 +++++
 srcpkgs/mailx/template                        | 54 ++++++-------------
 5 files changed, 66 insertions(+), 37 deletions(-)
 create mode 100644 srcpkgs/mailx/patches/mailx-12.5-collect.patch
 create mode 100644 srcpkgs/mailx/patches/mailx-12.5-fname-null.patch
 create mode 100644 srcpkgs/mailx/patches/mailx-12.5-lzw.patch
 create mode 100644 srcpkgs/mailx/patches/mailx-12.5-usage.patch

diff --git a/srcpkgs/mailx/patches/mailx-12.5-collect.patch b/srcpkgs/mailx/patches/mailx-12.5-collect.patch
new file mode 100644
index 00000000000..b84d2e8f365
--- /dev/null
+++ b/srcpkgs/mailx/patches/mailx-12.5-collect.patch
@@ -0,0 +1,13 @@
+--- mailx-12.4.orig/collect.c	2012-09-12 16:07:53.653103796 -0400
++++ mailx-12.4/collect.c	2012-09-12 21:27:05.092259236 -0400
+@@ -905,7 +905,9 @@ err:
+ 	if (collf != NULL) {
+ 		Fclose(collf);
+ 		collf = NULL;
+-	}
++	} else {
++        exit(1);
++    }
+ out:
+ 	if (collf != NULL) {
+ 		if ((cp = value("MAILX_TAIL")) != NULL) {
diff --git a/srcpkgs/mailx/patches/mailx-12.5-fname-null.patch b/srcpkgs/mailx/patches/mailx-12.5-fname-null.patch
new file mode 100644
index 00000000000..056e97f9488
--- /dev/null
+++ b/srcpkgs/mailx/patches/mailx-12.5-fname-null.patch
@@ -0,0 +1,12 @@
+diff -upr mailx-12.5.orig/names.c mailx-12.5/names.c
+--- mailx-12.5.orig/names.c	2006-03-04 01:32:16.000000000 +0100
++++ mailx-12.5/names.c	2012-11-01 15:28:43.883573793 +0100
+@@ -357,7 +357,7 @@ outof(struct name *names, FILE *fo, stru
+ 			free_child(pid);
+ 		} else {
+ 			int f;
+-			if ((fout = Zopen(fname, "a", NULL)) == NULL) {
++			if ((fname == NULL) || ((fout = Zopen(fname, "a", NULL)) == NULL)) {
+ 				perror(fname);
+ 				senderr++;
+ 				goto cant;
diff --git a/srcpkgs/mailx/patches/mailx-12.5-lzw.patch b/srcpkgs/mailx/patches/mailx-12.5-lzw.patch
new file mode 100644
index 00000000000..2dc1fbccf93
--- /dev/null
+++ b/srcpkgs/mailx/patches/mailx-12.5-lzw.patch
@@ -0,0 +1,12 @@
+diff -Nrbu mailx-12.5/lzw.c mailx-12.5-OK/lzw.c
+--- mailx-12.5/lzw.c	2006-03-04 03:32:16.000000000 +0300
++++ mailx-12.5-OK/lzw.c	2011-08-17 16:30:01.000000000 +0400
+@@ -516,6 +516,8 @@
+ 
+ 		/* Generate output characters in reverse order. */
+ 		while (code >= 256) {
++			if (stackp - de_stack >= HSIZE - 1)
++				return -1;
+ 			*stackp++ = tab_suffixof(code);
+ 			code = tab_prefixof(code);
+ 		}
diff --git a/srcpkgs/mailx/patches/mailx-12.5-usage.patch b/srcpkgs/mailx/patches/mailx-12.5-usage.patch
new file mode 100644
index 00000000000..3c375ade9b0
--- /dev/null
+++ b/srcpkgs/mailx/patches/mailx-12.5-usage.patch
@@ -0,0 +1,12 @@
+diff -upr mailx-12.5.orig/main.c mailx-12.5/main.c
+--- mailx-12.5.orig/main.c	2007-10-02 14:15:50.000000000 +0200
++++ mailx-12.5/main.c	2013-07-22 16:06:56.960765683 +0200
+@@ -353,7 +353,7 @@ main(int argc, char *argv[])
+ 		case '?':
+ usage:
+ 			fprintf(stderr, catgets(catd, CATSET, 135,
+-"Usage: %s -eiIUdEFntBDNHRV~ -T FILE -u USER -h hops -r address -s SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT -b USERS -c USERS -S OPTION users\n"), progname);
++"Usage: %s -eiIUdEFntBDNHRVv~ -T FILE -u USER -h hops -r address -s SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT -b USERS -c USERS -S OPTION users\n"), progname);
+ 			exit(2);
+ 		}
+ 	}
diff --git a/srcpkgs/mailx/template b/srcpkgs/mailx/template
index 7989f038749..be5017a1159 100644
--- a/srcpkgs/mailx/template
+++ b/srcpkgs/mailx/template
@@ -1,63 +1,43 @@
 # Template file for 'mailx'
 pkgname=mailx
 version=12.5
-revision=2
+revision=3
 patch_args="-Np1"
-wrksrc=mailx-${version}
+wrksrc="mailx-${version}"
 makedepends="openssl-devel mit-krb5-devel"
 short_desc="Feature-rich BSD mail(1)"
 homepage="http://heirloom.sourceforge.net/mailx.html"
-license="Custom"
+license="BSD"
 maintainer="Juan RP <xtraeme@gmail.com>"
-distfiles="http://pkgs.fedoraproject.org/repo/pkgs/mailx/mailx-12.5.tar.xz/836bf1da322d2d1f78b7056c2b3b2304/${pkgname}-${version}.tar.xz"
+distfiles="http://pkgs.fedoraproject.org/repo/pkgs/mailx/mailx-${version}.tar.xz/836bf1da322d2d1f78b7056c2b3b2304/${pkgname}-${version}.tar.xz"
 checksum=1b8136fb2466adeaf71a5e3c65db9fa1a967f1f6469ff689c2cf06e21f638823
-long_desc="
- Mailx is an enhanced mail command, which provides the functionality
- of the POSIX mailx command, as well as SysV mail and Berkeley Mail
- (from which it is derived).
-
- Additionally to the POSIX features, mailx can work with Maildir/ e-mail
- storage format (as well as mailboxes), supports IMAP, POP3 and SMTP
- procotols (including over SSL) to operate with remote hosts, handles mime
- types and different charsets. There are a lot of other useful features,
- see mailx(1).
-
- And as its ancient analogues, mailx can be used as a mail script language,
- both for sending and receiving mail.
-
- Besides the "mailx" command, this package provides "mail" and "Mail"
- (which should be compatible with its predecessors from the mailx-8.x source),
- as well as "nail" (the initial name of this project)."
-
-disable_parallel_build=yes
 
 do_build() {
-	echo	PREFIX=/usr 		\
-		BINDIR=/bin 		\
-		MANDIR=/usr/share/man	\
-		SYSCONFDIR=/etc		\
-		MAILRC=/etc/mail.rc	\
+	echo	PREFIX=/usr 			\
+		BINDIR=/usr/bin 		\
+		MANDIR=/usr/share/man		\
+		SYSCONFDIR=/etc			\
+		MAILRC=/etc/mail.rc		\
 		MAILSPOOL=/var/spool/mail	\
-		UCBINSTALL=install	\
-	> ${wrksrc}/makeflags
+		UCBINSTALL=install		\
+		STRIP=$STRIP			\
+		SENDMAIL=/usr/bin/sendmail	\
+	> makeflags
 
-	make $(cat makeflags) CFLAGS="${CFLAGS} -D_GNU_SOURCE" \
-		IPv6=-DHAVE_IPv6_FUNCS
+	make $(cat makeflags) IPv6=-DHAVE_IPv6_FUNCS \
+		CFLAGS="${CFLAGS} -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64"
 }
 
 do_install() {
 	make DESTDIR=${DESTDIR} $(cat makeflags) install
 
-	ln -s mailx ${DESTDIR}/bin/mail
-	ln -s mailx ${DESTDIR}/bin/Mail
+	ln -s mailx ${DESTDIR}/usr/bin/mail
 	ln -s mailx.1 ${DESTDIR}/usr/share/man/man1/mail.1
-	ln -s mailx.1 ${DESTDIR}/usr/share/man/man1/Mail.1
 }
 
 mailx_package() {
 	conf_files="/etc/mail.rc"
 	pkg_install() {
-		vmove etc
-		vmove usr
+		vmove all
 	}
 }