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