Beispiel #1
0
void nm_longrun_done(CONTEXT *ctx)
{
    struct nm_ctxdata *data = get_ctxdata(ctx);

    if (data && release_db(data) == 0)
        dprint(2, (debugfile, "nm: long run deinitialized\n"));
}
Beispiel #2
0
static notmuch_query_t *get_query(struct nm_ctxdata *data, int writable)
{
    notmuch_database_t *db = NULL;
    notmuch_query_t *q = NULL;
    const char *str;

    if (!data)
        return NULL;

    db = get_db(data, writable);
    str = get_query_string(data);

    if (!db || !str)
        goto err;

    q = notmuch_query_create(db, str);
    if (!q)
        goto err;

    apply_exclude_tags(q);
    notmuch_query_set_sort(q, NOTMUCH_SORT_NEWEST_FIRST);
    dprint(2, (debugfile, "nm: query successfully initialized\n"));
    return q;
err:
    if (!is_longrun(data))
        release_db(data);
    return NULL;
}
Beispiel #3
0
int nm_modify_message_tags(CONTEXT *ctx, HEADER *hdr, char *buf)
{
    struct nm_ctxdata *data = get_ctxdata(ctx);
    notmuch_database_t *db = NULL;
    notmuch_message_t *msg = NULL;
    int rc = -1;

    if (!buf || !*buf || !data)
        return -1;

    if (!(db = get_db(data, TRUE)) || !(msg = get_nm_message(db, hdr)))
        goto done;

    dprint(1, (debugfile, "nm: tags modify: '%s'\n", buf));

    update_tags(msg, buf);
    update_header_tags(hdr, msg);
    mutt_set_header_color(ctx, hdr);

    rc = 0;
    hdr->changed = TRUE;
done:
    if (!is_longrun(data))
        release_db(data);
    if (hdr->changed)
        ctx->mtime = time(NULL);
    dprint(1, (debugfile, "nm: tags modify done [rc=%d]\n", rc));
    return rc;
}
Beispiel #4
0
void nm_debug_check(CONTEXT *ctx)
{
    struct nm_ctxdata *data = get_ctxdata(ctx);

    if (!data)
        return;

    if (data->db) {
        dprint(1, (debugfile, "nm: ERROR: db is open, closing\n"));
        release_db(data);
    }
}
Beispiel #5
0
int nm_read_entire_thread(CONTEXT *ctx, HEADER *h)
{
    struct nm_ctxdata *data = get_ctxdata(ctx);
    const char *id;
    char *qstr = NULL;
    notmuch_query_t *q = NULL;
    notmuch_database_t *db = NULL;
    notmuch_message_t *msg = NULL;
    int rc = -1;

    if (!data)
        return -1;
    if (!(db = get_db(data, FALSE)) || !(msg = get_nm_message(db, h)))
        goto done;

    dprint(1, (debugfile, "nm: reading entire-thread messages...[current count=%d]\n",
               ctx->msgcount));

    nm_progress_reset(ctx);
    id = notmuch_message_get_thread_id(msg);
    if (!id)
        goto done;
    append_str_item(&qstr, "thread:", 0);
    append_str_item(&qstr, id, 0);

    q = notmuch_query_create(db, qstr);
    FREE(&qstr);
    if (!q)
        goto done;
    apply_exclude_tags(q);
    notmuch_query_set_sort(q, NOTMUCH_SORT_NEWEST_FIRST);

    read_threads_query(ctx, q, 1, 0);
    ctx->mtime = time(NULL);
    rc = 0;

    if (ctx->msgcount > data->oldmsgcount)
        mx_update_context(ctx, ctx->msgcount - data->oldmsgcount);
done:
    if (q)
        notmuch_query_destroy(q);
    if (!is_longrun(data))
        release_db(data);

    if (ctx->msgcount == data->oldmsgcount)
        mutt_message _("No more messages in the thread.");

    data->oldmsgcount = 0;
    dprint(1, (debugfile, "nm: reading entire-thread messages... done [rc=%d, count=%d]\n",
               rc, ctx->msgcount));
    return rc;
}
Beispiel #6
0
int nm_read_query(CONTEXT *ctx)
{
    notmuch_query_t *q;
    struct nm_ctxdata *data;
    int rc = -1;

    if (init_context(ctx) != 0)
        return -1;

    data = get_ctxdata(ctx);
    if (!data)
        return -1;

    dprint(1, (debugfile, "nm: reading messages...[current count=%d]\n",
               ctx->msgcount));

    nm_progress_reset(ctx);

    q = get_query(data, FALSE);
    if (q) {
        switch(get_query_type(data)) {
        case NM_QUERY_TYPE_MESGS:
            read_mesgs_query(ctx, q, 0);
            break;
        case NM_QUERY_TYPE_THREADS:
            read_threads_query(ctx, q, 0, get_limit(data));
            break;
        }
        notmuch_query_destroy(q);
        rc = 0;

    }

    if (!is_longrun(data))
        release_db(data);

    ctx->mtime = time(NULL);

    mx_update_context(ctx, ctx->msgcount);
    data->oldmsgcount = 0;

    dprint(1, (debugfile, "nm: reading messages... done [rc=%d, count=%d]\n",
               rc, ctx->msgcount));
    return rc;
}
Beispiel #7
0
/* heavily outdated */
int main(int argc, char **argv)
{
	wchar_t *database = mbstowcs_alloc("test_file");

/*	if (database == NULL)
		memerrmsg("main in dbio.c");
*/
	/* REMEMBER: set the INDEXDIR environment variable. */
	setProgramName(*argv);
	findUtf8OrDie();
	set_dbase_dir();
	/* Testing with book.idx and db, renamed, then edited sending output to
	   stdout, so I can compare! */
	fprintf(stderr, "Reading indexfile\n");
	read_idxfile(database);
	fprintf(stderr, "Reading databasefile\n");
	read_database(database);
	print_db(database, NULL);
	dbmodified = 1;
	save_db();
	release_idx();
	release_db();
	return 0;
}