[PATCH 3/5] dump: Disallow \n in message IDs
Austin Clements writes: > > randomchar = random_unichar (); > + if (randomchar == '\n') > + randomchar = 'x'; > what about something like do { randomchar = random_unichar (); } while (randomchar == '\n');
Re: [PATCH 3/5] dump: Disallow \n in message IDs
Austin Clements writes: > > randomchar = random_unichar (); > + if (randomchar == '\n') > + randomchar = 'x'; > what about something like do { randomchar = random_unichar (); } while (randomchar == '\n'); ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH 3/5] dump: Disallow \n in message IDs
When we switch to using regular Xapian queries in the dump format, \n will cause problems, so we disallow it. Specially, while Xapian can quote and parse queries containing \n without difficultly, quoted queries containing \n still span multiple lines, which breaks the line-orientedness of the dump format. Strictly speaking, we could still round-trip these, but it would significantly complicate restore as well as scripts that deal with tag dumps. This complexity would come at absolutely no benefit: because of the RFC 2822 unfolding rules, no amount of standards negligence can produce a message with a message ID containing a line break (not even Outlook can do it!). Hence, we simply disallow it. --- notmuch-dump.c |9 + test/random-corpus.c |2 ++ 2 files changed, 11 insertions(+) diff --git a/notmuch-dump.c b/notmuch-dump.c index d2dad40..29d79da 100644 --- a/notmuch-dump.c +++ b/notmuch-dump.c @@ -132,6 +132,15 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[]) if (output_format == DUMP_FORMAT_SUP) { fputs (")\n", output); } else { + if (strchr (message_id, '\n')) { + /* This will produce a line break in the output, which +* would be difficult to handle in tools. However, +* it's also impossible to produce an email containing +* a line break in a message ID because of unfolding, +* so we can safely disallow it. */ + fprintf (stderr, "Error: cannot dump message id containing line break: %s\n", message_id); + return 1; + } if (hex_encode (notmuch, message_id, &buffer, &buffer_size) != HEX_SUCCESS) { fprintf (stderr, "Error: failed to hex-encode msg-id %s\n", diff --git a/test/random-corpus.c b/test/random-corpus.c index f354d4b..d0e3e8f 100644 --- a/test/random-corpus.c +++ b/test/random-corpus.c @@ -97,6 +97,8 @@ random_utf8_string (void *ctx, size_t char_count) } randomchar = random_unichar (); + if (randomchar == '\n') + randomchar = 'x'; written = g_unichar_to_utf8 (randomchar, buf + offset); -- 1.7.10.4
[PATCH 3/5] dump: Disallow \n in message IDs
When we switch to using regular Xapian queries in the dump format, \n will cause problems, so we disallow it. Specially, while Xapian can quote and parse queries containing \n without difficultly, quoted queries containing \n still span multiple lines, which breaks the line-orientedness of the dump format. Strictly speaking, we could still round-trip these, but it would significantly complicate restore as well as scripts that deal with tag dumps. This complexity would come at absolutely no benefit: because of the RFC 2822 unfolding rules, no amount of standards negligence can produce a message with a message ID containing a line break (not even Outlook can do it!). Hence, we simply disallow it. --- notmuch-dump.c |9 + test/random-corpus.c |2 ++ 2 files changed, 11 insertions(+) diff --git a/notmuch-dump.c b/notmuch-dump.c index d2dad40..29d79da 100644 --- a/notmuch-dump.c +++ b/notmuch-dump.c @@ -132,6 +132,15 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[]) if (output_format == DUMP_FORMAT_SUP) { fputs (")\n", output); } else { + if (strchr (message_id, '\n')) { + /* This will produce a line break in the output, which +* would be difficult to handle in tools. However, +* it's also impossible to produce an email containing +* a line break in a message ID because of unfolding, +* so we can safely disallow it. */ + fprintf (stderr, "Error: cannot dump message id containing line break: %s\n", message_id); + return 1; + } if (hex_encode (notmuch, message_id, &buffer, &buffer_size) != HEX_SUCCESS) { fprintf (stderr, "Error: failed to hex-encode msg-id %s\n", diff --git a/test/random-corpus.c b/test/random-corpus.c index f354d4b..d0e3e8f 100644 --- a/test/random-corpus.c +++ b/test/random-corpus.c @@ -97,6 +97,8 @@ random_utf8_string (void *ctx, size_t char_count) } randomchar = random_unichar (); + if (randomchar == '\n') + randomchar = 'x'; written = g_unichar_to_utf8 (randomchar, buf + offset); -- 1.7.10.4 ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch