author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /kmicromail/libmailwrapper/mailwrapper.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-p1.zip kdepimpi-p1.tar.gz kdepimpi-p1.tar.bz2 |
initial public commit of qt4 portp1
Diffstat (limited to 'kmicromail/libmailwrapper/mailwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/mailwrapper.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/kmicromail/libmailwrapper/mailwrapper.cpp b/kmicromail/libmailwrapper/mailwrapper.cpp index 2ee1ab3..9c299e8 100644 --- a/kmicromail/libmailwrapper/mailwrapper.cpp +++ b/kmicromail/libmailwrapper/mailwrapper.cpp | |||
@@ -1,181 +1,183 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <sys/stat.h> | 2 | #include <sys/stat.h> |
3 | #include <sys/types.h> | 3 | #include <sys/types.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include <fcntl.h> | 5 | #include <fcntl.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <qdir.h> | 7 | #include <qdir.h> |
8 | //Added by qt3to4: | ||
9 | #include <Q3CString> | ||
8 | 10 | ||
9 | #include "mailwrapper.h" | 11 | #include "mailwrapper.h" |
10 | //#include "logindialog.h" | 12 | //#include "logindialog.h" |
11 | //#include "defines.h" | 13 | //#include "defines.h" |
12 | 14 | ||
13 | #define UNDEFINED 64 | 15 | #define UNDEFINED 64 |
14 | #define MAXLINE 76 | 16 | #define MAXLINE 76 |
15 | #define UTF16MASK 0x03FFUL | 17 | #define UTF16MASK 0x03FFUL |
16 | #define UTF16SHIFT 10 | 18 | #define UTF16SHIFT 10 |
17 | #define UTF16BASE 0x10000UL | 19 | #define UTF16BASE 0x10000UL |
18 | #define UTF16HIGHSTART 0xD800UL | 20 | #define UTF16HIGHSTART 0xD800UL |
19 | #define UTF16HIGHEND 0xDBFFUL | 21 | #define UTF16HIGHEND 0xDBFFUL |
20 | #define UTF16LOSTART 0xDC00UL | 22 | #define UTF16LOSTART 0xDC00UL |
21 | #define UTF16LOEND 0xDFFFUL | 23 | #define UTF16LOEND 0xDFFFUL |
22 | 24 | ||
23 | 25 | ||
24 | using namespace Opie::Core; | 26 | using namespace Opie::Core; |
25 | Attachment::Attachment( QString lnk ) | 27 | Attachment::Attachment( QString lnk ) |
26 | { | 28 | { |
27 | doc = lnk; | 29 | doc = lnk; |
28 | size = QFileInfo( doc ).size(); | 30 | size = QFileInfo( doc ).size(); |
29 | mPix = SmallIcon( "files" ); | 31 | mPix = SmallIcon( "files" ); |
30 | } | 32 | } |
31 | 33 | ||
32 | Folder::Folder(const QString&tmp_name, const QString&sep ) | 34 | Folder::Folder(const QString&tmp_name, const QString&sep ) |
33 | { | 35 | { |
34 | name = tmp_name; | 36 | name = tmp_name; |
35 | nameDisplay = name; | 37 | nameDisplay = name; |
36 | separator = sep; | 38 | separator = sep; |
37 | prefix = ""; | 39 | prefix = ""; |
38 | } | 40 | } |
39 | 41 | ||
40 | Folder::~Folder() | 42 | Folder::~Folder() |
41 | { | 43 | { |
42 | } | 44 | } |
43 | 45 | ||
44 | const QString& Folder::Separator()const | 46 | const QString& Folder::Separator()const |
45 | { | 47 | { |
46 | return separator; | 48 | return separator; |
47 | } | 49 | } |
48 | 50 | ||
49 | IMAPFolder::IMAPFolder(const QString&t_name,const QString&sep, bool select,bool no_inf, const QString&aprefix ) | 51 | IMAPFolder::IMAPFolder(const QString&t_name,const QString&sep, bool select,bool no_inf, const QString&aprefix ) |
50 | : Folder( t_name,sep ),m_MaySelect(select),m_NoInferior(no_inf) | 52 | : Folder( t_name,sep ),m_MaySelect(select),m_NoInferior(no_inf) |
51 | { | 53 | { |
52 | // Decode IMAP foldername | 54 | // Decode IMAP foldername |
53 | nameDisplay = IMAPFolder::decodeFolderName( t_name ); | 55 | nameDisplay = IMAPFolder::decodeFolderName( t_name ); |
54 | name = nameDisplay ; | 56 | name = nameDisplay ; |
55 | /* | 57 | /* |
56 | odebug << "folder " + name + " - displayed as " + nameDisplay << oendl; | 58 | odebug << "folder " + name + " - displayed as " + nameDisplay << oendl; |
57 | */ | 59 | */ |
58 | prefix = aprefix; | 60 | prefix = aprefix; |
59 | 61 | ||
60 | if (prefix.length()>0) { | 62 | if (prefix.length()>0) { |
61 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { | 63 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { |
62 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); | 64 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); |
63 | } | 65 | } |
64 | } | 66 | } |
65 | } | 67 | } |
66 | 68 | ||
67 | IMAPFolder::~IMAPFolder() | 69 | IMAPFolder::~IMAPFolder() |
68 | { | 70 | { |
69 | } | 71 | } |
70 | 72 | ||
71 | static unsigned char base64chars[] = | 73 | static unsigned char base64chars[] = |
72 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; | 74 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; |
73 | 75 | ||
74 | /** | 76 | /** |
75 | * Decodes base64 encoded parts of the imapfolder name | 77 | * Decodes base64 encoded parts of the imapfolder name |
76 | * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc | 78 | * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc |
77 | */ | 79 | */ |
78 | QString IMAPFolder::decodeFolderName( const QString &name ) | 80 | QString IMAPFolder::decodeFolderName( const QString &name ) |
79 | { | 81 | { |
80 | unsigned char c, i, bitcount; | 82 | unsigned char c, i, bitcount; |
81 | unsigned long ucs4, utf16, bitbuf; | 83 | unsigned long ucs4, utf16, bitbuf; |
82 | unsigned char base64[256], utf8[6]; | 84 | unsigned char base64[256], utf8[6]; |
83 | unsigned long srcPtr = 0; | 85 | unsigned long srcPtr = 0; |
84 | QCString dst = ""; | 86 | Q3CString dst = ""; |
85 | QCString src = name.ascii(); | 87 | Q3CString src = name.ascii(); |
86 | 88 | ||
87 | /* initialize modified base64 decoding table */ | 89 | /* initialize modified base64 decoding table */ |
88 | memset(base64, UNDEFINED, sizeof(base64)); | 90 | memset(base64, UNDEFINED, sizeof(base64)); |
89 | for (i = 0; i < sizeof(base64chars); ++i) { | 91 | for (i = 0; i < sizeof(base64chars); ++i) { |
90 | base64[(int)base64chars[i]] = i; | 92 | base64[(int)base64chars[i]] = i; |
91 | } | 93 | } |
92 | 94 | ||
93 | /* loop until end of string */ | 95 | /* loop until end of string */ |
94 | while (srcPtr < src.length ()) { | 96 | while (srcPtr < src.length ()) { |
95 | c = src[srcPtr++]; | 97 | c = src.at(srcPtr++); |
96 | /* deal with literal characters and &- */ | 98 | /* deal with literal characters and &- */ |
97 | if (c != '&' || src[srcPtr] == '-') { | 99 | if (c != '&' || src.at(srcPtr) == '-') { |
98 | /* encode literally */ | 100 | /* encode literally */ |
99 | dst += c; | 101 | dst += c; |
100 | /* skip over the '-' if this is an &- sequence */ | 102 | /* skip over the '-' if this is an &- sequence */ |
101 | if (c == '&') | 103 | if (c == '&') |
102 | srcPtr++; | 104 | srcPtr++; |
103 | } else { | 105 | } else { |
104 | /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */ | 106 | /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */ |
105 | bitbuf = 0; | 107 | bitbuf = 0; |
106 | bitcount = 0; | 108 | bitcount = 0; |
107 | ucs4 = 0; | 109 | ucs4 = 0; |
108 | while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) { | 110 | while ((c = base64[(unsigned char) src.at(srcPtr)]) != UNDEFINED) { |
109 | ++srcPtr; | 111 | ++srcPtr; |
110 | bitbuf = (bitbuf << 6) | c; | 112 | bitbuf = (bitbuf << 6) | c; |
111 | bitcount += 6; | 113 | bitcount += 6; |
112 | /* enough bits for a UTF-16 character? */ | 114 | /* enough bits for a UTF-16 character? */ |
113 | if (bitcount >= 16) { | 115 | if (bitcount >= 16) { |
114 | bitcount -= 16; | 116 | bitcount -= 16; |
115 | utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; | 117 | utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; |
116 | /* convert UTF16 to UCS4 */ | 118 | /* convert UTF16 to UCS4 */ |
117 | if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { | 119 | if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { |
118 | ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; | 120 | ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; |
119 | continue; | 121 | continue; |
120 | } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { | 122 | } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { |
121 | ucs4 += utf16 - UTF16LOSTART + UTF16BASE; | 123 | ucs4 += utf16 - UTF16LOSTART + UTF16BASE; |
122 | } else { | 124 | } else { |
123 | ucs4 = utf16; | 125 | ucs4 = utf16; |
124 | } | 126 | } |
125 | /* convert UTF-16 range of UCS4 to UTF-8 */ | 127 | /* convert UTF-16 range of UCS4 to UTF-8 */ |
126 | if (ucs4 <= 0x7fUL) { | 128 | if (ucs4 <= 0x7fUL) { |
127 | utf8[0] = ucs4; | 129 | utf8[0] = ucs4; |
128 | i = 1; | 130 | i = 1; |
129 | } else if (ucs4 <= 0x7ffUL) { | 131 | } else if (ucs4 <= 0x7ffUL) { |
130 | utf8[0] = 0xc0 | (ucs4 >> 6); | 132 | utf8[0] = 0xc0 | (ucs4 >> 6); |
131 | utf8[1] = 0x80 | (ucs4 & 0x3f); | 133 | utf8[1] = 0x80 | (ucs4 & 0x3f); |
132 | i = 2; | 134 | i = 2; |
133 | } else if (ucs4 <= 0xffffUL) { | 135 | } else if (ucs4 <= 0xffffUL) { |
134 | utf8[0] = 0xe0 | (ucs4 >> 12); | 136 | utf8[0] = 0xe0 | (ucs4 >> 12); |
135 | utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f); | 137 | utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f); |
136 | utf8[2] = 0x80 | (ucs4 & 0x3f); | 138 | utf8[2] = 0x80 | (ucs4 & 0x3f); |
137 | i = 3; | 139 | i = 3; |
138 | } else { | 140 | } else { |
139 | utf8[0] = 0xf0 | (ucs4 >> 18); | 141 | utf8[0] = 0xf0 | (ucs4 >> 18); |
140 | utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f); | 142 | utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f); |
141 | utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f); | 143 | utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f); |
142 | utf8[3] = 0x80 | (ucs4 & 0x3f); | 144 | utf8[3] = 0x80 | (ucs4 & 0x3f); |
143 | i = 4; | 145 | i = 4; |
144 | } | 146 | } |
145 | /* copy it */ | 147 | /* copy it */ |
146 | for (c = 0; c < i; ++c) { | 148 | for (c = 0; c < i; ++c) { |
147 | dst += utf8[c]; | 149 | dst += utf8[c]; |
148 | } | 150 | } |
149 | } | 151 | } |
150 | } | 152 | } |
151 | /* skip over trailing '-' in modified UTF-7 encoding */ | 153 | /* skip over trailing '-' in modified UTF-7 encoding */ |
152 | if (src[srcPtr] == '-') | 154 | if (src.at(srcPtr) == '-') |
153 | ++srcPtr; | 155 | ++srcPtr; |
154 | } | 156 | } |
155 | } | 157 | } |
156 | 158 | ||
157 | return QString::fromUtf8( dst.data() ); | 159 | return QString::fromUtf8( dst.data() ); |
158 | } | 160 | } |
159 | 161 | ||
160 | Mail::Mail() | 162 | Mail::Mail() |
161 | :Opie::Core::ORefCount(),name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") | 163 | :Opie::Core::ORefCount(),name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") |
162 | { | 164 | { |
163 | } | 165 | } |
164 | 166 | ||
165 | MHFolder::MHFolder(const QString&disp_name,const QString&mbox) | 167 | MHFolder::MHFolder(const QString&disp_name,const QString&mbox) |
166 | : Folder( disp_name,"/" ) | 168 | : Folder( disp_name,"/" ) |
167 | { | 169 | { |
168 | separator = "/"; | 170 | separator = "/"; |
169 | name = mbox; | 171 | name = mbox; |
170 | if (!disp_name.startsWith("/") && disp_name.length()>0) | 172 | if (!disp_name.startsWith("/") && disp_name.length()>0) |
171 | name+="/"; | 173 | name+="/"; |
172 | name+=disp_name; | 174 | name+=disp_name; |
173 | if (disp_name.length()==0) { | 175 | if (disp_name.length()==0) { |
174 | nameDisplay = separator; | 176 | nameDisplay = separator; |
175 | } | 177 | } |
176 | prefix = mbox; | 178 | prefix = mbox; |
177 | } | 179 | } |
178 | 180 | ||
179 | MHFolder::~MHFolder() | 181 | MHFolder::~MHFolder() |
180 | { | 182 | { |
181 | } | 183 | } |