Fix handling of multifile notes
This commit is contained in:
parent
2cd09b260d
commit
cb2464133b
2 changed files with 40 additions and 6 deletions
10
notes.sh
10
notes.sh
|
@ -184,7 +184,7 @@ unpack_part() {
|
||||||
if [[ $DISPOSITION == *"attachment"* ]]; then
|
if [[ $DISPOSITION == *"attachment"* ]]; then
|
||||||
ENCODING=$(get_header "$FILE" Content-Transfer-Encoding)
|
ENCODING=$(get_header "$FILE" Content-Transfer-Encoding)
|
||||||
FILENAME=$(echo "$DISPOSITION" | \
|
FILENAME=$(echo "$DISPOSITION" | \
|
||||||
sed -n 's/^.*filename="\{0,1\}\(.*\)"\{0,1\}$/\1/p')
|
sed -n 's/^.*filename="\{0,1\}\([^"]*\)"\{0,1\}$/\1/p')
|
||||||
FILTER="\
|
FILTER="\
|
||||||
{ \
|
{ \
|
||||||
if (body==1) {print \$0}\
|
if (body==1) {print \$0}\
|
||||||
|
@ -289,7 +289,7 @@ pack_mime() {
|
||||||
{
|
{
|
||||||
echo "MIME-Version: 1.0"
|
echo "MIME-Version: 1.0"
|
||||||
echo "Date: $MIME_TIMESTAMP"
|
echo "Date: $MIME_TIMESTAMP"
|
||||||
echo "Content-Type: multipart/mixed; boundary=$BOUNDARY"
|
echo "Content-Type: multipart/mixed; boundary=\"$BOUNDARY\""
|
||||||
get_headers "$DIR/note.md"
|
get_headers "$DIR/note.md"
|
||||||
echo
|
echo
|
||||||
echo "--$BOUNDARY"
|
echo "--$BOUNDARY"
|
||||||
|
@ -346,7 +346,10 @@ new_entry() {
|
||||||
get_body "$INP/note.md"
|
get_body "$INP/note.md"
|
||||||
} >> "$DIR/note.md"
|
} >> "$DIR/note.md"
|
||||||
elif [ -t 0 ]; then
|
elif [ -t 0 ]; then
|
||||||
|
OLD_DIR="$(pwd)"
|
||||||
|
cd "$DIR"
|
||||||
"$EDITOR" "$ENTRY_FILE"
|
"$EDITOR" "$ENTRY_FILE"
|
||||||
|
cd "$OLD_DIR"
|
||||||
else
|
else
|
||||||
while read -r line ; do
|
while read -r line ; do
|
||||||
echo "$line" >> "$ENTRY_FILE"
|
echo "$line" >> "$ENTRY_FILE"
|
||||||
|
@ -403,9 +406,12 @@ edit_entry() {
|
||||||
unpack_mime "$FILENAME" "$DIR"
|
unpack_mime "$FILENAME" "$DIR"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
OLD_DIR="$(pwd)"
|
||||||
|
cd "$DIR"
|
||||||
if ! "$EDITOR" "$DIR/note.md"; then
|
if ! "$EDITOR" "$DIR/note.md"; then
|
||||||
die "Editor returned non-zero exit code. Leaving the note untouched."
|
die "Editor returned non-zero exit code. Leaving the note untouched."
|
||||||
fi
|
fi
|
||||||
|
cd "$OLD_DIR"
|
||||||
|
|
||||||
UNIX_TIMESTAMP=$(date "+%s")
|
UNIX_TIMESTAMP=$(date "+%s")
|
||||||
HOSTNAME=$(hostname -s)
|
HOSTNAME=$(hostname -s)
|
||||||
|
|
36
test.sh
36
test.sh
|
@ -222,7 +222,7 @@ pack_multipart() {
|
||||||
|
|
||||||
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)"
|
BOUNDARY="$(cat "$(pwd)/notes/cur"/* | grep boundary= | cut -d '=' -f 2 | tr -d '\"')"
|
||||||
#echo "boundary: $BOUNDARY"
|
#echo "boundary: $BOUNDARY"
|
||||||
|
|
||||||
OUTPUT="$(echo "$OUTPUT" | sed "s/$BOUNDARY/boundary/g")"
|
OUTPUT="$(echo "$OUTPUT" | sed "s/$BOUNDARY/boundary/g")"
|
||||||
|
@ -230,7 +230,7 @@ pack_multipart() {
|
||||||
|
|
||||||
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
|
||||||
|
@ -264,7 +264,7 @@ pack_multipart_binary() {
|
||||||
|
|
||||||
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)"
|
BOUNDARY="$(cat "$(pwd)/notes/cur"/* | grep boundary= | cut -d '=' -f 2 | tr -d '\"')"
|
||||||
#echo "boundary: $BOUNDARY"
|
#echo "boundary: $BOUNDARY"
|
||||||
|
|
||||||
OUTPUT="$(echo "$OUTPUT" | sed "s/$BOUNDARY/boundary/g")"
|
OUTPUT="$(echo "$OUTPUT" | sed "s/$BOUNDARY/boundary/g")"
|
||||||
|
@ -272,7 +272,7 @@ pack_multipart_binary() {
|
||||||
|
|
||||||
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
|
||||||
|
@ -343,6 +343,33 @@ no_headers_dir() {
|
||||||
assert 'echo "$OUTPUT" | grep "This is a body"' "This is a body"
|
assert 'echo "$OUTPUT" | grep "This is a body"' "This is a body"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import_export() {
|
||||||
|
mkdir "$TMP/inpdir"
|
||||||
|
NOTE_ID="6e50650a-88d1-49a3-92eb-0ec329e6f6f8"
|
||||||
|
DATE="2021-05-29T18:47:34Z"
|
||||||
|
|
||||||
|
cat > "$TMP/inpdir/note.md" <<- EOF
|
||||||
|
X-Date: $DATE
|
||||||
|
X-Note-Id: $NOTE_ID
|
||||||
|
Subject: This is a subject
|
||||||
|
|
||||||
|
This is a body
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat > "$TMP/inpdir/file.txt" <<- EOF
|
||||||
|
This is a text attachment
|
||||||
|
EOF
|
||||||
|
|
||||||
|
"$BASE_DIR/notes.sh" -n "$TMP/inpdir"
|
||||||
|
|
||||||
|
mkdir "$TMP/outpdir"
|
||||||
|
|
||||||
|
"$BASE_DIR/notes.sh" -E $NOTE_ID "$TMP/outpdir"
|
||||||
|
|
||||||
|
assert 'cat "$TMP/outpdir/note.md"' "$(cat "$TMP/inpdir/note.md")"
|
||||||
|
assert 'cat "$TMP/outpdir/file.txt"' "$(cat "$TMP/inpdir/file.txt")"
|
||||||
|
}
|
||||||
|
|
||||||
testcase new_note_from_stdin
|
testcase new_note_from_stdin
|
||||||
testcase new_note_from_file
|
testcase new_note_from_file
|
||||||
testcase new_note_from_dir
|
testcase new_note_from_dir
|
||||||
|
@ -355,6 +382,7 @@ testcase pack_multipart_binary
|
||||||
testcase existing_headers
|
testcase existing_headers
|
||||||
testcase no_headers
|
testcase no_headers
|
||||||
testcase no_headers_dir
|
testcase no_headers_dir
|
||||||
|
testcase import_export
|
||||||
|
|
||||||
if [[ "$RESULT" == "0" ]]; then
|
if [[ "$RESULT" == "0" ]]; then
|
||||||
echo "All tests passed."
|
echo "All tests passed."
|
||||||
|
|
Loading…
Reference in a new issue