author | zautrix <zautrix> | 2004-10-16 10:18:46 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-16 10:18:46 (UTC) |
commit | 023b3c542a6dd4d1c4b53dba6bb2c68f605a7917 (patch) (unidiff) | |
tree | 96929f98d9de314dc48f0a89efa5d93a78644a3d | |
parent | 2897677d61fd8d33355611b5b951e2bee1136b9c (diff) | |
download | kdepimpi-023b3c542a6dd4d1c4b53dba6bb2c68f605a7917.zip kdepimpi-023b3c542a6dd4d1c4b53dba6bb2c68f605a7917.tar.gz kdepimpi-023b3c542a6dd4d1c4b53dba6bb2c68f605a7917.tar.bz2 |
umlaut fix for ompi
-rw-r--r-- | kmicromail/libmailwrapper/abstractmail.cpp | 12 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/genericwrapper.cpp | 4 |
2 files changed, 7 insertions, 9 deletions
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp index 673f288..2d7533c 100644 --- a/kmicromail/libmailwrapper/abstractmail.cpp +++ b/kmicromail/libmailwrapper/abstractmail.cpp | |||
@@ -1,280 +1,278 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #include "abstractmail.h" | 2 | #include "abstractmail.h" |
3 | #include "imapwrapper.h" | 3 | #include "imapwrapper.h" |
4 | #include "pop3wrapper.h" | 4 | #include "pop3wrapper.h" |
5 | #include "nntpwrapper.h" | 5 | #include "nntpwrapper.h" |
6 | #include "mhwrapper.h" | 6 | #include "mhwrapper.h" |
7 | #include "mailtypes.h" | 7 | #include "mailtypes.h" |
8 | #include <qpe/global.h> | 8 | #include <qpe/global.h> |
9 | 9 | ||
10 | 10 | ||
11 | #include <qprogressbar.h> | 11 | #include <qprogressbar.h> |
12 | #include <qapplication.h> | 12 | #include <qapplication.h> |
13 | #include <qmessagebox.h> | 13 | #include <qmessagebox.h> |
14 | 14 | ||
15 | #include <kdecore/kstandarddirs.h> | 15 | #include <kdecore/kstandarddirs.h> |
16 | #include <qfile.h> | 16 | #include <qfile.h> |
17 | #include <qtextstream.h> | 17 | #include <qtextstream.h> |
18 | #include <stdlib.h> | 18 | #include <stdlib.h> |
19 | #include <libetpan/mailmime_content.h> | 19 | #include <libetpan/mailmime_content.h> |
20 | #include <libetpan/mailmime.h> | 20 | #include <libetpan/mailmime.h> |
21 | 21 | ||
22 | using namespace Opie::Core; | 22 | using namespace Opie::Core; |
23 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) | 23 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) |
24 | { | 24 | { |
25 | return new IMAPwrapper(a); | 25 | return new IMAPwrapper(a); |
26 | } | 26 | } |
27 | 27 | ||
28 | AbstractMail* AbstractMail::getWrapper(POP3account *a) | 28 | AbstractMail* AbstractMail::getWrapper(POP3account *a) |
29 | { | 29 | { |
30 | return new POP3wrapper(a); | 30 | return new POP3wrapper(a); |
31 | } | 31 | } |
32 | 32 | ||
33 | AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) | 33 | AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) |
34 | { | 34 | { |
35 | return new NNTPwrapper(a); | 35 | return new NNTPwrapper(a); |
36 | } | 36 | } |
37 | 37 | ||
38 | AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) | 38 | AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) |
39 | { | 39 | { |
40 | return new MHwrapper(a,name); | 40 | return new MHwrapper(a,name); |
41 | } | 41 | } |
42 | 42 | ||
43 | AbstractMail* AbstractMail::getWrapper(Account*a) | 43 | AbstractMail* AbstractMail::getWrapper(Account*a) |
44 | { | 44 | { |
45 | if (!a) return 0; | 45 | if (!a) return 0; |
46 | switch (a->getType()) { | 46 | switch (a->getType()) { |
47 | case MAILLIB::A_IMAP: | 47 | case MAILLIB::A_IMAP: |
48 | return new IMAPwrapper((IMAPaccount*)a); | 48 | return new IMAPwrapper((IMAPaccount*)a); |
49 | break; | 49 | break; |
50 | case MAILLIB::A_POP3: | 50 | case MAILLIB::A_POP3: |
51 | return new POP3wrapper((POP3account*)a); | 51 | return new POP3wrapper((POP3account*)a); |
52 | break; | 52 | break; |
53 | case MAILLIB::A_NNTP: | 53 | case MAILLIB::A_NNTP: |
54 | return new NNTPwrapper((NNTPaccount*)a); | 54 | return new NNTPwrapper((NNTPaccount*)a); |
55 | break; | 55 | break; |
56 | default: | 56 | default: |
57 | return 0; | 57 | return 0; |
58 | } | 58 | } |
59 | } | 59 | } |
60 | 60 | ||
61 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) | 61 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) |
62 | { | 62 | { |
63 | // odebug << "Decode string start" << oendl; | 63 | // odebug << "Decode string start" << oendl; |
64 | char*result_text; | 64 | char*result_text; |
65 | size_t index = 0; | 65 | size_t index = 0; |
66 | /* reset for recursive use! */ | 66 | /* reset for recursive use! */ |
67 | size_t target_length = 0; | 67 | size_t target_length = 0; |
68 | result_text = 0; | 68 | result_text = 0; |
69 | int mimetype = MAILMIME_MECHANISM_7BIT; | 69 | int mimetype = MAILMIME_MECHANISM_7BIT; |
70 | if (enc.lower()=="quoted-printable") { | 70 | if (enc.lower()=="quoted-printable") { |
71 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 71 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
72 | } else if (enc.lower()=="base64") { | 72 | } else if (enc.lower()=="base64") { |
73 | mimetype = MAILMIME_MECHANISM_BASE64; | 73 | mimetype = MAILMIME_MECHANISM_BASE64; |
74 | } else if (enc.lower()=="8bit") { | 74 | } else if (enc.lower()=="8bit") { |
75 | mimetype = MAILMIME_MECHANISM_8BIT; | 75 | mimetype = MAILMIME_MECHANISM_8BIT; |
76 | } else if (enc.lower()=="binary") { | 76 | } else if (enc.lower()=="binary") { |
77 | mimetype = MAILMIME_MECHANISM_BINARY; | 77 | mimetype = MAILMIME_MECHANISM_BINARY; |
78 | } | 78 | } |
79 | 79 | ||
80 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, | 80 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, |
81 | &result_text,&target_length); | 81 | &result_text,&target_length); |
82 | 82 | ||
83 | encodedString* result = new encodedString(); | 83 | encodedString* result = new encodedString(); |
84 | if (err == MAILIMF_NO_ERROR) { | 84 | if (err == MAILIMF_NO_ERROR) { |
85 | result->setContent(result_text,target_length); | 85 | result->setContent(result_text,target_length); |
86 | } | 86 | } |
87 | //odebug << "Decode string finished" << oendl; | 87 | //odebug << "Decode string finished" << oendl; |
88 | return result; | 88 | return result; |
89 | } | 89 | } |
90 | 90 | ||
91 | QString AbstractMail::convert_String(const char*text) | 91 | QString AbstractMail::convert_String(const char*text) |
92 | { | 92 | { |
93 | //size_t index = 0; | 93 | size_t index = 0; |
94 | char*res = 0; | 94 | char*res = 0; |
95 | int err = MAILIMF_NO_ERROR; | 95 | int err = MAILIMF_NO_ERROR; |
96 | 96 | ||
97 | QString result(text); | 97 | QString result(text); |
98 | 98 | ||
99 | /* due a bug in libetpan it isn't usable this moment */ | 99 | err = mailmime_encoded_phrase_parse("iso-8859-1", |
100 | /* int err = mailmime_encoded_phrase_parse("iso-8859-1", | 100 | text, strlen(text),&index, "iso-8859-1",&res); |
101 | text, strlen(text),&index, "iso-8859-1",&res);*/ | ||
102 | //odebug << "Input: " << text << "" << oendl; | ||
103 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { | 101 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { |
104 | // result = QString(res); | 102 | result = QString(res); |
105 | // odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl; | ||
106 | } | 103 | } |
104 | //qDebug("convert_String:%s ",result.latin1() ); | ||
107 | if (res) free(res); | 105 | if (res) free(res); |
108 | return result; | 106 | return result; |
109 | } | 107 | } |
110 | 108 | ||
111 | /* cp & paste from launcher */ | 109 | /* cp & paste from launcher */ |
112 | QString AbstractMail::gen_attachment_id() | 110 | QString AbstractMail::gen_attachment_id() |
113 | { | 111 | { |
114 | QFile file( "/proc/sys/kernel/random/uuid" ); | 112 | QFile file( "/proc/sys/kernel/random/uuid" ); |
115 | if (!file.open(IO_ReadOnly ) ) | 113 | if (!file.open(IO_ReadOnly ) ) |
116 | return QString::null; | 114 | return QString::null; |
117 | 115 | ||
118 | QTextStream stream(&file); | 116 | QTextStream stream(&file); |
119 | 117 | ||
120 | return "{" + stream.read().stripWhiteSpace() + "}"; | 118 | return "{" + stream.read().stripWhiteSpace() + "}"; |
121 | } | 119 | } |
122 | 120 | ||
123 | int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) | 121 | int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) |
124 | { | 122 | { |
125 | return 0; | 123 | return 0; |
126 | } | 124 | } |
127 | 125 | ||
128 | QString AbstractMail::defaultLocalfolder() | 126 | QString AbstractMail::defaultLocalfolder() |
129 | { | 127 | { |
130 | // QString f = getenv( "HOME" ); | 128 | // QString f = getenv( "HOME" ); |
131 | QString f = locateLocal( "data", "kopiemail/localmail"); | 129 | QString f = locateLocal( "data", "kopiemail/localmail"); |
132 | // f += "/Applications/opiemail/localmail"; | 130 | // f += "/Applications/opiemail/localmail"; |
133 | return f; | 131 | return f; |
134 | } | 132 | } |
135 | 133 | ||
136 | QString AbstractMail::draftFolder() | 134 | QString AbstractMail::draftFolder() |
137 | { | 135 | { |
138 | return QString("Drafts"); | 136 | return QString("Drafts"); |
139 | } | 137 | } |
140 | 138 | ||
141 | /* temporary - will be removed when implemented in all classes */ | 139 | /* temporary - will be removed when implemented in all classes */ |
142 | void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) | 140 | void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) |
143 | { | 141 | { |
144 | } | 142 | } |
145 | void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) | 143 | void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) |
146 | { | 144 | { |
147 | //qDebug("AbstractMail::deleteMailList:: Please reimplement! "); | 145 | //qDebug("AbstractMail::deleteMailList:: Please reimplement! "); |
148 | // this is currently re-implemented in pop3wrapper and imapwrapper | 146 | // this is currently re-implemented in pop3wrapper and imapwrapper |
149 | int iii = 0; | 147 | int iii = 0; |
150 | int count = target.count(); | 148 | int count = target.count(); |
151 | QProgressBar wid ( count ); | 149 | QProgressBar wid ( count ); |
152 | wid.setCaption( tr("Deleting ...")); | 150 | wid.setCaption( tr("Deleting ...")); |
153 | wid.show(); | 151 | wid.show(); |
154 | while (iii < count ) { | 152 | while (iii < count ) { |
155 | Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count)); | 153 | Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count)); |
156 | wid.setProgress( iii ); | 154 | wid.setProgress( iii ); |
157 | wid.raise(); | 155 | wid.raise(); |
158 | qApp->processEvents(); | 156 | qApp->processEvents(); |
159 | RecMailP mail = (*target.at( iii )); | 157 | RecMailP mail = (*target.at( iii )); |
160 | deleteMail(mail); | 158 | deleteMail(mail); |
161 | ++iii; | 159 | ++iii; |
162 | } | 160 | } |
163 | } | 161 | } |
164 | 162 | ||
165 | void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail ) | 163 | void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail ) |
166 | { | 164 | { |
167 | //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1()); | 165 | //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1()); |
168 | // get local folder | 166 | // get local folder |
169 | Account * acc = getAccount(); | 167 | Account * acc = getAccount(); |
170 | if ( !acc ) return; | 168 | if ( !acc ) return; |
171 | QString lfName = acc->getLocalFolder(); | 169 | QString lfName = acc->getLocalFolder(); |
172 | if ( lfName.isEmpty() ) | 170 | if ( lfName.isEmpty() ) |
173 | lfName = acc->getAccountName(); | 171 | lfName = acc->getAccountName(); |
174 | // create local folder | 172 | // create local folder |
175 | if ( !targetMail->createMbox(lfName)) | 173 | if ( !targetMail->createMbox(lfName)) |
176 | { | 174 | { |
177 | QMessageBox::critical(0,tr("Error creating new Folder"), | 175 | QMessageBox::critical(0,tr("Error creating new Folder"), |
178 | tr("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName)); | 176 | tr("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName)); |
179 | return; | 177 | return; |
180 | } | 178 | } |
181 | QValueList<RecMailP> t; | 179 | QValueList<RecMailP> t; |
182 | listMessages(fromFolder->getName(),t,acc->getMaxMailSize() ); | 180 | listMessages(fromFolder->getName(),t,acc->getMaxMailSize() ); |
183 | if ( t.count() == 0 ) { | 181 | if ( t.count() == 0 ) { |
184 | qDebug("There are no new messages %s", fromFolder->getName().latin1()); | 182 | qDebug("There are no new messages %s", fromFolder->getName().latin1()); |
185 | Global::statusMessage(tr("There are no new messages")); | 183 | Global::statusMessage(tr("There are no new messages")); |
186 | return; | 184 | return; |
187 | } | 185 | } |
188 | QValueList<RecMailP> e; | 186 | QValueList<RecMailP> e; |
189 | targetMail->listMessages(lfName,e,acc->getMaxMailSize() ); | 187 | targetMail->listMessages(lfName,e,acc->getMaxMailSize() ); |
190 | //qDebug("target has mails %d ", e.count()); | 188 | //qDebug("target has mails %d ", e.count()); |
191 | QValueList<RecMailP> n; | 189 | QValueList<RecMailP> n; |
192 | int iii = 0; | 190 | int iii = 0; |
193 | int count = t.count(); | 191 | int count = t.count(); |
194 | while (iii < count ) { | 192 | while (iii < count ) { |
195 | RecMailP r = (*t.at( iii )); | 193 | RecMailP r = (*t.at( iii )); |
196 | bool found = false; | 194 | bool found = false; |
197 | int jjj = 0; | 195 | int jjj = 0; |
198 | int countE = e.count(); | 196 | int countE = e.count(); |
199 | while (jjj < countE ) { | 197 | while (jjj < countE ) { |
200 | RecMailP re = (*e.at( jjj )); | 198 | RecMailP re = (*e.at( jjj )); |
201 | if ( re->isEqual(r) ) { | 199 | if ( re->isEqual(r) ) { |
202 | found = true; | 200 | found = true; |
203 | break; | 201 | break; |
204 | } | 202 | } |
205 | ++jjj; | 203 | ++jjj; |
206 | } | 204 | } |
207 | if ( !found ) { | 205 | if ( !found ) { |
208 | //qDebug("AAAdate *%s* ", r->isodate.latin1() ); | 206 | //qDebug("AAAdate *%s* ", r->isodate.latin1() ); |
209 | n.append( r ); | 207 | n.append( r ); |
210 | } | 208 | } |
211 | ++iii; | 209 | ++iii; |
212 | } | 210 | } |
213 | qDebug("Downloaded %d messages ",n.count() ); | 211 | qDebug("Downloaded %d messages ",n.count() ); |
214 | if ( n.count() == 0 ) { | 212 | if ( n.count() == 0 ) { |
215 | Global::statusMessage(tr("There are no new messages")); | 213 | Global::statusMessage(tr("There are no new messages")); |
216 | return; | 214 | return; |
217 | } | 215 | } |
218 | mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer()); | 216 | mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer()); |
219 | Global::statusMessage(tr("Downloaded %1 messages").arg(n.count())); | 217 | Global::statusMessage(tr("Downloaded %1 messages").arg(n.count())); |
220 | 218 | ||
221 | #if 0 | 219 | #if 0 |
222 | QValueList<RecMailP> t; | 220 | QValueList<RecMailP> t; |
223 | listMessages(fromFolder->getName(),t, maxSizeInKb); | 221 | listMessages(fromFolder->getName(),t, maxSizeInKb); |
224 | mvcpMailList( t,targetFolder,targetWrapper,moveit); | 222 | mvcpMailList( t,targetFolder,targetWrapper,moveit); |
225 | #endif | 223 | #endif |
226 | 224 | ||
227 | } | 225 | } |
228 | void AbstractMail::mvcpAllMails(const FolderP&fromFolder, | 226 | void AbstractMail::mvcpAllMails(const FolderP&fromFolder, |
229 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) | 227 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) |
230 | { | 228 | { |
231 | QValueList<RecMailP> t; | 229 | QValueList<RecMailP> t; |
232 | listMessages(fromFolder->getName(),t, maxSizeInKb); | 230 | listMessages(fromFolder->getName(),t, maxSizeInKb); |
233 | mvcpMailList( t,targetFolder,targetWrapper,moveit); | 231 | mvcpMailList( t,targetFolder,targetWrapper,moveit); |
234 | 232 | ||
235 | } | 233 | } |
236 | void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, | 234 | void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, |
237 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 235 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
238 | { | 236 | { |
239 | encodedString*st = 0; | 237 | encodedString*st = 0; |
240 | int iii = 0; | 238 | int iii = 0; |
241 | int count = t.count(); | 239 | int count = t.count(); |
242 | if ( count == 0 ) | 240 | if ( count == 0 ) |
243 | return; | 241 | return; |
244 | // wel, processevents is qite strange, we need a widget for getting | 242 | // wel, processevents is qite strange, we need a widget for getting |
245 | // Global::statusMessage(tr("Copy2 message %1").arg(iii)); displaye | 243 | // Global::statusMessage(tr("Copy2 message %1").arg(iii)); displaye |
246 | 244 | ||
247 | QProgressBar wid ( count ); | 245 | QProgressBar wid ( count ); |
248 | wid.setCaption( tr("Copying ...")); | 246 | wid.setCaption( tr("Copying ...")); |
249 | wid.show(); | 247 | wid.show(); |
250 | while (iii < count ) { | 248 | while (iii < count ) { |
251 | Global::statusMessage(tr("Copy message %1 of %2").arg(iii).arg(count)); | 249 | Global::statusMessage(tr("Copy message %1 of %2").arg(iii).arg(count)); |
252 | wid.setProgress( iii ); | 250 | wid.setProgress( iii ); |
253 | wid.raise(); | 251 | wid.raise(); |
254 | qApp->processEvents(); | 252 | qApp->processEvents(); |
255 | RecMailP r = (*t.at( iii )); | 253 | RecMailP r = (*t.at( iii )); |
256 | st = fetchRawBody(r); | 254 | st = fetchRawBody(r); |
257 | if (st) { | 255 | if (st) { |
258 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); | 256 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); |
259 | delete st; | 257 | delete st; |
260 | } | 258 | } |
261 | ++iii; | 259 | ++iii; |
262 | } | 260 | } |
263 | if (moveit) { | 261 | if (moveit) { |
264 | deleteMailList( t ); | 262 | deleteMailList( t ); |
265 | //deleteAllMail(fromFolder); | 263 | //deleteAllMail(fromFolder); |
266 | } | 264 | } |
267 | } | 265 | } |
268 | 266 | ||
269 | void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 267 | void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
270 | { | 268 | { |
271 | encodedString*st = 0; | 269 | encodedString*st = 0; |
272 | st = fetchRawBody(mail); | 270 | st = fetchRawBody(mail); |
273 | if (st) { | 271 | if (st) { |
274 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); | 272 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); |
275 | delete st; | 273 | delete st; |
276 | } | 274 | } |
277 | if (moveit) { | 275 | if (moveit) { |
278 | deleteMail(mail); | 276 | deleteMail(mail); |
279 | } | 277 | } |
280 | } | 278 | } |
diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp index e691082..d89a5f9 100644 --- a/kmicromail/libmailwrapper/genericwrapper.cpp +++ b/kmicromail/libmailwrapper/genericwrapper.cpp | |||
@@ -1,530 +1,530 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #include "genericwrapper.h" | 2 | #include "genericwrapper.h" |
3 | #include <libetpan/libetpan.h> | 3 | #include <libetpan/libetpan.h> |
4 | #include "mailtypes.h" | 4 | #include "mailtypes.h" |
5 | 5 | ||
6 | #include <kconfig.h> | 6 | #include <kconfig.h> |
7 | #include <kglobal.h> | 7 | #include <kglobal.h> |
8 | #include <kstandarddirs.h> | 8 | #include <kstandarddirs.h> |
9 | 9 | ||
10 | 10 | ||
11 | using namespace Opie::Core; | 11 | using namespace Opie::Core; |
12 | Genericwrapper::Genericwrapper() | 12 | Genericwrapper::Genericwrapper() |
13 | : AbstractMail() | 13 | : AbstractMail() |
14 | { | 14 | { |
15 | bodyCache.clear(); | 15 | bodyCache.clear(); |
16 | m_storage = 0; | 16 | m_storage = 0; |
17 | m_folder = 0; | 17 | m_folder = 0; |
18 | } | 18 | } |
19 | 19 | ||
20 | Genericwrapper::~Genericwrapper() | 20 | Genericwrapper::~Genericwrapper() |
21 | { | 21 | { |
22 | if (m_folder) { | 22 | if (m_folder) { |
23 | mailfolder_free(m_folder); | 23 | mailfolder_free(m_folder); |
24 | } | 24 | } |
25 | if (m_storage) { | 25 | if (m_storage) { |
26 | mailstorage_free(m_storage); | 26 | mailstorage_free(m_storage); |
27 | } | 27 | } |
28 | cleanMimeCache(); | 28 | cleanMimeCache(); |
29 | } | 29 | } |
30 | const QDateTime Genericwrapper::parseDateTime( mailimf_date_time *date ) | 30 | const QDateTime Genericwrapper::parseDateTime( mailimf_date_time *date ) |
31 | { | 31 | { |
32 | 32 | ||
33 | QDate da (date->dt_year,date->dt_month, date->dt_day ); | 33 | QDate da (date->dt_year,date->dt_month, date->dt_day ); |
34 | QTime ti ( date->dt_hour, date->dt_min, date->dt_sec ); | 34 | QTime ti ( date->dt_hour, date->dt_min, date->dt_sec ); |
35 | QDateTime dt ( da ,ti ); | 35 | QDateTime dt ( da ,ti ); |
36 | int addsec = -date->dt_zone*36; | 36 | int addsec = -date->dt_zone*36; |
37 | //qDebug("adsec1 %d ",addsec ); | 37 | //qDebug("adsec1 %d ",addsec ); |
38 | dt = dt.addSecs( addsec ); | 38 | dt = dt.addSecs( addsec ); |
39 | int off = KGlobal::locale()->localTimeOffset( dt ); | 39 | int off = KGlobal::locale()->localTimeOffset( dt ); |
40 | //qDebug("adsec2 %d ",off*60 ); | 40 | //qDebug("adsec2 %d ",off*60 ); |
41 | 41 | ||
42 | dt = dt.addSecs( off*60 ); | 42 | dt = dt.addSecs( off*60 ); |
43 | return dt; | 43 | return dt; |
44 | #if 0 | 44 | #if 0 |
45 | QString ret; | 45 | QString ret; |
46 | if ( dt.date() == QDate::currentDate () ) | 46 | if ( dt.date() == QDate::currentDate () ) |
47 | ret = KGlobal::locale()->formatTime( dt.time(),true); | 47 | ret = KGlobal::locale()->formatTime( dt.time(),true); |
48 | 48 | ||
49 | else { | 49 | else { |
50 | ret = KGlobal::locale()->formatDateTime( dt,true,true); | 50 | ret = KGlobal::locale()->formatDateTime( dt,true,true); |
51 | } | 51 | } |
52 | #endif | 52 | #endif |
53 | #if 0 | 53 | #if 0 |
54 | if ( off < 0 ) | 54 | if ( off < 0 ) |
55 | ret += " -"; | 55 | ret += " -"; |
56 | else | 56 | else |
57 | ret += " +"; | 57 | ret += " +"; |
58 | ret += QString::number( off / 60 ); | 58 | ret += QString::number( off / 60 ); |
59 | ret += "h"; | 59 | ret += "h"; |
60 | #endif | 60 | #endif |
61 | #if 0 | 61 | #if 0 |
62 | char tmp[23]; | 62 | char tmp[23]; |
63 | 63 | ||
64 | // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | 64 | // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", |
65 | // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); | 65 | // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); |
66 | snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i", | 66 | snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i", |
67 | date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); | 67 | date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); |
68 | 68 | ||
69 | 69 | ||
70 | return QString( tmp ); | 70 | return QString( tmp ); |
71 | #endif | 71 | #endif |
72 | //return ret; | 72 | //return ret; |
73 | } | 73 | } |
74 | 74 | ||
75 | void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) | 75 | void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) |
76 | { | 76 | { |
77 | if (!mime) { | 77 | if (!mime) { |
78 | return; | 78 | return; |
79 | } | 79 | } |
80 | mailmime_field*field = 0; | 80 | mailmime_field*field = 0; |
81 | mailmime_single_fields fields; | 81 | mailmime_single_fields fields; |
82 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 82 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
83 | if (mime->mm_mime_fields != NULL) { | 83 | if (mime->mm_mime_fields != NULL) { |
84 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, | 84 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, |
85 | mime->mm_content_type); | 85 | mime->mm_content_type); |
86 | } | 86 | } |
87 | 87 | ||
88 | mailmime_content*type = fields.fld_content; | 88 | mailmime_content*type = fields.fld_content; |
89 | clistcell*current; | 89 | clistcell*current; |
90 | if (!type) { | 90 | if (!type) { |
91 | target->setType("text"); | 91 | target->setType("text"); |
92 | target->setSubtype("plain"); | 92 | target->setSubtype("plain"); |
93 | } else { | 93 | } else { |
94 | target->setSubtype(type->ct_subtype); | 94 | target->setSubtype(type->ct_subtype); |
95 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { | 95 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { |
96 | case MAILMIME_DISCRETE_TYPE_TEXT: | 96 | case MAILMIME_DISCRETE_TYPE_TEXT: |
97 | target->setType("text"); | 97 | target->setType("text"); |
98 | break; | 98 | break; |
99 | case MAILMIME_DISCRETE_TYPE_IMAGE: | 99 | case MAILMIME_DISCRETE_TYPE_IMAGE: |
100 | target->setType("image"); | 100 | target->setType("image"); |
101 | break; | 101 | break; |
102 | case MAILMIME_DISCRETE_TYPE_AUDIO: | 102 | case MAILMIME_DISCRETE_TYPE_AUDIO: |
103 | target->setType("audio"); | 103 | target->setType("audio"); |
104 | break; | 104 | break; |
105 | case MAILMIME_DISCRETE_TYPE_VIDEO: | 105 | case MAILMIME_DISCRETE_TYPE_VIDEO: |
106 | target->setType("video"); | 106 | target->setType("video"); |
107 | break; | 107 | break; |
108 | case MAILMIME_DISCRETE_TYPE_APPLICATION: | 108 | case MAILMIME_DISCRETE_TYPE_APPLICATION: |
109 | target->setType("application"); | 109 | target->setType("application"); |
110 | break; | 110 | break; |
111 | case MAILMIME_DISCRETE_TYPE_EXTENSION: | 111 | case MAILMIME_DISCRETE_TYPE_EXTENSION: |
112 | default: | 112 | default: |
113 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { | 113 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { |
114 | target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); | 114 | target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); |
115 | } | 115 | } |
116 | break; | 116 | break; |
117 | } | 117 | } |
118 | if (type->ct_parameters) { | 118 | if (type->ct_parameters) { |
119 | fillParameters(target,type->ct_parameters); | 119 | fillParameters(target,type->ct_parameters); |
120 | } | 120 | } |
121 | } | 121 | } |
122 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { | 122 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { |
123 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { | 123 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { |
124 | field = (mailmime_field*)current->data; | 124 | field = (mailmime_field*)current->data; |
125 | switch(field->fld_type) { | 125 | switch(field->fld_type) { |
126 | case MAILMIME_FIELD_TRANSFER_ENCODING: | 126 | case MAILMIME_FIELD_TRANSFER_ENCODING: |
127 | target->setEncoding(getencoding(field->fld_data.fld_encoding)); | 127 | target->setEncoding(getencoding(field->fld_data.fld_encoding)); |
128 | break; | 128 | break; |
129 | case MAILMIME_FIELD_ID: | 129 | case MAILMIME_FIELD_ID: |
130 | target->setIdentifier(field->fld_data.fld_id); | 130 | target->setIdentifier(field->fld_data.fld_id); |
131 | break; | 131 | break; |
132 | case MAILMIME_FIELD_DESCRIPTION: | 132 | case MAILMIME_FIELD_DESCRIPTION: |
133 | target->setDescription(field->fld_data.fld_description); | 133 | target->setDescription(field->fld_data.fld_description); |
134 | break; | 134 | break; |
135 | default: | 135 | default: |
136 | break; | 136 | break; |
137 | } | 137 | } |
138 | } | 138 | } |
139 | } | 139 | } |
140 | } | 140 | } |
141 | 141 | ||
142 | void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) | 142 | void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) |
143 | { | 143 | { |
144 | if (!parameters) {return;} | 144 | if (!parameters) {return;} |
145 | clistcell*current=0; | 145 | clistcell*current=0; |
146 | mailmime_parameter*param; | 146 | mailmime_parameter*param; |
147 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { | 147 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { |
148 | param = (mailmime_parameter*)current->data; | 148 | param = (mailmime_parameter*)current->data; |
149 | if (param) { | 149 | if (param) { |
150 | target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 150 | target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
151 | } | 151 | } |
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 | ||
155 | QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) | 155 | QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) |
156 | { | 156 | { |
157 | QString enc="7bit"; | 157 | QString enc="7bit"; |
158 | if (!aEnc) return enc; | 158 | if (!aEnc) return enc; |
159 | switch(aEnc->enc_type) { | 159 | switch(aEnc->enc_type) { |
160 | case MAILMIME_MECHANISM_7BIT: | 160 | case MAILMIME_MECHANISM_7BIT: |
161 | enc = "7bit"; | 161 | enc = "7bit"; |
162 | break; | 162 | break; |
163 | case MAILMIME_MECHANISM_8BIT: | 163 | case MAILMIME_MECHANISM_8BIT: |
164 | enc = "8bit"; | 164 | enc = "8bit"; |
165 | break; | 165 | break; |
166 | case MAILMIME_MECHANISM_BINARY: | 166 | case MAILMIME_MECHANISM_BINARY: |
167 | enc = "binary"; | 167 | enc = "binary"; |
168 | break; | 168 | break; |
169 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: | 169 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: |
170 | enc = "quoted-printable"; | 170 | enc = "quoted-printable"; |
171 | break; | 171 | break; |
172 | case MAILMIME_MECHANISM_BASE64: | 172 | case MAILMIME_MECHANISM_BASE64: |
173 | enc = "base64"; | 173 | enc = "base64"; |
174 | break; | 174 | break; |
175 | case MAILMIME_MECHANISM_TOKEN: | 175 | case MAILMIME_MECHANISM_TOKEN: |
176 | default: | 176 | default: |
177 | if (aEnc->enc_token) { | 177 | if (aEnc->enc_token) { |
178 | enc = QString(aEnc->enc_token); | 178 | enc = QString(aEnc->enc_token); |
179 | } | 179 | } |
180 | break; | 180 | break; |
181 | } | 181 | } |
182 | return enc; | 182 | return enc; |
183 | } | 183 | } |
184 | 184 | ||
185 | void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) | 185 | void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) |
186 | { | 186 | { |
187 | if (current_rec >= 10) { | 187 | if (current_rec >= 10) { |
188 | ; // odebug << "too deep recursion!" << oendl; | 188 | ; // odebug << "too deep recursion!" << oendl; |
189 | } | 189 | } |
190 | if (!message || !mime) { | 190 | if (!message || !mime) { |
191 | return; | 191 | return; |
192 | } | 192 | } |
193 | int r; | 193 | int r; |
194 | char*data = 0; | 194 | char*data = 0; |
195 | size_t len; | 195 | size_t len; |
196 | clistiter * cur = 0; | 196 | clistiter * cur = 0; |
197 | QString b; | 197 | QString b; |
198 | RecPartP part = new RecPart(); | 198 | RecPartP part = new RecPart(); |
199 | 199 | ||
200 | switch (mime->mm_type) { | 200 | switch (mime->mm_type) { |
201 | case MAILMIME_SINGLE: | 201 | case MAILMIME_SINGLE: |
202 | { | 202 | { |
203 | QValueList<int>countlist = recList; | 203 | QValueList<int>countlist = recList; |
204 | countlist.append(current_count); | 204 | countlist.append(current_count); |
205 | r = mailmessage_fetch_section(message,mime,&data,&len); | 205 | r = mailmessage_fetch_section(message,mime,&data,&len); |
206 | part->setSize(len); | 206 | part->setSize(len); |
207 | part->setPositionlist(countlist); | 207 | part->setPositionlist(countlist); |
208 | b = gen_attachment_id(); | 208 | b = gen_attachment_id(); |
209 | part->setIdentifier(b); | 209 | part->setIdentifier(b); |
210 | fillSingleBody(part,message,mime); | 210 | fillSingleBody(part,message,mime); |
211 | if (part->Type()=="text" && target->Bodytext().isNull()) { | 211 | if (part->Type()=="text" && target->Bodytext().isNull()) { |
212 | encodedString*rs = new encodedString(); | 212 | encodedString*rs = new encodedString(); |
213 | rs->setContent(data,len); | 213 | rs->setContent(data,len); |
214 | encodedString*res = decode_String(rs,part->Encoding()); | 214 | encodedString*res = decode_String(rs,part->Encoding()); |
215 | if (countlist.count()>2) { | 215 | if (countlist.count()>2) { |
216 | bodyCache[b]=rs; | 216 | bodyCache[b]=rs; |
217 | target->addPart(part); | 217 | target->addPart(part); |
218 | } else { | 218 | } else { |
219 | delete rs; | 219 | delete rs; |
220 | } | 220 | } |
221 | b = QString(res->Content()); | 221 | b = QString(res->Content()); |
222 | delete res; | 222 | delete res; |
223 | target->setBodytext(b); | 223 | target->setBodytext(b); |
224 | target->setDescription(part); | 224 | target->setDescription(part); |
225 | } else { | 225 | } else { |
226 | bodyCache[b]=new encodedString(data,len); | 226 | bodyCache[b]=new encodedString(data,len); |
227 | target->addPart(part); | 227 | target->addPart(part); |
228 | } | 228 | } |
229 | } | 229 | } |
230 | break; | 230 | break; |
231 | case MAILMIME_MULTIPLE: | 231 | case MAILMIME_MULTIPLE: |
232 | { | 232 | { |
233 | unsigned int ccount = 1; | 233 | unsigned int ccount = 1; |
234 | mailmime*cbody=0; | 234 | mailmime*cbody=0; |
235 | QValueList<int>countlist = recList; | 235 | QValueList<int>countlist = recList; |
236 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { | 236 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { |
237 | cbody = (mailmime*)clist_content(cur); | 237 | cbody = (mailmime*)clist_content(cur); |
238 | if (cbody->mm_type==MAILMIME_MULTIPLE) { | 238 | if (cbody->mm_type==MAILMIME_MULTIPLE) { |
239 | RecPartP targetPart = new RecPart(); | 239 | RecPartP targetPart = new RecPart(); |
240 | targetPart->setType("multipart"); | 240 | targetPart->setType("multipart"); |
241 | countlist.append(current_count); | 241 | countlist.append(current_count); |
242 | targetPart->setPositionlist(countlist); | 242 | targetPart->setPositionlist(countlist); |
243 | target->addPart(targetPart); | 243 | target->addPart(targetPart); |
244 | } | 244 | } |
245 | traverseBody(target,message, cbody,countlist,current_rec+1,ccount); | 245 | traverseBody(target,message, cbody,countlist,current_rec+1,ccount); |
246 | if (cbody->mm_type==MAILMIME_MULTIPLE) { | 246 | if (cbody->mm_type==MAILMIME_MULTIPLE) { |
247 | countlist = recList; | 247 | countlist = recList; |
248 | } | 248 | } |
249 | ++ccount; | 249 | ++ccount; |
250 | } | 250 | } |
251 | } | 251 | } |
252 | break; | 252 | break; |
253 | case MAILMIME_MESSAGE: | 253 | case MAILMIME_MESSAGE: |
254 | { | 254 | { |
255 | QValueList<int>countlist = recList; | 255 | QValueList<int>countlist = recList; |
256 | countlist.append(current_count); | 256 | countlist.append(current_count); |
257 | /* the own header is always at recursion 0 - we don't need that */ | 257 | /* the own header is always at recursion 0 - we don't need that */ |
258 | if (current_rec > 0) { | 258 | if (current_rec > 0) { |
259 | part->setPositionlist(countlist); | 259 | part->setPositionlist(countlist); |
260 | r = mailmessage_fetch_section(message,mime,&data,&len); | 260 | r = mailmessage_fetch_section(message,mime,&data,&len); |
261 | part->setSize(len); | 261 | part->setSize(len); |
262 | part->setPositionlist(countlist); | 262 | part->setPositionlist(countlist); |
263 | b = gen_attachment_id(); | 263 | b = gen_attachment_id(); |
264 | part->setIdentifier(b); | 264 | part->setIdentifier(b); |
265 | part->setType("message"); | 265 | part->setType("message"); |
266 | part->setSubtype("rfc822"); | 266 | part->setSubtype("rfc822"); |
267 | bodyCache[b]=new encodedString(data,len); | 267 | bodyCache[b]=new encodedString(data,len); |
268 | target->addPart(part); | 268 | target->addPart(part); |
269 | } | 269 | } |
270 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { | 270 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { |
271 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); | 271 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); |
272 | } | 272 | } |
273 | } | 273 | } |
274 | break; | 274 | break; |
275 | } | 275 | } |
276 | } | 276 | } |
277 | 277 | ||
278 | RecBodyP Genericwrapper::parseMail( mailmessage * msg ) | 278 | RecBodyP Genericwrapper::parseMail( mailmessage * msg ) |
279 | { | 279 | { |
280 | int err = MAILIMF_NO_ERROR; | 280 | int err = MAILIMF_NO_ERROR; |
281 | mailmime_single_fields fields; | 281 | //mailmime_single_fields fields; |
282 | /* is bound to msg and will be freed there */ | 282 | /* is bound to msg and will be freed there */ |
283 | mailmime * mime=0; | 283 | mailmime * mime=0; |
284 | RecBodyP body = new RecBody(); | 284 | RecBodyP body = new RecBody(); |
285 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 285 | //memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
286 | err = mailmessage_get_bodystructure(msg,&mime); | 286 | err = mailmessage_get_bodystructure(msg,&mime); |
287 | QValueList<int>recList; | 287 | QValueList<int>recList; |
288 | traverseBody(body,msg,mime,recList); | 288 | traverseBody(body,msg,mime,recList); |
289 | return body; | 289 | return body; |
290 | } | 290 | } |
291 | 291 | ||
292 | 292 | ||
293 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) | 293 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) |
294 | { | 294 | { |
295 | QString result( "" ); | 295 | QString result( "" ); |
296 | 296 | ||
297 | bool first = true; | 297 | bool first = true; |
298 | if (list == 0) return result; | 298 | if (list == 0) return result; |
299 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { | 299 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { |
300 | mailimf_address *addr = (mailimf_address *) current->data; | 300 | mailimf_address *addr = (mailimf_address *) current->data; |
301 | 301 | ||
302 | if ( !first ) { | 302 | if ( !first ) { |
303 | result.append( "," ); | 303 | result.append( "," ); |
304 | } else { | 304 | } else { |
305 | first = false; | 305 | first = false; |
306 | } | 306 | } |
307 | 307 | ||
308 | switch ( addr->ad_type ) { | 308 | switch ( addr->ad_type ) { |
309 | case MAILIMF_ADDRESS_MAILBOX: | 309 | case MAILIMF_ADDRESS_MAILBOX: |
310 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); | 310 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); |
311 | break; | 311 | break; |
312 | case MAILIMF_ADDRESS_GROUP: | 312 | case MAILIMF_ADDRESS_GROUP: |
313 | result.append( parseGroup( addr->ad_data.ad_group ) ); | 313 | result.append( parseGroup( addr->ad_data.ad_group ) ); |
314 | break; | 314 | break; |
315 | default: | 315 | default: |
316 | ; // odebug << "Generic: unkown mailimf address type" << oendl; | 316 | ; // odebug << "Generic: unkown mailimf address type" << oendl; |
317 | break; | 317 | break; |
318 | } | 318 | } |
319 | } | 319 | } |
320 | 320 | ||
321 | return result; | 321 | return result; |
322 | } | 322 | } |
323 | 323 | ||
324 | QString Genericwrapper::parseGroup( mailimf_group *group ) | 324 | QString Genericwrapper::parseGroup( mailimf_group *group ) |
325 | { | 325 | { |
326 | QString result( "" ); | 326 | QString result( "" ); |
327 | 327 | ||
328 | result.append( group->grp_display_name ); | 328 | result.append( group->grp_display_name ); |
329 | result.append( ": " ); | 329 | result.append( ": " ); |
330 | 330 | ||
331 | if ( group->grp_mb_list != NULL ) { | 331 | if ( group->grp_mb_list != NULL ) { |
332 | result.append( parseMailboxList( group->grp_mb_list ) ); | 332 | result.append( parseMailboxList( group->grp_mb_list ) ); |
333 | } | 333 | } |
334 | 334 | ||
335 | result.append( ";" ); | 335 | result.append( ";" ); |
336 | 336 | ||
337 | return result; | 337 | return result; |
338 | } | 338 | } |
339 | 339 | ||
340 | QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) | 340 | QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) |
341 | { | 341 | { |
342 | QString result( "" ); | 342 | QString result( "" ); |
343 | 343 | ||
344 | if ( box->mb_display_name == NULL ) { | 344 | if ( box->mb_display_name == NULL ) { |
345 | result.append( box->mb_addr_spec ); | 345 | result.append( box->mb_addr_spec ); |
346 | } else { | 346 | } else { |
347 | result.append( convert_String(box->mb_display_name).latin1() ); | 347 | result.append( convert_String(box->mb_display_name).latin1() ); |
348 | result.append( " <" ); | 348 | result.append( " <" ); |
349 | result.append( box->mb_addr_spec ); | 349 | result.append( box->mb_addr_spec ); |
350 | result.append( ">" ); | 350 | result.append( ">" ); |
351 | } | 351 | } |
352 | 352 | ||
353 | return result; | 353 | return result; |
354 | } | 354 | } |
355 | 355 | ||
356 | QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) | 356 | QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) |
357 | { | 357 | { |
358 | QString result( "" ); | 358 | QString result( "" ); |
359 | 359 | ||
360 | bool first = true; | 360 | bool first = true; |
361 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { | 361 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { |
362 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; | 362 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; |
363 | 363 | ||
364 | if ( !first ) { | 364 | if ( !first ) { |
365 | result.append( "," ); | 365 | result.append( "," ); |
366 | } else { | 366 | } else { |
367 | first = false; | 367 | first = false; |
368 | } | 368 | } |
369 | 369 | ||
370 | result.append( parseMailbox( box ) ); | 370 | result.append( parseMailbox( box ) ); |
371 | } | 371 | } |
372 | 372 | ||
373 | return result; | 373 | return result; |
374 | } | 374 | } |
375 | 375 | ||
376 | encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) | 376 | encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) |
377 | { | 377 | { |
378 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); | 378 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); |
379 | if (it==bodyCache.end()) return new encodedString(); | 379 | if (it==bodyCache.end()) return new encodedString(); |
380 | encodedString*t = decode_String(it.data(),part->Encoding()); | 380 | encodedString*t = decode_String(it.data(),part->Encoding()); |
381 | return t; | 381 | return t; |
382 | } | 382 | } |
383 | 383 | ||
384 | encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) | 384 | encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) |
385 | { | 385 | { |
386 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); | 386 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); |
387 | if (it==bodyCache.end()) return new encodedString(); | 387 | if (it==bodyCache.end()) return new encodedString(); |
388 | encodedString*t = it.data(); | 388 | encodedString*t = it.data(); |
389 | return t; | 389 | return t; |
390 | } | 390 | } |
391 | 391 | ||
392 | QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) | 392 | QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) |
393 | { | 393 | { |
394 | encodedString*t = fetchDecodedPart(mail,part); | 394 | encodedString*t = fetchDecodedPart(mail,part); |
395 | QString text=t->Content(); | 395 | QString text=t->Content(); |
396 | delete t; | 396 | delete t; |
397 | return text; | 397 | return text; |
398 | } | 398 | } |
399 | 399 | ||
400 | void Genericwrapper::cleanMimeCache() | 400 | void Genericwrapper::cleanMimeCache() |
401 | { | 401 | { |
402 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); | 402 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); |
403 | for (;it!=bodyCache.end();++it) { | 403 | for (;it!=bodyCache.end();++it) { |
404 | encodedString*t = it.data(); | 404 | encodedString*t = it.data(); |
405 | //it.setValue(0); | 405 | //it.setValue(0); |
406 | if (t) delete t; | 406 | if (t) delete t; |
407 | } | 407 | } |
408 | bodyCache.clear(); | 408 | bodyCache.clear(); |
409 | ; // odebug << "Genericwrapper: cache cleaned" << oendl; | 409 | ; // odebug << "Genericwrapper: cache cleaned" << oendl; |
410 | } | 410 | } |
411 | 411 | ||
412 | QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) | 412 | QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) |
413 | { | 413 | { |
414 | QStringList res; | 414 | QStringList res; |
415 | if (!in_replies || !in_replies->mid_list) return res; | 415 | if (!in_replies || !in_replies->mid_list) return res; |
416 | clistiter * current = 0; | 416 | clistiter * current = 0; |
417 | for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { | 417 | for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { |
418 | QString h((char*)current->data); | 418 | QString h((char*)current->data); |
419 | while (h.length()>0 && h[0]=='<') { | 419 | while (h.length()>0 && h[0]=='<') { |
420 | h.remove(0,1); | 420 | h.remove(0,1); |
421 | } | 421 | } |
422 | while (h.length()>0 && h[h.length()-1]=='>') { | 422 | while (h.length()>0 && h[h.length()-1]=='>') { |
423 | h.remove(h.length()-1,1); | 423 | h.remove(h.length()-1,1); |
424 | } | 424 | } |
425 | if (h.length()>0) { | 425 | if (h.length()>0) { |
426 | res.append(h); | 426 | res.append(h); |
427 | } | 427 | } |
428 | } | 428 | } |
429 | return res; | 429 | return res; |
430 | } | 430 | } |
431 | 431 | ||
432 | void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb) | 432 | void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb) |
433 | { | 433 | { |
434 | int r; | 434 | int r; |
435 | mailmessage_list * env_list = 0; | 435 | mailmessage_list * env_list = 0; |
436 | r = mailsession_get_messages_list(session,&env_list); | 436 | r = mailsession_get_messages_list(session,&env_list); |
437 | if (r != MAIL_NO_ERROR) { | 437 | if (r != MAIL_NO_ERROR) { |
438 | ; // odebug << "Error message list" << oendl; | 438 | ; // odebug << "Error message list" << oendl; |
439 | return; | 439 | return; |
440 | } | 440 | } |
441 | r = mailsession_get_envelopes_list(session, env_list); | 441 | r = mailsession_get_envelopes_list(session, env_list); |
442 | if (r != MAIL_NO_ERROR) { | 442 | if (r != MAIL_NO_ERROR) { |
443 | ; // odebug << "Error filling message list" << oendl; | 443 | ; // odebug << "Error filling message list" << oendl; |
444 | if (env_list) { | 444 | if (env_list) { |
445 | mailmessage_list_free(env_list); | 445 | mailmessage_list_free(env_list); |
446 | } | 446 | } |
447 | return; | 447 | return; |
448 | } | 448 | } |
449 | mailimf_references * refs = 0; | 449 | mailimf_references * refs = 0; |
450 | mailimf_in_reply_to * in_replies = 0; | 450 | mailimf_in_reply_to * in_replies = 0; |
451 | uint32_t i = 0; | 451 | uint32_t i = 0; |
452 | for(; i < carray_count(env_list->msg_tab) ; ++i) { | 452 | for(; i < carray_count(env_list->msg_tab) ; ++i) { |
453 | mailmessage * msg; | 453 | mailmessage * msg; |
454 | QBitArray mFlags(7); | 454 | QBitArray mFlags(7); |
455 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); | 455 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); |
456 | if (msg->msg_fields == NULL) { | 456 | if (msg->msg_fields == NULL) { |
457 | //; // odebug << "could not fetch envelope of message " << i << "" << oendl; | 457 | //; // odebug << "could not fetch envelope of message " << i << "" << oendl; |
458 | continue; | 458 | continue; |
459 | } | 459 | } |
460 | RecMailP mail = new RecMail(); | 460 | RecMailP mail = new RecMail(); |
461 | mail->setWrapper(this); | 461 | mail->setWrapper(this); |
462 | mail_flags * flag_result = 0; | 462 | mail_flags * flag_result = 0; |
463 | r = mailmessage_get_flags(msg,&flag_result); | 463 | r = mailmessage_get_flags(msg,&flag_result); |
464 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { | 464 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { |
465 | mFlags.setBit(FLAG_SEEN); | 465 | mFlags.setBit(FLAG_SEEN); |
466 | } | 466 | } |
467 | mailimf_single_fields single_fields; | 467 | mailimf_single_fields single_fields; |
468 | mailimf_single_fields_init(&single_fields, msg->msg_fields); | 468 | mailimf_single_fields_init(&single_fields, msg->msg_fields); |
469 | mail->setMsgsize(msg->msg_size); | 469 | mail->setMsgsize(msg->msg_size); |
470 | mail->setFlags(mFlags); | 470 | mail->setFlags(mFlags); |
471 | mail->setMbox(mailbox); | 471 | mail->setMbox(mailbox); |
472 | mail->setNumber(msg->msg_index); | 472 | mail->setNumber(msg->msg_index); |
473 | if (single_fields.fld_subject) | 473 | if (single_fields.fld_subject) |
474 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); | 474 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); |
475 | if (single_fields.fld_from) | 475 | if (single_fields.fld_from) |
476 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); | 476 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); |
477 | if (!mbox_as_to) { | 477 | if (!mbox_as_to) { |
478 | if (single_fields.fld_to) | 478 | if (single_fields.fld_to) |
479 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); | 479 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); |
480 | } else { | 480 | } else { |
481 | mail->setTo(mailbox); | 481 | mail->setTo(mailbox); |
482 | } | 482 | } |
483 | if (single_fields.fld_cc) | 483 | if (single_fields.fld_cc) |
484 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); | 484 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); |
485 | if (single_fields.fld_bcc) | 485 | if (single_fields.fld_bcc) |
486 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); | 486 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); |
487 | if (single_fields.fld_orig_date) { | 487 | if (single_fields.fld_orig_date) { |
488 | QDateTime dt = Genericwrapper::parseDateTime( single_fields.fld_orig_date->dt_date_time ); | 488 | QDateTime dt = Genericwrapper::parseDateTime( single_fields.fld_orig_date->dt_date_time ); |
489 | QString ret; | 489 | QString ret; |
490 | if ( dt.date() == QDate::currentDate () ) | 490 | if ( dt.date() == QDate::currentDate () ) |
491 | ret = KGlobal::locale()->formatTime( dt.time(),true); | 491 | ret = KGlobal::locale()->formatTime( dt.time(),true); |
492 | else { | 492 | else { |
493 | ret = KGlobal::locale()->formatDateTime( dt,true,true); | 493 | ret = KGlobal::locale()->formatDateTime( dt,true,true); |
494 | } | 494 | } |
495 | mail->setDate( ret ); | 495 | mail->setDate( ret ); |
496 | char tmp[20]; | 496 | char tmp[20]; |
497 | snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", | 497 | snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", |
498 | dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); | 498 | dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); |
499 | //qDebug(" iso %s ", tmp); | 499 | //qDebug(" iso %s ", tmp); |
500 | mail->setIsoDate( QString( tmp ) ); | 500 | mail->setIsoDate( QString( tmp ) ); |
501 | } | 501 | } |
502 | // crashes when accessing pop3 account? | 502 | // crashes when accessing pop3 account? |
503 | if (single_fields.fld_message_id) { | 503 | if (single_fields.fld_message_id) { |
504 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); | 504 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); |
505 | ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl; | 505 | ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl; |
506 | } | 506 | } |
507 | if (single_fields.fld_reply_to) { | 507 | if (single_fields.fld_reply_to) { |
508 | QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); | 508 | QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); |
509 | if (t.count()>0) { | 509 | if (t.count()>0) { |
510 | mail->setReplyto(t[0]); | 510 | mail->setReplyto(t[0]); |
511 | } | 511 | } |
512 | } | 512 | } |
513 | #if 0 | 513 | #if 0 |
514 | refs = single_fields.fld_references; | 514 | refs = single_fields.fld_references; |
515 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | 515 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { |
516 | char * text = (char*)refs->mid_list->first->data; | 516 | char * text = (char*)refs->mid_list->first->data; |
517 | mail->setReplyto(QString(text)); | 517 | mail->setReplyto(QString(text)); |
518 | } | 518 | } |
519 | #endif | 519 | #endif |
520 | if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list && | 520 | if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list && |
521 | clist_count(single_fields.fld_in_reply_to->mid_list)) { | 521 | clist_count(single_fields.fld_in_reply_to->mid_list)) { |
522 | mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); | 522 | mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); |
523 | } | 523 | } |
524 | if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 ) | 524 | if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 ) |
525 | target.append(mail); | 525 | target.append(mail); |
526 | } | 526 | } |
527 | if (env_list) { | 527 | if (env_list) { |
528 | mailmessage_list_free(env_list); | 528 | mailmessage_list_free(env_list); |
529 | } | 529 | } |
530 | } | 530 | } |