git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/3] format-patch: rfc2047-encode newlines in headers

From
Jeff King <peff@peff.net>
Date
Feb 23, 2011, 09:59 UTC
Message-ID
<20110223095917.GC9222@sigill.intra.peff.net>
In-Reply-To
<20110223094844.GA9205@sigill.intra.peff.net>

These should generally never happen, as we already concatenate multiples in subjects into a single line. But let's be defensive, since not encoding them means we will output malformed headers.

Signed-off-by: Jeff King <peff@peff.net>
---
 pretty.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/pretty.c b/pretty.c
index 0e167f4..65d20a7 100644
--- a/pretty.c
+++ b/pretty.c
@@ -228,7 +228,7 @@ static void add_rfc2047(struct strbuf *sb, const char *line, int len,
 
 	for (i = 0; i < len; i++) {
 		int ch = line[i];
-		if (non_ascii(ch))
+		if (non_ascii(ch) || ch == '\n')
 			goto needquote;
 		if ((i + 1 < len) && (ch == '=' && line[i+1] == '?'))
 			goto needquote;
@@ -254,7 +254,7 @@ needquote:
 		 * many programs do not understand this and just
 		 * leave the underscore in place.
 		 */
-		if (is_rfc2047_special(ch) || ch == ' ') {
+		if (is_rfc2047_special(ch) || ch == ' ' || ch == '\n') {
 			strbuf_addf(sb, "=%02X", ch);
 			line_len += 3;
 		}
-- 
1.7.2.5.15.gfdd1c
Previous: Jeff KingNext: Junio C Hamano
Message 7 of 15 in “generate a valid rfc2047 mail header for multi-line subject.”
  1. generate a valid rfc2047 mail header for multi-line subject.xzer, Feb 14, 2011
  2. Junio C HamanoFeb 22, 2011
  3. Jeff KingFeb 23, 2011
  4. Jeff KingFeb 23, 2011
  5. 1/3 strbuf: add fixed-length version of add_wrapped_textJeff King, Feb 23, 2011
  6. 2/3 format-patch: wrap long header linesJeff King, Feb 23, 2011
  7. 3/3 format-patch: rfc2047-encode newlines in headersJeff King, Feb 23, 2011
  8. Junio C HamanoFeb 23, 2011
  9. Jeff KingFeb 24, 2011
  10. xzerFeb 23, 2011
  11. Jeff KingFeb 23, 2011
  12. Junio C HamanoFeb 23, 2011
  13. Jeff KingFeb 24, 2011
  14. xzerFeb 23, 2011
  15. Junio C HamanoFeb 23, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.