<commit_before>/*
 * $Id$
 *
 * Copyright(C) 1998-2004 <NAME>
 * All rights reserved.
 *
 */

#include <qmfolder.h>
#include <qmmessageholder.h>

#include <qsstl.h>

#include <algorithm>
#include <cstdio>

#include "util.h"

#pragma warning(disable:4786)

using namespace qmimap4;
using namespace qm;
using namespace qs;


/****************************************************************************
 *
 * Util
 *
 */

wstring_ptr qmimap4::Util::getFolderName(NormalFolder* pFolder)
{
	assert(pFolder);
	
	wstring_ptr wstrName(pFolder->getFullName());
	
	if (pFolder->isFlag(Folder::FLAG_CHILDOFROOT)) {
		Account* pAccount = pFolder->getAccount();
		wstring_ptr wstrRootFolder(pAccount->getProperty(L"Imap4", L"RootFolder", L""));
		
		if (*wstrRootFolder.get()) {
			WCHAR wsz[] = { pFolder->getSeparator(), L'\0' };
			wstrName = concat(wstrRootFolder.get(), wsz, wstrName.get());
		}
	}
	
	return wstrName;
}

unsigned int qmimap4::Util::getFolderFlagsFromAttributes(unsigned int nAttributes)
{
	struct {
		ResponseList::Attribute attribute_;
		Folder::Flag flag_;
	} flags[] = {
		{ ResponseList::ATTRIBUTE_NOINFERIORS,	Folder::FLAG_NOINFERIORS	},
		{ ResponseList::ATTRIBUTE_NOSELECT,		Folder::FLAG_NOSELECT		}
	};
	
	unsigned int nFlags = 0;
	
	for (int n = 0; n < countof(flags); ++n) {
		if (nAttributes & flags[n].attribute_)
			nFlags |= flags[n].flag_;
	}
	
	return nFlags;
}

unsigned int qmimap4::Util::getMessageFlagsFromImap4Flags(unsigned int nSystemFlags,
														  const FetchDataFlags::FlagList& listCustomFlag)
{
	struct {
		Imap4::Flag imap4Flag_;
		MessageHolder::Flag messageFlag_;
	} flags[] = {
		{ Imap4::FLAG_ANSWERED,	MessageHolder::FLAG_REPLIED	},
		{ Imap4::FLAG_DELETED,	MessageHolder::FLAG_DELETED	},
		{ Imap4::FLAG_SEEN,		MessageHolder::FLAG_SEEN	},
		{ Imap4::FLAG_FLAGGED,	MessageHolder::FLAG_MARKED	}
	};
	
	unsigned int nMessageFlags = 0;
	for (int n = 0; n < countof(flags); ++n) {
		if (nSystemFlags & flags[n].imap4Flag_)
			nMessageFlags |= flags[n].messageFlag_;
	}
	
	return nMessageFlags;
}

unsigned int qmimap4::Util::getImap4FlagsFromMessageFlags(unsigned int nFlags)
{
	struct {
		MessageHolder::Flag messageFlag_;
		Imap4::Flag imap4Flag_;
	} flags[] = {
		{ MessageHolder::FLAG_REPLIED,	Imap4::FLAG_ANSWERED	},
		{ MessageHolder::FLAG_DELETED,	Imap4::FLAG_DELETED		},
		{ MessageHolder::FLAG_SEEN,		Imap4::FLAG_SEEN		},
		{ MessageHolder::FLAG_MARKED,	Imap4::FLAG_FLAGGED		}
	};
	
	unsigned int nImap4Flags = 0;
	for (int n = 0; n < countof(flags); ++n) {
		if (nFlags & flags[n].messageFlag_)
			nImap4Flags |= flags[n].imap4Flag_;
	}
	
	return nImap4Flags;
}

string_ptr qmimap4::Util::getMessageFromEnvelope(const FetchDataEnvelope* pEnvelope)
{
	assert(pEnvelope);
	
	StringBuffer<STRING> buf;
	
	const CHAR* pszMessageId = pEnvelope->getMessageId();
	if (pszMessageId && *pszMessageId) {
		buf.append("Message-Id: ");
		buf.append(pszMessageId);
		buf.append("\r\n");
	}<commit_msg>Fix \Draft is not handled. <BTS:623><commit_after>/*
 * $Id$
 *
 * Copyright(C) 1998-2004 <NAME>
 * All rights reserved.
 *
 */

#include <qmfolder.h>
#include <qmmessageholder.h>

#include <qsstl.h>

#include <algorithm>
#include <cstdio>

#include "util.h"

#pragma warning(disable:4786)

using namespace qmimap4;
using namespace qm;
using namespace qs;


/****************************************************************************
 *
 * Util
 *
 */

wstring_ptr qmimap4::Util::getFolderName(NormalFolder* pFolder)
{
	assert(pFolder);
	
	wstring_ptr wstrName(pFolder->getFullName());
	
	if (pFolder->isFlag(Folder::FLAG_CHILDOFROOT)) {
		Account* pAccount = pFolder->getAccount();
		wstring_ptr wstrRootFolder(pAccount->getProperty(L"Imap4", L"RootFolder", L""));
		
		if (*wstrRootFolder.get()) {
			WCHAR wsz[] = { pFolder->getSeparator(), L'\0' };
			wstrName = concat(wstrRootFolder.get(), wsz, wstrName.get());
		}
	}
	
	return wstrName;
}

unsigned int qmimap4::Util::getFolderFlagsFromAttributes(unsigned int nAttributes)
{
	struct {
		ResponseList::Attribute attribute_;
		Folder::Flag flag_;
	} flags[] = {
		{ ResponseList::ATTRIBUTE_NOINFERIORS,	Folder::FLAG_NOINFERIORS	},
		{ ResponseList::ATTRIBUTE_NOSELECT,		Folder::FLAG_NOSELECT		}
	};
	
	unsigned int nFlags = 0;
	
	for (int n = 0; n < countof(flags); ++n) {
		if (nAttributes & flags[n].attribute_)
			nFlags |= flags[n].flag_;
	}
	
	return nFlags;
}

unsigned int qmimap4::Util::getMessageFlagsFromImap4Flags(unsigned int nSystemFlags,
														  const FetchDataFlags::FlagList& listCustomFlag)
{
	struct {
		Imap4::Flag imap4Flag_;
		MessageHolder::Flag messageFlag_;
	} flags[] = {
		{ Imap4::FLAG_ANSWERED,	MessageHolder::FLAG_REPLIED	},
		{ Imap4::FLAG_DELETED,	MessageHolder::FLAG_DELETED	},
		{ Imap4::FLAG_SEEN,		MessageHolder::FLAG_SEEN	},
		{ Imap4::FLAG_FLAGGED,	MessageHolder::FLAG_MARKED	},
		{ Imap4::FLAG_DRAFT,	MessageHolder::FLAG_DRAFT	}
	};
	
	unsigned int nMessageFlags = 0;
	for (int n = 0; n < countof(flags); ++n) {
		if (nSystemFlags & flags[n].imap4Flag_)
			nMessageFlags |= flags[n].messageFlag_;
	}
	
	return nMessageFlags;
}

unsigned int qmimap4::Util::getImap4FlagsFromMessageFlags(unsigned int nFlags)
{
	struct {
		MessageHolder::Flag messageFlag_;
		Imap4::Flag imap4Flag_;
	} flags[] = {
		{ MessageHolder::FLAG_REPLIED,	Imap4::FLAG_ANSWERED	},
		{ MessageHolder::FLAG_DELETED,	Imap4::FLAG_DELETED		},
		{ MessageHolder::FLAG_SEEN,		Imap4::FLAG_SEEN		},
		{ MessageHolder::FLAG_MARKED,	Imap4::FLAG_FLAGGED		},
		{ MessageHolder::FLAG_DRAFT,	Imap4::FLAG_DRAFT		}
	};
	
	unsigned int nImap4Flags = 0;
	for (int n = 0; n < countof(flags); ++n) {
		if (nFlags & flags[n].messageFlag_)
			nImap4Flags |= flags[n].imap4Flag_;
	}
	
	return nImap4Flags;
}

string_ptr qmimap4::Util::getMessageFromEnvelope(const FetchDataEnvelope* pEnvelope)
{
	assert(pEnvelope);
	
	StringBuffer<STRING> buf;
	
	const CHAR* pszMessageId = pEnvelope->getMessageId();
	if (pszMessageId && *pszMessageId) {
		buf.append("Message-Id: ");
		buf.append(pszMessageId);
		buf.append("\r\n");
	}
{'fraction_non_alphanumeric': 0.16727574750830565, 'fraction_numerical': 0.015780730897009966, 'mean_word_length': 5.162743091095189, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 30, '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': '1645747', 'n_tokens_mistral': 2448, 'n_tokens_neox': 2261, 'n_words': 381}