예제 #1
0
static void dump_msg_metadata(struct istream *input)
{
	struct dbox_metadata_header hdr;
	const unsigned char *data;
	size_t size;
	const char *line;

	/* verify magic */
	if (i_stream_read_bytes(input, &data, &size, sizeof(hdr)) <= 0) {
		i_fatal("dbox missing metadata at %"PRIuUOFF_T,
			input->v_offset);
	}
	memcpy(&hdr, data, sizeof(hdr));
	if (memcmp(hdr.magic_post, DBOX_MAGIC_POST, sizeof(hdr.magic_post)) != 0)
		i_fatal("dbox wrong post-magic at %"PRIuUOFF_T, input->v_offset);
	i_stream_skip(input, sizeof(hdr));

	/* dump the metadata */
	for (;;) {
		if ((line = i_stream_read_next_line(input)) == NULL)
			i_fatal("dbox metadata ended unexpectedly at EOF");
		if (*line == '\0')
			break;

		switch (*line) {
		case DBOX_METADATA_GUID:
			printf("msg.guid = %s\n", line + 1);
			break;
		case DBOX_METADATA_POP3_UIDL:
			printf("msg.pop3-uidl = %s\n", line + 1);
			break;
		case DBOX_METADATA_POP3_ORDER:
			printf("msg.pop3-order = %s\n", line + 1);
			break;
		case DBOX_METADATA_RECEIVED_TIME:
			dump_timestamp(input, "msg.received", line + 1);
			break;
		case DBOX_METADATA_PHYSICAL_SIZE:
			(void)dump_size(input, "msg.physical-size", line + 1);
			break;
		case DBOX_METADATA_VIRTUAL_SIZE:
			(void)dump_size(input, "msg.virtual-size", line + 1);
			break;
		case DBOX_METADATA_EXT_REF:
			printf("msg.ext-ref = %s\n", line + 1);
			break;
		case DBOX_METADATA_ORIG_MAILBOX:
			printf("msg.orig-mailbox = %s\n", line + 1);
			break;

		case DBOX_METADATA_OLDV1_EXPUNGED:
		case DBOX_METADATA_OLDV1_FLAGS:
		case DBOX_METADATA_OLDV1_KEYWORDS:
		case DBOX_METADATA_OLDV1_SAVE_TIME:
		case DBOX_METADATA_OLDV1_SPACE:
			printf("msg.obsolete-%c = %s\n", *line, line + 1);
			break;
		}
	}
}
void wait_until(const chrono::time_point& timestamp) {
	while (true) {
		const auto& dump = get_dump();
		if (dump->find("handystats.dump_timestamp") != dump->cend()) {
			dump_timestamp_visitor visitor;
			const auto& dump_timestamp_ms =
				boost::apply_visitor(
						visitor,
						boost::get<handystats::metrics::attribute>(dump->at("handystats.dump_timestamp")).value()
					);

			chrono::time_point dump_timestamp(chrono::duration(dump_timestamp_ms, chrono::time_unit::MSEC), chrono::clock_type::SYSTEM);

			if (dump_timestamp >= timestamp) {
				return;
			}
		}

		std::this_thread::sleep_for(std::chrono::microseconds(1));
	}
}
예제 #3
0
static unsigned int dump_file_hdr(struct istream *input)
{
	const char *line, *const *arg, *version;
	unsigned int msg_hdr_size = 0;

	if ((line = i_stream_read_next_line(input)) == NULL)
		i_fatal("Empty file");
	arg = t_strsplit(line, " ");

	/* check version */
	version = *arg;
	if (version == NULL || !str_is_numeric(version, ' '))
		i_fatal("%s is not a dbox file", i_stream_get_name(input));
	if (strcmp(version, "2") != 0)
		i_fatal("Unsupported dbox file version %s", version);
	arg++;

	for (; *arg != NULL; arg++) {
		switch (**arg) {
		case DBOX_HEADER_MSG_HEADER_SIZE:
			msg_hdr_size = hex2dec((const void *)(*arg + 1),
					       strlen(*arg + 1));
			if (msg_hdr_size == 0) {
				i_fatal("Invalid msg_header_size header: %s",
					*arg + 1);
			}
			printf("file.msg_header_size = %u\n", msg_hdr_size);
			break;
		case DBOX_HEADER_CREATE_STAMP:
			dump_timestamp(input, "file.create_stamp", *arg + 1);
			break;
		default:
			printf("file.unknown-%c = %s\n", **arg, *arg + 1);
			break;
		}
	}
	if (msg_hdr_size == 0)
		i_fatal("Missing msg_header_size in file header");
	return msg_hdr_size;
}