git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] generate a valid rfc2047 mail header for multi-line subject.
@ 2011-02-14  8:09 xzer
  2011-02-22 20:43 ` Junio C Hamano
  0 siblings, 1 reply; 15+ messages in thread
From: xzer @ 2011-02-14  8:09 UTC (permalink / raw)
  To: git; +Cc: xzer

There is still a problem that git-am will lost the line break.
It's not easy to retain it, but as the first step, we can generate
a valid rfc2047 header now.
---
 pretty.c |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/pretty.c b/pretty.c
index 8549934..f18a38d 100644
--- a/pretty.c
+++ b/pretty.c
@@ -249,6 +249,33 @@ needquote:
 	strbuf_addstr(sb, "?=");
 }
 
+static void add_rfc2047_multiline(struct strbuf *sb, const char *line, int len,
+                       const char *encoding)
+{
+	int first = 1;
+	char *mline = xmemdupz(line, len);
+	const char *cline = mline;
+	int offset = 0, linelen = 0;
+        for (;;) {
+                linelen = get_one_line(cline);
+
+                cline += linelen;
+
+                if (!linelen)
+                        break;
+		
+		if (!first)
+			strbuf_addf(sb, "\n ");
+
+		offset = *(cline -1) == '\n'; 
+
+		add_rfc2047(sb, cline-linelen, linelen-offset, encoding);
+		first = 0;
+
+        }
+	free(mline);
+}
+
 void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
 		  const char *line, enum date_mode dmode,
 		  const char *encoding)
@@ -1115,7 +1142,7 @@ void pp_title_line(enum cmit_fmt fmt,
 	strbuf_grow(sb, title.len + 1024);
 	if (subject) {
 		strbuf_addstr(sb, subject);
-		add_rfc2047(sb, title.buf, title.len, encoding);
+		add_rfc2047_multiline(sb, title.buf, title.len, encoding);
 	} else {
 		strbuf_addbuf(sb, &title);
 	}
-- 
1.7.4.52.g00e6e.dirty

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

end of thread, other threads:[~2011-02-24  7:34 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-14  8:09 [PATCH] generate a valid rfc2047 mail header for multi-line subject xzer
2011-02-22 20:43 ` Junio C Hamano
2011-02-23  8:08   ` Jeff King
2011-02-23  9:48     ` Jeff King
2011-02-23  9:50       ` [PATCH 1/3] strbuf: add fixed-length version of add_wrapped_text Jeff King
2011-02-23  9:58       ` [PATCH 2/3] format-patch: wrap long header lines Jeff King
2011-02-23  9:59       ` [PATCH 3/3] format-patch: rfc2047-encode newlines in headers Jeff King
2011-02-23 21:47         ` Junio C Hamano
2011-02-24  7:15           ` Jeff King
2011-02-23 15:16       ` [PATCH] generate a valid rfc2047 mail header for multi-line subject xzer
2011-02-23 16:35         ` Jeff King
2011-02-23 17:34     ` Junio C Hamano
2011-02-24  7:34       ` Jeff King
2011-02-23 15:34   ` xzer
2011-02-23 17:45     ` Junio C Hamano

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).