[PATCH 06/18] insert: add new message to database
Hi On Wed, 25 Jul 2012, Peter Wang wrote: > Add the new message to the notmuch database, renaming the file to encode > notmuch tags as maildir flags. > --- > notmuch-insert.c | 44 > 1 files changed, 44 insertions(+), 0 deletions(-) > > diff --git a/notmuch-insert.c b/notmuch-insert.c > index bab1fed..dd449bc 100644 > --- a/notmuch-insert.c > +++ b/notmuch-insert.c > @@ -129,6 +129,42 @@ copy_fd_data (int fdin, int fdout) > } > > static notmuch_bool_t > +save_database (notmuch_database_t *notmuch, const char *path) I would prefer a different name here: save_database suggests to me that it is a "whole database" operation, whereas it is actually just adding a single message. Maybe add_message or notmuch_insert_add_message? Best wishes Mark > +{ > +notmuch_message_t *message; > +notmuch_status_t status; > + > +status = notmuch_database_add_message (notmuch, path, ); > +switch (status) { > +case NOTMUCH_STATUS_SUCCESS: > + break; > +case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: > + fprintf (stderr, "Warning: duplicate message.\n"); > + break; > +default: > +case NOTMUCH_STATUS_FILE_NOT_EMAIL: > +case NOTMUCH_STATUS_READ_ONLY_DATABASE: > +case NOTMUCH_STATUS_XAPIAN_EXCEPTION: > +case NOTMUCH_STATUS_OUT_OF_MEMORY: > +case NOTMUCH_STATUS_FILE_ERROR: > +case NOTMUCH_STATUS_NULL_POINTER: > +case NOTMUCH_STATUS_TAG_TOO_LONG: > +case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: > +case NOTMUCH_STATUS_UNBALANCED_ATOMIC: > +case NOTMUCH_STATUS_LAST_STATUS: > + fprintf (stderr, "Error: failed to add `%s' to notmuch database: %s\n", > + path, notmuch_status_to_string (status)); > + return FALSE; > +} > + > +notmuch_message_tags_to_maildir_flags (message); > + > +notmuch_message_destroy (message); > + > +return TRUE; > +} > + > +static notmuch_bool_t > insert_message (void *ctx, notmuch_database_t *notmuch, int fdin, > const char *dir) > { > @@ -152,6 +188,14 @@ insert_message (void *ctx, notmuch_database_t *notmuch, > int fdin, > > if (!ret) { > unlink (tmppath); > + return FALSE; > +} > + > +ret = save_database (notmuch, newpath); > + > +if (!ret) { > + /* XXX maybe there should be an option to keep the file in maildir? */ > + unlink (newpath); > } > > return ret; > -- > 1.7.4.4 > > ___ > notmuch mailing list > notmuch at notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch
Re: [PATCH 06/18] insert: add new message to database
Hi On Wed, 25 Jul 2012, Peter Wang noval...@gmail.com wrote: Add the new message to the notmuch database, renaming the file to encode notmuch tags as maildir flags. --- notmuch-insert.c | 44 1 files changed, 44 insertions(+), 0 deletions(-) diff --git a/notmuch-insert.c b/notmuch-insert.c index bab1fed..dd449bc 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -129,6 +129,42 @@ copy_fd_data (int fdin, int fdout) } static notmuch_bool_t +save_database (notmuch_database_t *notmuch, const char *path) I would prefer a different name here: save_database suggests to me that it is a whole database operation, whereas it is actually just adding a single message. Maybe add_message or notmuch_insert_add_message? Best wishes Mark +{ +notmuch_message_t *message; +notmuch_status_t status; + +status = notmuch_database_add_message (notmuch, path, message); +switch (status) { +case NOTMUCH_STATUS_SUCCESS: + break; +case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: + fprintf (stderr, Warning: duplicate message.\n); + break; +default: +case NOTMUCH_STATUS_FILE_NOT_EMAIL: +case NOTMUCH_STATUS_READ_ONLY_DATABASE: +case NOTMUCH_STATUS_XAPIAN_EXCEPTION: +case NOTMUCH_STATUS_OUT_OF_MEMORY: +case NOTMUCH_STATUS_FILE_ERROR: +case NOTMUCH_STATUS_NULL_POINTER: +case NOTMUCH_STATUS_TAG_TOO_LONG: +case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: +case NOTMUCH_STATUS_UNBALANCED_ATOMIC: +case NOTMUCH_STATUS_LAST_STATUS: + fprintf (stderr, Error: failed to add `%s' to notmuch database: %s\n, + path, notmuch_status_to_string (status)); + return FALSE; +} + +notmuch_message_tags_to_maildir_flags (message); + +notmuch_message_destroy (message); + +return TRUE; +} + +static notmuch_bool_t insert_message (void *ctx, notmuch_database_t *notmuch, int fdin, const char *dir) { @@ -152,6 +188,14 @@ insert_message (void *ctx, notmuch_database_t *notmuch, int fdin, if (!ret) { unlink (tmppath); + return FALSE; +} + +ret = save_database (notmuch, newpath); + +if (!ret) { + /* XXX maybe there should be an option to keep the file in maildir? */ + unlink (newpath); } return ret; -- 1.7.4.4 ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH 06/18] insert: add new message to database
Add the new message to the notmuch database, renaming the file to encode notmuch tags as maildir flags. --- notmuch-insert.c | 44 1 files changed, 44 insertions(+), 0 deletions(-) diff --git a/notmuch-insert.c b/notmuch-insert.c index bab1fed..dd449bc 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -129,6 +129,42 @@ copy_fd_data (int fdin, int fdout) } static notmuch_bool_t +save_database (notmuch_database_t *notmuch, const char *path) +{ +notmuch_message_t *message; +notmuch_status_t status; + +status = notmuch_database_add_message (notmuch, path, ); +switch (status) { +case NOTMUCH_STATUS_SUCCESS: + break; +case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: + fprintf (stderr, "Warning: duplicate message.\n"); + break; +default: +case NOTMUCH_STATUS_FILE_NOT_EMAIL: +case NOTMUCH_STATUS_READ_ONLY_DATABASE: +case NOTMUCH_STATUS_XAPIAN_EXCEPTION: +case NOTMUCH_STATUS_OUT_OF_MEMORY: +case NOTMUCH_STATUS_FILE_ERROR: +case NOTMUCH_STATUS_NULL_POINTER: +case NOTMUCH_STATUS_TAG_TOO_LONG: +case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: +case NOTMUCH_STATUS_UNBALANCED_ATOMIC: +case NOTMUCH_STATUS_LAST_STATUS: + fprintf (stderr, "Error: failed to add `%s' to notmuch database: %s\n", +path, notmuch_status_to_string (status)); + return FALSE; +} + +notmuch_message_tags_to_maildir_flags (message); + +notmuch_message_destroy (message); + +return TRUE; +} + +static notmuch_bool_t insert_message (void *ctx, notmuch_database_t *notmuch, int fdin, const char *dir) { @@ -152,6 +188,14 @@ insert_message (void *ctx, notmuch_database_t *notmuch, int fdin, if (!ret) { unlink (tmppath); + return FALSE; +} + +ret = save_database (notmuch, newpath); + +if (!ret) { + /* XXX maybe there should be an option to keep the file in maildir? */ + unlink (newpath); } return ret; -- 1.7.4.4