#!/bin/sh # # Copyright (c) 2005 Junio C Hamano # global test_description := ''git mailinfo and git mailsplit test'' source ./test-lib.sh global DATA := ""$TEST_DIRECTORY/t5100"" test_expect_success 'split sample box' \ 'git mailsplit -o. "$DATA/sample.mbox" >last && last=$(cat last) && echo total is $last && test $(cat last) = 18' proc check_mailinfo { global mail := $1, opt := $2 global mo := ""$mail$opt"" git mailinfo -u $opt "msg$mo" "patch$mo" <$mail >"info$mo" && test_cmp "$DATA/msg$mo" "msg$mo" && test_cmp "$DATA/patch$mo" "patch$mo" && test_cmp "$DATA/info$mo" "info$mo" } for mail in [00*] { test_expect_success "mailinfo $mail" ' check_mailinfo "$mail" "" && if test -f "$DATA/msg$mail--scissors" then check_mailinfo "$mail" --scissors fi && if test -f "$DATA/msg$mail--no-inbody-headers" then check_mailinfo "$mail" --no-inbody-headers fi && if test -f "$DATA/msg$mail--message-id" then check_mailinfo "$mail" --message-id fi ' } test_expect_success 'split box with rfc2047 samples' \ 'mkdir rfc2047 && git mailsplit -orfc2047 "$DATA/rfc2047-samples.mbox" \ >rfc2047/last && last=$(cat rfc2047/last) && echo total is $last && test $(cat rfc2047/last) = 11' for mail in [rfc2047/00*] { test_expect_success "mailinfo $mail" ' git mailinfo -u "$mail-msg" "$mail-patch" <"$mail" >"$mail-info" && echo msg && test_cmp "$DATA/empty" "$mail-msg" && echo patch && test_cmp "$DATA/empty" "$mail-patch" && echo info && test_cmp "$DATA/rfc2047-info-$(basename $mail)" "$mail-info" ' } test_expect_success 'respect NULs' ' git mailsplit -d3 -o. "$DATA/nul-plain" && test_cmp "$DATA/nul-plain" 001 && (cat 001 | git mailinfo msg patch) && test_line_count = 4 patch ' test_expect_success 'Preserve NULs out of MIME encoded message' ' git mailsplit -d5 -o. "$DATA/nul-b64.in" && test_cmp "$DATA/nul-b64.in" 00001 && git mailinfo msg patch <00001 && test_cmp "$DATA/nul-b64.expect" patch ' test_expect_success 'mailinfo on from header without name works' ' mkdir info-from && git mailsplit -oinfo-from "$DATA/info-from.in" && test_cmp "$DATA/info-from.in" info-from/0001 && git mailinfo info-from/msg info-from/patch \ info-from/out && test_cmp "$DATA/info-from.expect" info-from/out ' test_expect_success 'mailinfo finds headers after embedded From line' ' mkdir embed-from && git mailsplit -oembed-from "$DATA/embed-from.in" && test_cmp "$DATA/embed-from.in" embed-from/0001 && git mailinfo embed-from/msg embed-from/patch \ embed-from/out && test_cmp "$DATA/embed-from.expect" embed-from/out ' test_expect_success 'mailinfo on message with quoted >From' ' mkdir quoted-from && git mailsplit -oquoted-from "$DATA/quoted-from.in" && test_cmp "$DATA/quoted-from.in" quoted-from/0001 && git mailinfo quoted-from/msg quoted-from/patch \ quoted-from/out && test_cmp "$DATA/quoted-from.expect" quoted-from/msg ' test_expect_success 'mailinfo unescapes with --mboxrd' ' mkdir mboxrd && git mailsplit -omboxrd --mboxrd \ "$DATA/sample.mboxrd" >last && test x"$(cat last)" = x2 && for i in 0001 0002 do git mailinfo mboxrd/msg mboxrd/patch \ mboxrd/out && test_cmp "$DATA/${i}mboxrd" mboxrd/msg done && sp=" " && echo "From " >expect && echo "From " >>expect && echo >> expect && cat >sp <<-INPUT_END && From mboxrd Mon Sep 17 00:00:00 2001 From: trailing spacer Subject: [PATCH] a commit with trailing space From$sp >From$sp INPUT_END git mailsplit -f2 -omboxrd --mboxrd last && test x"$(cat last)" = x1 && git mailinfo mboxrd/msg mboxrd/patch quoted-string/info && test_cmp "$DATA/quoted-string.expect" quoted-string/info ' test_expect_success 'mailinfo handles rfc2822 comment' ' mkdir comment && git mailinfo /dev/null /dev/null <"$DATA/comment.in" \ >comment/info && test_cmp "$DATA/comment.expect" comment/info ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"git mailinfo and git mailsplit test">)} spids: [13] ) ] spids: [13] ) (C {(.)} {(./test-lib.sh)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:DATA) op: Equal rhs: {(DQ ($ VSub_Name "$TEST_DIRECTORY") (/t5100))} spids: [24] ) ] spids: [24] ) (C {(test_expect_success)} {(SQ <"split sample box">)} { (SQ <"git mailsplit -o. \"$DATA/sample.mbox\" >last &&\n"> <"\tlast=$(cat last) &&\n"> <"\techo total is $last &&\n"> <"\ttest $(cat last) = 18"> ) } ) (FuncDef name: check_mailinfo body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:mail) op: Equal rhs: {($ VSub_Number "$1")} spids: [55] ) (assign_pair lhs: (LhsName name:opt) op: Equal rhs: {($ VSub_Number "$2")} spids: [58] ) ] spids: [55] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:mo) op: Equal rhs: {(DQ ($ VSub_Name "$mail") ($ VSub_Name "$opt"))} spids: [62] ) ] spids: [62] ) (AndOr children: [ (SimpleCommand words: [ {(git)} {(mailinfo)} {(-u)} {($ VSub_Name "$opt")} {(DQ (msg) ($ VSub_Name "$mo"))} {(DQ (patch) ($ VSub_Name "$mo"))} ] redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {(DQ ($ VSub_Name "$mail"))} spids: [87] ) (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ (info) ($ VSub_Name "$mo"))} spids: [92] ) ] ) (AndOr children: [ (C {(test_cmp)} {(DQ ($ VSub_Name "$DATA") (/msg) ($ VSub_Name "$mo"))} {(DQ (msg) ($ VSub_Name "$mo"))} ) (AndOr children: [ (C {(test_cmp)} {(DQ ($ VSub_Name "$DATA") (/patch) ($ VSub_Name "$mo"))} {(DQ (patch) ($ VSub_Name "$mo"))} ) (C {(test_cmp)} {(DQ ($ VSub_Name "$DATA") (/info) ($ VSub_Name "$mo"))} {(DQ (info) ($ VSub_Name "$mo"))} ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [52] ) spids: [47 51] ) (ForEach iter_name: mail iter_words: [{(00) (Lit_Other "*")}] do_arg_iter: False body: (DoGroup children: [ (C {(test_expect_success)} {(DQ ("mailinfo ") ($ VSub_Name "$mail"))} { (SQ <"\n"> <"\t\tcheck_mailinfo \"$mail\" \"\" &&\n"> <"\t\tif test -f \"$DATA/msg$mail--scissors\"\n"> <"\t\tthen\n"> <"\t\t\tcheck_mailinfo \"$mail\" --scissors\n"> <"\t\tfi &&\n"> <"\t\tif test -f \"$DATA/msg$mail--no-inbody-headers\"\n"> <"\t\tthen\n"> <"\t\t\tcheck_mailinfo \"$mail\" --no-inbody-headers\n"> <"\t\tfi &&\n"> <"\t\tif test -f \"$DATA/msg$mail--message-id\"\n"> <"\t\tthen\n"> <"\t\t\tcheck_mailinfo \"$mail\" --message-id\n"> <"\t\tfi\n"> <"\t"> ) } ) ] spids: [159 187] ) spids: [155 -1] ) (C {(test_expect_success)} {(SQ <"split box with rfc2047 samples">)} { (SQ <"mkdir rfc2047 &&\n"> <"\tgit mailsplit -orfc2047 \"$DATA/rfc2047-samples.mbox\" \\\n"> <"\t >rfc2047/last &&\n"> <"\tlast=$(cat rfc2047/last) &&\n"> <"\techo total is $last &&\n"> <"\ttest $(cat rfc2047/last) = 11"> ) } ) (ForEach iter_name: mail iter_words: [{(rfc2047/00) (Lit_Other "*")}] do_arg_iter: False body: (DoGroup children: [ (C {(test_expect_success)} {(DQ ("mailinfo ") ($ VSub_Name "$mail"))} { (SQ <"\n"> < "\t\tgit mailinfo -u \"$mail-msg\" \"$mail-patch\" <\"$mail\" >\"$mail-info\" &&\n" > <"\t\techo msg &&\n"> <"\t\ttest_cmp \"$DATA/empty\" \"$mail-msg\" &&\n"> <"\t\techo patch &&\n"> <"\t\ttest_cmp \"$DATA/empty\" \"$mail-patch\" &&\n"> <"\t\techo info &&\n"> <"\t\ttest_cmp \"$DATA/rfc2047-info-$(basename $mail)\" \"$mail-info\"\n"> <"\t"> ) } ) ] spids: [218 240] ) spids: [214 -1] ) (C {(test_expect_success)} {(SQ <"respect NULs">)} { (SQ <"\n"> <"\n"> <"\tgit mailsplit -d3 -o. \"$DATA/nul-plain\" &&\n"> <"\ttest_cmp \"$DATA/nul-plain\" 001 &&\n"> <"\t(cat 001 | git mailinfo msg patch) &&\n"> <"\ttest_line_count = 4 patch\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"Preserve NULs out of MIME encoded message">)} { (SQ <"\n"> <"\n"> <"\tgit mailsplit -d5 -o. \"$DATA/nul-b64.in\" &&\n"> <"\ttest_cmp \"$DATA/nul-b64.in\" 00001 &&\n"> <"\tgit mailinfo msg patch <00001 &&\n"> <"\ttest_cmp \"$DATA/nul-b64.expect\" patch\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"mailinfo on from header without name works">)} { (SQ <"\n"> <"\n"> <"\tmkdir info-from &&\n"> <"\tgit mailsplit -oinfo-from \"$DATA/info-from.in\" &&\n"> <"\ttest_cmp \"$DATA/info-from.in\" info-from/0001 &&\n"> <"\tgit mailinfo info-from/msg info-from/patch \\\n"> <"\t info-from/out &&\n"> <"\ttest_cmp \"$DATA/info-from.expect\" info-from/out\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"mailinfo finds headers after embedded From line">)} { (SQ <"\n"> <"\tmkdir embed-from &&\n"> <"\tgit mailsplit -oembed-from \"$DATA/embed-from.in\" &&\n"> <"\ttest_cmp \"$DATA/embed-from.in\" embed-from/0001 &&\n"> <"\tgit mailinfo embed-from/msg embed-from/patch \\\n"> <"\t embed-from/out &&\n"> <"\ttest_cmp \"$DATA/embed-from.expect\" embed-from/out\n"> ) } ) (C {(test_expect_success)} {(SQ <"mailinfo on message with quoted >From">)} { (SQ <"\n"> <"\tmkdir quoted-from &&\n"> <"\tgit mailsplit -oquoted-from \"$DATA/quoted-from.in\" &&\n"> <"\ttest_cmp \"$DATA/quoted-from.in\" quoted-from/0001 &&\n"> <"\tgit mailinfo quoted-from/msg quoted-from/patch \\\n"> <"\t quoted-from/out &&\n"> <"\ttest_cmp \"$DATA/quoted-from.expect\" quoted-from/msg\n"> ) } ) (C {(test_expect_success)} {(SQ <"mailinfo unescapes with --mboxrd">)} { (SQ <"\n"> <"\tmkdir mboxrd &&\n"> <"\tgit mailsplit -omboxrd --mboxrd \\\n"> <"\t\t\"$DATA/sample.mboxrd\" >last &&\n"> <"\ttest x\"$(cat last)\" = x2 &&\n"> <"\tfor i in 0001 0002\n"> <"\tdo\n"> <"\t\tgit mailinfo mboxrd/msg mboxrd/patch \\\n"> <"\t\t mboxrd/out &&\n"> <"\t\ttest_cmp \"$DATA/${i}mboxrd\" mboxrd/msg\n"> <"\tdone &&\n"> <"\tsp=\" \" &&\n"> <"\techo \"From \" >expect &&\n"> <"\techo \"From \" >>expect &&\n"> <"\techo >> expect &&\n"> <"\tcat >sp <<-INPUT_END &&\n"> <"\tFrom mboxrd Mon Sep 17 00:00:00 2001\n"> <"\tFrom: trailing spacer \n"> <"\tSubject: [PATCH] a commit with trailing space\n"> <"\n"> <"\tFrom$sp\n"> <"\t>From$sp\n"> <"\n"> <"\tINPUT_END\n"> <"\n"> <"\tgit mailsplit -f2 -omboxrd --mboxrd last &&\n"> <"\ttest x\"$(cat last)\" = x1 &&\n"> <"\tgit mailinfo mboxrd/msg mboxrd/patch <"\ttest_cmp expect mboxrd/msg\n"> ) } ) (C {(test_expect_success)} {(SQ <"mailinfo handles rfc2822 quoted-string">)} { (SQ <"\n"> <"\tmkdir quoted-string &&\n"> <"\tgit mailinfo /dev/null /dev/null <\"$DATA/quoted-string.in\" \\\n"> <"\t\t>quoted-string/info &&\n"> <"\ttest_cmp \"$DATA/quoted-string.expect\" quoted-string/info\n"> ) } ) (C {(test_expect_success)} {(SQ <"mailinfo handles rfc2822 comment">)} { (SQ <"\n"> <"\tmkdir comment &&\n"> <"\tgit mailinfo /dev/null /dev/null <\"$DATA/comment.in\" \\\n"> <"\t\t>comment/info &&\n"> <"\ttest_cmp \"$DATA/comment.expect\" comment/info\n"> ) } ) (C {(test_done)}) ] )