diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mailnews/mime/src/comi18n.cpp | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/mailnews/mime/src/comi18n.cpp')
-rw-r--r-- | comm/mailnews/mime/src/comi18n.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/comm/mailnews/mime/src/comi18n.cpp b/comm/mailnews/mime/src/comi18n.cpp new file mode 100644 index 0000000000..90bfd17abf --- /dev/null +++ b/comm/mailnews/mime/src/comi18n.cpp @@ -0,0 +1,49 @@ +/* -*- 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 "comi18n.h" +#include "nsMsgUtils.h" +#include "nsServiceManagerUtils.h" +#include "nsComponentManagerUtils.h" +#include "nsIMimeConverter.h" +#include "mozilla/Preferences.h" +#include "mozilla/Encoding.h" +#include "mozilla/EncodingDetector.h" + +using namespace mozilla; + +//////////////////////////////////////////////////////////////////////////////// +// BEGIN PUBLIC INTERFACE +extern "C" { + +void MIME_DecodeMimeHeader(const char* header, const char* default_charset, + bool override_charset, bool eatContinuations, + nsACString& result) { + nsresult rv; + nsCOMPtr<nsIMimeConverter> mimeConverter = + do_GetService("@mozilla.org/messenger/mimeconverter;1", &rv); + if (NS_FAILED(rv)) { + result.Truncate(); + return; + } + mimeConverter->DecodeMimeHeaderToUTF8(nsDependentCString(header), + default_charset, override_charset, + eatContinuations, result); +} + +nsresult MIME_detect_charset(const char* aBuf, int32_t aLength, + nsACString& aCharset) { + mozilla::UniquePtr<mozilla::EncodingDetector> detector = + mozilla::EncodingDetector::Create(); + mozilla::Span<const uint8_t> src = + mozilla::AsBytes(mozilla::Span(aBuf, aLength)); + Unused << detector->Feed(src, true); + auto encoding = detector->Guess(nullptr, true); + encoding->Name(aCharset); + return NS_OK; +} + +} /* end of extern "C" */ +// END PUBLIC INTERFACE |