1 /* $Id: prunehistory.c 6124 2003-01-14 06:03:29Z rra $
3 ** Prune file names from history file.
11 #include "inn/history.h"
12 #include "inn/innconf.h"
13 #include "inn/messages.h"
19 ** Print usage message and exit.
24 fprintf(stderr, "Usage: prunehistory [-p] [-f file] [input]\n");
30 main(int ac, char *av[])
37 struct history *history = NULL;
40 /* First thing, set up logging and our identity. */
41 openlog("prunehistory", L_OPENLOG_FLAGS | LOG_PID, LOG_INN_PROG);
42 message_program_name = "prunehistory";
45 if (!innconf_read(NULL))
48 History = concatpath(innconf->pathdb, _PATH_HISTORY);
52 while ((i = getopt(ac, av, "f:p")) != EOF)
72 history = HISopen(History, innconf->hismethod, HIS_RDWR);
73 if (history == NULL) {
74 syswarn("cannot set up %s database", History);
79 /* Loop over all input. */
80 while (fgets(buff, sizeof buff, stdin) != NULL) {
81 time_t arrived, posted, expires;
83 if ((p = strchr(buff, '\n')) == NULL) {
87 warn("line too long, ignored: %.40s", buff);
92 /* Ignore blank and comment lines. */
93 if (buff[0] == '\0' || buff[0] == '#') {
99 if (buff[0] != '<' || (p = strchr(buff, '>')) == NULL) {
101 printf("%s\n", buff);
103 warn("line doesn't start with a message ID, ignored: %.40s",
109 if (HISlookup(history, buff, &arrived, &posted, &expires, NULL)) {
110 if (!HISreplace(history, buff, arrived, posted, expires, NULL))
111 syswarn("cannot write new text for %s", buff);
113 syswarn("no entry for %s", buff);
118 /* Close files; we're done. */
119 if (history != NULL && !HISclose(history)) {
120 syswarn("cannot close %s", History);