File indexing completed on 2024-05-26 05:28:38

0001 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
0002 
0003    This file is part of the Trojita Qt IMAP e-mail client,
0004    http://trojita.flaska.net/
0005 
0006    This program is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU General Public License as
0008    published by the Free Software Foundation; either version 2 of
0009    the License or (at your option) version 3 or any later version
0010    accepted by the membership of KDE e.V. (or its successor approved
0011    by the membership of KDE e.V.), which shall act as a proxy
0012    defined in Section 14 of version 3 of the license.
0013 
0014    This program is distributed in the hope that it will be useful,
0015    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017    GNU General Public License for more details.
0018 
0019    You should have received a copy of the GNU General Public License
0020    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 #ifndef IMAP_ENCODERS_H
0023 #define IMAP_ENCODERS_H
0024 
0025 #include <QMap>
0026 #include <QString>
0027 
0028 namespace Imap {
0029 
0030 typedef enum {
0031     DoubleQuoted,
0032     SquareBrackets,
0033     Parentheses
0034 } QuotedStringStyle;
0035 
0036 typedef enum {
0037     RFC2047_STRING_ASCII,
0038     RFC2047_STRING_LATIN,
0039     RFC2047_STRING_UTF8
0040 } Rfc2047StringCharacterSetType;
0041 
0042 /** @short Production type as per RFC 2047 chapter 5
0043 
0044 These differ in the set of characters that are allowed to be sent unescaped.
0045 */
0046 enum class Rfc2047ProductionType {
0047     /** @short "An 'encoded-word' may replace a 'text' token..." -- case (1) */
0048     Text,
0049     /** @short "As a replacement for a 'word' entity within a 'phrase'" -- case (3) */
0050     Phrase,
0051 };
0052 
0053 QString decodeByteArray(const QByteArray &encoded, const QByteArray &charset);
0054 
0055 QByteArray quotedString(const QByteArray &unquoted, QuotedStringStyle style = DoubleQuoted);
0056 QByteArray encodeRFC2047Phrase(const QString &text);
0057 
0058 QByteArray encodeRFC2047StringWithAsciiPrefix(const QString &text);
0059 QString decodeRFC2047String(const QByteArray &raw);
0060 
0061 QByteArray encodeImapFolderName(const QString &text);
0062 
0063 QString decodeImapFolderName(const QByteArray &raw);
0064 
0065 QByteArray quotedPrintableDecode(const QByteArray &raw);
0066 QByteArray quotedPrintableEncode(const QByteArray &raw);
0067 
0068 QString extractRfc2231Param(const QMap<QByteArray, QByteArray> &parameters, const QByteArray &key);
0069 QByteArray encodeRfc2231Parameter(const QByteArray &key, const QString &value);
0070 
0071 QString wrapFormatFlowed(const QString &input);
0072 
0073 void decodeContentTransferEncoding(const QByteArray &rawData, const QByteArray &encoding, QByteArray *outputData);
0074 }
0075 
0076 #endif // IMAP_ENCODERS_H