summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/accountview.cpp11
-rw-r--r--noncore/net/mail/accountview.h1
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.cpp13
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.h1
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp30
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h1
-rw-r--r--noncore/net/mail/mail.pro1
-rw-r--r--noncore/net/mail/mailistviewitem.cpp65
-rw-r--r--noncore/net/mail/mailistviewitem.h1
-rw-r--r--noncore/net/mail/mainwindow.cpp151
-rw-r--r--noncore/net/mail/mainwindow.h1
-rw-r--r--noncore/net/mail/opiemail.cpp119
-rw-r--r--noncore/net/mail/opiemail.h8
13 files changed, 263 insertions, 140 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp
index b7de7b9..9f4f358 100644
--- a/noncore/net/mail/accountview.cpp
+++ b/noncore/net/mail/accountview.cpp
@@ -1,891 +1,902 @@
1#include "accountview.h" 1#include "accountview.h"
2#include <libmailwrapper/mailtypes.h> 2#include <libmailwrapper/mailtypes.h>
3#include <libmailwrapper/abstractmail.h> 3#include <libmailwrapper/abstractmail.h>
4#include "defines.h" 4#include "defines.h"
5#include "newmaildir.h" 5#include "newmaildir.h"
6#include "selectstore.h" 6#include "selectstore.h"
7#include <qmessagebox.h> 7#include <qmessagebox.h>
8#include <qpopupmenu.h> 8#include <qpopupmenu.h>
9 9
10#define SETPIX(x) if (!account->getOffline()) {setPixmap( 0,x);} else {setPixmap( 0, PIXMAP_OFFLINE );} 10#define SETPIX(x) if (!account->getOffline()) {setPixmap( 0,x);} else {setPixmap( 0, PIXMAP_OFFLINE );}
11/** 11/**
12 * POP3 Account stuff 12 * POP3 Account stuff
13 */ 13 */
14POP3viewItem::POP3viewItem( POP3account *a, AccountView *parent ) 14POP3viewItem::POP3viewItem( POP3account *a, AccountView *parent )
15 : AccountViewItem( parent ) 15 : AccountViewItem( parent )
16{ 16{
17 account = a; 17 account = a;
18 wrapper = AbstractMail::getWrapper( account ); 18 wrapper = AbstractMail::getWrapper( account );
19 SETPIX(PIXMAP_POP3FOLDER); 19 SETPIX(PIXMAP_POP3FOLDER);
20#if 0 20#if 0
21 if (!account->getOffline()) { 21 if (!account->getOffline()) {
22 setPixmap( 0, ); 22 setPixmap( 0, );
23 } else { 23 } else {
24 setPixmap( 0, PIXMAP_OFFLINE ); 24 setPixmap( 0, PIXMAP_OFFLINE );
25 } 25 }
26#endif 26#endif
27 setText( 0, account->getAccountName() ); 27 setText( 0, account->getAccountName() );
28 setOpen( true ); 28 setOpen( true );
29} 29}
30 30
31POP3viewItem::~POP3viewItem() 31POP3viewItem::~POP3viewItem()
32{ 32{
33 delete wrapper; 33 delete wrapper;
34} 34}
35 35
36AbstractMail *POP3viewItem::getWrapper() 36AbstractMail *POP3viewItem::getWrapper()
37{ 37{
38 return wrapper; 38 return wrapper;
39} 39}
40 40
41void POP3viewItem::refresh( QList<RecMail> & ) 41void POP3viewItem::refresh( QList<RecMail> & )
42{ 42{
43 refresh(); 43 refresh();
44} 44}
45 45
46void POP3viewItem::refresh() 46void POP3viewItem::refresh()
47{ 47{
48 if (account->getOffline()) return; 48 if (account->getOffline()) return;
49 QList<Folder> *folders = wrapper->listFolders(); 49 QList<Folder> *folders = wrapper->listFolders();
50 QListViewItem *child = firstChild(); 50 QListViewItem *child = firstChild();
51 while ( child ) { 51 while ( child ) {
52 QListViewItem *tmp = child; 52 QListViewItem *tmp = child;
53 child = child->nextSibling(); 53 child = child->nextSibling();
54 delete tmp; 54 delete tmp;
55 } 55 }
56 Folder *it; 56 Folder *it;
57 QListViewItem*item = 0; 57 QListViewItem*item = 0;
58 for ( it = folders->first(); it; it = folders->next() ) { 58 for ( it = folders->first(); it; it = folders->next() ) {
59 item = new POP3folderItem( it, this , item ); 59 item = new POP3folderItem( it, this , item );
60 item->setSelectable(it->may_select()); 60 item->setSelectable(it->may_select());
61 } 61 }
62 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 62 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
63 folders->setAutoDelete(false); 63 folders->setAutoDelete(false);
64 delete folders; 64 delete folders;
65} 65}
66 66
67RecBody POP3viewItem::fetchBody( const RecMail &mail ) 67RecBody POP3viewItem::fetchBody( const RecMail &mail )
68{ 68{
69 qDebug( "POP3 fetchBody" ); 69 qDebug( "POP3 fetchBody" );
70 return wrapper->fetchBody( mail ); 70 return wrapper->fetchBody( mail );
71} 71}
72 72
73QPopupMenu * POP3viewItem::getContextMenu() 73QPopupMenu * POP3viewItem::getContextMenu()
74{ 74{
75 QPopupMenu *m = new QPopupMenu(0); 75 QPopupMenu *m = new QPopupMenu(0);
76 if (m) { 76 if (m) {
77 if (!account->getOffline()) { 77 if (!account->getOffline()) {
78 m->insertItem(QObject::tr("Disconnect",contextName),0); 78 m->insertItem(QObject::tr("Disconnect",contextName),0);
79 m->insertItem(QObject::tr("Set offline",contextName),1); 79 m->insertItem(QObject::tr("Set offline",contextName),1);
80 } else { 80 } else {
81 m->insertItem(QObject::tr("Set online",contextName),1); 81 m->insertItem(QObject::tr("Set online",contextName),1);
82 } 82 }
83 } 83 }
84 return m; 84 return m;
85} 85}
86 86
87void POP3viewItem::disconnect() 87void POP3viewItem::disconnect()
88{ 88{
89 QListViewItem *child = firstChild(); 89 QListViewItem *child = firstChild();
90 while ( child ) { 90 while ( child ) {
91 QListViewItem *tmp = child; 91 QListViewItem *tmp = child;
92 child = child->nextSibling(); 92 child = child->nextSibling();
93 delete tmp; 93 delete tmp;
94 } 94 }
95 wrapper->logout(); 95 wrapper->logout();
96} 96}
97 97
98void POP3viewItem::setOnOffline() 98void POP3viewItem::setOnOffline()
99{ 99{
100 if (!account->getOffline()) { 100 if (!account->getOffline()) {
101 disconnect(); 101 disconnect();
102 } 102 }
103 account->setOffline(!account->getOffline()); 103 account->setOffline(!account->getOffline());
104 account->save(); 104 account->save();
105 SETPIX(PIXMAP_POP3FOLDER); 105 SETPIX(PIXMAP_POP3FOLDER);
106 refresh(); 106 refresh();
107} 107}
108 108
109void POP3viewItem::contextMenuSelected(int which) 109void POP3viewItem::contextMenuSelected(int which)
110{ 110{
111 switch (which) { 111 switch (which) {
112 case 0: 112 case 0:
113 disconnect(); 113 disconnect();
114 break; 114 break;
115 case 1: 115 case 1:
116 setOnOffline(); 116 setOnOffline();
117 break; 117 break;
118 } 118 }
119} 119}
120 120
121POP3folderItem::~POP3folderItem() 121POP3folderItem::~POP3folderItem()
122{ 122{
123 delete folder; 123 delete folder;
124} 124}
125 125
126POP3folderItem::POP3folderItem( Folder *folderInit, POP3viewItem *parent , QListViewItem*after ) 126POP3folderItem::POP3folderItem( Folder *folderInit, POP3viewItem *parent , QListViewItem*after )
127 : AccountViewItem( parent,after ) 127 : AccountViewItem( parent,after )
128{ 128{
129 folder = folderInit; 129 folder = folderInit;
130 pop3 = parent; 130 pop3 = parent;
131 if (folder->getDisplayName().lower()!="inbox") { 131 if (folder->getDisplayName().lower()!="inbox") {
132 setPixmap( 0, PIXMAP_POP3FOLDER ); 132 setPixmap( 0, PIXMAP_POP3FOLDER );
133 } else { 133 } else {
134 setPixmap( 0, PIXMAP_INBOXFOLDER); 134 setPixmap( 0, PIXMAP_INBOXFOLDER);
135 } 135 }
136 setText( 0, folder->getDisplayName() ); 136 setText( 0, folder->getDisplayName() );
137} 137}
138 138
139void POP3folderItem::refresh(QList<RecMail>&target) 139void POP3folderItem::refresh(QList<RecMail>&target)
140{ 140{
141 if (folder->may_select()) 141 if (folder->may_select())
142 pop3->getWrapper()->listMessages( folder->getName(),target ); 142 pop3->getWrapper()->listMessages( folder->getName(),target );
143} 143}
144 144
145RecBody POP3folderItem::fetchBody(const RecMail&aMail) 145RecBody POP3folderItem::fetchBody(const RecMail&aMail)
146{ 146{
147 return pop3->getWrapper()->fetchBody(aMail); 147 return pop3->getWrapper()->fetchBody(aMail);
148} 148}
149 149
150QPopupMenu * POP3folderItem::getContextMenu() 150QPopupMenu * POP3folderItem::getContextMenu()
151{ 151{
152 QPopupMenu *m = new QPopupMenu(0); 152 QPopupMenu *m = new QPopupMenu(0);
153 if (m) { 153 if (m) {
154 m->insertItem(QObject::tr("Refresh header list",contextName),0); 154 m->insertItem(QObject::tr("Refresh header list",contextName),0);
155 m->insertItem(QObject::tr("Delete all mails",contextName),1); 155 m->insertItem(QObject::tr("Delete all mails",contextName),1);
156 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); 156 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2);
157 } 157 }
158 return m; 158 return m;
159} 159}
160 160
161void POP3folderItem::downloadMails() 161void POP3folderItem::downloadMails()
162{ 162{
163 AccountView*bl = pop3->accountView(); 163 AccountView*bl = pop3->accountView();
164 if (!bl) return; 164 if (!bl) return;
165 bl->downloadMails(folder,pop3->getWrapper()); 165 bl->downloadMails(folder,pop3->getWrapper());
166} 166}
167 167
168void POP3folderItem::contextMenuSelected(int which) 168void POP3folderItem::contextMenuSelected(int which)
169{ 169{
170 AccountView * view = (AccountView*)listView(); 170 AccountView * view = (AccountView*)listView();
171 switch (which) { 171 switch (which) {
172 case 0: 172 case 0:
173 /* must be 'cause pop3 lists are cached */ 173 /* must be 'cause pop3 lists are cached */
174 pop3->getWrapper()->logout(); 174 pop3->getWrapper()->logout();
175 view->refreshCurrent(); 175 view->refreshCurrent();
176 break; 176 break;
177 case 1: 177 case 1:
178 deleteAllMail(pop3->getWrapper(),folder); 178 deleteAllMail(pop3->getWrapper(),folder);
179 break; 179 break;
180 case 2: 180 case 2:
181 downloadMails(); 181 downloadMails();
182 break; 182 break;
183 default: 183 default:
184 break; 184 break;
185 } 185 }
186} 186}
187 187
188/** 188/**
189 * IMAP Account stuff 189 * IMAP Account stuff
190 */ 190 */
191IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent ) 191IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent )
192 : AccountViewItem( parent ) 192 : AccountViewItem( parent )
193{ 193{
194 account = a; 194 account = a;
195 wrapper = AbstractMail::getWrapper( account ); 195 wrapper = AbstractMail::getWrapper( account );
196 SETPIX(PIXMAP_IMAPFOLDER); 196 SETPIX(PIXMAP_IMAPFOLDER);
197 setText( 0, account->getAccountName() ); 197 setText( 0, account->getAccountName() );
198 setOpen( true ); 198 setOpen( true );
199} 199}
200 200
201IMAPviewItem::~IMAPviewItem() 201IMAPviewItem::~IMAPviewItem()
202{ 202{
203 delete wrapper; 203 delete wrapper;
204} 204}
205 205
206AbstractMail *IMAPviewItem::getWrapper() 206AbstractMail *IMAPviewItem::getWrapper()
207{ 207{
208 return wrapper; 208 return wrapper;
209} 209}
210 210
211IMAPfolderItem*IMAPviewItem::findSubItem(const QString&path,IMAPfolderItem*start) 211IMAPfolderItem*IMAPviewItem::findSubItem(const QString&path,IMAPfolderItem*start)
212{ 212{
213 IMAPfolderItem*pitem,*sitem; 213 IMAPfolderItem*pitem,*sitem;
214 if (!start) pitem = (IMAPfolderItem*)firstChild(); 214 if (!start) pitem = (IMAPfolderItem*)firstChild();
215 else pitem = (IMAPfolderItem*)start->firstChild(); 215 else pitem = (IMAPfolderItem*)start->firstChild();
216 while (pitem) { 216 while (pitem) {
217 if (pitem->matchName(path)) { 217 if (pitem->matchName(path)) {
218 break; 218 break;
219 } 219 }
220 if (pitem->childCount()>0) { 220 if (pitem->childCount()>0) {
221 sitem = findSubItem(path,pitem); 221 sitem = findSubItem(path,pitem);
222 if (sitem) { 222 if (sitem) {
223 pitem = sitem; 223 pitem = sitem;
224 break; 224 break;
225 } 225 }
226 } 226 }
227 pitem=(IMAPfolderItem*)pitem->nextSibling(); 227 pitem=(IMAPfolderItem*)pitem->nextSibling();
228 } 228 }
229 return pitem; 229 return pitem;
230} 230}
231 231
232void IMAPviewItem::refresh(QList<RecMail>&) 232void IMAPviewItem::refresh(QList<RecMail>&)
233{ 233{
234 refreshFolders(false); 234 refreshFolders(false);
235} 235}
236 236
237void IMAPviewItem::removeChilds() 237void IMAPviewItem::removeChilds()
238{ 238{
239 QListViewItem *child = firstChild(); 239 QListViewItem *child = firstChild();
240 while ( child ) { 240 while ( child ) {
241 QListViewItem *tmp = child; 241 QListViewItem *tmp = child;
242 child = child->nextSibling(); 242 child = child->nextSibling();
243 delete tmp; 243 delete tmp;
244 } 244 }
245 245
246} 246}
247 247
248const QStringList&IMAPviewItem::subFolders() 248const QStringList&IMAPviewItem::subFolders()
249{ 249{
250 return currentFolders; 250 return currentFolders;
251} 251}
252 252
253void IMAPviewItem::refreshFolders(bool force) 253void IMAPviewItem::refreshFolders(bool force)
254{ 254{
255 if (childCount()>0 && force==false) return; 255 if (childCount()>0 && force==false) return;
256 if (account->getOffline()) return; 256 if (account->getOffline()) return;
257 257
258 removeChilds(); 258 removeChilds();
259 currentFolders.clear(); 259 currentFolders.clear();
260 QList<Folder> *folders = wrapper->listFolders(); 260 QList<Folder> *folders = wrapper->listFolders();
261 261
262 Folder *it; 262 Folder *it;
263 QListViewItem*item = 0; 263 QListViewItem*item = 0;
264 QListViewItem*titem = 0; 264 QListViewItem*titem = 0;
265 QString fname,del,search; 265 QString fname,del,search;
266 int pos; 266 int pos;
267 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 267 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
268 folders->setAutoDelete(false); 268 folders->setAutoDelete(false);
269 269
270 for ( it = folders->first(); it; it = folders->next() ) { 270 for ( it = folders->first(); it; it = folders->next() ) {
271 if (it->getDisplayName().lower()=="inbox") { 271 if (it->getDisplayName().lower()=="inbox") {
272 item = new IMAPfolderItem( it, this , item ); 272 item = new IMAPfolderItem( it, this , item );
273 folders->remove(it); 273 folders->remove(it);
274 qDebug("inbox found"); 274 qDebug("inbox found");
275 break; 275 break;
276 } 276 }
277 } 277 }
278 for ( it = folders->first(); it; it = folders->next() ) { 278 for ( it = folders->first(); it; it = folders->next() ) {
279 fname = it->getDisplayName(); 279 fname = it->getDisplayName();
280 currentFolders.append(it->getName()); 280 currentFolders.append(it->getName());
281 pos = fname.findRev(it->Separator()); 281 pos = fname.findRev(it->Separator());
282 if (pos != -1) { 282 if (pos != -1) {
283 fname = fname.left(pos); 283 fname = fname.left(pos);
284 } 284 }
285 IMAPfolderItem*pitem = findSubItem(fname); 285 IMAPfolderItem*pitem = findSubItem(fname);
286 if (pitem) { 286 if (pitem) {
287 titem = item; 287 titem = item;
288 item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this); 288 item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this);
289 /* setup the short name */ 289 /* setup the short name */
290 item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1)); 290 item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1));
291 item = titem; 291 item = titem;
292 } else { 292 } else {
293 item = new IMAPfolderItem( it, this , item ); 293 item = new IMAPfolderItem( it, this , item );
294 } 294 }
295 } 295 }
296 delete folders; 296 delete folders;
297} 297}
298 298
299QPopupMenu * IMAPviewItem::getContextMenu() 299QPopupMenu * IMAPviewItem::getContextMenu()
300{ 300{
301 QPopupMenu *m = new QPopupMenu(0); 301 QPopupMenu *m = new QPopupMenu(0);
302 if (m) { 302 if (m) {
303 if (!account->getOffline()) { 303 if (!account->getOffline()) {
304 m->insertItem(QObject::tr("Refresh folder list",contextName),0); 304 m->insertItem(QObject::tr("Refresh folder list",contextName),0);
305 m->insertItem(QObject::tr("Create new folder",contextName),1); 305 m->insertItem(QObject::tr("Create new folder",contextName),1);
306 m->insertSeparator(); 306 m->insertSeparator();
307 m->insertItem(QObject::tr("Disconnect",contextName),2); 307 m->insertItem(QObject::tr("Disconnect",contextName),2);
308 m->insertItem(QObject::tr("Set offline",contextName),3); 308 m->insertItem(QObject::tr("Set offline",contextName),3);
309 } else { 309 } else {
310 m->insertItem(QObject::tr("Set online",contextName),3); 310 m->insertItem(QObject::tr("Set online",contextName),3);
311 } 311 }
312 } 312 }
313 return m; 313 return m;
314} 314}
315 315
316void IMAPviewItem::createNewFolder() 316void IMAPviewItem::createNewFolder()
317{ 317{
318 Newmdirdlg ndirdlg; 318 Newmdirdlg ndirdlg;
319 ndirdlg.showMaximized(); 319 ndirdlg.showMaximized();
320 if (ndirdlg.exec()) { 320 if (ndirdlg.exec()) {
321 QString ndir = ndirdlg.Newdir(); 321 QString ndir = ndirdlg.Newdir();
322 bool makesubs = ndirdlg.subpossible(); 322 bool makesubs = ndirdlg.subpossible();
323 QString delemiter = "/"; 323 QString delemiter = "/";
324 IMAPfolderItem*item = (IMAPfolderItem*)firstChild(); 324 IMAPfolderItem*item = (IMAPfolderItem*)firstChild();
325 if (item) { 325 if (item) {
326 delemiter = item->Delemiter(); 326 delemiter = item->Delemiter();
327 } 327 }
328 if (wrapper->createMbox(ndir,0,delemiter,makesubs)) { 328 if (wrapper->createMbox(ndir,0,delemiter,makesubs)) {
329 refreshFolders(true); 329 refreshFolders(true);
330 } 330 }
331 } 331 }
332} 332}
333 333
334void IMAPviewItem::contextMenuSelected(int id) 334void IMAPviewItem::contextMenuSelected(int id)
335{ 335{
336 qDebug("Id selected: %i",id); 336 qDebug("Id selected: %i",id);
337 switch (id) { 337 switch (id) {
338 case 0: 338 case 0:
339 refreshFolders(true); 339 refreshFolders(true);
340 break; 340 break;
341 case 1: 341 case 1:
342 createNewFolder(); 342 createNewFolder();
343 break; 343 break;
344 case 2: 344 case 2:
345 removeChilds(); 345 removeChilds();
346 wrapper->logout(); 346 wrapper->logout();
347 break; 347 break;
348 case 3: 348 case 3:
349 if (account->getOffline()==false) { 349 if (account->getOffline()==false) {
350 removeChilds(); 350 removeChilds();
351 wrapper->logout(); 351 wrapper->logout();
352 } 352 }
353 account->setOffline(!account->getOffline()); 353 account->setOffline(!account->getOffline());
354 account->save(); 354 account->save();
355 SETPIX(PIXMAP_IMAPFOLDER); 355 SETPIX(PIXMAP_IMAPFOLDER);
356 refreshFolders(false); 356 refreshFolders(false);
357 break; 357 break;
358 default: 358 default:
359 break; 359 break;
360 } 360 }
361} 361}
362 362
363RecBody IMAPviewItem::fetchBody(const RecMail&) 363RecBody IMAPviewItem::fetchBody(const RecMail&)
364{ 364{
365 return RecBody(); 365 return RecBody();
366} 366}
367 367
368bool IMAPviewItem::offline() 368bool IMAPviewItem::offline()
369{ 369{
370 return account->getOffline(); 370 return account->getOffline();
371} 371}
372 372
373IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after ) 373IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after )
374 : AccountViewItem( parent , after ) 374 : AccountViewItem( parent , after )
375{ 375{
376 folder = folderInit; 376 folder = folderInit;
377 imap = parent; 377 imap = parent;
378 if (folder->getDisplayName().lower()!="inbox") { 378 if (folder->getDisplayName().lower()!="inbox") {
379 setPixmap( 0, PIXMAP_IMAPFOLDER ); 379 setPixmap( 0, PIXMAP_IMAPFOLDER );
380 } else { 380 } else {
381 setPixmap( 0, PIXMAP_INBOXFOLDER); 381 setPixmap( 0, PIXMAP_INBOXFOLDER);
382 } 382 }
383 setText( 0, folder->getDisplayName() ); 383 setText( 0, folder->getDisplayName() );
384} 384}
385 385
386IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ) 386IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master )
387 : AccountViewItem( parent,after ) 387 : AccountViewItem( parent,after )
388{ 388{
389 folder = folderInit; 389 folder = folderInit;
390 imap = master; 390 imap = master;
391 if (folder->getDisplayName().lower()!="inbox") { 391 if (folder->getDisplayName().lower()!="inbox") {
392 setPixmap( 0, PIXMAP_IMAPFOLDER ); 392 setPixmap( 0, PIXMAP_IMAPFOLDER );
393 } else { 393 } else {
394 setPixmap( 0, PIXMAP_INBOXFOLDER); 394 setPixmap( 0, PIXMAP_INBOXFOLDER);
395 } 395 }
396 setText( 0, folder->getDisplayName() ); 396 setText( 0, folder->getDisplayName() );
397} 397}
398 398
399IMAPfolderItem::~IMAPfolderItem() 399IMAPfolderItem::~IMAPfolderItem()
400{ 400{
401 delete folder; 401 delete folder;
402} 402}
403 403
404const QString& IMAPfolderItem::Delemiter()const 404const QString& IMAPfolderItem::Delemiter()const
405{ 405{
406 return folder->Separator(); 406 return folder->Separator();
407} 407}
408 408
409bool IMAPfolderItem::matchName(const QString&name)const 409bool IMAPfolderItem::matchName(const QString&name)const
410{ 410{
411 return folder->getDisplayName()==name; 411 return folder->getDisplayName()==name;
412} 412}
413 413
414void IMAPfolderItem::refresh(QList<RecMail>&target) 414void IMAPfolderItem::refresh(QList<RecMail>&target)
415{ 415{
416 if (folder->may_select()) { 416 if (folder->may_select()) {
417 imap->getWrapper()->listMessages( folder->getName(),target ); 417 imap->getWrapper()->listMessages( folder->getName(),target );
418 } else { 418 } else {
419 target.clear(); 419 target.clear();
420 } 420 }
421} 421}
422 422
423RecBody IMAPfolderItem::fetchBody(const RecMail&aMail) 423RecBody IMAPfolderItem::fetchBody(const RecMail&aMail)
424{ 424{
425 return imap->getWrapper()->fetchBody(aMail); 425 return imap->getWrapper()->fetchBody(aMail);
426} 426}
427 427
428QPopupMenu * IMAPfolderItem::getContextMenu() 428QPopupMenu * IMAPfolderItem::getContextMenu()
429{ 429{
430 QPopupMenu *m = new QPopupMenu(0); 430 QPopupMenu *m = new QPopupMenu(0);
431 if (m) { 431 if (m) {
432 if (folder->may_select()) { 432 if (folder->may_select()) {
433 m->insertItem(QObject::tr("Refresh header list",contextName),0); 433 m->insertItem(QObject::tr("Refresh header list",contextName),0);
434 m->insertItem(QObject::tr("Move/Copie all mails",contextName),4); 434 m->insertItem(QObject::tr("Move/Copie all mails",contextName),4);
435 m->insertItem(QObject::tr("Delete all mails",contextName),1); 435 m->insertItem(QObject::tr("Delete all mails",contextName),1);
436 } 436 }
437 if (folder->no_inferior()==false) { 437 if (folder->no_inferior()==false) {
438 m->insertItem(QObject::tr("Create new subfolder",contextName),2); 438 m->insertItem(QObject::tr("Create new subfolder",contextName),2);
439 } 439 }
440 if (folder->getDisplayName().lower()!="inbox") { 440 if (folder->getDisplayName().lower()!="inbox") {
441 m->insertItem(QObject::tr("Delete folder",contextName),3); 441 m->insertItem(QObject::tr("Delete folder",contextName),3);
442 } 442 }
443 } 443 }
444 return m; 444 return m;
445} 445}
446 446
447void IMAPfolderItem::createNewFolder() 447void IMAPfolderItem::createNewFolder()
448{ 448{
449 Newmdirdlg ndirdlg; 449 Newmdirdlg ndirdlg;
450 ndirdlg.showMaximized(); 450 ndirdlg.showMaximized();
451 if (ndirdlg.exec()) { 451 if (ndirdlg.exec()) {
452 QString ndir = ndirdlg.Newdir(); 452 QString ndir = ndirdlg.Newdir();
453 bool makesubs = ndirdlg.subpossible(); 453 bool makesubs = ndirdlg.subpossible();
454 QString delemiter = Delemiter(); 454 QString delemiter = Delemiter();
455 if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) { 455 if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) {
456 imap->refreshFolders(true); 456 imap->refreshFolders(true);
457 } 457 }
458 } 458 }
459} 459}
460 460
461void IMAPfolderItem::deleteFolder() 461void IMAPfolderItem::deleteFolder()
462{ 462{
463 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), 463 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
464 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), 464 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()),
465 QObject::tr("Yes",contextName), 465 QObject::tr("Yes",contextName),
466 QObject::tr("No",contextName),QString::null,1,1); 466 QObject::tr("No",contextName),QString::null,1,1);
467 qDebug("Auswahl: %i",yesno); 467 qDebug("Auswahl: %i",yesno);
468 if (yesno == 0) { 468 if (yesno == 0) {
469 if (imap->getWrapper()->deleteMbox(folder)) { 469 if (imap->getWrapper()->deleteMbox(folder)) {
470 QListView*v=listView(); 470 QListView*v=listView();
471 IMAPviewItem * box = imap; 471 IMAPviewItem * box = imap;
472 /* be carefull - after that this object is destroyd so don't use 472 /* be carefull - after that this object is destroyd so don't use
473 * any member of it after that call!!*/ 473 * any member of it after that call!!*/
474 imap->refreshFolders(true); 474 imap->refreshFolders(true);
475 if (v) { 475 if (v) {
476 v->setSelected(box,true); 476 v->setSelected(box,true);
477 } 477 }
478 } 478 }
479 } 479 }
480} 480}
481 481
482void IMAPfolderItem::downloadMails() 482void IMAPfolderItem::downloadMails()
483{ 483{
484 AccountView*bl = imap->accountView(); 484 AccountView*bl = imap->accountView();
485 if (!bl) return; 485 if (!bl) return;
486 bl->downloadMails(folder,imap->getWrapper()); 486 bl->downloadMails(folder,imap->getWrapper());
487} 487}
488 488
489void IMAPfolderItem::contextMenuSelected(int id) 489void IMAPfolderItem::contextMenuSelected(int id)
490{ 490{
491 qDebug("Selected id: %i",id); 491 qDebug("Selected id: %i",id);
492 AccountView * view = (AccountView*)listView(); 492 AccountView * view = (AccountView*)listView();
493 switch(id) { 493 switch(id) {
494 case 0: 494 case 0:
495 view->refreshCurrent(); 495 view->refreshCurrent();
496 break; 496 break;
497 case 1: 497 case 1:
498 deleteAllMail(imap->getWrapper(),folder); 498 deleteAllMail(imap->getWrapper(),folder);
499 break; 499 break;
500 case 2: 500 case 2:
501 createNewFolder(); 501 createNewFolder();
502 break; 502 break;
503 case 3: 503 case 3:
504 deleteFolder(); 504 deleteFolder();
505 break; 505 break;
506 case 4: 506 case 4:
507 downloadMails(); 507 downloadMails();
508 break; 508 break;
509 default: 509 default:
510 break; 510 break;
511 } 511 }
512} 512}
513 513
514/** 514/**
515 * Generic stuff 515 * Generic stuff
516 */ 516 */
517 517
518const QString AccountViewItem::contextName="AccountViewItem"; 518const QString AccountViewItem::contextName="AccountViewItem";
519 519
520AccountViewItem::AccountViewItem( AccountView *parent ) 520AccountViewItem::AccountViewItem( AccountView *parent )
521 : QListViewItem( parent ) 521 : QListViewItem( parent )
522{ 522{
523 m_Backlink = parent; 523 m_Backlink = parent;
524} 524}
525 525
526AccountViewItem::AccountViewItem( QListViewItem *parent) 526AccountViewItem::AccountViewItem( QListViewItem *parent)
527 : QListViewItem( parent) 527 : QListViewItem( parent)
528{ 528{
529 m_Backlink = 0; 529 m_Backlink = 0;
530} 530}
531 531
532AccountViewItem::AccountViewItem( QListViewItem *parent , QListViewItem*after ) 532AccountViewItem::AccountViewItem( QListViewItem *parent , QListViewItem*after )
533 :QListViewItem( parent,after ) 533 :QListViewItem( parent,after )
534{ 534{
535 m_Backlink = 0; 535 m_Backlink = 0;
536} 536}
537 537
538AccountViewItem::~AccountViewItem() 538AccountViewItem::~AccountViewItem()
539{ 539{
540} 540}
541 541
542AccountView*AccountViewItem::accountView() 542AccountView*AccountViewItem::accountView()
543{ 543{
544 return m_Backlink; 544 return m_Backlink;
545} 545}
546 546
547void AccountViewItem::deleteAllMail(AbstractMail*wrapper,Folder*folder) 547void AccountViewItem::deleteAllMail(AbstractMail*wrapper,Folder*folder)
548{ 548{
549 if (!wrapper) return; 549 if (!wrapper) return;
550 QString fname=""; 550 QString fname="";
551 if (folder) fname = folder->getDisplayName(); 551 if (folder) fname = folder->getDisplayName();
552 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName), 552 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName),
553 QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName). 553 QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName).
554 arg(fname), 554 arg(fname),
555 QObject::tr("Yes",contextName), 555 QObject::tr("Yes",contextName),
556 QObject::tr("No",contextName),QString::null,1,1); 556 QObject::tr("No",contextName),QString::null,1,1);
557 qDebug("Auswahl: %i",yesno); 557 qDebug("Auswahl: %i",yesno);
558 if (yesno == 0) { 558 if (yesno == 0) {
559 if (wrapper->deleteAllMail(folder)) { 559 if (wrapper->deleteAllMail(folder)) {
560 AccountView * view = (AccountView*)listView(); 560 AccountView * view = (AccountView*)listView();
561 if (view) view->refreshCurrent(); 561 if (view) view->refreshCurrent();
562 } 562 }
563 } 563 }
564} 564}
565 565
566AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) 566AccountView::AccountView( QWidget *parent, const char *name, WFlags flags )
567 : QListView( parent, name, flags ) 567 : QListView( parent, name, flags )
568{ 568{
569 connect( this, SIGNAL( selectionChanged( QListViewItem * ) ), 569 connect( this, SIGNAL( selectionChanged( QListViewItem * ) ),
570 SLOT( refresh( QListViewItem * ) ) ); 570 SLOT( refresh( QListViewItem * ) ) );
571 connect( this, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this, 571 connect( this, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this,
572 SLOT( slotHold( int, QListViewItem *,const QPoint&,int ) ) ); 572 SLOT( slotHold( int, QListViewItem *,const QPoint&,int ) ) );
573 573
574 setSorting(0); 574 setSorting(0);
575} 575}
576 576
577AccountView::~AccountView() 577AccountView::~AccountView()
578{ 578{
579 imapAccounts.clear(); 579 imapAccounts.clear();
580 mboxAccounts.clear(); 580 mboxAccounts.clear();
581} 581}
582 582
583void AccountView::slotContextMenu(int id) 583void AccountView::slotContextMenu(int id)
584{ 584{
585 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); 585 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem());
586 if (!view) return; 586 if (!view) return;
587 view->contextMenuSelected(id); 587 view->contextMenuSelected(id);
588} 588}
589 589
590void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int) 590void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int)
591{ 591{
592 if (button==1) {return;} 592 if (button==1) {return;}
593 if (!item) return; 593 if (!item) return;
594 AccountViewItem *view = static_cast<AccountViewItem *>(item); 594 AccountViewItem *view = static_cast<AccountViewItem *>(item);
595 QPopupMenu*m = view->getContextMenu(); 595 QPopupMenu*m = view->getContextMenu();
596 if (!m) return; 596 if (!m) return;
597 connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int))); 597 connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int)));
598 m->setFocus(); 598 m->setFocus();
599 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); 599 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
600 delete m; 600 delete m;
601} 601}
602 602
603void AccountView::populate( QList<Account> list ) 603void AccountView::populate( QList<Account> list )
604{ 604{
605 clear(); 605 clear();
606 606
607 imapAccounts.clear(); 607 imapAccounts.clear();
608 mboxAccounts.clear(); 608 mboxAccounts.clear();
609 609
610 mboxAccounts.append(new MBOXviewItem(AbstractMail::defaultLocalfolder(),this)); 610 mboxAccounts.append(new MBOXviewItem(AbstractMail::defaultLocalfolder(),this));
611 611
612 Account *it; 612 Account *it;
613 for ( it = list.first(); it; it = list.next() ) { 613 for ( it = list.first(); it; it = list.next() ) {
614 if ( it->getType().compare( "IMAP" ) == 0 ) { 614 if ( it->getType().compare( "IMAP" ) == 0 ) {
615 IMAPaccount *imap = static_cast<IMAPaccount *>(it); 615 IMAPaccount *imap = static_cast<IMAPaccount *>(it);
616 qDebug( "added IMAP " + imap->getAccountName() ); 616 qDebug( "added IMAP " + imap->getAccountName() );
617 imapAccounts.append(new IMAPviewItem( imap, this )); 617 imapAccounts.append(new IMAPviewItem( imap, this ));
618 } else if ( it->getType().compare( "POP3" ) == 0 ) { 618 } else if ( it->getType().compare( "POP3" ) == 0 ) {
619 POP3account *pop3 = static_cast<POP3account *>(it); 619 POP3account *pop3 = static_cast<POP3account *>(it);
620 qDebug( "added POP3 " + pop3->getAccountName() ); 620 qDebug( "added POP3 " + pop3->getAccountName() );
621 /* must not be hold 'cause it isn't required */ 621 /* must not be hold 'cause it isn't required */
622 (void) new POP3viewItem( pop3, this ); 622 (void) new POP3viewItem( pop3, this );
623 } 623 }
624 } 624 }
625} 625}
626 626
627void AccountView::refresh(QListViewItem *item) { 627void AccountView::refresh(QListViewItem *item) {
628 628
629 qDebug("AccountView refresh..."); 629 qDebug("AccountView refresh...");
630 if ( item ) { 630 if ( item ) {
631 m_currentItem = item; 631 m_currentItem = item;
632 QList<RecMail> headerlist; 632 QList<RecMail> headerlist;
633 headerlist.setAutoDelete(true); 633 headerlist.setAutoDelete(true);
634 AccountViewItem *view = static_cast<AccountViewItem *>(item); 634 AccountViewItem *view = static_cast<AccountViewItem *>(item);
635 view->refresh(headerlist); 635 view->refresh(headerlist);
636 emit refreshMailview(&headerlist); 636 emit refreshMailview(&headerlist);
637 } 637 }
638} 638}
639 639
640void AccountView::refreshCurrent() 640void AccountView::refreshCurrent()
641{ 641{
642 m_currentItem = currentItem(); 642 m_currentItem = currentItem();
643 if ( !m_currentItem ) return; 643 if ( !m_currentItem ) return;
644 QList<RecMail> headerlist; 644 QList<RecMail> headerlist;
645 headerlist.setAutoDelete(true); 645 headerlist.setAutoDelete(true);
646 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); 646 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem);
647 view->refresh(headerlist); 647 view->refresh(headerlist);
648 emit refreshMailview(&headerlist); 648 emit refreshMailview(&headerlist);
649} 649}
650 650
651void AccountView::refreshAll() 651void AccountView::refreshAll()
652{ 652{
653 653
654} 654}
655 655
656RecBody AccountView::fetchBody(const RecMail&aMail) 656RecBody AccountView::fetchBody(const RecMail&aMail)
657{ 657{
658 QListViewItem*item = selectedItem (); 658 QListViewItem*item = selectedItem ();
659 if (!item) return RecBody(); 659 if (!item) return RecBody();
660 AccountViewItem *view = static_cast<AccountViewItem *>(item); 660 AccountViewItem *view = static_cast<AccountViewItem *>(item);
661 return view->fetchBody(aMail); 661 return view->fetchBody(aMail);
662} 662}
663 663
664void AccountView::setupFolderselect(Selectstore*sels) 664void AccountView::setupFolderselect(Selectstore*sels)
665{ 665{
666 sels->showMaximized(); 666 sels->showMaximized();
667 QStringList sFolders; 667 QStringList sFolders;
668 unsigned int i = 0; 668 unsigned int i = 0;
669 for (i=0; i < mboxAccounts.count();++i) { 669 for (i=0; i < mboxAccounts.count();++i) {
670 mboxAccounts[i]->refresh(false); 670 mboxAccounts[i]->refresh(false);
671 sFolders = mboxAccounts[i]->subFolders(); 671 sFolders = mboxAccounts[i]->subFolders();
672 sels->addAccounts(mboxAccounts[i]->getWrapper(),sFolders); 672 sels->addAccounts(mboxAccounts[i]->getWrapper(),sFolders);
673 } 673 }
674 for (i=0; i < imapAccounts.count();++i) { 674 for (i=0; i < imapAccounts.count();++i) {
675 if (imapAccounts[i]->offline()) 675 if (imapAccounts[i]->offline())
676 continue; 676 continue;
677 imapAccounts[i]->refreshFolders(false); 677 imapAccounts[i]->refreshFolders(false);
678 sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders()); 678 sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders());
679 } 679 }
680} 680}
681 681
682void AccountView::downloadMails(Folder*fromFolder,AbstractMail*fromWrapper) 682void AccountView::downloadMails(Folder*fromFolder,AbstractMail*fromWrapper)
683{ 683{
684 AbstractMail*targetMail = 0; 684 AbstractMail*targetMail = 0;
685 QString targetFolder = ""; 685 QString targetFolder = "";
686 Selectstore sels; 686 Selectstore sels;
687 setupFolderselect(&sels); 687 setupFolderselect(&sels);
688 if (!sels.exec()) return; 688 if (!sels.exec()) return;
689 targetMail = sels.currentMail(); 689 targetMail = sels.currentMail();
690 targetFolder = sels.currentFolder(); 690 targetFolder = sels.currentFolder();
691 if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) || 691 if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) ||
692 targetFolder.isEmpty()) { 692 targetFolder.isEmpty()) {
693 return; 693 return;
694 } 694 }
695 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) { 695 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) {
696 QMessageBox::critical(0,tr("Error creating new Folder"), 696 QMessageBox::critical(0,tr("Error creating new Folder"),
697 tr("<center>Error while creating<br>new folder - breaking.</center>")); 697 tr("<center>Error while creating<br>new folder - breaking.</center>"));
698 return; 698 return;
699 } 699 }
700 qDebug("Targetfolder: %s",targetFolder.latin1()); 700 qDebug("Targetfolder: %s",targetFolder.latin1());
701 qDebug("Fromfolder: %s",fromFolder->getName().latin1()); 701 qDebug("Fromfolder: %s",fromFolder->getName().latin1());
702 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails()); 702 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails());
703 refreshCurrent(); 703 refreshCurrent();
704} 704}
705 705
706/** 706/**
707 * MBOX Account stuff 707 * MBOX Account stuff
708 */ 708 */
709 709
710MBOXviewItem::MBOXviewItem( const QString&aPath, AccountView *parent ) 710MBOXviewItem::MBOXviewItem( const QString&aPath, AccountView *parent )
711 : AccountViewItem( parent ) 711 : AccountViewItem( parent )
712{ 712{
713 m_Path = aPath; 713 m_Path = aPath;
714 /* be carefull - the space within settext is wanted - thats why the string twice */ 714 /* be carefull - the space within settext is wanted - thats why the string twice */
715 wrapper = AbstractMail::getWrapper( m_Path,"Local Folders"); 715 wrapper = AbstractMail::getWrapper( m_Path,"Local Folders");
716 setPixmap( 0, PIXMAP_LOCALFOLDER ); 716 setPixmap( 0, PIXMAP_LOCALFOLDER );
717 setText( 0, " Local Folders" ); 717 setText( 0, " Local Folders" );
718 setOpen( true ); 718 setOpen( true );
719} 719}
720 720
721MBOXviewItem::~MBOXviewItem() 721MBOXviewItem::~MBOXviewItem()
722{ 722{
723 delete wrapper; 723 delete wrapper;
724} 724}
725 725
726AbstractMail *MBOXviewItem::getWrapper() 726AbstractMail *MBOXviewItem::getWrapper()
727{ 727{
728 return wrapper; 728 return wrapper;
729} 729}
730 730
731void MBOXviewItem::refresh( QList<RecMail> & ) 731void MBOXviewItem::refresh( QList<RecMail> & )
732{ 732{
733 refresh(false); 733 refresh(false);
734} 734}
735 735
736void MBOXviewItem::refresh(bool force) 736void MBOXviewItem::refresh(bool force)
737{ 737{
738 if (childCount()>0 && force==false) return; 738 if (childCount()>0 && force==false) return;
739 QList<Folder> *folders = wrapper->listFolders(); 739 QList<Folder> *folders = wrapper->listFolders();
740 QListViewItem *child = firstChild(); 740 QListViewItem *child = firstChild();
741 while ( child ) { 741 while ( child ) {
742 QListViewItem *tmp = child; 742 QListViewItem *tmp = child;
743 child = child->nextSibling(); 743 child = child->nextSibling();
744 delete tmp; 744 delete tmp;
745 } 745 }
746 Folder *it; 746 Folder *it;
747 QListViewItem*item = 0; 747 QListViewItem*item = 0;
748 for ( it = folders->first(); it; it = folders->next() ) { 748 for ( it = folders->first(); it; it = folders->next() ) {
749 item = new MBOXfolderItem( it, this , item ); 749 item = new MBOXfolderItem( it, this , item );
750 item->setSelectable(it->may_select()); 750 item->setSelectable(it->may_select());
751 } 751 }
752 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 752 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
753 folders->setAutoDelete(false); 753 folders->setAutoDelete(false);
754 delete folders; 754 delete folders;
755} 755}
756 756
757RecBody MBOXviewItem::fetchBody( const RecMail &mail ) 757RecBody MBOXviewItem::fetchBody( const RecMail &mail )
758{ 758{
759 qDebug( "MBOX fetchBody" ); 759 qDebug( "MBOX fetchBody" );
760 return wrapper->fetchBody( mail ); 760 return wrapper->fetchBody( mail );
761} 761}
762 762
763QPopupMenu * MBOXviewItem::getContextMenu() 763QPopupMenu * MBOXviewItem::getContextMenu()
764{ 764{
765 QPopupMenu *m = new QPopupMenu(0); 765 QPopupMenu *m = new QPopupMenu(0);
766 if (m) { 766 if (m) {
767 m->insertItem(QObject::tr("Refresh folder list",contextName),0); 767 m->insertItem(QObject::tr("Refresh folder list",contextName),0);
768 m->insertItem(QObject::tr("Create new folder",contextName),1); 768 m->insertItem(QObject::tr("Create new folder",contextName),1);
769 } 769 }
770 return m; 770 return m;
771} 771}
772 772
773void MBOXviewItem::createFolder() 773void MBOXviewItem::createFolder()
774{ 774{
775 Newmdirdlg ndirdlg(0,0,true); 775 Newmdirdlg ndirdlg(0,0,true);
776 ndirdlg.showMaximized(); 776 ndirdlg.showMaximized();
777 if (ndirdlg.exec()) { 777 if (ndirdlg.exec()) {
778 QString ndir = ndirdlg.Newdir(); 778 QString ndir = ndirdlg.Newdir();
779 if (wrapper->createMbox(ndir)) { 779 if (wrapper->createMbox(ndir)) {
780 refresh(true); 780 refresh(true);
781 } 781 }
782 } 782 }
783} 783}
784 784
785QStringList MBOXviewItem::subFolders() 785QStringList MBOXviewItem::subFolders()
786{ 786{
787 QStringList result; 787 QStringList result;
788 QListViewItem *child = firstChild(); 788 QListViewItem *child = firstChild();
789 while ( child ) { 789 while ( child ) {
790 MBOXfolderItem *tmp = (MBOXfolderItem*)child; 790 MBOXfolderItem *tmp = (MBOXfolderItem*)child;
791 child = child->nextSibling(); 791 child = child->nextSibling();
792 result.append(tmp->getFolder()->getName()); 792 result.append(tmp->getFolder()->getName());
793 } 793 }
794 qDebug("Size of result: %i",result.count()); 794 qDebug("Size of result: %i",result.count());
795 return result; 795 return result;
796} 796}
797 797
798void MBOXviewItem::contextMenuSelected(int which) 798void MBOXviewItem::contextMenuSelected(int which)
799{ 799{
800 switch (which) { 800 switch (which) {
801 case 0: 801 case 0:
802 refresh(true); 802 refresh(true);
803 break; 803 break;
804 case 1: 804 case 1:
805 createFolder(); 805 createFolder();
806 break; 806 break;
807 default: 807 default:
808 break; 808 break;
809 } 809 }
810} 810}
811 811
812MBOXfolderItem::~MBOXfolderItem() 812MBOXfolderItem::~MBOXfolderItem()
813{ 813{
814 delete folder; 814 delete folder;
815} 815}
816 816
817MBOXfolderItem::MBOXfolderItem( Folder *folderInit, MBOXviewItem *parent , QListViewItem*after ) 817MBOXfolderItem::MBOXfolderItem( Folder *folderInit, MBOXviewItem *parent , QListViewItem*after )
818 : AccountViewItem( parent,after ) 818 : AccountViewItem( parent,after )
819{ 819{
820 folder = folderInit; 820 folder = folderInit;
821 mbox = parent; 821 mbox = parent;
822 if (folder->getDisplayName().lower() == "outgoing") { 822 if (folder->getDisplayName().lower() == "outgoing") {
823 setPixmap( 0, PIXMAP_OUTBOXFOLDER ); 823 setPixmap( 0, PIXMAP_OUTBOXFOLDER );
824 } else if (folder->getDisplayName().lower() == "inbox") { 824 } else if (folder->getDisplayName().lower() == "inbox") {
825 setPixmap( 0, PIXMAP_INBOXFOLDER); 825 setPixmap( 0, PIXMAP_INBOXFOLDER);
826 } else { 826 } else {
827 setPixmap( 0, PIXMAP_MBOXFOLDER ); 827 setPixmap( 0, PIXMAP_MBOXFOLDER );
828 } 828 }
829 setText( 0, folder->getDisplayName() ); 829 setText( 0, folder->getDisplayName() );
830} 830}
831 831
832Folder*MBOXfolderItem::getFolder() 832Folder*MBOXfolderItem::getFolder()
833{ 833{
834 return folder; 834 return folder;
835} 835}
836 836
837void MBOXfolderItem::refresh(QList<RecMail>&target) 837void MBOXfolderItem::refresh(QList<RecMail>&target)
838{ 838{
839 if (folder->may_select()) 839 if (folder->may_select())
840 mbox->getWrapper()->listMessages( folder->getName(),target ); 840 mbox->getWrapper()->listMessages( folder->getName(),target );
841} 841}
842 842
843RecBody MBOXfolderItem::fetchBody(const RecMail&aMail) 843RecBody MBOXfolderItem::fetchBody(const RecMail&aMail)
844{ 844{
845 return mbox->getWrapper()->fetchBody(aMail); 845 return mbox->getWrapper()->fetchBody(aMail);
846} 846}
847 847
848void MBOXfolderItem::deleteFolder() 848void MBOXfolderItem::deleteFolder()
849{ 849{
850 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), 850 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
851 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), 851 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()),
852 QObject::tr("Yes",contextName), 852 QObject::tr("Yes",contextName),
853 QObject::tr("No",contextName),QString::null,1,1); 853 QObject::tr("No",contextName),QString::null,1,1);
854 qDebug("Auswahl: %i",yesno); 854 qDebug("Auswahl: %i",yesno);
855 if (yesno == 0) { 855 if (yesno == 0) {
856 if (mbox->getWrapper()->deleteMbox(folder)) { 856 if (mbox->getWrapper()->deleteMbox(folder)) {
857 QListView*v=listView(); 857 QListView*v=listView();
858 MBOXviewItem * box = mbox; 858 MBOXviewItem * box = mbox;
859 /* be carefull - after that this object is destroyd so don't use 859 /* be carefull - after that this object is destroyd so don't use
860 * any member of it after that call!!*/ 860 * any member of it after that call!!*/
861 mbox->refresh(true); 861 mbox->refresh(true);
862 if (v) { 862 if (v) {
863 v->setSelected(box,true); 863 v->setSelected(box,true);
864 } 864 }
865 } 865 }
866 } 866 }
867} 867}
868 868
869QPopupMenu * MBOXfolderItem::getContextMenu() 869QPopupMenu * MBOXfolderItem::getContextMenu()
870{ 870{
871 QPopupMenu *m = new QPopupMenu(0); 871 QPopupMenu *m = new QPopupMenu(0);
872 if (m) { 872 if (m) {
873 m->insertItem(QObject::tr("Delete all mails",contextName),0); 873 m->insertItem(QObject::tr("Delete all mails",contextName),0);
874 m->insertItem(QObject::tr("Delete folder",contextName),1); 874 m->insertItem(QObject::tr("Delete folder",contextName),1);
875 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2);
875 } 876 }
876 return m; 877 return m;
877} 878}
878 879
880void MBOXfolderItem::downloadMails()
881{
882 AccountView*bl = mbox->accountView();
883 if (!bl) return;
884 bl->downloadMails(folder,mbox->getWrapper());
885}
886
879void MBOXfolderItem::contextMenuSelected(int which) 887void MBOXfolderItem::contextMenuSelected(int which)
880{ 888{
881 switch(which) { 889 switch(which) {
882 case 0: 890 case 0:
883 deleteAllMail(mbox->getWrapper(),folder); 891 deleteAllMail(mbox->getWrapper(),folder);
884 break; 892 break;
885 case 1: 893 case 1:
886 deleteFolder(); 894 deleteFolder();
887 break; 895 break;
896 case 2:
897 downloadMails();
898 break;
888 default: 899 default:
889 break; 900 break;
890 } 901 }
891} 902}
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h
index df916c1..d9b5558 100644
--- a/noncore/net/mail/accountview.h
+++ b/noncore/net/mail/accountview.h
@@ -1,189 +1,190 @@
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 6
7#include <libmailwrapper/settings.h> 7#include <libmailwrapper/settings.h>
8#include <libmailwrapper/mailwrapper.h> 8#include <libmailwrapper/mailwrapper.h>
9#include <libmailwrapper/abstractmail.h> 9#include <libmailwrapper/abstractmail.h>
10 10
11class POP3wrapper; 11class POP3wrapper;
12class RecMail; 12class RecMail;
13class RecBody; 13class RecBody;
14class QPopupMenu; 14class QPopupMenu;
15class Selectstore; 15class Selectstore;
16class AccountView; 16class AccountView;
17 17
18class AccountViewItem : public QListViewItem 18class AccountViewItem : public QListViewItem
19{ 19{
20 20
21public: 21public:
22 AccountViewItem( AccountView *parent ); 22 AccountViewItem( AccountView *parent );
23 AccountViewItem( QListViewItem *parent); 23 AccountViewItem( QListViewItem *parent);
24 AccountViewItem( QListViewItem *parent , QListViewItem*after ); 24 AccountViewItem( QListViewItem *parent , QListViewItem*after );
25 virtual ~AccountViewItem(); 25 virtual ~AccountViewItem();
26 virtual void refresh(QList<RecMail>&)=0; 26 virtual void refresh(QList<RecMail>&)=0;
27 virtual RecBody fetchBody(const RecMail&)=0; 27 virtual RecBody fetchBody(const RecMail&)=0;
28 virtual QPopupMenu * getContextMenu(){return 0;}; 28 virtual QPopupMenu * getContextMenu(){return 0;};
29 virtual void contextMenuSelected(int){} 29 virtual void contextMenuSelected(int){}
30 virtual AccountView*accountView(); 30 virtual AccountView*accountView();
31protected: 31protected:
32 virtual void deleteAllMail(AbstractMail*wrapper,Folder*f); 32 virtual void deleteAllMail(AbstractMail*wrapper,Folder*f);
33 static const QString contextName; 33 static const QString contextName;
34 AccountView*m_Backlink; 34 AccountView*m_Backlink;
35}; 35};
36 36
37class POP3viewItem : public AccountViewItem 37class POP3viewItem : public AccountViewItem
38{ 38{
39 39
40public: 40public:
41 POP3viewItem( POP3account *a, AccountView *parent ); 41 POP3viewItem( POP3account *a, AccountView *parent );
42 virtual ~POP3viewItem(); 42 virtual ~POP3viewItem();
43 virtual void refresh( QList<RecMail> &target ); 43 virtual void refresh( QList<RecMail> &target );
44 virtual RecBody fetchBody( const RecMail &mail ); 44 virtual RecBody fetchBody( const RecMail &mail );
45 AbstractMail *getWrapper(); 45 AbstractMail *getWrapper();
46 virtual QPopupMenu * getContextMenu(); 46 virtual QPopupMenu * getContextMenu();
47 virtual void contextMenuSelected(int); 47 virtual void contextMenuSelected(int);
48 48
49protected: 49protected:
50 POP3account *account; 50 POP3account *account;
51 virtual void refresh(); 51 virtual void refresh();
52 AbstractMail *wrapper; 52 AbstractMail *wrapper;
53 void disconnect(); 53 void disconnect();
54 void setOnOffline(); 54 void setOnOffline();
55}; 55};
56 56
57class POP3folderItem : public AccountViewItem 57class POP3folderItem : public AccountViewItem
58{ 58{
59 59
60public: 60public:
61 POP3folderItem( Folder *folder, POP3viewItem *parent , QListViewItem*after ); 61 POP3folderItem( Folder *folder, POP3viewItem *parent , QListViewItem*after );
62 virtual ~POP3folderItem(); 62 virtual ~POP3folderItem();
63 virtual void refresh(QList<RecMail>&); 63 virtual void refresh(QList<RecMail>&);
64 virtual RecBody fetchBody(const RecMail&); 64 virtual RecBody fetchBody(const RecMail&);
65 virtual QPopupMenu * getContextMenu(); 65 virtual QPopupMenu * getContextMenu();
66 virtual void contextMenuSelected(int); 66 virtual void contextMenuSelected(int);
67 67
68protected: 68protected:
69 void downloadMails(); 69 void downloadMails();
70 Folder *folder; 70 Folder *folder;
71 POP3viewItem *pop3; 71 POP3viewItem *pop3;
72}; 72};
73 73
74class IMAPfolderItem; 74class IMAPfolderItem;
75 75
76class IMAPviewItem : public AccountViewItem 76class IMAPviewItem : public AccountViewItem
77{ 77{
78 friend class IMAPfolderItem; 78 friend class IMAPfolderItem;
79public: 79public:
80 IMAPviewItem( IMAPaccount *a, AccountView *parent ); 80 IMAPviewItem( IMAPaccount *a, AccountView *parent );
81 virtual ~IMAPviewItem(); 81 virtual ~IMAPviewItem();
82 virtual void refresh(QList<RecMail>&); 82 virtual void refresh(QList<RecMail>&);
83 virtual RecBody fetchBody(const RecMail&); 83 virtual RecBody fetchBody(const RecMail&);
84 AbstractMail *getWrapper(); 84 AbstractMail *getWrapper();
85 virtual QPopupMenu * getContextMenu(); 85 virtual QPopupMenu * getContextMenu();
86 virtual void contextMenuSelected(int); 86 virtual void contextMenuSelected(int);
87 const QStringList&subFolders(); 87 const QStringList&subFolders();
88 virtual void refreshFolders(bool force=false); 88 virtual void refreshFolders(bool force=false);
89 bool offline(); 89 bool offline();
90 90
91protected: 91protected:
92 IMAPfolderItem*findSubItem(const QString&path,IMAPfolderItem*start=0); 92 IMAPfolderItem*findSubItem(const QString&path,IMAPfolderItem*start=0);
93 virtual void createNewFolder(); 93 virtual void createNewFolder();
94 virtual void removeChilds(); 94 virtual void removeChilds();
95 IMAPaccount *account; 95 IMAPaccount *account;
96 AbstractMail *wrapper; 96 AbstractMail *wrapper;
97 QStringList currentFolders; 97 QStringList currentFolders;
98}; 98};
99 99
100class IMAPfolderItem : public AccountViewItem 100class IMAPfolderItem : public AccountViewItem
101{ 101{
102 102
103public: 103public:
104 IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after ); 104 IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after );
105 IMAPfolderItem( Folder *folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ); 105 IMAPfolderItem( Folder *folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master );
106 virtual ~IMAPfolderItem(); 106 virtual ~IMAPfolderItem();
107 virtual void refresh(QList<RecMail>&); 107 virtual void refresh(QList<RecMail>&);
108 virtual RecBody fetchBody(const RecMail&); 108 virtual RecBody fetchBody(const RecMail&);
109 bool matchName(const QString&name)const; 109 bool matchName(const QString&name)const;
110 virtual QPopupMenu * getContextMenu(); 110 virtual QPopupMenu * getContextMenu();
111 virtual void contextMenuSelected(int); 111 virtual void contextMenuSelected(int);
112 virtual const QString& Delemiter()const; 112 virtual const QString& Delemiter()const;
113protected: 113protected:
114 virtual void createNewFolder(); 114 virtual void createNewFolder();
115 virtual void deleteFolder(); 115 virtual void deleteFolder();
116 virtual void downloadMails(); 116 virtual void downloadMails();
117 Folder *folder; 117 Folder *folder;
118 IMAPviewItem *imap; 118 IMAPviewItem *imap;
119}; 119};
120 120
121class MBOXviewItem : public AccountViewItem 121class MBOXviewItem : public AccountViewItem
122{ 122{
123 friend class MBOXfolderItem; 123 friend class MBOXfolderItem;
124 124
125public: 125public:
126 MBOXviewItem( const QString&aMboxPath, AccountView *parent ); 126 MBOXviewItem( const QString&aMboxPath, AccountView *parent );
127 virtual ~MBOXviewItem(); 127 virtual ~MBOXviewItem();
128 virtual void refresh( QList<RecMail> &target ); 128 virtual void refresh( QList<RecMail> &target );
129 virtual RecBody fetchBody( const RecMail &mail ); 129 virtual RecBody fetchBody( const RecMail &mail );
130 AbstractMail *getWrapper(); 130 AbstractMail *getWrapper();
131 virtual QPopupMenu * getContextMenu(); 131 virtual QPopupMenu * getContextMenu();
132 virtual void contextMenuSelected(int); 132 virtual void contextMenuSelected(int);
133 QStringList subFolders(); 133 QStringList subFolders();
134 virtual void refresh(bool force=false); 134 virtual void refresh(bool force=false);
135 135
136protected: 136protected:
137 virtual void createFolder(); 137 virtual void createFolder();
138 QString m_Path; 138 QString m_Path;
139 AbstractMail *wrapper; 139 AbstractMail *wrapper;
140 140
141}; 141};
142 142
143class MBOXfolderItem : public AccountViewItem 143class MBOXfolderItem : public AccountViewItem
144{ 144{
145 145
146public: 146public:
147 MBOXfolderItem( Folder *folder, MBOXviewItem *parent , QListViewItem*after ); 147 MBOXfolderItem( Folder *folder, MBOXviewItem *parent , QListViewItem*after );
148 virtual ~MBOXfolderItem(); 148 virtual ~MBOXfolderItem();
149 virtual void refresh(QList<RecMail>&); 149 virtual void refresh(QList<RecMail>&);
150 virtual RecBody fetchBody(const RecMail&); 150 virtual RecBody fetchBody(const RecMail&);
151 virtual QPopupMenu * getContextMenu(); 151 virtual QPopupMenu * getContextMenu();
152 virtual void contextMenuSelected(int); 152 virtual void contextMenuSelected(int);
153 virtual Folder*getFolder(); 153 virtual Folder*getFolder();
154 154
155protected: 155protected:
156 void downloadMails();
156 virtual void deleteFolder(); 157 virtual void deleteFolder();
157 Folder *folder; 158 Folder *folder;
158 MBOXviewItem *mbox; 159 MBOXviewItem *mbox;
159}; 160};
160 161
161class AccountView : public QListView 162class AccountView : public QListView
162{ 163{
163 Q_OBJECT 164 Q_OBJECT
164 165
165public: 166public:
166 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 167 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
167 virtual ~AccountView(); 168 virtual ~AccountView();
168 virtual void populate( QList<Account> list ); 169 virtual void populate( QList<Account> list );
169 virtual RecBody fetchBody(const RecMail&aMail); 170 virtual RecBody fetchBody(const RecMail&aMail);
170 virtual void downloadMails(Folder*fromFolder,AbstractMail*fromWrapper); 171 virtual void downloadMails(Folder*fromFolder,AbstractMail*fromWrapper);
171 172
172public slots: 173public slots:
173 virtual void refreshAll(); 174 virtual void refreshAll();
174 virtual void refresh(QListViewItem *item); 175 virtual void refresh(QListViewItem *item);
175 virtual void refreshCurrent(); 176 virtual void refreshCurrent();
176 virtual void slotHold(int, QListViewItem *,const QPoint&,int); 177 virtual void slotHold(int, QListViewItem *,const QPoint&,int);
177 virtual void slotContextMenu(int id); 178 virtual void slotContextMenu(int id);
178 void setupFolderselect(Selectstore*sels); 179 void setupFolderselect(Selectstore*sels);
179 180
180signals: 181signals:
181 void refreshMailview(QList<RecMail>*); 182 void refreshMailview(QList<RecMail>*);
182 183
183protected: 184protected:
184 QListViewItem* m_currentItem; 185 QListViewItem* m_currentItem;
185 QValueList<IMAPviewItem*> imapAccounts; 186 QValueList<IMAPviewItem*> imapAccounts;
186 QValueList<MBOXviewItem*> mboxAccounts; 187 QValueList<MBOXviewItem*> mboxAccounts;
187}; 188};
188 189
189#endif 190#endif
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp
index 4b4c728..0280803 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.cpp
+++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp
@@ -1,125 +1,138 @@
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 "mboxwrapper.h" 4#include "mboxwrapper.h"
5#include "mailtypes.h" 5#include "mailtypes.h"
6 6
7#include <qstring.h> 7#include <qstring.h>
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
14AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 14AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
15{ 15{
16 return new IMAPwrapper(a); 16 return new IMAPwrapper(a);
17} 17}
18 18
19AbstractMail* AbstractMail::getWrapper(POP3account *a) 19AbstractMail* AbstractMail::getWrapper(POP3account *a)
20{ 20{
21 return new POP3wrapper(a); 21 return new POP3wrapper(a);
22} 22}
23 23
24AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) 24AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name)
25{ 25{
26 return new MBOXwrapper(a,name); 26 return new MBOXwrapper(a,name);
27} 27}
28 28
29encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 29encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
30{ 30{
31 qDebug("Decode string start"); 31 qDebug("Decode string start");
32 char*result_text; 32 char*result_text;
33 size_t index = 0; 33 size_t index = 0;
34 /* reset for recursive use! */ 34 /* reset for recursive use! */
35 size_t target_length = 0; 35 size_t target_length = 0;
36 result_text = 0; 36 result_text = 0;
37 int mimetype = MAILMIME_MECHANISM_7BIT; 37 int mimetype = MAILMIME_MECHANISM_7BIT;
38 if (enc.lower()=="quoted-printable") { 38 if (enc.lower()=="quoted-printable") {
39 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 39 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
40 } else if (enc.lower()=="base64") { 40 } else if (enc.lower()=="base64") {
41 mimetype = MAILMIME_MECHANISM_BASE64; 41 mimetype = MAILMIME_MECHANISM_BASE64;
42 } else if (enc.lower()=="8bit") { 42 } else if (enc.lower()=="8bit") {
43 mimetype = MAILMIME_MECHANISM_8BIT; 43 mimetype = MAILMIME_MECHANISM_8BIT;
44 } else if (enc.lower()=="binary") { 44 } else if (enc.lower()=="binary") {
45 mimetype = MAILMIME_MECHANISM_BINARY; 45 mimetype = MAILMIME_MECHANISM_BINARY;
46 } 46 }
47 47
48 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 48 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
49 &result_text,&target_length); 49 &result_text,&target_length);
50 50
51 encodedString* result = new encodedString(); 51 encodedString* result = new encodedString();
52 if (err == MAILIMF_NO_ERROR) { 52 if (err == MAILIMF_NO_ERROR) {
53 result->setContent(result_text,target_length); 53 result->setContent(result_text,target_length);
54 } 54 }
55 qDebug("Decode string finished"); 55 qDebug("Decode string finished");
56 return result; 56 return result;
57} 57}
58 58
59QString AbstractMail::convert_String(const char*text) 59QString AbstractMail::convert_String(const char*text)
60{ 60{
61 size_t index = 0; 61 size_t index = 0;
62 char*res = 0; 62 char*res = 0;
63 63
64 /* attention - doesn't work with arm systems! */ 64 /* attention - doesn't work with arm systems! */
65 int err = mailmime_encoded_phrase_parse("iso-8859-1", 65 int err = mailmime_encoded_phrase_parse("iso-8859-1",
66 text, strlen(text),&index, "iso-8859-1",&res); 66 text, strlen(text),&index, "iso-8859-1",&res);
67 if (err != MAILIMF_NO_ERROR) { 67 if (err != MAILIMF_NO_ERROR) {
68 if (res) free(res); 68 if (res) free(res);
69 return QString(text); 69 return QString(text);
70 } 70 }
71 if (res) { 71 if (res) {
72 QString result(res); 72 QString result(res);
73 free(res); 73 free(res);
74 return result; 74 return result;
75 } 75 }
76 return QString(text); 76 return QString(text);
77} 77}
78 78
79/* cp & paste from launcher */ 79/* cp & paste from launcher */
80QString AbstractMail::gen_attachment_id() 80QString AbstractMail::gen_attachment_id()
81{ 81{
82 QFile file( "/proc/sys/kernel/random/uuid" ); 82 QFile file( "/proc/sys/kernel/random/uuid" );
83 if (!file.open(IO_ReadOnly ) ) 83 if (!file.open(IO_ReadOnly ) )
84 return QString::null; 84 return QString::null;
85 85
86 QTextStream stream(&file); 86 QTextStream stream(&file);
87 87
88 return "{" + stream.read().stripWhiteSpace() + "}"; 88 return "{" + stream.read().stripWhiteSpace() + "}";
89} 89}
90 90
91int AbstractMail::createMbox(const QString&,const Folder*,const QString& delemiter,bool) 91int AbstractMail::createMbox(const QString&,const Folder*,const QString& delemiter,bool)
92{ 92{
93 return 0; 93 return 0;
94} 94}
95 95
96QString AbstractMail::defaultLocalfolder() 96QString AbstractMail::defaultLocalfolder()
97{ 97{
98 QString f = getenv( "HOME" ); 98 QString f = getenv( "HOME" );
99 f += "/Applications/opiemail/localmail"; 99 f += "/Applications/opiemail/localmail";
100 return f; 100 return f;
101} 101}
102 102
103/* temporary - will be removed when implemented in all classes */ 103/* temporary - will be removed when implemented in all classes */
104void AbstractMail::deleteMails(const QString &,QList<RecMail> &) 104void AbstractMail::deleteMails(const QString &,QList<RecMail> &)
105{ 105{
106} 106}
107 107
108void AbstractMail::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 108void AbstractMail::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
109{ 109{
110 QList<RecMail> t; 110 QList<RecMail> t;
111 listMessages(fromFolder->getName(),t); 111 listMessages(fromFolder->getName(),t);
112 encodedString*st = 0; 112 encodedString*st = 0;
113 while (t.count()>0) { 113 while (t.count()>0) {
114 RecMail*r = t.at(0); 114 RecMail*r = t.at(0);
115 st = fetchRawBody(*r); 115 st = fetchRawBody(*r);
116 if (st) { 116 if (st) {
117 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 117 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
118 delete st; 118 delete st;
119 } 119 }
120 t.removeFirst(); 120 t.removeFirst();
121 } 121 }
122 if (moveit) { 122 if (moveit) {
123 deleteAllMail(fromFolder); 123 deleteAllMail(fromFolder);
124 } 124 }
125} 125}
126
127void AbstractMail::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
128{
129 encodedString*st = 0;
130 st = fetchRawBody(mail);
131 if (st) {
132 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
133 delete st;
134 }
135 if (moveit) {
136 deleteMail(mail);
137 }
138}
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h
index 8debaae..f93bab4 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.h
+++ b/noncore/net/mail/libmailwrapper/abstractmail.h
@@ -1,64 +1,65 @@
1#ifndef __abstract_mail_ 1#ifndef __abstract_mail_
2#define __abstract_mail_ 2#define __abstract_mail_
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include "settings.h" 5#include "settings.h"
6 6
7class RecMail; 7class RecMail;
8class RecBody; 8class RecBody;
9class RecPart; 9class RecPart;
10class IMAPwrapper; 10class IMAPwrapper;
11class POP3wrapper; 11class POP3wrapper;
12class Folder; 12class Folder;
13class encodedString; 13class encodedString;
14struct folderStat; 14struct folderStat;
15 15
16class AbstractMail:public QObject 16class AbstractMail:public QObject
17{ 17{
18 Q_OBJECT 18 Q_OBJECT
19public: 19public:
20 AbstractMail(){}; 20 AbstractMail(){};
21 virtual ~AbstractMail(){} 21 virtual ~AbstractMail(){}
22 virtual QList<Folder>* listFolders()=0; 22 virtual QList<Folder>* listFolders()=0;
23 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; 23 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0; 24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0;
25 virtual RecBody fetchBody(const RecMail&mail)=0; 25 virtual RecBody fetchBody(const RecMail&mail)=0;
26 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; 26 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
27 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; 27 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
28 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; 28 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
29 virtual encodedString* fetchRawBody(const RecMail&mail)=0; 29 virtual encodedString* fetchRawBody(const RecMail&mail)=0;
30 30
31 virtual void deleteMail(const RecMail&mail)=0; 31 virtual void deleteMail(const RecMail&mail)=0;
32 virtual void answeredMail(const RecMail&mail)=0; 32 virtual void answeredMail(const RecMail&mail)=0;
33 virtual int deleteAllMail(const Folder*)=0; 33 virtual int deleteAllMail(const Folder*)=0;
34 virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); 34 virtual void deleteMails(const QString & FolderName,QList<RecMail> &target);
35 virtual int deleteMbox(const Folder*)=0; 35 virtual int deleteMbox(const Folder*)=0;
36 virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0; 36 virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0;
37 37
38 virtual void mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 38 virtual void mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
39 virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
39 40
40 virtual void cleanMimeCache(){}; 41 virtual void cleanMimeCache(){};
41 /* mail box methods */ 42 /* mail box methods */
42 /* parameter is the box to create. 43 /* parameter is the box to create.
43 * if the implementing subclass has prefixes, 44 * if the implementing subclass has prefixes,
44 * them has to be appended automatic. 45 * them has to be appended automatic.
45 */ 46 */
46 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); 47 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
47 virtual void logout()=0; 48 virtual void logout()=0;
48 49
49 static AbstractMail* getWrapper(IMAPaccount *a); 50 static AbstractMail* getWrapper(IMAPaccount *a);
50 static AbstractMail* getWrapper(POP3account *a); 51 static AbstractMail* getWrapper(POP3account *a);
51 /* mbox only! */ 52 /* mbox only! */
52 static AbstractMail* getWrapper(const QString&a,const QString&name="Local Folders"); 53 static AbstractMail* getWrapper(const QString&a,const QString&name="Local Folders");
53 54
54 static QString defaultLocalfolder(); 55 static QString defaultLocalfolder();
55 56
56 virtual const QString&getType()const=0; 57 virtual const QString&getType()const=0;
57 virtual const QString&getName()const=0; 58 virtual const QString&getName()const=0;
58 59
59protected: 60protected:
60 static encodedString*decode_String(const encodedString*text,const QString&enc); 61 static encodedString*decode_String(const encodedString*text,const QString&enc);
61 static QString convert_String(const char*text); 62 static QString convert_String(const char*text);
62 static QString gen_attachment_id(); 63 static QString gen_attachment_id();
63}; 64};
64#endif 65#endif
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 98634a3..4b633ea 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,1058 +1,1088 @@
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
9IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 9IMAPwrapper::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
17IMAPwrapper::~IMAPwrapper() 17IMAPwrapper::~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!*/
24int IMAPwrapper::selectMbox(const QString&mbox) 24int 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
39void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 39void 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
44void IMAPwrapper::login() 44void IMAPwrapper::login()
45{ 45{
46 const char *server, *user, *pass; 46 const char *server, *user, *pass;
47 uint16_t port; 47 uint16_t port;
48 int err = MAILIMAP_NO_ERROR; 48 int err = MAILIMAP_NO_ERROR;
49 49
50 if (account->getOffline()) return; 50 if (account->getOffline()) return;
51 /* we are connected this moment */ 51 /* we are connected this moment */
52 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 52 /* TODO: setup a timer holding the line or if connection closed - delete the value */
53 if (m_imap) { 53 if (m_imap) {
54 err = mailimap_noop(m_imap); 54 err = mailimap_noop(m_imap);
55 if (err!=MAILIMAP_NO_ERROR) { 55 if (err!=MAILIMAP_NO_ERROR) {
56 logout(); 56 logout();
57 } else { 57 } else {
58 mailstream_flush(m_imap->imap_stream); 58 mailstream_flush(m_imap->imap_stream);
59 return; 59 return;
60 } 60 }
61 } 61 }
62 server = account->getServer().latin1(); 62 server = account->getServer().latin1();
63 port = account->getPort().toUInt(); 63 port = account->getPort().toUInt();
64 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 64 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
65 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 65 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
66 login.show(); 66 login.show();
67 if ( QDialog::Accepted == login.exec() ) { 67 if ( QDialog::Accepted == login.exec() ) {
68 // ok 68 // ok
69 user = login.getUser().latin1(); 69 user = login.getUser().latin1();
70 pass = login.getPassword().latin1(); 70 pass = login.getPassword().latin1();
71 } else { 71 } else {
72 // cancel 72 // cancel
73 qDebug( "IMAP: Login canceled" ); 73 qDebug( "IMAP: Login canceled" );
74 return; 74 return;
75 } 75 }
76 } else { 76 } else {
77 user = account->getUser().latin1(); 77 user = account->getUser().latin1();
78 pass = account->getPassword().latin1(); 78 pass = account->getPassword().latin1();
79 } 79 }
80 80
81 m_imap = mailimap_new( 20, &imap_progress ); 81 m_imap = mailimap_new( 20, &imap_progress );
82 82
83 /* connect */ 83 /* connect */
84 if (account->getSSL()) { 84 if (account->getSSL()) {
85 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 85 err = mailimap_ssl_connect( m_imap, (char*)server, port );
86 } else { 86 } else {
87 err = mailimap_socket_connect( m_imap, (char*)server, port ); 87 err = mailimap_socket_connect( m_imap, (char*)server, port );
88 } 88 }
89 89
90 if ( err != MAILIMAP_NO_ERROR && 90 if ( err != MAILIMAP_NO_ERROR &&
91 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 91 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
92 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 92 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
93 QString failure = ""; 93 QString failure = "";
94 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 94 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
95 failure="Connection refused"; 95 failure="Connection refused";
96 } else { 96 } else {
97 failure="Unknown failure"; 97 failure="Unknown failure";
98 } 98 }
99 Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); 99 Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
100 mailimap_free( m_imap ); 100 mailimap_free( m_imap );
101 m_imap = 0; 101 m_imap = 0;
102 return; 102 return;
103 } 103 }
104 104
105 /* login */ 105 /* login */
106 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 106 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
107 if ( err != MAILIMAP_NO_ERROR ) { 107 if ( err != MAILIMAP_NO_ERROR ) {
108 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); 108 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
109 err = mailimap_close( m_imap ); 109 err = mailimap_close( m_imap );
110 mailimap_free( m_imap ); 110 mailimap_free( m_imap );
111 m_imap = 0; 111 m_imap = 0;
112 } 112 }
113} 113}
114 114
115void IMAPwrapper::logout() 115void IMAPwrapper::logout()
116{ 116{
117 int err = MAILIMAP_NO_ERROR; 117 int err = MAILIMAP_NO_ERROR;
118 if (!m_imap) return; 118 if (!m_imap) return;
119 err = mailimap_logout( m_imap ); 119 err = mailimap_logout( m_imap );
120 err = mailimap_close( m_imap ); 120 err = mailimap_close( m_imap );
121 mailimap_free( m_imap ); 121 mailimap_free( m_imap );
122 m_imap = 0; 122 m_imap = 0;
123 m_Lastmbox = ""; 123 m_Lastmbox = "";
124} 124}
125 125
126void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 126void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
127{ 127{
128 int err = MAILIMAP_NO_ERROR; 128 int err = MAILIMAP_NO_ERROR;
129 clist *result = 0; 129 clist *result = 0;
130 clistcell *current; 130 clistcell *current;
131 mailimap_fetch_type *fetchType = 0; 131 mailimap_fetch_type *fetchType = 0;
132 mailimap_set *set = 0; 132 mailimap_set *set = 0;
133 133
134 login(); 134 login();
135 if (!m_imap) { 135 if (!m_imap) {
136 return; 136 return;
137 } 137 }
138 /* select mailbox READONLY for operations */ 138 /* select mailbox READONLY for operations */
139 err = selectMbox(mailbox); 139 err = selectMbox(mailbox);
140 if ( err != MAILIMAP_NO_ERROR ) { 140 if ( err != MAILIMAP_NO_ERROR ) {
141 return; 141 return;
142 } 142 }
143 143
144 int last = m_imap->imap_selection_info->sel_exists; 144 int last = m_imap->imap_selection_info->sel_exists;
145 145
146 if (last == 0) { 146 if (last == 0) {
147 Global::statusMessage(tr("Mailbox has no mails")); 147 Global::statusMessage(tr("Mailbox has no mails"));
148 return; 148 return;
149 } else { 149 } else {
150 Global::statusMessage(tr("Mailbox has %1 mails").arg(last)); 150 Global::statusMessage(tr("Mailbox has %1 mails").arg(last));
151 } 151 }
152 152
153 /* the range has to start at 1!!! not with 0!!!! */ 153 /* the range has to start at 1!!! not with 0!!!! */
154 set = mailimap_set_new_interval( 1, last ); 154 set = mailimap_set_new_interval( 1, last );
155 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 155 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
156 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 156 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
157 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 157 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
158 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 158 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
159 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 159 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
160 160
161 err = mailimap_fetch( m_imap, set, fetchType, &result ); 161 err = mailimap_fetch( m_imap, set, fetchType, &result );
162 mailimap_set_free( set ); 162 mailimap_set_free( set );
163 mailimap_fetch_type_free( fetchType ); 163 mailimap_fetch_type_free( fetchType );
164 164
165 QString date,subject,from; 165 QString date,subject,from;
166 166
167 if ( err == MAILIMAP_NO_ERROR ) { 167 if ( err == MAILIMAP_NO_ERROR ) {
168 mailimap_msg_att * msg_att; 168 mailimap_msg_att * msg_att;
169 int i = 0; 169 int i = 0;
170 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 170 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
171 ++i; 171 ++i;
172 msg_att = (mailimap_msg_att*)current->data; 172 msg_att = (mailimap_msg_att*)current->data;
173 RecMail*m = parse_list_result(msg_att); 173 RecMail*m = parse_list_result(msg_att);
174 if (m) { 174 if (m) {
175 m->setNumber(i); 175 m->setNumber(i);
176 m->setMbox(mailbox); 176 m->setMbox(mailbox);
177 m->setWrapper(this); 177 m->setWrapper(this);
178 target.append(m); 178 target.append(m);
179 } 179 }
180 } 180 }
181 } else { 181 } else {
182 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); 182 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
183 } 183 }
184 if (result) mailimap_fetch_list_free(result); 184 if (result) mailimap_fetch_list_free(result);
185} 185}
186 186
187QList<Folder>* IMAPwrapper::listFolders() 187QList<Folder>* IMAPwrapper::listFolders()
188{ 188{
189 const char *path, *mask; 189 const char *path, *mask;
190 int err = MAILIMAP_NO_ERROR; 190 int err = MAILIMAP_NO_ERROR;
191 clist *result = 0; 191 clist *result = 0;
192 clistcell *current = 0; 192 clistcell *current = 0;
193 clistcell*cur_flag = 0; 193 clistcell*cur_flag = 0;
194 mailimap_mbx_list_flags*bflags = 0; 194 mailimap_mbx_list_flags*bflags = 0;
195 195
196 QList<Folder> * folders = new QList<Folder>(); 196 QList<Folder> * folders = new QList<Folder>();
197 folders->setAutoDelete( false ); 197 folders->setAutoDelete( false );
198 login(); 198 login();
199 if (!m_imap) { 199 if (!m_imap) {
200 return folders; 200 return folders;
201 } 201 }
202 202
203/* 203/*
204 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 204 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
205 * We must not forget to filter them out in next loop! 205 * We must not forget to filter them out in next loop!
206 * it seems like ugly code. and yes - it is ugly code. but the best way. 206 * it seems like ugly code. and yes - it is ugly code. but the best way.
207 */ 207 */
208 QString temp; 208 QString temp;
209 mask = "INBOX" ; 209 mask = "INBOX" ;
210 mailimap_mailbox_list *list; 210 mailimap_mailbox_list *list;
211 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 211 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
212 QString del; 212 QString del;
213 bool selectable = true; 213 bool selectable = true;
214 bool no_inferiors = false; 214 bool no_inferiors = false;
215 if ( err == MAILIMAP_NO_ERROR ) { 215 if ( err == MAILIMAP_NO_ERROR ) {
216 current = result->first; 216 current = result->first;
217 for ( int i = result->count; i > 0; i-- ) { 217 for ( int i = result->count; i > 0; i-- ) {
218 list = (mailimap_mailbox_list *) current->data; 218 list = (mailimap_mailbox_list *) current->data;
219 // it is better use the deep copy mechanism of qt itself 219 // it is better use the deep copy mechanism of qt itself
220 // instead of using strdup! 220 // instead of using strdup!
221 temp = list->mb_name; 221 temp = list->mb_name;
222 del = list->mb_delimiter; 222 del = list->mb_delimiter;
223 current = current->next; 223 current = current->next;
224 if ( (bflags = list->mb_flag) ) { 224 if ( (bflags = list->mb_flag) ) {
225 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 225 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
226 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 226 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
227 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 227 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
228 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 228 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
229 no_inferiors = true; 229 no_inferiors = true;
230 } 230 }
231 } 231 }
232 } 232 }
233 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 233 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
234 } 234 }
235 } else { 235 } else {
236 qDebug("error fetching folders: %s",m_imap->imap_response); 236 qDebug("error fetching folders: %s",m_imap->imap_response);
237 } 237 }
238 mailimap_list_result_free( result ); 238 mailimap_list_result_free( result );
239 239
240/* 240/*
241 * second stage - get the other then inbox folders 241 * second stage - get the other then inbox folders
242 */ 242 */
243 mask = "*" ; 243 mask = "*" ;
244 path = account->getPrefix().latin1(); 244 path = account->getPrefix().latin1();
245 if (!path) path = ""; 245 if (!path) path = "";
246 qDebug(path); 246 qDebug(path);
247 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 247 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
248 if ( err == MAILIMAP_NO_ERROR ) { 248 if ( err == MAILIMAP_NO_ERROR ) {
249 current = result->first; 249 current = result->first;
250 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 250 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
251 no_inferiors = false; 251 no_inferiors = false;
252 list = (mailimap_mailbox_list *) current->data; 252 list = (mailimap_mailbox_list *) current->data;
253 // it is better use the deep copy mechanism of qt itself 253 // it is better use the deep copy mechanism of qt itself
254 // instead of using strdup! 254 // instead of using strdup!
255 temp = list->mb_name; 255 temp = list->mb_name;
256 if (temp.lower()=="inbox") 256 if (temp.lower()=="inbox")
257 continue; 257 continue;
258 if (temp.lower()==account->getPrefix().lower()) 258 if (temp.lower()==account->getPrefix().lower())
259 continue; 259 continue;
260 if ( (bflags = list->mb_flag) ) { 260 if ( (bflags = list->mb_flag) ) {
261 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 261 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
262 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 262 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
263 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 263 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
264 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 264 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
265 no_inferiors = true; 265 no_inferiors = true;
266 } 266 }
267 } 267 }
268 } 268 }
269 del = list->mb_delimiter; 269 del = list->mb_delimiter;
270 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 270 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
271 } 271 }
272 } else { 272 } else {
273 qDebug("error fetching folders %s",m_imap->imap_response); 273 qDebug("error fetching folders %s",m_imap->imap_response);
274 } 274 }
275 if (result) mailimap_list_result_free( result ); 275 if (result) mailimap_list_result_free( result );
276 return folders; 276 return folders;
277} 277}
278 278
279RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 279RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
280{ 280{
281 RecMail * m = 0; 281 RecMail * m = 0;
282 mailimap_msg_att_item *item=0; 282 mailimap_msg_att_item *item=0;
283 clistcell *current,*c,*cf; 283 clistcell *current,*c,*cf;
284 mailimap_msg_att_dynamic*flist; 284 mailimap_msg_att_dynamic*flist;
285 mailimap_flag_fetch*cflag; 285 mailimap_flag_fetch*cflag;
286 int size; 286 int size;
287 QBitArray mFlags(7); 287 QBitArray mFlags(7);
288 QStringList addresslist; 288 QStringList addresslist;
289 289
290 if (!m_att) { 290 if (!m_att) {
291 return m; 291 return m;
292 } 292 }
293 m = new RecMail(); 293 m = new RecMail();
294 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 294 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
295 current = c; 295 current = c;
296 size = 0; 296 size = 0;
297 item = (mailimap_msg_att_item*)current->data; 297 item = (mailimap_msg_att_item*)current->data;
298 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 298 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
299 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 299 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
300 if (!flist->att_list) { 300 if (!flist->att_list) {
301 continue; 301 continue;
302 } 302 }
303 cf = flist->att_list->first; 303 cf = flist->att_list->first;
304 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 304 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
305 cflag = (mailimap_flag_fetch*)cf->data; 305 cflag = (mailimap_flag_fetch*)cf->data;
306 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 306 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
307 switch (cflag->fl_flag->fl_type) { 307 switch (cflag->fl_flag->fl_type) {
308 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 308 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
309 mFlags.setBit(FLAG_ANSWERED); 309 mFlags.setBit(FLAG_ANSWERED);
310 break; 310 break;
311 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 311 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
312 mFlags.setBit(FLAG_FLAGGED); 312 mFlags.setBit(FLAG_FLAGGED);
313 break; 313 break;
314 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 314 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
315 mFlags.setBit(FLAG_DELETED); 315 mFlags.setBit(FLAG_DELETED);
316 break; 316 break;
317 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 317 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
318 mFlags.setBit(FLAG_SEEN); 318 mFlags.setBit(FLAG_SEEN);
319 break; 319 break;
320 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 320 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
321 mFlags.setBit(FLAG_DRAFT); 321 mFlags.setBit(FLAG_DRAFT);
322 break; 322 break;
323 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 323 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
324 break; 324 break;
325 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 325 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
326 break; 326 break;
327 default: 327 default:
328 break; 328 break;
329 } 329 }
330 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 330 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
331 mFlags.setBit(FLAG_RECENT); 331 mFlags.setBit(FLAG_RECENT);
332 } 332 }
333 } 333 }
334 continue; 334 continue;
335 } 335 }
336 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 336 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
337 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 337 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
338 m->setDate(head->env_date); 338 m->setDate(head->env_date);
339 m->setSubject(convert_String((const char*)head->env_subject)); 339 m->setSubject(convert_String((const char*)head->env_subject));
340 //m->setSubject(head->env_subject); 340 //m->setSubject(head->env_subject);
341 if (head->env_from!=NULL) { 341 if (head->env_from!=NULL) {
342 addresslist = address_list_to_stringlist(head->env_from->frm_list); 342 addresslist = address_list_to_stringlist(head->env_from->frm_list);
343 if (addresslist.count()) { 343 if (addresslist.count()) {
344 m->setFrom(addresslist.first()); 344 m->setFrom(addresslist.first());
345 } 345 }
346 } 346 }
347 if (head->env_to!=NULL) { 347 if (head->env_to!=NULL) {
348 addresslist = address_list_to_stringlist(head->env_to->to_list); 348 addresslist = address_list_to_stringlist(head->env_to->to_list);
349 m->setTo(addresslist); 349 m->setTo(addresslist);
350 } 350 }
351 if (head->env_cc!=NULL) { 351 if (head->env_cc!=NULL) {
352 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 352 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
353 m->setCC(addresslist); 353 m->setCC(addresslist);
354 } 354 }
355 if (head->env_bcc!=NULL) { 355 if (head->env_bcc!=NULL) {
356 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 356 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
357 m->setBcc(addresslist); 357 m->setBcc(addresslist);
358 } 358 }
359 if (head->env_reply_to!=NULL) { 359 if (head->env_reply_to!=NULL) {
360 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 360 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
361 if (addresslist.count()) { 361 if (addresslist.count()) {
362 m->setReplyto(addresslist.first()); 362 m->setReplyto(addresslist.first());
363 } 363 }
364 } 364 }
365 m->setMsgid(QString(head->env_message_id)); 365 m->setMsgid(QString(head->env_message_id));
366 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 366 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
367#if 0 367#if 0
368 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 368 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
369 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 369 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
370 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); 370 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);
371 qDebug(da.toString()); 371 qDebug(da.toString());
372#endif 372#endif
373 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 373 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
374 size = item->att_data.att_static->att_data.att_rfc822_size; 374 size = item->att_data.att_static->att_data.att_rfc822_size;
375 } 375 }
376 } 376 }
377 /* msg is already deleted */ 377 /* msg is already deleted */
378 if (mFlags.testBit(FLAG_DELETED) && m) { 378 if (mFlags.testBit(FLAG_DELETED) && m) {
379 delete m; 379 delete m;
380 m = 0; 380 m = 0;
381 } 381 }
382 if (m) { 382 if (m) {
383 m->setFlags(mFlags); 383 m->setFlags(mFlags);
384 m->setMsgsize(size); 384 m->setMsgsize(size);
385 } 385 }
386 return m; 386 return m;
387} 387}
388 388
389RecBody IMAPwrapper::fetchBody(const RecMail&mail) 389RecBody IMAPwrapper::fetchBody(const RecMail&mail)
390{ 390{
391 RecBody body; 391 RecBody body;
392 const char *mb; 392 const char *mb;
393 int err = MAILIMAP_NO_ERROR; 393 int err = MAILIMAP_NO_ERROR;
394 clist *result = 0; 394 clist *result = 0;
395 clistcell *current; 395 clistcell *current;
396 mailimap_fetch_att *fetchAtt = 0; 396 mailimap_fetch_att *fetchAtt = 0;
397 mailimap_fetch_type *fetchType = 0; 397 mailimap_fetch_type *fetchType = 0;
398 mailimap_set *set = 0; 398 mailimap_set *set = 0;
399 mailimap_body*body_desc = 0; 399 mailimap_body*body_desc = 0;
400 400
401 mb = mail.getMbox().latin1(); 401 mb = mail.getMbox().latin1();
402 402
403 login(); 403 login();
404 if (!m_imap) { 404 if (!m_imap) {
405 return body; 405 return body;
406 } 406 }
407 err = selectMbox(mail.getMbox()); 407 err = selectMbox(mail.getMbox());
408 if ( err != MAILIMAP_NO_ERROR ) { 408 if ( err != MAILIMAP_NO_ERROR ) {
409 return body; 409 return body;
410 } 410 }
411 411
412 /* the range has to start at 1!!! not with 0!!!! */ 412 /* the range has to start at 1!!! not with 0!!!! */
413 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 413 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
414 fetchAtt = mailimap_fetch_att_new_bodystructure(); 414 fetchAtt = mailimap_fetch_att_new_bodystructure();
415 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 415 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
416 err = mailimap_fetch( m_imap, set, fetchType, &result ); 416 err = mailimap_fetch( m_imap, set, fetchType, &result );
417 mailimap_set_free( set ); 417 mailimap_set_free( set );
418 mailimap_fetch_type_free( fetchType ); 418 mailimap_fetch_type_free( fetchType );
419 419
420 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 420 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
421 mailimap_msg_att * msg_att; 421 mailimap_msg_att * msg_att;
422 msg_att = (mailimap_msg_att*)current->data; 422 msg_att = (mailimap_msg_att*)current->data;
423 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 423 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
424 QValueList<int> path; 424 QValueList<int> path;
425 body_desc = item->att_data.att_static->att_data.att_body; 425 body_desc = item->att_data.att_static->att_data.att_body;
426 traverseBody(mail,body_desc,body,0,path); 426 traverseBody(mail,body_desc,body,0,path);
427 } else { 427 } else {
428 qDebug("error fetching body: %s",m_imap->imap_response); 428 qDebug("error fetching body: %s",m_imap->imap_response);
429 } 429 }
430 if (result) mailimap_fetch_list_free(result); 430 if (result) mailimap_fetch_list_free(result);
431 return body; 431 return body;
432} 432}
433 433
434QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 434QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
435{ 435{
436 QStringList l; 436 QStringList l;
437 QString from; 437 QString from;
438 bool named_from; 438 bool named_from;
439 clistcell *current = NULL; 439 clistcell *current = NULL;
440 mailimap_address * current_address=NULL; 440 mailimap_address * current_address=NULL;
441 if (!list) { 441 if (!list) {
442 return l; 442 return l;
443 } 443 }
444 unsigned int count = 0; 444 unsigned int count = 0;
445 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 445 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
446 from = ""; 446 from = "";
447 named_from = false; 447 named_from = false;
448 current_address=(mailimap_address*)current->data; 448 current_address=(mailimap_address*)current->data;
449 if (current_address->ad_personal_name){ 449 if (current_address->ad_personal_name){
450 from+=convert_String((const char*)current_address->ad_personal_name); 450 from+=convert_String((const char*)current_address->ad_personal_name);
451 from+=" "; 451 from+=" ";
452 named_from = true; 452 named_from = true;
453 } 453 }
454 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 454 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
455 from+="<"; 455 from+="<";
456 } 456 }
457 if (current_address->ad_mailbox_name) { 457 if (current_address->ad_mailbox_name) {
458 from+=QString(current_address->ad_mailbox_name); 458 from+=QString(current_address->ad_mailbox_name);
459 from+="@"; 459 from+="@";
460 } 460 }
461 if (current_address->ad_host_name) { 461 if (current_address->ad_host_name) {
462 from+=QString(current_address->ad_host_name); 462 from+=QString(current_address->ad_host_name);
463 } 463 }
464 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 464 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
465 from+=">"; 465 from+=">";
466 } 466 }
467 l.append(QString(from)); 467 l.append(QString(from));
468 if (++count > 99) { 468 if (++count > 99) {
469 break; 469 break;
470 } 470 }
471 } 471 }
472 return l; 472 return l;
473} 473}
474 474
475encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 475encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
476{ 476{
477 encodedString*res=new encodedString; 477 encodedString*res=new encodedString;
478 int err; 478 int err;
479 mailimap_fetch_type *fetchType; 479 mailimap_fetch_type *fetchType;
480 mailimap_set *set; 480 mailimap_set *set;
481 clistcell*current,*cur; 481 clistcell*current,*cur;
482 mailimap_section_part * section_part = 0; 482 mailimap_section_part * section_part = 0;
483 mailimap_section_spec * section_spec = 0; 483 mailimap_section_spec * section_spec = 0;
484 mailimap_section * section = 0; 484 mailimap_section * section = 0;
485 mailimap_fetch_att * fetch_att = 0; 485 mailimap_fetch_att * fetch_att = 0;
486 486
487 login(); 487 login();
488 if (!m_imap) { 488 if (!m_imap) {
489 return res; 489 return res;
490 } 490 }
491 if (!internal_call) { 491 if (!internal_call) {
492 err = selectMbox(mail.getMbox()); 492 err = selectMbox(mail.getMbox());
493 if ( err != MAILIMAP_NO_ERROR ) { 493 if ( err != MAILIMAP_NO_ERROR ) {
494 return res; 494 return res;
495 } 495 }
496 } 496 }
497 set = mailimap_set_new_single(mail.getNumber()); 497 set = mailimap_set_new_single(mail.getNumber());
498 498
499 clist*id_list = 0; 499 clist*id_list = 0;
500 500
501 /* if path == empty then its a request for the whole rfc822 mail and generates 501 /* if path == empty then its a request for the whole rfc822 mail and generates
502 a "fetch <id> (body[])" statement on imap server */ 502 a "fetch <id> (body[])" statement on imap server */
503 if (path.count()>0 ) { 503 if (path.count()>0 ) {
504 id_list = clist_new(); 504 id_list = clist_new();
505 for (unsigned j=0; j < path.count();++j) { 505 for (unsigned j=0; j < path.count();++j) {
506 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 506 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
507 *p_id = path[j]; 507 *p_id = path[j];
508 clist_append(id_list,p_id); 508 clist_append(id_list,p_id);
509 } 509 }
510 section_part = mailimap_section_part_new(id_list); 510 section_part = mailimap_section_part_new(id_list);
511 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 511 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
512 } 512 }
513 513
514 section = mailimap_section_new(section_spec); 514 section = mailimap_section_new(section_spec);
515 fetch_att = mailimap_fetch_att_new_body_section(section); 515 fetch_att = mailimap_fetch_att_new_body_section(section);
516 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 516 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
517 517
518 clist*result = 0; 518 clist*result = 0;
519 519
520 err = mailimap_fetch( m_imap, set, fetchType, &result ); 520 err = mailimap_fetch( m_imap, set, fetchType, &result );
521 mailimap_set_free( set ); 521 mailimap_set_free( set );
522 mailimap_fetch_type_free( fetchType ); 522 mailimap_fetch_type_free( fetchType );
523 523
524 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 524 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
525 mailimap_msg_att * msg_att; 525 mailimap_msg_att * msg_att;
526 msg_att = (mailimap_msg_att*)current->data; 526 msg_att = (mailimap_msg_att*)current->data;
527 mailimap_msg_att_item*msg_att_item; 527 mailimap_msg_att_item*msg_att_item;
528 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 528 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
529 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 529 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
530 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 530 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
531 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 531 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
532 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 532 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
533 /* detach - we take over the content */ 533 /* detach - we take over the content */
534 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 534 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
535 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 535 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
536 } 536 }
537 } 537 }
538 } 538 }
539 } else { 539 } else {
540 qDebug("error fetching text: %s",m_imap->imap_response); 540 qDebug("error fetching text: %s",m_imap->imap_response);
541 } 541 }
542 if (result) mailimap_fetch_list_free(result); 542 if (result) mailimap_fetch_list_free(result);
543 return res; 543 return res;
544} 544}
545 545
546/* current_recursion is for recursive calls. 546/* current_recursion is for recursive calls.
547 current_count means the position inside the internal loop! */ 547 current_count means the position inside the internal loop! */
548void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, 548void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,
549 int current_recursion,QValueList<int>recList,int current_count) 549 int current_recursion,QValueList<int>recList,int current_count)
550{ 550{
551 if (!body || current_recursion>=10) { 551 if (!body || current_recursion>=10) {
552 return; 552 return;
553 } 553 }
554 switch (body->bd_type) { 554 switch (body->bd_type) {
555 case MAILIMAP_BODY_1PART: 555 case MAILIMAP_BODY_1PART:
556 { 556 {
557 QValueList<int>countlist = recList; 557 QValueList<int>countlist = recList;
558 countlist.append(current_count); 558 countlist.append(current_count);
559 RecPart currentPart; 559 RecPart currentPart;
560 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 560 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
561 QString id(""); 561 QString id("");
562 currentPart.setPositionlist(countlist); 562 currentPart.setPositionlist(countlist);
563 for (unsigned int j = 0; j < countlist.count();++j) { 563 for (unsigned int j = 0; j < countlist.count();++j) {
564 id+=(j>0?" ":""); 564 id+=(j>0?" ":"");
565 id+=QString("%1").arg(countlist[j]); 565 id+=QString("%1").arg(countlist[j]);
566 } 566 }
567 qDebug("ID = %s",id.latin1()); 567 qDebug("ID = %s",id.latin1());
568 currentPart.setIdentifier(id); 568 currentPart.setIdentifier(id);
569 fillSinglePart(currentPart,part1); 569 fillSinglePart(currentPart,part1);
570 /* important: Check for is NULL 'cause a body can be empty! 570 /* important: Check for is NULL 'cause a body can be empty!
571 And we put it only into the mail if it is the FIRST part */ 571 And we put it only into the mail if it is the FIRST part */
572 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { 572 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) {
573 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); 573 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding());
574 target_body.setDescription(currentPart); 574 target_body.setDescription(currentPart);
575 target_body.setBodytext(body_text); 575 target_body.setBodytext(body_text);
576 if (countlist.count()>1) { 576 if (countlist.count()>1) {
577 target_body.addPart(currentPart); 577 target_body.addPart(currentPart);
578 } 578 }
579 } else { 579 } else {
580 target_body.addPart(currentPart); 580 target_body.addPart(currentPart);
581 } 581 }
582 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 582 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
583 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); 583 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
584 } 584 }
585 } 585 }
586 break; 586 break;
587 case MAILIMAP_BODY_MPART: 587 case MAILIMAP_BODY_MPART:
588 { 588 {
589 QValueList<int>countlist = recList; 589 QValueList<int>countlist = recList;
590 clistcell*current=0; 590 clistcell*current=0;
591 mailimap_body*current_body=0; 591 mailimap_body*current_body=0;
592 unsigned int ccount = 1; 592 unsigned int ccount = 1;
593 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 593 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
594 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 594 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
595 current_body = (mailimap_body*)current->data; 595 current_body = (mailimap_body*)current->data;
596 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 596 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
597 RecPart targetPart; 597 RecPart targetPart;
598 targetPart.setType("multipart"); 598 targetPart.setType("multipart");
599 fillMultiPart(targetPart,mailDescription); 599 fillMultiPart(targetPart,mailDescription);
600 countlist.append(current_count); 600 countlist.append(current_count);
601 targetPart.setPositionlist(countlist); 601 targetPart.setPositionlist(countlist);
602 target_body.addPart(targetPart); 602 target_body.addPart(targetPart);
603 QString id(""); 603 QString id("");
604 for (unsigned int j = 0; j < countlist.count();++j) { 604 for (unsigned int j = 0; j < countlist.count();++j) {
605 id+=(j>0?" ":""); 605 id+=(j>0?" ":"");
606 id+=QString("%1").arg(countlist[j]); 606 id+=QString("%1").arg(countlist[j]);
607 } 607 }
608 qDebug("ID(mpart) = %s",id.latin1()); 608 qDebug("ID(mpart) = %s",id.latin1());
609 } 609 }
610 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); 610 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
611 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 611 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
612 countlist = recList; 612 countlist = recList;
613 } 613 }
614 ++ccount; 614 ++ccount;
615 } 615 }
616 } 616 }
617 break; 617 break;
618 default: 618 default:
619 break; 619 break;
620 } 620 }
621} 621}
622 622
623void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 623void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
624{ 624{
625 if (!Description) { 625 if (!Description) {
626 return; 626 return;
627 } 627 }
628 switch (Description->bd_type) { 628 switch (Description->bd_type) {
629 case MAILIMAP_BODY_TYPE_1PART_TEXT: 629 case MAILIMAP_BODY_TYPE_1PART_TEXT:
630 target_part.setType("text"); 630 target_part.setType("text");
631 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 631 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
632 break; 632 break;
633 case MAILIMAP_BODY_TYPE_1PART_BASIC: 633 case MAILIMAP_BODY_TYPE_1PART_BASIC:
634 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 634 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
635 break; 635 break;
636 case MAILIMAP_BODY_TYPE_1PART_MSG: 636 case MAILIMAP_BODY_TYPE_1PART_MSG:
637 target_part.setType("message"); 637 target_part.setType("message");
638 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 638 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
639 break; 639 break;
640 default: 640 default:
641 break; 641 break;
642 } 642 }
643} 643}
644 644
645void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 645void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
646{ 646{
647 if (!which) { 647 if (!which) {
648 return; 648 return;
649 } 649 }
650 QString sub; 650 QString sub;
651 sub = which->bd_media_text; 651 sub = which->bd_media_text;
652 qDebug("Type= text/%s",which->bd_media_text); 652 qDebug("Type= text/%s",which->bd_media_text);
653 target_part.setSubtype(sub.lower()); 653 target_part.setSubtype(sub.lower());
654 target_part.setLines(which->bd_lines); 654 target_part.setLines(which->bd_lines);
655 fillBodyFields(target_part,which->bd_fields); 655 fillBodyFields(target_part,which->bd_fields);
656} 656}
657 657
658void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 658void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
659{ 659{
660 if (!which) { 660 if (!which) {
661 return; 661 return;
662 } 662 }
663 target_part.setSubtype("rfc822"); 663 target_part.setSubtype("rfc822");
664 qDebug("Message part"); 664 qDebug("Message part");
665 /* we set this type to text/plain */ 665 /* we set this type to text/plain */
666 target_part.setLines(which->bd_lines); 666 target_part.setLines(which->bd_lines);
667 fillBodyFields(target_part,which->bd_fields); 667 fillBodyFields(target_part,which->bd_fields);
668} 668}
669 669
670void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which) 670void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which)
671{ 671{
672 if (!which) return; 672 if (!which) return;
673 QString sub = which->bd_media_subtype; 673 QString sub = which->bd_media_subtype;
674 target_part.setSubtype(sub.lower()); 674 target_part.setSubtype(sub.lower());
675 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { 675 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
676 clistcell*cur = 0; 676 clistcell*cur = 0;
677 mailimap_single_body_fld_param*param=0; 677 mailimap_single_body_fld_param*param=0;
678 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 678 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
679 param = (mailimap_single_body_fld_param*)cur->data; 679 param = (mailimap_single_body_fld_param*)cur->data;
680 if (param) { 680 if (param) {
681 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 681 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
682 } 682 }
683 } 683 }
684 } 684 }
685} 685}
686 686
687void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 687void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
688{ 688{
689 if (!which) { 689 if (!which) {
690 return; 690 return;
691 } 691 }
692 QString type,sub; 692 QString type,sub;
693 switch (which->bd_media_basic->med_type) { 693 switch (which->bd_media_basic->med_type) {
694 case MAILIMAP_MEDIA_BASIC_APPLICATION: 694 case MAILIMAP_MEDIA_BASIC_APPLICATION:
695 type = "application"; 695 type = "application";
696 break; 696 break;
697 case MAILIMAP_MEDIA_BASIC_AUDIO: 697 case MAILIMAP_MEDIA_BASIC_AUDIO:
698 type = "audio"; 698 type = "audio";
699 break; 699 break;
700 case MAILIMAP_MEDIA_BASIC_IMAGE: 700 case MAILIMAP_MEDIA_BASIC_IMAGE:
701 type = "image"; 701 type = "image";
702 break; 702 break;
703 case MAILIMAP_MEDIA_BASIC_MESSAGE: 703 case MAILIMAP_MEDIA_BASIC_MESSAGE:
704 type = "message"; 704 type = "message";
705 break; 705 break;
706 case MAILIMAP_MEDIA_BASIC_VIDEO: 706 case MAILIMAP_MEDIA_BASIC_VIDEO:
707 type = "video"; 707 type = "video";
708 break; 708 break;
709 case MAILIMAP_MEDIA_BASIC_OTHER: 709 case MAILIMAP_MEDIA_BASIC_OTHER:
710 default: 710 default:
711 if (which->bd_media_basic->med_basic_type) { 711 if (which->bd_media_basic->med_basic_type) {
712 type = which->bd_media_basic->med_basic_type; 712 type = which->bd_media_basic->med_basic_type;
713 } else { 713 } else {
714 type = ""; 714 type = "";
715 } 715 }
716 break; 716 break;
717 } 717 }
718 if (which->bd_media_basic->med_subtype) { 718 if (which->bd_media_basic->med_subtype) {
719 sub = which->bd_media_basic->med_subtype; 719 sub = which->bd_media_basic->med_subtype;
720 } else { 720 } else {
721 sub = ""; 721 sub = "";
722 } 722 }
723 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 723 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
724 target_part.setType(type.lower()); 724 target_part.setType(type.lower());
725 target_part.setSubtype(sub.lower()); 725 target_part.setSubtype(sub.lower());
726 fillBodyFields(target_part,which->bd_fields); 726 fillBodyFields(target_part,which->bd_fields);
727} 727}
728 728
729void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 729void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
730{ 730{
731 if (!which) return; 731 if (!which) return;
732 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 732 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
733 clistcell*cur; 733 clistcell*cur;
734 mailimap_single_body_fld_param*param=0; 734 mailimap_single_body_fld_param*param=0;
735 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 735 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
736 param = (mailimap_single_body_fld_param*)cur->data; 736 param = (mailimap_single_body_fld_param*)cur->data;
737 if (param) { 737 if (param) {
738 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 738 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
739 } 739 }
740 } 740 }
741 } 741 }
742 mailimap_body_fld_enc*enc = which->bd_encoding; 742 mailimap_body_fld_enc*enc = which->bd_encoding;
743 QString encoding(""); 743 QString encoding("");
744 switch (enc->enc_type) { 744 switch (enc->enc_type) {
745 case MAILIMAP_BODY_FLD_ENC_7BIT: 745 case MAILIMAP_BODY_FLD_ENC_7BIT:
746 encoding = "7bit"; 746 encoding = "7bit";
747 break; 747 break;
748 case MAILIMAP_BODY_FLD_ENC_8BIT: 748 case MAILIMAP_BODY_FLD_ENC_8BIT:
749 encoding = "8bit"; 749 encoding = "8bit";
750 break; 750 break;
751 case MAILIMAP_BODY_FLD_ENC_BINARY: 751 case MAILIMAP_BODY_FLD_ENC_BINARY:
752 encoding="binary"; 752 encoding="binary";
753 break; 753 break;
754 case MAILIMAP_BODY_FLD_ENC_BASE64: 754 case MAILIMAP_BODY_FLD_ENC_BASE64:
755 encoding="base64"; 755 encoding="base64";
756 break; 756 break;
757 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 757 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
758 encoding="quoted-printable"; 758 encoding="quoted-printable";
759 break; 759 break;
760 case MAILIMAP_BODY_FLD_ENC_OTHER: 760 case MAILIMAP_BODY_FLD_ENC_OTHER:
761 default: 761 default:
762 if (enc->enc_value) { 762 if (enc->enc_value) {
763 char*t=enc->enc_value; 763 char*t=enc->enc_value;
764 encoding=QString(enc->enc_value); 764 encoding=QString(enc->enc_value);
765 enc->enc_value=0L; 765 enc->enc_value=0L;
766 free(t); 766 free(t);
767 } 767 }
768 } 768 }
769 if (which->bd_description) { 769 if (which->bd_description) {
770 target_part.setDescription(QString(which->bd_description)); 770 target_part.setDescription(QString(which->bd_description));
771 } 771 }
772 target_part.setEncoding(encoding); 772 target_part.setEncoding(encoding);
773 target_part.setSize(which->bd_size); 773 target_part.setSize(which->bd_size);
774} 774}
775 775
776void IMAPwrapper::deleteMail(const RecMail&mail) 776void IMAPwrapper::deleteMail(const RecMail&mail)
777{ 777{
778 mailimap_flag_list*flist; 778 mailimap_flag_list*flist;
779 mailimap_set *set; 779 mailimap_set *set;
780 mailimap_store_att_flags * store_flags; 780 mailimap_store_att_flags * store_flags;
781 int err; 781 int err;
782 login(); 782 login();
783 if (!m_imap) { 783 if (!m_imap) {
784 return; 784 return;
785 } 785 }
786 err = selectMbox(mail.getMbox()); 786 err = selectMbox(mail.getMbox());
787 if ( err != MAILIMAP_NO_ERROR ) { 787 if ( err != MAILIMAP_NO_ERROR ) {
788 return; 788 return;
789 } 789 }
790 flist = mailimap_flag_list_new_empty(); 790 flist = mailimap_flag_list_new_empty();
791 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 791 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
792 store_flags = mailimap_store_att_flags_new_set_flags(flist); 792 store_flags = mailimap_store_att_flags_new_set_flags(flist);
793 set = mailimap_set_new_single(mail.getNumber()); 793 set = mailimap_set_new_single(mail.getNumber());
794 err = mailimap_store(m_imap,set,store_flags); 794 err = mailimap_store(m_imap,set,store_flags);
795 mailimap_set_free( set ); 795 mailimap_set_free( set );
796 mailimap_store_att_flags_free(store_flags); 796 mailimap_store_att_flags_free(store_flags);
797 797
798 if (err != MAILIMAP_NO_ERROR) { 798 if (err != MAILIMAP_NO_ERROR) {
799 qDebug("error deleting mail: %s",m_imap->imap_response); 799 qDebug("error deleting mail: %s",m_imap->imap_response);
800 return; 800 return;
801 } 801 }
802 qDebug("deleting mail: %s",m_imap->imap_response); 802 qDebug("deleting mail: %s",m_imap->imap_response);
803 /* should we realy do that at this moment? */ 803 /* should we realy do that at this moment? */
804 err = mailimap_expunge(m_imap); 804 err = mailimap_expunge(m_imap);
805 if (err != MAILIMAP_NO_ERROR) { 805 if (err != MAILIMAP_NO_ERROR) {
806 qDebug("error deleting mail: %s",m_imap->imap_response); 806 qDebug("error deleting mail: %s",m_imap->imap_response);
807 } 807 }
808 qDebug("Delete successfull %s",m_imap->imap_response); 808 qDebug("Delete successfull %s",m_imap->imap_response);
809} 809}
810 810
811void IMAPwrapper::answeredMail(const RecMail&mail) 811void IMAPwrapper::answeredMail(const RecMail&mail)
812{ 812{
813 mailimap_flag_list*flist; 813 mailimap_flag_list*flist;
814 mailimap_set *set; 814 mailimap_set *set;
815 mailimap_store_att_flags * store_flags; 815 mailimap_store_att_flags * store_flags;
816 int err; 816 int err;
817 login(); 817 login();
818 if (!m_imap) { 818 if (!m_imap) {
819 return; 819 return;
820 } 820 }
821 err = selectMbox(mail.getMbox()); 821 err = selectMbox(mail.getMbox());
822 if ( err != MAILIMAP_NO_ERROR ) { 822 if ( err != MAILIMAP_NO_ERROR ) {
823 return; 823 return;
824 } 824 }
825 flist = mailimap_flag_list_new_empty(); 825 flist = mailimap_flag_list_new_empty();
826 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 826 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
827 store_flags = mailimap_store_att_flags_new_add_flags(flist); 827 store_flags = mailimap_store_att_flags_new_add_flags(flist);
828 set = mailimap_set_new_single(mail.getNumber()); 828 set = mailimap_set_new_single(mail.getNumber());
829 err = mailimap_store(m_imap,set,store_flags); 829 err = mailimap_store(m_imap,set,store_flags);
830 mailimap_set_free( set ); 830 mailimap_set_free( set );
831 mailimap_store_att_flags_free(store_flags); 831 mailimap_store_att_flags_free(store_flags);
832 832
833 if (err != MAILIMAP_NO_ERROR) { 833 if (err != MAILIMAP_NO_ERROR) {
834 qDebug("error marking mail: %s",m_imap->imap_response); 834 qDebug("error marking mail: %s",m_imap->imap_response);
835 return; 835 return;
836 } 836 }
837} 837}
838 838
839QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 839QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
840{ 840{
841 QString body(""); 841 QString body("");
842 encodedString*res = fetchRawPart(mail,path,internal_call); 842 encodedString*res = fetchRawPart(mail,path,internal_call);
843 encodedString*r = decode_String(res,enc); 843 encodedString*r = decode_String(res,enc);
844 delete res; 844 delete res;
845 if (r) { 845 if (r) {
846 if (r->Length()>0) { 846 if (r->Length()>0) {
847 body = r->Content(); 847 body = r->Content();
848 } 848 }
849 delete r; 849 delete r;
850 } 850 }
851 return body; 851 return body;
852} 852}
853 853
854QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 854QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
855{ 855{
856 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); 856 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
857} 857}
858 858
859encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) 859encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
860{ 860{
861 encodedString*res = fetchRawPart(mail,part.Positionlist(),false); 861 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
862 encodedString*r = decode_String(res,part.Encoding()); 862 encodedString*r = decode_String(res,part.Encoding());
863 delete res; 863 delete res;
864 return r; 864 return r;
865} 865}
866 866
867encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 867encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
868{ 868{
869 return fetchRawPart(mail,part.Positionlist(),false); 869 return fetchRawPart(mail,part.Positionlist(),false);
870} 870}
871 871
872int IMAPwrapper::deleteAllMail(const Folder*folder) 872int IMAPwrapper::deleteAllMail(const Folder*folder)
873{ 873{
874 login(); 874 login();
875 if (!m_imap) { 875 if (!m_imap) {
876 return 0; 876 return 0;
877 } 877 }
878 mailimap_flag_list*flist; 878 mailimap_flag_list*flist;
879 mailimap_set *set; 879 mailimap_set *set;
880 mailimap_store_att_flags * store_flags; 880 mailimap_store_att_flags * store_flags;
881 int err = selectMbox(folder->getName()); 881 int err = selectMbox(folder->getName());
882 if ( err != MAILIMAP_NO_ERROR ) { 882 if ( err != MAILIMAP_NO_ERROR ) {
883 return 0; 883 return 0;
884 } 884 }
885 885
886 int last = m_imap->imap_selection_info->sel_exists; 886 int last = m_imap->imap_selection_info->sel_exists;
887 if (last == 0) { 887 if (last == 0) {
888 Global::statusMessage(tr("Mailbox has no mails!")); 888 Global::statusMessage(tr("Mailbox has no mails!"));
889 return 0; 889 return 0;
890 } 890 }
891 flist = mailimap_flag_list_new_empty(); 891 flist = mailimap_flag_list_new_empty();
892 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 892 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
893 store_flags = mailimap_store_att_flags_new_set_flags(flist); 893 store_flags = mailimap_store_att_flags_new_set_flags(flist);
894 set = mailimap_set_new_interval( 1, last ); 894 set = mailimap_set_new_interval( 1, last );
895 err = mailimap_store(m_imap,set,store_flags); 895 err = mailimap_store(m_imap,set,store_flags);
896 mailimap_set_free( set ); 896 mailimap_set_free( set );
897 mailimap_store_att_flags_free(store_flags); 897 mailimap_store_att_flags_free(store_flags);
898 if (err != MAILIMAP_NO_ERROR) { 898 if (err != MAILIMAP_NO_ERROR) {
899 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 899 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
900 return 0; 900 return 0;
901 } 901 }
902 qDebug("deleting mail: %s",m_imap->imap_response); 902 qDebug("deleting mail: %s",m_imap->imap_response);
903 /* should we realy do that at this moment? */ 903 /* should we realy do that at this moment? */
904 err = mailimap_expunge(m_imap); 904 err = mailimap_expunge(m_imap);
905 if (err != MAILIMAP_NO_ERROR) { 905 if (err != MAILIMAP_NO_ERROR) {
906 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 906 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
907 return 0; 907 return 0;
908 } 908 }
909 qDebug("Delete successfull %s",m_imap->imap_response); 909 qDebug("Delete successfull %s",m_imap->imap_response);
910 return 1; 910 return 1;
911} 911}
912 912
913int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) 913int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder)
914{ 914{
915 if (folder.length()==0) return 0; 915 if (folder.length()==0) return 0;
916 login(); 916 login();
917 if (!m_imap) {return 0;} 917 if (!m_imap) {return 0;}
918 QString pre = account->getPrefix(); 918 QString pre = account->getPrefix();
919 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { 919 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
920 pre+=delemiter; 920 pre+=delemiter;
921 } 921 }
922 if (parentfolder) { 922 if (parentfolder) {
923 pre += parentfolder->getDisplayName()+delemiter; 923 pre += parentfolder->getDisplayName()+delemiter;
924 } 924 }
925 pre+=folder; 925 pre+=folder;
926 if (getsubfolder) { 926 if (getsubfolder) {
927 if (delemiter.length()>0) { 927 if (delemiter.length()>0) {
928 pre+=delemiter; 928 pre+=delemiter;
929 } else { 929 } else {
930 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); 930 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre));
931 return 0; 931 return 0;
932 } 932 }
933 } 933 }
934 qDebug("Creating %s",pre.latin1()); 934 qDebug("Creating %s",pre.latin1());
935 int res = mailimap_create(m_imap,pre.latin1()); 935 int res = mailimap_create(m_imap,pre.latin1());
936 if (res != MAILIMAP_NO_ERROR) { 936 if (res != MAILIMAP_NO_ERROR) {
937 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 937 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
938 return 0; 938 return 0;
939 } 939 }
940 return 1; 940 return 1;
941} 941}
942 942
943int IMAPwrapper::deleteMbox(const Folder*folder) 943int IMAPwrapper::deleteMbox(const Folder*folder)
944{ 944{
945 if (!folder) return 0; 945 if (!folder) return 0;
946 login(); 946 login();
947 if (!m_imap) {return 0;} 947 if (!m_imap) {return 0;}
948 int res = mailimap_delete(m_imap,folder->getName()); 948 int res = mailimap_delete(m_imap,folder->getName());
949 if (res != MAILIMAP_NO_ERROR) { 949 if (res != MAILIMAP_NO_ERROR) {
950 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 950 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
951 return 0; 951 return 0;
952 } 952 }
953 return 1; 953 return 1;
954} 954}
955 955
956void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 956void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
957{ 957{
958 mailimap_status_att_list * att_list =0; 958 mailimap_status_att_list * att_list =0;
959 mailimap_mailbox_data_status * status=0; 959 mailimap_mailbox_data_status * status=0;
960 clistiter * cur = 0; 960 clistiter * cur = 0;
961 int r = 0; 961 int r = 0;
962 int res = 0; 962 int res = 0;
963 target_stat.message_count = 0; 963 target_stat.message_count = 0;
964 target_stat.message_unseen = 0; 964 target_stat.message_unseen = 0;
965 target_stat.message_recent = 0; 965 target_stat.message_recent = 0;
966 login(); 966 login();
967 if (!m_imap) { 967 if (!m_imap) {
968 return; 968 return;
969 } 969 }
970 att_list = mailimap_status_att_list_new_empty(); 970 att_list = mailimap_status_att_list_new_empty();
971 if (!att_list) return; 971 if (!att_list) return;
972 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 972 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
973 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 973 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
974 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 974 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
975 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 975 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
976 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { 976 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
977 for (cur = clist_begin(status->st_info_list); 977 for (cur = clist_begin(status->st_info_list);
978 cur != NULL ; cur = clist_next(cur)) { 978 cur != NULL ; cur = clist_next(cur)) {
979 mailimap_status_info * status_info; 979 mailimap_status_info * status_info;
980 status_info = (mailimap_status_info *)clist_content(cur); 980 status_info = (mailimap_status_info *)clist_content(cur);
981 switch (status_info->st_att) { 981 switch (status_info->st_att) {
982 case MAILIMAP_STATUS_ATT_MESSAGES: 982 case MAILIMAP_STATUS_ATT_MESSAGES:
983 target_stat.message_count = status_info->st_value; 983 target_stat.message_count = status_info->st_value;
984 break; 984 break;
985 case MAILIMAP_STATUS_ATT_RECENT: 985 case MAILIMAP_STATUS_ATT_RECENT:
986 target_stat.message_recent = status_info->st_value; 986 target_stat.message_recent = status_info->st_value;
987 break; 987 break;
988 case MAILIMAP_STATUS_ATT_UNSEEN: 988 case MAILIMAP_STATUS_ATT_UNSEEN:
989 target_stat.message_unseen = status_info->st_value; 989 target_stat.message_unseen = status_info->st_value;
990 break; 990 break;
991 } 991 }
992 } 992 }
993 } else { 993 } else {
994 qDebug("Error retrieving status"); 994 qDebug("Error retrieving status");
995 } 995 }
996 if (status) mailimap_mailbox_data_status_free(status); 996 if (status) mailimap_mailbox_data_status_free(status);
997 if (att_list) mailimap_status_att_list_free(att_list); 997 if (att_list) mailimap_status_att_list_free(att_list);
998} 998}
999 999
1000void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 1000void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
1001{ 1001{
1002 login(); 1002 login();
1003 if (!m_imap) return; 1003 if (!m_imap) return;
1004 if (!msg) return; 1004 if (!msg) return;
1005 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); 1005 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
1006 if (r != MAILIMAP_NO_ERROR) { 1006 if (r != MAILIMAP_NO_ERROR) {
1007 Global::statusMessage("Error storing mail!"); 1007 Global::statusMessage("Error storing mail!");
1008 } 1008 }
1009} 1009}
1010 1010
1011const QString&IMAPwrapper::getType()const 1011const QString&IMAPwrapper::getType()const
1012{ 1012{
1013 return account->getType(); 1013 return account->getType();
1014} 1014}
1015 1015
1016const QString&IMAPwrapper::getName()const 1016const QString&IMAPwrapper::getName()const
1017{ 1017{
1018 qDebug("Get name: %s",account->getAccountName().latin1()); 1018 qDebug("Get name: %s",account->getAccountName().latin1());
1019 return account->getAccountName(); 1019 return account->getAccountName();
1020} 1020}
1021 1021
1022encodedString* IMAPwrapper::fetchRawBody(const RecMail&mail) 1022encodedString* IMAPwrapper::fetchRawBody(const RecMail&mail)
1023{ 1023{
1024 // dummy 1024 // dummy
1025 QValueList<int> path; 1025 QValueList<int> path;
1026 return fetchRawPart(mail,path,false); 1026 return fetchRawPart(mail,path,false);
1027} 1027}
1028 1028
1029void IMAPwrapper::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 1029void IMAPwrapper::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
1030{ 1030{
1031 if (targetWrapper != this) { 1031 if (targetWrapper != this) {
1032 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); 1032 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit);
1033 qDebug("Using generic"); 1033 qDebug("Using generic");
1034 return; 1034 return;
1035 } 1035 }
1036 mailimap_set *set = 0; 1036 mailimap_set *set = 0;
1037 login(); 1037 login();
1038 if (!m_imap) { 1038 if (!m_imap) {
1039 return; 1039 return;
1040 } 1040 }
1041 int err = selectMbox(fromFolder->getName()); 1041 int err = selectMbox(fromFolder->getName());
1042 if ( err != MAILIMAP_NO_ERROR ) { 1042 if ( err != MAILIMAP_NO_ERROR ) {
1043 return; 1043 return;
1044 } 1044 }
1045 int last = m_imap->imap_selection_info->sel_exists; 1045 int last = m_imap->imap_selection_info->sel_exists;
1046 set = mailimap_set_new_interval( 1, last ); 1046 set = mailimap_set_new_interval( 1, last );
1047 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1047 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1048 mailimap_set_free( set ); 1048 mailimap_set_free( set );
1049 if ( err != MAILIMAP_NO_ERROR ) { 1049 if ( err != MAILIMAP_NO_ERROR ) {
1050 QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); 1050 QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response);
1051 Global::statusMessage(error_msg); 1051 Global::statusMessage(error_msg);
1052 qDebug(error_msg); 1052 qDebug(error_msg);
1053 return; 1053 return;
1054 } 1054 }
1055 if (moveit) { 1055 if (moveit) {
1056 deleteAllMail(fromFolder); 1056 deleteAllMail(fromFolder);
1057 } 1057 }
1058} 1058}
1059
1060void IMAPwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
1061{
1062 if (targetWrapper != this) {
1063 qDebug("Using generic");
1064 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit);
1065 return;
1066 }
1067 mailimap_set *set = 0;
1068 login();
1069 if (!m_imap) {
1070 return;
1071 }
1072 int err = selectMbox(mail.getMbox());
1073 if ( err != MAILIMAP_NO_ERROR ) {
1074 return;
1075 }
1076 set = mailimap_set_new_single(mail.getNumber());
1077 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1078 mailimap_set_free( set );
1079 if ( err != MAILIMAP_NO_ERROR ) {
1080 QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response);
1081 Global::statusMessage(error_msg);
1082 qDebug(error_msg);
1083 return;
1084 }
1085 if (moveit) {
1086 deleteMail(mail);
1087 }
1088}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index 99986c2..c10f86a 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -1,76 +1,77 @@
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
9struct mailimap; 9struct mailimap;
10struct mailimap_body; 10struct mailimap_body;
11struct mailimap_body_type_1part; 11struct mailimap_body_type_1part;
12struct mailimap_body_type_text; 12struct mailimap_body_type_text;
13struct mailimap_body_type_basic; 13struct mailimap_body_type_basic;
14struct mailimap_body_type_msg; 14struct mailimap_body_type_msg;
15struct mailimap_body_type_mpart; 15struct mailimap_body_type_mpart;
16struct mailimap_body_fields; 16struct mailimap_body_fields;
17struct mailimap_msg_att; 17struct mailimap_msg_att;
18class encodedString; 18class encodedString;
19 19
20class IMAPwrapper : public AbstractMail 20class IMAPwrapper : public AbstractMail
21{ 21{
22 Q_OBJECT 22 Q_OBJECT
23public: 23public:
24 IMAPwrapper( IMAPaccount *a ); 24 IMAPwrapper( IMAPaccount *a );
25 virtual ~IMAPwrapper(); 25 virtual ~IMAPwrapper();
26 virtual QList<Folder>* listFolders(); 26 virtual QList<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 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(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
35 virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
35 36
36 virtual RecBody fetchBody(const RecMail&mail); 37 virtual RecBody fetchBody(const RecMail&mail);
37 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 38 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
38 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 39 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
39 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 40 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
40 virtual encodedString* fetchRawBody(const RecMail&mail); 41 virtual encodedString* fetchRawBody(const RecMail&mail);
41 42
42 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); 43 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
43 virtual int deleteMbox(const Folder*folder); 44 virtual int deleteMbox(const Folder*folder);
44 45
45 static void imap_progress( size_t current, size_t maximum ); 46 static void imap_progress( size_t current, size_t maximum );
46 47
47 virtual void logout(); 48 virtual void logout();
48 virtual const QString&getType()const; 49 virtual const QString&getType()const;
49 virtual const QString&getName()const; 50 virtual const QString&getName()const;
50 51
51protected: 52protected:
52 RecMail*parse_list_result(mailimap_msg_att*); 53 RecMail*parse_list_result(mailimap_msg_att*);
53 void login(); 54 void login();
54 55
55 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); 56 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
56 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); 57 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call);
57 int selectMbox(const QString&mbox); 58 int selectMbox(const QString&mbox);
58 59
59 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 60 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
60 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 61 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
61 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 62 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
62 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); 63 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
63 void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which); 64 void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which);
64 void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1); 65 void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1);
65 66
66 /* just helpers */ 67 /* just helpers */
67 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 68 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
68 static QStringList address_list_to_stringlist(clist*list); 69 static QStringList address_list_to_stringlist(clist*list);
69 70
70 71
71 IMAPaccount *account; 72 IMAPaccount *account;
72 mailimap *m_imap; 73 mailimap *m_imap;
73 QString m_Lastmbox; 74 QString m_Lastmbox;
74}; 75};
75 76
76#endif 77#endif
diff --git a/noncore/net/mail/mail.pro b/noncore/net/mail/mail.pro
index 1abd2e8..90e1e46 100644
--- a/noncore/net/mail/mail.pro
+++ b/noncore/net/mail/mail.pro
@@ -1,56 +1,57 @@
1CONFIG += qt warn_on debug quick-app 1CONFIG += qt warn_on debug quick-app
2 2
3HEADERS = defines.h \ 3HEADERS = defines.h \
4 editaccounts.h \ 4 editaccounts.h \
5 composemail.h \ 5 composemail.h \
6 accountview.h \ 6 accountview.h \
7 mainwindow.h \ 7 mainwindow.h \
8 viewmail.h \ 8 viewmail.h \
9 viewmailbase.h \ 9 viewmailbase.h \
10 opiemail.h \ 10 opiemail.h \
11 mailistviewitem.h \ 11 mailistviewitem.h \
12 settingsdialog.h \ 12 settingsdialog.h \
13 statuswidget.h \ 13 statuswidget.h \
14 newmaildir.h \ 14 newmaildir.h \
15 selectstore.h 15 selectstore.h
16 16
17SOURCES = main.cpp \ 17SOURCES = main.cpp \
18 opiemail.cpp \ 18 opiemail.cpp \
19 mainwindow.cpp \ 19 mainwindow.cpp \
20 accountview.cpp \ 20 accountview.cpp \
21 composemail.cpp \ 21 composemail.cpp \
22 addresspicker.cpp \ 22 addresspicker.cpp \
23 editaccounts.cpp \ 23 editaccounts.cpp \
24 viewmail.cpp \ 24 viewmail.cpp \
25 viewmailbase.cpp \ 25 viewmailbase.cpp \
26 mailistviewitem.cpp \
26 settingsdialog.cpp \ 27 settingsdialog.cpp \
27 statuswidget.cpp \ 28 statuswidget.cpp \
28 newmaildir.cpp \ 29 newmaildir.cpp \
29 selectstore.cpp 30 selectstore.cpp
30 31
31INTERFACES = editaccountsui.ui \ 32INTERFACES = editaccountsui.ui \
32 selectmailtypeui.ui \ 33 selectmailtypeui.ui \
33 imapconfigui.ui \ 34 imapconfigui.ui \
34 pop3configui.ui \ 35 pop3configui.ui \
35 nntpconfigui.ui \ 36 nntpconfigui.ui \
36 smtpconfigui.ui \ 37 smtpconfigui.ui \
37 addresspickerui.ui \ 38 addresspickerui.ui \
38 composemailui.ui \ 39 composemailui.ui \
39 settingsdialogui.ui \ 40 settingsdialogui.ui \
40 statuswidgetui.ui \ 41 statuswidgetui.ui \
41 newmaildirui.ui \ 42 newmaildirui.ui \
42 selectstoreui.ui 43 selectstoreui.ui
43 44
44 45
45INCLUDEPATH += $(OPIEDIR)/include 46INCLUDEPATH += $(OPIEDIR)/include
46 47
47CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX ) 48CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX )
48contains( CONFTEST, y ){ 49contains( CONFTEST, y ){
49 LIBS += -lqpe -lopie -lmailwrapper -liconv 50 LIBS += -lqpe -lopie -lmailwrapper -liconv
50}else{ 51}else{
51 LIBS += -lqpe -lopie -lmailwrapper 52 LIBS += -lqpe -lopie -lmailwrapper
52} 53}
53 54
54TARGET = opiemail 55TARGET = opiemail
55 56
56include ( $(OPIEDIR)/include.pro ) 57include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/net/mail/mailistviewitem.cpp b/noncore/net/mail/mailistviewitem.cpp
new file mode 100644
index 0000000..f224dc3
--- a/dev/null
+++ b/noncore/net/mail/mailistviewitem.cpp
@@ -0,0 +1,65 @@
1#include "mailistviewitem.h"
2#include <qtextstream.h>
3#include <qpe/resource.h>
4
5MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * item )
6 :QListViewItem(parent,item),mail_data()
7{
8}
9
10void MailListViewItem::showEntry()
11{
12 if ( mail_data.getFlags().testBit( FLAG_ANSWERED ) == true) {
13 setPixmap( 0, Resource::loadPixmap( "mail/kmmsgreplied") );
14 } else if ( mail_data.getFlags().testBit( FLAG_SEEN ) == true ) {
15 /* I think it looks nicer if there are not such a log of icons but only on mails
16 replied or new - Alwin*/
17 //setPixmap( 0, Resource::loadPixmap( "mail/kmmsgunseen") );
18 } else {
19 setPixmap( 0, Resource::loadPixmap( "mail/kmmsgnew") );
20 }
21 double s = mail_data.Msgsize();
22 int w;
23 w=0;
24
25 while (s>1024) {
26 s/=1024;
27 ++w;
28 if (w>=2) break;
29 }
30
31 QString q="";
32 QString fsize="";
33 switch(w) {
34 case 1:
35 q="k";
36 break;
37 case 2:
38 q="M";
39 break;
40 default:
41 break;
42 }
43
44 {
45 QTextOStream o(&fsize);
46 if (w>0) o.precision(2); else o.precision(0);
47 o.setf(QTextStream::fixed);
48 o << s << " " << q << "Byte";
49 }
50
51 setText(1,mail_data.getSubject());
52 setText(2,mail_data.getFrom());
53 setText(3,fsize);
54 setText(4,mail_data.getDate());
55}
56
57void MailListViewItem::storeData(const RecMail&data)
58{
59 mail_data = data;
60}
61
62const RecMail& MailListViewItem::data()const
63{
64 return mail_data;
65}
diff --git a/noncore/net/mail/mailistviewitem.h b/noncore/net/mail/mailistviewitem.h
index 271f616..3b352a2 100644
--- a/noncore/net/mail/mailistviewitem.h
+++ b/noncore/net/mail/mailistviewitem.h
@@ -1,22 +1,21 @@
1#ifndef __MAILLISTVIEWITEM_H 1#ifndef __MAILLISTVIEWITEM_H
2#define __MAILLISTVIEWITEM_H 2#define __MAILLISTVIEWITEM_H
3 3
4#include <qlistview.h> 4#include <qlistview.h>
5#include <libmailwrapper/mailtypes.h> 5#include <libmailwrapper/mailtypes.h>
6 6
7
8class MailListViewItem:public QListViewItem 7class MailListViewItem:public QListViewItem
9{ 8{
10public: 9public:
11 MailListViewItem(QListView * parent, MailListViewItem * after ); 10 MailListViewItem(QListView * parent, MailListViewItem * after );
12 virtual ~MailListViewItem(){} 11 virtual ~MailListViewItem(){}
13 12
14 void storeData(const RecMail&data); 13 void storeData(const RecMail&data);
15 const RecMail&data()const; 14 const RecMail&data()const;
16 void showEntry(); 15 void showEntry();
17 16
18protected: 17protected:
19 RecMail mail_data; 18 RecMail mail_data;
20}; 19};
21 20
22#endif 21#endif
diff --git a/noncore/net/mail/mainwindow.cpp b/noncore/net/mail/mainwindow.cpp
index e16f853..c38392c 100644
--- a/noncore/net/mail/mainwindow.cpp
+++ b/noncore/net/mail/mainwindow.cpp
@@ -1,304 +1,205 @@
1#include <qlabel.h> 1#include <qlabel.h>
2#include <qvbox.h> 2#include <qvbox.h>
3#include <qheader.h> 3#include <qheader.h>
4#include <qtimer.h> 4#include <qtimer.h>
5#include <qlayout.h> 5#include <qlayout.h>
6#include <qmessagebox.h> 6#include <qmessagebox.h>
7#include <qtextstream.h>
8 7
9#include <qpe/qpeapplication.h> 8#include <qpe/qpeapplication.h>
10#include <qpe/resource.h> 9#include <qpe/resource.h>
11 10
12
13#include "defines.h" 11#include "defines.h"
14#include "mainwindow.h" 12#include "mainwindow.h"
15#include "viewmail.h"
16#include <libmailwrapper/mailtypes.h>
17#include "mailistviewitem.h"
18 13
19 14
20MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags ) 15MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags )
21 : QMainWindow( parent, name, flags ) 16 : QMainWindow( parent, name, flags )
22{ 17{
23 18
24 setCaption( tr( "Mail" ) ); 19 setCaption( tr( "Mail" ) );
25 setToolBarsMovable( false ); 20 setToolBarsMovable( false );
26 21
27 toolBar = new QToolBar( this ); 22 toolBar = new QToolBar( this );
28 menuBar = new QMenuBar( toolBar ); 23 menuBar = new QMenuBar( toolBar );
29 mailMenu = new QPopupMenu( menuBar ); 24 mailMenu = new QPopupMenu( menuBar );
30 menuBar->insertItem( tr( "Mail" ), mailMenu ); 25 menuBar->insertItem( tr( "Mail" ), mailMenu );
31 settingsMenu = new QPopupMenu( menuBar ); 26 settingsMenu = new QPopupMenu( menuBar );
32 menuBar->insertItem( tr( "Settings" ), settingsMenu ); 27 menuBar->insertItem( tr( "Settings" ), settingsMenu );
33 28
34 addToolBar( toolBar ); 29 addToolBar( toolBar );
35 toolBar->setHorizontalStretchable( true ); 30 toolBar->setHorizontalStretchable( true );
36 31
37 QLabel *spacer = new QLabel( toolBar ); 32 QLabel *spacer = new QLabel( toolBar );
38 spacer->setBackgroundMode( QWidget::PaletteButton ); 33 spacer->setBackgroundMode( QWidget::PaletteButton );
39 toolBar->setStretchableWidget( spacer ); 34 toolBar->setStretchableWidget( spacer );
40 35
41 composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL, 36 composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL,
42 0, 0, this ); 37 0, 0, this );
43 composeMail->addTo( toolBar ); 38 composeMail->addTo( toolBar );
44 composeMail->addTo( mailMenu ); 39 composeMail->addTo( mailMenu );
45 40
46 sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED, 41 sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED,
47 0, 0, this ); 42 0, 0, this );
48 sendQueued->addTo( toolBar ); 43 sendQueued->addTo( toolBar );
49 sendQueued->addTo( mailMenu ); 44 sendQueued->addTo( mailMenu );
50 45
51 /* 46 /*
52 syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC, 47 syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC,
53 0, 0, this ); 48 0, 0, this );
54 syncFolders->addTo( toolBar ); 49 syncFolders->addTo( toolBar );
55 syncFolders->addTo( mailMenu ); 50 syncFolders->addTo( mailMenu );
56 */ 51 */
57 52
58 showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS, 53 showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS,
59 0, 0, this, 0, true ); 54 0, 0, this, 0, true );
60 showFolders->addTo( toolBar ); 55 showFolders->addTo( toolBar );
61 showFolders->addTo( mailMenu ); 56 showFolders->addTo( mailMenu );
62 showFolders->setOn( true ); 57 showFolders->setOn( true );
63 connect(showFolders, SIGNAL( toggled( bool ) ), 58 connect(showFolders, SIGNAL( toggled( bool ) ),
64 SLOT( slotShowFolders( bool ) ) ); 59 SLOT( slotShowFolders( bool ) ) );
65 60
66 /* 61 /*
67 searchMails = new QAction( tr( "Search mails" ), QIconSet( Resource::loadPixmap("find") ), 62 searchMails = new QAction( tr( "Search mails" ), QIconSet( Resource::loadPixmap("find") ),
68 0, 0, this ); 63 0, 0, this );
69 searchMails->addTo( toolBar ); 64 searchMails->addTo( toolBar );
70 searchMails->addTo( mailMenu ); 65 searchMails->addTo( mailMenu );
71 */ 66 */
72 67
73 deleteMails = new QAction(tr("Delete Mail"), QIconSet( Resource::loadPixmap("trash")), 0, 0, this); 68 deleteMails = new QAction(tr("Delete Mail"), QIconSet( Resource::loadPixmap("trash")), 0, 0, this);
74 deleteMails->addTo( toolBar ); 69 deleteMails->addTo( toolBar );
75 deleteMails->addTo( mailMenu ); 70 deleteMails->addTo( mailMenu );
76 connect( deleteMails, SIGNAL( activated() ), 71 connect( deleteMails, SIGNAL( activated() ),
77 SLOT( slotDeleteMail() ) ); 72 SLOT( slotDeleteMail() ) );
78 73
79 editSettings = new QAction( tr( "Edit settings" ), QIconSet( Resource::loadPixmap("SettingsIcon") ) , 74 editSettings = new QAction( tr( "Edit settings" ), QIconSet( Resource::loadPixmap("SettingsIcon") ) ,
80 0, 0, this ); 75 0, 0, this );
81 editSettings->addTo( settingsMenu ); 76 editSettings->addTo( settingsMenu );
82 connect( editSettings, SIGNAL( activated() ), 77 connect( editSettings, SIGNAL( activated() ),
83 SLOT( slotEditSettings() ) ); 78 SLOT( slotEditSettings() ) );
84 editAccounts = new QAction( tr( "Configure accounts" ), QIconSet( Resource::loadPixmap("mail/editaccounts") ) , 79 editAccounts = new QAction( tr( "Configure accounts" ), QIconSet( Resource::loadPixmap("mail/editaccounts") ) ,
85 0, 0, this ); 80 0, 0, this );
86 editAccounts->addTo( settingsMenu ); 81 editAccounts->addTo( settingsMenu );
87 82
88 //setCentralWidget( view ); 83 //setCentralWidget( view );
89 84
90 QVBox* wrapperBox = new QVBox( this ); 85 QVBox* wrapperBox = new QVBox( this );
91 setCentralWidget( wrapperBox ); 86 setCentralWidget( wrapperBox );
92 87
93 QWidget *view = new QWidget( wrapperBox ); 88 QWidget *view = new QWidget( wrapperBox );
94 89
95 layout = new QBoxLayout ( view, QBoxLayout::LeftToRight ); 90 layout = new QBoxLayout ( view, QBoxLayout::LeftToRight );
96 91
97 folderView = new AccountView( view ); 92 folderView = new AccountView( view );
98 folderView->header()->hide(); 93 folderView->header()->hide();
99 folderView->setRootIsDecorated( true ); 94 folderView->setRootIsDecorated( true );
100 folderView->addColumn( tr( "Mailbox" ) ); 95 folderView->addColumn( tr( "Mailbox" ) );
101 96
102 layout->addWidget( folderView ); 97 layout->addWidget( folderView );
103 98
104 mailView = new QListView( view ); 99 mailView = new QListView( view );
105 mailView->addColumn( tr( "" ) ); 100 mailView->addColumn( tr( "" ) );
106 mailView->addColumn( tr( "Subject" ),QListView::Manual ); 101 mailView->addColumn( tr( "Subject" ),QListView::Manual );
107 mailView->addColumn( tr( "Sender" ),QListView::Manual ); 102 mailView->addColumn( tr( "Sender" ),QListView::Manual );
108 mailView->addColumn( tr( "Size" ),QListView::Manual); 103 mailView->addColumn( tr( "Size" ),QListView::Manual);
109 mailView->addColumn( tr( "Date" )); 104 mailView->addColumn( tr( "Date" ));
110 mailView->setAllColumnsShowFocus(true); 105 mailView->setAllColumnsShowFocus(true);
111 mailView->setSorting(-1); 106 mailView->setSorting(-1);
112 107
113 statusWidget = new StatusWidget( wrapperBox ); 108 statusWidget = new StatusWidget( wrapperBox );
114 statusWidget->hide(); 109 statusWidget->hide();
115 110
116 layout->addWidget( mailView ); 111 layout->addWidget( mailView );
117 layout->setStretchFactor( folderView, 1 ); 112 layout->setStretchFactor( folderView, 1 );
118 layout->setStretchFactor( mailView, 2 ); 113 layout->setStretchFactor( mailView, 2 );
119 114
120 slotAdjustLayout(); 115 slotAdjustLayout();
121 116
122 QPEApplication::setStylusOperation( mailView->viewport(),QPEApplication::RightOnHold); 117 QPEApplication::setStylusOperation( mailView->viewport(),QPEApplication::RightOnHold);
123 QPEApplication::setStylusOperation( folderView->viewport(),QPEApplication::RightOnHold); 118 QPEApplication::setStylusOperation( folderView->viewport(),QPEApplication::RightOnHold);
124 119
125 connect( mailView, SIGNAL( mouseButtonClicked(int, QListViewItem *,const QPoint&,int ) ),this, 120 connect( mailView, SIGNAL( mouseButtonClicked(int, QListViewItem *,const QPoint&,int ) ),this,
126 SLOT( mailLeftClicked( int, QListViewItem *,const QPoint&,int ) ) ); 121 SLOT( mailLeftClicked( int, QListViewItem *,const QPoint&,int ) ) );
127 connect( mailView, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this, 122 connect( mailView, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this,
128 SLOT( mailHold( int, QListViewItem *,const QPoint&,int ) ) ); 123 SLOT( mailHold( int, QListViewItem *,const QPoint&,int ) ) );
129 connect(folderView, SIGNAL(refreshMailview(QList<RecMail>*)),this,SLOT(refreshMailView(QList<RecMail>*))); 124 connect(folderView, SIGNAL(refreshMailview(QList<RecMail>*)),this,SLOT(refreshMailView(QList<RecMail>*)));
125 connect( composeMail, SIGNAL( activated() ), SLOT( slotComposeMail() ) );
126 connect( sendQueued, SIGNAL( activated() ), SLOT( slotSendQueued() ) );
127// connect( searchMails, SIGNAL( activated() ), SLOT( slotSearchMails() ) );
128 connect( editAccounts, SIGNAL( activated() ), SLOT( slotEditAccounts() ) );
129 // Added by Stefan Eilers to allow starting by addressbook..
130 // copied from old mail2
131#if !defined(QT_NO_COP)
132 connect( qApp, SIGNAL( appMessage( const QCString&, const QByteArray& ) ),
133 this, SLOT( appMessage( const QCString&, const QByteArray& ) ) );
134#endif
130 135
131 QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) ); 136 QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) );
132} 137}
133 138
134MainWindow::~MainWindow() 139MainWindow::~MainWindow()
135{ 140{
136} 141}
137 142
143void MainWindow::appMessage(const QCString &, const QByteArray &)
144{
145 qDebug("appMessage not reached");
146}
147
138void MainWindow::slotAdjustLayout() { 148void MainWindow::slotAdjustLayout() {
139 149
140 QWidget *d = QApplication::desktop(); 150 QWidget *d = QApplication::desktop();
141 151
142 if ( d->width() < d->height() ) { 152 if ( d->width() < d->height() ) {
143 layout->setDirection( QBoxLayout::TopToBottom ); 153 layout->setDirection( QBoxLayout::TopToBottom );
144 } else { 154 } else {
145 layout->setDirection( QBoxLayout::LeftToRight ); 155 layout->setDirection( QBoxLayout::LeftToRight );
146 } 156 }
147} 157}
148 158
149void MainWindow::slotAdjustColumns() 159void MainWindow::slotAdjustColumns()
150{ 160{
151 bool hidden = folderView->isHidden(); 161 bool hidden = folderView->isHidden();
152 if ( hidden ) folderView->show(); 162 if ( hidden ) folderView->show();
153 folderView->setColumnWidth( 0, folderView->visibleWidth() ); 163 folderView->setColumnWidth( 0, folderView->visibleWidth() );
154 if ( hidden ) folderView->hide(); 164 if ( hidden ) folderView->hide();
155 165
156 mailView->setColumnWidth( 0, 10 ); 166 mailView->setColumnWidth( 0, 10 );
157 mailView->setColumnWidth( 1, mailView->visibleWidth() - 130 ); 167 mailView->setColumnWidth( 1, mailView->visibleWidth() - 130 );
158 mailView->setColumnWidth( 2, 80 ); 168 mailView->setColumnWidth( 2, 80 );
159 mailView->setColumnWidth( 3, 50 ); 169 mailView->setColumnWidth( 3, 50 );
160 mailView->setColumnWidth( 4, 50 ); 170 mailView->setColumnWidth( 4, 50 );
161} 171}
162 172
163void MainWindow::slotEditSettings() 173void MainWindow::slotEditSettings()
164{ 174{
165} 175}
166 176
167void MainWindow::slotShowFolders( bool show ) 177void MainWindow::slotShowFolders( bool )
168{ 178{
169 qDebug( "Show Folders" ); 179 qDebug( "slotShowFolders not reached" );
170 if ( show && folderView->isHidden() ) {
171 qDebug( "-> showing" );
172 folderView->show();
173 } else if ( !show && !folderView->isHidden() ) {
174 qDebug( "-> hiding" );
175 folderView->hide();
176 }
177} 180}
178 181
179void MainWindow::refreshMailView(QList<RecMail>*list) 182void MainWindow::refreshMailView(QList<RecMail>*)
180{ 183{
181 MailListViewItem*item = 0; 184 qDebug( "refreshMailView not reached" );
182 mailView->clear();
183 for (unsigned int i = 0; i < list->count();++i) {
184 item = new MailListViewItem(mailView,item);
185 item->storeData(*(list->at(i)));
186 item->showEntry();
187 }
188} 185}
189void MainWindow::mailLeftClicked(int button, QListViewItem *item,const QPoint&,int ) 186
187void MainWindow::mailLeftClicked(int, QListViewItem *,const QPoint&,int )
190{ 188{
191 /* just LEFT button - or tap with stylus on pda */ 189 qDebug( "mailLeftClicked not reached" );
192 if (button!=1) return;
193 if (!item) return;
194 displayMail();
195} 190}
196 191
197void MainWindow::displayMail() 192void MainWindow::displayMail()
198{ 193{
199 QListViewItem*item = mailView->currentItem(); 194 qDebug("displayMail not reached");
200 if (!item) return;
201 RecMail mail = ((MailListViewItem*)item)->data();
202 RecBody body = folderView->fetchBody(mail);
203 ViewMail readMail( this );
204 readMail.setBody( body );
205 readMail.setMail( mail );
206 readMail.showMaximized();
207 readMail.exec();
208
209 if ( readMail.deleted ) {
210 folderView->refreshCurrent();
211 } else {
212 ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "") );
213 }
214} 195}
215 196
216void MainWindow::slotDeleteMail() 197void MainWindow::slotDeleteMail()
217{ 198{
218 if (!mailView->currentItem()) return; 199 qDebug("deleteMail not reached");
219 RecMail mail = ((MailListViewItem*)mailView->currentItem() )->data();
220 if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail.getFrom() + " - " + mail.getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) {
221 mail.Wrapper()->deleteMail( mail );
222 folderView->refreshCurrent();
223 }
224}
225
226void MainWindow::mailHold(int button, QListViewItem *item,const QPoint&,int )
227{
228 /* just the RIGHT button - or hold on pda */
229 if (button!=2) {return;}
230 qDebug("Event right/hold");
231 if (!item) return;
232 QPopupMenu *m = new QPopupMenu(0);
233 if (m) {
234 m->insertItem(tr("Read this mail"),this,SLOT(displayMail()));
235 m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail()));
236 m->setFocus();
237 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
238 delete m;
239 }
240}
241
242MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * item )
243 :QListViewItem(parent,item),mail_data()
244{
245}
246
247void MailListViewItem::showEntry()
248{
249 if ( mail_data.getFlags().testBit( FLAG_ANSWERED ) == true) {
250 setPixmap( 0, Resource::loadPixmap( "mail/kmmsgreplied") );
251 } else if ( mail_data.getFlags().testBit( FLAG_SEEN ) == true ) {
252 /* I think it looks nicer if there are not such a log of icons but only on mails
253 replied or new - Alwin*/
254 //setPixmap( 0, Resource::loadPixmap( "mail/kmmsgunseen") );
255 } else {
256 setPixmap( 0, Resource::loadPixmap( "mail/kmmsgnew") );
257 }
258 double s = mail_data.Msgsize();
259 int w;
260 w=0;
261
262 while (s>1024) {
263 s/=1024;
264 ++w;
265 if (w>=2) break;
266 }
267
268 QString q="";
269 QString fsize="";
270 switch(w) {
271 case 1:
272 q="k";
273 break;
274 case 2:
275 q="M";
276 break;
277 default:
278 break;
279 }
280
281 {
282 QTextOStream o(&fsize);
283 if (w>0) o.precision(2); else o.precision(0);
284 o.setf(QTextStream::fixed);
285 o << s << " " << q << "Byte";
286 }
287
288 setText(1,mail_data.getSubject());
289 setText(2,mail_data.getFrom());
290 setText(3,fsize);
291 setText(4,mail_data.getDate());
292} 200}
293 201
294void MailListViewItem::storeData(const RecMail&data) 202void MainWindow::mailHold(int, QListViewItem *,const QPoint&,int )
295{ 203{
296 mail_data = data; 204 qDebug("mailHold not reached");
297} 205}
298
299const RecMail& MailListViewItem::data()const
300{
301 return mail_data;
302}
303
304
diff --git a/noncore/net/mail/mainwindow.h b/noncore/net/mail/mainwindow.h
index 15d216a..20614cc 100644
--- a/noncore/net/mail/mainwindow.h
+++ b/noncore/net/mail/mainwindow.h
@@ -1,49 +1,50 @@
1#ifndef MAINWINDOW_H 1#ifndef MAINWINDOW_H
2#define MAINWINDOW_H 2#define MAINWINDOW_H
3 3
4#include <qmainwindow.h> 4#include <qmainwindow.h>
5#include <qlistview.h> 5#include <qlistview.h>
6#include <qaction.h> 6#include <qaction.h>
7 7
8#include <qtoolbar.h> 8#include <qtoolbar.h>
9#include <qmenubar.h> 9#include <qmenubar.h>
10 10
11#include "accountview.h" 11#include "accountview.h"
12#include "statuswidget.h" 12#include "statuswidget.h"
13 13
14class RecMail; 14class RecMail;
15 15
16class MainWindow : public QMainWindow 16class MainWindow : public QMainWindow
17{ 17{
18 Q_OBJECT 18 Q_OBJECT
19 19
20public: 20public:
21 MainWindow( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 21 MainWindow( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
22 virtual ~MainWindow(); 22 virtual ~MainWindow();
23 23
24public slots: 24public slots:
25 virtual void slotAdjustColumns(); 25 virtual void slotAdjustColumns();
26 virtual void appMessage(const QCString &msg, const QByteArray &data);
26 27
27protected slots: 28protected slots:
28 virtual void slotShowFolders( bool show ); 29 virtual void slotShowFolders( bool show );
29 virtual void refreshMailView(QList<RecMail>*); 30 virtual void refreshMailView(QList<RecMail>*);
30 virtual void displayMail(); 31 virtual void displayMail();
31 virtual void slotDeleteMail(); 32 virtual void slotDeleteMail();
32 virtual void mailHold(int, QListViewItem *,const QPoint&,int); 33 virtual void mailHold(int, QListViewItem *,const QPoint&,int);
33 virtual void slotAdjustLayout(); 34 virtual void slotAdjustLayout();
34 virtual void slotEditSettings(); 35 virtual void slotEditSettings();
35 virtual void mailLeftClicked( int, QListViewItem *,const QPoint&,int ); 36 virtual void mailLeftClicked( int, QListViewItem *,const QPoint&,int );
36 37
37protected: 38protected:
38 QToolBar *toolBar; 39 QToolBar *toolBar;
39 StatusWidget *statusWidget; 40 StatusWidget *statusWidget;
40 QMenuBar *menuBar; 41 QMenuBar *menuBar;
41 QPopupMenu *mailMenu, *settingsMenu; 42 QPopupMenu *mailMenu, *settingsMenu;
42 QAction *composeMail, *sendQueued, *showFolders, *searchMails, *deleteMails, 43 QAction *composeMail, *sendQueued, *showFolders, *searchMails, *deleteMails,
43 *editSettings, *editAccounts, *syncFolders; 44 *editSettings, *editAccounts, *syncFolders;
44 AccountView *folderView; 45 AccountView *folderView;
45 QListView *mailView; 46 QListView *mailView;
46 QBoxLayout *layout; 47 QBoxLayout *layout;
47}; 48};
48 49
49#endif 50#endif
diff --git a/noncore/net/mail/opiemail.cpp b/noncore/net/mail/opiemail.cpp
index c888708..dee3f70 100644
--- a/noncore/net/mail/opiemail.cpp
+++ b/noncore/net/mail/opiemail.cpp
@@ -1,120 +1,211 @@
1#include <qmessagebox.h> 1#include <qmessagebox.h>
2#include "settingsdialog.h" 2#include "settingsdialog.h"
3#include "opiemail.h" 3#include "opiemail.h"
4#include "editaccounts.h" 4#include "editaccounts.h"
5#include "composemail.h" 5#include "composemail.h"
6#include <libmailwrapper/smtpwrapper.h> 6#include <libmailwrapper/smtpwrapper.h>
7#include <qpe/qcopenvelope_qws.h> 7#include <qpe/qcopenvelope_qws.h>
8#include <qpe/resource.h>
8#include <qaction.h> 9#include <qaction.h>
9#include <qapplication.h> 10#include <qapplication.h>
11#include <libmailwrapper/mailtypes.h>
12#include "mailistviewitem.h"
13#include "viewmail.h"
14#include "selectstore.h"
10 15
11OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags ) 16OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags )
12 : MainWindow( parent, name, flags ) 17 : MainWindow( parent, name, flags )
13{ 18{
14 settings = new Settings(); 19 settings = new Settings();
15 20
16 folderView->populate( settings->getAccounts() ); 21 folderView->populate( settings->getAccounts() );
17
18 connect( composeMail, SIGNAL( activated() ), SLOT( slotComposeMail() ) );
19 connect( sendQueued, SIGNAL( activated() ), SLOT( slotSendQueued() ) );
20// connect( searchMails, SIGNAL( activated() ), SLOT( slotSearchMails() ) );
21 connect( editAccounts, SIGNAL( activated() ), SLOT( slotEditAccounts() ) );
22 // Added by Stefan Eilers to allow starting by addressbook..
23 // copied from old mail2
24#if !defined(QT_NO_COP)
25 connect( qApp, SIGNAL( appMessage( const QCString&, const QByteArray& ) ),
26 this, SLOT( appMessage( const QCString&, const QByteArray& ) ) );
27#endif
28
29
30
31} 22}
32 23
33OpieMail::~OpieMail() 24OpieMail::~OpieMail()
34{ 25{
35 if (settings) delete settings; 26 if (settings) delete settings;
36} 27}
37 28
38void OpieMail::appMessage(const QCString &msg, const QByteArray &data) 29void OpieMail::appMessage(const QCString &msg, const QByteArray &data)
39{ 30{
40 // copied from old mail2 31 // copied from old mail2
41 if (msg == "writeMail(QString,QString)") { 32 if (msg == "writeMail(QString,QString)") {
42 QDataStream stream(data,IO_ReadOnly); 33 QDataStream stream(data,IO_ReadOnly);
43 QString name, email; 34 QString name, email;
44 stream >> name >> email; 35 stream >> name >> email;
45 // removing the whitespaces at beginning and end is needed! 36 // removing the whitespaces at beginning and end is needed!
46 slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace()); 37 slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace());
47 } else if (msg == "newMail()") { 38 } else if (msg == "newMail()") {
48 slotComposeMail(); 39 slotComposeMail();
49 } 40 }
50} 41}
51 42
52void OpieMail::slotwriteMail(const QString&name,const QString&email) 43void OpieMail::slotwriteMail(const QString&name,const QString&email)
53{ 44{
54 ComposeMail compose( settings, this, 0 , true ); 45 ComposeMail compose( settings, this, 0 , true );
55 if (!email.isEmpty()) { 46 if (!email.isEmpty()) {
56 if (!name.isEmpty()) { 47 if (!name.isEmpty()) {
57 compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">"); 48 compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">");
58 } else { 49 } else {
59 compose.setTo(email); 50 compose.setTo(email);
60 } 51 }
61 } 52 }
62 compose.showMaximized(); 53 compose.showMaximized();
63 compose.slotAdjustColumns(); 54 compose.slotAdjustColumns();
64 compose.exec(); 55 compose.exec();
65} 56}
66 57
67void OpieMail::slotComposeMail() 58void OpieMail::slotComposeMail()
68{ 59{
69 qDebug( "Compose Mail" ); 60 qDebug( "Compose Mail" );
70 slotwriteMail(0l,0l); 61 slotwriteMail(0l,0l);
71} 62}
72 63
73void OpieMail::slotSendQueued() 64void OpieMail::slotSendQueued()
74{ 65{
75 qDebug( "Send Queued" ); 66 qDebug( "Send Queued" );
76 SMTPaccount *smtp = 0; 67 SMTPaccount *smtp = 0;
77 68
78 QList<Account> list = settings->getAccounts(); 69 QList<Account> list = settings->getAccounts();
79 Account *it; 70 Account *it;
80// if (list.count()==1) { 71// if (list.count()==1) {
81 for ( it = list.first(); it; it = list.next() ) { 72 for ( it = list.first(); it; it = list.next() ) {
82 if ( it->getType().compare( "SMTP" ) == 0 ) { 73 if ( it->getType().compare( "SMTP" ) == 0 ) {
83 smtp = static_cast<SMTPaccount *>(it); 74 smtp = static_cast<SMTPaccount *>(it);
84 break; 75 break;
85 } 76 }
86 } 77 }
87// } 78// }
88 if (smtp) { 79 if (smtp) {
89 SMTPwrapper * wrap = new SMTPwrapper(settings); 80 SMTPwrapper * wrap = new SMTPwrapper(settings);
90 if ( wrap->flushOutbox(smtp) ) { 81 if ( wrap->flushOutbox(smtp) ) {
91 QMessageBox::information(0,tr("Info"),tr("Mail queue flushed")); 82 QMessageBox::information(0,tr("Info"),tr("Mail queue flushed"));
92 } 83 }
93 } 84 }
94} 85}
95 86
96void OpieMail::slotSearchMails() 87void OpieMail::slotSearchMails()
97{ 88{
98 qDebug( "Search Mails" ); 89 qDebug( "Search Mails" );
99} 90}
100 91
101void OpieMail::slotEditSettings() 92void OpieMail::slotEditSettings()
102{ 93{
103 SettingsDialog settingsDialog( this, 0, true ); 94 SettingsDialog settingsDialog( this, 0, true );
104 settingsDialog.showMaximized(); 95 settingsDialog.showMaximized();
105 settingsDialog.exec(); 96 settingsDialog.exec();
106} 97}
107 98
108void OpieMail::slotEditAccounts() 99void OpieMail::slotEditAccounts()
109{ 100{
110 qDebug( "Edit Accounts" ); 101 qDebug( "Edit Accounts" );
111 EditAccounts eaDialog( settings, this, 0, true ); 102 EditAccounts eaDialog( settings, this, 0, true );
112 eaDialog.showMaximized(); 103 eaDialog.showMaximized();
113 eaDialog.slotAdjustColumns(); 104 eaDialog.slotAdjustColumns();
114 eaDialog.exec(); 105 eaDialog.exec();
115 if ( settings ) delete settings; 106 if ( settings ) delete settings;
116 settings = new Settings(); 107 settings = new Settings();
117 108
118 folderView->populate( settings->getAccounts() ); 109 folderView->populate( settings->getAccounts() );
119} 110}
120 111
112void OpieMail::displayMail()
113{
114 QListViewItem*item = mailView->currentItem();
115 if (!item) return;
116 RecMail mail = ((MailListViewItem*)item)->data();
117 RecBody body = folderView->fetchBody(mail);
118 ViewMail readMail( this );
119 readMail.setBody( body );
120 readMail.setMail( mail );
121 readMail.showMaximized();
122 readMail.exec();
123
124 if ( readMail.deleted ) {
125 folderView->refreshCurrent();
126 } else {
127 ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "") );
128 }
129}
130
131void OpieMail::slotDeleteMail()
132{
133 if (!mailView->currentItem()) return;
134 RecMail mail = ((MailListViewItem*)mailView->currentItem() )->data();
135 if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail.getFrom() + " - " + mail.getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) {
136 mail.Wrapper()->deleteMail( mail );
137 folderView->refreshCurrent();
138 }
139}
140
141void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int )
142{
143 /* just the RIGHT button - or hold on pda */
144 if (button!=2) {return;}
145 qDebug("Event right/hold");
146 if (!item) return;
147 QPopupMenu *m = new QPopupMenu(0);
148 if (m) {
149 m->insertItem(tr("Read this mail"),this,SLOT(displayMail()));
150 m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail()));
151 m->insertItem(tr("Copy/Move this mail"),this,SLOT(slotMoveCopyMail()));
152 m->setFocus();
153 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
154 delete m;
155 }
156}
157
158void OpieMail::slotShowFolders( bool show )
159{
160 qDebug( "Show Folders" );
161 if ( show && folderView->isHidden() ) {
162 qDebug( "-> showing" );
163 folderView->show();
164 } else if ( !show && !folderView->isHidden() ) {
165 qDebug( "-> hiding" );
166 folderView->hide();
167 }
168}
169
170void OpieMail::refreshMailView(QList<RecMail>*list)
171{
172 MailListViewItem*item = 0;
173 mailView->clear();
174 for (unsigned int i = 0; i < list->count();++i) {
175 item = new MailListViewItem(mailView,item);
176 item->storeData(*(list->at(i)));
177 item->showEntry();
178 }
179}
180
181void OpieMail::mailLeftClicked(int button, QListViewItem *item,const QPoint&,int )
182{
183 /* just LEFT button - or tap with stylus on pda */
184 if (button!=1) return;
185 if (!item) return;
186 displayMail();
187}
188
189void OpieMail::slotMoveCopyMail()
190{
191 if (!mailView->currentItem()) return;
192 RecMail mail = ((MailListViewItem*)mailView->currentItem() )->data();
193 AbstractMail*targetMail = 0;
194 QString targetFolder = "";
195 Selectstore sels;
196 folderView->setupFolderselect(&sels);
197 if (!sels.exec()) return;
198 targetMail = sels.currentMail();
199 targetFolder = sels.currentFolder();
200 if ( (mail.Wrapper()==targetMail && mail.getMbox()==targetFolder) ||
201 targetFolder.isEmpty()) {
202 return;
203 }
204 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) {
205 QMessageBox::critical(0,tr("Error creating new Folder"),
206 tr("<center>Error while creating<br>new folder - breaking.</center>"));
207 return;
208 }
209 mail.Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails());
210 folderView->refreshCurrent();
211}
diff --git a/noncore/net/mail/opiemail.h b/noncore/net/mail/opiemail.h
index 69b8d43..5821856 100644
--- a/noncore/net/mail/opiemail.h
+++ b/noncore/net/mail/opiemail.h
@@ -1,31 +1,39 @@
1#ifndef OPIEMAIL_H 1#ifndef OPIEMAIL_H
2#define OPIEMAIL_H 2#define OPIEMAIL_H
3 3
4#include "mainwindow.h" 4#include "mainwindow.h"
5#include <libmailwrapper/settings.h> 5#include <libmailwrapper/settings.h>
6 6
7 7
8class OpieMail : public MainWindow 8class OpieMail : public MainWindow
9{ 9{
10 Q_OBJECT 10 Q_OBJECT
11 11
12public: 12public:
13 OpieMail( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 13 OpieMail( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
14 virtual ~OpieMail(); 14 virtual ~OpieMail();
15 static QString appName() { return QString::fromLatin1("opiemail"); } 15 static QString appName() { return QString::fromLatin1("opiemail"); }
16 16
17public slots: 17public slots:
18 virtual void slotwriteMail(const QString&name,const QString&email); 18 virtual void slotwriteMail(const QString&name,const QString&email);
19 virtual void slotComposeMail(); 19 virtual void slotComposeMail();
20 virtual void appMessage(const QCString &msg, const QByteArray &data); 20 virtual void appMessage(const QCString &msg, const QByteArray &data);
21protected slots: 21protected slots:
22 virtual void slotSendQueued(); 22 virtual void slotSendQueued();
23 virtual void slotSearchMails(); 23 virtual void slotSearchMails();
24 virtual void slotEditSettings(); 24 virtual void slotEditSettings();
25 virtual void slotEditAccounts(); 25 virtual void slotEditAccounts();
26 virtual void displayMail();
27 virtual void slotDeleteMail();
28 virtual void mailHold(int, QListViewItem *,const QPoint&,int);
29 virtual void slotShowFolders( bool show );
30 virtual void refreshMailView(QList<RecMail>*);
31 virtual void mailLeftClicked( int, QListViewItem *,const QPoint&,int );
32 virtual void slotMoveCopyMail();
33
26private: 34private:
27 Settings *settings; 35 Settings *settings;
28 36
29}; 37};
30 38
31#endif 39#endif