author | conber <conber> | 2002-06-15 10:25:10 (UTC) |
---|---|---|
committer | conber <conber> | 2002-06-15 10:25:10 (UTC) |
commit | 95af3cd6c1a68ddd9200d4f7e25baf5c560f071c (patch) (unidiff) | |
tree | c24008f1524e137b42d8762e2b73f353e17c9824 | |
parent | 46a46dde707b08e1422757df00b1fb1941e49d4f (diff) | |
download | opie-95af3cd6c1a68ddd9200d4f7e25baf5c560f071c.zip opie-95af3cd6c1a68ddd9200d4f7e25baf5c560f071c.tar.gz opie-95af3cd6c1a68ddd9200d4f7e25baf5c560f071c.tar.bz2 |
changed include error
-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,201 +1,200 @@ | |||
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] == ' ') |
138 | x--; | 137 | x--; |
139 | x++; | 138 | x++; |
140 | } | 139 | } |
141 | if (x > 1) { | 140 | if (x > 1) { |
142 | decodedCount = decodeBase64Base(plain, destPtr); | 141 | decodedCount = decodeBase64Base(plain, destPtr); |
143 | destPtr += decodedCount; | 142 | destPtr += decodedCount; |
144 | bufCount += decodedCount; | 143 | bufCount += decodedCount; |
145 | } | 144 | } |
146 | } | 145 | } |
147 | 146 | ||
148 | buffer.resize(bufCount); | 147 | buffer.resize(bufCount); |
149 | return QString(buffer); | 148 | return QString(buffer); |
150 | } | 149 | } |
151 | 150 | ||
152 | int MiscFunctions::decodeBase64Base(char *src, char *bufOut) | 151 | int MiscFunctions::decodeBase64Base(char *src, char *bufOut) |
153 | { | 152 | { |
154 | char c, z; | 153 | char c, z; |
155 | char li[4]; | 154 | char li[4]; |
156 | int processed; | 155 | int processed; |
157 | 156 | ||
158 | for (int x = 0; x < 4; x++) { | 157 | for (int x = 0; x < 4; x++) { |
159 | c = src[x]; | 158 | c = src[x]; |
160 | 159 | ||
161 | if ( (int) c >= 'A' && (int) c <= 'Z') | 160 | if ( (int) c >= 'A' && (int) c <= 'Z') |
162 | li[x] = (int) c - (int) 'A'; | 161 | li[x] = (int) c - (int) 'A'; |
163 | if ( (int) c >= 'a' && (int) c <= 'z') | 162 | if ( (int) c >= 'a' && (int) c <= 'z') |
164 | li[x] = (int) c - (int) 'a' + 26; | 163 | li[x] = (int) c - (int) 'a' + 26; |
165 | if ( (int) c >= '0' && (int) c <= '9') | 164 | if ( (int) c >= '0' && (int) c <= '9') |
166 | li[x] = (int) c - (int) '0' + 52; | 165 | li[x] = (int) c - (int) '0' + 52; |
167 | if (c == '+') | 166 | if (c == '+') |
168 | li[x] = 62; | 167 | li[x] = 62; |
169 | if (c == '/') | 168 | if (c == '/') |
170 | li[x] = 63; | 169 | li[x] = 63; |
171 | } | 170 | } |
172 | 171 | ||
173 | processed = 1; | 172 | processed = 1; |
174 | bufOut[0] = (char) li[0] & (32+16+8+4+2+1); | 173 | bufOut[0] = (char) li[0] & (32+16+8+4+2+1); |
175 | bufOut[0] <<= 2; | 174 | bufOut[0] <<= 2; |
176 | z = li[1] >> 4; | 175 | z = li[1] >> 4; |
177 | bufOut[0] = bufOut[0] | z; | 176 | bufOut[0] = bufOut[0] | z; |
178 | 177 | ||
179 | if (src[2] != '=') { | 178 | if (src[2] != '=') { |
180 | bufOut[1] = (char) li[1] & (8+4+2+1); | 179 | bufOut[1] = (char) li[1] & (8+4+2+1); |
181 | bufOut[1] <<= 4; | 180 | bufOut[1] <<= 4; |
182 | z = li[2] >> 2; | 181 | z = li[2] >> 2; |
183 | bufOut[1] = bufOut[1] | z; | 182 | bufOut[1] = bufOut[1] | z; |
184 | processed++; | 183 | processed++; |
185 | 184 | ||
186 | if (src[3] != '=') { | 185 | if (src[3] != '=') { |
187 | bufOut[2] = (char) li[2] & (2+1); | 186 | bufOut[2] = (char) li[2] & (2+1); |
188 | bufOut[2] <<= 6; | 187 | bufOut[2] <<= 6; |
189 | z = li[3]; | 188 | z = li[3]; |
190 | bufOut[2] = bufOut[2] | z; | 189 | bufOut[2] = bufOut[2] | z; |
191 | processed++; | 190 | processed++; |
192 | } | 191 | } |
193 | } | 192 | } |
194 | return processed; | 193 | return processed; |
195 | } | 194 | } |
196 | 195 | ||
197 | QString MiscFunctions::uniqueString() | 196 | QString MiscFunctions::uniqueString() |
198 | { | 197 | { |
199 | QString uniqueString = QDate::currentDate().toString(); | 198 | QString uniqueString = QDate::currentDate().toString(); |
200 | uniqueString += QTime::currentTime().toString(); | 199 | uniqueString += QTime::currentTime().toString(); |
201 | uniqueString += QString("%1").arg(rand()); | 200 | uniqueString += QString("%1").arg(rand()); |