git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: xzer <xiaozhu@gmail.com>
To: git@vger.kernel.org
Cc: xzer <xiaozhu@gmail.com>
Subject: [PATCH] generate a valid rfc2047 mail header for multi-line subject.
Date: Mon, 14 Feb 2011 08:09:28 +0000	[thread overview]
Message-ID: <1297670968-28130-1-git-send-email-xiaozhu@gmail.com> (raw)

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

             reply	other threads:[~2011-02-14  8:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-14  8:09 xzer [this message]
2011-02-22 20:43 ` [PATCH] generate a valid rfc2047 mail header for multi-line subject 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1297670968-28130-1-git-send-email-xiaozhu@gmail.com \
    --to=xiaozhu@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).