From: Jay Soffian <jaysoffian@gmail.com>
To: git@vger.kernel.org
Cc: Jay Soffian <jaysoffian@gmail.com>
Subject: [PATCH 1/2] mailinfo: support rfc3676 (format=flowed) text/plain messages
Date: Thu, 14 Feb 2008 21:21:16 -0500 [thread overview]
Message-ID: <1203042077-11385-1-git-send-email-jaysoffian@gmail.com> (raw)
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>
---
It's been a while since I hacked C, so mucho scrutiny appreciated. The
mailinfo testsuite still passes, and this patch is followed by one which
adds a new test for this code, which also passes.
This is based off next, but mailinfo hasn't changed in a while, so it should apply cleanly to master (didn't test that though).
builtin-mailinfo.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index 2600847..deaf92b 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -20,6 +20,13 @@ static enum {
static enum {
TYPE_TEXT, TYPE_OTHER,
} message_type;
+/* RFC 3676 Text/Plain Format and DelSp Parameters */
+static enum {
+ FORMAT_NONE, FORMAT_FIXED, FORMAT_FLOWED,
+} tp_format;
+static enum {
+ DELSP_NONE, DELSP_YES, DELSP_NO,
+} tp_delsp;
static char charset[256];
static int patch_lines;
@@ -193,6 +200,18 @@ 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 (slurp_attr(line, "format=", attr) && !strcasecmp(attr, "flowed")) {
+ tp_format = FORMAT_FLOWED;
+ if (slurp_attr(line, "delsp=", attr) && !strcasecmp(attr, "yes"))
+ tp_delsp = DELSP_YES;
+ else
+ tp_delsp = DELSP_NO;
+ }
+ else
+ tp_format = FORMAT_FIXED;
+ }
if (slurp_attr(line, "boundary=", boundary + 2)) {
memcpy(boundary, "--", 2);
if (content_top++ >= &content[MAX_BOUNDARIES]) {
@@ -681,6 +700,8 @@ again:
transfer_encoding = TE_DONTCARE;
charset[0] = 0;
message_type = TYPE_TEXT;
+ tp_format = FORMAT_NONE;
+ tp_delsp = DELSP_NONE;
/* slurp in this section's info */
while (read_one_header_line(line, sizeof(line), fin))
@@ -770,6 +791,24 @@ static int handle_filter(char *line, unsigned linesize)
{
static int filter = 0;
+ if (tp_format == FORMAT_FLOWED && !!strcmp(line, "-- \n")) {
+ char *cp = line;
+ while (*cp == '>' && *cp != 0)
+ cp++;
+ if (*cp == ' ')
+ cp++;
+ line = cp;
+ if (!!strcmp(line, "-- \n")) {
+ while (*cp != '\n' && *cp !=0)
+ cp++;
+ if (cp > line && *cp == '\n' && *(cp-1) == ' ') {
+ if (tp_delsp == DELSP_YES)
+ *(cp-1) = '\0';
+ else
+ *cp = '\0';
+ }
+ }
+ }
/* filter tells us which part we left off on
* a non-zero return indicates we hit a filter point
*/
@@ -818,6 +857,7 @@ static void handle_body(void)
switch (transfer_encoding) {
case TE_BASE64:
+ case TE_QP:
{
char *op = line;
--
1.5.4.1.1281.g75df
next reply other threads:[~2008-02-15 2:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-15 2:21 Jay Soffian [this message]
2008-02-15 2:21 ` [PATCH 2/2] test mailinfo rfc3676 support Jay Soffian
2008-02-15 11:01 ` Johannes Schindelin
2008-02-15 16:44 ` Jay Soffian
2008-02-15 10:41 ` [PATCH 1/2] mailinfo: support rfc3676 (format=flowed) text/plain messages Johannes Schindelin
2008-02-15 16:35 ` Jay Soffian
2008-02-15 18:43 ` Jay Soffian
2008-02-16 2:30 ` Johannes Schindelin
2008-02-15 17:10 ` Junio C Hamano
2008-02-15 18:37 ` Jay Soffian
2008-02-16 6:57 ` Junio C Hamano
2008-02-16 7:43 ` Jay Soffian
2008-02-16 9:59 ` Junio C Hamano
2008-02-16 14:34 ` Derek Fawcus
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=1203042077-11385-1-git-send-email-jaysoffian@gmail.com \
--to=jaysoffian@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.