/uip/whatnow
/uip/whom
/uip/*.exe
+/test/getfullname
# Removed by mostlyclean:
*.o
## Important note: the "cleanup" test should always be last
##
TESTS = test/bad-input/test-header test/folder/test-create \
- test/folder/test-total test/inc/test-deb359167 test/inc/test-eom-align \
+ test/folder/test-total test/format/test-localmbox \
+ test/format/test-myname test/format/test-myhost \
+ test/format/test-mymbox \
+ test/inc/test-deb359167 test/inc/test-eom-align \
test/manpages/test-manpages test/mhbuild/test-forw \
test/mhshow/test-cte-binary test/mhshow/test-qp \
test/mhshow/test-subpart test/new/test-basic test/pick/test-stderr \
test/whatnow/test-ls test/cleanup
check_SCRIPTS = test/common.sh
+check_PROGRAMS = test/getfullname
##
## Stuff that should be cleaned via "make clean"
uip_viamail_SOURCES = uip/viamail.c uip/mhmisc.c uip/mhoutsbr.c uip/sendsbr.c \
uip/annosbr.c uip/distsbr.c
+test_getfullname_SOURCES = test/getfullname.c
+test_getfullname_LDADD =
+
##
## Our rebuild rules for files that aren't built via the normal mechanisms
##
export MH_INST_DIR=${MH_TEST_DIR}/inst
export MHMTSCONF=${MH_INST_DIR}${sysconfdir}/mts.conf
export PATH=${MH_INST_DIR}${bindir}:${PATH}
+ export MH_LIB_DIR=${MH_INST_DIR}${auxexecdir}
if [ -z "${srcdir}" ]; then
echo "srcdir not set; aborting"
mkdir $MH_TEST_DIR/Mail || exit 1
cat > $MH <<EOF || exit 1
Path: ${MH_TEST_DIR}/Mail
-mhlproc: ${MH_INST_DIR}${auxexecdir}/mhl
+mhlproc: ${MH_LIB_DIR}/mhl
EOF
for f in MailAliases components digestcomps distcomps forwcomps mhl.body \
--- /dev/null
+#!/bin/sh
+#
+# Test that we can retrieve the local mailbox name from the profile via
+# component functions
+#
+
+if [ -z "${MH_TEST_COMMON}" ]; then
+ echo "MH_TEST_COMMON not set; try running via 'make check'"
+fi
+
+. ${MH_TEST_COMMON}
+
+setup_test
+
+testname="Some User <some@domain.com>"
+
+echo "Local-Mailbox: ${testname}" >> ${MH}
+
+# We can use "ap" to get the output of format commands
+
+testoutput=$(${MH_LIB_DIR}/ap -format "%(profile Local-Mailbox)" ignore)
+
+if [ x"${testname}" != x"${testoutput}" ]; then
+ echo "Expected ${testname}, got ${testoutput}"
+ exit 1
+fi
+
+exit 0
--- /dev/null
+#!/bin/sh
+#
+# Test that the %(myhost) function returns the local hostname and
+# the localname entry out of the mts configuration file.
+#
+
+if [ -z "${MH_TEST_COMMON}" ]; then
+ echo "MH_TEST_COMMON not set; try running via 'make check'"
+fi
+
+. ${MH_TEST_COMMON}
+
+setup_test
+
+runtest()
+{
+ testoutput=$(${MH_LIB_DIR}/ap -format "%(myhost)" ignore)
+
+ if [ x"$1" != x"${testoutput}" ]; then
+ echo "For $2, expected $1 but got ${testoutput}"
+ exit 1
+ fi
+}
+
+runtest "$(hostname)" "local hostname test"
+
+cp ${MHMTSCONF} ${MH_TEST_DIR}/Mail/mts.conf || exit 1
+export MHMTSCONF="${MH_TEST_DIR}/Mail/mts.conf"
+
+echo "localname: some.random.name" >> ${MHMTSCONF}
+
+runtest "some.random.name" "mts.conf localname test"
+
+exit 0
--- /dev/null
+#!/bin/sh
+#
+# Test that the %(mymbox) function correctly determines whether or not
+# a particular email address is "mine" or not
+#
+
+if [ -z "${MH_TEST_COMMON}" ]; then
+ echo "MH_TEST_COMMON not set; try running via 'make check'"
+fi
+
+. ${MH_TEST_COMMON}
+
+setup_test
+
+runtest()
+{
+ testoutput=$(${MH_LIB_DIR}/ap -format "%(mymbox{text})" "$1")
+
+ if [ -z "${testoutput}" ]; then
+ echo "Test program did not return anything for $3"
+ exit 1
+ fi
+
+ if [ "${testoutput}" -ne $2 ]; then
+ echo "Did not get expected output for $3"
+ exit 1
+ fi
+}
+
+user="$(id -un)"
+host="$(hostname)"
+
+runtest "${user}" 1 "Basic user test"
+runtest "${user}@${host}" 1 "Basic user@host test"
+runtest "nosuchuser@nosuchhost.blah" 0 "Basic non-matching test"
+
+myname="Random User <random@user.something.com>"
+
+echo "Local-Mailbox: ${myname}" >> ${MH}
+
+runtest "${myname}" 1 "Local-Mailbox test"
+runtest "${user}@${host}" 0 "Local-mailbox overriding user@host test"
+
+exit 0
--- /dev/null
+#!/bin/sh
+#
+# Test that we can retrieve the local username via the passwd file,
+# the Signature profile entry, and via SIGNATURE environment variable.
+#
+
+if [ -z "${MH_TEST_COMMON}" ]; then
+ echo "MH_TEST_COMMON not set; try running via 'make check'"
+fi
+
+. ${MH_TEST_COMMON}
+
+setup_test
+
+unset SIGNATURE
+
+runtest()
+{
+ testoutput=$(${MH_LIB_DIR}/ap -format "%(myname)" ignore)
+
+ if [ x"$1" != x"${testoutput}" ]; then
+ echo "For $2, expected $1 but got ${testoutput}"
+ exit 1
+ fi
+}
+
+runtest "$(${MH_OBJ_DIR}/test/getfullname)" "GECOS field test"
+
+echo "Signature: Some Random Name 1" >> ${MH}
+
+runtest "Some Random Name 1" "MH Profile Signature test"
+
+export SIGNATURE="Some Random Name 2"
+
+runtest "${SIGNATURE}" "SIGNATURE Environment test"
+
+exit 0
--- /dev/null
+/*
+ * getfullname.c - Extract a user's name out of the GECOS field in
+ * the password file.
+ *
+ * This code is Copyright (c) 2012, by the authors of nmh. See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <pwd.h>
+
+int
+main(int argc, char *argv[])
+{
+ struct passwd *pwd;
+
+ pwd = getpwuid(getuid());
+
+ if (! pwd) {
+ fprintf(stderr, "Unable to retrieve user info for "
+ "userid %d\n", getuid());
+ exit(1);
+ }
+
+ printf("%s\n", pwd->pw_gecos);
+
+ exit(0);
+}