summaryrefslogtreecommitdiffstats
path: root/mailnews/base/src/nsMsgFolderCacheElement.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2019-11-03 00:17:46 -0400
committerMatt A. Tobin <email@mattatobin.com>2019-11-03 00:17:46 -0400
commit302bf1b523012e11b60425d6eee1221ebc2724eb (patch)
treeb191a895f8716efcbe42f454f37597a545a6f421 /mailnews/base/src/nsMsgFolderCacheElement.cpp
parent21b3f6247403c06f85e1f45d219f87549862198f (diff)
downloadUXP-302bf1b523012e11b60425d6eee1221ebc2724eb.tar
UXP-302bf1b523012e11b60425d6eee1221ebc2724eb.tar.gz
UXP-302bf1b523012e11b60425d6eee1221ebc2724eb.tar.lz
UXP-302bf1b523012e11b60425d6eee1221ebc2724eb.tar.xz
UXP-302bf1b523012e11b60425d6eee1221ebc2724eb.zip
Issue #1258 - Part 1: Import mailnews, ldap, and mork from comm-esr52.9.1
Diffstat (limited to 'mailnews/base/src/nsMsgFolderCacheElement.cpp')
-rw-r--r--mailnews/base/src/nsMsgFolderCacheElement.cpp163
1 files changed, 163 insertions, 0 deletions
diff --git a/mailnews/base/src/nsMsgFolderCacheElement.cpp b/mailnews/base/src/nsMsgFolderCacheElement.cpp
new file mode 100644
index 000000000..e1197c7ed
--- /dev/null
+++ b/mailnews/base/src/nsMsgFolderCacheElement.cpp
@@ -0,0 +1,163 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "msgCore.h"
+#include "nsMsgFolderCacheElement.h"
+#include "prmem.h"
+#include "nsMsgUtils.h"
+
+nsMsgFolderCacheElement::nsMsgFolderCacheElement()
+{
+ m_mdbRow = nullptr;
+ m_owningCache = nullptr;
+}
+
+nsMsgFolderCacheElement::~nsMsgFolderCacheElement()
+{
+ NS_IF_RELEASE(m_mdbRow);
+ // circular reference, don't do it.
+ // NS_IF_RELEASE(m_owningCache);
+}
+
+NS_IMPL_ISUPPORTS(nsMsgFolderCacheElement, nsIMsgFolderCacheElement)
+
+NS_IMETHODIMP nsMsgFolderCacheElement::GetKey(nsACString& aFolderKey)
+{
+ aFolderKey = m_folderKey;
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsMsgFolderCacheElement::SetKey(const nsACString& aFolderKey)
+{
+ m_folderKey = aFolderKey;
+ return NS_OK;
+}
+
+void nsMsgFolderCacheElement::SetOwningCache(nsMsgFolderCache *owningCache)
+{
+ m_owningCache = owningCache;
+ // circular reference, don't do it.
+ // if (owningCache)
+ // NS_ADDREF(owningCache);
+}
+
+NS_IMETHODIMP nsMsgFolderCacheElement::GetStringProperty(const char *propertyName, nsACString& result)
+{
+ NS_ENSURE_ARG_POINTER(propertyName);
+ NS_ENSURE_TRUE(m_mdbRow && m_owningCache, NS_ERROR_FAILURE);
+
+ mdb_token property_token;
+ nsresult ret = m_owningCache->GetStore()->StringToToken(m_owningCache->GetEnv(), propertyName, &property_token);
+ if (NS_SUCCEEDED(ret))
+ ret = m_owningCache->RowCellColumnToCharPtr(m_mdbRow, property_token, result);
+ return ret;
+}
+
+NS_IMETHODIMP nsMsgFolderCacheElement::GetInt32Property(const char *propertyName, int32_t *aResult)
+{
+ NS_ENSURE_ARG_POINTER(propertyName);
+ NS_ENSURE_ARG_POINTER(aResult);
+ NS_ENSURE_TRUE(m_mdbRow, NS_ERROR_FAILURE);
+
+ nsCString resultStr;
+ GetStringProperty(propertyName, resultStr);
+ if (resultStr.IsEmpty())
+ return NS_ERROR_FAILURE;
+
+ // This must be an inverse function to nsCString.AppentInt(),
+ // which uses snprintf("%x") internally, so that the wrapped negative numbers
+ // are decoded properly.
+ if (PR_sscanf(resultStr.get(), "%x", aResult) != 1)
+ {
+ NS_WARNING("Unexpected failure to decode hex string.");
+ return NS_ERROR_FAILURE;
+ }
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsMsgFolderCacheElement::GetInt64Property(const char *propertyName, int64_t *aResult)
+{
+ NS_ENSURE_ARG_POINTER(propertyName);
+ NS_ENSURE_ARG_POINTER(aResult);
+ NS_ENSURE_TRUE(m_mdbRow, NS_ERROR_FAILURE);
+
+ nsCString resultStr;
+ GetStringProperty(propertyName, resultStr);
+ if (resultStr.IsEmpty())
+ return NS_ERROR_FAILURE;
+
+ // This must be an inverse function to nsCString.AppentInt(),
+ // which uses snprintf("%x") internally, so that the wrapped negative numbers
+ // are decoded properly.
+ if (PR_sscanf(resultStr.get(), "%llx", aResult) != 1)
+ {
+ NS_WARNING("Unexpected failure to decode hex string.");
+ return NS_ERROR_FAILURE;
+ }
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsMsgFolderCacheElement::SetStringProperty(const char *propertyName, const nsACString& propertyValue)
+{
+ NS_ENSURE_ARG_POINTER(propertyName);
+ NS_ENSURE_TRUE(m_mdbRow, NS_ERROR_FAILURE);
+ nsresult rv = NS_OK;
+ mdb_token property_token;
+
+ if (m_owningCache)
+ {
+ rv = m_owningCache->GetStore()->StringToToken(m_owningCache->GetEnv(), propertyName, &property_token);
+ if (NS_SUCCEEDED(rv))
+ {
+ struct mdbYarn yarn;
+
+ yarn.mYarn_Grow = NULL;
+ if (m_mdbRow)
+ {
+ nsCString propertyVal (propertyValue);
+ yarn.mYarn_Buf = (void *) propertyVal.get();
+ yarn.mYarn_Size = strlen((const char *) yarn.mYarn_Buf) + 1;
+ yarn.mYarn_Fill = yarn.mYarn_Size - 1;
+ yarn.mYarn_Form = 0; // what to do with this? we're storing csid in the msg hdr...
+ rv = m_mdbRow->AddColumn(m_owningCache->GetEnv(), property_token, &yarn);
+ return rv;
+ }
+ }
+ }
+ return rv;
+}
+
+NS_IMETHODIMP nsMsgFolderCacheElement::SetInt32Property(const char *propertyName, int32_t propertyValue)
+{
+ NS_ENSURE_ARG_POINTER(propertyName);
+ NS_ENSURE_TRUE(m_mdbRow, NS_ERROR_FAILURE);
+
+ // This also supports encoding negative numbers into hex
+ // by integer wrapping them (e.g. -1 -> "ffffffff").
+ nsAutoCString propertyStr;
+ propertyStr.AppendInt(propertyValue, 16);
+ return SetStringProperty(propertyName, propertyStr);
+}
+
+NS_IMETHODIMP nsMsgFolderCacheElement::SetInt64Property(const char *propertyName, int64_t propertyValue)
+{
+ NS_ENSURE_ARG_POINTER(propertyName);
+ NS_ENSURE_TRUE(m_mdbRow, NS_ERROR_FAILURE);
+
+ // This also supports encoding negative numbers into hex
+ // by integer wrapping them (e.g. -1 -> "ffffffffffffffff").
+ nsAutoCString propertyStr;
+ propertyStr.AppendInt(propertyValue, 16);
+ return SetStringProperty(propertyName, propertyStr);
+}
+
+void nsMsgFolderCacheElement::SetMDBRow(nsIMdbRow *row)
+{
+ if (m_mdbRow)
+ NS_RELEASE(m_mdbRow);
+ NS_IF_ADDREF(m_mdbRow = row);
+}