summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/abstractmail.h9
-rw-r--r--noncore/net/mail/accountview.cpp179
-rw-r--r--noncore/net/mail/accountview.h27
-rw-r--r--noncore/net/mail/imapwrapper.cpp124
-rw-r--r--noncore/net/mail/imapwrapper.h4
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.h9
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp124
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h4
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.cpp4
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.h11
-rw-r--r--noncore/net/mail/mail.pro37
-rw-r--r--noncore/net/mail/mailwrapper.cpp4
-rw-r--r--noncore/net/mail/mailwrapper.h11
-rw-r--r--noncore/net/mail/mainwindow.cpp12
-rw-r--r--noncore/net/mail/newmaildir.cpp34
-rw-r--r--noncore/net/mail/newmaildir.h20
-rw-r--r--noncore/net/mail/newmaildirui.ui100
17 files changed, 639 insertions, 74 deletions
diff --git a/noncore/net/mail/abstractmail.h b/noncore/net/mail/abstractmail.h
index 509b68e..b609aa7 100644
--- a/noncore/net/mail/abstractmail.h
+++ b/noncore/net/mail/abstractmail.h
@@ -1,42 +1,51 @@
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;
14 14
15class AbstractMail:public QObject 15class AbstractMail:public QObject
16{ 16{
17 Q_OBJECT 17 Q_OBJECT
18public: 18public:
19 AbstractMail(){}; 19 AbstractMail(){};
20 virtual ~AbstractMail(){} 20 virtual ~AbstractMail(){}
21 virtual QList<Folder>* listFolders()=0; 21 virtual QList<Folder>* listFolders()=0;
22 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; 22 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
23 virtual RecBody fetchBody(const RecMail&mail)=0; 23 virtual RecBody fetchBody(const RecMail&mail)=0;
24 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; 24 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
25 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; 25 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
26 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; 26 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
27 27
28 virtual void deleteMail(const RecMail&mail)=0; 28 virtual void deleteMail(const RecMail&mail)=0;
29 virtual void answeredMail(const RecMail&mail)=0; 29 virtual void answeredMail(const RecMail&mail)=0;
30 virtual void cleanMimeCache(){}; 30 virtual void cleanMimeCache(){};
31 virtual int deleteAllMail(const Folder*){return 1;}
32
33 /* mail box methods */
34 /* parameter is the box to create.
35 * if the implementing subclass has prefixes,
36 * them has to be appended automatic.
37 */
38 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false){return 0;}
39 virtual int deleteMbox(const Folder*){return 1;}
31 40
32 static AbstractMail* getWrapper(IMAPaccount *a); 41 static AbstractMail* getWrapper(IMAPaccount *a);
33 static AbstractMail* getWrapper(POP3account *a); 42 static AbstractMail* getWrapper(POP3account *a);
34 /* mbox only! */ 43 /* mbox only! */
35 static AbstractMail* getWrapper(const QString&a); 44 static AbstractMail* getWrapper(const QString&a);
36 45
37protected: 46protected:
38 static encodedString*decode_String(const encodedString*text,const QString&enc); 47 static encodedString*decode_String(const encodedString*text,const QString&enc);
39 static QString convert_String(const char*text); 48 static QString convert_String(const char*text);
40 static QString gen_attachment_id(); 49 static QString gen_attachment_id();
41}; 50};
42#endif 51#endif
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp
index 59e8bc0..8aac14b 100644
--- a/noncore/net/mail/accountview.cpp
+++ b/noncore/net/mail/accountview.cpp
@@ -1,381 +1,546 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include "accountview.h" 2#include "accountview.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include "defines.h" 4#include "defines.h"
5#include "newmaildir.h"
6#include <qmessagebox.h>
7#include <qpopupmenu.h>
5 8
6/** 9/**
7 * POP3 Account stuff 10 * POP3 Account stuff
8 */ 11 */
9
10POP3viewItem::POP3viewItem( POP3account *a, QListView *parent ) 12POP3viewItem::POP3viewItem( POP3account *a, QListView *parent )
11 : AccountViewItem( parent ) 13 : AccountViewItem( parent )
12{ 14{
13 account = a; 15 account = a;
14 wrapper = AbstractMail::getWrapper( account ); 16 wrapper = AbstractMail::getWrapper( account );
15 setPixmap( 0, PIXMAP_POP3FOLDER ); 17 setPixmap( 0, PIXMAP_POP3FOLDER );
16 setText( 0, account->getAccountName() ); 18 setText( 0, account->getAccountName() );
17 setOpen( true ); 19 setOpen( true );
18} 20}
19 21
20POP3viewItem::~POP3viewItem() 22POP3viewItem::~POP3viewItem()
21{ 23{
22 delete wrapper; 24 delete wrapper;
23} 25}
24 26
25AbstractMail *POP3viewItem::getWrapper() 27AbstractMail *POP3viewItem::getWrapper()
26{ 28{
27 return wrapper; 29 return wrapper;
28} 30}
29 31
30void POP3viewItem::refresh( QList<RecMail> & ) 32void POP3viewItem::refresh( QList<RecMail> & )
31{ 33{
32 QList<Folder> *folders = wrapper->listFolders(); 34 QList<Folder> *folders = wrapper->listFolders();
33 QListViewItem *child = firstChild(); 35 QListViewItem *child = firstChild();
34 while ( child ) { 36 while ( child ) {
35 QListViewItem *tmp = child; 37 QListViewItem *tmp = child;
36 child = child->nextSibling(); 38 child = child->nextSibling();
37 delete tmp; 39 delete tmp;
38 } 40 }
39 Folder *it; 41 Folder *it;
40 QListViewItem*item = 0; 42 QListViewItem*item = 0;
41 for ( it = folders->first(); it; it = folders->next() ) { 43 for ( it = folders->first(); it; it = folders->next() ) {
42 item = new POP3folderItem( it, this , item ); 44 item = new POP3folderItem( it, this , item );
43 item->setSelectable(it->may_select()); 45 item->setSelectable(it->may_select());
44 } 46 }
45 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 47 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
46 folders->setAutoDelete(false); 48 folders->setAutoDelete(false);
47 delete folders; 49 delete folders;
48} 50}
49 51
50RecBody POP3viewItem::fetchBody( const RecMail &mail ) 52RecBody POP3viewItem::fetchBody( const RecMail &mail )
51{ 53{
52 qDebug( "POP3 fetchBody" ); 54 qDebug( "POP3 fetchBody" );
53 return wrapper->fetchBody( mail ); 55 return wrapper->fetchBody( mail );
54} 56}
55 57
56POP3folderItem::~POP3folderItem() 58POP3folderItem::~POP3folderItem()
57{ 59{
58 delete folder; 60 delete folder;
59} 61}
60 62
61POP3folderItem::POP3folderItem( Folder *folderInit, POP3viewItem *parent , QListViewItem*after ) 63POP3folderItem::POP3folderItem( Folder *folderInit, POP3viewItem *parent , QListViewItem*after )
62 : AccountViewItem( parent,after ) 64 : AccountViewItem( parent,after )
63{ 65{
64 folder = folderInit; 66 folder = folderInit;
65 pop3 = parent; 67 pop3 = parent;
66 if (folder->getDisplayName().lower()!="inbox") { 68 if (folder->getDisplayName().lower()!="inbox") {
67 setPixmap( 0, PIXMAP_POP3FOLDER ); 69 setPixmap( 0, PIXMAP_POP3FOLDER );
68 } else { 70 } else {
69 setPixmap( 0, PIXMAP_INBOXFOLDER); 71 setPixmap( 0, PIXMAP_INBOXFOLDER);
70 } 72 }
71 setText( 0, folder->getDisplayName() ); 73 setText( 0, folder->getDisplayName() );
72} 74}
73 75
74void POP3folderItem::refresh(QList<RecMail>&target) 76void POP3folderItem::refresh(QList<RecMail>&target)
75{ 77{
76 if (folder->may_select()) 78 if (folder->may_select())
77 pop3->getWrapper()->listMessages( folder->getName(),target ); 79 pop3->getWrapper()->listMessages( folder->getName(),target );
78} 80}
79 81
80RecBody POP3folderItem::fetchBody(const RecMail&aMail) 82RecBody POP3folderItem::fetchBody(const RecMail&aMail)
81{ 83{
82 return pop3->getWrapper()->fetchBody(aMail); 84 return pop3->getWrapper()->fetchBody(aMail);
83} 85}
84 86
85/** 87/**
86 * IMAP Account stuff 88 * IMAP Account stuff
87 */ 89 */
88IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent ) 90IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent )
89 : AccountViewItem( parent ) 91 : AccountViewItem( parent )
90{ 92{
91 account = a; 93 account = a;
92 wrapper = AbstractMail::getWrapper( account ); 94 wrapper = AbstractMail::getWrapper( account );
93 setPixmap( 0, PIXMAP_IMAPFOLDER ); 95 setPixmap( 0, PIXMAP_IMAPFOLDER );
94 setText( 0, account->getAccountName() ); 96 setText( 0, account->getAccountName() );
95 setOpen( true ); 97 setOpen( true );
96} 98}
97 99
98IMAPviewItem::~IMAPviewItem() 100IMAPviewItem::~IMAPviewItem()
99{ 101{
100 delete wrapper; 102 delete wrapper;
101} 103}
102 104
103AbstractMail *IMAPviewItem::getWrapper() 105AbstractMail *IMAPviewItem::getWrapper()
104{ 106{
105 return wrapper; 107 return wrapper;
106} 108}
107 109
108IMAPfolderItem*IMAPviewItem::findSubItem(const QString&path,IMAPfolderItem*start) 110IMAPfolderItem*IMAPviewItem::findSubItem(const QString&path,IMAPfolderItem*start)
109{ 111{
110 IMAPfolderItem*pitem,*sitem; 112 IMAPfolderItem*pitem,*sitem;
111 if (!start) pitem = (IMAPfolderItem*)firstChild(); 113 if (!start) pitem = (IMAPfolderItem*)firstChild();
112 else pitem = (IMAPfolderItem*)start->firstChild(); 114 else pitem = (IMAPfolderItem*)start->firstChild();
113 while (pitem) { 115 while (pitem) {
114 if (pitem->matchName(path)) { 116 if (pitem->matchName(path)) {
115 break; 117 break;
116 } 118 }
117 if (pitem->childCount()>0) { 119 if (pitem->childCount()>0) {
118 sitem = findSubItem(path,pitem); 120 sitem = findSubItem(path,pitem);
119 if (sitem) { 121 if (sitem) {
120 pitem = sitem; 122 pitem = sitem;
121 break; 123 break;
122 } 124 }
123 } 125 }
124 pitem=(IMAPfolderItem*)pitem->nextSibling(); 126 pitem=(IMAPfolderItem*)pitem->nextSibling();
125 } 127 }
126 return pitem; 128 return pitem;
127} 129}
128 130
129void IMAPviewItem::refresh(QList<RecMail>&) 131void IMAPviewItem::refresh(QList<RecMail>&)
130{ 132{
131 if (childCount()>0) return; 133 refreshFolders(false);
134}
135
136void IMAPviewItem::refreshFolders(bool force)
137{
138 if (childCount()>0 && force==false) return;
132 QList<Folder> *folders = wrapper->listFolders(); 139 QList<Folder> *folders = wrapper->listFolders();
133 140
134 QListViewItem *child = firstChild(); 141 QListViewItem *child = firstChild();
135 while ( child ) { 142 while ( child ) {
136 QListViewItem *tmp = child; 143 QListViewItem *tmp = child;
137 child = child->nextSibling(); 144 child = child->nextSibling();
138 delete tmp; 145 delete tmp;
139 } 146 }
140 147
141 Folder *it; 148 Folder *it;
142 QListViewItem*item = 0; 149 QListViewItem*item = 0;
143 QListViewItem*titem = 0; 150 QListViewItem*titem = 0;
144 QString fname,del,search; 151 QString fname,del,search;
145 int pos; 152 int pos;
146 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 153 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
147 folders->setAutoDelete(false); 154 folders->setAutoDelete(false);
148 155
149 for ( it = folders->first(); it; it = folders->next() ) { 156 for ( it = folders->first(); it; it = folders->next() ) {
150 if (it->getDisplayName().lower()=="inbox") { 157 if (it->getDisplayName().lower()=="inbox") {
151 item = new IMAPfolderItem( it, this , item ); 158 item = new IMAPfolderItem( it, this , item );
152 folders->remove(it); 159 folders->remove(it);
153 qDebug("inbox found"); 160 qDebug("inbox found");
154 break; 161 break;
155 } 162 }
156 } 163 }
157 for ( it = folders->first(); it; it = folders->next() ) { 164 for ( it = folders->first(); it; it = folders->next() ) {
158 fname = it->getDisplayName(); 165 fname = it->getDisplayName();
159 pos = fname.findRev(it->Separator()); 166 pos = fname.findRev(it->Separator());
160 if (pos != -1) { 167 if (pos != -1) {
161 fname = fname.left(pos); 168 fname = fname.left(pos);
162 } 169 }
163 IMAPfolderItem*pitem = findSubItem(fname); 170 IMAPfolderItem*pitem = findSubItem(fname);
164 if (pitem) { 171 if (pitem) {
165 titem = item; 172 titem = item;
166 item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this); 173 item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this);
167 item->setSelectable(it->may_select());
168 /* setup the short name */ 174 /* setup the short name */
169 item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1)); 175 item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1));
170 item = titem; 176 item = titem;
171 } else { 177 } else {
172 item = new IMAPfolderItem( it, this , item ); 178 item = new IMAPfolderItem( it, this , item );
173 item->setSelectable(it->may_select());
174 } 179 }
175 } 180 }
176 delete folders; 181 delete folders;
177} 182}
178 183
184QPopupMenu * IMAPviewItem::getContextMenu()
185{
186 QPopupMenu *m = new QPopupMenu(0);
187 if (m) {
188 m->insertItem(QObject::tr("Refresh folder list","IMAPviewItem"),0);
189 m->insertItem(QObject::tr("Create new folder","IMAPviewItem"),1);
190 m->insertSeparator();
191 m->insertItem(QObject::tr("Disconnect","IMAPviewItem"),2);
192 }
193 return m;
194}
195
196void IMAPviewItem::createNewFolder()
197{
198 Newmdirdlg ndirdlg;
199 ndirdlg.showMaximized();
200 if (ndirdlg.exec()) {
201 QString ndir = ndirdlg.Newdir();
202 bool makesubs = ndirdlg.subpossible();
203 QString delemiter = "/";
204 IMAPfolderItem*item = (IMAPfolderItem*)firstChild();
205 if (item) {
206 delemiter = item->Delemiter();
207 }
208 if (wrapper->createMbox(ndir,0,delemiter,makesubs)) {
209 refreshFolders(true);
210 }
211 }
212}
213
214void IMAPviewItem::contextMenuSelected(int id)
215{
216 qDebug("Id selected: %i",id);
217 switch (id) {
218 case 0:
219 refreshFolders(true);
220 break;
221 case 1:
222 createNewFolder();
223 break;
224 default:
225 break;
226 }
227}
228
179RecBody IMAPviewItem::fetchBody(const RecMail&) 229RecBody IMAPviewItem::fetchBody(const RecMail&)
180{ 230{
181 return RecBody(); 231 return RecBody();
182} 232}
183 233
184IMAPfolderItem::~IMAPfolderItem() 234IMAPfolderItem::~IMAPfolderItem()
185{ 235{
186 delete folder; 236 delete folder;
187} 237}
188 238
189IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after ) 239IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after )
190 : AccountViewItem( parent , after ) 240 : AccountViewItem( parent , after )
191{ 241{
192 folder = folderInit; 242 folder = folderInit;
193 imap = parent; 243 imap = parent;
194 if (folder->getDisplayName().lower()!="inbox") { 244 if (folder->getDisplayName().lower()!="inbox") {
195 setPixmap( 0, PIXMAP_IMAPFOLDER ); 245 setPixmap( 0, PIXMAP_IMAPFOLDER );
196 } else { 246 } else {
197 setPixmap( 0, PIXMAP_INBOXFOLDER); 247 setPixmap( 0, PIXMAP_INBOXFOLDER);
198 } 248 }
199 setText( 0, folder->getDisplayName() ); 249 setText( 0, folder->getDisplayName() );
200} 250}
201 251
202IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ) 252IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master )
203 : AccountViewItem( parent,after ) 253 : AccountViewItem( parent,after )
204{ 254{
205 folder = folderInit; 255 folder = folderInit;
206 imap = master; 256 imap = master;
207 if (folder->getDisplayName().lower()!="inbox") { 257 if (folder->getDisplayName().lower()!="inbox") {
208 setPixmap( 0, PIXMAP_IMAPFOLDER ); 258 setPixmap( 0, PIXMAP_IMAPFOLDER );
209 } else { 259 } else {
210 setPixmap( 0, PIXMAP_INBOXFOLDER); 260 setPixmap( 0, PIXMAP_INBOXFOLDER);
211 } 261 }
212 setText( 0, folder->getDisplayName() ); 262 setText( 0, folder->getDisplayName() );
213} 263}
214 264
265const QString& IMAPfolderItem::Delemiter()const
266{
267 return folder->Separator();
268}
269
215bool IMAPfolderItem::matchName(const QString&name)const 270bool IMAPfolderItem::matchName(const QString&name)const
216{ 271{
217 return folder->getDisplayName()==name; 272 return folder->getDisplayName()==name;
218} 273}
219 274
220void IMAPfolderItem::refresh(QList<RecMail>&target) 275void IMAPfolderItem::refresh(QList<RecMail>&target)
221{ 276{
222 if (folder->may_select()) 277 if (folder->may_select()) {
223 imap->getWrapper()->listMessages( folder->getName(),target ); 278 imap->getWrapper()->listMessages( folder->getName(),target );
279 } else {
280 target.clear();
281 }
224} 282}
225 283
226RecBody IMAPfolderItem::fetchBody(const RecMail&aMail) 284RecBody IMAPfolderItem::fetchBody(const RecMail&aMail)
227{ 285{
228 return imap->getWrapper()->fetchBody(aMail); 286 return imap->getWrapper()->fetchBody(aMail);
229} 287}
230 288
289QPopupMenu * IMAPfolderItem::getContextMenu()
290{
291 QPopupMenu *m = new QPopupMenu(0);
292 if (m) {
293 if (folder->may_select()) {
294 m->insertItem(QObject::tr("Refresh header list","IMAPfolderItem"),0);
295 m->insertItem(QObject::tr("Delete all mails","IMAPfolderItem"),1);
296 }
297 if (folder->no_inferior()==false) {
298 m->insertItem(QObject::tr("Create new subfolder","IMAPfolderItem"),2);
299 }
300 if (folder->getDisplayName().lower()!="inbox") {
301 m->insertItem(QObject::tr("Delete folder","IMAPfolderItem"),3);
302 }
303 }
304 return m;
305}
306
307void IMAPfolderItem::deleteAllMails()
308{
309 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails","IMAPfolderItem"),
310 QObject::tr("<center>Realy delete all mails in box <br>%1</center>","IMAPfolderItem").arg(folder->getDisplayName()),
311 QObject::tr("Yes","IMAPfolderItem"),
312 QObject::tr("No","IMAPfolderItem"),QString::null,1,1);
313 qDebug("Auswahl: %i",yesno);
314 if (yesno == 0) {
315 if (imap->getWrapper()->deleteAllMail(folder)) {
316 AccountView * view = (AccountView*)listView();
317 if (view) view->refreshCurrent();
318 }
319 }
320}
321
322void IMAPfolderItem::createNewFolder()
323{
324 Newmdirdlg ndirdlg;
325 ndirdlg.showMaximized();
326 if (ndirdlg.exec()) {
327 QString ndir = ndirdlg.Newdir();
328 bool makesubs = ndirdlg.subpossible();
329 QString delemiter = Delemiter();
330 if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) {
331 imap->refreshFolders(true);
332 }
333 }
334}
335
336void IMAPfolderItem::deleteFolder()
337{
338 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder","IMAPfolderItem"),
339 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>","IMAPfolderItem").arg(folder->getDisplayName()),
340 QObject::tr("Yes","IMAPfolderItem"),
341 QObject::tr("No","IMAPfolderItem"),QString::null,1,1);
342 qDebug("Auswahl: %i",yesno);
343 if (yesno == 0) {
344 if (imap->getWrapper()->deleteMbox(folder)) {
345 /* be carefull - after that this object is destroyd so don't call
346 * any member of it after that call!!*/
347 imap->refreshFolders(true);
348 }
349 }
350}
351
352void IMAPfolderItem::contextMenuSelected(int id)
353{
354 qDebug("Selected id: %i",id);
355 AccountView * view = (AccountView*)listView();
356 switch(id) {
357 case 0:
358 view->refreshCurrent();
359 break;
360 case 1:
361 deleteAllMails();
362 break;
363 case 2:
364 createNewFolder();
365 break;
366 case 3:
367 deleteFolder();
368 break;
369 default:
370 break;
371 }
372}
231 373
232/** 374/**
233 * Generic stuff 375 * Generic stuff
234 */ 376 */
235 377
236AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) 378AccountView::AccountView( QWidget *parent, const char *name, WFlags flags )
237 : QListView( parent, name, flags ) 379 : QListView( parent, name, flags )
238{ 380{
239 connect( this, SIGNAL( selectionChanged( QListViewItem * ) ), 381 connect( this, SIGNAL( selectionChanged( QListViewItem * ) ),
240 SLOT( refresh( QListViewItem * ) ) ); 382 SLOT( refresh( QListViewItem * ) ) );
383 connect( this, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this,
384 SLOT( slotHold( int, QListViewItem *,const QPoint&,int ) ) );
385
241 setSorting(0); 386 setSorting(0);
242} 387}
243 388
389void AccountView::slotContextMenu(int id)
390{
391 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem());
392 if (!view) return;
393 view->contextMenuSelected(id);
394}
395
396void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int)
397{
398 if (button==1) {return;}
399 if (!item) return;
400 AccountViewItem *view = static_cast<AccountViewItem *>(item);
401 QPopupMenu*m = view->getContextMenu();
402 if (!m) return;
403 connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int)));
404 m->setFocus();
405 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
406 delete m;
407}
408
244void AccountView::populate( QList<Account> list ) 409void AccountView::populate( QList<Account> list )
245{ 410{
246 clear(); 411 clear();
247 412
248 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); 413 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
249 (void) new MBOXviewItem(localfolders,this); 414 (void) new MBOXviewItem(localfolders,this);
250 415
251 Account *it; 416 Account *it;
252 for ( it = list.first(); it; it = list.next() ) { 417 for ( it = list.first(); it; it = list.next() ) {
253 if ( it->getType().compare( "IMAP" ) == 0 ) { 418 if ( it->getType().compare( "IMAP" ) == 0 ) {
254 IMAPaccount *imap = static_cast<IMAPaccount *>(it); 419 IMAPaccount *imap = static_cast<IMAPaccount *>(it);
255 qDebug( "added IMAP " + imap->getAccountName() ); 420 qDebug( "added IMAP " + imap->getAccountName() );
256 (void) new IMAPviewItem( imap, this ); 421 (void) new IMAPviewItem( imap, this );
257 } else if ( it->getType().compare( "POP3" ) == 0 ) { 422 } else if ( it->getType().compare( "POP3" ) == 0 ) {
258 POP3account *pop3 = static_cast<POP3account *>(it); 423 POP3account *pop3 = static_cast<POP3account *>(it);
259 qDebug( "added POP3 " + pop3->getAccountName() ); 424 qDebug( "added POP3 " + pop3->getAccountName() );
260 (void) new POP3viewItem( pop3, this ); 425 (void) new POP3viewItem( pop3, this );
261 } 426 }
262 } 427 }
263} 428}
264 429
265void AccountView::refresh(QListViewItem *item) { 430void AccountView::refresh(QListViewItem *item) {
266 431
267 qDebug("AccountView refresh..."); 432 qDebug("AccountView refresh...");
268 if ( item ) { 433 if ( item ) {
269 m_currentItem = item; 434 m_currentItem = item;
270 QList<RecMail> headerlist; 435 QList<RecMail> headerlist;
271 headerlist.setAutoDelete(true); 436 headerlist.setAutoDelete(true);
272 AccountViewItem *view = static_cast<AccountViewItem *>(item); 437 AccountViewItem *view = static_cast<AccountViewItem *>(item);
273 view->refresh(headerlist); 438 view->refresh(headerlist);
274 emit refreshMailview(&headerlist); 439 emit refreshMailview(&headerlist);
275 } 440 }
276} 441}
277 442
278void AccountView::refreshCurrent() 443void AccountView::refreshCurrent()
279{ 444{
445 m_currentItem = currentItem();
280 if ( !m_currentItem ) return; 446 if ( !m_currentItem ) return;
281 QList<RecMail> headerlist; 447 QList<RecMail> headerlist;
282 headerlist.setAutoDelete(true); 448 headerlist.setAutoDelete(true);
283 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); 449 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem);
284 view->refresh(headerlist); 450 view->refresh(headerlist);
285 emit refreshMailview(&headerlist); 451 emit refreshMailview(&headerlist);
286} 452}
287 453
288void AccountView::refreshAll() 454void AccountView::refreshAll()
289{ 455{
290 456
291} 457}
292 458
293RecBody AccountView::fetchBody(const RecMail&aMail) 459RecBody AccountView::fetchBody(const RecMail&aMail)
294{ 460{
295 QListViewItem*item = selectedItem (); 461 QListViewItem*item = selectedItem ();
296 if (!item) return RecBody(); 462 if (!item) return RecBody();
297 AccountViewItem *view = static_cast<AccountViewItem *>(item); 463 AccountViewItem *view = static_cast<AccountViewItem *>(item);
298 return view->fetchBody(aMail); 464 return view->fetchBody(aMail);
299} 465}
300 466
301/** 467/**
302 * MBOX Account stuff 468 * MBOX Account stuff
303 */ 469 */
304 470
305MBOXviewItem::MBOXviewItem( const QString&aPath, QListView *parent ) 471MBOXviewItem::MBOXviewItem( const QString&aPath, QListView *parent )
306 : AccountViewItem( parent ) 472 : AccountViewItem( parent )
307{ 473{
308 m_Path = aPath; 474 m_Path = aPath;
309 wrapper = AbstractMail::getWrapper( m_Path ); 475 wrapper = AbstractMail::getWrapper( m_Path );
310 setPixmap( 0, PIXMAP_LOCALFOLDER ); 476 setPixmap( 0, PIXMAP_LOCALFOLDER );
311 setText( 0, " Local Folders" ); 477 setText( 0, " Local Folders" );
312 setOpen( true ); 478 setOpen( true );
313} 479}
314 480
315MBOXviewItem::~MBOXviewItem() 481MBOXviewItem::~MBOXviewItem()
316{ 482{
317 delete wrapper; 483 delete wrapper;
318} 484}
319 485
320AbstractMail *MBOXviewItem::getWrapper() 486AbstractMail *MBOXviewItem::getWrapper()
321{ 487{
322 return wrapper; 488 return wrapper;
323} 489}
324 490
325void MBOXviewItem::refresh( QList<RecMail> & ) 491void MBOXviewItem::refresh( QList<RecMail> & )
326{ 492{
327 QList<Folder> *folders = wrapper->listFolders(); 493 QList<Folder> *folders = wrapper->listFolders();
328 QListViewItem *child = firstChild(); 494 QListViewItem *child = firstChild();
329 while ( child ) { 495 while ( child ) {
330 QListViewItem *tmp = child; 496 QListViewItem *tmp = child;
331 child = child->nextSibling(); 497 child = child->nextSibling();
332 delete tmp; 498 delete tmp;
333 } 499 }
334 Folder *it; 500 Folder *it;
335 QListViewItem*item = 0; 501 QListViewItem*item = 0;
336 for ( it = folders->first(); it; it = folders->next() ) { 502 for ( it = folders->first(); it; it = folders->next() ) {
337 item = new MBOXfolderItem( it, this , item ); 503 item = new MBOXfolderItem( it, this , item );
338 item->setSelectable(it->may_select()); 504 item->setSelectable(it->may_select());
339 } 505 }
340 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 506 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
341 folders->setAutoDelete(false); 507 folders->setAutoDelete(false);
342 delete folders; 508 delete folders;
343} 509}
344 510
345RecBody MBOXviewItem::fetchBody( const RecMail &mail ) 511RecBody MBOXviewItem::fetchBody( const RecMail &mail )
346{ 512{
347 qDebug( "POP3 fetchBody" ); 513 qDebug( "POP3 fetchBody" );
348 return wrapper->fetchBody( mail ); 514 return wrapper->fetchBody( mail );
349} 515}
350 516
351MBOXfolderItem::~MBOXfolderItem() 517MBOXfolderItem::~MBOXfolderItem()
352{ 518{
353 delete folder; 519 delete folder;
354} 520}
355 521
356MBOXfolderItem::MBOXfolderItem( Folder *folderInit, MBOXviewItem *parent , QListViewItem*after ) 522MBOXfolderItem::MBOXfolderItem( Folder *folderInit, MBOXviewItem *parent , QListViewItem*after )
357 : AccountViewItem( parent,after ) 523 : AccountViewItem( parent,after )
358{ 524{
359 folder = folderInit; 525 folder = folderInit;
360 mbox = parent; 526 mbox = parent;
361 if (folder->getDisplayName().lower() == "outgoing") { 527 if (folder->getDisplayName().lower() == "outgoing") {
362 setPixmap( 0, PIXMAP_OUTBOXFOLDER ); 528 setPixmap( 0, PIXMAP_OUTBOXFOLDER );
363 } else if (folder->getDisplayName().lower() == "inbox") { 529 } else if (folder->getDisplayName().lower() == "inbox") {
364 setPixmap( 0, PIXMAP_INBOXFOLDER); 530 setPixmap( 0, PIXMAP_INBOXFOLDER);
365 } else { 531 } else {
366 setPixmap( 0, PIXMAP_MBOXFOLDER ); 532 setPixmap( 0, PIXMAP_MBOXFOLDER );
367 } 533 }
368 setText( 0, folder->getDisplayName() ); 534 setText( 0, folder->getDisplayName() );
369} 535}
370 536
371void MBOXfolderItem::refresh(QList<RecMail>&target) 537void MBOXfolderItem::refresh(QList<RecMail>&target)
372{ 538{
373 if (folder->may_select()) 539 if (folder->may_select())
374 mbox->getWrapper()->listMessages( folder->getName(),target ); 540 mbox->getWrapper()->listMessages( folder->getName(),target );
375} 541}
376 542
377RecBody MBOXfolderItem::fetchBody(const RecMail&aMail) 543RecBody MBOXfolderItem::fetchBody(const RecMail&aMail)
378{ 544{
379 return mbox->getWrapper()->fetchBody(aMail); 545 return mbox->getWrapper()->fetchBody(aMail);
380} 546}
381
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h
index 35499ac..e7fe038 100644
--- a/noncore/net/mail/accountview.h
+++ b/noncore/net/mail/accountview.h
@@ -1,140 +1,157 @@
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 "settings.h" 7#include "settings.h"
8#include "mailwrapper.h" 8#include "mailwrapper.h"
9#include "abstractmail.h" 9#include "abstractmail.h"
10 10
11class POP3wrapper; 11class POP3wrapper;
12class RecMail; 12class RecMail;
13class RecBody; 13class RecBody;
14class QPopupMenu;
14 15
15class AccountViewItem : public QListViewItem 16class AccountViewItem : public QListViewItem
16{ 17{
17 18
18public: 19public:
19 AccountViewItem( QListView *parent ) : QListViewItem( parent ) {} 20 AccountViewItem( QListView *parent ) : QListViewItem( parent ) {}
20 AccountViewItem( QListViewItem *parent) : QListViewItem( parent) {} 21 AccountViewItem( QListViewItem *parent) : QListViewItem( parent) {}
21 AccountViewItem( QListViewItem *parent , QListViewItem*after ) : QListViewItem( parent,after ) {} 22 AccountViewItem( QListViewItem *parent , QListViewItem*after ) : QListViewItem( parent,after ) {}
22 virtual void refresh(QList<RecMail>&)=0; 23 virtual void refresh(QList<RecMail>&)=0;
23 virtual RecBody fetchBody(const RecMail&)=0; 24 virtual RecBody fetchBody(const RecMail&)=0;
25 virtual QPopupMenu * getContextMenu(){return 0;};
26 virtual void contextMenuSelected(int){}
24}; 27};
25 28
26class POP3viewItem : public AccountViewItem 29class POP3viewItem : public AccountViewItem
27{ 30{
28 31
29public: 32public:
30 POP3viewItem( POP3account *a, QListView *parent ); 33 POP3viewItem( POP3account *a, QListView *parent );
31 ~POP3viewItem(); 34 ~POP3viewItem();
32 virtual void refresh( QList<RecMail> &target ); 35 virtual void refresh( QList<RecMail> &target );
33 virtual RecBody fetchBody( const RecMail &mail ); 36 virtual RecBody fetchBody( const RecMail &mail );
34 AbstractMail *getWrapper(); 37 AbstractMail *getWrapper();
35private: 38private:
36 POP3account *account; 39 POP3account *account;
37 AbstractMail *wrapper; 40 AbstractMail *wrapper;
38 41
39}; 42};
40 43
41class POP3folderItem : public AccountViewItem 44class POP3folderItem : public AccountViewItem
42{ 45{
43 46
44public: 47public:
45 POP3folderItem( Folder *folder, POP3viewItem *parent , QListViewItem*after ); 48 POP3folderItem( Folder *folder, POP3viewItem *parent , QListViewItem*after );
46 ~POP3folderItem(); 49 ~POP3folderItem();
47 virtual void refresh(QList<RecMail>&); 50 virtual void refresh(QList<RecMail>&);
48 virtual RecBody fetchBody(const RecMail&); 51 virtual RecBody fetchBody(const RecMail&);
49private: 52private:
50 Folder *folder; 53 Folder *folder;
51 POP3viewItem *pop3; 54 POP3viewItem *pop3;
52}; 55};
53 56
54class IMAPfolderItem; 57class IMAPfolderItem;
55 58
56class IMAPviewItem : public AccountViewItem 59class IMAPviewItem : public AccountViewItem
57{ 60{
58 61 friend class IMAPfolderItem;
59public: 62public:
60 IMAPviewItem( IMAPaccount *a, QListView *parent ); 63 IMAPviewItem( IMAPaccount *a, QListView *parent );
61 ~IMAPviewItem(); 64 ~IMAPviewItem();
62 virtual void refresh(QList<RecMail>&); 65 virtual void refresh(QList<RecMail>&);
63 virtual RecBody fetchBody(const RecMail&); 66 virtual RecBody fetchBody(const RecMail&);
64 AbstractMail *getWrapper(); 67 AbstractMail *getWrapper();
68 virtual QPopupMenu * getContextMenu();
69 virtual void contextMenuSelected(int);
65 70
66protected: 71protected:
67 IMAPfolderItem*findSubItem(const QString&path,IMAPfolderItem*start=0); 72 IMAPfolderItem*findSubItem(const QString&path,IMAPfolderItem*start=0);
73 virtual void refreshFolders(bool force=false);
74 virtual void createNewFolder();
68 75
69private: 76private:
70 IMAPaccount *account; 77 IMAPaccount *account;
71 AbstractMail *wrapper; 78 AbstractMail *wrapper;
72}; 79};
73 80
74class IMAPfolderItem : public AccountViewItem 81class IMAPfolderItem : public AccountViewItem
75{ 82{
76 83
77public: 84public:
78 IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after ); 85 IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after );
79 IMAPfolderItem( Folder *folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ); 86 IMAPfolderItem( Folder *folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master );
80 ~IMAPfolderItem(); 87 ~IMAPfolderItem();
81 virtual void refresh(QList<RecMail>&); 88 virtual void refresh(QList<RecMail>&);
82 virtual RecBody fetchBody(const RecMail&); 89 virtual RecBody fetchBody(const RecMail&);
83 bool matchName(const QString&name)const; 90 bool matchName(const QString&name)const;
91 virtual void deleteAllMails();
92 virtual QPopupMenu * getContextMenu();
93 virtual void contextMenuSelected(int);
94 virtual const QString& Delemiter()const;
95protected:
96 virtual void createNewFolder();
97 virtual void deleteFolder();
98
84private: 99private:
85 Folder *folder; 100 Folder *folder;
86 IMAPviewItem *imap; 101 IMAPviewItem *imap;
87}; 102};
88 103
89class MBOXviewItem : public AccountViewItem 104class MBOXviewItem : public AccountViewItem
90{ 105{
91 106
92public: 107public:
93// MBOXviewItem( MBOXaccount *a, QListView *parent ); 108// MBOXviewItem( MBOXaccount *a, QListView *parent );
94 MBOXviewItem( const QString&aMboxPath, QListView *parent ); 109 MBOXviewItem( const QString&aMboxPath, QListView *parent );
95 ~MBOXviewItem(); 110 ~MBOXviewItem();
96 virtual void refresh( QList<RecMail> &target ); 111 virtual void refresh( QList<RecMail> &target );
97 virtual RecBody fetchBody( const RecMail &mail ); 112 virtual RecBody fetchBody( const RecMail &mail );
98 AbstractMail *getWrapper(); 113 AbstractMail *getWrapper();
99private: 114private:
100// MBOXaccount *account; 115// MBOXaccount *account;
101 QString m_Path; 116 QString m_Path;
102 AbstractMail *wrapper; 117 AbstractMail *wrapper;
103 118
104}; 119};
105 120
106class MBOXfolderItem : public AccountViewItem 121class MBOXfolderItem : public AccountViewItem
107{ 122{
108 123
109public: 124public:
110 MBOXfolderItem( Folder *folder, MBOXviewItem *parent , QListViewItem*after ); 125 MBOXfolderItem( Folder *folder, MBOXviewItem *parent , QListViewItem*after );
111 ~MBOXfolderItem(); 126 ~MBOXfolderItem();
112 virtual void refresh(QList<RecMail>&); 127 virtual void refresh(QList<RecMail>&);
113 virtual RecBody fetchBody(const RecMail&); 128 virtual RecBody fetchBody(const RecMail&);
114private: 129private:
115 Folder *folder; 130 Folder *folder;
116 MBOXviewItem *mbox; 131 MBOXviewItem *mbox;
117}; 132};
118 133
119class AccountView : public QListView 134class AccountView : public QListView
120{ 135{
121 Q_OBJECT 136 Q_OBJECT
122 137
123public: 138public:
124 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 139 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
125 void populate( QList<Account> list ); 140 void populate( QList<Account> list );
126 RecBody fetchBody(const RecMail&aMail); 141 RecBody fetchBody(const RecMail&aMail);
127 142
128public slots: 143public slots:
129 void refreshAll(); 144 virtual void refreshAll();
130 void refresh(QListViewItem *item); 145 virtual void refresh(QListViewItem *item);
131 void refreshCurrent(); 146 virtual void refreshCurrent();
132 147 virtual void slotHold(int, QListViewItem *,const QPoint&,int);
148 virtual void slotContextMenu(int id);
149
133signals: 150signals:
134 void refreshMailview(QList<RecMail>*); 151 void refreshMailview(QList<RecMail>*);
135 152
136private: 153private:
137 QListViewItem* m_currentItem; 154 QListViewItem* m_currentItem;
138}; 155};
139 156
140#endif 157#endif
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index ab20249..406c57c 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -1,485 +1,503 @@
1
2#include <stdlib.h> 1#include <stdlib.h>
3
4#include <libetpan/libetpan.h> 2#include <libetpan/libetpan.h>
3#include <qpe/global.h>
5 4
6#include "imapwrapper.h" 5#include "imapwrapper.h"
7#include "mailtypes.h" 6#include "mailtypes.h"
8#include "logindialog.h" 7#include "logindialog.h"
9 8
10IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 9IMAPwrapper::IMAPwrapper( IMAPaccount *a )
11 : AbstractMail() 10 : AbstractMail()
12{ 11{
13 account = a; 12 account = a;
14 m_imap = 0; 13 m_imap = 0;
15} 14}
16 15
17IMAPwrapper::~IMAPwrapper() 16IMAPwrapper::~IMAPwrapper()
18{ 17{
19 logout(); 18 logout();
20} 19}
21 20
22void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 21void IMAPwrapper::imap_progress( size_t current, size_t maximum )
23{ 22{
24 qDebug( "IMAP: %i of %i", current, maximum ); 23 qDebug( "IMAP: %i of %i", current, maximum );
25} 24}
26 25
27void IMAPwrapper::login() 26void IMAPwrapper::login()
28{ 27{
29 const char *server, *user, *pass; 28 const char *server, *user, *pass;
30 uint16_t port; 29 uint16_t port;
31 int err = MAILIMAP_NO_ERROR; 30 int err = MAILIMAP_NO_ERROR;
32 31
33 /* we are connected this moment */ 32 /* we are connected this moment */
34 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 33 /* TODO: setup a timer holding the line or if connection closed - delete the value */
35 if (m_imap) { 34 if (m_imap) {
36 err = mailimap_noop(m_imap); 35 err = mailimap_noop(m_imap);
37 if (err!=MAILIMAP_NO_ERROR) { 36 if (err!=MAILIMAP_NO_ERROR) {
38 logout(); 37 logout();
39 } else { 38 } else {
40 mailstream_flush(m_imap->imap_stream); 39 mailstream_flush(m_imap->imap_stream);
41 return; 40 return;
42 } 41 }
43 } 42 }
44 server = account->getServer().latin1(); 43 server = account->getServer().latin1();
45 port = account->getPort().toUInt(); 44 port = account->getPort().toUInt();
46 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 45 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
47 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 46 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
48 login.show(); 47 login.show();
49 if ( QDialog::Accepted == login.exec() ) { 48 if ( QDialog::Accepted == login.exec() ) {
50 // ok 49 // ok
51 user = strdup( login.getUser().latin1() ); 50 user = strdup( login.getUser().latin1() );
52 pass = strdup( login.getPassword().latin1() ); 51 pass = strdup( login.getPassword().latin1() );
53 } else { 52 } else {
54 // cancel 53 // cancel
55 qDebug( "IMAP: Login canceled" ); 54 qDebug( "IMAP: Login canceled" );
56 return; 55 return;
57 } 56 }
58 } else { 57 } else {
59 user = account->getUser().latin1(); 58 user = account->getUser().latin1();
60 pass = account->getPassword().latin1(); 59 pass = account->getPassword().latin1();
61 } 60 }
62 61
63 m_imap = mailimap_new( 20, &imap_progress ); 62 m_imap = mailimap_new( 20, &imap_progress );
64 /* connect */ 63 /* connect */
65 if (account->getSSL()) { 64 if (account->getSSL()) {
66 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 65 err = mailimap_ssl_connect( m_imap, (char*)server, port );
67 } else { 66 } else {
68 err = mailimap_socket_connect( m_imap, (char*)server, port ); 67 err = mailimap_socket_connect( m_imap, (char*)server, port );
69 } 68 }
70 69
71 if ( err != MAILIMAP_NO_ERROR && 70 if ( err != MAILIMAP_NO_ERROR &&
72 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 71 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
73 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 72 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
74 qDebug("error connecting server: %s",m_imap->imap_response); 73 Global::statusMessage(tr("error connecting imap server: %1").arg(m_imap->imap_response));
75 mailimap_free( m_imap ); 74 mailimap_free( m_imap );
76 m_imap = 0; 75 m_imap = 0;
77 return; 76 return;
78 } 77 }
79 78
80 /* login */ 79 /* login */
81 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 80 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
82 if ( err != MAILIMAP_NO_ERROR ) { 81 if ( err != MAILIMAP_NO_ERROR ) {
83 qDebug("error logging in imap: %s",m_imap->imap_response); 82 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
84 err = mailimap_close( m_imap ); 83 err = mailimap_close( m_imap );
85 mailimap_free( m_imap ); 84 mailimap_free( m_imap );
86 m_imap = 0; 85 m_imap = 0;
87 } 86 }
88} 87}
89 88
90void IMAPwrapper::logout() 89void IMAPwrapper::logout()
91{ 90{
92 int err = MAILIMAP_NO_ERROR; 91 int err = MAILIMAP_NO_ERROR;
93 if (!m_imap) return; 92 if (!m_imap) return;
94 err = mailimap_logout( m_imap ); 93 err = mailimap_logout( m_imap );
95 err = mailimap_close( m_imap ); 94 err = mailimap_close( m_imap );
96 mailimap_free( m_imap ); 95 mailimap_free( m_imap );
97 m_imap = 0; 96 m_imap = 0;
98} 97}
99 98
100void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 99void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
101{ 100{
102 const char *mb = 0; 101 const char *mb = 0;
103 int err = MAILIMAP_NO_ERROR; 102 int err = MAILIMAP_NO_ERROR;
104 clist *result = 0; 103 clist *result = 0;
105 clistcell *current; 104 clistcell *current;
106// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 105// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
107 mailimap_fetch_type *fetchType = 0; 106 mailimap_fetch_type *fetchType = 0;
108 mailimap_set *set = 0; 107 mailimap_set *set = 0;
109 108
110 mb = mailbox.latin1(); 109 mb = mailbox.latin1();
111 login(); 110 login();
112 if (!m_imap) { 111 if (!m_imap) {
113 return; 112 return;
114 } 113 }
115 /* select mailbox READONLY for operations */ 114 /* select mailbox READONLY for operations */
116 err = mailimap_examine( m_imap, (char*)mb); 115 err = mailimap_examine( m_imap, (char*)mb);
117 if ( err != MAILIMAP_NO_ERROR ) { 116 if ( err != MAILIMAP_NO_ERROR ) {
118 qDebug("error selecting mailbox: %s",m_imap->imap_response); 117 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response));
119 return; 118 return;
120 } 119 }
121 120
122 int last = m_imap->imap_selection_info->sel_exists; 121 int last = m_imap->imap_selection_info->sel_exists;
123 122
124 if (last == 0) { 123 if (last == 0) {
125 qDebug("mailbox has no mails"); 124 Global::statusMessage(tr("Mailbox has no mails"));
126 return; 125 return;
126 } else {
127 Global::statusMessage(tr("Mailbox has %1 mails").arg(last));
127 } 128 }
128 129
129 /* the range has to start at 1!!! not with 0!!!! */ 130 /* the range has to start at 1!!! not with 0!!!! */
130 set = mailimap_set_new_interval( 1, last ); 131 set = mailimap_set_new_interval( 1, last );
131 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 132 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
132 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 133 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
133 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 134 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
134 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 135 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
135 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 136 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
136 137
137 err = mailimap_fetch( m_imap, set, fetchType, &result ); 138 err = mailimap_fetch( m_imap, set, fetchType, &result );
138 mailimap_set_free( set ); 139 mailimap_set_free( set );
139 mailimap_fetch_type_free( fetchType ); 140 mailimap_fetch_type_free( fetchType );
140 141
141 QString date,subject,from; 142 QString date,subject,from;
142 143
143 if ( err == MAILIMAP_NO_ERROR ) { 144 if ( err == MAILIMAP_NO_ERROR ) {
144 mailimap_msg_att * msg_att; 145 mailimap_msg_att * msg_att;
145 int i = 0; 146 int i = 0;
146 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 147 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
147 ++i; 148 ++i;
148 msg_att = (mailimap_msg_att*)current->data; 149 msg_att = (mailimap_msg_att*)current->data;
149 RecMail*m = parse_list_result(msg_att); 150 RecMail*m = parse_list_result(msg_att);
150 if (m) { 151 if (m) {
151 m->setNumber(i); 152 m->setNumber(i);
152 m->setMbox(mailbox); 153 m->setMbox(mailbox);
153 m->setWrapper(this); 154 m->setWrapper(this);
154 target.append(m); 155 target.append(m);
155 } 156 }
156 } 157 }
157 } else { 158 } else {
158 qDebug("Error fetching headers: %s",m_imap->imap_response); 159 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
159 } 160 }
160 if (result) mailimap_fetch_list_free(result); 161 if (result) mailimap_fetch_list_free(result);
161} 162}
162 163
163QList<Folder>* IMAPwrapper::listFolders() 164QList<Folder>* IMAPwrapper::listFolders()
164{ 165{
165 const char *path, *mask; 166 const char *path, *mask;
166 int err = MAILIMAP_NO_ERROR; 167 int err = MAILIMAP_NO_ERROR;
167 clist *result = 0; 168 clist *result = 0;
168 clistcell *current = 0; 169 clistcell *current = 0;
170 clistcell*cur_flag = 0;
171 mailimap_mbx_list_flags*bflags = 0;
169 172
170 QList<Folder> * folders = new QList<Folder>(); 173 QList<Folder> * folders = new QList<Folder>();
171 folders->setAutoDelete( false ); 174 folders->setAutoDelete( false );
172 login(); 175 login();
173 if (!m_imap) { 176 if (!m_imap) {
174 return folders; 177 return folders;
175 } 178 }
176 179
177/* 180/*
178 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 181 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
179 * We must not forget to filter them out in next loop! 182 * We must not forget to filter them out in next loop!
180 * it seems like ugly code. and yes - it is ugly code. but the best way. 183 * it seems like ugly code. and yes - it is ugly code. but the best way.
181 */ 184 */
182 QString temp; 185 QString temp;
183 mask = "INBOX" ; 186 mask = "INBOX" ;
184 mailimap_mailbox_list *list; 187 mailimap_mailbox_list *list;
185 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 188 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
186 QString del; 189 QString del;
190 bool selectable = true;
191 bool no_inferiors = false;
187 if ( err == MAILIMAP_NO_ERROR ) { 192 if ( err == MAILIMAP_NO_ERROR ) {
188 current = result->first; 193 current = result->first;
189 for ( int i = result->count; i > 0; i-- ) { 194 for ( int i = result->count; i > 0; i-- ) {
190 list = (mailimap_mailbox_list *) current->data; 195 list = (mailimap_mailbox_list *) current->data;
191 // it is better use the deep copy mechanism of qt itself 196 // it is better use the deep copy mechanism of qt itself
192 // instead of using strdup! 197 // instead of using strdup!
193 temp = list->mb_name; 198 temp = list->mb_name;
194 del = list->mb_delimiter; 199 del = list->mb_delimiter;
195 folders->append( new IMAPFolder(temp,del,true,account->getPrefix()));
196 current = current->next; 200 current = current->next;
201 if ( (bflags = list->mb_flag) ) {
202 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
203 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
204 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
205 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
206 no_inferiors = true;
207 }
208 }
209 }
210 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
197 } 211 }
198 } else { 212 } else {
199 qDebug("error fetching folders: %s",m_imap->imap_response); 213 qDebug("error fetching folders: %s",m_imap->imap_response);
200 } 214 }
201 mailimap_list_result_free( result ); 215 mailimap_list_result_free( result );
202 216
203/* 217/*
204 * second stage - get the other then inbox folders 218 * second stage - get the other then inbox folders
205 */ 219 */
206 mask = "*" ; 220 mask = "*" ;
207 path = account->getPrefix().latin1(); 221 path = account->getPrefix().latin1();
208 if (!path) path = ""; 222 if (!path) path = "";
209 qDebug(path); 223 qDebug(path);
210 bool selectable = true;
211 mailimap_mbx_list_flags*bflags;
212 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 224 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
213 if ( err == MAILIMAP_NO_ERROR ) { 225 if ( err == MAILIMAP_NO_ERROR ) {
214 current = result->first; 226 current = result->first;
215 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 227 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
228 no_inferiors = false;
216 list = (mailimap_mailbox_list *) current->data; 229 list = (mailimap_mailbox_list *) current->data;
217 // it is better use the deep copy mechanism of qt itself 230 // it is better use the deep copy mechanism of qt itself
218 // instead of using strdup! 231 // instead of using strdup!
219 temp = list->mb_name; 232 temp = list->mb_name;
220 if (temp.lower()=="inbox") 233 if (temp.lower()=="inbox")
221 continue; 234 continue;
222 if (temp.lower()==account->getPrefix().lower()) 235 if (temp.lower()==account->getPrefix().lower())
223 continue; 236 continue;
224 if ( (bflags = list->mb_flag) ) { 237 if ( (bflags = list->mb_flag) ) {
225 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 238 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
226 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 239 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
240 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
241 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
242 no_inferiors = true;
243 }
244 }
227 } 245 }
228 del = list->mb_delimiter; 246 del = list->mb_delimiter;
229 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); 247 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
230 } 248 }
231 } else { 249 } else {
232 qDebug("error fetching folders %s",m_imap->imap_response); 250 qDebug("error fetching folders %s",m_imap->imap_response);
233 } 251 }
234 if (result) mailimap_list_result_free( result ); 252 if (result) mailimap_list_result_free( result );
235 return folders; 253 return folders;
236} 254}
237 255
238RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 256RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
239{ 257{
240 RecMail * m = 0; 258 RecMail * m = 0;
241 mailimap_msg_att_item *item=0; 259 mailimap_msg_att_item *item=0;
242 clistcell *current,*c,*cf; 260 clistcell *current,*c,*cf;
243 mailimap_msg_att_dynamic*flist; 261 mailimap_msg_att_dynamic*flist;
244 mailimap_flag_fetch*cflag; 262 mailimap_flag_fetch*cflag;
245 int size; 263 int size;
246 QBitArray mFlags(7); 264 QBitArray mFlags(7);
247 QStringList addresslist; 265 QStringList addresslist;
248 266
249 if (!m_att) { 267 if (!m_att) {
250 return m; 268 return m;
251 } 269 }
252 m = new RecMail(); 270 m = new RecMail();
253 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 271 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
254 current = c; 272 current = c;
255 size = 0; 273 size = 0;
256 item = (mailimap_msg_att_item*)current->data; 274 item = (mailimap_msg_att_item*)current->data;
257 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 275 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
258 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 276 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
259 if (!flist->att_list) { 277 if (!flist->att_list) {
260 continue; 278 continue;
261 } 279 }
262 cf = flist->att_list->first; 280 cf = flist->att_list->first;
263 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 281 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
264 cflag = (mailimap_flag_fetch*)cf->data; 282 cflag = (mailimap_flag_fetch*)cf->data;
265 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 283 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
266 switch (cflag->fl_flag->fl_type) { 284 switch (cflag->fl_flag->fl_type) {
267 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 285 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
268 mFlags.setBit(FLAG_ANSWERED); 286 mFlags.setBit(FLAG_ANSWERED);
269 break; 287 break;
270 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 288 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
271 mFlags.setBit(FLAG_FLAGGED); 289 mFlags.setBit(FLAG_FLAGGED);
272 break; 290 break;
273 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 291 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
274 mFlags.setBit(FLAG_DELETED); 292 mFlags.setBit(FLAG_DELETED);
275 break; 293 break;
276 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 294 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
277 mFlags.setBit(FLAG_SEEN); 295 mFlags.setBit(FLAG_SEEN);
278 break; 296 break;
279 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 297 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
280 mFlags.setBit(FLAG_DRAFT); 298 mFlags.setBit(FLAG_DRAFT);
281 break; 299 break;
282 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 300 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
283 break; 301 break;
284 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 302 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
285 break; 303 break;
286 default: 304 default:
287 break; 305 break;
288 } 306 }
289 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 307 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
290 mFlags.setBit(FLAG_RECENT); 308 mFlags.setBit(FLAG_RECENT);
291 } 309 }
292 } 310 }
293 continue; 311 continue;
294 } 312 }
295 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 313 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
296 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 314 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
297 m->setDate(head->env_date); 315 m->setDate(head->env_date);
298 m->setSubject(convert_String((const char*)head->env_subject)); 316 m->setSubject(convert_String((const char*)head->env_subject));
299 //m->setSubject(head->env_subject); 317 //m->setSubject(head->env_subject);
300 if (head->env_from!=NULL) { 318 if (head->env_from!=NULL) {
301 addresslist = address_list_to_stringlist(head->env_from->frm_list); 319 addresslist = address_list_to_stringlist(head->env_from->frm_list);
302 if (addresslist.count()) { 320 if (addresslist.count()) {
303 m->setFrom(addresslist.first()); 321 m->setFrom(addresslist.first());
304 } 322 }
305 } 323 }
306 if (head->env_to!=NULL) { 324 if (head->env_to!=NULL) {
307 addresslist = address_list_to_stringlist(head->env_to->to_list); 325 addresslist = address_list_to_stringlist(head->env_to->to_list);
308 m->setTo(addresslist); 326 m->setTo(addresslist);
309 } 327 }
310 if (head->env_cc!=NULL) { 328 if (head->env_cc!=NULL) {
311 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 329 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
312 m->setCC(addresslist); 330 m->setCC(addresslist);
313 } 331 }
314 if (head->env_bcc!=NULL) { 332 if (head->env_bcc!=NULL) {
315 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 333 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
316 m->setBcc(addresslist); 334 m->setBcc(addresslist);
317 } 335 }
318 if (head->env_reply_to!=NULL) { 336 if (head->env_reply_to!=NULL) {
319 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 337 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
320 if (addresslist.count()) { 338 if (addresslist.count()) {
321 m->setReplyto(addresslist.first()); 339 m->setReplyto(addresslist.first());
322 } 340 }
323 } 341 }
324 m->setMsgid(QString(head->env_message_id)); 342 m->setMsgid(QString(head->env_message_id));
325 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 343 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
326#if 0 344#if 0
327 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 345 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
328 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 346 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
329 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); 347 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);
330 qDebug(da.toString()); 348 qDebug(da.toString());
331#endif 349#endif
332 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 350 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
333 size = item->att_data.att_static->att_data.att_rfc822_size; 351 size = item->att_data.att_static->att_data.att_rfc822_size;
334 } 352 }
335 } 353 }
336 /* msg is already deleted */ 354 /* msg is already deleted */
337 if (mFlags.testBit(FLAG_DELETED) && m) { 355 if (mFlags.testBit(FLAG_DELETED) && m) {
338 delete m; 356 delete m;
339 m = 0; 357 m = 0;
340 } 358 }
341 if (m) { 359 if (m) {
342 m->setFlags(mFlags); 360 m->setFlags(mFlags);
343 m->setMsgsize(size); 361 m->setMsgsize(size);
344 } 362 }
345 return m; 363 return m;
346} 364}
347 365
348RecBody IMAPwrapper::fetchBody(const RecMail&mail) 366RecBody IMAPwrapper::fetchBody(const RecMail&mail)
349{ 367{
350 RecBody body; 368 RecBody body;
351 const char *mb; 369 const char *mb;
352 int err = MAILIMAP_NO_ERROR; 370 int err = MAILIMAP_NO_ERROR;
353 clist *result = 0; 371 clist *result = 0;
354 clistcell *current; 372 clistcell *current;
355 mailimap_fetch_att *fetchAtt = 0; 373 mailimap_fetch_att *fetchAtt = 0;
356 mailimap_fetch_type *fetchType = 0; 374 mailimap_fetch_type *fetchType = 0;
357 mailimap_set *set = 0; 375 mailimap_set *set = 0;
358 mailimap_body*body_desc = 0; 376 mailimap_body*body_desc = 0;
359 377
360 mb = mail.getMbox().latin1(); 378 mb = mail.getMbox().latin1();
361 379
362 login(); 380 login();
363 if (!m_imap) { 381 if (!m_imap) {
364 return body; 382 return body;
365 } 383 }
366 384
367 err = mailimap_select( m_imap, (char*)mb); 385 err = mailimap_select( m_imap, (char*)mb);
368 if ( err != MAILIMAP_NO_ERROR ) { 386 if ( err != MAILIMAP_NO_ERROR ) {
369 qDebug("error selecting mailbox: %s",m_imap->imap_response); 387 qDebug("error selecting mailbox: %s",m_imap->imap_response);
370 return body; 388 return body;
371 } 389 }
372 390
373 /* the range has to start at 1!!! not with 0!!!! */ 391 /* the range has to start at 1!!! not with 0!!!! */
374 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 392 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
375 fetchAtt = mailimap_fetch_att_new_bodystructure(); 393 fetchAtt = mailimap_fetch_att_new_bodystructure();
376 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 394 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
377 err = mailimap_fetch( m_imap, set, fetchType, &result ); 395 err = mailimap_fetch( m_imap, set, fetchType, &result );
378 mailimap_set_free( set ); 396 mailimap_set_free( set );
379 mailimap_fetch_type_free( fetchType ); 397 mailimap_fetch_type_free( fetchType );
380 398
381 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 399 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
382 mailimap_msg_att * msg_att; 400 mailimap_msg_att * msg_att;
383 msg_att = (mailimap_msg_att*)current->data; 401 msg_att = (mailimap_msg_att*)current->data;
384 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 402 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
385 body_desc = item->att_data.att_static->att_data.att_body; 403 body_desc = item->att_data.att_static->att_data.att_body;
386 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 404 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
387 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 405 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
388 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 406 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
389 qDebug("Mulitpart mail"); 407 qDebug("Mulitpart mail");
390 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 408 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
391 } 409 }
392 } else { 410 } else {
393 qDebug("error fetching body: %s",m_imap->imap_response); 411 qDebug("error fetching body: %s",m_imap->imap_response);
394 } 412 }
395 if (result) mailimap_fetch_list_free(result); 413 if (result) mailimap_fetch_list_free(result);
396 return body; 414 return body;
397} 415}
398 416
399/* this routine is just called when the mail has only ONE part. 417/* this routine is just called when the mail has only ONE part.
400 for filling the parts of a multi-part-message there are other 418 for filling the parts of a multi-part-message there are other
401 routines 'cause we can not simply fetch the whole body. */ 419 routines 'cause we can not simply fetch the whole body. */
402void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 420void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
403{ 421{
404 if (!mailDescription) { 422 if (!mailDescription) {
405 return; 423 return;
406 } 424 }
407 QString sub,body_text; 425 QString sub,body_text;
408 RecPart singlePart; 426 RecPart singlePart;
409 QValueList<int> path; 427 QValueList<int> path;
410 fillSinglePart(singlePart,mailDescription); 428 fillSinglePart(singlePart,mailDescription);
411 switch (mailDescription->bd_type) { 429 switch (mailDescription->bd_type) {
412 case MAILIMAP_BODY_TYPE_1PART_MSG: 430 case MAILIMAP_BODY_TYPE_1PART_MSG:
413 path.append(1); 431 path.append(1);
414 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 432 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
415 target_body.setBodytext(body_text); 433 target_body.setBodytext(body_text);
416 target_body.setDescription(singlePart); 434 target_body.setDescription(singlePart);
417 break; 435 break;
418 case MAILIMAP_BODY_TYPE_1PART_TEXT: 436 case MAILIMAP_BODY_TYPE_1PART_TEXT:
419 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 437 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
420 path.append(1); 438 path.append(1);
421 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 439 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
422 target_body.setBodytext(body_text); 440 target_body.setBodytext(body_text);
423 target_body.setDescription(singlePart); 441 target_body.setDescription(singlePart);
424 break; 442 break;
425 case MAILIMAP_BODY_TYPE_1PART_BASIC: 443 case MAILIMAP_BODY_TYPE_1PART_BASIC:
426 qDebug("Single attachment"); 444 qDebug("Single attachment");
427 target_body.setBodytext(""); 445 target_body.setBodytext("");
428 target_body.addPart(singlePart); 446 target_body.addPart(singlePart);
429 break; 447 break;
430 default: 448 default:
431 break; 449 break;
432 } 450 }
433 451
434 return; 452 return;
435} 453}
436 454
437QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 455QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
438{ 456{
439 QStringList l; 457 QStringList l;
440 QString from; 458 QString from;
441 bool named_from; 459 bool named_from;
442 clistcell *current = NULL; 460 clistcell *current = NULL;
443 mailimap_address * current_address=NULL; 461 mailimap_address * current_address=NULL;
444 if (!list) { 462 if (!list) {
445 return l; 463 return l;
446 } 464 }
447 unsigned int count = 0; 465 unsigned int count = 0;
448 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 466 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
449 from = ""; 467 from = "";
450 named_from = false; 468 named_from = false;
451 current_address=(mailimap_address*)current->data; 469 current_address=(mailimap_address*)current->data;
452 if (current_address->ad_personal_name){ 470 if (current_address->ad_personal_name){
453 from+=convert_String((const char*)current_address->ad_personal_name); 471 from+=convert_String((const char*)current_address->ad_personal_name);
454 //from+=QString(current_address->ad_personal_name); 472 //from+=QString(current_address->ad_personal_name);
455 from+=" "; 473 from+=" ";
456 named_from = true; 474 named_from = true;
457 } 475 }
458 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 476 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
459 from+="<"; 477 from+="<";
460 } 478 }
461 if (current_address->ad_mailbox_name) { 479 if (current_address->ad_mailbox_name) {
462 from+=QString(current_address->ad_mailbox_name); 480 from+=QString(current_address->ad_mailbox_name);
463 from+="@"; 481 from+="@";
464 } 482 }
465 if (current_address->ad_host_name) { 483 if (current_address->ad_host_name) {
466 from+=QString(current_address->ad_host_name); 484 from+=QString(current_address->ad_host_name);
467 } 485 }
468 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 486 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
469 from+=">"; 487 from+=">";
470 } 488 }
471 l.append(QString(from)); 489 l.append(QString(from));
472 if (++count > 99) { 490 if (++count > 99) {
473 break; 491 break;
474 } 492 }
475 } 493 }
476 return l; 494 return l;
477} 495}
478 496
479encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 497encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
480{ 498{
481 encodedString*res=new encodedString; 499 encodedString*res=new encodedString;
482 const char*mb; 500 const char*mb;
483 int err; 501 int err;
484 mailimap_fetch_type *fetchType; 502 mailimap_fetch_type *fetchType;
485 mailimap_set *set; 503 mailimap_set *set;
@@ -565,256 +583,340 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mai
565 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 583 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
566 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); 584 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding());
567 target_body.setDescription(currentPart); 585 target_body.setDescription(currentPart);
568 target_body.setBodytext(body_text); 586 target_body.setBodytext(body_text);
569 } else { 587 } else {
570 QString id(""); 588 QString id("");
571 for (unsigned int j = 0; j < countlist.count();++j) { 589 for (unsigned int j = 0; j < countlist.count();++j) {
572 id+=(j>0?" ":""); 590 id+=(j>0?" ":"");
573 id+=QString("%1").arg(countlist[j]); 591 id+=QString("%1").arg(countlist[j]);
574 } 592 }
575 qDebug("ID= %s",id.latin1()); 593 qDebug("ID= %s",id.latin1());
576 currentPart.setIdentifier(id); 594 currentPart.setIdentifier(id);
577 currentPart.setPositionlist(countlist); 595 currentPart.setPositionlist(countlist);
578 target_body.addPart(currentPart); 596 target_body.addPart(currentPart);
579 } 597 }
580 } 598 }
581 } 599 }
582} 600}
583 601
584void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 602void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
585{ 603{
586 if (!Description) { 604 if (!Description) {
587 return; 605 return;
588 } 606 }
589 switch (Description->bd_type) { 607 switch (Description->bd_type) {
590 case MAILIMAP_BODY_TYPE_1PART_TEXT: 608 case MAILIMAP_BODY_TYPE_1PART_TEXT:
591 target_part.setType("text"); 609 target_part.setType("text");
592 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 610 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
593 break; 611 break;
594 case MAILIMAP_BODY_TYPE_1PART_BASIC: 612 case MAILIMAP_BODY_TYPE_1PART_BASIC:
595 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 613 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
596 break; 614 break;
597 case MAILIMAP_BODY_TYPE_1PART_MSG: 615 case MAILIMAP_BODY_TYPE_1PART_MSG:
598 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 616 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
599 break; 617 break;
600 default: 618 default:
601 break; 619 break;
602 } 620 }
603} 621}
604 622
605void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 623void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
606{ 624{
607 if (!which) { 625 if (!which) {
608 return; 626 return;
609 } 627 }
610 QString sub; 628 QString sub;
611 sub = which->bd_media_text; 629 sub = which->bd_media_text;
612 target_part.setSubtype(sub.lower()); 630 target_part.setSubtype(sub.lower());
613 target_part.setLines(which->bd_lines); 631 target_part.setLines(which->bd_lines);
614 fillBodyFields(target_part,which->bd_fields); 632 fillBodyFields(target_part,which->bd_fields);
615} 633}
616 634
617void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 635void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
618{ 636{
619 if (!which) { 637 if (!which) {
620 return; 638 return;
621 } 639 }
622// QString sub; 640// QString sub;
623// sub = which->bd_media_text; 641// sub = which->bd_media_text;
624// target_part.setSubtype(sub.lower()); 642// target_part.setSubtype(sub.lower());
625 qDebug("Message part"); 643 qDebug("Message part");
626 /* we set this type to text/plain */ 644 /* we set this type to text/plain */
627 target_part.setType("text"); 645 target_part.setType("text");
628 target_part.setSubtype("plain"); 646 target_part.setSubtype("plain");
629 target_part.setLines(which->bd_lines); 647 target_part.setLines(which->bd_lines);
630 fillBodyFields(target_part,which->bd_fields); 648 fillBodyFields(target_part,which->bd_fields);
631} 649}
632 650
633void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 651void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
634{ 652{
635 if (!which) { 653 if (!which) {
636 return; 654 return;
637 } 655 }
638 QString type,sub; 656 QString type,sub;
639 switch (which->bd_media_basic->med_type) { 657 switch (which->bd_media_basic->med_type) {
640 case MAILIMAP_MEDIA_BASIC_APPLICATION: 658 case MAILIMAP_MEDIA_BASIC_APPLICATION:
641 type = "application"; 659 type = "application";
642 break; 660 break;
643 case MAILIMAP_MEDIA_BASIC_AUDIO: 661 case MAILIMAP_MEDIA_BASIC_AUDIO:
644 type = "audio"; 662 type = "audio";
645 break; 663 break;
646 case MAILIMAP_MEDIA_BASIC_IMAGE: 664 case MAILIMAP_MEDIA_BASIC_IMAGE:
647 type = "image"; 665 type = "image";
648 break; 666 break;
649 case MAILIMAP_MEDIA_BASIC_MESSAGE: 667 case MAILIMAP_MEDIA_BASIC_MESSAGE:
650 type = "message"; 668 type = "message";
651 break; 669 break;
652 case MAILIMAP_MEDIA_BASIC_VIDEO: 670 case MAILIMAP_MEDIA_BASIC_VIDEO:
653 type = "video"; 671 type = "video";
654 break; 672 break;
655 case MAILIMAP_MEDIA_BASIC_OTHER: 673 case MAILIMAP_MEDIA_BASIC_OTHER:
656 default: 674 default:
657 if (which->bd_media_basic->med_basic_type) { 675 if (which->bd_media_basic->med_basic_type) {
658 type = which->bd_media_basic->med_basic_type; 676 type = which->bd_media_basic->med_basic_type;
659 } else { 677 } else {
660 type = ""; 678 type = "";
661 } 679 }
662 break; 680 break;
663 } 681 }
664 if (which->bd_media_basic->med_subtype) { 682 if (which->bd_media_basic->med_subtype) {
665 sub = which->bd_media_basic->med_subtype; 683 sub = which->bd_media_basic->med_subtype;
666 } else { 684 } else {
667 sub = ""; 685 sub = "";
668 } 686 }
669 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 687 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
670 target_part.setType(type.lower()); 688 target_part.setType(type.lower());
671 target_part.setSubtype(sub.lower()); 689 target_part.setSubtype(sub.lower());
672 fillBodyFields(target_part,which->bd_fields); 690 fillBodyFields(target_part,which->bd_fields);
673} 691}
674 692
675void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 693void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
676{ 694{
677 if (!which) return; 695 if (!which) return;
678 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 696 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
679 clistcell*cur; 697 clistcell*cur;
680 mailimap_single_body_fld_param*param=0; 698 mailimap_single_body_fld_param*param=0;
681 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 699 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
682 param = (mailimap_single_body_fld_param*)cur->data; 700 param = (mailimap_single_body_fld_param*)cur->data;
683 if (param) { 701 if (param) {
684 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 702 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
685 } 703 }
686 } 704 }
687 } 705 }
688 mailimap_body_fld_enc*enc = which->bd_encoding; 706 mailimap_body_fld_enc*enc = which->bd_encoding;
689 QString encoding(""); 707 QString encoding("");
690 switch (enc->enc_type) { 708 switch (enc->enc_type) {
691 case MAILIMAP_BODY_FLD_ENC_7BIT: 709 case MAILIMAP_BODY_FLD_ENC_7BIT:
692 encoding = "7bit"; 710 encoding = "7bit";
693 break; 711 break;
694 case MAILIMAP_BODY_FLD_ENC_8BIT: 712 case MAILIMAP_BODY_FLD_ENC_8BIT:
695 encoding = "8bit"; 713 encoding = "8bit";
696 break; 714 break;
697 case MAILIMAP_BODY_FLD_ENC_BINARY: 715 case MAILIMAP_BODY_FLD_ENC_BINARY:
698 encoding="binary"; 716 encoding="binary";
699 break; 717 break;
700 case MAILIMAP_BODY_FLD_ENC_BASE64: 718 case MAILIMAP_BODY_FLD_ENC_BASE64:
701 encoding="base64"; 719 encoding="base64";
702 break; 720 break;
703 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 721 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
704 encoding="quoted-printable"; 722 encoding="quoted-printable";
705 break; 723 break;
706 case MAILIMAP_BODY_FLD_ENC_OTHER: 724 case MAILIMAP_BODY_FLD_ENC_OTHER:
707 default: 725 default:
708 if (enc->enc_value) { 726 if (enc->enc_value) {
709 char*t=enc->enc_value; 727 char*t=enc->enc_value;
710 encoding=QString(enc->enc_value); 728 encoding=QString(enc->enc_value);
711 enc->enc_value=0L; 729 enc->enc_value=0L;
712 free(t); 730 free(t);
713 } 731 }
714 } 732 }
715 if (which->bd_description) { 733 if (which->bd_description) {
716 target_part.setDescription(QString(which->bd_description)); 734 target_part.setDescription(QString(which->bd_description));
717 } 735 }
718 target_part.setEncoding(encoding); 736 target_part.setEncoding(encoding);
719 target_part.setSize(which->bd_size); 737 target_part.setSize(which->bd_size);
720} 738}
721 739
722void IMAPwrapper::deleteMail(const RecMail&mail) 740void IMAPwrapper::deleteMail(const RecMail&mail)
723{ 741{
724 mailimap_flag_list*flist; 742 mailimap_flag_list*flist;
725 mailimap_set *set; 743 mailimap_set *set;
726 mailimap_store_att_flags * store_flags; 744 mailimap_store_att_flags * store_flags;
727 int err; 745 int err;
728 login(); 746 login();
729 if (!m_imap) { 747 if (!m_imap) {
730 return; 748 return;
731 } 749 }
732 const char *mb = mail.getMbox().latin1(); 750 const char *mb = mail.getMbox().latin1();
733 err = mailimap_select( m_imap, (char*)mb); 751 err = mailimap_select( m_imap, (char*)mb);
734 if ( err != MAILIMAP_NO_ERROR ) { 752 if ( err != MAILIMAP_NO_ERROR ) {
735 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); 753 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
736 return; 754 return;
737 } 755 }
738 flist = mailimap_flag_list_new_empty(); 756 flist = mailimap_flag_list_new_empty();
739 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 757 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
740 store_flags = mailimap_store_att_flags_new_set_flags(flist); 758 store_flags = mailimap_store_att_flags_new_set_flags(flist);
741 set = mailimap_set_new_single(mail.getNumber()); 759 set = mailimap_set_new_single(mail.getNumber());
742 err = mailimap_store(m_imap,set,store_flags); 760 err = mailimap_store(m_imap,set,store_flags);
743 mailimap_set_free( set ); 761 mailimap_set_free( set );
744 mailimap_store_att_flags_free(store_flags); 762 mailimap_store_att_flags_free(store_flags);
745 763
746 if (err != MAILIMAP_NO_ERROR) { 764 if (err != MAILIMAP_NO_ERROR) {
747 qDebug("error deleting mail: %s",m_imap->imap_response); 765 qDebug("error deleting mail: %s",m_imap->imap_response);
748 return; 766 return;
749 } 767 }
750 qDebug("deleting mail: %s",m_imap->imap_response); 768 qDebug("deleting mail: %s",m_imap->imap_response);
751 /* should we realy do that at this moment? */ 769 /* should we realy do that at this moment? */
752 err = mailimap_expunge(m_imap); 770 err = mailimap_expunge(m_imap);
753 if (err != MAILIMAP_NO_ERROR) { 771 if (err != MAILIMAP_NO_ERROR) {
754 qDebug("error deleting mail: %s",m_imap->imap_response); 772 qDebug("error deleting mail: %s",m_imap->imap_response);
755 } 773 }
756 qDebug("Delete successfull %s",m_imap->imap_response); 774 qDebug("Delete successfull %s",m_imap->imap_response);
757} 775}
758 776
759void IMAPwrapper::answeredMail(const RecMail&mail) 777void IMAPwrapper::answeredMail(const RecMail&mail)
760{ 778{
761 mailimap_flag_list*flist; 779 mailimap_flag_list*flist;
762 mailimap_set *set; 780 mailimap_set *set;
763 mailimap_store_att_flags * store_flags; 781 mailimap_store_att_flags * store_flags;
764 int err; 782 int err;
765 login(); 783 login();
766 if (!m_imap) { 784 if (!m_imap) {
767 return; 785 return;
768 } 786 }
769 const char *mb = mail.getMbox().latin1(); 787 const char *mb = mail.getMbox().latin1();
770 err = mailimap_select( m_imap, (char*)mb); 788 err = mailimap_select( m_imap, (char*)mb);
771 if ( err != MAILIMAP_NO_ERROR ) { 789 if ( err != MAILIMAP_NO_ERROR ) {
772 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); 790 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response);
773 return; 791 return;
774 } 792 }
775 flist = mailimap_flag_list_new_empty(); 793 flist = mailimap_flag_list_new_empty();
776 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 794 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
777 store_flags = mailimap_store_att_flags_new_add_flags(flist); 795 store_flags = mailimap_store_att_flags_new_add_flags(flist);
778 set = mailimap_set_new_single(mail.getNumber()); 796 set = mailimap_set_new_single(mail.getNumber());
779 err = mailimap_store(m_imap,set,store_flags); 797 err = mailimap_store(m_imap,set,store_flags);
780 mailimap_set_free( set ); 798 mailimap_set_free( set );
781 mailimap_store_att_flags_free(store_flags); 799 mailimap_store_att_flags_free(store_flags);
782 800
783 if (err != MAILIMAP_NO_ERROR) { 801 if (err != MAILIMAP_NO_ERROR) {
784 qDebug("error marking mail: %s",m_imap->imap_response); 802 qDebug("error marking mail: %s",m_imap->imap_response);
785 return; 803 return;
786 } 804 }
787} 805}
788 806
789QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 807QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
790{ 808{
791 QString body(""); 809 QString body("");
792 encodedString*res = fetchRawPart(mail,path,internal_call); 810 encodedString*res = fetchRawPart(mail,path,internal_call);
793 encodedString*r = decode_String(res,enc); 811 encodedString*r = decode_String(res,enc);
794 delete res; 812 delete res;
795 if (r) { 813 if (r) {
796 if (r->Length()>0) { 814 if (r->Length()>0) {
797 body = r->Content(); 815 body = r->Content();
798 } 816 }
799 delete r; 817 delete r;
800 } 818 }
801 return body; 819 return body;
802} 820}
803 821
804QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 822QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
805{ 823{
806 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); 824 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
807} 825}
808 826
809encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) 827encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
810{ 828{
811 encodedString*res = fetchRawPart(mail,part.Positionlist(),false); 829 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
812 encodedString*r = decode_String(res,part.Encoding()); 830 encodedString*r = decode_String(res,part.Encoding());
813 delete res; 831 delete res;
814 return r; 832 return r;
815} 833}
816 834
817encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 835encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
818{ 836{
819 return fetchRawPart(mail,part.Positionlist(),false); 837 return fetchRawPart(mail,part.Positionlist(),false);
820} 838}
839
840int IMAPwrapper::deleteAllMail(const Folder*folder)
841{
842 login();
843 if (!m_imap) {
844 return 0;
845 }
846 mailimap_flag_list*flist;
847 mailimap_set *set;
848 mailimap_store_att_flags * store_flags;
849 int err = mailimap_select( m_imap, folder->getName().latin1());
850 if ( err != MAILIMAP_NO_ERROR ) {
851 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response));
852 return 0;
853 }
854 int last = m_imap->imap_selection_info->sel_exists;
855 if (last == 0) {
856 Global::statusMessage(tr("Mailbox has no mails!"));
857 return 0;
858 }
859 flist = mailimap_flag_list_new_empty();
860 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
861 store_flags = mailimap_store_att_flags_new_set_flags(flist);
862 set = mailimap_set_new_interval( 1, last );
863 err = mailimap_store(m_imap,set,store_flags);
864 mailimap_set_free( set );
865 mailimap_store_att_flags_free(store_flags);
866 if (err != MAILIMAP_NO_ERROR) {
867 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
868 return 0;
869 }
870 qDebug("deleting mail: %s",m_imap->imap_response);
871 /* should we realy do that at this moment? */
872 err = mailimap_expunge(m_imap);
873 if (err != MAILIMAP_NO_ERROR) {
874 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
875 return 0;
876 }
877 qDebug("Delete successfull %s",m_imap->imap_response);
878 return 1;
879}
880
881int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder)
882{
883 if (folder.length()==0) return 0;
884 login();
885 if (!m_imap) {return 0;}
886 QString pre = account->getPrefix();
887 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
888 pre+=delemiter;
889 }
890 if (parentfolder) {
891 pre += parentfolder->getDisplayName()+delemiter;
892 }
893 pre+=folder;
894 if (getsubfolder) {
895 if (delemiter.length()>0) {
896 pre+=delemiter;
897 } else {
898 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre));
899 return 0;
900 }
901 }
902 qDebug("Creating %s",pre.latin1());
903 int res = mailimap_create(m_imap,pre.latin1());
904 if (res != MAILIMAP_NO_ERROR) {
905 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
906 return 0;
907 }
908 return 1;
909}
910
911int IMAPwrapper::deleteMbox(const Folder*folder)
912{
913 if (!folder) return 0;
914 login();
915 if (!m_imap) {return 0;}
916 int res = mailimap_delete(m_imap,folder->getName());
917 if (res != MAILIMAP_NO_ERROR) {
918 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
919 return 0;
920 }
921 return 1;
922}
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h
index f046297..9b20288 100644
--- a/noncore/net/mail/imapwrapper.h
+++ b/noncore/net/mail/imapwrapper.h
@@ -1,63 +1,67 @@
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_type_1part; 10struct mailimap_body_type_1part;
11struct mailimap_body_type_text; 11struct mailimap_body_type_text;
12struct mailimap_body_type_basic; 12struct mailimap_body_type_basic;
13struct mailimap_body_type_msg; 13struct mailimap_body_type_msg;
14struct mailimap_body_type_mpart; 14struct mailimap_body_type_mpart;
15struct mailimap_body_fields; 15struct mailimap_body_fields;
16struct mailimap_msg_att; 16struct mailimap_msg_att;
17class encodedString; 17class encodedString;
18 18
19class IMAPwrapper : public AbstractMail 19class IMAPwrapper : public AbstractMail
20{ 20{
21 Q_OBJECT 21 Q_OBJECT
22public: 22public:
23 IMAPwrapper( IMAPaccount *a ); 23 IMAPwrapper( IMAPaccount *a );
24 virtual ~IMAPwrapper(); 24 virtual ~IMAPwrapper();
25 virtual QList<Folder>* listFolders(); 25 virtual QList<Folder>* listFolders();
26 virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); 26 virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
27 27
28 virtual void deleteMail(const RecMail&mail); 28 virtual void deleteMail(const RecMail&mail);
29 virtual void answeredMail(const RecMail&mail); 29 virtual void answeredMail(const RecMail&mail);
30 virtual int deleteAllMail(const Folder*folder);
30 31
31 virtual RecBody fetchBody(const RecMail&mail); 32 virtual RecBody fetchBody(const RecMail&mail);
32 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 33 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
33 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 34 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
34 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 35 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
35 36
37 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
38 virtual int deleteMbox(const Folder*folder);
39
36 static void imap_progress( size_t current, size_t maximum ); 40 static void imap_progress( size_t current, size_t maximum );
37 41
38protected: 42protected:
39 RecMail*parse_list_result(mailimap_msg_att*); 43 RecMail*parse_list_result(mailimap_msg_att*);
40 void login(); 44 void login();
41 void logout(); 45 void logout();
42 46
43 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); 47 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
44 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); 48 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call);
45 49
46 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); 50 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
47 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); 51 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>());
48 52
49 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 53 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
50 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 54 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
51 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 55 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
52 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); 56 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
53 57
54 /* just helpers */ 58 /* just helpers */
55 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 59 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
56 static QStringList address_list_to_stringlist(clist*list); 60 static QStringList address_list_to_stringlist(clist*list);
57 61
58 62
59 IMAPaccount *account; 63 IMAPaccount *account;
60 mailimap *m_imap; 64 mailimap *m_imap;
61}; 65};
62 66
63#endif 67#endif
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h
index 509b68e..b609aa7 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.h
+++ b/noncore/net/mail/libmailwrapper/abstractmail.h
@@ -1,42 +1,51 @@
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;
14 14
15class AbstractMail:public QObject 15class AbstractMail:public QObject
16{ 16{
17 Q_OBJECT 17 Q_OBJECT
18public: 18public:
19 AbstractMail(){}; 19 AbstractMail(){};
20 virtual ~AbstractMail(){} 20 virtual ~AbstractMail(){}
21 virtual QList<Folder>* listFolders()=0; 21 virtual QList<Folder>* listFolders()=0;
22 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; 22 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
23 virtual RecBody fetchBody(const RecMail&mail)=0; 23 virtual RecBody fetchBody(const RecMail&mail)=0;
24 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; 24 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
25 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; 25 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
26 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; 26 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
27 27
28 virtual void deleteMail(const RecMail&mail)=0; 28 virtual void deleteMail(const RecMail&mail)=0;
29 virtual void answeredMail(const RecMail&mail)=0; 29 virtual void answeredMail(const RecMail&mail)=0;
30 virtual void cleanMimeCache(){}; 30 virtual void cleanMimeCache(){};
31 virtual int deleteAllMail(const Folder*){return 1;}
32
33 /* mail box methods */
34 /* parameter is the box to create.
35 * if the implementing subclass has prefixes,
36 * them has to be appended automatic.
37 */
38 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false){return 0;}
39 virtual int deleteMbox(const Folder*){return 1;}
31 40
32 static AbstractMail* getWrapper(IMAPaccount *a); 41 static AbstractMail* getWrapper(IMAPaccount *a);
33 static AbstractMail* getWrapper(POP3account *a); 42 static AbstractMail* getWrapper(POP3account *a);
34 /* mbox only! */ 43 /* mbox only! */
35 static AbstractMail* getWrapper(const QString&a); 44 static AbstractMail* getWrapper(const QString&a);
36 45
37protected: 46protected:
38 static encodedString*decode_String(const encodedString*text,const QString&enc); 47 static encodedString*decode_String(const encodedString*text,const QString&enc);
39 static QString convert_String(const char*text); 48 static QString convert_String(const char*text);
40 static QString gen_attachment_id(); 49 static QString gen_attachment_id();
41}; 50};
42#endif 51#endif
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index ab20249..406c57c 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,485 +1,503 @@
1
2#include <stdlib.h> 1#include <stdlib.h>
3
4#include <libetpan/libetpan.h> 2#include <libetpan/libetpan.h>
3#include <qpe/global.h>
5 4
6#include "imapwrapper.h" 5#include "imapwrapper.h"
7#include "mailtypes.h" 6#include "mailtypes.h"
8#include "logindialog.h" 7#include "logindialog.h"
9 8
10IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 9IMAPwrapper::IMAPwrapper( IMAPaccount *a )
11 : AbstractMail() 10 : AbstractMail()
12{ 11{
13 account = a; 12 account = a;
14 m_imap = 0; 13 m_imap = 0;
15} 14}
16 15
17IMAPwrapper::~IMAPwrapper() 16IMAPwrapper::~IMAPwrapper()
18{ 17{
19 logout(); 18 logout();
20} 19}
21 20
22void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 21void IMAPwrapper::imap_progress( size_t current, size_t maximum )
23{ 22{
24 qDebug( "IMAP: %i of %i", current, maximum ); 23 qDebug( "IMAP: %i of %i", current, maximum );
25} 24}
26 25
27void IMAPwrapper::login() 26void IMAPwrapper::login()
28{ 27{
29 const char *server, *user, *pass; 28 const char *server, *user, *pass;
30 uint16_t port; 29 uint16_t port;
31 int err = MAILIMAP_NO_ERROR; 30 int err = MAILIMAP_NO_ERROR;
32 31
33 /* we are connected this moment */ 32 /* we are connected this moment */
34 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 33 /* TODO: setup a timer holding the line or if connection closed - delete the value */
35 if (m_imap) { 34 if (m_imap) {
36 err = mailimap_noop(m_imap); 35 err = mailimap_noop(m_imap);
37 if (err!=MAILIMAP_NO_ERROR) { 36 if (err!=MAILIMAP_NO_ERROR) {
38 logout(); 37 logout();
39 } else { 38 } else {
40 mailstream_flush(m_imap->imap_stream); 39 mailstream_flush(m_imap->imap_stream);
41 return; 40 return;
42 } 41 }
43 } 42 }
44 server = account->getServer().latin1(); 43 server = account->getServer().latin1();
45 port = account->getPort().toUInt(); 44 port = account->getPort().toUInt();
46 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 45 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
47 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 46 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
48 login.show(); 47 login.show();
49 if ( QDialog::Accepted == login.exec() ) { 48 if ( QDialog::Accepted == login.exec() ) {
50 // ok 49 // ok
51 user = strdup( login.getUser().latin1() ); 50 user = strdup( login.getUser().latin1() );
52 pass = strdup( login.getPassword().latin1() ); 51 pass = strdup( login.getPassword().latin1() );
53 } else { 52 } else {
54 // cancel 53 // cancel
55 qDebug( "IMAP: Login canceled" ); 54 qDebug( "IMAP: Login canceled" );
56 return; 55 return;
57 } 56 }
58 } else { 57 } else {
59 user = account->getUser().latin1(); 58 user = account->getUser().latin1();
60 pass = account->getPassword().latin1(); 59 pass = account->getPassword().latin1();
61 } 60 }
62 61
63 m_imap = mailimap_new( 20, &imap_progress ); 62 m_imap = mailimap_new( 20, &imap_progress );
64 /* connect */ 63 /* connect */
65 if (account->getSSL()) { 64 if (account->getSSL()) {
66 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 65 err = mailimap_ssl_connect( m_imap, (char*)server, port );
67 } else { 66 } else {
68 err = mailimap_socket_connect( m_imap, (char*)server, port ); 67 err = mailimap_socket_connect( m_imap, (char*)server, port );
69 } 68 }
70 69
71 if ( err != MAILIMAP_NO_ERROR && 70 if ( err != MAILIMAP_NO_ERROR &&
72 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 71 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
73 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 72 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
74 qDebug("error connecting server: %s",m_imap->imap_response); 73 Global::statusMessage(tr("error connecting imap server: %1").arg(m_imap->imap_response));
75 mailimap_free( m_imap ); 74 mailimap_free( m_imap );
76 m_imap = 0; 75 m_imap = 0;
77 return; 76 return;
78 } 77 }
79 78
80 /* login */ 79 /* login */
81 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 80 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
82 if ( err != MAILIMAP_NO_ERROR ) { 81 if ( err != MAILIMAP_NO_ERROR ) {
83 qDebug("error logging in imap: %s",m_imap->imap_response); 82 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
84 err = mailimap_close( m_imap ); 83 err = mailimap_close( m_imap );
85 mailimap_free( m_imap ); 84 mailimap_free( m_imap );
86 m_imap = 0; 85 m_imap = 0;
87 } 86 }
88} 87}
89 88
90void IMAPwrapper::logout() 89void IMAPwrapper::logout()
91{ 90{
92 int err = MAILIMAP_NO_ERROR; 91 int err = MAILIMAP_NO_ERROR;
93 if (!m_imap) return; 92 if (!m_imap) return;
94 err = mailimap_logout( m_imap ); 93 err = mailimap_logout( m_imap );
95 err = mailimap_close( m_imap ); 94 err = mailimap_close( m_imap );
96 mailimap_free( m_imap ); 95 mailimap_free( m_imap );
97 m_imap = 0; 96 m_imap = 0;
98} 97}
99 98
100void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 99void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
101{ 100{
102 const char *mb = 0; 101 const char *mb = 0;
103 int err = MAILIMAP_NO_ERROR; 102 int err = MAILIMAP_NO_ERROR;
104 clist *result = 0; 103 clist *result = 0;
105 clistcell *current; 104 clistcell *current;
106// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 105// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
107 mailimap_fetch_type *fetchType = 0; 106 mailimap_fetch_type *fetchType = 0;
108 mailimap_set *set = 0; 107 mailimap_set *set = 0;
109 108
110 mb = mailbox.latin1(); 109 mb = mailbox.latin1();
111 login(); 110 login();
112 if (!m_imap) { 111 if (!m_imap) {
113 return; 112 return;
114 } 113 }
115 /* select mailbox READONLY for operations */ 114 /* select mailbox READONLY for operations */
116 err = mailimap_examine( m_imap, (char*)mb); 115 err = mailimap_examine( m_imap, (char*)mb);
117 if ( err != MAILIMAP_NO_ERROR ) { 116 if ( err != MAILIMAP_NO_ERROR ) {
118 qDebug("error selecting mailbox: %s",m_imap->imap_response); 117 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response));
119 return; 118 return;
120 } 119 }
121 120
122 int last = m_imap->imap_selection_info->sel_exists; 121 int last = m_imap->imap_selection_info->sel_exists;
123 122
124 if (last == 0) { 123 if (last == 0) {
125 qDebug("mailbox has no mails"); 124 Global::statusMessage(tr("Mailbox has no mails"));
126 return; 125 return;
126 } else {
127 Global::statusMessage(tr("Mailbox has %1 mails").arg(last));
127 } 128 }
128 129
129 /* the range has to start at 1!!! not with 0!!!! */ 130 /* the range has to start at 1!!! not with 0!!!! */
130 set = mailimap_set_new_interval( 1, last ); 131 set = mailimap_set_new_interval( 1, last );
131 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 132 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
132 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 133 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
133 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 134 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
134 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 135 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
135 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 136 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
136 137
137 err = mailimap_fetch( m_imap, set, fetchType, &result ); 138 err = mailimap_fetch( m_imap, set, fetchType, &result );
138 mailimap_set_free( set ); 139 mailimap_set_free( set );
139 mailimap_fetch_type_free( fetchType ); 140 mailimap_fetch_type_free( fetchType );
140 141
141 QString date,subject,from; 142 QString date,subject,from;
142 143
143 if ( err == MAILIMAP_NO_ERROR ) { 144 if ( err == MAILIMAP_NO_ERROR ) {
144 mailimap_msg_att * msg_att; 145 mailimap_msg_att * msg_att;
145 int i = 0; 146 int i = 0;
146 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 147 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
147 ++i; 148 ++i;
148 msg_att = (mailimap_msg_att*)current->data; 149 msg_att = (mailimap_msg_att*)current->data;
149 RecMail*m = parse_list_result(msg_att); 150 RecMail*m = parse_list_result(msg_att);
150 if (m) { 151 if (m) {
151 m->setNumber(i); 152 m->setNumber(i);
152 m->setMbox(mailbox); 153 m->setMbox(mailbox);
153 m->setWrapper(this); 154 m->setWrapper(this);
154 target.append(m); 155 target.append(m);
155 } 156 }
156 } 157 }
157 } else { 158 } else {
158 qDebug("Error fetching headers: %s",m_imap->imap_response); 159 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
159 } 160 }
160 if (result) mailimap_fetch_list_free(result); 161 if (result) mailimap_fetch_list_free(result);
161} 162}
162 163
163QList<Folder>* IMAPwrapper::listFolders() 164QList<Folder>* IMAPwrapper::listFolders()
164{ 165{
165 const char *path, *mask; 166 const char *path, *mask;
166 int err = MAILIMAP_NO_ERROR; 167 int err = MAILIMAP_NO_ERROR;
167 clist *result = 0; 168 clist *result = 0;
168 clistcell *current = 0; 169 clistcell *current = 0;
170 clistcell*cur_flag = 0;
171 mailimap_mbx_list_flags*bflags = 0;
169 172
170 QList<Folder> * folders = new QList<Folder>(); 173 QList<Folder> * folders = new QList<Folder>();
171 folders->setAutoDelete( false ); 174 folders->setAutoDelete( false );
172 login(); 175 login();
173 if (!m_imap) { 176 if (!m_imap) {
174 return folders; 177 return folders;
175 } 178 }
176 179
177/* 180/*
178 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 181 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
179 * We must not forget to filter them out in next loop! 182 * We must not forget to filter them out in next loop!
180 * it seems like ugly code. and yes - it is ugly code. but the best way. 183 * it seems like ugly code. and yes - it is ugly code. but the best way.
181 */ 184 */
182 QString temp; 185 QString temp;
183 mask = "INBOX" ; 186 mask = "INBOX" ;
184 mailimap_mailbox_list *list; 187 mailimap_mailbox_list *list;
185 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 188 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
186 QString del; 189 QString del;
190 bool selectable = true;
191 bool no_inferiors = false;
187 if ( err == MAILIMAP_NO_ERROR ) { 192 if ( err == MAILIMAP_NO_ERROR ) {
188 current = result->first; 193 current = result->first;
189 for ( int i = result->count; i > 0; i-- ) { 194 for ( int i = result->count; i > 0; i-- ) {
190 list = (mailimap_mailbox_list *) current->data; 195 list = (mailimap_mailbox_list *) current->data;
191 // it is better use the deep copy mechanism of qt itself 196 // it is better use the deep copy mechanism of qt itself
192 // instead of using strdup! 197 // instead of using strdup!
193 temp = list->mb_name; 198 temp = list->mb_name;
194 del = list->mb_delimiter; 199 del = list->mb_delimiter;
195 folders->append( new IMAPFolder(temp,del,true,account->getPrefix()));
196 current = current->next; 200 current = current->next;
201 if ( (bflags = list->mb_flag) ) {
202 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
203 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
204 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
205 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
206 no_inferiors = true;
207 }
208 }
209 }
210 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
197 } 211 }
198 } else { 212 } else {
199 qDebug("error fetching folders: %s",m_imap->imap_response); 213 qDebug("error fetching folders: %s",m_imap->imap_response);
200 } 214 }
201 mailimap_list_result_free( result ); 215 mailimap_list_result_free( result );
202 216
203/* 217/*
204 * second stage - get the other then inbox folders 218 * second stage - get the other then inbox folders
205 */ 219 */
206 mask = "*" ; 220 mask = "*" ;
207 path = account->getPrefix().latin1(); 221 path = account->getPrefix().latin1();
208 if (!path) path = ""; 222 if (!path) path = "";
209 qDebug(path); 223 qDebug(path);
210 bool selectable = true;
211 mailimap_mbx_list_flags*bflags;
212 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 224 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
213 if ( err == MAILIMAP_NO_ERROR ) { 225 if ( err == MAILIMAP_NO_ERROR ) {
214 current = result->first; 226 current = result->first;
215 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 227 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
228 no_inferiors = false;
216 list = (mailimap_mailbox_list *) current->data; 229 list = (mailimap_mailbox_list *) current->data;
217 // it is better use the deep copy mechanism of qt itself 230 // it is better use the deep copy mechanism of qt itself
218 // instead of using strdup! 231 // instead of using strdup!
219 temp = list->mb_name; 232 temp = list->mb_name;
220 if (temp.lower()=="inbox") 233 if (temp.lower()=="inbox")
221 continue; 234 continue;
222 if (temp.lower()==account->getPrefix().lower()) 235 if (temp.lower()==account->getPrefix().lower())
223 continue; 236 continue;
224 if ( (bflags = list->mb_flag) ) { 237 if ( (bflags = list->mb_flag) ) {
225 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 238 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
226 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 239 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
240 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
241 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
242 no_inferiors = true;
243 }
244 }
227 } 245 }
228 del = list->mb_delimiter; 246 del = list->mb_delimiter;
229 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); 247 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
230 } 248 }
231 } else { 249 } else {
232 qDebug("error fetching folders %s",m_imap->imap_response); 250 qDebug("error fetching folders %s",m_imap->imap_response);
233 } 251 }
234 if (result) mailimap_list_result_free( result ); 252 if (result) mailimap_list_result_free( result );
235 return folders; 253 return folders;
236} 254}
237 255
238RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 256RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
239{ 257{
240 RecMail * m = 0; 258 RecMail * m = 0;
241 mailimap_msg_att_item *item=0; 259 mailimap_msg_att_item *item=0;
242 clistcell *current,*c,*cf; 260 clistcell *current,*c,*cf;
243 mailimap_msg_att_dynamic*flist; 261 mailimap_msg_att_dynamic*flist;
244 mailimap_flag_fetch*cflag; 262 mailimap_flag_fetch*cflag;
245 int size; 263 int size;
246 QBitArray mFlags(7); 264 QBitArray mFlags(7);
247 QStringList addresslist; 265 QStringList addresslist;
248 266
249 if (!m_att) { 267 if (!m_att) {
250 return m; 268 return m;
251 } 269 }
252 m = new RecMail(); 270 m = new RecMail();
253 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 271 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
254 current = c; 272 current = c;
255 size = 0; 273 size = 0;
256 item = (mailimap_msg_att_item*)current->data; 274 item = (mailimap_msg_att_item*)current->data;
257 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 275 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
258 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 276 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
259 if (!flist->att_list) { 277 if (!flist->att_list) {
260 continue; 278 continue;
261 } 279 }
262 cf = flist->att_list->first; 280 cf = flist->att_list->first;
263 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 281 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
264 cflag = (mailimap_flag_fetch*)cf->data; 282 cflag = (mailimap_flag_fetch*)cf->data;
265 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 283 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
266 switch (cflag->fl_flag->fl_type) { 284 switch (cflag->fl_flag->fl_type) {
267 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 285 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
268 mFlags.setBit(FLAG_ANSWERED); 286 mFlags.setBit(FLAG_ANSWERED);
269 break; 287 break;
270 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 288 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
271 mFlags.setBit(FLAG_FLAGGED); 289 mFlags.setBit(FLAG_FLAGGED);
272 break; 290 break;
273 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 291 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
274 mFlags.setBit(FLAG_DELETED); 292 mFlags.setBit(FLAG_DELETED);
275 break; 293 break;
276 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 294 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
277 mFlags.setBit(FLAG_SEEN); 295 mFlags.setBit(FLAG_SEEN);
278 break; 296 break;
279 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 297 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
280 mFlags.setBit(FLAG_DRAFT); 298 mFlags.setBit(FLAG_DRAFT);
281 break; 299 break;
282 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 300 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
283 break; 301 break;
284 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 302 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
285 break; 303 break;
286 default: 304 default:
287 break; 305 break;
288 } 306 }
289 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 307 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
290 mFlags.setBit(FLAG_RECENT); 308 mFlags.setBit(FLAG_RECENT);
291 } 309 }
292 } 310 }
293 continue; 311 continue;
294 } 312 }
295 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 313 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
296 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 314 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
297 m->setDate(head->env_date); 315 m->setDate(head->env_date);
298 m->setSubject(convert_String((const char*)head->env_subject)); 316 m->setSubject(convert_String((const char*)head->env_subject));
299 //m->setSubject(head->env_subject); 317 //m->setSubject(head->env_subject);
300 if (head->env_from!=NULL) { 318 if (head->env_from!=NULL) {
301 addresslist = address_list_to_stringlist(head->env_from->frm_list); 319 addresslist = address_list_to_stringlist(head->env_from->frm_list);
302 if (addresslist.count()) { 320 if (addresslist.count()) {
303 m->setFrom(addresslist.first()); 321 m->setFrom(addresslist.first());
304 } 322 }
305 } 323 }
306 if (head->env_to!=NULL) { 324 if (head->env_to!=NULL) {
307 addresslist = address_list_to_stringlist(head->env_to->to_list); 325 addresslist = address_list_to_stringlist(head->env_to->to_list);
308 m->setTo(addresslist); 326 m->setTo(addresslist);
309 } 327 }
310 if (head->env_cc!=NULL) { 328 if (head->env_cc!=NULL) {
311 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 329 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
312 m->setCC(addresslist); 330 m->setCC(addresslist);
313 } 331 }
314 if (head->env_bcc!=NULL) { 332 if (head->env_bcc!=NULL) {
315 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 333 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
316 m->setBcc(addresslist); 334 m->setBcc(addresslist);
317 } 335 }
318 if (head->env_reply_to!=NULL) { 336 if (head->env_reply_to!=NULL) {
319 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 337 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
320 if (addresslist.count()) { 338 if (addresslist.count()) {
321 m->setReplyto(addresslist.first()); 339 m->setReplyto(addresslist.first());
322 } 340 }
323 } 341 }
324 m->setMsgid(QString(head->env_message_id)); 342 m->setMsgid(QString(head->env_message_id));
325 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 343 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
326#if 0 344#if 0
327 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 345 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
328 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 346 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
329 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); 347 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);
330 qDebug(da.toString()); 348 qDebug(da.toString());
331#endif 349#endif
332 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 350 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
333 size = item->att_data.att_static->att_data.att_rfc822_size; 351 size = item->att_data.att_static->att_data.att_rfc822_size;
334 } 352 }
335 } 353 }
336 /* msg is already deleted */ 354 /* msg is already deleted */
337 if (mFlags.testBit(FLAG_DELETED) && m) { 355 if (mFlags.testBit(FLAG_DELETED) && m) {
338 delete m; 356 delete m;
339 m = 0; 357 m = 0;
340 } 358 }
341 if (m) { 359 if (m) {
342 m->setFlags(mFlags); 360 m->setFlags(mFlags);
343 m->setMsgsize(size); 361 m->setMsgsize(size);
344 } 362 }
345 return m; 363 return m;
346} 364}
347 365
348RecBody IMAPwrapper::fetchBody(const RecMail&mail) 366RecBody IMAPwrapper::fetchBody(const RecMail&mail)
349{ 367{
350 RecBody body; 368 RecBody body;
351 const char *mb; 369 const char *mb;
352 int err = MAILIMAP_NO_ERROR; 370 int err = MAILIMAP_NO_ERROR;
353 clist *result = 0; 371 clist *result = 0;
354 clistcell *current; 372 clistcell *current;
355 mailimap_fetch_att *fetchAtt = 0; 373 mailimap_fetch_att *fetchAtt = 0;
356 mailimap_fetch_type *fetchType = 0; 374 mailimap_fetch_type *fetchType = 0;
357 mailimap_set *set = 0; 375 mailimap_set *set = 0;
358 mailimap_body*body_desc = 0; 376 mailimap_body*body_desc = 0;
359 377
360 mb = mail.getMbox().latin1(); 378 mb = mail.getMbox().latin1();
361 379
362 login(); 380 login();
363 if (!m_imap) { 381 if (!m_imap) {
364 return body; 382 return body;
365 } 383 }
366 384
367 err = mailimap_select( m_imap, (char*)mb); 385 err = mailimap_select( m_imap, (char*)mb);
368 if ( err != MAILIMAP_NO_ERROR ) { 386 if ( err != MAILIMAP_NO_ERROR ) {
369 qDebug("error selecting mailbox: %s",m_imap->imap_response); 387 qDebug("error selecting mailbox: %s",m_imap->imap_response);
370 return body; 388 return body;
371 } 389 }
372 390
373 /* the range has to start at 1!!! not with 0!!!! */ 391 /* the range has to start at 1!!! not with 0!!!! */
374 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 392 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
375 fetchAtt = mailimap_fetch_att_new_bodystructure(); 393 fetchAtt = mailimap_fetch_att_new_bodystructure();
376 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 394 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
377 err = mailimap_fetch( m_imap, set, fetchType, &result ); 395 err = mailimap_fetch( m_imap, set, fetchType, &result );
378 mailimap_set_free( set ); 396 mailimap_set_free( set );
379 mailimap_fetch_type_free( fetchType ); 397 mailimap_fetch_type_free( fetchType );
380 398
381 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 399 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
382 mailimap_msg_att * msg_att; 400 mailimap_msg_att * msg_att;
383 msg_att = (mailimap_msg_att*)current->data; 401 msg_att = (mailimap_msg_att*)current->data;
384 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 402 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
385 body_desc = item->att_data.att_static->att_data.att_body; 403 body_desc = item->att_data.att_static->att_data.att_body;
386 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 404 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
387 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 405 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
388 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 406 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
389 qDebug("Mulitpart mail"); 407 qDebug("Mulitpart mail");
390 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 408 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
391 } 409 }
392 } else { 410 } else {
393 qDebug("error fetching body: %s",m_imap->imap_response); 411 qDebug("error fetching body: %s",m_imap->imap_response);
394 } 412 }
395 if (result) mailimap_fetch_list_free(result); 413 if (result) mailimap_fetch_list_free(result);
396 return body; 414 return body;
397} 415}
398 416
399/* this routine is just called when the mail has only ONE part. 417/* this routine is just called when the mail has only ONE part.
400 for filling the parts of a multi-part-message there are other 418 for filling the parts of a multi-part-message there are other
401 routines 'cause we can not simply fetch the whole body. */ 419 routines 'cause we can not simply fetch the whole body. */
402void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 420void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
403{ 421{
404 if (!mailDescription) { 422 if (!mailDescription) {
405 return; 423 return;
406 } 424 }
407 QString sub,body_text; 425 QString sub,body_text;
408 RecPart singlePart; 426 RecPart singlePart;
409 QValueList<int> path; 427 QValueList<int> path;
410 fillSinglePart(singlePart,mailDescription); 428 fillSinglePart(singlePart,mailDescription);
411 switch (mailDescription->bd_type) { 429 switch (mailDescription->bd_type) {
412 case MAILIMAP_BODY_TYPE_1PART_MSG: 430 case MAILIMAP_BODY_TYPE_1PART_MSG:
413 path.append(1); 431 path.append(1);
414 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 432 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
415 target_body.setBodytext(body_text); 433 target_body.setBodytext(body_text);
416 target_body.setDescription(singlePart); 434 target_body.setDescription(singlePart);
417 break; 435 break;
418 case MAILIMAP_BODY_TYPE_1PART_TEXT: 436 case MAILIMAP_BODY_TYPE_1PART_TEXT:
419 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 437 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
420 path.append(1); 438 path.append(1);
421 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 439 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
422 target_body.setBodytext(body_text); 440 target_body.setBodytext(body_text);
423 target_body.setDescription(singlePart); 441 target_body.setDescription(singlePart);
424 break; 442 break;
425 case MAILIMAP_BODY_TYPE_1PART_BASIC: 443 case MAILIMAP_BODY_TYPE_1PART_BASIC:
426 qDebug("Single attachment"); 444 qDebug("Single attachment");
427 target_body.setBodytext(""); 445 target_body.setBodytext("");
428 target_body.addPart(singlePart); 446 target_body.addPart(singlePart);
429 break; 447 break;
430 default: 448 default:
431 break; 449 break;
432 } 450 }
433 451
434 return; 452 return;
435} 453}
436 454
437QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 455QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
438{ 456{
439 QStringList l; 457 QStringList l;
440 QString from; 458 QString from;
441 bool named_from; 459 bool named_from;
442 clistcell *current = NULL; 460 clistcell *current = NULL;
443 mailimap_address * current_address=NULL; 461 mailimap_address * current_address=NULL;
444 if (!list) { 462 if (!list) {
445 return l; 463 return l;
446 } 464 }
447 unsigned int count = 0; 465 unsigned int count = 0;
448 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 466 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
449 from = ""; 467 from = "";
450 named_from = false; 468 named_from = false;
451 current_address=(mailimap_address*)current->data; 469 current_address=(mailimap_address*)current->data;
452 if (current_address->ad_personal_name){ 470 if (current_address->ad_personal_name){
453 from+=convert_String((const char*)current_address->ad_personal_name); 471 from+=convert_String((const char*)current_address->ad_personal_name);
454 //from+=QString(current_address->ad_personal_name); 472 //from+=QString(current_address->ad_personal_name);
455 from+=" "; 473 from+=" ";
456 named_from = true; 474 named_from = true;
457 } 475 }
458 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 476 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
459 from+="<"; 477 from+="<";
460 } 478 }
461 if (current_address->ad_mailbox_name) { 479 if (current_address->ad_mailbox_name) {
462 from+=QString(current_address->ad_mailbox_name); 480 from+=QString(current_address->ad_mailbox_name);
463 from+="@"; 481 from+="@";
464 } 482 }
465 if (current_address->ad_host_name) { 483 if (current_address->ad_host_name) {
466 from+=QString(current_address->ad_host_name); 484 from+=QString(current_address->ad_host_name);
467 } 485 }
468 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 486 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
469 from+=">"; 487 from+=">";
470 } 488 }
471 l.append(QString(from)); 489 l.append(QString(from));
472 if (++count > 99) { 490 if (++count > 99) {
473 break; 491 break;
474 } 492 }
475 } 493 }
476 return l; 494 return l;
477} 495}
478 496
479encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 497encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
480{ 498{
481 encodedString*res=new encodedString; 499 encodedString*res=new encodedString;
482 const char*mb; 500 const char*mb;
483 int err; 501 int err;
484 mailimap_fetch_type *fetchType; 502 mailimap_fetch_type *fetchType;
485 mailimap_set *set; 503 mailimap_set *set;
@@ -565,256 +583,340 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mai
565 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 583 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
566 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); 584 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding());
567 target_body.setDescription(currentPart); 585 target_body.setDescription(currentPart);
568 target_body.setBodytext(body_text); 586 target_body.setBodytext(body_text);
569 } else { 587 } else {
570 QString id(""); 588 QString id("");
571 for (unsigned int j = 0; j < countlist.count();++j) { 589 for (unsigned int j = 0; j < countlist.count();++j) {
572 id+=(j>0?" ":""); 590 id+=(j>0?" ":"");
573 id+=QString("%1").arg(countlist[j]); 591 id+=QString("%1").arg(countlist[j]);
574 } 592 }
575 qDebug("ID= %s",id.latin1()); 593 qDebug("ID= %s",id.latin1());
576 currentPart.setIdentifier(id); 594 currentPart.setIdentifier(id);
577 currentPart.setPositionlist(countlist); 595 currentPart.setPositionlist(countlist);
578 target_body.addPart(currentPart); 596 target_body.addPart(currentPart);
579 } 597 }
580 } 598 }
581 } 599 }
582} 600}
583 601
584void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 602void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
585{ 603{
586 if (!Description) { 604 if (!Description) {
587 return; 605 return;
588 } 606 }
589 switch (Description->bd_type) { 607 switch (Description->bd_type) {
590 case MAILIMAP_BODY_TYPE_1PART_TEXT: 608 case MAILIMAP_BODY_TYPE_1PART_TEXT:
591 target_part.setType("text"); 609 target_part.setType("text");
592 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 610 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
593 break; 611 break;
594 case MAILIMAP_BODY_TYPE_1PART_BASIC: 612 case MAILIMAP_BODY_TYPE_1PART_BASIC:
595 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 613 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
596 break; 614 break;
597 case MAILIMAP_BODY_TYPE_1PART_MSG: 615 case MAILIMAP_BODY_TYPE_1PART_MSG:
598 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 616 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
599 break; 617 break;
600 default: 618 default:
601 break; 619 break;
602 } 620 }
603} 621}
604 622
605void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 623void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
606{ 624{
607 if (!which) { 625 if (!which) {
608 return; 626 return;
609 } 627 }
610 QString sub; 628 QString sub;
611 sub = which->bd_media_text; 629 sub = which->bd_media_text;
612 target_part.setSubtype(sub.lower()); 630 target_part.setSubtype(sub.lower());
613 target_part.setLines(which->bd_lines); 631 target_part.setLines(which->bd_lines);
614 fillBodyFields(target_part,which->bd_fields); 632 fillBodyFields(target_part,which->bd_fields);
615} 633}
616 634
617void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 635void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
618{ 636{
619 if (!which) { 637 if (!which) {
620 return; 638 return;
621 } 639 }
622// QString sub; 640// QString sub;
623// sub = which->bd_media_text; 641// sub = which->bd_media_text;
624// target_part.setSubtype(sub.lower()); 642// target_part.setSubtype(sub.lower());
625 qDebug("Message part"); 643 qDebug("Message part");
626 /* we set this type to text/plain */ 644 /* we set this type to text/plain */
627 target_part.setType("text"); 645 target_part.setType("text");
628 target_part.setSubtype("plain"); 646 target_part.setSubtype("plain");
629 target_part.setLines(which->bd_lines); 647 target_part.setLines(which->bd_lines);
630 fillBodyFields(target_part,which->bd_fields); 648 fillBodyFields(target_part,which->bd_fields);
631} 649}
632 650
633void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 651void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
634{ 652{
635 if (!which) { 653 if (!which) {
636 return; 654 return;
637 } 655 }
638 QString type,sub; 656 QString type,sub;
639 switch (which->bd_media_basic->med_type) { 657 switch (which->bd_media_basic->med_type) {
640 case MAILIMAP_MEDIA_BASIC_APPLICATION: 658 case MAILIMAP_MEDIA_BASIC_APPLICATION:
641 type = "application"; 659 type = "application";
642 break; 660 break;
643 case MAILIMAP_MEDIA_BASIC_AUDIO: 661 case MAILIMAP_MEDIA_BASIC_AUDIO:
644 type = "audio"; 662 type = "audio";
645 break; 663 break;
646 case MAILIMAP_MEDIA_BASIC_IMAGE: 664 case MAILIMAP_MEDIA_BASIC_IMAGE:
647 type = "image"; 665 type = "image";
648 break; 666 break;
649 case MAILIMAP_MEDIA_BASIC_MESSAGE: 667 case MAILIMAP_MEDIA_BASIC_MESSAGE:
650 type = "message"; 668 type = "message";
651 break; 669 break;
652 case MAILIMAP_MEDIA_BASIC_VIDEO: 670 case MAILIMAP_MEDIA_BASIC_VIDEO:
653 type = "video"; 671 type = "video";
654 break; 672 break;
655 case MAILIMAP_MEDIA_BASIC_OTHER: 673 case MAILIMAP_MEDIA_BASIC_OTHER:
656 default: 674 default:
657 if (which->bd_media_basic->med_basic_type) { 675 if (which->bd_media_basic->med_basic_type) {
658 type = which->bd_media_basic->med_basic_type; 676 type = which->bd_media_basic->med_basic_type;
659 } else { 677 } else {
660 type = ""; 678 type = "";
661 } 679 }
662 break; 680 break;
663 } 681 }
664 if (which->bd_media_basic->med_subtype) { 682 if (which->bd_media_basic->med_subtype) {
665 sub = which->bd_media_basic->med_subtype; 683 sub = which->bd_media_basic->med_subtype;
666 } else { 684 } else {
667 sub = ""; 685 sub = "";
668 } 686 }
669 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 687 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
670 target_part.setType(type.lower()); 688 target_part.setType(type.lower());
671 target_part.setSubtype(sub.lower()); 689 target_part.setSubtype(sub.lower());
672 fillBodyFields(target_part,which->bd_fields); 690 fillBodyFields(target_part,which->bd_fields);
673} 691}
674 692
675void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 693void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
676{ 694{
677 if (!which) return; 695 if (!which) return;
678 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 696 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
679 clistcell*cur; 697 clistcell*cur;
680 mailimap_single_body_fld_param*param=0; 698 mailimap_single_body_fld_param*param=0;
681 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 699 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
682 param = (mailimap_single_body_fld_param*)cur->data; 700 param = (mailimap_single_body_fld_param*)cur->data;
683 if (param) { 701 if (param) {
684 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 702 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
685 } 703 }
686 } 704 }
687 } 705 }
688 mailimap_body_fld_enc*enc = which->bd_encoding; 706 mailimap_body_fld_enc*enc = which->bd_encoding;
689 QString encoding(""); 707 QString encoding("");
690 switch (enc->enc_type) { 708 switch (enc->enc_type) {
691 case MAILIMAP_BODY_FLD_ENC_7BIT: 709 case MAILIMAP_BODY_FLD_ENC_7BIT:
692 encoding = "7bit"; 710 encoding = "7bit";
693 break; 711 break;
694 case MAILIMAP_BODY_FLD_ENC_8BIT: 712 case MAILIMAP_BODY_FLD_ENC_8BIT:
695 encoding = "8bit"; 713 encoding = "8bit";
696 break; 714 break;
697 case MAILIMAP_BODY_FLD_ENC_BINARY: 715 case MAILIMAP_BODY_FLD_ENC_BINARY:
698 encoding="binary"; 716 encoding="binary";
699 break; 717 break;
700 case MAILIMAP_BODY_FLD_ENC_BASE64: 718 case MAILIMAP_BODY_FLD_ENC_BASE64:
701 encoding="base64"; 719 encoding="base64";
702 break; 720 break;
703 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 721 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
704 encoding="quoted-printable"; 722 encoding="quoted-printable";
705 break; 723 break;
706 case MAILIMAP_BODY_FLD_ENC_OTHER: 724 case MAILIMAP_BODY_FLD_ENC_OTHER:
707 default: 725 default:
708 if (enc->enc_value) { 726 if (enc->enc_value) {
709 char*t=enc->enc_value; 727 char*t=enc->enc_value;
710 encoding=QString(enc->enc_value); 728 encoding=QString(enc->enc_value);
711 enc->enc_value=0L; 729 enc->enc_value=0L;
712 free(t); 730 free(t);
713 } 731 }
714 } 732 }
715 if (which->bd_description) { 733 if (which->bd_description) {
716 target_part.setDescription(QString(which->bd_description)); 734 target_part.setDescription(QString(which->bd_description));
717 } 735 }
718 target_part.setEncoding(encoding); 736 target_part.setEncoding(encoding);
719 target_part.setSize(which->bd_size); 737 target_part.setSize(which->bd_size);
720} 738}
721 739
722void IMAPwrapper::deleteMail(const RecMail&mail) 740void IMAPwrapper::deleteMail(const RecMail&mail)
723{ 741{
724 mailimap_flag_list*flist; 742 mailimap_flag_list*flist;
725 mailimap_set *set; 743 mailimap_set *set;
726 mailimap_store_att_flags * store_flags; 744 mailimap_store_att_flags * store_flags;
727 int err; 745 int err;
728 login(); 746 login();
729 if (!m_imap) { 747 if (!m_imap) {
730 return; 748 return;
731 } 749 }
732 const char *mb = mail.getMbox().latin1(); 750 const char *mb = mail.getMbox().latin1();
733 err = mailimap_select( m_imap, (char*)mb); 751 err = mailimap_select( m_imap, (char*)mb);
734 if ( err != MAILIMAP_NO_ERROR ) { 752 if ( err != MAILIMAP_NO_ERROR ) {
735 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); 753 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
736 return; 754 return;
737 } 755 }
738 flist = mailimap_flag_list_new_empty(); 756 flist = mailimap_flag_list_new_empty();
739 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 757 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
740 store_flags = mailimap_store_att_flags_new_set_flags(flist); 758 store_flags = mailimap_store_att_flags_new_set_flags(flist);
741 set = mailimap_set_new_single(mail.getNumber()); 759 set = mailimap_set_new_single(mail.getNumber());
742 err = mailimap_store(m_imap,set,store_flags); 760 err = mailimap_store(m_imap,set,store_flags);
743 mailimap_set_free( set ); 761 mailimap_set_free( set );
744 mailimap_store_att_flags_free(store_flags); 762 mailimap_store_att_flags_free(store_flags);
745 763
746 if (err != MAILIMAP_NO_ERROR) { 764 if (err != MAILIMAP_NO_ERROR) {
747 qDebug("error deleting mail: %s",m_imap->imap_response); 765 qDebug("error deleting mail: %s",m_imap->imap_response);
748 return; 766 return;
749 } 767 }
750 qDebug("deleting mail: %s",m_imap->imap_response); 768 qDebug("deleting mail: %s",m_imap->imap_response);
751 /* should we realy do that at this moment? */ 769 /* should we realy do that at this moment? */
752 err = mailimap_expunge(m_imap); 770 err = mailimap_expunge(m_imap);
753 if (err != MAILIMAP_NO_ERROR) { 771 if (err != MAILIMAP_NO_ERROR) {
754 qDebug("error deleting mail: %s",m_imap->imap_response); 772 qDebug("error deleting mail: %s",m_imap->imap_response);
755 } 773 }
756 qDebug("Delete successfull %s",m_imap->imap_response); 774 qDebug("Delete successfull %s",m_imap->imap_response);
757} 775}
758 776
759void IMAPwrapper::answeredMail(const RecMail&mail) 777void IMAPwrapper::answeredMail(const RecMail&mail)
760{ 778{
761 mailimap_flag_list*flist; 779 mailimap_flag_list*flist;
762 mailimap_set *set; 780 mailimap_set *set;
763 mailimap_store_att_flags * store_flags; 781 mailimap_store_att_flags * store_flags;
764 int err; 782 int err;
765 login(); 783 login();
766 if (!m_imap) { 784 if (!m_imap) {
767 return; 785 return;
768 } 786 }
769 const char *mb = mail.getMbox().latin1(); 787 const char *mb = mail.getMbox().latin1();
770 err = mailimap_select( m_imap, (char*)mb); 788 err = mailimap_select( m_imap, (char*)mb);
771 if ( err != MAILIMAP_NO_ERROR ) { 789 if ( err != MAILIMAP_NO_ERROR ) {
772 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); 790 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response);
773 return; 791 return;
774 } 792 }
775 flist = mailimap_flag_list_new_empty(); 793 flist = mailimap_flag_list_new_empty();
776 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 794 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
777 store_flags = mailimap_store_att_flags_new_add_flags(flist); 795 store_flags = mailimap_store_att_flags_new_add_flags(flist);
778 set = mailimap_set_new_single(mail.getNumber()); 796 set = mailimap_set_new_single(mail.getNumber());
779 err = mailimap_store(m_imap,set,store_flags); 797 err = mailimap_store(m_imap,set,store_flags);
780 mailimap_set_free( set ); 798 mailimap_set_free( set );
781 mailimap_store_att_flags_free(store_flags); 799 mailimap_store_att_flags_free(store_flags);
782 800
783 if (err != MAILIMAP_NO_ERROR) { 801 if (err != MAILIMAP_NO_ERROR) {
784 qDebug("error marking mail: %s",m_imap->imap_response); 802 qDebug("error marking mail: %s",m_imap->imap_response);
785 return; 803 return;
786 } 804 }
787} 805}
788 806
789QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 807QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
790{ 808{
791 QString body(""); 809 QString body("");
792 encodedString*res = fetchRawPart(mail,path,internal_call); 810 encodedString*res = fetchRawPart(mail,path,internal_call);
793 encodedString*r = decode_String(res,enc); 811 encodedString*r = decode_String(res,enc);
794 delete res; 812 delete res;
795 if (r) { 813 if (r) {
796 if (r->Length()>0) { 814 if (r->Length()>0) {
797 body = r->Content(); 815 body = r->Content();
798 } 816 }
799 delete r; 817 delete r;
800 } 818 }
801 return body; 819 return body;
802} 820}
803 821
804QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 822QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
805{ 823{
806 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); 824 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
807} 825}
808 826
809encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) 827encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
810{ 828{
811 encodedString*res = fetchRawPart(mail,part.Positionlist(),false); 829 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
812 encodedString*r = decode_String(res,part.Encoding()); 830 encodedString*r = decode_String(res,part.Encoding());
813 delete res; 831 delete res;
814 return r; 832 return r;
815} 833}
816 834
817encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 835encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
818{ 836{
819 return fetchRawPart(mail,part.Positionlist(),false); 837 return fetchRawPart(mail,part.Positionlist(),false);
820} 838}
839
840int IMAPwrapper::deleteAllMail(const Folder*folder)
841{
842 login();
843 if (!m_imap) {
844 return 0;
845 }
846 mailimap_flag_list*flist;
847 mailimap_set *set;
848 mailimap_store_att_flags * store_flags;
849 int err = mailimap_select( m_imap, folder->getName().latin1());
850 if ( err != MAILIMAP_NO_ERROR ) {
851 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response));
852 return 0;
853 }
854 int last = m_imap->imap_selection_info->sel_exists;
855 if (last == 0) {
856 Global::statusMessage(tr("Mailbox has no mails!"));
857 return 0;
858 }
859 flist = mailimap_flag_list_new_empty();
860 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
861 store_flags = mailimap_store_att_flags_new_set_flags(flist);
862 set = mailimap_set_new_interval( 1, last );
863 err = mailimap_store(m_imap,set,store_flags);
864 mailimap_set_free( set );
865 mailimap_store_att_flags_free(store_flags);
866 if (err != MAILIMAP_NO_ERROR) {
867 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
868 return 0;
869 }
870 qDebug("deleting mail: %s",m_imap->imap_response);
871 /* should we realy do that at this moment? */
872 err = mailimap_expunge(m_imap);
873 if (err != MAILIMAP_NO_ERROR) {
874 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
875 return 0;
876 }
877 qDebug("Delete successfull %s",m_imap->imap_response);
878 return 1;
879}
880
881int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder)
882{
883 if (folder.length()==0) return 0;
884 login();
885 if (!m_imap) {return 0;}
886 QString pre = account->getPrefix();
887 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
888 pre+=delemiter;
889 }
890 if (parentfolder) {
891 pre += parentfolder->getDisplayName()+delemiter;
892 }
893 pre+=folder;
894 if (getsubfolder) {
895 if (delemiter.length()>0) {
896 pre+=delemiter;
897 } else {
898 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre));
899 return 0;
900 }
901 }
902 qDebug("Creating %s",pre.latin1());
903 int res = mailimap_create(m_imap,pre.latin1());
904 if (res != MAILIMAP_NO_ERROR) {
905 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
906 return 0;
907 }
908 return 1;
909}
910
911int IMAPwrapper::deleteMbox(const Folder*folder)
912{
913 if (!folder) return 0;
914 login();
915 if (!m_imap) {return 0;}
916 int res = mailimap_delete(m_imap,folder->getName());
917 if (res != MAILIMAP_NO_ERROR) {
918 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
919 return 0;
920 }
921 return 1;
922}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index f046297..9b20288 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -1,63 +1,67 @@
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_type_1part; 10struct mailimap_body_type_1part;
11struct mailimap_body_type_text; 11struct mailimap_body_type_text;
12struct mailimap_body_type_basic; 12struct mailimap_body_type_basic;
13struct mailimap_body_type_msg; 13struct mailimap_body_type_msg;
14struct mailimap_body_type_mpart; 14struct mailimap_body_type_mpart;
15struct mailimap_body_fields; 15struct mailimap_body_fields;
16struct mailimap_msg_att; 16struct mailimap_msg_att;
17class encodedString; 17class encodedString;
18 18
19class IMAPwrapper : public AbstractMail 19class IMAPwrapper : public AbstractMail
20{ 20{
21 Q_OBJECT 21 Q_OBJECT
22public: 22public:
23 IMAPwrapper( IMAPaccount *a ); 23 IMAPwrapper( IMAPaccount *a );
24 virtual ~IMAPwrapper(); 24 virtual ~IMAPwrapper();
25 virtual QList<Folder>* listFolders(); 25 virtual QList<Folder>* listFolders();
26 virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); 26 virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
27 27
28 virtual void deleteMail(const RecMail&mail); 28 virtual void deleteMail(const RecMail&mail);
29 virtual void answeredMail(const RecMail&mail); 29 virtual void answeredMail(const RecMail&mail);
30 virtual int deleteAllMail(const Folder*folder);
30 31
31 virtual RecBody fetchBody(const RecMail&mail); 32 virtual RecBody fetchBody(const RecMail&mail);
32 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 33 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
33 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 34 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
34 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 35 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
35 36
37 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
38 virtual int deleteMbox(const Folder*folder);
39
36 static void imap_progress( size_t current, size_t maximum ); 40 static void imap_progress( size_t current, size_t maximum );
37 41
38protected: 42protected:
39 RecMail*parse_list_result(mailimap_msg_att*); 43 RecMail*parse_list_result(mailimap_msg_att*);
40 void login(); 44 void login();
41 void logout(); 45 void logout();
42 46
43 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); 47 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
44 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); 48 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call);
45 49
46 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); 50 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
47 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); 51 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>());
48 52
49 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 53 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
50 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 54 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
51 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 55 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
52 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); 56 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
53 57
54 /* just helpers */ 58 /* just helpers */
55 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 59 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
56 static QStringList address_list_to_stringlist(clist*list); 60 static QStringList address_list_to_stringlist(clist*list);
57 61
58 62
59 IMAPaccount *account; 63 IMAPaccount *account;
60 mailimap *m_imap; 64 mailimap *m_imap;
61}; 65};
62 66
63#endif 67#endif
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
index 6479783..9398823 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
@@ -1,137 +1,137 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <sys/stat.h> 2#include <sys/stat.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <fcntl.h> 5#include <fcntl.h>
6#include <string.h> 6#include <string.h>
7#include <qdir.h> 7#include <qdir.h>
8 8
9#include "mailwrapper.h" 9#include "mailwrapper.h"
10#include "logindialog.h" 10#include "logindialog.h"
11#include "defines.h" 11#include "defines.h"
12 12
13Attachment::Attachment( DocLnk lnk ) 13Attachment::Attachment( DocLnk lnk )
14{ 14{
15 doc = lnk; 15 doc = lnk;
16 size = QFileInfo( doc.file() ).size(); 16 size = QFileInfo( doc.file() ).size();
17} 17}
18 18
19Folder::Folder(const QString&tmp_name, const QString&sep ) 19Folder::Folder(const QString&tmp_name, const QString&sep )
20{ 20{
21 name = tmp_name; 21 name = tmp_name;
22 nameDisplay = name; 22 nameDisplay = name;
23 separator = sep; 23 separator = sep;
24} 24}
25 25
26const QString& Folder::Separator()const 26const QString& Folder::Separator()const
27{ 27{
28 return separator; 28 return separator;
29} 29}
30 30
31IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix ) 31IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&prefix )
32 : Folder( name,sep ),m_MaySelect(select) 32 : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf)
33{ 33{
34 // Decode IMAP foldername 34 // Decode IMAP foldername
35 nameDisplay = IMAPFolder::decodeFolderName( name ); 35 nameDisplay = IMAPFolder::decodeFolderName( name );
36 qDebug( "folder " + name + " - displayed as " + nameDisplay ); 36 qDebug( "folder " + name + " - displayed as " + nameDisplay );
37 37
38 if (prefix.length()>0) { 38 if (prefix.length()>0) {
39 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { 39 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) {
40 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); 40 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length());
41 } 41 }
42 } 42 }
43} 43}
44 44
45static unsigned char base64chars[] = 45static unsigned char base64chars[] =
46 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; 46 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
47 47
48/** 48/**
49 * Decodes base64 encoded parts of the imapfolder name 49 * Decodes base64 encoded parts of the imapfolder name
50 * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc 50 * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc
51 */ 51 */
52QString IMAPFolder::decodeFolderName( const QString &name ) 52QString IMAPFolder::decodeFolderName( const QString &name )
53{ 53{
54 unsigned char c, i, bitcount; 54 unsigned char c, i, bitcount;
55 unsigned long ucs4, utf16, bitbuf; 55 unsigned long ucs4, utf16, bitbuf;
56 unsigned char base64[256], utf8[6]; 56 unsigned char base64[256], utf8[6];
57 unsigned long srcPtr = 0; 57 unsigned long srcPtr = 0;
58 QCString dst = ""; 58 QCString dst = "";
59 QCString src = name.ascii(); 59 QCString src = name.ascii();
60 60
61 /* initialize modified base64 decoding table */ 61 /* initialize modified base64 decoding table */
62 memset(base64, UNDEFINED, sizeof(base64)); 62 memset(base64, UNDEFINED, sizeof(base64));
63 for (i = 0; i < sizeof(base64chars); ++i) { 63 for (i = 0; i < sizeof(base64chars); ++i) {
64 base64[(int)base64chars[i]] = i; 64 base64[(int)base64chars[i]] = i;
65 } 65 }
66 66
67 /* loop until end of string */ 67 /* loop until end of string */
68 while (srcPtr < src.length ()) { 68 while (srcPtr < src.length ()) {
69 c = src[srcPtr++]; 69 c = src[srcPtr++];
70 /* deal with literal characters and &- */ 70 /* deal with literal characters and &- */
71 if (c != '&' || src[srcPtr] == '-') { 71 if (c != '&' || src[srcPtr] == '-') {
72 /* encode literally */ 72 /* encode literally */
73 dst += c; 73 dst += c;
74 /* skip over the '-' if this is an &- sequence */ 74 /* skip over the '-' if this is an &- sequence */
75 if (c == '&') 75 if (c == '&')
76 srcPtr++; 76 srcPtr++;
77 } else { 77 } else {
78 /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */ 78 /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */
79 bitbuf = 0; 79 bitbuf = 0;
80 bitcount = 0; 80 bitcount = 0;
81 ucs4 = 0; 81 ucs4 = 0;
82 while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) { 82 while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) {
83 ++srcPtr; 83 ++srcPtr;
84 bitbuf = (bitbuf << 6) | c; 84 bitbuf = (bitbuf << 6) | c;
85 bitcount += 6; 85 bitcount += 6;
86 /* enough bits for a UTF-16 character? */ 86 /* enough bits for a UTF-16 character? */
87 if (bitcount >= 16) { 87 if (bitcount >= 16) {
88 bitcount -= 16; 88 bitcount -= 16;
89 utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; 89 utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff;
90 /* convert UTF16 to UCS4 */ 90 /* convert UTF16 to UCS4 */
91 if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { 91 if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) {
92 ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; 92 ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT;
93 continue; 93 continue;
94 } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { 94 } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) {
95 ucs4 += utf16 - UTF16LOSTART + UTF16BASE; 95 ucs4 += utf16 - UTF16LOSTART + UTF16BASE;
96 } else { 96 } else {
97 ucs4 = utf16; 97 ucs4 = utf16;
98 } 98 }
99 /* convert UTF-16 range of UCS4 to UTF-8 */ 99 /* convert UTF-16 range of UCS4 to UTF-8 */
100 if (ucs4 <= 0x7fUL) { 100 if (ucs4 <= 0x7fUL) {
101 utf8[0] = ucs4; 101 utf8[0] = ucs4;
102 i = 1; 102 i = 1;
103 } else if (ucs4 <= 0x7ffUL) { 103 } else if (ucs4 <= 0x7ffUL) {
104 utf8[0] = 0xc0 | (ucs4 >> 6); 104 utf8[0] = 0xc0 | (ucs4 >> 6);
105 utf8[1] = 0x80 | (ucs4 & 0x3f); 105 utf8[1] = 0x80 | (ucs4 & 0x3f);
106 i = 2; 106 i = 2;
107 } else if (ucs4 <= 0xffffUL) { 107 } else if (ucs4 <= 0xffffUL) {
108 utf8[0] = 0xe0 | (ucs4 >> 12); 108 utf8[0] = 0xe0 | (ucs4 >> 12);
109 utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f); 109 utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f);
110 utf8[2] = 0x80 | (ucs4 & 0x3f); 110 utf8[2] = 0x80 | (ucs4 & 0x3f);
111 i = 3; 111 i = 3;
112 } else { 112 } else {
113 utf8[0] = 0xf0 | (ucs4 >> 18); 113 utf8[0] = 0xf0 | (ucs4 >> 18);
114 utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f); 114 utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f);
115 utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f); 115 utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f);
116 utf8[3] = 0x80 | (ucs4 & 0x3f); 116 utf8[3] = 0x80 | (ucs4 & 0x3f);
117 i = 4; 117 i = 4;
118 } 118 }
119 /* copy it */ 119 /* copy it */
120 for (c = 0; c < i; ++c) { 120 for (c = 0; c < i; ++c) {
121 dst += utf8[c]; 121 dst += utf8[c];
122 } 122 }
123 } 123 }
124 } 124 }
125 /* skip over trailing '-' in modified UTF-7 encoding */ 125 /* skip over trailing '-' in modified UTF-7 encoding */
126 if (src[srcPtr] == '-') 126 if (src[srcPtr] == '-')
127 ++srcPtr; 127 ++srcPtr;
128 } 128 }
129 } 129 }
130 130
131 return QString::fromUtf8( dst.data() ); 131 return QString::fromUtf8( dst.data() );
132} 132}
133 133
134Mail::Mail() 134Mail::Mail()
135 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") 135 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("")
136{ 136{
137} 137}
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h
index 8fd886f..a60777d 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.h
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.h
@@ -1,91 +1,92 @@
1#ifndef MAILWRAPPER_H 1#ifndef MAILWRAPPER_H
2#define MAILWRAPPER_H 2#define MAILWRAPPER_H
3 3
4#include <qpe/applnk.h> 4#include <qpe/applnk.h>
5 5
6#include <qbitarray.h> 6#include <qbitarray.h>
7#include <qdatetime.h> 7#include <qdatetime.h>
8 8
9#include "settings.h" 9#include "settings.h"
10 10
11class Attachment 11class Attachment
12{ 12{
13public: 13public:
14 Attachment( DocLnk lnk ); 14 Attachment( DocLnk lnk );
15 virtual ~Attachment(){} 15 virtual ~Attachment(){}
16 const QString getFileName()const{ return doc.file(); } 16 const QString getFileName()const{ return doc.file(); }
17 const QString getName()const{ return doc.name(); } 17 const QString getName()const{ return doc.name(); }
18 const QString getMimeType()const{ return doc.type(); } 18 const QString getMimeType()const{ return doc.type(); }
19 const QPixmap getPixmap()const{ return doc.pixmap(); } 19 const QPixmap getPixmap()const{ return doc.pixmap(); }
20 const int getSize()const { return size; } 20 const int getSize()const { return size; }
21 DocLnk getDocLnk() { return doc; } 21 DocLnk getDocLnk() { return doc; }
22 22
23protected: 23protected:
24 DocLnk doc; 24 DocLnk doc;
25 int size; 25 int size;
26 26
27}; 27};
28 28
29class Mail 29class Mail
30{ 30{
31public: 31public:
32 Mail(); 32 Mail();
33 /* Possible that this destructor must not be declared virtual 33 /* Possible that this destructor must not be declared virtual
34 * 'cause it seems that it will never have some child classes. 34 * 'cause it seems that it will never have some child classes.
35 * in this case this object will not get a virtual table -> memory and 35 * in this case this object will not get a virtual table -> memory and
36 * speed will be a little bit better? 36 * speed will be a little bit better?
37 */ 37 */
38 virtual ~Mail(){} 38 virtual ~Mail(){}
39 void addAttachment( Attachment *att ) { attList.append( att ); } 39 void addAttachment( Attachment *att ) { attList.append( att ); }
40 const QList<Attachment>& getAttachments()const { return attList; } 40 const QList<Attachment>& getAttachments()const { return attList; }
41 void removeAttachment( Attachment *att ) { attList.remove( att ); } 41 void removeAttachment( Attachment *att ) { attList.remove( att ); }
42 const QString&getName()const { return name; } 42 const QString&getName()const { return name; }
43 void setName( QString s ) { name = s; } 43 void setName( QString s ) { name = s; }
44 const QString&getMail()const{ return mail; } 44 const QString&getMail()const{ return mail; }
45 void setMail( const QString&s ) { mail = s; } 45 void setMail( const QString&s ) { mail = s; }
46 const QString&getTo()const{ return to; } 46 const QString&getTo()const{ return to; }
47 void setTo( const QString&s ) { to = s; } 47 void setTo( const QString&s ) { to = s; }
48 const QString&getCC()const{ return cc; } 48 const QString&getCC()const{ return cc; }
49 void setCC( const QString&s ) { cc = s; } 49 void setCC( const QString&s ) { cc = s; }
50 const QString&getBCC()const { return bcc; } 50 const QString&getBCC()const { return bcc; }
51 void setBCC( const QString&s ) { bcc = s; } 51 void setBCC( const QString&s ) { bcc = s; }
52 const QString&getMessage()const { return message; } 52 const QString&getMessage()const { return message; }
53 void setMessage( const QString&s ) { message = s; } 53 void setMessage( const QString&s ) { message = s; }
54 const QString&getSubject()const { return subject; } 54 const QString&getSubject()const { return subject; }
55 void setSubject( const QString&s ) { subject = s; } 55 void setSubject( const QString&s ) { subject = s; }
56 const QString&getReply()const{ return reply; } 56 const QString&getReply()const{ return reply; }
57 void setReply( const QString&a ) { reply = a; } 57 void setReply( const QString&a ) { reply = a; }
58 58
59private: 59private:
60 QList<Attachment> attList; 60 QList<Attachment> attList;
61 QString name, mail, to, cc, bcc, reply, subject, message; 61 QString name, mail, to, cc, bcc, reply, subject, message;
62}; 62};
63 63
64class Folder : public QObject 64class Folder : public QObject
65{ 65{
66 Q_OBJECT 66 Q_OBJECT
67 67
68public: 68public:
69 Folder( const QString&init_name,const QString&sep ); 69 Folder( const QString&init_name,const QString&sep );
70 const QString&getDisplayName()const { return nameDisplay; } 70 const QString&getDisplayName()const { return nameDisplay; }
71 const QString&getName()const { return name; } 71 const QString&getName()const { return name; }
72 virtual bool may_select()const{return true;}; 72 virtual bool may_select()const{return true;}
73 virtual bool no_inferior()const{return true;}
73 const QString&Separator()const; 74 const QString&Separator()const;
74 75
75protected: 76protected:
76 QString nameDisplay, name, separator; 77 QString nameDisplay, name, separator;
77 78
78}; 79};
79 80
80class IMAPFolder : public Folder 81class IMAPFolder : public Folder
81{ 82{
82 public: 83 public:
83 IMAPFolder(const QString&name, const QString&sep, bool select=true,const QString&prefix="" ); 84 IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" );
84 virtual bool may_select()const{return m_MaySelect;} 85 virtual bool may_select()const{return m_MaySelect;}
86 virtual bool no_inferior()const{return m_NoInferior;}
85 private: 87 private:
86 static QString decodeFolderName( const QString &name ); 88 static QString decodeFolderName( const QString &name );
87 bool m_MaySelect; 89 bool m_MaySelect,m_NoInferior;
88
89}; 90};
90 91
91#endif 92#endif
diff --git a/noncore/net/mail/mail.pro b/noncore/net/mail/mail.pro
index ea5fb58..2c15a7b 100644
--- a/noncore/net/mail/mail.pro
+++ b/noncore/net/mail/mail.pro
@@ -1,73 +1,76 @@
1CONFIG += qt warn_on debug quick-app 1CONFIG += qt warn_on debug quick-app
2 2
3HEADERS = defines.h \ 3HEADERS = defines.h \
4 logindialog.h \ 4 logindialog.h \
5 settings.h \ 5 settings.h \
6 editaccounts.h \ 6 editaccounts.h \
7 mailwrapper.h \ 7 mailwrapper.h \
8 composemail.h \ 8 composemail.h \
9 accountview.h \ 9 accountview.h \
10 mainwindow.h \ 10 mainwindow.h \
11 viewmail.h \ 11 viewmail.h \
12 viewmailbase.h \ 12 viewmailbase.h \
13 opiemail.h \ 13 opiemail.h \
14 imapwrapper.h \ 14 imapwrapper.h \
15 mailtypes.h \ 15 mailtypes.h \
16 mailistviewitem.h \ 16 mailistviewitem.h \
17 pop3wrapper.h \ 17 pop3wrapper.h \
18 abstractmail.h \ 18 abstractmail.h \
19 settingsdialog.h \ 19 settingsdialog.h \
20 statuswidget.h \ 20 statuswidget.h \
21 smtpwrapper.h \ 21 smtpwrapper.h \
22 genericwrapper.h \ 22 genericwrapper.h \
23 mboxwrapper.h \ 23 mboxwrapper.h \
24 sendmailprogress.h 24 sendmailprogress.h \
25 newmaildir.h
25 26
26SOURCES = main.cpp \ 27SOURCES = main.cpp \
27 opiemail.cpp \ 28 opiemail.cpp \
28 mainwindow.cpp \ 29 mainwindow.cpp \
29 accountview.cpp \ 30 accountview.cpp \
30 composemail.cpp \ 31 composemail.cpp \
31 mailwrapper.cpp \ 32 mailwrapper.cpp \
32 imapwrapper.cpp \ 33 imapwrapper.cpp \
33 addresspicker.cpp \ 34 addresspicker.cpp \
34 editaccounts.cpp \ 35 editaccounts.cpp \
35 logindialog.cpp \ 36 logindialog.cpp \
36 viewmail.cpp \ 37 viewmail.cpp \
37 viewmailbase.cpp \ 38 viewmailbase.cpp \
38 settings.cpp \ 39 settings.cpp \
39 mailtypes.cpp \ 40 mailtypes.cpp \
40 pop3wrapper.cpp \ 41 pop3wrapper.cpp \
41 abstractmail.cpp \ 42 abstractmail.cpp \
42 settingsdialog.cpp \ 43 settingsdialog.cpp \
43 statuswidget.cpp \ 44 statuswidget.cpp \
44 smtpwrapper.cpp \ 45 smtpwrapper.cpp \
45 genericwrapper.cpp \ 46 genericwrapper.cpp \
46 mboxwrapper.cpp \ 47 mboxwrapper.cpp \
47 sendmailprogress.cpp 48 sendmailprogress.cpp \
49 newmaildir.cpp
48 50
49INTERFACES = editaccountsui.ui \ 51INTERFACES = editaccountsui.ui \
50 selectmailtypeui.ui \ 52 selectmailtypeui.ui \
51 imapconfigui.ui \ 53 imapconfigui.ui \
52 pop3configui.ui \ 54 pop3configui.ui \
53 nntpconfigui.ui \ 55 nntpconfigui.ui \
54 smtpconfigui.ui \ 56 smtpconfigui.ui \
55 addresspickerui.ui \ 57 addresspickerui.ui \
56 logindialogui.ui \ 58 logindialogui.ui \
57 composemailui.ui \ 59 composemailui.ui \
58 settingsdialogui.ui \ 60 settingsdialogui.ui \
59 statuswidgetui.ui \ 61 statuswidgetui.ui \
60 sendmailprogressui.ui 62 sendmailprogressui.ui \
63 newmaildirui.ui
61 64
62INCLUDEPATH += $(OPIEDIR)/include 65INCLUDEPATH += $(OPIEDIR)/include
63 66
64CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX ) 67CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX )
65contains( CONFTEST, y ){ 68contains( CONFTEST, y ){
66 LIBS += -lqpe -letpan -lssl -lcrypto -lopie -liconv 69 LIBS += -lqpe -letpan -lssl -lcrypto -lopie -liconv
67}else{ 70}else{
68 LIBS += -lqpe -letpan -lssl -lcrypto -lopie 71 LIBS += -lqpe -letpan -lssl -lcrypto -lopie
69} 72}
70 73
71TARGET = opiemail 74TARGET = opiemail
72 75
73include ( $(OPIEDIR)/include.pro ) 76include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/net/mail/mailwrapper.cpp b/noncore/net/mail/mailwrapper.cpp
index 6479783..9398823 100644
--- a/noncore/net/mail/mailwrapper.cpp
+++ b/noncore/net/mail/mailwrapper.cpp
@@ -1,137 +1,137 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <sys/stat.h> 2#include <sys/stat.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <fcntl.h> 5#include <fcntl.h>
6#include <string.h> 6#include <string.h>
7#include <qdir.h> 7#include <qdir.h>
8 8
9#include "mailwrapper.h" 9#include "mailwrapper.h"
10#include "logindialog.h" 10#include "logindialog.h"
11#include "defines.h" 11#include "defines.h"
12 12
13Attachment::Attachment( DocLnk lnk ) 13Attachment::Attachment( DocLnk lnk )
14{ 14{
15 doc = lnk; 15 doc = lnk;
16 size = QFileInfo( doc.file() ).size(); 16 size = QFileInfo( doc.file() ).size();
17} 17}
18 18
19Folder::Folder(const QString&tmp_name, const QString&sep ) 19Folder::Folder(const QString&tmp_name, const QString&sep )
20{ 20{
21 name = tmp_name; 21 name = tmp_name;
22 nameDisplay = name; 22 nameDisplay = name;
23 separator = sep; 23 separator = sep;
24} 24}
25 25
26const QString& Folder::Separator()const 26const QString& Folder::Separator()const
27{ 27{
28 return separator; 28 return separator;
29} 29}
30 30
31IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix ) 31IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&prefix )
32 : Folder( name,sep ),m_MaySelect(select) 32 : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf)
33{ 33{
34 // Decode IMAP foldername 34 // Decode IMAP foldername
35 nameDisplay = IMAPFolder::decodeFolderName( name ); 35 nameDisplay = IMAPFolder::decodeFolderName( name );
36 qDebug( "folder " + name + " - displayed as " + nameDisplay ); 36 qDebug( "folder " + name + " - displayed as " + nameDisplay );
37 37
38 if (prefix.length()>0) { 38 if (prefix.length()>0) {
39 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { 39 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) {
40 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); 40 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length());
41 } 41 }
42 } 42 }
43} 43}
44 44
45static unsigned char base64chars[] = 45static unsigned char base64chars[] =
46 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; 46 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
47 47
48/** 48/**
49 * Decodes base64 encoded parts of the imapfolder name 49 * Decodes base64 encoded parts of the imapfolder name
50 * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc 50 * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc
51 */ 51 */
52QString IMAPFolder::decodeFolderName( const QString &name ) 52QString IMAPFolder::decodeFolderName( const QString &name )
53{ 53{
54 unsigned char c, i, bitcount; 54 unsigned char c, i, bitcount;
55 unsigned long ucs4, utf16, bitbuf; 55 unsigned long ucs4, utf16, bitbuf;
56 unsigned char base64[256], utf8[6]; 56 unsigned char base64[256], utf8[6];
57 unsigned long srcPtr = 0; 57 unsigned long srcPtr = 0;
58 QCString dst = ""; 58 QCString dst = "";
59 QCString src = name.ascii(); 59 QCString src = name.ascii();
60 60
61 /* initialize modified base64 decoding table */ 61 /* initialize modified base64 decoding table */
62 memset(base64, UNDEFINED, sizeof(base64)); 62 memset(base64, UNDEFINED, sizeof(base64));
63 for (i = 0; i < sizeof(base64chars); ++i) { 63 for (i = 0; i < sizeof(base64chars); ++i) {
64 base64[(int)base64chars[i]] = i; 64 base64[(int)base64chars[i]] = i;
65 } 65 }
66 66
67 /* loop until end of string */ 67 /* loop until end of string */
68 while (srcPtr < src.length ()) { 68 while (srcPtr < src.length ()) {
69 c = src[srcPtr++]; 69 c = src[srcPtr++];
70 /* deal with literal characters and &- */ 70 /* deal with literal characters and &- */
71 if (c != '&' || src[srcPtr] == '-') { 71 if (c != '&' || src[srcPtr] == '-') {
72 /* encode literally */ 72 /* encode literally */
73 dst += c; 73 dst += c;
74 /* skip over the '-' if this is an &- sequence */ 74 /* skip over the '-' if this is an &- sequence */
75 if (c == '&') 75 if (c == '&')
76 srcPtr++; 76 srcPtr++;
77 } else { 77 } else {
78 /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */ 78 /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */
79 bitbuf = 0; 79 bitbuf = 0;
80 bitcount = 0; 80 bitcount = 0;
81 ucs4 = 0; 81 ucs4 = 0;
82 while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) { 82 while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) {
83 ++srcPtr; 83 ++srcPtr;
84 bitbuf = (bitbuf << 6) | c; 84 bitbuf = (bitbuf << 6) | c;
85 bitcount += 6; 85 bitcount += 6;
86 /* enough bits for a UTF-16 character? */ 86 /* enough bits for a UTF-16 character? */
87 if (bitcount >= 16) { 87 if (bitcount >= 16) {
88 bitcount -= 16; 88 bitcount -= 16;
89 utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; 89 utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff;
90 /* convert UTF16 to UCS4 */ 90 /* convert UTF16 to UCS4 */
91 if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { 91 if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) {
92 ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; 92 ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT;
93 continue; 93 continue;
94 } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { 94 } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) {
95 ucs4 += utf16 - UTF16LOSTART + UTF16BASE; 95 ucs4 += utf16 - UTF16LOSTART + UTF16BASE;
96 } else { 96 } else {
97 ucs4 = utf16; 97 ucs4 = utf16;
98 } 98 }
99 /* convert UTF-16 range of UCS4 to UTF-8 */ 99 /* convert UTF-16 range of UCS4 to UTF-8 */
100 if (ucs4 <= 0x7fUL) { 100 if (ucs4 <= 0x7fUL) {
101 utf8[0] = ucs4; 101 utf8[0] = ucs4;
102 i = 1; 102 i = 1;
103 } else if (ucs4 <= 0x7ffUL) { 103 } else if (ucs4 <= 0x7ffUL) {
104 utf8[0] = 0xc0 | (ucs4 >> 6); 104 utf8[0] = 0xc0 | (ucs4 >> 6);
105 utf8[1] = 0x80 | (ucs4 & 0x3f); 105 utf8[1] = 0x80 | (ucs4 & 0x3f);
106 i = 2; 106 i = 2;
107 } else if (ucs4 <= 0xffffUL) { 107 } else if (ucs4 <= 0xffffUL) {
108 utf8[0] = 0xe0 | (ucs4 >> 12); 108 utf8[0] = 0xe0 | (ucs4 >> 12);
109 utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f); 109 utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f);
110 utf8[2] = 0x80 | (ucs4 & 0x3f); 110 utf8[2] = 0x80 | (ucs4 & 0x3f);
111 i = 3; 111 i = 3;
112 } else { 112 } else {
113 utf8[0] = 0xf0 | (ucs4 >> 18); 113 utf8[0] = 0xf0 | (ucs4 >> 18);
114 utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f); 114 utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f);
115 utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f); 115 utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f);
116 utf8[3] = 0x80 | (ucs4 & 0x3f); 116 utf8[3] = 0x80 | (ucs4 & 0x3f);
117 i = 4; 117 i = 4;
118 } 118 }
119 /* copy it */ 119 /* copy it */
120 for (c = 0; c < i; ++c) { 120 for (c = 0; c < i; ++c) {
121 dst += utf8[c]; 121 dst += utf8[c];
122 } 122 }
123 } 123 }
124 } 124 }
125 /* skip over trailing '-' in modified UTF-7 encoding */ 125 /* skip over trailing '-' in modified UTF-7 encoding */
126 if (src[srcPtr] == '-') 126 if (src[srcPtr] == '-')
127 ++srcPtr; 127 ++srcPtr;
128 } 128 }
129 } 129 }
130 130
131 return QString::fromUtf8( dst.data() ); 131 return QString::fromUtf8( dst.data() );
132} 132}
133 133
134Mail::Mail() 134Mail::Mail()
135 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") 135 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("")
136{ 136{
137} 137}
diff --git a/noncore/net/mail/mailwrapper.h b/noncore/net/mail/mailwrapper.h
index 8fd886f..a60777d 100644
--- a/noncore/net/mail/mailwrapper.h
+++ b/noncore/net/mail/mailwrapper.h
@@ -1,91 +1,92 @@
1#ifndef MAILWRAPPER_H 1#ifndef MAILWRAPPER_H
2#define MAILWRAPPER_H 2#define MAILWRAPPER_H
3 3
4#include <qpe/applnk.h> 4#include <qpe/applnk.h>
5 5
6#include <qbitarray.h> 6#include <qbitarray.h>
7#include <qdatetime.h> 7#include <qdatetime.h>
8 8
9#include "settings.h" 9#include "settings.h"
10 10
11class Attachment 11class Attachment
12{ 12{
13public: 13public:
14 Attachment( DocLnk lnk ); 14 Attachment( DocLnk lnk );
15 virtual ~Attachment(){} 15 virtual ~Attachment(){}
16 const QString getFileName()const{ return doc.file(); } 16 const QString getFileName()const{ return doc.file(); }
17 const QString getName()const{ return doc.name(); } 17 const QString getName()const{ return doc.name(); }
18 const QString getMimeType()const{ return doc.type(); } 18 const QString getMimeType()const{ return doc.type(); }
19 const QPixmap getPixmap()const{ return doc.pixmap(); } 19 const QPixmap getPixmap()const{ return doc.pixmap(); }
20 const int getSize()const { return size; } 20 const int getSize()const { return size; }
21 DocLnk getDocLnk() { return doc; } 21 DocLnk getDocLnk() { return doc; }
22 22
23protected: 23protected:
24 DocLnk doc; 24 DocLnk doc;
25 int size; 25 int size;
26 26
27}; 27};
28 28
29class Mail 29class Mail
30{ 30{
31public: 31public:
32 Mail(); 32 Mail();
33 /* Possible that this destructor must not be declared virtual 33 /* Possible that this destructor must not be declared virtual
34 * 'cause it seems that it will never have some child classes. 34 * 'cause it seems that it will never have some child classes.
35 * in this case this object will not get a virtual table -> memory and 35 * in this case this object will not get a virtual table -> memory and
36 * speed will be a little bit better? 36 * speed will be a little bit better?
37 */ 37 */
38 virtual ~Mail(){} 38 virtual ~Mail(){}
39 void addAttachment( Attachment *att ) { attList.append( att ); } 39 void addAttachment( Attachment *att ) { attList.append( att ); }
40 const QList<Attachment>& getAttachments()const { return attList; } 40 const QList<Attachment>& getAttachments()const { return attList; }
41 void removeAttachment( Attachment *att ) { attList.remove( att ); } 41 void removeAttachment( Attachment *att ) { attList.remove( att ); }
42 const QString&getName()const { return name; } 42 const QString&getName()const { return name; }
43 void setName( QString s ) { name = s; } 43 void setName( QString s ) { name = s; }
44 const QString&getMail()const{ return mail; } 44 const QString&getMail()const{ return mail; }
45 void setMail( const QString&s ) { mail = s; } 45 void setMail( const QString&s ) { mail = s; }
46 const QString&getTo()const{ return to; } 46 const QString&getTo()const{ return to; }
47 void setTo( const QString&s ) { to = s; } 47 void setTo( const QString&s ) { to = s; }
48 const QString&getCC()const{ return cc; } 48 const QString&getCC()const{ return cc; }
49 void setCC( const QString&s ) { cc = s; } 49 void setCC( const QString&s ) { cc = s; }
50 const QString&getBCC()const { return bcc; } 50 const QString&getBCC()const { return bcc; }
51 void setBCC( const QString&s ) { bcc = s; } 51 void setBCC( const QString&s ) { bcc = s; }
52 const QString&getMessage()const { return message; } 52 const QString&getMessage()const { return message; }
53 void setMessage( const QString&s ) { message = s; } 53 void setMessage( const QString&s ) { message = s; }
54 const QString&getSubject()const { return subject; } 54 const QString&getSubject()const { return subject; }
55 void setSubject( const QString&s ) { subject = s; } 55 void setSubject( const QString&s ) { subject = s; }
56 const QString&getReply()const{ return reply; } 56 const QString&getReply()const{ return reply; }
57 void setReply( const QString&a ) { reply = a; } 57 void setReply( const QString&a ) { reply = a; }
58 58
59private: 59private:
60 QList<Attachment> attList; 60 QList<Attachment> attList;
61 QString name, mail, to, cc, bcc, reply, subject, message; 61 QString name, mail, to, cc, bcc, reply, subject, message;
62}; 62};
63 63
64class Folder : public QObject 64class Folder : public QObject
65{ 65{
66 Q_OBJECT 66 Q_OBJECT
67 67
68public: 68public:
69 Folder( const QString&init_name,const QString&sep ); 69 Folder( const QString&init_name,const QString&sep );
70 const QString&getDisplayName()const { return nameDisplay; } 70 const QString&getDisplayName()const { return nameDisplay; }
71 const QString&getName()const { return name; } 71 const QString&getName()const { return name; }
72 virtual bool may_select()const{return true;}; 72 virtual bool may_select()const{return true;}
73 virtual bool no_inferior()const{return true;}
73 const QString&Separator()const; 74 const QString&Separator()const;
74 75
75protected: 76protected:
76 QString nameDisplay, name, separator; 77 QString nameDisplay, name, separator;
77 78
78}; 79};
79 80
80class IMAPFolder : public Folder 81class IMAPFolder : public Folder
81{ 82{
82 public: 83 public:
83 IMAPFolder(const QString&name, const QString&sep, bool select=true,const QString&prefix="" ); 84 IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" );
84 virtual bool may_select()const{return m_MaySelect;} 85 virtual bool may_select()const{return m_MaySelect;}
86 virtual bool no_inferior()const{return m_NoInferior;}
85 private: 87 private:
86 static QString decodeFolderName( const QString &name ); 88 static QString decodeFolderName( const QString &name );
87 bool m_MaySelect; 89 bool m_MaySelect,m_NoInferior;
88
89}; 90};
90 91
91#endif 92#endif
diff --git a/noncore/net/mail/mainwindow.cpp b/noncore/net/mail/mainwindow.cpp
index dc8c188..cf4cbe8 100644
--- a/noncore/net/mail/mainwindow.cpp
+++ b/noncore/net/mail/mainwindow.cpp
@@ -1,309 +1,303 @@
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> 7#include <qtextstream.h>
8 8
9#include <qpe/qpeapplication.h> 9#include <qpe/qpeapplication.h>
10#include <qpe/resource.h> 10#include <qpe/resource.h>
11 11
12#include "defines.h" 12#include "defines.h"
13#include "mainwindow.h" 13#include "mainwindow.h"
14#include "settingsdialog.h" 14#include "settingsdialog.h"
15#include "viewmail.h" 15#include "viewmail.h"
16#include "mailtypes.h" 16#include "mailtypes.h"
17#include "mailistviewitem.h" 17#include "mailistviewitem.h"
18 18
19 19
20MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags ) 20MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags )
21 : QMainWindow( parent, name, flags ) 21 : QMainWindow( parent, name, flags )
22{ 22{
23 setCaption( tr( "Mail" ) ); 23 setCaption( tr( "Mail" ) );
24 setToolBarsMovable( false ); 24 setToolBarsMovable( false );
25 25
26 toolBar = new QToolBar( this ); 26 toolBar = new QToolBar( this );
27 menuBar = new QMenuBar( toolBar ); 27 menuBar = new QMenuBar( toolBar );
28 mailMenu = new QPopupMenu( menuBar ); 28 mailMenu = new QPopupMenu( menuBar );
29 menuBar->insertItem( tr( "Mail" ), mailMenu ); 29 menuBar->insertItem( tr( "Mail" ), mailMenu );
30 settingsMenu = new QPopupMenu( menuBar ); 30 settingsMenu = new QPopupMenu( menuBar );
31 menuBar->insertItem( tr( "Settings" ), settingsMenu ); 31 menuBar->insertItem( tr( "Settings" ), settingsMenu );
32 32
33 addToolBar( toolBar ); 33 addToolBar( toolBar );
34 toolBar->setHorizontalStretchable( true ); 34 toolBar->setHorizontalStretchable( true );
35 35
36 QLabel *spacer = new QLabel( toolBar ); 36 QLabel *spacer = new QLabel( toolBar );
37 spacer->setBackgroundMode( QWidget::PaletteButton ); 37 spacer->setBackgroundMode( QWidget::PaletteButton );
38 toolBar->setStretchableWidget( spacer ); 38 toolBar->setStretchableWidget( spacer );
39 39
40 composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL, 40 composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL,
41 0, 0, this ); 41 0, 0, this );
42 composeMail->addTo( toolBar ); 42 composeMail->addTo( toolBar );
43 composeMail->addTo( mailMenu ); 43 composeMail->addTo( mailMenu );
44 44
45 sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED, 45 sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED,
46 0, 0, this ); 46 0, 0, this );
47 sendQueued->addTo( toolBar ); 47 sendQueued->addTo( toolBar );
48 sendQueued->addTo( mailMenu ); 48 sendQueued->addTo( mailMenu );
49 49
50 /* 50 /*
51 syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC, 51 syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC,
52 0, 0, this ); 52 0, 0, this );
53 syncFolders->addTo( toolBar ); 53 syncFolders->addTo( toolBar );
54 syncFolders->addTo( mailMenu ); 54 syncFolders->addTo( mailMenu );
55 */ 55 */
56 56
57 showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS, 57 showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS,
58 0, 0, this, 0, true ); 58 0, 0, this, 0, true );
59 showFolders->addTo( toolBar ); 59 showFolders->addTo( toolBar );
60 showFolders->addTo( mailMenu ); 60 showFolders->addTo( mailMenu );
61 showFolders->setOn( true ); 61 showFolders->setOn( true );
62 connect(showFolders, SIGNAL( toggled( bool ) ), 62 connect(showFolders, SIGNAL( toggled( bool ) ),
63 SLOT( slotShowFolders( bool ) ) ); 63 SLOT( slotShowFolders( bool ) ) );
64 64
65 /* 65 /*
66 searchMails = new QAction( tr( "Search mails" ), ICON_SEARCHMAILS, 66 searchMails = new QAction( tr( "Search mails" ), ICON_SEARCHMAILS,
67 0, 0, this ); 67 0, 0, this );
68 searchMails->addTo( toolBar ); 68 searchMails->addTo( toolBar );
69 searchMails->addTo( mailMenu ); 69 searchMails->addTo( mailMenu );
70 */ 70 */
71 71
72 deleteMails = new QAction(tr("Delete Mail"), QIconSet(Resource::loadPixmap("mail/delete")), 0, 0, this); 72 deleteMails = new QAction(tr("Delete Mail"), QIconSet(Resource::loadPixmap("mail/delete")), 0, 0, this);
73 deleteMails->addTo( toolBar ); 73 deleteMails->addTo( toolBar );
74 deleteMails->addTo( mailMenu ); 74 deleteMails->addTo( mailMenu );
75 connect( deleteMails, SIGNAL( activated() ), 75 connect( deleteMails, SIGNAL( activated() ),
76 SLOT( slotDeleteMail() ) ); 76 SLOT( slotDeleteMail() ) );
77 77
78 editSettings = new QAction( tr( "Edit settings" ), ICON_EDITSETTINGS, 78 editSettings = new QAction( tr( "Edit settings" ), ICON_EDITSETTINGS,
79 0, 0, this ); 79 0, 0, this );
80 editSettings->addTo( settingsMenu ); 80 editSettings->addTo( settingsMenu );
81 connect( editSettings, SIGNAL( activated() ), 81 connect( editSettings, SIGNAL( activated() ),
82 SLOT( slotEditSettings() ) ); 82 SLOT( slotEditSettings() ) );
83 83
84 editAccounts = new QAction( tr( "Configure accounts" ), ICON_EDITACCOUNTS, 84 editAccounts = new QAction( tr( "Configure accounts" ), ICON_EDITACCOUNTS,
85 0, 0, this ); 85 0, 0, this );
86 editAccounts->addTo( settingsMenu ); 86 editAccounts->addTo( settingsMenu );
87 87
88 //setCentralWidget( view ); 88 //setCentralWidget( view );
89 89
90 QVBox* wrapperBox = new QVBox( this ); 90 QVBox* wrapperBox = new QVBox( this );
91 setCentralWidget( wrapperBox ); 91 setCentralWidget( wrapperBox );
92 92
93 QWidget *view = new QWidget( wrapperBox ); 93 QWidget *view = new QWidget( wrapperBox );
94 94
95 layout = new QBoxLayout ( view, QBoxLayout::LeftToRight ); 95 layout = new QBoxLayout ( view, QBoxLayout::LeftToRight );
96 96
97 folderView = new AccountView( view ); 97 folderView = new AccountView( view );
98 folderView->header()->hide(); 98 folderView->header()->hide();
99 folderView->setRootIsDecorated( true ); 99 folderView->setRootIsDecorated( true );
100 folderView->addColumn( tr( "Mailbox" ) ); 100 folderView->addColumn( tr( "Mailbox" ) );
101 101
102 layout->addWidget( folderView ); 102 layout->addWidget( folderView );
103 103
104 mailView = new QListView( view ); 104 mailView = new QListView( view );
105 mailView->addColumn( tr( "" ) ); 105 mailView->addColumn( tr( "" ) );
106 mailView->addColumn( tr( "Subject" ),QListView::Manual ); 106 mailView->addColumn( tr( "Subject" ),QListView::Manual );
107 mailView->addColumn( tr( "Sender" ),QListView::Manual ); 107 mailView->addColumn( tr( "Sender" ),QListView::Manual );
108 mailView->addColumn( tr( "Size" ),QListView::Manual); 108 mailView->addColumn( tr( "Size" ),QListView::Manual);
109 mailView->addColumn( tr( "Date" )); 109 mailView->addColumn( tr( "Date" ));
110 mailView->setAllColumnsShowFocus(true); 110 mailView->setAllColumnsShowFocus(true);
111 mailView->setSorting(-1); 111 mailView->setSorting(-1);
112 112
113 statusWidget = new StatusWidget( wrapperBox ); 113 statusWidget = new StatusWidget( wrapperBox );
114 statusWidget->hide(); 114 statusWidget->hide();
115 115
116 layout->addWidget( mailView ); 116 layout->addWidget( mailView );
117 layout->setStretchFactor( folderView, 1 ); 117 layout->setStretchFactor( folderView, 1 );
118 layout->setStretchFactor( mailView, 2 ); 118 layout->setStretchFactor( mailView, 2 );
119 119
120
121 slotAdjustLayout(); 120 slotAdjustLayout();
122 121
123 QPEApplication::setStylusOperation( mailView->viewport(),QPEApplication::RightOnHold); 122 QPEApplication::setStylusOperation( mailView->viewport(),QPEApplication::RightOnHold);
124 123 QPEApplication::setStylusOperation( folderView->viewport(),QPEApplication::RightOnHold);
124
125 connect( mailView, SIGNAL( mouseButtonClicked(int, QListViewItem *,const QPoint&,int ) ),this, 125 connect( mailView, SIGNAL( mouseButtonClicked(int, QListViewItem *,const QPoint&,int ) ),this,
126 SLOT( mailLeftClicked( int, QListViewItem *,const QPoint&,int ) ) ); 126 SLOT( mailLeftClicked( int, QListViewItem *,const QPoint&,int ) ) );
127
128 connect( mailView, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this, 127 connect( mailView, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this,
129 SLOT( mailHold( int, QListViewItem *,const QPoint&,int ) ) ); 128 SLOT( mailHold( int, QListViewItem *,const QPoint&,int ) ) );
130#if 0
131 connect( mailView, SIGNAL( rightButtonClicked( QListViewItem *,const QPoint&,int ) ),this,
132 SLOT( mailHold(QListViewItem *,const QPoint&,int) ));
133#endif
134 connect(folderView, SIGNAL(refreshMailview(QList<RecMail>*)),this,SLOT(refreshMailView(QList<RecMail>*))); 129 connect(folderView, SIGNAL(refreshMailview(QList<RecMail>*)),this,SLOT(refreshMailView(QList<RecMail>*)));
135 130
136 QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) ); 131 QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) );
137
138} 132}
139 133
140 134
141void MainWindow::slotAdjustLayout() { 135void MainWindow::slotAdjustLayout() {
142 136
143 QWidget *d = QApplication::desktop(); 137 QWidget *d = QApplication::desktop();
144 138
145 if ( d->width() < d->height() ) { 139 if ( d->width() < d->height() ) {
146 layout->setDirection( QBoxLayout::TopToBottom ); 140 layout->setDirection( QBoxLayout::TopToBottom );
147 } else { 141 } else {
148 layout->setDirection( QBoxLayout::LeftToRight ); 142 layout->setDirection( QBoxLayout::LeftToRight );
149 } 143 }
150} 144}
151 145
152void MainWindow::slotAdjustColumns() 146void MainWindow::slotAdjustColumns()
153{ 147{
154 bool hidden = folderView->isHidden(); 148 bool hidden = folderView->isHidden();
155 if ( hidden ) folderView->show(); 149 if ( hidden ) folderView->show();
156 folderView->setColumnWidth( 0, folderView->visibleWidth() ); 150 folderView->setColumnWidth( 0, folderView->visibleWidth() );
157 if ( hidden ) folderView->hide(); 151 if ( hidden ) folderView->hide();
158 152
159 mailView->setColumnWidth( 0, 10 ); 153 mailView->setColumnWidth( 0, 10 );
160 mailView->setColumnWidth( 1, mailView->visibleWidth() - 130 ); 154 mailView->setColumnWidth( 1, mailView->visibleWidth() - 130 );
161 mailView->setColumnWidth( 2, 80 ); 155 mailView->setColumnWidth( 2, 80 );
162 mailView->setColumnWidth( 3, 50 ); 156 mailView->setColumnWidth( 3, 50 );
163 mailView->setColumnWidth( 4, 50 ); 157 mailView->setColumnWidth( 4, 50 );
164} 158}
165 159
166void MainWindow::slotEditSettings() { 160void MainWindow::slotEditSettings() {
167 SettingsDialog settingsDialog( this, 0, true ); 161 SettingsDialog settingsDialog( this, 0, true );
168 settingsDialog.showMaximized(); 162 settingsDialog.showMaximized();
169 settingsDialog.exec(); 163 settingsDialog.exec();
170} 164}
171 165
172void MainWindow::slotShowFolders( bool show ) 166void MainWindow::slotShowFolders( bool show )
173{ 167{
174 qDebug( "Show Folders" ); 168 qDebug( "Show Folders" );
175 if ( show && folderView->isHidden() ) { 169 if ( show && folderView->isHidden() ) {
176 qDebug( "-> showing" ); 170 qDebug( "-> showing" );
177 folderView->show(); 171 folderView->show();
178 } else if ( !show && !folderView->isHidden() ) { 172 } else if ( !show && !folderView->isHidden() ) {
179 qDebug( "-> hiding" ); 173 qDebug( "-> hiding" );
180 folderView->hide(); 174 folderView->hide();
181 } 175 }
182} 176}
183 177
184void MainWindow::refreshMailView(QList<RecMail>*list) 178void MainWindow::refreshMailView(QList<RecMail>*list)
185{ 179{
186 MailListViewItem*item = 0; 180 MailListViewItem*item = 0;
187 mailView->clear(); 181 mailView->clear();
188 for (unsigned int i = 0; i < list->count();++i) { 182 for (unsigned int i = 0; i < list->count();++i) {
189 item = new MailListViewItem(mailView,item); 183 item = new MailListViewItem(mailView,item);
190 item->storeData(*(list->at(i))); 184 item->storeData(*(list->at(i)));
191 item->showEntry(); 185 item->showEntry();
192 } 186 }
193} 187}
194void MainWindow::mailLeftClicked(int button, QListViewItem *item,const QPoint&,int ) 188void MainWindow::mailLeftClicked(int button, QListViewItem *item,const QPoint&,int )
195{ 189{
196 /* just LEFT button - or tap with stylus on pda */ 190 /* just LEFT button - or tap with stylus on pda */
197 if (button!=1) return; 191 if (button!=1) return;
198 if (!item) return; 192 if (!item) return;
199 displayMail(); 193 displayMail();
200} 194}
201 195
202void MainWindow::displayMail() 196void MainWindow::displayMail()
203{ 197{
204 QListViewItem*item = mailView->currentItem(); 198 QListViewItem*item = mailView->currentItem();
205 if (!item) return; 199 if (!item) return;
206 RecMail mail = ((MailListViewItem*)item)->data(); 200 RecMail mail = ((MailListViewItem*)item)->data();
207 RecBody body = folderView->fetchBody(mail); 201 RecBody body = folderView->fetchBody(mail);
208 ViewMail readMail( this ); 202 ViewMail readMail( this );
209 readMail.setBody( body ); 203 readMail.setBody( body );
210 readMail.setMail( mail ); 204 readMail.setMail( mail );
211 readMail.showMaximized(); 205 readMail.showMaximized();
212 readMail.exec(); 206 readMail.exec();
213 207
214 if ( readMail.deleted ) { 208 if ( readMail.deleted ) {
215 folderView->refreshCurrent(); 209 folderView->refreshCurrent();
216 } else { 210 } else {
217 ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "") ); 211 ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "") );
218 } 212 }
219} 213}
220 214
221void MainWindow::slotDeleteMail() 215void MainWindow::slotDeleteMail()
222{ 216{
223 if (!mailView->currentItem()) return; 217 if (!mailView->currentItem()) return;
224 RecMail mail = ((MailListViewItem*)mailView->currentItem() )->data(); 218 RecMail mail = ((MailListViewItem*)mailView->currentItem() )->data();
225 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 ) { 219 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 ) {
226 mail.Wrapper()->deleteMail( mail ); 220 mail.Wrapper()->deleteMail( mail );
227 folderView->refreshCurrent(); 221 folderView->refreshCurrent();
228 } 222 }
229} 223}
230 224
231void MainWindow::mailHold(int button, QListViewItem *item,const QPoint&,int ) 225void MainWindow::mailHold(int button, QListViewItem *item,const QPoint&,int )
232{ 226{
233 /* just the RIGHT button - or hold on pda */ 227 /* just the RIGHT button - or hold on pda */
234 if (button!=2) {return;} 228 if (button!=2) {return;}
235 qDebug("Event right/hold"); 229 qDebug("Event right/hold");
236 if (!item) return; 230 if (!item) return;
237 QPopupMenu *m = new QPopupMenu(0); 231 QPopupMenu *m = new QPopupMenu(0);
238 if (m) { 232 if (m) {
239 m->insertItem(tr("Read this mail"),this,SLOT(displayMail())); 233 m->insertItem(tr("Read this mail"),this,SLOT(displayMail()));
240 m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail())); 234 m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail()));
241 m->setFocus(); 235 m->setFocus();
242 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); 236 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
243 delete m; 237 delete m;
244 } 238 }
245} 239}
246 240
247MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * item ) 241MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * item )
248 :QListViewItem(parent,item),mail_data() 242 :QListViewItem(parent,item),mail_data()
249{ 243{
250} 244}
251 245
252void MailListViewItem::showEntry() 246void MailListViewItem::showEntry()
253{ 247{
254 if ( mail_data.getFlags().testBit( FLAG_ANSWERED ) == true) { 248 if ( mail_data.getFlags().testBit( FLAG_ANSWERED ) == true) {
255 setPixmap( 0, Resource::loadPixmap( "mail/kmmsgreplied") ); 249 setPixmap( 0, Resource::loadPixmap( "mail/kmmsgreplied") );
256 } else if ( mail_data.getFlags().testBit( FLAG_SEEN ) == true ) { 250 } else if ( mail_data.getFlags().testBit( FLAG_SEEN ) == true ) {
257 /* I think it looks nicer if there are not such a log of icons but only on mails 251 /* I think it looks nicer if there are not such a log of icons but only on mails
258 replied or new - Alwin*/ 252 replied or new - Alwin*/
259 //setPixmap( 0, Resource::loadPixmap( "mail/kmmsgunseen") ); 253 //setPixmap( 0, Resource::loadPixmap( "mail/kmmsgunseen") );
260 } else { 254 } else {
261 setPixmap( 0, Resource::loadPixmap( "mail/kmmsgnew") ); 255 setPixmap( 0, Resource::loadPixmap( "mail/kmmsgnew") );
262 } 256 }
263 double s = mail_data.Msgsize(); 257 double s = mail_data.Msgsize();
264 int w; 258 int w;
265 w=0; 259 w=0;
266 260
267 while (s>1024) { 261 while (s>1024) {
268 s/=1024; 262 s/=1024;
269 ++w; 263 ++w;
270 if (w>=2) break; 264 if (w>=2) break;
271 } 265 }
272 266
273 QString q=""; 267 QString q="";
274 QString fsize=""; 268 QString fsize="";
275 switch(w) { 269 switch(w) {
276 case 1: 270 case 1:
277 q="k"; 271 q="k";
278 break; 272 break;
279 case 2: 273 case 2:
280 q="M"; 274 q="M";
281 break; 275 break;
282 default: 276 default:
283 break; 277 break;
284 } 278 }
285 279
286 { 280 {
287 QTextOStream o(&fsize); 281 QTextOStream o(&fsize);
288 if (w>0) o.precision(2); else o.precision(0); 282 if (w>0) o.precision(2); else o.precision(0);
289 o.setf(QTextStream::fixed); 283 o.setf(QTextStream::fixed);
290 o << s << " " << q << "Byte"; 284 o << s << " " << q << "Byte";
291 } 285 }
292 286
293 setText(1,mail_data.getSubject()); 287 setText(1,mail_data.getSubject());
294 setText(2,mail_data.getFrom()); 288 setText(2,mail_data.getFrom());
295 setText(3,fsize); 289 setText(3,fsize);
296 setText(4,mail_data.getDate()); 290 setText(4,mail_data.getDate());
297} 291}
298 292
299void MailListViewItem::storeData(const RecMail&data) 293void MailListViewItem::storeData(const RecMail&data)
300{ 294{
301 mail_data = data; 295 mail_data = data;
302} 296}
303 297
304const RecMail& MailListViewItem::data()const 298const RecMail& MailListViewItem::data()const
305{ 299{
306 return mail_data; 300 return mail_data;
307} 301}
308 302
309 303
diff --git a/noncore/net/mail/newmaildir.cpp b/noncore/net/mail/newmaildir.cpp
new file mode 100644
index 0000000..3fc66f4
--- a/dev/null
+++ b/noncore/net/mail/newmaildir.cpp
@@ -0,0 +1,34 @@
1#include "newmaildir.h"
2#include <qdialog.h>
3#include <qvariant.h>
4#include <qlineedit.h>
5#include <qcheckbox.h>
6
7Newmdirdlg::Newmdirdlg( QWidget* parent, const char* name)
8 : Newmdirdlgui(parent,name,true),ndir(""),possible_subs(false)
9{
10}
11
12Newmdirdlg::~Newmdirdlg()
13{
14}
15
16void Newmdirdlg::accept()
17{
18 ndir = dirnameEdit->text();
19 possible_subs = subdirsPossibleBox->isChecked();
20 if (ndir.isEmpty()) {
21 return;
22 }
23 Newmdirdlgui::accept();
24}
25
26const QString&Newmdirdlg::Newdir()const
27{
28 return ndir;
29}
30
31const bool Newmdirdlg::subpossible()const
32{
33 return possible_subs;
34}
diff --git a/noncore/net/mail/newmaildir.h b/noncore/net/mail/newmaildir.h
new file mode 100644
index 0000000..1eb904e
--- a/dev/null
+++ b/noncore/net/mail/newmaildir.h
@@ -0,0 +1,20 @@
1#include "newmaildirui.h"
2#include <qvariant.h>
3
4class Newmdirdlg : public Newmdirdlgui
5{
6 Q_OBJECT
7public:
8 Newmdirdlg( QWidget* parent = 0, const char* name = 0);
9 ~Newmdirdlg();
10
11 const QString&Newdir()const;
12 const bool subpossible()const;
13
14protected slots:
15 virtual void accept();
16
17protected:
18 QString ndir;
19 bool possible_subs;
20};
diff --git a/noncore/net/mail/newmaildirui.ui b/noncore/net/mail/newmaildirui.ui
new file mode 100644
index 0000000..72b2d04
--- a/dev/null
+++ b/noncore/net/mail/newmaildirui.ui
@@ -0,0 +1,100 @@
1<!DOCTYPE UI><UI>
2<class>Newmdirdlgui</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>newmdirdlg</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>223</width>
15 <height>110</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Enter directory name</string>
21 </property>
22 <vbox>
23 <property stdset="1">
24 <name>margin</name>
25 <number>11</number>
26 </property>
27 <property stdset="1">
28 <name>spacing</name>
29 <number>6</number>
30 </property>
31 <widget>
32 <class>QLayoutWidget</class>
33 <property stdset="1">
34 <name>name</name>
35 <cstring>Layout5</cstring>
36 </property>
37 <grid>
38 <property stdset="1">
39 <name>margin</name>
40 <number>0</number>
41 </property>
42 <property stdset="1">
43 <name>spacing</name>
44 <number>6</number>
45 </property>
46 <widget row="0" column="0" >
47 <class>QLabel</class>
48 <property stdset="1">
49 <name>name</name>
50 <cstring>dirnameLabel</cstring>
51 </property>
52 <property stdset="1">
53 <name>text</name>
54 <string>Directory name:</string>
55 </property>
56 </widget>
57 <widget row="0" column="1" >
58 <class>QLineEdit</class>
59 <property stdset="1">
60 <name>name</name>
61 <cstring>dirnameEdit</cstring>
62 </property>
63 </widget>
64 </grid>
65 </widget>
66 <widget>
67 <class>QCheckBox</class>
68 <property stdset="1">
69 <name>name</name>
70 <cstring>subdirsPossibleBox</cstring>
71 </property>
72 <property stdset="1">
73 <name>text</name>
74 <string>Directory contains other subdirs</string>
75 </property>
76 </widget>
77 <spacer>
78 <property>
79 <name>name</name>
80 <cstring>Spacer4</cstring>
81 </property>
82 <property stdset="1">
83 <name>orientation</name>
84 <enum>Vertical</enum>
85 </property>
86 <property stdset="1">
87 <name>sizeType</name>
88 <enum>Expanding</enum>
89 </property>
90 <property>
91 <name>sizeHint</name>
92 <size>
93 <width>20</width>
94 <height>20</height>
95 </size>
96 </property>
97 </spacer>
98 </vbox>
99</widget>
100</UI>