mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
add_message: Add an optional parameter for getting the just-added message.
We use this to implement the addition of "inbox" and "unread" tags for all messages added by "notmuch new".
This commit is contained in:
parent
d07dd49aac
commit
ae0bd3f503
3 changed files with 46 additions and 9 deletions
10
database.cc
10
database.cc
|
@ -821,7 +821,8 @@ _notmuch_database_link_message (notmuch_database_t *notmuch,
|
||||||
|
|
||||||
notmuch_status_t
|
notmuch_status_t
|
||||||
notmuch_database_add_message (notmuch_database_t *notmuch,
|
notmuch_database_add_message (notmuch_database_t *notmuch,
|
||||||
const char *filename)
|
const char *filename,
|
||||||
|
notmuch_message_t **message_ret)
|
||||||
{
|
{
|
||||||
notmuch_message_file_t *message_file;
|
notmuch_message_file_t *message_file;
|
||||||
notmuch_message_t *message;
|
notmuch_message_t *message;
|
||||||
|
@ -926,8 +927,13 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
|
||||||
}
|
}
|
||||||
|
|
||||||
DONE:
|
DONE:
|
||||||
if (message)
|
if (message) {
|
||||||
|
if (message_ret)
|
||||||
|
*message_ret = message;
|
||||||
|
else
|
||||||
notmuch_message_destroy (message);
|
notmuch_message_destroy (message);
|
||||||
|
}
|
||||||
|
|
||||||
if (message_file)
|
if (message_file)
|
||||||
notmuch_message_file_close (message_file);
|
notmuch_message_file_close (message_file);
|
||||||
|
|
||||||
|
|
35
notmuch.c
35
notmuch.c
|
@ -67,6 +67,8 @@ typedef struct command {
|
||||||
const char *usage;
|
const char *usage;
|
||||||
} command_t;
|
} command_t;
|
||||||
|
|
||||||
|
typedef void (*add_files_callback_t) (notmuch_message_t *message);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int ignore_read_only_directories;
|
int ignore_read_only_directories;
|
||||||
int saw_read_only_directory;
|
int saw_read_only_directory;
|
||||||
|
@ -75,6 +77,8 @@ typedef struct {
|
||||||
int processed_files;
|
int processed_files;
|
||||||
int added_messages;
|
int added_messages;
|
||||||
struct timeval tv_start;
|
struct timeval tv_start;
|
||||||
|
|
||||||
|
add_files_callback_t callback;
|
||||||
} add_files_state_t;
|
} add_files_state_t;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -176,6 +180,7 @@ add_files_recursive (notmuch_database_t *notmuch,
|
||||||
char *next = NULL;
|
char *next = NULL;
|
||||||
time_t path_mtime, path_dbtime;
|
time_t path_mtime, path_dbtime;
|
||||||
notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
|
notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
|
||||||
|
notmuch_message_t *message, **closure;
|
||||||
|
|
||||||
/* If we're told to, we bail out on encountering a read-only
|
/* If we're told to, we bail out on encountering a read-only
|
||||||
* directory, (with this being a clear clue from the user to
|
* directory, (with this being a clear clue from the user to
|
||||||
|
@ -249,11 +254,19 @@ add_files_recursive (notmuch_database_t *notmuch,
|
||||||
if (st->st_mtime > path_dbtime) {
|
if (st->st_mtime > path_dbtime) {
|
||||||
state->processed_files++;
|
state->processed_files++;
|
||||||
|
|
||||||
status = notmuch_database_add_message (notmuch, next);
|
if (state->callback)
|
||||||
|
closure = &message;
|
||||||
|
else
|
||||||
|
closure = NULL;
|
||||||
|
|
||||||
|
status = notmuch_database_add_message (notmuch, next, closure);
|
||||||
switch (status) {
|
switch (status) {
|
||||||
/* success */
|
/* success */
|
||||||
case NOTMUCH_STATUS_SUCCESS:
|
case NOTMUCH_STATUS_SUCCESS:
|
||||||
state->added_messages++;
|
state->added_messages++;
|
||||||
|
if (state->callback)
|
||||||
|
(state->callback) (message);
|
||||||
|
notmuch_message_destroy (message);
|
||||||
break;
|
break;
|
||||||
/* Non-fatal issues (go on to next file) */
|
/* Non-fatal issues (go on to next file) */
|
||||||
case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
|
case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
|
||||||
|
@ -495,6 +508,7 @@ setup_command (unused (int argc), unused (char *argv[]))
|
||||||
add_files_state.total_files = count;
|
add_files_state.total_files = count;
|
||||||
add_files_state.processed_files = 0;
|
add_files_state.processed_files = 0;
|
||||||
add_files_state.added_messages = 0;
|
add_files_state.added_messages = 0;
|
||||||
|
add_files_state.callback = NULL;
|
||||||
gettimeofday (&add_files_state.tv_start, NULL);
|
gettimeofday (&add_files_state.tv_start, NULL);
|
||||||
|
|
||||||
ret = add_files (notmuch, mail_directory, &add_files_state);
|
ret = add_files (notmuch, mail_directory, &add_files_state);
|
||||||
|
@ -537,6 +551,13 @@ setup_command (unused (int argc), unused (char *argv[]))
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
tag_inbox_and_unread (notmuch_message_t *message)
|
||||||
|
{
|
||||||
|
notmuch_message_add_tag (message, "inbox");
|
||||||
|
notmuch_message_add_tag (message, "unread");
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
new_command (unused (int argc), unused (char *argv[]))
|
new_command (unused (int argc), unused (char *argv[]))
|
||||||
{
|
{
|
||||||
|
@ -560,6 +581,7 @@ new_command (unused (int argc), unused (char *argv[]))
|
||||||
add_files_state.total_files = 0;
|
add_files_state.total_files = 0;
|
||||||
add_files_state.processed_files = 0;
|
add_files_state.processed_files = 0;
|
||||||
add_files_state.added_messages = 0;
|
add_files_state.added_messages = 0;
|
||||||
|
add_files_state.callback = tag_inbox_and_unread;
|
||||||
gettimeofday (&add_files_state.tv_start, NULL);
|
gettimeofday (&add_files_state.tv_start, NULL);
|
||||||
|
|
||||||
ret = add_files (notmuch, mail_directory, &add_files_state);
|
ret = add_files (notmuch, mail_directory, &add_files_state);
|
||||||
|
@ -880,10 +902,13 @@ command_t commands[] = {
|
||||||
"\t\tthe setup command has not previously been completed." },
|
"\t\tthe setup command has not previously been completed." },
|
||||||
{ "new", new_command,
|
{ "new", new_command,
|
||||||
"Find and import any new messages.\n\n"
|
"Find and import any new messages.\n\n"
|
||||||
"\t\tScans all sub-directories of the database, adding new files\n"
|
"\t\tScans all sub-directories of the database, adding new messages\n"
|
||||||
"\t\tthat are found. Note: \"notmuch new\" will skip any\n"
|
"\t\tthat are found. Each new message will be tagges as both\n"
|
||||||
"\t\tread-only directories, so you can use that to mark\n"
|
"\t\t\"inbox\" and \"unread\".\n"
|
||||||
"\t\tdirectories that will not receive any new mail."},
|
"\n"
|
||||||
|
"\t\tNote: \"notmuch new\" will skip any read-only directories,\n"
|
||||||
|
"\t\tso you can use that to mark tdirectories that will not\n"
|
||||||
|
"\t\treceive any new mail (and make \"notmuch new\" faster)." },
|
||||||
{ "search", search_command,
|
{ "search", search_command,
|
||||||
"<search-term> [...]\n\n"
|
"<search-term> [...]\n\n"
|
||||||
"\t\tSearch for threads matching the given search terms.\n"
|
"\t\tSearch for threads matching the given search terms.\n"
|
||||||
|
|
|
@ -246,6 +246,11 @@ notmuch_database_get_timestamp (notmuch_database_t *database,
|
||||||
* reference the filename, and will not copy the entire contents of
|
* reference the filename, and will not copy the entire contents of
|
||||||
* the file.
|
* the file.
|
||||||
*
|
*
|
||||||
|
* If 'message' is not NULL, then '*message' will be initialized to a
|
||||||
|
* message object that can be used for things such as adding tags to
|
||||||
|
* the just-added message. The user should call
|
||||||
|
* notmuch_message_destroy when done with the message.
|
||||||
|
*
|
||||||
* Return value:
|
* Return value:
|
||||||
*
|
*
|
||||||
* NOTMUCH_STATUS_SUCCESS: Message successfully added to database.
|
* NOTMUCH_STATUS_SUCCESS: Message successfully added to database.
|
||||||
|
@ -263,7 +268,8 @@ notmuch_database_get_timestamp (notmuch_database_t *database,
|
||||||
*/
|
*/
|
||||||
notmuch_status_t
|
notmuch_status_t
|
||||||
notmuch_database_add_message (notmuch_database_t *database,
|
notmuch_database_add_message (notmuch_database_t *database,
|
||||||
const char *filename);
|
const char *filename,
|
||||||
|
notmuch_message_t **message);
|
||||||
|
|
||||||
/* Find a message with the given messsage_id.
|
/* Find a message with the given messsage_id.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue