summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/accountview.cpp33
-rw-r--r--noncore/net/mail/accountview.h4
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.h1
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp74
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h1
-rw-r--r--noncore/net/mail/libmailwrapper/mboxwrapper.cpp13
-rw-r--r--noncore/net/mail/libmailwrapper/mboxwrapper.h3
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp11
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h3
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp17
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.h4
-rw-r--r--noncore/net/mail/mail.pro9
-rw-r--r--noncore/net/mail/selectstore.cpp19
-rw-r--r--noncore/net/mail/selectstore.h19
-rw-r--r--noncore/net/mail/selectstoreui.ui244
15 files changed, 400 insertions, 55 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp
index 77fa706..faa6982 100644
--- a/noncore/net/mail/accountview.cpp
+++ b/noncore/net/mail/accountview.cpp
@@ -1,668 +1,693 @@
1#include "accountview.h" 1#include "accountview.h"
2#include <libmailwrapper/mailtypes.h> 2#include <libmailwrapper/mailtypes.h>
3#include <libmailwrapper/abstractmail.h> 3#include <libmailwrapper/abstractmail.h>
4#include "defines.h" 4#include "defines.h"
5#include "newmaildir.h" 5#include "newmaildir.h"
6#include "selectstore.h"
6#include <qmessagebox.h> 7#include <qmessagebox.h>
7#include <qpopupmenu.h> 8#include <qpopupmenu.h>
8 9
9/** 10/**
10 * POP3 Account stuff 11 * POP3 Account stuff
11 */ 12 */
12POP3viewItem::POP3viewItem( POP3account *a, QListView *parent ) 13POP3viewItem::POP3viewItem( POP3account *a, QListView *parent )
13 : AccountViewItem( parent ) 14 : AccountViewItem( parent )
14{ 15{
15 account = a; 16 account = a;
16 wrapper = AbstractMail::getWrapper( account ); 17 wrapper = AbstractMail::getWrapper( account );
17 setPixmap( 0, PIXMAP_POP3FOLDER ); 18 setPixmap( 0, PIXMAP_POP3FOLDER );
18 setText( 0, account->getAccountName() ); 19 setText( 0, account->getAccountName() );
19 setOpen( true ); 20 setOpen( true );
20} 21}
21 22
22POP3viewItem::~POP3viewItem() 23POP3viewItem::~POP3viewItem()
23{ 24{
24 delete wrapper; 25 delete wrapper;
25} 26}
26 27
27AbstractMail *POP3viewItem::getWrapper() 28AbstractMail *POP3viewItem::getWrapper()
28{ 29{
29 return wrapper; 30 return wrapper;
30} 31}
31 32
32void POP3viewItem::refresh( QList<RecMail> & ) 33void POP3viewItem::refresh( QList<RecMail> & )
33{ 34{
34 QList<Folder> *folders = wrapper->listFolders(); 35 QList<Folder> *folders = wrapper->listFolders();
35 QListViewItem *child = firstChild(); 36 QListViewItem *child = firstChild();
36 while ( child ) { 37 while ( child ) {
37 QListViewItem *tmp = child; 38 QListViewItem *tmp = child;
38 child = child->nextSibling(); 39 child = child->nextSibling();
39 delete tmp; 40 delete tmp;
40 } 41 }
41 Folder *it; 42 Folder *it;
42 QListViewItem*item = 0; 43 QListViewItem*item = 0;
43 for ( it = folders->first(); it; it = folders->next() ) { 44 for ( it = folders->first(); it; it = folders->next() ) {
44 item = new POP3folderItem( it, this , item ); 45 item = new POP3folderItem( it, this , item );
45 item->setSelectable(it->may_select()); 46 item->setSelectable(it->may_select());
46 } 47 }
47 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 48 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
48 folders->setAutoDelete(false); 49 folders->setAutoDelete(false);
49 delete folders; 50 delete folders;
50} 51}
51 52
52RecBody POP3viewItem::fetchBody( const RecMail &mail ) 53RecBody POP3viewItem::fetchBody( const RecMail &mail )
53{ 54{
54 qDebug( "POP3 fetchBody" ); 55 qDebug( "POP3 fetchBody" );
55 return wrapper->fetchBody( mail ); 56 return wrapper->fetchBody( mail );
56} 57}
57 58
58POP3folderItem::~POP3folderItem() 59POP3folderItem::~POP3folderItem()
59{ 60{
60 delete folder; 61 delete folder;
61} 62}
62 63
63POP3folderItem::POP3folderItem( Folder *folderInit, POP3viewItem *parent , QListViewItem*after ) 64POP3folderItem::POP3folderItem( Folder *folderInit, POP3viewItem *parent , QListViewItem*after )
64 : AccountViewItem( parent,after ) 65 : AccountViewItem( parent,after )
65{ 66{
66 folder = folderInit; 67 folder = folderInit;
67 pop3 = parent; 68 pop3 = parent;
68 if (folder->getDisplayName().lower()!="inbox") { 69 if (folder->getDisplayName().lower()!="inbox") {
69 setPixmap( 0, PIXMAP_POP3FOLDER ); 70 setPixmap( 0, PIXMAP_POP3FOLDER );
70 } else { 71 } else {
71 setPixmap( 0, PIXMAP_INBOXFOLDER); 72 setPixmap( 0, PIXMAP_INBOXFOLDER);
72 } 73 }
73 setText( 0, folder->getDisplayName() ); 74 setText( 0, folder->getDisplayName() );
74} 75}
75 76
76void POP3folderItem::refresh(QList<RecMail>&target) 77void POP3folderItem::refresh(QList<RecMail>&target)
77{ 78{
78 if (folder->may_select()) 79 if (folder->may_select())
79 pop3->getWrapper()->listMessages( folder->getName(),target ); 80 pop3->getWrapper()->listMessages( folder->getName(),target );
80} 81}
81 82
82RecBody POP3folderItem::fetchBody(const RecMail&aMail) 83RecBody POP3folderItem::fetchBody(const RecMail&aMail)
83{ 84{
84 return pop3->getWrapper()->fetchBody(aMail); 85 return pop3->getWrapper()->fetchBody(aMail);
85} 86}
86 87
87QPopupMenu * POP3folderItem::getContextMenu() 88QPopupMenu * POP3folderItem::getContextMenu()
88{ 89{
89 QPopupMenu *m = new QPopupMenu(0); 90 QPopupMenu *m = new QPopupMenu(0);
90 if (m) { 91 if (m) {
91 m->insertItem(QObject::tr("Refresh header list",contextName),0); 92 m->insertItem(QObject::tr("Refresh header list",contextName),0);
92 m->insertItem(QObject::tr("Delete all mails",contextName),1); 93 m->insertItem(QObject::tr("Delete all mails",contextName),1);
94 m->insertItem(QObject::tr("Download all mails",contextName),2);
93 } 95 }
94 return m; 96 return m;
95} 97}
96 98
99void POP3folderItem::downloadMails()
100{
101 Selectstore sels;
102 sels.showMaximized();
103 sels.exec();
104}
105
97void POP3folderItem::contextMenuSelected(int which) 106void POP3folderItem::contextMenuSelected(int which)
98{ 107{
99 AccountView * view = (AccountView*)listView(); 108 AccountView * view = (AccountView*)listView();
100 switch (which) { 109 switch (which) {
101 case 0: 110 case 0:
111 /* must be 'cause pop3 lists are cached */
112 pop3->getWrapper()->logout();
102 view->refreshCurrent(); 113 view->refreshCurrent();
103 break; 114 break;
104 case 1: 115 case 1:
105 deleteAllMail(pop3->getWrapper(),folder); 116 deleteAllMail(pop3->getWrapper(),folder);
106 break; 117 break;
118 case 2:
119 downloadMails();
120 break;
107 default: 121 default:
108 break; 122 break;
109 } 123 }
110} 124}
111 125
112/** 126/**
113 * IMAP Account stuff 127 * IMAP Account stuff
114 */ 128 */
115IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent ) 129IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent )
116 : AccountViewItem( parent ) 130 : AccountViewItem( parent )
117{ 131{
118 account = a; 132 account = a;
119 wrapper = AbstractMail::getWrapper( account ); 133 wrapper = AbstractMail::getWrapper( account );
120 setPixmap( 0, PIXMAP_IMAPFOLDER ); 134 setPixmap( 0, PIXMAP_IMAPFOLDER );
121 setText( 0, account->getAccountName() ); 135 setText( 0, account->getAccountName() );
122 setOpen( true ); 136 setOpen( true );
123} 137}
124 138
125IMAPviewItem::~IMAPviewItem() 139IMAPviewItem::~IMAPviewItem()
126{ 140{
127 delete wrapper; 141 delete wrapper;
128} 142}
129 143
130AbstractMail *IMAPviewItem::getWrapper() 144AbstractMail *IMAPviewItem::getWrapper()
131{ 145{
132 return wrapper; 146 return wrapper;
133} 147}
134 148
135IMAPfolderItem*IMAPviewItem::findSubItem(const QString&path,IMAPfolderItem*start) 149IMAPfolderItem*IMAPviewItem::findSubItem(const QString&path,IMAPfolderItem*start)
136{ 150{
137 IMAPfolderItem*pitem,*sitem; 151 IMAPfolderItem*pitem,*sitem;
138 if (!start) pitem = (IMAPfolderItem*)firstChild(); 152 if (!start) pitem = (IMAPfolderItem*)firstChild();
139 else pitem = (IMAPfolderItem*)start->firstChild(); 153 else pitem = (IMAPfolderItem*)start->firstChild();
140 while (pitem) { 154 while (pitem) {
141 if (pitem->matchName(path)) { 155 if (pitem->matchName(path)) {
142 break; 156 break;
143 } 157 }
144 if (pitem->childCount()>0) { 158 if (pitem->childCount()>0) {
145 sitem = findSubItem(path,pitem); 159 sitem = findSubItem(path,pitem);
146 if (sitem) { 160 if (sitem) {
147 pitem = sitem; 161 pitem = sitem;
148 break; 162 break;
149 } 163 }
150 } 164 }
151 pitem=(IMAPfolderItem*)pitem->nextSibling(); 165 pitem=(IMAPfolderItem*)pitem->nextSibling();
152 } 166 }
153 return pitem; 167 return pitem;
154} 168}
155 169
156void IMAPviewItem::refresh(QList<RecMail>&) 170void IMAPviewItem::refresh(QList<RecMail>&)
157{ 171{
158 refreshFolders(false); 172 refreshFolders(false);
159} 173}
160 174
161void IMAPviewItem::refreshFolders(bool force) 175void IMAPviewItem::removeChilds()
162{ 176{
163 if (childCount()>0 && force==false) return;
164 QList<Folder> *folders = wrapper->listFolders();
165
166 QListViewItem *child = firstChild(); 177 QListViewItem *child = firstChild();
167 while ( child ) { 178 while ( child ) {
168 QListViewItem *tmp = child; 179 QListViewItem *tmp = child;
169 child = child->nextSibling(); 180 child = child->nextSibling();
170 delete tmp; 181 delete tmp;
171 } 182 }
172 183
184}
185
186void IMAPviewItem::refreshFolders(bool force)
187{
188 if (childCount()>0 && force==false) return;
189
190 removeChilds();
191
192 QList<Folder> *folders = wrapper->listFolders();
193
173 Folder *it; 194 Folder *it;
174 QListViewItem*item = 0; 195 QListViewItem*item = 0;
175 QListViewItem*titem = 0; 196 QListViewItem*titem = 0;
176 QString fname,del,search; 197 QString fname,del,search;
177 int pos; 198 int pos;
178 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 199 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
179 folders->setAutoDelete(false); 200 folders->setAutoDelete(false);
180 201
181 for ( it = folders->first(); it; it = folders->next() ) { 202 for ( it = folders->first(); it; it = folders->next() ) {
182 if (it->getDisplayName().lower()=="inbox") { 203 if (it->getDisplayName().lower()=="inbox") {
183 item = new IMAPfolderItem( it, this , item ); 204 item = new IMAPfolderItem( it, this , item );
184 folders->remove(it); 205 folders->remove(it);
185 qDebug("inbox found"); 206 qDebug("inbox found");
186 break; 207 break;
187 } 208 }
188 } 209 }
189 for ( it = folders->first(); it; it = folders->next() ) { 210 for ( it = folders->first(); it; it = folders->next() ) {
190 fname = it->getDisplayName(); 211 fname = it->getDisplayName();
191 pos = fname.findRev(it->Separator()); 212 pos = fname.findRev(it->Separator());
192 if (pos != -1) { 213 if (pos != -1) {
193 fname = fname.left(pos); 214 fname = fname.left(pos);
194 } 215 }
195 IMAPfolderItem*pitem = findSubItem(fname); 216 IMAPfolderItem*pitem = findSubItem(fname);
196 if (pitem) { 217 if (pitem) {
197 titem = item; 218 titem = item;
198 item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this); 219 item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this);
199 /* setup the short name */ 220 /* setup the short name */
200 item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1)); 221 item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1));
201 item = titem; 222 item = titem;
202 } else { 223 } else {
203 item = new IMAPfolderItem( it, this , item ); 224 item = new IMAPfolderItem( it, this , item );
204 } 225 }
205 } 226 }
206 delete folders; 227 delete folders;
207} 228}
208 229
209QPopupMenu * IMAPviewItem::getContextMenu() 230QPopupMenu * IMAPviewItem::getContextMenu()
210{ 231{
211 QPopupMenu *m = new QPopupMenu(0); 232 QPopupMenu *m = new QPopupMenu(0);
212 if (m) { 233 if (m) {
213 m->insertItem(QObject::tr("Refresh folder list",contextName),0); 234 m->insertItem(QObject::tr("Refresh folder list",contextName),0);
214 m->insertItem(QObject::tr("Create new folder",contextName),1); 235 m->insertItem(QObject::tr("Create new folder",contextName),1);
215 m->insertSeparator(); 236 m->insertSeparator();
216 m->insertItem(QObject::tr("Disconnect",contextName),2); 237 m->insertItem(QObject::tr("Disconnect",contextName),2);
217 } 238 }
218 return m; 239 return m;
219} 240}
220 241
221void IMAPviewItem::createNewFolder() 242void IMAPviewItem::createNewFolder()
222{ 243{
223 Newmdirdlg ndirdlg; 244 Newmdirdlg ndirdlg;
224 ndirdlg.showMaximized(); 245 ndirdlg.showMaximized();
225 if (ndirdlg.exec()) { 246 if (ndirdlg.exec()) {
226 QString ndir = ndirdlg.Newdir(); 247 QString ndir = ndirdlg.Newdir();
227 bool makesubs = ndirdlg.subpossible(); 248 bool makesubs = ndirdlg.subpossible();
228 QString delemiter = "/"; 249 QString delemiter = "/";
229 IMAPfolderItem*item = (IMAPfolderItem*)firstChild(); 250 IMAPfolderItem*item = (IMAPfolderItem*)firstChild();
230 if (item) { 251 if (item) {
231 delemiter = item->Delemiter(); 252 delemiter = item->Delemiter();
232 } 253 }
233 if (wrapper->createMbox(ndir,0,delemiter,makesubs)) { 254 if (wrapper->createMbox(ndir,0,delemiter,makesubs)) {
234 refreshFolders(true); 255 refreshFolders(true);
235 } 256 }
236 } 257 }
237} 258}
238 259
239void IMAPviewItem::contextMenuSelected(int id) 260void IMAPviewItem::contextMenuSelected(int id)
240{ 261{
241 qDebug("Id selected: %i",id); 262 qDebug("Id selected: %i",id);
242 switch (id) { 263 switch (id) {
243 case 0: 264 case 0:
244 refreshFolders(true); 265 refreshFolders(true);
245 break; 266 break;
246 case 1: 267 case 1:
247 createNewFolder(); 268 createNewFolder();
248 break; 269 break;
270 case 2:
271 removeChilds();
272 wrapper->logout();
273 break;
249 default: 274 default:
250 break; 275 break;
251 } 276 }
252} 277}
253 278
254RecBody IMAPviewItem::fetchBody(const RecMail&) 279RecBody IMAPviewItem::fetchBody(const RecMail&)
255{ 280{
256 return RecBody(); 281 return RecBody();
257} 282}
258 283
259IMAPfolderItem::~IMAPfolderItem() 284IMAPfolderItem::~IMAPfolderItem()
260{ 285{
261 delete folder; 286 delete folder;
262} 287}
263 288
264IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after ) 289IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after )
265 : AccountViewItem( parent , after ) 290 : AccountViewItem( parent , after )
266{ 291{
267 folder = folderInit; 292 folder = folderInit;
268 imap = parent; 293 imap = parent;
269 if (folder->getDisplayName().lower()!="inbox") { 294 if (folder->getDisplayName().lower()!="inbox") {
270 setPixmap( 0, PIXMAP_IMAPFOLDER ); 295 setPixmap( 0, PIXMAP_IMAPFOLDER );
271 } else { 296 } else {
272 setPixmap( 0, PIXMAP_INBOXFOLDER); 297 setPixmap( 0, PIXMAP_INBOXFOLDER);
273 } 298 }
274 setText( 0, folder->getDisplayName() ); 299 setText( 0, folder->getDisplayName() );
275} 300}
276 301
277IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ) 302IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master )
278 : AccountViewItem( parent,after ) 303 : AccountViewItem( parent,after )
279{ 304{
280 folder = folderInit; 305 folder = folderInit;
281 imap = master; 306 imap = master;
282 if (folder->getDisplayName().lower()!="inbox") { 307 if (folder->getDisplayName().lower()!="inbox") {
283 setPixmap( 0, PIXMAP_IMAPFOLDER ); 308 setPixmap( 0, PIXMAP_IMAPFOLDER );
284 } else { 309 } else {
285 setPixmap( 0, PIXMAP_INBOXFOLDER); 310 setPixmap( 0, PIXMAP_INBOXFOLDER);
286 } 311 }
287 setText( 0, folder->getDisplayName() ); 312 setText( 0, folder->getDisplayName() );
288} 313}
289 314
290const QString& IMAPfolderItem::Delemiter()const 315const QString& IMAPfolderItem::Delemiter()const
291{ 316{
292 return folder->Separator(); 317 return folder->Separator();
293} 318}
294 319
295bool IMAPfolderItem::matchName(const QString&name)const 320bool IMAPfolderItem::matchName(const QString&name)const
296{ 321{
297 return folder->getDisplayName()==name; 322 return folder->getDisplayName()==name;
298} 323}
299 324
300void IMAPfolderItem::refresh(QList<RecMail>&target) 325void IMAPfolderItem::refresh(QList<RecMail>&target)
301{ 326{
302 if (folder->may_select()) { 327 if (folder->may_select()) {
303 imap->getWrapper()->listMessages( folder->getName(),target ); 328 imap->getWrapper()->listMessages( folder->getName(),target );
304 } else { 329 } else {
305 target.clear(); 330 target.clear();
306 } 331 }
307} 332}
308 333
309RecBody IMAPfolderItem::fetchBody(const RecMail&aMail) 334RecBody IMAPfolderItem::fetchBody(const RecMail&aMail)
310{ 335{
311 return imap->getWrapper()->fetchBody(aMail); 336 return imap->getWrapper()->fetchBody(aMail);
312} 337}
313 338
314QPopupMenu * IMAPfolderItem::getContextMenu() 339QPopupMenu * IMAPfolderItem::getContextMenu()
315{ 340{
316 QPopupMenu *m = new QPopupMenu(0); 341 QPopupMenu *m = new QPopupMenu(0);
317 if (m) { 342 if (m) {
318 if (folder->may_select()) { 343 if (folder->may_select()) {
319 m->insertItem(QObject::tr("Refresh header list",contextName),0); 344 m->insertItem(QObject::tr("Refresh header list",contextName),0);
320 m->insertItem(QObject::tr("Delete all mails",contextName),1); 345 m->insertItem(QObject::tr("Delete all mails",contextName),1);
321 } 346 }
322 if (folder->no_inferior()==false) { 347 if (folder->no_inferior()==false) {
323 m->insertItem(QObject::tr("Create new subfolder",contextName),2); 348 m->insertItem(QObject::tr("Create new subfolder",contextName),2);
324 } 349 }
325 if (folder->getDisplayName().lower()!="inbox") { 350 if (folder->getDisplayName().lower()!="inbox") {
326 m->insertItem(QObject::tr("Delete folder",contextName),3); 351 m->insertItem(QObject::tr("Delete folder",contextName),3);
327 } 352 }
328 } 353 }
329 return m; 354 return m;
330} 355}
331 356
332void IMAPfolderItem::createNewFolder() 357void IMAPfolderItem::createNewFolder()
333{ 358{
334 Newmdirdlg ndirdlg; 359 Newmdirdlg ndirdlg;
335 ndirdlg.showMaximized(); 360 ndirdlg.showMaximized();
336 if (ndirdlg.exec()) { 361 if (ndirdlg.exec()) {
337 QString ndir = ndirdlg.Newdir(); 362 QString ndir = ndirdlg.Newdir();
338 bool makesubs = ndirdlg.subpossible(); 363 bool makesubs = ndirdlg.subpossible();
339 QString delemiter = Delemiter(); 364 QString delemiter = Delemiter();
340 if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) { 365 if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) {
341 imap->refreshFolders(true); 366 imap->refreshFolders(true);
342 } 367 }
343 } 368 }
344} 369}
345 370
346void IMAPfolderItem::deleteFolder() 371void IMAPfolderItem::deleteFolder()
347{ 372{
348 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), 373 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
349 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), 374 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()),
350 QObject::tr("Yes",contextName), 375 QObject::tr("Yes",contextName),
351 QObject::tr("No",contextName),QString::null,1,1); 376 QObject::tr("No",contextName),QString::null,1,1);
352 qDebug("Auswahl: %i",yesno); 377 qDebug("Auswahl: %i",yesno);
353 if (yesno == 0) { 378 if (yesno == 0) {
354 if (imap->getWrapper()->deleteMbox(folder)) { 379 if (imap->getWrapper()->deleteMbox(folder)) {
355 QListView*v=listView(); 380 QListView*v=listView();
356 IMAPviewItem * box = imap; 381 IMAPviewItem * box = imap;
357 /* be carefull - after that this object is destroyd so don't use 382 /* be carefull - after that this object is destroyd so don't use
358 * any member of it after that call!!*/ 383 * any member of it after that call!!*/
359 imap->refreshFolders(true); 384 imap->refreshFolders(true);
360 if (v) { 385 if (v) {
361 v->setSelected(box,true); 386 v->setSelected(box,true);
362 } 387 }
363 } 388 }
364 } 389 }
365} 390}
366 391
367void IMAPfolderItem::contextMenuSelected(int id) 392void IMAPfolderItem::contextMenuSelected(int id)
368{ 393{
369 qDebug("Selected id: %i",id); 394 qDebug("Selected id: %i",id);
370 AccountView * view = (AccountView*)listView(); 395 AccountView * view = (AccountView*)listView();
371 switch(id) { 396 switch(id) {
372 case 0: 397 case 0:
373 view->refreshCurrent(); 398 view->refreshCurrent();
374 break; 399 break;
375 case 1: 400 case 1:
376 deleteAllMail(imap->getWrapper(),folder); 401 deleteAllMail(imap->getWrapper(),folder);
377 break; 402 break;
378 case 2: 403 case 2:
379 createNewFolder(); 404 createNewFolder();
380 break; 405 break;
381 case 3: 406 case 3:
382 deleteFolder(); 407 deleteFolder();
383 break; 408 break;
384 default: 409 default:
385 break; 410 break;
386 } 411 }
387} 412}
388 413
389/** 414/**
390 * Generic stuff 415 * Generic stuff
391 */ 416 */
392 417
393const QString AccountViewItem::contextName="AccountViewItem"; 418const QString AccountViewItem::contextName="AccountViewItem";
394 419
395void AccountViewItem::deleteAllMail(AbstractMail*wrapper,Folder*folder) 420void AccountViewItem::deleteAllMail(AbstractMail*wrapper,Folder*folder)
396{ 421{
397 if (!wrapper) return; 422 if (!wrapper) return;
398 QString fname=""; 423 QString fname="";
399 if (folder) fname = folder->getDisplayName(); 424 if (folder) fname = folder->getDisplayName();
400 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName), 425 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName),
401 QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName). 426 QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName).
402 arg(fname), 427 arg(fname),
403 QObject::tr("Yes",contextName), 428 QObject::tr("Yes",contextName),
404 QObject::tr("No",contextName),QString::null,1,1); 429 QObject::tr("No",contextName),QString::null,1,1);
405 qDebug("Auswahl: %i",yesno); 430 qDebug("Auswahl: %i",yesno);
406 if (yesno == 0) { 431 if (yesno == 0) {
407 if (wrapper->deleteAllMail(folder)) { 432 if (wrapper->deleteAllMail(folder)) {
408 AccountView * view = (AccountView*)listView(); 433 AccountView * view = (AccountView*)listView();
409 if (view) view->refreshCurrent(); 434 if (view) view->refreshCurrent();
410 } 435 }
411 } 436 }
412} 437}
413 438
414AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) 439AccountView::AccountView( QWidget *parent, const char *name, WFlags flags )
415 : QListView( parent, name, flags ) 440 : QListView( parent, name, flags )
416{ 441{
417 connect( this, SIGNAL( selectionChanged( QListViewItem * ) ), 442 connect( this, SIGNAL( selectionChanged( QListViewItem * ) ),
418 SLOT( refresh( QListViewItem * ) ) ); 443 SLOT( refresh( QListViewItem * ) ) );
419 connect( this, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this, 444 connect( this, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this,
420 SLOT( slotHold( int, QListViewItem *,const QPoint&,int ) ) ); 445 SLOT( slotHold( int, QListViewItem *,const QPoint&,int ) ) );
421 446
422 setSorting(0); 447 setSorting(0);
423} 448}
424 449
425void AccountView::slotContextMenu(int id) 450void AccountView::slotContextMenu(int id)
426{ 451{
427 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); 452 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem());
428 if (!view) return; 453 if (!view) return;
429 view->contextMenuSelected(id); 454 view->contextMenuSelected(id);
430} 455}
431 456
432void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int) 457void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int)
433{ 458{
434 if (button==1) {return;} 459 if (button==1) {return;}
435 if (!item) return; 460 if (!item) return;
436 AccountViewItem *view = static_cast<AccountViewItem *>(item); 461 AccountViewItem *view = static_cast<AccountViewItem *>(item);
437 QPopupMenu*m = view->getContextMenu(); 462 QPopupMenu*m = view->getContextMenu();
438 if (!m) return; 463 if (!m) return;
439 connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int))); 464 connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int)));
440 m->setFocus(); 465 m->setFocus();
441 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); 466 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
442 delete m; 467 delete m;
443} 468}
444 469
445void AccountView::populate( QList<Account> list ) 470void AccountView::populate( QList<Account> list )
446{ 471{
447 clear(); 472 clear();
448 473
449 (void) new MBOXviewItem(AbstractMail::defaultLocalfolder(),this); 474 (void) new MBOXviewItem(AbstractMail::defaultLocalfolder(),this);
450 475
451 Account *it; 476 Account *it;
452 for ( it = list.first(); it; it = list.next() ) { 477 for ( it = list.first(); it; it = list.next() ) {
453 if ( it->getType().compare( "IMAP" ) == 0 ) { 478 if ( it->getType().compare( "IMAP" ) == 0 ) {
454 IMAPaccount *imap = static_cast<IMAPaccount *>(it); 479 IMAPaccount *imap = static_cast<IMAPaccount *>(it);
455 qDebug( "added IMAP " + imap->getAccountName() ); 480 qDebug( "added IMAP " + imap->getAccountName() );
456 (void) new IMAPviewItem( imap, this ); 481 (void) new IMAPviewItem( imap, this );
457 } else if ( it->getType().compare( "POP3" ) == 0 ) { 482 } else if ( it->getType().compare( "POP3" ) == 0 ) {
458 POP3account *pop3 = static_cast<POP3account *>(it); 483 POP3account *pop3 = static_cast<POP3account *>(it);
459 qDebug( "added POP3 " + pop3->getAccountName() ); 484 qDebug( "added POP3 " + pop3->getAccountName() );
460 (void) new POP3viewItem( pop3, this ); 485 (void) new POP3viewItem( pop3, this );
461 } 486 }
462 } 487 }
463} 488}
464 489
465void AccountView::refresh(QListViewItem *item) { 490void AccountView::refresh(QListViewItem *item) {
466 491
467 qDebug("AccountView refresh..."); 492 qDebug("AccountView refresh...");
468 if ( item ) { 493 if ( item ) {
469 m_currentItem = item; 494 m_currentItem = item;
470 QList<RecMail> headerlist; 495 QList<RecMail> headerlist;
471 headerlist.setAutoDelete(true); 496 headerlist.setAutoDelete(true);
472 AccountViewItem *view = static_cast<AccountViewItem *>(item); 497 AccountViewItem *view = static_cast<AccountViewItem *>(item);
473 view->refresh(headerlist); 498 view->refresh(headerlist);
474 emit refreshMailview(&headerlist); 499 emit refreshMailview(&headerlist);
475 } 500 }
476} 501}
477 502
478void AccountView::refreshCurrent() 503void AccountView::refreshCurrent()
479{ 504{
480 m_currentItem = currentItem(); 505 m_currentItem = currentItem();
481 if ( !m_currentItem ) return; 506 if ( !m_currentItem ) return;
482 QList<RecMail> headerlist; 507 QList<RecMail> headerlist;
483 headerlist.setAutoDelete(true); 508 headerlist.setAutoDelete(true);
484 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); 509 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem);
485 view->refresh(headerlist); 510 view->refresh(headerlist);
486 emit refreshMailview(&headerlist); 511 emit refreshMailview(&headerlist);
487} 512}
488 513
489void AccountView::refreshAll() 514void AccountView::refreshAll()
490{ 515{
491 516
492} 517}
493 518
494RecBody AccountView::fetchBody(const RecMail&aMail) 519RecBody AccountView::fetchBody(const RecMail&aMail)
495{ 520{
496 QListViewItem*item = selectedItem (); 521 QListViewItem*item = selectedItem ();
497 if (!item) return RecBody(); 522 if (!item) return RecBody();
498 AccountViewItem *view = static_cast<AccountViewItem *>(item); 523 AccountViewItem *view = static_cast<AccountViewItem *>(item);
499 return view->fetchBody(aMail); 524 return view->fetchBody(aMail);
500} 525}
501 526
502/** 527/**
503 * MBOX Account stuff 528 * MBOX Account stuff
504 */ 529 */
505 530
506MBOXviewItem::MBOXviewItem( const QString&aPath, QListView *parent ) 531MBOXviewItem::MBOXviewItem( const QString&aPath, QListView *parent )
507 : AccountViewItem( parent ) 532 : AccountViewItem( parent )
508{ 533{
509 m_Path = aPath; 534 m_Path = aPath;
510 wrapper = AbstractMail::getWrapper( m_Path ); 535 wrapper = AbstractMail::getWrapper( m_Path );
511 setPixmap( 0, PIXMAP_LOCALFOLDER ); 536 setPixmap( 0, PIXMAP_LOCALFOLDER );
512 setText( 0, " Local Folders" ); 537 setText( 0, " Local Folders" );
513 setOpen( true ); 538 setOpen( true );
514} 539}
515 540
516MBOXviewItem::~MBOXviewItem() 541MBOXviewItem::~MBOXviewItem()
517{ 542{
518 delete wrapper; 543 delete wrapper;
519} 544}
520 545
521AbstractMail *MBOXviewItem::getWrapper() 546AbstractMail *MBOXviewItem::getWrapper()
522{ 547{
523 return wrapper; 548 return wrapper;
524} 549}
525 550
526void MBOXviewItem::refresh( QList<RecMail> & ) 551void MBOXviewItem::refresh( QList<RecMail> & )
527{ 552{
528 refresh(false); 553 refresh(false);
529} 554}
530 555
531void MBOXviewItem::refresh(bool force) 556void MBOXviewItem::refresh(bool force)
532{ 557{
533 if (childCount()>0 && force==false) return; 558 if (childCount()>0 && force==false) return;
534 QList<Folder> *folders = wrapper->listFolders(); 559 QList<Folder> *folders = wrapper->listFolders();
535 QListViewItem *child = firstChild(); 560 QListViewItem *child = firstChild();
536 while ( child ) { 561 while ( child ) {
537 QListViewItem *tmp = child; 562 QListViewItem *tmp = child;
538 child = child->nextSibling(); 563 child = child->nextSibling();
539 delete tmp; 564 delete tmp;
540 } 565 }
541 Folder *it; 566 Folder *it;
542 QListViewItem*item = 0; 567 QListViewItem*item = 0;
543 for ( it = folders->first(); it; it = folders->next() ) { 568 for ( it = folders->first(); it; it = folders->next() ) {
544 item = new MBOXfolderItem( it, this , item ); 569 item = new MBOXfolderItem( it, this , item );
545 item->setSelectable(it->may_select()); 570 item->setSelectable(it->may_select());
546 } 571 }
547 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 572 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
548 folders->setAutoDelete(false); 573 folders->setAutoDelete(false);
549 delete folders; 574 delete folders;
550} 575}
551 576
552RecBody MBOXviewItem::fetchBody( const RecMail &mail ) 577RecBody MBOXviewItem::fetchBody( const RecMail &mail )
553{ 578{
554 qDebug( "MBOX fetchBody" ); 579 qDebug( "MBOX fetchBody" );
555 return wrapper->fetchBody( mail ); 580 return wrapper->fetchBody( mail );
556} 581}
557 582
558QPopupMenu * MBOXviewItem::getContextMenu() 583QPopupMenu * MBOXviewItem::getContextMenu()
559{ 584{
560 QPopupMenu *m = new QPopupMenu(0); 585 QPopupMenu *m = new QPopupMenu(0);
561 if (m) { 586 if (m) {
562 m->insertItem(QObject::tr("Refresh folder list",contextName),0); 587 m->insertItem(QObject::tr("Refresh folder list",contextName),0);
563 m->insertItem(QObject::tr("Create new folder",contextName),1); 588 m->insertItem(QObject::tr("Create new folder",contextName),1);
564 } 589 }
565 return m; 590 return m;
566} 591}
567 592
568void MBOXviewItem::createFolder() 593void MBOXviewItem::createFolder()
569{ 594{
570 Newmdirdlg ndirdlg(0,0,true); 595 Newmdirdlg ndirdlg(0,0,true);
571 ndirdlg.showMaximized(); 596 ndirdlg.showMaximized();
572 if (ndirdlg.exec()) { 597 if (ndirdlg.exec()) {
573 QString ndir = ndirdlg.Newdir(); 598 QString ndir = ndirdlg.Newdir();
574 if (wrapper->createMbox(ndir)) { 599 if (wrapper->createMbox(ndir)) {
575 refresh(true); 600 refresh(true);
576 } 601 }
577 } 602 }
578} 603}
579 604
580void MBOXviewItem::contextMenuSelected(int which) 605void MBOXviewItem::contextMenuSelected(int which)
581{ 606{
582 switch (which) { 607 switch (which) {
583 case 0: 608 case 0:
584 refresh(true); 609 refresh(true);
585 break; 610 break;
586 case 1: 611 case 1:
587 createFolder(); 612 createFolder();
588 break; 613 break;
589 default: 614 default:
590 break; 615 break;
591 } 616 }
592} 617}
593 618
594MBOXfolderItem::~MBOXfolderItem() 619MBOXfolderItem::~MBOXfolderItem()
595{ 620{
596 delete folder; 621 delete folder;
597} 622}
598 623
599MBOXfolderItem::MBOXfolderItem( Folder *folderInit, MBOXviewItem *parent , QListViewItem*after ) 624MBOXfolderItem::MBOXfolderItem( Folder *folderInit, MBOXviewItem *parent , QListViewItem*after )
600 : AccountViewItem( parent,after ) 625 : AccountViewItem( parent,after )
601{ 626{
602 folder = folderInit; 627 folder = folderInit;
603 mbox = parent; 628 mbox = parent;
604 if (folder->getDisplayName().lower() == "outgoing") { 629 if (folder->getDisplayName().lower() == "outgoing") {
605 setPixmap( 0, PIXMAP_OUTBOXFOLDER ); 630 setPixmap( 0, PIXMAP_OUTBOXFOLDER );
606 } else if (folder->getDisplayName().lower() == "inbox") { 631 } else if (folder->getDisplayName().lower() == "inbox") {
607 setPixmap( 0, PIXMAP_INBOXFOLDER); 632 setPixmap( 0, PIXMAP_INBOXFOLDER);
608 } else { 633 } else {
609 setPixmap( 0, PIXMAP_MBOXFOLDER ); 634 setPixmap( 0, PIXMAP_MBOXFOLDER );
610 } 635 }
611 setText( 0, folder->getDisplayName() ); 636 setText( 0, folder->getDisplayName() );
612} 637}
613 638
614void MBOXfolderItem::refresh(QList<RecMail>&target) 639void MBOXfolderItem::refresh(QList<RecMail>&target)
615{ 640{
616 if (folder->may_select()) 641 if (folder->may_select())
617 mbox->getWrapper()->listMessages( folder->getName(),target ); 642 mbox->getWrapper()->listMessages( folder->getName(),target );
618} 643}
619 644
620RecBody MBOXfolderItem::fetchBody(const RecMail&aMail) 645RecBody MBOXfolderItem::fetchBody(const RecMail&aMail)
621{ 646{
622 return mbox->getWrapper()->fetchBody(aMail); 647 return mbox->getWrapper()->fetchBody(aMail);
623} 648}
624 649
625void MBOXfolderItem::deleteFolder() 650void MBOXfolderItem::deleteFolder()
626{ 651{
627 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), 652 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
628 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), 653 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()),
629 QObject::tr("Yes",contextName), 654 QObject::tr("Yes",contextName),
630 QObject::tr("No",contextName),QString::null,1,1); 655 QObject::tr("No",contextName),QString::null,1,1);
631 qDebug("Auswahl: %i",yesno); 656 qDebug("Auswahl: %i",yesno);
632 if (yesno == 0) { 657 if (yesno == 0) {
633 if (mbox->getWrapper()->deleteMbox(folder)) { 658 if (mbox->getWrapper()->deleteMbox(folder)) {
634 QListView*v=listView(); 659 QListView*v=listView();
635 MBOXviewItem * box = mbox; 660 MBOXviewItem * box = mbox;
636 /* be carefull - after that this object is destroyd so don't use 661 /* be carefull - after that this object is destroyd so don't use
637 * any member of it after that call!!*/ 662 * any member of it after that call!!*/
638 mbox->refresh(true); 663 mbox->refresh(true);
639 if (v) { 664 if (v) {
640 v->setSelected(box,true); 665 v->setSelected(box,true);
641 } 666 }
642 } 667 }
643 } 668 }
644} 669}
645 670
646QPopupMenu * MBOXfolderItem::getContextMenu() 671QPopupMenu * MBOXfolderItem::getContextMenu()
647{ 672{
648 QPopupMenu *m = new QPopupMenu(0); 673 QPopupMenu *m = new QPopupMenu(0);
649 if (m) { 674 if (m) {
650 m->insertItem(QObject::tr("Delete all mails",contextName),0); 675 m->insertItem(QObject::tr("Delete all mails",contextName),0);
651 m->insertItem(QObject::tr("Delete folder",contextName),1); 676 m->insertItem(QObject::tr("Delete folder",contextName),1);
652 } 677 }
653 return m; 678 return m;
654} 679}
655 680
656void MBOXfolderItem::contextMenuSelected(int which) 681void MBOXfolderItem::contextMenuSelected(int which)
657{ 682{
658 switch(which) { 683 switch(which) {
659 case 0: 684 case 0:
660 deleteAllMail(mbox->getWrapper(),folder); 685 deleteAllMail(mbox->getWrapper(),folder);
661 break; 686 break;
662 case 1: 687 case 1:
663 deleteFolder(); 688 deleteFolder();
664 break; 689 break;
665 default: 690 default:
666 break; 691 break;
667 } 692 }
668} 693}
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h
index 1d2bf19..7131192 100644
--- a/noncore/net/mail/accountview.h
+++ b/noncore/net/mail/accountview.h
@@ -1,175 +1,179 @@
1#ifndef ACCOUNTVIEW_H 1#ifndef ACCOUNTVIEW_H
2#define ACCOUNTVIEW_H 2#define ACCOUNTVIEW_H
3 3
4#include <qlistview.h> 4#include <qlistview.h>
5#include <qlist.h> 5#include <qlist.h>
6 6
7#include <libmailwrapper/settings.h> 7#include <libmailwrapper/settings.h>
8#include <libmailwrapper/mailwrapper.h> 8#include <libmailwrapper/mailwrapper.h>
9#include <libmailwrapper/abstractmail.h> 9#include <libmailwrapper/abstractmail.h>
10 10
11class POP3wrapper; 11class POP3wrapper;
12class RecMail; 12class RecMail;
13class RecBody; 13class RecBody;
14class QPopupMenu; 14class QPopupMenu;
15 15
16class AccountViewItem : public QListViewItem 16class AccountViewItem : public QListViewItem
17{ 17{
18 18
19public: 19public:
20 AccountViewItem( QListView *parent ) : QListViewItem( parent ) {} 20 AccountViewItem( QListView *parent ) : QListViewItem( parent ) {}
21 AccountViewItem( QListViewItem *parent) : QListViewItem( parent) {} 21 AccountViewItem( QListViewItem *parent) : QListViewItem( parent) {}
22 AccountViewItem( QListViewItem *parent , QListViewItem*after ) : QListViewItem( parent,after ) {} 22 AccountViewItem( QListViewItem *parent , QListViewItem*after ) : QListViewItem( parent,after ) {}
23 virtual void refresh(QList<RecMail>&)=0; 23 virtual void refresh(QList<RecMail>&)=0;
24 virtual RecBody fetchBody(const RecMail&)=0; 24 virtual RecBody fetchBody(const RecMail&)=0;
25 virtual QPopupMenu * getContextMenu(){return 0;}; 25 virtual QPopupMenu * getContextMenu(){return 0;};
26 virtual void contextMenuSelected(int){} 26 virtual void contextMenuSelected(int){}
27protected: 27protected:
28 virtual void deleteAllMail(AbstractMail*wrapper,Folder*f); 28 virtual void deleteAllMail(AbstractMail*wrapper,Folder*f);
29 static const QString contextName; 29 static const QString contextName;
30}; 30};
31 31
32class POP3viewItem : public AccountViewItem 32class POP3viewItem : public AccountViewItem
33{ 33{
34 34
35public: 35public:
36 POP3viewItem( POP3account *a, QListView *parent ); 36 POP3viewItem( POP3account *a, QListView *parent );
37 ~POP3viewItem(); 37 ~POP3viewItem();
38 virtual void refresh( QList<RecMail> &target ); 38 virtual void refresh( QList<RecMail> &target );
39 virtual RecBody fetchBody( const RecMail &mail ); 39 virtual RecBody fetchBody( const RecMail &mail );
40 AbstractMail *getWrapper(); 40 AbstractMail *getWrapper();
41private: 41private:
42 POP3account *account; 42 POP3account *account;
43 AbstractMail *wrapper; 43 AbstractMail *wrapper;
44 44
45}; 45};
46 46
47class POP3folderItem : public AccountViewItem 47class POP3folderItem : public AccountViewItem
48{ 48{
49 49
50public: 50public:
51 POP3folderItem( Folder *folder, POP3viewItem *parent , QListViewItem*after ); 51 POP3folderItem( Folder *folder, POP3viewItem *parent , QListViewItem*after );
52 ~POP3folderItem(); 52 ~POP3folderItem();
53 virtual void refresh(QList<RecMail>&); 53 virtual void refresh(QList<RecMail>&);
54 virtual RecBody fetchBody(const RecMail&); 54 virtual RecBody fetchBody(const RecMail&);
55 virtual QPopupMenu * getContextMenu(); 55 virtual QPopupMenu * getContextMenu();
56 virtual void contextMenuSelected(int); 56 virtual void contextMenuSelected(int);
57 57
58protected:
59 void downloadMails();
60
58private: 61private:
59 Folder *folder; 62 Folder *folder;
60 POP3viewItem *pop3; 63 POP3viewItem *pop3;
61}; 64};
62 65
63class IMAPfolderItem; 66class IMAPfolderItem;
64 67
65class IMAPviewItem : public AccountViewItem 68class IMAPviewItem : public AccountViewItem
66{ 69{
67 friend class IMAPfolderItem; 70 friend class IMAPfolderItem;
68public: 71public:
69 IMAPviewItem( IMAPaccount *a, QListView *parent ); 72 IMAPviewItem( IMAPaccount *a, QListView *parent );
70 ~IMAPviewItem(); 73 ~IMAPviewItem();
71 virtual void refresh(QList<RecMail>&); 74 virtual void refresh(QList<RecMail>&);
72 virtual RecBody fetchBody(const RecMail&); 75 virtual RecBody fetchBody(const RecMail&);
73 AbstractMail *getWrapper(); 76 AbstractMail *getWrapper();
74 virtual QPopupMenu * getContextMenu(); 77 virtual QPopupMenu * getContextMenu();
75 virtual void contextMenuSelected(int); 78 virtual void contextMenuSelected(int);
76 79
77protected: 80protected:
78 IMAPfolderItem*findSubItem(const QString&path,IMAPfolderItem*start=0); 81 IMAPfolderItem*findSubItem(const QString&path,IMAPfolderItem*start=0);
79 virtual void refreshFolders(bool force=false); 82 virtual void refreshFolders(bool force=false);
80 virtual void createNewFolder(); 83 virtual void createNewFolder();
84 virtual void removeChilds();
81 85
82private: 86private:
83 IMAPaccount *account; 87 IMAPaccount *account;
84 AbstractMail *wrapper; 88 AbstractMail *wrapper;
85}; 89};
86 90
87class IMAPfolderItem : public AccountViewItem 91class IMAPfolderItem : public AccountViewItem
88{ 92{
89 93
90public: 94public:
91 IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after ); 95 IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after );
92 IMAPfolderItem( Folder *folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ); 96 IMAPfolderItem( Folder *folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master );
93 ~IMAPfolderItem(); 97 ~IMAPfolderItem();
94 virtual void refresh(QList<RecMail>&); 98 virtual void refresh(QList<RecMail>&);
95 virtual RecBody fetchBody(const RecMail&); 99 virtual RecBody fetchBody(const RecMail&);
96 bool matchName(const QString&name)const; 100 bool matchName(const QString&name)const;
97 virtual QPopupMenu * getContextMenu(); 101 virtual QPopupMenu * getContextMenu();
98 virtual void contextMenuSelected(int); 102 virtual void contextMenuSelected(int);
99 virtual const QString& Delemiter()const; 103 virtual const QString& Delemiter()const;
100protected: 104protected:
101 virtual void createNewFolder(); 105 virtual void createNewFolder();
102 virtual void deleteFolder(); 106 virtual void deleteFolder();
103 107
104private: 108private:
105 Folder *folder; 109 Folder *folder;
106 IMAPviewItem *imap; 110 IMAPviewItem *imap;
107}; 111};
108 112
109class MBOXviewItem : public AccountViewItem 113class MBOXviewItem : public AccountViewItem
110{ 114{
111 friend class MBOXfolderItem; 115 friend class MBOXfolderItem;
112 116
113public: 117public:
114// MBOXviewItem( MBOXaccount *a, QListView *parent ); 118// MBOXviewItem( MBOXaccount *a, QListView *parent );
115 MBOXviewItem( const QString&aMboxPath, QListView *parent ); 119 MBOXviewItem( const QString&aMboxPath, QListView *parent );
116 ~MBOXviewItem(); 120 ~MBOXviewItem();
117 virtual void refresh( QList<RecMail> &target ); 121 virtual void refresh( QList<RecMail> &target );
118 virtual RecBody fetchBody( const RecMail &mail ); 122 virtual RecBody fetchBody( const RecMail &mail );
119 AbstractMail *getWrapper(); 123 AbstractMail *getWrapper();
120 virtual QPopupMenu * getContextMenu(); 124 virtual QPopupMenu * getContextMenu();
121 virtual void contextMenuSelected(int); 125 virtual void contextMenuSelected(int);
122 126
123protected: 127protected:
124 virtual void refresh(bool force=false); 128 virtual void refresh(bool force=false);
125 virtual void createFolder(); 129 virtual void createFolder();
126 130
127private: 131private:
128// MBOXaccount *account; 132// MBOXaccount *account;
129 QString m_Path; 133 QString m_Path;
130 AbstractMail *wrapper; 134 AbstractMail *wrapper;
131 135
132}; 136};
133 137
134class MBOXfolderItem : public AccountViewItem 138class MBOXfolderItem : public AccountViewItem
135{ 139{
136 140
137public: 141public:
138 MBOXfolderItem( Folder *folder, MBOXviewItem *parent , QListViewItem*after ); 142 MBOXfolderItem( Folder *folder, MBOXviewItem *parent , QListViewItem*after );
139 ~MBOXfolderItem(); 143 ~MBOXfolderItem();
140 virtual void refresh(QList<RecMail>&); 144 virtual void refresh(QList<RecMail>&);
141 virtual RecBody fetchBody(const RecMail&); 145 virtual RecBody fetchBody(const RecMail&);
142 virtual QPopupMenu * getContextMenu(); 146 virtual QPopupMenu * getContextMenu();
143 virtual void contextMenuSelected(int); 147 virtual void contextMenuSelected(int);
144 148
145protected: 149protected:
146 virtual void deleteFolder(); 150 virtual void deleteFolder();
147private: 151private:
148 Folder *folder; 152 Folder *folder;
149 MBOXviewItem *mbox; 153 MBOXviewItem *mbox;
150}; 154};
151 155
152class AccountView : public QListView 156class AccountView : public QListView
153{ 157{
154 Q_OBJECT 158 Q_OBJECT
155 159
156public: 160public:
157 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 161 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
158 void populate( QList<Account> list ); 162 void populate( QList<Account> list );
159 RecBody fetchBody(const RecMail&aMail); 163 RecBody fetchBody(const RecMail&aMail);
160 164
161public slots: 165public slots:
162 virtual void refreshAll(); 166 virtual void refreshAll();
163 virtual void refresh(QListViewItem *item); 167 virtual void refresh(QListViewItem *item);
164 virtual void refreshCurrent(); 168 virtual void refreshCurrent();
165 virtual void slotHold(int, QListViewItem *,const QPoint&,int); 169 virtual void slotHold(int, QListViewItem *,const QPoint&,int);
166 virtual void slotContextMenu(int id); 170 virtual void slotContextMenu(int id);
167 171
168signals: 172signals:
169 void refreshMailview(QList<RecMail>*); 173 void refreshMailview(QList<RecMail>*);
170 174
171private: 175private:
172 QListViewItem* m_currentItem; 176 QListViewItem* m_currentItem;
173}; 177};
174 178
175#endif 179#endif
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h
index 7c060db..9770991 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.h
+++ b/noncore/net/mail/libmailwrapper/abstractmail.h
@@ -1,59 +1,60 @@
1#ifndef __abstract_mail_ 1#ifndef __abstract_mail_
2#define __abstract_mail_ 2#define __abstract_mail_
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include "settings.h" 5#include "settings.h"
6 6
7class RecMail; 7class RecMail;
8class RecBody; 8class RecBody;
9class RecPart; 9class RecPart;
10class IMAPwrapper; 10class IMAPwrapper;
11class POP3wrapper; 11class POP3wrapper;
12class Folder; 12class Folder;
13class encodedString; 13class encodedString;
14struct folderStat; 14struct folderStat;
15 15
16class AbstractMail:public QObject 16class AbstractMail:public QObject
17{ 17{
18 Q_OBJECT 18 Q_OBJECT
19public: 19public:
20 AbstractMail(){}; 20 AbstractMail(){};
21 virtual ~AbstractMail(){} 21 virtual ~AbstractMail(){}
22 virtual QList<Folder>* listFolders()=0; 22 virtual QList<Folder>* listFolders()=0;
23 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; 23 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0; 24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0;
25 virtual RecBody fetchBody(const RecMail&mail)=0; 25 virtual RecBody fetchBody(const RecMail&mail)=0;
26 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; 26 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
27 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; 27 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
28 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; 28 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
29 virtual encodedString* fetchRawBody(const RecMail&mail)=0;
29 30
30 virtual void deleteMail(const RecMail&mail)=0; 31 virtual void deleteMail(const RecMail&mail)=0;
31 virtual void answeredMail(const RecMail&mail)=0; 32 virtual void answeredMail(const RecMail&mail)=0;
32 virtual int deleteAllMail(const Folder*)=0; 33 virtual int deleteAllMail(const Folder*)=0;
33 virtual int deleteMbox(const Folder*)=0; 34 virtual int deleteMbox(const Folder*)=0;
34 virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0; 35 virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0;
35 36
36 virtual void cleanMimeCache(){}; 37 virtual void cleanMimeCache(){};
37 /* mail box methods */ 38 /* mail box methods */
38 /* parameter is the box to create. 39 /* parameter is the box to create.
39 * if the implementing subclass has prefixes, 40 * if the implementing subclass has prefixes,
40 * them has to be appended automatic. 41 * them has to be appended automatic.
41 */ 42 */
42 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); 43 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
43 virtual void logout()=0; 44 virtual void logout()=0;
44 45
45 static AbstractMail* getWrapper(IMAPaccount *a); 46 static AbstractMail* getWrapper(IMAPaccount *a);
46 static AbstractMail* getWrapper(POP3account *a); 47 static AbstractMail* getWrapper(POP3account *a);
47 /* mbox only! */ 48 /* mbox only! */
48 static AbstractMail* getWrapper(const QString&a); 49 static AbstractMail* getWrapper(const QString&a);
49 50
50 static QString defaultLocalfolder(); 51 static QString defaultLocalfolder();
51 52
52 virtual const QString&getType()const=0; 53 virtual const QString&getType()const=0;
53 54
54protected: 55protected:
55 static encodedString*decode_String(const encodedString*text,const QString&enc); 56 static encodedString*decode_String(const encodedString*text,const QString&enc);
56 static QString convert_String(const char*text); 57 static QString convert_String(const char*text);
57 static QString gen_attachment_id(); 58 static QString gen_attachment_id();
58}; 59};
59#endif 60#endif
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 95b317a..d252159 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,992 +1,1014 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <libetpan/libetpan.h> 2#include <libetpan/libetpan.h>
3#include <qpe/global.h> 3#include <qpe/global.h>
4 4
5#include "imapwrapper.h" 5#include "imapwrapper.h"
6#include "mailtypes.h" 6#include "mailtypes.h"
7#include "logindialog.h" 7#include "logindialog.h"
8 8
9IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 9IMAPwrapper::IMAPwrapper( IMAPaccount *a )
10 : AbstractMail() 10 : AbstractMail()
11{ 11{
12 account = a; 12 account = a;
13 m_imap = 0; 13 m_imap = 0;
14} 14}
15 15
16IMAPwrapper::~IMAPwrapper() 16IMAPwrapper::~IMAPwrapper()
17{ 17{
18 logout(); 18 logout();
19} 19}
20 20
21void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 21void IMAPwrapper::imap_progress( size_t current, size_t maximum )
22{ 22{
23 qDebug( "IMAP: %i of %i", current, maximum ); 23 qDebug( "IMAP: %i of %i", current, maximum );
24} 24}
25 25
26void IMAPwrapper::login() 26void IMAPwrapper::login()
27{ 27{
28 const char *server, *user, *pass; 28 const char *server, *user, *pass;
29 uint16_t port; 29 uint16_t port;
30 int err = MAILIMAP_NO_ERROR; 30 int err = MAILIMAP_NO_ERROR;
31 31
32 /* we are connected this moment */ 32 /* we are connected this moment */
33 /* 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 */
34 if (m_imap) { 34 if (m_imap) {
35 err = mailimap_noop(m_imap); 35 err = mailimap_noop(m_imap);
36 if (err!=MAILIMAP_NO_ERROR) { 36 if (err!=MAILIMAP_NO_ERROR) {
37 logout(); 37 logout();
38 } else { 38 } else {
39 mailstream_flush(m_imap->imap_stream); 39 mailstream_flush(m_imap->imap_stream);
40 return; 40 return;
41 } 41 }
42 } 42 }
43 server = account->getServer().latin1(); 43 server = account->getServer().latin1();
44 port = account->getPort().toUInt(); 44 port = account->getPort().toUInt();
45 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 45 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
46 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 46 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
47 login.show(); 47 login.show();
48 if ( QDialog::Accepted == login.exec() ) { 48 if ( QDialog::Accepted == login.exec() ) {
49 // ok 49 // ok
50 user = login.getUser().latin1(); 50 user = login.getUser().latin1();
51 pass = login.getPassword().latin1(); 51 pass = login.getPassword().latin1();
52 } else { 52 } else {
53 // cancel 53 // cancel
54 qDebug( "IMAP: Login canceled" ); 54 qDebug( "IMAP: Login canceled" );
55 return; 55 return;
56 } 56 }
57 } else { 57 } else {
58 user = account->getUser().latin1(); 58 user = account->getUser().latin1();
59 pass = account->getPassword().latin1(); 59 pass = account->getPassword().latin1();
60 } 60 }
61 61
62 m_imap = mailimap_new( 20, &imap_progress ); 62 m_imap = mailimap_new( 20, &imap_progress );
63 63
64 /* connect */ 64 /* connect */
65 if (account->getSSL()) { 65 if (account->getSSL()) {
66 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 66 err = mailimap_ssl_connect( m_imap, (char*)server, port );
67 } else { 67 } else {
68 err = mailimap_socket_connect( m_imap, (char*)server, port ); 68 err = mailimap_socket_connect( m_imap, (char*)server, port );
69 } 69 }
70 70
71 if ( err != MAILIMAP_NO_ERROR && 71 if ( err != MAILIMAP_NO_ERROR &&
72 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 72 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
73 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 73 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
74 QString failure = ""; 74 QString failure = "";
75 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 75 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
76 failure="Connection refused"; 76 failure="Connection refused";
77 } else { 77 } else {
78 failure="Unknown failure"; 78 failure="Unknown failure";
79 } 79 }
80 Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); 80 Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
81 mailimap_free( m_imap ); 81 mailimap_free( m_imap );
82 m_imap = 0; 82 m_imap = 0;
83 return; 83 return;
84 } 84 }
85 85
86 /* login */ 86 /* login */
87 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 87 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
88 if ( err != MAILIMAP_NO_ERROR ) { 88 if ( err != MAILIMAP_NO_ERROR ) {
89 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); 89 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
90 err = mailimap_close( m_imap ); 90 err = mailimap_close( m_imap );
91 mailimap_free( m_imap ); 91 mailimap_free( m_imap );
92 m_imap = 0; 92 m_imap = 0;
93 } 93 }
94} 94}
95 95
96void IMAPwrapper::logout() 96void IMAPwrapper::logout()
97{ 97{
98 int err = MAILIMAP_NO_ERROR; 98 int err = MAILIMAP_NO_ERROR;
99 if (!m_imap) return; 99 if (!m_imap) return;
100 err = mailimap_logout( m_imap ); 100 err = mailimap_logout( m_imap );
101 err = mailimap_close( m_imap ); 101 err = mailimap_close( m_imap );
102 mailimap_free( m_imap ); 102 mailimap_free( m_imap );
103 m_imap = 0; 103 m_imap = 0;
104} 104}
105 105
106void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 106void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
107{ 107{
108 const char *mb = 0; 108 const char *mb = 0;
109 int err = MAILIMAP_NO_ERROR; 109 int err = MAILIMAP_NO_ERROR;
110 clist *result = 0; 110 clist *result = 0;
111 clistcell *current; 111 clistcell *current;
112// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 112// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
113 mailimap_fetch_type *fetchType = 0; 113 mailimap_fetch_type *fetchType = 0;
114 mailimap_set *set = 0; 114 mailimap_set *set = 0;
115 115
116 mb = mailbox.latin1(); 116 mb = mailbox.latin1();
117 login(); 117 login();
118 if (!m_imap) { 118 if (!m_imap) {
119 return; 119 return;
120 } 120 }
121 /* select mailbox READONLY for operations */ 121 /* select mailbox READONLY for operations */
122 err = mailimap_examine( m_imap, (char*)mb); 122 err = mailimap_examine( m_imap, (char*)mb);
123 if ( err != MAILIMAP_NO_ERROR ) { 123 if ( err != MAILIMAP_NO_ERROR ) {
124 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response)); 124 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response));
125 return; 125 return;
126 } 126 }
127 127
128 int last = m_imap->imap_selection_info->sel_exists; 128 int last = m_imap->imap_selection_info->sel_exists;
129 129
130 if (last == 0) { 130 if (last == 0) {
131 Global::statusMessage(tr("Mailbox has no mails")); 131 Global::statusMessage(tr("Mailbox has no mails"));
132 return; 132 return;
133 } else { 133 } else {
134 Global::statusMessage(tr("Mailbox has %1 mails").arg(last)); 134 Global::statusMessage(tr("Mailbox has %1 mails").arg(last));
135 } 135 }
136 136
137 /* the range has to start at 1!!! not with 0!!!! */ 137 /* the range has to start at 1!!! not with 0!!!! */
138 set = mailimap_set_new_interval( 1, last ); 138 set = mailimap_set_new_interval( 1, last );
139 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 139 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
140 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 140 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
141 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 141 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
142 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 142 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
143 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 143 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
144 144
145 err = mailimap_fetch( m_imap, set, fetchType, &result ); 145 err = mailimap_fetch( m_imap, set, fetchType, &result );
146 mailimap_set_free( set ); 146 mailimap_set_free( set );
147 mailimap_fetch_type_free( fetchType ); 147 mailimap_fetch_type_free( fetchType );
148 148
149 QString date,subject,from; 149 QString date,subject,from;
150 150
151 if ( err == MAILIMAP_NO_ERROR ) { 151 if ( err == MAILIMAP_NO_ERROR ) {
152 mailimap_msg_att * msg_att; 152 mailimap_msg_att * msg_att;
153 int i = 0; 153 int i = 0;
154 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 154 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
155 ++i; 155 ++i;
156 msg_att = (mailimap_msg_att*)current->data; 156 msg_att = (mailimap_msg_att*)current->data;
157 RecMail*m = parse_list_result(msg_att); 157 RecMail*m = parse_list_result(msg_att);
158 if (m) { 158 if (m) {
159 m->setNumber(i); 159 m->setNumber(i);
160 m->setMbox(mailbox); 160 m->setMbox(mailbox);
161 m->setWrapper(this); 161 m->setWrapper(this);
162 target.append(m); 162 target.append(m);
163 } 163 }
164 } 164 }
165 } else { 165 } else {
166 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); 166 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
167 } 167 }
168 if (result) mailimap_fetch_list_free(result); 168 if (result) mailimap_fetch_list_free(result);
169} 169}
170 170
171QList<Folder>* IMAPwrapper::listFolders() 171QList<Folder>* IMAPwrapper::listFolders()
172{ 172{
173 const char *path, *mask; 173 const char *path, *mask;
174 int err = MAILIMAP_NO_ERROR; 174 int err = MAILIMAP_NO_ERROR;
175 clist *result = 0; 175 clist *result = 0;
176 clistcell *current = 0; 176 clistcell *current = 0;
177 clistcell*cur_flag = 0; 177 clistcell*cur_flag = 0;
178 mailimap_mbx_list_flags*bflags = 0; 178 mailimap_mbx_list_flags*bflags = 0;
179 179
180 QList<Folder> * folders = new QList<Folder>(); 180 QList<Folder> * folders = new QList<Folder>();
181 folders->setAutoDelete( false ); 181 folders->setAutoDelete( false );
182 login(); 182 login();
183 if (!m_imap) { 183 if (!m_imap) {
184 return folders; 184 return folders;
185 } 185 }
186 186
187/* 187/*
188 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 188 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
189 * We must not forget to filter them out in next loop! 189 * We must not forget to filter them out in next loop!
190 * it seems like ugly code. and yes - it is ugly code. but the best way. 190 * it seems like ugly code. and yes - it is ugly code. but the best way.
191 */ 191 */
192 QString temp; 192 QString temp;
193 mask = "INBOX" ; 193 mask = "INBOX" ;
194 mailimap_mailbox_list *list; 194 mailimap_mailbox_list *list;
195 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 195 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
196 QString del; 196 QString del;
197 bool selectable = true; 197 bool selectable = true;
198 bool no_inferiors = false; 198 bool no_inferiors = false;
199 if ( err == MAILIMAP_NO_ERROR ) { 199 if ( err == MAILIMAP_NO_ERROR ) {
200 current = result->first; 200 current = result->first;
201 for ( int i = result->count; i > 0; i-- ) { 201 for ( int i = result->count; i > 0; i-- ) {
202 list = (mailimap_mailbox_list *) current->data; 202 list = (mailimap_mailbox_list *) current->data;
203 // it is better use the deep copy mechanism of qt itself 203 // it is better use the deep copy mechanism of qt itself
204 // instead of using strdup! 204 // instead of using strdup!
205 temp = list->mb_name; 205 temp = list->mb_name;
206 del = list->mb_delimiter; 206 del = list->mb_delimiter;
207 current = current->next; 207 current = current->next;
208 if ( (bflags = list->mb_flag) ) { 208 if ( (bflags = list->mb_flag) ) {
209 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 209 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
210 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 210 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
211 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 211 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
212 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 212 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
213 no_inferiors = true; 213 no_inferiors = true;
214 } 214 }
215 } 215 }
216 } 216 }
217 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 217 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
218 } 218 }
219 } else { 219 } else {
220 qDebug("error fetching folders: %s",m_imap->imap_response); 220 qDebug("error fetching folders: %s",m_imap->imap_response);
221 } 221 }
222 mailimap_list_result_free( result ); 222 mailimap_list_result_free( result );
223 223
224/* 224/*
225 * second stage - get the other then inbox folders 225 * second stage - get the other then inbox folders
226 */ 226 */
227 mask = "*" ; 227 mask = "*" ;
228 path = account->getPrefix().latin1(); 228 path = account->getPrefix().latin1();
229 if (!path) path = ""; 229 if (!path) path = "";
230 qDebug(path); 230 qDebug(path);
231 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 231 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
232 if ( err == MAILIMAP_NO_ERROR ) { 232 if ( err == MAILIMAP_NO_ERROR ) {
233 current = result->first; 233 current = result->first;
234 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 234 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
235 no_inferiors = false; 235 no_inferiors = false;
236 list = (mailimap_mailbox_list *) current->data; 236 list = (mailimap_mailbox_list *) current->data;
237 // it is better use the deep copy mechanism of qt itself 237 // it is better use the deep copy mechanism of qt itself
238 // instead of using strdup! 238 // instead of using strdup!
239 temp = list->mb_name; 239 temp = list->mb_name;
240 if (temp.lower()=="inbox") 240 if (temp.lower()=="inbox")
241 continue; 241 continue;
242 if (temp.lower()==account->getPrefix().lower()) 242 if (temp.lower()==account->getPrefix().lower())
243 continue; 243 continue;
244 if ( (bflags = list->mb_flag) ) { 244 if ( (bflags = list->mb_flag) ) {
245 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 245 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
246 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 246 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
247 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 247 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
248 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 248 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
249 no_inferiors = true; 249 no_inferiors = true;
250 } 250 }
251 } 251 }
252 } 252 }
253 del = list->mb_delimiter; 253 del = list->mb_delimiter;
254 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 254 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
255 } 255 }
256 } else { 256 } else {
257 qDebug("error fetching folders %s",m_imap->imap_response); 257 qDebug("error fetching folders %s",m_imap->imap_response);
258 } 258 }
259 if (result) mailimap_list_result_free( result ); 259 if (result) mailimap_list_result_free( result );
260 return folders; 260 return folders;
261} 261}
262 262
263RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 263RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
264{ 264{
265 RecMail * m = 0; 265 RecMail * m = 0;
266 mailimap_msg_att_item *item=0; 266 mailimap_msg_att_item *item=0;
267 clistcell *current,*c,*cf; 267 clistcell *current,*c,*cf;
268 mailimap_msg_att_dynamic*flist; 268 mailimap_msg_att_dynamic*flist;
269 mailimap_flag_fetch*cflag; 269 mailimap_flag_fetch*cflag;
270 int size; 270 int size;
271 QBitArray mFlags(7); 271 QBitArray mFlags(7);
272 QStringList addresslist; 272 QStringList addresslist;
273 273
274 if (!m_att) { 274 if (!m_att) {
275 return m; 275 return m;
276 } 276 }
277 m = new RecMail(); 277 m = new RecMail();
278 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 278 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
279 current = c; 279 current = c;
280 size = 0; 280 size = 0;
281 item = (mailimap_msg_att_item*)current->data; 281 item = (mailimap_msg_att_item*)current->data;
282 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 282 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
283 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 283 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
284 if (!flist->att_list) { 284 if (!flist->att_list) {
285 continue; 285 continue;
286 } 286 }
287 cf = flist->att_list->first; 287 cf = flist->att_list->first;
288 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 288 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
289 cflag = (mailimap_flag_fetch*)cf->data; 289 cflag = (mailimap_flag_fetch*)cf->data;
290 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 290 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
291 switch (cflag->fl_flag->fl_type) { 291 switch (cflag->fl_flag->fl_type) {
292 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 292 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
293 mFlags.setBit(FLAG_ANSWERED); 293 mFlags.setBit(FLAG_ANSWERED);
294 break; 294 break;
295 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 295 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
296 mFlags.setBit(FLAG_FLAGGED); 296 mFlags.setBit(FLAG_FLAGGED);
297 break; 297 break;
298 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 298 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
299 mFlags.setBit(FLAG_DELETED); 299 mFlags.setBit(FLAG_DELETED);
300 break; 300 break;
301 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 301 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
302 mFlags.setBit(FLAG_SEEN); 302 mFlags.setBit(FLAG_SEEN);
303 break; 303 break;
304 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 304 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
305 mFlags.setBit(FLAG_DRAFT); 305 mFlags.setBit(FLAG_DRAFT);
306 break; 306 break;
307 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 307 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
308 break; 308 break;
309 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 309 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
310 break; 310 break;
311 default: 311 default:
312 break; 312 break;
313 } 313 }
314 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 314 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
315 mFlags.setBit(FLAG_RECENT); 315 mFlags.setBit(FLAG_RECENT);
316 } 316 }
317 } 317 }
318 continue; 318 continue;
319 } 319 }
320 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 320 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
321 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 321 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
322 m->setDate(head->env_date); 322 m->setDate(head->env_date);
323 m->setSubject(convert_String((const char*)head->env_subject)); 323 m->setSubject(convert_String((const char*)head->env_subject));
324 //m->setSubject(head->env_subject); 324 //m->setSubject(head->env_subject);
325 if (head->env_from!=NULL) { 325 if (head->env_from!=NULL) {
326 addresslist = address_list_to_stringlist(head->env_from->frm_list); 326 addresslist = address_list_to_stringlist(head->env_from->frm_list);
327 if (addresslist.count()) { 327 if (addresslist.count()) {
328 m->setFrom(addresslist.first()); 328 m->setFrom(addresslist.first());
329 } 329 }
330 } 330 }
331 if (head->env_to!=NULL) { 331 if (head->env_to!=NULL) {
332 addresslist = address_list_to_stringlist(head->env_to->to_list); 332 addresslist = address_list_to_stringlist(head->env_to->to_list);
333 m->setTo(addresslist); 333 m->setTo(addresslist);
334 } 334 }
335 if (head->env_cc!=NULL) { 335 if (head->env_cc!=NULL) {
336 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 336 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
337 m->setCC(addresslist); 337 m->setCC(addresslist);
338 } 338 }
339 if (head->env_bcc!=NULL) { 339 if (head->env_bcc!=NULL) {
340 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 340 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
341 m->setBcc(addresslist); 341 m->setBcc(addresslist);
342 } 342 }
343 if (head->env_reply_to!=NULL) { 343 if (head->env_reply_to!=NULL) {
344 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 344 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
345 if (addresslist.count()) { 345 if (addresslist.count()) {
346 m->setReplyto(addresslist.first()); 346 m->setReplyto(addresslist.first());
347 } 347 }
348 } 348 }
349 m->setMsgid(QString(head->env_message_id)); 349 m->setMsgid(QString(head->env_message_id));
350 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 350 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
351#if 0 351#if 0
352 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 352 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
353 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 353 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
354 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); 354 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);
355 qDebug(da.toString()); 355 qDebug(da.toString());
356#endif 356#endif
357 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 357 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
358 size = item->att_data.att_static->att_data.att_rfc822_size; 358 size = item->att_data.att_static->att_data.att_rfc822_size;
359 } 359 }
360 } 360 }
361 /* msg is already deleted */ 361 /* msg is already deleted */
362 if (mFlags.testBit(FLAG_DELETED) && m) { 362 if (mFlags.testBit(FLAG_DELETED) && m) {
363 delete m; 363 delete m;
364 m = 0; 364 m = 0;
365 } 365 }
366 if (m) { 366 if (m) {
367 m->setFlags(mFlags); 367 m->setFlags(mFlags);
368 m->setMsgsize(size); 368 m->setMsgsize(size);
369 } 369 }
370 return m; 370 return m;
371} 371}
372 372
373RecBody IMAPwrapper::fetchBody(const RecMail&mail) 373RecBody IMAPwrapper::fetchBody(const RecMail&mail)
374{ 374{
375 RecBody body; 375 RecBody body;
376 const char *mb; 376 const char *mb;
377 int err = MAILIMAP_NO_ERROR; 377 int err = MAILIMAP_NO_ERROR;
378 clist *result = 0; 378 clist *result = 0;
379 clistcell *current; 379 clistcell *current;
380 mailimap_fetch_att *fetchAtt = 0; 380 mailimap_fetch_att *fetchAtt = 0;
381 mailimap_fetch_type *fetchType = 0; 381 mailimap_fetch_type *fetchType = 0;
382 mailimap_set *set = 0; 382 mailimap_set *set = 0;
383 mailimap_body*body_desc = 0; 383 mailimap_body*body_desc = 0;
384 384
385 mb = mail.getMbox().latin1(); 385 mb = mail.getMbox().latin1();
386 386
387 login(); 387 login();
388 if (!m_imap) { 388 if (!m_imap) {
389 return body; 389 return body;
390 } 390 }
391 391
392 err = mailimap_select( m_imap, (char*)mb); 392 err = mailimap_select( m_imap, (char*)mb);
393 if ( err != MAILIMAP_NO_ERROR ) { 393 if ( err != MAILIMAP_NO_ERROR ) {
394 qDebug("error selecting mailbox: %s",m_imap->imap_response); 394 qDebug("error selecting mailbox: %s",m_imap->imap_response);
395 return body; 395 return body;
396 } 396 }
397 397
398 /* the range has to start at 1!!! not with 0!!!! */ 398 /* the range has to start at 1!!! not with 0!!!! */
399 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 399 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
400 fetchAtt = mailimap_fetch_att_new_bodystructure(); 400 fetchAtt = mailimap_fetch_att_new_bodystructure();
401 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 401 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
402 err = mailimap_fetch( m_imap, set, fetchType, &result ); 402 err = mailimap_fetch( m_imap, set, fetchType, &result );
403 mailimap_set_free( set ); 403 mailimap_set_free( set );
404 mailimap_fetch_type_free( fetchType ); 404 mailimap_fetch_type_free( fetchType );
405 405
406 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 406 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
407 mailimap_msg_att * msg_att; 407 mailimap_msg_att * msg_att;
408 msg_att = (mailimap_msg_att*)current->data; 408 msg_att = (mailimap_msg_att*)current->data;
409 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 409 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
410 QValueList<int> path; 410 QValueList<int> path;
411 body_desc = item->att_data.att_static->att_data.att_body; 411 body_desc = item->att_data.att_static->att_data.att_body;
412 traverseBody(mail,body_desc,body,0,path); 412 traverseBody(mail,body_desc,body,0,path);
413 } else { 413 } else {
414 qDebug("error fetching body: %s",m_imap->imap_response); 414 qDebug("error fetching body: %s",m_imap->imap_response);
415 } 415 }
416 if (result) mailimap_fetch_list_free(result); 416 if (result) mailimap_fetch_list_free(result);
417 return body; 417 return body;
418} 418}
419 419
420QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 420QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
421{ 421{
422 QStringList l; 422 QStringList l;
423 QString from; 423 QString from;
424 bool named_from; 424 bool named_from;
425 clistcell *current = NULL; 425 clistcell *current = NULL;
426 mailimap_address * current_address=NULL; 426 mailimap_address * current_address=NULL;
427 if (!list) { 427 if (!list) {
428 return l; 428 return l;
429 } 429 }
430 unsigned int count = 0; 430 unsigned int count = 0;
431 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 431 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
432 from = ""; 432 from = "";
433 named_from = false; 433 named_from = false;
434 current_address=(mailimap_address*)current->data; 434 current_address=(mailimap_address*)current->data;
435 if (current_address->ad_personal_name){ 435 if (current_address->ad_personal_name){
436 from+=convert_String((const char*)current_address->ad_personal_name); 436 from+=convert_String((const char*)current_address->ad_personal_name);
437 from+=" "; 437 from+=" ";
438 named_from = true; 438 named_from = true;
439 } 439 }
440 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 440 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
441 from+="<"; 441 from+="<";
442 } 442 }
443 if (current_address->ad_mailbox_name) { 443 if (current_address->ad_mailbox_name) {
444 from+=QString(current_address->ad_mailbox_name); 444 from+=QString(current_address->ad_mailbox_name);
445 from+="@"; 445 from+="@";
446 } 446 }
447 if (current_address->ad_host_name) { 447 if (current_address->ad_host_name) {
448 from+=QString(current_address->ad_host_name); 448 from+=QString(current_address->ad_host_name);
449 } 449 }
450 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 450 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
451 from+=">"; 451 from+=">";
452 } 452 }
453 l.append(QString(from)); 453 l.append(QString(from));
454 if (++count > 99) { 454 if (++count > 99) {
455 break; 455 break;
456 } 456 }
457 } 457 }
458 return l; 458 return l;
459} 459}
460 460
461encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 461encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
462{ 462{
463 encodedString*res=new encodedString; 463 encodedString*res=new encodedString;
464 const char*mb; 464 const char*mb;
465 int err; 465 int err;
466 mailimap_fetch_type *fetchType; 466 mailimap_fetch_type *fetchType;
467 mailimap_set *set; 467 mailimap_set *set;
468 clistcell*current,*cur; 468 clistcell*current,*cur;
469 mailimap_section_part * section_part = 0;
470 mailimap_section_spec * section_spec = 0;
471 mailimap_section * section = 0;
472 mailimap_fetch_att * fetch_att = 0;
469 473
470 login(); 474 login();
471 if (!m_imap) { 475 if (!m_imap) {
472 return res; 476 return res;
473 } 477 }
474 if (!internal_call) { 478 if (!internal_call) {
475 mb = mail.getMbox().latin1(); 479 mb = mail.getMbox().latin1();
476 err = mailimap_select( m_imap, (char*)mb); 480 err = mailimap_select( m_imap, (char*)mb);
477 if ( err != MAILIMAP_NO_ERROR ) { 481 if ( err != MAILIMAP_NO_ERROR ) {
478 qDebug("error selecting mailbox: %s",m_imap->imap_response); 482 qDebug("error selecting mailbox: %s",m_imap->imap_response);
479 return res; 483 return res;
480 } 484 }
481 } 485 }
482 set = mailimap_set_new_single(mail.getNumber()); 486 set = mailimap_set_new_single(mail.getNumber());
483 clist*id_list=clist_new();
484 for (unsigned j=0; j < path.count();++j) {
485 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
486 *p_id = path[j];
487 clist_append(id_list,p_id);
488 }
489 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
490 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
491 mailimap_section * section = mailimap_section_new(section_spec);
492 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
493 487
488 clist*id_list = 0;
489
490 /* if path == empty then its a request for the whole rfc822 mail and generates
491 a "fetch <id> (body[])" statement on imap server */
492 if (path.count()>0 ) {
493 id_list = clist_new();
494 for (unsigned j=0; j < path.count();++j) {
495 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
496 *p_id = path[j];
497 clist_append(id_list,p_id);
498 }
499 section_part = mailimap_section_part_new(id_list);
500 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
501 }
502
503 section = mailimap_section_new(section_spec);
504 fetch_att = mailimap_fetch_att_new_body_section(section);
494 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 505 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
495 506
496 clist*result = 0; 507 clist*result = 0;
497 508
498 err = mailimap_fetch( m_imap, set, fetchType, &result ); 509 err = mailimap_fetch( m_imap, set, fetchType, &result );
499 mailimap_set_free( set ); 510 mailimap_set_free( set );
500 mailimap_fetch_type_free( fetchType ); 511 mailimap_fetch_type_free( fetchType );
501 512
502 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 513 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
503 mailimap_msg_att * msg_att; 514 mailimap_msg_att * msg_att;
504 msg_att = (mailimap_msg_att*)current->data; 515 msg_att = (mailimap_msg_att*)current->data;
505 mailimap_msg_att_item*msg_att_item; 516 mailimap_msg_att_item*msg_att_item;
506 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 517 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
507 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 518 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
508 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 519 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
509 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 520 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
510 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 521 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
511 /* detach - we take over the content */ 522 /* detach - we take over the content */
512 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 523 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
513 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 524 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
514 } 525 }
515 } 526 }
516 } 527 }
517 } else { 528 } else {
518 qDebug("error fetching text: %s",m_imap->imap_response); 529 qDebug("error fetching text: %s",m_imap->imap_response);
519 } 530 }
520 if (result) mailimap_fetch_list_free(result); 531 if (result) mailimap_fetch_list_free(result);
521 return res; 532 return res;
522} 533}
523 534
524/* current_recursion is for recursive calls. 535/* current_recursion is for recursive calls.
525 current_count means the position inside the internal loop! */ 536 current_count means the position inside the internal loop! */
526void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, 537void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,
527 int current_recursion,QValueList<int>recList,int current_count) 538 int current_recursion,QValueList<int>recList,int current_count)
528{ 539{
529 if (!body || current_recursion>=10) { 540 if (!body || current_recursion>=10) {
530 return; 541 return;
531 } 542 }
532 switch (body->bd_type) { 543 switch (body->bd_type) {
533 case MAILIMAP_BODY_1PART: 544 case MAILIMAP_BODY_1PART:
534 { 545 {
535 QValueList<int>countlist = recList; 546 QValueList<int>countlist = recList;
536 countlist.append(current_count); 547 countlist.append(current_count);
537 RecPart currentPart; 548 RecPart currentPart;
538 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 549 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
539 QString id(""); 550 QString id("");
540 currentPart.setPositionlist(countlist); 551 currentPart.setPositionlist(countlist);
541 for (unsigned int j = 0; j < countlist.count();++j) { 552 for (unsigned int j = 0; j < countlist.count();++j) {
542 id+=(j>0?" ":""); 553 id+=(j>0?" ":"");
543 id+=QString("%1").arg(countlist[j]); 554 id+=QString("%1").arg(countlist[j]);
544 } 555 }
545 qDebug("ID = %s",id.latin1()); 556 qDebug("ID = %s",id.latin1());
546 currentPart.setIdentifier(id); 557 currentPart.setIdentifier(id);
547 fillSinglePart(currentPart,part1); 558 fillSinglePart(currentPart,part1);
548 /* important: Check for is NULL 'cause a body can be empty! 559 /* important: Check for is NULL 'cause a body can be empty!
549 And we put it only into the mail if it is the FIRST part */ 560 And we put it only into the mail if it is the FIRST part */
550 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { 561 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) {
551 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); 562 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding());
552 target_body.setDescription(currentPart); 563 target_body.setDescription(currentPart);
553 target_body.setBodytext(body_text); 564 target_body.setBodytext(body_text);
554 if (countlist.count()>1) { 565 if (countlist.count()>1) {
555 target_body.addPart(currentPart); 566 target_body.addPart(currentPart);
556 } 567 }
557 } else { 568 } else {
558 target_body.addPart(currentPart); 569 target_body.addPart(currentPart);
559 } 570 }
560 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 571 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
561 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); 572 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
562 } 573 }
563 } 574 }
564 break; 575 break;
565 case MAILIMAP_BODY_MPART: 576 case MAILIMAP_BODY_MPART:
566 { 577 {
567 QValueList<int>countlist = recList; 578 QValueList<int>countlist = recList;
568 clistcell*current=0; 579 clistcell*current=0;
569 mailimap_body*current_body=0; 580 mailimap_body*current_body=0;
570 unsigned int ccount = 1; 581 unsigned int ccount = 1;
571 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 582 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
572 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 583 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
573 current_body = (mailimap_body*)current->data; 584 current_body = (mailimap_body*)current->data;
574 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 585 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
575 RecPart targetPart; 586 RecPart targetPart;
576 targetPart.setType("multipart"); 587 targetPart.setType("multipart");
577 fillMultiPart(targetPart,mailDescription); 588 fillMultiPart(targetPart,mailDescription);
578 countlist.append(current_count); 589 countlist.append(current_count);
579 targetPart.setPositionlist(countlist); 590 targetPart.setPositionlist(countlist);
580 target_body.addPart(targetPart); 591 target_body.addPart(targetPart);
581 QString id(""); 592 QString id("");
582 for (unsigned int j = 0; j < countlist.count();++j) { 593 for (unsigned int j = 0; j < countlist.count();++j) {
583 id+=(j>0?" ":""); 594 id+=(j>0?" ":"");
584 id+=QString("%1").arg(countlist[j]); 595 id+=QString("%1").arg(countlist[j]);
585 } 596 }
586 qDebug("ID(mpart) = %s",id.latin1()); 597 qDebug("ID(mpart) = %s",id.latin1());
587 } 598 }
588 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); 599 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
589 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 600 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
590 countlist = recList; 601 countlist = recList;
591 } 602 }
592 ++ccount; 603 ++ccount;
593 } 604 }
594 } 605 }
595 break; 606 break;
596 default: 607 default:
597 break; 608 break;
598 } 609 }
599} 610}
600 611
601void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 612void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
602{ 613{
603 if (!Description) { 614 if (!Description) {
604 return; 615 return;
605 } 616 }
606 switch (Description->bd_type) { 617 switch (Description->bd_type) {
607 case MAILIMAP_BODY_TYPE_1PART_TEXT: 618 case MAILIMAP_BODY_TYPE_1PART_TEXT:
608 target_part.setType("text"); 619 target_part.setType("text");
609 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 620 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
610 break; 621 break;
611 case MAILIMAP_BODY_TYPE_1PART_BASIC: 622 case MAILIMAP_BODY_TYPE_1PART_BASIC:
612 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 623 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
613 break; 624 break;
614 case MAILIMAP_BODY_TYPE_1PART_MSG: 625 case MAILIMAP_BODY_TYPE_1PART_MSG:
615 target_part.setType("message"); 626 target_part.setType("message");
616 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 627 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
617 break; 628 break;
618 default: 629 default:
619 break; 630 break;
620 } 631 }
621} 632}
622 633
623void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 634void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
624{ 635{
625 if (!which) { 636 if (!which) {
626 return; 637 return;
627 } 638 }
628 QString sub; 639 QString sub;
629 sub = which->bd_media_text; 640 sub = which->bd_media_text;
630 qDebug("Type= text/%s",which->bd_media_text); 641 qDebug("Type= text/%s",which->bd_media_text);
631 target_part.setSubtype(sub.lower()); 642 target_part.setSubtype(sub.lower());
632 target_part.setLines(which->bd_lines); 643 target_part.setLines(which->bd_lines);
633 fillBodyFields(target_part,which->bd_fields); 644 fillBodyFields(target_part,which->bd_fields);
634} 645}
635 646
636void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 647void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
637{ 648{
638 if (!which) { 649 if (!which) {
639 return; 650 return;
640 } 651 }
641 target_part.setSubtype("rfc822"); 652 target_part.setSubtype("rfc822");
642 qDebug("Message part"); 653 qDebug("Message part");
643 /* we set this type to text/plain */ 654 /* we set this type to text/plain */
644 target_part.setLines(which->bd_lines); 655 target_part.setLines(which->bd_lines);
645 fillBodyFields(target_part,which->bd_fields); 656 fillBodyFields(target_part,which->bd_fields);
646} 657}
647 658
648void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which) 659void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which)
649{ 660{
650 if (!which) return; 661 if (!which) return;
651 QString sub = which->bd_media_subtype; 662 QString sub = which->bd_media_subtype;
652 target_part.setSubtype(sub.lower()); 663 target_part.setSubtype(sub.lower());
653 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { 664 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
654 clistcell*cur = 0; 665 clistcell*cur = 0;
655 mailimap_single_body_fld_param*param=0; 666 mailimap_single_body_fld_param*param=0;
656 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 667 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
657 param = (mailimap_single_body_fld_param*)cur->data; 668 param = (mailimap_single_body_fld_param*)cur->data;
658 if (param) { 669 if (param) {
659 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 670 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
660 } 671 }
661 } 672 }
662 } 673 }
663} 674}
664 675
665void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 676void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
666{ 677{
667 if (!which) { 678 if (!which) {
668 return; 679 return;
669 } 680 }
670 QString type,sub; 681 QString type,sub;
671 switch (which->bd_media_basic->med_type) { 682 switch (which->bd_media_basic->med_type) {
672 case MAILIMAP_MEDIA_BASIC_APPLICATION: 683 case MAILIMAP_MEDIA_BASIC_APPLICATION:
673 type = "application"; 684 type = "application";
674 break; 685 break;
675 case MAILIMAP_MEDIA_BASIC_AUDIO: 686 case MAILIMAP_MEDIA_BASIC_AUDIO:
676 type = "audio"; 687 type = "audio";
677 break; 688 break;
678 case MAILIMAP_MEDIA_BASIC_IMAGE: 689 case MAILIMAP_MEDIA_BASIC_IMAGE:
679 type = "image"; 690 type = "image";
680 break; 691 break;
681 case MAILIMAP_MEDIA_BASIC_MESSAGE: 692 case MAILIMAP_MEDIA_BASIC_MESSAGE:
682 type = "message"; 693 type = "message";
683 break; 694 break;
684 case MAILIMAP_MEDIA_BASIC_VIDEO: 695 case MAILIMAP_MEDIA_BASIC_VIDEO:
685 type = "video"; 696 type = "video";
686 break; 697 break;
687 case MAILIMAP_MEDIA_BASIC_OTHER: 698 case MAILIMAP_MEDIA_BASIC_OTHER:
688 default: 699 default:
689 if (which->bd_media_basic->med_basic_type) { 700 if (which->bd_media_basic->med_basic_type) {
690 type = which->bd_media_basic->med_basic_type; 701 type = which->bd_media_basic->med_basic_type;
691 } else { 702 } else {
692 type = ""; 703 type = "";
693 } 704 }
694 break; 705 break;
695 } 706 }
696 if (which->bd_media_basic->med_subtype) { 707 if (which->bd_media_basic->med_subtype) {
697 sub = which->bd_media_basic->med_subtype; 708 sub = which->bd_media_basic->med_subtype;
698 } else { 709 } else {
699 sub = ""; 710 sub = "";
700 } 711 }
701 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 712 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
702 target_part.setType(type.lower()); 713 target_part.setType(type.lower());
703 target_part.setSubtype(sub.lower()); 714 target_part.setSubtype(sub.lower());
704 fillBodyFields(target_part,which->bd_fields); 715 fillBodyFields(target_part,which->bd_fields);
705} 716}
706 717
707void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 718void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
708{ 719{
709 if (!which) return; 720 if (!which) return;
710 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 721 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
711 clistcell*cur; 722 clistcell*cur;
712 mailimap_single_body_fld_param*param=0; 723 mailimap_single_body_fld_param*param=0;
713 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 724 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
714 param = (mailimap_single_body_fld_param*)cur->data; 725 param = (mailimap_single_body_fld_param*)cur->data;
715 if (param) { 726 if (param) {
716 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 727 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
717 } 728 }
718 } 729 }
719 } 730 }
720 mailimap_body_fld_enc*enc = which->bd_encoding; 731 mailimap_body_fld_enc*enc = which->bd_encoding;
721 QString encoding(""); 732 QString encoding("");
722 switch (enc->enc_type) { 733 switch (enc->enc_type) {
723 case MAILIMAP_BODY_FLD_ENC_7BIT: 734 case MAILIMAP_BODY_FLD_ENC_7BIT:
724 encoding = "7bit"; 735 encoding = "7bit";
725 break; 736 break;
726 case MAILIMAP_BODY_FLD_ENC_8BIT: 737 case MAILIMAP_BODY_FLD_ENC_8BIT:
727 encoding = "8bit"; 738 encoding = "8bit";
728 break; 739 break;
729 case MAILIMAP_BODY_FLD_ENC_BINARY: 740 case MAILIMAP_BODY_FLD_ENC_BINARY:
730 encoding="binary"; 741 encoding="binary";
731 break; 742 break;
732 case MAILIMAP_BODY_FLD_ENC_BASE64: 743 case MAILIMAP_BODY_FLD_ENC_BASE64:
733 encoding="base64"; 744 encoding="base64";
734 break; 745 break;
735 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 746 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
736 encoding="quoted-printable"; 747 encoding="quoted-printable";
737 break; 748 break;
738 case MAILIMAP_BODY_FLD_ENC_OTHER: 749 case MAILIMAP_BODY_FLD_ENC_OTHER:
739 default: 750 default:
740 if (enc->enc_value) { 751 if (enc->enc_value) {
741 char*t=enc->enc_value; 752 char*t=enc->enc_value;
742 encoding=QString(enc->enc_value); 753 encoding=QString(enc->enc_value);
743 enc->enc_value=0L; 754 enc->enc_value=0L;
744 free(t); 755 free(t);
745 } 756 }
746 } 757 }
747 if (which->bd_description) { 758 if (which->bd_description) {
748 target_part.setDescription(QString(which->bd_description)); 759 target_part.setDescription(QString(which->bd_description));
749 } 760 }
750 target_part.setEncoding(encoding); 761 target_part.setEncoding(encoding);
751 target_part.setSize(which->bd_size); 762 target_part.setSize(which->bd_size);
752} 763}
753 764
754void IMAPwrapper::deleteMail(const RecMail&mail) 765void IMAPwrapper::deleteMail(const RecMail&mail)
755{ 766{
756 mailimap_flag_list*flist; 767 mailimap_flag_list*flist;
757 mailimap_set *set; 768 mailimap_set *set;
758 mailimap_store_att_flags * store_flags; 769 mailimap_store_att_flags * store_flags;
759 int err; 770 int err;
760 login(); 771 login();
761 if (!m_imap) { 772 if (!m_imap) {
762 return; 773 return;
763 } 774 }
764 const char *mb = mail.getMbox().latin1(); 775 const char *mb = mail.getMbox().latin1();
765 err = mailimap_select( m_imap, (char*)mb); 776 err = mailimap_select( m_imap, (char*)mb);
766 if ( err != MAILIMAP_NO_ERROR ) { 777 if ( err != MAILIMAP_NO_ERROR ) {
767 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); 778 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
768 return; 779 return;
769 } 780 }
770 flist = mailimap_flag_list_new_empty(); 781 flist = mailimap_flag_list_new_empty();
771 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 782 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
772 store_flags = mailimap_store_att_flags_new_set_flags(flist); 783 store_flags = mailimap_store_att_flags_new_set_flags(flist);
773 set = mailimap_set_new_single(mail.getNumber()); 784 set = mailimap_set_new_single(mail.getNumber());
774 err = mailimap_store(m_imap,set,store_flags); 785 err = mailimap_store(m_imap,set,store_flags);
775 mailimap_set_free( set ); 786 mailimap_set_free( set );
776 mailimap_store_att_flags_free(store_flags); 787 mailimap_store_att_flags_free(store_flags);
777 788
778 if (err != MAILIMAP_NO_ERROR) { 789 if (err != MAILIMAP_NO_ERROR) {
779 qDebug("error deleting mail: %s",m_imap->imap_response); 790 qDebug("error deleting mail: %s",m_imap->imap_response);
780 return; 791 return;
781 } 792 }
782 qDebug("deleting mail: %s",m_imap->imap_response); 793 qDebug("deleting mail: %s",m_imap->imap_response);
783 /* should we realy do that at this moment? */ 794 /* should we realy do that at this moment? */
784 err = mailimap_expunge(m_imap); 795 err = mailimap_expunge(m_imap);
785 if (err != MAILIMAP_NO_ERROR) { 796 if (err != MAILIMAP_NO_ERROR) {
786 qDebug("error deleting mail: %s",m_imap->imap_response); 797 qDebug("error deleting mail: %s",m_imap->imap_response);
787 } 798 }
788 qDebug("Delete successfull %s",m_imap->imap_response); 799 qDebug("Delete successfull %s",m_imap->imap_response);
789} 800}
790 801
791void IMAPwrapper::answeredMail(const RecMail&mail) 802void IMAPwrapper::answeredMail(const RecMail&mail)
792{ 803{
793 mailimap_flag_list*flist; 804 mailimap_flag_list*flist;
794 mailimap_set *set; 805 mailimap_set *set;
795 mailimap_store_att_flags * store_flags; 806 mailimap_store_att_flags * store_flags;
796 int err; 807 int err;
797 login(); 808 login();
798 if (!m_imap) { 809 if (!m_imap) {
799 return; 810 return;
800 } 811 }
801 const char *mb = mail.getMbox().latin1(); 812 const char *mb = mail.getMbox().latin1();
802 err = mailimap_select( m_imap, (char*)mb); 813 err = mailimap_select( m_imap, (char*)mb);
803 if ( err != MAILIMAP_NO_ERROR ) { 814 if ( err != MAILIMAP_NO_ERROR ) {
804 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); 815 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response);
805 return; 816 return;
806 } 817 }
807 flist = mailimap_flag_list_new_empty(); 818 flist = mailimap_flag_list_new_empty();
808 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 819 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
809 store_flags = mailimap_store_att_flags_new_add_flags(flist); 820 store_flags = mailimap_store_att_flags_new_add_flags(flist);
810 set = mailimap_set_new_single(mail.getNumber()); 821 set = mailimap_set_new_single(mail.getNumber());
811 err = mailimap_store(m_imap,set,store_flags); 822 err = mailimap_store(m_imap,set,store_flags);
812 mailimap_set_free( set ); 823 mailimap_set_free( set );
813 mailimap_store_att_flags_free(store_flags); 824 mailimap_store_att_flags_free(store_flags);
814 825
815 if (err != MAILIMAP_NO_ERROR) { 826 if (err != MAILIMAP_NO_ERROR) {
816 qDebug("error marking mail: %s",m_imap->imap_response); 827 qDebug("error marking mail: %s",m_imap->imap_response);
817 return; 828 return;
818 } 829 }
819} 830}
820 831
821QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 832QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
822{ 833{
823 QString body(""); 834 QString body("");
824 encodedString*res = fetchRawPart(mail,path,internal_call); 835 encodedString*res = fetchRawPart(mail,path,internal_call);
825 encodedString*r = decode_String(res,enc); 836 encodedString*r = decode_String(res,enc);
826 delete res; 837 delete res;
827 if (r) { 838 if (r) {
828 if (r->Length()>0) { 839 if (r->Length()>0) {
829 body = r->Content(); 840 body = r->Content();
830 } 841 }
831 delete r; 842 delete r;
832 } 843 }
833 return body; 844 return body;
834} 845}
835 846
836QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 847QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
837{ 848{
838 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); 849 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
839} 850}
840 851
841encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) 852encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
842{ 853{
843 encodedString*res = fetchRawPart(mail,part.Positionlist(),false); 854 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
844 encodedString*r = decode_String(res,part.Encoding()); 855 encodedString*r = decode_String(res,part.Encoding());
845 delete res; 856 delete res;
846 return r; 857 return r;
847} 858}
848 859
849encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 860encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
850{ 861{
851 return fetchRawPart(mail,part.Positionlist(),false); 862 return fetchRawPart(mail,part.Positionlist(),false);
852} 863}
853 864
854int IMAPwrapper::deleteAllMail(const Folder*folder) 865int IMAPwrapper::deleteAllMail(const Folder*folder)
855{ 866{
856 login(); 867 login();
857 if (!m_imap) { 868 if (!m_imap) {
858 return 0; 869 return 0;
859 } 870 }
860 mailimap_flag_list*flist; 871 mailimap_flag_list*flist;
861 mailimap_set *set; 872 mailimap_set *set;
862 mailimap_store_att_flags * store_flags; 873 mailimap_store_att_flags * store_flags;
863 int err = mailimap_select( m_imap, folder->getName().latin1()); 874 int err = mailimap_select( m_imap, folder->getName().latin1());
864 if ( err != MAILIMAP_NO_ERROR ) { 875 if ( err != MAILIMAP_NO_ERROR ) {
865 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response)); 876 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response));
866 return 0; 877 return 0;
867 } 878 }
868 int last = m_imap->imap_selection_info->sel_exists; 879 int last = m_imap->imap_selection_info->sel_exists;
869 if (last == 0) { 880 if (last == 0) {
870 Global::statusMessage(tr("Mailbox has no mails!")); 881 Global::statusMessage(tr("Mailbox has no mails!"));
871 return 0; 882 return 0;
872 } 883 }
873 flist = mailimap_flag_list_new_empty(); 884 flist = mailimap_flag_list_new_empty();
874 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 885 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
875 store_flags = mailimap_store_att_flags_new_set_flags(flist); 886 store_flags = mailimap_store_att_flags_new_set_flags(flist);
876 set = mailimap_set_new_interval( 1, last ); 887 set = mailimap_set_new_interval( 1, last );
877 err = mailimap_store(m_imap,set,store_flags); 888 err = mailimap_store(m_imap,set,store_flags);
878 mailimap_set_free( set ); 889 mailimap_set_free( set );
879 mailimap_store_att_flags_free(store_flags); 890 mailimap_store_att_flags_free(store_flags);
880 if (err != MAILIMAP_NO_ERROR) { 891 if (err != MAILIMAP_NO_ERROR) {
881 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 892 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
882 return 0; 893 return 0;
883 } 894 }
884 qDebug("deleting mail: %s",m_imap->imap_response); 895 qDebug("deleting mail: %s",m_imap->imap_response);
885 /* should we realy do that at this moment? */ 896 /* should we realy do that at this moment? */
886 err = mailimap_expunge(m_imap); 897 err = mailimap_expunge(m_imap);
887 if (err != MAILIMAP_NO_ERROR) { 898 if (err != MAILIMAP_NO_ERROR) {
888 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 899 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
889 return 0; 900 return 0;
890 } 901 }
891 qDebug("Delete successfull %s",m_imap->imap_response); 902 qDebug("Delete successfull %s",m_imap->imap_response);
892 return 1; 903 return 1;
893} 904}
894 905
895int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) 906int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder)
896{ 907{
897 if (folder.length()==0) return 0; 908 if (folder.length()==0) return 0;
898 login(); 909 login();
899 if (!m_imap) {return 0;} 910 if (!m_imap) {return 0;}
900 QString pre = account->getPrefix(); 911 QString pre = account->getPrefix();
901 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { 912 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
902 pre+=delemiter; 913 pre+=delemiter;
903 } 914 }
904 if (parentfolder) { 915 if (parentfolder) {
905 pre += parentfolder->getDisplayName()+delemiter; 916 pre += parentfolder->getDisplayName()+delemiter;
906 } 917 }
907 pre+=folder; 918 pre+=folder;
908 if (getsubfolder) { 919 if (getsubfolder) {
909 if (delemiter.length()>0) { 920 if (delemiter.length()>0) {
910 pre+=delemiter; 921 pre+=delemiter;
911 } else { 922 } else {
912 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); 923 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre));
913 return 0; 924 return 0;
914 } 925 }
915 } 926 }
916 qDebug("Creating %s",pre.latin1()); 927 qDebug("Creating %s",pre.latin1());
917 int res = mailimap_create(m_imap,pre.latin1()); 928 int res = mailimap_create(m_imap,pre.latin1());
918 if (res != MAILIMAP_NO_ERROR) { 929 if (res != MAILIMAP_NO_ERROR) {
919 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 930 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
920 return 0; 931 return 0;
921 } 932 }
922 return 1; 933 return 1;
923} 934}
924 935
925int IMAPwrapper::deleteMbox(const Folder*folder) 936int IMAPwrapper::deleteMbox(const Folder*folder)
926{ 937{
927 if (!folder) return 0; 938 if (!folder) return 0;
928 login(); 939 login();
929 if (!m_imap) {return 0;} 940 if (!m_imap) {return 0;}
930 int res = mailimap_delete(m_imap,folder->getName()); 941 int res = mailimap_delete(m_imap,folder->getName());
931 if (res != MAILIMAP_NO_ERROR) { 942 if (res != MAILIMAP_NO_ERROR) {
932 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 943 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
933 return 0; 944 return 0;
934 } 945 }
935 return 1; 946 return 1;
936} 947}
937 948
938void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 949void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
939{ 950{
940 mailimap_status_att_list * att_list =0; 951 mailimap_status_att_list * att_list =0;
941 mailimap_mailbox_data_status * status=0; 952 mailimap_mailbox_data_status * status=0;
942 clistiter * cur = 0; 953 clistiter * cur = 0;
943 int r = 0; 954 int r = 0;
944 int res = 0; 955 int res = 0;
945 target_stat.message_count = 0; 956 target_stat.message_count = 0;
946 target_stat.message_unseen = 0; 957 target_stat.message_unseen = 0;
947 target_stat.message_recent = 0; 958 target_stat.message_recent = 0;
948 login(); 959 login();
949 if (!m_imap) { 960 if (!m_imap) {
950 return; 961 return;
951 } 962 }
952 att_list = mailimap_status_att_list_new_empty(); 963 att_list = mailimap_status_att_list_new_empty();
953 if (!att_list) return; 964 if (!att_list) return;
954 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 965 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
955 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 966 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
956 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 967 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
957 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 968 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
958 for (cur = clist_begin(status->st_info_list); 969 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
959 cur != NULL ; cur = clist_next(cur)) { 970 for (cur = clist_begin(status->st_info_list);
960 mailimap_status_info * status_info; 971 cur != NULL ; cur = clist_next(cur)) {
961 status_info = (mailimap_status_info *)clist_content(cur); 972 mailimap_status_info * status_info;
962 switch (status_info->st_att) { 973 status_info = (mailimap_status_info *)clist_content(cur);
963 case MAILIMAP_STATUS_ATT_MESSAGES: 974 switch (status_info->st_att) {
964 target_stat.message_count = status_info->st_value; 975 case MAILIMAP_STATUS_ATT_MESSAGES:
965 break; 976 target_stat.message_count = status_info->st_value;
966 case MAILIMAP_STATUS_ATT_RECENT: 977 break;
967 target_stat.message_recent = status_info->st_value; 978 case MAILIMAP_STATUS_ATT_RECENT:
968 break; 979 target_stat.message_recent = status_info->st_value;
969 case MAILIMAP_STATUS_ATT_UNSEEN: 980 break;
970 target_stat.message_unseen = status_info->st_value; 981 case MAILIMAP_STATUS_ATT_UNSEEN:
971 break; 982 target_stat.message_unseen = status_info->st_value;
983 break;
984 }
972 } 985 }
986 } else {
987 qDebug("Error retrieving status");
973 } 988 }
974 mailimap_mailbox_data_status_free(status); 989 if (status) mailimap_mailbox_data_status_free(status);
975 mailimap_status_att_list_free(att_list); 990 if (att_list) mailimap_status_att_list_free(att_list);
976} 991}
977 992
978void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 993void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
979{ 994{
980 login(); 995 login();
981 if (!m_imap) return; 996 if (!m_imap) return;
982 if (!msg) return; 997 if (!msg) return;
983 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); 998 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
984 if (r != MAILIMAP_NO_ERROR) { 999 if (r != MAILIMAP_NO_ERROR) {
985 Global::statusMessage("Error storing mail!"); 1000 Global::statusMessage("Error storing mail!");
986 } 1001 }
987} 1002}
988 1003
989const QString&IMAPwrapper::getType()const 1004const QString&IMAPwrapper::getType()const
990{ 1005{
991 return account->getType(); 1006 return account->getType();
992} 1007}
1008
1009encodedString* IMAPwrapper::fetchRawBody(const RecMail&mail)
1010{
1011 // dummy
1012 QValueList<int> path;
1013 return fetchRawPart(mail,path,false);
1014}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index 6a9c411..b246f58 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -1,70 +1,71 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "abstractmail.h" 6#include "abstractmail.h"
7#include <libetpan/clist.h> 7#include <libetpan/clist.h>
8 8
9struct mailimap; 9struct mailimap;
10struct mailimap_body; 10struct mailimap_body;
11struct mailimap_body_type_1part; 11struct mailimap_body_type_1part;
12struct mailimap_body_type_text; 12struct mailimap_body_type_text;
13struct mailimap_body_type_basic; 13struct mailimap_body_type_basic;
14struct mailimap_body_type_msg; 14struct mailimap_body_type_msg;
15struct mailimap_body_type_mpart; 15struct mailimap_body_type_mpart;
16struct mailimap_body_fields; 16struct mailimap_body_fields;
17struct mailimap_msg_att; 17struct mailimap_msg_att;
18class encodedString; 18class encodedString;
19 19
20class IMAPwrapper : public AbstractMail 20class IMAPwrapper : public AbstractMail
21{ 21{
22 Q_OBJECT 22 Q_OBJECT
23public: 23public:
24 IMAPwrapper( IMAPaccount *a ); 24 IMAPwrapper( IMAPaccount *a );
25 virtual ~IMAPwrapper(); 25 virtual ~IMAPwrapper();
26 virtual QList<Folder>* listFolders(); 26 virtual QList<Folder>* listFolders();
27 virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); 27 virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
29 29
30 virtual void deleteMail(const RecMail&mail); 30 virtual void deleteMail(const RecMail&mail);
31 virtual void answeredMail(const RecMail&mail); 31 virtual void answeredMail(const RecMail&mail);
32 virtual int deleteAllMail(const Folder*folder); 32 virtual int deleteAllMail(const Folder*folder);
33 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 33 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
34 34
35 virtual RecBody fetchBody(const RecMail&mail); 35 virtual RecBody fetchBody(const RecMail&mail);
36 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 36 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
37 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 37 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
38 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 38 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
39 virtual encodedString* fetchRawBody(const RecMail&mail);
39 40
40 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); 41 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
41 virtual int deleteMbox(const Folder*folder); 42 virtual int deleteMbox(const Folder*folder);
42 43
43 static void imap_progress( size_t current, size_t maximum ); 44 static void imap_progress( size_t current, size_t maximum );
44 45
45 virtual void logout(); 46 virtual void logout();
46 virtual const QString&getType()const; 47 virtual const QString&getType()const;
47protected: 48protected:
48 RecMail*parse_list_result(mailimap_msg_att*); 49 RecMail*parse_list_result(mailimap_msg_att*);
49 void login(); 50 void login();
50 51
51 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); 52 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
52 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); 53 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call);
53 54
54 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 55 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
55 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 56 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
56 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 57 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
57 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); 58 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
58 void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which); 59 void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which);
59 void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1); 60 void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1);
60 61
61 /* just helpers */ 62 /* just helpers */
62 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 63 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
63 static QStringList address_list_to_stringlist(clist*list); 64 static QStringList address_list_to_stringlist(clist*list);
64 65
65 66
66 IMAPaccount *account; 67 IMAPaccount *account;
67 mailimap *m_imap; 68 mailimap *m_imap;
68}; 69};
69 70
70#endif 71#endif
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp
index 60f7507..3a0b30a 100644
--- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp
@@ -1,331 +1,332 @@
1#include "mboxwrapper.h" 1#include "mboxwrapper.h"
2#include "mailtypes.h" 2#include "mailtypes.h"
3#include "mailwrapper.h" 3#include "mailwrapper.h"
4#include <libetpan/libetpan.h> 4#include <libetpan/libetpan.h>
5#include <qdir.h> 5#include <qdir.h>
6#include <stdlib.h> 6#include <stdlib.h>
7#include <qpe/global.h> 7#include <qpe/global.h>
8 8
9const QString MBOXwrapper::wrapperType="MBOX"; 9const QString MBOXwrapper::wrapperType="MBOX";
10 10
11MBOXwrapper::MBOXwrapper(const QString & mbox_dir) 11MBOXwrapper::MBOXwrapper(const QString & mbox_dir)
12 : Genericwrapper(),MBOXPath(mbox_dir) 12 : Genericwrapper(),MBOXPath(mbox_dir)
13{ 13{
14 QDir dir(MBOXPath); 14 QDir dir(MBOXPath);
15 if (!dir.exists()) { 15 if (!dir.exists()) {
16 dir.mkdir(MBOXPath); 16 dir.mkdir(MBOXPath);
17 } 17 }
18} 18}
19 19
20MBOXwrapper::~MBOXwrapper() 20MBOXwrapper::~MBOXwrapper()
21{ 21{
22} 22}
23 23
24void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) 24void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target )
25{ 25{
26 mailstorage*storage = mailstorage_new(NULL); 26 mailstorage*storage = mailstorage_new(NULL);
27 QString p = MBOXPath+"/"; 27 QString p = MBOXPath+"/";
28 p+=mailbox; 28 p+=mailbox;
29 29
30 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 30 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
31 mailfolder*folder; 31 mailfolder*folder;
32 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 32 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
33 r = mailfolder_connect(folder); 33 r = mailfolder_connect(folder);
34 if (r != MAIL_NO_ERROR) { 34 if (r != MAIL_NO_ERROR) {
35 qDebug("Error initializing mbox"); 35 qDebug("Error initializing mbox");
36 mailfolder_free(folder); 36 mailfolder_free(folder);
37 mailstorage_free(storage); 37 mailstorage_free(storage);
38 return; 38 return;
39 } 39 }
40 40
41 parseList(target,folder->fld_session,mailbox); 41 parseList(target,folder->fld_session,mailbox);
42 42
43 mailfolder_disconnect(folder); 43 mailfolder_disconnect(folder);
44 mailfolder_free(folder); 44 mailfolder_free(folder);
45 mailstorage_free(storage); 45 mailstorage_free(storage);
46 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); 46 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count()));
47} 47}
48 48
49QList<Folder>* MBOXwrapper::listFolders() 49QList<Folder>* MBOXwrapper::listFolders()
50{ 50{
51 QList<Folder> * folders = new QList<Folder>(); 51 QList<Folder> * folders = new QList<Folder>();
52 folders->setAutoDelete( false ); 52 folders->setAutoDelete( false );
53 QDir dir(MBOXPath); 53 QDir dir(MBOXPath);
54 if (!dir.exists()) return folders; 54 if (!dir.exists()) return folders;
55 dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); 55 dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable);
56 QStringList entries = dir.entryList(); 56 QStringList entries = dir.entryList();
57 QStringList::ConstIterator it = entries.begin(); 57 QStringList::ConstIterator it = entries.begin();
58 for (;it!=entries.end();++it) { 58 for (;it!=entries.end();++it) {
59 Folder*inb=new Folder(*it,"/"); 59 Folder*inb=new Folder(*it,"/");
60 folders->append(inb); 60 folders->append(inb);
61 } 61 }
62 return folders; 62 return folders;
63} 63}
64 64
65void MBOXwrapper::deleteMail(const RecMail&mail) 65void MBOXwrapper::deleteMail(const RecMail&mail)
66{ 66{
67 mailstorage*storage = mailstorage_new(NULL); 67 mailstorage*storage = mailstorage_new(NULL);
68 QString p = MBOXPath+"/"; 68 QString p = MBOXPath+"/";
69 p+=mail.getMbox(); 69 p+=mail.getMbox();
70 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 70 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
71 mailfolder*folder; 71 mailfolder*folder;
72 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 72 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
73 r = mailfolder_connect(folder); 73 r = mailfolder_connect(folder);
74 if (r != MAIL_NO_ERROR) { 74 if (r != MAIL_NO_ERROR) {
75 qDebug("Error initializing mbox"); 75 qDebug("Error initializing mbox");
76 mailfolder_free(folder); 76 mailfolder_free(folder);
77 mailstorage_free(storage); 77 mailstorage_free(storage);
78 return; 78 return;
79 } 79 }
80 r = mailsession_remove_message(folder->fld_session,mail.getNumber()); 80 r = mailsession_remove_message(folder->fld_session,mail.getNumber());
81 if (r != MAIL_NO_ERROR) { 81 if (r != MAIL_NO_ERROR) {
82 qDebug("error deleting mail"); 82 qDebug("error deleting mail");
83 } 83 }
84 mailfolder_free(folder); 84 mailfolder_free(folder);
85 mailstorage_free(storage); 85 mailstorage_free(storage);
86} 86}
87 87
88void MBOXwrapper::answeredMail(const RecMail&) 88void MBOXwrapper::answeredMail(const RecMail&)
89{ 89{
90} 90}
91 91
92RecBody MBOXwrapper::fetchBody( const RecMail &mail ) 92RecBody MBOXwrapper::fetchBody( const RecMail &mail )
93{ 93{
94 RecBody body; 94 RecBody body;
95 mailstorage*storage = mailstorage_new(NULL); 95 mailstorage*storage = mailstorage_new(NULL);
96 QString p = MBOXPath+"/"; 96 QString p = MBOXPath+"/";
97 p+=mail.getMbox(); 97 p+=mail.getMbox();
98 mailmessage * msg; 98 mailmessage * msg;
99 char*data=0; 99 char*data=0;
100 size_t size; 100 size_t size;
101 101
102 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 102 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
103 mailfolder*folder; 103 mailfolder*folder;
104 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 104 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
105 r = mailfolder_connect(folder); 105 r = mailfolder_connect(folder);
106 if (r != MAIL_NO_ERROR) { 106 if (r != MAIL_NO_ERROR) {
107 qDebug("Error initializing mbox"); 107 qDebug("Error initializing mbox");
108 mailfolder_free(folder); 108 mailfolder_free(folder);
109 mailstorage_free(storage); 109 mailstorage_free(storage);
110 return body; 110 return body;
111 } 111 }
112 r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); 112 r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg);
113 if (r != MAIL_NO_ERROR) { 113 if (r != MAIL_NO_ERROR) {
114 qDebug("Error fetching mail %i",mail.getNumber()); 114 qDebug("Error fetching mail %i",mail.getNumber());
115 mailfolder_free(folder); 115 mailfolder_free(folder);
116 mailstorage_free(storage); 116 mailstorage_free(storage);
117 return body; 117 return body;
118 } 118 }
119 r = mailmessage_fetch(msg,&data,&size); 119 r = mailmessage_fetch(msg,&data,&size);
120 if (r != MAIL_NO_ERROR) { 120 if (r != MAIL_NO_ERROR) {
121 qDebug("Error fetching mail %i",mail.getNumber()); 121 qDebug("Error fetching mail %i",mail.getNumber());
122 mailfolder_free(folder); 122 mailfolder_free(folder);
123 mailstorage_free(storage); 123 mailstorage_free(storage);
124 mailmessage_free(msg); 124 mailmessage_free(msg);
125 return body; 125 return body;
126 } 126 }
127 body = parseMail(msg); 127 body = parseMail(msg);
128 mailmessage_fetch_result_free(msg,data); 128 mailmessage_fetch_result_free(msg,data);
129 mailfolder_free(folder); 129 mailfolder_free(folder);
130 mailstorage_free(storage); 130 mailstorage_free(storage);
131 131
132 return body; 132 return body;
133} 133}
134 134
135void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) 135void MBOXwrapper::mbox_progress( size_t current, size_t maximum )
136{ 136{
137 qDebug("MBOX %i von %i",current,maximum); 137 qDebug("MBOX %i von %i",current,maximum);
138} 138}
139 139
140int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool ) 140int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool )
141{ 141{
142 QString p = MBOXPath+"/"; 142 QString p = MBOXPath+"/";
143 p+=folder; 143 p+=folder;
144 QFileInfo fi(p); 144 QFileInfo fi(p);
145 if (fi.exists()) { 145 if (fi.exists()) {
146 Global::statusMessage(tr("Mailbox exists.")); 146 Global::statusMessage(tr("Mailbox exists."));
147 return 0; 147 return 0;
148 } 148 }
149 mailmbox_folder*f = 0; 149 mailmbox_folder*f = 0;
150 if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { 150 if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) {
151 Global::statusMessage(tr("Error init folder")); 151 Global::statusMessage(tr("Error init folder"));
152 return 0; 152 return 0;
153 } 153 }
154 if (f) mailmbox_done(f); 154 if (f) mailmbox_done(f);
155 return 1; 155 return 1;
156} 156}
157 157
158void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 158void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
159{ 159{
160 QString p = MBOXPath+"/"; 160 QString p = MBOXPath+"/";
161 p+=folder; 161 p+=folder;
162 mailmbox_folder*f = 0; 162 mailmbox_folder*f = 0;
163 int r = mailmbox_init(p.latin1(),0,1,0,&f); 163 int r = mailmbox_init(p.latin1(),0,1,0,&f);
164 if (r != MAIL_NO_ERROR) { 164 if (r != MAIL_NO_ERROR) {
165 Global::statusMessage(tr("Error init folder")); 165 Global::statusMessage(tr("Error init folder"));
166 return; 166 return;
167 } 167 }
168 r = mailmbox_append_message(f,msg,length); 168 r = mailmbox_append_message(f,msg,length);
169 if (r != MAIL_NO_ERROR) { 169 if (r != MAIL_NO_ERROR) {
170 Global::statusMessage(tr("Error writing to message folder")); 170 Global::statusMessage(tr("Error writing to message folder"));
171 } 171 }
172 mailmbox_done(f); 172 mailmbox_done(f);
173} 173}
174 174
175void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) 175encodedString* MBOXwrapper::fetchRawBody(const RecMail&mail)
176{ 176{
177 RecBody body; 177 RecBody body;
178 mailstorage*storage = mailstorage_new(NULL); 178 mailstorage*storage = mailstorage_new(NULL);
179 QString p = MBOXPath+"/"; 179 QString p = MBOXPath+"/";
180 p+=mail.getMbox(); 180 p+=mail.getMbox();
181 mailmessage * msg; 181 mailmessage * msg;
182 char*data=0; 182 char*data=0;
183 size_t size; 183 size_t size;
184 184
185 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 185 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
186 mailfolder*folder; 186 mailfolder*folder;
187 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 187 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
188 r = mailfolder_connect(folder); 188 r = mailfolder_connect(folder);
189 if (r != MAIL_NO_ERROR) { 189 if (r != MAIL_NO_ERROR) {
190 Global::statusMessage(tr("Error initializing mbox")); 190 Global::statusMessage(tr("Error initializing mbox"));
191 mailfolder_free(folder); 191 mailfolder_free(folder);
192 mailstorage_free(storage); 192 mailstorage_free(storage);
193 return; 193 return 0;
194 } 194 }
195 r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); 195 r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg);
196 if (r != MAIL_NO_ERROR) { 196 if (r != MAIL_NO_ERROR) {
197 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); 197 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
198 mailfolder_free(folder); 198 mailfolder_free(folder);
199 mailstorage_free(storage); 199 mailstorage_free(storage);
200 return; 200 return 0;
201 } 201 }
202 r = mailmessage_fetch(msg,&data,&size); 202 r = mailmessage_fetch(msg,&data,&size);
203 if (r != MAIL_NO_ERROR) { 203 if (r != MAIL_NO_ERROR) {
204 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); 204 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
205 mailfolder_free(folder); 205 mailfolder_free(folder);
206 mailstorage_free(storage); 206 mailstorage_free(storage);
207 mailmessage_free(msg); 207 mailmessage_free(msg);
208 return; 208 return 0;
209 } 209 }
210 *target = data; 210 encodedString*result = new encodedString(data,size);
211 *length = size; 211
212 mailfolder_free(folder); 212 mailfolder_free(folder);
213 mailstorage_free(storage); 213 mailstorage_free(storage);
214 mailmessage_free(msg); 214 mailmessage_free(msg);
215 return result;
215} 216}
216 217
217void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) 218void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target)
218{ 219{
219 QString p = MBOXPath+"/"; 220 QString p = MBOXPath+"/";
220 p+=mailbox; 221 p+=mailbox;
221 mailmbox_folder*f = 0; 222 mailmbox_folder*f = 0;
222 int r = mailmbox_init(p.latin1(),0,1,0,&f); 223 int r = mailmbox_init(p.latin1(),0,1,0,&f);
223 if (r != MAIL_NO_ERROR) { 224 if (r != MAIL_NO_ERROR) {
224 qDebug("Error init folder"); 225 qDebug("Error init folder");
225 return; 226 return;
226 } 227 }
227 deleteMails(f,target); 228 deleteMails(f,target);
228 mailmbox_done(f); 229 mailmbox_done(f);
229} 230}
230 231
231void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target) 232void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target)
232{ 233{
233 if (!f) return; 234 if (!f) return;
234 int r; 235 int r;
235 for (unsigned int i=0; i < target.count();++i) { 236 for (unsigned int i=0; i < target.count();++i) {
236 r = mailmbox_delete_msg(f,target.at(i)->getNumber()); 237 r = mailmbox_delete_msg(f,target.at(i)->getNumber());
237 if (r!=MAILMBOX_NO_ERROR) { 238 if (r!=MAILMBOX_NO_ERROR) {
238 qDebug("error delete mail"); 239 qDebug("error delete mail");
239 } 240 }
240 } 241 }
241 r = mailmbox_expunge(f); 242 r = mailmbox_expunge(f);
242 if (r != MAILMBOX_NO_ERROR) { 243 if (r != MAILMBOX_NO_ERROR) {
243 qDebug("error expunge mailbox"); 244 qDebug("error expunge mailbox");
244 } 245 }
245} 246}
246 247
247int MBOXwrapper::deleteAllMail(const Folder*tfolder) 248int MBOXwrapper::deleteAllMail(const Folder*tfolder)
248{ 249{
249 if (!tfolder) return 0; 250 if (!tfolder) return 0;
250 QString p = MBOXPath+tfolder->getDisplayName(); 251 QString p = MBOXPath+tfolder->getDisplayName();
251 int res = 1; 252 int res = 1;
252 253
253 mailfolder*folder = 0; 254 mailfolder*folder = 0;
254 mailmessage_list*l=0; 255 mailmessage_list*l=0;
255 mailstorage*storage = mailstorage_new(NULL); 256 mailstorage*storage = mailstorage_new(NULL);
256 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 257 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
257 if (r != MAIL_NO_ERROR) { 258 if (r != MAIL_NO_ERROR) {
258 Global::statusMessage(tr("Error initializing mbox")); 259 Global::statusMessage(tr("Error initializing mbox"));
259 res = 0; 260 res = 0;
260 } 261 }
261 if (res) { 262 if (res) {
262 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 263 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
263 r = mailfolder_connect(folder); 264 r = mailfolder_connect(folder);
264 if (r != MAIL_NO_ERROR) { 265 if (r != MAIL_NO_ERROR) {
265 Global::statusMessage(tr("Error initializing mbox")); 266 Global::statusMessage(tr("Error initializing mbox"));
266 res = 0; 267 res = 0;
267 } 268 }
268 } 269 }
269 if (res) { 270 if (res) {
270 r = mailsession_get_messages_list(folder->fld_session,&l); 271 r = mailsession_get_messages_list(folder->fld_session,&l);
271 if (r != MAIL_NO_ERROR) { 272 if (r != MAIL_NO_ERROR) {
272 qDebug("Error message list"); 273 qDebug("Error message list");
273 res=0; 274 res=0;
274 } 275 }
275 } 276 }
276 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { 277 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
277 r = mailsession_remove_message(folder->fld_session,i+1); 278 r = mailsession_remove_message(folder->fld_session,i+1);
278 if (r != MAIL_NO_ERROR) { 279 if (r != MAIL_NO_ERROR) {
279 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 280 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
280 res = 0; 281 res = 0;
281 break; 282 break;
282 } 283 }
283 } 284 }
284 if (l) mailmessage_list_free(l); 285 if (l) mailmessage_list_free(l);
285 if (folder) mailfolder_free(folder); 286 if (folder) mailfolder_free(folder);
286 if (storage) mailstorage_free(storage); 287 if (storage) mailstorage_free(storage);
287 return res; 288 return res;
288} 289}
289 290
290int MBOXwrapper::deleteMbox(const Folder*tfolder) 291int MBOXwrapper::deleteMbox(const Folder*tfolder)
291{ 292{
292 if (!tfolder) return 0; 293 if (!tfolder) return 0;
293 QString p = MBOXPath+tfolder->getDisplayName(); 294 QString p = MBOXPath+tfolder->getDisplayName();
294 QFile fi(p); 295 QFile fi(p);
295 if (!fi.exists()) { 296 if (!fi.exists()) {
296 Global::statusMessage(tr("Mailbox doesn't exist.")); 297 Global::statusMessage(tr("Mailbox doesn't exist."));
297 return 0; 298 return 0;
298 } 299 }
299 if (!fi.remove()) { 300 if (!fi.remove()) {
300 Global::statusMessage(tr("Error deleting Mailbox.")); 301 Global::statusMessage(tr("Error deleting Mailbox."));
301 return 0; 302 return 0;
302 } 303 }
303 return 1; 304 return 1;
304} 305}
305 306
306void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 307void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
307{ 308{
308 mailfolder*folder = 0; 309 mailfolder*folder = 0;
309 mailstorage*storage = mailstorage_new(NULL); 310 mailstorage*storage = mailstorage_new(NULL);
310 target_stat.message_count = 0; 311 target_stat.message_count = 0;
311 target_stat.message_unseen = 0; 312 target_stat.message_unseen = 0;
312 target_stat.message_recent = 0; 313 target_stat.message_recent = 0;
313 QString p = MBOXPath+"/"+mailbox; 314 QString p = MBOXPath+"/"+mailbox;
314 QFile fi(p); 315 QFile fi(p);
315 if (!fi.exists()) { 316 if (!fi.exists()) {
316 Global::statusMessage(tr("Mailbox doesn't exist.")); 317 Global::statusMessage(tr("Mailbox doesn't exist."));
317 return; 318 return;
318 } 319 }
319 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 320 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
320 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 321 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
321 r = mailfolder_connect(folder); 322 r = mailfolder_connect(folder);
322 r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, 323 r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count,
323 &target_stat.message_recent,&target_stat.message_unseen); 324 &target_stat.message_recent,&target_stat.message_unseen);
324 if (folder) mailfolder_free(folder); 325 if (folder) mailfolder_free(folder);
325 if (storage) mailstorage_free(storage); 326 if (storage) mailstorage_free(storage);
326} 327}
327 328
328const QString&MBOXwrapper::getType()const 329const QString&MBOXwrapper::getType()const
329{ 330{
330 return wrapperType; 331 return wrapperType;
331} 332}
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.h b/noncore/net/mail/libmailwrapper/mboxwrapper.h
index f97fce2..2794014 100644
--- a/noncore/net/mail/libmailwrapper/mboxwrapper.h
+++ b/noncore/net/mail/libmailwrapper/mboxwrapper.h
@@ -1,44 +1,45 @@
1#ifndef __MBOX_WRAPPER_H 1#ifndef __MBOX_WRAPPER_H
2#define __MBOX_WRAPPER_H 2#define __MBOX_WRAPPER_H
3 3
4#include "genericwrapper.h" 4#include "genericwrapper.h"
5#include <qstring.h> 5#include <qstring.h>
6 6
7class RecMail; 7class RecMail;
8class RecBody; 8class RecBody;
9class encodedString;
9struct mailmbox_folder; 10struct mailmbox_folder;
10 11
11class MBOXwrapper : public Genericwrapper 12class MBOXwrapper : public Genericwrapper
12{ 13{
13 Q_OBJECT 14 Q_OBJECT
14public: 15public:
15 MBOXwrapper(const QString & dir); 16 MBOXwrapper(const QString & dir);
16 virtual ~MBOXwrapper(); 17 virtual ~MBOXwrapper();
17 18
18 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
19 virtual QList<Folder>* listFolders(); 20 virtual QList<Folder>* listFolders();
20 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 21 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
21 22
22 virtual void deleteMail(const RecMail&mail); 23 virtual void deleteMail(const RecMail&mail);
23 virtual void answeredMail(const RecMail&mail); 24 virtual void answeredMail(const RecMail&mail);
24 25
25 virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false); 26 virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false);
26 virtual int deleteMbox(const Folder*); 27 virtual int deleteMbox(const Folder*);
27 28
28 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 29 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
29 30
30 virtual RecBody fetchBody( const RecMail &mail ); 31 virtual RecBody fetchBody( const RecMail &mail );
31 static void mbox_progress( size_t current, size_t maximum ); 32 static void mbox_progress( size_t current, size_t maximum );
32 33
33 virtual void fetchRawBody(const RecMail&mail,char**target,size_t*length); 34 virtual encodedString* fetchRawBody(const RecMail&mail);
34 virtual void deleteMails(const QString & mailbox,QList<RecMail> &target); 35 virtual void deleteMails(const QString & mailbox,QList<RecMail> &target);
35 virtual int deleteAllMail(const Folder*); 36 virtual int deleteAllMail(const Folder*);
36 virtual const QString&getType()const; 37 virtual const QString&getType()const;
37 38
38protected: 39protected:
39 static void deleteMails(mailmbox_folder*f,QList<RecMail> &target); 40 static void deleteMails(mailmbox_folder*f,QList<RecMail> &target);
40 QString MBOXPath; 41 QString MBOXPath;
41 static const QString wrapperType; 42 static const QString wrapperType;
42}; 43};
43 44
44#endif 45#endif
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 45408dd..72c145b 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -1,242 +1,249 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include "pop3wrapper.h" 2#include "pop3wrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include "logindialog.h" 4#include "logindialog.h"
5#include <libetpan/libetpan.h> 5#include <libetpan/libetpan.h>
6#include <qpe/global.h> 6#include <qpe/global.h>
7#include <qfile.h> 7#include <qfile.h>
8#include <qstring.h> 8#include <qstring.h>
9 9
10/* we don't fetch messages larger than 5 MB */ 10/* we don't fetch messages larger than 5 MB */
11#define HARD_MSG_SIZE_LIMIT 5242880 11#define HARD_MSG_SIZE_LIMIT 5242880
12 12
13POP3wrapper::POP3wrapper( POP3account *a ) 13POP3wrapper::POP3wrapper( POP3account *a )
14 : Genericwrapper() 14 : Genericwrapper()
15{ 15{
16 account = a; 16 account = a;
17 m_pop3 = NULL; 17 m_pop3 = NULL;
18 m_folder = NULL; 18 m_folder = NULL;
19 msgTempName = a->getFileName()+"_msg_cache"; 19 msgTempName = a->getFileName()+"_msg_cache";
20 last_msg_id = 0; 20 last_msg_id = 0;
21} 21}
22 22
23POP3wrapper::~POP3wrapper() 23POP3wrapper::~POP3wrapper()
24{ 24{
25 logout(); 25 logout();
26 QFile msg_cache(msgTempName); 26 QFile msg_cache(msgTempName);
27 if (msg_cache.exists()) { 27 if (msg_cache.exists()) {
28 msg_cache.remove(); 28 msg_cache.remove();
29 } 29 }
30} 30}
31 31
32void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 32void POP3wrapper::pop3_progress( size_t current, size_t maximum )
33{ 33{
34 qDebug( "POP3: %i of %i", current, maximum ); 34 qDebug( "POP3: %i of %i", current, maximum );
35} 35}
36 36
37RecBody POP3wrapper::fetchBody( const RecMail &mail ) 37RecBody POP3wrapper::fetchBody( const RecMail &mail )
38{ 38{
39 int err = MAILPOP3_NO_ERROR; 39 int err = MAILPOP3_NO_ERROR;
40 char *message = 0; 40 char *message = 0;
41 size_t length = 0; 41 size_t length = 0;
42 42
43 login(); 43 login();
44 if ( !m_pop3 ) { 44 if ( !m_pop3 ) {
45 return RecBody(); 45 return RecBody();
46 } 46 }
47 47
48 RecBody body; 48 RecBody body;
49 mailmessage * mailmsg; 49 mailmessage * mailmsg;
50 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { 50 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
51 qDebug("Message to large: %i",mail.Msgsize()); 51 qDebug("Message to large: %i",mail.Msgsize());
52 return body; 52 return body;
53 } 53 }
54 54
55 QFile msg_cache(msgTempName); 55 QFile msg_cache(msgTempName);
56 56
57 cleanMimeCache(); 57 cleanMimeCache();
58 58
59 if (mail.getNumber()!=last_msg_id) { 59 if (mail.getNumber()!=last_msg_id) {
60 if (msg_cache.exists()) { 60 if (msg_cache.exists()) {
61 msg_cache.remove(); 61 msg_cache.remove();
62 } 62 }
63 msg_cache.open(IO_ReadWrite|IO_Truncate); 63 msg_cache.open(IO_ReadWrite|IO_Truncate);
64 last_msg_id = mail.getNumber(); 64 last_msg_id = mail.getNumber();
65 err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); 65 err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg);
66 err = mailmessage_fetch(mailmsg,&message,&length); 66 err = mailmessage_fetch(mailmsg,&message,&length);
67 msg_cache.writeBlock(message,length); 67 msg_cache.writeBlock(message,length);
68 } else { 68 } else {
69 QString msg=""; 69 QString msg="";
70 msg_cache.open(IO_ReadOnly); 70 msg_cache.open(IO_ReadOnly);
71 message = new char[4096]; 71 message = new char[4096];
72 memset(message,0,4096); 72 memset(message,0,4096);
73 while (msg_cache.readBlock(message,4095)>0) { 73 while (msg_cache.readBlock(message,4095)>0) {
74 msg+=message; 74 msg+=message;
75 memset(message,0,4096); 75 memset(message,0,4096);
76 } 76 }
77 delete message; 77 delete message;
78 message = (char*)malloc(msg.length()+1*sizeof(char)); 78 message = (char*)malloc(msg.length()+1*sizeof(char));
79 memset(message,0,msg.length()+1); 79 memset(message,0,msg.length()+1);
80 memcpy(message,msg.latin1(),msg.length()); 80 memcpy(message,msg.latin1(),msg.length());
81 /* transform to libetpan stuff */ 81 /* transform to libetpan stuff */
82 mailmsg = mailmessage_new(); 82 mailmsg = mailmessage_new();
83 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 83 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
84 generic_message_t * msg_data; 84 generic_message_t * msg_data;
85 msg_data = (generic_message_t *)mailmsg->msg_data; 85 msg_data = (generic_message_t *)mailmsg->msg_data;
86 msg_data->msg_fetched = 1; 86 msg_data->msg_fetched = 1;
87 msg_data->msg_message = message; 87 msg_data->msg_message = message;
88 msg_data->msg_length = strlen(message); 88 msg_data->msg_length = strlen(message);
89 } 89 }
90 body = parseMail(mailmsg); 90 body = parseMail(mailmsg);
91 91
92 /* clean up */ 92 /* clean up */
93 if (mailmsg) mailmessage_free(mailmsg); 93 if (mailmsg) mailmessage_free(mailmsg);
94 if (message) free(message); 94 if (message) free(message);
95 95
96 return body; 96 return body;
97} 97}
98 98
99void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 99void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
100{ 100{
101 login(); 101 login();
102 if (!m_pop3) return; 102 if (!m_pop3) return;
103 uint32_t res_messages,res_recent,res_unseen; 103 uint32_t res_messages,res_recent,res_unseen;
104 mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen); 104 mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen);
105 parseList(target,m_folder->fld_session,"INBOX"); 105 parseList(target,m_folder->fld_session,"INBOX");
106 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); 106 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages));
107} 107}
108 108
109void POP3wrapper::login() 109void POP3wrapper::login()
110{ 110{
111 /* we'll hold the line */ 111 /* we'll hold the line */
112 if ( m_pop3 != NULL ) return; 112 if ( m_pop3 != NULL ) return;
113 113
114 const char *server, *user, *pass; 114 const char *server, *user, *pass;
115 uint16_t port; 115 uint16_t port;
116 int err = MAILPOP3_NO_ERROR; 116 int err = MAILPOP3_NO_ERROR;
117 117
118 server = account->getServer().latin1(); 118 server = account->getServer().latin1();
119 port = account->getPort().toUInt(); 119 port = account->getPort().toUInt();
120 120
121 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 121 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
122 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 122 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
123 login.show(); 123 login.show();
124 if ( QDialog::Accepted == login.exec() ) { 124 if ( QDialog::Accepted == login.exec() ) {
125 // ok 125 // ok
126 user = login.getUser().latin1(); 126 user = login.getUser().latin1();
127 pass = login.getPassword().latin1(); 127 pass = login.getPassword().latin1();
128 } else { 128 } else {
129 // cancel 129 // cancel
130 qDebug( "POP3: Login canceled" ); 130 qDebug( "POP3: Login canceled" );
131 return; 131 return;
132 } 132 }
133 } else { 133 } else {
134 user = account->getUser().latin1(); 134 user = account->getUser().latin1();
135 pass = account->getPassword().latin1(); 135 pass = account->getPassword().latin1();
136 } 136 }
137 137
138 bool ssl = account->getSSL(); 138 bool ssl = account->getSSL();
139 139
140 m_pop3=mailstorage_new(NULL); 140 m_pop3=mailstorage_new(NULL);
141 pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,CONNECTION_TYPE_TRY_STARTTLS,POP3_AUTH_TYPE_TRY_APOP, 141 pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,CONNECTION_TYPE_TRY_STARTTLS,POP3_AUTH_TYPE_TRY_APOP,
142 (char*)user,(char*)pass,0,0,0); 142 (char*)user,(char*)pass,0,0,0);
143 143
144 m_folder = mailfolder_new(m_pop3, NULL, NULL); 144 m_folder = mailfolder_new(m_pop3, NULL, NULL);
145 145
146 if (m_folder==0) { 146 if (m_folder==0) {
147 Global::statusMessage(tr("Error initializing folder")); 147 Global::statusMessage(tr("Error initializing folder"));
148 mailstorage_free(m_pop3); 148 mailstorage_free(m_pop3);
149 m_pop3 = NULL; 149 m_pop3 = NULL;
150 return; 150 return;
151 } 151 }
152 err = mailfolder_connect(m_folder); 152 err = mailfolder_connect(m_folder);
153 if (err != MAIL_NO_ERROR) { 153 if (err != MAIL_NO_ERROR) {
154 Global::statusMessage(tr("Error initializing folder")); 154 Global::statusMessage(tr("Error initializing folder"));
155 mailfolder_free(m_folder); 155 mailfolder_free(m_folder);
156 m_folder = 0; 156 m_folder = 0;
157 mailstorage_free(m_pop3); 157 mailstorage_free(m_pop3);
158 m_pop3 = 0; 158 m_pop3 = 0;
159 } 159 }
160 qDebug( "POP3: logged in!" ); 160 qDebug( "POP3: logged in!" );
161} 161}
162 162
163void POP3wrapper::logout() 163void POP3wrapper::logout()
164{ 164{
165 int err = MAILPOP3_NO_ERROR; 165 int err = MAILPOP3_NO_ERROR;
166 if ( m_pop3 == NULL ) return; 166 if ( m_pop3 == NULL ) return;
167 mailfolder_free(m_folder); 167 mailfolder_free(m_folder);
168 m_folder = 0; 168 m_folder = 0;
169 mailstorage_free(m_pop3); 169 mailstorage_free(m_pop3);
170 m_pop3 = 0; 170 m_pop3 = 0;
171} 171}
172 172
173 173
174QList<Folder>* POP3wrapper::listFolders() 174QList<Folder>* POP3wrapper::listFolders()
175{ 175{
176 QList<Folder> * folders = new QList<Folder>(); 176 QList<Folder> * folders = new QList<Folder>();
177 folders->setAutoDelete( false ); 177 folders->setAutoDelete( false );
178 Folder*inb=new Folder("INBOX","/"); 178 Folder*inb=new Folder("INBOX","/");
179 folders->append(inb); 179 folders->append(inb);
180 return folders; 180 return folders;
181} 181}
182 182
183void POP3wrapper::deleteMail(const RecMail&mail) 183void POP3wrapper::deleteMail(const RecMail&mail)
184{ 184{
185 login(); 185 login();
186 if (!m_pop3) return; 186 if (!m_pop3) return;
187 int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber()); 187 int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber());
188 if (err != MAIL_NO_ERROR) { 188 if (err != MAIL_NO_ERROR) {
189 Global::statusMessage(tr("error deleting mail")); 189 Global::statusMessage(tr("error deleting mail"));
190 } 190 }
191} 191}
192 192
193void POP3wrapper::answeredMail(const RecMail&) 193void POP3wrapper::answeredMail(const RecMail&)
194{ 194{
195} 195}
196 196
197int POP3wrapper::deleteAllMail(const Folder*) 197int POP3wrapper::deleteAllMail(const Folder*)
198{ 198{
199 login(); 199 login();
200 if (!m_pop3) return 0; 200 if (!m_pop3) return 0;
201 int res = 1; 201 int res = 1;
202 202
203 uint32_t result = 0; 203 uint32_t result = 0;
204 int err = mailsession_messages_number(m_folder->fld_session,NULL,&result); 204 int err = mailsession_messages_number(m_folder->fld_session,NULL,&result);
205 if (err != MAIL_NO_ERROR) { 205 if (err != MAIL_NO_ERROR) {
206 Global::statusMessage(tr("Error getting folder info")); 206 Global::statusMessage(tr("Error getting folder info"));
207 return 0; 207 return 0;
208 } 208 }
209 for (unsigned int i = 0; i < result; ++i) { 209 for (unsigned int i = 0; i < result; ++i) {
210 err = mailsession_remove_message(m_folder->fld_session,i+1); 210 err = mailsession_remove_message(m_folder->fld_session,i+1);
211 if (err != MAIL_NO_ERROR) { 211 if (err != MAIL_NO_ERROR) {
212 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 212 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
213 res=0; 213 res=0;
214 } 214 }
215 break; 215 break;
216 } 216 }
217 return res; 217 return res;
218} 218}
219 219
220void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) 220void POP3wrapper::statusFolder(folderStat&target_stat,const QString&)
221{ 221{
222 login(); 222 login();
223 target_stat.message_count = 0; 223 target_stat.message_count = 0;
224 target_stat.message_unseen = 0; 224 target_stat.message_unseen = 0;
225 target_stat.message_recent = 0; 225 target_stat.message_recent = 0;
226 if (!m_pop3) return; 226 if (!m_pop3) return;
227 int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count, 227 int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count,
228 &target_stat.message_recent,&target_stat.message_unseen); 228 &target_stat.message_recent,&target_stat.message_unseen);
229} 229}
230 230
231void POP3wrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) 231encodedString* POP3wrapper::fetchRawBody(const RecMail&mail)
232{ 232{
233 char*target=0;
234 size_t length=0;
235 encodedString*res = 0;
233 mailmessage * mailmsg = 0; 236 mailmessage * mailmsg = 0;
234 int err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); 237 int err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg);
235 err = mailmessage_fetch(mailmsg,target,length); 238 err = mailmessage_fetch(mailmsg,&target,&length);
236 if (mailmsg) mailmessage_free(mailmsg); 239 if (mailmsg) mailmessage_free(mailmsg);
240 if (target) {
241 res = new encodedString(target,length);
242 }
243 return res;
237} 244}
238 245
239const QString&POP3wrapper::getType()const 246const QString&POP3wrapper::getType()const
240{ 247{
241 return account->getType(); 248 return account->getType();
242} 249}
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h
index b7e8f27..f0307b6 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.h
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h
@@ -1,41 +1,42 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include "genericwrapper.h" 5#include "genericwrapper.h"
6#include <qstring.h> 6#include <qstring.h>
7 7
8class encodedString;
8struct mailstorage; 9struct mailstorage;
9struct mailfolder; 10struct mailfolder;
10 11
11class POP3wrapper : public Genericwrapper 12class POP3wrapper : public Genericwrapper
12{ 13{
13 Q_OBJECT 14 Q_OBJECT
14 15
15public: 16public:
16 POP3wrapper( POP3account *a ); 17 POP3wrapper( POP3account *a );
17 virtual ~POP3wrapper(); 18 virtual ~POP3wrapper();
18 /* mailbox will be ignored */ 19 /* mailbox will be ignored */
19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 20 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
20 virtual QList<Folder>* listFolders(); 21 virtual QList<Folder>* listFolders();
21 /* mailbox will be ignored */ 22 /* mailbox will be ignored */
22 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 23 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
23 24
24 virtual void deleteMail(const RecMail&mail); 25 virtual void deleteMail(const RecMail&mail);
25 virtual void answeredMail(const RecMail&mail); 26 virtual void answeredMail(const RecMail&mail);
26 virtual int deleteAllMail(const Folder*); 27 virtual int deleteAllMail(const Folder*);
27 28
28 virtual RecBody fetchBody( const RecMail &mail ); 29 virtual RecBody fetchBody( const RecMail &mail );
29 virtual void fetchRawBody(const RecMail&mail,char**target,size_t*length); 30 virtual encodedString* fetchRawBody(const RecMail&mail);
30 virtual void logout(); 31 virtual void logout();
31 virtual const QString&getType()const; 32 virtual const QString&getType()const;
32 static void pop3_progress( size_t current, size_t maximum ); 33 static void pop3_progress( size_t current, size_t maximum );
33 34
34protected: 35protected:
35 void login(); 36 void login();
36 POP3account *account; 37 POP3account *account;
37 mailstorage*m_pop3; 38 mailstorage*m_pop3;
38 mailfolder*m_folder; 39 mailfolder*m_folder;
39}; 40};
40 41
41#endif 42#endif
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
index e054365..00181ff 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
@@ -1,734 +1,731 @@
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#include <qt.h> 8#include <qt.h>
9 9
10#include <qpe/config.h> 10#include <qpe/config.h>
11#include <qpe/qcopenvelope_qws.h> 11#include <qpe/qcopenvelope_qws.h>
12 12
13#include <libetpan/libetpan.h> 13#include <libetpan/libetpan.h>
14 14
15#include "smtpwrapper.h" 15#include "smtpwrapper.h"
16#include "mailwrapper.h" 16#include "mailwrapper.h"
17#include "mboxwrapper.h" 17#include "mboxwrapper.h"
18#include "logindialog.h" 18#include "logindialog.h"
19#include "mailtypes.h" 19#include "mailtypes.h"
20//#include "defines.h" 20//#include "defines.h"
21#include "sendmailprogress.h" 21#include "sendmailprogress.h"
22 22
23const char* SMTPwrapper::USER_AGENT="OpieMail v0.3"; 23const char* SMTPwrapper::USER_AGENT="OpieMail v0.3";
24 24
25progressMailSend*SMTPwrapper::sendProgress = 0; 25progressMailSend*SMTPwrapper::sendProgress = 0;
26 26
27SMTPwrapper::SMTPwrapper( Settings *s ) 27SMTPwrapper::SMTPwrapper( Settings *s )
28 : QObject() 28 : QObject()
29{ 29{
30 settings = s; 30 settings = s;
31 Config cfg( "mail" ); 31 Config cfg( "mail" );
32 cfg.setGroup( "Status" ); 32 cfg.setGroup( "Status" );
33 m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); 33 m_queuedMail = cfg.readNumEntry( "outgoing", 0 );
34 emit queuedMails( m_queuedMail ); 34 emit queuedMails( m_queuedMail );
35 connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) ); 35 connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) );
36} 36}
37 37
38void SMTPwrapper::emitQCop( int queued ) { 38void SMTPwrapper::emitQCop( int queued ) {
39 QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); 39 QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" );
40 env << queued; 40 env << queued;
41} 41}
42 42
43QString SMTPwrapper::mailsmtpError( int errnum ) 43QString SMTPwrapper::mailsmtpError( int errnum )
44{ 44{
45 switch ( errnum ) { 45 switch ( errnum ) {
46 case MAILSMTP_NO_ERROR: 46 case MAILSMTP_NO_ERROR:
47 return tr( "No error" ); 47 return tr( "No error" );
48 case MAILSMTP_ERROR_UNEXPECTED_CODE: 48 case MAILSMTP_ERROR_UNEXPECTED_CODE:
49 return tr( "Unexpected error code" ); 49 return tr( "Unexpected error code" );
50 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 50 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
51 return tr( "Service not available" ); 51 return tr( "Service not available" );
52 case MAILSMTP_ERROR_STREAM: 52 case MAILSMTP_ERROR_STREAM:
53 return tr( "Stream error" ); 53 return tr( "Stream error" );
54 case MAILSMTP_ERROR_HOSTNAME: 54 case MAILSMTP_ERROR_HOSTNAME:
55 return tr( "gethostname() failed" ); 55 return tr( "gethostname() failed" );
56 case MAILSMTP_ERROR_NOT_IMPLEMENTED: 56 case MAILSMTP_ERROR_NOT_IMPLEMENTED:
57 return tr( "Not implemented" ); 57 return tr( "Not implemented" );
58 case MAILSMTP_ERROR_ACTION_NOT_TAKEN: 58 case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
59 return tr( "Error, action not taken" ); 59 return tr( "Error, action not taken" );
60 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: 60 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
61 return tr( "Data exceeds storage allocation" ); 61 return tr( "Data exceeds storage allocation" );
62 case MAILSMTP_ERROR_IN_PROCESSING: 62 case MAILSMTP_ERROR_IN_PROCESSING:
63 return tr( "Error in processing" ); 63 return tr( "Error in processing" );
64 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 64 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
65 // return tr( "Insufficient system storage" ); 65 // return tr( "Insufficient system storage" );
66 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 66 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
67 return tr( "Mailbox unavailable" ); 67 return tr( "Mailbox unavailable" );
68 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: 68 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
69 return tr( "Mailbox name not allowed" ); 69 return tr( "Mailbox name not allowed" );
70 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: 70 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
71 return tr( "Bad command sequence" ); 71 return tr( "Bad command sequence" );
72 case MAILSMTP_ERROR_USER_NOT_LOCAL: 72 case MAILSMTP_ERROR_USER_NOT_LOCAL:
73 return tr( "User not local" ); 73 return tr( "User not local" );
74 case MAILSMTP_ERROR_TRANSACTION_FAILED: 74 case MAILSMTP_ERROR_TRANSACTION_FAILED:
75 return tr( "Transaction failed" ); 75 return tr( "Transaction failed" );
76 case MAILSMTP_ERROR_MEMORY: 76 case MAILSMTP_ERROR_MEMORY:
77 return tr( "Memory error" ); 77 return tr( "Memory error" );
78 case MAILSMTP_ERROR_CONNECTION_REFUSED: 78 case MAILSMTP_ERROR_CONNECTION_REFUSED:
79 return tr( "Connection refused" ); 79 return tr( "Connection refused" );
80 default: 80 default:
81 return tr( "Unknown error code" ); 81 return tr( "Unknown error code" );
82 } 82 }
83} 83}
84 84
85mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) 85mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail )
86{ 86{
87 return mailimf_mailbox_new( strdup( name.latin1() ), 87 return mailimf_mailbox_new( strdup( name.latin1() ),
88 strdup( mail.latin1() ) ); 88 strdup( mail.latin1() ) );
89} 89}
90 90
91mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) 91mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr )
92{ 92{
93 mailimf_address_list *addresses; 93 mailimf_address_list *addresses;
94 94
95 if ( addr.isEmpty() ) return NULL; 95 if ( addr.isEmpty() ) return NULL;
96 96
97 addresses = mailimf_address_list_new_empty(); 97 addresses = mailimf_address_list_new_empty();
98 98
99 bool literal_open = false; 99 bool literal_open = false;
100 unsigned int startpos = 0; 100 unsigned int startpos = 0;
101 QStringList list; 101 QStringList list;
102 QString s; 102 QString s;
103 unsigned int i = 0; 103 unsigned int i = 0;
104 for (; i < addr.length();++i) { 104 for (; i < addr.length();++i) {
105 switch (addr[i]) { 105 switch (addr[i]) {
106 case '\"': 106 case '\"':
107 literal_open = !literal_open; 107 literal_open = !literal_open;
108 break; 108 break;
109 case ',': 109 case ',':
110 if (!literal_open) { 110 if (!literal_open) {
111 s = addr.mid(startpos,i-startpos); 111 s = addr.mid(startpos,i-startpos);
112 if (!s.isEmpty()) { 112 if (!s.isEmpty()) {
113 list.append(s); 113 list.append(s);
114 qDebug("Appended %s",s.latin1()); 114 qDebug("Appended %s",s.latin1());
115 } 115 }
116 // !!!! this is a MUST BE! 116 // !!!! this is a MUST BE!
117 startpos = ++i; 117 startpos = ++i;
118 } 118 }
119 break; 119 break;
120 default: 120 default:
121 break; 121 break;
122 } 122 }
123 } 123 }
124 s = addr.mid(startpos,i-startpos); 124 s = addr.mid(startpos,i-startpos);
125 if (!s.isEmpty()) { 125 if (!s.isEmpty()) {
126 list.append(s); 126 list.append(s);
127 qDebug("Appended %s",s.latin1()); 127 qDebug("Appended %s",s.latin1());
128 } 128 }
129 QStringList::Iterator it; 129 QStringList::Iterator it;
130 for ( it = list.begin(); it != list.end(); it++ ) { 130 for ( it = list.begin(); it != list.end(); it++ ) {
131 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); 131 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() );
132 if ( err != MAILIMF_NO_ERROR ) { 132 if ( err != MAILIMF_NO_ERROR ) {
133 qDebug( "Error parsing" ); 133 qDebug( "Error parsing" );
134 qDebug( *it ); 134 qDebug( *it );
135 } else { 135 } else {
136 qDebug( "Parse success! %s",(*it).latin1()); 136 qDebug( "Parse success! %s",(*it).latin1());
137 } 137 }
138 } 138 }
139 return addresses; 139 return addresses;
140} 140}
141 141
142mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) 142mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail )
143{ 143{
144 mailimf_fields *fields; 144 mailimf_fields *fields;
145 mailimf_field *xmailer; 145 mailimf_field *xmailer;
146 mailimf_mailbox *sender=0,*fromBox=0; 146 mailimf_mailbox *sender=0,*fromBox=0;
147 mailimf_mailbox_list *from=0; 147 mailimf_mailbox_list *from=0;
148 mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; 148 mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0;
149 char *subject = strdup( mail.getSubject().latin1() ); 149 char *subject = strdup( mail.getSubject().latin1() );
150 int err; 150 int err;
151 151
152 sender = newMailbox( mail.getName(), mail.getMail() ); 152 sender = newMailbox( mail.getName(), mail.getMail() );
153 if ( sender == NULL ) goto err_free; 153 if ( sender == NULL ) goto err_free;
154 154
155 fromBox = newMailbox( mail.getName(), mail.getMail() ); 155 fromBox = newMailbox( mail.getName(), mail.getMail() );
156 if ( fromBox == NULL ) goto err_free_sender; 156 if ( fromBox == NULL ) goto err_free_sender;
157 157
158 from = mailimf_mailbox_list_new_empty(); 158 from = mailimf_mailbox_list_new_empty();
159 if ( from == NULL ) goto err_free_fromBox; 159 if ( from == NULL ) goto err_free_fromBox;
160 160
161 err = mailimf_mailbox_list_add( from, fromBox ); 161 err = mailimf_mailbox_list_add( from, fromBox );
162 if ( err != MAILIMF_NO_ERROR ) goto err_free_from; 162 if ( err != MAILIMF_NO_ERROR ) goto err_free_from;
163 163
164 to = parseAddresses( mail.getTo() ); 164 to = parseAddresses( mail.getTo() );
165 if ( to == NULL ) goto err_free_from; 165 if ( to == NULL ) goto err_free_from;
166 166
167 cc = parseAddresses( mail.getCC() ); 167 cc = parseAddresses( mail.getCC() );
168 bcc = parseAddresses( mail.getBCC() ); 168 bcc = parseAddresses( mail.getBCC() );
169 reply = parseAddresses( mail.getReply() ); 169 reply = parseAddresses( mail.getReply() );
170 170
171 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, 171 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
172 NULL, NULL, subject ); 172 NULL, NULL, subject );
173 if ( fields == NULL ) goto err_free_reply; 173 if ( fields == NULL ) goto err_free_reply;
174 174
175 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), 175 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
176 strdup( USER_AGENT ) ); 176 strdup( USER_AGENT ) );
177 if ( xmailer == NULL ) goto err_free_fields; 177 if ( xmailer == NULL ) goto err_free_fields;
178 178
179 err = mailimf_fields_add( fields, xmailer ); 179 err = mailimf_fields_add( fields, xmailer );
180 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; 180 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer;
181 181
182 return fields; // Success :) 182 return fields; // Success :)
183 183
184err_free_xmailer: 184err_free_xmailer:
185 if (xmailer) mailimf_field_free( xmailer ); 185 if (xmailer) mailimf_field_free( xmailer );
186err_free_fields: 186err_free_fields:
187 if (fields) mailimf_fields_free( fields ); 187 if (fields) mailimf_fields_free( fields );
188err_free_reply: 188err_free_reply:
189 if (reply) mailimf_address_list_free( reply ); 189 if (reply) mailimf_address_list_free( reply );
190 if (bcc) mailimf_address_list_free( bcc ); 190 if (bcc) mailimf_address_list_free( bcc );
191 if (cc) mailimf_address_list_free( cc ); 191 if (cc) mailimf_address_list_free( cc );
192 if (to) mailimf_address_list_free( to ); 192 if (to) mailimf_address_list_free( to );
193err_free_from: 193err_free_from:
194 if (from) mailimf_mailbox_list_free( from ); 194 if (from) mailimf_mailbox_list_free( from );
195err_free_fromBox: 195err_free_fromBox:
196 mailimf_mailbox_free( fromBox ); 196 mailimf_mailbox_free( fromBox );
197err_free_sender: 197err_free_sender:
198 if (sender) mailimf_mailbox_free( sender ); 198 if (sender) mailimf_mailbox_free( sender );
199err_free: 199err_free:
200 if (subject) free( subject ); 200 if (subject) free( subject );
201 qDebug( "createImfFields - error" ); 201 qDebug( "createImfFields - error" );
202 202
203 return NULL; // Error :( 203 return NULL; // Error :(
204} 204}
205 205
206mailmime *SMTPwrapper::buildTxtPart(const QString&str ) 206mailmime *SMTPwrapper::buildTxtPart(const QString&str )
207{ 207{
208 mailmime *txtPart; 208 mailmime *txtPart;
209 mailmime_fields *fields; 209 mailmime_fields *fields;
210 mailmime_content *content; 210 mailmime_content *content;
211 mailmime_parameter *param; 211 mailmime_parameter *param;
212 int err; 212 int err;
213 213
214 param = mailmime_parameter_new( strdup( "charset" ), 214 param = mailmime_parameter_new( strdup( "charset" ),
215 strdup( "iso-8859-1" ) ); 215 strdup( "iso-8859-1" ) );
216 if ( param == NULL ) goto err_free; 216 if ( param == NULL ) goto err_free;
217 217
218 content = mailmime_content_new_with_str( "text/plain" ); 218 content = mailmime_content_new_with_str( "text/plain" );
219 if ( content == NULL ) goto err_free_param; 219 if ( content == NULL ) goto err_free_param;
220 220
221 err = clist_append( content->ct_parameters, param ); 221 err = clist_append( content->ct_parameters, param );
222 if ( err != MAILIMF_NO_ERROR ) goto err_free_content; 222 if ( err != MAILIMF_NO_ERROR ) goto err_free_content;
223 223
224 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); 224 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT);
225 if ( fields == NULL ) goto err_free_content; 225 if ( fields == NULL ) goto err_free_content;
226 226
227 txtPart = mailmime_new_empty( content, fields ); 227 txtPart = mailmime_new_empty( content, fields );
228 if ( txtPart == NULL ) goto err_free_fields; 228 if ( txtPart == NULL ) goto err_free_fields;
229 229
230 err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); 230 err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() );
231 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 231 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
232 232
233 return txtPart; // Success :) 233 return txtPart; // Success :)
234 234
235err_free_txtPart: 235err_free_txtPart:
236 mailmime_free( txtPart ); 236 mailmime_free( txtPart );
237err_free_fields: 237err_free_fields:
238 mailmime_fields_free( fields ); 238 mailmime_fields_free( fields );
239err_free_content: 239err_free_content:
240 mailmime_content_free( content ); 240 mailmime_content_free( content );
241err_free_param: 241err_free_param:
242 mailmime_parameter_free( param ); 242 mailmime_parameter_free( param );
243err_free: 243err_free:
244 qDebug( "buildTxtPart - error" ); 244 qDebug( "buildTxtPart - error" );
245 245
246 return NULL; // Error :( 246 return NULL; // Error :(
247} 247}
248 248
249mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) 249mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent )
250{ 250{
251 mailmime * filePart = 0; 251 mailmime * filePart = 0;
252 mailmime_fields * fields = 0; 252 mailmime_fields * fields = 0;
253 mailmime_content * content = 0; 253 mailmime_content * content = 0;
254 mailmime_parameter * param = 0; 254 mailmime_parameter * param = 0;
255 char*name = 0; 255 char*name = 0;
256 char*file = 0; 256 char*file = 0;
257 int err; 257 int err;
258 258
259 int pos = filename.findRev( '/' ); 259 int pos = filename.findRev( '/' );
260 260
261 if (filename.length()>0) { 261 if (filename.length()>0) {
262 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 262 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
263 name = strdup( tmp.latin1() ); // just filename 263 name = strdup( tmp.latin1() ); // just filename
264 file = strdup( filename.latin1() ); // full name with path 264 file = strdup( filename.latin1() ); // full name with path
265 } 265 }
266 266
267 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; 267 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
268 int mechanism = MAILMIME_MECHANISM_BASE64; 268 int mechanism = MAILMIME_MECHANISM_BASE64;
269 269
270 if ( mimetype.startsWith( "text/" ) ) { 270 if ( mimetype.startsWith( "text/" ) ) {
271 param = mailmime_parameter_new( strdup( "charset" ), 271 param = mailmime_parameter_new( strdup( "charset" ),
272 strdup( "iso-8859-1" ) ); 272 strdup( "iso-8859-1" ) );
273 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 273 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
274 } 274 }
275 275
276 fields = mailmime_fields_new_filename( 276 fields = mailmime_fields_new_filename(
277 disptype, name, 277 disptype, name,
278 mechanism ); 278 mechanism );
279 content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); 279 content = mailmime_content_new_with_str( (char*)mimetype.latin1() );
280 if (content!=0 && fields != 0) { 280 if (content!=0 && fields != 0) {
281 if (param) { 281 if (param) {
282 clist_append(content->ct_parameters,param); 282 clist_append(content->ct_parameters,param);
283 param = 0; 283 param = 0;
284 } 284 }
285 if (filename.length()>0) { 285 if (filename.length()>0) {
286 QFileInfo f(filename); 286 QFileInfo f(filename);
287 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); 287 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1()));
288 clist_append(content->ct_parameters,param); 288 clist_append(content->ct_parameters,param);
289 param = 0; 289 param = 0;
290 } 290 }
291 filePart = mailmime_new_empty( content, fields ); 291 filePart = mailmime_new_empty( content, fields );
292 } 292 }
293 if (filePart) { 293 if (filePart) {
294 if (filename.length()>0) { 294 if (filename.length()>0) {
295 err = mailmime_set_body_file( filePart, file ); 295 err = mailmime_set_body_file( filePart, file );
296 } else { 296 } else {
297 err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); 297 err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length());
298 } 298 }
299 if (err != MAILIMF_NO_ERROR) { 299 if (err != MAILIMF_NO_ERROR) {
300 qDebug("Error setting body with file %s",file); 300 qDebug("Error setting body with file %s",file);
301 mailmime_free( filePart ); 301 mailmime_free( filePart );
302 filePart = 0; 302 filePart = 0;
303 } 303 }
304 } 304 }
305 305
306 if (!filePart) { 306 if (!filePart) {
307 if ( param != NULL ) { 307 if ( param != NULL ) {
308 mailmime_parameter_free( param ); 308 mailmime_parameter_free( param );
309 } 309 }
310 if (content) { 310 if (content) {
311 mailmime_content_free( content ); 311 mailmime_content_free( content );
312 } 312 }
313 if (fields) { 313 if (fields) {
314 mailmime_fields_free( fields ); 314 mailmime_fields_free( fields );
315 } else { 315 } else {
316 if (name) { 316 if (name) {
317 free( name ); 317 free( name );
318 } 318 }
319 if (file) { 319 if (file) {
320 free( file ); 320 free( file );
321 } 321 }
322 } 322 }
323 } 323 }
324 return filePart; // Success :) 324 return filePart; // Success :)
325 325
326} 326}
327 327
328void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) 328void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files )
329{ 329{
330 const Attachment *it; 330 const Attachment *it;
331 unsigned int count = files.count(); 331 unsigned int count = files.count();
332 qDebug("List contains %i values",count); 332 qDebug("List contains %i values",count);
333 for ( unsigned int i = 0; i < count; ++i ) { 333 for ( unsigned int i = 0; i < count; ++i ) {
334 qDebug( "Adding file" ); 334 qDebug( "Adding file" );
335 mailmime *filePart; 335 mailmime *filePart;
336 int err; 336 int err;
337 it = ((QList<Attachment>)files).at(i); 337 it = ((QList<Attachment>)files).at(i);
338 338
339 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); 339 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" );
340 if ( filePart == NULL ) { 340 if ( filePart == NULL ) {
341 qDebug( "addFileParts: error adding file:" ); 341 qDebug( "addFileParts: error adding file:" );
342 qDebug( it->getFileName() ); 342 qDebug( it->getFileName() );
343 continue; 343 continue;
344 } 344 }
345 err = mailmime_smart_add_part( message, filePart ); 345 err = mailmime_smart_add_part( message, filePart );
346 if ( err != MAILIMF_NO_ERROR ) { 346 if ( err != MAILIMF_NO_ERROR ) {
347 mailmime_free( filePart ); 347 mailmime_free( filePart );
348 qDebug("error smart add"); 348 qDebug("error smart add");
349 } 349 }
350 } 350 }
351} 351}
352 352
353mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) 353mailmime *SMTPwrapper::createMimeMail(const Mail &mail )
354{ 354{
355 mailmime *message, *txtPart; 355 mailmime *message, *txtPart;
356 mailimf_fields *fields; 356 mailimf_fields *fields;
357 int err; 357 int err;
358 358
359 fields = createImfFields( mail ); 359 fields = createImfFields( mail );
360 if ( fields == NULL ) goto err_free; 360 if ( fields == NULL ) goto err_free;
361 361
362 message = mailmime_new_message_data( NULL ); 362 message = mailmime_new_message_data( NULL );
363 if ( message == NULL ) goto err_free_fields; 363 if ( message == NULL ) goto err_free_fields;
364 364
365 mailmime_set_imf_fields( message, fields ); 365 mailmime_set_imf_fields( message, fields );
366 366
367 txtPart = buildTxtPart( mail.getMessage() ); 367 txtPart = buildTxtPart( mail.getMessage() );
368 368
369 if ( txtPart == NULL ) goto err_free_message; 369 if ( txtPart == NULL ) goto err_free_message;
370 370
371 err = mailmime_smart_add_part( message, txtPart ); 371 err = mailmime_smart_add_part( message, txtPart );
372 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 372 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
373 373
374 addFileParts( message, mail.getAttachments() ); 374 addFileParts( message, mail.getAttachments() );
375 375
376 return message; // Success :) 376 return message; // Success :)
377 377
378err_free_txtPart: 378err_free_txtPart:
379 mailmime_free( txtPart ); 379 mailmime_free( txtPart );
380err_free_message: 380err_free_message:
381 mailmime_free( message ); 381 mailmime_free( message );
382err_free_fields: 382err_free_fields:
383 mailimf_fields_free( fields ); 383 mailimf_fields_free( fields );
384err_free: 384err_free:
385 qDebug( "createMimeMail: error" ); 385 qDebug( "createMimeMail: error" );
386 386
387 return NULL; // Error :( 387 return NULL; // Error :(
388} 388}
389 389
390mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) 390mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type )
391{ 391{
392 mailimf_field *field; 392 mailimf_field *field;
393 clistiter *it; 393 clistiter *it;
394 394
395 it = clist_begin( fields->fld_list ); 395 it = clist_begin( fields->fld_list );
396 while ( it ) { 396 while ( it ) {
397 field = (mailimf_field *) it->data; 397 field = (mailimf_field *) it->data;
398 if ( field->fld_type == type ) { 398 if ( field->fld_type == type ) {
399 return field; 399 return field;
400 } 400 }
401 it = it->next; 401 it = it->next;
402 } 402 }
403 403
404 return NULL; 404 return NULL;
405} 405}
406 406
407void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) 407void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list )
408{ 408{
409 clistiter *it, *it2; 409 clistiter *it, *it2;
410 410
411 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { 411 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) {
412 mailimf_address *addr; 412 mailimf_address *addr;
413 addr = (mailimf_address *) it->data; 413 addr = (mailimf_address *) it->data;
414 414
415 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { 415 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) {
416 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); 416 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL );
417 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { 417 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) {
418 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; 418 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list;
419 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { 419 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
420 mailimf_mailbox *mbox; 420 mailimf_mailbox *mbox;
421 mbox = (mailimf_mailbox *) it2->data; 421 mbox = (mailimf_mailbox *) it2->data;
422 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); 422 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL );
423 } 423 }
424 } 424 }
425 } 425 }
426} 426}
427 427
428clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) 428clist *SMTPwrapper::createRcptList( mailimf_fields *fields )
429{ 429{
430 clist *rcptList; 430 clist *rcptList;
431 mailimf_field *field; 431 mailimf_field *field;
432 432
433 rcptList = esmtp_address_list_new(); 433 rcptList = esmtp_address_list_new();
434 434
435 field = getField( fields, MAILIMF_FIELD_TO ); 435 field = getField( fields, MAILIMF_FIELD_TO );
436 if ( field && (field->fld_type == MAILIMF_FIELD_TO) 436 if ( field && (field->fld_type == MAILIMF_FIELD_TO)
437 && field->fld_data.fld_to->to_addr_list ) { 437 && field->fld_data.fld_to->to_addr_list ) {
438 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); 438 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
439 } 439 }
440 440
441 field = getField( fields, MAILIMF_FIELD_CC ); 441 field = getField( fields, MAILIMF_FIELD_CC );
442 if ( field && (field->fld_type == MAILIMF_FIELD_CC) 442 if ( field && (field->fld_type == MAILIMF_FIELD_CC)
443 && field->fld_data.fld_cc->cc_addr_list ) { 443 && field->fld_data.fld_cc->cc_addr_list ) {
444 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); 444 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
445 } 445 }
446 446
447 field = getField( fields, MAILIMF_FIELD_BCC ); 447 field = getField( fields, MAILIMF_FIELD_BCC );
448 if ( field && (field->fld_type == MAILIMF_FIELD_BCC) 448 if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
449 && field->fld_data.fld_bcc->bcc_addr_list ) { 449 && field->fld_data.fld_bcc->bcc_addr_list ) {
450 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); 450 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
451 } 451 }
452 452
453 return rcptList; 453 return rcptList;
454} 454}
455 455
456char *SMTPwrapper::getFrom( mailimf_field *ffrom) 456char *SMTPwrapper::getFrom( mailimf_field *ffrom)
457{ 457{
458 char *from = NULL; 458 char *from = NULL;
459 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) 459 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM)
460 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { 460 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) {
461 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; 461 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list;
462 clistiter *it; 462 clistiter *it;
463 for ( it = clist_begin( cl ); it; it = it->next ) { 463 for ( it = clist_begin( cl ); it; it = it->next ) {
464 mailimf_mailbox *mb = (mailimf_mailbox *) it->data; 464 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
465 from = strdup( mb->mb_addr_spec ); 465 from = strdup( mb->mb_addr_spec );
466 } 466 }
467 } 467 }
468 468
469 return from; 469 return from;
470} 470}
471 471
472char *SMTPwrapper::getFrom( mailmime *mail ) 472char *SMTPwrapper::getFrom( mailmime *mail )
473{ 473{
474 /* no need to delete - its just a pointer to structure content */ 474 /* no need to delete - its just a pointer to structure content */
475 mailimf_field *ffrom = 0; 475 mailimf_field *ffrom = 0;
476 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); 476 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
477 return getFrom(ffrom); 477 return getFrom(ffrom);
478} 478}
479 479
480void SMTPwrapper::progress( size_t current, size_t maximum ) 480void SMTPwrapper::progress( size_t current, size_t maximum )
481{ 481{
482 if (SMTPwrapper::sendProgress) { 482 if (SMTPwrapper::sendProgress) {
483 SMTPwrapper::sendProgress->setSingleMail(current, maximum ); 483 SMTPwrapper::sendProgress->setSingleMail(current, maximum );
484 qApp->processEvents(); 484 qApp->processEvents();
485 } 485 }
486} 486}
487 487
488void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) 488void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box)
489{ 489{
490 if (!mail) return; 490 if (!mail) return;
491 QString localfolders = AbstractMail::defaultLocalfolder(); 491 QString localfolders = AbstractMail::defaultLocalfolder();
492 MBOXwrapper*wrap = new MBOXwrapper(localfolders); 492 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
493 wrap->storeMessage(mail,length,box); 493 wrap->storeMessage(mail,length,box);
494 delete wrap; 494 delete wrap;
495} 495}
496 496
497void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) 497void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
498{ 498{
499 clist *rcpts = 0; 499 clist *rcpts = 0;
500 char *from, *data; 500 char *from, *data;
501 size_t size; 501 size_t size;
502 502
503 if ( smtp == NULL ) { 503 if ( smtp == NULL ) {
504 return; 504 return;
505 } 505 }
506 from = data = 0; 506 from = data = 0;
507 507
508 mailmessage * msg = 0; 508 mailmessage * msg = 0;
509 msg = mime_message_init(mail); 509 msg = mime_message_init(mail);
510 mime_message_set_tmpdir(msg,getenv( "HOME" )); 510 mime_message_set_tmpdir(msg,getenv( "HOME" ));
511 int r = mailmessage_fetch(msg,&data,&size); 511 int r = mailmessage_fetch(msg,&data,&size);
512 mime_message_detach_mime(msg); 512 mime_message_detach_mime(msg);
513 mailmessage_free(msg); 513 mailmessage_free(msg);
514 if (r != MAIL_NO_ERROR || !data) { 514 if (r != MAIL_NO_ERROR || !data) {
515 if (data) free(data); 515 if (data) free(data);
516 qDebug("Error fetching mime..."); 516 qDebug("Error fetching mime...");
517 return; 517 return;
518 } 518 }
519 QString tmp = data; 519 QString tmp = data;
520 tmp.replace(QRegExp("\r+",true,false),""); 520 tmp.replace(QRegExp("\r+",true,false),"");
521 msg = 0; 521 msg = 0;
522 if (later) { 522 if (later) {
523 storeMail((char*)tmp.data(),tmp.length(),"Outgoing"); 523 storeMail((char*)tmp.data(),tmp.length(),"Outgoing");
524 if (data) free( data ); 524 if (data) free( data );
525 Config cfg( "mail" ); 525 Config cfg( "mail" );
526 cfg.setGroup( "Status" ); 526 cfg.setGroup( "Status" );
527 cfg.writeEntry( "outgoing", ++m_queuedMail ); 527 cfg.writeEntry( "outgoing", ++m_queuedMail );
528 emit queuedMails( m_queuedMail ); 528 emit queuedMails( m_queuedMail );
529 return; 529 return;
530 } 530 }
531 from = getFrom( mail ); 531 from = getFrom( mail );
532 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 532 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
533 smtpSend(from,rcpts,data,size,smtp); 533 smtpSend(from,rcpts,data,size,smtp);
534 if (data) {free(data);} 534 if (data) {free(data);}
535 if (from) {free(from);} 535 if (from) {free(from);}
536 if (rcpts) smtp_address_list_free( rcpts ); 536 if (rcpts) smtp_address_list_free( rcpts );
537} 537}
538 538
539int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) 539int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp )
540{ 540{
541 char *server, *user, *pass; 541 char *server, *user, *pass;
542 bool ssl; 542 bool ssl;
543 uint16_t port; 543 uint16_t port;
544 mailsmtp *session; 544 mailsmtp *session;
545 int err,result; 545 int err,result;
546 546
547 result = 1; 547 result = 1;
548 server = user = pass = 0; 548 server = user = pass = 0;
549 server = strdup( smtp->getServer().latin1() ); 549 server = strdup( smtp->getServer().latin1() );
550 ssl = smtp->getSSL(); 550 ssl = smtp->getSSL();
551 port = smtp->getPort().toUInt(); 551 port = smtp->getPort().toUInt();
552 552
553 session = mailsmtp_new( 20, &progress ); 553 session = mailsmtp_new( 20, &progress );
554 if ( session == NULL ) goto free_mem; 554 if ( session == NULL ) goto free_mem;
555 555
556 qDebug( "Servername %s at port %i", server, port ); 556 qDebug( "Servername %s at port %i", server, port );
557 if ( ssl ) { 557 if ( ssl ) {
558 qDebug( "SSL session" ); 558 qDebug( "SSL session" );
559 err = mailsmtp_ssl_connect( session, server, port ); 559 err = mailsmtp_ssl_connect( session, server, port );
560 } else { 560 } else {
561 qDebug( "No SSL session" ); 561 qDebug( "No SSL session" );
562 err = mailsmtp_socket_connect( session, server, port ); 562 err = mailsmtp_socket_connect( session, server, port );
563 } 563 }
564 if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;} 564 if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;}
565 565
566 err = mailsmtp_init( session ); 566 err = mailsmtp_init( session );
567 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} 567 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;}
568 568
569 qDebug( "INIT OK" ); 569 qDebug( "INIT OK" );
570 570
571 if ( smtp->getLogin() ) { 571 if ( smtp->getLogin() ) {
572 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { 572 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
573 // get'em 573 // get'em
574 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); 574 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true );
575 login.show(); 575 login.show();
576 if ( QDialog::Accepted == login.exec() ) { 576 if ( QDialog::Accepted == login.exec() ) {
577 // ok 577 // ok
578 user = strdup( login.getUser().latin1() ); 578 user = strdup( login.getUser().latin1() );
579 pass = strdup( login.getPassword().latin1() ); 579 pass = strdup( login.getPassword().latin1() );
580 } else { 580 } else {
581 result = 0; goto free_con_session; 581 result = 0; goto free_con_session;
582 } 582 }
583 } else { 583 } else {
584 user = strdup( smtp->getUser().latin1() ); 584 user = strdup( smtp->getUser().latin1() );
585 pass = strdup( smtp->getPassword().latin1() ); 585 pass = strdup( smtp->getPassword().latin1() );
586 } 586 }
587 qDebug( "session->auth: %i", session->auth); 587 qDebug( "session->auth: %i", session->auth);
588 err = mailsmtp_auth( session, user, pass ); 588 err = mailsmtp_auth( session, user, pass );
589 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); 589 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
590 qDebug( "Done auth!" ); 590 qDebug( "Done auth!" );
591 } 591 }
592 592
593 err = mailsmtp_send( session, from, rcpts, data, size ); 593 err = mailsmtp_send( session, from, rcpts, data, size );
594 if ( err != MAILSMTP_NO_ERROR ) { 594 if ( err != MAILSMTP_NO_ERROR ) {
595 qDebug("Error sending mail: %s",mailsmtpError(err).latin1()); 595 qDebug("Error sending mail: %s",mailsmtpError(err).latin1());
596 result = 0; goto free_con_session; 596 result = 0; goto free_con_session;
597 } 597 }
598 598
599 qDebug( "Mail sent." ); 599 qDebug( "Mail sent." );
600 storeMail(data,size,"Sent"); 600 storeMail(data,size,"Sent");
601 601
602free_con_session: 602free_con_session:
603 mailsmtp_quit( session ); 603 mailsmtp_quit( session );
604free_mem_session: 604free_mem_session:
605 mailsmtp_free( session ); 605 mailsmtp_free( session );
606free_mem: 606free_mem:
607 if (server) free( server ); 607 if (server) free( server );
608 if ( smtp->getLogin() ) { 608 if ( smtp->getLogin() ) {
609 free( user ); 609 free( user );
610 free( pass ); 610 free( pass );
611 } 611 }
612 return result; 612 return result;
613} 613}
614 614
615void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) 615void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later )
616{ 616{
617 mailmime * mimeMail; 617 mailmime * mimeMail;
618 618
619 SMTPaccount *smtp = aSmtp; 619 SMTPaccount *smtp = aSmtp;
620 620
621 if (!later && !smtp) { 621 if (!later && !smtp) {
622 qDebug("Didn't get any send method - giving up"); 622 qDebug("Didn't get any send method - giving up");
623 return; 623 return;
624 } 624 }
625 mimeMail = createMimeMail(mail ); 625 mimeMail = createMimeMail(mail );
626 if ( mimeMail == NULL ) { 626 if ( mimeMail == NULL ) {
627 qDebug( "sendMail: error creating mime mail" ); 627 qDebug( "sendMail: error creating mime mail" );
628 } else { 628 } else {
629 sendProgress = new progressMailSend(); 629 sendProgress = new progressMailSend();
630 sendProgress->show(); 630 sendProgress->show();
631 sendProgress->setMaxMails(1); 631 sendProgress->setMaxMails(1);
632 smtpSend( mimeMail,later,smtp); 632 smtpSend( mimeMail,later,smtp);
633 qDebug("Clean up done"); 633 qDebug("Clean up done");
634 sendProgress->hide(); 634 sendProgress->hide();
635 delete sendProgress; 635 delete sendProgress;
636 sendProgress = 0; 636 sendProgress = 0;
637 mailmime_free( mimeMail ); 637 mailmime_free( mimeMail );
638 } 638 }
639} 639}
640 640
641int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) 641int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
642{ 642{
643 char*data = 0;
644 size_t length = 0;
645 size_t curTok = 0; 643 size_t curTok = 0;
646 mailimf_fields *fields = 0; 644 mailimf_fields *fields = 0;
647 mailimf_field*ffrom = 0; 645 mailimf_field*ffrom = 0;
648 clist *rcpts = 0; 646 clist *rcpts = 0;
649 char*from = 0; 647 char*from = 0;
650 int res = 0; 648 int res = 0;
651 649
652 wrap->fetchRawBody(*which,&data,&length); 650 encodedString * data = wrap->fetchRawBody(*which);
653 if (!data) return 0; 651 if (!data) return 0;
654 int err = mailimf_fields_parse( data, length, &curTok, &fields ); 652 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields );
655 if (err != MAILIMF_NO_ERROR) { 653 if (err != MAILIMF_NO_ERROR) {
656 free(data); 654 delete data;
657 delete wrap; 655 delete wrap;
658 return 0; 656 return 0;
659 } 657 }
660 658
661 rcpts = createRcptList( fields ); 659 rcpts = createRcptList( fields );
662 ffrom = getField(fields, MAILIMF_FIELD_FROM ); 660 ffrom = getField(fields, MAILIMF_FIELD_FROM );
663 from = getFrom(ffrom); 661 from = getFrom(ffrom);
664 662
665 qDebug("Size: %i vs. %i",length,strlen(data));
666 if (rcpts && from) { 663 if (rcpts && from) {
667 res = smtpSend(from,rcpts,data,length,smtp ); 664 res = smtpSend(from,rcpts,data->Content(),data->Length(),smtp );
668 } 665 }
669 if (fields) { 666 if (fields) {
670 mailimf_fields_free(fields); 667 mailimf_fields_free(fields);
671 fields = 0; 668 fields = 0;
672 } 669 }
673 if (data) { 670 if (data) {
674 free(data); 671 delete data;
675 } 672 }
676 if (from) { 673 if (from) {
677 free(from); 674 free(from);
678 } 675 }
679 if (rcpts) { 676 if (rcpts) {
680 smtp_address_list_free( rcpts ); 677 smtp_address_list_free( rcpts );
681 } 678 }
682 return res; 679 return res;
683} 680}
684 681
685/* this is a special fun */ 682/* this is a special fun */
686bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) 683bool SMTPwrapper::flushOutbox(SMTPaccount*smtp)
687{ 684{
688 bool returnValue = true; 685 bool returnValue = true;
689 686
690 if (!smtp) return false; 687 if (!smtp) return false;
691 688
692 QString localfolders = AbstractMail::defaultLocalfolder(); 689 QString localfolders = AbstractMail::defaultLocalfolder();
693 MBOXwrapper*wrap = new MBOXwrapper(localfolders); 690 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
694 if (!wrap) { 691 if (!wrap) {
695 qDebug("memory error"); 692 qDebug("memory error");
696 return false; 693 return false;
697 } 694 }
698 QList<RecMail> mailsToSend; 695 QList<RecMail> mailsToSend;
699 QList<RecMail> mailsToRemove; 696 QList<RecMail> mailsToRemove;
700 QString mbox("Outgoing"); 697 QString mbox("Outgoing");
701 wrap->listMessages(mbox,mailsToSend); 698 wrap->listMessages(mbox,mailsToSend);
702 if (mailsToSend.count()==0) { 699 if (mailsToSend.count()==0) {
703 delete wrap; 700 delete wrap;
704 return false; 701 return false;
705 } 702 }
706 mailsToSend.setAutoDelete(false); 703 mailsToSend.setAutoDelete(false);
707 sendProgress = new progressMailSend(); 704 sendProgress = new progressMailSend();
708 sendProgress->show(); 705 sendProgress->show();
709 sendProgress->setMaxMails(mailsToSend.count()); 706 sendProgress->setMaxMails(mailsToSend.count());
710 707
711 while (mailsToSend.count()>0) { 708 while (mailsToSend.count()>0) {
712 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { 709 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) {
713 QMessageBox::critical(0,tr("Error sending mail"), 710 QMessageBox::critical(0,tr("Error sending mail"),
714 tr("Error sending queued mail - breaking")); 711 tr("Error sending queued mail - breaking"));
715 returnValue = false; 712 returnValue = false;
716 break; 713 break;
717 } 714 }
718 mailsToRemove.append(mailsToSend.at(0)); 715 mailsToRemove.append(mailsToSend.at(0));
719 mailsToSend.removeFirst(); 716 mailsToSend.removeFirst();
720 sendProgress->setCurrentMails(mailsToRemove.count()); 717 sendProgress->setCurrentMails(mailsToRemove.count());
721 } 718 }
722 Config cfg( "mail" ); 719 Config cfg( "mail" );
723 cfg.setGroup( "Status" ); 720 cfg.setGroup( "Status" );
724 m_queuedMail = 0; 721 m_queuedMail = 0;
725 cfg.writeEntry( "outgoing", m_queuedMail ); 722 cfg.writeEntry( "outgoing", m_queuedMail );
726 emit queuedMails( m_queuedMail ); 723 emit queuedMails( m_queuedMail );
727 sendProgress->hide(); 724 sendProgress->hide();
728 delete sendProgress; 725 delete sendProgress;
729 sendProgress = 0; 726 sendProgress = 0;
730 wrap->deleteMails(mbox,mailsToRemove); 727 wrap->deleteMails(mbox,mailsToRemove);
731 mailsToSend.setAutoDelete(true); 728 mailsToSend.setAutoDelete(true);
732 delete wrap; 729 delete wrap;
733 return returnValue; 730 return returnValue;
734} 731}
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h
index 4a4352f..04fc4b0 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.h
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h
@@ -1,72 +1,72 @@
1#ifndef SMTPwrapper_H 1#ifndef SMTPwrapper_H
2#define SMTPwrapper_H 2#define SMTPwrapper_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#include <libetpan/clist.h> 8#include <libetpan/clist.h>
9 9
10#include "settings.h" 10#include "settings.h"
11 11
12class Mail; 12class Mail;
13class MBOXwrapper; 13class MBOXwrapper;
14class RecMail; 14class RecMail;
15class Attachment; 15class Attachment;
16struct mailimf_fields; 16struct mailimf_fields;
17struct mailimf_field; 17struct mailimf_field;
18struct mailimf_mailbox; 18struct mailimf_mailbox;
19struct mailmime; 19struct mailmime;
20struct mailimf_address_list; 20struct mailimf_address_list;
21class progressMailSend; 21class progressMailSend;
22 22
23class SMTPwrapper : public QObject 23class SMTPwrapper : public QObject
24{ 24{
25 Q_OBJECT 25 Q_OBJECT
26 26
27public: 27public:
28 SMTPwrapper( Settings *s ); 28 SMTPwrapper( Settings *s );
29 virtual ~SMTPwrapper(){} 29 virtual ~SMTPwrapper(){}
30 void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false ); 30 void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false );
31 bool flushOutbox(SMTPaccount*smtp); 31 bool flushOutbox(SMTPaccount*smtp);
32 32
33 static progressMailSend*sendProgress; 33 static progressMailSend*sendProgress;
34 34
35signals: 35signals:
36 void queuedMails( int ); 36 void queuedMails( int );
37 37
38protected: 38protected:
39 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 39 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
40 mailimf_fields *createImfFields(const Mail &mail ); 40 mailimf_fields *createImfFields(const Mail &mail );
41 mailmime *createMimeMail(const Mail&mail ); 41 mailmime *createMimeMail(const Mail&mail );
42 42
43 mailimf_address_list *parseAddresses(const QString&addr ); 43 mailimf_address_list *parseAddresses(const QString&addr );
44 void addFileParts( mailmime *message,const QList<Attachment>&files ); 44 void addFileParts( mailmime *message,const QList<Attachment>&files );
45 mailmime *buildTxtPart(const QString&str ); 45 mailmime *buildTxtPart(const QString&str );
46 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); 46 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content);
47 void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); 47 void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp );
48 clist *createRcptList( mailimf_fields *fields ); 48 clist *createRcptList( mailimf_fields *fields );
49 49
50 static void storeMail(char*mail, size_t length, const QString&box); 50 static void storeMail(const char*mail, size_t length, const QString&box);
51 static QString mailsmtpError( int err ); 51 static QString mailsmtpError( int err );
52 static void progress( size_t current, size_t maximum ); 52 static void progress( size_t current, size_t maximum );
53 static void addRcpts( clist *list, mailimf_address_list *addr_list ); 53 static void addRcpts( clist *list, mailimf_address_list *addr_list );
54 static char *getFrom( mailmime *mail ); 54 static char *getFrom( mailmime *mail );
55 static char *getFrom( mailimf_field *ffrom); 55 static char *getFrom( mailimf_field *ffrom);
56 static mailimf_field *getField( mailimf_fields *fields, int type ); 56 static mailimf_field *getField( mailimf_fields *fields, int type );
57 int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); 57 int smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp );
58 58
59 void storeMail(mailmime*mail, const QString&box); 59 void storeMail(mailmime*mail, const QString&box);
60 Settings *settings; 60 Settings *settings;
61 61
62 int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which); 62 int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which);
63 63
64 int m_queuedMail; 64 int m_queuedMail;
65 static const char* USER_AGENT; 65 static const char* USER_AGENT;
66 66
67protected slots: 67protected slots:
68 void emitQCop( int queued ); 68 void emitQCop( int queued );
69 69
70}; 70};
71 71
72#endif 72#endif
diff --git a/noncore/net/mail/mail.pro b/noncore/net/mail/mail.pro
index 96ffaa8..1abd2e8 100644
--- a/noncore/net/mail/mail.pro
+++ b/noncore/net/mail/mail.pro
@@ -1,53 +1,56 @@
1CONFIG += qt warn_on debug quick-app 1CONFIG += qt warn_on debug quick-app
2 2
3HEADERS = defines.h \ 3HEADERS = defines.h \
4 editaccounts.h \ 4 editaccounts.h \
5 composemail.h \ 5 composemail.h \
6 accountview.h \ 6 accountview.h \
7 mainwindow.h \ 7 mainwindow.h \
8 viewmail.h \ 8 viewmail.h \
9 viewmailbase.h \ 9 viewmailbase.h \
10 opiemail.h \ 10 opiemail.h \
11 mailistviewitem.h \ 11 mailistviewitem.h \
12 settingsdialog.h \ 12 settingsdialog.h \
13 statuswidget.h \ 13 statuswidget.h \
14 newmaildir.h 14 newmaildir.h \
15 selectstore.h
15 16
16SOURCES = main.cpp \ 17SOURCES = main.cpp \
17 opiemail.cpp \ 18 opiemail.cpp \
18 mainwindow.cpp \ 19 mainwindow.cpp \
19 accountview.cpp \ 20 accountview.cpp \
20 composemail.cpp \ 21 composemail.cpp \
21 addresspicker.cpp \ 22 addresspicker.cpp \
22 editaccounts.cpp \ 23 editaccounts.cpp \
23 viewmail.cpp \ 24 viewmail.cpp \
24 viewmailbase.cpp \ 25 viewmailbase.cpp \
25 settingsdialog.cpp \ 26 settingsdialog.cpp \
26 statuswidget.cpp \ 27 statuswidget.cpp \
27 newmaildir.cpp 28 newmaildir.cpp \
29 selectstore.cpp
28 30
29INTERFACES = editaccountsui.ui \ 31INTERFACES = editaccountsui.ui \
30 selectmailtypeui.ui \ 32 selectmailtypeui.ui \
31 imapconfigui.ui \ 33 imapconfigui.ui \
32 pop3configui.ui \ 34 pop3configui.ui \
33 nntpconfigui.ui \ 35 nntpconfigui.ui \
34 smtpconfigui.ui \ 36 smtpconfigui.ui \
35 addresspickerui.ui \ 37 addresspickerui.ui \
36 composemailui.ui \ 38 composemailui.ui \
37 settingsdialogui.ui \ 39 settingsdialogui.ui \
38 statuswidgetui.ui \ 40 statuswidgetui.ui \
39 newmaildirui.ui 41 newmaildirui.ui \
42 selectstoreui.ui
40 43
41 44
42INCLUDEPATH += $(OPIEDIR)/include 45INCLUDEPATH += $(OPIEDIR)/include
43 46
44CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX ) 47CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX )
45contains( CONFTEST, y ){ 48contains( CONFTEST, y ){
46 LIBS += -lqpe -lopie -lmailwrapper -liconv 49 LIBS += -lqpe -lopie -lmailwrapper -liconv
47}else{ 50}else{
48 LIBS += -lqpe -lopie -lmailwrapper 51 LIBS += -lqpe -lopie -lmailwrapper
49} 52}
50 53
51TARGET = opiemail 54TARGET = opiemail
52 55
53include ( $(OPIEDIR)/include.pro ) 56include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/net/mail/selectstore.cpp b/noncore/net/mail/selectstore.cpp
new file mode 100644
index 0000000..28ab5a8
--- a/dev/null
+++ b/noncore/net/mail/selectstore.cpp
@@ -0,0 +1,19 @@
1#include "selectstore.h"
2
3Selectstore::Selectstore(QWidget* parent, const char* name)
4 :selectstoreui(parent,name,true)
5{
6
7}
8
9Selectstore::~Selectstore()
10{
11}
12
13void Selectstore::slotCreateNewFolder()
14{
15}
16
17void Selectstore::slotMoveMail()
18{
19}
diff --git a/noncore/net/mail/selectstore.h b/noncore/net/mail/selectstore.h
new file mode 100644
index 0000000..8b8e8ee
--- a/dev/null
+++ b/noncore/net/mail/selectstore.h
@@ -0,0 +1,19 @@
1#ifndef _SELECTSTORE_H
2#define _SELECTSTORE_H
3
4#include "selectstoreui.h"
5
6class Selectstore:public selectstoreui
7{
8 Q_OBJECT
9public:
10 Selectstore(QWidget* parent = 0, const char* name = 0);
11 virtual ~Selectstore();
12
13protected:
14 virtual void slotCreateNewFolder();
15 virtual void slotMoveMail();
16protected slots:
17
18};
19#endif
diff --git a/noncore/net/mail/selectstoreui.ui b/noncore/net/mail/selectstoreui.ui
new file mode 100644
index 0000000..3741b71
--- a/dev/null
+++ b/noncore/net/mail/selectstoreui.ui
@@ -0,0 +1,244 @@
1<!DOCTYPE UI><UI>
2<class>selectstoreui</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>selectstoreui</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>190</width>
15 <height>273</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Select target box</string>
21 </property>
22 <property>
23 <name>layoutMargin</name>
24 </property>
25 <property>
26 <name>layoutSpacing</name>
27 </property>
28 <vbox>
29 <property stdset="1">
30 <name>margin</name>
31 <number>2</number>
32 </property>
33 <property stdset="1">
34 <name>spacing</name>
35 <number>2</number>
36 </property>
37 <widget>
38 <class>QLabel</class>
39 <property stdset="1">
40 <name>name</name>
41 <cstring>headlabel</cstring>
42 </property>
43 <property stdset="1">
44 <name>text</name>
45 <string>&lt;b&gt;Store mail(s) to&lt;/b&gt;</string>
46 </property>
47 <property stdset="1">
48 <name>alignment</name>
49 <set>AlignCenter</set>
50 </property>
51 <property>
52 <name>hAlign</name>
53 </property>
54 </widget>
55 <widget>
56 <class>QLayoutWidget</class>
57 <property stdset="1">
58 <name>name</name>
59 <cstring>Layout2</cstring>
60 </property>
61 <grid>
62 <property stdset="1">
63 <name>margin</name>
64 <number>0</number>
65 </property>
66 <property stdset="1">
67 <name>spacing</name>
68 <number>6</number>
69 </property>
70 <widget row="1" column="1" >
71 <class>QComboBox</class>
72 <property stdset="1">
73 <name>name</name>
74 <cstring>folderSelection</cstring>
75 </property>
76 <property stdset="1">
77 <name>sizePolicy</name>
78 <sizepolicy>
79 <hsizetype>3</hsizetype>
80 <vsizetype>0</vsizetype>
81 </sizepolicy>
82 </property>
83 </widget>
84 <widget row="1" column="0" >
85 <class>QLabel</class>
86 <property stdset="1">
87 <name>name</name>
88 <cstring>folderLabel</cstring>
89 </property>
90 <property stdset="1">
91 <name>text</name>
92 <string>Folder:</string>
93 </property>
94 <property stdset="1">
95 <name>alignment</name>
96 <set>AlignVCenter|AlignRight</set>
97 </property>
98 <property>
99 <name>hAlign</name>
100 </property>
101 </widget>
102 <widget row="0" column="1" >
103 <class>QComboBox</class>
104 <property stdset="1">
105 <name>name</name>
106 <cstring>accountSelection</cstring>
107 </property>
108 <property stdset="1">
109 <name>sizePolicy</name>
110 <sizepolicy>
111 <hsizetype>3</hsizetype>
112 <vsizetype>0</vsizetype>
113 </sizepolicy>
114 </property>
115 </widget>
116 <widget row="0" column="0" >
117 <class>QLabel</class>
118 <property stdset="1">
119 <name>name</name>
120 <cstring>accountlabel</cstring>
121 </property>
122 <property stdset="1">
123 <name>sizePolicy</name>
124 <sizepolicy>
125 <hsizetype>1</hsizetype>
126 <vsizetype>1</vsizetype>
127 </sizepolicy>
128 </property>
129 <property stdset="1">
130 <name>text</name>
131 <string>Account:</string>
132 </property>
133 <property stdset="1">
134 <name>alignment</name>
135 <set>AlignVCenter|AlignRight</set>
136 </property>
137 <property>
138 <name>hAlign</name>
139 </property>
140 </widget>
141 </grid>
142 </widget>
143 <widget>
144 <class>Line</class>
145 <property stdset="1">
146 <name>name</name>
147 <cstring>Line1</cstring>
148 </property>
149 <property stdset="1">
150 <name>orientation</name>
151 <enum>Horizontal</enum>
152 </property>
153 </widget>
154 <widget>
155 <class>QCheckBox</class>
156 <property stdset="1">
157 <name>name</name>
158 <cstring>newFoldersel</cstring>
159 </property>
160 <property stdset="1">
161 <name>text</name>
162 <string>Create new folder</string>
163 </property>
164 </widget>
165 <widget>
166 <class>QLineEdit</class>
167 <property stdset="1">
168 <name>name</name>
169 <cstring>newFolderedit</cstring>
170 </property>
171 <property stdset="1">
172 <name>enabled</name>
173 <bool>false</bool>
174 </property>
175 </widget>
176 <widget>
177 <class>Line</class>
178 <property stdset="1">
179 <name>name</name>
180 <cstring>Line2</cstring>
181 </property>
182 <property stdset="1">
183 <name>orientation</name>
184 <enum>Horizontal</enum>
185 </property>
186 </widget>
187 <widget>
188 <class>QCheckBox</class>
189 <property stdset="1">
190 <name>name</name>
191 <cstring>selMove</cstring>
192 </property>
193 <property stdset="1">
194 <name>text</name>
195 <string>Move mail(s)</string>
196 </property>
197 </widget>
198 <spacer>
199 <property>
200 <name>name</name>
201 <cstring>Spacer2</cstring>
202 </property>
203 <property stdset="1">
204 <name>orientation</name>
205 <enum>Vertical</enum>
206 </property>
207 <property stdset="1">
208 <name>sizeType</name>
209 <enum>Expanding</enum>
210 </property>
211 <property>
212 <name>sizeHint</name>
213 <size>
214 <width>20</width>
215 <height>20</height>
216 </size>
217 </property>
218 </spacer>
219 </vbox>
220</widget>
221<connections>
222 <connection>
223 <sender>selMove</sender>
224 <signal>clicked()</signal>
225 <receiver>selectstoreui</receiver>
226 <slot>slotMoveMail()</slot>
227 </connection>
228 <connection>
229 <sender>newFoldersel</sender>
230 <signal>clicked()</signal>
231 <receiver>selectstoreui</receiver>
232 <slot>slotCreateNewFolder()</slot>
233 </connection>
234 <slot access="protected">slotMoveMail()</slot>
235 <slot access="protected">slotCreateNewFolder()</slot>
236</connections>
237<tabstops>
238 <tabstop>accountSelection</tabstop>
239 <tabstop>folderSelection</tabstop>
240 <tabstop>newFoldersel</tabstop>
241 <tabstop>newFolderedit</tabstop>
242 <tabstop>selMove</tabstop>
243</tabstops>
244</UI>