-(forma)t string
-infile
-outfile
+ -attendee
-[no]contenttype
-unfold
-debug
EOF
#### Skip nmh intro text.
-run_prog mhical -help | sed '/^$/,$d' >"$actual" 2>&1
+run_prog mhical -help 2>&1 | sed '/^$/,$d' >"$actual"
check "$expected" "$actual"
cat >"$expected" <<'EOF'
BEGIN:VCALENDAR
METHOD:REPLY
-PRODID:nmh mhical v0.1
+PRODID:nmh mhical v0.5
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Eastern Standard Time
>"$MH_TEST_DIR/test1.txt"
check "$expected" "$MH_TEST_DIR/test1.txt"
+
+# check accept of request with -attendee
+start_test "accept of request with -attendee"
+cat >"$expected" <<'EOF'
+BEGIN:VCALENDAR
+METHOD:REPLY
+PRODID:nmh mhical v0.5
+VERSION:2.0
+BEGIN:VTIMEZONE
+TZID:Eastern Standard Time
+BEGIN:STANDARD
+DTSTART:16010101T020000
+TZOFFSETFROM:-0400
+TZOFFSETTO:-0500
+RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:16010101T020000
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0400
+RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3
+END:DAYLIGHT
+END:VTIMEZONE
+BEGIN:VEVENT
+ORGANIZER;CN=Requester:MAILTO:requester@example.com
+ATTENDEE;PARTSTAT=ACCEPTED;CN=Requestee1:MAILTO:requestee1@example.com
+SUMMARY;LANGUAGE=en-US:Accepted: test request
+DTSTART;TZID=Eastern Standard Time:20150105T090000
+DTEND;TZID=Eastern Standard Time:20150105T093000
+UID:0123456789
+CLASS:PUBLIC
+PRIORITY:5
+TRANSP:OPAQUE
+STATUS:CONFIRMED
+SEQUENCE:0
+LOCATION;LANGUAGE=en-US:
+END:VEVENT
+END:VCALENDAR
+EOF
+
+cp "$MH" "${MH}.save"
+printf 'Alternate-Mailboxes: RequesteeToo <requestee1@example.com>\n' >> "$MH"
+mhical -reply accept -attendee requestee1@example.com <"$MH_TEST_DIR/test1.ics" \
+ | egrep -v '^DTSTAMP:' >"$MH_TEST_DIR/test1.txt"
+check "$expected" "$MH_TEST_DIR/test1.txt"
+
+
+# check accept of request with other -attendee
+start_test "accept of request with other -attendee"
+cat >"$expected" <<'EOF'
+BEGIN:VCALENDAR
+METHOD:REPLY
+PRODID:nmh mhical v0.5
+VERSION:2.0
+BEGIN:VTIMEZONE
+TZID:Eastern Standard Time
+BEGIN:STANDARD
+DTSTART:16010101T020000
+TZOFFSETFROM:-0400
+TZOFFSETTO:-0500
+RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:16010101T020000
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0400
+RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3
+END:DAYLIGHT
+END:VTIMEZONE
+BEGIN:VEVENT
+ORGANIZER;CN=Requester:MAILTO:requester@example.com
+ATTENDEE;PARTSTAT=ACCEPTED;CN=Requestee2:MAILTO:requestee2@example.com
+SUMMARY;LANGUAGE=en-US:Accepted: test request
+DTSTART;TZID=Eastern Standard Time:20150105T090000
+DTEND;TZID=Eastern Standard Time:20150105T093000
+UID:0123456789
+CLASS:PUBLIC
+PRIORITY:5
+TRANSP:OPAQUE
+STATUS:CONFIRMED
+SEQUENCE:0
+LOCATION;LANGUAGE=en-US:
+END:VEVENT
+END:VCALENDAR
+EOF
+
+mhical -reply accept -attendee requestee2@example.com <"$MH_TEST_DIR/test1.ics" \
+ | egrep -v '^DTSTAMP:' >"$MH_TEST_DIR/test1.txt"
+check "$expected" "$MH_TEST_DIR/test1.txt"
+
+
+# check accept of request without required -attendee
+start_test "accept of request without required -attendee"
+cat >"$expected" <<'EOF'
+mhical: Multiple attendees match your address, re-run with -attendee switch
+EOF
+
+mhical -reply accept <"$MH_TEST_DIR/test1.ics" 2>"$MH_TEST_DIR/test1.txt" \
+ && false
+check "$expected" "$MH_TEST_DIR/test1.txt"
+mv "${MH}.save" "$MH"
+
+
# check accept of multiple vevent requests in single vcalendar
start_test "accept of multiple vevent requests in single vcalendar"
cat >"$expected" <<'EOF'
BEGIN:VCALENDAR
METHOD:REPLY
-PRODID:nmh mhical v0.1
+PRODID:nmh mhical v0.5
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Eastern Standard Time
cat >"$expected" <<'EOF'
BEGIN:VCALENDAR
METHOD:REPLY
-PRODID:nmh mhical v0.1
+PRODID:nmh mhical v0.5
VERSION:2.0
BEGIN:VEVENT
ORGANIZER;CN=Requester:MAILTO:requester@example.com
cat >"$expected" <<'EOF'
BEGIN:VCALENDAR
METHOD:REPLY
-PRODID:nmh mhical v0.1
+PRODID:nmh mhical v0.5
VERSION:2.0
BEGIN:VEVENT
ORGANIZER;CN=Requester:MAILTO:requester@example.com
BEGIN:VCALENDAR
METHOD:CANCEL
-PRODID:nmh mhical v0.1
+PRODID:nmh mhical v0.5
VERSION:2.0
BEGIN:VEVENT
ORGANIZER;CN=Requestee2:MAILTO:requestee2@example.com
cat >"$expected" <<'EOF'
Summary: test
Description: this file does not end with a newline
-At: Sun, 14 May 2017 09:00 -0400
-To: Sun, 14 May 2017 10:00
+At: Sun, 14 May 2017 13:00 +0000
+To: Sun, 14 May 2017 14:00
EOF
printf %s \
SUMMARY:test
DESCRIPTION:this file does not end with a newline
END:VEVENT
-END:VCALENDAR" | mhical >"$actual"
+END:VCALENDAR" | TZ=UTC mhical >"$actual"
check "$expected" "$actual"
+# check invalid line folding
+start_test "invalid line folding"
+
+cat >"$expected" <<'EOF'
+Summary: test
+Description: this file does not end with a newline
+At: Sun, 14 May 2017 13:00 +0000
+To: Sun, 14 May 2017 14:00
+EOF
+
+cat >"$expected_err" <<'EOF'
+mhical: syntax error, unexpected ICAL_COMMA, expecting ICAL_COLON after " this line is not folded"
+EOF
+
+set +e
+printf %s \
+"BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//TDP v3.0//EN
+BEGIN:VEVENT
+DTSTAMP:20170514T122300Z
+DTSTART:20170514T130000Z
+DTEND:20170514T140000Z
+SUMMARY:test
+DESCRIPTION:this file does not end with a newline
+and this line is not folded,
+END:VEVENT
+END:VCALENDAR" | TZ=UTC mhical >"$actual" 2>"$actual_err"
+set -e
+check "$expected" "$actual"
+check "$expected_err" "$actual_err"
+
+
+# check null input
+start_test "null input"
+check_exit '-eq 0' mhical </dev/null
+
+
finish_test
exit $failed