unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
blob fe71108a621003f74eb10c1af1501e801bf25040 2270 bytes (raw)
name: notmuch-list.c 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
 
/* notmuch - Not much of an email program, (just index and search)
 *
 * Copyright © 2009 Carl Worth
 * Copyright © 2009 Jan Janak
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see http://www.gnu.org/licenses/ .
 *
 * Authors: Carl Worth <cworth@cworth.org>
 *          Jan Janak <jan@ryngle.com>
 */

#include "notmuch-client.h"

enum list_cmd {
	LIST_TAGS
};


static int
list_all_tags(notmuch_database_t* db)
{
	notmuch_tags_t* tags;
	const char* t;

	if ((tags = notmuch_database_get_tags(db)) == NULL) {
		fprintf(stderr, "Error while obtaining tags from the database.\n");
		return 1;
	}

	while((t = notmuch_tags_get(tags))) {
		printf("%s\n", t);
		notmuch_tags_advance(tags);
	}

	notmuch_tags_destroy(tags);
	return 0;
}

int
notmuch_list_command (void *ctx, int argc, char *argv[])
{
    notmuch_config_t *config;
    notmuch_database_t *db;
	enum list_cmd cmd;

	config = NULL;
	db = NULL;

	if (argc < 1) {
		fprintf(stderr, "Error: notmuch list requires at least one parameter.\n");
		fprintf(stderr, "(See notmuch help list)\n");
		goto error;
	}

	if (!strcmp(argv[0], "tags")) {
		cmd = LIST_TAGS;
	} else {
		fprintf(stderr, "Sub-command '%s' not supported.\n", argv[0]);
		goto error;
	}

    if ((config = notmuch_config_open (ctx, NULL, NULL)) == NULL) {
		goto error;
	}

    db = notmuch_database_open (notmuch_config_get_database_path (config));
    if (db == NULL) {
		goto error;
	}

	switch(cmd) {
	case LIST_TAGS:
		if (list_all_tags(db) != 0) goto error;
		break;

	default:
		fprintf(stderr, "Unsupported command: bug in notmuch_list_command.\n");
		goto error;
	}

    notmuch_database_close (db);
    return 0;

error:
	if (db) notmuch_database_close(db);
	return 1;
}

debug log:

solving fe71108 ...
found fe71108 in https://yhetil.org/notmuch/1258630481-5133-2-git-send-email-jan@ryngle.com/

applying [1/1] https://yhetil.org/notmuch/1258630481-5133-2-git-send-email-jan@ryngle.com/
diff --git a/notmuch-list.c b/notmuch-list.c
new file mode 100644
index 0000000..fe71108

Checking patch notmuch-list.c...
Applied patch notmuch-list.c cleanly.

index at:
100644 fe71108a621003f74eb10c1af1501e801bf25040	notmuch-list.c

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).