<commit_before>/* Copyright (c) 2007-2009 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "hex-binary.h"
#include "mail-index-private.h"
#include "mail-transaction-log.h"

#include <stdio.h>

static struct mail_transaction_ext_intro prev_intro;

uint32_t mail_index_offset_to_uint32(uint32_t offset)
{
	const unsigned char *buf = (const unsigned char *) &offset;

	if ((offset & 0x80808080) != 0x80808080)
		return 0;

	return (((uint32_t)buf[3] & 0x7f) << 2) |
		(((uint32_t)buf[2] & 0x7f) << 9) |
		(((uint32_t)buf[1] & 0x7f) << 16) |
		(((uint32_t)buf[0] & 0x7f) << 23);
}

static void dump_hdr(int fd, uint64_t *modseq_r)
{
	struct mail_transaction_log_header hdr;
	ssize_t ret;

	ret = read(fd, &hdr, sizeof(hdr));
	if (ret != sizeof(hdr)) {
		i_fatal("file hdr read() %"PRIuSIZE_T" != %"PRIuSIZE_T,
			ret, sizeof(hdr));
	}
	if (hdr.hdr_size < sizeof(hdr)) {
		memset(PTR_OFFSET(&hdr, hdr.hdr_size), 0,
		       sizeof(hdr) - hdr.hdr_size);
	}
	lseek(fd, hdr.hdr_size, SEEK_SET);

	printf("version = %u.%u\n", hdr.major_version, hdr.minor_version);
	printf("hdr size = %u\n", hdr.hdr_size);
	printf("index id = %u\n", hdr.indexid);
	printf("file seq = %u\n", hdr.file_seq);
	printf("prev file = %u/%u\n", hdr.prev_file_seq, hdr.prev_file_offset);
	printf("create stamp = %u\n", hdr.create_stamp);
	printf("initial modseq = %llu\n",
	       (unsigned long long)hdr.initial_modseq);
	printf("compat flags = %x\n", hdr.compat_flags);
	*modseq_r = hdr.initial_modseq;
}

static bool
mail_transaction_header_has_modseq(const struct mail_transaction_header *hdr)
{
	switch (hdr->type & MAIL_TRANSACTION_TYPE_MASK) {
	case MAIL_TRANSACTION_EXPUNGE | MAIL_TRANSACTION_EXPUNGE_PROT:
	case MAIL_TRANSACTION_EXPUNGE_GUID | MAIL_TRANSACTION_EXPUNGE_PROT:
		if ((hdr->type & MAIL_TRANSACTION_EXTERNAL) == 0) {
			/* ignore expunge requests */
			break;
		}
	case MAIL_TRANSACTION_APPEND:
	case MAIL_TRANSACTION_FLAG_UPDATE:
	case MAIL_TRANSACTION_KEYWORD_UPDATE:
	case MAIL_TRANSACTION_KEYWORD_RESET:
		/* these changes increase modseq */
		return TRUE;
	}
	return FALSE;
}
static const char *log_record_type(unsigned int type)<commit_msg>logview: UID updates increase modseq.<commit_after>/* Copyright (c) 2007-2009 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "hex-binary.h"
#include "mail-index-private.h"
#include "mail-transaction-log.h"

#include <stdio.h>

static struct mail_transaction_ext_intro prev_intro;

uint32_t mail_index_offset_to_uint32(uint32_t offset)
{
	const unsigned char *buf = (const unsigned char *) &offset;

	if ((offset & 0x80808080) != 0x80808080)
		return 0;

	return (((uint32_t)buf[3] & 0x7f) << 2) |
		(((uint32_t)buf[2] & 0x7f) << 9) |
		(((uint32_t)buf[1] & 0x7f) << 16) |
		(((uint32_t)buf[0] & 0x7f) << 23);
}

static void dump_hdr(int fd, uint64_t *modseq_r)
{
	struct mail_transaction_log_header hdr;
	ssize_t ret;

	ret = read(fd, &hdr, sizeof(hdr));
	if (ret != sizeof(hdr)) {
		i_fatal("file hdr read() %"PRIuSIZE_T" != %"PRIuSIZE_T,
			ret, sizeof(hdr));
	}
	if (hdr.hdr_size < sizeof(hdr)) {
		memset(PTR_OFFSET(&hdr, hdr.hdr_size), 0,
		       sizeof(hdr) - hdr.hdr_size);
	}
	lseek(fd, hdr.hdr_size, SEEK_SET);

	printf("version = %u.%u\n", hdr.major_version, hdr.minor_version);
	printf("hdr size = %u\n", hdr.hdr_size);
	printf("index id = %u\n", hdr.indexid);
	printf("file seq = %u\n", hdr.file_seq);
	printf("prev file = %u/%u\n", hdr.prev_file_seq, hdr.prev_file_offset);
	printf("create stamp = %u\n", hdr.create_stamp);
	printf("initial modseq = %llu\n",
	       (unsigned long long)hdr.initial_modseq);
	printf("compat flags = %x\n", hdr.compat_flags);
	*modseq_r = hdr.initial_modseq;
}

static bool
mail_transaction_header_has_modseq(const struct mail_transaction_header *hdr)
{
	switch (hdr->type & MAIL_TRANSACTION_TYPE_MASK) {
	case MAIL_TRANSACTION_EXPUNGE | MAIL_TRANSACTION_EXPUNGE_PROT:
	case MAIL_TRANSACTION_EXPUNGE_GUID | MAIL_TRANSACTION_EXPUNGE_PROT:
		if ((hdr->type & MAIL_TRANSACTION_EXTERNAL) == 0) {
			/* ignore expunge requests */
			break;
		}
	case MAIL_TRANSACTION_APPEND:
	case MAIL_TRANSACTION_FLAG_UPDATE:
	case MAIL_TRANSACTION_KEYWORD_UPDATE:
	case MAIL_TRANSACTION_KEYWORD_RESET:
	case MAIL_TRANSACTION_UID_UPDATE:
		/* these changes increase modseq */
		return TRUE;
	}
	return FALSE;
}
static const char *log_record_type(unsigned int type)
{'fraction_non_alphanumeric': 0.14357452636384388, 'fraction_numerical': 0.02876055695046793, 'mean_word_length': 5.094575799721836, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4509735', 'n_tokens_mistral': 1901, 'n_tokens_neox': 1759, 'n_words': 351}