summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
efd7ca5)
space on a line. Thanks to Valdis for reporting that and to
Ralph for the awk and sed magic to emulate diff -w (and cat -s).
+#### Filter that squeezes blank lines, emulating GNU cat -s.
+squeeze_lines() {
+ awk '!length && e {next} {e = !length} 1'
+}
+
+#### Filter that inserts initial whitespace and converts non-breakable
+#### space U+00A0 to an ASCII space.
+prepare_space() {
+ sed 's/^/ /; s/'"`printf '\\302\\240'`"'/ /g'
+}
+
#### check() requires two arguments, each the name of a file to be
#### diff'ed.
#### If the same, the second file is removed. And the first file is
#### removed unless there's an optional argument with a value of
#### 'keep first'.
#### If different, global variable "failed" is incremented.
#### check() requires two arguments, each the name of a file to be
#### diff'ed.
#### If the same, the second file is removed. And the first file is
#### removed unless there's an optional argument with a value of
#### 'keep first'.
#### If different, global variable "failed" is incremented.
-#### If there's an optional 'ignore space' argument, diff -b will
-#### be used instead of cmp to compare the files.
+#### If there's an optional 'ignore space' argument, spacing differences
+#### will not be considered signficant, emulating GNU diff -w. It
+#### is assumed that the first file has already been run through
+#### prepare_space.
check() {
first=$1; shift
second=$1; shift
check() {
first=$1; shift
second=$1; shift
success=
if [ "$ignorespace" ]; then
#### POSIX diff should support -b.
success=
if [ "$ignorespace" ]; then
#### POSIX diff should support -b.
- diff -b "$first" "$second" >/dev/null && success=1
+ prepare_space <"$second" | diff -b "$first" - >/dev/null && success=1
else
cmp -s "$first" "$second" && success=1
fi
else
cmp -s "$first" "$second" && success=1
fi
actual="$MH_TEST_DIR/test-mhfixmsg$$.actual"
actual_err="$MH_TEST_DIR/test-mhfixmsg$$.actual_err"
actual="$MH_TEST_DIR/test-mhfixmsg$$.actual"
actual_err="$MH_TEST_DIR/test-mhfixmsg$$.actual_err"
+#### Make sure that html-to-text conversion is what we expect.
+LC_ALL=en_US.UTF-8; export LC_ALL
+
set +e
if grep mhfixmsg-format-text/html "${MH_TEST_DIR}/Mail/mhn.defaults" \
>/dev/null; then
set +e
if grep mhfixmsg-format-text/html "${MH_TEST_DIR}/Mail/mhn.defaults" \
>/dev/null; then
# check -reformat (enabled by default): addition of text/plain part
# to solitary text/html part
#
# check -reformat (enabled by default): addition of text/plain part
# to solitary text/html part
#
+prepare_space >"$expected" <<EOF
MIME-Version: 1.0
From: sender@example.com
To: bonquiqui@example.com
MIME-Version: 1.0
From: sender@example.com
To: bonquiqui@example.com
mhfixmsg: 12 part 1, decode text/html; charset=\"Windows-1252\"" \
>"$expected.err"
mhfixmsg: 12 part 1, decode text/html; charset=\"Windows-1252\"" \
>"$expected.err"
- #### lynx inserts multiple blank lines, so use uniq to squeeze them.
- mhfixmsg last -outfile - -verbose 2>"$actual.err" | uniq >"$actual"
- check "$expected" "$actual"
+ #### lynx inserts multiple blank lines, so squeeze them.
+ mhfixmsg last -outfile - -verbose 2>"$actual.err" | squeeze_lines >"$actual"
+ check "$expected" "$actual" 'ignore space'
check "$expected.err" "$actual.err"
else
rm -f "$expected"
check "$expected.err" "$actual.err"
else
rm -f "$expected"
# check handling of boundary string that appears in message body
#
# check handling of boundary string that appears in message body
#
+prepare_space >"$expected" <<EOF
MIME-Version: 1.0
From: sender@example.com
To: bonquiqui@example.com
MIME-Version: 1.0
From: sender@example.com
To: bonquiqui@example.com
mhfixmsg: 12 part 1, decode text/html; charset=\"Windows-1252\"" \
>"$expected.err"
mhfixmsg: 12 part 1, decode text/html; charset=\"Windows-1252\"" \
>"$expected.err"
- #### lynx inserts multiple blank lines, so use uniq to squeeze them.
- mhfixmsg last -outfile - -verbose 2>"$actual.err" | uniq >"$actual"
- check "$expected" "$actual"
+ #### lynx inserts multiple blank lines, so squeeze them.
+ mhfixmsg last -outfile - -verbose 2>"$actual.err" | squeeze_lines >"$actual"
+ check "$expected" "$actual" 'ignore space'
check "$expected.err" "$actual.err"
else
rm -f "$expected"
check "$expected.err" "$actual.err"
else
rm -f "$expected"
+prepare_space >"$expected" <<EOF
MIME-Version: 1.0
From: sender@example.com
To: bonquiqui@example.com
MIME-Version: 1.0
From: sender@example.com
To: bonquiqui@example.com
if [ $can_reformat_texthtml -eq 1 ]; then
printf '%s\n' 'mhfixmsg: 12, insert text/plain part' >"$expected.err"
if [ $can_reformat_texthtml -eq 1 ]; then
printf '%s\n' 'mhfixmsg: 12, insert text/plain part' >"$expected.err"
- #### lynx inserts multiple blank lines, so use uniq to squeeze them.
- mhfixmsg last -nodecode -outfile - -verbose 2>"$actual.err" | uniq >"$actual"
- check "$expected" "$actual"
+ #### lynx inserts multiple blank lines, so squeeze them.
+ mhfixmsg last -nodecode -outfile - -verbose 2>"$actual.err" | \
+ squeeze_lines >"$actual"
+ check "$expected" "$actual" 'ignore space'
check "$expected.err" "$actual.err"
else
rm -f "$expected"
check "$expected.err" "$actual.err"
else
rm -f "$expected"
# check that -reformat succeeds when decode of binary text fails
# check that -reformat succeeds when decode of binary text fails
-cat >"$expected" <<'EOF'
+prepare_space >"$expected" <<'EOF'
MIME-Version: 1.0
Date: Thu, 11 Apr 2013 02:47:08 -0700
To: <me@example.com>
MIME-Version: 1.0
Date: Thu, 11 Apr 2013 02:47:08 -0700
To: <me@example.com>
EOF
if [ $can_reformat_texthtml -eq 1 ]; then
EOF
if [ $can_reformat_texthtml -eq 1 ]; then
- #### lynx inserts multiple blank lines, so use uniq to squeeze them.
+ #### lynx inserts multiple blank lines, so squeeze them.
#### Truncate to avoid comparing the html portion because it can
#### get reformatted.
#### Truncate to avoid comparing the html portion because it can
#### get reformatted.
- mhfixmsg last -outfile - | uniq | head -22 >"$actual"
+ mhfixmsg last -outfile - | squeeze_lines | head -22 >"$actual"
check "$expected" "$actual" 'ignore space'
else
cp -p "$MH_TEST_DIR/Mail/inbox/15" "$MH_TEST_DIR/Mail/inbox/15.backup"
check "$expected" "$actual" 'ignore space'
else
cp -p "$MH_TEST_DIR/Mail/inbox/15" "$MH_TEST_DIR/Mail/inbox/15.backup"
# check that text/plain part is added to lone text/html in multipart/related
# check that text/plain part is added to lone text/html in multipart/related
+prepare_space >"$expected" <<EOF
MIME-Version: 1.0
Date: Tue, 26 Feb 2013 18:07:20 -0600
Subject: multipart/related, not /alternative
MIME-Version: 1.0
Date: Tue, 26 Feb 2013 18:07:20 -0600
Subject: multipart/related, not /alternative
EOF
if [ $can_reformat_texthtml -eq 1 ]; then
EOF
if [ $can_reformat_texthtml -eq 1 ]; then
- #### lynx inserts multiple blank lines, so use uniq to squeeze them.
- mhfixmsg last -outfile - | uniq >"$actual"
- check "$expected" "$actual"
+ #### lynx inserts multiple blank lines, so squeeze them.
+ mhfixmsg last -outfile - | squeeze_lines >"$actual"
+ check "$expected" "$actual" 'ignore space'
else
rm -f "$expected"
fi
else
rm -f "$expected"
fi
# check -replacetextplain
# check -replacetextplain
+prepare_space >"$expected" <<EOF
To: recipient@example.com
From: sender@example.com
Subject: mhfixmsg replacement of bad text/plain part test
To: recipient@example.com
From: sender@example.com
Subject: mhfixmsg replacement of bad text/plain part test
EOF
if [ $can_reformat_texthtml -eq 1 ]; then
EOF
if [ $can_reformat_texthtml -eq 1 ]; then
- #### lynx inserts multiple blank lines, so use uniq to squeeze them.
- mhfixmsg last -replacetextplain -outfile - | uniq > "$actual"
- check "$expected" "$actual"
+ #### lynx inserts multiple blank lines, so squeeze them.
+ mhfixmsg last -replacetextplain -outfile - | squeeze_lines > "$actual"
+ check "$expected" "$actual" 'ignore space'
else
rm -f "$expected"
fi
else
rm -f "$expected"
fi