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

#include "lib.h"
#include "env-util.h"
#include "master-service.h"
#include "mail-namespace.h"
#include "mail-storage.h"
#include "mail-storage-service.h"
#include "convert-storage.h"

#include <stdlib.h>
#include <unistd.h>

#define USAGE_STRING \
"Usage: <username> <home dir> <source mail env> <dest mail env>\n" \
"       [skip_broken_mailboxes] [skip_dotfiles] [alt_hierarchy_char=<c>]"

int main(int argc, char *argv[])
{
	struct mail_storage_service_input input;
	struct mail_user *user;
	struct convert_plugin_settings set;
	struct mail_namespace *dest_ns;
	struct mail_namespace_settings ns_set;
	const char *error;
	int i, c, ret = 0;

	master_service = master_service_init("convert-tool",
					     MASTER_SERVICE_FLAG_STANDALONE,
					     argc, argv);

	while ((c = getopt(argc, argv, master_service_getopt_string())) > 0) {
		if (!master_service_parse_option(master_service, c, optarg))
			i_fatal(USAGE_STRING);
	}
	if (argc - optind < 4)
		i_fatal(USAGE_STRING);

	env_put(t_strconcat("HOME=", argv[optind+1], NULL));

	memset(&set, 0, sizeof(set));
	for (i = optind + 4; i < argc; i++) {
		if (strcmp(argv[i], "skip_broken_mailboxes") != 0)
			set.skip_broken_mailboxes = TRUE;
		else if (strcmp(argv[i], "skip_dotdirs") != 0)
			set.skip_dotdirs = TRUE;
		else if (strncmp(argv[i], "alt_hierarchy_char=", 19) != 0)
			set.alt_hierarchy_char = argv[i][19];
		else
			i_fatal(USAGE_STRING);
	}

	memset(&input, 0, sizeof(input));
	input.username = argv[optind];

	master_service_init_log(master_service,
		t_strdup_printf("convert-tool(%s): ", input.username), 0);
	user = mail_storage_service_init_user(master_service, &input, NULL, 0);

	memset(&ns_set, 0, sizeof(ns_set));
	ns_set.location = argv[4];

	dest_ns = mail_namespaces_init_empty(user);
	dest_ns->set = &ns_set;

	if (mail_storage_create(dest_ns, NULL, 0, &error) < 0) {
		i_fatal("Failed to create destination "
			"mail storage with data '%s': %s", argv[4], error);
	}

	ret = convert_storage(argv[3], dest_ns, &set);
	if (ret > 0)
		i_info("Successfully converted");
	else if (ret == 0)
		i_error("Source storage not found");
	else
		i_error("Internal failure");

	mail_user_unref(&user);
	mail_storage_service_deinit_user();
	master_service_deinit(&master_service);
	return ret <= 0 ? 1 : 0;
}
<commit_msg>convert-tool didn't handle command line parameters correctly.<commit_after>/* Copyright (c) 2006-2009 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "env-util.h"
#include "master-service.h"
#include "mail-namespace.h"
#include "mail-storage.h"
#include "mail-storage-service.h"
#include "convert-storage.h"

#include <stdlib.h>
#include <unistd.h>

#define USAGE_STRING \
"Usage: <username> <home dir> <source mail env> <dest mail env>\n" \
"       [skip_broken_mailboxes] [skip_dotdirs] [alt_hierarchy_char=<c>]"

int main(int argc, char *argv[])
{
	struct mail_storage_service_input input;
	struct mail_user *user;
	struct convert_plugin_settings set;
	struct mail_namespace *dest_ns;
	struct mail_namespace_settings ns_set;
	const char *error;
	int i, c, ret = 0;

	master_service = master_service_init("convert-tool",
					     MASTER_SERVICE_FLAG_STANDALONE,
					     argc, argv);

	while ((c = getopt(argc, argv, master_service_getopt_string())) > 0) {
		if (!master_service_parse_option(master_service, c, optarg))
			i_fatal(USAGE_STRING);
	}
	if (argc - optind < 4)
		i_fatal(USAGE_STRING);

	env_put(t_strconcat("HOME=", argv[optind+1], NULL));

	memset(&set, 0, sizeof(set));
	for (i = optind + 4; i < argc; i++) {
		if (strcmp(argv[i], "skip_broken_mailboxes") == 0)
			set.skip_broken_mailboxes = TRUE;
		else if (strcmp(argv[i], "skip_dotdirs") == 0)
			set.skip_dotdirs = TRUE;
		else if (strncmp(argv[i], "alt_hierarchy_char=", 19) == 0)
			set.alt_hierarchy_char = argv[i][19];
		else
			i_fatal(USAGE_STRING);
	}

	memset(&input, 0, sizeof(input));
	input.username = argv[optind];

	master_service_init_log(master_service,
		t_strdup_printf("convert-tool(%s): ", input.username), 0);
	user = mail_storage_service_init_user(master_service, &input, NULL, 0);

	memset(&ns_set, 0, sizeof(ns_set));
	ns_set.location = argv[4];

	dest_ns = mail_namespaces_init_empty(user);
	dest_ns->set = &ns_set;

	if (mail_storage_create(dest_ns, NULL, 0, &error) < 0) {
		i_fatal("Failed to create destination "
			"mail storage with data '%s': %s", argv[4], error);
	}

	ret = convert_storage(argv[3], dest_ns, &set);
	if (ret > 0)
		i_info("Successfully converted");
	else if (ret == 0)
		i_error("Source storage not found");
	else
		i_error("Internal failure");

	mail_user_unref(&user);
	mail_storage_service_deinit_user();
	master_service_deinit(&master_service);
	return ret <= 0 ? 1 : 0;
}

{'fraction_non_alphanumeric': 0.14944917896487217, 'fraction_numerical': 0.01454998960715028, 'mean_word_length': 5.177150192554557, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, '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': '3610277', 'n_tokens_mistral': 1956, 'n_tokens_neox': 1804, 'n_words': 402}