Fix tests and MIME attachments
This commit is contained in:
parent
e279f66801
commit
87c286d5b1
2 changed files with 27 additions and 27 deletions
6
notes.sh
6
notes.sh
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
#
|
#
|
||||||
# Distributed under the terms of the BSD License
|
# Distributed under the terms of the BSD License
|
||||||
#
|
#
|
||||||
|
@ -121,7 +121,7 @@ get_headers() {
|
||||||
FILTER="\
|
FILTER="\
|
||||||
{ \
|
{ \
|
||||||
if (\$0~/^$/) {exit} \
|
if (\$0~/^$/) {exit} \
|
||||||
if (\$0!~/^[^ ]*: .*$/) {exit} \
|
if (\$0!~/^[^ ]*:.*$/) {exit} \
|
||||||
print \$0 \
|
print \$0 \
|
||||||
} \
|
} \
|
||||||
"
|
"
|
||||||
|
@ -276,7 +276,7 @@ pack_part() {
|
||||||
echo "Content-Type: $CONTENT_TYPE"
|
echo "Content-Type: $CONTENT_TYPE"
|
||||||
echo "Content-Transfer-Encoding: base64"
|
echo "Content-Transfer-Encoding: base64"
|
||||||
echo
|
echo
|
||||||
base64 | fold -w 76 < "$PART_FILE"
|
base64 < "$PART_FILE" | fold -w 76
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
48
test.sh
48
test.sh
|
@ -1,16 +1,16 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
#
|
#
|
||||||
# Distributed under the terms of the BSD License
|
# Distributed under the terms of the BSD License
|
||||||
#
|
#
|
||||||
# Copyright (c) 2021, Konstantin Nazarov <mail@knazarov.com>
|
# Copyright (c) 2021, Konstantin Nazarov <mail@knazarov.com>
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
# modification, are permitted provided that the following conditions are met:
|
# modification, are permitted provided that the following conditions are met:
|
||||||
#
|
#
|
||||||
# 1. Redistributions of source code must retain the above copyright notice, this
|
# 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
# list of conditions and the following disclaimer.
|
# list of conditions and the following disclaimer.
|
||||||
#
|
#
|
||||||
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
# this list of conditions and the following disclaimer in the documentation
|
# this list of conditions and the following disclaimer in the documentation
|
||||||
# and/or other materials provided with the distribution.
|
# and/or other materials provided with the distribution.
|
||||||
|
@ -61,10 +61,10 @@ assert() {
|
||||||
command="$1"
|
command="$1"
|
||||||
expected="$(echo -ne "${2:-}")"
|
expected="$(echo -ne "${2:-}")"
|
||||||
result="$(eval 2>/dev/null $1 <<< ${3:-})" || true
|
result="$(eval 2>/dev/null $1 <<< ${3:-})" || true
|
||||||
|
|
||||||
if [[ "$result" == "$expected" ]]; then
|
if [[ "$result" == "$expected" ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
result="$(sed -e :a -e '$!N;s/\n/\\n/;ta' <<< "$result")"
|
result="$(sed -e :a -e '$!N;s/\n/\\n/;ta' <<< "$result")"
|
||||||
|
|
||||||
echo "Expected '$command' == '$expected'. Got: '$result'"
|
echo "Expected '$command' == '$expected'. Got: '$result'"
|
||||||
|
@ -97,7 +97,7 @@ new_note_from_file() {
|
||||||
|
|
||||||
"$BASE_DIR/notes.sh" -n "$TMP/input.md"
|
"$BASE_DIR/notes.sh" -n "$TMP/input.md"
|
||||||
OUTPUT="$(cat "$(pwd)/notes/cur"/*)"
|
OUTPUT="$(cat "$(pwd)/notes/cur"/*)"
|
||||||
|
|
||||||
assert 'echo "$OUTPUT" | grep Subject' "Subject: This is a header"
|
assert 'echo "$OUTPUT" | grep Subject' "Subject: This is a header"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ new_note_from_dir() {
|
||||||
|
|
||||||
"$BASE_DIR/notes.sh" -n "$TMP/inpdir"
|
"$BASE_DIR/notes.sh" -n "$TMP/inpdir"
|
||||||
OUTPUT="$(cat "$(pwd)/notes/cur"/*)"
|
OUTPUT="$(cat "$(pwd)/notes/cur"/*)"
|
||||||
|
|
||||||
assert 'echo "$OUTPUT" | grep Subject' "Subject: This is a header"
|
assert 'echo "$OUTPUT" | grep Subject' "Subject: This is a header"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ edit_note() {
|
||||||
NOTE_ID="$(cat "$(pwd)/notes/cur"/* | grep X-Note-Id | cut -d ' ' -f 2)"
|
NOTE_ID="$(cat "$(pwd)/notes/cur"/* | grep X-Note-Id | cut -d ' ' -f 2)"
|
||||||
|
|
||||||
cat > "$(pwd)/editor.sh" <<- EOF
|
cat > "$(pwd)/editor.sh" <<- EOF
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
FILENAME="\$1"
|
FILENAME="\$1"
|
||||||
echo "line2" >> "\$FILENAME"
|
echo "line2" >> "\$FILENAME"
|
||||||
EOF
|
EOF
|
||||||
|
@ -192,7 +192,7 @@ edit_note_add_file() {
|
||||||
NOTE_ID="$(cat "$(pwd)/notes/cur"/* | grep X-Note-Id | cut -d ' ' -f 2)"
|
NOTE_ID="$(cat "$(pwd)/notes/cur"/* | grep X-Note-Id | cut -d ' ' -f 2)"
|
||||||
|
|
||||||
cat > "$(pwd)/editor.sh" <<- EOF
|
cat > "$(pwd)/editor.sh" <<- EOF
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
FILENAME="\$1"
|
FILENAME="\$1"
|
||||||
echo "newfile" > "\$FILENAME.txt"
|
echo "newfile" > "\$FILENAME.txt"
|
||||||
EOF
|
EOF
|
||||||
|
@ -216,7 +216,7 @@ edit_note_no_modifications() {
|
||||||
NOTE_FILE="$(ls "$(pwd)/notes/cur"/*)"
|
NOTE_FILE="$(ls "$(pwd)/notes/cur"/*)"
|
||||||
|
|
||||||
cat > "$(pwd)/editor.sh" <<- EOF
|
cat > "$(pwd)/editor.sh" <<- EOF
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
EOF
|
EOF
|
||||||
chmod a+x "$(pwd)/editor.sh"
|
chmod a+x "$(pwd)/editor.sh"
|
||||||
export EDITOR="$(pwd)/editor.sh"
|
export EDITOR="$(pwd)/editor.sh"
|
||||||
|
@ -233,7 +233,7 @@ resume_editing() {
|
||||||
NOTE_ID="$(cat "$(pwd)/notes/cur"/* | grep X-Note-Id | cut -d ' ' -f 2)"
|
NOTE_ID="$(cat "$(pwd)/notes/cur"/* | grep X-Note-Id | cut -d ' ' -f 2)"
|
||||||
|
|
||||||
cat > "$(pwd)/editor.sh" <<- EOF
|
cat > "$(pwd)/editor.sh" <<- EOF
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
FILENAME="\$1"
|
FILENAME="\$1"
|
||||||
echo "myline2" >> "\$FILENAME"
|
echo "myline2" >> "\$FILENAME"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -247,7 +247,7 @@ resume_editing() {
|
||||||
assert 'echo "$OUTPUT" | grep myline | wc -l | tr -d " "' "1"
|
assert 'echo "$OUTPUT" | grep myline | wc -l | tr -d " "' "1"
|
||||||
|
|
||||||
cat > "$(pwd)/editor.sh" <<- EOF
|
cat > "$(pwd)/editor.sh" <<- EOF
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
FILENAME="\$1"
|
FILENAME="\$1"
|
||||||
echo "myline3" >> "\$FILENAME"
|
echo "myline3" >> "\$FILENAME"
|
||||||
EOF
|
EOF
|
||||||
|
@ -277,7 +277,7 @@ pack_multipart() {
|
||||||
|
|
||||||
"$BASE_DIR/notes.sh" -n "$TMP/inpdir"
|
"$BASE_DIR/notes.sh" -n "$TMP/inpdir"
|
||||||
OUTPUT="$(cat "$(pwd)/notes/cur"/*)"
|
OUTPUT="$(cat "$(pwd)/notes/cur"/*)"
|
||||||
|
|
||||||
assert 'echo "$OUTPUT" | grep Subject' "Subject: This is a header"
|
assert 'echo "$OUTPUT" | grep Subject' "Subject: This is a header"
|
||||||
assert 'echo "$OUTPUT" | grep -o "text attachment"' "text attachment"
|
assert 'echo "$OUTPUT" | grep -o "text attachment"' "text attachment"
|
||||||
BOUNDARY="$(cat "$(pwd)/notes/cur"/* | grep boundary= | cut -d '=' -f 2 | tr -d '\"')"
|
BOUNDARY="$(cat "$(pwd)/notes/cur"/* | grep boundary= | cut -d '=' -f 2 | tr -d '\"')"
|
||||||
|
@ -285,21 +285,21 @@ pack_multipart() {
|
||||||
|
|
||||||
OUTPUT="$(echo "$OUTPUT" | sed "s/$BOUNDARY/boundary/g")"
|
OUTPUT="$(echo "$OUTPUT" | sed "s/$BOUNDARY/boundary/g")"
|
||||||
OUTPUT="$(echo "$OUTPUT" | grep -v "Date" | grep -v "X-Note-Id")"
|
OUTPUT="$(echo "$OUTPUT" | grep -v "Date" | grep -v "X-Note-Id")"
|
||||||
|
|
||||||
read -d '' -r EXPECTED <<- EOF || true
|
read -d '' -r EXPECTED <<- EOF || true
|
||||||
MIME-Version: 1.0
|
MIME-Version: 1.0
|
||||||
Content-Type: multipart/mixed; boundary="boundary"
|
Content-Type: multipart/mixed; boundary="boundary"
|
||||||
Subject: This is a header
|
Subject: This is a header
|
||||||
|
|
||||||
--boundary
|
--boundary
|
||||||
Content-Type: text/plain; charset=utf-8
|
Content-Type: text/plain; charset=utf-8
|
||||||
Content-Disposition: inline
|
Content-Disposition: inline
|
||||||
|
|
||||||
This is a body
|
This is a body
|
||||||
--boundary
|
--boundary
|
||||||
Content-Disposition: attachment; filename="file.txt"
|
Content-Disposition: attachment; filename="file.txt"
|
||||||
Content-Type: text/plain
|
Content-Type: text/plain
|
||||||
|
|
||||||
This is a text attachment
|
This is a text attachment
|
||||||
--boundary--
|
--boundary--
|
||||||
EOF
|
EOF
|
||||||
|
@ -319,7 +319,7 @@ pack_multipart_binary() {
|
||||||
|
|
||||||
"$BASE_DIR/notes.sh" -n "$TMP/inpdir"
|
"$BASE_DIR/notes.sh" -n "$TMP/inpdir"
|
||||||
OUTPUT="$(cat "$(pwd)/notes/cur"/*)"
|
OUTPUT="$(cat "$(pwd)/notes/cur"/*)"
|
||||||
|
|
||||||
assert 'echo "$OUTPUT" | grep Subject' "Subject: This is a header"
|
assert 'echo "$OUTPUT" | grep Subject' "Subject: This is a header"
|
||||||
|
|
||||||
BOUNDARY="$(cat "$(pwd)/notes/cur"/* | grep boundary= | cut -d '=' -f 2 | tr -d '\"')"
|
BOUNDARY="$(cat "$(pwd)/notes/cur"/* | grep boundary= | cut -d '=' -f 2 | tr -d '\"')"
|
||||||
|
@ -327,16 +327,16 @@ pack_multipart_binary() {
|
||||||
|
|
||||||
OUTPUT="$(echo "$OUTPUT" | sed "s/$BOUNDARY/boundary/g")"
|
OUTPUT="$(echo "$OUTPUT" | sed "s/$BOUNDARY/boundary/g")"
|
||||||
OUTPUT="$(echo "$OUTPUT" | grep -v "Date" | grep -v "X-Note-Id")"
|
OUTPUT="$(echo "$OUTPUT" | grep -v "Date" | grep -v "X-Note-Id")"
|
||||||
|
|
||||||
read -d '' -r EXPECTED <<- EOF || true
|
read -d '' -r EXPECTED <<- EOF || true
|
||||||
MIME-Version: 1.0
|
MIME-Version: 1.0
|
||||||
Content-Type: multipart/mixed; boundary="boundary"
|
Content-Type: multipart/mixed; boundary="boundary"
|
||||||
Subject: This is a header
|
Subject: This is a header
|
||||||
|
|
||||||
--boundary
|
--boundary
|
||||||
Content-Type: text/plain; charset=utf-8
|
Content-Type: text/plain; charset=utf-8
|
||||||
Content-Disposition: inline
|
Content-Disposition: inline
|
||||||
|
|
||||||
This is a body
|
This is a body
|
||||||
--boundary
|
--boundary
|
||||||
Content-Disposition: attachment; filename="file.png"
|
Content-Disposition: attachment; filename="file.png"
|
||||||
|
@ -367,7 +367,7 @@ existing_headers() {
|
||||||
|
|
||||||
"$BASE_DIR/notes.sh" -n "$TMP/inpdir"
|
"$BASE_DIR/notes.sh" -n "$TMP/inpdir"
|
||||||
OUTPUT="$(cat "$(pwd)/notes/cur"/*)"
|
OUTPUT="$(cat "$(pwd)/notes/cur"/*)"
|
||||||
|
|
||||||
assert 'echo "$OUTPUT" | grep Subject' "Subject: This is a subject"
|
assert 'echo "$OUTPUT" | grep Subject' "Subject: This is a subject"
|
||||||
|
|
||||||
assert 'echo "$OUTPUT" | grep X-Note-Id' "X-Note-Id: $NOTE_ID"
|
assert 'echo "$OUTPUT" | grep X-Note-Id' "X-Note-Id: $NOTE_ID"
|
||||||
|
|
Loading…
Reference in a new issue