File indexing completed on 2023-09-24 09:25:00
0001 /* -*- c++ -*- 0002 kmime_codecs.h 0003 0004 KMime, the KDE Internet mail/usenet news message library. 0005 SPDX-FileCopyrightText: 2001 the KMime authors. 0006 See file AUTHORS for details 0007 0008 SPDX-License-Identifier: LGPL-2.0-or-later 0009 */ 0010 #pragma once 0011 0012 #include <QByteArray> 0013 #include <QString> 0014 0015 namespace KMime 0016 { 0017 0018 /** 0019 Encodes string @p src according to RFC2047 using charset @p charset. 0020 0021 This function also makes commas, quotes and other characters part of the encoded name, for example 0022 the string "Jöhn Döe" <john@example.com"> would be encoded as <encoded word for "Jöhn Döe"> <john@example.com>, 0023 i.e. the opening and closing quote mark would be part of the encoded word. 0024 Therefore don't use this function for input strings that contain semantically meaningful characters, 0025 like the quoting marks in this example. 0026 0027 @param src source string. 0028 @param charset charset to use. If it can't encode the string, UTF-8 will be used instead. 0029 @param addressHeader if this flag is true, all special chars 0030 like <,>,[,],... will be encoded, too. 0031 @param allow8bitHeaders if this flag is true, 8Bit headers are allowed. 0032 0033 @return the encoded string. 0034 */ 0035 Q_REQUIRED_RESULT QByteArray encodeRFC2047String(const QString &src, const QByteArray &charset, bool addressHeader = false, bool allow8bitHeaders = false); 0036 0037 /** 0038 * Same as encodeRFC2047String(), but with a crucial difference: Instead of encoding the complete 0039 * string as a single encoded word, the string will be split up at control characters, and only parts of 0040 * the sentence that really need to be encoded will be encoded. 0041 */ 0042 Q_REQUIRED_RESULT QByteArray encodeRFC2047Sentence(const QString &src, const QByteArray &charset); 0043 0044 /** 0045 Decodes string @p src according to RFC2231 0046 0047 @param src source string. 0048 @param usedCs the detected charset is returned here 0049 @param defaultCS the charset to use in case the detected 0050 one isn't known to us. 0051 @param forceCS force the use of the default charset. 0052 0053 @return the decoded string. 0054 */ 0055 Q_REQUIRED_RESULT QString decodeRFC2231String(const QByteArray &src, QByteArray &usedCS, const QByteArray &defaultCS = QByteArray(), bool forceCS = false); 0056 0057 /** 0058 Encodes string @p src according to RFC2231 using charset @p charset. 0059 0060 @param src source string. 0061 @param charset charset to use. 0062 @return the encoded string. 0063 */ 0064 Q_REQUIRED_RESULT QByteArray encodeRFC2231String(const QString &src, const QByteArray &charset); 0065 0066 } // namespace KMime 0067