X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=database.cc;h=7a3019e1de0a708f31c9daba6ca0e81e9144509d;hp=7858f9d45d790a6077d223f4966017f1957503fd;hb=e37b7cc2da75c9a43e31c1fa6d29f1177445c1d8;hpb=68a10091d6b2c29e996ee84040eecad487cb5e91 diff --git a/database.cc b/database.cc index 7858f9d4..7a3019e1 100644 --- a/database.cc +++ b/database.cc @@ -28,6 +28,63 @@ 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 NORMAL_PREFIX[] = { + { "subject", "S" }, + { "body", "B" }, + { "from_name", "FN" }, + { "to_name", "TN" }, + { "name", "N" }, + { "attachment", "A" } +}; + +prefix_t BOOLEAN_PREFIX[] = { + { "type", "K" }, + { "from_email", "FE" }, + { "to_email", "TE" }, + { "email", "E" }, + { "date", "D" }, + { "label", "L" }, + { "tag", "L" }, + { "source_id", "I" }, + { "attachment_extension", "O" }, + { "msgid", "Q" }, + { "thread", "H" }, + { "ref", "R" }, + { "timestamp", "KTS" }, +}; + +const char * +_find_prefix (const char *name) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE (NORMAL_PREFIX); i++) + if (strcmp (name, NORMAL_PREFIX[i].name) == 0) + return NORMAL_PREFIX[i].prefix; + + 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) { @@ -40,10 +97,12 @@ notmuch_status_to_string (notmuch_status_t status) return "Something went wrong trying to read or write a file"; case NOTMUCH_STATUS_FILE_NOT_EMAIL: return "File is not an email"; + case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: + return "Message ID is identical to a message in database"; case NOTMUCH_STATUS_NULL_POINTER: return "Erroneous NULL pointer"; case NOTMUCH_STATUS_TAG_TOO_LONG: - return "Tag value is too long"; + return "Tag value is too long (exceeds NOTMUCH_TAG_MAX)"; default: case NOTMUCH_STATUS_LAST_STATUS: return "Unknown error status value"; @@ -656,23 +715,8 @@ notmuch_database_add_message (notmuch_database_t *notmuch, /* Has a message previously been added with the same ID? */ old_filename = notmuch_message_get_filename (message); if (old_filename && strlen (old_filename)) { - /* XXX: This is too noisy to actually print, and what do we - * really expect the user to do? Go manually delete a - * redundant message or merge two similar messages? - * Instead we should handle this transparently. - * - * What we likely want to move to is adding both filenames - * to the database so that subsequent indexing will pick up - * terms from both files. - */ -#if 0 - fprintf (stderr, - "Note: Attempting to add a message with a duplicate message ID:\n" - "Old: %s\n" "New: %s\n", - old_filename, filename); - fprintf (stderr, "The old filename will be used, but any new terms\n" - "from the new message will added to the database.\n"); -#endif + ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID; + goto DONE; } else { _notmuch_message_set_filename (message, filename); _notmuch_message_add_term (message, "type", "mail");