X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=database.cc;h=3d9672707b20a6213dc00cf4f83404da03508d5b;hp=712ab260225658588f0d427888694c74a5728800;hb=15d949b7404b322df39e2aae7a5653e4cf8a8dc9;hpb=b3cbcea8fdfdc71c5021fac483943a45ace816d3 diff --git a/database.cc b/database.cc index 712ab260..3d967270 100644 --- a/database.cc +++ b/database.cc @@ -28,6 +28,43 @@ using namespace std; +#define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0])) + +/* These prefix values are specifically chosen to be compatible + * with sup, (http://sup.rubyforge.org), written by + * William Morgan , and released + * under the GNU GPL v2. + */ + +typedef struct { + const char *name; + const char *prefix; +} prefix_t; + +prefix_t BOOLEAN_PREFIX[] = { + { "type", "K" }, + { "tag", "L" }, + { "msgid", "Q" }, + { "thread", "H" }, + { "ref", "R" }, + { "timestamp", "KTS" }, +}; + +const char * +_find_prefix (const char *name) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX); i++) + if (strcmp (name, BOOLEAN_PREFIX[i].name) == 0) + return BOOLEAN_PREFIX[i].prefix; + + fprintf (stderr, "Internal error: No prefix exists for '%s'\n", name); + exit (1); + + return ""; +} + const char * notmuch_status_to_string (notmuch_status_t status) { @@ -505,11 +542,12 @@ find_timestamp_document (notmuch_database_t *notmuch, const char *db_key, static char * timestamp_db_key (const char *key) { - if (strlen (key) + 1 > NOTMUCH_TERM_MAX) { + int term_len = strlen (_find_prefix ("timestamp")) + strlen (key); + + if (term_len > NOTMUCH_TERM_MAX) return notmuch_sha1_of_string (key); - } else { + else return strdup (key); - } } notmuch_status_t