X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-dump.c;h=2024e30391d541921656285c5f2c1cd02965974c;hp=d2dad40da22f2943545aa475d178e65d1e29c79b;hb=dd8ea3203c823145750891c8a1a10b46ffa03daa;hpb=bfe66da4321ce63b6fb3693eddf809e2e0532888 diff --git a/notmuch-dump.c b/notmuch-dump.c index d2dad40d..2024e303 100644 --- a/notmuch-dump.c +++ b/notmuch-dump.c @@ -20,11 +20,11 @@ #include "notmuch-client.h" #include "dump-restore-private.h" +#include "string-util.h" int -notmuch_dump_command (unused (void *ctx), int argc, char *argv[]) +notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[]) { - notmuch_config_t *config; notmuch_database_t *notmuch; notmuch_query_t *query; FILE *output = stdout; @@ -33,10 +33,6 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[]) notmuch_tags_t *tags; const char *query_str = ""; - config = notmuch_config_open (ctx, NULL, NULL); - if (config == NULL) - return 1; - if (notmuch_database_open (notmuch_config_get_database_path (config), NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much)) return 1; @@ -102,6 +98,18 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[]) message = notmuch_messages_get (messages); message_id = notmuch_message_get_message_id (message); + if (output_format == DUMP_FORMAT_BATCH_TAG && + 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, "Warning: skipping message id containing line break: \"%s\"\n", message_id); + notmuch_message_destroy (message); + continue; + } + if (output_format == DUMP_FORMAT_SUP) { fprintf (output, "%s (", message_id); } @@ -132,13 +140,13 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[]) if (output_format == DUMP_FORMAT_SUP) { fputs (")\n", output); } else { - if (hex_encode (notmuch, message_id, - &buffer, &buffer_size) != HEX_SUCCESS) { - fprintf (stderr, "Error: failed to hex-encode msg-id %s\n", - message_id); + if (make_boolean_term (notmuch, "id", message_id, + &buffer, &buffer_size)) { + fprintf (stderr, "Error quoting message id %s: %s\n", + message_id, strerror (errno)); return 1; } - fprintf (output, " -- id:%s\n", buffer); + fprintf (output, " -- %s\n", buffer); } notmuch_message_destroy (message);