<commit_before>//
//  MCMailProvider.cpp
//  mailcore2
//
//  Created by <NAME> on 4/28/13.
//  Copyright (c) 2013 MailCore. All rights reserved.
//

#include "MCMailProvider.h"
#include "MCNetService.h"
#include "MCIterator.h"
#include "MCJSON.h"

#include <regex.h>

using namespace mailcore;

void MailProvider::init()
{
    mIdentifier = NULL;
	mImapServices = new Array();
    mSmtpServices = new Array();
    mPopServices = new Array();
    mDomainMatch = new Array();
    mMxSet = new Set();
    mMailboxPaths = NULL;
}

MailProvider::MailProvider()
{
    init();
}

MailProvider::~MailProvider()
{
	MC_SAFE_RELEASE(mImapServices);
	MC_SAFE_RELEASE(mSmtpServices);
	MC_SAFE_RELEASE(mPopServices);
	MC_SAFE_RELEASE(mMxSet);
	MC_SAFE_RELEASE(mDomainMatch);
	MC_SAFE_RELEASE(mMailboxPaths);
	MC_SAFE_RELEASE(mIdentifier);
}

MailProvider * MailProvider::providerWithInfo(HashMap * info)
{
    MailProvider * provider = new MailProvider();
    provider->fillWithInfo(info);
    provider->autorelease();
    return provider;
}

void MailProvider::fillWithInfo(HashMap * info)
{
	Array * imapInfos;
    Array * smtpInfos;
    Array * popInfos;
    HashMap * serverInfo;
    Array * mxs;
    
    MC_SAFE_RELEASE(mDomainMatch);
    if (info->objectForKey(MCSTR("domain-match")) != NULL) {
        mDomainMatch = (Array *) info->objectForKey(MCSTR("domain-match"))->retain();
    }
    MC_SAFE_RELEASE(mMailboxPaths);
    if (info->objectForKey(MCSTR("mailboxes")) != NULL) {
        mMailboxPaths = (HashMap *) info->objectForKey(MCSTR("mailboxes"))->retain();
    }
    mxs = (Array *) info->objectForKey(MCSTR("mx"));
    mMxSet->removeAllObjects();
	mc_foreacharray(String, mx, mxs) {
		mMxSet->addObject(mx->lowercaseString());
	}
    
    serverInfo = (HashMap *) info->objectForKey(MCSTR("servers"));
    imapInfos = (Array *) serverInfo->objectForKey(MCSTR("imap"));
    smtpInfos = (Array *) serverInfo->objectForKey(MCSTR("smtp"));
    popInfos = (Array *) serverInfo->objectForKey(MCSTR("pop"));
    
    mImapServices->removeAllObjects();
	mc_foreacharray(HashMap, imapInfo, imapInfos) {
		NetService * service = NetService::serviceWithInfo(imapInfo);
        mImapServices->addObject(service);
	}
	
    mSmtpServices->removeAllObjects();
	mc_foreacharray(HashMap, smtpInfo, smtpInfos) {
		NetService * service = NetService::serviceWithInfo(smtpInfo);
		mSmtpServices->addObject(service);
        service->release();
	}
	
    mPopServices->removeAllObjects();
	mc_foreacharray(HashMap, popInfo, popInfos) {
		NetService * service = NetService::serviceWithInfo(popInfo);
		mPopServices->addObject(service);
        service->release();
	}
}

void MailProvider::setIdentifier(String * identifier)
{
	MC_SAFE_REPLACE_COPY(String, mIdentifier, identifier);<commit_msg>Fixed crash when using mailproviders<commit_after>//
//  MCMailProvider.cpp
//  mailcore2
//
//  Created by <NAME> on 4/28/13.
//  Copyright (c) 2013 MailCore. All rights reserved.
//

#include "MCMailProvider.h"
#include "MCNetService.h"
#include "MCIterator.h"
#include "MCJSON.h"

#include <regex.h>

using namespace mailcore;

void MailProvider::init()
{
    mIdentifier = NULL;
	mImapServices = new Array();
    mSmtpServices = new Array();
    mPopServices = new Array();
    mDomainMatch = new Array();
    mMxSet = new Set();
    mMailboxPaths = NULL;
}

MailProvider::MailProvider()
{
    init();
}

MailProvider::~MailProvider()
{
	MC_SAFE_RELEASE(mImapServices);
	MC_SAFE_RELEASE(mSmtpServices);
	MC_SAFE_RELEASE(mPopServices);
	MC_SAFE_RELEASE(mMxSet);
	MC_SAFE_RELEASE(mDomainMatch);
	MC_SAFE_RELEASE(mMailboxPaths);
	MC_SAFE_RELEASE(mIdentifier);
}

MailProvider * MailProvider::providerWithInfo(HashMap * info)
{
    MailProvider * provider = new MailProvider();
    provider->fillWithInfo(info);
    provider->autorelease();
    return provider;
}

void MailProvider::fillWithInfo(HashMap * info)
{
	Array * imapInfos;
    Array * smtpInfos;
    Array * popInfos;
    HashMap * serverInfo;
    Array * mxs;
    
    MC_SAFE_RELEASE(mDomainMatch);
    if (info->objectForKey(MCSTR("domain-match")) != NULL) {
        mDomainMatch = (Array *) info->objectForKey(MCSTR("domain-match"))->retain();
    }
    MC_SAFE_RELEASE(mMailboxPaths);
    if (info->objectForKey(MCSTR("mailboxes")) != NULL) {
        mMailboxPaths = (HashMap *) info->objectForKey(MCSTR("mailboxes"))->retain();
    }
    mxs = (Array *) info->objectForKey(MCSTR("mx"));
    mMxSet->removeAllObjects();
	mc_foreacharray(String, mx, mxs) {
		mMxSet->addObject(mx->lowercaseString());
	}
    
    serverInfo = (HashMap *) info->objectForKey(MCSTR("servers"));
    imapInfos = (Array *) serverInfo->objectForKey(MCSTR("imap"));
    smtpInfos = (Array *) serverInfo->objectForKey(MCSTR("smtp"));
    popInfos = (Array *) serverInfo->objectForKey(MCSTR("pop"));
    
    mImapServices->removeAllObjects();
	mc_foreacharray(HashMap, imapInfo, imapInfos) {
		NetService * service = NetService::serviceWithInfo(imapInfo);
        mImapServices->addObject(service);
	}
	
    mSmtpServices->removeAllObjects();
	mc_foreacharray(HashMap, smtpInfo, smtpInfos) {
		NetService * service = NetService::serviceWithInfo(smtpInfo);
		mSmtpServices->addObject(service);
	}
	
    mPopServices->removeAllObjects();
	mc_foreacharray(HashMap, popInfo, popInfos) {
		NetService * service = NetService::serviceWithInfo(popInfo);
		mPopServices->addObject(service);
	}
}

void MailProvider::setIdentifier(String * identifier)
{
	MC_SAFE_REPLACE_COPY(String, mIdentifier, identifier);
{'fraction_non_alphanumeric': 0.14360834088848595, 'fraction_numerical': 0.003626473254759746, 'mean_word_length': 4.716062176165803, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 53, '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': '348033', 'n_tokens_mistral': 1937, 'n_tokens_neox': 1894, 'n_words': 299}