diff options
author | Matt A. Tobin <email@mattatobin.com> | 2019-11-03 00:17:46 -0400 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2019-11-03 00:17:46 -0400 |
commit | 302bf1b523012e11b60425d6eee1221ebc2724eb (patch) | |
tree | b191a895f8716efcbe42f454f37597a545a6f421 /mailnews/news/src/nsNewsUtils.cpp | |
parent | 21b3f6247403c06f85e1f45d219f87549862198f (diff) | |
download | UXP-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/news/src/nsNewsUtils.cpp')
-rw-r--r-- | mailnews/news/src/nsNewsUtils.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/mailnews/news/src/nsNewsUtils.cpp b/mailnews/news/src/nsNewsUtils.cpp new file mode 100644 index 000000000..b7fc5e70c --- /dev/null +++ b/mailnews/news/src/nsNewsUtils.cpp @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 2; 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 "nntpCore.h" +#include "nsNewsUtils.h" +#include "nsMsgUtils.h" + + +/* parses NewsMessageURI */ +nsresult +nsParseNewsMessageURI(const char* uri, nsCString& group, nsMsgKey *key) +{ + NS_ENSURE_ARG_POINTER(uri); + NS_ENSURE_ARG_POINTER(key); + + nsAutoCString uriStr(uri); + int32_t keySeparator = uriStr.FindChar('#'); + if(keySeparator != -1) + { + int32_t keyEndSeparator = MsgFindCharInSet(uriStr, "?&", keySeparator); + + // Grab between the last '/' and the '#' for the key + group = StringHead(uriStr, keySeparator); + int32_t groupSeparator = group.RFind("/"); + if (groupSeparator == -1) + return NS_ERROR_FAILURE; + + // Our string APIs don't let us unescape into the same buffer from earlier, + // so escape into a temporary + nsAutoCString unescapedGroup; + MsgUnescapeString(Substring(group, groupSeparator + 1), 0, unescapedGroup); + group = unescapedGroup; + + nsAutoCString keyStr; + if (keyEndSeparator != -1) + keyStr = Substring(uriStr, keySeparator + 1, keyEndSeparator - (keySeparator + 1)); + else + keyStr = Substring(uriStr, keySeparator + 1); + nsresult errorCode; + *key = keyStr.ToInteger(&errorCode); + + return errorCode; + } + return NS_ERROR_FAILURE; +} + +nsresult nsCreateNewsBaseMessageURI(const char *baseURI, nsCString &baseMessageURI) +{ + nsAutoCString tailURI(baseURI); + + // chop off news:/ + if (tailURI.Find(kNewsRootURI) == 0) + tailURI.Cut(0, PL_strlen(kNewsRootURI)); + + baseMessageURI = kNewsMessageRootURI; + baseMessageURI += tailURI; + + return NS_OK; +} |