summaryrefslogtreecommitdiff
authoralwin <alwin>2004-01-08 19:15:10 (UTC)
committer alwin <alwin>2004-01-08 19:15:10 (UTC)
commit6287f011db0a566d17ae1614d8129f421125d934 (patch) (unidiff)
tree8c449974e9b577fe8dcc5348c4d109e82659b218
parent44443aec5d4b8f974b30b1e9b4ea920d6582add1 (diff)
downloadopie-6287f011db0a566d17ae1614d8129f421125d934.zip
opie-6287f011db0a566d17ae1614d8129f421125d934.tar.gz
opie-6287f011db0a566d17ae1614d8129f421125d934.tar.bz2
MH storage implemented
local folders will be type of MH not MBOX
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/accountview.cpp64
-rw-r--r--noncore/net/mail/accountview.h18
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.cpp3
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.cpp8
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.h4
-rw-r--r--noncore/net/mail/libmailwrapper/libmailwrapper.pro6
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.cpp18
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.h11
-rw-r--r--noncore/net/mail/libmailwrapper/mboxwrapper.h1
-rw-r--r--noncore/net/mail/libmailwrapper/mhwrapper.cpp330
-rw-r--r--noncore/net/mail/libmailwrapper/mhwrapper.h50
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp3
12 files changed, 468 insertions, 48 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp
index 9f4f358..62cbf62 100644
--- a/noncore/net/mail/accountview.cpp
+++ b/noncore/net/mail/accountview.cpp
@@ -1,902 +1,902 @@
1#include "accountview.h" 1#include "accountview.h"
2#include <libmailwrapper/mailtypes.h> 2#include <libmailwrapper/mailtypes.h>
3#include <libmailwrapper/abstractmail.h> 3#include <libmailwrapper/abstractmail.h>
4#include "defines.h" 4#include "defines.h"
5#include "newmaildir.h" 5#include "newmaildir.h"
6#include "selectstore.h" 6#include "selectstore.h"
7#include <qmessagebox.h> 7#include <qmessagebox.h>
8#include <qpopupmenu.h> 8#include <qpopupmenu.h>
9 9
10#define SETPIX(x) if (!account->getOffline()) {setPixmap( 0,x);} else {setPixmap( 0, PIXMAP_OFFLINE );} 10#define SETPIX(x) if (!account->getOffline()) {setPixmap( 0,x);} else {setPixmap( 0, PIXMAP_OFFLINE );}
11/** 11/**
12 * POP3 Account stuff 12 * POP3 Account stuff
13 */ 13 */
14POP3viewItem::POP3viewItem( POP3account *a, AccountView *parent ) 14POP3viewItem::POP3viewItem( POP3account *a, AccountView *parent )
15 : AccountViewItem( parent ) 15 : AccountViewItem( parent )
16{ 16{
17 account = a; 17 account = a;
18 wrapper = AbstractMail::getWrapper( account ); 18 wrapper = AbstractMail::getWrapper( account );
19 SETPIX(PIXMAP_POP3FOLDER); 19 SETPIX(PIXMAP_POP3FOLDER);
20#if 0 20#if 0
21 if (!account->getOffline()) { 21 if (!account->getOffline()) {
22 setPixmap( 0, ); 22 setPixmap( 0, );
23 } else { 23 } else {
24 setPixmap( 0, PIXMAP_OFFLINE ); 24 setPixmap( 0, PIXMAP_OFFLINE );
25 } 25 }
26#endif 26#endif
27 setText( 0, account->getAccountName() ); 27 setText( 0, account->getAccountName() );
28 setOpen( true ); 28 setOpen( true );
29} 29}
30 30
31POP3viewItem::~POP3viewItem() 31POP3viewItem::~POP3viewItem()
32{ 32{
33 delete wrapper; 33 delete wrapper;
34} 34}
35 35
36AbstractMail *POP3viewItem::getWrapper() 36AbstractMail *POP3viewItem::getWrapper()
37{ 37{
38 return wrapper; 38 return wrapper;
39} 39}
40 40
41void POP3viewItem::refresh( QList<RecMail> & ) 41void POP3viewItem::refresh( QList<RecMail> & )
42{ 42{
43 refresh(); 43 refresh();
44} 44}
45 45
46void POP3viewItem::refresh() 46void POP3viewItem::refresh()
47{ 47{
48 if (account->getOffline()) return; 48 if (account->getOffline()) return;
49 QList<Folder> *folders = wrapper->listFolders(); 49 QList<Folder> *folders = wrapper->listFolders();
50 QListViewItem *child = firstChild(); 50 QListViewItem *child = firstChild();
51 while ( child ) { 51 while ( child ) {
52 QListViewItem *tmp = child; 52 QListViewItem *tmp = child;
53 child = child->nextSibling(); 53 child = child->nextSibling();
54 delete tmp; 54 delete tmp;
55 } 55 }
56 Folder *it; 56 Folder *it;
57 QListViewItem*item = 0; 57 QListViewItem*item = 0;
58 for ( it = folders->first(); it; it = folders->next() ) { 58 for ( it = folders->first(); it; it = folders->next() ) {
59 item = new POP3folderItem( it, this , item ); 59 item = new POP3folderItem( it, this , item );
60 item->setSelectable(it->may_select()); 60 item->setSelectable(it->may_select());
61 } 61 }
62 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 62 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
63 folders->setAutoDelete(false); 63 folders->setAutoDelete(false);
64 delete folders; 64 delete folders;
65} 65}
66 66
67RecBody POP3viewItem::fetchBody( const RecMail &mail ) 67RecBody POP3viewItem::fetchBody( const RecMail &mail )
68{ 68{
69 qDebug( "POP3 fetchBody" ); 69 qDebug( "POP3 fetchBody" );
70 return wrapper->fetchBody( mail ); 70 return wrapper->fetchBody( mail );
71} 71}
72 72
73QPopupMenu * POP3viewItem::getContextMenu() 73QPopupMenu * POP3viewItem::getContextMenu()
74{ 74{
75 QPopupMenu *m = new QPopupMenu(0); 75 QPopupMenu *m = new QPopupMenu(0);
76 if (m) { 76 if (m) {
77 if (!account->getOffline()) { 77 if (!account->getOffline()) {
78 m->insertItem(QObject::tr("Disconnect",contextName),0); 78 m->insertItem(QObject::tr("Disconnect",contextName),0);
79 m->insertItem(QObject::tr("Set offline",contextName),1); 79 m->insertItem(QObject::tr("Set offline",contextName),1);
80 } else { 80 } else {
81 m->insertItem(QObject::tr("Set online",contextName),1); 81 m->insertItem(QObject::tr("Set online",contextName),1);
82 } 82 }
83 } 83 }
84 return m; 84 return m;
85} 85}
86 86
87void POP3viewItem::disconnect() 87void POP3viewItem::disconnect()
88{ 88{
89 QListViewItem *child = firstChild(); 89 QListViewItem *child = firstChild();
90 while ( child ) { 90 while ( child ) {
91 QListViewItem *tmp = child; 91 QListViewItem *tmp = child;
92 child = child->nextSibling(); 92 child = child->nextSibling();
93 delete tmp; 93 delete tmp;
94 } 94 }
95 wrapper->logout(); 95 wrapper->logout();
96} 96}
97 97
98void POP3viewItem::setOnOffline() 98void POP3viewItem::setOnOffline()
99{ 99{
100 if (!account->getOffline()) { 100 if (!account->getOffline()) {
101 disconnect(); 101 disconnect();
102 } 102 }
103 account->setOffline(!account->getOffline()); 103 account->setOffline(!account->getOffline());
104 account->save(); 104 account->save();
105 SETPIX(PIXMAP_POP3FOLDER); 105 SETPIX(PIXMAP_POP3FOLDER);
106 refresh(); 106 refresh();
107} 107}
108 108
109void POP3viewItem::contextMenuSelected(int which) 109void POP3viewItem::contextMenuSelected(int which)
110{ 110{
111 switch (which) { 111 switch (which) {
112 case 0: 112 case 0:
113 disconnect(); 113 disconnect();
114 break; 114 break;
115 case 1: 115 case 1:
116 setOnOffline(); 116 setOnOffline();
117 break; 117 break;
118 } 118 }
119} 119}
120 120
121POP3folderItem::~POP3folderItem() 121POP3folderItem::~POP3folderItem()
122{ 122{
123 delete folder; 123 delete folder;
124} 124}
125 125
126POP3folderItem::POP3folderItem( Folder *folderInit, POP3viewItem *parent , QListViewItem*after ) 126POP3folderItem::POP3folderItem( Folder *folderInit, POP3viewItem *parent , QListViewItem*after )
127 : AccountViewItem( parent,after ) 127 : AccountViewItem( parent,after )
128{ 128{
129 folder = folderInit; 129 folder = folderInit;
130 pop3 = parent; 130 pop3 = parent;
131 if (folder->getDisplayName().lower()!="inbox") { 131 if (folder->getDisplayName().lower()!="inbox") {
132 setPixmap( 0, PIXMAP_POP3FOLDER ); 132 setPixmap( 0, PIXMAP_POP3FOLDER );
133 } else { 133 } else {
134 setPixmap( 0, PIXMAP_INBOXFOLDER); 134 setPixmap( 0, PIXMAP_INBOXFOLDER);
135 } 135 }
136 setText( 0, folder->getDisplayName() ); 136 setText( 0, folder->getDisplayName() );
137} 137}
138 138
139void POP3folderItem::refresh(QList<RecMail>&target) 139void POP3folderItem::refresh(QList<RecMail>&target)
140{ 140{
141 if (folder->may_select()) 141 if (folder->may_select())
142 pop3->getWrapper()->listMessages( folder->getName(),target ); 142 pop3->getWrapper()->listMessages( folder->getName(),target );
143} 143}
144 144
145RecBody POP3folderItem::fetchBody(const RecMail&aMail) 145RecBody POP3folderItem::fetchBody(const RecMail&aMail)
146{ 146{
147 return pop3->getWrapper()->fetchBody(aMail); 147 return pop3->getWrapper()->fetchBody(aMail);
148} 148}
149 149
150QPopupMenu * POP3folderItem::getContextMenu() 150QPopupMenu * POP3folderItem::getContextMenu()
151{ 151{
152 QPopupMenu *m = new QPopupMenu(0); 152 QPopupMenu *m = new QPopupMenu(0);
153 if (m) { 153 if (m) {
154 m->insertItem(QObject::tr("Refresh header list",contextName),0); 154 m->insertItem(QObject::tr("Refresh header list",contextName),0);
155 m->insertItem(QObject::tr("Delete all mails",contextName),1); 155 m->insertItem(QObject::tr("Delete all mails",contextName),1);
156 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); 156 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2);
157 } 157 }
158 return m; 158 return m;
159} 159}
160 160
161void POP3folderItem::downloadMails() 161void POP3folderItem::downloadMails()
162{ 162{
163 AccountView*bl = pop3->accountView(); 163 AccountView*bl = pop3->accountView();
164 if (!bl) return; 164 if (!bl) return;
165 bl->downloadMails(folder,pop3->getWrapper()); 165 bl->downloadMails(folder,pop3->getWrapper());
166} 166}
167 167
168void POP3folderItem::contextMenuSelected(int which) 168void POP3folderItem::contextMenuSelected(int which)
169{ 169{
170 AccountView * view = (AccountView*)listView(); 170 AccountView * view = (AccountView*)listView();
171 switch (which) { 171 switch (which) {
172 case 0: 172 case 0:
173 /* must be 'cause pop3 lists are cached */ 173 /* must be 'cause pop3 lists are cached */
174 pop3->getWrapper()->logout(); 174 pop3->getWrapper()->logout();
175 view->refreshCurrent(); 175 view->refreshCurrent();
176 break; 176 break;
177 case 1: 177 case 1:
178 deleteAllMail(pop3->getWrapper(),folder); 178 deleteAllMail(pop3->getWrapper(),folder);
179 break; 179 break;
180 case 2: 180 case 2:
181 downloadMails(); 181 downloadMails();
182 break; 182 break;
183 default: 183 default:
184 break; 184 break;
185 } 185 }
186} 186}
187 187
188/** 188/**
189 * IMAP Account stuff 189 * IMAP Account stuff
190 */ 190 */
191IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent ) 191IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent )
192 : AccountViewItem( parent ) 192 : AccountViewItem( parent )
193{ 193{
194 account = a; 194 account = a;
195 wrapper = AbstractMail::getWrapper( account ); 195 wrapper = AbstractMail::getWrapper( account );
196 SETPIX(PIXMAP_IMAPFOLDER); 196 SETPIX(PIXMAP_IMAPFOLDER);
197 setText( 0, account->getAccountName() ); 197 setText( 0, account->getAccountName() );
198 setOpen( true ); 198 setOpen( true );
199} 199}
200 200
201IMAPviewItem::~IMAPviewItem() 201IMAPviewItem::~IMAPviewItem()
202{ 202{
203 delete wrapper; 203 delete wrapper;
204} 204}
205 205
206AbstractMail *IMAPviewItem::getWrapper() 206AbstractMail *IMAPviewItem::getWrapper()
207{ 207{
208 return wrapper; 208 return wrapper;
209} 209}
210 210
211IMAPfolderItem*IMAPviewItem::findSubItem(const QString&path,IMAPfolderItem*start) 211IMAPfolderItem*IMAPviewItem::findSubItem(const QString&path,IMAPfolderItem*start)
212{ 212{
213 IMAPfolderItem*pitem,*sitem; 213 IMAPfolderItem*pitem,*sitem;
214 if (!start) pitem = (IMAPfolderItem*)firstChild(); 214 if (!start) pitem = (IMAPfolderItem*)firstChild();
215 else pitem = (IMAPfolderItem*)start->firstChild(); 215 else pitem = (IMAPfolderItem*)start->firstChild();
216 while (pitem) { 216 while (pitem) {
217 if (pitem->matchName(path)) { 217 if (pitem->matchName(path)) {
218 break; 218 break;
219 } 219 }
220 if (pitem->childCount()>0) { 220 if (pitem->childCount()>0) {
221 sitem = findSubItem(path,pitem); 221 sitem = findSubItem(path,pitem);
222 if (sitem) { 222 if (sitem) {
223 pitem = sitem; 223 pitem = sitem;
224 break; 224 break;
225 } 225 }
226 } 226 }
227 pitem=(IMAPfolderItem*)pitem->nextSibling(); 227 pitem=(IMAPfolderItem*)pitem->nextSibling();
228 } 228 }
229 return pitem; 229 return pitem;
230} 230}
231 231
232void IMAPviewItem::refresh(QList<RecMail>&) 232void IMAPviewItem::refresh(QList<RecMail>&)
233{ 233{
234 refreshFolders(false); 234 refreshFolders(false);
235} 235}
236 236
237void IMAPviewItem::removeChilds() 237void IMAPviewItem::removeChilds()
238{ 238{
239 QListViewItem *child = firstChild(); 239 QListViewItem *child = firstChild();
240 while ( child ) { 240 while ( child ) {
241 QListViewItem *tmp = child; 241 QListViewItem *tmp = child;
242 child = child->nextSibling(); 242 child = child->nextSibling();
243 delete tmp; 243 delete tmp;
244 } 244 }
245 245
246} 246}
247 247
248const QStringList&IMAPviewItem::subFolders() 248const QStringList&IMAPviewItem::subFolders()
249{ 249{
250 return currentFolders; 250 return currentFolders;
251} 251}
252 252
253void IMAPviewItem::refreshFolders(bool force) 253void IMAPviewItem::refreshFolders(bool force)
254{ 254{
255 if (childCount()>0 && force==false) return; 255 if (childCount()>0 && force==false) return;
256 if (account->getOffline()) return; 256 if (account->getOffline()) return;
257 257
258 removeChilds(); 258 removeChilds();
259 currentFolders.clear(); 259 currentFolders.clear();
260 QList<Folder> *folders = wrapper->listFolders(); 260 QList<Folder> *folders = wrapper->listFolders();
261 261
262 Folder *it; 262 Folder *it;
263 QListViewItem*item = 0; 263 QListViewItem*item = 0;
264 QListViewItem*titem = 0; 264 QListViewItem*titem = 0;
265 QString fname,del,search; 265 QString fname,del,search;
266 int pos; 266 int pos;
267 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 267 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
268 folders->setAutoDelete(false); 268 folders->setAutoDelete(false);
269 269
270 for ( it = folders->first(); it; it = folders->next() ) { 270 for ( it = folders->first(); it; it = folders->next() ) {
271 if (it->getDisplayName().lower()=="inbox") { 271 if (it->getDisplayName().lower()=="inbox") {
272 item = new IMAPfolderItem( it, this , item ); 272 item = new IMAPfolderItem( it, this , item );
273 folders->remove(it); 273 folders->remove(it);
274 qDebug("inbox found"); 274 qDebug("inbox found");
275 break; 275 break;
276 } 276 }
277 } 277 }
278 for ( it = folders->first(); it; it = folders->next() ) { 278 for ( it = folders->first(); it; it = folders->next() ) {
279 fname = it->getDisplayName(); 279 fname = it->getDisplayName();
280 currentFolders.append(it->getName()); 280 currentFolders.append(it->getName());
281 pos = fname.findRev(it->Separator()); 281 pos = fname.findRev(it->Separator());
282 if (pos != -1) { 282 if (pos != -1) {
283 fname = fname.left(pos); 283 fname = fname.left(pos);
284 } 284 }
285 IMAPfolderItem*pitem = findSubItem(fname); 285 IMAPfolderItem*pitem = findSubItem(fname);
286 if (pitem) { 286 if (pitem) {
287 titem = item; 287 titem = item;
288 item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this); 288 item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this);
289 /* setup the short name */ 289 /* setup the short name */
290 item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1)); 290 item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1));
291 item = titem; 291 item = titem;
292 } else { 292 } else {
293 item = new IMAPfolderItem( it, this , item ); 293 item = new IMAPfolderItem( it, this , item );
294 } 294 }
295 } 295 }
296 delete folders; 296 delete folders;
297} 297}
298 298
299QPopupMenu * IMAPviewItem::getContextMenu() 299QPopupMenu * IMAPviewItem::getContextMenu()
300{ 300{
301 QPopupMenu *m = new QPopupMenu(0); 301 QPopupMenu *m = new QPopupMenu(0);
302 if (m) { 302 if (m) {
303 if (!account->getOffline()) { 303 if (!account->getOffline()) {
304 m->insertItem(QObject::tr("Refresh folder list",contextName),0); 304 m->insertItem(QObject::tr("Refresh folder list",contextName),0);
305 m->insertItem(QObject::tr("Create new folder",contextName),1); 305 m->insertItem(QObject::tr("Create new folder",contextName),1);
306 m->insertSeparator(); 306 m->insertSeparator();
307 m->insertItem(QObject::tr("Disconnect",contextName),2); 307 m->insertItem(QObject::tr("Disconnect",contextName),2);
308 m->insertItem(QObject::tr("Set offline",contextName),3); 308 m->insertItem(QObject::tr("Set offline",contextName),3);
309 } else { 309 } else {
310 m->insertItem(QObject::tr("Set online",contextName),3); 310 m->insertItem(QObject::tr("Set online",contextName),3);
311 } 311 }
312 } 312 }
313 return m; 313 return m;
314} 314}
315 315
316void IMAPviewItem::createNewFolder() 316void IMAPviewItem::createNewFolder()
317{ 317{
318 Newmdirdlg ndirdlg; 318 Newmdirdlg ndirdlg;
319 ndirdlg.showMaximized(); 319 ndirdlg.showMaximized();
320 if (ndirdlg.exec()) { 320 if (ndirdlg.exec()) {
321 QString ndir = ndirdlg.Newdir(); 321 QString ndir = ndirdlg.Newdir();
322 bool makesubs = ndirdlg.subpossible(); 322 bool makesubs = ndirdlg.subpossible();
323 QString delemiter = "/"; 323 QString delemiter = "/";
324 IMAPfolderItem*item = (IMAPfolderItem*)firstChild(); 324 IMAPfolderItem*item = (IMAPfolderItem*)firstChild();
325 if (item) { 325 if (item) {
326 delemiter = item->Delemiter(); 326 delemiter = item->Delemiter();
327 } 327 }
328 if (wrapper->createMbox(ndir,0,delemiter,makesubs)) { 328 if (wrapper->createMbox(ndir,0,delemiter,makesubs)) {
329 refreshFolders(true); 329 refreshFolders(true);
330 } 330 }
331 } 331 }
332} 332}
333 333
334void IMAPviewItem::contextMenuSelected(int id) 334void IMAPviewItem::contextMenuSelected(int id)
335{ 335{
336 qDebug("Id selected: %i",id); 336 qDebug("Id selected: %i",id);
337 switch (id) { 337 switch (id) {
338 case 0: 338 case 0:
339 refreshFolders(true); 339 refreshFolders(true);
340 break; 340 break;
341 case 1: 341 case 1:
342 createNewFolder(); 342 createNewFolder();
343 break; 343 break;
344 case 2: 344 case 2:
345 removeChilds(); 345 removeChilds();
346 wrapper->logout(); 346 wrapper->logout();
347 break; 347 break;
348 case 3: 348 case 3:
349 if (account->getOffline()==false) { 349 if (account->getOffline()==false) {
350 removeChilds(); 350 removeChilds();
351 wrapper->logout(); 351 wrapper->logout();
352 } 352 }
353 account->setOffline(!account->getOffline()); 353 account->setOffline(!account->getOffline());
354 account->save(); 354 account->save();
355 SETPIX(PIXMAP_IMAPFOLDER); 355 SETPIX(PIXMAP_IMAPFOLDER);
356 refreshFolders(false); 356 refreshFolders(false);
357 break; 357 break;
358 default: 358 default:
359 break; 359 break;
360 } 360 }
361} 361}
362 362
363RecBody IMAPviewItem::fetchBody(const RecMail&) 363RecBody IMAPviewItem::fetchBody(const RecMail&)
364{ 364{
365 return RecBody(); 365 return RecBody();
366} 366}
367 367
368bool IMAPviewItem::offline() 368bool IMAPviewItem::offline()
369{ 369{
370 return account->getOffline(); 370 return account->getOffline();
371} 371}
372 372
373IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after ) 373IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after )
374 : AccountViewItem( parent , after ) 374 : AccountViewItem( parent , after )
375{ 375{
376 folder = folderInit; 376 folder = folderInit;
377 imap = parent; 377 imap = parent;
378 if (folder->getDisplayName().lower()!="inbox") { 378 if (folder->getDisplayName().lower()!="inbox") {
379 setPixmap( 0, PIXMAP_IMAPFOLDER ); 379 setPixmap( 0, PIXMAP_IMAPFOLDER );
380 } else { 380 } else {
381 setPixmap( 0, PIXMAP_INBOXFOLDER); 381 setPixmap( 0, PIXMAP_INBOXFOLDER);
382 } 382 }
383 setText( 0, folder->getDisplayName() ); 383 setText( 0, folder->getDisplayName() );
384} 384}
385 385
386IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ) 386IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master )
387 : AccountViewItem( parent,after ) 387 : AccountViewItem( parent,after )
388{ 388{
389 folder = folderInit; 389 folder = folderInit;
390 imap = master; 390 imap = master;
391 if (folder->getDisplayName().lower()!="inbox") { 391 if (folder->getDisplayName().lower()!="inbox") {
392 setPixmap( 0, PIXMAP_IMAPFOLDER ); 392 setPixmap( 0, PIXMAP_IMAPFOLDER );
393 } else { 393 } else {
394 setPixmap( 0, PIXMAP_INBOXFOLDER); 394 setPixmap( 0, PIXMAP_INBOXFOLDER);
395 } 395 }
396 setText( 0, folder->getDisplayName() ); 396 setText( 0, folder->getDisplayName() );
397} 397}
398 398
399IMAPfolderItem::~IMAPfolderItem() 399IMAPfolderItem::~IMAPfolderItem()
400{ 400{
401 delete folder; 401 delete folder;
402} 402}
403 403
404const QString& IMAPfolderItem::Delemiter()const 404const QString& IMAPfolderItem::Delemiter()const
405{ 405{
406 return folder->Separator(); 406 return folder->Separator();
407} 407}
408 408
409bool IMAPfolderItem::matchName(const QString&name)const 409bool IMAPfolderItem::matchName(const QString&name)const
410{ 410{
411 return folder->getDisplayName()==name; 411 return folder->getDisplayName()==name;
412} 412}
413 413
414void IMAPfolderItem::refresh(QList<RecMail>&target) 414void IMAPfolderItem::refresh(QList<RecMail>&target)
415{ 415{
416 if (folder->may_select()) { 416 if (folder->may_select()) {
417 imap->getWrapper()->listMessages( folder->getName(),target ); 417 imap->getWrapper()->listMessages( folder->getName(),target );
418 } else { 418 } else {
419 target.clear(); 419 target.clear();
420 } 420 }
421} 421}
422 422
423RecBody IMAPfolderItem::fetchBody(const RecMail&aMail) 423RecBody IMAPfolderItem::fetchBody(const RecMail&aMail)
424{ 424{
425 return imap->getWrapper()->fetchBody(aMail); 425 return imap->getWrapper()->fetchBody(aMail);
426} 426}
427 427
428QPopupMenu * IMAPfolderItem::getContextMenu() 428QPopupMenu * IMAPfolderItem::getContextMenu()
429{ 429{
430 QPopupMenu *m = new QPopupMenu(0); 430 QPopupMenu *m = new QPopupMenu(0);
431 if (m) { 431 if (m) {
432 if (folder->may_select()) { 432 if (folder->may_select()) {
433 m->insertItem(QObject::tr("Refresh header list",contextName),0); 433 m->insertItem(QObject::tr("Refresh header list",contextName),0);
434 m->insertItem(QObject::tr("Move/Copie all mails",contextName),4); 434 m->insertItem(QObject::tr("Move/Copie all mails",contextName),4);
435 m->insertItem(QObject::tr("Delete all mails",contextName),1); 435 m->insertItem(QObject::tr("Delete all mails",contextName),1);
436 } 436 }
437 if (folder->no_inferior()==false) { 437 if (folder->no_inferior()==false) {
438 m->insertItem(QObject::tr("Create new subfolder",contextName),2); 438 m->insertItem(QObject::tr("Create new subfolder",contextName),2);
439 } 439 }
440 if (folder->getDisplayName().lower()!="inbox") { 440 if (folder->getDisplayName().lower()!="inbox") {
441 m->insertItem(QObject::tr("Delete folder",contextName),3); 441 m->insertItem(QObject::tr("Delete folder",contextName),3);
442 } 442 }
443 } 443 }
444 return m; 444 return m;
445} 445}
446 446
447void IMAPfolderItem::createNewFolder() 447void IMAPfolderItem::createNewFolder()
448{ 448{
449 Newmdirdlg ndirdlg; 449 Newmdirdlg ndirdlg;
450 ndirdlg.showMaximized(); 450 ndirdlg.showMaximized();
451 if (ndirdlg.exec()) { 451 if (ndirdlg.exec()) {
452 QString ndir = ndirdlg.Newdir(); 452 QString ndir = ndirdlg.Newdir();
453 bool makesubs = ndirdlg.subpossible(); 453 bool makesubs = ndirdlg.subpossible();
454 QString delemiter = Delemiter(); 454 QString delemiter = Delemiter();
455 if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) { 455 if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) {
456 imap->refreshFolders(true); 456 imap->refreshFolders(true);
457 } 457 }
458 } 458 }
459} 459}
460 460
461void IMAPfolderItem::deleteFolder() 461void IMAPfolderItem::deleteFolder()
462{ 462{
463 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), 463 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
464 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), 464 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()),
465 QObject::tr("Yes",contextName), 465 QObject::tr("Yes",contextName),
466 QObject::tr("No",contextName),QString::null,1,1); 466 QObject::tr("No",contextName),QString::null,1,1);
467 qDebug("Auswahl: %i",yesno); 467 qDebug("Auswahl: %i",yesno);
468 if (yesno == 0) { 468 if (yesno == 0) {
469 if (imap->getWrapper()->deleteMbox(folder)) { 469 if (imap->getWrapper()->deleteMbox(folder)) {
470 QListView*v=listView(); 470 QListView*v=listView();
471 IMAPviewItem * box = imap; 471 IMAPviewItem * box = imap;
472 /* be carefull - after that this object is destroyd so don't use 472 /* be carefull - after that this object is destroyd so don't use
473 * any member of it after that call!!*/ 473 * any member of it after that call!!*/
474 imap->refreshFolders(true); 474 imap->refreshFolders(true);
475 if (v) { 475 if (v) {
476 v->setSelected(box,true); 476 v->setSelected(box,true);
477 } 477 }
478 } 478 }
479 } 479 }
480} 480}
481 481
482void IMAPfolderItem::downloadMails() 482void IMAPfolderItem::downloadMails()
483{ 483{
484 AccountView*bl = imap->accountView(); 484 AccountView*bl = imap->accountView();
485 if (!bl) return; 485 if (!bl) return;
486 bl->downloadMails(folder,imap->getWrapper()); 486 bl->downloadMails(folder,imap->getWrapper());
487} 487}
488 488
489void IMAPfolderItem::contextMenuSelected(int id) 489void IMAPfolderItem::contextMenuSelected(int id)
490{ 490{
491 qDebug("Selected id: %i",id); 491 qDebug("Selected id: %i",id);
492 AccountView * view = (AccountView*)listView(); 492 AccountView * view = (AccountView*)listView();
493 switch(id) { 493 switch(id) {
494 case 0: 494 case 0:
495 view->refreshCurrent(); 495 view->refreshCurrent();
496 break; 496 break;
497 case 1: 497 case 1:
498 deleteAllMail(imap->getWrapper(),folder); 498 deleteAllMail(imap->getWrapper(),folder);
499 break; 499 break;
500 case 2: 500 case 2:
501 createNewFolder(); 501 createNewFolder();
502 break; 502 break;
503 case 3: 503 case 3:
504 deleteFolder(); 504 deleteFolder();
505 break; 505 break;
506 case 4: 506 case 4:
507 downloadMails(); 507 downloadMails();
508 break; 508 break;
509 default: 509 default:
510 break; 510 break;
511 } 511 }
512} 512}
513 513
514/** 514/**
515 * Generic stuff 515 * Generic stuff
516 */ 516 */
517 517
518const QString AccountViewItem::contextName="AccountViewItem"; 518const QString AccountViewItem::contextName="AccountViewItem";
519 519
520AccountViewItem::AccountViewItem( AccountView *parent ) 520AccountViewItem::AccountViewItem( AccountView *parent )
521 : QListViewItem( parent ) 521 : QListViewItem( parent )
522{ 522{
523 m_Backlink = parent; 523 m_Backlink = parent;
524} 524}
525 525
526AccountViewItem::AccountViewItem( QListViewItem *parent) 526AccountViewItem::AccountViewItem( QListViewItem *parent)
527 : QListViewItem( parent) 527 : QListViewItem( parent)
528{ 528{
529 m_Backlink = 0; 529 m_Backlink = 0;
530} 530}
531 531
532AccountViewItem::AccountViewItem( QListViewItem *parent , QListViewItem*after ) 532AccountViewItem::AccountViewItem( QListViewItem *parent , QListViewItem*after )
533 :QListViewItem( parent,after ) 533 :QListViewItem( parent,after )
534{ 534{
535 m_Backlink = 0; 535 m_Backlink = 0;
536} 536}
537 537
538AccountViewItem::~AccountViewItem() 538AccountViewItem::~AccountViewItem()
539{ 539{
540} 540}
541 541
542AccountView*AccountViewItem::accountView() 542AccountView*AccountViewItem::accountView()
543{ 543{
544 return m_Backlink; 544 return m_Backlink;
545} 545}
546 546
547void AccountViewItem::deleteAllMail(AbstractMail*wrapper,Folder*folder) 547void AccountViewItem::deleteAllMail(AbstractMail*wrapper,Folder*folder)
548{ 548{
549 if (!wrapper) return; 549 if (!wrapper) return;
550 QString fname=""; 550 QString fname="";
551 if (folder) fname = folder->getDisplayName(); 551 if (folder) fname = folder->getDisplayName();
552 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName), 552 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName),
553 QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName). 553 QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName).
554 arg(fname), 554 arg(fname),
555 QObject::tr("Yes",contextName), 555 QObject::tr("Yes",contextName),
556 QObject::tr("No",contextName),QString::null,1,1); 556 QObject::tr("No",contextName),QString::null,1,1);
557 qDebug("Auswahl: %i",yesno); 557 qDebug("Auswahl: %i",yesno);
558 if (yesno == 0) { 558 if (yesno == 0) {
559 if (wrapper->deleteAllMail(folder)) { 559 if (wrapper->deleteAllMail(folder)) {
560 AccountView * view = (AccountView*)listView(); 560 AccountView * view = (AccountView*)listView();
561 if (view) view->refreshCurrent(); 561 if (view) view->refreshCurrent();
562 } 562 }
563 } 563 }
564} 564}
565 565
566AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) 566AccountView::AccountView( QWidget *parent, const char *name, WFlags flags )
567 : QListView( parent, name, flags ) 567 : QListView( parent, name, flags )
568{ 568{
569 connect( this, SIGNAL( selectionChanged( QListViewItem * ) ), 569 connect( this, SIGNAL( selectionChanged( QListViewItem * ) ),
570 SLOT( refresh( QListViewItem * ) ) ); 570 SLOT( refresh( QListViewItem * ) ) );
571 connect( this, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this, 571 connect( this, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this,
572 SLOT( slotHold( int, QListViewItem *,const QPoint&,int ) ) ); 572 SLOT( slotHold( int, QListViewItem *,const QPoint&,int ) ) );
573 573
574 setSorting(0); 574 setSorting(0);
575} 575}
576 576
577AccountView::~AccountView() 577AccountView::~AccountView()
578{ 578{
579 imapAccounts.clear(); 579 imapAccounts.clear();
580 mboxAccounts.clear(); 580 mhAccounts.clear();
581} 581}
582 582
583void AccountView::slotContextMenu(int id) 583void AccountView::slotContextMenu(int id)
584{ 584{
585 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); 585 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem());
586 if (!view) return; 586 if (!view) return;
587 view->contextMenuSelected(id); 587 view->contextMenuSelected(id);
588} 588}
589 589
590void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int) 590void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int)
591{ 591{
592 if (button==1) {return;} 592 if (button==1) {return;}
593 if (!item) return; 593 if (!item) return;
594 AccountViewItem *view = static_cast<AccountViewItem *>(item); 594 AccountViewItem *view = static_cast<AccountViewItem *>(item);
595 QPopupMenu*m = view->getContextMenu(); 595 QPopupMenu*m = view->getContextMenu();
596 if (!m) return; 596 if (!m) return;
597 connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int))); 597 connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int)));
598 m->setFocus(); 598 m->setFocus();
599 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); 599 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
600 delete m; 600 delete m;
601} 601}
602 602
603void AccountView::populate( QList<Account> list ) 603void AccountView::populate( QList<Account> list )
604{ 604{
605 clear(); 605 clear();
606 606
607 imapAccounts.clear(); 607 imapAccounts.clear();
608 mboxAccounts.clear(); 608 mhAccounts.clear();
609 609
610 mboxAccounts.append(new MBOXviewItem(AbstractMail::defaultLocalfolder(),this)); 610 mhAccounts.append(new MHviewItem(AbstractMail::defaultLocalfolder(),this));
611 611
612 Account *it; 612 Account *it;
613 for ( it = list.first(); it; it = list.next() ) { 613 for ( it = list.first(); it; it = list.next() ) {
614 if ( it->getType().compare( "IMAP" ) == 0 ) { 614 if ( it->getType().compare( "IMAP" ) == 0 ) {
615 IMAPaccount *imap = static_cast<IMAPaccount *>(it); 615 IMAPaccount *imap = static_cast<IMAPaccount *>(it);
616 qDebug( "added IMAP " + imap->getAccountName() ); 616 qDebug( "added IMAP " + imap->getAccountName() );
617 imapAccounts.append(new IMAPviewItem( imap, this )); 617 imapAccounts.append(new IMAPviewItem( imap, this ));
618 } else if ( it->getType().compare( "POP3" ) == 0 ) { 618 } else if ( it->getType().compare( "POP3" ) == 0 ) {
619 POP3account *pop3 = static_cast<POP3account *>(it); 619 POP3account *pop3 = static_cast<POP3account *>(it);
620 qDebug( "added POP3 " + pop3->getAccountName() ); 620 qDebug( "added POP3 " + pop3->getAccountName() );
621 /* must not be hold 'cause it isn't required */ 621 /* must not be hold 'cause it isn't required */
622 (void) new POP3viewItem( pop3, this ); 622 (void) new POP3viewItem( pop3, this );
623 } 623 }
624 } 624 }
625} 625}
626 626
627void AccountView::refresh(QListViewItem *item) { 627void AccountView::refresh(QListViewItem *item) {
628 628
629 qDebug("AccountView refresh..."); 629 qDebug("AccountView refresh...");
630 if ( item ) { 630 if ( item ) {
631 m_currentItem = item; 631 m_currentItem = item;
632 QList<RecMail> headerlist; 632 QList<RecMail> headerlist;
633 headerlist.setAutoDelete(true); 633 headerlist.setAutoDelete(true);
634 AccountViewItem *view = static_cast<AccountViewItem *>(item); 634 AccountViewItem *view = static_cast<AccountViewItem *>(item);
635 view->refresh(headerlist); 635 view->refresh(headerlist);
636 emit refreshMailview(&headerlist); 636 emit refreshMailview(&headerlist);
637 } 637 }
638} 638}
639 639
640void AccountView::refreshCurrent() 640void AccountView::refreshCurrent()
641{ 641{
642 m_currentItem = currentItem(); 642 m_currentItem = currentItem();
643 if ( !m_currentItem ) return; 643 if ( !m_currentItem ) return;
644 QList<RecMail> headerlist; 644 QList<RecMail> headerlist;
645 headerlist.setAutoDelete(true); 645 headerlist.setAutoDelete(true);
646 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); 646 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem);
647 view->refresh(headerlist); 647 view->refresh(headerlist);
648 emit refreshMailview(&headerlist); 648 emit refreshMailview(&headerlist);
649} 649}
650 650
651void AccountView::refreshAll() 651void AccountView::refreshAll()
652{ 652{
653 653
654} 654}
655 655
656RecBody AccountView::fetchBody(const RecMail&aMail) 656RecBody AccountView::fetchBody(const RecMail&aMail)
657{ 657{
658 QListViewItem*item = selectedItem (); 658 QListViewItem*item = selectedItem ();
659 if (!item) return RecBody(); 659 if (!item) return RecBody();
660 AccountViewItem *view = static_cast<AccountViewItem *>(item); 660 AccountViewItem *view = static_cast<AccountViewItem *>(item);
661 return view->fetchBody(aMail); 661 return view->fetchBody(aMail);
662} 662}
663 663
664void AccountView::setupFolderselect(Selectstore*sels) 664void AccountView::setupFolderselect(Selectstore*sels)
665{ 665{
666 sels->showMaximized(); 666 sels->showMaximized();
667 QStringList sFolders; 667 QStringList sFolders;
668 unsigned int i = 0; 668 unsigned int i = 0;
669 for (i=0; i < mboxAccounts.count();++i) { 669 for (i=0; i < mhAccounts.count();++i) {
670 mboxAccounts[i]->refresh(false); 670 mhAccounts[i]->refresh(false);
671 sFolders = mboxAccounts[i]->subFolders(); 671 sFolders = mhAccounts[i]->subFolders();
672 sels->addAccounts(mboxAccounts[i]->getWrapper(),sFolders); 672 sels->addAccounts(mhAccounts[i]->getWrapper(),sFolders);
673 } 673 }
674 for (i=0; i < imapAccounts.count();++i) { 674 for (i=0; i < imapAccounts.count();++i) {
675 if (imapAccounts[i]->offline()) 675 if (imapAccounts[i]->offline())
676 continue; 676 continue;
677 imapAccounts[i]->refreshFolders(false); 677 imapAccounts[i]->refreshFolders(false);
678 sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders()); 678 sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders());
679 } 679 }
680} 680}
681 681
682void AccountView::downloadMails(Folder*fromFolder,AbstractMail*fromWrapper) 682void AccountView::downloadMails(Folder*fromFolder,AbstractMail*fromWrapper)
683{ 683{
684 AbstractMail*targetMail = 0; 684 AbstractMail*targetMail = 0;
685 QString targetFolder = ""; 685 QString targetFolder = "";
686 Selectstore sels; 686 Selectstore sels;
687 setupFolderselect(&sels); 687 setupFolderselect(&sels);
688 if (!sels.exec()) return; 688 if (!sels.exec()) return;
689 targetMail = sels.currentMail(); 689 targetMail = sels.currentMail();
690 targetFolder = sels.currentFolder(); 690 targetFolder = sels.currentFolder();
691 if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) || 691 if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) ||
692 targetFolder.isEmpty()) { 692 targetFolder.isEmpty()) {
693 return; 693 return;
694 } 694 }
695 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) { 695 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) {
696 QMessageBox::critical(0,tr("Error creating new Folder"), 696 QMessageBox::critical(0,tr("Error creating new Folder"),
697 tr("<center>Error while creating<br>new folder - breaking.</center>")); 697 tr("<center>Error while creating<br>new folder - breaking.</center>"));
698 return; 698 return;
699 } 699 }
700 qDebug("Targetfolder: %s",targetFolder.latin1()); 700 qDebug("Targetfolder: %s",targetFolder.latin1());
701 qDebug("Fromfolder: %s",fromFolder->getName().latin1()); 701 qDebug("Fromfolder: %s",fromFolder->getName().latin1());
702 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails()); 702 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails());
703 refreshCurrent(); 703 refreshCurrent();
704} 704}
705 705
706/** 706/**
707 * MBOX Account stuff 707 * MH Account stuff
708 */ 708 */
709 709
710MBOXviewItem::MBOXviewItem( const QString&aPath, AccountView *parent ) 710MHviewItem::MHviewItem( const QString&aPath, AccountView *parent )
711 : AccountViewItem( parent ) 711 : AccountViewItem( parent )
712{ 712{
713 m_Path = aPath; 713 m_Path = aPath;
714 /* be carefull - the space within settext is wanted - thats why the string twice */ 714 /* be carefull - the space within settext is wanted - thats why the string twice */
715 wrapper = AbstractMail::getWrapper( m_Path,"Local Folders"); 715 wrapper = AbstractMail::getWrapper( m_Path,"Local Folders");
716 setPixmap( 0, PIXMAP_LOCALFOLDER ); 716 setPixmap( 0, PIXMAP_LOCALFOLDER );
717 setText( 0, " Local Folders" ); 717 setText( 0, " Local Folders" );
718 setOpen( true ); 718 setOpen( true );
719} 719}
720 720
721MBOXviewItem::~MBOXviewItem() 721MHviewItem::~MHviewItem()
722{ 722{
723 delete wrapper; 723 delete wrapper;
724} 724}
725 725
726AbstractMail *MBOXviewItem::getWrapper() 726AbstractMail *MHviewItem::getWrapper()
727{ 727{
728 return wrapper; 728 return wrapper;
729} 729}
730 730
731void MBOXviewItem::refresh( QList<RecMail> & ) 731void MHviewItem::refresh( QList<RecMail> & )
732{ 732{
733 refresh(false); 733 refresh(false);
734} 734}
735 735
736void MBOXviewItem::refresh(bool force) 736void MHviewItem::refresh(bool force)
737{ 737{
738 if (childCount()>0 && force==false) return; 738 if (childCount()>0 && force==false) return;
739 QList<Folder> *folders = wrapper->listFolders(); 739 QList<Folder> *folders = wrapper->listFolders();
740 QListViewItem *child = firstChild(); 740 QListViewItem *child = firstChild();
741 while ( child ) { 741 while ( child ) {
742 QListViewItem *tmp = child; 742 QListViewItem *tmp = child;
743 child = child->nextSibling(); 743 child = child->nextSibling();
744 delete tmp; 744 delete tmp;
745 } 745 }
746 Folder *it; 746 Folder *it;
747 QListViewItem*item = 0; 747 QListViewItem*item = 0;
748 for ( it = folders->first(); it; it = folders->next() ) { 748 for ( it = folders->first(); it; it = folders->next() ) {
749 item = new MBOXfolderItem( it, this , item ); 749 item = new MHfolderItem( it, this , item );
750 item->setSelectable(it->may_select()); 750 item->setSelectable(it->may_select());
751 } 751 }
752 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 752 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
753 folders->setAutoDelete(false); 753 folders->setAutoDelete(false);
754 delete folders; 754 delete folders;
755} 755}
756 756
757RecBody MBOXviewItem::fetchBody( const RecMail &mail ) 757RecBody MHviewItem::fetchBody( const RecMail &mail )
758{ 758{
759 qDebug( "MBOX fetchBody" ); 759 qDebug( "MH fetchBody" );
760 return wrapper->fetchBody( mail ); 760 return wrapper->fetchBody( mail );
761} 761}
762 762
763QPopupMenu * MBOXviewItem::getContextMenu() 763QPopupMenu * MHviewItem::getContextMenu()
764{ 764{
765 QPopupMenu *m = new QPopupMenu(0); 765 QPopupMenu *m = new QPopupMenu(0);
766 if (m) { 766 if (m) {
767 m->insertItem(QObject::tr("Refresh folder list",contextName),0); 767 m->insertItem(QObject::tr("Refresh folder list",contextName),0);
768 m->insertItem(QObject::tr("Create new folder",contextName),1); 768 m->insertItem(QObject::tr("Create new folder",contextName),1);
769 } 769 }
770 return m; 770 return m;
771} 771}
772 772
773void MBOXviewItem::createFolder() 773void MHviewItem::createFolder()
774{ 774{
775 Newmdirdlg ndirdlg(0,0,true); 775 Newmdirdlg ndirdlg(0,0,true);
776 ndirdlg.showMaximized(); 776 ndirdlg.showMaximized();
777 if (ndirdlg.exec()) { 777 if (ndirdlg.exec()) {
778 QString ndir = ndirdlg.Newdir(); 778 QString ndir = ndirdlg.Newdir();
779 if (wrapper->createMbox(ndir)) { 779 if (wrapper->createMbox(ndir)) {
780 refresh(true); 780 refresh(true);
781 } 781 }
782 } 782 }
783} 783}
784 784
785QStringList MBOXviewItem::subFolders() 785QStringList MHviewItem::subFolders()
786{ 786{
787 QStringList result; 787 QStringList result;
788 QListViewItem *child = firstChild(); 788 QListViewItem *child = firstChild();
789 while ( child ) { 789 while ( child ) {
790 MBOXfolderItem *tmp = (MBOXfolderItem*)child; 790 MHfolderItem *tmp = (MHfolderItem*)child;
791 child = child->nextSibling(); 791 child = child->nextSibling();
792 result.append(tmp->getFolder()->getName()); 792 result.append(tmp->getFolder()->getDisplayName());
793 } 793 }
794 qDebug("Size of result: %i",result.count()); 794 qDebug("Size of result: %i",result.count());
795 return result; 795 return result;
796} 796}
797 797
798void MBOXviewItem::contextMenuSelected(int which) 798void MHviewItem::contextMenuSelected(int which)
799{ 799{
800 switch (which) { 800 switch (which) {
801 case 0: 801 case 0:
802 refresh(true); 802 refresh(true);
803 break; 803 break;
804 case 1: 804 case 1:
805 createFolder(); 805 createFolder();
806 break; 806 break;
807 default: 807 default:
808 break; 808 break;
809 } 809 }
810} 810}
811 811
812MBOXfolderItem::~MBOXfolderItem() 812MHfolderItem::~MHfolderItem()
813{ 813{
814 delete folder; 814 delete folder;
815} 815}
816 816
817MBOXfolderItem::MBOXfolderItem( Folder *folderInit, MBOXviewItem *parent , QListViewItem*after ) 817MHfolderItem::MHfolderItem( Folder *folderInit, MHviewItem *parent , QListViewItem*after )
818 : AccountViewItem( parent,after ) 818 : AccountViewItem( parent,after )
819{ 819{
820 folder = folderInit; 820 folder = folderInit;
821 mbox = parent; 821 mbox = parent;
822 if (folder->getDisplayName().lower() == "outgoing") { 822 if (folder->getDisplayName().lower() == "outgoing") {
823 setPixmap( 0, PIXMAP_OUTBOXFOLDER ); 823 setPixmap( 0, PIXMAP_OUTBOXFOLDER );
824 } else if (folder->getDisplayName().lower() == "inbox") { 824 } else if (folder->getDisplayName().lower() == "inbox") {
825 setPixmap( 0, PIXMAP_INBOXFOLDER); 825 setPixmap( 0, PIXMAP_INBOXFOLDER);
826 } else { 826 } else {
827 setPixmap( 0, PIXMAP_MBOXFOLDER ); 827 setPixmap( 0, PIXMAP_MBOXFOLDER );
828 } 828 }
829 setText( 0, folder->getDisplayName() ); 829 setText( 0, folder->getDisplayName() );
830} 830}
831 831
832Folder*MBOXfolderItem::getFolder() 832Folder*MHfolderItem::getFolder()
833{ 833{
834 return folder; 834 return folder;
835} 835}
836 836
837void MBOXfolderItem::refresh(QList<RecMail>&target) 837void MHfolderItem::refresh(QList<RecMail>&target)
838{ 838{
839 if (folder->may_select()) 839 if (folder->may_select())
840 mbox->getWrapper()->listMessages( folder->getName(),target ); 840 mbox->getWrapper()->listMessages( folder->getName(),target );
841} 841}
842 842
843RecBody MBOXfolderItem::fetchBody(const RecMail&aMail) 843RecBody MHfolderItem::fetchBody(const RecMail&aMail)
844{ 844{
845 return mbox->getWrapper()->fetchBody(aMail); 845 return mbox->getWrapper()->fetchBody(aMail);
846} 846}
847 847
848void MBOXfolderItem::deleteFolder() 848void MHfolderItem::deleteFolder()
849{ 849{
850 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), 850 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
851 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), 851 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()),
852 QObject::tr("Yes",contextName), 852 QObject::tr("Yes",contextName),
853 QObject::tr("No",contextName),QString::null,1,1); 853 QObject::tr("No",contextName),QString::null,1,1);
854 qDebug("Auswahl: %i",yesno); 854 qDebug("Auswahl: %i",yesno);
855 if (yesno == 0) { 855 if (yesno == 0) {
856 if (mbox->getWrapper()->deleteMbox(folder)) { 856 if (mbox->getWrapper()->deleteMbox(folder)) {
857 QListView*v=listView(); 857 QListView*v=listView();
858 MBOXviewItem * box = mbox; 858 MHviewItem * box = mbox;
859 /* be carefull - after that this object is destroyd so don't use 859 /* be carefull - after that this object is destroyd so don't use
860 * any member of it after that call!!*/ 860 * any member of it after that call!!*/
861 mbox->refresh(true); 861 mbox->refresh(true);
862 if (v) { 862 if (v) {
863 v->setSelected(box,true); 863 v->setSelected(box,true);
864 } 864 }
865 } 865 }
866 } 866 }
867} 867}
868 868
869QPopupMenu * MBOXfolderItem::getContextMenu() 869QPopupMenu * MHfolderItem::getContextMenu()
870{ 870{
871 QPopupMenu *m = new QPopupMenu(0); 871 QPopupMenu *m = new QPopupMenu(0);
872 if (m) { 872 if (m) {
873 m->insertItem(QObject::tr("Delete all mails",contextName),0); 873 m->insertItem(QObject::tr("Delete all mails",contextName),0);
874 m->insertItem(QObject::tr("Delete folder",contextName),1); 874 m->insertItem(QObject::tr("Delete folder",contextName),1);
875 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); 875 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2);
876 } 876 }
877 return m; 877 return m;
878} 878}
879 879
880void MBOXfolderItem::downloadMails() 880void MHfolderItem::downloadMails()
881{ 881{
882 AccountView*bl = mbox->accountView(); 882 AccountView*bl = mbox->accountView();
883 if (!bl) return; 883 if (!bl) return;
884 bl->downloadMails(folder,mbox->getWrapper()); 884 bl->downloadMails(folder,mbox->getWrapper());
885} 885}
886 886
887void MBOXfolderItem::contextMenuSelected(int which) 887void MHfolderItem::contextMenuSelected(int which)
888{ 888{
889 switch(which) { 889 switch(which) {
890 case 0: 890 case 0:
891 deleteAllMail(mbox->getWrapper(),folder); 891 deleteAllMail(mbox->getWrapper(),folder);
892 break; 892 break;
893 case 1: 893 case 1:
894 deleteFolder(); 894 deleteFolder();
895 break; 895 break;
896 case 2: 896 case 2:
897 downloadMails(); 897 downloadMails();
898 break; 898 break;
899 default: 899 default:
900 break; 900 break;
901 } 901 }
902} 902}
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h
index d9b5558..f5a2973 100644
--- a/noncore/net/mail/accountview.h
+++ b/noncore/net/mail/accountview.h
@@ -1,190 +1,190 @@
1#ifndef ACCOUNTVIEW_H 1#ifndef ACCOUNTVIEW_H
2#define ACCOUNTVIEW_H 2#define ACCOUNTVIEW_H
3 3
4#include <qlistview.h> 4#include <qlistview.h>
5#include <qlist.h> 5#include <qlist.h>
6 6
7#include <libmailwrapper/settings.h> 7#include <libmailwrapper/settings.h>
8#include <libmailwrapper/mailwrapper.h> 8#include <libmailwrapper/mailwrapper.h>
9#include <libmailwrapper/abstractmail.h> 9#include <libmailwrapper/abstractmail.h>
10 10
11class POP3wrapper; 11class POP3wrapper;
12class RecMail; 12class RecMail;
13class RecBody; 13class RecBody;
14class QPopupMenu; 14class QPopupMenu;
15class Selectstore; 15class Selectstore;
16class AccountView; 16class AccountView;
17 17
18class AccountViewItem : public QListViewItem 18class AccountViewItem : public QListViewItem
19{ 19{
20 20
21public: 21public:
22 AccountViewItem( AccountView *parent ); 22 AccountViewItem( AccountView *parent );
23 AccountViewItem( QListViewItem *parent); 23 AccountViewItem( QListViewItem *parent);
24 AccountViewItem( QListViewItem *parent , QListViewItem*after ); 24 AccountViewItem( QListViewItem *parent , QListViewItem*after );
25 virtual ~AccountViewItem(); 25 virtual ~AccountViewItem();
26 virtual void refresh(QList<RecMail>&)=0; 26 virtual void refresh(QList<RecMail>&)=0;
27 virtual RecBody fetchBody(const RecMail&)=0; 27 virtual RecBody fetchBody(const RecMail&)=0;
28 virtual QPopupMenu * getContextMenu(){return 0;}; 28 virtual QPopupMenu * getContextMenu(){return 0;};
29 virtual void contextMenuSelected(int){} 29 virtual void contextMenuSelected(int){}
30 virtual AccountView*accountView(); 30 virtual AccountView*accountView();
31protected: 31protected:
32 virtual void deleteAllMail(AbstractMail*wrapper,Folder*f); 32 virtual void deleteAllMail(AbstractMail*wrapper,Folder*f);
33 static const QString contextName; 33 static const QString contextName;
34 AccountView*m_Backlink; 34 AccountView*m_Backlink;
35}; 35};
36 36
37class POP3viewItem : public AccountViewItem 37class POP3viewItem : public AccountViewItem
38{ 38{
39 39
40public: 40public:
41 POP3viewItem( POP3account *a, AccountView *parent ); 41 POP3viewItem( POP3account *a, AccountView *parent );
42 virtual ~POP3viewItem(); 42 virtual ~POP3viewItem();
43 virtual void refresh( QList<RecMail> &target ); 43 virtual void refresh( QList<RecMail> &target );
44 virtual RecBody fetchBody( const RecMail &mail ); 44 virtual RecBody fetchBody( const RecMail &mail );
45 AbstractMail *getWrapper(); 45 AbstractMail *getWrapper();
46 virtual QPopupMenu * getContextMenu(); 46 virtual QPopupMenu * getContextMenu();
47 virtual void contextMenuSelected(int); 47 virtual void contextMenuSelected(int);
48 48
49protected: 49protected:
50 POP3account *account; 50 POP3account *account;
51 virtual void refresh(); 51 virtual void refresh();
52 AbstractMail *wrapper; 52 AbstractMail *wrapper;
53 void disconnect(); 53 void disconnect();
54 void setOnOffline(); 54 void setOnOffline();
55}; 55};
56 56
57class POP3folderItem : public AccountViewItem 57class POP3folderItem : public AccountViewItem
58{ 58{
59 59
60public: 60public:
61 POP3folderItem( Folder *folder, POP3viewItem *parent , QListViewItem*after ); 61 POP3folderItem( Folder *folder, POP3viewItem *parent , QListViewItem*after );
62 virtual ~POP3folderItem(); 62 virtual ~POP3folderItem();
63 virtual void refresh(QList<RecMail>&); 63 virtual void refresh(QList<RecMail>&);
64 virtual RecBody fetchBody(const RecMail&); 64 virtual RecBody fetchBody(const RecMail&);
65 virtual QPopupMenu * getContextMenu(); 65 virtual QPopupMenu * getContextMenu();
66 virtual void contextMenuSelected(int); 66 virtual void contextMenuSelected(int);
67 67
68protected: 68protected:
69 void downloadMails(); 69 void downloadMails();
70 Folder *folder; 70 Folder *folder;
71 POP3viewItem *pop3; 71 POP3viewItem *pop3;
72}; 72};
73 73
74class IMAPfolderItem; 74class IMAPfolderItem;
75 75
76class IMAPviewItem : public AccountViewItem 76class IMAPviewItem : public AccountViewItem
77{ 77{
78 friend class IMAPfolderItem; 78 friend class IMAPfolderItem;
79public: 79public:
80 IMAPviewItem( IMAPaccount *a, AccountView *parent ); 80 IMAPviewItem( IMAPaccount *a, AccountView *parent );
81 virtual ~IMAPviewItem(); 81 virtual ~IMAPviewItem();
82 virtual void refresh(QList<RecMail>&); 82 virtual void refresh(QList<RecMail>&);
83 virtual RecBody fetchBody(const RecMail&); 83 virtual RecBody fetchBody(const RecMail&);
84 AbstractMail *getWrapper(); 84 AbstractMail *getWrapper();
85 virtual QPopupMenu * getContextMenu(); 85 virtual QPopupMenu * getContextMenu();
86 virtual void contextMenuSelected(int); 86 virtual void contextMenuSelected(int);
87 const QStringList&subFolders(); 87 const QStringList&subFolders();
88 virtual void refreshFolders(bool force=false); 88 virtual void refreshFolders(bool force=false);
89 bool offline(); 89 bool offline();
90 90
91protected: 91protected:
92 IMAPfolderItem*findSubItem(const QString&path,IMAPfolderItem*start=0); 92 IMAPfolderItem*findSubItem(const QString&path,IMAPfolderItem*start=0);
93 virtual void createNewFolder(); 93 virtual void createNewFolder();
94 virtual void removeChilds(); 94 virtual void removeChilds();
95 IMAPaccount *account; 95 IMAPaccount *account;
96 AbstractMail *wrapper; 96 AbstractMail *wrapper;
97 QStringList currentFolders; 97 QStringList currentFolders;
98}; 98};
99 99
100class IMAPfolderItem : public AccountViewItem 100class IMAPfolderItem : public AccountViewItem
101{ 101{
102 102
103public: 103public:
104 IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after ); 104 IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after );
105 IMAPfolderItem( Folder *folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ); 105 IMAPfolderItem( Folder *folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master );
106 virtual ~IMAPfolderItem(); 106 virtual ~IMAPfolderItem();
107 virtual void refresh(QList<RecMail>&); 107 virtual void refresh(QList<RecMail>&);
108 virtual RecBody fetchBody(const RecMail&); 108 virtual RecBody fetchBody(const RecMail&);
109 bool matchName(const QString&name)const; 109 bool matchName(const QString&name)const;
110 virtual QPopupMenu * getContextMenu(); 110 virtual QPopupMenu * getContextMenu();
111 virtual void contextMenuSelected(int); 111 virtual void contextMenuSelected(int);
112 virtual const QString& Delemiter()const; 112 virtual const QString& Delemiter()const;
113protected: 113protected:
114 virtual void createNewFolder(); 114 virtual void createNewFolder();
115 virtual void deleteFolder(); 115 virtual void deleteFolder();
116 virtual void downloadMails(); 116 virtual void downloadMails();
117 Folder *folder; 117 Folder *folder;
118 IMAPviewItem *imap; 118 IMAPviewItem *imap;
119}; 119};
120 120
121class MBOXviewItem : public AccountViewItem 121class MHviewItem : public AccountViewItem
122{ 122{
123 friend class MBOXfolderItem; 123 friend class MHfolderItem;
124 124
125public: 125public:
126 MBOXviewItem( const QString&aMboxPath, AccountView *parent ); 126 MHviewItem( const QString&aMboxPath, AccountView *parent );
127 virtual ~MBOXviewItem(); 127 virtual ~MHviewItem();
128 virtual void refresh( QList<RecMail> &target ); 128 virtual void refresh( QList<RecMail> &target );
129 virtual RecBody fetchBody( const RecMail &mail ); 129 virtual RecBody fetchBody( const RecMail &mail );
130 AbstractMail *getWrapper(); 130 AbstractMail *getWrapper();
131 virtual QPopupMenu * getContextMenu(); 131 virtual QPopupMenu * getContextMenu();
132 virtual void contextMenuSelected(int); 132 virtual void contextMenuSelected(int);
133 QStringList subFolders(); 133 QStringList subFolders();
134 virtual void refresh(bool force=false); 134 virtual void refresh(bool force=false);
135 135
136protected: 136protected:
137 virtual void createFolder(); 137 virtual void createFolder();
138 QString m_Path; 138 QString m_Path;
139 AbstractMail *wrapper; 139 AbstractMail *wrapper;
140 140
141}; 141};
142 142
143class MBOXfolderItem : public AccountViewItem 143class MHfolderItem : public AccountViewItem
144{ 144{
145 145
146public: 146public:
147 MBOXfolderItem( Folder *folder, MBOXviewItem *parent , QListViewItem*after ); 147 MHfolderItem( Folder *folder, MHviewItem *parent , QListViewItem*after );
148 virtual ~MBOXfolderItem(); 148 virtual ~MHfolderItem();
149 virtual void refresh(QList<RecMail>&); 149 virtual void refresh(QList<RecMail>&);
150 virtual RecBody fetchBody(const RecMail&); 150 virtual RecBody fetchBody(const RecMail&);
151 virtual QPopupMenu * getContextMenu(); 151 virtual QPopupMenu * getContextMenu();
152 virtual void contextMenuSelected(int); 152 virtual void contextMenuSelected(int);
153 virtual Folder*getFolder(); 153 virtual Folder*getFolder();
154 154
155protected: 155protected:
156 void downloadMails(); 156 void downloadMails();
157 virtual void deleteFolder(); 157 virtual void deleteFolder();
158 Folder *folder; 158 Folder *folder;
159 MBOXviewItem *mbox; 159 MHviewItem *mbox;
160}; 160};
161 161
162class AccountView : public QListView 162class AccountView : public QListView
163{ 163{
164 Q_OBJECT 164 Q_OBJECT
165 165
166public: 166public:
167 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 167 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
168 virtual ~AccountView(); 168 virtual ~AccountView();
169 virtual void populate( QList<Account> list ); 169 virtual void populate( QList<Account> list );
170 virtual RecBody fetchBody(const RecMail&aMail); 170 virtual RecBody fetchBody(const RecMail&aMail);
171 virtual void downloadMails(Folder*fromFolder,AbstractMail*fromWrapper); 171 virtual void downloadMails(Folder*fromFolder,AbstractMail*fromWrapper);
172 172
173public slots: 173public slots:
174 virtual void refreshAll(); 174 virtual void refreshAll();
175 virtual void refresh(QListViewItem *item); 175 virtual void refresh(QListViewItem *item);
176 virtual void refreshCurrent(); 176 virtual void refreshCurrent();
177 virtual void slotHold(int, QListViewItem *,const QPoint&,int); 177 virtual void slotHold(int, QListViewItem *,const QPoint&,int);
178 virtual void slotContextMenu(int id); 178 virtual void slotContextMenu(int id);
179 void setupFolderselect(Selectstore*sels); 179 void setupFolderselect(Selectstore*sels);
180 180
181signals: 181signals:
182 void refreshMailview(QList<RecMail>*); 182 void refreshMailview(QList<RecMail>*);
183 183
184protected: 184protected:
185 QListViewItem* m_currentItem; 185 QListViewItem* m_currentItem;
186 QValueList<IMAPviewItem*> imapAccounts; 186 QValueList<IMAPviewItem*> imapAccounts;
187 QValueList<MBOXviewItem*> mboxAccounts; 187 QValueList<MHviewItem*> mhAccounts;
188}; 188};
189 189
190#endif 190#endif
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp
index 0280803..592cd5e 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.cpp
+++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp
@@ -1,138 +1,139 @@
1#include "abstractmail.h" 1#include "abstractmail.h"
2#include "imapwrapper.h" 2#include "imapwrapper.h"
3#include "pop3wrapper.h" 3#include "pop3wrapper.h"
4#include "mhwrapper.h"
4#include "mboxwrapper.h" 5#include "mboxwrapper.h"
5#include "mailtypes.h" 6#include "mailtypes.h"
6 7
7#include <qstring.h> 8#include <qstring.h>
8#include <qfile.h> 9#include <qfile.h>
9#include <qtextstream.h> 10#include <qtextstream.h>
10#include <stdlib.h> 11#include <stdlib.h>
11#include <libetpan/mailmime_content.h> 12#include <libetpan/mailmime_content.h>
12#include <libetpan/mailmime.h> 13#include <libetpan/mailmime.h>
13 14
14AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 15AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
15{ 16{
16 return new IMAPwrapper(a); 17 return new IMAPwrapper(a);
17} 18}
18 19
19AbstractMail* AbstractMail::getWrapper(POP3account *a) 20AbstractMail* AbstractMail::getWrapper(POP3account *a)
20{ 21{
21 return new POP3wrapper(a); 22 return new POP3wrapper(a);
22} 23}
23 24
24AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) 25AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name)
25{ 26{
26 return new MBOXwrapper(a,name); 27 return new MHwrapper(a,name);
27} 28}
28 29
29encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 30encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
30{ 31{
31 qDebug("Decode string start"); 32 qDebug("Decode string start");
32 char*result_text; 33 char*result_text;
33 size_t index = 0; 34 size_t index = 0;
34 /* reset for recursive use! */ 35 /* reset for recursive use! */
35 size_t target_length = 0; 36 size_t target_length = 0;
36 result_text = 0; 37 result_text = 0;
37 int mimetype = MAILMIME_MECHANISM_7BIT; 38 int mimetype = MAILMIME_MECHANISM_7BIT;
38 if (enc.lower()=="quoted-printable") { 39 if (enc.lower()=="quoted-printable") {
39 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 40 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
40 } else if (enc.lower()=="base64") { 41 } else if (enc.lower()=="base64") {
41 mimetype = MAILMIME_MECHANISM_BASE64; 42 mimetype = MAILMIME_MECHANISM_BASE64;
42 } else if (enc.lower()=="8bit") { 43 } else if (enc.lower()=="8bit") {
43 mimetype = MAILMIME_MECHANISM_8BIT; 44 mimetype = MAILMIME_MECHANISM_8BIT;
44 } else if (enc.lower()=="binary") { 45 } else if (enc.lower()=="binary") {
45 mimetype = MAILMIME_MECHANISM_BINARY; 46 mimetype = MAILMIME_MECHANISM_BINARY;
46 } 47 }
47 48
48 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 49 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
49 &result_text,&target_length); 50 &result_text,&target_length);
50 51
51 encodedString* result = new encodedString(); 52 encodedString* result = new encodedString();
52 if (err == MAILIMF_NO_ERROR) { 53 if (err == MAILIMF_NO_ERROR) {
53 result->setContent(result_text,target_length); 54 result->setContent(result_text,target_length);
54 } 55 }
55 qDebug("Decode string finished"); 56 qDebug("Decode string finished");
56 return result; 57 return result;
57} 58}
58 59
59QString AbstractMail::convert_String(const char*text) 60QString AbstractMail::convert_String(const char*text)
60{ 61{
61 size_t index = 0; 62 size_t index = 0;
62 char*res = 0; 63 char*res = 0;
63 64
64 /* attention - doesn't work with arm systems! */ 65 /* attention - doesn't work with arm systems! */
65 int err = mailmime_encoded_phrase_parse("iso-8859-1", 66 int err = mailmime_encoded_phrase_parse("iso-8859-1",
66 text, strlen(text),&index, "iso-8859-1",&res); 67 text, strlen(text),&index, "iso-8859-1",&res);
67 if (err != MAILIMF_NO_ERROR) { 68 if (err != MAILIMF_NO_ERROR) {
68 if (res) free(res); 69 if (res) free(res);
69 return QString(text); 70 return QString(text);
70 } 71 }
71 if (res) { 72 if (res) {
72 QString result(res); 73 QString result(res);
73 free(res); 74 free(res);
74 return result; 75 return result;
75 } 76 }
76 return QString(text); 77 return QString(text);
77} 78}
78 79
79/* cp & paste from launcher */ 80/* cp & paste from launcher */
80QString AbstractMail::gen_attachment_id() 81QString AbstractMail::gen_attachment_id()
81{ 82{
82 QFile file( "/proc/sys/kernel/random/uuid" ); 83 QFile file( "/proc/sys/kernel/random/uuid" );
83 if (!file.open(IO_ReadOnly ) ) 84 if (!file.open(IO_ReadOnly ) )
84 return QString::null; 85 return QString::null;
85 86
86 QTextStream stream(&file); 87 QTextStream stream(&file);
87 88
88 return "{" + stream.read().stripWhiteSpace() + "}"; 89 return "{" + stream.read().stripWhiteSpace() + "}";
89} 90}
90 91
91int AbstractMail::createMbox(const QString&,const Folder*,const QString& delemiter,bool) 92int AbstractMail::createMbox(const QString&,const Folder*,const QString& delemiter,bool)
92{ 93{
93 return 0; 94 return 0;
94} 95}
95 96
96QString AbstractMail::defaultLocalfolder() 97QString AbstractMail::defaultLocalfolder()
97{ 98{
98 QString f = getenv( "HOME" ); 99 QString f = getenv( "HOME" );
99 f += "/Applications/opiemail/localmail"; 100 f += "/Applications/opiemail/localmail";
100 return f; 101 return f;
101} 102}
102 103
103/* temporary - will be removed when implemented in all classes */ 104/* temporary - will be removed when implemented in all classes */
104void AbstractMail::deleteMails(const QString &,QList<RecMail> &) 105void AbstractMail::deleteMails(const QString &,QList<RecMail> &)
105{ 106{
106} 107}
107 108
108void AbstractMail::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 109void AbstractMail::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
109{ 110{
110 QList<RecMail> t; 111 QList<RecMail> t;
111 listMessages(fromFolder->getName(),t); 112 listMessages(fromFolder->getName(),t);
112 encodedString*st = 0; 113 encodedString*st = 0;
113 while (t.count()>0) { 114 while (t.count()>0) {
114 RecMail*r = t.at(0); 115 RecMail*r = t.at(0);
115 st = fetchRawBody(*r); 116 st = fetchRawBody(*r);
116 if (st) { 117 if (st) {
117 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 118 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
118 delete st; 119 delete st;
119 } 120 }
120 t.removeFirst(); 121 t.removeFirst();
121 } 122 }
122 if (moveit) { 123 if (moveit) {
123 deleteAllMail(fromFolder); 124 deleteAllMail(fromFolder);
124 } 125 }
125} 126}
126 127
127void AbstractMail::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 128void AbstractMail::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
128{ 129{
129 encodedString*st = 0; 130 encodedString*st = 0;
130 st = fetchRawBody(mail); 131 st = fetchRawBody(mail);
131 if (st) { 132 if (st) {
132 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 133 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
133 delete st; 134 delete st;
134 } 135 }
135 if (moveit) { 136 if (moveit) {
136 deleteMail(mail); 137 deleteMail(mail);
137 } 138 }
138} 139}
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
index 2d1596d..b1e4459 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
@@ -1,504 +1,512 @@
1#include "genericwrapper.h" 1#include "genericwrapper.h"
2#include <libetpan/libetpan.h> 2#include <libetpan/libetpan.h>
3#include "mailtypes.h" 3#include "mailtypes.h"
4 4
5Genericwrapper::Genericwrapper() 5Genericwrapper::Genericwrapper()
6 : AbstractMail() 6 : AbstractMail()
7{ 7{
8 bodyCache.clear(); 8 bodyCache.clear();
9 m_storage = 0;
10 m_folder = 0;
9} 11}
10 12
11Genericwrapper::~Genericwrapper() 13Genericwrapper::~Genericwrapper()
12{ 14{
15 if (m_folder) {
16 mailfolder_free(m_folder);
17 }
18 if (m_storage) {
19 mailstorage_free(m_storage);
20 }
13 cleanMimeCache(); 21 cleanMimeCache();
14} 22}
15 23
16void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) 24void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime)
17{ 25{
18 if (!mime) { 26 if (!mime) {
19 return; 27 return;
20 } 28 }
21 mailmime_field*field = 0; 29 mailmime_field*field = 0;
22 mailmime_single_fields fields; 30 mailmime_single_fields fields;
23 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 31 memset(&fields, 0, sizeof(struct mailmime_single_fields));
24 if (mime->mm_mime_fields != NULL) { 32 if (mime->mm_mime_fields != NULL) {
25 mailmime_single_fields_init(&fields, mime->mm_mime_fields, 33 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
26 mime->mm_content_type); 34 mime->mm_content_type);
27 } 35 }
28 36
29 mailmime_content*type = fields.fld_content; 37 mailmime_content*type = fields.fld_content;
30 clistcell*current; 38 clistcell*current;
31 if (!type) { 39 if (!type) {
32 target.setType("text"); 40 target.setType("text");
33 target.setSubtype("plain"); 41 target.setSubtype("plain");
34 } else { 42 } else {
35 target.setSubtype(type->ct_subtype); 43 target.setSubtype(type->ct_subtype);
36 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { 44 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
37 case MAILMIME_DISCRETE_TYPE_TEXT: 45 case MAILMIME_DISCRETE_TYPE_TEXT:
38 target.setType("text"); 46 target.setType("text");
39 break; 47 break;
40 case MAILMIME_DISCRETE_TYPE_IMAGE: 48 case MAILMIME_DISCRETE_TYPE_IMAGE:
41 target.setType("image"); 49 target.setType("image");
42 break; 50 break;
43 case MAILMIME_DISCRETE_TYPE_AUDIO: 51 case MAILMIME_DISCRETE_TYPE_AUDIO:
44 target.setType("audio"); 52 target.setType("audio");
45 break; 53 break;
46 case MAILMIME_DISCRETE_TYPE_VIDEO: 54 case MAILMIME_DISCRETE_TYPE_VIDEO:
47 target.setType("video"); 55 target.setType("video");
48 break; 56 break;
49 case MAILMIME_DISCRETE_TYPE_APPLICATION: 57 case MAILMIME_DISCRETE_TYPE_APPLICATION:
50 target.setType("application"); 58 target.setType("application");
51 break; 59 break;
52 case MAILMIME_DISCRETE_TYPE_EXTENSION: 60 case MAILMIME_DISCRETE_TYPE_EXTENSION:
53 default: 61 default:
54 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { 62 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) {
55 target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); 63 target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension);
56 } 64 }
57 break; 65 break;
58 } 66 }
59 if (type->ct_parameters) { 67 if (type->ct_parameters) {
60 fillParameters(target,type->ct_parameters); 68 fillParameters(target,type->ct_parameters);
61 } 69 }
62 } 70 }
63 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { 71 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) {
64 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { 72 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) {
65 field = (mailmime_field*)current->data; 73 field = (mailmime_field*)current->data;
66 switch(field->fld_type) { 74 switch(field->fld_type) {
67 case MAILMIME_FIELD_TRANSFER_ENCODING: 75 case MAILMIME_FIELD_TRANSFER_ENCODING:
68 target.setEncoding(getencoding(field->fld_data.fld_encoding)); 76 target.setEncoding(getencoding(field->fld_data.fld_encoding));
69 break; 77 break;
70 case MAILMIME_FIELD_ID: 78 case MAILMIME_FIELD_ID:
71 target.setIdentifier(field->fld_data.fld_id); 79 target.setIdentifier(field->fld_data.fld_id);
72 break; 80 break;
73 case MAILMIME_FIELD_DESCRIPTION: 81 case MAILMIME_FIELD_DESCRIPTION:
74 target.setDescription(field->fld_data.fld_description); 82 target.setDescription(field->fld_data.fld_description);
75 break; 83 break;
76 default: 84 default:
77 break; 85 break;
78 } 86 }
79 } 87 }
80 } 88 }
81} 89}
82 90
83void Genericwrapper::fillParameters(RecPart&target,clist*parameters) 91void Genericwrapper::fillParameters(RecPart&target,clist*parameters)
84{ 92{
85 if (!parameters) {return;} 93 if (!parameters) {return;}
86 clistcell*current=0; 94 clistcell*current=0;
87 mailmime_parameter*param; 95 mailmime_parameter*param;
88 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { 96 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) {
89 param = (mailmime_parameter*)current->data; 97 param = (mailmime_parameter*)current->data;
90 if (param) { 98 if (param) {
91 target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 99 target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
92 } 100 }
93 } 101 }
94} 102}
95 103
96QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) 104QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
97{ 105{
98 QString enc="7bit"; 106 QString enc="7bit";
99 if (!aEnc) return enc; 107 if (!aEnc) return enc;
100 switch(aEnc->enc_type) { 108 switch(aEnc->enc_type) {
101 case MAILMIME_MECHANISM_7BIT: 109 case MAILMIME_MECHANISM_7BIT:
102 enc = "7bit"; 110 enc = "7bit";
103 break; 111 break;
104 case MAILMIME_MECHANISM_8BIT: 112 case MAILMIME_MECHANISM_8BIT:
105 enc = "8bit"; 113 enc = "8bit";
106 break; 114 break;
107 case MAILMIME_MECHANISM_BINARY: 115 case MAILMIME_MECHANISM_BINARY:
108 enc = "binary"; 116 enc = "binary";
109 break; 117 break;
110 case MAILMIME_MECHANISM_QUOTED_PRINTABLE: 118 case MAILMIME_MECHANISM_QUOTED_PRINTABLE:
111 enc = "quoted-printable"; 119 enc = "quoted-printable";
112 break; 120 break;
113 case MAILMIME_MECHANISM_BASE64: 121 case MAILMIME_MECHANISM_BASE64:
114 enc = "base64"; 122 enc = "base64";
115 break; 123 break;
116 case MAILMIME_MECHANISM_TOKEN: 124 case MAILMIME_MECHANISM_TOKEN:
117 default: 125 default:
118 if (aEnc->enc_token) { 126 if (aEnc->enc_token) {
119 enc = QString(aEnc->enc_token); 127 enc = QString(aEnc->enc_token);
120 } 128 }
121 break; 129 break;
122 } 130 }
123 return enc; 131 return enc;
124} 132}
125 133
126void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) 134void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count)
127{ 135{
128 if (current_rec >= 10) { 136 if (current_rec >= 10) {
129 qDebug("too deep recursion!"); 137 qDebug("too deep recursion!");
130 } 138 }
131 if (!message || !mime) { 139 if (!message || !mime) {
132 return; 140 return;
133 } 141 }
134 int r; 142 int r;
135 char*data = 0; 143 char*data = 0;
136 size_t len; 144 size_t len;
137 clistiter * cur = 0; 145 clistiter * cur = 0;
138 QString b; 146 QString b;
139 RecPart part; 147 RecPart part;
140 148
141 switch (mime->mm_type) { 149 switch (mime->mm_type) {
142 case MAILMIME_SINGLE: 150 case MAILMIME_SINGLE:
143 { 151 {
144 QValueList<int>countlist = recList; 152 QValueList<int>countlist = recList;
145 countlist.append(current_count); 153 countlist.append(current_count);
146 r = mailmessage_fetch_section(message,mime,&data,&len); 154 r = mailmessage_fetch_section(message,mime,&data,&len);
147 part.setSize(len); 155 part.setSize(len);
148 part.setPositionlist(countlist); 156 part.setPositionlist(countlist);
149 b = gen_attachment_id(); 157 b = gen_attachment_id();
150 part.setIdentifier(b); 158 part.setIdentifier(b);
151 fillSingleBody(part,message,mime); 159 fillSingleBody(part,message,mime);
152 if (part.Type()=="text" && target.Bodytext().isNull()) { 160 if (part.Type()=="text" && target.Bodytext().isNull()) {
153 encodedString*r = new encodedString(); 161 encodedString*r = new encodedString();
154 r->setContent(data,len); 162 r->setContent(data,len);
155 encodedString*res = decode_String(r,part.Encoding()); 163 encodedString*res = decode_String(r,part.Encoding());
156 if (countlist.count()>2) { 164 if (countlist.count()>2) {
157 bodyCache[b]=r; 165 bodyCache[b]=r;
158 target.addPart(part); 166 target.addPart(part);
159 } else { 167 } else {
160 delete r; 168 delete r;
161 } 169 }
162 b = QString(res->Content()); 170 b = QString(res->Content());
163 delete res; 171 delete res;
164 target.setBodytext(b); 172 target.setBodytext(b);
165 target.setDescription(part); 173 target.setDescription(part);
166 } else { 174 } else {
167 bodyCache[b]=new encodedString(data,len); 175 bodyCache[b]=new encodedString(data,len);
168 target.addPart(part); 176 target.addPart(part);
169 } 177 }
170 } 178 }
171 break; 179 break;
172 case MAILMIME_MULTIPLE: 180 case MAILMIME_MULTIPLE:
173 { 181 {
174 unsigned int ccount = 1; 182 unsigned int ccount = 1;
175 mailmime*cbody=0; 183 mailmime*cbody=0;
176 QValueList<int>countlist = recList; 184 QValueList<int>countlist = recList;
177 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { 185 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
178 cbody = (mailmime*)clist_content(cur); 186 cbody = (mailmime*)clist_content(cur);
179 if (cbody->mm_type==MAILMIME_MULTIPLE) { 187 if (cbody->mm_type==MAILMIME_MULTIPLE) {
180 RecPart targetPart; 188 RecPart targetPart;
181 targetPart.setType("multipart"); 189 targetPart.setType("multipart");
182 countlist.append(current_count); 190 countlist.append(current_count);
183 targetPart.setPositionlist(countlist); 191 targetPart.setPositionlist(countlist);
184 target.addPart(targetPart); 192 target.addPart(targetPart);
185 } 193 }
186 traverseBody(target,message, cbody,countlist,current_rec+1,ccount); 194 traverseBody(target,message, cbody,countlist,current_rec+1,ccount);
187 if (cbody->mm_type==MAILMIME_MULTIPLE) { 195 if (cbody->mm_type==MAILMIME_MULTIPLE) {
188 countlist = recList; 196 countlist = recList;
189 } 197 }
190 ++ccount; 198 ++ccount;
191 } 199 }
192 } 200 }
193 break; 201 break;
194 case MAILMIME_MESSAGE: 202 case MAILMIME_MESSAGE:
195 { 203 {
196 QValueList<int>countlist = recList; 204 QValueList<int>countlist = recList;
197 countlist.append(current_count); 205 countlist.append(current_count);
198 /* the own header is always at recursion 0 - we don't need that */ 206 /* the own header is always at recursion 0 - we don't need that */
199 if (current_rec > 0) { 207 if (current_rec > 0) {
200 part.setPositionlist(countlist); 208 part.setPositionlist(countlist);
201 r = mailmessage_fetch_section(message,mime,&data,&len); 209 r = mailmessage_fetch_section(message,mime,&data,&len);
202 part.setSize(len); 210 part.setSize(len);
203 part.setPositionlist(countlist); 211 part.setPositionlist(countlist);
204 b = gen_attachment_id(); 212 b = gen_attachment_id();
205 part.setIdentifier(b); 213 part.setIdentifier(b);
206 part.setType("message"); 214 part.setType("message");
207 part.setSubtype("rfc822"); 215 part.setSubtype("rfc822");
208 bodyCache[b]=new encodedString(data,len); 216 bodyCache[b]=new encodedString(data,len);
209 target.addPart(part); 217 target.addPart(part);
210 } 218 }
211 if (mime->mm_data.mm_message.mm_msg_mime != NULL) { 219 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
212 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); 220 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1);
213 } 221 }
214 } 222 }
215 break; 223 break;
216 } 224 }
217} 225}
218 226
219RecBody Genericwrapper::parseMail( mailmessage * msg ) 227RecBody Genericwrapper::parseMail( mailmessage * msg )
220{ 228{
221 int err = MAILIMF_NO_ERROR; 229 int err = MAILIMF_NO_ERROR;
222 mailmime_single_fields fields; 230 mailmime_single_fields fields;
223 /* is bound to msg and will be freed there */ 231 /* is bound to msg and will be freed there */
224 mailmime * mime=0; 232 mailmime * mime=0;
225 RecBody body; 233 RecBody body;
226 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 234 memset(&fields, 0, sizeof(struct mailmime_single_fields));
227 err = mailmessage_get_bodystructure(msg,&mime); 235 err = mailmessage_get_bodystructure(msg,&mime);
228 QValueList<int>recList; 236 QValueList<int>recList;
229 traverseBody(body,msg,mime,recList); 237 traverseBody(body,msg,mime,recList);
230 return body; 238 return body;
231} 239}
232 240
233RecMail *Genericwrapper::parseHeader( const char *header ) 241RecMail *Genericwrapper::parseHeader( const char *header )
234{ 242{
235 int err = MAILIMF_NO_ERROR; 243 int err = MAILIMF_NO_ERROR;
236 size_t curTok = 0; 244 size_t curTok = 0;
237 RecMail *mail = new RecMail(); 245 RecMail *mail = new RecMail();
238 mailimf_fields *fields = 0; 246 mailimf_fields *fields = 0;
239 mailimf_references * refs = 0; 247 mailimf_references * refs = 0;
240 mailimf_keywords*keys = 0; 248 mailimf_keywords*keys = 0;
241 QString status; 249 QString status;
242 QString value; 250 QString value;
243 QBitArray mFlags(7); 251 QBitArray mFlags(7);
244 252
245 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 253 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
246 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 254 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
247 mailimf_field *field = (mailimf_field *) current->data; 255 mailimf_field *field = (mailimf_field *) current->data;
248 switch ( field->fld_type ) { 256 switch ( field->fld_type ) {
249 case MAILIMF_FIELD_FROM: 257 case MAILIMF_FIELD_FROM:
250 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 258 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
251 break; 259 break;
252 case MAILIMF_FIELD_TO: 260 case MAILIMF_FIELD_TO:
253 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 261 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
254 break; 262 break;
255 case MAILIMF_FIELD_CC: 263 case MAILIMF_FIELD_CC:
256 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 264 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
257 break; 265 break;
258 case MAILIMF_FIELD_BCC: 266 case MAILIMF_FIELD_BCC:
259 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 267 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
260 break; 268 break;
261 case MAILIMF_FIELD_SUBJECT: 269 case MAILIMF_FIELD_SUBJECT:
262 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); 270 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) );
263 break; 271 break;
264 case MAILIMF_FIELD_ORIG_DATE: 272 case MAILIMF_FIELD_ORIG_DATE:
265 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 273 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
266 break; 274 break;
267 case MAILIMF_FIELD_MESSAGE_ID: 275 case MAILIMF_FIELD_MESSAGE_ID:
268 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); 276 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value));
269 break; 277 break;
270 case MAILIMF_FIELD_REFERENCES: 278 case MAILIMF_FIELD_REFERENCES:
271 refs = field->fld_data.fld_references; 279 refs = field->fld_data.fld_references;
272 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 280 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
273 char * text = (char*)refs->mid_list->first->data; 281 char * text = (char*)refs->mid_list->first->data;
274 mail->setReplyto(QString(text)); 282 mail->setReplyto(QString(text));
275 } 283 }
276 break; 284 break;
277 case MAILIMF_FIELD_KEYWORDS: 285 case MAILIMF_FIELD_KEYWORDS:
278 keys = field->fld_data.fld_keywords; 286 keys = field->fld_data.fld_keywords;
279 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { 287 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
280 qDebug("Keyword: %s",(char*)cur->data); 288 qDebug("Keyword: %s",(char*)cur->data);
281 } 289 }
282 break; 290 break;
283 case MAILIMF_FIELD_OPTIONAL_FIELD: 291 case MAILIMF_FIELD_OPTIONAL_FIELD:
284 status = field->fld_data.fld_optional_field->fld_name; 292 status = field->fld_data.fld_optional_field->fld_name;
285 value = field->fld_data.fld_optional_field->fld_value; 293 value = field->fld_data.fld_optional_field->fld_value;
286 if (status.lower()=="status") { 294 if (status.lower()=="status") {
287 if (value.lower()=="ro") { 295 if (value.lower()=="ro") {
288 mFlags.setBit(FLAG_SEEN); 296 mFlags.setBit(FLAG_SEEN);
289 } 297 }
290 } else if (status.lower()=="x-status") { 298 } else if (status.lower()=="x-status") {
291 qDebug("X-Status: %s",value.latin1()); 299 qDebug("X-Status: %s",value.latin1());
292 if (value.lower()=="a") { 300 if (value.lower()=="a") {
293 mFlags.setBit(FLAG_ANSWERED); 301 mFlags.setBit(FLAG_ANSWERED);
294 } 302 }
295 } else { 303 } else {
296// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, 304// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name,
297// field->fld_data.fld_optional_field->fld_value); 305// field->fld_data.fld_optional_field->fld_value);
298 } 306 }
299 break; 307 break;
300 default: 308 default:
301 qDebug("Non parsed field"); 309 qDebug("Non parsed field");
302 break; 310 break;
303 } 311 }
304 } 312 }
305 if (fields) mailimf_fields_free(fields); 313 if (fields) mailimf_fields_free(fields);
306 mail->setFlags(mFlags); 314 mail->setFlags(mFlags);
307 return mail; 315 return mail;
308} 316}
309 317
310QString Genericwrapper::parseDateTime( mailimf_date_time *date ) 318QString Genericwrapper::parseDateTime( mailimf_date_time *date )
311{ 319{
312 char tmp[23]; 320 char tmp[23];
313 321
314 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 322 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
315 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 323 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
316 324
317 return QString( tmp ); 325 return QString( tmp );
318} 326}
319 327
320QString Genericwrapper::parseAddressList( mailimf_address_list *list ) 328QString Genericwrapper::parseAddressList( mailimf_address_list *list )
321{ 329{
322 QString result( "" ); 330 QString result( "" );
323 331
324 bool first = true; 332 bool first = true;
325 if (list == 0) return result; 333 if (list == 0) return result;
326 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 334 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
327 mailimf_address *addr = (mailimf_address *) current->data; 335 mailimf_address *addr = (mailimf_address *) current->data;
328 336
329 if ( !first ) { 337 if ( !first ) {
330 result.append( "," ); 338 result.append( "," );
331 } else { 339 } else {
332 first = false; 340 first = false;
333 } 341 }
334 342
335 switch ( addr->ad_type ) { 343 switch ( addr->ad_type ) {
336 case MAILIMF_ADDRESS_MAILBOX: 344 case MAILIMF_ADDRESS_MAILBOX:
337 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 345 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
338 break; 346 break;
339 case MAILIMF_ADDRESS_GROUP: 347 case MAILIMF_ADDRESS_GROUP:
340 result.append( parseGroup( addr->ad_data.ad_group ) ); 348 result.append( parseGroup( addr->ad_data.ad_group ) );
341 break; 349 break;
342 default: 350 default:
343 qDebug( "Generic: unkown mailimf address type" ); 351 qDebug( "Generic: unkown mailimf address type" );
344 break; 352 break;
345 } 353 }
346 } 354 }
347 355
348 return result; 356 return result;
349} 357}
350 358
351QString Genericwrapper::parseGroup( mailimf_group *group ) 359QString Genericwrapper::parseGroup( mailimf_group *group )
352{ 360{
353 QString result( "" ); 361 QString result( "" );
354 362
355 result.append( group->grp_display_name ); 363 result.append( group->grp_display_name );
356 result.append( ": " ); 364 result.append( ": " );
357 365
358 if ( group->grp_mb_list != NULL ) { 366 if ( group->grp_mb_list != NULL ) {
359 result.append( parseMailboxList( group->grp_mb_list ) ); 367 result.append( parseMailboxList( group->grp_mb_list ) );
360 } 368 }
361 369
362 result.append( ";" ); 370 result.append( ";" );
363 371
364 return result; 372 return result;
365} 373}
366 374
367QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) 375QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
368{ 376{
369 QString result( "" ); 377 QString result( "" );
370 378
371 if ( box->mb_display_name == NULL ) { 379 if ( box->mb_display_name == NULL ) {
372 result.append( box->mb_addr_spec ); 380 result.append( box->mb_addr_spec );
373 } else { 381 } else {
374 result.append( convert_String(box->mb_display_name).latin1() ); 382 result.append( convert_String(box->mb_display_name).latin1() );
375 result.append( " <" ); 383 result.append( " <" );
376 result.append( box->mb_addr_spec ); 384 result.append( box->mb_addr_spec );
377 result.append( ">" ); 385 result.append( ">" );
378 } 386 }
379 387
380 return result; 388 return result;
381} 389}
382 390
383QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) 391QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
384{ 392{
385 QString result( "" ); 393 QString result( "" );
386 394
387 bool first = true; 395 bool first = true;
388 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 396 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
389 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 397 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
390 398
391 if ( !first ) { 399 if ( !first ) {
392 result.append( "," ); 400 result.append( "," );
393 } else { 401 } else {
394 first = false; 402 first = false;
395 } 403 }
396 404
397 result.append( parseMailbox( box ) ); 405 result.append( parseMailbox( box ) );
398 } 406 }
399 407
400 return result; 408 return result;
401} 409}
402 410
403encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part) 411encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part)
404{ 412{
405 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); 413 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
406 if (it==bodyCache.end()) return new encodedString(); 414 if (it==bodyCache.end()) return new encodedString();
407 encodedString*t = decode_String(it.data(),part.Encoding()); 415 encodedString*t = decode_String(it.data(),part.Encoding());
408 return t; 416 return t;
409} 417}
410 418
411encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 419encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
412{ 420{
413 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); 421 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
414 if (it==bodyCache.end()) return new encodedString(); 422 if (it==bodyCache.end()) return new encodedString();
415 encodedString*t = it.data(); 423 encodedString*t = it.data();
416 return t; 424 return t;
417} 425}
418 426
419QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 427QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
420{ 428{
421 encodedString*t = fetchDecodedPart(mail,part); 429 encodedString*t = fetchDecodedPart(mail,part);
422 QString text=t->Content(); 430 QString text=t->Content();
423 delete t; 431 delete t;
424 return text; 432 return text;
425} 433}
426 434
427void Genericwrapper::cleanMimeCache() 435void Genericwrapper::cleanMimeCache()
428{ 436{
429 QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); 437 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
430 for (;it!=bodyCache.end();++it) { 438 for (;it!=bodyCache.end();++it) {
431 encodedString*t = it.data(); 439 encodedString*t = it.data();
432 //it.setValue(0); 440 //it.setValue(0);
433 if (t) delete t; 441 if (t) delete t;
434 } 442 }
435 bodyCache.clear(); 443 bodyCache.clear();
436 qDebug("Genericwrapper: cache cleaned"); 444 qDebug("Genericwrapper: cache cleaned");
437} 445}
438 446
439void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox) 447void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox)
440{ 448{
441 int r; 449 int r;
442 mailmessage_list * env_list = 0; 450 mailmessage_list * env_list = 0;
443 r = mailsession_get_messages_list(session,&env_list); 451 r = mailsession_get_messages_list(session,&env_list);
444 if (r != MAIL_NO_ERROR) { 452 if (r != MAIL_NO_ERROR) {
445 qDebug("Error message list"); 453 qDebug("Error message list");
446 return; 454 return;
447 } 455 }
448 r = mailsession_get_envelopes_list(session, env_list); 456 r = mailsession_get_envelopes_list(session, env_list);
449 if (r != MAIL_NO_ERROR) { 457 if (r != MAIL_NO_ERROR) {
450 qDebug("Error filling message list"); 458 qDebug("Error filling message list");
451 if (env_list) { 459 if (env_list) {
452 mailmessage_list_free(env_list); 460 mailmessage_list_free(env_list);
453 } 461 }
454 return; 462 return;
455 } 463 }
456 mailimf_references * refs; 464 mailimf_references * refs;
457 uint32_t i = 0; 465 uint32_t i = 0;
458 for(; i < carray_count(env_list->msg_tab) ; ++i) { 466 for(; i < carray_count(env_list->msg_tab) ; ++i) {
459 mailmessage * msg; 467 mailmessage * msg;
460 QBitArray mFlags(7); 468 QBitArray mFlags(7);
461 msg = (mailmessage*)carray_get(env_list->msg_tab, i); 469 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
462 if (msg->msg_fields == NULL) { 470 if (msg->msg_fields == NULL) {
463 qDebug("could not fetch envelope of message %i", i); 471 qDebug("could not fetch envelope of message %i", i);
464 continue; 472 continue;
465 } 473 }
466 RecMail * mail = new RecMail(); 474 RecMail * mail = new RecMail();
467 mail->setWrapper(this); 475 mail->setWrapper(this);
468 mail_flags * flag_result = 0; 476 mail_flags * flag_result = 0;
469 r = mailmessage_get_flags(msg,&flag_result); 477 r = mailmessage_get_flags(msg,&flag_result);
470 if (r == MAIL_ERROR_NOT_IMPLEMENTED) { 478 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
471 mFlags.setBit(FLAG_SEEN); 479 mFlags.setBit(FLAG_SEEN);
472 } 480 }
473 mailimf_single_fields single_fields; 481 mailimf_single_fields single_fields;
474 mailimf_single_fields_init(&single_fields, msg->msg_fields); 482 mailimf_single_fields_init(&single_fields, msg->msg_fields);
475 mail->setMsgsize(msg->msg_size); 483 mail->setMsgsize(msg->msg_size);
476 mail->setFlags(mFlags); 484 mail->setFlags(mFlags);
477 mail->setMbox(mailbox); 485 mail->setMbox(mailbox);
478 mail->setNumber(msg->msg_index); 486 mail->setNumber(msg->msg_index);
479 if (single_fields.fld_subject) 487 if (single_fields.fld_subject)
480 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); 488 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
481 if (single_fields.fld_from) 489 if (single_fields.fld_from)
482 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); 490 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
483 if (single_fields.fld_to) 491 if (single_fields.fld_to)
484 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); 492 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
485 if (single_fields.fld_cc) 493 if (single_fields.fld_cc)
486 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); 494 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) );
487 if (single_fields.fld_bcc) 495 if (single_fields.fld_bcc)
488 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); 496 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) );
489 if (single_fields.fld_orig_date) 497 if (single_fields.fld_orig_date)
490 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); 498 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) );
491 // crashes when accessing pop3 account 499 // crashes when accessing pop3 account
492 // if (single_fields.fld_message_id->mid_value) 500 // if (single_fields.fld_message_id->mid_value)
493 // mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); 501 // mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
494 refs = single_fields.fld_references; 502 refs = single_fields.fld_references;
495 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 503 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
496 char * text = (char*)refs->mid_list->first->data; 504 char * text = (char*)refs->mid_list->first->data;
497 mail->setReplyto(QString(text)); 505 mail->setReplyto(QString(text));
498 } 506 }
499 target.append(mail); 507 target.append(mail);
500 } 508 }
501 if (env_list) { 509 if (env_list) {
502 mailmessage_list_free(env_list); 510 mailmessage_list_free(env_list);
503 } 511 }
504} 512}
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.h b/noncore/net/mail/libmailwrapper/genericwrapper.h
index 1d65c0a..e471dc8 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.h
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.h
@@ -1,62 +1,66 @@
1#ifndef __GENERIC_WRAPPER_H 1#ifndef __GENERIC_WRAPPER_H
2#define __GENERIC_WRAPPER_H 2#define __GENERIC_WRAPPER_H
3 3
4#include "abstractmail.h" 4#include "abstractmail.h"
5#include <qmap.h> 5#include <qmap.h>
6#include <qstring.h> 6#include <qstring.h>
7#include <libetpan/clist.h> 7#include <libetpan/clist.h>
8 8
9class RecMail; 9class RecMail;
10class RecBody; 10class RecBody;
11class encodedString; 11class encodedString;
12struct mailpop3; 12struct mailpop3;
13struct mailmessage; 13struct mailmessage;
14struct mailmime; 14struct mailmime;
15struct mailmime_mechanism; 15struct mailmime_mechanism;
16struct mailimf_mailbox_list; 16struct mailimf_mailbox_list;
17struct mailimf_mailbox; 17struct mailimf_mailbox;
18struct mailimf_date_time; 18struct mailimf_date_time;
19struct mailimf_group; 19struct mailimf_group;
20struct mailimf_address_list; 20struct mailimf_address_list;
21struct mailsession; 21struct mailsession;
22struct mailstorage;
23struct mailfolder;
22 24
23/* this class hold just the funs shared between 25/* this class hold just the funs shared between
24 * mbox and pop3 (later mh, too) mail access. 26 * mbox and pop3 (later mh, too) mail access.
25 * it is not desigend to make a instance of it! 27 * it is not desigend to make a instance of it!
26 */ 28 */
27class Genericwrapper : public AbstractMail 29class Genericwrapper : public AbstractMail
28{ 30{
29 Q_OBJECT 31 Q_OBJECT
30public: 32public:
31 Genericwrapper(); 33 Genericwrapper();
32 virtual ~Genericwrapper(); 34 virtual ~Genericwrapper();
33 35
34 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 36 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
35 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 37 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
36 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 38 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
37 virtual void cleanMimeCache(); 39 virtual void cleanMimeCache();
38 virtual int deleteMbox(const Folder*){return 1;} 40 virtual int deleteMbox(const Folder*){return 1;}
39 virtual void logout(){}; 41 virtual void logout(){};
40 virtual void storeMessage(const char*msg,size_t length, const QString&folder){}; 42 virtual void storeMessage(const char*msg,size_t length, const QString&folder){};
41 43
42protected: 44protected:
43 RecMail *parseHeader( const char *header ); 45 RecMail *parseHeader( const char *header );
44 RecBody parseMail( mailmessage * msg ); 46 RecBody parseMail( mailmessage * msg );
45 QString parseMailboxList( mailimf_mailbox_list *list ); 47 QString parseMailboxList( mailimf_mailbox_list *list );
46 QString parseMailbox( mailimf_mailbox *box ); 48 QString parseMailbox( mailimf_mailbox *box );
47 QString parseGroup( mailimf_group *group ); 49 QString parseGroup( mailimf_group *group );
48 QString parseAddressList( mailimf_address_list *list ); 50 QString parseAddressList( mailimf_address_list *list );
49 QString parseDateTime( mailimf_date_time *date ); 51 QString parseDateTime( mailimf_date_time *date );
50 52
51 void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=1); 53 void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=1);
52 static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); 54 static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime);
53 static void fillParameters(RecPart&target,clist*parameters); 55 static void fillParameters(RecPart&target,clist*parameters);
54 static QString getencoding(mailmime_mechanism*aEnc); 56 static QString getencoding(mailmime_mechanism*aEnc);
55 virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox); 57 virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox);
56 58
57 QString msgTempName; 59 QString msgTempName;
58 unsigned int last_msg_id; 60 unsigned int last_msg_id;
59 QMap<QString,encodedString*> bodyCache; 61 QMap<QString,encodedString*> bodyCache;
62 mailstorage * m_storage;
63 mailfolder*m_folder;
60}; 64};
61 65
62#endif 66#endif
diff --git a/noncore/net/mail/libmailwrapper/libmailwrapper.pro b/noncore/net/mail/libmailwrapper/libmailwrapper.pro
index 18583bb..71f6cca 100644
--- a/noncore/net/mail/libmailwrapper/libmailwrapper.pro
+++ b/noncore/net/mail/libmailwrapper/libmailwrapper.pro
@@ -1,46 +1,48 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on debug 2CONFIG += qt warn_on debug
3 3
4HEADERS = mailwrapper.h \ 4HEADERS = mailwrapper.h \
5 imapwrapper.h \ 5 imapwrapper.h \
6 mailtypes.h \ 6 mailtypes.h \
7 pop3wrapper.h \ 7 pop3wrapper.h \
8 abstractmail.h \ 8 abstractmail.h \
9 smtpwrapper.h \ 9 smtpwrapper.h \
10 genericwrapper.h \ 10 genericwrapper.h \
11 mboxwrapper.h \ 11 mboxwrapper.h \
12 settings.h \ 12 settings.h \
13 logindialog.h \ 13 logindialog.h \
14 sendmailprogress.h \ 14 sendmailprogress.h \
15 statusmail.h 15 statusmail.h \
16 mhwrapper.h
16 17
17SOURCES = imapwrapper.cpp \ 18SOURCES = imapwrapper.cpp \
18 mailwrapper.cpp \ 19 mailwrapper.cpp \
19 mailtypes.cpp \ 20 mailtypes.cpp \
20 pop3wrapper.cpp \ 21 pop3wrapper.cpp \
21 abstractmail.cpp \ 22 abstractmail.cpp \
22 smtpwrapper.cpp \ 23 smtpwrapper.cpp \
23 genericwrapper.cpp \ 24 genericwrapper.cpp \
24 mboxwrapper.cpp \ 25 mboxwrapper.cpp \
25 settings.cpp \ 26 settings.cpp \
26 logindialog.cpp \ 27 logindialog.cpp \
27 sendmailprogress.cpp \ 28 sendmailprogress.cpp \
28 statusmail.cpp 29 statusmail.cpp \
30 mhwrapper.cpp
29 31
30 INTERFACES = logindialogui.ui \ 32 INTERFACES = logindialogui.ui \
31 sendmailprogressui.ui 33 sendmailprogressui.ui
32 34
33 35
34INCLUDEPATH += $(OPIEDIR)/include 36INCLUDEPATH += $(OPIEDIR)/include
35 37
36CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX ) 38CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX )
37contains( CONFTEST, y ){ 39contains( CONFTEST, y ){
38 LIBS += -lqpe -letpan -lssl -lcrypto -liconv 40 LIBS += -lqpe -letpan -lssl -lcrypto -liconv
39}else{ 41}else{
40 LIBS += -lqpe -letpan -lssl -lcrypto 42 LIBS += -lqpe -letpan -lssl -lcrypto
41} 43}
42 44
43DESTDIR = $(OPIEDIR)/lib$(PROJMAK) 45DESTDIR = $(OPIEDIR)/lib$(PROJMAK)
44TARGET = mailwrapper 46TARGET = mailwrapper
45 47
46include ( $(OPIEDIR)/include.pro ) 48include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
index 75b9343..ebdbf4b 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
@@ -1,148 +1,164 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <sys/stat.h> 2#include <sys/stat.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <fcntl.h> 5#include <fcntl.h>
6#include <string.h> 6#include <string.h>
7#include <qdir.h> 7#include <qdir.h>
8 8
9#include "mailwrapper.h" 9#include "mailwrapper.h"
10//#include "logindialog.h" 10//#include "logindialog.h"
11//#include "defines.h" 11//#include "defines.h"
12 12
13#define UNDEFINED 64 13#define UNDEFINED 64
14#define MAXLINE 76 14#define MAXLINE 76
15#define UTF16MASK 0x03FFUL 15#define UTF16MASK 0x03FFUL
16#define UTF16SHIFT 10 16#define UTF16SHIFT 10
17#define UTF16BASE 0x10000UL 17#define UTF16BASE 0x10000UL
18#define UTF16HIGHSTART 0xD800UL 18#define UTF16HIGHSTART 0xD800UL
19#define UTF16HIGHEND 0xDBFFUL 19#define UTF16HIGHEND 0xDBFFUL
20#define UTF16LOSTART 0xDC00UL 20#define UTF16LOSTART 0xDC00UL
21#define UTF16LOEND 0xDFFFUL 21#define UTF16LOEND 0xDFFFUL
22 22
23 23
24Attachment::Attachment( DocLnk lnk ) 24Attachment::Attachment( DocLnk lnk )
25{ 25{
26 doc = lnk; 26 doc = lnk;
27 size = QFileInfo( doc.file() ).size(); 27 size = QFileInfo( doc.file() ).size();
28} 28}
29 29
30Folder::Folder(const QString&tmp_name, const QString&sep ) 30Folder::Folder(const QString&tmp_name, const QString&sep )
31{ 31{
32 name = tmp_name; 32 name = tmp_name;
33 nameDisplay = name; 33 nameDisplay = name;
34 separator = sep; 34 separator = sep;
35 prefix = "";
35} 36}
36 37
37const QString& Folder::Separator()const 38const QString& Folder::Separator()const
38{ 39{
39 return separator; 40 return separator;
40} 41}
41 42
42IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&prefix ) 43IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&aprefix )
43 : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf) 44 : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf)
44{ 45{
45 // Decode IMAP foldername 46 // Decode IMAP foldername
46 nameDisplay = IMAPFolder::decodeFolderName( name ); 47 nameDisplay = IMAPFolder::decodeFolderName( name );
47 qDebug( "folder " + name + " - displayed as " + nameDisplay ); 48 qDebug( "folder " + name + " - displayed as " + nameDisplay );
49 prefix = aprefix;
48 50
49 if (prefix.length()>0) { 51 if (prefix.length()>0) {
50 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { 52 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) {
51 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); 53 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length());
52 } 54 }
53 } 55 }
54} 56}
55 57
56static unsigned char base64chars[] = 58static unsigned char base64chars[] =
57 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; 59 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
58 60
59/** 61/**
60 * Decodes base64 encoded parts of the imapfolder name 62 * Decodes base64 encoded parts of the imapfolder name
61 * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc 63 * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc
62 */ 64 */
63QString IMAPFolder::decodeFolderName( const QString &name ) 65QString IMAPFolder::decodeFolderName( const QString &name )
64{ 66{
65 unsigned char c, i, bitcount; 67 unsigned char c, i, bitcount;
66 unsigned long ucs4, utf16, bitbuf; 68 unsigned long ucs4, utf16, bitbuf;
67 unsigned char base64[256], utf8[6]; 69 unsigned char base64[256], utf8[6];
68 unsigned long srcPtr = 0; 70 unsigned long srcPtr = 0;
69 QCString dst = ""; 71 QCString dst = "";
70 QCString src = name.ascii(); 72 QCString src = name.ascii();
71 73
72 /* initialize modified base64 decoding table */ 74 /* initialize modified base64 decoding table */
73 memset(base64, UNDEFINED, sizeof(base64)); 75 memset(base64, UNDEFINED, sizeof(base64));
74 for (i = 0; i < sizeof(base64chars); ++i) { 76 for (i = 0; i < sizeof(base64chars); ++i) {
75 base64[(int)base64chars[i]] = i; 77 base64[(int)base64chars[i]] = i;
76 } 78 }
77 79
78 /* loop until end of string */ 80 /* loop until end of string */
79 while (srcPtr < src.length ()) { 81 while (srcPtr < src.length ()) {
80 c = src[srcPtr++]; 82 c = src[srcPtr++];
81 /* deal with literal characters and &- */ 83 /* deal with literal characters and &- */
82 if (c != '&' || src[srcPtr] == '-') { 84 if (c != '&' || src[srcPtr] == '-') {
83 /* encode literally */ 85 /* encode literally */
84 dst += c; 86 dst += c;
85 /* skip over the '-' if this is an &- sequence */ 87 /* skip over the '-' if this is an &- sequence */
86 if (c == '&') 88 if (c == '&')
87 srcPtr++; 89 srcPtr++;
88 } else { 90 } else {
89 /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */ 91 /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */
90 bitbuf = 0; 92 bitbuf = 0;
91 bitcount = 0; 93 bitcount = 0;
92 ucs4 = 0; 94 ucs4 = 0;
93 while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) { 95 while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) {
94 ++srcPtr; 96 ++srcPtr;
95 bitbuf = (bitbuf << 6) | c; 97 bitbuf = (bitbuf << 6) | c;
96 bitcount += 6; 98 bitcount += 6;
97 /* enough bits for a UTF-16 character? */ 99 /* enough bits for a UTF-16 character? */
98 if (bitcount >= 16) { 100 if (bitcount >= 16) {
99 bitcount -= 16; 101 bitcount -= 16;
100 utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; 102 utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff;
101 /* convert UTF16 to UCS4 */ 103 /* convert UTF16 to UCS4 */
102 if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { 104 if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) {
103 ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; 105 ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT;
104 continue; 106 continue;
105 } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { 107 } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) {
106 ucs4 += utf16 - UTF16LOSTART + UTF16BASE; 108 ucs4 += utf16 - UTF16LOSTART + UTF16BASE;
107 } else { 109 } else {
108 ucs4 = utf16; 110 ucs4 = utf16;
109 } 111 }
110 /* convert UTF-16 range of UCS4 to UTF-8 */ 112 /* convert UTF-16 range of UCS4 to UTF-8 */
111 if (ucs4 <= 0x7fUL) { 113 if (ucs4 <= 0x7fUL) {
112 utf8[0] = ucs4; 114 utf8[0] = ucs4;
113 i = 1; 115 i = 1;
114 } else if (ucs4 <= 0x7ffUL) { 116 } else if (ucs4 <= 0x7ffUL) {
115 utf8[0] = 0xc0 | (ucs4 >> 6); 117 utf8[0] = 0xc0 | (ucs4 >> 6);
116 utf8[1] = 0x80 | (ucs4 & 0x3f); 118 utf8[1] = 0x80 | (ucs4 & 0x3f);
117 i = 2; 119 i = 2;
118 } else if (ucs4 <= 0xffffUL) { 120 } else if (ucs4 <= 0xffffUL) {
119 utf8[0] = 0xe0 | (ucs4 >> 12); 121 utf8[0] = 0xe0 | (ucs4 >> 12);
120 utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f); 122 utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f);
121 utf8[2] = 0x80 | (ucs4 & 0x3f); 123 utf8[2] = 0x80 | (ucs4 & 0x3f);
122 i = 3; 124 i = 3;
123 } else { 125 } else {
124 utf8[0] = 0xf0 | (ucs4 >> 18); 126 utf8[0] = 0xf0 | (ucs4 >> 18);
125 utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f); 127 utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f);
126 utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f); 128 utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f);
127 utf8[3] = 0x80 | (ucs4 & 0x3f); 129 utf8[3] = 0x80 | (ucs4 & 0x3f);
128 i = 4; 130 i = 4;
129 } 131 }
130 /* copy it */ 132 /* copy it */
131 for (c = 0; c < i; ++c) { 133 for (c = 0; c < i; ++c) {
132 dst += utf8[c]; 134 dst += utf8[c];
133 } 135 }
134 } 136 }
135 } 137 }
136 /* skip over trailing '-' in modified UTF-7 encoding */ 138 /* skip over trailing '-' in modified UTF-7 encoding */
137 if (src[srcPtr] == '-') 139 if (src[srcPtr] == '-')
138 ++srcPtr; 140 ++srcPtr;
139 } 141 }
140 } 142 }
141 143
142 return QString::fromUtf8( dst.data() ); 144 return QString::fromUtf8( dst.data() );
143} 145}
144 146
145Mail::Mail() 147Mail::Mail()
146 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") 148 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("")
147{ 149{
148} 150}
151
152MHFolder::MHFolder(const QString&disp_name,const QString&mbox)
153 : Folder( disp_name,"/" )
154{
155 separator = "/";
156 name = mbox;
157 if (!disp_name.startsWith("/") && disp_name.length()>0)
158 name+="/";
159 name+=disp_name;
160 if (disp_name.length()==0) {
161 nameDisplay = separator;
162 }
163 prefix = mbox;
164}
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h
index a60777d..caaa3a2 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.h
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.h
@@ -1,92 +1,99 @@
1#ifndef MAILWRAPPER_H 1#ifndef MAILWRAPPER_H
2#define MAILWRAPPER_H 2#define MAILWRAPPER_H
3 3
4#include <qpe/applnk.h> 4#include <qpe/applnk.h>
5 5
6#include <qbitarray.h> 6#include <qbitarray.h>
7#include <qdatetime.h> 7#include <qdatetime.h>
8 8
9#include "settings.h" 9#include "settings.h"
10 10
11class Attachment 11class Attachment
12{ 12{
13public: 13public:
14 Attachment( DocLnk lnk ); 14 Attachment( DocLnk lnk );
15 virtual ~Attachment(){} 15 virtual ~Attachment(){}
16 const QString getFileName()const{ return doc.file(); } 16 const QString getFileName()const{ return doc.file(); }
17 const QString getName()const{ return doc.name(); } 17 const QString getName()const{ return doc.name(); }
18 const QString getMimeType()const{ return doc.type(); } 18 const QString getMimeType()const{ return doc.type(); }
19 const QPixmap getPixmap()const{ return doc.pixmap(); } 19 const QPixmap getPixmap()const{ return doc.pixmap(); }
20 const int getSize()const { return size; } 20 const int getSize()const { return size; }
21 DocLnk getDocLnk() { return doc; } 21 DocLnk getDocLnk() { return doc; }
22 22
23protected: 23protected:
24 DocLnk doc; 24 DocLnk doc;
25 int size; 25 int size;
26 26
27}; 27};
28 28
29class Mail 29class Mail
30{ 30{
31public: 31public:
32 Mail(); 32 Mail();
33 /* Possible that this destructor must not be declared virtual 33 /* Possible that this destructor must not be declared virtual
34 * 'cause it seems that it will never have some child classes. 34 * 'cause it seems that it will never have some child classes.
35 * in this case this object will not get a virtual table -> memory and 35 * in this case this object will not get a virtual table -> memory and
36 * speed will be a little bit better? 36 * speed will be a little bit better?
37 */ 37 */
38 virtual ~Mail(){} 38 virtual ~Mail(){}
39 void addAttachment( Attachment *att ) { attList.append( att ); } 39 void addAttachment( Attachment *att ) { attList.append( att ); }
40 const QList<Attachment>& getAttachments()const { return attList; } 40 const QList<Attachment>& getAttachments()const { return attList; }
41 void removeAttachment( Attachment *att ) { attList.remove( att ); } 41 void removeAttachment( Attachment *att ) { attList.remove( att ); }
42 const QString&getName()const { return name; } 42 const QString&getName()const { return name; }
43 void setName( QString s ) { name = s; } 43 void setName( QString s ) { name = s; }
44 const QString&getMail()const{ return mail; } 44 const QString&getMail()const{ return mail; }
45 void setMail( const QString&s ) { mail = s; } 45 void setMail( const QString&s ) { mail = s; }
46 const QString&getTo()const{ return to; } 46 const QString&getTo()const{ return to; }
47 void setTo( const QString&s ) { to = s; } 47 void setTo( const QString&s ) { to = s; }
48 const QString&getCC()const{ return cc; } 48 const QString&getCC()const{ return cc; }
49 void setCC( const QString&s ) { cc = s; } 49 void setCC( const QString&s ) { cc = s; }
50 const QString&getBCC()const { return bcc; } 50 const QString&getBCC()const { return bcc; }
51 void setBCC( const QString&s ) { bcc = s; } 51 void setBCC( const QString&s ) { bcc = s; }
52 const QString&getMessage()const { return message; } 52 const QString&getMessage()const { return message; }
53 void setMessage( const QString&s ) { message = s; } 53 void setMessage( const QString&s ) { message = s; }
54 const QString&getSubject()const { return subject; } 54 const QString&getSubject()const { return subject; }
55 void setSubject( const QString&s ) { subject = s; } 55 void setSubject( const QString&s ) { subject = s; }
56 const QString&getReply()const{ return reply; } 56 const QString&getReply()const{ return reply; }
57 void setReply( const QString&a ) { reply = a; } 57 void setReply( const QString&a ) { reply = a; }
58 58
59private: 59private:
60 QList<Attachment> attList; 60 QList<Attachment> attList;
61 QString name, mail, to, cc, bcc, reply, subject, message; 61 QString name, mail, to, cc, bcc, reply, subject, message;
62}; 62};
63 63
64class Folder : public QObject 64class Folder : public QObject
65{ 65{
66 Q_OBJECT 66 Q_OBJECT
67 67
68public: 68public:
69 Folder( const QString&init_name,const QString&sep ); 69 Folder( const QString&init_name,const QString&sep );
70 const QString&getDisplayName()const { return nameDisplay; } 70 const QString&getDisplayName()const { return nameDisplay; }
71 const QString&getName()const { return name; } 71 const QString&getName()const { return name; }
72 const QString&getPrefix()const{return prefix; }
72 virtual bool may_select()const{return true;} 73 virtual bool may_select()const{return true;}
73 virtual bool no_inferior()const{return true;} 74 virtual bool no_inferior()const{return true;}
74 const QString&Separator()const; 75 const QString&Separator()const;
75 76
76protected: 77protected:
77 QString nameDisplay, name, separator; 78 QString nameDisplay, name, separator,prefix;
78 79};
80
81class MHFolder : public Folder
82{
83 Q_OBJECT
84public:
85 MHFolder(const QString&disp_name,const QString&mbox);
79}; 86};
80 87
81class IMAPFolder : public Folder 88class IMAPFolder : public Folder
82{ 89{
83 public: 90 public:
84 IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" ); 91 IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" );
85 virtual bool may_select()const{return m_MaySelect;} 92 virtual bool may_select()const{return m_MaySelect;}
86 virtual bool no_inferior()const{return m_NoInferior;} 93 virtual bool no_inferior()const{return m_NoInferior;}
87 private: 94 private:
88 static QString decodeFolderName( const QString &name ); 95 static QString decodeFolderName( const QString &name );
89 bool m_MaySelect,m_NoInferior; 96 bool m_MaySelect,m_NoInferior;
90}; 97};
91 98
92#endif 99#endif
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.h b/noncore/net/mail/libmailwrapper/mboxwrapper.h
index 194ff86..a579a3d 100644
--- a/noncore/net/mail/libmailwrapper/mboxwrapper.h
+++ b/noncore/net/mail/libmailwrapper/mboxwrapper.h
@@ -1,47 +1,48 @@
1#ifndef __MBOX_WRAPPER_H 1#ifndef __MBOX_WRAPPER_H
2#define __MBOX_WRAPPER_H 2#define __MBOX_WRAPPER_H
3 3
4#include "genericwrapper.h" 4#include "genericwrapper.h"
5#include <qstring.h> 5#include <qstring.h>
6 6
7class RecMail; 7class RecMail;
8class RecBody; 8class RecBody;
9class encodedString; 9class encodedString;
10struct mailmbox_folder; 10struct mailmbox_folder;
11 11
12class MBOXwrapper : public Genericwrapper 12class MBOXwrapper : public Genericwrapper
13{ 13{
14 Q_OBJECT 14 Q_OBJECT
15
15public: 16public:
16 MBOXwrapper(const QString & dir,const QString&name); 17 MBOXwrapper(const QString & dir,const QString&name);
17 virtual ~MBOXwrapper(); 18 virtual ~MBOXwrapper();
18 19
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 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 22 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
22 23
23 virtual void deleteMail(const RecMail&mail); 24 virtual void deleteMail(const RecMail&mail);
24 virtual void answeredMail(const RecMail&mail); 25 virtual void answeredMail(const RecMail&mail);
25 26
26 virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false); 27 virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false);
27 virtual int deleteMbox(const Folder*); 28 virtual int deleteMbox(const Folder*);
28 29
29 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 30 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
30 31
31 virtual RecBody fetchBody( const RecMail &mail ); 32 virtual RecBody fetchBody( const RecMail &mail );
32 static void mbox_progress( size_t current, size_t maximum ); 33 static void mbox_progress( size_t current, size_t maximum );
33 34
34 virtual encodedString* fetchRawBody(const RecMail&mail); 35 virtual encodedString* fetchRawBody(const RecMail&mail);
35 virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); 36 virtual void deleteMails(const QString & FolderName,QList<RecMail> &target);
36 virtual int deleteAllMail(const Folder*); 37 virtual int deleteAllMail(const Folder*);
37 virtual const QString&getType()const; 38 virtual const QString&getType()const;
38 virtual const QString&getName()const; 39 virtual const QString&getName()const;
39 40
40protected: 41protected:
41 static void deleteMails(mailmbox_folder*f,QList<RecMail> &target); 42 static void deleteMails(mailmbox_folder*f,QList<RecMail> &target);
42 QString MBOXPath; 43 QString MBOXPath;
43 QString MBOXName; 44 QString MBOXName;
44 static const QString wrapperType; 45 static const QString wrapperType;
45}; 46};
46 47
47#endif 48#endif
diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.cpp b/noncore/net/mail/libmailwrapper/mhwrapper.cpp
new file mode 100644
index 0000000..85f9cf0
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/mhwrapper.cpp
@@ -0,0 +1,330 @@
1#include "mhwrapper.h"
2#include "mailtypes.h"
3#include "mailwrapper.h"
4#include <libetpan/libetpan.h>
5#include <qdir.h>
6#include <stdlib.h>
7#include <qpe/global.h>
8
9const QString MHwrapper::wrapperType="MH";
10
11MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name)
12 : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name)
13{
14 if (MHPath.length()>0) {
15 if (MHPath[MHPath.length()-1]=='/') {
16 MHPath=MHPath.left(MHPath.length()-1);
17 }
18 qDebug(MHPath);
19 QDir dir(MHPath);
20 if (!dir.exists()) {
21 dir.mkdir(MHPath);
22 }
23 init_storage();
24 }
25}
26
27void MHwrapper::init_storage()
28{
29 int r;
30 QString pre = MHPath;
31 if (!m_storage) {
32 m_storage = mailstorage_new(NULL);
33 r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0);
34 if (r != MAIL_NO_ERROR) {
35 qDebug("error initializing storage");
36 mailstorage_free(m_storage);
37 m_storage = 0;
38 return;
39 }
40 }
41 r = mailstorage_connect(m_storage);
42 if (r!=MAIL_NO_ERROR) {
43 qDebug("error connecting storage");
44 mailstorage_free(m_storage);
45 m_storage = 0;
46 }
47}
48
49void MHwrapper::clean_storage()
50{
51 if (m_storage) {
52 mailstorage_disconnect(m_storage);
53 mailstorage_free(m_storage);
54 m_storage = 0;
55 }
56}
57
58MHwrapper::~MHwrapper()
59{
60 clean_storage();
61}
62
63void MHwrapper::listMessages(const QString & mailbox, QList<RecMail> &target )
64{
65 init_storage();
66 if (!m_storage) {
67 return;
68 }
69 QString f = buildPath(mailbox);
70 int r = mailsession_select_folder(m_storage->sto_session,(char*)mailbox.latin1());
71 if (r!=MAIL_NO_ERROR) {
72 qDebug("error selecting folder!");
73 return;
74 }
75 parseList(target,m_storage->sto_session,f);
76 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count()));
77}
78
79QList<Folder>* MHwrapper::listFolders()
80{
81 QList<Folder> * folders = new QList<Folder>();
82 folders->setAutoDelete( false );
83 init_storage();
84 if (!m_storage) {
85 return folders;
86 }
87 mail_list*flist = 0;
88 clistcell*current=0;
89 int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist);
90 if (r != MAIL_NO_ERROR || !flist) {
91 qDebug("error getting folder list");
92 return folders;
93 }
94 for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) {
95 QString t = (char*)current->data;
96 t.replace(0,MHPath.length(),"");
97 folders->append(new MHFolder(t,MHPath));
98 }
99 mail_list_free(flist);
100 return folders;
101}
102
103void MHwrapper::deleteMail(const RecMail&mail)
104{
105 init_storage();
106 if (!m_storage) {
107 return;
108 }
109 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1());
110 if (r!=MAIL_NO_ERROR) {
111 qDebug("error selecting folder!");
112 return;
113 }
114 r = mailsession_remove_message(m_storage->sto_session,mail.getNumber());
115 if (r != MAIL_NO_ERROR) {
116 qDebug("error deleting mail");
117 }
118}
119
120void MHwrapper::answeredMail(const RecMail&)
121{
122}
123
124RecBody MHwrapper::fetchBody( const RecMail &mail )
125{
126 RecBody body;
127 init_storage();
128 if (!m_storage) {
129 return body;
130 }
131 mailmessage * msg;
132 char*data=0;
133 size_t size;
134
135 /* mail should hold the complete path! */
136 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1());
137 if (r != MAIL_NO_ERROR) {
138 return body;
139 }
140 r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg);
141 if (r != MAIL_NO_ERROR) {
142 qDebug("Error fetching mail %i",mail.getNumber());
143 return body;
144 }
145 body = parseMail(msg);
146 mailmessage_fetch_result_free(msg,data);
147 return body;
148}
149
150void MHwrapper::mbox_progress( size_t current, size_t maximum )
151{
152 qDebug("MH %i von %i",current,maximum);
153}
154
155QString MHwrapper::buildPath(const QString&p)
156{
157 QString f="";
158 if (p.length()==0||p=="/")
159 return MHPath;
160 if (!p.startsWith(MHPath)) {
161 f+=MHPath;
162 }
163 if (!p.startsWith("/")) {
164 f+="/";
165 }
166 f+=p;
167 return f;
168}
169
170int MHwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool )
171{
172 init_storage();
173 if (!m_storage) {
174 return 0;
175 }
176 QString f = buildPath(folder);
177 int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1());
178 if (r != MAIL_NO_ERROR) {
179 qDebug("error creating folder");
180 return 0;
181 }
182 qDebug("Folder created");
183 mailstorage_disconnect(m_storage);
184 return 1;
185}
186
187void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder)
188{
189 init_storage();
190 if (!m_storage) {
191 return;
192 }
193 QString f = buildPath(Folder);
194 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
195 if (r!=MAIL_NO_ERROR) {
196 qDebug("error selecting folder!");
197 return;
198 }
199 r = mailsession_append_message(m_storage->sto_session,(char*)msg,length);
200 if (r!=MAIL_NO_ERROR) {
201 qDebug("error storing mail");
202 }
203 return;
204}
205
206encodedString* MHwrapper::fetchRawBody(const RecMail&mail)
207{
208 encodedString*result = 0;
209 init_storage();
210 if (!m_storage) {
211 return result;
212 }
213 mailmessage * msg = 0;
214 char*data=0;
215 size_t size;
216 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1());
217 if (r!=MAIL_NO_ERROR) {
218 qDebug("error selecting folder!");
219 return result;
220 }
221 r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg);
222 if (r != MAIL_NO_ERROR) {
223 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
224 return 0;
225 }
226 r = mailmessage_fetch(msg,&data,&size);
227 if (r != MAIL_NO_ERROR) {
228 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
229 if (msg) mailmessage_free(msg);
230 return 0;
231 }
232 result = new encodedString(data,size);
233 if (msg) mailmessage_free(msg);
234 return result;
235}
236
237void MHwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target)
238{
239#if 0
240 QString p = MHPath+"/";
241 p+=mailbox;
242 mailmbox_folder*f = 0;
243 int r = mailmbox_init(p.latin1(),0,1,0,&f);
244 if (r != MAIL_NO_ERROR) {
245 qDebug("Error init folder");
246 return;
247 }
248 deleteMails(f,target);
249 mailmbox_done(f);
250#endif
251}
252
253int MHwrapper::deleteAllMail(const Folder*tfolder)
254{
255 init_storage();
256 if (!m_storage) {
257 return 0;
258 }
259 int res = 1;
260 if (!tfolder) return 0;
261 int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1());
262 if (r!=MAIL_NO_ERROR) {
263 qDebug("error selecting folder!");
264 return 0;
265 }
266 mailmessage_list*l=0;
267 r = mailsession_get_messages_list(m_storage->sto_session,&l);
268 if (r != MAIL_NO_ERROR) {
269 qDebug("Error message list");
270 res = 0;
271 }
272 unsigned j = 0;
273 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
274 mailmessage * msg;
275 msg = (mailmessage*)carray_get(l->msg_tab, i);
276 j = msg->msg_index;
277 r = mailsession_remove_message(m_storage->sto_session,j);
278 if (r != MAIL_NO_ERROR) {
279 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
280 res = 0;
281 break;
282 }
283 }
284 if (l) mailmessage_list_free(l);
285 return res;
286}
287
288int MHwrapper::deleteMbox(const Folder*tfolder)
289{
290 init_storage();
291 if (!m_storage) {
292 return 0;
293 }
294 if (!tfolder) return 0;
295 int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1());
296 if (r != MAIL_NO_ERROR) {
297 qDebug("error deleting mail box");
298 return 0;
299 }
300 qDebug("mail box deleted");
301 mailstorage_disconnect(m_storage);
302 return 1;
303}
304
305void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
306{
307 init_storage();
308 if (!m_storage) {
309 return;
310 }
311 target_stat.message_count = 0;
312 target_stat.message_unseen = 0;
313 target_stat.message_recent = 0;
314 QString f = buildPath(mailbox);
315 int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count,
316 &target_stat.message_recent,&target_stat.message_unseen);
317 if (r != MAIL_NO_ERROR) {
318 Global::statusMessage(tr("Error retrieving status"));
319 }
320}
321
322const QString&MHwrapper::getType()const
323{
324 return wrapperType;
325}
326
327const QString&MHwrapper::getName()const
328{
329 return MHName;
330}
diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.h b/noncore/net/mail/libmailwrapper/mhwrapper.h
new file mode 100644
index 0000000..7f028b4
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/mhwrapper.h
@@ -0,0 +1,50 @@
1#ifndef __MH_WRAPPER_H
2#define __MH_WRAPPER_H
3
4#include "genericwrapper.h"
5#include <qstring.h>
6
7class RecMail;
8class RecBody;
9class encodedString;
10struct mailmbox_folder;
11
12class MHwrapper : public Genericwrapper
13{
14 Q_OBJECT
15public:
16 MHwrapper(const QString & dir,const QString&name);
17 virtual ~MHwrapper();
18
19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
20 virtual QList<Folder>* listFolders();
21 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
22
23 virtual void deleteMail(const RecMail&mail);
24 virtual void answeredMail(const RecMail&mail);
25
26 virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false);
27 virtual int deleteMbox(const Folder*);
28
29 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
30
31 virtual RecBody fetchBody( const RecMail &mail );
32 static void mbox_progress( size_t current, size_t maximum );
33
34 virtual encodedString* fetchRawBody(const RecMail&mail);
35 virtual void deleteMails(const QString & FolderName,QList<RecMail> &target);
36 virtual int deleteAllMail(const Folder*);
37 virtual const QString&getType()const;
38 virtual const QString&getName()const;
39
40protected:
41 QString buildPath(const QString&p);
42 QString MHPath;
43 QString MHName;
44 static const QString wrapperType;
45
46 void init_storage();
47 void clean_storage();
48};
49
50#endif
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
index 281b88e..08f6bb7 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
@@ -1,727 +1,728 @@
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 "abstractmail.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(const 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 AbstractMail*wrap = AbstractMail::getWrapper(localfolders); 492 AbstractMail*wrap = AbstractMail::getWrapper(localfolders);
493 wrap->createMbox(box);
493 wrap->storeMessage(mail,length,box); 494 wrap->storeMessage(mail,length,box);
494 delete wrap; 495 delete wrap;
495} 496}
496 497
497void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) 498void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
498{ 499{
499 clist *rcpts = 0; 500 clist *rcpts = 0;
500 char *from, *data; 501 char *from, *data;
501 size_t size; 502 size_t size;
502 503
503 if ( smtp == NULL ) { 504 if ( smtp == NULL ) {
504 return; 505 return;
505 } 506 }
506 from = data = 0; 507 from = data = 0;
507 508
508 mailmessage * msg = 0; 509 mailmessage * msg = 0;
509 msg = mime_message_init(mail); 510 msg = mime_message_init(mail);
510 mime_message_set_tmpdir(msg,getenv( "HOME" )); 511 mime_message_set_tmpdir(msg,getenv( "HOME" ));
511 int r = mailmessage_fetch(msg,&data,&size); 512 int r = mailmessage_fetch(msg,&data,&size);
512 mime_message_detach_mime(msg); 513 mime_message_detach_mime(msg);
513 mailmessage_free(msg); 514 mailmessage_free(msg);
514 if (r != MAIL_NO_ERROR || !data) { 515 if (r != MAIL_NO_ERROR || !data) {
515 if (data) free(data); 516 if (data) free(data);
516 qDebug("Error fetching mime..."); 517 qDebug("Error fetching mime...");
517 return; 518 return;
518 } 519 }
519 msg = 0; 520 msg = 0;
520 if (later) { 521 if (later) {
521 storeMail(data,size,"Outgoing"); 522 storeMail(data,size,"Outgoing");
522 if (data) free( data ); 523 if (data) free( data );
523 Config cfg( "mail" ); 524 Config cfg( "mail" );
524 cfg.setGroup( "Status" ); 525 cfg.setGroup( "Status" );
525 cfg.writeEntry( "outgoing", ++m_queuedMail ); 526 cfg.writeEntry( "outgoing", ++m_queuedMail );
526 emit queuedMails( m_queuedMail ); 527 emit queuedMails( m_queuedMail );
527 return; 528 return;
528 } 529 }
529 from = getFrom( mail ); 530 from = getFrom( mail );
530 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 531 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
531 smtpSend(from,rcpts,data,size,smtp); 532 smtpSend(from,rcpts,data,size,smtp);
532 if (data) {free(data);} 533 if (data) {free(data);}
533 if (from) {free(from);} 534 if (from) {free(from);}
534 if (rcpts) smtp_address_list_free( rcpts ); 535 if (rcpts) smtp_address_list_free( rcpts );
535} 536}
536 537
537int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ) 538int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp )
538{ 539{
539 const char *server, *user, *pass; 540 const char *server, *user, *pass;
540 bool ssl; 541 bool ssl;
541 uint16_t port; 542 uint16_t port;
542 mailsmtp *session; 543 mailsmtp *session;
543 int err,result; 544 int err,result;
544 545
545 result = 1; 546 result = 1;
546 server = user = pass = 0; 547 server = user = pass = 0;
547 server = smtp->getServer().latin1(); 548 server = smtp->getServer().latin1();
548 ssl = smtp->getSSL(); 549 ssl = smtp->getSSL();
549 port = smtp->getPort().toUInt(); 550 port = smtp->getPort().toUInt();
550 551
551 session = mailsmtp_new( 20, &progress ); 552 session = mailsmtp_new( 20, &progress );
552 if ( session == NULL ) goto free_mem; 553 if ( session == NULL ) goto free_mem;
553 554
554 qDebug( "Servername %s at port %i", server, port ); 555 qDebug( "Servername %s at port %i", server, port );
555 if ( ssl ) { 556 if ( ssl ) {
556 qDebug( "SSL session" ); 557 qDebug( "SSL session" );
557 err = mailsmtp_ssl_connect( session, server, port ); 558 err = mailsmtp_ssl_connect( session, server, port );
558 } else { 559 } else {
559 qDebug( "No SSL session" ); 560 qDebug( "No SSL session" );
560 err = mailsmtp_socket_connect( session, server, port ); 561 err = mailsmtp_socket_connect( session, server, port );
561 } 562 }
562 if ( err != MAILSMTP_NO_ERROR ) {qDebug("Error init connection");result = 0;goto free_mem_session;} 563 if ( err != MAILSMTP_NO_ERROR ) {qDebug("Error init connection");result = 0;goto free_mem_session;}
563 564
564 err = mailsmtp_init( session ); 565 err = mailsmtp_init( session );
565 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} 566 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;}
566 567
567 qDebug( "INIT OK" ); 568 qDebug( "INIT OK" );
568 569
569 if ( smtp->getLogin() ) { 570 if ( smtp->getLogin() ) {
570 qDebug("smtp with auth"); 571 qDebug("smtp with auth");
571 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { 572 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
572 // get'em 573 // get'em
573 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); 574 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true );
574 login.show(); 575 login.show();
575 if ( QDialog::Accepted == login.exec() ) { 576 if ( QDialog::Accepted == login.exec() ) {
576 // ok 577 // ok
577 user = login.getUser().latin1(); 578 user = login.getUser().latin1();
578 pass = login.getPassword().latin1(); 579 pass = login.getPassword().latin1();
579 } else { 580 } else {
580 result = 0; goto free_con_session; 581 result = 0; goto free_con_session;
581 } 582 }
582 } else { 583 } else {
583 user = smtp->getUser().latin1(); 584 user = smtp->getUser().latin1();
584 pass = smtp->getPassword().latin1(); 585 pass = smtp->getPassword().latin1();
585 } 586 }
586 qDebug( "session->auth: %i", session->auth); 587 qDebug( "session->auth: %i", session->auth);
587 err = mailsmtp_auth( session, (char*)user, (char*)pass ); 588 err = mailsmtp_auth( session, (char*)user, (char*)pass );
588 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); 589 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
589 qDebug( "Done auth!" ); 590 qDebug( "Done auth!" );
590 } else { 591 } else {
591 qDebug("SMTP without auth"); 592 qDebug("SMTP without auth");
592 } 593 }
593 594
594 err = mailsmtp_send( session, from, rcpts, data, size ); 595 err = mailsmtp_send( session, from, rcpts, data, size );
595 if ( err != MAILSMTP_NO_ERROR ) { 596 if ( err != MAILSMTP_NO_ERROR ) {
596 qDebug("Error sending mail: %s",mailsmtpError(err).latin1()); 597 qDebug("Error sending mail: %s",mailsmtpError(err).latin1());
597 result = 0; goto free_con_session; 598 result = 0; goto free_con_session;
598 } 599 }
599 600
600 qDebug( "Mail sent." ); 601 qDebug( "Mail sent." );
601 storeMail(data,size,"Sent"); 602 storeMail(data,size,"Sent");
602 603
603free_con_session: 604free_con_session:
604 mailsmtp_quit( session ); 605 mailsmtp_quit( session );
605free_mem_session: 606free_mem_session:
606 mailsmtp_free( session ); 607 mailsmtp_free( session );
607free_mem: 608free_mem:
608 return result; 609 return result;
609} 610}
610 611
611void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) 612void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later )
612{ 613{
613 mailmime * mimeMail; 614 mailmime * mimeMail;
614 615
615 SMTPaccount *smtp = aSmtp; 616 SMTPaccount *smtp = aSmtp;
616 617
617 if (!later && !smtp) { 618 if (!later && !smtp) {
618 qDebug("Didn't get any send method - giving up"); 619 qDebug("Didn't get any send method - giving up");
619 return; 620 return;
620 } 621 }
621 mimeMail = createMimeMail(mail ); 622 mimeMail = createMimeMail(mail );
622 if ( mimeMail == NULL ) { 623 if ( mimeMail == NULL ) {
623 qDebug( "sendMail: error creating mime mail" ); 624 qDebug( "sendMail: error creating mime mail" );
624 } else { 625 } else {
625 sendProgress = new progressMailSend(); 626 sendProgress = new progressMailSend();
626 sendProgress->show(); 627 sendProgress->show();
627 sendProgress->setMaxMails(1); 628 sendProgress->setMaxMails(1);
628 smtpSend( mimeMail,later,smtp); 629 smtpSend( mimeMail,later,smtp);
629 qDebug("Clean up done"); 630 qDebug("Clean up done");
630 sendProgress->hide(); 631 sendProgress->hide();
631 delete sendProgress; 632 delete sendProgress;
632 sendProgress = 0; 633 sendProgress = 0;
633 mailmime_free( mimeMail ); 634 mailmime_free( mimeMail );
634 } 635 }
635} 636}
636 637
637int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which) 638int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which)
638{ 639{
639 size_t curTok = 0; 640 size_t curTok = 0;
640 mailimf_fields *fields = 0; 641 mailimf_fields *fields = 0;
641 mailimf_field*ffrom = 0; 642 mailimf_field*ffrom = 0;
642 clist *rcpts = 0; 643 clist *rcpts = 0;
643 char*from = 0; 644 char*from = 0;
644 int res = 0; 645 int res = 0;
645 646
646 encodedString * data = wrap->fetchRawBody(*which); 647 encodedString * data = wrap->fetchRawBody(*which);
647 if (!data) return 0; 648 if (!data) return 0;
648 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); 649 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields );
649 if (err != MAILIMF_NO_ERROR) { 650 if (err != MAILIMF_NO_ERROR) {
650 delete data; 651 delete data;
651 delete wrap; 652 delete wrap;
652 return 0; 653 return 0;
653 } 654 }
654 655
655 rcpts = createRcptList( fields ); 656 rcpts = createRcptList( fields );
656 ffrom = getField(fields, MAILIMF_FIELD_FROM ); 657 ffrom = getField(fields, MAILIMF_FIELD_FROM );
657 from = getFrom(ffrom); 658 from = getFrom(ffrom);
658 659
659 if (rcpts && from) { 660 if (rcpts && from) {
660 res = smtpSend(from,rcpts,data->Content(),data->Length(),smtp ); 661 res = smtpSend(from,rcpts,data->Content(),data->Length(),smtp );
661 } 662 }
662 if (fields) { 663 if (fields) {
663 mailimf_fields_free(fields); 664 mailimf_fields_free(fields);
664 fields = 0; 665 fields = 0;
665 } 666 }
666 if (data) { 667 if (data) {
667 delete data; 668 delete data;
668 } 669 }
669 if (from) { 670 if (from) {
670 free(from); 671 free(from);
671 } 672 }
672 if (rcpts) { 673 if (rcpts) {
673 smtp_address_list_free( rcpts ); 674 smtp_address_list_free( rcpts );
674 } 675 }
675 return res; 676 return res;
676} 677}
677 678
678/* this is a special fun */ 679/* this is a special fun */
679bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) 680bool SMTPwrapper::flushOutbox(SMTPaccount*smtp)
680{ 681{
681 bool returnValue = true; 682 bool returnValue = true;
682 683
683 if (!smtp) return false; 684 if (!smtp) return false;
684 685
685 QString localfolders = AbstractMail::defaultLocalfolder(); 686 QString localfolders = AbstractMail::defaultLocalfolder();
686 AbstractMail*wrap = AbstractMail::getWrapper(localfolders); 687 AbstractMail*wrap = AbstractMail::getWrapper(localfolders);
687 if (!wrap) { 688 if (!wrap) {
688 qDebug("memory error"); 689 qDebug("memory error");
689 return false; 690 return false;
690 } 691 }
691 QList<RecMail> mailsToSend; 692 QList<RecMail> mailsToSend;
692 QList<RecMail> mailsToRemove; 693 QList<RecMail> mailsToRemove;
693 QString mbox("Outgoing"); 694 QString mbox("Outgoing");
694 wrap->listMessages(mbox,mailsToSend); 695 wrap->listMessages(mbox,mailsToSend);
695 if (mailsToSend.count()==0) { 696 if (mailsToSend.count()==0) {
696 delete wrap; 697 delete wrap;
697 return false; 698 return false;
698 } 699 }
699 mailsToSend.setAutoDelete(false); 700 mailsToSend.setAutoDelete(false);
700 sendProgress = new progressMailSend(); 701 sendProgress = new progressMailSend();
701 sendProgress->show(); 702 sendProgress->show();
702 sendProgress->setMaxMails(mailsToSend.count()); 703 sendProgress->setMaxMails(mailsToSend.count());
703 704
704 while (mailsToSend.count()>0) { 705 while (mailsToSend.count()>0) {
705 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { 706 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) {
706 QMessageBox::critical(0,tr("Error sending mail"), 707 QMessageBox::critical(0,tr("Error sending mail"),
707 tr("Error sending queued mail - breaking")); 708 tr("Error sending queued mail - breaking"));
708 returnValue = false; 709 returnValue = false;
709 break; 710 break;
710 } 711 }
711 mailsToRemove.append(mailsToSend.at(0)); 712 mailsToRemove.append(mailsToSend.at(0));
712 mailsToSend.removeFirst(); 713 mailsToSend.removeFirst();
713 sendProgress->setCurrentMails(mailsToRemove.count()); 714 sendProgress->setCurrentMails(mailsToRemove.count());
714 } 715 }
715 Config cfg( "mail" ); 716 Config cfg( "mail" );
716 cfg.setGroup( "Status" ); 717 cfg.setGroup( "Status" );
717 m_queuedMail = 0; 718 m_queuedMail = 0;
718 cfg.writeEntry( "outgoing", m_queuedMail ); 719 cfg.writeEntry( "outgoing", m_queuedMail );
719 emit queuedMails( m_queuedMail ); 720 emit queuedMails( m_queuedMail );
720 sendProgress->hide(); 721 sendProgress->hide();
721 delete sendProgress; 722 delete sendProgress;
722 sendProgress = 0; 723 sendProgress = 0;
723 wrap->deleteMails(mbox,mailsToRemove); 724 wrap->deleteMails(mbox,mailsToRemove);
724 mailsToSend.setAutoDelete(true); 725 mailsToSend.setAutoDelete(true);
725 delete wrap; 726 delete wrap;
726 return returnValue; 727 return returnValue;
727} 728}