diff options
author | 2013-06-28 23:22:55 -0700 | |
---|---|---|
committer | 2013-06-28 23:22:55 -0700 | |
commit | 55ce286ebe364761cd682025b8a19bd13351a46e (patch) | |
tree | 2c1f06790d7c42e9590a93f6412500b975a6bfda | |
parent | db0663dcdcffef7739c5fcd2dc8c9ba6d06f8fab (diff) | |
parent | 6b43e147ea6c005c9fadd7a0e79d40dececb781d (diff) |
Merge pull request #158 from CodaFi/Copy
Implemented mailcore::NetService::copy() and mailcore::NetService::description().
-rw-r--r-- | src/core/provider/MCMailProvider.cc | 108 | ||||
-rw-r--r-- | src/core/provider/MCMailProvider.h | 4 | ||||
-rw-r--r-- | src/core/provider/MCNetService.cc | 62 | ||||
-rw-r--r-- | src/core/provider/MCNetService.h | 53 |
4 files changed, 135 insertions, 92 deletions
diff --git a/src/core/provider/MCMailProvider.cc b/src/core/provider/MCMailProvider.cc index b814e2ea..43fd94f9 100644 --- a/src/core/provider/MCMailProvider.cc +++ b/src/core/provider/MCMailProvider.cc @@ -18,7 +18,7 @@ using namespace mailcore; void MailProvider::init() { mIdentifier = NULL; - mImapServices = new Array(); + mImapServices = new Array(); mSmtpServices = new Array(); mPopServices = new Array(); mDomainMatch = new Array(); @@ -31,15 +31,27 @@ MailProvider::MailProvider() init(); } +MailProvider::MailProvider(MailProvider * other) +{ + init(); + MC_SAFE_REPLACE_COPY(String, mIdentifier, other->mIdentifier); + MC_SAFE_REPLACE_COPY(Array, mImapServices, other->mImapServices); + MC_SAFE_REPLACE_COPY(Array, mSmtpServices, other->mSmtpServices); + MC_SAFE_REPLACE_COPY(Array, mPopServices, other->mPopServices); + MC_SAFE_REPLACE_COPY(Array, mDomainMatch, other->mDomainMatch); + MC_SAFE_REPLACE_COPY(Set, mMxSet, other->mMxSet); + MC_SAFE_REPLACE_COPY(HashMap, mMailboxPaths, other->mMailboxPaths); +} + 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); + 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) @@ -52,7 +64,7 @@ MailProvider * MailProvider::providerWithInfo(HashMap * info) void MailProvider::fillWithInfo(HashMap * info) { - Array * imapInfos; + Array * imapInfos; Array * smtpInfos; Array * popInfos; HashMap * serverInfo; @@ -68,9 +80,9 @@ void MailProvider::fillWithInfo(HashMap * info) } mxs = (Array *) info->objectForKey(MCSTR("mx")); mMxSet->removeAllObjects(); - mc_foreacharray(String, mx, mxs) { - mMxSet->addObject(mx->lowercaseString()); - } + mc_foreacharray(String, mx, mxs) { + mMxSet->addObject(mx->lowercaseString()); + } serverInfo = (HashMap *) info->objectForKey(MCSTR("servers")); imapInfos = (Array *) serverInfo->objectForKey(MCSTR("imap")); @@ -78,52 +90,52 @@ void MailProvider::fillWithInfo(HashMap * info) popInfos = (Array *) serverInfo->objectForKey(MCSTR("pop")); mImapServices->removeAllObjects(); - mc_foreacharray(HashMap, imapInfo, imapInfos) { - NetService * service = NetService::serviceWithInfo(imapInfo); + 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); - } - + 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); - } + 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); + MC_SAFE_REPLACE_COPY(String, mIdentifier, identifier); } String * MailProvider::identifier() { - return mIdentifier; + return mIdentifier; } Array * MailProvider::imapServices() { - return mImapServices; + return mImapServices; } Array * MailProvider::smtpServices() { - return mSmtpServices; + return mSmtpServices; } Array * MailProvider::popServices() { - return mPopServices; + return mPopServices; } bool MailProvider::matchEmail(String * email) { - Array * components; + Array * components; String * domain; const char * cDomain; @@ -133,9 +145,9 @@ bool MailProvider::matchEmail(String * email) domain = (String *) components->lastObject(); cDomain = domain->UTF8Characters(); - - mc_foreacharray(String, match, mDomainMatch) { - regex_t r; + + mc_foreacharray(String, match, mDomainMatch) { + regex_t r; bool matched; match = String::stringWithUTF8Format("^%s$", match->UTF8Characters()); @@ -151,14 +163,14 @@ bool MailProvider::matchEmail(String * email) if (matched) return true; - } + } return false; } bool MailProvider::matchMX(String * hostname) { - return mMxSet->containsObject(hostname->lowercaseString()); + return mMxSet->containsObject(hostname->lowercaseString()); } String * MailProvider::sentMailFolderPath() @@ -168,38 +180,38 @@ String * MailProvider::sentMailFolderPath() String * MailProvider::starredFolderPath() { - return (String *) mMailboxPaths->objectForKey(MCSTR("starred")); + return (String *) mMailboxPaths->objectForKey(MCSTR("starred")); } String * MailProvider::allMailFolderPath() { - return (String *) mMailboxPaths->objectForKey(MCSTR("allmail")); + return (String *) mMailboxPaths->objectForKey(MCSTR("allmail")); } String * MailProvider::trashFolderPath() { - return (String *) mMailboxPaths->objectForKey(MCSTR("trash")); + return (String *) mMailboxPaths->objectForKey(MCSTR("trash")); } String * MailProvider::draftsFolderPath() { - return (String *) mMailboxPaths->objectForKey(MCSTR("drafts")); + return (String *) mMailboxPaths->objectForKey(MCSTR("drafts")); } String * MailProvider::spamFolderPath() { - return (String *) mMailboxPaths->objectForKey(MCSTR("spam")); + return (String *) mMailboxPaths->objectForKey(MCSTR("spam")); } String * MailProvider::importantFolderPath() { - return (String *) mMailboxPaths->objectForKey(MCSTR("important")); + return (String *) mMailboxPaths->objectForKey(MCSTR("important")); } bool MailProvider::isMainFolder(String * folderPath, String * prefix) { - mc_foreachdictionaryValue(String, path, mMailboxPaths) { - String * fullPath; + mc_foreachdictionaryValue(String, path, mMailboxPaths) { + String * fullPath; if (prefix != NULL) { fullPath = prefix->stringByAppendingString((String *) path); @@ -210,7 +222,7 @@ bool MailProvider::isMainFolder(String * folderPath, String * prefix) if (fullPath->isEqual(folderPath)) return true; - } + } return false; } @@ -219,3 +231,9 @@ String * MailProvider::description() { return String::stringWithUTF8Format("<%s:%p, %s>", className()->UTF8Characters(), this, MCUTF8(mIdentifier)); } + +Object * MailProvider::copy() +{ + return new MailProvider(this); +} + diff --git a/src/core/provider/MCMailProvider.h b/src/core/provider/MCMailProvider.h index 306b180d..81b816e9 100644 --- a/src/core/provider/MCMailProvider.h +++ b/src/core/provider/MCMailProvider.h @@ -45,8 +45,10 @@ namespace mailcore { virtual bool isMainFolder(String * folderPath, String * prefix); public: // subclass behavior + MailProvider(MailProvider * other); virtual String * description(); - + virtual Object * copy(); + public: // private virtual void setIdentifier(String * identifier); virtual void fillWithInfo(HashMap * info); diff --git a/src/core/provider/MCNetService.cc b/src/core/provider/MCNetService.cc index 53ae7475..f760dc61 100644 --- a/src/core/provider/MCNetService.cc +++ b/src/core/provider/MCNetService.cc @@ -19,12 +19,20 @@ void NetService::init() NetService::NetService() { - init(); + init(); +} + +NetService::NetService(NetService * other) +{ + init(); + MC_SAFE_REPLACE_COPY(String, mHostname, other->mHostname); + mPort = other->mPort; + mConnectionType = other->mConnectionType; } NetService::~NetService() { - MC_SAFE_RELEASE(mHostname); + MC_SAFE_RELEASE(mHostname); } NetService * NetService::serviceWithInfo(HashMap * info) @@ -37,10 +45,10 @@ NetService * NetService::serviceWithInfo(HashMap * info) void NetService::fillWithInfo(HashMap * info) { - bool ssl = false; + bool ssl = false; bool starttls = false; - - setHostname((String *) info->objectForKey(MCSTR("hostname"))); + + setHostname((String *) info->objectForKey(MCSTR("hostname"))); if (info->objectForKey(MCSTR("port")) != NULL) { setPort(((Value *) info->objectForKey(MCSTR("port")))->intValue()); } @@ -68,57 +76,57 @@ void NetService::setHostname(String *hostname) String * NetService::hostname() { - return mHostname; + return mHostname; } void NetService::setPort(unsigned int port) { - mPort = port; + mPort = port; } unsigned int NetService::port() { - return mPort; + return mPort; } void NetService::setConnectionType(ConnectionType connectionType) { - mConnectionType = connectionType; + mConnectionType = connectionType; } ConnectionType NetService::connectionType() { - return mConnectionType; + return mConnectionType; } String * NetService::normalizedHostnameWithEmail(String * email) { - Array *components = email->componentsSeparatedByString(MCSTR("@")); - String *hostname = (String *) mHostname->copy(); - if (components->count() != 0) { - hostname->replaceOccurrencesOfString(MCSTR("{domain}"), (String *) components->lastObject()); - return hostname; - } - return mHostname; + Array *components = email->componentsSeparatedByString(MCSTR("@")); + String *hostname = (String *) mHostname->copy(); + if (components->count() != 0) { + hostname->replaceOccurrencesOfString(MCSTR("{domain}"), (String *) components->lastObject()); + return hostname; + } + return mHostname; } HashMap * NetService::info() { - HashMap * result; + HashMap * result; result = new HashMap(); if (mHostname != NULL) { - result->setObjectForKey(MCSTR("hostname"), mHostname); + result->setObjectForKey(MCSTR("hostname"), mHostname); } if (mPort != 0) { - result->setObjectForKey(MCSTR("port"), Value::valueWithIntValue(mPort)); + result->setObjectForKey(MCSTR("port"), Value::valueWithIntValue(mPort)); } switch (mConnectionType) { case ConnectionTypeTLS: - result->setObjectForKey(MCSTR("ssl"), Value::valueWithBoolValue(true)); + result->setObjectForKey(MCSTR("ssl"), Value::valueWithBoolValue(true)); break; case ConnectionTypeStartTLS: - result->setObjectForKey(MCSTR("starttls"), Value::valueWithBoolValue(true)); + result->setObjectForKey(MCSTR("starttls"), Value::valueWithBoolValue(true)); break; default: break; @@ -126,3 +134,13 @@ HashMap * NetService::info() return result; } + +String * NetService::description() +{ + return String::stringWithUTF8Format("<%s:%p, hostname: %s, port: %u>", className()->UTF8Characters(), this, MCUTF8(mHostname), mPort); +} + +Object * NetService::copy() +{ + return new NetService(this); +} diff --git a/src/core/provider/MCNetService.h b/src/core/provider/MCNetService.h index 7b0b9e14..d3aa5dd7 100644 --- a/src/core/provider/MCNetService.h +++ b/src/core/provider/MCNetService.h @@ -15,35 +15,40 @@ #ifdef __cplusplus namespace mailcore { - class NetService : public Object { - - public: - NetService(); - virtual ~NetService(); - - virtual void setHostname(String * hostname); - virtual String * hostname(); - - virtual void setPort(unsigned int port); - virtual unsigned int port(); - - virtual void setConnectionType(ConnectionType connectionType); - virtual ConnectionType connectionType(); - - virtual String * normalizedHostnameWithEmail(String * email); + class NetService : public Object { + + public: + NetService(); + virtual ~NetService(); + + virtual void setHostname(String * hostname); + virtual String * hostname(); + + virtual void setPort(unsigned int port); + virtual unsigned int port(); + + virtual void setConnectionType(ConnectionType connectionType); + virtual ConnectionType connectionType(); + + virtual String * normalizedHostnameWithEmail(String * email); public: // serialization static NetService * serviceWithInfo(HashMap * info); - virtual HashMap * info(); + virtual HashMap * info(); + + public: //subclass behavior + NetService(NetService * other); + virtual String * description(); + virtual Object * copy(); + + private: + String * mHostname; + unsigned int mPort; + ConnectionType mConnectionType; - private: - String * mHostname; - unsigned int mPort; - ConnectionType mConnectionType; - - void init(); + void init(); void fillWithInfo(HashMap * info); - }; + }; } #endif |