--- /dev/null
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 37B14431FAF\r
+ for <notmuch@notmuchmail.org>; Fri, 27 Jul 2012 14:30:20 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id m9vMtwkBKBzl for <notmuch@notmuchmail.org>;\r
+ Fri, 27 Jul 2012 14:30:19 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU\r
+ [18.7.68.35])\r
+ by olra.theworths.org (Postfix) with ESMTP id 39740431FAE\r
+ for <notmuch@notmuchmail.org>; Fri, 27 Jul 2012 14:30:19 -0700 (PDT)\r
+X-AuditID: 12074423-b7f396d0000008f4-1d-5013086abe92\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+ by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id C3.16.02292.A6803105; Fri, 27 Jul 2012 17:30:18 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q6RLUIYf017969; \r
+ Fri, 27 Jul 2012 17:30:18 -0400\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+ (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q6RLUG7H028955\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Fri, 27 Jul 2012 17:30:17 -0400 (EDT)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1Sus6x-000126-TR; Fri, 27 Jul 2012 17:30:15 -0400\r
+Date: Fri, 27 Jul 2012 17:30:15 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Mark Walters <markwalters1009@gmail.com>\r
+Subject: Re: [PATCH 03/13] sprinter: Add a string_len method\r
+Message-ID: <20120727213015.GC8502@mit.edu>\r
+References: <1343183693-17134-1-git-send-email-amdragon@mit.edu>\r
+ <1343183693-17134-4-git-send-email-amdragon@mit.edu>\r
+ <87a9ynis8s.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+In-Reply-To: <87a9ynis8s.fsf@qmul.ac.uk>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFmphleLIzCtJLcpLzFFi42IRYrdT183iEA4wmHtM12L1XB6L6zdnMjsw\r
+ eeycdZfd49mqW8wBTFFcNimpOZllqUX6dglcGXuP3WAvuKBXMe/DCcYGxvXKXYycHBICJhIz\r
+ t/xkgbDFJC7cW8/WxcjFISSwj1Fi19W37BDOBkaJ22vnMkE4J5kkln1/AOUsYZR4PvkoI0g/\r
+ i4CqxMzzW8FsNgENiW37l4PZIgI6ErcPLWAHsZkFpCW+/W5mArGFBWwkTsxdBrabV0BbYvuR\r
+ TSwQQ6cySqx+0s8OkRCUODnzCQtEs5bEjX8vgZo5wAYt/8cBEuYE2rVyXQsziC0qoCIx5eQ2\r
+ tgmMQrOQdM9C0j0LoXsBI/MqRtmU3Crd3MTMnOLUZN3i5MS8vNQiXTO93MwSvdSU0k2M4MB2\r
+ Ud7B+Oeg0iFGAQ5GJR5epetCAUKsiWXFlbmHGCU5mJREeUvZhAOE+JLyUyozEosz4otKc1KL\r
+ DzFKcDArifDa7AAq501JrKxKLcqHSUlzsCiJ815LuekvJJCeWJKanZpakFoEk5Xh4FCS4L3P\r
+ DjRUsCg1PbUiLTOnBCHNxMEJMpwHaPh7kBre4oLE3OLMdIj8KUZFKXHePpCEAEgiozQPrheW\r
+ eF4xigO9Isx7BaSKB5i04LpfAQ1mAhpsEQ1ydXFJIkJKqoHx3IdzJTOTWA0O/e6ycq3yZT7W\r
+ e9SOjcn1Ak+1l/XJN/rL6p41nFhVr3xM98mH7TZ7xWa/tY78s9J59pL5zBpXovqtOb83ixhI\r
+ 5TNvtU5sSNC2XBYTeLky8tZzySkNu/47/j/odmt5n2G05JL2mAdTF7pmTnixpPzM+ba8e/LB\r
+ crXCJXeXSRorsRRnJBpqMRcVJwIA/ugG0BcDAAA=\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 27 Jul 2012 21:30:20 -0000\r
+\r
+Quoth Mark Walters on Jul 25 at 7:57 pm:\r
+> \r
+> Hi\r
+> \r
+> I have read this series (apart from the test changes) and it is both\r
+> very nice to review and looks good. It builds and all tests pass at all\r
+> the interesting partial stages and when fully applied. I have a few very\r
+> minor comments.\r
+> \r
+> On Wed, 25 Jul 2012, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> > This method allows callers to output strings with specific lengths.\r
+> > It's useful both for strings with embedded NULs (which JSON can\r
+> > represent, though parser support is apparently spotty), and\r
+> > non-terminated strings.\r
+> > ---\r
+> > sprinter-json.c | 11 +++++++++--\r
+> > sprinter-text.c | 11 +++++++++--\r
+> > sprinter.h | 1 +\r
+> > 3 files changed, 19 insertions(+), 4 deletions(-)\r
+> >\r
+> > diff --git a/sprinter-json.c b/sprinter-json.c\r
+> > index 4649655..2587ca6 100644\r
+> > --- a/sprinter-json.c\r
+> > +++ b/sprinter-json.c\r
+> > @@ -89,7 +89,7 @@ json_end (struct sprinter *sp)\r
+> > }\r
+> > \r
+> > static void\r
+> > -json_string (struct sprinter *sp, const char *val)\r
+> > +json_string_len (struct sprinter *sp, const char *val, size_t len)\r
+> > {\r
+> \r
+> I think this function could do with a comment along the lines of the\r
+> commit message. It might be nice to document somewhere where/when we\r
+\r
+Will do. I put a comment on this function explaining how it handles\r
+NULs, as well as a comment on the generic vtable pointer explaining\r
+string_len.\r
+\r
+> might actually have nulls in an encoded string (are they allowed in\r
+> bodies, headers etc).\r
+\r
+Interestingly, RFC822, while being limited to 7-bit ASCII, explicitly\r
+did allow NULs [RFC822, CHAR non-terminal]. RFC2822 explicitly\r
+obsoletes them [RFC2822 4 or appendix B], which means consumers should\r
+support them, but generators must not generate them. As usual, MIME\r
+makes things more complicated by supporting a "binary" content\r
+transfer encoding that does permits NULs. However, good luck getting\r
+that through SMTP business; SMTP theoretically allows any ASCII\r
+control character, but the standard specifically warns that control\r
+characters other than SP, HT, CR, and LF should be avoided [RFC2821\r
+4.1.1.4]. Even if you've negotiated the 8BITMIME extension [RFC1652],\r
+you're limited by what MIME's "8bit" content transfer encoding\r
+permits, which differs from the "binary" content transfer encoding by\r
+disallowing (guess what) NULs and long lines.\r
+\r
+In other words: yes.\r
+\r
+> Actually, do we know that the json emacs parser handles nulls correctly?\r
+\r
+It does. Emacs strings are clean, so json.el doesn't have to do\r
+special anything to support them.\r
+\r
+> Best wishes\r
+> \r
+> Mark\r
+> > static const char *const escapes[] = {\r
+> > ['\"'] = "\\\"", ['\\'] = "\\\\", ['\b'] = "\\b",\r
+> > @@ -98,7 +98,7 @@ json_string (struct sprinter *sp, const char *val)\r
+> > struct sprinter_json *spj = json_begin_value (sp);\r
+> > \r
+> > fputc ('"', spj->stream);\r
+> > - for (; *val; ++val) {\r
+> > + for (; len; ++val, --len) {\r
+> > unsigned char ch = *val;\r
+> > if (ch < ARRAY_SIZE (escapes) && escapes[ch])\r
+> > fputs (escapes[ch], spj->stream);\r
+> > @@ -111,6 +111,12 @@ json_string (struct sprinter *sp, const char *val)\r
+> > }\r
+> > \r
+> > static void\r
+> > +json_string (struct sprinter *sp, const char *val)\r
+> > +{\r
+> > + json_string_len (sp, val, strlen (val));\r
+> > +}\r
+> > +\r
+> > +static void\r
+> > json_integer (struct sprinter *sp, int val)\r
+> > {\r
+> > struct sprinter_json *spj = json_begin_value (sp);\r
+> > @@ -166,6 +172,7 @@ sprinter_json_create (const void *ctx, FILE *stream)\r
+> > .begin_list = json_begin_list,\r
+> > .end = json_end,\r
+> > .string = json_string,\r
+> > + .string_len = json_string_len,\r
+> > .integer = json_integer,\r
+> > .boolean = json_boolean,\r
+> > .null = json_null,\r
+> > diff --git a/sprinter-text.c b/sprinter-text.c\r
+> > index b208840..dfa54b5 100644\r
+> > --- a/sprinter-text.c\r
+> > +++ b/sprinter-text.c\r
+> > @@ -25,14 +25,20 @@ struct sprinter_text {\r
+> > };\r
+> > \r
+> > static void\r
+> > -text_string (struct sprinter *sp, const char *val)\r
+> > +text_string_len (struct sprinter *sp, const char *val, size_t len)\r
+> > {\r
+> > struct sprinter_text *sptxt = (struct sprinter_text *) sp;\r
+> > \r
+> > if (sptxt->current_prefix != NULL)\r
+> > fprintf (sptxt->stream, "%s:", sptxt->current_prefix);\r
+> > \r
+> > - fputs(val, sptxt->stream);\r
+> > + fwrite (val, len, 1, sptxt->stream);\r
+> > +}\r
+> > +\r
+> > +static void\r
+> > +text_string (struct sprinter *sp, const char *val)\r
+> > +{\r
+> > + text_string_len (sp, val, strlen (val));\r
+> > }\r
+> > \r
+> > static void\r
+> > @@ -105,6 +111,7 @@ sprinter_text_create (const void *ctx, FILE *stream)\r
+> > .begin_list = text_begin_list,\r
+> > .end = text_end,\r
+> > .string = text_string,\r
+> > + .string_len = text_string_len,\r
+> > .integer = text_integer,\r
+> > .boolean = text_boolean,\r
+> > .null = text_null,\r
+> > diff --git a/sprinter.h b/sprinter.h\r
+> > index 6680d41..826a852 100644\r
+> > --- a/sprinter.h\r
+> > +++ b/sprinter.h\r
+> > @@ -28,6 +28,7 @@ typedef struct sprinter {\r
+> > * For string, the char * must be UTF-8 encoded.\r
+> > */\r
+> > void (*string) (struct sprinter *, const char *);\r
+> > + void (*string_len) (struct sprinter *, const char *, size_t);\r
+> > void (*integer) (struct sprinter *, int);\r
+> > void (*boolean) (struct sprinter *, notmuch_bool_t);\r
+> > void (*null) (struct sprinter *);\r
+> >\r
+> > _______________________________________________\r
+> > notmuch mailing list\r
+> > notmuch@notmuchmail.org\r
+> > http://notmuchmail.org/mailman/listinfo/notmuch\r
+> \r
+\r
+-- \r
+Austin Clements MIT/'06/PhD/CSAIL\r
+amdragon@mit.edu http://web.mit.edu/amdragon\r
+ Somewhere in the dream we call reality you will find me,\r
+ searching for the reality we call dreams.\r