123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- #include <kopano/platform.h>
- #include <kopano/archiver-common.h>
- #include <kopano/stringutil.h>
- namespace KC {
- bool entryid_t::operator==(const entryid_t &other) const
- {
- return getUnwrapped().m_vEntryId == other.getUnwrapped().m_vEntryId;
- }
- bool entryid_t::operator<(const entryid_t &other) const
- {
- return getUnwrapped().m_vEntryId < other.getUnwrapped().m_vEntryId;
- }
- bool entryid_t::operator>(const entryid_t &other) const
- {
- return getUnwrapped().m_vEntryId > other.getUnwrapped().m_vEntryId;
- }
- bool entryid_t::wrap(const std::string &strPath)
- {
- if (!kc_istarts_with(strPath, "file://") &&
- !kc_istarts_with(strPath, "http://") &&
- !kc_istarts_with(strPath, "https://"))
- return false;
-
- m_vEntryId.insert(m_vEntryId.begin(), (LPBYTE)strPath.c_str(), (LPBYTE)strPath.c_str() + strPath.size() + 1);
- return true;
- }
- bool entryid_t::unwrap(std::string *lpstrPath)
- {
- if (!isWrapped())
- return false;
-
- auto iter = std::find(m_vEntryId.begin(), m_vEntryId.end(), 0);
- if (iter == m_vEntryId.end())
- return false;
-
- if (lpstrPath)
- lpstrPath->assign((char*)&m_vEntryId.front(), iter - m_vEntryId.cbegin());
-
- m_vEntryId.erase(m_vEntryId.begin(), ++iter);
- return true;
- }
- bool entryid_t::isWrapped() const
- {
-
- const std::string strEntryId((char*)&m_vEntryId.front(), m_vEntryId.size());
- return kc_istarts_with(strEntryId, "file://") ||
- kc_istarts_with(strEntryId, "http://") ||
- kc_istarts_with(strEntryId, "https://");
- }
- entryid_t entryid_t::getUnwrapped() const
- {
- if (!isWrapped())
- return *this;
- entryid_t tmp(*this);
- tmp.unwrap(NULL);
- return tmp;
- }
- int abentryid_t::compare(const abentryid_t &other) const
- {
- if (size() < other.size())
- return -1;
- if (size() > other.size())
- return 1;
- if (size() <= 32) {
-
- return memcmp(LPBYTE(*this), LPBYTE(other), size());
- }
-
- int res = memcmp(LPBYTE(*this), LPBYTE(other), 28);
- if (res != 0)
- return res;
-
- return memcmp(LPBYTE(*this) + 32, LPBYTE(other) + 32, size() - 32);
- }
- eResult MAPIErrorToArchiveError(HRESULT hr)
- {
- switch (hr) {
- case hrSuccess: return Success;
- case MAPI_E_NOT_ENOUGH_MEMORY: return OutOfMemory;
- case MAPI_E_INVALID_PARAMETER: return InvalidParameter;
- case MAPI_W_PARTIAL_COMPLETION: return PartialCompletion;
- default: return Failure;
- }
- }
- const char* ArchiveResultString(eResult result)
- {
- const char* retval = "Unknown result";
- switch (result)
- {
- case Success:
- retval = "Success";
- break;
- case OutOfMemory:
- retval = "Out of memory";
- break;
- case InvalidParameter:
- retval = "Invalid parameter";
- break;
- case PartialCompletion:
- retval = "Partial completion";
- break;
- case Failure:
- retval = "Failure";
- break;
- default:
- ;
- }
- return retval;
- }
- }
|