git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jay Soffian <jaysoffian@gmail.com>
To: git@vger.kernel.org
Cc: Jay Soffian <jaysoffian@gmail.com>,
	Junio C Hamano <gitster@pobox.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: [PATCH 2/3] mailinfo: support rfc3676 (format=flowed) text/plain messages
Date: Fri, 15 Feb 2008 16:53:37 -0500	[thread overview]
Message-ID: <1203112418-25199-2-git-send-email-jaysoffian@gmail.com> (raw)
In-Reply-To: <1203112418-25199-1-git-send-email-jaysoffian@gmail.com>

RFC 3676 establishes two parameters (Format and DelSP) to be used with
the Text/Plain media type. In the presence of these parameters, trailing
whitespace is used to indicate flowed lines and a canonical quote
indicator is used to indicate quoted lines.

mailinfo now unfolds, unquotes, and un-space-stuffs such messages.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
This is a bit simpler than the previous patch and incorporates most of
Johannes' feedback. I also switched from enum's to int's since enum's
were really overkill.

 builtin-mailinfo.c |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index 11f154b..0492baf 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -21,6 +21,10 @@ static enum  {
 	TYPE_TEXT, TYPE_OTHER,
 } message_type;
 
+/* RFC 3676 Text/Plain Format and DelSp Parameters */
+static int message_format_is_flowed;
+static int message_delsp_is_yes;
+
 static char charset[256];
 static int patch_lines;
 static char **p_hdr_data, **s_hdr_data;
@@ -193,6 +197,15 @@ static int handle_content_type(char *line)
 
 	if (strcasestr(line, "text/") == NULL)
 		 message_type = TYPE_OTHER;
+	else if (strcasestr(line, "text/plain")) {
+		char attr[256];
+		if ((message_format_is_flowed = (
+			slurp_attr(line, "format=", attr) &&
+			!strcasecmp(attr, "flowed"))))
+			message_delsp_is_yes = (
+				slurp_attr(line, "delsp=", attr) &&
+				!strcasecmp(attr, "yes"));
+	}
 	if (slurp_attr(line, "boundary=", boundary + 2)) {
 		memcpy(boundary, "--", 2);
 		if (content_top++ >= &content[MAX_BOUNDARIES]) {
@@ -681,6 +694,8 @@ again:
 	transfer_encoding = TE_DONTCARE;
 	charset[0] = 0;
 	message_type = TYPE_TEXT;
+	message_format_is_flowed = 0;
+	message_delsp_is_yes = 0;
 
 	/* slurp in this section's info */
 	while (read_one_header_line(line, sizeof(line), fin))
@@ -770,6 +785,22 @@ static int handle_filter(char *line, unsigned linesize)
 {
 	static int filter = 0;
 
+	if (message_format_is_flowed && strcmp(line, "-- \n")) {
+		/* strip quote markers */
+		while (*line && *line == '>')
+			line++;
+		/* undo space-stuffing */
+		if (*line == ' ')
+			line++;
+		if (strcmp(line, "-- \n")) {
+			char *cp = strchrnul(line, '\n');
+			if (cp > line && *(cp-1) == ' ' && *cp == '\n')
+				/* line is flowed (wrapped); remove
+				 * the \n or <space>\n if delsp is yes
+				 */
+				*(cp-(message_delsp_is_yes?1:0)) = '\0';
+		}
+	}
 	/* filter tells us which part we left off on
 	 * a non-zero return indicates we hit a filter point
 	 */
-- 
1.5.4.1.1281.g75df

  reply	other threads:[~2008-02-15 21:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-15 21:53 [PATCH 1/3] mailinfo: ensure handle_filter gets only one line at a time Jay Soffian
2008-02-15 21:53 ` Jay Soffian [this message]
2008-02-15 21:53   ` [PATCH 3/3] test mailinfo rfc3676 support Jay Soffian
2008-02-15 23:24 ` [PATCH 1/3] mailinfo: ensure handle_filter gets only one line at a time Junio C Hamano
2008-02-15 23:37   ` Jay Soffian
2008-02-16  6:17     ` Junio C Hamano
2008-02-16  6:22       ` Junio C Hamano
2008-02-16  6:51       ` Jay Soffian

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=1203112418-25199-2-git-send-email-jaysoffian@gmail.com \
    --to=jaysoffian@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).