git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] send-email: add extra safetly in address sanitazion
@ 2012-02-04 16:32 Felipe Contreras
  2012-02-05 19:39 ` Thomas Rast
  0 siblings, 1 reply; 11+ messages in thread
From: Felipe Contreras @ 2012-02-04 16:32 UTC (permalink / raw)
  To: git
  Cc: Felipe Contreras, Brandon Casey, Uwe Kleine-König,
	Brian Gernhardt, Robin H. Johnson,
	Ævar Arnfjörð Bjarmason

Currently bad addresses like 'Foo Bar <foo@bar.com>>' will just be sent
verbatim -- that's not good; we should either error out, or sanitize
them.

The following patch adds extra sanitazion so the following
transformations are performed:

  'Foo Bar <foo@bar.com>' -> 'Foo Bar <foo@bar.com>'
  '"Foo Bar" <foo@bar.com>' -> '"Foo Bar" <foo@bar.com>'
  'foo@bar.com' -> 'foo@bar.com'
  '<foo@bar.com>' -> 'foo@bar.com'
  'Foo Bar' -> 'Foo Bar'
  'Foo Bar <foo@bar.com>>' -> 'Foo Bar <foo@bar.com>'
  '"Foo Bar" <foo@bar.com>>' -> '"Foo Bar" <foo@bar.com>'
  '<foo@bar.com>>' -> 'foo@bar.com'

Basically, we try to check that the address is in the form of
"Name <email>", and if not, assume it's "email". According to commit
155197e[1], the "prhase" should not be empty, so if it is, remove the
<>. Extra characters after the first ">" are ignored.

[1] send-email: rfc822 forbids using <address@domain> without a non-empty "phrase"

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 git-send-email.perl |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index ef30c55..19c600f 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -889,15 +889,21 @@ sub is_rfc2047_quoted {
 # use the simplest quoting being able to handle the recipient
 sub sanitize_address {
 	my ($recipient) = @_;
-	my ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)\s*(<.*)/);
+	my ($recipient_name, $recipient_addr);
+
+	if ($recipient =~ /^(.*?)\s*<(.*?)>/) {
+		($recipient_name, $recipient_addr) = ($1, $2);
+	} else {
+		$recipient_addr = $recipient;
+	}
 
 	if (not $recipient_name) {
-		return $recipient;
+		return $recipient_addr;
 	}
 
 	# if recipient_name is already quoted, do nothing
 	if (is_rfc2047_quoted($recipient_name)) {
-		return $recipient;
+		return "$recipient_name <$recipient_addr>";
 	}
 
 	# rfc2047 is needed if a non-ascii char is included
@@ -912,7 +918,7 @@ sub sanitize_address {
 		$recipient_name = qq["$recipient_name"];
 	}
 
-	return "$recipient_name $recipient_addr";
+	return "$recipient_name <$recipient_addr>";
 
 }
 
-- 
1.7.9

^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [PATCH] send-email: add extra safetly in address sanitazion
@ 2012-02-04 15:10 Felipe Contreras
  2012-02-04 15:26 ` Felipe Contreras
  0 siblings, 1 reply; 11+ messages in thread
From: Felipe Contreras @ 2012-02-04 15:10 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Felipe Contreras

Otherwise, 'git send-email' would be happy to do:

 % git send-email --to '<foo@bar.com>>'

And use '<foo@bar.com>>' in the headers.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 git-send-email.perl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index ef30c55..b8bf014 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -889,7 +889,7 @@ sub is_rfc2047_quoted {
 # use the simplest quoting being able to handle the recipient
 sub sanitize_address {
 	my ($recipient) = @_;
-	my ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)\s*(<.*)/);
+	my ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)\s*(<.*?>)/);
 
 	if (not $recipient_name) {
 		return $recipient;
-- 
1.7.9

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-02-06  1:49 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-04 16:32 [PATCH] send-email: add extra safetly in address sanitazion Felipe Contreras
2012-02-05 19:39 ` Thomas Rast
2012-02-05 20:51   ` Felipe Contreras
2012-02-05 21:51     ` Thomas Rast
2012-02-06  1:27       ` Felipe Contreras
2012-02-06  1:48         ` Junio C Hamano
2012-02-05 21:52   ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2012-02-04 15:10 Felipe Contreras
2012-02-04 15:26 ` Felipe Contreras
2012-02-05 21:12   ` Junio C Hamano
2012-02-05 21:20     ` Felipe Contreras

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).