aboutsummaryrefslogtreecommitdiffstats
path: root/xml
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-06-22 08:38:09 -0400
committerW. Trevor King <wking@drexel.edu>2009-06-22 08:38:09 -0400
commitbfeb35712e37acfd7f393c9ca6f9d67090dab739 (patch)
treea4d4cef7ac79c69cdd6e787c5caeed03ade7dd2c /xml
parent2553cc43edd5a792c2f12d10ea1ab4f8cd771cc1 (diff)
downloadbugseverywhere-bfeb35712e37acfd7f393c9ca6f9d67090dab739.tar.gz
Converted xml/grepm to xml/catmutt.
Now $ cat example.mbox | catmutt works. Onwards to be-xml-to-mbox!
Diffstat (limited to 'xml')
-rwxr-xr-xxml/catmutt59
-rw-r--r--xml/grepm65
2 files changed, 59 insertions, 65 deletions
diff --git a/xml/catmutt b/xml/catmutt
new file mode 100755
index 0000000..246bf39
--- /dev/null
+++ b/xml/catmutt
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+# catmutt - wrap mutt allowing mboxes read from stdin.
+#
+# Copyright (C) 1998-1999 Moritz Barsnick <barsnick (at) gmx (dot) net>,
+# 2009 William Trevor King <wking (at) drexel (dot) edu>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# version 2 as published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# developed from grepm-0.6
+# http://www.barsnick.net/sw/grepm.html
+
+PROGNAME=`basename "$0"`
+export TMPDIR="${TMPDIR-/tmp}" # used by mktemp
+umask 077
+
+if [ $# -gt 0 ] && [ "$1" = "--help" ]; then
+ echo 1>&2 "Usage: ${PROGNAME} [--help] mutt-arguments"
+ echo 1>&2 ""
+ echo 1>&2 "Read a mailbox file from stdin and opens it with mutt."
+ echo 1>&2 "For example: cat somefile.mbox | ${PROGNAME}"
+ exit 0
+fi
+
+# Note: the -t/-p options to mktemp are deprecated for mktemp (GNU
+# coreutils) 7.1 in favor of --tmpdir but the --tmpdir option does not
+# exist yet for my 6.10-3ubuntu2 coreutils
+TMPFILE=`mktemp -t catmutt.XXXXXX` || exit 1
+
+trap "rm -f ${TMPFILE}; exit 1" 1 2 3 13 15
+
+cat > "${TMPFILE}" || exit 1
+
+# Now that we've read in the mailbox file, reopen stdin for mutt/user
+# interaction. We're not technically in a tty, so use a little hack
+# from "greno" at
+# http://www.linuxforums.org/forum/linux-programming-scripting/98607-bash-stdin-problem.html
+tty="/dev/$(ps -p$$ --no-heading | awk '{print $2}')"
+exec < ${tty}
+
+if [ `wc -c "${TMPFILE}" | awk '{print $1}'` -gt 0 ]; then
+ echo 1>&2 "Calling mutt on mailbox file (${TMPFILE})."
+ mutt -R -f "${TMPFILE}" "$@"
+else
+ echo 1>&2 "Empty mailbox input."
+fi
+
+rm -f "${TMPFILE}" && echo 1>&2 "Deleted results file (${TMPFILE})."
diff --git a/xml/grepm b/xml/grepm
deleted file mode 100644
index cf5472a..0000000
--- a/xml/grepm
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/bin/sh
-
-# grepm - a wrapper for grepmail utilizing mutt
-
-# Copyright (C) 1998-1999 Moritz Barsnick <barsnick (at) gmx (dot) net>
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# version 2 as published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# grepm-0.6
-#
-# written 1998-11-xx by Moritz Barsnick <barsnick (at) gmx (dot) net>
-# updated 1998-12-22: added "-m" option for grepmail
-# added "exit 1" to trap
-# updated 1999-01-04: added check for empty "mailbox" (don't open mutt)
-# added messages
-# added umask (to keep others from reading your messages)
-# updated 1999-01-19: added trap for SIGPIPE (any other suggestions?)
-# updated 1999-07-05: added $TMPDIR; we're still subject to races ($TMPFILE
-# might exist)
-# updated 1999-11-29: have mutt open the temporary mailbox read-only -
-# there's no use in editing it anyway
-
-
-PROGNAME=`basename "$0"`
-TMPDIR=${TMPDIR-/tmp}
-
-umask 077
-
-if [ $# -lt 1 ]; then
- echo 1>&2 "Usage: ${PROGNAME} arguments"
- exit 1
-fi
-
-TMPFILE="${TMPDIR}/grepmail-output.$$"
-
-# I _would_ check this with "-e", but not all /bin/sh's understand it
-# so this is just a kludge
-
-if [ -f ${TMPFILE} -o -d ${TMPFILE} -o -w ${TMPFILE} ]; then
- echo 1>&2 "Temporary file ${TMPFILE} exists for some reason! Aborting."
- exit 1
-fi
-
-trap "rm -f ${TMPFILE}; exit 1" 1 2 3 13 15
-
-grepmail -m "$@" > "${TMPFILE}"
-if [ `wc -c "${TMPFILE}" | awk '{print $1}'` -gt 0 ]; then
- echo 1>&2 "Calling mutt on results file (${TMPFILE})."
- mutt -R -f "${TMPFILE}"
-else
- echo 1>&2 "No matches."
-fi
-
-rm -f "${TMPFILE}" && echo 1>&2 "Deleted results file (${TMPFILE})."