#!/bin/sh # Copyright 2008 Lukas Sandström # # AppendPatch - A script to be used together with ExternalEditor # for Mozilla Thunderbird to properly include patches inline in e-mails. # ExternalEditor can be downloaded at http://globs.org/articles.php?lng=en&pg=2 global CONFFILE := ""~/.appprc global SEP := '"-=-=-=-=-=-=-=-=-=# Don't remove this line #=-=-=-=-=-=-=-=-=-'" if test -e $CONFFILE { global LAST_DIR := $[grep -m 1 "^LAST_DIR=" $(CONFFILE)|sed -e 's/^LAST_DIR=//] cd $(LAST_DIR) } else { cd > /dev/null } global PATCH := $[zenity --file-selection] if test "$Status" != "0" { #zenity --error --text "No patchfile given." exit 1 } cd - > /dev/null global SUBJECT := $[sed -n -e '/^Subject: /p' $(PATCH)] global HEADERS := $[sed -e '/^'"$(SEP)"'$/,$d' $1] global BODY := $[sed -e "1,/$(SEP)/d" $1] global CMT_MSG := $[sed -e '1,/^$/d' -e '/^---$/,$d' $(PATCH)] global DIFF := $[sed -e '1,/^---$/d' $(PATCH)] global CCS := $[echo -e "$CMT_MSG\n$HEADERS" | sed -n -e 's/^Cc: \(.*\)$/\1,/gp' \ -e 's/^Signed-off-by: \(.*\)/\1,/gp] echo $SUBJECT > $1 echo "Cc: $CCS" >> $1 echo $HEADERS | sed -e '/^Subject: /d' -e '/^Cc: /d' >> $1 echo $SEP >> $1 echo $CMT_MSG >> $1 echo "---" >> $1 if test "x$(BODY)x" != "xx" { echo >> $1 echo $BODY >> $1 echo >> $1 } echo $DIFF >> $1 global LAST_DIR := $[dirname $(PATCH)] grep -v "^LAST_DIR=" $(CONFFILE) > "$(CONFFILE)_" echo "LAST_DIR=$(LAST_DIR)" >> "$(CONFFILE)_" mv "$(CONFFILE)_" $(CONFFILE) (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CONFFILE) op: Equal rhs: {(TildeSubPart prefix:"") (/.appprc)} spids: [20] ) ] spids: [20] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:SEP) op: Equal rhs: {(DQ ("-=-=-=-=-=-=-=-=-=# Don't remove this line #=-=-=-=-=-=-=-=-=-"))} spids: [25] ) ] spids: [25] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-e)} {(DQ ($ VSub_Name "$CONFFILE"))} {(Lit_Other "]")}) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LAST_DIR) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(grep)} {(-m)} {(1)} {(DQ ("^LAST_DIR="))} {(DQ (${ VSub_Name CONFFILE))} ) (C {(sed)} {(-e)} {(SQ <"s/^LAST_DIR=//">)}) ] negated: False ) ] ) left_token: spids: [48 72] ) } spids: [47] ) ] spids: [47] ) (C {(cd)} {(DQ (${ VSub_Name LAST_DIR))}) ] spids: [-1 44] ) ] else_action: [ (SimpleCommand words: [{(cd)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[88])] ) ] spids: [83 92] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PATCH) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(zenity)} {(--file-selection)})]) left_token: spids: [96 100] ) } spids: [95] ) ] spids: [95] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_QMark "$?"))} {(KW_Bang "!") (Lit_Other "=")} {(DQ (0))} {(Lit_Other "]")} ) terminator: ) ] action: [(C {(exit)} {(1)})] spids: [-1 122] ) ] spids: [-1 133] ) (SimpleCommand words: [{(cd)} {(-)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[140])] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:SUBJECT) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(sed)} {(-n)} {(-e)} {(SQ <"/^Subject: /p">)} {(DQ (${ VSub_Name PATCH))}) ] ) left_token: spids: [146 162] ) } spids: [145] ) ] spids: [145] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:HEADERS) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(sed)} {(-e)} {(SQ <"/^">) (DQ (${ VSub_Name SEP)) (SQ <"$/,$d">)} {($ VSub_Number "$1")} ) ] ) left_token: spids: [165 183] ) } spids: [164] ) ] spids: [164] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:BODY) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(sed)} {(-e)} {(DQ ("1,/") (${ VSub_Name SEP) (/d))} {($ VSub_Number "$1")}) ] ) left_token: spids: [186 200] ) } spids: [185] ) ] spids: [185] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CMT_MSG) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(sed)} {(-e)} {(SQ <"1,/^$/d">)} {(-e)} {(SQ <"/^---$/,$d">)} {(DQ (${ VSub_Name PATCH))} ) ] ) left_token: spids: [203 223] ) } spids: [202] ) ] spids: [202] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:DIFF) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(sed)} {(-e)} {(SQ <"1,/^---$/d">)} {(DQ (${ VSub_Name PATCH))})] ) left_token: spids: [226 240] ) } spids: [225] ) ] spids: [225] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CCS) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(-e)} { (DQ ($ VSub_Name "$CMT_MSG") (EscapedLiteralPart token: ) ($ VSub_Name "$HEADERS") ) } ) (C {(sed)} {(-n)} {(-e)} {(SQ <"s/^Cc: \\(.*\\)$/\\1,/gp">)} {(-e)} {(SQ <"s/^Signed-off-by: \\(.*\\)/\\1,/gp">)} ) ] negated: False ) ] ) left_token: spids: [244 274] ) } spids: [243] ) ] spids: [243] ) (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Name "$SUBJECT"))}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{($ VSub_Number "$1")} spids:[283])] ) (SimpleCommand words: [{(echo)} {(DQ ("Cc: ") ($ VSub_Name "$CCS"))}] redirects: [(Redir op_id:Redir_DGreat fd:-1 arg_word:{($ VSub_Number "$1")} spids:[294])] ) (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Name "$HEADERS"))}) (SimpleCommand words: [{(sed)} {(-e)} {(SQ <"/^Subject: /d">)} {(-e)} {(SQ <"/^Cc: /d">)}] redirects: [(Redir op_id:Redir_DGreat fd:-1 arg_word:{($ VSub_Number "$1")} spids:[320])] ) ] negated: False ) (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Name "$SEP"))}] redirects: [(Redir op_id:Redir_DGreat fd:-1 arg_word:{($ VSub_Number "$1")} spids:[330])] ) (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Name "$CMT_MSG"))}] redirects: [(Redir op_id:Redir_DGreat fd:-1 arg_word:{($ VSub_Number "$1")} spids:[341])] ) (SimpleCommand words: [{(echo)} {(DQ (---))}] redirects: [(Redir op_id:Redir_DGreat fd:-1 arg_word:{($ VSub_Number "$1")} spids:[351])] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ (x) (${ VSub_Name BODY) (x))} {(KW_Bang "!") (Lit_Other "=")} {(DQ (xx))} {(Lit_Other "]")} ) terminator: ) ] action: [ (SimpleCommand words: [{(echo)}] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {($ VSub_Number "$1")} spids: [383] ) ] ) (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Name "$BODY"))}] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {($ VSub_Number "$1")} spids: [394] ) ] ) (SimpleCommand words: [{(echo)}] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {($ VSub_Number "$1")} spids: [401] ) ] ) ] spids: [-1 378] ) ] spids: [-1 405] ) (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Name "$DIFF"))}] redirects: [(Redir op_id:Redir_DGreat fd:-1 arg_word:{($ VSub_Number "$1")} spids:[413])] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LAST_DIR) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(dirname)} {(DQ (${ VSub_Name PATCH))})]) left_token: spids: [419 427] ) } spids: [418] ) ] spids: [418] ) (SimpleCommand words: [{(grep)} {(-v)} {(DQ ("^LAST_DIR="))} {(DQ (${ VSub_Name CONFFILE))}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ (${ VSub_Name CONFFILE) (_))} spids: [444] ) ] ) (SimpleCommand words: [{(echo)} {(DQ ("LAST_DIR=") (${ VSub_Name LAST_DIR))}] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {(DQ (${ VSub_Name CONFFILE) (_))} spids: [462] ) ] ) (C {(mv)} {(DQ (${ VSub_Name CONFFILE) (_))} {(DQ (${ VSub_Name CONFFILE))}) ] )