Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the SVN-Notify CPAN distribution.

Report information
The Basics
Id: 20630
Status: resolved
Worked: 30 min
Priority: 0/
Queue: SVN-Notify

People
Owner: dwheeler [...] cpan.org
Requestors: rjbs [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: 2.63



Subject: --add-header to add arbitrary headers
I'd like to be able to add arbitrary headers to the email, to include things like auto-approval for MLMs. Patch with tests attached. -- rjbs
Subject: add-header.patch
diff -Nur SVN-Notify-2.62/MANIFEST SVN-Notify-rjbs/MANIFEST --- SVN-Notify-2.62/MANIFEST 2006-06-30 14:03:25.000000000 -0400 +++ SVN-Notify-rjbs/MANIFEST 2006-07-22 20:56:54.000000000 -0400 @@ -31,6 +31,7 @@ t/data/info/222.txt t/data/info/333.txt t/data/info/444.txt +t/add-header.t t/errors.t t/html.t t/htmlcolordiff.t diff -Nur SVN-Notify-2.62/lib/SVN/Notify.pm SVN-Notify-rjbs/lib/SVN/Notify.pm --- SVN-Notify-2.62/lib/SVN/Notify.pm 2006-06-30 14:03:26.000000000 -0400 +++ SVN-Notify-rjbs/lib/SVN/Notify.pm 2006-07-22 20:40:34.000000000 -0400 @@ -571,6 +571,7 @@ $params{svnlook} ||= $ENV{SVNLOOK} || $class->find_exe('svnlook'); $params{with_diff} ||= $params{attach_diff}; $params{verbose} ||= 0; + $params{extra_headers} ||= []; $params{charset} ||= 'UTF-8'; $params{io_layer} ||= "encoding($params{charset})"; $params{smtp_authtype} ||= 'PLAIN'; @@ -588,6 +589,16 @@ $params{revision_url} .= '/revision/?rev=%s&view=rev' } + # Parse extra headers. + if (my @extra_headers = @{ $params{extra_headers} }) { + my @headers; + for my $string (@extra_headers) { + my @pair = split /=/, $string, 2; + push @headers, \@pair; + } + $params{extra_headers} = \@headers; + } + # Make it so! $class->_dbpnt( "Instantiating $class object") if $params{verbose}; @@ -690,6 +701,7 @@ 'attach-diff|a' => \$opts->{attach_diff}, 'diff-switches|w=s' => \$opts->{diff_switches}, 'reply-to|R=s' => \$opts->{reply_to}, + 'add-header=s@' => \$opts->{extra_headers}, 'subject-prefix|P=s' => \$opts->{subject_prefix}, 'subject-cx|C' => \$opts->{subject_cx}, 'strip-cx-regex|X=s@' => \$opts->{strip_cx_regex}, @@ -1142,6 +1154,13 @@ print $out "X-Mailer: SVN::Notify ", $self->VERSION, ": http://search.cpan.org/dist/SVN-Notify/\n"; + if ($self->{extra_headers}) { + for my $header (@{ $self->{extra_headers} }) { + my ($name, $value) = @$header; + print $out "$name: $value\n"; + } + } + return $self; } diff -Nur SVN-Notify-2.62/t/add-header.t SVN-Notify-rjbs/t/add-header.t --- SVN-Notify-2.62/t/add-header.t 1969-12-31 19:00:00.000000000 -0500 +++ SVN-Notify-rjbs/t/add-header.t 2006-07-22 20:56:35.000000000 -0400 @@ -0,0 +1,59 @@ +#!perl +use strict; +use warnings; + +use Test::More; + +eval { require IO::String; }; +plan skip_all => "IO::String required for these tests." if $@; + +plan tests => 2; + +use SVN::Notify; + +{ # First, make sure the test basically makes sense: + my $io = IO::String->new; + + my $notify = SVN::Notify->new( + repos_path => 'whatever', + revision => 'whatever', + to => [ qw(test@test.example.com) ], + ); + + $notify->output_headers($io); + + $io->seek(0,0); + my $output = do { local $/; <$io>; }; + + like( + $output, + qr/^To: test\@test\.example\.com\n/m, + "the output includes To:" + ); +} + +{ # Then try it with + my $io = IO::String->new; + + my $notify = SVN::Notify->new( + repos_path => 'whatever', + revision => 'whatever', + to => [ qw(test@test.example.com) ], + extra_headers => [ + 'Approve=secret password', + 'X-Flavor=vegemite', + ], + ); + + $notify->output_headers($io); + + $io->seek(0,0); + my $output = do { local $/; <$io>; }; + + like( + $output, + qr/^Approve: secret password\nX-Flavor: vegemite\n/m, + "the output includes extra headers" + ); +} +
Subject: Re: [rt.cpan.org #20630] --add-header to add arbitrary headers
Date: Sun, 23 Jul 2006 09:42:05 -0700
To: bug-SVN-Notify [...] rt.cpan.org
From: David Wheeler <dwheeler [...] cpan.org>
On Jul 22, 2006, at 17:59, Ricardo Signes via RT wrote: Show quoted text
> Patch with tests attached.
Yeah, but no docs. Also, you can use 'add-header=s%' in Getopt::Long to just get a hash without having to parse it yourself. --to-regex- map does that. Thanks, David
Subject: Re: [rt.cpan.org #20630] --add-header to add arbitrary headers
Date: Sun, 23 Jul 2006 13:40:26 -0400
To: David Wheeler via RT <bug-SVN-Notify [...] rt.cpan.org>
From: Ricardo SIGNES <rjbs [...] cpan.org>
* David Wheeler via RT <bug-SVN-Notify@rt.cpan.org> [2006-07-23T12:49:09] Show quoted text
> On Jul 22, 2006, at 17:59, Ricardo Signes via RT wrote: >
> > Patch with tests attached.
> > Yeah, but no docs.
Oops. :( Show quoted text
> Also, you can use 'add-header=s%' in Getopt::Long to just get a hash without > having to parse it yourself. --to-regex- map does that.
The header of an email message is a list of name/value pairs, but it is not a hash. svnnotify --add-header Foo=bar --add-header Foo=baz -- rjbs
Download signature.asc
application/pgp-signature 189b

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #20630] --add-header to add arbitrary headers
Date: Sun, 23 Jul 2006 12:14:39 -0700
To: bug-SVN-Notify [...] rt.cpan.org
From: David Wheeler <david [...] kineticode.com>
On Jul 23, 2006, at 10:47, Ricardo Signes via RT wrote: Show quoted text
> Oops. :( >
>> Also, you can use 'add-header=s%' in Getopt::Long to just get a >> hash without >> having to parse it yourself. --to-regex- map does that.
> > The header of an email message is a list of name/value pairs, but > it is not a > hash. > > svnnotify --add-header Foo=bar --add-header Foo=baz
Yeah, but that's exactly the syntax you can use to make it into a hash by using 'add-header=s%'. Then SVN::Notify doesn't have to parse the name/value pairs. Best, David
Subject: Re: [rt.cpan.org #20630] --add-header to add arbitrary headers
Date: Sun, 23 Jul 2006 15:37:31 -0400
To: David Wheeler via RT <bug-SVN-Notify [...] rt.cpan.org>
From: Ricardo SIGNES <rjbs [...] cpan.org>
* David Wheeler via RT <bug-SVN-Notify@rt.cpan.org> [2006-07-23T15:15:03] Show quoted text
> > svnnotify --add-header Foo=bar --add-header Foo=baz
> > Yeah, but that's exactly the syntax you can use to make it into a > hash by using 'add-header=s%'. Then SVN::Notify doesn't have to parse > the name/value pairs.
Right. I could use =s% to get the incorrect behavior very easily. How would that be helpful? It should be possible to have two added values for one header. If we use a hash, only one can be kept. ~/tmp$ perl getopt --foo bar=x --foo baz=12 --foo baz=13 $VAR1 = { 'bar' => 'x', 'baz' => '13' }; -- rjbs
Download signature.asc
application/pgp-signature 189b

Message body not shown because it is not plain text.

The attached patch is identical, but documents the switch. -- rjbs
diff -Nur SVN-Notify-2.62/MANIFEST SVN-Notify-rjbs/MANIFEST --- SVN-Notify-2.62/MANIFEST 2006-06-30 14:03:25.000000000 -0400 +++ SVN-Notify-rjbs/MANIFEST 2006-07-22 20:56:54.000000000 -0400 @@ -31,6 +31,7 @@ t/data/info/222.txt t/data/info/333.txt t/data/info/444.txt +t/add-header.t t/errors.t t/html.t t/htmlcolordiff.t diff -Nur SVN-Notify-2.62/bin/svnnotify SVN-Notify-rjbs/bin/svnnotify --- SVN-Notify-2.62/bin/svnnotify 2006-06-30 14:03:25.000000000 -0400 +++ SVN-Notify-rjbs/bin/svnnotify 2006-07-23 15:38:14.000000000 -0400 @@ -81,6 +81,7 @@ -a --attach-diff Attach the diff to the message. -w --diff-switches SWITCHES Switches to pass to C<svnlook diff>. -R --reply-to ADDRESS Address for use in the Reply-To header. + --add-header NAME=VALUE Extra email headers to add -P --subject-prefix PREFIX String to prepend to the subject. -C --subject-cx Include the context of the commit in the subject. diff -Nur SVN-Notify-2.62/lib/SVN/Notify.pm SVN-Notify-rjbs/lib/SVN/Notify.pm --- SVN-Notify-2.62/lib/SVN/Notify.pm 2006-06-30 14:03:26.000000000 -0400 +++ SVN-Notify-rjbs/lib/SVN/Notify.pm 2006-07-22 20:40:34.000000000 -0400 @@ -571,6 +571,7 @@ $params{svnlook} ||= $ENV{SVNLOOK} || $class->find_exe('svnlook'); $params{with_diff} ||= $params{attach_diff}; $params{verbose} ||= 0; + $params{extra_headers} ||= []; $params{charset} ||= 'UTF-8'; $params{io_layer} ||= "encoding($params{charset})"; $params{smtp_authtype} ||= 'PLAIN'; @@ -588,6 +589,16 @@ $params{revision_url} .= '/revision/?rev=%s&view=rev' } + # Parse extra headers. + if (my @extra_headers = @{ $params{extra_headers} }) { + my @headers; + for my $string (@extra_headers) { + my @pair = split /=/, $string, 2; + push @headers, \@pair; + } + $params{extra_headers} = \@headers; + } + # Make it so! $class->_dbpnt( "Instantiating $class object") if $params{verbose}; @@ -690,6 +701,7 @@ 'attach-diff|a' => \$opts->{attach_diff}, 'diff-switches|w=s' => \$opts->{diff_switches}, 'reply-to|R=s' => \$opts->{reply_to}, + 'add-header=s@' => \$opts->{extra_headers}, 'subject-prefix|P=s' => \$opts->{subject_prefix}, 'subject-cx|C' => \$opts->{subject_cx}, 'strip-cx-regex|X=s@' => \$opts->{strip_cx_regex}, @@ -1142,6 +1154,13 @@ print $out "X-Mailer: SVN::Notify ", $self->VERSION, ": http://search.cpan.org/dist/SVN-Notify/\n"; + if ($self->{extra_headers}) { + for my $header (@{ $self->{extra_headers} }) { + my ($name, $value) = @$header; + print $out "$name: $value\n"; + } + } + return $self; } diff -Nur SVN-Notify-2.62/t/add-header.t SVN-Notify-rjbs/t/add-header.t --- SVN-Notify-2.62/t/add-header.t 1969-12-31 19:00:00.000000000 -0500 +++ SVN-Notify-rjbs/t/add-header.t 2006-07-22 20:56:35.000000000 -0400 @@ -0,0 +1,59 @@ +#!perl +use strict; +use warnings; + +use Test::More; + +eval { require IO::String; }; +plan skip_all => "IO::String required for these tests." if $@; + +plan tests => 2; + +use SVN::Notify; + +{ # First, make sure the test basically makes sense: + my $io = IO::String->new; + + my $notify = SVN::Notify->new( + repos_path => 'whatever', + revision => 'whatever', + to => [ qw(test@test.example.com) ], + ); + + $notify->output_headers($io); + + $io->seek(0,0); + my $output = do { local $/; <$io>; }; + + like( + $output, + qr/^To: test\@test\.example\.com\n/m, + "the output includes To:" + ); +} + +{ # Then try it with + my $io = IO::String->new; + + my $notify = SVN::Notify->new( + repos_path => 'whatever', + revision => 'whatever', + to => [ qw(test@test.example.com) ], + extra_headers => [ + 'Approve=secret password', + 'X-Flavor=vegemite', + ], + ); + + $notify->output_headers($io); + + $io->seek(0,0); + my $output = do { local $/; <$io>; }; + + like( + $output, + qr/^Approve: secret password\nX-Flavor: vegemite\n/m, + "the output includes extra headers" + ); +} +
Subject: Re: [rt.cpan.org #20630] --add-header to add arbitrary headers
Date: Sun, 23 Jul 2006 14:10:59 -0700
To: bug-SVN-Notify [...] rt.cpan.org
From: David Wheeler <dwheeler [...] cpan.org>
On Jul 23, 2006, at 12:37, Ricardo Signes via RT wrote: Show quoted text
> Right. I could use =s% to get the incorrect behavior very easily. > How would > that be helpful? > > It should be possible to have two added values for one header. If > we use a > hash, only one can be kept.
Ah, right, good point. But we can still let Getopt::Long do the parsing. Check out this script: use Getopt::Long; use Data::Dumper; my $f; GetOptions( 'foo=s%' => sub { shift; push @{ $f->{+shift} }, shift } ); Print Dumper $f Best, David
Committed, with significant modification. Released in 2.63. Thanks!