KIMAP2
Go to the documentation of this file.
36 #include <sys/types.h>
41 #include <QtCore/QTextCodec>
42 #include <QtCore/QBuffer>
43 #include <QtCore/QByteArray>
44 #include <QtCore/QLatin1Char>
47 using namespace KIMAP2;
53 static const unsigned char base64chars[] =
54 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
57 static const char especials[17] =
"()<>@,;:\"/[]?.= ";
60 #define UTF16MASK 0x03FFUL
62 #define UTF16BASE 0x10000UL
63 #define UTF16HIGHSTART 0xD800UL
64 #define UTF16HIGHEND 0xDBFFUL
65 #define UTF16LOSTART 0xDC00UL
66 #define UTF16LOEND 0xDFFFUL
72 unsigned char c, i, bitcount;
73 unsigned long ucs4, utf16, bitbuf;
74 unsigned char base64[256], utf8[6];
75 unsigned int srcPtr = 0;
78 uint srcLen = inSrc.
length();
81 memset(base64, UNDEFINED,
sizeof(base64));
82 for (i = 0; i <
sizeof(base64chars); ++i) {
83 base64[(int)base64chars[i]] = i;
87 while (srcPtr < srcLen) {
90 if (c !=
'&' || src[srcPtr] ==
'-') {
102 while ((c = base64[(
unsigned char)src[srcPtr]]) != UNDEFINED) {
104 bitbuf = (bitbuf << 6) | c;
107 if (bitcount >= 16) {
109 utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff;
111 if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) {
112 ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT;
114 }
else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) {
115 ucs4 += utf16 - UTF16LOSTART + UTF16BASE;
120 if (ucs4 <= 0x7fUL) {
123 }
else if (ucs4 <= 0x7ffUL) {
124 utf8[0] = 0xc0 | (ucs4 >> 6);
125 utf8[1] = 0x80 | (ucs4 & 0x3f);
127 }
else if (ucs4 <= 0xffffUL) {
128 utf8[0] = 0xe0 | (ucs4 >> 12);
129 utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f);
130 utf8[2] = 0x80 | (ucs4 & 0x3f);
133 utf8[0] = 0xf0 | (ucs4 >> 18);
134 utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f);
135 utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f);
136 utf8[3] = 0x80 | (ucs4 & 0x3f);
140 for (c = 0; c < i; ++c) {
146 if (src[srcPtr] ==
'-') {
166 for (
unsigned int i = 0; i < len; i++) {
167 if (src[i] ==
'"' || src[i] ==
'\\') {
181 for (
unsigned int i = 0; i < len; i++) {
199 unsigned int utf8pos, utf8total, c, utf7mode, bitstogo, utf16flag;
200 unsigned int ucs4, bitbuf;
211 while (srcPtr < src.
length()) {
212 c = (
unsigned char)src[srcPtr++];
214 if (c >=
' ' && c <=
'~') {
218 dst += base64chars[(bitbuf << (6 - bitstogo)) & 0x3F];
240 }
else if (utf8total) {
242 ucs4 = (ucs4 << 6) | (c & 0x3FUL);
243 if (++utf8pos < utf8total) {
251 }
else if (c < 0xF0) {
264 if (ucs4 >= UTF16BASE) {
267 (bitbuf << 16) | ((ucs4 >> UTF16SHIFT) + UTF16HIGHSTART);
268 ucs4 = (ucs4 & UTF16MASK) + UTF16LOSTART;
271 bitbuf = (bitbuf << 16) | ucs4;
276 while (bitstogo >= 6) {
279 base64chars[(bitstogo ? (bitbuf >> bitstogo) : bitbuf) & 0x3F];
286 dst += base64chars[(bitbuf << (6 - bitstogo)) & 0x3F];
300 replace(QStringLiteral(
"windows"), QStringLiteral(
"cp")).toLatin1());
326 if (!str.
contains(QStringLiteral(
"=?"))) {
333 char *pos, *beg, *end, *mid = Q_NULLPTR;
335 char encoding = 0, ch;
337 const int maxLen = 200;
341 for (pos = aStr.
data(); *pos; pos++) {
342 if (pos[0] !=
'=' || pos[1] !=
'?') {
350 for (i = 2, pos += 2;
352 (*pos !=
'?' && (ispunct(*pos) || isalnum(*pos)));
356 if (*pos !=
'?' || i < 4 || i >= maxLen) {
363 language = charset.
right(charset.
length() - pt - 1);
369 encoding = toupper(pos[1]);
371 (encoding !=
'Q' && encoding !=
'B' &&
372 encoding !=
'q' && encoding !=
'b')) {
382 while (i < maxLen && *pos && !(*pos ==
'?' && *(pos + 1) ==
'=')) {
387 if (i >= maxLen || !*pos) {
395 if (encoding ==
'Q') {
397 for (i = cstr.
length() - 1; i >= 0; --i) {
398 if (cstr[i] ==
'_') {
413 for (i = 0; i < len; ++i) {
450 const signed char *latin =
451 reinterpret_cast<const signed char *
>
457 int resultLen = 3 * str.
length() / 2;
476 for (i = 0; i < 16; ++i) {
477 if (*l == especials[i]) {
485 if (l -
start + 2 * numQuotes >= 58 || *l == 60) {
501 if (resultLen - rptr - 1 <=
start - latin + 1 + 16) {
503 resultLen += (
start - latin + 1) * 2 + 20;
506 while (latin <
start) {
507 result[rptr++] = *latin;
510 result.
replace(rptr, 15,
"=?iso-8859-1?q?");
512 if (resultLen - rptr - 1 <= 3 * (
stop - latin + 1)) {
513 resultLen += (
stop - latin + 1) * 4 + 20;
516 while (latin <
stop) {
519 for (i = 0; i < 16; ++i) {
520 if (*latin == especials[i]) {
528 result[rptr++] =
'=';
529 hexcode = ((*latin & 0xF0) >> 4) + 48;
533 result[rptr++] = hexcode;
534 hexcode = (*latin & 0x0F) + 48;
538 result[rptr++] = hexcode;
540 result[rptr++] = *latin;
544 result[rptr++] =
'?';
545 result[rptr++] =
'=';
548 if (rptr == resultLen - 1) {
552 result[rptr++] = *latin;
568 signed char *latin = (
signed char *)calloc(1, str.
length() + 1);
569 char *latin_us = (
char *)latin;
571 signed char *l = latin;
589 for (i = 0; i < 16; ++i) {
590 if (*l == especials[i]) {
596 hexcode = ((*l & 0xF0) >> 4) + 48;
601 hexcode = (*l & 0x0F) + 48;
641 while (p < (
int) st.
length()) {
642 if (st.
at(p) == 37) {
651 st.
replace(p, 1, ch * 16 + ch2);
KIMAP2_EXPORT QTextCodec * codecForName(const QString &name)
Fetches a Codec by name.
void truncate(int position)
KIMAP2_EXPORT QString encodeImapFolderName(const QString &src)
Converts an Unicode IMAP mailbox to a QString which can be used in IMAP communication.
const KIMAP2_EXPORT QString decodeRFC2231String(const QString &str)
Decodes a RFC2231 string str.
QString fromUtf8(const char *str, int size)
void stop(Ekos::AlignState mode)
KIMAP_EXPORT QByteArray quoteIMAP(const QByteArray &src)
Replaces " with \" and \ with \ " and \ characters.
Q_SCRIPTABLE Q_NOREPLY void start()
QByteArray toLatin1() const const
const KIMAP2_EXPORT QByteArray encodeRFC2047String(const QByteArray &str)
Encodes a RFC2047 string str.
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
KIMAP2_EXPORT QString decodeImapFolderName(const QString &inSrc)
Converts an UTF-7 encoded IMAP mailbox to a Unicode QString.
bool isEmpty() const const
const KIMAP2_EXPORT QString decodeRFC2047String(const QString &str)
Decodes a RFC2047 string str.
QByteArray toUtf8() const const
QTextCodec * codecForName(const QByteArray &name)
QByteArray fromBase64(const QByteArray &base64, QByteArray::Base64Options options)
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
QByteArray & replace(int pos, int len, const char *after)
QString & replace(int position, int n, QChar after)
QString & remove(int position, int n)
QString toLower() const const
QByteArray left(int len) const const
bool isEmpty() const const
const char * constData() const const
QString right(int n) const const
KIMAP_EXPORT QTextCodec * codecForName(const QString &name)
Fetches a Codec by name.
const QChar at(int position) const const
KIMAP_EXPORT QByteArray decodeImapFolderName(const QByteArray &inSrc)
Converts an UTF-7 encoded IMAP mailbox to a QByteArray.
const KIMAP_EXPORT QString decodeRFC2047String(const QString &str)
Decodes a RFC2047 string str.
const KIMAP_EXPORT QByteArray encodeRFC2047String(const QByteArray &str)
Encodes a RFC2047 string str.
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
KIMAP2_EXPORT QByteArray quoteIMAP(const QByteArray &src)
Replaces " with \" and \ with \ " and \ characters.
QString toUnicode(const QByteArray &a) const const
KCODECS_EXPORT QByteArray quotedPrintableDecode(const QByteArray &in)
char toLatin1() const const
Provides handlers for various RFC/MIME encodings.
QString mid(int position, int n) const const
const KIMAP2_EXPORT QString encodeRFC2231String(const QString &str)
Encodes a RFC2231 string str.
KIMAP_EXPORT QByteArray encodeImapFolderName(const QByteArray &src)
Converts an Unicode IMAP mailbox to a QByteArray which can be used in IMAP communication.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 6 2023 04:10:17 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.