# [PATCH] send-email: extend sanitize_address_rfc822 to do rfc2047 quoting

7 messages from 2007-07-10 to 2007-07-11. Participants: Uwe Kleine-König, Sven Verdoolaege.
Thread: https://gitlist.dev/t/8968

## Uwe Kleine-König, 2007-07-10 17:02

Subject: [PATCH] send-email: extend sanitize_address_rfc822 to do rfc2047 quoting
Message-ID: <11840869641759-git-send-email-ukleinek@informatik.uni-freiburg.de>
URL: https://gitlist.dev/e/11840869641759-git-send-email-ukleinek%40informatik.uni-freiburg.de

```
Without this patch I'm not able to properly send emails as I have a
non-ascii character in my name.

Signed-off-by: Uwe Kleine-König <ukleinek@informatik.uni-freiburg.de>
---
As I'm not a perl profi, someone wants to check this code.

Actually this series is a test, as it is sended with the patched send-email.

I hope it works :-)

Uwe

 git-send-email.perl |   24 +++++++++++++++++++-----
 1 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index 89f7c36..8b3d450 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -459,16 +459,30 @@ sub unquote_rfc2047 {
 	return "$_";
 }
 
-# If an address contains a . in the name portion, the name must be quoted.
+# If an address contains a non-ascii char in the name port, quote it according
+# to rfc2047.
+# If an address contains a . in the name portion, the name must be quoted using
+# double quotes.
 sub sanitize_address_rfc822
 {
 	my ($recipient) = @_;
-	my ($recipient_name) = ($recipient =~ /^(.*?)\s+</);
+	my ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)(\s+<.*)/);
+
+	if ($recipient_name && $recipient_name =~ /[^-a-zA-Z0-9!*+\/ ]/ && $recipient_name !~ /=\?utf-8\?q?.*\?=/) {
+		$recipient_name =~ s/([^-a-zA-Z0-9!*+ ])/sprintf("=%02X", ord($1))/eg;
+		$recipient_name =~ s/ /_/;
+		$recipient_name =~ s/(.*)/=\?utf-8\?q\?$1\?=/;
+	}
+
 	if ($recipient_name && $recipient_name =~ /\./ && $recipient_name !~ /^".*"$/) {
-		my ($name, $addr) = ($recipient =~ /^(.*?)(\s+<.*)/);
-		$recipient = "\"$name\"$addr";
+		$recipient_name = "\"$recipient_name\"";
+	}
+
+	if ($recipient_name) {
+		return "$recipient_name$recipient_addr";
+	} else {
+		return "$recipient";
 	}
-	return $recipient;
 }
 
 sub send_message
-- 
1.5.3.rc0.823.gdedbf

```

## Uwe Kleine-König, 2007-07-10 17:02

Subject: [PATCH] [RFC] send-email: honor --suppress-from --signed-off-cc
Message-ID: <11840869671745-git-send-email-ukleinek@informatik.uni-freiburg.de>
URL: https://gitlist.dev/e/11840869671745-git-send-email-ukleinek%40informatik.uni-freiburg.de
In-Reply-To: <11840869641759-git-send-email-ukleinek@informatik.uni-freiburg.de>

```
From: Uwe Kleine-KÃ¶nig <ukleinek@informatik.uni-freiburg.de>

---
Not sure, if this is how it should be.  Maybe we need another flag?

Best regards
Uwe

 git-send-email.perl |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index 8b3d450..a03153b 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -641,9 +641,11 @@ foreach my $t (@files) {
 			if (/^(Signed-off-by|Cc): (.*)$/i && $signed_off_cc) {
 				my $c = $2;
 				chomp $c;
-				push @cc, $c;
-				printf("(sob) Adding cc: %s from line '%s'\n",
-					$c, $_) unless $quiet;
+				if (!$suppress_from or $c eq $from) {
+					push @cc, $c;
+					printf("(sob) Adding cc: %s from line '%s'\n",
+						$c, $_) unless $quiet;
+				}
 			}
 		}
 	}
-- 
1.5.3.rc0.823.gdedbf

```

## Uwe Kleine-König, 2007-07-11 07:55

Subject: Re: [PATCH] [RFC] send-email: honor --suppress-from --signed-off-cc
Message-ID: <20070711075519.GB5815@informatik.uni-freiburg.de>
URL: https://gitlist.dev/e/20070711075519.GB5815%40informatik.uni-freiburg.de
In-Reply-To: <11840869671745-git-send-email-ukleinek@informatik.uni-freiburg.de>

```
Hello,

please forget that second patch, it was sent with a dirty send-email and
even that was wrong.  The first patch however is IMHO a good one.

I will look again into my issues with send-email probably next week.

Best regards
Uwe

-- 
Uwe Kleine-König

http://www.google.com/search?q=5%2B7

```

## Sven Verdoolaege, 2007-07-11 08:42

Subject: Re: [PATCH] send-email: extend sanitize_address_rfc822 to do rfc2047 quoting
Message-ID: <20070711084232.GE1528MdfPADPa@greensroom.kotnet.org>
URL: https://gitlist.dev/e/20070711084232.GE1528MdfPADPa%40greensroom.kotnet.org
In-Reply-To: <11840869641759-git-send-email-ukleinek@informatik.uni-freiburg.de>

```
On Tue, Jul 10, 2007 at 07:02:43PM +0200, Uwe Kleine-König wrote:
>  	my ($recipient) = @_;
> -	my ($recipient_name) = ($recipient =~ /^(.*?)\s+</);
> +	my ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)(\s+<.*)/);
> +
> +	if ($recipient_name && $recipient_name =~ /[^-a-zA-Z0-9!*+\/ ]/ && $recipient_name !~ /=\?utf-8\?q?.*\?=/) {

Why the extra test for truthness of $recipient_name ?

>  	if ($recipient_name && $recipient_name =~ /\./ && $recipient_name !~ /^".*"$/) {
> -		my ($name, $addr) = ($recipient =~ /^(.*?)(\s+<.*)/);
> -		$recipient = "\"$name\"$addr";
> +		$recipient_name = "\"$recipient_name\"";
> +	}
> +
> +	if ($recipient_name) {
> +		return "$recipient_name$recipient_addr";
> +	} else {
> +		return "$recipient";
>  	}
> -	return $recipient;

Why did you introduce interpolation just to get $recipient again?
Then again, why do you need a test at all here?

	return $recipient_name . $recipient_addr;

should work, no?

skimo

```

## Uwe Kleine-König, 2007-07-11 11:49

Subject: Re: [PATCH] send-email: extend sanitize_address_rfc822 to do rfc2047 quoting
Message-ID: <20070711114909.GA14086@informatik.uni-freiburg.de>
URL: https://gitlist.dev/e/20070711114909.GA14086%40informatik.uni-freiburg.de
In-Reply-To: <20070711084232.GE1528MdfPADPa@greensroom.kotnet.org>

```
Sven Verdoolaege wrote:
> On Tue, Jul 10, 2007 at 07:02:43PM +0200, Uwe Kleine-König wrote:
> >  	my ($recipient) = @_;
> > -	my ($recipient_name) = ($recipient =~ /^(.*?)\s+</);
> > +	my ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)(\s+<.*)/);
> > +
> > +	if ($recipient_name && $recipient_name =~ /[^-a-zA-Z0-9!*+\/ ]/ && $recipient_name !~ /=\?utf-8\?q?.*\?=/) {
> 
> Why the extra test for truthness of $recipient_name ?
Try:

	my $recipient = 'skimo@kotnet.org';
	my ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)(\s+<.*)/);
	print "Hoppla\n" if (!$recipient_name);

i.e. if the pattern doesn't match, recipient_name is undefined.

But the function could be simplyfied anyhow.  e.g.

	if ($recipient_name) {
		... do all the quoting ...
		return "$recipient_name$recipient_addr";
	} else {
		return $recipient;
	}

Best regards
Uwe

-- 
Uwe Kleine-König

http://www.google.com/search?q=square+root+of+2

```

## Sven Verdoolaege, 2007-07-11 12:08

Subject: Re: [PATCH] send-email: extend sanitize_address_rfc822 to do rfc2047 quoting
Message-ID: <20070711120807.GH1528MdfPADPa@greensroom.kotnet.org>
URL: https://gitlist.dev/e/20070711120807.GH1528MdfPADPa%40greensroom.kotnet.org
In-Reply-To: <20070711114909.GA14086@informatik.uni-freiburg.de>

```
On Wed, Jul 11, 2007 at 01:49:09PM +0200, Uwe Kleine-König wrote:
> Sven Verdoolaege wrote:
> > On Tue, Jul 10, 2007 at 07:02:43PM +0200, Uwe Kleine-König wrote:
> > >  	my ($recipient) = @_;
> > > -	my ($recipient_name) = ($recipient =~ /^(.*?)\s+</);
> > > +	my ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)(\s+<.*)/);
> > > +
> > > +	if ($recipient_name && $recipient_name =~ /[^-a-zA-Z0-9!*+\/ ]/ && $recipient_name !~ /=\?utf-8\?q?.*\?=/) {
> > 
> > Why the extra test for truthness of $recipient_name ?
> 
> i.e. if the pattern doesn't match, recipient_name is undefined.

I know.  I just didn't realize git-send-email was run with -w.
Sorry for the noise.

skimo

```

## Sven Verdoolaege, 2007-07-11 12:49

Subject: Re: [PATCH] send-email: extend sanitize_address_rfc822 to do rfc2047 quoting
Message-ID: <20070711124928.GJ1528MdfPADPa@greensroom.kotnet.org>
URL: https://gitlist.dev/e/20070711124928.GJ1528MdfPADPa%40greensroom.kotnet.org
In-Reply-To: <81b0412b0707110538s7eda05e8g6973e20fc4d91931@mail.gmail.com>

```
On Wed, Jul 11, 2007 at 02:38:11PM +0200, Alex Riesen wrote:
> On 7/11/07, Uwe Kleine-König <ukleinek@informatik.uni-freiburg.de> wrote:
> >Try:
> >
> >        my $recipient = 'skimo@kotnet.org';
> >        my ($recipient_name, $recipient_addr) = ($recipient =~ 
> >        /^(.*?)(\s+<.*)/);
> >        print "Hoppla\n" if (!$recipient_name);
> 
> Still wrong. Try it on "0 <0user@buildhost.localnet>"

I was going to suggest using defined($recipient_name) to make it clear,
but it won't affect correctness as "0" won't match the regexps in
sanitize_address_rfc822 anyway.

skimo

```
