{"thread":{"id":"21135","subject":"[PATCH] git-send-email.perl: Fold long header lines to 78 chars","startedAt":"2009-10-05T16:24:58Z","lastAt":"2009-10-10T00:57:26Z","messageCount":7,"participants":["Joe Perches","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"124260","messageId":"1254759898.1799.449.camel@Joe-Laptop.home","threadId":"21135","inReplyTo":null,"subject":"[PATCH] git-send-email.perl: Fold long header lines to 78 chars","fromName":"Joe Perches","fromEmail":"joe@perches.com","sentAt":"2009-10-05T16:24:58Z","receivedAt":"2009-10-05T16:24:58Z","isPatch":true,"sender":{"key":"joe@perches.com","avatar":"https://avatars.githubusercontent.com/u/13122723?v=4"},"body":"Some MTAs reject or filter long header lines which can\nbe generated if the cc list is only a few entries.\n\nFold long header lines to 78 chars to be more rfc compliant.\n\nSigned-off-by: Joe Perches <joe@perches.com>\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex dd821f7..cb8b48b 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -814,6 +814,41 @@ sub sanitize_address\n \n }\n \n+# Fold header lines to 78 chars if possible for better RFC 2822 compliance\n+# Does not terminate last line with newline\n+sub fold_header\n+{\n+    my ($folded_line, $separator, @entries) = @_;\n+    my $folded_header = \"\";\n+    my $count = 0;\n+    my $trim_sep = $separator;\n+\n+    $trim_sep =~ s/\\s+$//;\n+\n+    foreach my $entry (@entries) {\n+\tif ($count == 0) {\n+\t    $folded_line = \"$folded_line$entry\";\n+\t} elsif ((length($folded_line) + length($entry)) > 78) {\n+\t    if ($folded_header ne \"\") {\n+\t\t$folded_header = \"$folded_header$trim_sep\\n\";\n+\t    }\n+\t    $folded_header = \"$folded_header$folded_line\";\n+\t    $folded_line = \" $entry\";\n+\t} else {\n+\t    $folded_line = \"$folded_line$separator$entry\";\n+\t}\n+\t$count++;\n+    }\n+\n+    if ($count == 0) {\n+\t$folded_header = \"$folded_line\";\n+    } else {\n+\t$folded_header = \"$folded_header$trim_sep\\n$folded_line\";\n+    }\n+\n+    return \"$folded_header\";\n+}\n+\n # Returns 1 if the message was sent, and 0 otherwise.\n # In actuality, the whole program dies when there\n # is an error sending a message.\n@@ -835,10 +870,10 @@ sub send_message\n \t    $gitversion = Git::version();\n \t}\n \n-\tmy $cc = join(\", \", unique_email_list(@cc));\n+\t@cc = unique_email_list(@cc);\n \tmy $ccline = \"\";\n-\tif ($cc ne '') {\n-\t\t$ccline = \"\\nCc: $cc\";\n+\tif (@cc gt 0) {\n+\t\t$ccline = fold_header(\"\\nCc: \", \", \", @cc);\n \t}\n \tmy $sanitized_sender = sanitize_address($sender);\n \tmake_message_id() unless defined($message_id);\n@@ -976,7 +1011,7 @@ X-Mailer: git-send-email $gitversion\n \t\tif ($smtp_server !~ m#^/#) {\n \t\t\tprint \"Server: $smtp_server\\n\";\n \t\t\tprint \"MAIL FROM:<$raw_from>\\n\";\n-\t\t\tprint \"RCPT TO:\".join(',',(map { \"<$_>\" } @recipients)).\"\\n\";\n+\t\t\tprint fold_header(\"RCPT TO:\", \",\", map { \"<$_>\" } @recipients).\"\\n\";\n \t\t} else {\n \t\t\tprint \"Sendmail: $smtp_server \".join(' ',@sendmail_parameters).\"\\n\";\n \t\t}\n"},{"id":"124359","messageId":"7vd44yo4uz.fsf@alter.siamese.dyndns.org","threadId":"21135","inReplyTo":"1254759898.1799.449.camel@Joe-Laptop.home","subject":"Re: [PATCH] git-send-email.perl: Fold long header lines to 78 chars","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-08T05:02:28Z","receivedAt":"2009-10-08T05:02:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Joe Perches <joe@perches.com> writes:\n\n> Some MTAs reject or filter long header lines which can\n> be generated if the cc list is only a few entries.\n>\n> Fold long header lines to 78 chars to be more rfc compliant.\n>\n> Signed-off-by: Joe Perches <joe@perches.com>\n>\n> diff --git a/git-send-email.perl b/git-send-email.perl\n> index dd821f7..cb8b48b 100755\n> --- a/git-send-email.perl\n> +++ b/git-send-email.perl\n> @@ -835,10 +870,10 @@ sub send_message\n>  \t    $gitversion = Git::version();\n>  \t}\n>  \n> -\tmy $cc = join(\", \", unique_email_list(@cc));\n> +\t@cc = unique_email_list(@cc);\n>  \tmy $ccline = \"\";\n> -\tif ($cc ne '') {\n> -\t\t$ccline = \"\\nCc: $cc\";\n> +\tif (@cc gt 0) {\n\n\"gt\"?  I think you meant (@cc > 0) but you can also say \"if (@cc) {\" which\nwould most clearly convey what you want to say..\n\n> +\t\t$ccline = fold_header(\"\\nCc: \", \", \", @cc);\n>  \t}\n>  \tmy $sanitized_sender = sanitize_address($sender);\n>  \tmake_message_id() unless defined($message_id);\n> @@ -976,7 +1011,7 @@ X-Mailer: git-send-email $gitversion\n>  \t\tif ($smtp_server !~ m#^/#) {\n>  \t\t\tprint \"Server: $smtp_server\\n\";\n>  \t\t\tprint \"MAIL FROM:<$raw_from>\\n\";\n> -\t\t\tprint \"RCPT TO:\".join(',',(map { \"<$_>\" } @recipients)).\"\\n\";\n> +\t\t\tprint fold_header(\"RCPT TO:\", \",\", map { \"<$_>\" } @recipients).\"\\n\";\nI do not think this hunk is correct.\n\nShouldn't we be rather repeating \"RCPT TO: \" for each recipient, as\nRFC2821 4.1.1.3 says (this is an issue with the original code)?  I do not\nthink SMTP's \"RCPT TO\" command has the notion of continuation line used\nfor the payload (i.e. RFC 2822 Internet Message Format), and folding the\nline is a new bug this patch introduces.\n\n>  \t\t} else {\n>  \t\t\tprint \"Sendmail: $smtp_server \".join(' ',@sendmail_parameters).\"\\n\";\n>  \t\t}\n"},{"id":"124361","messageId":"1254979690.2056.103.camel@Joe-Laptop.home","threadId":"21135","inReplyTo":"7vd44yo4uz.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] git-send-email.perl: Fold long header lines to 78 chars","fromName":"Joe Perches","fromEmail":"joe@perches.com","sentAt":"2009-10-08T05:28:10Z","receivedAt":"2009-10-08T05:28:10Z","isPatch":true,"sender":{"key":"joe@perches.com","avatar":"https://avatars.githubusercontent.com/u/13122723?v=4"},"body":"On Wed, 2009-10-07 at 22:02 -0700, Junio C Hamano wrote:\n> Joe Perches <joe@perches.com> writes:\n> > Some MTAs reject or filter long header lines which can\n> > be generated if the cc list is only a few entries.\n> > Fold long header lines to 78 chars to be more rfc compliant.\n> >\n> > -\tmy $cc = join(\", \", unique_email_list(@cc));\n\nIt's probably better/simpler to not use fold_header and\njust do the same join as \"my $to\"\n\n\tmy $cc = join(\",\\n\\t\", unique_email_list(@cc));\n\n> >  \t\tif ($smtp_server !~ m#^/#) {\n> >  \t\t\tprint \"Server: $smtp_server\\n\";\n> >  \t\t\tprint \"MAIL FROM:<$raw_from>\\n\";\n> > -\t\t\tprint \"RCPT TO:\".join(',',(map { \"<$_>\" } @recipients)).\"\\n\";\n> > +\t\t\tprint fold_header(\"RCPT TO:\", \",\", map { \"<$_>\" } @recipients).\"\\n\";\n> I do not think this hunk is correct.\n> Shouldn't we be rather repeating \"RCPT TO: \" for each recipient, as\n> RFC2821 4.1.1.3 says (this is an issue with the original code)?\n\nLooks like you're right.\n\nWant a new patch or will you fix both issues?\n\nI suggest using the same join as \"To:\" for \"Cc:\" and\nmultiple single line \"RCPT TO:\"s.\n"},{"id":"124384","messageId":"7vy6nlhmw7.fsf@alter.siamese.dyndns.org","threadId":"21135","inReplyTo":"1254979690.2056.103.camel@Joe-Laptop.home","subject":"Re: [PATCH] git-send-email.perl: Fold long header lines to 78 chars","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-08T16:27:04Z","receivedAt":"2009-10-08T16:27:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Joe Perches <joe@perches.com> writes:\n\n>> I do not think this hunk is correct.\n>> Shouldn't we be rather repeating \"RCPT TO: \" for each recipient, as\n>> RFC2821 4.1.1.3 says (this is an issue with the original code)?\n>\n> Looks like you're right.\n>\n> Want a new patch or will you fix both issues?\n>\n> I suggest using the same join as \"To:\" for \"Cc:\" and\n> multiple single line \"RCPT TO:\"s.\n\nSure.  Please make it so.\n"},{"id":"124389","messageId":"1255021406.2056.122.camel@Joe-Laptop.home","threadId":"21135","inReplyTo":"7vy6nlhmw7.fsf@alter.siamese.dyndns.org","subject":"[PATCH v2] git-send-email.perl: fold multiple entry \"Cc:\" and multiple single line \"RCPT TO:\"s","fromName":"Joe Perches","fromEmail":"joe@perches.com","sentAt":"2009-10-08T17:03:26Z","receivedAt":"2009-10-08T17:03:26Z","isPatch":true,"sender":{"key":"joe@perches.com","avatar":"https://avatars.githubusercontent.com/u/13122723?v=4"},"body":"Some MTAs reject Cc: lines longer than 78 chars.\nAvoid this by using the same join as \"To:\" \",\\n\\t\"\nso each subsequent Cc entry is on a new line.\n\nRCPT TO: should have a single entry per line.\nsee: http://www.ietf.org/rfc/rfc2821.txt\n\nSigned-off-by: Joe Perches <joe@perches.com>\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex dd821f7..ce81425 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -835,7 +835,7 @@ sub send_message\n \t    $gitversion = Git::version();\n \t}\n \n-\tmy $cc = join(\", \", unique_email_list(@cc));\n+\tmy $cc = join(\",\\n\\t\", unique_email_list(@cc));\n \tmy $ccline = \"\";\n \tif ($cc ne '') {\n \t\t$ccline = \"\\nCc: $cc\";\n@@ -976,7 +976,9 @@ X-Mailer: git-send-email $gitversion\n \t\tif ($smtp_server !~ m#^/#) {\n \t\t\tprint \"Server: $smtp_server\\n\";\n \t\t\tprint \"MAIL FROM:<$raw_from>\\n\";\n-\t\t\tprint \"RCPT TO:\".join(',',(map { \"<$_>\" } @recipients)).\"\\n\";\n+\t\t\tforeach my $entry (@recipients) {\n+\t\t\t    print \"RCPT TO:<$entry>\\n\";\n+\t\t\t}\n \t\t} else {\n \t\t\tprint \"Sendmail: $smtp_server \".join(' ',@sendmail_parameters).\"\\n\";\n \t\t}\n"},{"id":"124430","messageId":"7vtyy95ae8.fsf@alter.siamese.dyndns.org","threadId":"21135","inReplyTo":"1255021406.2056.122.camel@Joe-Laptop.home","subject":"Re: [PATCH v2] git-send-email.perl: fold multiple entry \"Cc:\" and multiple single line \"RCPT TO:\"s","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-09T06:50:07Z","receivedAt":"2009-10-09T06:50:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Joe Perches <joe@perches.com> writes:\n\n> Some MTAs reject Cc: lines longer than 78 chars.\n> Avoid this by using the same join as \"To:\" \",\\n\\t\"\n> so each subsequent Cc entry is on a new line.\n>\n> RCPT TO: should have a single entry per line.\n> see: http://www.ietf.org/rfc/rfc2821.txt\n>\n> Signed-off-by: Joe Perches <joe@perches.com>\n\nThanks.\n"},{"id":"124550","messageId":"7vtyy8dq15.fsf@alter.siamese.dyndns.org","threadId":"21135","inReplyTo":"1255021406.2056.122.camel@Joe-Laptop.home","subject":"Re: [PATCH v2] git-send-email.perl: fold multiple entry \"Cc:\" and multiple single line \"RCPT TO:\"s","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-10T00:57:26Z","receivedAt":"2009-10-10T00:57:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This breaks t9001 since it expects an old (and probably incorrect) RCPT TO:\nlines.  I fixed them up.\n"}]}