author | alwin <alwin> | 2004-03-12 14:12:00 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-03-12 14:12:00 (UTC) |
commit | d1929ef43f0eaaa17aa42196384d1ed925132873 (patch) (unidiff) | |
tree | eff911f93fe7919d7820e5a2e68b72f2f76143da | |
parent | d38384a6edb0110117e0297864f813b379d52789 (diff) | |
download | opie-d1929ef43f0eaaa17aa42196384d1ed925132873.zip opie-d1929ef43f0eaaa17aa42196384d1ed925132873.tar.gz opie-d1929ef43f0eaaa17aa42196384d1ed925132873.tar.bz2 |
some pointers embedded into osmart_pointer handling
21 files changed, 190 insertions, 172 deletions
diff --git a/noncore/net/mail/accountitem.cpp b/noncore/net/mail/accountitem.cpp index 396dcb7..3e12563 100644 --- a/noncore/net/mail/accountitem.cpp +++ b/noncore/net/mail/accountitem.cpp | |||
@@ -1,1140 +1,1133 @@ | |||
1 | 1 | ||
2 | #include "accountitem.h" | 2 | #include "accountitem.h" |
3 | #include "accountview.h" | 3 | #include "accountview.h" |
4 | #include "newmaildir.h" | 4 | #include "newmaildir.h" |
5 | #include "nntpgroupsdlg.h" | 5 | #include "nntpgroupsdlg.h" |
6 | #include "defines.h" | 6 | #include "defines.h" |
7 | 7 | ||
8 | /* OPIE */ | 8 | /* OPIE */ |
9 | #include <libmailwrapper/mailtypes.h> | 9 | #include <libmailwrapper/mailtypes.h> |
10 | #include <libmailwrapper/abstractmail.h> | 10 | #include <libmailwrapper/abstractmail.h> |
11 | #include <libmailwrapper/mailwrapper.h> | 11 | #include <libmailwrapper/mailwrapper.h> |
12 | #include <qpe/qpeapplication.h> | 12 | #include <qpe/qpeapplication.h> |
13 | 13 | ||
14 | /* QT */ | 14 | /* QT */ |
15 | #include <qpopupmenu.h> | 15 | #include <qpopupmenu.h> |
16 | #include <qmessagebox.h> | 16 | #include <qmessagebox.h> |
17 | 17 | ||
18 | #define SETPIX(x) if (!account->getOffline()) {setPixmap( 0,x);} else {setPixmap( 0, PIXMAP_OFFLINE );} | 18 | #define SETPIX(x) if (!account->getOffline()) {setPixmap( 0,x);} else {setPixmap( 0, PIXMAP_OFFLINE );} |
19 | /** | 19 | /** |
20 | * POP3 Account stuff | 20 | * POP3 Account stuff |
21 | */ | 21 | */ |
22 | POP3viewItem::POP3viewItem( POP3account *a, AccountView *parent ) | 22 | POP3viewItem::POP3viewItem( POP3account *a, AccountView *parent ) |
23 | : AccountViewItem( parent ) | 23 | : AccountViewItem( parent ) |
24 | { | 24 | { |
25 | account = a; | 25 | account = a; |
26 | wrapper = AbstractMail::getWrapper( account ); | 26 | wrapper = AbstractMail::getWrapper( account ); |
27 | SETPIX(PIXMAP_POP3FOLDER); | 27 | SETPIX(PIXMAP_POP3FOLDER); |
28 | #if 0 | 28 | #if 0 |
29 | if (!account->getOffline()) | 29 | if (!account->getOffline()) |
30 | { | 30 | { |
31 | setPixmap( 0, ); | 31 | setPixmap( 0, ); |
32 | } | 32 | } |
33 | else | 33 | else |
34 | { | 34 | { |
35 | setPixmap( 0, PIXMAP_OFFLINE ); | 35 | setPixmap( 0, PIXMAP_OFFLINE ); |
36 | } | 36 | } |
37 | #endif | 37 | #endif |
38 | setText( 0, account->getAccountName() ); | 38 | setText( 0, account->getAccountName() ); |
39 | setOpen( true ); | 39 | setOpen( true ); |
40 | } | 40 | } |
41 | 41 | ||
42 | POP3viewItem::~POP3viewItem() | 42 | POP3viewItem::~POP3viewItem() |
43 | { | 43 | { |
44 | delete wrapper; | 44 | delete wrapper; |
45 | } | 45 | } |
46 | 46 | ||
47 | AbstractMail *POP3viewItem::getWrapper() | 47 | AbstractMail *POP3viewItem::getWrapper() |
48 | { | 48 | { |
49 | return wrapper; | 49 | return wrapper; |
50 | } | 50 | } |
51 | 51 | ||
52 | void POP3viewItem::refresh( QList<RecMail> & ) | 52 | void POP3viewItem::refresh( QList<RecMail> & ) |
53 | { | 53 | { |
54 | refresh(); | 54 | refresh(); |
55 | } | 55 | } |
56 | 56 | ||
57 | void POP3viewItem::refresh() | 57 | void POP3viewItem::refresh() |
58 | { | 58 | { |
59 | if (account->getOffline()) return; | 59 | if (account->getOffline()) return; |
60 | QList<Folder> *folders = wrapper->listFolders(); | 60 | QValueList<FolderP> *folders = wrapper->listFolders(); |
61 | QListViewItem *child = firstChild(); | 61 | QListViewItem *child = firstChild(); |
62 | while ( child ) | 62 | while ( child ) |
63 | { | 63 | { |
64 | QListViewItem *tmp = child; | 64 | QListViewItem *tmp = child; |
65 | child = child->nextSibling(); | 65 | child = child->nextSibling(); |
66 | delete tmp; | 66 | delete tmp; |
67 | } | 67 | } |
68 | Folder *it; | 68 | QValueList<FolderP>::ConstIterator it; |
69 | QListViewItem*item = 0; | 69 | QListViewItem*item = 0; |
70 | for ( it = folders->first(); it; it = folders->next() ) | 70 | for ( it = folders->begin(); it!=folders->end(); ++it) |
71 | { | 71 | { |
72 | item = new POP3folderItem( it, this , item ); | 72 | item = new POP3folderItem( (*it), this , item ); |
73 | item->setSelectable(it->may_select()); | 73 | item->setSelectable( (*it)->may_select()); |
74 | } | 74 | } |
75 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
76 | folders->setAutoDelete(false); | ||
77 | delete folders; | 75 | delete folders; |
78 | } | 76 | } |
79 | 77 | ||
80 | RecBody POP3viewItem::fetchBody( const RecMail &mail ) | 78 | RecBody POP3viewItem::fetchBody( const RecMail &mail ) |
81 | { | 79 | { |
82 | qDebug( "POP3 fetchBody" ); | 80 | qDebug( "POP3 fetchBody" ); |
83 | return wrapper->fetchBody( mail ); | 81 | return wrapper->fetchBody( mail ); |
84 | } | 82 | } |
85 | 83 | ||
86 | QPopupMenu * POP3viewItem::getContextMenu() | 84 | QPopupMenu * POP3viewItem::getContextMenu() |
87 | { | 85 | { |
88 | QPopupMenu *m = new QPopupMenu(0); | 86 | QPopupMenu *m = new QPopupMenu(0); |
89 | if (m) | 87 | if (m) |
90 | { | 88 | { |
91 | if (!account->getOffline()) | 89 | if (!account->getOffline()) |
92 | { | 90 | { |
93 | m->insertItem(QObject::tr("Disconnect",contextName),0); | 91 | m->insertItem(QObject::tr("Disconnect",contextName),0); |
94 | m->insertItem(QObject::tr("Set offline",contextName),1); | 92 | m->insertItem(QObject::tr("Set offline",contextName),1); |
95 | } | 93 | } |
96 | else | 94 | else |
97 | { | 95 | { |
98 | m->insertItem(QObject::tr("Set online",contextName),1); | 96 | m->insertItem(QObject::tr("Set online",contextName),1); |
99 | } | 97 | } |
100 | } | 98 | } |
101 | return m; | 99 | return m; |
102 | } | 100 | } |
103 | 101 | ||
104 | void POP3viewItem::disconnect() | 102 | void POP3viewItem::disconnect() |
105 | { | 103 | { |
106 | QListViewItem *child = firstChild(); | 104 | QListViewItem *child = firstChild(); |
107 | while ( child ) | 105 | while ( child ) |
108 | { | 106 | { |
109 | QListViewItem *tmp = child; | 107 | QListViewItem *tmp = child; |
110 | child = child->nextSibling(); | 108 | child = child->nextSibling(); |
111 | delete tmp; | 109 | delete tmp; |
112 | } | 110 | } |
113 | wrapper->logout(); | 111 | wrapper->logout(); |
114 | } | 112 | } |
115 | 113 | ||
116 | void POP3viewItem::setOnOffline() | 114 | void POP3viewItem::setOnOffline() |
117 | { | 115 | { |
118 | if (!account->getOffline()) | 116 | if (!account->getOffline()) |
119 | { | 117 | { |
120 | disconnect(); | 118 | disconnect(); |
121 | } | 119 | } |
122 | account->setOffline(!account->getOffline()); | 120 | account->setOffline(!account->getOffline()); |
123 | account->save(); | 121 | account->save(); |
124 | SETPIX(PIXMAP_POP3FOLDER); | 122 | SETPIX(PIXMAP_POP3FOLDER); |
125 | refresh(); | 123 | refresh(); |
126 | } | 124 | } |
127 | 125 | ||
128 | void POP3viewItem::contextMenuSelected(int which) | 126 | void POP3viewItem::contextMenuSelected(int which) |
129 | { | 127 | { |
130 | switch (which) | 128 | switch (which) |
131 | { | 129 | { |
132 | case 0: | 130 | case 0: |
133 | disconnect(); | 131 | disconnect(); |
134 | break; | 132 | break; |
135 | case 1: | 133 | case 1: |
136 | setOnOffline(); | 134 | setOnOffline(); |
137 | break; | 135 | break; |
138 | } | 136 | } |
139 | } | 137 | } |
140 | 138 | ||
141 | POP3folderItem::~POP3folderItem() | 139 | POP3folderItem::~POP3folderItem() |
142 | {} | 140 | {} |
143 | 141 | ||
144 | POP3folderItem::POP3folderItem( Folder *folderInit, POP3viewItem *parent , QListViewItem*after ) | 142 | POP3folderItem::POP3folderItem( const FolderP&folderInit, POP3viewItem *parent , QListViewItem*after ) |
145 | : AccountViewItem( parent,after ) | 143 | : AccountViewItem(folderInit,parent,after ) |
146 | { | 144 | { |
147 | folder = folderInit; | ||
148 | pop3 = parent; | 145 | pop3 = parent; |
149 | if (folder->getDisplayName().lower()!="inbox") | 146 | if (folder->getDisplayName().lower()!="inbox") |
150 | { | 147 | { |
151 | setPixmap( 0, PIXMAP_POP3FOLDER ); | 148 | setPixmap( 0, PIXMAP_POP3FOLDER ); |
152 | } | 149 | } |
153 | else | 150 | else |
154 | { | 151 | { |
155 | setPixmap( 0, PIXMAP_INBOXFOLDER); | 152 | setPixmap( 0, PIXMAP_INBOXFOLDER); |
156 | } | 153 | } |
157 | setText( 0, folder->getDisplayName() ); | 154 | setText( 0, folder->getDisplayName() ); |
158 | } | 155 | } |
159 | 156 | ||
160 | void POP3folderItem::refresh(QList<RecMail>&target) | 157 | void POP3folderItem::refresh(QList<RecMail>&target) |
161 | { | 158 | { |
162 | if (folder->may_select()) | 159 | if (folder->may_select()) |
163 | pop3->getWrapper()->listMessages( folder->getName(),target ); | 160 | pop3->getWrapper()->listMessages( folder->getName(),target ); |
164 | } | 161 | } |
165 | 162 | ||
166 | RecBody POP3folderItem::fetchBody(const RecMail&aMail) | 163 | RecBody POP3folderItem::fetchBody(const RecMail&aMail) |
167 | { | 164 | { |
168 | return pop3->getWrapper()->fetchBody(aMail); | 165 | return pop3->getWrapper()->fetchBody(aMail); |
169 | } | 166 | } |
170 | 167 | ||
171 | QPopupMenu * POP3folderItem::getContextMenu() | 168 | QPopupMenu * POP3folderItem::getContextMenu() |
172 | { | 169 | { |
173 | QPopupMenu *m = new QPopupMenu(0); | 170 | QPopupMenu *m = new QPopupMenu(0); |
174 | if (m) | 171 | if (m) |
175 | { | 172 | { |
176 | m->insertItem(QObject::tr("Refresh header list",contextName),0); | 173 | m->insertItem(QObject::tr("Refresh header list",contextName),0); |
177 | m->insertItem(QObject::tr("Delete all mails",contextName),1); | 174 | m->insertItem(QObject::tr("Delete all mails",contextName),1); |
178 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); | 175 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); |
179 | } | 176 | } |
180 | return m; | 177 | return m; |
181 | } | 178 | } |
182 | 179 | ||
183 | void POP3folderItem::downloadMails() | 180 | void POP3folderItem::downloadMails() |
184 | { | 181 | { |
185 | AccountView*bl = pop3->accountView(); | 182 | AccountView*bl = pop3->accountView(); |
186 | if (!bl) return; | 183 | if (!bl) return; |
187 | bl->downloadMails(folder,pop3->getWrapper()); | 184 | bl->downloadMails(folder,pop3->getWrapper()); |
188 | } | 185 | } |
189 | 186 | ||
190 | void POP3folderItem::contextMenuSelected(int which) | 187 | void POP3folderItem::contextMenuSelected(int which) |
191 | { | 188 | { |
192 | AccountView * view = (AccountView*)listView(); | 189 | AccountView * view = (AccountView*)listView(); |
193 | switch (which) | 190 | switch (which) |
194 | { | 191 | { |
195 | case 0: | 192 | case 0: |
196 | /* must be 'cause pop3 lists are cached */ | 193 | /* must be 'cause pop3 lists are cached */ |
197 | pop3->getWrapper()->logout(); | 194 | pop3->getWrapper()->logout(); |
198 | view->refreshCurrent(); | 195 | view->refreshCurrent(); |
199 | break; | 196 | break; |
200 | case 1: | 197 | case 1: |
201 | deleteAllMail(pop3->getWrapper(),folder); | 198 | deleteAllMail(pop3->getWrapper(),folder); |
202 | break; | 199 | break; |
203 | case 2: | 200 | case 2: |
204 | downloadMails(); | 201 | downloadMails(); |
205 | break; | 202 | break; |
206 | default: | 203 | default: |
207 | break; | 204 | break; |
208 | } | 205 | } |
209 | } | 206 | } |
210 | 207 | ||
211 | /** | 208 | /** |
212 | * NNTP Account stuff | 209 | * NNTP Account stuff |
213 | */ | 210 | */ |
214 | NNTPviewItem::NNTPviewItem( NNTPaccount *a, AccountView *parent ) | 211 | NNTPviewItem::NNTPviewItem( NNTPaccount *a, AccountView *parent ) |
215 | : AccountViewItem( parent ) | 212 | : AccountViewItem( parent ) |
216 | { | 213 | { |
217 | account = a; | 214 | account = a; |
218 | wrapper = AbstractMail::getWrapper( account ); | 215 | wrapper = AbstractMail::getWrapper( account ); |
219 | //FIXME | 216 | //FIXME |
220 | SETPIX(PIXMAP_POP3FOLDER); | 217 | SETPIX(PIXMAP_POP3FOLDER); |
221 | #if 0 | 218 | #if 0 |
222 | if (!account->getOffline()) | 219 | if (!account->getOffline()) |
223 | { | 220 | { |
224 | setPixmap( 0, ); | 221 | setPixmap( 0, ); |
225 | } | 222 | } |
226 | else | 223 | else |
227 | { | 224 | { |
228 | setPixmap( 0, PIXMAP_OFFLINE ); | 225 | setPixmap( 0, PIXMAP_OFFLINE ); |
229 | } | 226 | } |
230 | #endif | 227 | #endif |
231 | setText( 0, account->getAccountName() ); | 228 | setText( 0, account->getAccountName() ); |
232 | setOpen( true ); | 229 | setOpen( true ); |
233 | } | 230 | } |
234 | 231 | ||
235 | NNTPviewItem::~NNTPviewItem() | 232 | NNTPviewItem::~NNTPviewItem() |
236 | { | 233 | { |
237 | delete wrapper; | 234 | delete wrapper; |
238 | } | 235 | } |
239 | 236 | ||
240 | AbstractMail *NNTPviewItem::getWrapper() | 237 | AbstractMail *NNTPviewItem::getWrapper() |
241 | { | 238 | { |
242 | return wrapper; | 239 | return wrapper; |
243 | } | 240 | } |
244 | 241 | ||
245 | void NNTPviewItem::refresh( QList<RecMail> & ) | 242 | void NNTPviewItem::refresh( QList<RecMail> & ) |
246 | { | 243 | { |
247 | refresh(); | 244 | refresh(); |
248 | } | 245 | } |
249 | 246 | ||
250 | void NNTPviewItem::refresh() | 247 | void NNTPviewItem::refresh() |
251 | { | 248 | { |
252 | if (account->getOffline()) return; | 249 | if (account->getOffline()) return; |
253 | QList<Folder> *folders = wrapper->listFolders(); | 250 | QValueList<FolderP> *folders = wrapper->listFolders(); |
251 | |||
254 | QListViewItem *child = firstChild(); | 252 | QListViewItem *child = firstChild(); |
255 | while ( child ) | 253 | while ( child ) |
256 | { | 254 | { |
257 | QListViewItem *tmp = child; | 255 | QListViewItem *tmp = child; |
258 | child = child->nextSibling(); | 256 | child = child->nextSibling(); |
259 | delete tmp; | 257 | delete tmp; |
260 | } | 258 | } |
261 | Folder *it; | 259 | QValueList<FolderP>::ConstIterator it; |
262 | QListViewItem*item = 0; | 260 | QListViewItem*item = 0; |
263 | for ( it = folders->first(); it; it = folders->next() ) | 261 | for ( it = folders->begin(); it!=folders->end(); ++it) |
264 | { | 262 | { |
265 | item = new NNTPfolderItem( it, this , item ); | 263 | item = new NNTPfolderItem( (*it), this , item ); |
266 | item->setSelectable(it->may_select()); | 264 | item->setSelectable( (*it)->may_select()); |
267 | } | 265 | } |
268 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
269 | folders->setAutoDelete(false); | ||
270 | delete folders; | 266 | delete folders; |
271 | } | 267 | } |
272 | 268 | ||
273 | RecBody NNTPviewItem::fetchBody( const RecMail &mail ) | 269 | RecBody NNTPviewItem::fetchBody( const RecMail &mail ) |
274 | { | 270 | { |
275 | qDebug( "NNTP fetchBody" ); | 271 | qDebug( "NNTP fetchBody" ); |
276 | return wrapper->fetchBody( mail ); | 272 | return wrapper->fetchBody( mail ); |
277 | } | 273 | } |
278 | 274 | ||
279 | QPopupMenu * NNTPviewItem::getContextMenu() | 275 | QPopupMenu * NNTPviewItem::getContextMenu() |
280 | { | 276 | { |
281 | QPopupMenu *m = new QPopupMenu(0); | 277 | QPopupMenu *m = new QPopupMenu(0); |
282 | if (m) | 278 | if (m) |
283 | { | 279 | { |
284 | if (!account->getOffline()) | 280 | if (!account->getOffline()) |
285 | { | 281 | { |
286 | m->insertItem(QObject::tr("Disconnect",contextName),0); | 282 | m->insertItem(QObject::tr("Disconnect",contextName),0); |
287 | m->insertItem(QObject::tr("Set offline",contextName),1); | 283 | m->insertItem(QObject::tr("Set offline",contextName),1); |
288 | m->insertItem(QObject::tr("(Un-)Subscribe groups",contextName),2); | 284 | m->insertItem(QObject::tr("(Un-)Subscribe groups",contextName),2); |
289 | } | 285 | } |
290 | else | 286 | else |
291 | { | 287 | { |
292 | m->insertItem(QObject::tr("Set online",contextName),1); | 288 | m->insertItem(QObject::tr("Set online",contextName),1); |
293 | } | 289 | } |
294 | } | 290 | } |
295 | return m; | 291 | return m; |
296 | } | 292 | } |
297 | 293 | ||
298 | void NNTPviewItem::subscribeGroups() | 294 | void NNTPviewItem::subscribeGroups() |
299 | { | 295 | { |
300 | NNTPGroupsDlg dlg(account); | 296 | NNTPGroupsDlg dlg(account); |
301 | if (QPEApplication::execDialog(&dlg)== QDialog::Accepted ){ | 297 | if (QPEApplication::execDialog(&dlg)== QDialog::Accepted ){ |
302 | refresh(); | 298 | refresh(); |
303 | } | 299 | } |
304 | } | 300 | } |
305 | 301 | ||
306 | void NNTPviewItem::disconnect() | 302 | void NNTPviewItem::disconnect() |
307 | { | 303 | { |
308 | QListViewItem *child = firstChild(); | 304 | QListViewItem *child = firstChild(); |
309 | while ( child ) | 305 | while ( child ) |
310 | { | 306 | { |
311 | QListViewItem *tmp = child; | 307 | QListViewItem *tmp = child; |
312 | child = child->nextSibling(); | 308 | child = child->nextSibling(); |
313 | delete tmp; | 309 | delete tmp; |
314 | } | 310 | } |
315 | wrapper->logout(); | 311 | wrapper->logout(); |
316 | } | 312 | } |
317 | 313 | ||
318 | void NNTPviewItem::setOnOffline() | 314 | void NNTPviewItem::setOnOffline() |
319 | { | 315 | { |
320 | if (!account->getOffline()) | 316 | if (!account->getOffline()) |
321 | { | 317 | { |
322 | disconnect(); | 318 | disconnect(); |
323 | } | 319 | } |
324 | account->setOffline(!account->getOffline()); | 320 | account->setOffline(!account->getOffline()); |
325 | account->save(); | 321 | account->save(); |
326 | //FIXME | 322 | //FIXME |
327 | SETPIX(PIXMAP_POP3FOLDER); | 323 | SETPIX(PIXMAP_POP3FOLDER); |
328 | refresh(); | 324 | refresh(); |
329 | } | 325 | } |
330 | 326 | ||
331 | void NNTPviewItem::contextMenuSelected(int which) | 327 | void NNTPviewItem::contextMenuSelected(int which) |
332 | { | 328 | { |
333 | switch (which) | 329 | switch (which) |
334 | { | 330 | { |
335 | case 0: | 331 | case 0: |
336 | disconnect(); | 332 | disconnect(); |
337 | break; | 333 | break; |
338 | case 1: | 334 | case 1: |
339 | setOnOffline(); | 335 | setOnOffline(); |
340 | break; | 336 | break; |
341 | case 2: | 337 | case 2: |
342 | subscribeGroups(); | 338 | subscribeGroups(); |
343 | break; | 339 | break; |
344 | } | 340 | } |
345 | } | 341 | } |
346 | 342 | ||
347 | NNTPfolderItem::~NNTPfolderItem() | 343 | NNTPfolderItem::~NNTPfolderItem() |
348 | {} | 344 | {} |
349 | 345 | ||
350 | NNTPfolderItem::NNTPfolderItem( Folder *folderInit, NNTPviewItem *parent , QListViewItem*after ) | 346 | NNTPfolderItem::NNTPfolderItem( const FolderP &folderInit, NNTPviewItem *parent , QListViewItem*after ) |
351 | : AccountViewItem( parent,after ) | 347 | : AccountViewItem( folderInit, parent,after ) |
352 | { | 348 | { |
353 | folder = folderInit; | ||
354 | nntp = parent; | 349 | nntp = parent; |
355 | if (folder->getDisplayName().lower()!="inbox") | 350 | if (folder->getDisplayName().lower()!="inbox") |
356 | { | 351 | { |
357 | setPixmap( 0, PIXMAP_POP3FOLDER ); | 352 | setPixmap( 0, PIXMAP_POP3FOLDER ); |
358 | } | 353 | } |
359 | else | 354 | else |
360 | { | 355 | { |
361 | setPixmap( 0, PIXMAP_INBOXFOLDER); | 356 | setPixmap( 0, PIXMAP_INBOXFOLDER); |
362 | } | 357 | } |
363 | setText( 0, folder->getDisplayName() ); | 358 | setText( 0, folder->getDisplayName() ); |
364 | } | 359 | } |
365 | 360 | ||
366 | void NNTPfolderItem::refresh(QList<RecMail>&target) | 361 | void NNTPfolderItem::refresh(QList<RecMail>&target) |
367 | { | 362 | { |
368 | if (folder->may_select()) | 363 | if (folder->may_select()) |
369 | nntp->getWrapper()->listMessages( folder->getName(),target ); | 364 | nntp->getWrapper()->listMessages( folder->getName(),target ); |
370 | } | 365 | } |
371 | 366 | ||
372 | RecBody NNTPfolderItem::fetchBody(const RecMail&aMail) | 367 | RecBody NNTPfolderItem::fetchBody(const RecMail&aMail) |
373 | { | 368 | { |
374 | return nntp->getWrapper()->fetchBody(aMail); | 369 | return nntp->getWrapper()->fetchBody(aMail); |
375 | } | 370 | } |
376 | 371 | ||
377 | QPopupMenu * NNTPfolderItem::getContextMenu() | 372 | QPopupMenu * NNTPfolderItem::getContextMenu() |
378 | { | 373 | { |
379 | QPopupMenu *m = new QPopupMenu(0); | 374 | QPopupMenu *m = new QPopupMenu(0); |
380 | if (m) | 375 | if (m) |
381 | { | 376 | { |
382 | m->insertItem(QObject::tr("Refresh header list",contextName),0); | 377 | m->insertItem(QObject::tr("Refresh header list",contextName),0); |
383 | m->insertItem(QObject::tr("Copy all postings",contextName),1); | 378 | m->insertItem(QObject::tr("Copy all postings",contextName),1); |
384 | } | 379 | } |
385 | return m; | 380 | return m; |
386 | } | 381 | } |
387 | 382 | ||
388 | void NNTPfolderItem::downloadMails() | 383 | void NNTPfolderItem::downloadMails() |
389 | { | 384 | { |
390 | AccountView*bl = nntp->accountView(); | 385 | AccountView*bl = nntp->accountView(); |
391 | if (!bl) return; | 386 | if (!bl) return; |
392 | bl->downloadMails(folder,nntp->getWrapper()); | 387 | bl->downloadMails(folder,nntp->getWrapper()); |
393 | } | 388 | } |
394 | 389 | ||
395 | void NNTPfolderItem::contextMenuSelected(int which) | 390 | void NNTPfolderItem::contextMenuSelected(int which) |
396 | { | 391 | { |
397 | AccountView * view = (AccountView*)listView(); | 392 | AccountView * view = (AccountView*)listView(); |
398 | switch (which) | 393 | switch (which) |
399 | { | 394 | { |
400 | case 0: | 395 | case 0: |
401 | /* must be 'cause pop3 lists are cached */ | 396 | /* must be 'cause pop3 lists are cached */ |
402 | nntp->getWrapper()->logout(); | 397 | nntp->getWrapper()->logout(); |
403 | view->refreshCurrent(); | 398 | view->refreshCurrent(); |
404 | break; | 399 | break; |
405 | case 1: | 400 | case 1: |
406 | downloadMails(); | 401 | downloadMails(); |
407 | break; | 402 | break; |
408 | default: | 403 | default: |
409 | break; | 404 | break; |
410 | } | 405 | } |
411 | } | 406 | } |
412 | 407 | ||
413 | /** | 408 | /** |
414 | * IMAP Account stuff | 409 | * IMAP Account stuff |
415 | */ | 410 | */ |
416 | IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent ) | 411 | IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent ) |
417 | : AccountViewItem( parent ) | 412 | : AccountViewItem( parent ) |
418 | { | 413 | { |
419 | account = a; | 414 | account = a; |
420 | wrapper = AbstractMail::getWrapper( account ); | 415 | wrapper = AbstractMail::getWrapper( account ); |
421 | SETPIX(PIXMAP_IMAPFOLDER); | 416 | SETPIX(PIXMAP_IMAPFOLDER); |
422 | setText( 0, account->getAccountName() ); | 417 | setText( 0, account->getAccountName() ); |
423 | setOpen( true ); | 418 | setOpen( true ); |
424 | } | 419 | } |
425 | 420 | ||
426 | IMAPviewItem::~IMAPviewItem() | 421 | IMAPviewItem::~IMAPviewItem() |
427 | { | 422 | { |
428 | delete wrapper; | 423 | delete wrapper; |
429 | } | 424 | } |
430 | 425 | ||
431 | AbstractMail *IMAPviewItem::getWrapper() | 426 | AbstractMail *IMAPviewItem::getWrapper() |
432 | { | 427 | { |
433 | return wrapper; | 428 | return wrapper; |
434 | } | 429 | } |
435 | 430 | ||
436 | void IMAPviewItem::refresh(QList<RecMail>&) | 431 | void IMAPviewItem::refresh(QList<RecMail>&) |
437 | { | 432 | { |
438 | refreshFolders(false); | 433 | refreshFolders(false); |
439 | } | 434 | } |
440 | 435 | ||
441 | const QStringList&IMAPviewItem::subFolders() | 436 | const QStringList&IMAPviewItem::subFolders() |
442 | { | 437 | { |
443 | return currentFolders; | 438 | return currentFolders; |
444 | } | 439 | } |
445 | 440 | ||
446 | void IMAPviewItem::refreshFolders(bool force) | 441 | void IMAPviewItem::refreshFolders(bool force) |
447 | { | 442 | { |
448 | if (childCount()>0 && force==false) return; | 443 | if (childCount()>0 && force==false) return; |
449 | if (account->getOffline()) return; | 444 | if (account->getOffline()) return; |
450 | 445 | ||
451 | removeChilds(); | 446 | removeChilds(); |
452 | currentFolders.clear(); | 447 | currentFolders.clear(); |
453 | QList<Folder> *folders = wrapper->listFolders(); | 448 | QValueList<FolderP> * folders = wrapper->listFolders(); |
454 | 449 | ||
455 | Folder *it; | 450 | QValueList<FolderP>::Iterator it; |
456 | QListViewItem*item = 0; | 451 | QListViewItem*item = 0; |
457 | QListViewItem*titem = 0; | 452 | QListViewItem*titem = 0; |
458 | QString fname,del,search; | 453 | QString fname,del,search; |
459 | int pos; | 454 | int pos; |
460 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
461 | folders->setAutoDelete(false); | ||
462 | 455 | ||
463 | for ( it = folders->first(); it; it = folders->next() ) | 456 | for ( it = folders->begin(); it!=folders->end(); ++it) |
464 | { | 457 | { |
465 | if (it->getDisplayName().lower()=="inbox") | 458 | if ((*it)->getDisplayName().lower()=="inbox") |
466 | { | 459 | { |
467 | item = new IMAPfolderItem( it, this , item ); | 460 | item = new IMAPfolderItem( (*it), this , item ); |
468 | folders->remove(it); | 461 | folders->remove(it); |
469 | qDebug("inbox found"); | 462 | qDebug("inbox found"); |
470 | break; | 463 | break; |
471 | } | 464 | } |
472 | } | 465 | } |
473 | for ( it = folders->first(); it; it = folders->next() ) | 466 | for ( it = folders->begin(); it!=folders->end(); ++it) |
474 | { | 467 | { |
475 | fname = it->getDisplayName(); | 468 | fname = (*it)->getDisplayName(); |
476 | currentFolders.append(it->getName()); | 469 | currentFolders.append((*it)->getName()); |
477 | pos = fname.findRev(it->Separator()); | 470 | pos = fname.findRev((*it)->Separator()); |
478 | if (pos != -1) | 471 | if (pos != -1) |
479 | { | 472 | { |
480 | fname = fname.left(pos); | 473 | fname = fname.left(pos); |
481 | } | 474 | } |
482 | IMAPfolderItem*pitem = (IMAPfolderItem*)findSubItem(fname); | 475 | IMAPfolderItem*pitem = (IMAPfolderItem*)findSubItem(fname); |
483 | if (pitem) | 476 | if (pitem) |
484 | { | 477 | { |
485 | titem = item; | 478 | titem = item; |
486 | item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this); | 479 | item = new IMAPfolderItem( (*it),pitem,pitem->firstChild(),this); |
487 | /* setup the short name */ | 480 | /* setup the short name */ |
488 | item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1)); | 481 | item->setText(0,(*it)->getDisplayName().right((*it)->getDisplayName().length()-pos-1)); |
489 | item = titem; | 482 | item = titem; |
490 | } | 483 | } |
491 | else | 484 | else |
492 | { | 485 | { |
493 | item = new IMAPfolderItem( it, this , item ); | 486 | item = new IMAPfolderItem( (*it), this , item ); |
494 | } | 487 | } |
495 | } | 488 | } |
496 | delete folders; | 489 | delete folders; |
497 | } | 490 | } |
498 | 491 | ||
499 | QPopupMenu * IMAPviewItem::getContextMenu() | 492 | QPopupMenu * IMAPviewItem::getContextMenu() |
500 | { | 493 | { |
501 | QPopupMenu *m = new QPopupMenu(0); | 494 | QPopupMenu *m = new QPopupMenu(0); |
502 | if (m) | 495 | if (m) |
503 | { | 496 | { |
504 | if (!account->getOffline()) | 497 | if (!account->getOffline()) |
505 | { | 498 | { |
506 | m->insertItem(QObject::tr("Refresh folder list",contextName),0); | 499 | m->insertItem(QObject::tr("Refresh folder list",contextName),0); |
507 | m->insertItem(QObject::tr("Create new folder",contextName),1); | 500 | m->insertItem(QObject::tr("Create new folder",contextName),1); |
508 | m->insertSeparator(); | 501 | m->insertSeparator(); |
509 | m->insertItem(QObject::tr("Disconnect",contextName),2); | 502 | m->insertItem(QObject::tr("Disconnect",contextName),2); |
510 | m->insertItem(QObject::tr("Set offline",contextName),3); | 503 | m->insertItem(QObject::tr("Set offline",contextName),3); |
511 | } | 504 | } |
512 | else | 505 | else |
513 | { | 506 | { |
514 | m->insertItem(QObject::tr("Set online",contextName),3); | 507 | m->insertItem(QObject::tr("Set online",contextName),3); |
515 | } | 508 | } |
516 | } | 509 | } |
517 | return m; | 510 | return m; |
518 | } | 511 | } |
519 | 512 | ||
520 | void IMAPviewItem::createNewFolder() | 513 | void IMAPviewItem::createNewFolder() |
521 | { | 514 | { |
522 | Newmdirdlg ndirdlg; | 515 | Newmdirdlg ndirdlg; |
523 | if ( QPEApplication::execDialog( &ndirdlg )) | 516 | if ( QPEApplication::execDialog( &ndirdlg )) |
524 | { | 517 | { |
525 | QString ndir = ndirdlg.Newdir(); | 518 | QString ndir = ndirdlg.Newdir(); |
526 | bool makesubs = ndirdlg.subpossible(); | 519 | bool makesubs = ndirdlg.subpossible(); |
527 | QString delemiter = "/"; | 520 | QString delemiter = "/"; |
528 | IMAPfolderItem*item = (IMAPfolderItem*)firstChild(); | 521 | IMAPfolderItem*item = (IMAPfolderItem*)firstChild(); |
529 | if (item) | 522 | if (item) |
530 | { | 523 | { |
531 | delemiter = item->Delemiter(); | 524 | delemiter = item->Delemiter(); |
532 | } | 525 | } |
533 | if (wrapper->createMbox(ndir,0,delemiter,makesubs)) | 526 | if (wrapper->createMbox(ndir,0,delemiter,makesubs)) |
534 | { | 527 | { |
535 | refreshFolders(true); | 528 | refreshFolders(true); |
536 | } | 529 | } |
537 | } | 530 | } |
538 | } | 531 | } |
539 | 532 | ||
540 | void IMAPviewItem::contextMenuSelected(int id) | 533 | void IMAPviewItem::contextMenuSelected(int id) |
541 | { | 534 | { |
542 | qDebug("Id selected: %i",id); | 535 | qDebug("Id selected: %i",id); |
543 | switch (id) | 536 | switch (id) |
544 | { | 537 | { |
545 | case 0: | 538 | case 0: |
546 | refreshFolders(true); | 539 | refreshFolders(true); |
547 | break; | 540 | break; |
548 | case 1: | 541 | case 1: |
549 | createNewFolder(); | 542 | createNewFolder(); |
550 | break; | 543 | break; |
551 | case 2: | 544 | case 2: |
552 | removeChilds(); | 545 | removeChilds(); |
553 | wrapper->logout(); | 546 | wrapper->logout(); |
554 | break; | 547 | break; |
555 | case 3: | 548 | case 3: |
556 | if (account->getOffline()==false) | 549 | if (account->getOffline()==false) |
557 | { | 550 | { |
558 | removeChilds(); | 551 | removeChilds(); |
559 | wrapper->logout(); | 552 | wrapper->logout(); |
560 | } | 553 | } |
561 | account->setOffline(!account->getOffline()); | 554 | account->setOffline(!account->getOffline()); |
562 | account->save(); | 555 | account->save(); |
563 | SETPIX(PIXMAP_IMAPFOLDER); | 556 | SETPIX(PIXMAP_IMAPFOLDER); |
564 | refreshFolders(false); | 557 | refreshFolders(false); |
565 | break; | 558 | break; |
566 | default: | 559 | default: |
567 | break; | 560 | break; |
568 | } | 561 | } |
569 | } | 562 | } |
570 | 563 | ||
571 | RecBody IMAPviewItem::fetchBody(const RecMail&) | 564 | RecBody IMAPviewItem::fetchBody(const RecMail&) |
572 | { | 565 | { |
573 | return RecBody(); | 566 | return RecBody(); |
574 | } | 567 | } |
575 | 568 | ||
576 | bool IMAPviewItem::offline() | 569 | bool IMAPviewItem::offline() |
577 | { | 570 | { |
578 | return account->getOffline(); | 571 | return account->getOffline(); |
579 | } | 572 | } |
580 | 573 | ||
581 | IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after ) | 574 | IMAPfolderItem::IMAPfolderItem( const FolderP& folderInit, IMAPviewItem *parent , QListViewItem*after ) |
582 | : AccountViewItem( parent , after ) | 575 | : AccountViewItem( folderInit, parent , after ) |
583 | { | 576 | { |
584 | folder = folderInit; | ||
585 | imap = parent; | 577 | imap = parent; |
586 | if (folder->getDisplayName().lower()!="inbox") | 578 | if (folder->getDisplayName().lower()!="inbox") |
587 | { | 579 | { |
588 | setPixmap( 0, PIXMAP_IMAPFOLDER ); | 580 | setPixmap( 0, PIXMAP_IMAPFOLDER ); |
589 | } | 581 | } |
590 | else | 582 | else |
591 | { | 583 | { |
592 | setPixmap( 0, PIXMAP_INBOXFOLDER); | 584 | setPixmap( 0, PIXMAP_INBOXFOLDER); |
593 | } | 585 | } |
594 | setText( 0, folder->getDisplayName() ); | 586 | setText( 0, folder->getDisplayName() ); |
595 | } | 587 | } |
596 | 588 | ||
597 | IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ) | 589 | IMAPfolderItem::IMAPfolderItem(const FolderP &folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ) |
598 | : AccountViewItem( parent,after ) | 590 | : AccountViewItem(folderInit, parent,after ) |
599 | { | 591 | { |
600 | folder = folderInit; | ||
601 | imap = master; | 592 | imap = master; |
602 | if (folder->getDisplayName().lower()!="inbox") | 593 | if (folder->getDisplayName().lower()!="inbox") |
603 | { | 594 | { |
604 | setPixmap( 0, PIXMAP_IMAPFOLDER ); | 595 | setPixmap( 0, PIXMAP_IMAPFOLDER ); |
605 | } | 596 | } |
606 | else | 597 | else |
607 | { | 598 | { |
608 | setPixmap( 0, PIXMAP_INBOXFOLDER); | 599 | setPixmap( 0, PIXMAP_INBOXFOLDER); |
609 | } | 600 | } |
610 | setText( 0, folder->getDisplayName() ); | 601 | setText( 0, folder->getDisplayName() ); |
611 | } | 602 | } |
612 | 603 | ||
613 | IMAPfolderItem::~IMAPfolderItem() | 604 | IMAPfolderItem::~IMAPfolderItem() |
614 | {} | 605 | {} |
615 | 606 | ||
616 | const QString& IMAPfolderItem::Delemiter()const | 607 | const QString& IMAPfolderItem::Delemiter()const |
617 | { | 608 | { |
618 | return folder->Separator(); | 609 | return folder->Separator(); |
619 | } | 610 | } |
620 | 611 | ||
621 | void IMAPfolderItem::refresh(QList<RecMail>&target) | 612 | void IMAPfolderItem::refresh(QList<RecMail>&target) |
622 | { | 613 | { |
623 | if (folder->may_select()) | 614 | if (folder->may_select()) |
624 | { | 615 | { |
625 | imap->getWrapper()->listMessages( folder->getName(),target ); | 616 | imap->getWrapper()->listMessages( folder->getName(),target ); |
626 | } | 617 | } |
627 | else | 618 | else |
628 | { | 619 | { |
629 | target.clear(); | 620 | target.clear(); |
630 | } | 621 | } |
631 | } | 622 | } |
632 | 623 | ||
633 | RecBody IMAPfolderItem::fetchBody(const RecMail&aMail) | 624 | RecBody IMAPfolderItem::fetchBody(const RecMail&aMail) |
634 | { | 625 | { |
635 | return imap->getWrapper()->fetchBody(aMail); | 626 | return imap->getWrapper()->fetchBody(aMail); |
636 | } | 627 | } |
637 | 628 | ||
638 | QPopupMenu * IMAPfolderItem::getContextMenu() | 629 | QPopupMenu * IMAPfolderItem::getContextMenu() |
639 | { | 630 | { |
640 | QPopupMenu *m = new QPopupMenu(0); | 631 | QPopupMenu *m = new QPopupMenu(0); |
641 | if (m) | 632 | if (m) |
642 | { | 633 | { |
643 | if (folder->may_select()) | 634 | if (folder->may_select()) |
644 | { | 635 | { |
645 | m->insertItem(QObject::tr("Refresh header list",contextName),0); | 636 | m->insertItem(QObject::tr("Refresh header list",contextName),0); |
646 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),4); | 637 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),4); |
647 | m->insertItem(QObject::tr("Delete all mails",contextName),1); | 638 | m->insertItem(QObject::tr("Delete all mails",contextName),1); |
648 | } | 639 | } |
649 | if (folder->no_inferior()==false) | 640 | if (folder->no_inferior()==false) |
650 | { | 641 | { |
651 | m->insertItem(QObject::tr("Create new subfolder",contextName),2); | 642 | m->insertItem(QObject::tr("Create new subfolder",contextName),2); |
652 | } | 643 | } |
653 | if (folder->getDisplayName().lower()!="inbox") | 644 | if (folder->getDisplayName().lower()!="inbox") |
654 | { | 645 | { |
655 | m->insertItem(QObject::tr("Delete folder",contextName),3); | 646 | m->insertItem(QObject::tr("Delete folder",contextName),3); |
656 | } | 647 | } |
657 | } | 648 | } |
658 | return m; | 649 | return m; |
659 | } | 650 | } |
660 | 651 | ||
661 | void IMAPfolderItem::createNewFolder() | 652 | void IMAPfolderItem::createNewFolder() |
662 | { | 653 | { |
663 | Newmdirdlg ndirdlg; | 654 | Newmdirdlg ndirdlg; |
664 | if ( QPEApplication::execDialog( &ndirdlg ) ) | 655 | if ( QPEApplication::execDialog( &ndirdlg ) ) |
665 | { | 656 | { |
666 | QString ndir = ndirdlg.Newdir(); | 657 | QString ndir = ndirdlg.Newdir(); |
667 | bool makesubs = ndirdlg.subpossible(); | 658 | bool makesubs = ndirdlg.subpossible(); |
668 | QString delemiter = Delemiter(); | 659 | QString delemiter = Delemiter(); |
669 | if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) | 660 | if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) |
670 | { | 661 | { |
671 | imap->refreshFolders(true); | 662 | imap->refreshFolders(true); |
672 | } | 663 | } |
673 | } | 664 | } |
674 | } | 665 | } |
675 | 666 | ||
676 | void IMAPfolderItem::deleteFolder() | 667 | void IMAPfolderItem::deleteFolder() |
677 | { | 668 | { |
678 | int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), | 669 | int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), |
679 | QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), | 670 | QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), |
680 | QObject::tr("Yes",contextName), | 671 | QObject::tr("Yes",contextName), |
681 | QObject::tr("No",contextName),QString::null,1,1); | 672 | QObject::tr("No",contextName),QString::null,1,1); |
682 | qDebug("Auswahl: %i",yesno); | 673 | qDebug("Auswahl: %i",yesno); |
683 | if (yesno == 0) | 674 | if (yesno == 0) |
684 | { | 675 | { |
685 | if (imap->getWrapper()->deleteMbox(folder)) | 676 | if (imap->getWrapper()->deleteMbox(folder)) |
686 | { | 677 | { |
687 | QListView*v=listView(); | 678 | QListView*v=listView(); |
688 | IMAPviewItem * box = imap; | 679 | IMAPviewItem * box = imap; |
689 | /* be carefull - after that this object is destroyd so don't use | 680 | /* be carefull - after that this object is destroyd so don't use |
690 | * any member of it after that call!!*/ | 681 | * any member of it after that call!!*/ |
691 | imap->refreshFolders(true); | 682 | imap->refreshFolders(true); |
692 | if (v) | 683 | if (v) |
693 | { | 684 | { |
694 | v->setSelected(box,true); | 685 | v->setSelected(box,true); |
695 | } | 686 | } |
696 | } | 687 | } |
697 | } | 688 | } |
698 | } | 689 | } |
699 | 690 | ||
700 | void IMAPfolderItem::downloadMails() | 691 | void IMAPfolderItem::downloadMails() |
701 | { | 692 | { |
702 | AccountView*bl = imap->accountView(); | 693 | AccountView*bl = imap->accountView(); |
703 | if (!bl) return; | 694 | if (!bl) return; |
704 | bl->downloadMails(folder,imap->getWrapper()); | 695 | bl->downloadMails(folder,imap->getWrapper()); |
705 | } | 696 | } |
706 | 697 | ||
707 | void IMAPfolderItem::contextMenuSelected(int id) | 698 | void IMAPfolderItem::contextMenuSelected(int id) |
708 | { | 699 | { |
709 | qDebug("Selected id: %i",id); | 700 | qDebug("Selected id: %i",id); |
710 | AccountView * view = (AccountView*)listView(); | 701 | AccountView * view = (AccountView*)listView(); |
711 | switch(id) | 702 | switch(id) |
712 | { | 703 | { |
713 | case 0: | 704 | case 0: |
714 | view->refreshCurrent(); | 705 | view->refreshCurrent(); |
715 | break; | 706 | break; |
716 | case 1: | 707 | case 1: |
717 | deleteAllMail(imap->getWrapper(),folder); | 708 | deleteAllMail(imap->getWrapper(),folder); |
718 | break; | 709 | break; |
719 | case 2: | 710 | case 2: |
720 | createNewFolder(); | 711 | createNewFolder(); |
721 | break; | 712 | break; |
722 | case 3: | 713 | case 3: |
723 | deleteFolder(); | 714 | deleteFolder(); |
724 | break; | 715 | break; |
725 | case 4: | 716 | case 4: |
726 | downloadMails(); | 717 | downloadMails(); |
727 | break; | 718 | break; |
728 | default: | 719 | default: |
729 | break; | 720 | break; |
730 | } | 721 | } |
731 | } | 722 | } |
732 | 723 | ||
733 | /** | 724 | /** |
734 | * MH Account stuff | 725 | * MH Account stuff |
735 | */ | 726 | */ |
736 | /* MH is a little bit different - the top folder can contains messages other than in IMAP and | 727 | /* MH is a little bit different - the top folder can contains messages other than in IMAP and |
737 | POP3 and MBOX */ | 728 | POP3 and MBOX */ |
738 | MHviewItem::MHviewItem( const QString&aPath, AccountView *parent ) | 729 | MHviewItem::MHviewItem( const QString&aPath, AccountView *parent ) |
739 | : AccountViewItem( parent ) | 730 | : AccountViewItem( parent ) |
740 | { | 731 | { |
741 | m_Path = aPath; | 732 | m_Path = aPath; |
742 | /* be carefull - the space within settext is wanted - thats why the string twice */ | 733 | /* be carefull - the space within settext is wanted - thats why the string twice */ |
743 | wrapper = AbstractMail::getWrapper( m_Path,"Local Folders"); | 734 | wrapper = AbstractMail::getWrapper( m_Path,"Local Folders"); |
744 | setPixmap( 0, PIXMAP_LOCALFOLDER ); | 735 | setPixmap( 0, PIXMAP_LOCALFOLDER ); |
745 | setText( 0, " Local Folders" ); | 736 | setText( 0, " Local Folders" ); |
746 | setOpen( true ); | 737 | setOpen( true ); |
747 | folder = 0; | 738 | folder = 0; |
748 | } | 739 | } |
749 | 740 | ||
750 | MHviewItem::~MHviewItem() | 741 | MHviewItem::~MHviewItem() |
751 | { | 742 | { |
752 | delete wrapper; | 743 | delete wrapper; |
753 | } | 744 | } |
754 | 745 | ||
755 | AbstractMail *MHviewItem::getWrapper() | 746 | AbstractMail *MHviewItem::getWrapper() |
756 | { | 747 | { |
757 | return wrapper; | 748 | return wrapper; |
758 | } | 749 | } |
759 | 750 | ||
760 | void MHviewItem::refresh( QList<RecMail> & target) | 751 | void MHviewItem::refresh( QList<RecMail> & target) |
761 | { | 752 | { |
762 | refresh(false); | 753 | refresh(false); |
763 | getWrapper()->listMessages( "",target ); | 754 | getWrapper()->listMessages( "",target ); |
764 | } | 755 | } |
765 | 756 | ||
766 | void MHviewItem::refresh(bool force) | 757 | void MHviewItem::refresh(bool force) |
767 | { | 758 | { |
768 | if (childCount()>0 && force==false) return; | 759 | if (childCount()>0 && force==false) return; |
769 | removeChilds(); | 760 | removeChilds(); |
770 | currentFolders.clear(); | 761 | currentFolders.clear(); |
771 | QList<Folder> *folders = wrapper->listFolders(); | 762 | QValueList<FolderP> *folders = wrapper->listFolders(); |
772 | Folder *it; | 763 | QValueList<FolderP>::ConstIterator it; |
773 | MHfolderItem*item = 0; | 764 | MHfolderItem*item = 0; |
774 | MHfolderItem*pmaster = 0; | 765 | MHfolderItem*pmaster = 0; |
775 | QString fname = ""; | 766 | QString fname = ""; |
776 | int pos; | 767 | int pos; |
777 | for ( it = folders->first(); it; it = folders->next() ) | 768 | for ( it = folders->begin(); it!=folders->end(); ++it) |
778 | { | 769 | { |
779 | fname = it->getDisplayName(); | 770 | fname = (*it)->getDisplayName(); |
780 | /* this folder itself */ | 771 | /* this folder itself */ |
781 | if (fname=="/") | 772 | if (fname=="/") |
782 | { | 773 | { |
783 | currentFolders.append(fname); | 774 | currentFolders.append(fname); |
784 | folder = it; | 775 | folder = (*it); |
785 | continue; | 776 | continue; |
786 | } | 777 | } |
787 | currentFolders.append(fname); | 778 | currentFolders.append(fname); |
788 | pos = fname.findRev("/"); | 779 | pos = fname.findRev("/"); |
789 | if (pos > 0) | 780 | if (pos > 0) |
790 | { | 781 | { |
791 | fname = fname.left(pos); | 782 | fname = fname.left(pos); |
792 | pmaster = (MHfolderItem*)findSubItem(fname); | 783 | pmaster = (MHfolderItem*)findSubItem(fname); |
793 | } | 784 | } |
794 | else | 785 | else |
795 | { | 786 | { |
796 | pmaster = 0; | 787 | pmaster = 0; |
797 | } | 788 | } |
798 | if (pmaster) | 789 | if (pmaster) |
799 | { | 790 | { |
800 | item = new MHfolderItem( it, pmaster, item, this ); | 791 | item = new MHfolderItem( (*it), pmaster, item, this ); |
801 | } | 792 | } |
802 | else | 793 | else |
803 | { | 794 | { |
804 | item = new MHfolderItem( it, this , item ); | 795 | item = new MHfolderItem( (*it), this , item ); |
805 | } | 796 | } |
806 | item->setSelectable(it->may_select()); | 797 | item->setSelectable((*it)->may_select()); |
807 | } | 798 | } |
808 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
809 | folders->setAutoDelete(false); | ||
810 | delete folders; | 799 | delete folders; |
811 | } | 800 | } |
812 | 801 | ||
813 | RecBody MHviewItem::fetchBody( const RecMail &mail ) | 802 | RecBody MHviewItem::fetchBody( const RecMail &mail ) |
814 | { | 803 | { |
815 | qDebug( "MH fetchBody" ); | 804 | qDebug( "MH fetchBody" ); |
816 | return wrapper->fetchBody( mail ); | 805 | return wrapper->fetchBody( mail ); |
817 | } | 806 | } |
818 | 807 | ||
819 | QPopupMenu * MHviewItem::getContextMenu() | 808 | QPopupMenu * MHviewItem::getContextMenu() |
820 | { | 809 | { |
821 | QPopupMenu *m = new QPopupMenu(0); | 810 | QPopupMenu *m = new QPopupMenu(0); |
822 | if (m) | 811 | if (m) |
823 | { | 812 | { |
824 | m->insertItem(QObject::tr("Refresh folder list",contextName),0); | 813 | m->insertItem(QObject::tr("Refresh folder list",contextName),0); |
825 | m->insertItem(QObject::tr("Create new folder",contextName),1); | 814 | m->insertItem(QObject::tr("Create new folder",contextName),1); |
826 | m->insertItem(QObject::tr("Delete all mails",contextName),2); | 815 | m->insertItem(QObject::tr("Delete all mails",contextName),2); |
827 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),3); | 816 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),3); |
828 | } | 817 | } |
829 | return m; | 818 | return m; |
830 | } | 819 | } |
831 | 820 | ||
832 | void MHviewItem::createFolder() | 821 | void MHviewItem::createFolder() |
833 | { | 822 | { |
834 | Newmdirdlg ndirdlg(0,0,true); | 823 | Newmdirdlg ndirdlg(0,0,true); |
835 | if ( QPEApplication::execDialog( &ndirdlg ) ) | 824 | if ( QPEApplication::execDialog( &ndirdlg ) ) |
836 | { | 825 | { |
837 | QString ndir = ndirdlg.Newdir(); | 826 | QString ndir = ndirdlg.Newdir(); |
838 | if (wrapper->createMbox(ndir)) | 827 | if (wrapper->createMbox(ndir)) |
839 | { | 828 | { |
840 | refresh(true); | 829 | refresh(true); |
841 | } | 830 | } |
842 | } | 831 | } |
843 | } | 832 | } |
844 | 833 | ||
845 | void MHviewItem::downloadMails() | 834 | void MHviewItem::downloadMails() |
846 | { | 835 | { |
847 | AccountView*bl = accountView(); | 836 | AccountView*bl = accountView(); |
848 | if (!bl) return; | 837 | if (!bl) return; |
849 | bl->downloadMails(folder,getWrapper()); | 838 | bl->downloadMails(folder,getWrapper()); |
850 | } | 839 | } |
851 | 840 | ||
852 | QStringList MHviewItem::subFolders() | 841 | QStringList MHviewItem::subFolders() |
853 | { | 842 | { |
854 | return currentFolders; | 843 | return currentFolders; |
855 | } | 844 | } |
856 | 845 | ||
857 | void MHviewItem::contextMenuSelected(int which) | 846 | void MHviewItem::contextMenuSelected(int which) |
858 | { | 847 | { |
859 | switch (which) | 848 | switch (which) |
860 | { | 849 | { |
861 | case 0: | 850 | case 0: |
862 | refresh(true); | 851 | refresh(true); |
863 | break; | 852 | break; |
864 | case 1: | 853 | case 1: |
865 | createFolder(); | 854 | createFolder(); |
866 | break; | 855 | break; |
867 | case 2: | 856 | case 2: |
868 | deleteAllMail(getWrapper(),folder); | 857 | deleteAllMail(getWrapper(),folder); |
869 | break; | 858 | break; |
870 | case 3: | 859 | case 3: |
871 | downloadMails(); | 860 | downloadMails(); |
872 | break; | 861 | break; |
873 | default: | 862 | default: |
874 | break; | 863 | break; |
875 | } | 864 | } |
876 | } | 865 | } |
877 | 866 | ||
878 | MHfolderItem::~MHfolderItem() | 867 | MHfolderItem::~MHfolderItem() |
879 | {} | 868 | {} |
880 | 869 | ||
881 | MHfolderItem::MHfolderItem( Folder *folderInit, MHviewItem *parent , QListViewItem*after ) | 870 | MHfolderItem::MHfolderItem( const FolderP &folderInit, MHviewItem *parent , QListViewItem*after ) |
882 | : AccountViewItem( parent,after ) | 871 | : AccountViewItem(folderInit, parent,after ) |
883 | { | 872 | { |
884 | folder = folderInit; | ||
885 | mbox = parent; | 873 | mbox = parent; |
886 | initName(); | 874 | initName(); |
887 | } | 875 | } |
888 | 876 | ||
889 | MHfolderItem::MHfolderItem( Folder *folderInit, MHfolderItem *parent, QListViewItem*after, MHviewItem*master) | 877 | MHfolderItem::MHfolderItem(const FolderP& folderInit, MHfolderItem *parent, QListViewItem*after, MHviewItem*master) |
890 | : AccountViewItem( parent,after ) | 878 | : AccountViewItem(folderInit, parent,after ) |
891 | { | 879 | { |
892 | folder = folderInit; | 880 | folder = folderInit; |
893 | mbox = master; | 881 | mbox = master; |
894 | initName(); | 882 | initName(); |
895 | } | 883 | } |
896 | 884 | ||
897 | void MHfolderItem::initName() | 885 | void MHfolderItem::initName() |
898 | { | 886 | { |
899 | QString bName = folder->getDisplayName(); | 887 | QString bName = folder->getDisplayName(); |
900 | if (bName.startsWith("/")&&bName.length()>1) | 888 | if (bName.startsWith("/")&&bName.length()>1) |
901 | { | 889 | { |
902 | bName.replace(0,1,""); | 890 | bName.replace(0,1,""); |
903 | } | 891 | } |
904 | int pos = bName.findRev("/"); | 892 | int pos = bName.findRev("/"); |
905 | if (pos > 0) | 893 | if (pos > 0) |
906 | { | 894 | { |
907 | bName.replace(0,pos+1,""); | 895 | bName.replace(0,pos+1,""); |
908 | } | 896 | } |
909 | if (bName.lower() == "outgoing") | 897 | if (bName.lower() == "outgoing") |
910 | { | 898 | { |
911 | setPixmap( 0, PIXMAP_OUTBOXFOLDER ); | 899 | setPixmap( 0, PIXMAP_OUTBOXFOLDER ); |
912 | } | 900 | } |
913 | else if (bName.lower() == "inbox") | 901 | else if (bName.lower() == "inbox") |
914 | { | 902 | { |
915 | setPixmap( 0, PIXMAP_INBOXFOLDER); | 903 | setPixmap( 0, PIXMAP_INBOXFOLDER); |
916 | } else if (bName.lower() == "drafts") { | 904 | } else if (bName.lower() == "drafts") { |
917 | setPixmap(0, Resource::loadPixmap("inline/edit")); | 905 | setPixmap(0, Resource::loadPixmap("inline/edit")); |
918 | } else { | 906 | } else { |
919 | setPixmap( 0, PIXMAP_MBOXFOLDER ); | 907 | setPixmap( 0, PIXMAP_MBOXFOLDER ); |
920 | } | 908 | } |
921 | setText( 0, bName ); | 909 | setText( 0, bName ); |
922 | } | 910 | } |
923 | 911 | ||
924 | Folder*MHfolderItem::getFolder() | 912 | const FolderP&MHfolderItem::getFolder()const |
925 | { | 913 | { |
926 | return folder; | 914 | return folder; |
927 | } | 915 | } |
928 | 916 | ||
929 | void MHfolderItem::refresh(QList<RecMail>&target) | 917 | void MHfolderItem::refresh(QList<RecMail>&target) |
930 | { | 918 | { |
931 | if (folder->may_select()) | 919 | if (folder->may_select()) |
932 | mbox->getWrapper()->listMessages( folder->getName(),target ); | 920 | mbox->getWrapper()->listMessages( folder->getName(),target ); |
933 | } | 921 | } |
934 | 922 | ||
935 | RecBody MHfolderItem::fetchBody(const RecMail&aMail) | 923 | RecBody MHfolderItem::fetchBody(const RecMail&aMail) |
936 | { | 924 | { |
937 | return mbox->getWrapper()->fetchBody(aMail); | 925 | return mbox->getWrapper()->fetchBody(aMail); |
938 | } | 926 | } |
939 | 927 | ||
940 | void MHfolderItem::deleteFolder() | 928 | void MHfolderItem::deleteFolder() |
941 | { | 929 | { |
942 | int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), | 930 | int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), |
943 | QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), | 931 | QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), |
944 | QObject::tr("Yes",contextName), | 932 | QObject::tr("Yes",contextName), |
945 | QObject::tr("No",contextName),QString::null,1,1); | 933 | QObject::tr("No",contextName),QString::null,1,1); |
946 | qDebug("Auswahl: %i",yesno); | 934 | qDebug("Auswahl: %i",yesno); |
947 | if (yesno == 0) | 935 | if (yesno == 0) |
948 | { | 936 | { |
949 | if (mbox->getWrapper()->deleteMbox(folder)) | 937 | if (mbox->getWrapper()->deleteMbox(folder)) |
950 | { | 938 | { |
951 | QListView*v=listView(); | 939 | QListView*v=listView(); |
952 | MHviewItem * box = mbox; | 940 | MHviewItem * box = mbox; |
953 | /* be carefull - after that this object is destroyd so don't use | 941 | /* be carefull - after that this object is destroyd so don't use |
954 | * any member of it after that call!!*/ | 942 | * any member of it after that call!!*/ |
955 | mbox->refresh(true); | 943 | mbox->refresh(true); |
956 | if (v) | 944 | if (v) |
957 | { | 945 | { |
958 | v->setSelected(box,true); | 946 | v->setSelected(box,true); |
959 | } | 947 | } |
960 | } | 948 | } |
961 | } | 949 | } |
962 | } | 950 | } |
963 | 951 | ||
964 | QPopupMenu * MHfolderItem::getContextMenu() | 952 | QPopupMenu * MHfolderItem::getContextMenu() |
965 | { | 953 | { |
966 | QPopupMenu *m = new QPopupMenu(0); | 954 | QPopupMenu *m = new QPopupMenu(0); |
967 | if (m) | 955 | if (m) |
968 | { | 956 | { |
969 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); | 957 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); |
970 | m->insertItem(QObject::tr("Delete all mails",contextName),0); | 958 | m->insertItem(QObject::tr("Delete all mails",contextName),0); |
971 | m->insertItem(QObject::tr("Create new subfolder",contextName),3); | 959 | m->insertItem(QObject::tr("Create new subfolder",contextName),3); |
972 | m->insertItem(QObject::tr("Delete folder",contextName),1); | 960 | m->insertItem(QObject::tr("Delete folder",contextName),1); |
973 | } | 961 | } |
974 | return m; | 962 | return m; |
975 | } | 963 | } |
976 | 964 | ||
977 | void MHfolderItem::downloadMails() | 965 | void MHfolderItem::downloadMails() |
978 | { | 966 | { |
979 | AccountView*bl = mbox->accountView(); | 967 | AccountView*bl = mbox->accountView(); |
980 | if (!bl) return; | 968 | if (!bl) return; |
981 | bl->downloadMails(folder,mbox->getWrapper()); | 969 | bl->downloadMails(folder,mbox->getWrapper()); |
982 | } | 970 | } |
983 | 971 | ||
984 | void MHfolderItem::createFolder() | 972 | void MHfolderItem::createFolder() |
985 | { | 973 | { |
986 | Newmdirdlg ndirdlg(0,0,true); | 974 | Newmdirdlg ndirdlg(0,0,true); |
987 | if ( QPEApplication::execDialog( &ndirdlg ) ) | 975 | if ( QPEApplication::execDialog( &ndirdlg ) ) |
988 | { | 976 | { |
989 | QString ndir = ndirdlg.Newdir(); | 977 | QString ndir = ndirdlg.Newdir(); |
990 | if (mbox->getWrapper()->createMbox(ndir,folder)) | 978 | if (mbox->getWrapper()->createMbox(ndir,folder)) |
991 | { | 979 | { |
992 | QListView*v=listView(); | 980 | QListView*v=listView(); |
993 | MHviewItem * box = mbox; | 981 | MHviewItem * box = mbox; |
994 | /* be carefull - after that this object is destroyd so don't use | 982 | /* be carefull - after that this object is destroyd so don't use |
995 | * any member of it after that call!!*/ | 983 | * any member of it after that call!!*/ |
996 | mbox->refresh(true); | 984 | mbox->refresh(true); |
997 | if (v) | 985 | if (v) |
998 | { | 986 | { |
999 | v->setSelected(box,true); | 987 | v->setSelected(box,true); |
1000 | } | 988 | } |
1001 | } | 989 | } |
1002 | } | 990 | } |
1003 | } | 991 | } |
1004 | 992 | ||
1005 | void MHfolderItem::contextMenuSelected(int which) | 993 | void MHfolderItem::contextMenuSelected(int which) |
1006 | { | 994 | { |
1007 | switch(which) | 995 | switch(which) |
1008 | { | 996 | { |
1009 | case 0: | 997 | case 0: |
1010 | deleteAllMail(mbox->getWrapper(),folder); | 998 | deleteAllMail(mbox->getWrapper(),folder); |
1011 | break; | 999 | break; |
1012 | case 1: | 1000 | case 1: |
1013 | deleteFolder(); | 1001 | deleteFolder(); |
1014 | break; | 1002 | break; |
1015 | case 2: | 1003 | case 2: |
1016 | downloadMails(); | 1004 | downloadMails(); |
1017 | break; | 1005 | break; |
1018 | case 3: | 1006 | case 3: |
1019 | createFolder(); | 1007 | createFolder(); |
1020 | break; | 1008 | break; |
1021 | default: | 1009 | default: |
1022 | break; | 1010 | break; |
1023 | } | 1011 | } |
1024 | } | 1012 | } |
1025 | 1013 | ||
1026 | bool MHfolderItem::isDraftfolder() | 1014 | bool MHfolderItem::isDraftfolder() |
1027 | { | 1015 | { |
1028 | if (folder && folder->getName()==AbstractMail::defaultLocalfolder()+"/"+AbstractMail::draftFolder()) return true; | 1016 | if (folder && folder->getName()==AbstractMail::defaultLocalfolder()+"/"+AbstractMail::draftFolder()) return true; |
1029 | return false; | 1017 | return false; |
1030 | } | 1018 | } |
1031 | 1019 | ||
1032 | /** | 1020 | /** |
1033 | * Generic stuff | 1021 | * Generic stuff |
1034 | */ | 1022 | */ |
1035 | 1023 | ||
1036 | const QString AccountViewItem::contextName="AccountViewItem"; | 1024 | const QString AccountViewItem::contextName="AccountViewItem"; |
1037 | 1025 | ||
1038 | AccountViewItem::AccountViewItem( AccountView *parent ) | 1026 | AccountViewItem::AccountViewItem( AccountView *parent ) |
1039 | : QListViewItem( parent ) | 1027 | : QListViewItem( parent ) |
1040 | { | 1028 | { |
1041 | init(); | 1029 | init(); |
1042 | m_Backlink = parent; | 1030 | m_Backlink = parent; |
1043 | } | 1031 | } |
1044 | 1032 | ||
1045 | AccountViewItem::AccountViewItem( QListViewItem *parent) | 1033 | AccountViewItem::AccountViewItem( QListViewItem *parent) |
1046 | : QListViewItem( parent) | 1034 | : QListViewItem( parent),folder(0) |
1047 | { | 1035 | { |
1048 | init(); | 1036 | init(); |
1049 | } | 1037 | } |
1050 | 1038 | ||
1051 | AccountViewItem::AccountViewItem( QListViewItem *parent , QListViewItem*after ) | 1039 | AccountViewItem::AccountViewItem( QListViewItem *parent , QListViewItem*after ) |
1052 | :QListViewItem( parent,after ) | 1040 | :QListViewItem( parent,after ),folder(0) |
1041 | { | ||
1042 | init(); | ||
1043 | } | ||
1044 | |||
1045 | AccountViewItem::AccountViewItem( const Opie::osmart_pointer<Folder>&folderInit,QListViewItem *parent , QListViewItem*after ) | ||
1046 | :QListViewItem( parent,after ),folder(folderInit) | ||
1053 | { | 1047 | { |
1054 | init(); | 1048 | init(); |
1055 | } | 1049 | } |
1056 | 1050 | ||
1057 | void AccountViewItem::init() | 1051 | void AccountViewItem::init() |
1058 | { | 1052 | { |
1059 | m_Backlink = 0; | 1053 | m_Backlink = 0; |
1060 | folder = 0; | ||
1061 | } | 1054 | } |
1062 | 1055 | ||
1063 | AccountViewItem::~AccountViewItem() | 1056 | AccountViewItem::~AccountViewItem() |
1064 | { | 1057 | { |
1065 | if (folder) delete folder; | 1058 | folder = 0; |
1066 | } | 1059 | } |
1067 | 1060 | ||
1068 | AccountView*AccountViewItem::accountView() | 1061 | AccountView*AccountViewItem::accountView() |
1069 | { | 1062 | { |
1070 | return m_Backlink; | 1063 | return m_Backlink; |
1071 | } | 1064 | } |
1072 | 1065 | ||
1073 | void AccountViewItem::deleteAllMail(AbstractMail*wrapper,Folder*folder) | 1066 | void AccountViewItem::deleteAllMail(AbstractMail*wrapper,const FolderP&folder) |
1074 | { | 1067 | { |
1075 | if (!wrapper) return; | 1068 | if (!wrapper) return; |
1076 | QString fname=""; | 1069 | QString fname=""; |
1077 | if (folder) fname = folder->getDisplayName(); | 1070 | if (folder) fname = folder->getDisplayName(); |
1078 | int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName), | 1071 | int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName), |
1079 | QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName). | 1072 | QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName). |
1080 | arg(fname), | 1073 | arg(fname), |
1081 | QObject::tr("Yes",contextName), | 1074 | QObject::tr("Yes",contextName), |
1082 | QObject::tr("No",contextName),QString::null,1,1); | 1075 | QObject::tr("No",contextName),QString::null,1,1); |
1083 | qDebug("Auswahl: %i",yesno); | 1076 | qDebug("Auswahl: %i",yesno); |
1084 | if (yesno == 0) | 1077 | if (yesno == 0) |
1085 | { | 1078 | { |
1086 | if (wrapper->deleteAllMail(folder)) | 1079 | if (wrapper->deleteAllMail(folder)) |
1087 | { | 1080 | { |
1088 | AccountView * view = (AccountView*)listView(); | 1081 | AccountView * view = (AccountView*)listView(); |
1089 | if (view) view->refreshCurrent(); | 1082 | if (view) view->refreshCurrent(); |
1090 | } | 1083 | } |
1091 | } | 1084 | } |
1092 | } | 1085 | } |
1093 | 1086 | ||
1094 | void AccountViewItem::removeChilds() | 1087 | void AccountViewItem::removeChilds() |
1095 | { | 1088 | { |
1096 | QListViewItem *child = firstChild(); | 1089 | QListViewItem *child = firstChild(); |
1097 | while ( child ) | 1090 | while ( child ) |
1098 | { | 1091 | { |
1099 | QListViewItem *tmp = child; | 1092 | QListViewItem *tmp = child; |
1100 | child = child->nextSibling(); | 1093 | child = child->nextSibling(); |
1101 | delete tmp; | 1094 | delete tmp; |
1102 | } | 1095 | } |
1103 | } | 1096 | } |
1104 | 1097 | ||
1105 | bool AccountViewItem::matchName(const QString&name)const | 1098 | bool AccountViewItem::matchName(const QString&name)const |
1106 | { | 1099 | { |
1107 | if (!folder) return false; | 1100 | if (!folder) return false; |
1108 | return folder->getDisplayName()==name; | 1101 | return folder->getDisplayName()==name; |
1109 | } | 1102 | } |
1110 | 1103 | ||
1111 | 1104 | ||
1112 | AccountViewItem*AccountViewItem::findSubItem(const QString&path,AccountViewItem*start) | 1105 | AccountViewItem*AccountViewItem::findSubItem(const QString&path,AccountViewItem*start) |
1113 | { | 1106 | { |
1114 | AccountViewItem*pitem,*sitem; | 1107 | AccountViewItem*pitem,*sitem; |
1115 | if (!start) pitem = (AccountViewItem*)firstChild(); | 1108 | if (!start) pitem = (AccountViewItem*)firstChild(); |
1116 | else pitem = (AccountViewItem*)start->firstChild(); | 1109 | else pitem = (AccountViewItem*)start->firstChild(); |
1117 | while (pitem) | 1110 | while (pitem) |
1118 | { | 1111 | { |
1119 | if (pitem->matchName(path)) | 1112 | if (pitem->matchName(path)) |
1120 | { | 1113 | { |
1121 | break; | 1114 | break; |
1122 | } | 1115 | } |
1123 | if (pitem->childCount()>0) | 1116 | if (pitem->childCount()>0) |
1124 | { | 1117 | { |
1125 | sitem = findSubItem(path,pitem); | 1118 | sitem = findSubItem(path,pitem); |
1126 | if (sitem) | 1119 | if (sitem) |
1127 | { | 1120 | { |
1128 | pitem = sitem; | 1121 | pitem = sitem; |
1129 | break; | 1122 | break; |
1130 | } | 1123 | } |
1131 | } | 1124 | } |
1132 | pitem=(AccountViewItem*)pitem->nextSibling(); | 1125 | pitem=(AccountViewItem*)pitem->nextSibling(); |
1133 | } | 1126 | } |
1134 | return pitem; | 1127 | return pitem; |
1135 | } | 1128 | } |
1136 | 1129 | ||
1137 | bool AccountViewItem::isDraftfolder() | 1130 | bool AccountViewItem::isDraftfolder() |
1138 | { | 1131 | { |
1139 | return false; | 1132 | return false; |
1140 | } | 1133 | } |
diff --git a/noncore/net/mail/accountitem.h b/noncore/net/mail/accountitem.h index eb3baa3..8f712f5 100644 --- a/noncore/net/mail/accountitem.h +++ b/noncore/net/mail/accountitem.h | |||
@@ -1,207 +1,210 @@ | |||
1 | #ifndef __ACCOUNT_ITEM | 1 | #ifndef __ACCOUNT_ITEM |
2 | #define __ACCOUNT_ITEM | 2 | #define __ACCOUNT_ITEM |
3 | 3 | ||
4 | #include <qlistview.h> | 4 | #include <qlistview.h> |
5 | #include <qlist.h> | 5 | #include <qlist.h> |
6 | #include <opie2/osmart_pointer.h> | ||
6 | 7 | ||
7 | class POP3wrapper; | 8 | class POP3wrapper; |
8 | class RecMail; | 9 | class RecMail; |
9 | class RecBody; | 10 | class RecBody; |
10 | class QPopupMenu; | 11 | class QPopupMenu; |
11 | class Selectstore; | 12 | class Selectstore; |
12 | class AccountView; | 13 | class AccountView; |
13 | class POP3account; | 14 | class POP3account; |
14 | class NNTPaccount; | 15 | class NNTPaccount; |
15 | class IMAPaccount; | 16 | class IMAPaccount; |
16 | class AbstractMail; | 17 | class AbstractMail; |
17 | class Folder; | 18 | class Folder; |
18 | 19 | ||
19 | class AccountViewItem : public QListViewItem | 20 | class AccountViewItem : public QListViewItem |
20 | { | 21 | { |
21 | 22 | ||
22 | public: | 23 | public: |
23 | AccountViewItem( AccountView *parent ); | 24 | AccountViewItem( AccountView *parent ); |
24 | AccountViewItem( QListViewItem *parent); | 25 | AccountViewItem( QListViewItem *parent); |
25 | AccountViewItem( QListViewItem *parent , QListViewItem*after ); | 26 | AccountViewItem( QListViewItem *parent , QListViewItem*after ); |
27 | AccountViewItem( const Opie::osmart_pointer<Folder>&folderInit,QListViewItem *parent , QListViewItem*after ); | ||
28 | |||
26 | virtual ~AccountViewItem(); | 29 | virtual ~AccountViewItem(); |
27 | virtual void refresh(QList<RecMail>&)=0; | 30 | virtual void refresh(QList<RecMail>&)=0; |
28 | virtual RecBody fetchBody(const RecMail&)=0; | 31 | virtual RecBody fetchBody(const RecMail&)=0; |
29 | virtual QPopupMenu * getContextMenu(){return 0;}; | 32 | virtual QPopupMenu * getContextMenu(){return 0;}; |
30 | virtual void contextMenuSelected(int){} | 33 | virtual void contextMenuSelected(int){} |
31 | virtual AccountView*accountView(); | 34 | virtual AccountView*accountView(); |
32 | virtual bool matchName(const QString&name)const; | 35 | virtual bool matchName(const QString&name)const; |
33 | virtual bool isDraftfolder(); | 36 | virtual bool isDraftfolder(); |
34 | 37 | ||
35 | protected: | 38 | protected: |
36 | AccountViewItem*findSubItem(const QString&path,AccountViewItem*start=0); | 39 | AccountViewItem*findSubItem(const QString&path,AccountViewItem*start=0); |
37 | virtual void init(); | 40 | virtual void init(); |
38 | virtual void removeChilds(); | 41 | virtual void removeChilds(); |
39 | virtual void deleteAllMail(AbstractMail*wrapper,Folder*f); | 42 | virtual void deleteAllMail(AbstractMail*wrapper,const Opie::osmart_pointer<Folder>&f); |
40 | static const QString contextName; | 43 | static const QString contextName; |
41 | AccountView*m_Backlink; | 44 | AccountView*m_Backlink; |
42 | Folder *folder; | 45 | Opie::osmart_pointer<Folder> folder; |
43 | }; | 46 | }; |
44 | 47 | ||
45 | class POP3viewItem : public AccountViewItem | 48 | class POP3viewItem : public AccountViewItem |
46 | { | 49 | { |
47 | 50 | ||
48 | public: | 51 | public: |
49 | POP3viewItem( POP3account *a, AccountView *parent ); | 52 | POP3viewItem( POP3account *a, AccountView *parent ); |
50 | virtual ~POP3viewItem(); | 53 | virtual ~POP3viewItem(); |
51 | virtual void refresh( QList<RecMail> &target ); | 54 | virtual void refresh( QList<RecMail> &target ); |
52 | virtual RecBody fetchBody( const RecMail &mail ); | 55 | virtual RecBody fetchBody( const RecMail &mail ); |
53 | AbstractMail *getWrapper(); | 56 | AbstractMail *getWrapper(); |
54 | virtual QPopupMenu * getContextMenu(); | 57 | virtual QPopupMenu * getContextMenu(); |
55 | virtual void contextMenuSelected(int); | 58 | virtual void contextMenuSelected(int); |
56 | 59 | ||
57 | protected: | 60 | protected: |
58 | POP3account *account; | 61 | POP3account *account; |
59 | virtual void refresh(); | 62 | virtual void refresh(); |
60 | AbstractMail *wrapper; | 63 | AbstractMail *wrapper; |
61 | void disconnect(); | 64 | void disconnect(); |
62 | void setOnOffline(); | 65 | void setOnOffline(); |
63 | }; | 66 | }; |
64 | 67 | ||
65 | class POP3folderItem : public AccountViewItem | 68 | class POP3folderItem : public AccountViewItem |
66 | { | 69 | { |
67 | 70 | ||
68 | public: | 71 | public: |
69 | POP3folderItem( Folder *folder, POP3viewItem *parent , QListViewItem*after ); | 72 | POP3folderItem( const Opie::osmart_pointer<Folder>&folder, POP3viewItem *parent , QListViewItem*after ); |
70 | virtual ~POP3folderItem(); | 73 | virtual ~POP3folderItem(); |
71 | virtual void refresh(QList<RecMail>&); | 74 | virtual void refresh(QList<RecMail>&); |
72 | virtual RecBody fetchBody(const RecMail&); | 75 | virtual RecBody fetchBody(const RecMail&); |
73 | virtual QPopupMenu * getContextMenu(); | 76 | virtual QPopupMenu * getContextMenu(); |
74 | virtual void contextMenuSelected(int); | 77 | virtual void contextMenuSelected(int); |
75 | 78 | ||
76 | protected: | 79 | protected: |
77 | void downloadMails(); | 80 | void downloadMails(); |
78 | POP3viewItem *pop3; | 81 | POP3viewItem *pop3; |
79 | }; | 82 | }; |
80 | 83 | ||
81 | 84 | ||
82 | class NNTPviewItem : public AccountViewItem | 85 | class NNTPviewItem : public AccountViewItem |
83 | { | 86 | { |
84 | 87 | ||
85 | public: | 88 | public: |
86 | NNTPviewItem( NNTPaccount *a, AccountView *parent ); | 89 | NNTPviewItem( NNTPaccount *a, AccountView *parent ); |
87 | virtual ~NNTPviewItem(); | 90 | virtual ~NNTPviewItem(); |
88 | virtual void refresh( QList<RecMail> &target ); | 91 | virtual void refresh( QList<RecMail> &target ); |
89 | virtual RecBody fetchBody( const RecMail &mail ); | 92 | virtual RecBody fetchBody( const RecMail &mail ); |
90 | AbstractMail *getWrapper(); | 93 | AbstractMail *getWrapper(); |
91 | virtual QPopupMenu * getContextMenu(); | 94 | virtual QPopupMenu * getContextMenu(); |
92 | virtual void contextMenuSelected(int); | 95 | virtual void contextMenuSelected(int); |
93 | 96 | ||
94 | protected: | 97 | protected: |
95 | NNTPaccount *account; | 98 | NNTPaccount *account; |
96 | virtual void refresh(); | 99 | virtual void refresh(); |
97 | AbstractMail *wrapper; | 100 | AbstractMail *wrapper; |
98 | void disconnect(); | 101 | void disconnect(); |
99 | void setOnOffline(); | 102 | void setOnOffline(); |
100 | void subscribeGroups(); | 103 | void subscribeGroups(); |
101 | }; | 104 | }; |
102 | 105 | ||
103 | class NNTPfolderItem : public AccountViewItem | 106 | class NNTPfolderItem : public AccountViewItem |
104 | { | 107 | { |
105 | 108 | ||
106 | public: | 109 | public: |
107 | NNTPfolderItem( Folder *folder, NNTPviewItem *parent , QListViewItem*after ); | 110 | NNTPfolderItem(const Opie::osmart_pointer<Folder>&folder, NNTPviewItem *parent , QListViewItem*after ); |
108 | virtual ~NNTPfolderItem(); | 111 | virtual ~NNTPfolderItem(); |
109 | virtual void refresh(QList<RecMail>&); | 112 | virtual void refresh(QList<RecMail>&); |
110 | virtual RecBody fetchBody(const RecMail&); | 113 | virtual RecBody fetchBody(const RecMail&); |
111 | virtual QPopupMenu * getContextMenu(); | 114 | virtual QPopupMenu * getContextMenu(); |
112 | virtual void contextMenuSelected(int); | 115 | virtual void contextMenuSelected(int); |
113 | 116 | ||
114 | protected: | 117 | protected: |
115 | void downloadMails(); | 118 | void downloadMails(); |
116 | NNTPviewItem *nntp; | 119 | NNTPviewItem *nntp; |
117 | }; | 120 | }; |
118 | 121 | ||
119 | 122 | ||
120 | 123 | ||
121 | class IMAPviewItem : public AccountViewItem | 124 | class IMAPviewItem : public AccountViewItem |
122 | { | 125 | { |
123 | friend class IMAPfolderItem; | 126 | friend class IMAPfolderItem; |
124 | public: | 127 | public: |
125 | IMAPviewItem( IMAPaccount *a, AccountView *parent ); | 128 | IMAPviewItem( IMAPaccount *a, AccountView *parent ); |
126 | virtual ~IMAPviewItem(); | 129 | virtual ~IMAPviewItem(); |
127 | virtual void refresh(QList<RecMail>&); | 130 | virtual void refresh(QList<RecMail>&); |
128 | virtual RecBody fetchBody(const RecMail&); | 131 | virtual RecBody fetchBody(const RecMail&); |
129 | AbstractMail *getWrapper(); | 132 | AbstractMail *getWrapper(); |
130 | virtual QPopupMenu * getContextMenu(); | 133 | virtual QPopupMenu * getContextMenu(); |
131 | virtual void contextMenuSelected(int); | 134 | virtual void contextMenuSelected(int); |
132 | const QStringList&subFolders(); | 135 | const QStringList&subFolders(); |
133 | virtual void refreshFolders(bool force=false); | 136 | virtual void refreshFolders(bool force=false); |
134 | bool offline(); | 137 | bool offline(); |
135 | 138 | ||
136 | protected: | 139 | protected: |
137 | virtual void createNewFolder(); | 140 | virtual void createNewFolder(); |
138 | IMAPaccount *account; | 141 | IMAPaccount *account; |
139 | AbstractMail *wrapper; | 142 | AbstractMail *wrapper; |
140 | QStringList currentFolders; | 143 | QStringList currentFolders; |
141 | }; | 144 | }; |
142 | 145 | ||
143 | class IMAPfolderItem : public AccountViewItem | 146 | class IMAPfolderItem : public AccountViewItem |
144 | { | 147 | { |
145 | 148 | ||
146 | public: | 149 | public: |
147 | IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after ); | 150 | IMAPfolderItem( const Opie::osmart_pointer<Folder>&folder, IMAPviewItem *parent , QListViewItem*after ); |
148 | IMAPfolderItem( Folder *folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ); | 151 | IMAPfolderItem( const Opie::osmart_pointer<Folder>&folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ); |
149 | virtual ~IMAPfolderItem(); | 152 | virtual ~IMAPfolderItem(); |
150 | virtual void refresh(QList<RecMail>&); | 153 | virtual void refresh(QList<RecMail>&); |
151 | virtual RecBody fetchBody(const RecMail&); | 154 | virtual RecBody fetchBody(const RecMail&); |
152 | virtual QPopupMenu * getContextMenu(); | 155 | virtual QPopupMenu * getContextMenu(); |
153 | virtual void contextMenuSelected(int); | 156 | virtual void contextMenuSelected(int); |
154 | virtual const QString& Delemiter()const; | 157 | virtual const QString& Delemiter()const; |
155 | protected: | 158 | protected: |
156 | virtual void createNewFolder(); | 159 | virtual void createNewFolder(); |
157 | virtual void deleteFolder(); | 160 | virtual void deleteFolder(); |
158 | virtual void downloadMails(); | 161 | virtual void downloadMails(); |
159 | IMAPviewItem *imap; | 162 | IMAPviewItem *imap; |
160 | }; | 163 | }; |
161 | 164 | ||
162 | class MHviewItem : public AccountViewItem | 165 | class MHviewItem : public AccountViewItem |
163 | { | 166 | { |
164 | friend class MHfolderItem; | 167 | friend class MHfolderItem; |
165 | 168 | ||
166 | public: | 169 | public: |
167 | MHviewItem( const QString&aMboxPath, AccountView *parent ); | 170 | MHviewItem( const QString&aMboxPath, AccountView *parent ); |
168 | virtual ~MHviewItem(); | 171 | virtual ~MHviewItem(); |
169 | virtual void refresh( QList<RecMail> &target ); | 172 | virtual void refresh( QList<RecMail> &target ); |
170 | virtual RecBody fetchBody( const RecMail &mail ); | 173 | virtual RecBody fetchBody( const RecMail &mail ); |
171 | AbstractMail *getWrapper(); | 174 | AbstractMail *getWrapper(); |
172 | virtual QPopupMenu * getContextMenu(); | 175 | virtual QPopupMenu * getContextMenu(); |
173 | virtual void contextMenuSelected(int); | 176 | virtual void contextMenuSelected(int); |
174 | QStringList subFolders(); | 177 | QStringList subFolders(); |
175 | virtual void refresh(bool force=false); | 178 | virtual void refresh(bool force=false); |
176 | 179 | ||
177 | protected: | 180 | protected: |
178 | void downloadMails(); | 181 | void downloadMails(); |
179 | virtual void createFolder(); | 182 | virtual void createFolder(); |
180 | QString m_Path; | 183 | QString m_Path; |
181 | AbstractMail *wrapper; | 184 | AbstractMail *wrapper; |
182 | QStringList currentFolders; | 185 | QStringList currentFolders; |
183 | }; | 186 | }; |
184 | 187 | ||
185 | class MHfolderItem : public AccountViewItem | 188 | class MHfolderItem : public AccountViewItem |
186 | { | 189 | { |
187 | 190 | ||
188 | public: | 191 | public: |
189 | MHfolderItem( Folder *folder, MHviewItem *parent , QListViewItem*after ); | 192 | MHfolderItem( const Opie::osmart_pointer<Folder>&folder, MHviewItem *parent , QListViewItem*after ); |
190 | MHfolderItem( Folder *folder, MHfolderItem *parent, QListViewItem*after, MHviewItem*master); | 193 | MHfolderItem( const Opie::osmart_pointer<Folder>&folder, MHfolderItem *parent, QListViewItem*after, MHviewItem*master); |
191 | virtual ~MHfolderItem(); | 194 | virtual ~MHfolderItem(); |
192 | virtual void refresh(QList<RecMail>&); | 195 | virtual void refresh(QList<RecMail>&); |
193 | virtual RecBody fetchBody(const RecMail&); | 196 | virtual RecBody fetchBody(const RecMail&); |
194 | virtual QPopupMenu * getContextMenu(); | 197 | virtual QPopupMenu * getContextMenu(); |
195 | virtual void contextMenuSelected(int); | 198 | virtual void contextMenuSelected(int); |
196 | virtual Folder*getFolder(); | 199 | virtual const Opie::osmart_pointer<Folder>&getFolder()const; |
197 | virtual bool isDraftfolder(); | 200 | virtual bool isDraftfolder(); |
198 | 201 | ||
199 | protected: | 202 | protected: |
200 | void downloadMails(); | 203 | void downloadMails(); |
201 | virtual void createFolder(); | 204 | virtual void createFolder(); |
202 | virtual void deleteFolder(); | 205 | virtual void deleteFolder(); |
203 | void initName(); | 206 | void initName(); |
204 | MHviewItem *mbox; | 207 | MHviewItem *mbox; |
205 | }; | 208 | }; |
206 | 209 | ||
207 | #endif | 210 | #endif |
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp index 7938d4f..297f553 100644 --- a/noncore/net/mail/accountview.cpp +++ b/noncore/net/mail/accountview.cpp | |||
@@ -1,177 +1,177 @@ | |||
1 | 1 | ||
2 | #include "accountview.h" | 2 | #include "accountview.h" |
3 | #include "accountitem.h" | 3 | #include "accountitem.h" |
4 | #include "selectstore.h" | 4 | #include "selectstore.h" |
5 | 5 | ||
6 | /* OPIE */ | 6 | /* OPIE */ |
7 | #include <libmailwrapper/settings.h> | 7 | #include <libmailwrapper/settings.h> |
8 | #include <libmailwrapper/mailwrapper.h> | 8 | #include <libmailwrapper/mailwrapper.h> |
9 | #include <libmailwrapper/mailtypes.h> | 9 | #include <libmailwrapper/mailtypes.h> |
10 | #include <libmailwrapper/abstractmail.h> | 10 | #include <libmailwrapper/abstractmail.h> |
11 | #include <qpe/qpeapplication.h> | 11 | #include <qpe/qpeapplication.h> |
12 | 12 | ||
13 | /* QT */ | 13 | /* QT */ |
14 | #include <qmessagebox.h> | 14 | #include <qmessagebox.h> |
15 | #include <qpopupmenu.h> | 15 | #include <qpopupmenu.h> |
16 | 16 | ||
17 | AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) | 17 | AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) |
18 | : QListView( parent, name, flags ) | 18 | : QListView( parent, name, flags ) |
19 | { | 19 | { |
20 | connect( this, SIGNAL( selectionChanged(QListViewItem*) ), | 20 | connect( this, SIGNAL( selectionChanged(QListViewItem*) ), |
21 | SLOT( refresh(QListViewItem*) ) ); | 21 | SLOT( refresh(QListViewItem*) ) ); |
22 | connect( this, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),this, | 22 | connect( this, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),this, |
23 | SLOT( slotHold(int,QListViewItem*,const QPoint&,int) ) ); | 23 | SLOT( slotHold(int,QListViewItem*,const QPoint&,int) ) ); |
24 | setSorting(0); | 24 | setSorting(0); |
25 | } | 25 | } |
26 | 26 | ||
27 | AccountView::~AccountView() | 27 | AccountView::~AccountView() |
28 | { | 28 | { |
29 | imapAccounts.clear(); | 29 | imapAccounts.clear(); |
30 | mhAccounts.clear(); | 30 | mhAccounts.clear(); |
31 | } | 31 | } |
32 | 32 | ||
33 | void AccountView::slotContextMenu(int id) | 33 | void AccountView::slotContextMenu(int id) |
34 | { | 34 | { |
35 | AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); | 35 | AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); |
36 | if (!view) return; | 36 | if (!view) return; |
37 | view->contextMenuSelected(id); | 37 | view->contextMenuSelected(id); |
38 | } | 38 | } |
39 | 39 | ||
40 | void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int) | 40 | void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int) |
41 | { | 41 | { |
42 | if (button==1) {return;} | 42 | if (button==1) {return;} |
43 | if (!item) return; | 43 | if (!item) return; |
44 | AccountViewItem *view = static_cast<AccountViewItem *>(item); | 44 | AccountViewItem *view = static_cast<AccountViewItem *>(item); |
45 | QPopupMenu*m = view->getContextMenu(); | 45 | QPopupMenu*m = view->getContextMenu(); |
46 | if (!m) return; | 46 | if (!m) return; |
47 | connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int))); | 47 | connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int))); |
48 | m->setFocus(); | 48 | m->setFocus(); |
49 | m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); | 49 | m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); |
50 | delete m; | 50 | delete m; |
51 | } | 51 | } |
52 | 52 | ||
53 | void AccountView::populate( QList<Account> list ) | 53 | void AccountView::populate( QList<Account> list ) |
54 | { | 54 | { |
55 | clear(); | 55 | clear(); |
56 | 56 | ||
57 | imapAccounts.clear(); | 57 | imapAccounts.clear(); |
58 | mhAccounts.clear(); | 58 | mhAccounts.clear(); |
59 | 59 | ||
60 | mhAccounts.append(new MHviewItem(AbstractMail::defaultLocalfolder(),this)); | 60 | mhAccounts.append(new MHviewItem(AbstractMail::defaultLocalfolder(),this)); |
61 | 61 | ||
62 | Account *it; | 62 | Account *it; |
63 | for ( it = list.first(); it; it = list.next() ) | 63 | for ( it = list.first(); it; it = list.next() ) |
64 | { | 64 | { |
65 | if ( it->getType() == MAILLIB::A_IMAP ) | 65 | if ( it->getType() == MAILLIB::A_IMAP ) |
66 | { | 66 | { |
67 | IMAPaccount *imap = static_cast<IMAPaccount *>(it); | 67 | IMAPaccount *imap = static_cast<IMAPaccount *>(it); |
68 | qDebug( "added IMAP " + imap->getAccountName() ); | 68 | qDebug( "added IMAP " + imap->getAccountName() ); |
69 | imapAccounts.append(new IMAPviewItem( imap, this )); | 69 | imapAccounts.append(new IMAPviewItem( imap, this )); |
70 | } | 70 | } |
71 | else if ( it->getType() == MAILLIB::A_POP3 ) | 71 | else if ( it->getType() == MAILLIB::A_POP3 ) |
72 | { | 72 | { |
73 | POP3account *pop3 = static_cast<POP3account *>(it); | 73 | POP3account *pop3 = static_cast<POP3account *>(it); |
74 | qDebug( "added POP3 " + pop3->getAccountName() ); | 74 | qDebug( "added POP3 " + pop3->getAccountName() ); |
75 | /* must not be hold 'cause it isn't required */ | 75 | /* must not be hold 'cause it isn't required */ |
76 | (void) new POP3viewItem( pop3, this ); | 76 | (void) new POP3viewItem( pop3, this ); |
77 | } | 77 | } |
78 | else if ( it->getType() == MAILLIB::A_NNTP ) | 78 | else if ( it->getType() == MAILLIB::A_NNTP ) |
79 | { | 79 | { |
80 | NNTPaccount *nntp = static_cast<NNTPaccount *>(it); | 80 | NNTPaccount *nntp = static_cast<NNTPaccount *>(it); |
81 | qDebug( "added NNTP " + nntp->getAccountName() ); | 81 | qDebug( "added NNTP " + nntp->getAccountName() ); |
82 | /* must not be hold 'cause it isn't required */ | 82 | /* must not be hold 'cause it isn't required */ |
83 | (void) new NNTPviewItem( nntp, this ); | 83 | (void) new NNTPviewItem( nntp, this ); |
84 | } | 84 | } |
85 | } | 85 | } |
86 | } | 86 | } |
87 | 87 | ||
88 | void AccountView::refresh(QListViewItem *item) | 88 | void AccountView::refresh(QListViewItem *item) |
89 | { | 89 | { |
90 | 90 | ||
91 | qDebug("AccountView refresh..."); | 91 | qDebug("AccountView refresh..."); |
92 | if ( item ) | 92 | if ( item ) |
93 | { | 93 | { |
94 | m_currentItem = item; | 94 | m_currentItem = item; |
95 | QList<RecMail> headerlist; | 95 | QList<RecMail> headerlist; |
96 | headerlist.setAutoDelete(true); | 96 | headerlist.setAutoDelete(true); |
97 | AccountViewItem *view = static_cast<AccountViewItem *>(item); | 97 | AccountViewItem *view = static_cast<AccountViewItem *>(item); |
98 | view->refresh(headerlist); | 98 | view->refresh(headerlist); |
99 | emit refreshMailview(&headerlist); | 99 | emit refreshMailview(&headerlist); |
100 | } | 100 | } |
101 | } | 101 | } |
102 | 102 | ||
103 | void AccountView::refreshCurrent() | 103 | void AccountView::refreshCurrent() |
104 | { | 104 | { |
105 | m_currentItem = currentItem(); | 105 | m_currentItem = currentItem(); |
106 | if ( !m_currentItem ) return; | 106 | if ( !m_currentItem ) return; |
107 | QList<RecMail> headerlist; | 107 | QList<RecMail> headerlist; |
108 | headerlist.setAutoDelete(true); | 108 | headerlist.setAutoDelete(true); |
109 | AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); | 109 | AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); |
110 | view->refresh(headerlist); | 110 | view->refresh(headerlist); |
111 | emit refreshMailview(&headerlist); | 111 | emit refreshMailview(&headerlist); |
112 | } | 112 | } |
113 | 113 | ||
114 | void AccountView::refreshAll() | 114 | void AccountView::refreshAll() |
115 | { | 115 | { |
116 | } | 116 | } |
117 | 117 | ||
118 | RecBody AccountView::fetchBody(const RecMail&aMail) | 118 | RecBody AccountView::fetchBody(const RecMail&aMail) |
119 | { | 119 | { |
120 | QListViewItem*item = selectedItem (); | 120 | QListViewItem*item = selectedItem (); |
121 | if (!item) return RecBody(); | 121 | if (!item) return RecBody(); |
122 | AccountViewItem *view = static_cast<AccountViewItem *>(item); | 122 | AccountViewItem *view = static_cast<AccountViewItem *>(item); |
123 | return view->fetchBody(aMail); | 123 | return view->fetchBody(aMail); |
124 | } | 124 | } |
125 | 125 | ||
126 | void AccountView::setupFolderselect(Selectstore*sels) | 126 | void AccountView::setupFolderselect(Selectstore*sels) |
127 | { | 127 | { |
128 | QPEApplication::showDialog( sels ); | 128 | QPEApplication::showDialog( sels ); |
129 | QStringList sFolders; | 129 | QStringList sFolders; |
130 | unsigned int i = 0; | 130 | unsigned int i = 0; |
131 | for (i=0; i < mhAccounts.count();++i) | 131 | for (i=0; i < mhAccounts.count();++i) |
132 | { | 132 | { |
133 | mhAccounts[i]->refresh(false); | 133 | mhAccounts[i]->refresh(false); |
134 | sFolders = mhAccounts[i]->subFolders(); | 134 | sFolders = mhAccounts[i]->subFolders(); |
135 | sels->addAccounts(mhAccounts[i]->getWrapper(),sFolders); | 135 | sels->addAccounts(mhAccounts[i]->getWrapper(),sFolders); |
136 | } | 136 | } |
137 | for (i=0; i < imapAccounts.count();++i) | 137 | for (i=0; i < imapAccounts.count();++i) |
138 | { | 138 | { |
139 | if (imapAccounts[i]->offline()) | 139 | if (imapAccounts[i]->offline()) |
140 | continue; | 140 | continue; |
141 | imapAccounts[i]->refreshFolders(false); | 141 | imapAccounts[i]->refreshFolders(false); |
142 | sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders()); | 142 | sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders()); |
143 | } | 143 | } |
144 | } | 144 | } |
145 | 145 | ||
146 | void AccountView::downloadMails(Folder*fromFolder,AbstractMail*fromWrapper) | 146 | void AccountView::downloadMails(const FolderP&fromFolder,AbstractMail*fromWrapper) |
147 | { | 147 | { |
148 | AbstractMail*targetMail = 0; | 148 | AbstractMail*targetMail = 0; |
149 | QString targetFolder = ""; | 149 | QString targetFolder = ""; |
150 | Selectstore sels; | 150 | Selectstore sels; |
151 | setupFolderselect(&sels); | 151 | setupFolderselect(&sels); |
152 | if (!sels.exec()) return; | 152 | if (!sels.exec()) return; |
153 | targetMail = sels.currentMail(); | 153 | targetMail = sels.currentMail(); |
154 | targetFolder = sels.currentFolder(); | 154 | targetFolder = sels.currentFolder(); |
155 | if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) || | 155 | if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) || |
156 | targetFolder.isEmpty()) | 156 | targetFolder.isEmpty()) |
157 | { | 157 | { |
158 | return; | 158 | return; |
159 | } | 159 | } |
160 | if (sels.newFolder() && !targetMail->createMbox(targetFolder)) | 160 | if (sels.newFolder() && !targetMail->createMbox(targetFolder)) |
161 | { | 161 | { |
162 | QMessageBox::critical(0,tr("Error creating new Folder"), | 162 | QMessageBox::critical(0,tr("Error creating new Folder"), |
163 | tr("<center>Error while creating<br>new folder - breaking.</center>")); | 163 | tr("<center>Error while creating<br>new folder - breaking.</center>")); |
164 | return; | 164 | return; |
165 | } | 165 | } |
166 | qDebug("Targetfolder: %s",targetFolder.latin1()); | 166 | qDebug("Targetfolder: %s",targetFolder.latin1()); |
167 | qDebug("Fromfolder: %s",fromFolder->getName().latin1()); | 167 | qDebug("Fromfolder: %s",fromFolder->getName().latin1()); |
168 | fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails()); | 168 | fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails()); |
169 | refreshCurrent(); | 169 | refreshCurrent(); |
170 | } | 170 | } |
171 | 171 | ||
172 | bool AccountView::currentisDraft() | 172 | bool AccountView::currentisDraft() |
173 | { | 173 | { |
174 | AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); | 174 | AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); |
175 | if (!view) return false; | 175 | if (!view) return false; |
176 | return view->isDraftfolder(); | 176 | return view->isDraftfolder(); |
177 | } | 177 | } |
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h index 5000202..3478c0b 100644 --- a/noncore/net/mail/accountview.h +++ b/noncore/net/mail/accountview.h | |||
@@ -1,45 +1,46 @@ | |||
1 | #ifndef ACCOUNTVIEW_H | 1 | #ifndef ACCOUNTVIEW_H |
2 | #define ACCOUNTVIEW_H | 2 | #define ACCOUNTVIEW_H |
3 | 3 | ||
4 | #include <qlistview.h> | 4 | #include <qlistview.h> |
5 | #include <qlist.h> | 5 | #include <qlist.h> |
6 | #include <opie2/osmart_pointer.h> | ||
6 | 7 | ||
7 | class Selectstore; | 8 | class Selectstore; |
8 | class RecMail; | 9 | class RecMail; |
9 | class RecBody; | 10 | class RecBody; |
10 | class Folder; | 11 | class Folder; |
11 | class AbstractMail; | 12 | class AbstractMail; |
12 | class Account; | 13 | class Account; |
13 | class IMAPviewItem; | 14 | class IMAPviewItem; |
14 | class MHviewItem; | 15 | class MHviewItem; |
15 | 16 | ||
16 | class AccountView : public QListView | 17 | class AccountView : public QListView |
17 | { | 18 | { |
18 | Q_OBJECT | 19 | Q_OBJECT |
19 | 20 | ||
20 | public: | 21 | public: |
21 | AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); | 22 | AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); |
22 | virtual ~AccountView(); | 23 | virtual ~AccountView(); |
23 | virtual void populate( QList<Account> list ); | 24 | virtual void populate( QList<Account> list ); |
24 | virtual RecBody fetchBody(const RecMail&aMail); | 25 | virtual RecBody fetchBody(const RecMail&aMail); |
25 | virtual void downloadMails(Folder*fromFolder,AbstractMail*fromWrapper); | 26 | virtual void downloadMails(const Opie::osmart_pointer<Folder>&fromFolder,AbstractMail*fromWrapper); |
26 | virtual bool currentisDraft(); | 27 | virtual bool currentisDraft(); |
27 | 28 | ||
28 | public slots: | 29 | public slots: |
29 | virtual void refreshAll(); | 30 | virtual void refreshAll(); |
30 | virtual void refresh(QListViewItem *item); | 31 | virtual void refresh(QListViewItem *item); |
31 | virtual void refreshCurrent(); | 32 | virtual void refreshCurrent(); |
32 | virtual void slotHold(int, QListViewItem *,const QPoint&,int); | 33 | virtual void slotHold(int, QListViewItem *,const QPoint&,int); |
33 | virtual void slotContextMenu(int id); | 34 | virtual void slotContextMenu(int id); |
34 | void setupFolderselect(Selectstore*sels); | 35 | void setupFolderselect(Selectstore*sels); |
35 | 36 | ||
36 | signals: | 37 | signals: |
37 | void refreshMailview(QList<RecMail>*); | 38 | void refreshMailview(QList<RecMail>*); |
38 | 39 | ||
39 | protected: | 40 | protected: |
40 | QListViewItem* m_currentItem; | 41 | QListViewItem* m_currentItem; |
41 | QValueList<IMAPviewItem*> imapAccounts; | 42 | QValueList<IMAPviewItem*> imapAccounts; |
42 | QValueList<MHviewItem*> mhAccounts; | 43 | QValueList<MHviewItem*> mhAccounts; |
43 | }; | 44 | }; |
44 | 45 | ||
45 | #endif | 46 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp index ac6f380..7e6d383 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.cpp +++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp | |||
@@ -1,166 +1,167 @@ | |||
1 | #include "abstractmail.h" | 1 | #include "abstractmail.h" |
2 | #include "imapwrapper.h" | 2 | #include "imapwrapper.h" |
3 | #include "pop3wrapper.h" | 3 | #include "pop3wrapper.h" |
4 | #include "nntpwrapper.h" | 4 | #include "nntpwrapper.h" |
5 | #include "mhwrapper.h" | 5 | #include "mhwrapper.h" |
6 | #include "mailtypes.h" | 6 | #include "mailtypes.h" |
7 | 7 | ||
8 | #include <qfile.h> | 8 | #include <qfile.h> |
9 | #include <qtextstream.h> | 9 | #include <qtextstream.h> |
10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
11 | #include <libetpan/mailmime_content.h> | 11 | #include <libetpan/mailmime_content.h> |
12 | #include <libetpan/mailmime.h> | 12 | #include <libetpan/mailmime.h> |
13 | 13 | ||
14 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) | 14 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) |
15 | { | 15 | { |
16 | return new IMAPwrapper(a); | 16 | return new IMAPwrapper(a); |
17 | } | 17 | } |
18 | 18 | ||
19 | AbstractMail* AbstractMail::getWrapper(POP3account *a) | 19 | AbstractMail* AbstractMail::getWrapper(POP3account *a) |
20 | { | 20 | { |
21 | return new POP3wrapper(a); | 21 | return new POP3wrapper(a); |
22 | } | 22 | } |
23 | 23 | ||
24 | AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) | 24 | AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) |
25 | { | 25 | { |
26 | return new NNTPwrapper(a); | 26 | return new NNTPwrapper(a); |
27 | } | 27 | } |
28 | 28 | ||
29 | AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) | 29 | AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) |
30 | { | 30 | { |
31 | return new MHwrapper(a,name); | 31 | return new MHwrapper(a,name); |
32 | } | 32 | } |
33 | 33 | ||
34 | AbstractMail* AbstractMail::getWrapper(Account*a) | 34 | AbstractMail* AbstractMail::getWrapper(Account*a) |
35 | { | 35 | { |
36 | if (!a) return 0; | 36 | if (!a) return 0; |
37 | switch (a->getType()) { | 37 | switch (a->getType()) { |
38 | case MAILLIB::A_IMAP: | 38 | case MAILLIB::A_IMAP: |
39 | return new IMAPwrapper((IMAPaccount*)a); | 39 | return new IMAPwrapper((IMAPaccount*)a); |
40 | break; | 40 | break; |
41 | case MAILLIB::A_POP3: | 41 | case MAILLIB::A_POP3: |
42 | return new POP3wrapper((POP3account*)a); | 42 | return new POP3wrapper((POP3account*)a); |
43 | break; | 43 | break; |
44 | case MAILLIB::A_NNTP: | 44 | case MAILLIB::A_NNTP: |
45 | return new NNTPwrapper((NNTPaccount*)a); | 45 | return new NNTPwrapper((NNTPaccount*)a); |
46 | break; | 46 | break; |
47 | default: | 47 | default: |
48 | return 0; | 48 | return 0; |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) | 52 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) |
53 | { | 53 | { |
54 | qDebug("Decode string start"); | 54 | qDebug("Decode string start"); |
55 | char*result_text; | 55 | char*result_text; |
56 | size_t index = 0; | 56 | size_t index = 0; |
57 | /* reset for recursive use! */ | 57 | /* reset for recursive use! */ |
58 | size_t target_length = 0; | 58 | size_t target_length = 0; |
59 | result_text = 0; | 59 | result_text = 0; |
60 | int mimetype = MAILMIME_MECHANISM_7BIT; | 60 | int mimetype = MAILMIME_MECHANISM_7BIT; |
61 | if (enc.lower()=="quoted-printable") { | 61 | if (enc.lower()=="quoted-printable") { |
62 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 62 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
63 | } else if (enc.lower()=="base64") { | 63 | } else if (enc.lower()=="base64") { |
64 | mimetype = MAILMIME_MECHANISM_BASE64; | 64 | mimetype = MAILMIME_MECHANISM_BASE64; |
65 | } else if (enc.lower()=="8bit") { | 65 | } else if (enc.lower()=="8bit") { |
66 | mimetype = MAILMIME_MECHANISM_8BIT; | 66 | mimetype = MAILMIME_MECHANISM_8BIT; |
67 | } else if (enc.lower()=="binary") { | 67 | } else if (enc.lower()=="binary") { |
68 | mimetype = MAILMIME_MECHANISM_BINARY; | 68 | mimetype = MAILMIME_MECHANISM_BINARY; |
69 | } | 69 | } |
70 | 70 | ||
71 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, | 71 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, |
72 | &result_text,&target_length); | 72 | &result_text,&target_length); |
73 | 73 | ||
74 | encodedString* result = new encodedString(); | 74 | encodedString* result = new encodedString(); |
75 | if (err == MAILIMF_NO_ERROR) { | 75 | if (err == MAILIMF_NO_ERROR) { |
76 | result->setContent(result_text,target_length); | 76 | result->setContent(result_text,target_length); |
77 | } | 77 | } |
78 | qDebug("Decode string finished"); | 78 | qDebug("Decode string finished"); |
79 | return result; | 79 | return result; |
80 | } | 80 | } |
81 | 81 | ||
82 | QString AbstractMail::convert_String(const char*text) | 82 | QString AbstractMail::convert_String(const char*text) |
83 | { | 83 | { |
84 | size_t index = 0; | 84 | size_t index = 0; |
85 | char*res = 0; | 85 | char*res = 0; |
86 | int err = MAILIMF_NO_ERROR; | 86 | int err = MAILIMF_NO_ERROR; |
87 | 87 | ||
88 | QString result(text); | 88 | QString result(text); |
89 | 89 | ||
90 | /* due a bug in libetpan it isn't usable this moment */ | 90 | /* due a bug in libetpan it isn't usable this moment */ |
91 | /* int err = mailmime_encoded_phrase_parse("iso-8859-1", | 91 | /* int err = mailmime_encoded_phrase_parse("iso-8859-1", |
92 | text, strlen(text),&index, "iso-8859-1",&res);*/ | 92 | text, strlen(text),&index, "iso-8859-1",&res);*/ |
93 | //qDebug("Input: %s",text); | 93 | //qDebug("Input: %s",text); |
94 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { | 94 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { |
95 | // result = QString(res); | 95 | // result = QString(res); |
96 | // qDebug("Res: %s, length: %i",res,strlen(res)); | 96 | // qDebug("Res: %s, length: %i",res,strlen(res)); |
97 | } | 97 | } |
98 | if (res) free(res); | 98 | if (res) free(res); |
99 | return result; | 99 | return result; |
100 | } | 100 | } |
101 | 101 | ||
102 | /* cp & paste from launcher */ | 102 | /* cp & paste from launcher */ |
103 | QString AbstractMail::gen_attachment_id() | 103 | QString AbstractMail::gen_attachment_id() |
104 | { | 104 | { |
105 | QFile file( "/proc/sys/kernel/random/uuid" ); | 105 | QFile file( "/proc/sys/kernel/random/uuid" ); |
106 | if (!file.open(IO_ReadOnly ) ) | 106 | if (!file.open(IO_ReadOnly ) ) |
107 | return QString::null; | 107 | return QString::null; |
108 | 108 | ||
109 | QTextStream stream(&file); | 109 | QTextStream stream(&file); |
110 | 110 | ||
111 | return "{" + stream.read().stripWhiteSpace() + "}"; | 111 | return "{" + stream.read().stripWhiteSpace() + "}"; |
112 | } | 112 | } |
113 | 113 | ||
114 | int AbstractMail::createMbox(const QString&,const Folder*,const QString& delemiter,bool) | 114 | int AbstractMail::createMbox(const QString&,const FolderP&,const QString& delemiter,bool) |
115 | { | 115 | { |
116 | return 0; | 116 | return 0; |
117 | } | 117 | } |
118 | 118 | ||
119 | QString AbstractMail::defaultLocalfolder() | 119 | QString AbstractMail::defaultLocalfolder() |
120 | { | 120 | { |
121 | QString f = getenv( "HOME" ); | 121 | QString f = getenv( "HOME" ); |
122 | f += "/Applications/opiemail/localmail"; | 122 | f += "/Applications/opiemail/localmail"; |
123 | return f; | 123 | return f; |
124 | } | 124 | } |
125 | 125 | ||
126 | QString AbstractMail::draftFolder() | 126 | QString AbstractMail::draftFolder() |
127 | { | 127 | { |
128 | return QString("Drafts"); | 128 | return QString("Drafts"); |
129 | } | 129 | } |
130 | 130 | ||
131 | /* temporary - will be removed when implemented in all classes */ | 131 | /* temporary - will be removed when implemented in all classes */ |
132 | void AbstractMail::deleteMails(const QString &,QList<RecMail> &) | 132 | void AbstractMail::deleteMails(const QString &,QList<RecMail> &) |
133 | { | 133 | { |
134 | } | 134 | } |
135 | 135 | ||
136 | void AbstractMail::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 136 | void AbstractMail::mvcpAllMails(const FolderP&fromFolder, |
137 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | ||
137 | { | 138 | { |
138 | QList<RecMail> t; | 139 | QList<RecMail> t; |
139 | listMessages(fromFolder->getName(),t); | 140 | listMessages(fromFolder->getName(),t); |
140 | encodedString*st = 0; | 141 | encodedString*st = 0; |
141 | while (t.count()>0) { | 142 | while (t.count()>0) { |
142 | RecMail*r = t.at(0); | 143 | RecMail*r = t.at(0); |
143 | st = fetchRawBody(*r); | 144 | st = fetchRawBody(*r); |
144 | if (st) { | 145 | if (st) { |
145 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); | 146 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); |
146 | delete st; | 147 | delete st; |
147 | } | 148 | } |
148 | t.removeFirst(); | 149 | t.removeFirst(); |
149 | } | 150 | } |
150 | if (moveit) { | 151 | if (moveit) { |
151 | deleteAllMail(fromFolder); | 152 | deleteAllMail(fromFolder); |
152 | } | 153 | } |
153 | } | 154 | } |
154 | 155 | ||
155 | void AbstractMail::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 156 | void AbstractMail::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
156 | { | 157 | { |
157 | encodedString*st = 0; | 158 | encodedString*st = 0; |
158 | st = fetchRawBody(mail); | 159 | st = fetchRawBody(mail); |
159 | if (st) { | 160 | if (st) { |
160 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); | 161 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); |
161 | delete st; | 162 | delete st; |
162 | } | 163 | } |
163 | if (moveit) { | 164 | if (moveit) { |
164 | deleteMail(mail); | 165 | deleteMail(mail); |
165 | } | 166 | } |
166 | } | 167 | } |
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h index d377452..d911468 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.h +++ b/noncore/net/mail/libmailwrapper/abstractmail.h | |||
@@ -1,70 +1,74 @@ | |||
1 | #ifndef __abstract_mail_ | 1 | #ifndef __abstract_mail_ |
2 | #define __abstract_mail_ | 2 | #define __abstract_mail_ |
3 | 3 | ||
4 | #include "maildefines.h" | 4 | #include "maildefines.h" |
5 | 5 | ||
6 | #include <qobject.h> | ||
7 | #include "settings.h" | 6 | #include "settings.h" |
8 | 7 | ||
8 | #include <qobject.h> | ||
9 | #include <opie2/osmart_pointer.h> | ||
10 | |||
9 | class RecMail; | 11 | class RecMail; |
10 | class RecBody; | 12 | class RecBody; |
11 | class RecPart; | 13 | class RecPart; |
12 | class IMAPwrapper; | 14 | class IMAPwrapper; |
13 | class POP3wrapper; | 15 | class POP3wrapper; |
14 | class Folder; | 16 | class Folder; |
15 | class encodedString; | 17 | class encodedString; |
16 | struct folderStat; | 18 | struct folderStat; |
17 | 19 | ||
18 | class AbstractMail:public QObject | 20 | class AbstractMail:public QObject |
19 | { | 21 | { |
20 | Q_OBJECT | 22 | Q_OBJECT |
21 | public: | 23 | public: |
22 | AbstractMail(){}; | 24 | AbstractMail(){}; |
23 | virtual ~AbstractMail(){} | 25 | virtual ~AbstractMail(){} |
24 | virtual QList<Folder>* listFolders()=0; | 26 | virtual QValueList<Opie::osmart_pointer<Folder> >* listFolders()=0; |
25 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; | 27 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; |
26 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0; | 28 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0; |
27 | virtual RecBody fetchBody(const RecMail&mail)=0; | 29 | virtual RecBody fetchBody(const RecMail&mail)=0; |
28 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; | 30 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; |
29 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; | 31 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; |
30 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; | 32 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; |
31 | virtual encodedString* fetchRawBody(const RecMail&mail)=0; | 33 | virtual encodedString* fetchRawBody(const RecMail&mail)=0; |
32 | 34 | ||
33 | virtual void deleteMail(const RecMail&mail)=0; | 35 | virtual void deleteMail(const RecMail&mail)=0; |
34 | virtual void answeredMail(const RecMail&mail)=0; | 36 | virtual void answeredMail(const RecMail&mail)=0; |
35 | virtual int deleteAllMail(const Folder*)=0; | 37 | virtual int deleteAllMail(const Opie::osmart_pointer<Folder>&)=0; |
36 | virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); | 38 | virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); |
37 | virtual int deleteMbox(const Folder*)=0; | 39 | virtual int deleteMbox(const Opie::osmart_pointer<Folder>&)=0; |
38 | virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0; | 40 | virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0; |
39 | 41 | ||
40 | virtual void mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | 42 | virtual void mvcpAllMails(const Opie::osmart_pointer<Folder>&fromFolder, |
43 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | ||
41 | virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | 44 | virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); |
42 | 45 | ||
43 | virtual void cleanMimeCache(){}; | 46 | virtual void cleanMimeCache(){}; |
44 | /* mail box methods */ | 47 | /* mail box methods */ |
45 | /* parameter is the box to create. | 48 | /* parameter is the box to create. |
46 | * if the implementing subclass has prefixes, | 49 | * if the implementing subclass has prefixes, |
47 | * them has to be appended automatic. | 50 | * them has to be appended automatic. |
48 | */ | 51 | */ |
49 | virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); | 52 | virtual int createMbox(const QString&,const Opie::osmart_pointer<Folder>&parentfolder=0, |
53 | const QString& delemiter="/",bool getsubfolder=false); | ||
50 | virtual void logout()=0; | 54 | virtual void logout()=0; |
51 | 55 | ||
52 | static AbstractMail* getWrapper(IMAPaccount *a); | 56 | static AbstractMail* getWrapper(IMAPaccount *a); |
53 | static AbstractMail* getWrapper(POP3account *a); | 57 | static AbstractMail* getWrapper(POP3account *a); |
54 | static AbstractMail* getWrapper(NNTPaccount *a); | 58 | static AbstractMail* getWrapper(NNTPaccount *a); |
55 | /* mbox only! */ | 59 | /* mbox only! */ |
56 | static AbstractMail* getWrapper(const QString&a,const QString&name="Local Folders"); | 60 | static AbstractMail* getWrapper(const QString&a,const QString&name="Local Folders"); |
57 | static AbstractMail* getWrapper(Account*a); | 61 | static AbstractMail* getWrapper(Account*a); |
58 | 62 | ||
59 | static QString defaultLocalfolder(); | 63 | static QString defaultLocalfolder(); |
60 | static QString draftFolder(); | 64 | static QString draftFolder(); |
61 | 65 | ||
62 | virtual MAILLIB::ATYPE getType()const=0; | 66 | virtual MAILLIB::ATYPE getType()const=0; |
63 | virtual const QString&getName()const=0; | 67 | virtual const QString&getName()const=0; |
64 | 68 | ||
65 | protected: | 69 | protected: |
66 | static encodedString*decode_String(const encodedString*text,const QString&enc); | 70 | static encodedString*decode_String(const encodedString*text,const QString&enc); |
67 | static QString convert_String(const char*text); | 71 | static QString convert_String(const char*text); |
68 | static QString gen_attachment_id(); | 72 | static QString gen_attachment_id(); |
69 | }; | 73 | }; |
70 | #endif | 74 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.h b/noncore/net/mail/libmailwrapper/genericwrapper.h index b3cd4fe..d0db45a 100644 --- a/noncore/net/mail/libmailwrapper/genericwrapper.h +++ b/noncore/net/mail/libmailwrapper/genericwrapper.h | |||
@@ -1,67 +1,67 @@ | |||
1 | #ifndef __GENERIC_WRAPPER_H | 1 | #ifndef __GENERIC_WRAPPER_H |
2 | #define __GENERIC_WRAPPER_H | 2 | #define __GENERIC_WRAPPER_H |
3 | 3 | ||
4 | #include "abstractmail.h" | 4 | #include "abstractmail.h" |
5 | #include <qmap.h> | 5 | #include <qmap.h> |
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | #include <libetpan/clist.h> | 7 | #include <libetpan/clist.h> |
8 | 8 | ||
9 | class RecMail; | 9 | class RecMail; |
10 | class RecBody; | 10 | class RecBody; |
11 | class encodedString; | 11 | class encodedString; |
12 | struct mailpop3; | 12 | struct mailpop3; |
13 | struct mailmessage; | 13 | struct mailmessage; |
14 | struct mailmime; | 14 | struct mailmime; |
15 | struct mailmime_mechanism; | 15 | struct mailmime_mechanism; |
16 | struct mailimf_mailbox_list; | 16 | struct mailimf_mailbox_list; |
17 | struct mailimf_mailbox; | 17 | struct mailimf_mailbox; |
18 | struct mailimf_date_time; | 18 | struct mailimf_date_time; |
19 | struct mailimf_group; | 19 | struct mailimf_group; |
20 | struct mailimf_address_list; | 20 | struct mailimf_address_list; |
21 | struct mailsession; | 21 | struct mailsession; |
22 | struct mailstorage; | 22 | struct mailstorage; |
23 | struct mailfolder; | 23 | struct mailfolder; |
24 | struct mailimf_in_reply_to; | 24 | struct mailimf_in_reply_to; |
25 | 25 | ||
26 | /* this class hold just the funs shared between | 26 | /* this class hold just the funs shared between |
27 | * mbox and pop3 (later mh, too) mail access. | 27 | * mbox and pop3 (later mh, too) mail access. |
28 | * it is not desigend to make a instance of it! | 28 | * it is not desigend to make a instance of it! |
29 | */ | 29 | */ |
30 | class Genericwrapper : public AbstractMail | 30 | class Genericwrapper : public AbstractMail |
31 | { | 31 | { |
32 | Q_OBJECT | 32 | Q_OBJECT |
33 | public: | 33 | public: |
34 | Genericwrapper(); | 34 | Genericwrapper(); |
35 | virtual ~Genericwrapper(); | 35 | virtual ~Genericwrapper(); |
36 | 36 | ||
37 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); | 37 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); |
38 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); | 38 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); |
39 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); | 39 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); |
40 | virtual void cleanMimeCache(); | 40 | virtual void cleanMimeCache(); |
41 | virtual int deleteMbox(const Folder*){return 1;} | 41 | virtual int deleteMbox(const Opie::osmart_pointer<Folder>&){return 1;} |
42 | virtual void logout(){}; | 42 | virtual void logout(){}; |
43 | virtual void storeMessage(const char*msg,size_t length, const QString&folder){}; | 43 | virtual void storeMessage(const char*msg,size_t length, const QString&folder){}; |
44 | 44 | ||
45 | protected: | 45 | protected: |
46 | RecBody parseMail( mailmessage * msg ); | 46 | RecBody parseMail( mailmessage * msg ); |
47 | QString parseMailboxList( mailimf_mailbox_list *list ); | 47 | QString parseMailboxList( mailimf_mailbox_list *list ); |
48 | QString parseMailbox( mailimf_mailbox *box ); | 48 | QString parseMailbox( mailimf_mailbox *box ); |
49 | QString parseGroup( mailimf_group *group ); | 49 | QString parseGroup( mailimf_group *group ); |
50 | QString parseAddressList( mailimf_address_list *list ); | 50 | QString parseAddressList( mailimf_address_list *list ); |
51 | QString parseDateTime( mailimf_date_time *date ); | 51 | QString parseDateTime( mailimf_date_time *date ); |
52 | 52 | ||
53 | void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=1); | 53 | void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=1); |
54 | static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); | 54 | static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); |
55 | static void fillParameters(RecPart&target,clist*parameters); | 55 | static void fillParameters(RecPart&target,clist*parameters); |
56 | static QString getencoding(mailmime_mechanism*aEnc); | 56 | static QString getencoding(mailmime_mechanism*aEnc); |
57 | virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox,bool mbox_as_to=false); | 57 | virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox,bool mbox_as_to=false); |
58 | QStringList parseInreplies(mailimf_in_reply_to * in_replies); | 58 | QStringList parseInreplies(mailimf_in_reply_to * in_replies); |
59 | 59 | ||
60 | QString msgTempName; | 60 | QString msgTempName; |
61 | unsigned int last_msg_id; | 61 | unsigned int last_msg_id; |
62 | QMap<QString,encodedString*> bodyCache; | 62 | QMap<QString,encodedString*> bodyCache; |
63 | mailstorage * m_storage; | 63 | mailstorage * m_storage; |
64 | mailfolder*m_folder; | 64 | mailfolder*m_folder; |
65 | }; | 65 | }; |
66 | 66 | ||
67 | #endif | 67 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index e29a0a0..3b3be0f 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,1185 +1,1185 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <libetpan/libetpan.h> | 2 | #include <libetpan/libetpan.h> |
3 | #include <qpe/global.h> | 3 | #include <qpe/global.h> |
4 | 4 | ||
5 | #include "imapwrapper.h" | 5 | #include "imapwrapper.h" |
6 | #include "mailtypes.h" | 6 | #include "mailtypes.h" |
7 | #include "logindialog.h" | 7 | #include "logindialog.h" |
8 | 8 | ||
9 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 9 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
10 | : AbstractMail() | 10 | : AbstractMail() |
11 | { | 11 | { |
12 | account = a; | 12 | account = a; |
13 | m_imap = 0; | 13 | m_imap = 0; |
14 | m_Lastmbox = ""; | 14 | m_Lastmbox = ""; |
15 | } | 15 | } |
16 | 16 | ||
17 | IMAPwrapper::~IMAPwrapper() | 17 | IMAPwrapper::~IMAPwrapper() |
18 | { | 18 | { |
19 | logout(); | 19 | logout(); |
20 | } | 20 | } |
21 | 21 | ||
22 | /* to avoid to often select statements in loops etc. | 22 | /* to avoid to often select statements in loops etc. |
23 | we trust that we are logged in and connection is established!*/ | 23 | we trust that we are logged in and connection is established!*/ |
24 | int IMAPwrapper::selectMbox(const QString&mbox) | 24 | int IMAPwrapper::selectMbox(const QString&mbox) |
25 | { | 25 | { |
26 | if (mbox == m_Lastmbox) { | 26 | if (mbox == m_Lastmbox) { |
27 | return MAILIMAP_NO_ERROR; | 27 | return MAILIMAP_NO_ERROR; |
28 | } | 28 | } |
29 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); | 29 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); |
30 | if ( err != MAILIMAP_NO_ERROR ) { | 30 | if ( err != MAILIMAP_NO_ERROR ) { |
31 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 31 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
32 | m_Lastmbox = ""; | 32 | m_Lastmbox = ""; |
33 | return err; | 33 | return err; |
34 | } | 34 | } |
35 | m_Lastmbox = mbox; | 35 | m_Lastmbox = mbox; |
36 | return err; | 36 | return err; |
37 | } | 37 | } |
38 | 38 | ||
39 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 39 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
40 | { | 40 | { |
41 | qDebug( "IMAP: %i of %i", current, maximum ); | 41 | qDebug( "IMAP: %i of %i", current, maximum ); |
42 | } | 42 | } |
43 | 43 | ||
44 | bool IMAPwrapper::start_tls(bool force_tls) | 44 | bool IMAPwrapper::start_tls(bool force_tls) |
45 | { | 45 | { |
46 | int err; | 46 | int err; |
47 | bool try_tls; | 47 | bool try_tls; |
48 | mailimap_capability_data * cap_data = 0; | 48 | mailimap_capability_data * cap_data = 0; |
49 | 49 | ||
50 | err = mailimap_capability(m_imap,&cap_data); | 50 | err = mailimap_capability(m_imap,&cap_data); |
51 | if (err != MAILIMAP_NO_ERROR) { | 51 | if (err != MAILIMAP_NO_ERROR) { |
52 | Global::statusMessage("error getting capabilities!"); | 52 | Global::statusMessage("error getting capabilities!"); |
53 | qDebug("error getting capabilities!"); | 53 | qDebug("error getting capabilities!"); |
54 | return false; | 54 | return false; |
55 | } | 55 | } |
56 | clistiter * cur; | 56 | clistiter * cur; |
57 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { | 57 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { |
58 | struct mailimap_capability * cap; | 58 | struct mailimap_capability * cap; |
59 | cap = (struct mailimap_capability *)clist_content(cur); | 59 | cap = (struct mailimap_capability *)clist_content(cur); |
60 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { | 60 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { |
61 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { | 61 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { |
62 | try_tls = true; | 62 | try_tls = true; |
63 | break; | 63 | break; |
64 | } | 64 | } |
65 | } | 65 | } |
66 | } | 66 | } |
67 | if (cap_data) { | 67 | if (cap_data) { |
68 | mailimap_capability_data_free(cap_data); | 68 | mailimap_capability_data_free(cap_data); |
69 | } | 69 | } |
70 | if (try_tls) { | 70 | if (try_tls) { |
71 | err = mailimap_starttls(m_imap); | 71 | err = mailimap_starttls(m_imap); |
72 | if (err != MAILIMAP_NO_ERROR && force_tls) { | 72 | if (err != MAILIMAP_NO_ERROR && force_tls) { |
73 | Global::statusMessage(tr("Server has no TLS support!")); | 73 | Global::statusMessage(tr("Server has no TLS support!")); |
74 | qDebug("Server has no TLS support!"); | 74 | qDebug("Server has no TLS support!"); |
75 | try_tls = false; | 75 | try_tls = false; |
76 | } else { | 76 | } else { |
77 | mailstream_low * low; | 77 | mailstream_low * low; |
78 | mailstream_low * new_low; | 78 | mailstream_low * new_low; |
79 | low = mailstream_get_low(m_imap->imap_stream); | 79 | low = mailstream_get_low(m_imap->imap_stream); |
80 | if (!low) { | 80 | if (!low) { |
81 | try_tls = false; | 81 | try_tls = false; |
82 | } else { | 82 | } else { |
83 | int fd = mailstream_low_get_fd(low); | 83 | int fd = mailstream_low_get_fd(low); |
84 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 84 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
85 | mailstream_low_free(low); | 85 | mailstream_low_free(low); |
86 | mailstream_set_low(m_imap->imap_stream, new_low); | 86 | mailstream_set_low(m_imap->imap_stream, new_low); |
87 | } else { | 87 | } else { |
88 | try_tls = false; | 88 | try_tls = false; |
89 | } | 89 | } |
90 | } | 90 | } |
91 | } | 91 | } |
92 | } | 92 | } |
93 | return try_tls; | 93 | return try_tls; |
94 | } | 94 | } |
95 | 95 | ||
96 | void IMAPwrapper::login() | 96 | void IMAPwrapper::login() |
97 | { | 97 | { |
98 | const char *server, *user, *pass; | 98 | const char *server, *user, *pass; |
99 | uint16_t port; | 99 | uint16_t port; |
100 | int err = MAILIMAP_NO_ERROR; | 100 | int err = MAILIMAP_NO_ERROR; |
101 | 101 | ||
102 | if (account->getOffline()) return; | 102 | if (account->getOffline()) return; |
103 | /* we are connected this moment */ | 103 | /* we are connected this moment */ |
104 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 104 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
105 | if (m_imap) { | 105 | if (m_imap) { |
106 | err = mailimap_noop(m_imap); | 106 | err = mailimap_noop(m_imap); |
107 | if (err!=MAILIMAP_NO_ERROR) { | 107 | if (err!=MAILIMAP_NO_ERROR) { |
108 | logout(); | 108 | logout(); |
109 | } else { | 109 | } else { |
110 | mailstream_flush(m_imap->imap_stream); | 110 | mailstream_flush(m_imap->imap_stream); |
111 | return; | 111 | return; |
112 | } | 112 | } |
113 | } | 113 | } |
114 | server = account->getServer().latin1(); | 114 | server = account->getServer().latin1(); |
115 | port = account->getPort().toUInt(); | 115 | port = account->getPort().toUInt(); |
116 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 116 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
117 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 117 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
118 | login.show(); | 118 | login.show(); |
119 | if ( QDialog::Accepted == login.exec() ) { | 119 | if ( QDialog::Accepted == login.exec() ) { |
120 | // ok | 120 | // ok |
121 | user = login.getUser().latin1(); | 121 | user = login.getUser().latin1(); |
122 | pass = login.getPassword().latin1(); | 122 | pass = login.getPassword().latin1(); |
123 | } else { | 123 | } else { |
124 | // cancel | 124 | // cancel |
125 | qDebug( "IMAP: Login canceled" ); | 125 | qDebug( "IMAP: Login canceled" ); |
126 | return; | 126 | return; |
127 | } | 127 | } |
128 | } else { | 128 | } else { |
129 | user = account->getUser().latin1(); | 129 | user = account->getUser().latin1(); |
130 | pass = account->getPassword().latin1(); | 130 | pass = account->getPassword().latin1(); |
131 | } | 131 | } |
132 | 132 | ||
133 | m_imap = mailimap_new( 20, &imap_progress ); | 133 | m_imap = mailimap_new( 20, &imap_progress ); |
134 | 134 | ||
135 | /* connect */ | 135 | /* connect */ |
136 | bool ssl = false; | 136 | bool ssl = false; |
137 | bool try_tls = false; | 137 | bool try_tls = false; |
138 | bool force_tls = false; | 138 | bool force_tls = false; |
139 | 139 | ||
140 | if ( account->ConnectionType() == 2 ) { | 140 | if ( account->ConnectionType() == 2 ) { |
141 | ssl = true; | 141 | ssl = true; |
142 | } | 142 | } |
143 | if (account->ConnectionType()==1) { | 143 | if (account->ConnectionType()==1) { |
144 | force_tls = true; | 144 | force_tls = true; |
145 | } | 145 | } |
146 | 146 | ||
147 | if ( ssl ) { | 147 | if ( ssl ) { |
148 | qDebug( "using ssl" ); | 148 | qDebug( "using ssl" ); |
149 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 149 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
150 | } else { | 150 | } else { |
151 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 151 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
152 | } | 152 | } |
153 | 153 | ||
154 | if ( err != MAILIMAP_NO_ERROR && | 154 | if ( err != MAILIMAP_NO_ERROR && |
155 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 155 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
156 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 156 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
157 | QString failure = ""; | 157 | QString failure = ""; |
158 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | 158 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { |
159 | failure="Connection refused"; | 159 | failure="Connection refused"; |
160 | } else { | 160 | } else { |
161 | failure="Unknown failure"; | 161 | failure="Unknown failure"; |
162 | } | 162 | } |
163 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); | 163 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); |
164 | mailimap_free( m_imap ); | 164 | mailimap_free( m_imap ); |
165 | m_imap = 0; | 165 | m_imap = 0; |
166 | return; | 166 | return; |
167 | } | 167 | } |
168 | 168 | ||
169 | if (!ssl) { | 169 | if (!ssl) { |
170 | try_tls = start_tls(force_tls); | 170 | try_tls = start_tls(force_tls); |
171 | } | 171 | } |
172 | 172 | ||
173 | bool ok = true; | 173 | bool ok = true; |
174 | if (force_tls && !try_tls) { | 174 | if (force_tls && !try_tls) { |
175 | Global::statusMessage(tr("Server has no TLS support!")); | 175 | Global::statusMessage(tr("Server has no TLS support!")); |
176 | qDebug("Server has no TLS support!"); | 176 | qDebug("Server has no TLS support!"); |
177 | ok = false; | 177 | ok = false; |
178 | } | 178 | } |
179 | 179 | ||
180 | 180 | ||
181 | /* login */ | 181 | /* login */ |
182 | 182 | ||
183 | if (ok) { | 183 | if (ok) { |
184 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 184 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
185 | if ( err != MAILIMAP_NO_ERROR ) { | 185 | if ( err != MAILIMAP_NO_ERROR ) { |
186 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); | 186 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); |
187 | ok = false; | 187 | ok = false; |
188 | } | 188 | } |
189 | } | 189 | } |
190 | if (!ok) { | 190 | if (!ok) { |
191 | err = mailimap_close( m_imap ); | 191 | err = mailimap_close( m_imap ); |
192 | mailimap_free( m_imap ); | 192 | mailimap_free( m_imap ); |
193 | m_imap = 0; | 193 | m_imap = 0; |
194 | } | 194 | } |
195 | } | 195 | } |
196 | 196 | ||
197 | void IMAPwrapper::logout() | 197 | void IMAPwrapper::logout() |
198 | { | 198 | { |
199 | int err = MAILIMAP_NO_ERROR; | 199 | int err = MAILIMAP_NO_ERROR; |
200 | if (!m_imap) return; | 200 | if (!m_imap) return; |
201 | err = mailimap_logout( m_imap ); | 201 | err = mailimap_logout( m_imap ); |
202 | err = mailimap_close( m_imap ); | 202 | err = mailimap_close( m_imap ); |
203 | mailimap_free( m_imap ); | 203 | mailimap_free( m_imap ); |
204 | m_imap = 0; | 204 | m_imap = 0; |
205 | m_Lastmbox = ""; | 205 | m_Lastmbox = ""; |
206 | } | 206 | } |
207 | 207 | ||
208 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 208 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
209 | { | 209 | { |
210 | int err = MAILIMAP_NO_ERROR; | 210 | int err = MAILIMAP_NO_ERROR; |
211 | clist *result = 0; | 211 | clist *result = 0; |
212 | clistcell *current; | 212 | clistcell *current; |
213 | mailimap_fetch_type *fetchType = 0; | 213 | mailimap_fetch_type *fetchType = 0; |
214 | mailimap_set *set = 0; | 214 | mailimap_set *set = 0; |
215 | 215 | ||
216 | login(); | 216 | login(); |
217 | if (!m_imap) { | 217 | if (!m_imap) { |
218 | return; | 218 | return; |
219 | } | 219 | } |
220 | /* select mailbox READONLY for operations */ | 220 | /* select mailbox READONLY for operations */ |
221 | err = selectMbox(mailbox); | 221 | err = selectMbox(mailbox); |
222 | if ( err != MAILIMAP_NO_ERROR ) { | 222 | if ( err != MAILIMAP_NO_ERROR ) { |
223 | return; | 223 | return; |
224 | } | 224 | } |
225 | 225 | ||
226 | int last = m_imap->imap_selection_info->sel_exists; | 226 | int last = m_imap->imap_selection_info->sel_exists; |
227 | 227 | ||
228 | if (last == 0) { | 228 | if (last == 0) { |
229 | Global::statusMessage(tr("Mailbox has no mails")); | 229 | Global::statusMessage(tr("Mailbox has no mails")); |
230 | return; | 230 | return; |
231 | } else { | 231 | } else { |
232 | } | 232 | } |
233 | 233 | ||
234 | /* the range has to start at 1!!! not with 0!!!! */ | 234 | /* the range has to start at 1!!! not with 0!!!! */ |
235 | set = mailimap_set_new_interval( 1, last ); | 235 | set = mailimap_set_new_interval( 1, last ); |
236 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 236 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
237 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 237 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
238 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 238 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
239 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 239 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
240 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 240 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
241 | 241 | ||
242 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 242 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
243 | mailimap_set_free( set ); | 243 | mailimap_set_free( set ); |
244 | mailimap_fetch_type_free( fetchType ); | 244 | mailimap_fetch_type_free( fetchType ); |
245 | 245 | ||
246 | QString date,subject,from; | 246 | QString date,subject,from; |
247 | 247 | ||
248 | if ( err == MAILIMAP_NO_ERROR ) { | 248 | if ( err == MAILIMAP_NO_ERROR ) { |
249 | mailimap_msg_att * msg_att; | 249 | mailimap_msg_att * msg_att; |
250 | int i = 0; | 250 | int i = 0; |
251 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 251 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
252 | ++i; | 252 | ++i; |
253 | msg_att = (mailimap_msg_att*)current->data; | 253 | msg_att = (mailimap_msg_att*)current->data; |
254 | RecMail*m = parse_list_result(msg_att); | 254 | RecMail*m = parse_list_result(msg_att); |
255 | if (m) { | 255 | if (m) { |
256 | m->setNumber(i); | 256 | m->setNumber(i); |
257 | m->setMbox(mailbox); | 257 | m->setMbox(mailbox); |
258 | m->setWrapper(this); | 258 | m->setWrapper(this); |
259 | target.append(m); | 259 | target.append(m); |
260 | } | 260 | } |
261 | } | 261 | } |
262 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); | 262 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); |
263 | } else { | 263 | } else { |
264 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); | 264 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); |
265 | } | 265 | } |
266 | if (result) mailimap_fetch_list_free(result); | 266 | if (result) mailimap_fetch_list_free(result); |
267 | } | 267 | } |
268 | 268 | ||
269 | QList<Folder>* IMAPwrapper::listFolders() | 269 | QValueList<Opie::osmart_pointer<Folder> >* IMAPwrapper::listFolders() |
270 | { | 270 | { |
271 | const char *path, *mask; | 271 | const char *path, *mask; |
272 | int err = MAILIMAP_NO_ERROR; | 272 | int err = MAILIMAP_NO_ERROR; |
273 | clist *result = 0; | 273 | clist *result = 0; |
274 | clistcell *current = 0; | 274 | clistcell *current = 0; |
275 | clistcell*cur_flag = 0; | 275 | clistcell*cur_flag = 0; |
276 | mailimap_mbx_list_flags*bflags = 0; | 276 | mailimap_mbx_list_flags*bflags = 0; |
277 | 277 | ||
278 | QList<Folder> * folders = new QList<Folder>(); | 278 | QValueList<FolderP>* folders = new QValueList<FolderP>(); |
279 | folders->setAutoDelete( false ); | ||
280 | login(); | 279 | login(); |
281 | if (!m_imap) { | 280 | if (!m_imap) { |
282 | return folders; | 281 | return folders; |
283 | } | 282 | } |
284 | 283 | ||
285 | /* | 284 | /* |
286 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 285 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
287 | * We must not forget to filter them out in next loop! | 286 | * We must not forget to filter them out in next loop! |
288 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 287 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
289 | */ | 288 | */ |
290 | QString temp; | 289 | QString temp; |
291 | mask = "INBOX" ; | 290 | mask = "INBOX" ; |
292 | mailimap_mailbox_list *list; | 291 | mailimap_mailbox_list *list; |
293 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 292 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
294 | QString del; | 293 | QString del; |
295 | bool selectable = true; | 294 | bool selectable = true; |
296 | bool no_inferiors = false; | 295 | bool no_inferiors = false; |
297 | if ( err == MAILIMAP_NO_ERROR ) { | 296 | if ( err == MAILIMAP_NO_ERROR ) { |
298 | current = result->first; | 297 | current = result->first; |
299 | for ( int i = result->count; i > 0; i-- ) { | 298 | for ( int i = result->count; i > 0; i-- ) { |
300 | list = (mailimap_mailbox_list *) current->data; | 299 | list = (mailimap_mailbox_list *) current->data; |
301 | // it is better use the deep copy mechanism of qt itself | 300 | // it is better use the deep copy mechanism of qt itself |
302 | // instead of using strdup! | 301 | // instead of using strdup! |
303 | temp = list->mb_name; | 302 | temp = list->mb_name; |
304 | del = list->mb_delimiter; | 303 | del = list->mb_delimiter; |
305 | current = current->next; | 304 | current = current->next; |
306 | if ( (bflags = list->mb_flag) ) { | 305 | if ( (bflags = list->mb_flag) ) { |
307 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 306 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
308 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 307 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
309 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 308 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
310 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 309 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
311 | no_inferiors = true; | 310 | no_inferiors = true; |
312 | } | 311 | } |
313 | } | 312 | } |
314 | } | 313 | } |
315 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 314 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
316 | } | 315 | } |
317 | } else { | 316 | } else { |
318 | qDebug("error fetching folders: %s",m_imap->imap_response); | 317 | qDebug("error fetching folders: %s",m_imap->imap_response); |
319 | } | 318 | } |
320 | mailimap_list_result_free( result ); | 319 | mailimap_list_result_free( result ); |
321 | 320 | ||
322 | /* | 321 | /* |
323 | * second stage - get the other then inbox folders | 322 | * second stage - get the other then inbox folders |
324 | */ | 323 | */ |
325 | mask = "*" ; | 324 | mask = "*" ; |
326 | path = account->getPrefix().latin1(); | 325 | path = account->getPrefix().latin1(); |
327 | if (!path) path = ""; | 326 | if (!path) path = ""; |
328 | qDebug(path); | 327 | qDebug(path); |
329 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 328 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
330 | if ( err == MAILIMAP_NO_ERROR ) { | 329 | if ( err == MAILIMAP_NO_ERROR ) { |
331 | current = result->first; | 330 | current = result->first; |
332 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 331 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
333 | no_inferiors = false; | 332 | no_inferiors = false; |
334 | list = (mailimap_mailbox_list *) current->data; | 333 | list = (mailimap_mailbox_list *) current->data; |
335 | // it is better use the deep copy mechanism of qt itself | 334 | // it is better use the deep copy mechanism of qt itself |
336 | // instead of using strdup! | 335 | // instead of using strdup! |
337 | temp = list->mb_name; | 336 | temp = list->mb_name; |
338 | if (temp.lower()=="inbox") | 337 | if (temp.lower()=="inbox") |
339 | continue; | 338 | continue; |
340 | if (temp.lower()==account->getPrefix().lower()) | 339 | if (temp.lower()==account->getPrefix().lower()) |
341 | continue; | 340 | continue; |
342 | if ( (bflags = list->mb_flag) ) { | 341 | if ( (bflags = list->mb_flag) ) { |
343 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 342 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
344 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 343 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
345 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 344 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
346 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 345 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
347 | no_inferiors = true; | 346 | no_inferiors = true; |
348 | } | 347 | } |
349 | } | 348 | } |
350 | } | 349 | } |
351 | del = list->mb_delimiter; | 350 | del = list->mb_delimiter; |
352 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 351 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
353 | } | 352 | } |
354 | } else { | 353 | } else { |
355 | qDebug("error fetching folders %s",m_imap->imap_response); | 354 | qDebug("error fetching folders %s",m_imap->imap_response); |
356 | } | 355 | } |
357 | if (result) mailimap_list_result_free( result ); | 356 | if (result) mailimap_list_result_free( result ); |
358 | return folders; | 357 | return folders; |
359 | } | 358 | } |
360 | 359 | ||
361 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 360 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
362 | { | 361 | { |
363 | RecMail * m = 0; | 362 | RecMail * m = 0; |
364 | mailimap_msg_att_item *item=0; | 363 | mailimap_msg_att_item *item=0; |
365 | clistcell *current,*c,*cf; | 364 | clistcell *current,*c,*cf; |
366 | mailimap_msg_att_dynamic*flist; | 365 | mailimap_msg_att_dynamic*flist; |
367 | mailimap_flag_fetch*cflag; | 366 | mailimap_flag_fetch*cflag; |
368 | int size; | 367 | int size; |
369 | QBitArray mFlags(7); | 368 | QBitArray mFlags(7); |
370 | QStringList addresslist; | 369 | QStringList addresslist; |
371 | 370 | ||
372 | if (!m_att) { | 371 | if (!m_att) { |
373 | return m; | 372 | return m; |
374 | } | 373 | } |
375 | m = new RecMail(); | 374 | m = new RecMail(); |
376 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 375 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
377 | current = c; | 376 | current = c; |
378 | size = 0; | 377 | size = 0; |
379 | item = (mailimap_msg_att_item*)current->data; | 378 | item = (mailimap_msg_att_item*)current->data; |
380 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 379 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
381 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 380 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
382 | if (!flist->att_list) { | 381 | if (!flist->att_list) { |
383 | continue; | 382 | continue; |
384 | } | 383 | } |
385 | cf = flist->att_list->first; | 384 | cf = flist->att_list->first; |
386 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 385 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
387 | cflag = (mailimap_flag_fetch*)cf->data; | 386 | cflag = (mailimap_flag_fetch*)cf->data; |
388 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 387 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
389 | switch (cflag->fl_flag->fl_type) { | 388 | switch (cflag->fl_flag->fl_type) { |
390 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 389 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
391 | mFlags.setBit(FLAG_ANSWERED); | 390 | mFlags.setBit(FLAG_ANSWERED); |
392 | break; | 391 | break; |
393 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 392 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
394 | mFlags.setBit(FLAG_FLAGGED); | 393 | mFlags.setBit(FLAG_FLAGGED); |
395 | break; | 394 | break; |
396 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 395 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
397 | mFlags.setBit(FLAG_DELETED); | 396 | mFlags.setBit(FLAG_DELETED); |
398 | break; | 397 | break; |
399 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 398 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
400 | mFlags.setBit(FLAG_SEEN); | 399 | mFlags.setBit(FLAG_SEEN); |
401 | break; | 400 | break; |
402 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 401 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
403 | mFlags.setBit(FLAG_DRAFT); | 402 | mFlags.setBit(FLAG_DRAFT); |
404 | break; | 403 | break; |
405 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 404 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
406 | break; | 405 | break; |
407 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 406 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
408 | break; | 407 | break; |
409 | default: | 408 | default: |
410 | break; | 409 | break; |
411 | } | 410 | } |
412 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 411 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
413 | mFlags.setBit(FLAG_RECENT); | 412 | mFlags.setBit(FLAG_RECENT); |
414 | } | 413 | } |
415 | } | 414 | } |
416 | continue; | 415 | continue; |
417 | } | 416 | } |
418 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 417 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
419 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 418 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
420 | m->setDate(head->env_date); | 419 | m->setDate(head->env_date); |
421 | m->setSubject(convert_String((const char*)head->env_subject)); | 420 | m->setSubject(convert_String((const char*)head->env_subject)); |
422 | //m->setSubject(head->env_subject); | 421 | //m->setSubject(head->env_subject); |
423 | if (head->env_from!=NULL) { | 422 | if (head->env_from!=NULL) { |
424 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 423 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
425 | if (addresslist.count()) { | 424 | if (addresslist.count()) { |
426 | m->setFrom(addresslist.first()); | 425 | m->setFrom(addresslist.first()); |
427 | } | 426 | } |
428 | } | 427 | } |
429 | if (head->env_to!=NULL) { | 428 | if (head->env_to!=NULL) { |
430 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 429 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
431 | m->setTo(addresslist); | 430 | m->setTo(addresslist); |
432 | } | 431 | } |
433 | if (head->env_cc!=NULL) { | 432 | if (head->env_cc!=NULL) { |
434 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 433 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
435 | m->setCC(addresslist); | 434 | m->setCC(addresslist); |
436 | } | 435 | } |
437 | if (head->env_bcc!=NULL) { | 436 | if (head->env_bcc!=NULL) { |
438 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 437 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
439 | m->setBcc(addresslist); | 438 | m->setBcc(addresslist); |
440 | } | 439 | } |
441 | /* reply to address, eg. email. */ | 440 | /* reply to address, eg. email. */ |
442 | if (head->env_reply_to!=NULL) { | 441 | if (head->env_reply_to!=NULL) { |
443 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 442 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
444 | if (addresslist.count()) { | 443 | if (addresslist.count()) { |
445 | m->setReplyto(addresslist.first()); | 444 | m->setReplyto(addresslist.first()); |
446 | } | 445 | } |
447 | } | 446 | } |
448 | if (head->env_in_reply_to!=NULL) { | 447 | if (head->env_in_reply_to!=NULL) { |
449 | QString h(head->env_in_reply_to); | 448 | QString h(head->env_in_reply_to); |
450 | while (h.length()>0 && h[0]=='<') { | 449 | while (h.length()>0 && h[0]=='<') { |
451 | h.remove(0,1); | 450 | h.remove(0,1); |
452 | } | 451 | } |
453 | while (h.length()>0 && h[h.length()-1]=='>') { | 452 | while (h.length()>0 && h[h.length()-1]=='>') { |
454 | h.remove(h.length()-1,1); | 453 | h.remove(h.length()-1,1); |
455 | } | 454 | } |
456 | if (h.length()>0) { | 455 | if (h.length()>0) { |
457 | m->setInreply(QStringList(h)); | 456 | m->setInreply(QStringList(h)); |
458 | } | 457 | } |
459 | } | 458 | } |
460 | if (head->env_message_id) { | 459 | if (head->env_message_id) { |
461 | m->setMsgid(QString(head->env_message_id)); | 460 | m->setMsgid(QString(head->env_message_id)); |
462 | } | 461 | } |
463 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 462 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
464 | #if 0 | 463 | #if 0 |
465 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 464 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
466 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 465 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
467 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); | 466 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); |
468 | qDebug(da.toString()); | 467 | qDebug(da.toString()); |
469 | #endif | 468 | #endif |
470 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 469 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
471 | size = item->att_data.att_static->att_data.att_rfc822_size; | 470 | size = item->att_data.att_static->att_data.att_rfc822_size; |
472 | } | 471 | } |
473 | } | 472 | } |
474 | /* msg is already deleted */ | 473 | /* msg is already deleted */ |
475 | if (mFlags.testBit(FLAG_DELETED) && m) { | 474 | if (mFlags.testBit(FLAG_DELETED) && m) { |
476 | delete m; | 475 | delete m; |
477 | m = 0; | 476 | m = 0; |
478 | } | 477 | } |
479 | if (m) { | 478 | if (m) { |
480 | m->setFlags(mFlags); | 479 | m->setFlags(mFlags); |
481 | m->setMsgsize(size); | 480 | m->setMsgsize(size); |
482 | } | 481 | } |
483 | return m; | 482 | return m; |
484 | } | 483 | } |
485 | 484 | ||
486 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 485 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
487 | { | 486 | { |
488 | RecBody body; | 487 | RecBody body; |
489 | const char *mb; | 488 | const char *mb; |
490 | int err = MAILIMAP_NO_ERROR; | 489 | int err = MAILIMAP_NO_ERROR; |
491 | clist *result = 0; | 490 | clist *result = 0; |
492 | clistcell *current; | 491 | clistcell *current; |
493 | mailimap_fetch_att *fetchAtt = 0; | 492 | mailimap_fetch_att *fetchAtt = 0; |
494 | mailimap_fetch_type *fetchType = 0; | 493 | mailimap_fetch_type *fetchType = 0; |
495 | mailimap_set *set = 0; | 494 | mailimap_set *set = 0; |
496 | mailimap_body*body_desc = 0; | 495 | mailimap_body*body_desc = 0; |
497 | 496 | ||
498 | mb = mail.getMbox().latin1(); | 497 | mb = mail.getMbox().latin1(); |
499 | 498 | ||
500 | login(); | 499 | login(); |
501 | if (!m_imap) { | 500 | if (!m_imap) { |
502 | return body; | 501 | return body; |
503 | } | 502 | } |
504 | err = selectMbox(mail.getMbox()); | 503 | err = selectMbox(mail.getMbox()); |
505 | if ( err != MAILIMAP_NO_ERROR ) { | 504 | if ( err != MAILIMAP_NO_ERROR ) { |
506 | return body; | 505 | return body; |
507 | } | 506 | } |
508 | 507 | ||
509 | /* the range has to start at 1!!! not with 0!!!! */ | 508 | /* the range has to start at 1!!! not with 0!!!! */ |
510 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 509 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
511 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 510 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
512 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 511 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
513 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 512 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
514 | mailimap_set_free( set ); | 513 | mailimap_set_free( set ); |
515 | mailimap_fetch_type_free( fetchType ); | 514 | mailimap_fetch_type_free( fetchType ); |
516 | 515 | ||
517 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 516 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
518 | mailimap_msg_att * msg_att; | 517 | mailimap_msg_att * msg_att; |
519 | msg_att = (mailimap_msg_att*)current->data; | 518 | msg_att = (mailimap_msg_att*)current->data; |
520 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 519 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
521 | QValueList<int> path; | 520 | QValueList<int> path; |
522 | body_desc = item->att_data.att_static->att_data.att_body; | 521 | body_desc = item->att_data.att_static->att_data.att_body; |
523 | traverseBody(mail,body_desc,body,0,path); | 522 | traverseBody(mail,body_desc,body,0,path); |
524 | } else { | 523 | } else { |
525 | qDebug("error fetching body: %s",m_imap->imap_response); | 524 | qDebug("error fetching body: %s",m_imap->imap_response); |
526 | } | 525 | } |
527 | if (result) mailimap_fetch_list_free(result); | 526 | if (result) mailimap_fetch_list_free(result); |
528 | return body; | 527 | return body; |
529 | } | 528 | } |
530 | 529 | ||
531 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 530 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
532 | { | 531 | { |
533 | QStringList l; | 532 | QStringList l; |
534 | QString from; | 533 | QString from; |
535 | bool named_from; | 534 | bool named_from; |
536 | clistcell *current = NULL; | 535 | clistcell *current = NULL; |
537 | mailimap_address * current_address=NULL; | 536 | mailimap_address * current_address=NULL; |
538 | if (!list) { | 537 | if (!list) { |
539 | return l; | 538 | return l; |
540 | } | 539 | } |
541 | unsigned int count = 0; | 540 | unsigned int count = 0; |
542 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 541 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
543 | from = ""; | 542 | from = ""; |
544 | named_from = false; | 543 | named_from = false; |
545 | current_address=(mailimap_address*)current->data; | 544 | current_address=(mailimap_address*)current->data; |
546 | if (current_address->ad_personal_name){ | 545 | if (current_address->ad_personal_name){ |
547 | from+=convert_String((const char*)current_address->ad_personal_name); | 546 | from+=convert_String((const char*)current_address->ad_personal_name); |
548 | from+=" "; | 547 | from+=" "; |
549 | named_from = true; | 548 | named_from = true; |
550 | } | 549 | } |
551 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 550 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
552 | from+="<"; | 551 | from+="<"; |
553 | } | 552 | } |
554 | if (current_address->ad_mailbox_name) { | 553 | if (current_address->ad_mailbox_name) { |
555 | from+=QString(current_address->ad_mailbox_name); | 554 | from+=QString(current_address->ad_mailbox_name); |
556 | from+="@"; | 555 | from+="@"; |
557 | } | 556 | } |
558 | if (current_address->ad_host_name) { | 557 | if (current_address->ad_host_name) { |
559 | from+=QString(current_address->ad_host_name); | 558 | from+=QString(current_address->ad_host_name); |
560 | } | 559 | } |
561 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 560 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
562 | from+=">"; | 561 | from+=">"; |
563 | } | 562 | } |
564 | l.append(QString(from)); | 563 | l.append(QString(from)); |
565 | if (++count > 99) { | 564 | if (++count > 99) { |
566 | break; | 565 | break; |
567 | } | 566 | } |
568 | } | 567 | } |
569 | return l; | 568 | return l; |
570 | } | 569 | } |
571 | 570 | ||
572 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) | 571 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
573 | { | 572 | { |
574 | encodedString*res=new encodedString; | 573 | encodedString*res=new encodedString; |
575 | int err; | 574 | int err; |
576 | mailimap_fetch_type *fetchType; | 575 | mailimap_fetch_type *fetchType; |
577 | mailimap_set *set; | 576 | mailimap_set *set; |
578 | clistcell*current,*cur; | 577 | clistcell*current,*cur; |
579 | mailimap_section_part * section_part = 0; | 578 | mailimap_section_part * section_part = 0; |
580 | mailimap_section_spec * section_spec = 0; | 579 | mailimap_section_spec * section_spec = 0; |
581 | mailimap_section * section = 0; | 580 | mailimap_section * section = 0; |
582 | mailimap_fetch_att * fetch_att = 0; | 581 | mailimap_fetch_att * fetch_att = 0; |
583 | 582 | ||
584 | login(); | 583 | login(); |
585 | if (!m_imap) { | 584 | if (!m_imap) { |
586 | return res; | 585 | return res; |
587 | } | 586 | } |
588 | if (!internal_call) { | 587 | if (!internal_call) { |
589 | err = selectMbox(mail.getMbox()); | 588 | err = selectMbox(mail.getMbox()); |
590 | if ( err != MAILIMAP_NO_ERROR ) { | 589 | if ( err != MAILIMAP_NO_ERROR ) { |
591 | return res; | 590 | return res; |
592 | } | 591 | } |
593 | } | 592 | } |
594 | set = mailimap_set_new_single(mail.getNumber()); | 593 | set = mailimap_set_new_single(mail.getNumber()); |
595 | 594 | ||
596 | clist*id_list = 0; | 595 | clist*id_list = 0; |
597 | 596 | ||
598 | /* if path == empty then its a request for the whole rfc822 mail and generates | 597 | /* if path == empty then its a request for the whole rfc822 mail and generates |
599 | a "fetch <id> (body[])" statement on imap server */ | 598 | a "fetch <id> (body[])" statement on imap server */ |
600 | if (path.count()>0 ) { | 599 | if (path.count()>0 ) { |
601 | id_list = clist_new(); | 600 | id_list = clist_new(); |
602 | for (unsigned j=0; j < path.count();++j) { | 601 | for (unsigned j=0; j < path.count();++j) { |
603 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 602 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
604 | *p_id = path[j]; | 603 | *p_id = path[j]; |
605 | clist_append(id_list,p_id); | 604 | clist_append(id_list,p_id); |
606 | } | 605 | } |
607 | section_part = mailimap_section_part_new(id_list); | 606 | section_part = mailimap_section_part_new(id_list); |
608 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 607 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
609 | } | 608 | } |
610 | 609 | ||
611 | section = mailimap_section_new(section_spec); | 610 | section = mailimap_section_new(section_spec); |
612 | fetch_att = mailimap_fetch_att_new_body_section(section); | 611 | fetch_att = mailimap_fetch_att_new_body_section(section); |
613 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 612 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
614 | 613 | ||
615 | clist*result = 0; | 614 | clist*result = 0; |
616 | 615 | ||
617 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 616 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
618 | mailimap_set_free( set ); | 617 | mailimap_set_free( set ); |
619 | mailimap_fetch_type_free( fetchType ); | 618 | mailimap_fetch_type_free( fetchType ); |
620 | 619 | ||
621 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 620 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
622 | mailimap_msg_att * msg_att; | 621 | mailimap_msg_att * msg_att; |
623 | msg_att = (mailimap_msg_att*)current->data; | 622 | msg_att = (mailimap_msg_att*)current->data; |
624 | mailimap_msg_att_item*msg_att_item; | 623 | mailimap_msg_att_item*msg_att_item; |
625 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 624 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
626 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 625 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
627 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 626 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
628 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 627 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
629 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 628 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
630 | /* detach - we take over the content */ | 629 | /* detach - we take over the content */ |
631 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 630 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
632 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 631 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
633 | } | 632 | } |
634 | } | 633 | } |
635 | } | 634 | } |
636 | } else { | 635 | } else { |
637 | qDebug("error fetching text: %s",m_imap->imap_response); | 636 | qDebug("error fetching text: %s",m_imap->imap_response); |
638 | } | 637 | } |
639 | if (result) mailimap_fetch_list_free(result); | 638 | if (result) mailimap_fetch_list_free(result); |
640 | return res; | 639 | return res; |
641 | } | 640 | } |
642 | 641 | ||
643 | /* current_recursion is for recursive calls. | 642 | /* current_recursion is for recursive calls. |
644 | current_count means the position inside the internal loop! */ | 643 | current_count means the position inside the internal loop! */ |
645 | void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, | 644 | void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, |
646 | int current_recursion,QValueList<int>recList,int current_count) | 645 | int current_recursion,QValueList<int>recList,int current_count) |
647 | { | 646 | { |
648 | if (!body || current_recursion>=10) { | 647 | if (!body || current_recursion>=10) { |
649 | return; | 648 | return; |
650 | } | 649 | } |
651 | switch (body->bd_type) { | 650 | switch (body->bd_type) { |
652 | case MAILIMAP_BODY_1PART: | 651 | case MAILIMAP_BODY_1PART: |
653 | { | 652 | { |
654 | QValueList<int>countlist = recList; | 653 | QValueList<int>countlist = recList; |
655 | countlist.append(current_count); | 654 | countlist.append(current_count); |
656 | RecPart currentPart; | 655 | RecPart currentPart; |
657 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; | 656 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; |
658 | QString id(""); | 657 | QString id(""); |
659 | currentPart.setPositionlist(countlist); | 658 | currentPart.setPositionlist(countlist); |
660 | for (unsigned int j = 0; j < countlist.count();++j) { | 659 | for (unsigned int j = 0; j < countlist.count();++j) { |
661 | id+=(j>0?" ":""); | 660 | id+=(j>0?" ":""); |
662 | id+=QString("%1").arg(countlist[j]); | 661 | id+=QString("%1").arg(countlist[j]); |
663 | } | 662 | } |
664 | qDebug("ID = %s",id.latin1()); | 663 | qDebug("ID = %s",id.latin1()); |
665 | currentPart.setIdentifier(id); | 664 | currentPart.setIdentifier(id); |
666 | fillSinglePart(currentPart,part1); | 665 | fillSinglePart(currentPart,part1); |
667 | /* important: Check for is NULL 'cause a body can be empty! | 666 | /* important: Check for is NULL 'cause a body can be empty! |
668 | And we put it only into the mail if it is the FIRST part */ | 667 | And we put it only into the mail if it is the FIRST part */ |
669 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { | 668 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { |
670 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); | 669 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); |
671 | target_body.setDescription(currentPart); | 670 | target_body.setDescription(currentPart); |
672 | target_body.setBodytext(body_text); | 671 | target_body.setBodytext(body_text); |
673 | if (countlist.count()>1) { | 672 | if (countlist.count()>1) { |
674 | target_body.addPart(currentPart); | 673 | target_body.addPart(currentPart); |
675 | } | 674 | } |
676 | } else { | 675 | } else { |
677 | target_body.addPart(currentPart); | 676 | target_body.addPart(currentPart); |
678 | } | 677 | } |
679 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { | 678 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { |
680 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); | 679 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); |
681 | } | 680 | } |
682 | } | 681 | } |
683 | break; | 682 | break; |
684 | case MAILIMAP_BODY_MPART: | 683 | case MAILIMAP_BODY_MPART: |
685 | { | 684 | { |
686 | QValueList<int>countlist = recList; | 685 | QValueList<int>countlist = recList; |
687 | clistcell*current=0; | 686 | clistcell*current=0; |
688 | mailimap_body*current_body=0; | 687 | mailimap_body*current_body=0; |
689 | unsigned int ccount = 1; | 688 | unsigned int ccount = 1; |
690 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; | 689 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; |
691 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 690 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
692 | current_body = (mailimap_body*)current->data; | 691 | current_body = (mailimap_body*)current->data; |
693 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 692 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
694 | RecPart targetPart; | 693 | RecPart targetPart; |
695 | targetPart.setType("multipart"); | 694 | targetPart.setType("multipart"); |
696 | fillMultiPart(targetPart,mailDescription); | 695 | fillMultiPart(targetPart,mailDescription); |
697 | countlist.append(current_count); | 696 | countlist.append(current_count); |
698 | targetPart.setPositionlist(countlist); | 697 | targetPart.setPositionlist(countlist); |
699 | target_body.addPart(targetPart); | 698 | target_body.addPart(targetPart); |
700 | QString id(""); | 699 | QString id(""); |
701 | for (unsigned int j = 0; j < countlist.count();++j) { | 700 | for (unsigned int j = 0; j < countlist.count();++j) { |
702 | id+=(j>0?" ":""); | 701 | id+=(j>0?" ":""); |
703 | id+=QString("%1").arg(countlist[j]); | 702 | id+=QString("%1").arg(countlist[j]); |
704 | } | 703 | } |
705 | qDebug("ID(mpart) = %s",id.latin1()); | 704 | qDebug("ID(mpart) = %s",id.latin1()); |
706 | } | 705 | } |
707 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); | 706 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); |
708 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 707 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
709 | countlist = recList; | 708 | countlist = recList; |
710 | } | 709 | } |
711 | ++ccount; | 710 | ++ccount; |
712 | } | 711 | } |
713 | } | 712 | } |
714 | break; | 713 | break; |
715 | default: | 714 | default: |
716 | break; | 715 | break; |
717 | } | 716 | } |
718 | } | 717 | } |
719 | 718 | ||
720 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 719 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
721 | { | 720 | { |
722 | if (!Description) { | 721 | if (!Description) { |
723 | return; | 722 | return; |
724 | } | 723 | } |
725 | switch (Description->bd_type) { | 724 | switch (Description->bd_type) { |
726 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 725 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
727 | target_part.setType("text"); | 726 | target_part.setType("text"); |
728 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 727 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
729 | break; | 728 | break; |
730 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 729 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
731 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 730 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
732 | break; | 731 | break; |
733 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 732 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
734 | target_part.setType("message"); | 733 | target_part.setType("message"); |
735 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 734 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
736 | break; | 735 | break; |
737 | default: | 736 | default: |
738 | break; | 737 | break; |
739 | } | 738 | } |
740 | } | 739 | } |
741 | 740 | ||
742 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 741 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
743 | { | 742 | { |
744 | if (!which) { | 743 | if (!which) { |
745 | return; | 744 | return; |
746 | } | 745 | } |
747 | QString sub; | 746 | QString sub; |
748 | sub = which->bd_media_text; | 747 | sub = which->bd_media_text; |
749 | qDebug("Type= text/%s",which->bd_media_text); | 748 | qDebug("Type= text/%s",which->bd_media_text); |
750 | target_part.setSubtype(sub.lower()); | 749 | target_part.setSubtype(sub.lower()); |
751 | target_part.setLines(which->bd_lines); | 750 | target_part.setLines(which->bd_lines); |
752 | fillBodyFields(target_part,which->bd_fields); | 751 | fillBodyFields(target_part,which->bd_fields); |
753 | } | 752 | } |
754 | 753 | ||
755 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 754 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
756 | { | 755 | { |
757 | if (!which) { | 756 | if (!which) { |
758 | return; | 757 | return; |
759 | } | 758 | } |
760 | target_part.setSubtype("rfc822"); | 759 | target_part.setSubtype("rfc822"); |
761 | qDebug("Message part"); | 760 | qDebug("Message part"); |
762 | /* we set this type to text/plain */ | 761 | /* we set this type to text/plain */ |
763 | target_part.setLines(which->bd_lines); | 762 | target_part.setLines(which->bd_lines); |
764 | fillBodyFields(target_part,which->bd_fields); | 763 | fillBodyFields(target_part,which->bd_fields); |
765 | } | 764 | } |
766 | 765 | ||
767 | void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which) | 766 | void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which) |
768 | { | 767 | { |
769 | if (!which) return; | 768 | if (!which) return; |
770 | QString sub = which->bd_media_subtype; | 769 | QString sub = which->bd_media_subtype; |
771 | target_part.setSubtype(sub.lower()); | 770 | target_part.setSubtype(sub.lower()); |
772 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { | 771 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { |
773 | clistcell*cur = 0; | 772 | clistcell*cur = 0; |
774 | mailimap_single_body_fld_param*param=0; | 773 | mailimap_single_body_fld_param*param=0; |
775 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 774 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
776 | param = (mailimap_single_body_fld_param*)cur->data; | 775 | param = (mailimap_single_body_fld_param*)cur->data; |
777 | if (param) { | 776 | if (param) { |
778 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 777 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
779 | } | 778 | } |
780 | } | 779 | } |
781 | } | 780 | } |
782 | } | 781 | } |
783 | 782 | ||
784 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 783 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
785 | { | 784 | { |
786 | if (!which) { | 785 | if (!which) { |
787 | return; | 786 | return; |
788 | } | 787 | } |
789 | QString type,sub; | 788 | QString type,sub; |
790 | switch (which->bd_media_basic->med_type) { | 789 | switch (which->bd_media_basic->med_type) { |
791 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 790 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
792 | type = "application"; | 791 | type = "application"; |
793 | break; | 792 | break; |
794 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 793 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
795 | type = "audio"; | 794 | type = "audio"; |
796 | break; | 795 | break; |
797 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 796 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
798 | type = "image"; | 797 | type = "image"; |
799 | break; | 798 | break; |
800 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 799 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
801 | type = "message"; | 800 | type = "message"; |
802 | break; | 801 | break; |
803 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 802 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
804 | type = "video"; | 803 | type = "video"; |
805 | break; | 804 | break; |
806 | case MAILIMAP_MEDIA_BASIC_OTHER: | 805 | case MAILIMAP_MEDIA_BASIC_OTHER: |
807 | default: | 806 | default: |
808 | if (which->bd_media_basic->med_basic_type) { | 807 | if (which->bd_media_basic->med_basic_type) { |
809 | type = which->bd_media_basic->med_basic_type; | 808 | type = which->bd_media_basic->med_basic_type; |
810 | } else { | 809 | } else { |
811 | type = ""; | 810 | type = ""; |
812 | } | 811 | } |
813 | break; | 812 | break; |
814 | } | 813 | } |
815 | if (which->bd_media_basic->med_subtype) { | 814 | if (which->bd_media_basic->med_subtype) { |
816 | sub = which->bd_media_basic->med_subtype; | 815 | sub = which->bd_media_basic->med_subtype; |
817 | } else { | 816 | } else { |
818 | sub = ""; | 817 | sub = ""; |
819 | } | 818 | } |
820 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); | 819 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); |
821 | target_part.setType(type.lower()); | 820 | target_part.setType(type.lower()); |
822 | target_part.setSubtype(sub.lower()); | 821 | target_part.setSubtype(sub.lower()); |
823 | fillBodyFields(target_part,which->bd_fields); | 822 | fillBodyFields(target_part,which->bd_fields); |
824 | } | 823 | } |
825 | 824 | ||
826 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | 825 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) |
827 | { | 826 | { |
828 | if (!which) return; | 827 | if (!which) return; |
829 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 828 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
830 | clistcell*cur; | 829 | clistcell*cur; |
831 | mailimap_single_body_fld_param*param=0; | 830 | mailimap_single_body_fld_param*param=0; |
832 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 831 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
833 | param = (mailimap_single_body_fld_param*)cur->data; | 832 | param = (mailimap_single_body_fld_param*)cur->data; |
834 | if (param) { | 833 | if (param) { |
835 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 834 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
836 | } | 835 | } |
837 | } | 836 | } |
838 | } | 837 | } |
839 | mailimap_body_fld_enc*enc = which->bd_encoding; | 838 | mailimap_body_fld_enc*enc = which->bd_encoding; |
840 | QString encoding(""); | 839 | QString encoding(""); |
841 | switch (enc->enc_type) { | 840 | switch (enc->enc_type) { |
842 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 841 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
843 | encoding = "7bit"; | 842 | encoding = "7bit"; |
844 | break; | 843 | break; |
845 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 844 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
846 | encoding = "8bit"; | 845 | encoding = "8bit"; |
847 | break; | 846 | break; |
848 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 847 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
849 | encoding="binary"; | 848 | encoding="binary"; |
850 | break; | 849 | break; |
851 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 850 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
852 | encoding="base64"; | 851 | encoding="base64"; |
853 | break; | 852 | break; |
854 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 853 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
855 | encoding="quoted-printable"; | 854 | encoding="quoted-printable"; |
856 | break; | 855 | break; |
857 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 856 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
858 | default: | 857 | default: |
859 | if (enc->enc_value) { | 858 | if (enc->enc_value) { |
860 | char*t=enc->enc_value; | 859 | char*t=enc->enc_value; |
861 | encoding=QString(enc->enc_value); | 860 | encoding=QString(enc->enc_value); |
862 | enc->enc_value=0L; | 861 | enc->enc_value=0L; |
863 | free(t); | 862 | free(t); |
864 | } | 863 | } |
865 | } | 864 | } |
866 | if (which->bd_description) { | 865 | if (which->bd_description) { |
867 | target_part.setDescription(QString(which->bd_description)); | 866 | target_part.setDescription(QString(which->bd_description)); |
868 | } | 867 | } |
869 | target_part.setEncoding(encoding); | 868 | target_part.setEncoding(encoding); |
870 | target_part.setSize(which->bd_size); | 869 | target_part.setSize(which->bd_size); |
871 | } | 870 | } |
872 | 871 | ||
873 | void IMAPwrapper::deleteMail(const RecMail&mail) | 872 | void IMAPwrapper::deleteMail(const RecMail&mail) |
874 | { | 873 | { |
875 | mailimap_flag_list*flist; | 874 | mailimap_flag_list*flist; |
876 | mailimap_set *set; | 875 | mailimap_set *set; |
877 | mailimap_store_att_flags * store_flags; | 876 | mailimap_store_att_flags * store_flags; |
878 | int err; | 877 | int err; |
879 | login(); | 878 | login(); |
880 | if (!m_imap) { | 879 | if (!m_imap) { |
881 | return; | 880 | return; |
882 | } | 881 | } |
883 | err = selectMbox(mail.getMbox()); | 882 | err = selectMbox(mail.getMbox()); |
884 | if ( err != MAILIMAP_NO_ERROR ) { | 883 | if ( err != MAILIMAP_NO_ERROR ) { |
885 | return; | 884 | return; |
886 | } | 885 | } |
887 | flist = mailimap_flag_list_new_empty(); | 886 | flist = mailimap_flag_list_new_empty(); |
888 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 887 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
889 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 888 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
890 | set = mailimap_set_new_single(mail.getNumber()); | 889 | set = mailimap_set_new_single(mail.getNumber()); |
891 | err = mailimap_store(m_imap,set,store_flags); | 890 | err = mailimap_store(m_imap,set,store_flags); |
892 | mailimap_set_free( set ); | 891 | mailimap_set_free( set ); |
893 | mailimap_store_att_flags_free(store_flags); | 892 | mailimap_store_att_flags_free(store_flags); |
894 | 893 | ||
895 | if (err != MAILIMAP_NO_ERROR) { | 894 | if (err != MAILIMAP_NO_ERROR) { |
896 | qDebug("error deleting mail: %s",m_imap->imap_response); | 895 | qDebug("error deleting mail: %s",m_imap->imap_response); |
897 | return; | 896 | return; |
898 | } | 897 | } |
899 | qDebug("deleting mail: %s",m_imap->imap_response); | 898 | qDebug("deleting mail: %s",m_imap->imap_response); |
900 | /* should we realy do that at this moment? */ | 899 | /* should we realy do that at this moment? */ |
901 | err = mailimap_expunge(m_imap); | 900 | err = mailimap_expunge(m_imap); |
902 | if (err != MAILIMAP_NO_ERROR) { | 901 | if (err != MAILIMAP_NO_ERROR) { |
903 | qDebug("error deleting mail: %s",m_imap->imap_response); | 902 | qDebug("error deleting mail: %s",m_imap->imap_response); |
904 | } | 903 | } |
905 | qDebug("Delete successfull %s",m_imap->imap_response); | 904 | qDebug("Delete successfull %s",m_imap->imap_response); |
906 | } | 905 | } |
907 | 906 | ||
908 | void IMAPwrapper::answeredMail(const RecMail&mail) | 907 | void IMAPwrapper::answeredMail(const RecMail&mail) |
909 | { | 908 | { |
910 | mailimap_flag_list*flist; | 909 | mailimap_flag_list*flist; |
911 | mailimap_set *set; | 910 | mailimap_set *set; |
912 | mailimap_store_att_flags * store_flags; | 911 | mailimap_store_att_flags * store_flags; |
913 | int err; | 912 | int err; |
914 | login(); | 913 | login(); |
915 | if (!m_imap) { | 914 | if (!m_imap) { |
916 | return; | 915 | return; |
917 | } | 916 | } |
918 | err = selectMbox(mail.getMbox()); | 917 | err = selectMbox(mail.getMbox()); |
919 | if ( err != MAILIMAP_NO_ERROR ) { | 918 | if ( err != MAILIMAP_NO_ERROR ) { |
920 | return; | 919 | return; |
921 | } | 920 | } |
922 | flist = mailimap_flag_list_new_empty(); | 921 | flist = mailimap_flag_list_new_empty(); |
923 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 922 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
924 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | 923 | store_flags = mailimap_store_att_flags_new_add_flags(flist); |
925 | set = mailimap_set_new_single(mail.getNumber()); | 924 | set = mailimap_set_new_single(mail.getNumber()); |
926 | err = mailimap_store(m_imap,set,store_flags); | 925 | err = mailimap_store(m_imap,set,store_flags); |
927 | mailimap_set_free( set ); | 926 | mailimap_set_free( set ); |
928 | mailimap_store_att_flags_free(store_flags); | 927 | mailimap_store_att_flags_free(store_flags); |
929 | 928 | ||
930 | if (err != MAILIMAP_NO_ERROR) { | 929 | if (err != MAILIMAP_NO_ERROR) { |
931 | qDebug("error marking mail: %s",m_imap->imap_response); | 930 | qDebug("error marking mail: %s",m_imap->imap_response); |
932 | return; | 931 | return; |
933 | } | 932 | } |
934 | } | 933 | } |
935 | 934 | ||
936 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 935 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) |
937 | { | 936 | { |
938 | QString body(""); | 937 | QString body(""); |
939 | encodedString*res = fetchRawPart(mail,path,internal_call); | 938 | encodedString*res = fetchRawPart(mail,path,internal_call); |
940 | encodedString*r = decode_String(res,enc); | 939 | encodedString*r = decode_String(res,enc); |
941 | delete res; | 940 | delete res; |
942 | if (r) { | 941 | if (r) { |
943 | if (r->Length()>0) { | 942 | if (r->Length()>0) { |
944 | body = r->Content(); | 943 | body = r->Content(); |
945 | } | 944 | } |
946 | delete r; | 945 | delete r; |
947 | } | 946 | } |
948 | return body; | 947 | return body; |
949 | } | 948 | } |
950 | 949 | ||
951 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) | 950 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) |
952 | { | 951 | { |
953 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); | 952 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); |
954 | } | 953 | } |
955 | 954 | ||
956 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) | 955 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) |
957 | { | 956 | { |
958 | encodedString*res = fetchRawPart(mail,part.Positionlist(),false); | 957 | encodedString*res = fetchRawPart(mail,part.Positionlist(),false); |
959 | encodedString*r = decode_String(res,part.Encoding()); | 958 | encodedString*r = decode_String(res,part.Encoding()); |
960 | delete res; | 959 | delete res; |
961 | return r; | 960 | return r; |
962 | } | 961 | } |
963 | 962 | ||
964 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) | 963 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) |
965 | { | 964 | { |
966 | return fetchRawPart(mail,part.Positionlist(),false); | 965 | return fetchRawPart(mail,part.Positionlist(),false); |
967 | } | 966 | } |
968 | 967 | ||
969 | int IMAPwrapper::deleteAllMail(const Folder*folder) | 968 | int IMAPwrapper::deleteAllMail(const FolderP&folder) |
970 | { | 969 | { |
971 | login(); | 970 | login(); |
972 | if (!m_imap) { | 971 | if (!m_imap) { |
973 | return 0; | 972 | return 0; |
974 | } | 973 | } |
975 | mailimap_flag_list*flist; | 974 | mailimap_flag_list*flist; |
976 | mailimap_set *set; | 975 | mailimap_set *set; |
977 | mailimap_store_att_flags * store_flags; | 976 | mailimap_store_att_flags * store_flags; |
978 | int err = selectMbox(folder->getName()); | 977 | int err = selectMbox(folder->getName()); |
979 | if ( err != MAILIMAP_NO_ERROR ) { | 978 | if ( err != MAILIMAP_NO_ERROR ) { |
980 | return 0; | 979 | return 0; |
981 | } | 980 | } |
982 | 981 | ||
983 | int last = m_imap->imap_selection_info->sel_exists; | 982 | int last = m_imap->imap_selection_info->sel_exists; |
984 | if (last == 0) { | 983 | if (last == 0) { |
985 | Global::statusMessage(tr("Mailbox has no mails!")); | 984 | Global::statusMessage(tr("Mailbox has no mails!")); |
986 | return 0; | 985 | return 0; |
987 | } | 986 | } |
988 | flist = mailimap_flag_list_new_empty(); | 987 | flist = mailimap_flag_list_new_empty(); |
989 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 988 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
990 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 989 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
991 | set = mailimap_set_new_interval( 1, last ); | 990 | set = mailimap_set_new_interval( 1, last ); |
992 | err = mailimap_store(m_imap,set,store_flags); | 991 | err = mailimap_store(m_imap,set,store_flags); |
993 | mailimap_set_free( set ); | 992 | mailimap_set_free( set ); |
994 | mailimap_store_att_flags_free(store_flags); | 993 | mailimap_store_att_flags_free(store_flags); |
995 | if (err != MAILIMAP_NO_ERROR) { | 994 | if (err != MAILIMAP_NO_ERROR) { |
996 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | 995 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); |
997 | return 0; | 996 | return 0; |
998 | } | 997 | } |
999 | qDebug("deleting mail: %s",m_imap->imap_response); | 998 | qDebug("deleting mail: %s",m_imap->imap_response); |
1000 | /* should we realy do that at this moment? */ | 999 | /* should we realy do that at this moment? */ |
1001 | err = mailimap_expunge(m_imap); | 1000 | err = mailimap_expunge(m_imap); |
1002 | if (err != MAILIMAP_NO_ERROR) { | 1001 | if (err != MAILIMAP_NO_ERROR) { |
1003 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | 1002 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); |
1004 | return 0; | 1003 | return 0; |
1005 | } | 1004 | } |
1006 | qDebug("Delete successfull %s",m_imap->imap_response); | 1005 | qDebug("Delete successfull %s",m_imap->imap_response); |
1007 | return 1; | 1006 | return 1; |
1008 | } | 1007 | } |
1009 | 1008 | ||
1010 | int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) | 1009 | int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) |
1011 | { | 1010 | { |
1012 | if (folder.length()==0) return 0; | 1011 | if (folder.length()==0) return 0; |
1013 | login(); | 1012 | login(); |
1014 | if (!m_imap) {return 0;} | 1013 | if (!m_imap) {return 0;} |
1015 | QString pre = account->getPrefix(); | 1014 | QString pre = account->getPrefix(); |
1016 | if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { | 1015 | if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { |
1017 | pre+=delemiter; | 1016 | pre+=delemiter; |
1018 | } | 1017 | } |
1019 | if (parentfolder) { | 1018 | if (parentfolder) { |
1020 | pre += parentfolder->getDisplayName()+delemiter; | 1019 | pre += parentfolder->getDisplayName()+delemiter; |
1021 | } | 1020 | } |
1022 | pre+=folder; | 1021 | pre+=folder; |
1023 | if (getsubfolder) { | 1022 | if (getsubfolder) { |
1024 | if (delemiter.length()>0) { | 1023 | if (delemiter.length()>0) { |
1025 | pre+=delemiter; | 1024 | pre+=delemiter; |
1026 | } else { | 1025 | } else { |
1027 | Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); | 1026 | Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); |
1028 | return 0; | 1027 | return 0; |
1029 | } | 1028 | } |
1030 | } | 1029 | } |
1031 | qDebug("Creating %s",pre.latin1()); | 1030 | qDebug("Creating %s",pre.latin1()); |
1032 | int res = mailimap_create(m_imap,pre.latin1()); | 1031 | int res = mailimap_create(m_imap,pre.latin1()); |
1033 | if (res != MAILIMAP_NO_ERROR) { | 1032 | if (res != MAILIMAP_NO_ERROR) { |
1034 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); | 1033 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); |
1035 | return 0; | 1034 | return 0; |
1036 | } | 1035 | } |
1037 | return 1; | 1036 | return 1; |
1038 | } | 1037 | } |
1039 | 1038 | ||
1040 | int IMAPwrapper::deleteMbox(const Folder*folder) | 1039 | int IMAPwrapper::deleteMbox(const FolderP&folder) |
1041 | { | 1040 | { |
1042 | if (!folder) return 0; | 1041 | if (!folder) return 0; |
1043 | login(); | 1042 | login(); |
1044 | if (!m_imap) {return 0;} | 1043 | if (!m_imap) {return 0;} |
1045 | int res = mailimap_delete(m_imap,folder->getName()); | 1044 | int res = mailimap_delete(m_imap,folder->getName()); |
1046 | if (res != MAILIMAP_NO_ERROR) { | 1045 | if (res != MAILIMAP_NO_ERROR) { |
1047 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); | 1046 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); |
1048 | return 0; | 1047 | return 0; |
1049 | } | 1048 | } |
1050 | return 1; | 1049 | return 1; |
1051 | } | 1050 | } |
1052 | 1051 | ||
1053 | void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | 1052 | void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) |
1054 | { | 1053 | { |
1055 | mailimap_status_att_list * att_list =0; | 1054 | mailimap_status_att_list * att_list =0; |
1056 | mailimap_mailbox_data_status * status=0; | 1055 | mailimap_mailbox_data_status * status=0; |
1057 | clistiter * cur = 0; | 1056 | clistiter * cur = 0; |
1058 | int r = 0; | 1057 | int r = 0; |
1059 | int res = 0; | 1058 | int res = 0; |
1060 | target_stat.message_count = 0; | 1059 | target_stat.message_count = 0; |
1061 | target_stat.message_unseen = 0; | 1060 | target_stat.message_unseen = 0; |
1062 | target_stat.message_recent = 0; | 1061 | target_stat.message_recent = 0; |
1063 | login(); | 1062 | login(); |
1064 | if (!m_imap) { | 1063 | if (!m_imap) { |
1065 | return; | 1064 | return; |
1066 | } | 1065 | } |
1067 | att_list = mailimap_status_att_list_new_empty(); | 1066 | att_list = mailimap_status_att_list_new_empty(); |
1068 | if (!att_list) return; | 1067 | if (!att_list) return; |
1069 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); | 1068 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); |
1070 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); | 1069 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); |
1071 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); | 1070 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); |
1072 | r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); | 1071 | r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); |
1073 | if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { | 1072 | if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { |
1074 | for (cur = clist_begin(status->st_info_list); | 1073 | for (cur = clist_begin(status->st_info_list); |
1075 | cur != NULL ; cur = clist_next(cur)) { | 1074 | cur != NULL ; cur = clist_next(cur)) { |
1076 | mailimap_status_info * status_info; | 1075 | mailimap_status_info * status_info; |
1077 | status_info = (mailimap_status_info *)clist_content(cur); | 1076 | status_info = (mailimap_status_info *)clist_content(cur); |
1078 | switch (status_info->st_att) { | 1077 | switch (status_info->st_att) { |
1079 | case MAILIMAP_STATUS_ATT_MESSAGES: | 1078 | case MAILIMAP_STATUS_ATT_MESSAGES: |
1080 | target_stat.message_count = status_info->st_value; | 1079 | target_stat.message_count = status_info->st_value; |
1081 | break; | 1080 | break; |
1082 | case MAILIMAP_STATUS_ATT_RECENT: | 1081 | case MAILIMAP_STATUS_ATT_RECENT: |
1083 | target_stat.message_recent = status_info->st_value; | 1082 | target_stat.message_recent = status_info->st_value; |
1084 | break; | 1083 | break; |
1085 | case MAILIMAP_STATUS_ATT_UNSEEN: | 1084 | case MAILIMAP_STATUS_ATT_UNSEEN: |
1086 | target_stat.message_unseen = status_info->st_value; | 1085 | target_stat.message_unseen = status_info->st_value; |
1087 | break; | 1086 | break; |
1088 | } | 1087 | } |
1089 | } | 1088 | } |
1090 | } else { | 1089 | } else { |
1091 | qDebug("Error retrieving status"); | 1090 | qDebug("Error retrieving status"); |
1092 | } | 1091 | } |
1093 | if (status) mailimap_mailbox_data_status_free(status); | 1092 | if (status) mailimap_mailbox_data_status_free(status); |
1094 | if (att_list) mailimap_status_att_list_free(att_list); | 1093 | if (att_list) mailimap_status_att_list_free(att_list); |
1095 | } | 1094 | } |
1096 | 1095 | ||
1097 | void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | 1096 | void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) |
1098 | { | 1097 | { |
1099 | login(); | 1098 | login(); |
1100 | if (!m_imap) return; | 1099 | if (!m_imap) return; |
1101 | if (!msg) return; | 1100 | if (!msg) return; |
1102 | int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); | 1101 | int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); |
1103 | if (r != MAILIMAP_NO_ERROR) { | 1102 | if (r != MAILIMAP_NO_ERROR) { |
1104 | Global::statusMessage("Error storing mail!"); | 1103 | Global::statusMessage("Error storing mail!"); |
1105 | } | 1104 | } |
1106 | } | 1105 | } |
1107 | 1106 | ||
1108 | MAILLIB::ATYPE IMAPwrapper::getType()const | 1107 | MAILLIB::ATYPE IMAPwrapper::getType()const |
1109 | { | 1108 | { |
1110 | return account->getType(); | 1109 | return account->getType(); |
1111 | } | 1110 | } |
1112 | 1111 | ||
1113 | const QString&IMAPwrapper::getName()const | 1112 | const QString&IMAPwrapper::getName()const |
1114 | { | 1113 | { |
1115 | qDebug("Get name: %s",account->getAccountName().latin1()); | 1114 | qDebug("Get name: %s",account->getAccountName().latin1()); |
1116 | return account->getAccountName(); | 1115 | return account->getAccountName(); |
1117 | } | 1116 | } |
1118 | 1117 | ||
1119 | encodedString* IMAPwrapper::fetchRawBody(const RecMail&mail) | 1118 | encodedString* IMAPwrapper::fetchRawBody(const RecMail&mail) |
1120 | { | 1119 | { |
1121 | // dummy | 1120 | // dummy |
1122 | QValueList<int> path; | 1121 | QValueList<int> path; |
1123 | return fetchRawPart(mail,path,false); | 1122 | return fetchRawPart(mail,path,false); |
1124 | } | 1123 | } |
1125 | 1124 | ||
1126 | void IMAPwrapper::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 1125 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, |
1126 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | ||
1127 | { | 1127 | { |
1128 | if (targetWrapper != this) { | 1128 | if (targetWrapper != this) { |
1129 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); | 1129 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); |
1130 | qDebug("Using generic"); | 1130 | qDebug("Using generic"); |
1131 | return; | 1131 | return; |
1132 | } | 1132 | } |
1133 | mailimap_set *set = 0; | 1133 | mailimap_set *set = 0; |
1134 | login(); | 1134 | login(); |
1135 | if (!m_imap) { | 1135 | if (!m_imap) { |
1136 | return; | 1136 | return; |
1137 | } | 1137 | } |
1138 | int err = selectMbox(fromFolder->getName()); | 1138 | int err = selectMbox(fromFolder->getName()); |
1139 | if ( err != MAILIMAP_NO_ERROR ) { | 1139 | if ( err != MAILIMAP_NO_ERROR ) { |
1140 | return; | 1140 | return; |
1141 | } | 1141 | } |
1142 | int last = m_imap->imap_selection_info->sel_exists; | 1142 | int last = m_imap->imap_selection_info->sel_exists; |
1143 | set = mailimap_set_new_interval( 1, last ); | 1143 | set = mailimap_set_new_interval( 1, last ); |
1144 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1144 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1145 | mailimap_set_free( set ); | 1145 | mailimap_set_free( set ); |
1146 | if ( err != MAILIMAP_NO_ERROR ) { | 1146 | if ( err != MAILIMAP_NO_ERROR ) { |
1147 | QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); | 1147 | QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); |
1148 | Global::statusMessage(error_msg); | 1148 | Global::statusMessage(error_msg); |
1149 | qDebug(error_msg); | 1149 | qDebug(error_msg); |
1150 | return; | 1150 | return; |
1151 | } | 1151 | } |
1152 | if (moveit) { | 1152 | if (moveit) { |
1153 | deleteAllMail(fromFolder); | 1153 | deleteAllMail(fromFolder); |
1154 | } | 1154 | } |
1155 | } | 1155 | } |
1156 | 1156 | ||
1157 | void IMAPwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 1157 | void IMAPwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
1158 | { | 1158 | { |
1159 | if (targetWrapper != this) { | 1159 | if (targetWrapper != this) { |
1160 | qDebug("Using generic"); | 1160 | qDebug("Using generic"); |
1161 | AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); | 1161 | AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); |
1162 | return; | 1162 | return; |
1163 | } | 1163 | } |
1164 | mailimap_set *set = 0; | 1164 | mailimap_set *set = 0; |
1165 | login(); | 1165 | login(); |
1166 | if (!m_imap) { | 1166 | if (!m_imap) { |
1167 | return; | 1167 | return; |
1168 | } | 1168 | } |
1169 | int err = selectMbox(mail.getMbox()); | 1169 | int err = selectMbox(mail.getMbox()); |
1170 | if ( err != MAILIMAP_NO_ERROR ) { | 1170 | if ( err != MAILIMAP_NO_ERROR ) { |
1171 | return; | 1171 | return; |
1172 | } | 1172 | } |
1173 | set = mailimap_set_new_single(mail.getNumber()); | 1173 | set = mailimap_set_new_single(mail.getNumber()); |
1174 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1174 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1175 | mailimap_set_free( set ); | 1175 | mailimap_set_free( set ); |
1176 | if ( err != MAILIMAP_NO_ERROR ) { | 1176 | if ( err != MAILIMAP_NO_ERROR ) { |
1177 | QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); | 1177 | QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); |
1178 | Global::statusMessage(error_msg); | 1178 | Global::statusMessage(error_msg); |
1179 | qDebug(error_msg); | 1179 | qDebug(error_msg); |
1180 | return; | 1180 | return; |
1181 | } | 1181 | } |
1182 | if (moveit) { | 1182 | if (moveit) { |
1183 | deleteMail(mail); | 1183 | deleteMail(mail); |
1184 | } | 1184 | } |
1185 | } | 1185 | } |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h index 2623725..15f049f 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.h +++ b/noncore/net/mail/libmailwrapper/imapwrapper.h | |||
@@ -1,78 +1,80 @@ | |||
1 | #ifndef __IMAPWRAPPER | 1 | #ifndef __IMAPWRAPPER |
2 | #define __IMAPWRAPPER | 2 | #define __IMAPWRAPPER |
3 | 3 | ||
4 | #include <qlist.h> | 4 | #include <qlist.h> |
5 | #include "mailwrapper.h" | 5 | #include "mailwrapper.h" |
6 | #include "abstractmail.h" | 6 | #include "abstractmail.h" |
7 | #include <libetpan/clist.h> | 7 | #include <libetpan/clist.h> |
8 | 8 | ||
9 | struct mailimap; | 9 | struct mailimap; |
10 | struct mailimap_body; | 10 | struct mailimap_body; |
11 | struct mailimap_body_type_1part; | 11 | struct mailimap_body_type_1part; |
12 | struct mailimap_body_type_text; | 12 | struct mailimap_body_type_text; |
13 | struct mailimap_body_type_basic; | 13 | struct mailimap_body_type_basic; |
14 | struct mailimap_body_type_msg; | 14 | struct mailimap_body_type_msg; |
15 | struct mailimap_body_type_mpart; | 15 | struct mailimap_body_type_mpart; |
16 | struct mailimap_body_fields; | 16 | struct mailimap_body_fields; |
17 | struct mailimap_msg_att; | 17 | struct mailimap_msg_att; |
18 | class encodedString; | 18 | class encodedString; |
19 | 19 | ||
20 | class IMAPwrapper : public AbstractMail | 20 | class IMAPwrapper : public AbstractMail |
21 | { | 21 | { |
22 | Q_OBJECT | 22 | Q_OBJECT |
23 | public: | 23 | public: |
24 | IMAPwrapper( IMAPaccount *a ); | 24 | IMAPwrapper( IMAPaccount *a ); |
25 | virtual ~IMAPwrapper(); | 25 | virtual ~IMAPwrapper(); |
26 | virtual QList<Folder>* listFolders(); | 26 | virtual QValueList<Opie::osmart_pointer<Folder> >* listFolders(); |
27 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); | 27 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); |
28 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | 28 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); |
29 | 29 | ||
30 | virtual void deleteMail(const RecMail&mail); | 30 | virtual void deleteMail(const RecMail&mail); |
31 | virtual void answeredMail(const RecMail&mail); | 31 | virtual void answeredMail(const RecMail&mail); |
32 | virtual int deleteAllMail(const Folder*folder); | 32 | virtual int deleteAllMail(const Opie::osmart_pointer<Folder>&folder); |
33 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); | 33 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); |
34 | virtual void mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | 34 | virtual void mvcpAllMails(const Opie::osmart_pointer<Folder>&fromFolder, |
35 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | ||
35 | virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | 36 | virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); |
36 | 37 | ||
37 | virtual RecBody fetchBody(const RecMail&mail); | 38 | virtual RecBody fetchBody(const RecMail&mail); |
38 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); | 39 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); |
39 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); | 40 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); |
40 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); | 41 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); |
41 | virtual encodedString* fetchRawBody(const RecMail&mail); | 42 | virtual encodedString* fetchRawBody(const RecMail&mail); |
42 | 43 | ||
43 | virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); | 44 | virtual int createMbox(const QString&,const Opie::osmart_pointer<Folder>&parentfolder=0, |
44 | virtual int deleteMbox(const Folder*folder); | 45 | const QString& delemiter="/",bool getsubfolder=false); |
45 | 46 | virtual int deleteMbox(const Opie::osmart_pointer<Folder>&folder); | |
47 | |||
46 | static void imap_progress( size_t current, size_t maximum ); | 48 | static void imap_progress( size_t current, size_t maximum ); |
47 | 49 | ||
48 | virtual void logout(); | 50 | virtual void logout(); |
49 | virtual MAILLIB::ATYPE getType()const; | 51 | virtual MAILLIB::ATYPE getType()const; |
50 | virtual const QString&getName()const; | 52 | virtual const QString&getName()const; |
51 | 53 | ||
52 | protected: | 54 | protected: |
53 | RecMail*parse_list_result(mailimap_msg_att*); | 55 | RecMail*parse_list_result(mailimap_msg_att*); |
54 | void login(); | 56 | void login(); |
55 | bool start_tls(bool force=true); | 57 | bool start_tls(bool force=true); |
56 | 58 | ||
57 | virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); | 59 | virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); |
58 | virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); | 60 | virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); |
59 | int selectMbox(const QString&mbox); | 61 | int selectMbox(const QString&mbox); |
60 | 62 | ||
61 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); | 63 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); |
62 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); | 64 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); |
63 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); | 65 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); |
64 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); | 66 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); |
65 | void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which); | 67 | void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which); |
66 | void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1); | 68 | void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1); |
67 | 69 | ||
68 | /* just helpers */ | 70 | /* just helpers */ |
69 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); | 71 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); |
70 | static QStringList address_list_to_stringlist(clist*list); | 72 | static QStringList address_list_to_stringlist(clist*list); |
71 | 73 | ||
72 | 74 | ||
73 | IMAPaccount *account; | 75 | IMAPaccount *account; |
74 | mailimap *m_imap; | 76 | mailimap *m_imap; |
75 | QString m_Lastmbox; | 77 | QString m_Lastmbox; |
76 | }; | 78 | }; |
77 | 79 | ||
78 | #endif | 80 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.h b/noncore/net/mail/libmailwrapper/mailtypes.h index 17c6db9..10d367f 100644 --- a/noncore/net/mail/libmailwrapper/mailtypes.h +++ b/noncore/net/mail/libmailwrapper/mailtypes.h | |||
@@ -1,198 +1,197 @@ | |||
1 | #ifndef __MAIL_TYPES_H | 1 | #ifndef __MAIL_TYPES_H |
2 | #define __MAIL_TYPES_H | 2 | #define __MAIL_TYPES_H |
3 | 3 | ||
4 | #define FLAG_ANSWERED 0 | 4 | #define FLAG_ANSWERED 0 |
5 | #define FLAG_FLAGGED 1 | 5 | #define FLAG_FLAGGED 1 |
6 | #define FLAG_DELETED 2 | 6 | #define FLAG_DELETED 2 |
7 | #define FLAG_SEEN 3 | 7 | #define FLAG_SEEN 3 |
8 | #define FLAG_DRAFT 4 | 8 | #define FLAG_DRAFT 4 |
9 | #define FLAG_RECENT 5 | 9 | #define FLAG_RECENT 5 |
10 | 10 | ||
11 | #include <qlist.h> | ||
12 | #include <qbitarray.h> | 11 | #include <qbitarray.h> |
13 | #include <qstring.h> | 12 | #include <qstring.h> |
14 | #include <qstringlist.h> | 13 | #include <qstringlist.h> |
15 | #include <qmap.h> | 14 | #include <qmap.h> |
16 | #include <qvaluelist.h> | 15 | #include <qvaluelist.h> |
17 | 16 | ||
18 | class AbstractMail; | 17 | class AbstractMail; |
19 | /* a class to describe mails in a mailbox */ | 18 | /* a class to describe mails in a mailbox */ |
20 | /* Attention! | 19 | /* Attention! |
21 | From programmers point of view it would make sense to | 20 | From programmers point of view it would make sense to |
22 | store the mail body into this class, too. | 21 | store the mail body into this class, too. |
23 | But: not from the point of view of the device. | 22 | But: not from the point of view of the device. |
24 | Mailbodies can be real large. So we request them when | 23 | Mailbodies can be real large. So we request them when |
25 | needed from the mail-wrapper class direct from the server itself | 24 | needed from the mail-wrapper class direct from the server itself |
26 | (imap) or from a file-based cache (pop3?) | 25 | (imap) or from a file-based cache (pop3?) |
27 | So there is no interface "const QString&body()" but you should | 26 | So there is no interface "const QString&body()" but you should |
28 | make a request to the mailwrapper with this class as parameter to | 27 | make a request to the mailwrapper with this class as parameter to |
29 | get the body. Same words for the attachments. | 28 | get the body. Same words for the attachments. |
30 | */ | 29 | */ |
31 | class RecMail | 30 | class RecMail |
32 | { | 31 | { |
33 | public: | 32 | public: |
34 | RecMail(); | 33 | RecMail(); |
35 | RecMail(const RecMail&old); | 34 | RecMail(const RecMail&old); |
36 | virtual ~RecMail(); | 35 | virtual ~RecMail(); |
37 | 36 | ||
38 | const int getNumber()const{return msg_number;} | 37 | const int getNumber()const{return msg_number;} |
39 | void setNumber(int number){msg_number=number;} | 38 | void setNumber(int number){msg_number=number;} |
40 | const QString&getDate()const{ return date; } | 39 | const QString&getDate()const{ return date; } |
41 | void setDate( const QString&a ) { date = a; } | 40 | void setDate( const QString&a ) { date = a; } |
42 | const QString&getFrom()const{ return from; } | 41 | const QString&getFrom()const{ return from; } |
43 | void setFrom( const QString&a ) { from = a; } | 42 | void setFrom( const QString&a ) { from = a; } |
44 | const QString&getSubject()const { return subject; } | 43 | const QString&getSubject()const { return subject; } |
45 | void setSubject( const QString&s ) { subject = s; } | 44 | void setSubject( const QString&s ) { subject = s; } |
46 | const QString&getMbox()const{return mbox;} | 45 | const QString&getMbox()const{return mbox;} |
47 | void setMbox(const QString&box){mbox = box;} | 46 | void setMbox(const QString&box){mbox = box;} |
48 | void setMsgid(const QString&id){msg_id=id;} | 47 | void setMsgid(const QString&id){msg_id=id;} |
49 | const QString&Msgid()const{return msg_id;} | 48 | const QString&Msgid()const{return msg_id;} |
50 | void setReplyto(const QString&reply){replyto=reply;} | 49 | void setReplyto(const QString&reply){replyto=reply;} |
51 | const QString&Replyto()const{return replyto;} | 50 | const QString&Replyto()const{return replyto;} |
52 | void setMsgsize(int size){msg_size = size;} | 51 | void setMsgsize(int size){msg_size = size;} |
53 | const int Msgsize()const{return msg_size;} | 52 | const int Msgsize()const{return msg_size;} |
54 | 53 | ||
55 | 54 | ||
56 | void setTo(const QStringList&list); | 55 | void setTo(const QStringList&list); |
57 | const QStringList&To()const; | 56 | const QStringList&To()const; |
58 | void setCC(const QStringList&list); | 57 | void setCC(const QStringList&list); |
59 | const QStringList&CC()const; | 58 | const QStringList&CC()const; |
60 | void setBcc(const QStringList&list); | 59 | void setBcc(const QStringList&list); |
61 | const QStringList&Bcc()const; | 60 | const QStringList&Bcc()const; |
62 | void setInreply(const QStringList&list); | 61 | void setInreply(const QStringList&list); |
63 | const QStringList&Inreply()const; | 62 | const QStringList&Inreply()const; |
64 | void setReferences(const QStringList&list); | 63 | void setReferences(const QStringList&list); |
65 | const QStringList&References()const; | 64 | const QStringList&References()const; |
66 | 65 | ||
67 | const QBitArray&getFlags()const{return msg_flags;} | 66 | const QBitArray&getFlags()const{return msg_flags;} |
68 | void setFlags(const QBitArray&flags){msg_flags = flags;} | 67 | void setFlags(const QBitArray&flags){msg_flags = flags;} |
69 | 68 | ||
70 | void setWrapper(AbstractMail*wrapper); | 69 | void setWrapper(AbstractMail*wrapper); |
71 | AbstractMail* Wrapper(); | 70 | AbstractMail* Wrapper(); |
72 | 71 | ||
73 | protected: | 72 | protected: |
74 | QString subject,date,from,mbox,msg_id,replyto; | 73 | QString subject,date,from,mbox,msg_id,replyto; |
75 | int msg_number,msg_size; | 74 | int msg_number,msg_size; |
76 | QBitArray msg_flags; | 75 | QBitArray msg_flags; |
77 | QStringList to,cc,bcc,in_reply_to,references; | 76 | QStringList to,cc,bcc,in_reply_to,references; |
78 | AbstractMail*wrapper; | 77 | AbstractMail*wrapper; |
79 | void init(); | 78 | void init(); |
80 | void copy_old(const RecMail&old); | 79 | void copy_old(const RecMail&old); |
81 | }; | 80 | }; |
82 | 81 | ||
83 | typedef QMap<QString,QString> part_plist_t; | 82 | typedef QMap<QString,QString> part_plist_t; |
84 | 83 | ||
85 | class RecPart | 84 | class RecPart |
86 | { | 85 | { |
87 | protected: | 86 | protected: |
88 | QString m_type,m_subtype,m_identifier,m_encoding,m_description; | 87 | QString m_type,m_subtype,m_identifier,m_encoding,m_description; |
89 | unsigned int m_lines,m_size; | 88 | unsigned int m_lines,m_size; |
90 | part_plist_t m_Parameters; | 89 | part_plist_t m_Parameters; |
91 | /* describes the position in the mail */ | 90 | /* describes the position in the mail */ |
92 | QValueList<int> m_poslist; | 91 | QValueList<int> m_poslist; |
93 | 92 | ||
94 | public: | 93 | public: |
95 | RecPart(); | 94 | RecPart(); |
96 | virtual ~RecPart(); | 95 | virtual ~RecPart(); |
97 | 96 | ||
98 | const QString&Type()const; | 97 | const QString&Type()const; |
99 | void setType(const QString&type); | 98 | void setType(const QString&type); |
100 | const QString&Subtype()const; | 99 | const QString&Subtype()const; |
101 | void setSubtype(const QString&subtype); | 100 | void setSubtype(const QString&subtype); |
102 | const QString&Identifier()const; | 101 | const QString&Identifier()const; |
103 | void setIdentifier(const QString&identifier); | 102 | void setIdentifier(const QString&identifier); |
104 | const QString&Encoding()const; | 103 | const QString&Encoding()const; |
105 | void setEncoding(const QString&encoding); | 104 | void setEncoding(const QString&encoding); |
106 | const QString&Description()const; | 105 | const QString&Description()const; |
107 | void setDescription(const QString&desc); | 106 | void setDescription(const QString&desc); |
108 | void setLines(unsigned int lines); | 107 | void setLines(unsigned int lines); |
109 | const unsigned int Lines()const; | 108 | const unsigned int Lines()const; |
110 | void setSize(unsigned int size); | 109 | void setSize(unsigned int size); |
111 | const unsigned int Size()const; | 110 | const unsigned int Size()const; |
112 | 111 | ||
113 | 112 | ||
114 | void setParameters(const part_plist_t&list); | 113 | void setParameters(const part_plist_t&list); |
115 | const part_plist_t&Parameters()const; | 114 | const part_plist_t&Parameters()const; |
116 | void addParameter(const QString&key,const QString&value); | 115 | void addParameter(const QString&key,const QString&value); |
117 | const QString searchParamter(const QString&key)const; | 116 | const QString searchParamter(const QString&key)const; |
118 | void setPositionlist(const QValueList<int>&poslist); | 117 | void setPositionlist(const QValueList<int>&poslist); |
119 | const QValueList<int>& Positionlist()const; | 118 | const QValueList<int>& Positionlist()const; |
120 | }; | 119 | }; |
121 | 120 | ||
122 | class RecBody | 121 | class RecBody |
123 | { | 122 | { |
124 | protected: | 123 | protected: |
125 | QString m_BodyText; | 124 | QString m_BodyText; |
126 | QValueList<RecPart> m_PartsList; | 125 | QValueList<RecPart> m_PartsList; |
127 | RecPart m_description; | 126 | RecPart m_description; |
128 | 127 | ||
129 | public: | 128 | public: |
130 | RecBody(); | 129 | RecBody(); |
131 | virtual ~RecBody(); | 130 | virtual ~RecBody(); |
132 | void setBodytext(const QString&); | 131 | void setBodytext(const QString&); |
133 | const QString& Bodytext()const; | 132 | const QString& Bodytext()const; |
134 | 133 | ||
135 | void setDescription(const RecPart&des); | 134 | void setDescription(const RecPart&des); |
136 | const RecPart& Description()const; | 135 | const RecPart& Description()const; |
137 | 136 | ||
138 | void setParts(const QValueList<RecPart>&parts); | 137 | void setParts(const QValueList<RecPart>&parts); |
139 | const QValueList<RecPart>& Parts()const; | 138 | const QValueList<RecPart>& Parts()const; |
140 | void addPart(const RecPart&part); | 139 | void addPart(const RecPart&part); |
141 | }; | 140 | }; |
142 | 141 | ||
143 | class encodedString | 142 | class encodedString |
144 | { | 143 | { |
145 | public: | 144 | public: |
146 | encodedString(); | 145 | encodedString(); |
147 | /* | 146 | /* |
148 | creates an new content string. | 147 | creates an new content string. |
149 | it makes a deep copy of it! | 148 | it makes a deep copy of it! |
150 | */ | 149 | */ |
151 | encodedString(const char*nContent,unsigned int length); | 150 | encodedString(const char*nContent,unsigned int length); |
152 | /* | 151 | /* |
153 | Take over the nContent. Means: it will just copy the pointer, not the content. | 152 | Take over the nContent. Means: it will just copy the pointer, not the content. |
154 | so make sure: No one else frees the string, the string has allocated with | 153 | so make sure: No one else frees the string, the string has allocated with |
155 | malloc for compatibility with c-based libs | 154 | malloc for compatibility with c-based libs |
156 | */ | 155 | */ |
157 | encodedString(char*nContent,unsigned int nSize); | 156 | encodedString(char*nContent,unsigned int nSize); |
158 | /* copy construkor - makes ALWAYS a deep copy!!!! */ | 157 | /* copy construkor - makes ALWAYS a deep copy!!!! */ |
159 | encodedString(const encodedString&old); | 158 | encodedString(const encodedString&old); |
160 | /* assign operator - makes ALWAYS a deep copy!!!! */ | 159 | /* assign operator - makes ALWAYS a deep copy!!!! */ |
161 | encodedString& operator=(const encodedString&old); | 160 | encodedString& operator=(const encodedString&old); |
162 | /* destructor - cleans the content */ | 161 | /* destructor - cleans the content */ |
163 | virtual ~encodedString(); | 162 | virtual ~encodedString(); |
164 | 163 | ||
165 | /* returns a pointer to the content - do not delete yoursel! */ | 164 | /* returns a pointer to the content - do not delete yoursel! */ |
166 | const char*Content()const; | 165 | const char*Content()const; |
167 | /* returns the lengths of the content 'cause it must not be a null-terminated string! */ | 166 | /* returns the lengths of the content 'cause it must not be a null-terminated string! */ |
168 | const int Length()const; | 167 | const int Length()const; |
169 | 168 | ||
170 | /* | 169 | /* |
171 | makes a deep copy of nContent! | 170 | makes a deep copy of nContent! |
172 | */ | 171 | */ |
173 | void setContent(const char*nContent,int nSize); | 172 | void setContent(const char*nContent,int nSize); |
174 | /* | 173 | /* |
175 | Take over the nContent. Means: it will just copy the pointer, not the content. | 174 | Take over the nContent. Means: it will just copy the pointer, not the content. |
176 | so make sure: No one else frees the string, the string has allocated with | 175 | so make sure: No one else frees the string, the string has allocated with |
177 | malloc for compatibility with c-based libs | 176 | malloc for compatibility with c-based libs |
178 | */ | 177 | */ |
179 | void setContent(char*nContent,int nSize); | 178 | void setContent(char*nContent,int nSize); |
180 | 179 | ||
181 | protected: | 180 | protected: |
182 | char * content; | 181 | char * content; |
183 | unsigned int size; | 182 | unsigned int size; |
184 | 183 | ||
185 | void init(); | 184 | void init(); |
186 | void copy_old(const encodedString&old); | 185 | void copy_old(const encodedString&old); |
187 | void clean(); | 186 | void clean(); |
188 | }; | 187 | }; |
189 | 188 | ||
190 | struct folderStat | 189 | struct folderStat |
191 | { | 190 | { |
192 | unsigned int message_count; | 191 | unsigned int message_count; |
193 | unsigned int message_unseen; | 192 | unsigned int message_unseen; |
194 | unsigned int message_recent; | 193 | unsigned int message_recent; |
195 | folderStat&operator=(const folderStat&old); | 194 | folderStat&operator=(const folderStat&old); |
196 | }; | 195 | }; |
197 | 196 | ||
198 | #endif | 197 | #endif |
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,166 +1,178 @@ | |||
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; |
108 | continue; | 116 | continue; |
109 | } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { | 117 | } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { |
110 | ucs4 += utf16 - UTF16LOSTART + UTF16BASE; | 118 | ucs4 += utf16 - UTF16LOSTART + UTF16BASE; |
111 | } else { | 119 | } else { |
112 | ucs4 = utf16; | 120 | ucs4 = utf16; |
113 | } | 121 | } |
114 | /* convert UTF-16 range of UCS4 to UTF-8 */ | 122 | /* convert UTF-16 range of UCS4 to UTF-8 */ |
115 | if (ucs4 <= 0x7fUL) { | 123 | if (ucs4 <= 0x7fUL) { |
116 | utf8[0] = ucs4; | 124 | utf8[0] = ucs4; |
117 | i = 1; | 125 | i = 1; |
118 | } else if (ucs4 <= 0x7ffUL) { | 126 | } else if (ucs4 <= 0x7ffUL) { |
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 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h index c66572c..3b3bb32 100644 --- a/noncore/net/mail/libmailwrapper/mailwrapper.h +++ b/noncore/net/mail/libmailwrapper/mailwrapper.h | |||
@@ -1,104 +1,106 @@ | |||
1 | #ifndef MAILWRAPPER_H | 1 | #ifndef MAILWRAPPER_H |
2 | #define MAILWRAPPER_H | 2 | #define MAILWRAPPER_H |
3 | 3 | ||
4 | #include <qpe/applnk.h> | 4 | #include <qpe/applnk.h> |
5 | 5 | ||
6 | #include <qbitarray.h> | 6 | #include <qbitarray.h> |
7 | #include <qdatetime.h> | 7 | #include <qdatetime.h> |
8 | 8 | ||
9 | #include "settings.h" | 9 | #include "settings.h" |
10 | 10 | ||
11 | #include <opie2/osmart_pointer.h> | 11 | #include <opie2/osmart_pointer.h> |
12 | 12 | ||
13 | class Attachment | 13 | class Attachment |
14 | { | 14 | { |
15 | public: | 15 | public: |
16 | Attachment( DocLnk lnk ); | 16 | Attachment( DocLnk lnk ); |
17 | virtual ~Attachment(){} | 17 | virtual ~Attachment(){} |
18 | const QString getFileName()const{ return doc.file(); } | 18 | const QString getFileName()const{ return doc.file(); } |
19 | const QString getName()const{ return doc.name(); } | 19 | const QString getName()const{ return doc.name(); } |
20 | const QString getMimeType()const{ return doc.type(); } | 20 | const QString getMimeType()const{ return doc.type(); } |
21 | const QPixmap getPixmap()const{ return doc.pixmap(); } | 21 | const QPixmap getPixmap()const{ return doc.pixmap(); } |
22 | const int getSize()const { return size; } | 22 | const int getSize()const { return size; } |
23 | DocLnk getDocLnk() { return doc; } | 23 | DocLnk getDocLnk() { return doc; } |
24 | 24 | ||
25 | protected: | 25 | protected: |
26 | DocLnk doc; | 26 | DocLnk doc; |
27 | int size; | 27 | int size; |
28 | 28 | ||
29 | }; | 29 | }; |
30 | 30 | ||
31 | class Mail:public Opie::oref_count | 31 | class Mail:public Opie::oref_count |
32 | { | 32 | { |
33 | public: | 33 | public: |
34 | Mail(); | 34 | Mail(); |
35 | /* Possible that this destructor must not be declared virtual | 35 | /* Possible that this destructor must not be declared virtual |
36 | * 'cause it seems that it will never have some child classes. | 36 | * 'cause it seems that it will never have some child classes. |
37 | * in this case this object will not get a virtual table -> memory and | 37 | * in this case this object will not get a virtual table -> memory and |
38 | * speed will be a little bit better? | 38 | * speed will be a little bit better? |
39 | */ | 39 | */ |
40 | virtual ~Mail(){} | 40 | virtual ~Mail(){} |
41 | void addAttachment( Attachment *att ) { attList.append( att ); } | 41 | void addAttachment( Attachment *att ) { attList.append( att ); } |
42 | const QList<Attachment>& getAttachments()const { return attList; } | 42 | const QList<Attachment>& getAttachments()const { return attList; } |
43 | void removeAttachment( Attachment *att ) { attList.remove( att ); } | 43 | void removeAttachment( Attachment *att ) { attList.remove( att ); } |
44 | const QString&getName()const { return name; } | 44 | const QString&getName()const { return name; } |
45 | void setName( QString s ) { name = s; } | 45 | void setName( QString s ) { name = s; } |
46 | const QString&getMail()const{ return mail; } | 46 | const QString&getMail()const{ return mail; } |
47 | void setMail( const QString&s ) { mail = s; } | 47 | void setMail( const QString&s ) { mail = s; } |
48 | const QString&getTo()const{ return to; } | 48 | const QString&getTo()const{ return to; } |
49 | void setTo( const QString&s ) { to = s; } | 49 | void setTo( const QString&s ) { to = s; } |
50 | const QString&getCC()const{ return cc; } | 50 | const QString&getCC()const{ return cc; } |
51 | void setCC( const QString&s ) { cc = s; } | 51 | void setCC( const QString&s ) { cc = s; } |
52 | const QString&getBCC()const { return bcc; } | 52 | const QString&getBCC()const { return bcc; } |
53 | void setBCC( const QString&s ) { bcc = s; } | 53 | void setBCC( const QString&s ) { bcc = s; } |
54 | const QString&getMessage()const { return message; } | 54 | const QString&getMessage()const { return message; } |
55 | void setMessage( const QString&s ) { message = s; } | 55 | void setMessage( const QString&s ) { message = s; } |
56 | const QString&getSubject()const { return subject; } | 56 | const QString&getSubject()const { return subject; } |
57 | void setSubject( const QString&s ) { subject = s; } | 57 | void setSubject( const QString&s ) { subject = s; } |
58 | const QString&getReply()const{ return reply; } | 58 | const QString&getReply()const{ return reply; } |
59 | void setReply( const QString&a ) { reply = a; } | 59 | void setReply( const QString&a ) { reply = a; } |
60 | void setInreply(const QStringList&list){m_in_reply_to = list;} | 60 | void setInreply(const QStringList&list){m_in_reply_to = list;} |
61 | const QStringList&Inreply()const{return m_in_reply_to;} | 61 | const QStringList&Inreply()const{return m_in_reply_to;} |
62 | 62 | ||
63 | private: | 63 | private: |
64 | QList<Attachment> attList; | 64 | QList<Attachment> attList; |
65 | QString name, mail, to, cc, bcc, reply, subject, message; | 65 | QString name, mail, to, cc, bcc, reply, subject, message; |
66 | QStringList m_in_reply_to; | 66 | QStringList m_in_reply_to; |
67 | }; | 67 | }; |
68 | 68 | ||
69 | class Folder : public QObject | 69 | class Folder:public Opie::oref_count |
70 | { | 70 | { |
71 | Q_OBJECT | ||
72 | |||
73 | public: | 71 | public: |
74 | Folder( const QString&init_name,const QString&sep ); | 72 | Folder( const QString&init_name,const QString&sep ); |
73 | virtual ~Folder(); | ||
75 | const QString&getDisplayName()const { return nameDisplay; } | 74 | const QString&getDisplayName()const { return nameDisplay; } |
76 | const QString&getName()const { return name; } | 75 | const QString&getName()const { return name; } |
77 | const QString&getPrefix()const{return prefix; } | 76 | const QString&getPrefix()const{return prefix; } |
78 | virtual bool may_select()const{return true;} | 77 | virtual bool may_select()const{return true;} |
79 | virtual bool no_inferior()const{return true;} | 78 | virtual bool no_inferior()const{return true;} |
80 | const QString&Separator()const; | 79 | const QString&Separator()const; |
81 | 80 | ||
82 | protected: | 81 | protected: |
83 | QString nameDisplay, name, separator,prefix; | 82 | QString nameDisplay, name, separator,prefix; |
84 | }; | 83 | }; |
85 | 84 | ||
85 | typedef Opie::osmart_pointer<Folder> FolderP; | ||
86 | |||
86 | class MHFolder : public Folder | 87 | class MHFolder : public Folder |
87 | { | 88 | { |
88 | Q_OBJECT | ||
89 | public: | 89 | public: |
90 | MHFolder(const QString&disp_name,const QString&mbox); | 90 | MHFolder(const QString&disp_name,const QString&mbox); |
91 | virtual ~MHFolder(); | ||
91 | }; | 92 | }; |
92 | 93 | ||
93 | class IMAPFolder : public Folder | 94 | class IMAPFolder : public Folder |
94 | { | 95 | { |
95 | public: | 96 | public: |
96 | IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" ); | 97 | IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" ); |
98 | virtual ~IMAPFolder(); | ||
97 | virtual bool may_select()const{return m_MaySelect;} | 99 | virtual bool may_select()const{return m_MaySelect;} |
98 | virtual bool no_inferior()const{return m_NoInferior;} | 100 | virtual bool no_inferior()const{return m_NoInferior;} |
99 | private: | 101 | private: |
100 | static QString decodeFolderName( const QString &name ); | 102 | static QString decodeFolderName( const QString &name ); |
101 | bool m_MaySelect,m_NoInferior; | 103 | bool m_MaySelect,m_NoInferior; |
102 | }; | 104 | }; |
103 | 105 | ||
104 | #endif | 106 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp index abe4bb6..9ff3de2 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp | |||
@@ -1,335 +1,334 @@ | |||
1 | #include "mboxwrapper.h" | 1 | #include "mboxwrapper.h" |
2 | #include "mailtypes.h" | 2 | #include "mailtypes.h" |
3 | #include "mailwrapper.h" | 3 | #include "mailwrapper.h" |
4 | #include <libetpan/libetpan.h> | 4 | #include <libetpan/libetpan.h> |
5 | #include <qdir.h> | 5 | #include <qdir.h> |
6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
7 | #include <qpe/global.h> | 7 | #include <qpe/global.h> |
8 | 8 | ||
9 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name) | 9 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name) |
10 | : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name) | 10 | : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name) |
11 | { | 11 | { |
12 | QDir dir(MBOXPath); | 12 | QDir dir(MBOXPath); |
13 | if (!dir.exists()) { | 13 | if (!dir.exists()) { |
14 | dir.mkdir(MBOXPath); | 14 | dir.mkdir(MBOXPath); |
15 | } | 15 | } |
16 | } | 16 | } |
17 | 17 | ||
18 | MBOXwrapper::~MBOXwrapper() | 18 | MBOXwrapper::~MBOXwrapper() |
19 | { | 19 | { |
20 | } | 20 | } |
21 | 21 | ||
22 | void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | 22 | void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) |
23 | { | 23 | { |
24 | mailstorage*storage = mailstorage_new(NULL); | 24 | mailstorage*storage = mailstorage_new(NULL); |
25 | QString p = MBOXPath+"/"; | 25 | QString p = MBOXPath+"/"; |
26 | p+=mailbox; | 26 | p+=mailbox; |
27 | 27 | ||
28 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 28 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
29 | mailfolder*folder; | 29 | mailfolder*folder; |
30 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 30 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
31 | r = mailfolder_connect(folder); | 31 | r = mailfolder_connect(folder); |
32 | if (r != MAIL_NO_ERROR) { | 32 | if (r != MAIL_NO_ERROR) { |
33 | qDebug("Error initializing mbox"); | 33 | qDebug("Error initializing mbox"); |
34 | mailfolder_free(folder); | 34 | mailfolder_free(folder); |
35 | mailstorage_free(storage); | 35 | mailstorage_free(storage); |
36 | return; | 36 | return; |
37 | } | 37 | } |
38 | 38 | ||
39 | parseList(target,folder->fld_session,mailbox); | 39 | parseList(target,folder->fld_session,mailbox); |
40 | 40 | ||
41 | mailfolder_disconnect(folder); | 41 | mailfolder_disconnect(folder); |
42 | mailfolder_free(folder); | 42 | mailfolder_free(folder); |
43 | mailstorage_free(storage); | 43 | mailstorage_free(storage); |
44 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); | 44 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); |
45 | } | 45 | } |
46 | 46 | ||
47 | QList<Folder>* MBOXwrapper::listFolders() | 47 | QValueList<Opie::osmart_pointer<Folder> >* MBOXwrapper::listFolders() |
48 | { | 48 | { |
49 | QList<Folder> * folders = new QList<Folder>(); | 49 | QValueList<Opie::osmart_pointer<Folder> >* folders = new QValueList<Opie::osmart_pointer<Folder> >(); |
50 | folders->setAutoDelete( false ); | ||
51 | QDir dir(MBOXPath); | 50 | QDir dir(MBOXPath); |
52 | if (!dir.exists()) return folders; | 51 | if (!dir.exists()) return folders; |
53 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); | 52 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); |
54 | QStringList entries = dir.entryList(); | 53 | QStringList entries = dir.entryList(); |
55 | QStringList::ConstIterator it = entries.begin(); | 54 | QStringList::ConstIterator it = entries.begin(); |
56 | for (;it!=entries.end();++it) { | 55 | for (;it!=entries.end();++it) { |
57 | Folder*inb=new Folder(*it,"/"); | 56 | FolderP inb=new Folder(*it,"/"); |
58 | folders->append(inb); | 57 | folders->append(inb); |
59 | } | 58 | } |
60 | return folders; | 59 | return folders; |
61 | } | 60 | } |
62 | 61 | ||
63 | void MBOXwrapper::deleteMail(const RecMail&mail) | 62 | void MBOXwrapper::deleteMail(const RecMail&mail) |
64 | { | 63 | { |
65 | mailstorage*storage = mailstorage_new(NULL); | 64 | mailstorage*storage = mailstorage_new(NULL); |
66 | QString p = MBOXPath+"/"; | 65 | QString p = MBOXPath+"/"; |
67 | p+=mail.getMbox(); | 66 | p+=mail.getMbox(); |
68 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 67 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
69 | mailfolder*folder; | 68 | mailfolder*folder; |
70 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 69 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
71 | r = mailfolder_connect(folder); | 70 | r = mailfolder_connect(folder); |
72 | if (r != MAIL_NO_ERROR) { | 71 | if (r != MAIL_NO_ERROR) { |
73 | qDebug("Error initializing mbox"); | 72 | qDebug("Error initializing mbox"); |
74 | mailfolder_free(folder); | 73 | mailfolder_free(folder); |
75 | mailstorage_free(storage); | 74 | mailstorage_free(storage); |
76 | return; | 75 | return; |
77 | } | 76 | } |
78 | r = mailsession_remove_message(folder->fld_session,mail.getNumber()); | 77 | r = mailsession_remove_message(folder->fld_session,mail.getNumber()); |
79 | if (r != MAIL_NO_ERROR) { | 78 | if (r != MAIL_NO_ERROR) { |
80 | qDebug("error deleting mail"); | 79 | qDebug("error deleting mail"); |
81 | } | 80 | } |
82 | mailfolder_free(folder); | 81 | mailfolder_free(folder); |
83 | mailstorage_free(storage); | 82 | mailstorage_free(storage); |
84 | } | 83 | } |
85 | 84 | ||
86 | void MBOXwrapper::answeredMail(const RecMail&) | 85 | void MBOXwrapper::answeredMail(const RecMail&) |
87 | { | 86 | { |
88 | } | 87 | } |
89 | 88 | ||
90 | RecBody MBOXwrapper::fetchBody( const RecMail &mail ) | 89 | RecBody MBOXwrapper::fetchBody( const RecMail &mail ) |
91 | { | 90 | { |
92 | RecBody body; | 91 | RecBody body; |
93 | mailstorage*storage = mailstorage_new(NULL); | 92 | mailstorage*storage = mailstorage_new(NULL); |
94 | QString p = MBOXPath+"/"; | 93 | QString p = MBOXPath+"/"; |
95 | p+=mail.getMbox(); | 94 | p+=mail.getMbox(); |
96 | mailmessage * msg; | 95 | mailmessage * msg; |
97 | char*data=0; | 96 | char*data=0; |
98 | size_t size; | 97 | size_t size; |
99 | 98 | ||
100 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 99 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
101 | mailfolder*folder; | 100 | mailfolder*folder; |
102 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 101 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
103 | r = mailfolder_connect(folder); | 102 | r = mailfolder_connect(folder); |
104 | if (r != MAIL_NO_ERROR) { | 103 | if (r != MAIL_NO_ERROR) { |
105 | qDebug("Error initializing mbox"); | 104 | qDebug("Error initializing mbox"); |
106 | mailfolder_free(folder); | 105 | mailfolder_free(folder); |
107 | mailstorage_free(storage); | 106 | mailstorage_free(storage); |
108 | return body; | 107 | return body; |
109 | } | 108 | } |
110 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | 109 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); |
111 | if (r != MAIL_NO_ERROR) { | 110 | if (r != MAIL_NO_ERROR) { |
112 | qDebug("Error fetching mail %i",mail.getNumber()); | 111 | qDebug("Error fetching mail %i",mail.getNumber()); |
113 | mailfolder_free(folder); | 112 | mailfolder_free(folder); |
114 | mailstorage_free(storage); | 113 | mailstorage_free(storage); |
115 | return body; | 114 | return body; |
116 | } | 115 | } |
117 | r = mailmessage_fetch(msg,&data,&size); | 116 | r = mailmessage_fetch(msg,&data,&size); |
118 | if (r != MAIL_NO_ERROR) { | 117 | if (r != MAIL_NO_ERROR) { |
119 | qDebug("Error fetching mail %i",mail.getNumber()); | 118 | qDebug("Error fetching mail %i",mail.getNumber()); |
120 | mailfolder_free(folder); | 119 | mailfolder_free(folder); |
121 | mailstorage_free(storage); | 120 | mailstorage_free(storage); |
122 | mailmessage_free(msg); | 121 | mailmessage_free(msg); |
123 | return body; | 122 | return body; |
124 | } | 123 | } |
125 | body = parseMail(msg); | 124 | body = parseMail(msg); |
126 | mailmessage_fetch_result_free(msg,data); | 125 | mailmessage_fetch_result_free(msg,data); |
127 | mailfolder_free(folder); | 126 | mailfolder_free(folder); |
128 | mailstorage_free(storage); | 127 | mailstorage_free(storage); |
129 | 128 | ||
130 | return body; | 129 | return body; |
131 | } | 130 | } |
132 | 131 | ||
133 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) | 132 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) |
134 | { | 133 | { |
135 | qDebug("MBOX %i von %i",current,maximum); | 134 | qDebug("MBOX %i von %i",current,maximum); |
136 | } | 135 | } |
137 | 136 | ||
138 | int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool ) | 137 | int MBOXwrapper::createMbox(const QString&folder,const FolderP&,const QString&,bool ) |
139 | { | 138 | { |
140 | QString p = MBOXPath+"/"; | 139 | QString p = MBOXPath+"/"; |
141 | p+=folder; | 140 | p+=folder; |
142 | QFileInfo fi(p); | 141 | QFileInfo fi(p); |
143 | if (fi.exists()) { | 142 | if (fi.exists()) { |
144 | Global::statusMessage(tr("Mailbox exists.")); | 143 | Global::statusMessage(tr("Mailbox exists.")); |
145 | return 0; | 144 | return 0; |
146 | } | 145 | } |
147 | mailmbox_folder*f = 0; | 146 | mailmbox_folder*f = 0; |
148 | if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { | 147 | if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { |
149 | Global::statusMessage(tr("Error init folder")); | 148 | Global::statusMessage(tr("Error init folder")); |
150 | return 0; | 149 | return 0; |
151 | } | 150 | } |
152 | if (f) mailmbox_done(f); | 151 | if (f) mailmbox_done(f); |
153 | return 1; | 152 | return 1; |
154 | } | 153 | } |
155 | 154 | ||
156 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | 155 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) |
157 | { | 156 | { |
158 | QString p = MBOXPath+"/"; | 157 | QString p = MBOXPath+"/"; |
159 | p+=folder; | 158 | p+=folder; |
160 | mailmbox_folder*f = 0; | 159 | mailmbox_folder*f = 0; |
161 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 160 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
162 | if (r != MAIL_NO_ERROR) { | 161 | if (r != MAIL_NO_ERROR) { |
163 | Global::statusMessage(tr("Error init folder")); | 162 | Global::statusMessage(tr("Error init folder")); |
164 | return; | 163 | return; |
165 | } | 164 | } |
166 | r = mailmbox_append_message(f,msg,length); | 165 | r = mailmbox_append_message(f,msg,length); |
167 | if (r != MAIL_NO_ERROR) { | 166 | if (r != MAIL_NO_ERROR) { |
168 | Global::statusMessage(tr("Error writing to message folder")); | 167 | Global::statusMessage(tr("Error writing to message folder")); |
169 | } | 168 | } |
170 | mailmbox_done(f); | 169 | mailmbox_done(f); |
171 | } | 170 | } |
172 | 171 | ||
173 | encodedString* MBOXwrapper::fetchRawBody(const RecMail&mail) | 172 | encodedString* MBOXwrapper::fetchRawBody(const RecMail&mail) |
174 | { | 173 | { |
175 | RecBody body; | 174 | RecBody body; |
176 | mailstorage*storage = mailstorage_new(NULL); | 175 | mailstorage*storage = mailstorage_new(NULL); |
177 | QString p = MBOXPath+"/"; | 176 | QString p = MBOXPath+"/"; |
178 | p+=mail.getMbox(); | 177 | p+=mail.getMbox(); |
179 | mailmessage * msg; | 178 | mailmessage * msg; |
180 | char*data=0; | 179 | char*data=0; |
181 | size_t size; | 180 | size_t size; |
182 | 181 | ||
183 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 182 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
184 | mailfolder*folder; | 183 | mailfolder*folder; |
185 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 184 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
186 | r = mailfolder_connect(folder); | 185 | r = mailfolder_connect(folder); |
187 | if (r != MAIL_NO_ERROR) { | 186 | if (r != MAIL_NO_ERROR) { |
188 | Global::statusMessage(tr("Error initializing mbox")); | 187 | Global::statusMessage(tr("Error initializing mbox")); |
189 | mailfolder_free(folder); | 188 | mailfolder_free(folder); |
190 | mailstorage_free(storage); | 189 | mailstorage_free(storage); |
191 | return 0; | 190 | return 0; |
192 | } | 191 | } |
193 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | 192 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); |
194 | if (r != MAIL_NO_ERROR) { | 193 | if (r != MAIL_NO_ERROR) { |
195 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); | 194 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); |
196 | mailfolder_free(folder); | 195 | mailfolder_free(folder); |
197 | mailstorage_free(storage); | 196 | mailstorage_free(storage); |
198 | return 0; | 197 | return 0; |
199 | } | 198 | } |
200 | r = mailmessage_fetch(msg,&data,&size); | 199 | r = mailmessage_fetch(msg,&data,&size); |
201 | if (r != MAIL_NO_ERROR) { | 200 | if (r != MAIL_NO_ERROR) { |
202 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); | 201 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); |
203 | mailfolder_free(folder); | 202 | mailfolder_free(folder); |
204 | mailstorage_free(storage); | 203 | mailstorage_free(storage); |
205 | mailmessage_free(msg); | 204 | mailmessage_free(msg); |
206 | return 0; | 205 | return 0; |
207 | } | 206 | } |
208 | encodedString*result = new encodedString(data,size); | 207 | encodedString*result = new encodedString(data,size); |
209 | 208 | ||
210 | mailfolder_free(folder); | 209 | mailfolder_free(folder); |
211 | mailstorage_free(storage); | 210 | mailstorage_free(storage); |
212 | mailmessage_free(msg); | 211 | mailmessage_free(msg); |
213 | return result; | 212 | return result; |
214 | } | 213 | } |
215 | 214 | ||
216 | void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) | 215 | void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) |
217 | { | 216 | { |
218 | QString p = MBOXPath+"/"; | 217 | QString p = MBOXPath+"/"; |
219 | p+=mailbox; | 218 | p+=mailbox; |
220 | mailmbox_folder*f = 0; | 219 | mailmbox_folder*f = 0; |
221 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 220 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
222 | if (r != MAIL_NO_ERROR) { | 221 | if (r != MAIL_NO_ERROR) { |
223 | qDebug("Error init folder"); | 222 | qDebug("Error init folder"); |
224 | return; | 223 | return; |
225 | } | 224 | } |
226 | deleteMails(f,target); | 225 | deleteMails(f,target); |
227 | mailmbox_done(f); | 226 | mailmbox_done(f); |
228 | } | 227 | } |
229 | 228 | ||
230 | void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target) | 229 | void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target) |
231 | { | 230 | { |
232 | if (!f) return; | 231 | if (!f) return; |
233 | int r; | 232 | int r; |
234 | for (unsigned int i=0; i < target.count();++i) { | 233 | for (unsigned int i=0; i < target.count();++i) { |
235 | r = mailmbox_delete_msg(f,target.at(i)->getNumber()); | 234 | r = mailmbox_delete_msg(f,target.at(i)->getNumber()); |
236 | if (r!=MAILMBOX_NO_ERROR) { | 235 | if (r!=MAILMBOX_NO_ERROR) { |
237 | qDebug("error delete mail"); | 236 | qDebug("error delete mail"); |
238 | } | 237 | } |
239 | } | 238 | } |
240 | r = mailmbox_expunge(f); | 239 | r = mailmbox_expunge(f); |
241 | if (r != MAILMBOX_NO_ERROR) { | 240 | if (r != MAILMBOX_NO_ERROR) { |
242 | qDebug("error expunge mailbox"); | 241 | qDebug("error expunge mailbox"); |
243 | } | 242 | } |
244 | } | 243 | } |
245 | 244 | ||
246 | int MBOXwrapper::deleteAllMail(const Folder*tfolder) | 245 | int MBOXwrapper::deleteAllMail(const FolderP&tfolder) |
247 | { | 246 | { |
248 | if (!tfolder) return 0; | 247 | if (!tfolder) return 0; |
249 | QString p = MBOXPath+"/"+tfolder->getDisplayName(); | 248 | QString p = MBOXPath+"/"+tfolder->getDisplayName(); |
250 | int res = 1; | 249 | int res = 1; |
251 | 250 | ||
252 | mailfolder*folder = 0; | 251 | mailfolder*folder = 0; |
253 | mailmessage_list*l=0; | 252 | mailmessage_list*l=0; |
254 | mailstorage*storage = mailstorage_new(NULL); | 253 | mailstorage*storage = mailstorage_new(NULL); |
255 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 254 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
256 | if (r != MAIL_NO_ERROR) { | 255 | if (r != MAIL_NO_ERROR) { |
257 | Global::statusMessage(tr("Error initializing mbox")); | 256 | Global::statusMessage(tr("Error initializing mbox")); |
258 | res = 0; | 257 | res = 0; |
259 | } | 258 | } |
260 | if (res) { | 259 | if (res) { |
261 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 260 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
262 | r = mailfolder_connect(folder); | 261 | r = mailfolder_connect(folder); |
263 | if (r != MAIL_NO_ERROR) { | 262 | if (r != MAIL_NO_ERROR) { |
264 | Global::statusMessage(tr("Error initializing mbox")); | 263 | Global::statusMessage(tr("Error initializing mbox")); |
265 | res = 0; | 264 | res = 0; |
266 | } | 265 | } |
267 | } | 266 | } |
268 | if (res) { | 267 | if (res) { |
269 | r = mailsession_get_messages_list(folder->fld_session,&l); | 268 | r = mailsession_get_messages_list(folder->fld_session,&l); |
270 | if (r != MAIL_NO_ERROR) { | 269 | if (r != MAIL_NO_ERROR) { |
271 | qDebug("Error message list"); | 270 | qDebug("Error message list"); |
272 | res=0; | 271 | res=0; |
273 | } | 272 | } |
274 | } | 273 | } |
275 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | 274 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { |
276 | r = mailsession_remove_message(folder->fld_session,i+1); | 275 | r = mailsession_remove_message(folder->fld_session,i+1); |
277 | if (r != MAIL_NO_ERROR) { | 276 | if (r != MAIL_NO_ERROR) { |
278 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 277 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
279 | res = 0; | 278 | res = 0; |
280 | break; | 279 | break; |
281 | } | 280 | } |
282 | } | 281 | } |
283 | if (l) mailmessage_list_free(l); | 282 | if (l) mailmessage_list_free(l); |
284 | if (folder) mailfolder_free(folder); | 283 | if (folder) mailfolder_free(folder); |
285 | if (storage) mailstorage_free(storage); | 284 | if (storage) mailstorage_free(storage); |
286 | return res; | 285 | return res; |
287 | } | 286 | } |
288 | 287 | ||
289 | int MBOXwrapper::deleteMbox(const Folder*tfolder) | 288 | int MBOXwrapper::deleteMbox(const FolderP&tfolder) |
290 | { | 289 | { |
291 | if (!tfolder) return 0; | 290 | if (!tfolder) return 0; |
292 | QString p = MBOXPath+"/"+tfolder->getDisplayName(); | 291 | QString p = MBOXPath+"/"+tfolder->getDisplayName(); |
293 | QFile fi(p); | 292 | QFile fi(p); |
294 | if (!fi.exists()) { | 293 | if (!fi.exists()) { |
295 | Global::statusMessage(tr("Mailbox doesn't exist.")); | 294 | Global::statusMessage(tr("Mailbox doesn't exist.")); |
296 | return 0; | 295 | return 0; |
297 | } | 296 | } |
298 | if (!fi.remove()) { | 297 | if (!fi.remove()) { |
299 | Global::statusMessage(tr("Error deleting Mailbox.")); | 298 | Global::statusMessage(tr("Error deleting Mailbox.")); |
300 | return 0; | 299 | return 0; |
301 | } | 300 | } |
302 | return 1; | 301 | return 1; |
303 | } | 302 | } |
304 | 303 | ||
305 | void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | 304 | void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) |
306 | { | 305 | { |
307 | mailfolder*folder = 0; | 306 | mailfolder*folder = 0; |
308 | mailstorage*storage = mailstorage_new(NULL); | 307 | mailstorage*storage = mailstorage_new(NULL); |
309 | target_stat.message_count = 0; | 308 | target_stat.message_count = 0; |
310 | target_stat.message_unseen = 0; | 309 | target_stat.message_unseen = 0; |
311 | target_stat.message_recent = 0; | 310 | target_stat.message_recent = 0; |
312 | QString p = MBOXPath+"/"+mailbox; | 311 | QString p = MBOXPath+"/"+mailbox; |
313 | QFile fi(p); | 312 | QFile fi(p); |
314 | if (!fi.exists()) { | 313 | if (!fi.exists()) { |
315 | Global::statusMessage(tr("Mailbox doesn't exist.")); | 314 | Global::statusMessage(tr("Mailbox doesn't exist.")); |
316 | return; | 315 | return; |
317 | } | 316 | } |
318 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 317 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
319 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 318 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
320 | r = mailfolder_connect(folder); | 319 | r = mailfolder_connect(folder); |
321 | r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, | 320 | r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, |
322 | &target_stat.message_recent,&target_stat.message_unseen); | 321 | &target_stat.message_recent,&target_stat.message_unseen); |
323 | if (folder) mailfolder_free(folder); | 322 | if (folder) mailfolder_free(folder); |
324 | if (storage) mailstorage_free(storage); | 323 | if (storage) mailstorage_free(storage); |
325 | } | 324 | } |
326 | 325 | ||
327 | MAILLIB::ATYPE MBOXwrapper::getType()const | 326 | MAILLIB::ATYPE MBOXwrapper::getType()const |
328 | { | 327 | { |
329 | return MAILLIB::A_MBOX; | 328 | return MAILLIB::A_MBOX; |
330 | } | 329 | } |
331 | 330 | ||
332 | const QString&MBOXwrapper::getName()const | 331 | const QString&MBOXwrapper::getName()const |
333 | { | 332 | { |
334 | return MBOXName; | 333 | return MBOXName; |
335 | } | 334 | } |
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.h b/noncore/net/mail/libmailwrapper/mboxwrapper.h index 7e7f359..c3d9b50 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.h +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.h | |||
@@ -1,47 +1,48 @@ | |||
1 | #ifndef __MBOX_WRAPPER_H | 1 | #ifndef __MBOX_WRAPPER_H |
2 | #define __MBOX_WRAPPER_H | 2 | #define __MBOX_WRAPPER_H |
3 | 3 | ||
4 | #include "genericwrapper.h" | 4 | #include "genericwrapper.h" |
5 | #include <qstring.h> | 5 | #include <qstring.h> |
6 | 6 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | class encodedString; | 9 | class encodedString; |
10 | struct mailmbox_folder; | 10 | struct mailmbox_folder; |
11 | 11 | ||
12 | class MBOXwrapper : public Genericwrapper | 12 | class MBOXwrapper : public Genericwrapper |
13 | { | 13 | { |
14 | Q_OBJECT | 14 | Q_OBJECT |
15 | 15 | ||
16 | public: | 16 | public: |
17 | MBOXwrapper(const QString & dir,const QString&name); | 17 | MBOXwrapper(const QString & dir,const QString&name); |
18 | virtual ~MBOXwrapper(); | 18 | virtual ~MBOXwrapper(); |
19 | 19 | ||
20 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 20 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
21 | virtual QList<Folder>* listFolders(); | 21 | virtual QValueList<Opie::osmart_pointer<Folder> >* listFolders(); |
22 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | 22 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); |
23 | 23 | ||
24 | virtual void deleteMail(const RecMail&mail); | 24 | virtual void deleteMail(const RecMail&mail); |
25 | virtual void answeredMail(const RecMail&mail); | 25 | virtual void answeredMail(const RecMail&mail); |
26 | 26 | ||
27 | virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false); | 27 | virtual int createMbox(const QString&folder,const Opie::osmart_pointer<Folder>&f=0, |
28 | virtual int deleteMbox(const Folder*); | 28 | const QString&d="",bool s=false); |
29 | virtual int deleteMbox(const Opie::osmart_pointer<Folder>&); | ||
29 | 30 | ||
30 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); | 31 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); |
31 | 32 | ||
32 | virtual RecBody fetchBody( const RecMail &mail ); | 33 | virtual RecBody fetchBody( const RecMail &mail ); |
33 | static void mbox_progress( size_t current, size_t maximum ); | 34 | static void mbox_progress( size_t current, size_t maximum ); |
34 | 35 | ||
35 | virtual encodedString* fetchRawBody(const RecMail&mail); | 36 | virtual encodedString* fetchRawBody(const RecMail&mail); |
36 | virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); | 37 | virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); |
37 | virtual int deleteAllMail(const Folder*); | 38 | virtual int deleteAllMail(const Opie::osmart_pointer<Folder>&); |
38 | virtual MAILLIB::ATYPE getType()const; | 39 | virtual MAILLIB::ATYPE getType()const; |
39 | virtual const QString&getName()const; | 40 | virtual const QString&getName()const; |
40 | 41 | ||
41 | protected: | 42 | protected: |
42 | static void deleteMails(mailmbox_folder*f,QList<RecMail> &target); | 43 | static void deleteMails(mailmbox_folder*f,QList<RecMail> &target); |
43 | QString MBOXPath; | 44 | QString MBOXPath; |
44 | QString MBOXName; | 45 | QString MBOXName; |
45 | }; | 46 | }; |
46 | 47 | ||
47 | #endif | 48 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.cpp b/noncore/net/mail/libmailwrapper/mhwrapper.cpp index 560eab0..aaaa20a 100644 --- a/noncore/net/mail/libmailwrapper/mhwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mhwrapper.cpp | |||
@@ -1,443 +1,443 @@ | |||
1 | #include "mhwrapper.h" | 1 | #include "mhwrapper.h" |
2 | #include "mailtypes.h" | 2 | #include "mailtypes.h" |
3 | #include "mailwrapper.h" | 3 | #include "mailwrapper.h" |
4 | #include <libetpan/libetpan.h> | 4 | #include <libetpan/libetpan.h> |
5 | #include <qdir.h> | 5 | #include <qdir.h> |
6 | #include <qmessagebox.h> | 6 | #include <qmessagebox.h> |
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | #include <qpe/global.h> | 8 | #include <qpe/global.h> |
9 | #include <opie2/oprocess.h> | 9 | #include <opie2/oprocess.h> |
10 | 10 | ||
11 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) | 11 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) |
12 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) | 12 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) |
13 | { | 13 | { |
14 | if (MHPath.length()>0) { | 14 | if (MHPath.length()>0) { |
15 | if (MHPath[MHPath.length()-1]=='/') { | 15 | if (MHPath[MHPath.length()-1]=='/') { |
16 | MHPath=MHPath.left(MHPath.length()-1); | 16 | MHPath=MHPath.left(MHPath.length()-1); |
17 | } | 17 | } |
18 | qDebug(MHPath); | 18 | qDebug(MHPath); |
19 | QDir dir(MHPath); | 19 | QDir dir(MHPath); |
20 | if (!dir.exists()) { | 20 | if (!dir.exists()) { |
21 | dir.mkdir(MHPath); | 21 | dir.mkdir(MHPath); |
22 | } | 22 | } |
23 | init_storage(); | 23 | init_storage(); |
24 | } | 24 | } |
25 | } | 25 | } |
26 | 26 | ||
27 | void MHwrapper::init_storage() | 27 | void MHwrapper::init_storage() |
28 | { | 28 | { |
29 | int r; | 29 | int r; |
30 | QString pre = MHPath; | 30 | QString pre = MHPath; |
31 | if (!m_storage) { | 31 | if (!m_storage) { |
32 | m_storage = mailstorage_new(NULL); | 32 | m_storage = mailstorage_new(NULL); |
33 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); | 33 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); |
34 | if (r != MAIL_NO_ERROR) { | 34 | if (r != MAIL_NO_ERROR) { |
35 | qDebug("error initializing storage"); | 35 | qDebug("error initializing storage"); |
36 | mailstorage_free(m_storage); | 36 | mailstorage_free(m_storage); |
37 | m_storage = 0; | 37 | m_storage = 0; |
38 | return; | 38 | return; |
39 | } | 39 | } |
40 | } | 40 | } |
41 | r = mailstorage_connect(m_storage); | 41 | r = mailstorage_connect(m_storage); |
42 | if (r!=MAIL_NO_ERROR) { | 42 | if (r!=MAIL_NO_ERROR) { |
43 | qDebug("error connecting storage"); | 43 | qDebug("error connecting storage"); |
44 | mailstorage_free(m_storage); | 44 | mailstorage_free(m_storage); |
45 | m_storage = 0; | 45 | m_storage = 0; |
46 | } | 46 | } |
47 | } | 47 | } |
48 | 48 | ||
49 | void MHwrapper::clean_storage() | 49 | void MHwrapper::clean_storage() |
50 | { | 50 | { |
51 | if (m_storage) { | 51 | if (m_storage) { |
52 | mailstorage_disconnect(m_storage); | 52 | mailstorage_disconnect(m_storage); |
53 | mailstorage_free(m_storage); | 53 | mailstorage_free(m_storage); |
54 | m_storage = 0; | 54 | m_storage = 0; |
55 | } | 55 | } |
56 | } | 56 | } |
57 | 57 | ||
58 | MHwrapper::~MHwrapper() | 58 | MHwrapper::~MHwrapper() |
59 | { | 59 | { |
60 | clean_storage(); | 60 | clean_storage(); |
61 | } | 61 | } |
62 | 62 | ||
63 | void MHwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | 63 | void MHwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) |
64 | { | 64 | { |
65 | init_storage(); | 65 | init_storage(); |
66 | if (!m_storage) { | 66 | if (!m_storage) { |
67 | return; | 67 | return; |
68 | } | 68 | } |
69 | QString f = buildPath(mailbox); | 69 | QString f = buildPath(mailbox); |
70 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 70 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
71 | if (r!=MAIL_NO_ERROR) { | 71 | if (r!=MAIL_NO_ERROR) { |
72 | qDebug("listMessages: error selecting folder!"); | 72 | qDebug("listMessages: error selecting folder!"); |
73 | return; | 73 | return; |
74 | } | 74 | } |
75 | parseList(target,m_storage->sto_session,f); | 75 | parseList(target,m_storage->sto_session,f); |
76 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); | 76 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); |
77 | } | 77 | } |
78 | 78 | ||
79 | QList<Folder>* MHwrapper::listFolders() | 79 | QValueList<Opie::osmart_pointer<Folder> >* MHwrapper::listFolders() |
80 | { | 80 | { |
81 | QList<Folder> * folders = new QList<Folder>(); | 81 | QValueList<Opie::osmart_pointer<Folder> >* folders = new QValueList<Opie::osmart_pointer<Folder> >(); |
82 | folders->setAutoDelete( false ); | ||
83 | /* this is needed! */ | 82 | /* this is needed! */ |
84 | if (m_storage) mailstorage_disconnect(m_storage); | 83 | if (m_storage) mailstorage_disconnect(m_storage); |
85 | init_storage(); | 84 | init_storage(); |
86 | if (!m_storage) { | 85 | if (!m_storage) { |
87 | return folders; | 86 | return folders; |
88 | } | 87 | } |
89 | mail_list*flist = 0; | 88 | mail_list*flist = 0; |
90 | clistcell*current=0; | 89 | clistcell*current=0; |
91 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); | 90 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); |
92 | if (r != MAIL_NO_ERROR || !flist) { | 91 | if (r != MAIL_NO_ERROR || !flist) { |
93 | qDebug("error getting folder list"); | 92 | qDebug("error getting folder list"); |
94 | return folders; | 93 | return folders; |
95 | } | 94 | } |
96 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { | 95 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { |
97 | QString t = (char*)current->data; | 96 | QString t = (char*)current->data; |
98 | t.replace(0,MHPath.length(),""); | 97 | t.replace(0,MHPath.length(),""); |
99 | folders->append(new MHFolder(t,MHPath)); | 98 | folders->append(new MHFolder(t,MHPath)); |
100 | } | 99 | } |
101 | mail_list_free(flist); | 100 | mail_list_free(flist); |
102 | return folders; | 101 | return folders; |
103 | } | 102 | } |
104 | 103 | ||
105 | void MHwrapper::deleteMail(const RecMail&mail) | 104 | void MHwrapper::deleteMail(const RecMail&mail) |
106 | { | 105 | { |
107 | init_storage(); | 106 | init_storage(); |
108 | if (!m_storage) { | 107 | if (!m_storage) { |
109 | return; | 108 | return; |
110 | } | 109 | } |
111 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); | 110 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); |
112 | if (r!=MAIL_NO_ERROR) { | 111 | if (r!=MAIL_NO_ERROR) { |
113 | qDebug("error selecting folder!"); | 112 | qDebug("error selecting folder!"); |
114 | return; | 113 | return; |
115 | } | 114 | } |
116 | r = mailsession_remove_message(m_storage->sto_session,mail.getNumber()); | 115 | r = mailsession_remove_message(m_storage->sto_session,mail.getNumber()); |
117 | if (r != MAIL_NO_ERROR) { | 116 | if (r != MAIL_NO_ERROR) { |
118 | qDebug("error deleting mail"); | 117 | qDebug("error deleting mail"); |
119 | } | 118 | } |
120 | } | 119 | } |
121 | 120 | ||
122 | void MHwrapper::answeredMail(const RecMail&) | 121 | void MHwrapper::answeredMail(const RecMail&) |
123 | { | 122 | { |
124 | } | 123 | } |
125 | 124 | ||
126 | RecBody MHwrapper::fetchBody( const RecMail &mail ) | 125 | RecBody MHwrapper::fetchBody( const RecMail &mail ) |
127 | { | 126 | { |
128 | RecBody body; | 127 | RecBody body; |
129 | init_storage(); | 128 | init_storage(); |
130 | if (!m_storage) { | 129 | if (!m_storage) { |
131 | return body; | 130 | return body; |
132 | } | 131 | } |
133 | mailmessage * msg; | 132 | mailmessage * msg; |
134 | char*data=0; | 133 | char*data=0; |
135 | size_t size; | 134 | size_t size; |
136 | 135 | ||
137 | /* mail should hold the complete path! */ | 136 | /* mail should hold the complete path! */ |
138 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); | 137 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); |
139 | if (r != MAIL_NO_ERROR) { | 138 | if (r != MAIL_NO_ERROR) { |
140 | return body; | 139 | return body; |
141 | } | 140 | } |
142 | r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg); | 141 | r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg); |
143 | if (r != MAIL_NO_ERROR) { | 142 | if (r != MAIL_NO_ERROR) { |
144 | qDebug("Error fetching mail %i",mail.getNumber()); | 143 | qDebug("Error fetching mail %i",mail.getNumber()); |
145 | return body; | 144 | return body; |
146 | } | 145 | } |
147 | body = parseMail(msg); | 146 | body = parseMail(msg); |
148 | mailmessage_fetch_result_free(msg,data); | 147 | mailmessage_fetch_result_free(msg,data); |
149 | return body; | 148 | return body; |
150 | } | 149 | } |
151 | 150 | ||
152 | void MHwrapper::mbox_progress( size_t current, size_t maximum ) | 151 | void MHwrapper::mbox_progress( size_t current, size_t maximum ) |
153 | { | 152 | { |
154 | qDebug("MH %i von %i",current,maximum); | 153 | qDebug("MH %i von %i",current,maximum); |
155 | } | 154 | } |
156 | 155 | ||
157 | QString MHwrapper::buildPath(const QString&p) | 156 | QString MHwrapper::buildPath(const QString&p) |
158 | { | 157 | { |
159 | QString f=""; | 158 | QString f=""; |
160 | if (p.length()==0||p=="/") | 159 | if (p.length()==0||p=="/") |
161 | return MHPath; | 160 | return MHPath; |
162 | if (!p.startsWith(MHPath)) { | 161 | if (!p.startsWith(MHPath)) { |
163 | f+=MHPath; | 162 | f+=MHPath; |
164 | } | 163 | } |
165 | if (!p.startsWith("/")) { | 164 | if (!p.startsWith("/")) { |
166 | f+="/"; | 165 | f+="/"; |
167 | } | 166 | } |
168 | f+=p; | 167 | f+=p; |
169 | return f; | 168 | return f; |
170 | } | 169 | } |
171 | 170 | ||
172 | int MHwrapper::createMbox(const QString&folder,const Folder*pfolder,const QString&,bool ) | 171 | int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool ) |
173 | { | 172 | { |
174 | init_storage(); | 173 | init_storage(); |
175 | if (!m_storage) { | 174 | if (!m_storage) { |
176 | return 0; | 175 | return 0; |
177 | } | 176 | } |
178 | QString f; | 177 | QString f; |
179 | if (!pfolder) { | 178 | if (!pfolder) { |
180 | // toplevel folder | 179 | // toplevel folder |
181 | f = buildPath(folder); | 180 | f = buildPath(folder); |
182 | } else { | 181 | } else { |
183 | f = pfolder->getName(); | 182 | f = pfolder->getName(); |
184 | f+="/"; | 183 | f+="/"; |
185 | f+=folder; | 184 | f+=folder; |
186 | } | 185 | } |
187 | qDebug(f); | 186 | qDebug(f); |
188 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); | 187 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); |
189 | if (r != MAIL_NO_ERROR) { | 188 | if (r != MAIL_NO_ERROR) { |
190 | qDebug("error creating folder %i",r); | 189 | qDebug("error creating folder %i",r); |
191 | return 0; | 190 | return 0; |
192 | } | 191 | } |
193 | qDebug("Folder created"); | 192 | qDebug("Folder created"); |
194 | return 1; | 193 | return 1; |
195 | } | 194 | } |
196 | 195 | ||
197 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) | 196 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) |
198 | { | 197 | { |
199 | init_storage(); | 198 | init_storage(); |
200 | if (!m_storage) { | 199 | if (!m_storage) { |
201 | return; | 200 | return; |
202 | } | 201 | } |
203 | QString f = buildPath(Folder); | 202 | QString f = buildPath(Folder); |
204 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 203 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
205 | if (r!=MAIL_NO_ERROR) { | 204 | if (r!=MAIL_NO_ERROR) { |
206 | qDebug("error selecting folder!"); | 205 | qDebug("error selecting folder!"); |
207 | return; | 206 | return; |
208 | } | 207 | } |
209 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); | 208 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); |
210 | if (r!=MAIL_NO_ERROR) { | 209 | if (r!=MAIL_NO_ERROR) { |
211 | qDebug("error storing mail"); | 210 | qDebug("error storing mail"); |
212 | } | 211 | } |
213 | return; | 212 | return; |
214 | } | 213 | } |
215 | 214 | ||
216 | encodedString* MHwrapper::fetchRawBody(const RecMail&mail) | 215 | encodedString* MHwrapper::fetchRawBody(const RecMail&mail) |
217 | { | 216 | { |
218 | encodedString*result = 0; | 217 | encodedString*result = 0; |
219 | init_storage(); | 218 | init_storage(); |
220 | if (!m_storage) { | 219 | if (!m_storage) { |
221 | return result; | 220 | return result; |
222 | } | 221 | } |
223 | mailmessage * msg = 0; | 222 | mailmessage * msg = 0; |
224 | char*data=0; | 223 | char*data=0; |
225 | size_t size; | 224 | size_t size; |
226 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); | 225 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); |
227 | if (r!=MAIL_NO_ERROR) { | 226 | if (r!=MAIL_NO_ERROR) { |
228 | qDebug("error selecting folder!"); | 227 | qDebug("error selecting folder!"); |
229 | return result; | 228 | return result; |
230 | } | 229 | } |
231 | r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg); | 230 | r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg); |
232 | if (r != MAIL_NO_ERROR) { | 231 | if (r != MAIL_NO_ERROR) { |
233 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); | 232 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); |
234 | return 0; | 233 | return 0; |
235 | } | 234 | } |
236 | r = mailmessage_fetch(msg,&data,&size); | 235 | r = mailmessage_fetch(msg,&data,&size); |
237 | if (r != MAIL_NO_ERROR) { | 236 | if (r != MAIL_NO_ERROR) { |
238 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); | 237 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); |
239 | if (msg) mailmessage_free(msg); | 238 | if (msg) mailmessage_free(msg); |
240 | return 0; | 239 | return 0; |
241 | } | 240 | } |
242 | result = new encodedString(data,size); | 241 | result = new encodedString(data,size); |
243 | if (msg) mailmessage_free(msg); | 242 | if (msg) mailmessage_free(msg); |
244 | return result; | 243 | return result; |
245 | } | 244 | } |
246 | 245 | ||
247 | void MHwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) | 246 | void MHwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) |
248 | { | 247 | { |
249 | QString f = buildPath(mailbox); | 248 | QString f = buildPath(mailbox); |
250 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 249 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
251 | if (r!=MAIL_NO_ERROR) { | 250 | if (r!=MAIL_NO_ERROR) { |
252 | qDebug("deleteMails: error selecting folder!"); | 251 | qDebug("deleteMails: error selecting folder!"); |
253 | return; | 252 | return; |
254 | } | 253 | } |
255 | RecMail*c = 0; | 254 | RecMail*c = 0; |
256 | for (unsigned int i=0; i < target.count();++i) { | 255 | for (unsigned int i=0; i < target.count();++i) { |
257 | c = target.at(i); | 256 | c = target.at(i); |
258 | r = mailsession_remove_message(m_storage->sto_session,c->getNumber()); | 257 | r = mailsession_remove_message(m_storage->sto_session,c->getNumber()); |
259 | if (r != MAIL_NO_ERROR) { | 258 | if (r != MAIL_NO_ERROR) { |
260 | qDebug("error deleting mail"); | 259 | qDebug("error deleting mail"); |
261 | break; | 260 | break; |
262 | } | 261 | } |
263 | } | 262 | } |
264 | } | 263 | } |
265 | 264 | ||
266 | int MHwrapper::deleteAllMail(const Folder*tfolder) | 265 | int MHwrapper::deleteAllMail(const FolderP&tfolder) |
267 | { | 266 | { |
268 | init_storage(); | 267 | init_storage(); |
269 | if (!m_storage) { | 268 | if (!m_storage) { |
270 | return 0; | 269 | return 0; |
271 | } | 270 | } |
272 | int res = 1; | 271 | int res = 1; |
273 | if (!tfolder) return 0; | 272 | if (!tfolder) return 0; |
274 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | 273 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); |
275 | if (r!=MAIL_NO_ERROR) { | 274 | if (r!=MAIL_NO_ERROR) { |
276 | qDebug("error selecting folder!"); | 275 | qDebug("error selecting folder!"); |
277 | return 0; | 276 | return 0; |
278 | } | 277 | } |
279 | mailmessage_list*l=0; | 278 | mailmessage_list*l=0; |
280 | r = mailsession_get_messages_list(m_storage->sto_session,&l); | 279 | r = mailsession_get_messages_list(m_storage->sto_session,&l); |
281 | if (r != MAIL_NO_ERROR) { | 280 | if (r != MAIL_NO_ERROR) { |
282 | qDebug("Error message list"); | 281 | qDebug("Error message list"); |
283 | res = 0; | 282 | res = 0; |
284 | } | 283 | } |
285 | unsigned j = 0; | 284 | unsigned j = 0; |
286 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | 285 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { |
287 | mailmessage * msg; | 286 | mailmessage * msg; |
288 | msg = (mailmessage*)carray_get(l->msg_tab, i); | 287 | msg = (mailmessage*)carray_get(l->msg_tab, i); |
289 | j = msg->msg_index; | 288 | j = msg->msg_index; |
290 | r = mailsession_remove_message(m_storage->sto_session,j); | 289 | r = mailsession_remove_message(m_storage->sto_session,j); |
291 | if (r != MAIL_NO_ERROR) { | 290 | if (r != MAIL_NO_ERROR) { |
292 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 291 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
293 | res = 0; | 292 | res = 0; |
294 | break; | 293 | break; |
295 | } | 294 | } |
296 | } | 295 | } |
297 | if (l) mailmessage_list_free(l); | 296 | if (l) mailmessage_list_free(l); |
298 | return res; | 297 | return res; |
299 | } | 298 | } |
300 | 299 | ||
301 | int MHwrapper::deleteMbox(const Folder*tfolder) | 300 | int MHwrapper::deleteMbox(const FolderP&tfolder) |
302 | { | 301 | { |
303 | init_storage(); | 302 | init_storage(); |
304 | if (!m_storage) { | 303 | if (!m_storage) { |
305 | return 0; | 304 | return 0; |
306 | } | 305 | } |
307 | if (!tfolder) return 0; | 306 | if (!tfolder) return 0; |
308 | if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; | 307 | if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; |
309 | 308 | ||
310 | int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | 309 | int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); |
311 | 310 | ||
312 | if (r != MAIL_NO_ERROR) { | 311 | if (r != MAIL_NO_ERROR) { |
313 | qDebug("error deleting mail box"); | 312 | qDebug("error deleting mail box"); |
314 | return 0; | 313 | return 0; |
315 | } | 314 | } |
316 | QString cmd = "rm -rf "+tfolder->getName(); | 315 | QString cmd = "rm -rf "+tfolder->getName(); |
317 | QStringList command; | 316 | QStringList command; |
318 | command << "/bin/sh"; | 317 | command << "/bin/sh"; |
319 | command << "-c"; | 318 | command << "-c"; |
320 | command << cmd.latin1(); | 319 | command << cmd.latin1(); |
321 | OProcess *process = new OProcess(); | 320 | OProcess *process = new OProcess(); |
322 | 321 | ||
323 | connect(process, SIGNAL(processExited(OProcess*)), | 322 | connect(process, SIGNAL(processExited(OProcess*)), |
324 | this, SLOT( processEnded(OProcess*))); | 323 | this, SLOT( processEnded(OProcess*))); |
325 | connect(process, SIGNAL( receivedStderr(OProcess*,char*,int)), | 324 | connect(process, SIGNAL( receivedStderr(OProcess*,char*,int)), |
326 | this, SLOT( oprocessStderr(OProcess*,char*,int))); | 325 | this, SLOT( oprocessStderr(OProcess*,char*,int))); |
327 | 326 | ||
328 | *process << command; | 327 | *process << command; |
329 | removeMboxfailed = false; | 328 | removeMboxfailed = false; |
330 | if(!process->start(OProcess::Block, OProcess::All) ) { | 329 | if(!process->start(OProcess::Block, OProcess::All) ) { |
331 | qDebug("could not start process"); | 330 | qDebug("could not start process"); |
332 | return 0; | 331 | return 0; |
333 | } | 332 | } |
334 | qDebug("mail box deleted"); | 333 | qDebug("mail box deleted"); |
335 | return 1; | 334 | return 1; |
336 | } | 335 | } |
337 | 336 | ||
338 | void MHwrapper::processEnded(OProcess *p) | 337 | void MHwrapper::processEnded(OProcess *p) |
339 | { | 338 | { |
340 | if (p) delete p; | 339 | if (p) delete p; |
341 | } | 340 | } |
342 | 341 | ||
343 | void MHwrapper::oprocessStderr(OProcess*, char *buffer, int ) | 342 | void MHwrapper::oprocessStderr(OProcess*, char *buffer, int ) |
344 | { | 343 | { |
345 | QString lineStr = buffer; | 344 | QString lineStr = buffer; |
346 | QMessageBox::warning( 0, tr("Error"), lineStr ,tr("Ok") ); | 345 | QMessageBox::warning( 0, tr("Error"), lineStr ,tr("Ok") ); |
347 | removeMboxfailed = true; | 346 | removeMboxfailed = true; |
348 | } | 347 | } |
349 | 348 | ||
350 | void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | 349 | void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) |
351 | { | 350 | { |
352 | init_storage(); | 351 | init_storage(); |
353 | if (!m_storage) { | 352 | if (!m_storage) { |
354 | return; | 353 | return; |
355 | } | 354 | } |
356 | target_stat.message_count = 0; | 355 | target_stat.message_count = 0; |
357 | target_stat.message_unseen = 0; | 356 | target_stat.message_unseen = 0; |
358 | target_stat.message_recent = 0; | 357 | target_stat.message_recent = 0; |
359 | QString f = buildPath(mailbox); | 358 | QString f = buildPath(mailbox); |
360 | int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, | 359 | int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, |
361 | &target_stat.message_recent,&target_stat.message_unseen); | 360 | &target_stat.message_recent,&target_stat.message_unseen); |
362 | if (r != MAIL_NO_ERROR) { | 361 | if (r != MAIL_NO_ERROR) { |
363 | Global::statusMessage(tr("Error retrieving status")); | 362 | Global::statusMessage(tr("Error retrieving status")); |
364 | } | 363 | } |
365 | } | 364 | } |
366 | 365 | ||
367 | MAILLIB::ATYPE MHwrapper::getType()const | 366 | MAILLIB::ATYPE MHwrapper::getType()const |
368 | { | 367 | { |
369 | return MAILLIB::A_MH; | 368 | return MAILLIB::A_MH; |
370 | } | 369 | } |
371 | 370 | ||
372 | const QString&MHwrapper::getName()const | 371 | const QString&MHwrapper::getName()const |
373 | { | 372 | { |
374 | return MHName; | 373 | return MHName; |
375 | } | 374 | } |
376 | void MHwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 375 | void MHwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
377 | { | 376 | { |
378 | init_storage(); | 377 | init_storage(); |
379 | if (!m_storage) { | 378 | if (!m_storage) { |
380 | return; | 379 | return; |
381 | } | 380 | } |
382 | if (targetWrapper != this) { | 381 | if (targetWrapper != this) { |
383 | qDebug("Using generic"); | 382 | qDebug("Using generic"); |
384 | Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); | 383 | Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); |
385 | return; | 384 | return; |
386 | } | 385 | } |
387 | qDebug("Using internal routines for move/copy"); | 386 | qDebug("Using internal routines for move/copy"); |
388 | QString tf = buildPath(targetFolder); | 387 | QString tf = buildPath(targetFolder); |
389 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); | 388 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); |
390 | if (r != MAIL_NO_ERROR) { | 389 | if (r != MAIL_NO_ERROR) { |
391 | qDebug("Error selecting source mailbox"); | 390 | qDebug("Error selecting source mailbox"); |
392 | return; | 391 | return; |
393 | } | 392 | } |
394 | if (moveit) { | 393 | if (moveit) { |
395 | r = mailsession_move_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1()); | 394 | r = mailsession_move_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1()); |
396 | } else { | 395 | } else { |
397 | r = mailsession_copy_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1()); | 396 | r = mailsession_copy_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1()); |
398 | } | 397 | } |
399 | if (r != MAIL_NO_ERROR) { | 398 | if (r != MAIL_NO_ERROR) { |
400 | qDebug("Error copy/moving mail internal (%i)",r); | 399 | qDebug("Error copy/moving mail internal (%i)",r); |
401 | } | 400 | } |
402 | } | 401 | } |
403 | 402 | ||
404 | void MHwrapper::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 403 | void MHwrapper::mvcpAllMails(const FolderP&fromFolder, |
404 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | ||
405 | { | 405 | { |
406 | init_storage(); | 406 | init_storage(); |
407 | if (!m_storage) { | 407 | if (!m_storage) { |
408 | return; | 408 | return; |
409 | } | 409 | } |
410 | if (targetWrapper != this) { | 410 | if (targetWrapper != this) { |
411 | qDebug("Using generic"); | 411 | qDebug("Using generic"); |
412 | Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); | 412 | Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); |
413 | return; | 413 | return; |
414 | } | 414 | } |
415 | if (!fromFolder) return; | 415 | if (!fromFolder) return; |
416 | int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1()); | 416 | int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1()); |
417 | if (r!=MAIL_NO_ERROR) { | 417 | if (r!=MAIL_NO_ERROR) { |
418 | qDebug("error selecting source folder!"); | 418 | qDebug("error selecting source folder!"); |
419 | return; | 419 | return; |
420 | } | 420 | } |
421 | QString tf = buildPath(targetFolder); | 421 | QString tf = buildPath(targetFolder); |
422 | mailmessage_list*l=0; | 422 | mailmessage_list*l=0; |
423 | r = mailsession_get_messages_list(m_storage->sto_session,&l); | 423 | r = mailsession_get_messages_list(m_storage->sto_session,&l); |
424 | if (r != MAIL_NO_ERROR) { | 424 | if (r != MAIL_NO_ERROR) { |
425 | qDebug("Error message list"); | 425 | qDebug("Error message list"); |
426 | } | 426 | } |
427 | unsigned j = 0; | 427 | unsigned j = 0; |
428 | for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) { | 428 | for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) { |
429 | mailmessage * msg; | 429 | mailmessage * msg; |
430 | msg = (mailmessage*)carray_get(l->msg_tab, i); | 430 | msg = (mailmessage*)carray_get(l->msg_tab, i); |
431 | j = msg->msg_index; | 431 | j = msg->msg_index; |
432 | if (moveit) { | 432 | if (moveit) { |
433 | r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1()); | 433 | r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1()); |
434 | } else { | 434 | } else { |
435 | r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1()); | 435 | r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1()); |
436 | } | 436 | } |
437 | if (r != MAIL_NO_ERROR) { | 437 | if (r != MAIL_NO_ERROR) { |
438 | qDebug("Error copy/moving mail internal (%i)",r); | 438 | qDebug("Error copy/moving mail internal (%i)",r); |
439 | break; | 439 | break; |
440 | } | 440 | } |
441 | } | 441 | } |
442 | if (l) mailmessage_list_free(l); | 442 | if (l) mailmessage_list_free(l); |
443 | } | 443 | } |
diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.h b/noncore/net/mail/libmailwrapper/mhwrapper.h index b7c23af..c7c8183 100644 --- a/noncore/net/mail/libmailwrapper/mhwrapper.h +++ b/noncore/net/mail/libmailwrapper/mhwrapper.h | |||
@@ -1,60 +1,62 @@ | |||
1 | #ifndef __MH_WRAPPER_H | 1 | #ifndef __MH_WRAPPER_H |
2 | #define __MH_WRAPPER_H | 2 | #define __MH_WRAPPER_H |
3 | 3 | ||
4 | #include "maildefines.h" | 4 | #include "maildefines.h" |
5 | 5 | ||
6 | #include "genericwrapper.h" | 6 | #include "genericwrapper.h" |
7 | #include <qstring.h> | 7 | #include <qstring.h> |
8 | 8 | ||
9 | class RecMail; | 9 | class RecMail; |
10 | class RecBody; | 10 | class RecBody; |
11 | class encodedString; | 11 | class encodedString; |
12 | struct mailmbox_folder; | 12 | struct mailmbox_folder; |
13 | class OProcess; | 13 | class OProcess; |
14 | 14 | ||
15 | class MHwrapper : public Genericwrapper | 15 | class MHwrapper : public Genericwrapper |
16 | { | 16 | { |
17 | Q_OBJECT | 17 | Q_OBJECT |
18 | public: | 18 | public: |
19 | MHwrapper(const QString & dir,const QString&name); | 19 | MHwrapper(const QString & dir,const QString&name); |
20 | virtual ~MHwrapper(); | 20 | virtual ~MHwrapper(); |
21 | 21 | ||
22 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 22 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
23 | virtual QList<Folder>* listFolders(); | 23 | virtual QValueList<Opie::osmart_pointer<Folder> >* listFolders(); |
24 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | 24 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); |
25 | 25 | ||
26 | virtual void deleteMail(const RecMail&mail); | 26 | virtual void deleteMail(const RecMail&mail); |
27 | virtual void answeredMail(const RecMail&mail); | 27 | virtual void answeredMail(const RecMail&mail); |
28 | virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | 28 | virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); |
29 | virtual void mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | 29 | virtual void mvcpAllMails(const Opie::osmart_pointer<Folder>&fromFolder, |
30 | 30 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | |
31 | virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false); | 31 | |
32 | virtual int deleteMbox(const Folder*); | 32 | virtual int createMbox(const QString&folder,const Opie::osmart_pointer<Folder>&f=0, |
33 | const QString&d="",bool s=false); | ||
34 | virtual int deleteMbox(const Opie::osmart_pointer<Folder>&); | ||
33 | 35 | ||
34 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); | 36 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); |
35 | 37 | ||
36 | virtual RecBody fetchBody( const RecMail &mail ); | 38 | virtual RecBody fetchBody( const RecMail &mail ); |
37 | static void mbox_progress( size_t current, size_t maximum ); | 39 | static void mbox_progress( size_t current, size_t maximum ); |
38 | 40 | ||
39 | virtual encodedString* fetchRawBody(const RecMail&mail); | 41 | virtual encodedString* fetchRawBody(const RecMail&mail); |
40 | virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); | 42 | virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); |
41 | virtual int deleteAllMail(const Folder*); | 43 | virtual int deleteAllMail(const Opie::osmart_pointer<Folder>&); |
42 | virtual MAILLIB::ATYPE getType()const; | 44 | virtual MAILLIB::ATYPE getType()const; |
43 | virtual const QString&getName()const; | 45 | virtual const QString&getName()const; |
44 | 46 | ||
45 | public slots: | 47 | public slots: |
46 | /* for deleting maildirs we are using a system call */ | 48 | /* for deleting maildirs we are using a system call */ |
47 | virtual void oprocessStderr(OProcess*, char *buffer, int ); | 49 | virtual void oprocessStderr(OProcess*, char *buffer, int ); |
48 | virtual void processEnded(OProcess *); | 50 | virtual void processEnded(OProcess *); |
49 | protected: | 51 | protected: |
50 | QString buildPath(const QString&p); | 52 | QString buildPath(const QString&p); |
51 | QString MHPath; | 53 | QString MHPath; |
52 | QString MHName; | 54 | QString MHName; |
53 | 55 | ||
54 | void init_storage(); | 56 | void init_storage(); |
55 | void clean_storage(); | 57 | void clean_storage(); |
56 | 58 | ||
57 | bool removeMboxfailed; | 59 | bool removeMboxfailed; |
58 | }; | 60 | }; |
59 | 61 | ||
60 | #endif | 62 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/nntpwrapper.cpp b/noncore/net/mail/libmailwrapper/nntpwrapper.cpp index 1956c61..2ec052c 100644 --- a/noncore/net/mail/libmailwrapper/nntpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/nntpwrapper.cpp | |||
@@ -1,284 +1,283 @@ | |||
1 | #include "nntpwrapper.h" | 1 | #include "nntpwrapper.h" |
2 | #include "logindialog.h" | 2 | #include "logindialog.h" |
3 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
4 | 4 | ||
5 | #include <qfile.h> | 5 | #include <qfile.h> |
6 | 6 | ||
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | 8 | ||
9 | #include <libetpan/libetpan.h> | 9 | #include <libetpan/libetpan.h> |
10 | 10 | ||
11 | 11 | ||
12 | #define HARD_MSG_SIZE_LIMIT 5242880 | 12 | #define HARD_MSG_SIZE_LIMIT 5242880 |
13 | 13 | ||
14 | NNTPwrapper::NNTPwrapper( NNTPaccount *a ) | 14 | NNTPwrapper::NNTPwrapper( NNTPaccount *a ) |
15 | : Genericwrapper() { | 15 | : Genericwrapper() { |
16 | account = a; | 16 | account = a; |
17 | m_nntp = NULL; | 17 | m_nntp = NULL; |
18 | msgTempName = a->getFileName()+"_msg_cache"; | 18 | msgTempName = a->getFileName()+"_msg_cache"; |
19 | last_msg_id = 0; | 19 | last_msg_id = 0; |
20 | } | 20 | } |
21 | 21 | ||
22 | NNTPwrapper::~NNTPwrapper() { | 22 | NNTPwrapper::~NNTPwrapper() { |
23 | logout(); | 23 | logout(); |
24 | QFile msg_cache(msgTempName); | 24 | QFile msg_cache(msgTempName); |
25 | if (msg_cache.exists()) { | 25 | if (msg_cache.exists()) { |
26 | msg_cache.remove(); | 26 | msg_cache.remove(); |
27 | } | 27 | } |
28 | } | 28 | } |
29 | 29 | ||
30 | void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) { | 30 | void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) { |
31 | qDebug( "NNTP: %i of %i", current, maximum ); | 31 | qDebug( "NNTP: %i of %i", current, maximum ); |
32 | } | 32 | } |
33 | 33 | ||
34 | 34 | ||
35 | RecBody NNTPwrapper::fetchBody( const RecMail &mail ) { | 35 | RecBody NNTPwrapper::fetchBody( const RecMail &mail ) { |
36 | int err = NEWSNNTP_NO_ERROR; | 36 | int err = NEWSNNTP_NO_ERROR; |
37 | char *message = 0; | 37 | char *message = 0; |
38 | size_t length = 0; | 38 | size_t length = 0; |
39 | 39 | ||
40 | login(); | 40 | login(); |
41 | if ( !m_nntp ) { | 41 | if ( !m_nntp ) { |
42 | return RecBody(); | 42 | return RecBody(); |
43 | } | 43 | } |
44 | 44 | ||
45 | RecBody body; | 45 | RecBody body; |
46 | mailmessage * mailmsg; | 46 | mailmessage * mailmsg; |
47 | if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { | 47 | if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { |
48 | qDebug("Message to large: %i",mail.Msgsize()); | 48 | qDebug("Message to large: %i",mail.Msgsize()); |
49 | return body; | 49 | return body; |
50 | } | 50 | } |
51 | 51 | ||
52 | QFile msg_cache(msgTempName); | 52 | QFile msg_cache(msgTempName); |
53 | 53 | ||
54 | cleanMimeCache(); | 54 | cleanMimeCache(); |
55 | 55 | ||
56 | if (mail.getNumber()!=last_msg_id) { | 56 | if (mail.getNumber()!=last_msg_id) { |
57 | if (msg_cache.exists()) { | 57 | if (msg_cache.exists()) { |
58 | msg_cache.remove(); | 58 | msg_cache.remove(); |
59 | } | 59 | } |
60 | msg_cache.open(IO_ReadWrite|IO_Truncate); | 60 | msg_cache.open(IO_ReadWrite|IO_Truncate); |
61 | last_msg_id = mail.getNumber(); | 61 | last_msg_id = mail.getNumber(); |
62 | err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg); | 62 | err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg); |
63 | err = mailmessage_fetch(mailmsg,&message,&length); | 63 | err = mailmessage_fetch(mailmsg,&message,&length); |
64 | msg_cache.writeBlock(message,length); | 64 | msg_cache.writeBlock(message,length); |
65 | } else { | 65 | } else { |
66 | QString msg=""; | 66 | QString msg=""; |
67 | msg_cache.open(IO_ReadOnly); | 67 | msg_cache.open(IO_ReadOnly); |
68 | message = new char[4096]; | 68 | message = new char[4096]; |
69 | memset(message,0,4096); | 69 | memset(message,0,4096); |
70 | while (msg_cache.readBlock(message,4095)>0) { | 70 | while (msg_cache.readBlock(message,4095)>0) { |
71 | msg+=message; | 71 | msg+=message; |
72 | memset(message,0,4096); | 72 | memset(message,0,4096); |
73 | } | 73 | } |
74 | delete message; | 74 | delete message; |
75 | message = (char*)malloc(msg.length()+1*sizeof(char)); | 75 | message = (char*)malloc(msg.length()+1*sizeof(char)); |
76 | memset(message,0,msg.length()+1); | 76 | memset(message,0,msg.length()+1); |
77 | memcpy(message,msg.latin1(),msg.length()); | 77 | memcpy(message,msg.latin1(),msg.length()); |
78 | /* transform to libetpan stuff */ | 78 | /* transform to libetpan stuff */ |
79 | mailmsg = mailmessage_new(); | 79 | mailmsg = mailmessage_new(); |
80 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); | 80 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); |
81 | generic_message_t * msg_data; | 81 | generic_message_t * msg_data; |
82 | msg_data = (generic_message_t *)mailmsg->msg_data; | 82 | msg_data = (generic_message_t *)mailmsg->msg_data; |
83 | msg_data->msg_fetched = 1; | 83 | msg_data->msg_fetched = 1; |
84 | msg_data->msg_message = message; | 84 | msg_data->msg_message = message; |
85 | msg_data->msg_length = strlen(message); | 85 | msg_data->msg_length = strlen(message); |
86 | } | 86 | } |
87 | body = parseMail(mailmsg); | 87 | body = parseMail(mailmsg); |
88 | 88 | ||
89 | /* clean up */ | 89 | /* clean up */ |
90 | if (mailmsg) | 90 | if (mailmsg) |
91 | mailmessage_free(mailmsg); | 91 | mailmessage_free(mailmsg); |
92 | if (message) | 92 | if (message) |
93 | free(message); | 93 | free(message); |
94 | 94 | ||
95 | return body; | 95 | return body; |
96 | } | 96 | } |
97 | 97 | ||
98 | 98 | ||
99 | void NNTPwrapper::listMessages(const QString & which, QList<RecMail> &target ) | 99 | void NNTPwrapper::listMessages(const QString & which, QList<RecMail> &target ) |
100 | { | 100 | { |
101 | login(); | 101 | login(); |
102 | if (!m_nntp) | 102 | if (!m_nntp) |
103 | return; | 103 | return; |
104 | uint32_t res_messages,res_recent,res_unseen; | 104 | uint32_t res_messages,res_recent,res_unseen; |
105 | mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen); | 105 | mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen); |
106 | parseList(target,m_nntp->sto_session,which,true); | 106 | parseList(target,m_nntp->sto_session,which,true); |
107 | } | 107 | } |
108 | 108 | ||
109 | void NNTPwrapper::login() | 109 | void NNTPwrapper::login() |
110 | { | 110 | { |
111 | if (account->getOffline()) | 111 | if (account->getOffline()) |
112 | return; | 112 | return; |
113 | /* we'll hold the line */ | 113 | /* we'll hold the line */ |
114 | if ( m_nntp != NULL ) | 114 | if ( m_nntp != NULL ) |
115 | return; | 115 | return; |
116 | 116 | ||
117 | const char *server, *user, *pass; | 117 | const char *server, *user, *pass; |
118 | QString User,Pass; | 118 | QString User,Pass; |
119 | uint16_t port; | 119 | uint16_t port; |
120 | int err = NEWSNNTP_NO_ERROR; | 120 | int err = NEWSNNTP_NO_ERROR; |
121 | 121 | ||
122 | server = account->getServer().latin1(); | 122 | server = account->getServer().latin1(); |
123 | port = account->getPort().toUInt(); | 123 | port = account->getPort().toUInt(); |
124 | 124 | ||
125 | user = pass = 0; | 125 | user = pass = 0; |
126 | 126 | ||
127 | if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) { | 127 | if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) { |
128 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 128 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
129 | login.show(); | 129 | login.show(); |
130 | if ( QDialog::Accepted == login.exec() ) { | 130 | if ( QDialog::Accepted == login.exec() ) { |
131 | // ok | 131 | // ok |
132 | User = login.getUser().latin1(); | 132 | User = login.getUser().latin1(); |
133 | Pass = login.getPassword().latin1(); | 133 | Pass = login.getPassword().latin1(); |
134 | } else { | 134 | } else { |
135 | // cancel | 135 | // cancel |
136 | qDebug( "NNTP: Login canceled" ); | 136 | qDebug( "NNTP: Login canceled" ); |
137 | return; | 137 | return; |
138 | } | 138 | } |
139 | } else { | 139 | } else { |
140 | User = account->getUser().latin1(); | 140 | User = account->getUser().latin1(); |
141 | Pass = account->getPassword().latin1(); | 141 | Pass = account->getPassword().latin1(); |
142 | } | 142 | } |
143 | 143 | ||
144 | if (User.isEmpty()) { | 144 | if (User.isEmpty()) { |
145 | user=0; | 145 | user=0; |
146 | pass = 0; | 146 | pass = 0; |
147 | } else { | 147 | } else { |
148 | user=User.latin1(); | 148 | user=User.latin1(); |
149 | pass=Pass.latin1(); | 149 | pass=Pass.latin1(); |
150 | } | 150 | } |
151 | // bool ssl = account->getSSL(); | 151 | // bool ssl = account->getSSL(); |
152 | 152 | ||
153 | m_nntp=mailstorage_new(NULL); | 153 | m_nntp=mailstorage_new(NULL); |
154 | 154 | ||
155 | int conntypeset = account->ConnectionType(); | 155 | int conntypeset = account->ConnectionType(); |
156 | int conntype = 0; | 156 | int conntype = 0; |
157 | if ( conntypeset == 3 ) { | 157 | if ( conntypeset == 3 ) { |
158 | conntype = CONNECTION_TYPE_COMMAND; | 158 | conntype = CONNECTION_TYPE_COMMAND; |
159 | } else if ( conntypeset == 2 ) { | 159 | } else if ( conntypeset == 2 ) { |
160 | conntype = CONNECTION_TYPE_TLS; | 160 | conntype = CONNECTION_TYPE_TLS; |
161 | } else if ( conntypeset == 1 ) { | 161 | } else if ( conntypeset == 1 ) { |
162 | conntype = CONNECTION_TYPE_STARTTLS; | 162 | conntype = CONNECTION_TYPE_STARTTLS; |
163 | } else if ( conntypeset == 0 ) { | 163 | } else if ( conntypeset == 0 ) { |
164 | conntype = CONNECTION_TYPE_TRY_STARTTLS; | 164 | conntype = CONNECTION_TYPE_TRY_STARTTLS; |
165 | } | 165 | } |
166 | 166 | ||
167 | nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN, | 167 | nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN, |
168 | (char*)user,(char*)pass,0,0,0); | 168 | (char*)user,(char*)pass,0,0,0); |
169 | 169 | ||
170 | err = mailstorage_connect( m_nntp ); | 170 | err = mailstorage_connect( m_nntp ); |
171 | 171 | ||
172 | if (err != NEWSNNTP_NO_ERROR) { | 172 | if (err != NEWSNNTP_NO_ERROR) { |
173 | qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) ); | 173 | qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) ); |
174 | // Global::statusMessage(tr("Error initializing folder")); | 174 | // Global::statusMessage(tr("Error initializing folder")); |
175 | mailstorage_free(m_nntp); | 175 | mailstorage_free(m_nntp); |
176 | m_nntp = 0; | 176 | m_nntp = 0; |
177 | 177 | ||
178 | } | 178 | } |
179 | 179 | ||
180 | } | 180 | } |
181 | 181 | ||
182 | void NNTPwrapper::logout() | 182 | void NNTPwrapper::logout() |
183 | { | 183 | { |
184 | int err = NEWSNNTP_NO_ERROR; | 184 | int err = NEWSNNTP_NO_ERROR; |
185 | if ( m_nntp == NULL ) | 185 | if ( m_nntp == NULL ) |
186 | return; | 186 | return; |
187 | mailstorage_free(m_nntp); | 187 | mailstorage_free(m_nntp); |
188 | m_nntp = 0; | 188 | m_nntp = 0; |
189 | } | 189 | } |
190 | 190 | ||
191 | QList<Folder>* NNTPwrapper::listFolders() { | 191 | QValueList<Opie::osmart_pointer<Folder> >* NNTPwrapper::listFolders() { |
192 | 192 | ||
193 | QList<Folder> * folders = new QList<Folder>(); | 193 | QValueList<Opie::osmart_pointer<Folder> >* folders = new QValueList<Opie::osmart_pointer<Folder> >(); |
194 | folders->setAutoDelete( false ); | ||
195 | QStringList groups; | 194 | QStringList groups; |
196 | if (account) { | 195 | if (account) { |
197 | groups = account->getGroups(); | 196 | groups = account->getGroups(); |
198 | } | 197 | } |
199 | for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) { | 198 | for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) { |
200 | folders->append(new Folder((*it),".")); | 199 | folders->append(new Folder((*it),".")); |
201 | } | 200 | } |
202 | return folders; | 201 | return folders; |
203 | } | 202 | } |
204 | 203 | ||
205 | /* we made this method in raw nntp access of etpan and not via generic interface | 204 | /* we made this method in raw nntp access of etpan and not via generic interface |
206 | * 'cause in that case there will be doubled copy operations. eg. the etpan would | 205 | * 'cause in that case there will be doubled copy operations. eg. the etpan would |
207 | * copy that stuff into its own structures and we must copy it into useable c++ | 206 | * copy that stuff into its own structures and we must copy it into useable c++ |
208 | * structures for our frontend. this would not make sense, so it is better to reimplement | 207 | * structures for our frontend. this would not make sense, so it is better to reimplement |
209 | * the stuff from generic interface of etpan but copy it direct to qt classes. | 208 | * the stuff from generic interface of etpan but copy it direct to qt classes. |
210 | */ | 209 | */ |
211 | QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) { | 210 | QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) { |
212 | login(); | 211 | login(); |
213 | QStringList res; | 212 | QStringList res; |
214 | clist *result = 0; | 213 | clist *result = 0; |
215 | clistcell *current = 0; | 214 | clistcell *current = 0; |
216 | newsnntp_group_description *group; | 215 | newsnntp_group_description *group; |
217 | 216 | ||
218 | if ( m_nntp ) { | 217 | if ( m_nntp ) { |
219 | mailsession * session = m_nntp->sto_session; | 218 | mailsession * session = m_nntp->sto_session; |
220 | newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; | 219 | newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; |
221 | int err = NEWSNNTP_NO_ERROR; | 220 | int err = NEWSNNTP_NO_ERROR; |
222 | if (mask.isEmpty()) { | 221 | if (mask.isEmpty()) { |
223 | err = newsnntp_list(news, &result); | 222 | err = newsnntp_list(news, &result); |
224 | } else { | 223 | } else { |
225 | /* taken from generic wrapper of etpan */ | 224 | /* taken from generic wrapper of etpan */ |
226 | QString nmask = mask+".*"; | 225 | QString nmask = mask+".*"; |
227 | err = newsnntp_list_active(news, nmask.latin1(), &result); | 226 | err = newsnntp_list_active(news, nmask.latin1(), &result); |
228 | } | 227 | } |
229 | if ( err == NEWSNNTP_NO_ERROR && result) { | 228 | if ( err == NEWSNNTP_NO_ERROR && result) { |
230 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current) ) { | 229 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current) ) { |
231 | group = ( newsnntp_group_description* ) current->data; | 230 | group = ( newsnntp_group_description* ) current->data; |
232 | if (!group||!group->grp_name||strlen(group->grp_name)==0) continue; | 231 | if (!group||!group->grp_name||strlen(group->grp_name)==0) continue; |
233 | res.append(group->grp_name); | 232 | res.append(group->grp_name); |
234 | } | 233 | } |
235 | } | 234 | } |
236 | } | 235 | } |
237 | if (result) { | 236 | if (result) { |
238 | newsnntp_list_free(result); | 237 | newsnntp_list_free(result); |
239 | } | 238 | } |
240 | return res; | 239 | return res; |
241 | } | 240 | } |
242 | 241 | ||
243 | void NNTPwrapper::answeredMail(const RecMail&) {} | 242 | void NNTPwrapper::answeredMail(const RecMail&) {} |
244 | 243 | ||
245 | void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) { | 244 | void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) { |
246 | login(); | 245 | login(); |
247 | target_stat.message_count = 0; | 246 | target_stat.message_count = 0; |
248 | target_stat.message_unseen = 0; | 247 | target_stat.message_unseen = 0; |
249 | target_stat.message_recent = 0; | 248 | target_stat.message_recent = 0; |
250 | if (!m_nntp) | 249 | if (!m_nntp) |
251 | return; | 250 | return; |
252 | int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count, | 251 | int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count, |
253 | &target_stat.message_recent,&target_stat.message_unseen); | 252 | &target_stat.message_recent,&target_stat.message_unseen); |
254 | } | 253 | } |
255 | 254 | ||
256 | 255 | ||
257 | encodedString* NNTPwrapper::fetchRawBody(const RecMail&mail) { | 256 | encodedString* NNTPwrapper::fetchRawBody(const RecMail&mail) { |
258 | char*target=0; | 257 | char*target=0; |
259 | size_t length=0; | 258 | size_t length=0; |
260 | encodedString*res = 0; | 259 | encodedString*res = 0; |
261 | mailmessage * mailmsg = 0; | 260 | mailmessage * mailmsg = 0; |
262 | int err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg); | 261 | int err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg); |
263 | err = mailmessage_fetch(mailmsg,&target,&length); | 262 | err = mailmessage_fetch(mailmsg,&target,&length); |
264 | if (mailmsg) | 263 | if (mailmsg) |
265 | mailmessage_free(mailmsg); | 264 | mailmessage_free(mailmsg); |
266 | if (target) { | 265 | if (target) { |
267 | res = new encodedString(target,length); | 266 | res = new encodedString(target,length); |
268 | } | 267 | } |
269 | return res; | 268 | return res; |
270 | } | 269 | } |
271 | 270 | ||
272 | MAILLIB::ATYPE NNTPwrapper::getType()const { | 271 | MAILLIB::ATYPE NNTPwrapper::getType()const { |
273 | return account->getType(); | 272 | return account->getType(); |
274 | } | 273 | } |
275 | 274 | ||
276 | const QString&NNTPwrapper::getName()const{ | 275 | const QString&NNTPwrapper::getName()const{ |
277 | return account->getAccountName(); | 276 | return account->getAccountName(); |
278 | } | 277 | } |
279 | 278 | ||
280 | void NNTPwrapper::deleteMail(const RecMail&) { | 279 | void NNTPwrapper::deleteMail(const RecMail&) { |
281 | } | 280 | } |
282 | 281 | ||
283 | int NNTPwrapper::deleteAllMail(const Folder*) { | 282 | int NNTPwrapper::deleteAllMail(const FolderP&) { |
284 | } | 283 | } |
diff --git a/noncore/net/mail/libmailwrapper/nntpwrapper.h b/noncore/net/mail/libmailwrapper/nntpwrapper.h index 955b9f1..d3a384a 100644 --- a/noncore/net/mail/libmailwrapper/nntpwrapper.h +++ b/noncore/net/mail/libmailwrapper/nntpwrapper.h | |||
@@ -1,48 +1,48 @@ | |||
1 | #ifndef __NNTPWRAPPER | 1 | #ifndef __NNTPWRAPPER |
2 | #define __NNTPWRAPPER | 2 | #define __NNTPWRAPPER |
3 | 3 | ||
4 | #include "mailwrapper.h" | 4 | #include "mailwrapper.h" |
5 | #include "genericwrapper.h" | 5 | #include "genericwrapper.h" |
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | #include <libetpan/clist.h> | 7 | #include <libetpan/clist.h> |
8 | 8 | ||
9 | class encodedString; | 9 | class encodedString; |
10 | struct mailstorage; | 10 | struct mailstorage; |
11 | struct mailfolder; | 11 | struct mailfolder; |
12 | 12 | ||
13 | class NNTPwrapper : public Genericwrapper | 13 | class NNTPwrapper : public Genericwrapper |
14 | { | 14 | { |
15 | 15 | ||
16 | Q_OBJECT | 16 | Q_OBJECT |
17 | 17 | ||
18 | public: | 18 | public: |
19 | NNTPwrapper( NNTPaccount *a ); | 19 | NNTPwrapper( NNTPaccount *a ); |
20 | virtual ~NNTPwrapper(); | 20 | virtual ~NNTPwrapper(); |
21 | 21 | ||
22 | /* mailbox will be ignored */ | 22 | /* mailbox will be ignored */ |
23 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 23 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
24 | /* should only get the subscribed one */ | 24 | /* should only get the subscribed one */ |
25 | virtual QList<Folder>* listFolders(); | 25 | virtual QValueList<Opie::osmart_pointer<Folder> >* listFolders(); |
26 | /* mailbox will be ignored */ | 26 | /* mailbox will be ignored */ |
27 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | 27 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); |
28 | QStringList listAllNewsgroups(const QString&mask = QString::null); | 28 | QStringList listAllNewsgroups(const QString&mask = QString::null); |
29 | virtual void deleteMail(const RecMail&mail); | 29 | virtual void deleteMail(const RecMail&mail); |
30 | virtual void answeredMail(const RecMail&mail); | 30 | virtual void answeredMail(const RecMail&mail); |
31 | virtual int deleteAllMail(const Folder*); | 31 | virtual int deleteAllMail(const Opie::osmart_pointer<Folder>&); |
32 | 32 | ||
33 | virtual RecBody fetchBody( const RecMail &mail ); | 33 | virtual RecBody fetchBody( const RecMail &mail ); |
34 | virtual encodedString* fetchRawBody(const RecMail&mail); | 34 | virtual encodedString* fetchRawBody(const RecMail&mail); |
35 | virtual void logout(); | 35 | virtual void logout(); |
36 | virtual MAILLIB::ATYPE getType()const; | 36 | virtual MAILLIB::ATYPE getType()const; |
37 | virtual const QString&getName()const; | 37 | virtual const QString&getName()const; |
38 | static void nntp_progress( size_t current, size_t maximum ); | 38 | static void nntp_progress( size_t current, size_t maximum ); |
39 | 39 | ||
40 | protected: | 40 | protected: |
41 | void login(); | 41 | void login(); |
42 | NNTPaccount *account; | 42 | NNTPaccount *account; |
43 | mailstorage* m_nntp; | 43 | mailstorage* m_nntp; |
44 | 44 | ||
45 | 45 | ||
46 | }; | 46 | }; |
47 | 47 | ||
48 | #endif | 48 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index 0939b22..7bf7ed2 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp | |||
@@ -1,255 +1,254 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include "pop3wrapper.h" | 2 | #include "pop3wrapper.h" |
3 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
4 | #include "logindialog.h" | 4 | #include "logindialog.h" |
5 | #include <libetpan/libetpan.h> | 5 | #include <libetpan/libetpan.h> |
6 | #include <qpe/global.h> | 6 | #include <qpe/global.h> |
7 | #include <qfile.h> | 7 | #include <qfile.h> |
8 | //#include <qstring.h> | 8 | //#include <qstring.h> |
9 | 9 | ||
10 | /* we don't fetch messages larger than 5 MB */ | 10 | /* we don't fetch messages larger than 5 MB */ |
11 | #define HARD_MSG_SIZE_LIMIT 5242880 | 11 | #define HARD_MSG_SIZE_LIMIT 5242880 |
12 | 12 | ||
13 | POP3wrapper::POP3wrapper( POP3account *a ) | 13 | POP3wrapper::POP3wrapper( POP3account *a ) |
14 | : Genericwrapper() { | 14 | : Genericwrapper() { |
15 | account = a; | 15 | account = a; |
16 | m_pop3 = NULL; | 16 | m_pop3 = NULL; |
17 | msgTempName = a->getFileName()+"_msg_cache"; | 17 | msgTempName = a->getFileName()+"_msg_cache"; |
18 | last_msg_id = 0; | 18 | last_msg_id = 0; |
19 | } | 19 | } |
20 | 20 | ||
21 | POP3wrapper::~POP3wrapper() { | 21 | POP3wrapper::~POP3wrapper() { |
22 | logout(); | 22 | logout(); |
23 | QFile msg_cache(msgTempName); | 23 | QFile msg_cache(msgTempName); |
24 | if (msg_cache.exists()) { | 24 | if (msg_cache.exists()) { |
25 | msg_cache.remove(); | 25 | msg_cache.remove(); |
26 | } | 26 | } |
27 | } | 27 | } |
28 | 28 | ||
29 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { | 29 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { |
30 | qDebug( "POP3: %i of %i", current, maximum ); | 30 | qDebug( "POP3: %i of %i", current, maximum ); |
31 | } | 31 | } |
32 | 32 | ||
33 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) { | 33 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) { |
34 | int err = MAILPOP3_NO_ERROR; | 34 | int err = MAILPOP3_NO_ERROR; |
35 | char *message = 0; | 35 | char *message = 0; |
36 | size_t length = 0; | 36 | size_t length = 0; |
37 | 37 | ||
38 | login(); | 38 | login(); |
39 | if ( !m_pop3 ) { | 39 | if ( !m_pop3 ) { |
40 | return RecBody(); | 40 | return RecBody(); |
41 | } | 41 | } |
42 | 42 | ||
43 | RecBody body; | 43 | RecBody body; |
44 | mailmessage * mailmsg; | 44 | mailmessage * mailmsg; |
45 | if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { | 45 | if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { |
46 | qDebug("Message to large: %i",mail.Msgsize()); | 46 | qDebug("Message to large: %i",mail.Msgsize()); |
47 | return body; | 47 | return body; |
48 | } | 48 | } |
49 | 49 | ||
50 | QFile msg_cache(msgTempName); | 50 | QFile msg_cache(msgTempName); |
51 | 51 | ||
52 | cleanMimeCache(); | 52 | cleanMimeCache(); |
53 | 53 | ||
54 | if (mail.getNumber()!=last_msg_id) { | 54 | if (mail.getNumber()!=last_msg_id) { |
55 | if (msg_cache.exists()) { | 55 | if (msg_cache.exists()) { |
56 | msg_cache.remove(); | 56 | msg_cache.remove(); |
57 | } | 57 | } |
58 | msg_cache.open(IO_ReadWrite|IO_Truncate); | 58 | msg_cache.open(IO_ReadWrite|IO_Truncate); |
59 | last_msg_id = mail.getNumber(); | 59 | last_msg_id = mail.getNumber(); |
60 | err = mailsession_get_message(m_pop3->sto_session, mail.getNumber(), &mailmsg); | 60 | err = mailsession_get_message(m_pop3->sto_session, mail.getNumber(), &mailmsg); |
61 | err = mailmessage_fetch(mailmsg,&message,&length); | 61 | err = mailmessage_fetch(mailmsg,&message,&length); |
62 | msg_cache.writeBlock(message,length); | 62 | msg_cache.writeBlock(message,length); |
63 | } else { | 63 | } else { |
64 | QString msg=""; | 64 | QString msg=""; |
65 | msg_cache.open(IO_ReadOnly); | 65 | msg_cache.open(IO_ReadOnly); |
66 | message = new char[4096]; | 66 | message = new char[4096]; |
67 | memset(message,0,4096); | 67 | memset(message,0,4096); |
68 | while (msg_cache.readBlock(message,4095)>0) { | 68 | while (msg_cache.readBlock(message,4095)>0) { |
69 | msg+=message; | 69 | msg+=message; |
70 | memset(message,0,4096); | 70 | memset(message,0,4096); |
71 | } | 71 | } |
72 | delete message; | 72 | delete message; |
73 | message = (char*)malloc(msg.length()+1*sizeof(char)); | 73 | message = (char*)malloc(msg.length()+1*sizeof(char)); |
74 | memset(message,0,msg.length()+1); | 74 | memset(message,0,msg.length()+1); |
75 | memcpy(message,msg.latin1(),msg.length()); | 75 | memcpy(message,msg.latin1(),msg.length()); |
76 | /* transform to libetpan stuff */ | 76 | /* transform to libetpan stuff */ |
77 | mailmsg = mailmessage_new(); | 77 | mailmsg = mailmessage_new(); |
78 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); | 78 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); |
79 | generic_message_t * msg_data; | 79 | generic_message_t * msg_data; |
80 | msg_data = (generic_message_t *)mailmsg->msg_data; | 80 | msg_data = (generic_message_t *)mailmsg->msg_data; |
81 | msg_data->msg_fetched = 1; | 81 | msg_data->msg_fetched = 1; |
82 | msg_data->msg_message = message; | 82 | msg_data->msg_message = message; |
83 | msg_data->msg_length = strlen(message); | 83 | msg_data->msg_length = strlen(message); |
84 | } | 84 | } |
85 | body = parseMail(mailmsg); | 85 | body = parseMail(mailmsg); |
86 | 86 | ||
87 | /* clean up */ | 87 | /* clean up */ |
88 | if (mailmsg) | 88 | if (mailmsg) |
89 | mailmessage_free(mailmsg); | 89 | mailmessage_free(mailmsg); |
90 | if (message) | 90 | if (message) |
91 | free(message); | 91 | free(message); |
92 | 92 | ||
93 | return body; | 93 | return body; |
94 | } | 94 | } |
95 | 95 | ||
96 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) | 96 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) |
97 | { | 97 | { |
98 | login(); | 98 | login(); |
99 | if (!m_pop3) | 99 | if (!m_pop3) |
100 | return; | 100 | return; |
101 | uint32_t res_messages,res_recent,res_unseen; | 101 | uint32_t res_messages,res_recent,res_unseen; |
102 | mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); | 102 | mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); |
103 | parseList(target,m_pop3->sto_session,"INBOX"); | 103 | parseList(target,m_pop3->sto_session,"INBOX"); |
104 | Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); | 104 | Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); |
105 | } | 105 | } |
106 | 106 | ||
107 | void POP3wrapper::login() | 107 | void POP3wrapper::login() |
108 | { | 108 | { |
109 | if (account->getOffline()) | 109 | if (account->getOffline()) |
110 | return; | 110 | return; |
111 | /* we'll hold the line */ | 111 | /* we'll hold the line */ |
112 | if ( m_pop3 != NULL ) | 112 | if ( m_pop3 != NULL ) |
113 | return; | 113 | return; |
114 | 114 | ||
115 | const char *server, *user, *pass; | 115 | const char *server, *user, *pass; |
116 | uint16_t port; | 116 | uint16_t port; |
117 | int err = MAILPOP3_NO_ERROR; | 117 | int err = MAILPOP3_NO_ERROR; |
118 | 118 | ||
119 | server = account->getServer().latin1(); | 119 | server = account->getServer().latin1(); |
120 | port = account->getPort().toUInt(); | 120 | port = account->getPort().toUInt(); |
121 | 121 | ||
122 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 122 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
123 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 123 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
124 | login.show(); | 124 | login.show(); |
125 | if ( QDialog::Accepted == login.exec() ) { | 125 | if ( QDialog::Accepted == login.exec() ) { |
126 | // ok | 126 | // ok |
127 | user = login.getUser().latin1(); | 127 | user = login.getUser().latin1(); |
128 | pass = login.getPassword().latin1(); | 128 | pass = login.getPassword().latin1(); |
129 | } else { | 129 | } else { |
130 | // cancel | 130 | // cancel |
131 | qDebug( "POP3: Login canceled" ); | 131 | qDebug( "POP3: Login canceled" ); |
132 | return; | 132 | return; |
133 | } | 133 | } |
134 | } else { | 134 | } else { |
135 | user = account->getUser().latin1(); | 135 | user = account->getUser().latin1(); |
136 | pass = account->getPassword().latin1(); | 136 | pass = account->getPassword().latin1(); |
137 | } | 137 | } |
138 | 138 | ||
139 | // bool ssl = account->getSSL(); | 139 | // bool ssl = account->getSSL(); |
140 | 140 | ||
141 | m_pop3=mailstorage_new(NULL); | 141 | m_pop3=mailstorage_new(NULL); |
142 | 142 | ||
143 | int conntypeset = account->ConnectionType(); | 143 | int conntypeset = account->ConnectionType(); |
144 | int conntype = 0; | 144 | int conntype = 0; |
145 | if ( conntypeset == 3 ) { | 145 | if ( conntypeset == 3 ) { |
146 | conntype = CONNECTION_TYPE_COMMAND; | 146 | conntype = CONNECTION_TYPE_COMMAND; |
147 | } else if ( conntypeset == 2 ) { | 147 | } else if ( conntypeset == 2 ) { |
148 | conntype = CONNECTION_TYPE_TLS; | 148 | conntype = CONNECTION_TYPE_TLS; |
149 | } else if ( conntypeset == 1 ) { | 149 | } else if ( conntypeset == 1 ) { |
150 | conntype = CONNECTION_TYPE_STARTTLS; | 150 | conntype = CONNECTION_TYPE_STARTTLS; |
151 | } else if ( conntypeset == 0 ) { | 151 | } else if ( conntypeset == 0 ) { |
152 | conntype = CONNECTION_TYPE_TRY_STARTTLS; | 152 | conntype = CONNECTION_TYPE_TRY_STARTTLS; |
153 | } | 153 | } |
154 | 154 | ||
155 | //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); | 155 | //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); |
156 | 156 | ||
157 | pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, | 157 | pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, |
158 | (char*)user,(char*)pass,0,0,0); | 158 | (char*)user,(char*)pass,0,0,0); |
159 | 159 | ||
160 | 160 | ||
161 | err = mailstorage_connect(m_pop3); | 161 | err = mailstorage_connect(m_pop3); |
162 | if (err != MAIL_NO_ERROR) { | 162 | if (err != MAIL_NO_ERROR) { |
163 | qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) ); | 163 | qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) ); |
164 | Global::statusMessage(tr("Error initializing folder")); | 164 | Global::statusMessage(tr("Error initializing folder")); |
165 | mailstorage_free(m_pop3); | 165 | mailstorage_free(m_pop3); |
166 | m_pop3 = 0; | 166 | m_pop3 = 0; |
167 | } | 167 | } |
168 | } | 168 | } |
169 | 169 | ||
170 | void POP3wrapper::logout() | 170 | void POP3wrapper::logout() |
171 | { | 171 | { |
172 | int err = MAILPOP3_NO_ERROR; | 172 | int err = MAILPOP3_NO_ERROR; |
173 | if ( m_pop3 == NULL ) | 173 | if ( m_pop3 == NULL ) |
174 | return; | 174 | return; |
175 | mailstorage_free(m_pop3); | 175 | mailstorage_free(m_pop3); |
176 | m_pop3 = 0; | 176 | m_pop3 = 0; |
177 | } | 177 | } |
178 | 178 | ||
179 | 179 | ||
180 | QList<Folder>* POP3wrapper::listFolders() { | 180 | QValueList<Opie::osmart_pointer<Folder> >* POP3wrapper::listFolders() { |
181 | QList<Folder> * folders = new QList<Folder>(); | 181 | QValueList<Opie::osmart_pointer<Folder> >* folders = new QValueList<FolderP>(); |
182 | folders->setAutoDelete( false ); | 182 | FolderP inb=new Folder("INBOX","/"); |
183 | Folder*inb=new Folder("INBOX","/"); | ||
184 | folders->append(inb); | 183 | folders->append(inb); |
185 | return folders; | 184 | return folders; |
186 | } | 185 | } |
187 | 186 | ||
188 | void POP3wrapper::deleteMail(const RecMail&mail) { | 187 | void POP3wrapper::deleteMail(const RecMail&mail) { |
189 | login(); | 188 | login(); |
190 | if (!m_pop3) | 189 | if (!m_pop3) |
191 | return; | 190 | return; |
192 | int err = mailsession_remove_message(m_pop3->sto_session,mail.getNumber()); | 191 | int err = mailsession_remove_message(m_pop3->sto_session,mail.getNumber()); |
193 | if (err != MAIL_NO_ERROR) { | 192 | if (err != MAIL_NO_ERROR) { |
194 | Global::statusMessage(tr("error deleting mail")); | 193 | Global::statusMessage(tr("error deleting mail")); |
195 | } | 194 | } |
196 | } | 195 | } |
197 | 196 | ||
198 | void POP3wrapper::answeredMail(const RecMail&) {} | 197 | void POP3wrapper::answeredMail(const RecMail&) {} |
199 | 198 | ||
200 | int POP3wrapper::deleteAllMail(const Folder*) { | 199 | int POP3wrapper::deleteAllMail(const FolderP&) { |
201 | login(); | 200 | login(); |
202 | if (!m_pop3) | 201 | if (!m_pop3) |
203 | return 0; | 202 | return 0; |
204 | int res = 1; | 203 | int res = 1; |
205 | 204 | ||
206 | uint32_t result = 0; | 205 | uint32_t result = 0; |
207 | int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); | 206 | int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); |
208 | if (err != MAIL_NO_ERROR) { | 207 | if (err != MAIL_NO_ERROR) { |
209 | Global::statusMessage(tr("Error getting folder info")); | 208 | Global::statusMessage(tr("Error getting folder info")); |
210 | return 0; | 209 | return 0; |
211 | } | 210 | } |
212 | for (unsigned int i = 0; i < result; ++i) { | 211 | for (unsigned int i = 0; i < result; ++i) { |
213 | err = mailsession_remove_message(m_pop3->sto_session,i+1); | 212 | err = mailsession_remove_message(m_pop3->sto_session,i+1); |
214 | if (err != MAIL_NO_ERROR) { | 213 | if (err != MAIL_NO_ERROR) { |
215 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 214 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
216 | res=0; | 215 | res=0; |
217 | } | 216 | } |
218 | break; | 217 | break; |
219 | } | 218 | } |
220 | return res; | 219 | return res; |
221 | } | 220 | } |
222 | 221 | ||
223 | void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { | 222 | void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { |
224 | login(); | 223 | login(); |
225 | target_stat.message_count = 0; | 224 | target_stat.message_count = 0; |
226 | target_stat.message_unseen = 0; | 225 | target_stat.message_unseen = 0; |
227 | target_stat.message_recent = 0; | 226 | target_stat.message_recent = 0; |
228 | if (!m_pop3) | 227 | if (!m_pop3) |
229 | return; | 228 | return; |
230 | int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, | 229 | int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, |
231 | &target_stat.message_recent,&target_stat.message_unseen); | 230 | &target_stat.message_recent,&target_stat.message_unseen); |
232 | } | 231 | } |
233 | 232 | ||
234 | encodedString* POP3wrapper::fetchRawBody(const RecMail&mail) { | 233 | encodedString* POP3wrapper::fetchRawBody(const RecMail&mail) { |
235 | char*target=0; | 234 | char*target=0; |
236 | size_t length=0; | 235 | size_t length=0; |
237 | encodedString*res = 0; | 236 | encodedString*res = 0; |
238 | mailmessage * mailmsg = 0; | 237 | mailmessage * mailmsg = 0; |
239 | int err = mailsession_get_message(m_pop3->sto_session, mail.getNumber(), &mailmsg); | 238 | int err = mailsession_get_message(m_pop3->sto_session, mail.getNumber(), &mailmsg); |
240 | err = mailmessage_fetch(mailmsg,&target,&length); | 239 | err = mailmessage_fetch(mailmsg,&target,&length); |
241 | if (mailmsg) | 240 | if (mailmsg) |
242 | mailmessage_free(mailmsg); | 241 | mailmessage_free(mailmsg); |
243 | if (target) { | 242 | if (target) { |
244 | res = new encodedString(target,length); | 243 | res = new encodedString(target,length); |
245 | } | 244 | } |
246 | return res; | 245 | return res; |
247 | } | 246 | } |
248 | 247 | ||
249 | MAILLIB::ATYPE POP3wrapper::getType()const { | 248 | MAILLIB::ATYPE POP3wrapper::getType()const { |
250 | return account->getType(); | 249 | return account->getType(); |
251 | } | 250 | } |
252 | 251 | ||
253 | const QString&POP3wrapper::getName()const{ | 252 | const QString&POP3wrapper::getName()const{ |
254 | return account->getAccountName(); | 253 | return account->getAccountName(); |
255 | } | 254 | } |
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index 391c841..e4afb94 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h | |||
@@ -1,42 +1,42 @@ | |||
1 | #ifndef __POP3WRAPPER | 1 | #ifndef __POP3WRAPPER |
2 | #define __POP3WRAPPER | 2 | #define __POP3WRAPPER |
3 | 3 | ||
4 | #include "mailwrapper.h" | 4 | #include "mailwrapper.h" |
5 | #include "genericwrapper.h" | 5 | #include "genericwrapper.h" |
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | 7 | ||
8 | class encodedString; | 8 | class encodedString; |
9 | struct mailstorage; | 9 | struct mailstorage; |
10 | struct mailfolder; | 10 | struct mailfolder; |
11 | 11 | ||
12 | class POP3wrapper : public Genericwrapper | 12 | class POP3wrapper : public Genericwrapper |
13 | { | 13 | { |
14 | Q_OBJECT | 14 | Q_OBJECT |
15 | 15 | ||
16 | public: | 16 | public: |
17 | POP3wrapper( POP3account *a ); | 17 | POP3wrapper( POP3account *a ); |
18 | virtual ~POP3wrapper(); | 18 | virtual ~POP3wrapper(); |
19 | /* mailbox will be ignored */ | 19 | /* mailbox will be ignored */ |
20 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 20 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
21 | virtual QList<Folder>* listFolders(); | 21 | virtual QValueList<Opie::osmart_pointer<Folder> >* listFolders(); |
22 | /* mailbox will be ignored */ | 22 | /* mailbox will be ignored */ |
23 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | 23 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); |
24 | 24 | ||
25 | virtual void deleteMail(const RecMail&mail); | 25 | virtual void deleteMail(const RecMail&mail); |
26 | virtual void answeredMail(const RecMail&mail); | 26 | virtual void answeredMail(const RecMail&mail); |
27 | virtual int deleteAllMail(const Folder*); | 27 | virtual int deleteAllMail(const Opie::osmart_pointer<Folder>&); |
28 | 28 | ||
29 | virtual RecBody fetchBody( const RecMail &mail ); | 29 | virtual RecBody fetchBody( const RecMail &mail ); |
30 | virtual encodedString* fetchRawBody(const RecMail&mail); | 30 | virtual encodedString* fetchRawBody(const RecMail&mail); |
31 | virtual void logout(); | 31 | virtual void logout(); |
32 | virtual MAILLIB::ATYPE getType()const; | 32 | virtual MAILLIB::ATYPE getType()const; |
33 | virtual const QString&getName()const; | 33 | virtual const QString&getName()const; |
34 | static void pop3_progress( size_t current, size_t maximum ); | 34 | static void pop3_progress( size_t current, size_t maximum ); |
35 | 35 | ||
36 | protected: | 36 | protected: |
37 | void login(); | 37 | void login(); |
38 | POP3account *account; | 38 | POP3account *account; |
39 | mailstorage*m_pop3; | 39 | mailstorage*m_pop3; |
40 | }; | 40 | }; |
41 | 41 | ||
42 | #endif | 42 | #endif |
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp index aa8f37a..78652d7 100644 --- a/noncore/net/mail/viewmail.cpp +++ b/noncore/net/mail/viewmail.cpp | |||
@@ -1,475 +1,476 @@ | |||
1 | #include "composemail.h" | 1 | #include "composemail.h" |
2 | #include "viewmail.h" | 2 | #include "viewmail.h" |
3 | 3 | ||
4 | /* OPIE */ | 4 | /* OPIE */ |
5 | #include <libmailwrapper/settings.h> | 5 | #include <libmailwrapper/settings.h> |
6 | #include <libmailwrapper/abstractmail.h> | 6 | #include <libmailwrapper/abstractmail.h> |
7 | #include <libmailwrapper/mailtypes.h> | 7 | #include <libmailwrapper/mailtypes.h> |
8 | 8 | ||
9 | #include <opie2/ofiledialog.h> | 9 | #include <opie2/ofiledialog.h> |
10 | #include <qpe/config.h> | 10 | #include <qpe/config.h> |
11 | #include <qpe/qpeapplication.h> | 11 | #include <qpe/qpeapplication.h> |
12 | 12 | ||
13 | /* QT */ | 13 | /* QT */ |
14 | #include <qtextbrowser.h> | 14 | #include <qtextbrowser.h> |
15 | #include <qmessagebox.h> | 15 | #include <qmessagebox.h> |
16 | #include <qtextstream.h> | 16 | #include <qtextstream.h> |
17 | #include <qaction.h> | 17 | #include <qaction.h> |
18 | #include <qpopupmenu.h> | 18 | #include <qpopupmenu.h> |
19 | #include <qfile.h> | 19 | #include <qfile.h> |
20 | 20 | ||
21 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, | 21 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, |
22 | const QString&fsize,int num,const QValueList<int>&path) | 22 | const QString&fsize,int num,const QValueList<int>&path) |
23 | : QListViewItem(parent,after),_partNum(num) | 23 | : QListViewItem(parent,after),_partNum(num) |
24 | { | 24 | { |
25 | _path=path; | 25 | _path=path; |
26 | setText(0, mime); | 26 | setText(0, mime); |
27 | setText(1, desc); | 27 | setText(1, desc); |
28 | setText(2, file); | 28 | setText(2, file); |
29 | setText(3, fsize); | 29 | setText(3, fsize); |
30 | } | 30 | } |
31 | 31 | ||
32 | AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, | 32 | AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, |
33 | const QString&fsize,int num,const QValueList<int>&path) | 33 | const QString&fsize,int num,const QValueList<int>&path) |
34 | : QListViewItem(parent,after),_partNum(num) | 34 | : QListViewItem(parent,after),_partNum(num) |
35 | { | 35 | { |
36 | _path=path; | 36 | _path=path; |
37 | setText(0, mime); | 37 | setText(0, mime); |
38 | setText(1, desc); | 38 | setText(1, desc); |
39 | setText(2, file); | 39 | setText(2, file); |
40 | setText(3, fsize); | 40 | setText(3, fsize); |
41 | } | 41 | } |
42 | 42 | ||
43 | bool AttachItem::isParentof(const QValueList<int>&path) | 43 | bool AttachItem::isParentof(const QValueList<int>&path) |
44 | { | 44 | { |
45 | /* if not set, then no parent */ | 45 | /* if not set, then no parent */ |
46 | if (path.count()==0||_path.count()==0) return false; | 46 | if (path.count()==0||_path.count()==0) return false; |
47 | /* the parent must have one digit less then a child */ | 47 | /* the parent must have one digit less then a child */ |
48 | if (path.count()!=_path.count()+1) return false; | 48 | if (path.count()!=_path.count()+1) return false; |
49 | for (unsigned int i=0; i < _path.count();++i) | 49 | for (unsigned int i=0; i < _path.count();++i) |
50 | { | 50 | { |
51 | if (_path[i]!=path[i]) return false; | 51 | if (_path[i]!=path[i]) return false; |
52 | } | 52 | } |
53 | return true; | 53 | return true; |
54 | } | 54 | } |
55 | 55 | ||
56 | AttachItem* ViewMail::searchParent(const QValueList<int>&path) | 56 | AttachItem* ViewMail::searchParent(const QValueList<int>&path) |
57 | { | 57 | { |
58 | QListViewItemIterator it( attachments ); | 58 | QListViewItemIterator it( attachments ); |
59 | for ( ; it.current(); ++it ) | 59 | for ( ; it.current(); ++it ) |
60 | { | 60 | { |
61 | AttachItem*ati = (AttachItem*)it.current(); | 61 | AttachItem*ati = (AttachItem*)it.current(); |
62 | if (ati->isParentof(path)) return ati; | 62 | if (ati->isParentof(path)) return ati; |
63 | } | 63 | } |
64 | return 0; | 64 | return 0; |
65 | } | 65 | } |
66 | 66 | ||
67 | AttachItem* ViewMail::lastChild(AttachItem*parent) | 67 | AttachItem* ViewMail::lastChild(AttachItem*parent) |
68 | { | 68 | { |
69 | if (!parent) return 0; | 69 | if (!parent) return 0; |
70 | AttachItem* item = (AttachItem*)parent->firstChild(); | 70 | AttachItem* item = (AttachItem*)parent->firstChild(); |
71 | if (!item) return item; | 71 | if (!item) return item; |
72 | AttachItem*temp=0; | 72 | AttachItem*temp=0; |
73 | while( (temp=(AttachItem*)item->nextSibling())) | 73 | while( (temp=(AttachItem*)item->nextSibling())) |
74 | { | 74 | { |
75 | item = temp; | 75 | item = temp; |
76 | } | 76 | } |
77 | return item; | 77 | return item; |
78 | } | 78 | } |
79 | 79 | ||
80 | void ViewMail::setBody( RecBody body ) | 80 | void ViewMail::setBody( RecBody body ) |
81 | { | 81 | { |
82 | 82 | ||
83 | m_body = body; | 83 | m_body = body; |
84 | m_mail[2] = body.Bodytext(); | 84 | m_mail[2] = body.Bodytext(); |
85 | attachbutton->setEnabled(body.Parts().count()>0); | 85 | attachbutton->setEnabled(body.Parts().count()>0); |
86 | attachments->setEnabled(body.Parts().count()>0); | 86 | attachments->setEnabled(body.Parts().count()>0); |
87 | if (body.Parts().count()==0) | 87 | if (body.Parts().count()==0) |
88 | { | 88 | { |
89 | return; | 89 | return; |
90 | } | 90 | } |
91 | AttachItem * curItem=0; | 91 | AttachItem * curItem=0; |
92 | AttachItem * parentItem = 0; | 92 | AttachItem * parentItem = 0; |
93 | QString type=body.Description().Type()+"/"+body.Description().Subtype(); | 93 | QString type=body.Description().Type()+"/"+body.Description().Subtype(); |
94 | QString desc,fsize; | 94 | QString desc,fsize; |
95 | double s = body.Description().Size(); | 95 | double s = body.Description().Size(); |
96 | int w; | 96 | int w; |
97 | w=0; | 97 | w=0; |
98 | 98 | ||
99 | while (s>1024) | 99 | while (s>1024) |
100 | { | 100 | { |
101 | s/=1024; | 101 | s/=1024; |
102 | ++w; | 102 | ++w; |
103 | if (w>=2) break; | 103 | if (w>=2) break; |
104 | } | 104 | } |
105 | 105 | ||
106 | QString q=""; | 106 | QString q=""; |
107 | switch(w) | 107 | switch(w) |
108 | { | 108 | { |
109 | case 1: | 109 | case 1: |
110 | q="k"; | 110 | q="k"; |
111 | break; | 111 | break; |
112 | case 2: | 112 | case 2: |
113 | q="M"; | 113 | q="M"; |
114 | break; | 114 | break; |
115 | default: | 115 | default: |
116 | break; | 116 | break; |
117 | } | 117 | } |
118 | 118 | ||
119 | { | 119 | { |
120 | /* I did not found a method to make a CONTENT reset on a QTextStream | 120 | /* I did not found a method to make a CONTENT reset on a QTextStream |
121 | so I use this construct that the stream will re-constructed in each | 121 | so I use this construct that the stream will re-constructed in each |
122 | loop. To let it work, the textstream is packed into a own area of | 122 | loop. To let it work, the textstream is packed into a own area of |
123 | code is it will be destructed after finishing its small job. | 123 | code is it will be destructed after finishing its small job. |
124 | */ | 124 | */ |
125 | QTextOStream o(&fsize); | 125 | QTextOStream o(&fsize); |
126 | if (w>0) o.precision(2); else o.precision(0); | 126 | if (w>0) o.precision(2); else o.precision(0); |
127 | o.setf(QTextStream::fixed); | 127 | o.setf(QTextStream::fixed); |
128 | o << s << " " << q << "Byte"; | 128 | o << s << " " << q << "Byte"; |
129 | } | 129 | } |
130 | 130 | ||
131 | curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body.Description().Positionlist()); | 131 | curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body.Description().Positionlist()); |
132 | QString filename = ""; | 132 | QString filename = ""; |
133 | 133 | ||
134 | for (unsigned int i = 0; i < body.Parts().count();++i) | 134 | for (unsigned int i = 0; i < body.Parts().count();++i) |
135 | { | 135 | { |
136 | filename = ""; | ||
136 | type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); | 137 | type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); |
137 | part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); | 138 | part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); |
138 | for (;it!=body.Parts()[i].Parameters().end();++it) | 139 | for (;it!=body.Parts()[i].Parameters().end();++it) |
139 | { | 140 | { |
140 | qDebug(it.key()); | 141 | qDebug(it.key()); |
141 | if (it.key().lower()=="name") | 142 | if (it.key().lower()=="name") |
142 | { | 143 | { |
143 | filename=it.data(); | 144 | filename=it.data(); |
144 | } | 145 | } |
145 | } | 146 | } |
146 | s = body.Parts()[i].Size(); | 147 | s = body.Parts()[i].Size(); |
147 | w = 0; | 148 | w = 0; |
148 | while (s>1024) | 149 | while (s>1024) |
149 | { | 150 | { |
150 | s/=1024; | 151 | s/=1024; |
151 | ++w; | 152 | ++w; |
152 | if (w>=2) break; | 153 | if (w>=2) break; |
153 | } | 154 | } |
154 | switch(w) | 155 | switch(w) |
155 | { | 156 | { |
156 | case 1: | 157 | case 1: |
157 | q="k"; | 158 | q="k"; |
158 | break; | 159 | break; |
159 | case 2: | 160 | case 2: |
160 | q="M"; | 161 | q="M"; |
161 | break; | 162 | break; |
162 | default: | 163 | default: |
163 | q=""; | 164 | q=""; |
164 | break; | 165 | break; |
165 | } | 166 | } |
166 | QTextOStream o(&fsize); | 167 | QTextOStream o(&fsize); |
167 | if (w>0) o.precision(2); else o.precision(0); | 168 | if (w>0) o.precision(2); else o.precision(0); |
168 | o.setf(QTextStream::fixed); | 169 | o.setf(QTextStream::fixed); |
169 | o << s << " " << q << "Byte"; | 170 | o << s << " " << q << "Byte"; |
170 | desc = body.Parts()[i].Description(); | 171 | desc = body.Parts()[i].Description(); |
171 | parentItem = searchParent(body.Parts()[i].Positionlist()); | 172 | parentItem = searchParent(body.Parts()[i].Positionlist()); |
172 | if (parentItem) | 173 | if (parentItem) |
173 | { | 174 | { |
174 | AttachItem*temp = lastChild(parentItem); | 175 | AttachItem*temp = lastChild(parentItem); |
175 | if (temp) curItem = temp; | 176 | if (temp) curItem = temp; |
176 | curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist()); | 177 | curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist()); |
177 | attachments->setRootIsDecorated(true); | 178 | attachments->setRootIsDecorated(true); |
178 | curItem = parentItem; | 179 | curItem = parentItem; |
179 | } | 180 | } |
180 | else | 181 | else |
181 | { | 182 | { |
182 | curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist()); | 183 | curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist()); |
183 | } | 184 | } |
184 | } | 185 | } |
185 | } | 186 | } |
186 | 187 | ||
187 | 188 | ||
188 | void ViewMail::slotShowHtml( bool state ) | 189 | void ViewMail::slotShowHtml( bool state ) |
189 | { | 190 | { |
190 | m_showHtml = state; | 191 | m_showHtml = state; |
191 | setText(); | 192 | setText(); |
192 | } | 193 | } |
193 | 194 | ||
194 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) | 195 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) |
195 | { | 196 | { |
196 | if (!item ) | 197 | if (!item ) |
197 | return; | 198 | return; |
198 | 199 | ||
199 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) | 200 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) |
200 | { | 201 | { |
201 | setText(); | 202 | setText(); |
202 | return; | 203 | return; |
203 | } | 204 | } |
204 | QPopupMenu *menu = new QPopupMenu(); | 205 | QPopupMenu *menu = new QPopupMenu(); |
205 | int ret=0; | 206 | int ret=0; |
206 | 207 | ||
207 | if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) | 208 | if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) |
208 | { | 209 | { |
209 | menu->insertItem( tr( "Show Text" ), 1 ); | 210 | menu->insertItem( tr( "Show Text" ), 1 ); |
210 | } | 211 | } |
211 | menu->insertItem( tr( "Save Attachment" ), 0 ); | 212 | menu->insertItem( tr( "Save Attachment" ), 0 ); |
212 | menu->insertSeparator(1); | 213 | menu->insertSeparator(1); |
213 | 214 | ||
214 | ret = menu->exec( point, 0 ); | 215 | ret = menu->exec( point, 0 ); |
215 | 216 | ||
216 | switch(ret) | 217 | switch(ret) |
217 | { | 218 | { |
218 | case 0: | 219 | case 0: |
219 | { | 220 | { |
220 | MimeTypes types; | 221 | MimeTypes types; |
221 | types.insert( "all", "*" ); | 222 | types.insert( "all", "*" ); |
222 | QString str = Opie::OFileDialog::getSaveFileName( 1, | 223 | QString str = Opie::OFileDialog::getSaveFileName( 1, |
223 | "/", item->text( 2 ) , types, 0 ); | 224 | "/", item->text( 2 ) , types, 0 ); |
224 | 225 | ||
225 | if( !str.isEmpty() ) | 226 | if( !str.isEmpty() ) |
226 | { | 227 | { |
227 | encodedString*content = m_recMail.Wrapper()->fetchDecodedPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); | 228 | encodedString*content = m_recMail.Wrapper()->fetchDecodedPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); |
228 | if (content) | 229 | if (content) |
229 | { | 230 | { |
230 | QFile output(str); | 231 | QFile output(str); |
231 | output.open(IO_WriteOnly); | 232 | output.open(IO_WriteOnly); |
232 | output.writeBlock(content->Content(),content->Length()); | 233 | output.writeBlock(content->Content(),content->Length()); |
233 | output.close(); | 234 | output.close(); |
234 | delete content; | 235 | delete content; |
235 | } | 236 | } |
236 | } | 237 | } |
237 | } | 238 | } |
238 | break ; | 239 | break ; |
239 | 240 | ||
240 | case 1: | 241 | case 1: |
241 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) | 242 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) |
242 | { | 243 | { |
243 | setText(); | 244 | setText(); |
244 | } | 245 | } |
245 | else | 246 | else |
246 | { | 247 | { |
247 | if ( m_recMail.Wrapper() != 0l ) | 248 | if ( m_recMail.Wrapper() != 0l ) |
248 | { // make sure that there is a wrapper , even after delete or simular actions | 249 | { // make sure that there is a wrapper , even after delete or simular actions |
249 | browser->setText( m_recMail.Wrapper()->fetchTextPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); | 250 | browser->setText( m_recMail.Wrapper()->fetchTextPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); |
250 | } | 251 | } |
251 | } | 252 | } |
252 | break; | 253 | break; |
253 | } | 254 | } |
254 | delete menu; | 255 | delete menu; |
255 | } | 256 | } |
256 | 257 | ||
257 | 258 | ||
258 | void ViewMail::setMail( RecMail mail ) | 259 | void ViewMail::setMail( RecMail mail ) |
259 | { | 260 | { |
260 | 261 | ||
261 | m_recMail = mail; | 262 | m_recMail = mail; |
262 | 263 | ||
263 | m_mail[0] = mail.getFrom(); | 264 | m_mail[0] = mail.getFrom(); |
264 | m_mail[1] = mail.getSubject(); | 265 | m_mail[1] = mail.getSubject(); |
265 | m_mail[3] = mail.getDate(); | 266 | m_mail[3] = mail.getDate(); |
266 | m_mail[4] = mail.Msgid(); | 267 | m_mail[4] = mail.Msgid(); |
267 | 268 | ||
268 | m_mail2[0] = mail.To(); | 269 | m_mail2[0] = mail.To(); |
269 | m_mail2[1] = mail.CC(); | 270 | m_mail2[1] = mail.CC(); |
270 | m_mail2[2] = mail.Bcc(); | 271 | m_mail2[2] = mail.Bcc(); |
271 | 272 | ||
272 | setText(); | 273 | setText(); |
273 | } | 274 | } |
274 | 275 | ||
275 | 276 | ||
276 | 277 | ||
277 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) | 278 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) |
278 | : ViewMailBase(parent, name, fl), _inLoop(false) | 279 | : ViewMailBase(parent, name, fl), _inLoop(false) |
279 | { | 280 | { |
280 | m_gotBody = false; | 281 | m_gotBody = false; |
281 | deleted = false; | 282 | deleted = false; |
282 | 283 | ||
283 | connect( reply, SIGNAL(activated()), SLOT(slotReply())); | 284 | connect( reply, SIGNAL(activated()), SLOT(slotReply())); |
284 | connect( forward, SIGNAL(activated()), SLOT(slotForward())); | 285 | connect( forward, SIGNAL(activated()), SLOT(slotForward())); |
285 | connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) ); | 286 | connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) ); |
286 | connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) ); | 287 | connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) ); |
287 | 288 | ||
288 | attachments->setEnabled(m_gotBody); | 289 | attachments->setEnabled(m_gotBody); |
289 | connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) ); | 290 | connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) ); |
290 | 291 | ||
291 | readConfig(); | 292 | readConfig(); |
292 | attachments->setSorting(-1); | 293 | attachments->setSorting(-1); |
293 | } | 294 | } |
294 | 295 | ||
295 | void ViewMail::readConfig() | 296 | void ViewMail::readConfig() |
296 | { | 297 | { |
297 | Config cfg( "mail" ); | 298 | Config cfg( "mail" ); |
298 | cfg.setGroup( "Settings" ); | 299 | cfg.setGroup( "Settings" ); |
299 | m_showHtml = cfg.readBoolEntry( "showHtml", false ); | 300 | m_showHtml = cfg.readBoolEntry( "showHtml", false ); |
300 | showHtml->setOn( m_showHtml ); | 301 | showHtml->setOn( m_showHtml ); |
301 | } | 302 | } |
302 | 303 | ||
303 | void ViewMail::setText() | 304 | void ViewMail::setText() |
304 | { | 305 | { |
305 | 306 | ||
306 | QString toString; | 307 | QString toString; |
307 | QString ccString; | 308 | QString ccString; |
308 | QString bccString; | 309 | QString bccString; |
309 | 310 | ||
310 | for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) | 311 | for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) |
311 | { | 312 | { |
312 | toString += (*it); | 313 | toString += (*it); |
313 | } | 314 | } |
314 | for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) | 315 | for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) |
315 | { | 316 | { |
316 | ccString += (*it); | 317 | ccString += (*it); |
317 | } | 318 | } |
318 | for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) | 319 | for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) |
319 | { | 320 | { |
320 | bccString += (*it); | 321 | bccString += (*it); |
321 | } | 322 | } |
322 | 323 | ||
323 | setCaption( caption().arg( m_mail[0] ) ); | 324 | setCaption( caption().arg( m_mail[0] ) ); |
324 | 325 | ||
325 | m_mailHtml = "<html><body>" | 326 | m_mailHtml = "<html><body>" |
326 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" | 327 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" |
327 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" | 328 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" |
328 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" | 329 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" |
329 | "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" | 330 | "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" |
330 | "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + | 331 | "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + |
331 | tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" | 332 | tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" |
332 | "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + | 333 | "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + |
333 | "</td></tr></table><font face=fixed>"; | 334 | "</td></tr></table><font face=fixed>"; |
334 | 335 | ||
335 | if ( !m_showHtml ) | 336 | if ( !m_showHtml ) |
336 | { | 337 | { |
337 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); | 338 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); |
338 | } | 339 | } |
339 | else | 340 | else |
340 | { | 341 | { |
341 | browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); | 342 | browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); |
342 | } | 343 | } |
343 | // remove later in favor of a real handling | 344 | // remove later in favor of a real handling |
344 | m_gotBody = true; | 345 | m_gotBody = true; |
345 | } | 346 | } |
346 | 347 | ||
347 | 348 | ||
348 | ViewMail::~ViewMail() | 349 | ViewMail::~ViewMail() |
349 | { | 350 | { |
350 | m_recMail.Wrapper()->cleanMimeCache(); | 351 | m_recMail.Wrapper()->cleanMimeCache(); |
351 | hide(); | 352 | hide(); |
352 | } | 353 | } |
353 | 354 | ||
354 | void ViewMail::hide() | 355 | void ViewMail::hide() |
355 | { | 356 | { |
356 | QWidget::hide(); | 357 | QWidget::hide(); |
357 | 358 | ||
358 | if (_inLoop) | 359 | if (_inLoop) |
359 | { | 360 | { |
360 | _inLoop = false; | 361 | _inLoop = false; |
361 | qApp->exit_loop(); | 362 | qApp->exit_loop(); |
362 | 363 | ||
363 | } | 364 | } |
364 | 365 | ||
365 | } | 366 | } |
366 | 367 | ||
367 | void ViewMail::exec() | 368 | void ViewMail::exec() |
368 | { | 369 | { |
369 | show(); | 370 | show(); |
370 | 371 | ||
371 | if (!_inLoop) | 372 | if (!_inLoop) |
372 | { | 373 | { |
373 | _inLoop = true; | 374 | _inLoop = true; |
374 | qApp->enter_loop(); | 375 | qApp->enter_loop(); |
375 | } | 376 | } |
376 | 377 | ||
377 | } | 378 | } |
378 | 379 | ||
379 | QString ViewMail::deHtml(const QString &string) | 380 | QString ViewMail::deHtml(const QString &string) |
380 | { | 381 | { |
381 | QString string_ = string; | 382 | QString string_ = string; |
382 | string_.replace(QRegExp("&"), "&"); | 383 | string_.replace(QRegExp("&"), "&"); |
383 | string_.replace(QRegExp("<"), "<"); | 384 | string_.replace(QRegExp("<"), "<"); |
384 | string_.replace(QRegExp(">"), ">"); | 385 | string_.replace(QRegExp(">"), ">"); |
385 | string_.replace(QRegExp("\\n"), "<br>"); | 386 | string_.replace(QRegExp("\\n"), "<br>"); |
386 | return string_; | 387 | return string_; |
387 | } | 388 | } |
388 | 389 | ||
389 | void ViewMail::slotReply() | 390 | void ViewMail::slotReply() |
390 | { | 391 | { |
391 | if (!m_gotBody) | 392 | if (!m_gotBody) |
392 | { | 393 | { |
393 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); | 394 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); |
394 | return; | 395 | return; |
395 | } | 396 | } |
396 | 397 | ||
397 | QString rtext; | 398 | QString rtext; |
398 | rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose | 399 | rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose |
399 | .arg( m_mail[0] ) | 400 | .arg( m_mail[0] ) |
400 | .arg( m_mail[3] ); | 401 | .arg( m_mail[3] ); |
401 | 402 | ||
402 | QString text = m_mail[2]; | 403 | QString text = m_mail[2]; |
403 | QStringList lines = QStringList::split(QRegExp("\\n"), text); | 404 | QStringList lines = QStringList::split(QRegExp("\\n"), text); |
404 | QStringList::Iterator it; | 405 | QStringList::Iterator it; |
405 | for (it = lines.begin(); it != lines.end(); it++) | 406 | for (it = lines.begin(); it != lines.end(); it++) |
406 | { | 407 | { |
407 | rtext += "> " + *it + "\n"; | 408 | rtext += "> " + *it + "\n"; |
408 | } | 409 | } |
409 | rtext += "\n"; | 410 | rtext += "\n"; |
410 | 411 | ||
411 | QString prefix; | 412 | QString prefix; |
412 | if ( m_mail[1].find(QRegExp("^Re: .*$")) != -1) prefix = ""; | 413 | if ( m_mail[1].find(QRegExp("^Re: .*$")) != -1) prefix = ""; |
413 | else prefix = "Re: "; // no i18n on purpose | 414 | else prefix = "Re: "; // no i18n on purpose |
414 | 415 | ||
415 | Settings *settings = new Settings(); | 416 | Settings *settings = new Settings(); |
416 | ComposeMail composer( settings ,this, 0, true); | 417 | ComposeMail composer( settings ,this, 0, true); |
417 | if (m_recMail.Replyto().isEmpty()) { | 418 | if (m_recMail.Replyto().isEmpty()) { |
418 | composer.setTo( m_recMail.getFrom()); | 419 | composer.setTo( m_recMail.getFrom()); |
419 | } else { | 420 | } else { |
420 | composer.setTo( m_recMail.Replyto()); | 421 | composer.setTo( m_recMail.Replyto()); |
421 | } | 422 | } |
422 | composer.setSubject( prefix + m_mail[1] ); | 423 | composer.setSubject( prefix + m_mail[1] ); |
423 | composer.setMessage( rtext ); | 424 | composer.setMessage( rtext ); |
424 | composer.setInReplyTo(m_recMail.Msgid()); | 425 | composer.setInReplyTo(m_recMail.Msgid()); |
425 | 426 | ||
426 | if ( QDialog::Accepted == QPEApplication::execDialog( &composer ) ) | 427 | if ( QDialog::Accepted == QPEApplication::execDialog( &composer ) ) |
427 | { | 428 | { |
428 | m_recMail.Wrapper()->answeredMail(m_recMail); | 429 | m_recMail.Wrapper()->answeredMail(m_recMail); |
429 | } | 430 | } |
430 | } | 431 | } |
431 | 432 | ||
432 | void ViewMail::slotForward() | 433 | void ViewMail::slotForward() |
433 | { | 434 | { |
434 | if (!m_gotBody) | 435 | if (!m_gotBody) |
435 | { | 436 | { |
436 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); | 437 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); |
437 | return; | 438 | return; |
438 | } | 439 | } |
439 | 440 | ||
440 | QString ftext; | 441 | QString ftext; |
441 | ftext += QString("\n----- Forwarded message from %1 -----\n\n") | 442 | ftext += QString("\n----- Forwarded message from %1 -----\n\n") |
442 | .arg( m_mail[0] ); | 443 | .arg( m_mail[0] ); |
443 | if (!m_mail[3].isNull()) | 444 | if (!m_mail[3].isNull()) |
444 | ftext += QString("Date: %1\n") | 445 | ftext += QString("Date: %1\n") |
445 | .arg( m_mail[3] ); | 446 | .arg( m_mail[3] ); |
446 | if (!m_mail[0].isNull()) | 447 | if (!m_mail[0].isNull()) |
447 | ftext += QString("From: %1\n") | 448 | ftext += QString("From: %1\n") |
448 | .arg( m_mail[0] ); | 449 | .arg( m_mail[0] ); |
449 | if (!m_mail[1].isNull()) | 450 | if (!m_mail[1].isNull()) |
450 | ftext += QString("Subject: %1\n") | 451 | ftext += QString("Subject: %1\n") |
451 | .arg( m_mail[1] ); | 452 | .arg( m_mail[1] ); |
452 | 453 | ||
453 | ftext += QString("\n%1\n") | 454 | ftext += QString("\n%1\n") |
454 | .arg( m_mail[2]); | 455 | .arg( m_mail[2]); |
455 | 456 | ||
456 | ftext += QString("----- End forwarded message -----\n"); | 457 | ftext += QString("----- End forwarded message -----\n"); |
457 | 458 | ||
458 | Settings *settings = new Settings(); | 459 | Settings *settings = new Settings(); |
459 | ComposeMail composer( settings ,this, 0, true); | 460 | ComposeMail composer( settings ,this, 0, true); |
460 | composer.setSubject( "Fwd: " + m_mail[1] ); | 461 | composer.setSubject( "Fwd: " + m_mail[1] ); |
461 | composer.setMessage( ftext ); | 462 | composer.setMessage( ftext ); |
462 | if ( QDialog::Accepted == QPEApplication::execDialog( &composer )) | 463 | if ( QDialog::Accepted == QPEApplication::execDialog( &composer )) |
463 | { | 464 | { |
464 | } | 465 | } |
465 | } | 466 | } |
466 | 467 | ||
467 | void ViewMail::slotDeleteMail( ) | 468 | void ViewMail::slotDeleteMail( ) |
468 | { | 469 | { |
469 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) | 470 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) |
470 | { | 471 | { |
471 | m_recMail.Wrapper()->deleteMail( m_recMail ); | 472 | m_recMail.Wrapper()->deleteMail( m_recMail ); |
472 | hide(); | 473 | hide(); |
473 | deleted = true; | 474 | deleted = true; |
474 | } | 475 | } |
475 | } | 476 | } |