Commit 1ae763d4 1ae763d4ecb847ea17dbaf97565af58dae832d02 by Sergey Poznyakoff

mh: further improvements in mnh & mh testsuite.

* mh/mhn.c (_mhn_profile_get): Try mhn-<prefix>-<type> if
mhn-<prefix>-<type>/<subtype> does not exist.
(normalize_path): Use mu_normalize_path.
(store_handler) <store_to_file>: Honor mhn-<prefix>, if set.
* tests/atlocal.in (remove_curdir): New function.
* mh/tests/mhn.at: Implement more -store tests.
* mh/tests/testsuite.at (MH_SETUP): Set curdir for use by other testcases.
* mh/tests/comp.at: Use remove_curdir to sort out the cwd.
* mh/tests/forw.at: Likewise.
* mh/tests/mark.at: Likewise.
* mh/tests/mhpath.at: Likewise.
* mh/tests/repl.at: Likewise.
1 parent 7dcee33a
......@@ -585,17 +585,16 @@ _mhn_profile_get (const char *prefix, const char *type, const char *subtype,
const char *defval)
{
char *name;
const char *str;
const char *str = NULL;
if (subtype)
{
mu_asprintf (&name, "mhn-%s-%s/%s", prefix, type, subtype);
str = mh_global_profile_get (name, NULL);
free (name);
if (!str)
return _mhn_profile_get (prefix, type, NULL, defval);
}
else
if (!str)
{
mu_asprintf (&name, "mhn-%s-%s", prefix, type);
str = mh_global_profile_get (name, defval);
......@@ -1533,58 +1532,16 @@ mhn_show ()
char *
normalize_path (const char *cwd, char *path)
{
int len;
char *p;
size_t len;
char *pcwd = NULL;
if (!path)
return path;
if (path[0] == '/')
return NULL;
if (!cwd)
cwd = pcwd = mu_getcwd ();
path = mh_safe_make_file_name (cwd, path);
/* delete trailing delimiter if any */
if (len && path[len-1] == '/')
path[len-1] = 0;
/* Eliminate any /../ */
for (p = strchr (path, '.'); p; p = strchr (p, '.'))
{
if (p > path && p[-1] == '/')
{
if (p[1] == '.' && (p[2] == 0 || p[2] == '/'))
/* found */
{
char *q, *s;
/* Find previous delimiter */
for (q = p-2; *q != '/' && q >= path; q--)
;
if (q < path)
break;
/* Copy stuff */
s = p + 2;
p = q;
while ((*q++ = *s++))
;
continue;
}
}
p++;
}
if (path[0] == 0)
{
path[0] = '/';
path[1] = 0;
}
path = mu_normalize_path (mh_safe_make_file_name (cwd, path));
len = strlen (cwd);
if (strlen (path) < len || memcmp (path, cwd, len))
......@@ -1694,6 +1651,18 @@ store_handler (mu_message_t msg, msg_part_t part, char *type, char *encoding,
break;
case store_to_file:
if (dir && name[0] != '/')
{
char *s = mu_make_file_name (dir, name);
if (!s)
{
rc = ENOMEM;
mu_diag_funcall (MU_DIAG_ERROR, "mu_make_file_name", NULL, rc);
break;
}
free (name);
name = s;
}
printf (_("storing message %s part %s as file %s\n"),
prefix, partstr, name);
......
......@@ -3,4 +3,6 @@
# Copyright (C) 2004, 2010 Free Software Foundation, Inc.
PATH=@abs_builddir@:@abs_top_builddir@/mh:$top_srcdir:$srcdir:$PATH
\ No newline at end of file
remove_curdir() {
sed "s|$curdir/*||;s| *$||" $*
}
......
......@@ -18,8 +18,7 @@ m4_pushdef([MH_KEYWORDS],[comp])
m4_pushdef([compcmd],[comp -editor $abs_top_srcdir/mh/tests/mhed])
MH_CHECK([comp -file],[comp00 comp-file],[
dir=`pwd`
echo quit | compcmd -file ./infile | sed "s|$dir/*||;s| *$||"
echo quit | compcmd -file ./infile | remove_curdir
cat infile
],
[0],
......@@ -39,8 +38,7 @@ Seen by mhed
])
MH_CHECK([comp -file (del)],[comp01 comp-file_del],[
dir=`pwd`
echo 'quit -delete' | compcmd -file ./infile | sed "s|$dir/*||;s| *$||"
echo 'quit -delete' | compcmd -file ./infile | remove_curdir
],
[0],
[-- Editor invocation: ./infile
......@@ -53,7 +51,7 @@ Subject:
What now?])
MH_CHECK([comp file],[comp02 comp_file],[
echo 'quit' | compcmd file | sed "s|$dir/*||;s| *$||"
echo 'quit' | compcmd file | remove_curdir
cat Mail/file
],
[0],
......@@ -80,7 +78,7 @@ Subject: test input
message body
])
echo 'quit' | compcmd -use file | sed "s|$dir/*||;s| *$||"
echo 'quit' | compcmd -use file | remove_curdir
cat Mail/file
],
[0],
......@@ -110,7 +108,7 @@ Subject: test input
message body
])
echo 'quit' | compcmd +inbox 1 | sed "s|$dir/*||;s| *$||"
echo 'quit' | compcmd +inbox 1 | remove_curdir
echo Mail/draft
cat Mail/draft
echo Message
......@@ -143,8 +141,7 @@ message body
MH_CHECK([comp -draftfolder],[comp05 comp-draftfolder draftfolder],[
mkdir Mail/drafts
dir=`pwd`
echo 'quit' | compcmd -draftfolder drafts | sed "s|$dir/*||;s| *$||"
echo 'quit' | compcmd -draftfolder drafts | remove_curdir
cat Mail/drafts/1
],
[0],
......@@ -173,8 +170,7 @@ message body
])
echo "cur: 1" > Mail/drafts/.mh_sequences
dir=`pwd`
echo 'quit' | compcmd -draftfolder drafts -use| sed "s|$dir/*||;s| *$||"
echo 'quit' | compcmd -draftfolder drafts -use| remove_curdir
cat Mail/drafts/1
],
[0],
......
......@@ -26,8 +26,7 @@ Subject: test input
message body
])
dir=`pwd`
echo quit | forwcmd +inbox 1 | sed "s|$dir/*||;s| *$||"
echo quit | forwcmd +inbox 1 | remove_curdir
echo == Mail/draft ==
cat Mail/draft
echo == Message ==
......@@ -87,8 +86,7 @@ Subject: test input
message body
])
dir=`pwd`
echo quit | forwcmd -format +inbox 1 | sed "s|$dir/*||;s| *$||"
echo quit | forwcmd -format +inbox 1 | remove_curdir
echo == Mail/draft ==
cat Mail/draft
echo == Message ==
......@@ -154,8 +152,7 @@ Subject: 2nd message
2nd message body
])
dir=`pwd`
echo quit | forwcmd +inbox 1 2 | sed "s|$dir/*||;s| *$||"
echo quit | forwcmd +inbox 1 2 | remove_curdir
echo == Mail/draft ==
cat Mail/draft
echo == Message 1 ==
......@@ -239,8 +236,7 @@ Subject: test input
message body
])
dir=`pwd`
forwcmd -build +inbox 1 | sed "s|$dir/*||;s| *$||"
forwcmd -build +inbox 1 | remove_curdir
echo == Mail/draft ==
cat Mail/draft
echo == Message ==
......@@ -285,10 +281,9 @@ Subject: 2nd message
2nd message body
])
dir=`pwd`
forwcmd -build -mime +inbox 1 2 | sed "s|$dir/*||;s| *$||"
forwcmd -build -mime +inbox 1 2 | remove_curdir
echo == Mail/draft ==
sed "s|$dir/*||;s| *$||" Mail/draft
remove_curdir Mail/draft
echo == Message 1 ==
sed '/^X-IMAPbase/d' Mail/inbox/1
echo == Message 2 ==
......@@ -326,7 +321,7 @@ Subject: test input
message body
])
echo "quit" | forwcmd -draftfolder drafts 1 | sed "s|$dir/*||;s| *$||"
echo "quit" | forwcmd -draftfolder drafts 1 | remove_curdir
echo == Mail/drafts/1 ==
cat Mail/drafts/1
echo == Message ==
......@@ -383,7 +378,7 @@ Subject: test input
message body
])
echo "quit" | forwcmd -file infile | sed "s|$dir/*||;s| *$||"
echo "quit" | forwcmd -file infile | remove_curdir
],
[0],
[-- Editor invocation: Mail/draft
......
......@@ -44,7 +44,6 @@ MH_CHECK([mark -add -nopublic],[mark02 mark-add-nopublic],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
echo 'Current-Folder: inbox' > Mail/context
mark -nopublic -sequence andro -add 1 2 3
dir=`pwd`
sed -n '/^atr-andro/{s/ */ /g;s/ $//;s/^[[^:]]*:/atr-andro:/;p}' Mail/context
],
[0],
......
......@@ -127,5 +127,144 @@ Do you think I can listen all day to such stuff?
Be off, or I'll kick you down stairs!'
])
MH_CHECK([mhn -store -auto],[mhn03 mhn-store-auto],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
mhn +inbox -store -auto 4 | remove_curdir || exit $?
],
[0],
[storing message 4 part 1 as file msg.21
storing message 4 part 2.1 as file msg.22
storing message 4 part 2.2.1 as file msg.23
storing message 4 part 2.2.2 as file msg.24
])
MH_CHECK([mhn -store -auto -part],[mhn04 mhn-store-auto-part],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
mhn +inbox -store -auto -part 2.2.1 4 | remove_curdir || exit $?
],
[0],
[storing message 4 part 2.2.1 as file msg.23
])
MH_CHECK([mhn -store -auto (pathname safety)],[mhn05 mhn-store-auto-safety],[
mkdir Mail/inbox
sed 's|; *name="msg|; name="../msg|' \
$abs_top_srcdir/testsuite/mh/mbox1/4 > Mail/inbox/4
mhn +inbox -store -auto -part 2.1 4 || echo $?
echo == 4.2.1.octet-stream ==
cat 4.2.1.octet-stream
],
[0],
[storing message 4 part 2.1 as file 4.2.1.octet-stream
== 4.2.1.octet-stream ==
`You are old,' said the youth, `as I mentioned before,
And have grown most uncommonly fat;
Yet you turned a back-somersault in at the door--
Pray, what is the reason of that?'
`In my youth,' said the sage, as he shook his grey locks,
`I kept all my limbs very supple
By the use of this ointment--one shilling the box--
Allow me to sell you a couple?'
])
MH_CHECK([mhn-storage],[mhn06 mhn-store-auto],[
mkdir Mail/inbox
cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
mkdir out
echo "mhn-storage: $curdir/out" >> $MH
mhn +inbox -store 4 | remove_curdir || echo $?
],
[0],
[storing message 4 part 1 as file out/4.1.plain
storing message 4 part 2.1 as file out/4.2.1.octet-stream
storing message 4 part 2.2.1 as file out/4.2.2.1.octet-stream
storing message 4 part 2.2.2 as file out/4.2.2.2.octet-stream
])
MH_CHECK([mhn-store-: all escapes],[mhn07 mhn-store_escapes],[
mkdir Mail/inbox
cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
echo "mhn-store-application: %%-%m%P.%s-%p" >> $MH
mhn +inbox -store 4 | remove_curdir || exit $?
find . -name '%*'
],
[0],
[storing message 4 part 1 as file 4.1.plain
storing message 4 part 2.1 as file %4.2.1.octet-stream-2.1
storing message 4 part 2.2.1 as file %4.2.2.1.octet-stream-2.2.1
storing message 4 part 2.2.2 as file %4.2.2.2.octet-stream-2.2.2
./%4.2.1.octet-stream-2.1
./%4.2.2.1.octet-stream-2.2.1
./%4.2.2.2.octet-stream-2.2.2
])
MH_CHECK([mhn-store-: absolute path],[mhn08 mhn-store_abspath],[
mkdir Mail/inbox
mkdir out
cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
echo "mhn-store-application: $curdir/out/%m%P.%s" >> $MH
mhn +inbox -store 4 | remove_curdir || exit $?
],
[0],
[storing message 4 part 1 as file 4.1.plain
storing message 4 part 2.1 as file out/4.2.1.octet-stream
storing message 4 part 2.2.1 as file out/4.2.2.1.octet-stream
storing message 4 part 2.2.2 as file out/4.2.2.2.octet-stream
])
MH_CHECK([mhn-store-: +folder],[mhn09 mhn-store+folder],[
mkdir Mail/inbox
mkdir Mail/app
cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
echo "mhn-store-application: +app" >> $MH
mhn +inbox -store 4 | remove_curdir || exit $?
],
[0],
[storing message 4 part 1 as file 4.1.plain
storing message 4 part 2.1 to folder +app as message 1
storing message 4 part 2.2.1 to folder +app as message 2
storing message 4 part 2.2.2 to folder +app as message 3
])
MH_CHECK([mhn-store-: +],[mhn10 mhn-store+],[
mkdir Mail/inbox
cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
echo "Current-Folder: inbox" > Mail/context
cat >> $MH <<EOT
mhn-store-application/octet-stream: +
EOT
mhn +inbox -store -part 2.2.1 4 | remove_curdir || exit $?
],
[0],
[storing message 4 part 2.2.1 to folder inbox as message 5
])
MH_CHECK([mhn-store-: pipe],[mhn11 mhn-store-pipe],[
mkdir Mail/inbox
cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
echo "Current-Folder: inbox" > Mail/context
echo "mhn-store-text: | $abs_top_srcdir/mh/tests/mhed -" >> $MH
mhn +inbox -store -part 1 4 | sed 's| *$||' || exit $?
],
[0],
[-- Editor invocation: -
-- Input file:
`You are old, Father William,' the young man said,
`And your hair has become very white;
And yet you incessantly stand on your head--
Do you think, at your age, it is right?'
`In my youth,' Father William replied to his son,
`I feared it might injure the brain;
But, now that I'm perfectly sure I have none,
Why, I do it again and again.'
-- Input file end
storing msg 4 part 1 using command /home/gray/gnu/mailutils/mh/tests/mhed -
])
m4_popdef[MH_KEYWORDS])
# End of mhn.at
......
......@@ -19,7 +19,7 @@ m4_pushdef([MH_KEYWORDS],[mhpath])
MH_CHECK([mhpath],[mhpath00],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
echo 'Current-Folder: inbox' > Mail/context
mhpath | sed 's|^'"$dir"'/||'
mhpath | remove_curdir
],
[0],
[Mail/inbox
......@@ -28,7 +28,7 @@ mhpath | sed 's|^'"$dir"'/||'
MH_CHECK([mhpath +],[mhpath01 mhpath+],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
echo 'Current-Folder: inbox' > Mail/context
mhpath +| sed 's|^'"$dir"'/||'
mhpath +| remove_curdir
],
[0],
[Mail
......@@ -36,8 +36,7 @@ mhpath +| sed 's|^'"$dir"'/||'
MH_CHECK([mhpath msgs],[mhpath02 mhparam_msgs],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
dir=`pwd`
mhpath 1-3 | sed 's|^'"$dir"'/||'
mhpath 1-3 | remove_curdir
],
[0],
[Mail/inbox/1
......@@ -47,8 +46,7 @@ Mail/inbox/3
MH_CHECK([mhpath msgs (some nonexistent)],[mhpath03 mhparam_msgs_some_nonex],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
dir=`pwd`
mhpath 4-10 | sed 's|^'"$dir"'/||'
mhpath 4-10 | remove_curdir
],
[0],
[Mail/inbox/4
......@@ -57,8 +55,7 @@ Mail/inbox/5
MH_CHECK([mhpath msgs (all nonexistent)],[mhpath04 mhparam_msgs_all_nonex],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
dir=`pwd`
mhpath 8-10 | sed 's|^'"$dir"'/||'
mhpath 8-10 | remove_curdir
],
[0],
[],
......@@ -89,8 +86,7 @@ mhpath 8-10 | sed 's|^'"$dir"'/||'
MH_CHECK([mhpath nonexistent],[mhpath05 mhparam_nonexistent],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
dir=`pwd`
mhpath 10 | sed 's|^'"$dir"'/||'
mhpath 10 | remove_curdir
],
[0],
[],
......@@ -99,8 +95,7 @@ mhpath 10 | sed 's|^'"$dir"'/||'
MH_CHECK([mhpath new],[mhpath06 mhparam_new],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
dir=`pwd`
mhpath new | sed 's|^'"$dir"'/||'
mhpath new | remove_curdir
],
[0],
[Mail/inbox/6
......
......@@ -26,7 +26,7 @@ Subject: test input
message body
])
echo "quit" | replcmd +inbox 1 | sed "s|$dir/*||;s| *$||"
echo "quit" | replcmd +inbox 1 | remove_curdir
echo == Mail/draft ==
cat Mail/draft
],
......@@ -56,7 +56,7 @@ Subject: test input
message body
])
echo "quit" | replcmd -draftfolder drafts +inbox 1 | sed "s|$dir/*||;s| *$||"
echo "quit" | replcmd -draftfolder drafts +inbox 1 | remove_curdir
echo == Mail/drafts/1 ==
cat Mail/drafts/1
],
......@@ -79,4 +79,4 @@ Seen by mhed
m4_popdef([replcmd])
m4_popdef([MH_KEYWORDS])
# End of repl.at
\ No newline at end of file
# End of repl.at
......
......@@ -18,11 +18,11 @@ m4_include([testsuite.inc])
m4_define([MH_SETUP],[
test -d Mail || mkdir Mail
dir=`pwd`
MH=$dir/mh_profile
curdir=`pwd`
MH=$curdir/mh_profile
export MH
cat > $MH <<EOT
Path: $dir/Mail
Path: $curdir/Mail
mhetcdir: $abs_top_srcdir/mh/etc
EOT
exec <&-
......