-rw-r--r-- | noncore/unsupported/mail2/libmail/miscfunctions.cpp | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/noncore/unsupported/mail2/libmail/miscfunctions.cpp b/noncore/unsupported/mail2/libmail/miscfunctions.cpp index 0edbfa8..c81b101 100644 --- a/noncore/unsupported/mail2/libmail/miscfunctions.cpp +++ b/noncore/unsupported/mail2/libmail/miscfunctions.cpp | |||
@@ -1,137 +1,136 @@ | |||
1 | #include <qdatetime.h> | 1 | #include <qdatetime.h> |
2 | 2 | ||
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include <time.h> | 5 | #include <time.h> |
6 | 6 | ||
7 | #include <openssl/md5.h> | ||
8 | |||
9 | #include "miscfunctions.h" | 7 | #include "miscfunctions.h" |
8 | #include "md5.h" | ||
10 | 9 | ||
11 | QString MiscFunctions::encodeQPrintable(const QString &src) | 10 | QString MiscFunctions::encodeQPrintable(const QString &src) |
12 | { | 11 | { |
13 | // TODO: implent encodeQPrintable | 12 | // TODO: implent encodeQPrintable |
14 | return src; | 13 | return src; |
15 | } | 14 | } |
16 | 15 | ||
17 | QString MiscFunctions::decodeQPrintable(const QString &src) | 16 | QString MiscFunctions::decodeQPrintable(const QString &src) |
18 | { | 17 | { |
19 | QString out; | 18 | QString out; |
20 | 19 | ||
21 | for (unsigned int i = 0; i <= src.length(); i++) { | 20 | for (unsigned int i = 0; i <= src.length(); i++) { |
22 | if (src[i] == '=') { | 21 | if (src[i] == '=') { |
23 | if (src[i+1] == "\n") { | 22 | if (src[i+1] == "\n") { |
24 | i += 1; | 23 | i += 1; |
25 | } else { | 24 | } else { |
26 | QString temp = QString("%1%2").arg(src[i+1]).arg(src[i+2]); | 25 | QString temp = QString("%1%2").arg(src[i+1]).arg(src[i+2]); |
27 | int number = temp.toInt(0, 16); | 26 | int number = temp.toInt(0, 16); |
28 | 27 | ||
29 | out += QChar(number); | 28 | out += QChar(number); |
30 | i += 2; | 29 | i += 2; |
31 | } | 30 | } |
32 | } else { | 31 | } else { |
33 | out += src[i]; | 32 | out += src[i]; |
34 | } | 33 | } |
35 | } | 34 | } |
36 | return out; | 35 | return out; |
37 | } | 36 | } |
38 | 37 | ||
39 | QString MiscFunctions::encodeBase64(const QString &src) | 38 | QString MiscFunctions::encodeBase64(const QString &src) |
40 | { | 39 | { |
41 | char *dataPtr = (char *) src.latin1(); | 40 | char *dataPtr = (char *) src.latin1(); |
42 | int len = src.length(); | 41 | int len = src.length(); |
43 | int count = 0; | 42 | int count = 0; |
44 | QString temp = ""; | 43 | QString temp = ""; |
45 | 44 | ||
46 | while (len > 0) { | 45 | while (len > 0) { |
47 | if (len < 3) { | 46 | if (len < 3) { |
48 | encodeBase64Base(dataPtr, &temp, len); | 47 | encodeBase64Base(dataPtr, &temp, len); |
49 | len = 0; | 48 | len = 0; |
50 | } else { | 49 | } else { |
51 | encodeBase64Base(dataPtr, &temp, 3); | 50 | encodeBase64Base(dataPtr, &temp, 3); |
52 | len -= 3; | 51 | len -= 3; |
53 | dataPtr += 3; | 52 | dataPtr += 3; |
54 | count += 4; | 53 | count += 4; |
55 | } | 54 | } |
56 | if (count > 72) { | 55 | if (count > 72) { |
57 | count = 0; | 56 | count = 0; |
58 | temp += "\n"; | 57 | temp += "\n"; |
59 | } | 58 | } |
60 | } | 59 | } |
61 | 60 | ||
62 | return temp; | 61 | return temp; |
63 | } | 62 | } |
64 | 63 | ||
65 | void MiscFunctions::encodeBase64Base(char *src, QString *dest, int len) | 64 | void MiscFunctions::encodeBase64Base(char *src, QString *dest, int len) |
66 | { | 65 | { |
67 | QString temp; | 66 | QString temp; |
68 | uchar c; | 67 | uchar c; |
69 | uchar bufOut[4]; | 68 | uchar bufOut[4]; |
70 | 69 | ||
71 | bufOut[0] = src[0]; | 70 | bufOut[0] = src[0]; |
72 | bufOut[0] >>= 2; | 71 | bufOut[0] >>= 2; |
73 | 72 | ||
74 | bufOut[1] = src[0]; | 73 | bufOut[1] = src[0]; |
75 | bufOut[1] = bufOut[1] & (1 + 2); | 74 | bufOut[1] = bufOut[1] & (1 + 2); |
76 | bufOut[1] <<= 4; | 75 | bufOut[1] <<= 4; |
77 | if (len > 1) c = src[1]; | 76 | if (len > 1) c = src[1]; |
78 | else c = 0; | 77 | else c = 0; |
79 | 78 | ||
80 | c = c & (16 + 32 + 64 + 128); | 79 | c = c & (16 + 32 + 64 + 128); |
81 | c >>= 4; | 80 | c >>= 4; |
82 | bufOut[1] = bufOut[1] | c; | 81 | bufOut[1] = bufOut[1] | c; |
83 | 82 | ||
84 | bufOut[2] = src[1]; | 83 | bufOut[2] = src[1]; |
85 | bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8); | 84 | bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8); |
86 | bufOut[2] <<= 2; | 85 | bufOut[2] <<= 2; |
87 | if (len > 2) c = src[2]; | 86 | if (len > 2) c = src[2]; |
88 | else c = 0; | 87 | else c = 0; |
89 | 88 | ||
90 | c >>= 6; | 89 | c >>= 6; |
91 | bufOut[2] = bufOut[2] | c; | 90 | bufOut[2] = bufOut[2] | c; |
92 | 91 | ||
93 | bufOut[3] = src[2]; | 92 | bufOut[3] = src[2]; |
94 | bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32); | 93 | bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32); |
95 | 94 | ||
96 | if (len == 1) { | 95 | if (len == 1) { |
97 | bufOut[2] = 64; | 96 | bufOut[2] = 64; |
98 | bufOut[3] = 64; | 97 | bufOut[3] = 64; |
99 | } | 98 | } |
100 | if (len == 2) { | 99 | if (len == 2) { |
101 | bufOut[3] = 64; | 100 | bufOut[3] = 64; |
102 | } | 101 | } |
103 | for (int x = 0; x < 4; x++) { | 102 | for (int x = 0; x < 4; x++) { |
104 | if (bufOut[x] <= 25) | 103 | if (bufOut[x] <= 25) |
105 | bufOut[x] += (uint) 'A'; | 104 | bufOut[x] += (uint) 'A'; |
106 | else if (bufOut[x] >= 26 && bufOut[x] <= 51) | 105 | else if (bufOut[x] >= 26 && bufOut[x] <= 51) |
107 | bufOut[x] += (uint) 'a' - 26; | 106 | bufOut[x] += (uint) 'a' - 26; |
108 | else if (bufOut[x] >= 52 && bufOut[x] <= 61) | 107 | else if (bufOut[x] >= 52 && bufOut[x] <= 61) |
109 | bufOut[x] += (uint) '0' - 52; | 108 | bufOut[x] += (uint) '0' - 52; |
110 | else if (bufOut[x] == 62) | 109 | else if (bufOut[x] == 62) |
111 | bufOut[x] = '+'; | 110 | bufOut[x] = '+'; |
112 | else if (bufOut[x] == 63) | 111 | else if (bufOut[x] == 63) |
113 | bufOut[x] = '/'; | 112 | bufOut[x] = '/'; |
114 | else if (bufOut[x] == 64) | 113 | else if (bufOut[x] == 64) |
115 | bufOut[x] = '='; | 114 | bufOut[x] = '='; |
116 | 115 | ||
117 | dest->append(bufOut[x]); | 116 | dest->append(bufOut[x]); |
118 | } | 117 | } |
119 | } | 118 | } |
120 | 119 | ||
121 | QString MiscFunctions::decodeBase64(const QString &src) | 120 | QString MiscFunctions::decodeBase64(const QString &src) |
122 | { | 121 | { |
123 | char plain[4]; | 122 | char plain[4]; |
124 | char *destPtr; | 123 | char *destPtr; |
125 | QByteArray buffer; | 124 | QByteArray buffer; |
126 | uint bufCount = 0, pos = 0, decodedCount, x; | 125 | uint bufCount = 0, pos = 0, decodedCount, x; |
127 | 126 | ||
128 | buffer.resize(src.length() * 3 / 4); | 127 | buffer.resize(src.length() * 3 / 4); |
129 | destPtr = buffer.data(); | 128 | destPtr = buffer.data(); |
130 | 129 | ||
131 | while (pos < src.length()) { | 130 | while (pos < src.length()) { |
132 | decodedCount = 4; | 131 | decodedCount = 4; |
133 | x = 0; | 132 | x = 0; |
134 | while ((x < 4) && (pos < src.length())) { | 133 | while ((x < 4) && (pos < src.length())) { |
135 | plain[x] = src[pos].latin1(); | 134 | plain[x] = src[pos].latin1(); |
136 | pos++; | 135 | pos++; |
137 | if (plain[x] == '\r' || plain[x] == '\n' || plain[x] == ' ') | 136 | if (plain[x] == '\r' || plain[x] == '\n' || plain[x] == ' ') |