dovecot-2.0: Added mailboxlogview utility for viewing mailbox logs.

dovecot at dovecot.org dovecot at dovecot.org
Thu Aug 6 03:30:53 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/d354dc450c63
changeset: 9735:d354dc450c63
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Aug 05 20:30:06 2009 -0400
description:
Added mailboxlogview utility for viewing mailbox logs.

diffstat:

2 files changed, 96 insertions(+)
src/util/Makefile.am      |    6 +++
src/util/mailboxlogview.c |   90 +++++++++++++++++++++++++++++++++++++++++++++

diffs (117 lines):

diff -r 1c0132ccb0be -r d354dc450c63 src/util/Makefile.am
--- a/src/util/Makefile.am	Wed Aug 05 20:29:52 2009 -0400
+++ b/src/util/Makefile.am	Wed Aug 05 20:30:06 2009 -0400
@@ -7,6 +7,7 @@ pkglibexec_PROGRAMS = \
 	imap-utf7 \
 	listview \
 	logview \
+	mailboxlogview \
 	maildirlock \
 	threadview
 
@@ -53,6 +54,11 @@ logview_SOURCES = \
 logview_SOURCES = \
 	logview.c
 
+mailboxlogview_LDADD = $(LIBDOVECOT)
+mailboxlogview_DEPENDENCIES = $(LIBDOVECOT)
+mailboxlogview_SOURCES = \
+	mailboxlogview.c
+
 maildirlock_LDADD = $(LIBDOVECOT)
 maildirlock_DEPENDENCIES = $(LIBDOVECOT)
 maildirlock_SOURCES = \
diff -r 1c0132ccb0be -r d354dc450c63 src/util/mailboxlogview.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/util/mailboxlogview.c	Wed Aug 05 20:30:06 2009 -0400
@@ -0,0 +1,90 @@
+/* Copyright (c) 2007-2009 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "hex-binary.h"
+#include "mailbox-log.h"
+
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <time.h>
+
+static const char *unixdate2str(time_t timestamp)
+{
+	static char buf[64];
+	struct tm *tm;
+
+	tm = localtime(&timestamp);
+	strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm);
+	return buf;
+}
+
+static int dump_record(int fd)
+{
+	off_t offset;
+	ssize_t ret;
+	struct mailbox_log_record rec;
+	time_t timestamp;
+
+	offset = lseek(fd, 0, SEEK_CUR);
+
+	ret = read(fd, &rec, sizeof(rec));
+	if (ret == 0)
+		return 0;
+
+	if (ret != sizeof(rec)) {
+		i_fatal("rec read() %"PRIuSIZE_T" != %"PRIuSIZE_T,
+			ret, sizeof(rec));
+	}
+
+	printf("#%"PRIuUOFF_T": ", offset);
+	switch (rec.type) {
+	case MAILBOX_LOG_RECORD_DELETE_MAILBOX:
+		printf("delete-mailbox");
+		break;
+	case MAILBOX_LOG_RECORD_DELETE_DIR:
+		printf("delete-dir");
+		break;
+	case MAILBOX_LOG_RECORD_RENAME:
+		printf("rename");
+		break;
+	case MAILBOX_LOG_RECORD_SUBSCRIBE:
+		printf("subscribe");
+		break;
+	case MAILBOX_LOG_RECORD_UNSUBSCRIBE:
+		printf("unsubscribe");
+		break;
+	}
+	printf(" %s", binary_to_hex(rec.mailbox_guid,
+				    sizeof(rec.mailbox_guid)));
+
+	timestamp = ((uint32_t)rec.timestamp[0] << 24) |
+		((uint32_t)rec.timestamp[1] << 16) |
+		((uint32_t)rec.timestamp[2] << 8) |
+		(uint32_t)rec.timestamp[3];
+	printf(" (%s)\n", unixdate2str(timestamp));
+	return 1;
+}
+
+int main(int argc, const char *argv[])
+{
+	int fd, ret;
+
+	lib_init();
+
+	if (argc < 2)
+		i_fatal("Usage: logview dovecot.mailbox.log");
+
+	fd = open(argv[1], O_RDONLY);
+	if (fd < 0) {
+		i_error("open(): %m");
+		return 1;
+	}
+
+	do {
+		T_BEGIN {
+			ret = dump_record(fd);
+		} T_END;
+	} while (ret > 0);
+	return 0;
+}


More information about the dovecot-cvs mailing list