{"thread":{"id":"32460","subject":"generating format-patch options from an e-mail","startedAt":"2012-12-26T20:28:30Z","lastAt":"2012-12-26T20:28:30Z","messageCount":1,"participants":["Simon Oosthoek"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"205506","messageId":"20121226202830.GA29813@simaj.xs4all.nl","threadId":"32460","inReplyTo":null,"subject":"generating format-patch options from an e-mail","fromName":"Simon Oosthoek","fromEmail":"s.oosthoek@xs4all.nl","sentAt":"2012-12-26T20:28:30Z","receivedAt":"2012-12-26T20:28:30Z","isPatch":false,"sender":{"key":"s.oosthoek@xs4all.nl","avatar":"https://avatars.githubusercontent.com/u/11677720?v=4"},"body":"Hi all\n\nI've been very frustrated by the process to setup a commandline for git format-patch, to include everyone in the cc list and reply to the right message-id.\n\nIn my frustration I created a perl script to generate the options from a saved e-mail, I realise that it may be non-general and perhaps it could be written better using a module which understands e-mails, but well, it worked for me ;-)\n\nAnyway, I could imagine this as optional flag of git format-patch, so you could say:\n$ git format-patch -s --in-reply-to-email <mboxfile> a7fe7de8\n\nBut I'll save that as an exercise for the reader (or the future)\n\nCheers\n\nSimon\n\nPS, now with the script\n\n\n#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\nour @to;\nour @cc;\nour @id;\nour $emptyline=0;\n\nif (defined $ARGV[0] and -f $ARGV[0]) {\n\topen (MAIL, \"<$ARGV[0]\") or die \"cannot open $ARGV[0]\\n\";\n\t#while (my $line=<MAIL> && ($emptyline == 0) ) {\n\twhile (my $line=<MAIL> ) {\n\t\t\tchomp $line;\n\t\t\tmy $header=\"\";\n\t\t\tmy $content=\"\";\n\t\t\n\t\t\tif ($line =~ /^(.*?):.*[ ,<](.*?@.*?)[>, ]/ ||\n\t\t\t\t\t$line =~ /^(.*ID?):.*[ ,<](.*?)[>, ]/) {\n\t\t\t\t\t$header=$1;\n\t\t\t\t\t$content=$2;\n\t\t\t\t\tif ($header eq \"From\") {\n\t\t\t\t\t\t\tpush(@to, $content);\n\t\t\t\t\t} if ($header eq \"To\") {\n\t\t\t\t\t\t\tpush(@cc, $content);\n\t\t\t\t\t} elsif ($header eq \"Cc\") {\n\t\t\t\t\t\t\t$line =~ /:(.*)$/;\n\t\t\t\t\t\t\tmy @ccs=split(/,/, $1);\n\t\t\t\t\t\t\tforeach my $addr (@ccs) {\n\t\t\t\t\t\t\t\t\tif ($addr =~ /<(.*)>/) {\n\t\t\t\t\t\t\t\t\t\t\tpush(@cc, $1);\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\tpush(@cc, $addr);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t} elsif ($header eq \"Message-ID\") {\n\t\t\t\t\t\t\tpush(@id, $content);\n\t\t\t\t\t}\n\t\t\t}\n\t\t\t$emptyline++ if (length($line) == 0);\n\n\t}\n\tclose (MAIL);\n}\n\n\nforeach my $item (@to) {\n\t\tprint \" --to \\\"$item\\\"\";\n}\nforeach my $item (@cc) {\n\t\tprint \" --cc \\\"$item\\\"\";\n}\nforeach my $item (@id) {\n\t\tprint \" --in-reply-to \\\"$item\\\"\";\n}\n"}]}