1 /* $Id: grephistory.c 7041 2004-12-19 08:33:49Z rra $
3 ** Get data from history database.
10 #include "inn/history.h"
11 #include "inn/innconf.h"
12 #include "inn/messages.h"
18 ** Read stdin for list of Message-ID's, output list of ones we
19 ** don't have. Or, output list of files for ones we DO have.
22 IhaveSendme(struct history *h, char What)
28 while (fgets(buff, sizeof buff, stdin) != NULL) {
29 time_t arrived, posted, expires;
32 for (p = buff; ISWHITE(*p); p++)
36 for (q = p; *q && *q != '>' && !ISWHITE(*q); q++)
42 if (!HIScheck(h, p)) {
48 /* Ihave -- say if we want it, and continue. */
53 if (HISlookup(h, p, &arrived, &posted, &expires, &token))
54 printf("%s\n", TokenToText(token));
60 ** Print a usage message and exit.
65 fprintf(stderr, "Usage: grephistory [flags] MessageID\n");
71 main(int ac, char *av[])
77 struct history *history;
78 time_t arrived, posted, expires;
80 unsigned int Verbosity = 0;
82 /* First thing, set up logging and our identity. */
83 openlog("grephistory", L_OPENLOG_FLAGS | LOG_PID, LOG_INN_PROG);
84 message_program_name = "grephistory";
87 if (!innconf_read(NULL))
90 History = concatpath(innconf->pathdb, _PATH_HISTORY);
95 while ((i = getopt(ac, av, "vf:eilnqs")) != EOF)
113 die("only one [eilnqs] flag allowed");
121 history = HISopen(History, innconf->hismethod, HIS_RDONLY);
123 die("cannot open history");
125 /* Set operating mode. */
132 IhaveSendme(history, What);
138 /* All modes other than -i -l want a Message-ID. */
144 warn("accessing history by hash isn't supported");
148 /* Add optional braces if not already present. */
150 key = concat("<", key, ">", (char *) 0);
153 if (!HIScheck(history, key)) {
156 die("not found (hash is %s)", HashToText(HashMessageID(key)));
161 else if (What != 'q') {
162 if (HISlookup(history, key, &arrived, &posted, &expires, &token)) {
164 printf("[]\t%ld~-~%ld\t%s\n", (long)arrived, (long)posted,
169 printf("%s (hash is %s)\n", TokenToText(token),
170 HashToText(HashMessageID(key)));
172 printf("%s\n", TokenToText(token));
175 else if (What == 'n')
176 printf("/dev/null\n");