summaryrefslogtreecommitdiff
authoralwin <alwin>2004-03-12 19:24:38 (UTC)
committer alwin <alwin>2004-03-12 19:24:38 (UTC)
commitb600871ce93553a116a66fd80acd6dfc1cc46829 (patch) (unidiff)
treeb361346a49e09d9f0220993583bf183cf29bd974
parent874d5a34eca296263dcd1adf857aebe9981825a1 (diff)
downloadopie-b600871ce93553a116a66fd80acd6dfc1cc46829.zip
opie-b600871ce93553a116a66fd80acd6dfc1cc46829.tar.gz
opie-b600871ce93553a116a66fd80acd6dfc1cc46829.tar.bz2
some more smart-pointers
some bugfixes some renaming of internals
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/accountitem.cpp34
-rw-r--r--noncore/net/mail/accountitem.h58
-rw-r--r--noncore/net/mail/accountview.cpp12
-rw-r--r--noncore/net/mail/accountview.h11
-rw-r--r--noncore/net/mail/composemail.cpp24
-rw-r--r--noncore/net/mail/composemail.h4
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.cpp16
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.h36
-rw-r--r--noncore/net/mail/libmailwrapper/generatemail.cpp4
-rw-r--r--noncore/net/mail/libmailwrapper/generatemail.h6
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.cpp10
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.h10
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp49
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h34
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.cpp4
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.h15
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.cpp2
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.h8
-rw-r--r--noncore/net/mail/libmailwrapper/mboxwrapper.cpp43
-rw-r--r--noncore/net/mail/libmailwrapper/mboxwrapper.h24
-rw-r--r--noncore/net/mail/libmailwrapper/mhwrapper.cpp50
-rw-r--r--noncore/net/mail/libmailwrapper/mhwrapper.h26
-rw-r--r--noncore/net/mail/libmailwrapper/nntpwrapper.cpp26
-rw-r--r--noncore/net/mail/libmailwrapper/nntpwrapper.h14
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp32
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h14
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp18
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.h6
-rw-r--r--noncore/net/mail/libmailwrapper/storemail.cpp2
-rw-r--r--noncore/net/mail/libmailwrapper/storemail.h2
-rw-r--r--noncore/net/mail/mailistviewitem.cpp20
-rw-r--r--noncore/net/mail/mailistviewitem.h6
-rw-r--r--noncore/net/mail/mainwindow.cpp7
-rw-r--r--noncore/net/mail/mainwindow.h11
-rw-r--r--noncore/net/mail/opiemail.cpp24
-rw-r--r--noncore/net/mail/opiemail.h4
-rw-r--r--noncore/net/mail/viewmail.cpp36
-rw-r--r--noncore/net/mail/viewmail.h34
38 files changed, 369 insertions, 367 deletions
diff --git a/noncore/net/mail/accountitem.cpp b/noncore/net/mail/accountitem.cpp
index 3e12563..9a09c18 100644
--- a/noncore/net/mail/accountitem.cpp
+++ b/noncore/net/mail/accountitem.cpp
@@ -1,1133 +1,1133 @@
1 1
2#include "accountitem.h" 2#include "accountitem.h"
3#include "accountview.h" 3#include "accountview.h"
4#include "newmaildir.h" 4#include "newmaildir.h"
5#include "nntpgroupsdlg.h" 5#include "nntpgroupsdlg.h"
6#include "defines.h" 6#include "defines.h"
7 7
8/* OPIE */ 8/* OPIE */
9#include <libmailwrapper/mailtypes.h> 9#include <libmailwrapper/mailtypes.h>
10#include <libmailwrapper/abstractmail.h> 10#include <libmailwrapper/abstractmail.h>
11#include <libmailwrapper/mailwrapper.h> 11#include <libmailwrapper/mailwrapper.h>
12#include <qpe/qpeapplication.h> 12#include <qpe/qpeapplication.h>
13 13
14/* QT */ 14/* QT */
15#include <qpopupmenu.h> 15#include <qpopupmenu.h>
16#include <qmessagebox.h> 16#include <qmessagebox.h>
17 17
18#define SETPIX(x) if (!account->getOffline()) {setPixmap( 0,x);} else {setPixmap( 0, PIXMAP_OFFLINE );} 18#define SETPIX(x) if (!account->getOffline()) {setPixmap( 0,x);} else {setPixmap( 0, PIXMAP_OFFLINE );}
19/** 19/**
20 * POP3 Account stuff 20 * POP3 Account stuff
21 */ 21 */
22POP3viewItem::POP3viewItem( POP3account *a, AccountView *parent ) 22POP3viewItem::POP3viewItem( POP3account *a, AccountView *parent )
23 : AccountViewItem( parent ) 23 : AccountViewItem( parent )
24{ 24{
25 account = a; 25 account = a;
26 wrapper = AbstractMail::getWrapper( account ); 26 wrapper = AbstractMail::getWrapper( account );
27 SETPIX(PIXMAP_POP3FOLDER); 27 SETPIX(PIXMAP_POP3FOLDER);
28#if 0 28#if 0
29 if (!account->getOffline()) 29 if (!account->getOffline())
30 { 30 {
31 setPixmap( 0, ); 31 setPixmap( 0, );
32 } 32 }
33 else 33 else
34 { 34 {
35 setPixmap( 0, PIXMAP_OFFLINE ); 35 setPixmap( 0, PIXMAP_OFFLINE );
36 } 36 }
37#endif 37#endif
38 setText( 0, account->getAccountName() ); 38 setText( 0, account->getAccountName() );
39 setOpen( true ); 39 setOpen( true );
40} 40}
41 41
42POP3viewItem::~POP3viewItem() 42POP3viewItem::~POP3viewItem()
43{ 43{
44 delete wrapper; 44 delete wrapper;
45} 45}
46 46
47AbstractMail *POP3viewItem::getWrapper() 47AbstractMail *POP3viewItem::getWrapper()
48{ 48{
49 return wrapper; 49 return wrapper;
50} 50}
51 51
52void POP3viewItem::refresh( QList<RecMail> & ) 52void POP3viewItem::refresh(QValueList<Opie::OSmartPointer<RecMail> > & )
53{ 53{
54 refresh(); 54 refresh();
55} 55}
56 56
57void POP3viewItem::refresh() 57void POP3viewItem::refresh()
58{ 58{
59 if (account->getOffline()) return; 59 if (account->getOffline()) return;
60 QValueList<FolderP> *folders = wrapper->listFolders(); 60 QValueList<FolderP> *folders = wrapper->listFolders();
61 QListViewItem *child = firstChild(); 61 QListViewItem *child = firstChild();
62 while ( child ) 62 while ( child )
63 { 63 {
64 QListViewItem *tmp = child; 64 QListViewItem *tmp = child;
65 child = child->nextSibling(); 65 child = child->nextSibling();
66 delete tmp; 66 delete tmp;
67 } 67 }
68 QValueList<FolderP>::ConstIterator it; 68 QValueList<FolderP>::ConstIterator it;
69 QListViewItem*item = 0; 69 QListViewItem*item = 0;
70 for ( it = folders->begin(); it!=folders->end(); ++it) 70 for ( it = folders->begin(); it!=folders->end(); ++it)
71 { 71 {
72 item = new POP3folderItem( (*it), this , item ); 72 item = new POP3folderItem( (*it), this , item );
73 item->setSelectable( (*it)->may_select()); 73 item->setSelectable( (*it)->may_select());
74 } 74 }
75 delete folders; 75 delete folders;
76} 76}
77 77
78RecBody POP3viewItem::fetchBody( const RecMail &mail ) 78RecBody POP3viewItem::fetchBody( const RecMailP &mail )
79{ 79{
80 qDebug( "POP3 fetchBody" ); 80 qDebug( "POP3 fetchBody" );
81 return wrapper->fetchBody( mail ); 81 return wrapper->fetchBody( mail );
82} 82}
83 83
84QPopupMenu * POP3viewItem::getContextMenu() 84QPopupMenu * POP3viewItem::getContextMenu()
85{ 85{
86 QPopupMenu *m = new QPopupMenu(0); 86 QPopupMenu *m = new QPopupMenu(0);
87 if (m) 87 if (m)
88 { 88 {
89 if (!account->getOffline()) 89 if (!account->getOffline())
90 { 90 {
91 m->insertItem(QObject::tr("Disconnect",contextName),0); 91 m->insertItem(QObject::tr("Disconnect",contextName),0);
92 m->insertItem(QObject::tr("Set offline",contextName),1); 92 m->insertItem(QObject::tr("Set offline",contextName),1);
93 } 93 }
94 else 94 else
95 { 95 {
96 m->insertItem(QObject::tr("Set online",contextName),1); 96 m->insertItem(QObject::tr("Set online",contextName),1);
97 } 97 }
98 } 98 }
99 return m; 99 return m;
100} 100}
101 101
102void POP3viewItem::disconnect() 102void POP3viewItem::disconnect()
103{ 103{
104 QListViewItem *child = firstChild(); 104 QListViewItem *child = firstChild();
105 while ( child ) 105 while ( child )
106 { 106 {
107 QListViewItem *tmp = child; 107 QListViewItem *tmp = child;
108 child = child->nextSibling(); 108 child = child->nextSibling();
109 delete tmp; 109 delete tmp;
110 } 110 }
111 wrapper->logout(); 111 wrapper->logout();
112} 112}
113 113
114void POP3viewItem::setOnOffline() 114void POP3viewItem::setOnOffline()
115{ 115{
116 if (!account->getOffline()) 116 if (!account->getOffline())
117 { 117 {
118 disconnect(); 118 disconnect();
119 } 119 }
120 account->setOffline(!account->getOffline()); 120 account->setOffline(!account->getOffline());
121 account->save(); 121 account->save();
122 SETPIX(PIXMAP_POP3FOLDER); 122 SETPIX(PIXMAP_POP3FOLDER);
123 refresh(); 123 refresh();
124} 124}
125 125
126void POP3viewItem::contextMenuSelected(int which) 126void POP3viewItem::contextMenuSelected(int which)
127{ 127{
128 switch (which) 128 switch (which)
129 { 129 {
130 case 0: 130 case 0:
131 disconnect(); 131 disconnect();
132 break; 132 break;
133 case 1: 133 case 1:
134 setOnOffline(); 134 setOnOffline();
135 break; 135 break;
136 } 136 }
137} 137}
138 138
139POP3folderItem::~POP3folderItem() 139POP3folderItem::~POP3folderItem()
140{} 140{}
141 141
142POP3folderItem::POP3folderItem( const FolderP&folderInit, POP3viewItem *parent , QListViewItem*after ) 142POP3folderItem::POP3folderItem( const FolderP&folderInit, POP3viewItem *parent , QListViewItem*after )
143 : AccountViewItem(folderInit,parent,after ) 143 : AccountViewItem(folderInit,parent,after )
144{ 144{
145 pop3 = parent; 145 pop3 = parent;
146 if (folder->getDisplayName().lower()!="inbox") 146 if (folder->getDisplayName().lower()!="inbox")
147 { 147 {
148 setPixmap( 0, PIXMAP_POP3FOLDER ); 148 setPixmap( 0, PIXMAP_POP3FOLDER );
149 } 149 }
150 else 150 else
151 { 151 {
152 setPixmap( 0, PIXMAP_INBOXFOLDER); 152 setPixmap( 0, PIXMAP_INBOXFOLDER);
153 } 153 }
154 setText( 0, folder->getDisplayName() ); 154 setText( 0, folder->getDisplayName() );
155} 155}
156 156
157void POP3folderItem::refresh(QList<RecMail>&target) 157void POP3folderItem::refresh(QValueList<RecMailP>&target)
158{ 158{
159 if (folder->may_select()) 159 if (folder->may_select())
160 pop3->getWrapper()->listMessages( folder->getName(),target ); 160 pop3->getWrapper()->listMessages( folder->getName(),target );
161} 161}
162 162
163RecBody POP3folderItem::fetchBody(const RecMail&aMail) 163RecBody POP3folderItem::fetchBody(const RecMailP&aMail)
164{ 164{
165 return pop3->getWrapper()->fetchBody(aMail); 165 return pop3->getWrapper()->fetchBody(aMail);
166} 166}
167 167
168QPopupMenu * POP3folderItem::getContextMenu() 168QPopupMenu * POP3folderItem::getContextMenu()
169{ 169{
170 QPopupMenu *m = new QPopupMenu(0); 170 QPopupMenu *m = new QPopupMenu(0);
171 if (m) 171 if (m)
172 { 172 {
173 m->insertItem(QObject::tr("Refresh header list",contextName),0); 173 m->insertItem(QObject::tr("Refresh header list",contextName),0);
174 m->insertItem(QObject::tr("Delete all mails",contextName),1); 174 m->insertItem(QObject::tr("Delete all mails",contextName),1);
175 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); 175 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2);
176 } 176 }
177 return m; 177 return m;
178} 178}
179 179
180void POP3folderItem::downloadMails() 180void POP3folderItem::downloadMails()
181{ 181{
182 AccountView*bl = pop3->accountView(); 182 AccountView*bl = pop3->accountView();
183 if (!bl) return; 183 if (!bl) return;
184 bl->downloadMails(folder,pop3->getWrapper()); 184 bl->downloadMails(folder,pop3->getWrapper());
185} 185}
186 186
187void POP3folderItem::contextMenuSelected(int which) 187void POP3folderItem::contextMenuSelected(int which)
188{ 188{
189 AccountView * view = (AccountView*)listView(); 189 AccountView * view = (AccountView*)listView();
190 switch (which) 190 switch (which)
191 { 191 {
192 case 0: 192 case 0:
193 /* must be 'cause pop3 lists are cached */ 193 /* must be 'cause pop3 lists are cached */
194 pop3->getWrapper()->logout(); 194 pop3->getWrapper()->logout();
195 view->refreshCurrent(); 195 view->refreshCurrent();
196 break; 196 break;
197 case 1: 197 case 1:
198 deleteAllMail(pop3->getWrapper(),folder); 198 deleteAllMail(pop3->getWrapper(),folder);
199 break; 199 break;
200 case 2: 200 case 2:
201 downloadMails(); 201 downloadMails();
202 break; 202 break;
203 default: 203 default:
204 break; 204 break;
205 } 205 }
206} 206}
207 207
208/** 208/**
209 * NNTP Account stuff 209 * NNTP Account stuff
210 */ 210 */
211NNTPviewItem::NNTPviewItem( NNTPaccount *a, AccountView *parent ) 211NNTPviewItem::NNTPviewItem( NNTPaccount *a, AccountView *parent )
212 : AccountViewItem( parent ) 212 : AccountViewItem( parent )
213{ 213{
214 account = a; 214 account = a;
215 wrapper = AbstractMail::getWrapper( account ); 215 wrapper = AbstractMail::getWrapper( account );
216 //FIXME 216 //FIXME
217 SETPIX(PIXMAP_POP3FOLDER); 217 SETPIX(PIXMAP_POP3FOLDER);
218#if 0 218#if 0
219 if (!account->getOffline()) 219 if (!account->getOffline())
220 { 220 {
221 setPixmap( 0, ); 221 setPixmap( 0, );
222 } 222 }
223 else 223 else
224 { 224 {
225 setPixmap( 0, PIXMAP_OFFLINE ); 225 setPixmap( 0, PIXMAP_OFFLINE );
226 } 226 }
227#endif 227#endif
228 setText( 0, account->getAccountName() ); 228 setText( 0, account->getAccountName() );
229 setOpen( true ); 229 setOpen( true );
230} 230}
231 231
232NNTPviewItem::~NNTPviewItem() 232NNTPviewItem::~NNTPviewItem()
233{ 233{
234 delete wrapper; 234 delete wrapper;
235} 235}
236 236
237AbstractMail *NNTPviewItem::getWrapper() 237AbstractMail *NNTPviewItem::getWrapper()
238{ 238{
239 return wrapper; 239 return wrapper;
240} 240}
241 241
242void NNTPviewItem::refresh( QList<RecMail> & ) 242void NNTPviewItem::refresh( QValueList<RecMailP> & )
243{ 243{
244 refresh(); 244 refresh();
245} 245}
246 246
247void NNTPviewItem::refresh() 247void NNTPviewItem::refresh()
248{ 248{
249 if (account->getOffline()) return; 249 if (account->getOffline()) return;
250 QValueList<FolderP> *folders = wrapper->listFolders(); 250 QValueList<FolderP> *folders = wrapper->listFolders();
251 251
252 QListViewItem *child = firstChild(); 252 QListViewItem *child = firstChild();
253 while ( child ) 253 while ( child )
254 { 254 {
255 QListViewItem *tmp = child; 255 QListViewItem *tmp = child;
256 child = child->nextSibling(); 256 child = child->nextSibling();
257 delete tmp; 257 delete tmp;
258 } 258 }
259 QValueList<FolderP>::ConstIterator it; 259 QValueList<FolderP>::ConstIterator it;
260 QListViewItem*item = 0; 260 QListViewItem*item = 0;
261 for ( it = folders->begin(); it!=folders->end(); ++it) 261 for ( it = folders->begin(); it!=folders->end(); ++it)
262 { 262 {
263 item = new NNTPfolderItem( (*it), this , item ); 263 item = new NNTPfolderItem( (*it), this , item );
264 item->setSelectable( (*it)->may_select()); 264 item->setSelectable( (*it)->may_select());
265 } 265 }
266 delete folders; 266 delete folders;
267} 267}
268 268
269RecBody NNTPviewItem::fetchBody( const RecMail &mail ) 269RecBody NNTPviewItem::fetchBody( const RecMailP &mail )
270{ 270{
271 qDebug( "NNTP fetchBody" ); 271 qDebug( "NNTP fetchBody" );
272 return wrapper->fetchBody( mail ); 272 return wrapper->fetchBody( mail );
273} 273}
274 274
275QPopupMenu * NNTPviewItem::getContextMenu() 275QPopupMenu * NNTPviewItem::getContextMenu()
276{ 276{
277 QPopupMenu *m = new QPopupMenu(0); 277 QPopupMenu *m = new QPopupMenu(0);
278 if (m) 278 if (m)
279 { 279 {
280 if (!account->getOffline()) 280 if (!account->getOffline())
281 { 281 {
282 m->insertItem(QObject::tr("Disconnect",contextName),0); 282 m->insertItem(QObject::tr("Disconnect",contextName),0);
283 m->insertItem(QObject::tr("Set offline",contextName),1); 283 m->insertItem(QObject::tr("Set offline",contextName),1);
284 m->insertItem(QObject::tr("(Un-)Subscribe groups",contextName),2); 284 m->insertItem(QObject::tr("(Un-)Subscribe groups",contextName),2);
285 } 285 }
286 else 286 else
287 { 287 {
288 m->insertItem(QObject::tr("Set online",contextName),1); 288 m->insertItem(QObject::tr("Set online",contextName),1);
289 } 289 }
290 } 290 }
291 return m; 291 return m;
292} 292}
293 293
294void NNTPviewItem::subscribeGroups() 294void NNTPviewItem::subscribeGroups()
295{ 295{
296 NNTPGroupsDlg dlg(account); 296 NNTPGroupsDlg dlg(account);
297 if (QPEApplication::execDialog(&dlg)== QDialog::Accepted ){ 297 if (QPEApplication::execDialog(&dlg)== QDialog::Accepted ){
298 refresh(); 298 refresh();
299 } 299 }
300} 300}
301 301
302void NNTPviewItem::disconnect() 302void NNTPviewItem::disconnect()
303{ 303{
304 QListViewItem *child = firstChild(); 304 QListViewItem *child = firstChild();
305 while ( child ) 305 while ( child )
306 { 306 {
307 QListViewItem *tmp = child; 307 QListViewItem *tmp = child;
308 child = child->nextSibling(); 308 child = child->nextSibling();
309 delete tmp; 309 delete tmp;
310 } 310 }
311 wrapper->logout(); 311 wrapper->logout();
312} 312}
313 313
314void NNTPviewItem::setOnOffline() 314void NNTPviewItem::setOnOffline()
315{ 315{
316 if (!account->getOffline()) 316 if (!account->getOffline())
317 { 317 {
318 disconnect(); 318 disconnect();
319 } 319 }
320 account->setOffline(!account->getOffline()); 320 account->setOffline(!account->getOffline());
321 account->save(); 321 account->save();
322 //FIXME 322 //FIXME
323 SETPIX(PIXMAP_POP3FOLDER); 323 SETPIX(PIXMAP_POP3FOLDER);
324 refresh(); 324 refresh();
325} 325}
326 326
327void NNTPviewItem::contextMenuSelected(int which) 327void NNTPviewItem::contextMenuSelected(int which)
328{ 328{
329 switch (which) 329 switch (which)
330 { 330 {
331 case 0: 331 case 0:
332 disconnect(); 332 disconnect();
333 break; 333 break;
334 case 1: 334 case 1:
335 setOnOffline(); 335 setOnOffline();
336 break; 336 break;
337 case 2: 337 case 2:
338 subscribeGroups(); 338 subscribeGroups();
339 break; 339 break;
340 } 340 }
341} 341}
342 342
343NNTPfolderItem::~NNTPfolderItem() 343NNTPfolderItem::~NNTPfolderItem()
344{} 344{}
345 345
346NNTPfolderItem::NNTPfolderItem( const FolderP &folderInit, NNTPviewItem *parent , QListViewItem*after ) 346NNTPfolderItem::NNTPfolderItem( const FolderP &folderInit, NNTPviewItem *parent , QListViewItem*after )
347 : AccountViewItem( folderInit, parent,after ) 347 : AccountViewItem( folderInit, parent,after )
348{ 348{
349 nntp = parent; 349 nntp = parent;
350 if (folder->getDisplayName().lower()!="inbox") 350 if (folder->getDisplayName().lower()!="inbox")
351 { 351 {
352 setPixmap( 0, PIXMAP_POP3FOLDER ); 352 setPixmap( 0, PIXMAP_POP3FOLDER );
353 } 353 }
354 else 354 else
355 { 355 {
356 setPixmap( 0, PIXMAP_INBOXFOLDER); 356 setPixmap( 0, PIXMAP_INBOXFOLDER);
357 } 357 }
358 setText( 0, folder->getDisplayName() ); 358 setText( 0, folder->getDisplayName() );
359} 359}
360 360
361void NNTPfolderItem::refresh(QList<RecMail>&target) 361void NNTPfolderItem::refresh(QValueList<RecMailP>&target)
362{ 362{
363 if (folder->may_select()) 363 if (folder->may_select())
364 nntp->getWrapper()->listMessages( folder->getName(),target ); 364 nntp->getWrapper()->listMessages( folder->getName(),target );
365} 365}
366 366
367RecBody NNTPfolderItem::fetchBody(const RecMail&aMail) 367RecBody NNTPfolderItem::fetchBody(const RecMailP&aMail)
368{ 368{
369 return nntp->getWrapper()->fetchBody(aMail); 369 return nntp->getWrapper()->fetchBody(aMail);
370} 370}
371 371
372QPopupMenu * NNTPfolderItem::getContextMenu() 372QPopupMenu * NNTPfolderItem::getContextMenu()
373{ 373{
374 QPopupMenu *m = new QPopupMenu(0); 374 QPopupMenu *m = new QPopupMenu(0);
375 if (m) 375 if (m)
376 { 376 {
377 m->insertItem(QObject::tr("Refresh header list",contextName),0); 377 m->insertItem(QObject::tr("Refresh header list",contextName),0);
378 m->insertItem(QObject::tr("Copy all postings",contextName),1); 378 m->insertItem(QObject::tr("Copy all postings",contextName),1);
379 } 379 }
380 return m; 380 return m;
381} 381}
382 382
383void NNTPfolderItem::downloadMails() 383void NNTPfolderItem::downloadMails()
384{ 384{
385 AccountView*bl = nntp->accountView(); 385 AccountView*bl = nntp->accountView();
386 if (!bl) return; 386 if (!bl) return;
387 bl->downloadMails(folder,nntp->getWrapper()); 387 bl->downloadMails(folder,nntp->getWrapper());
388} 388}
389 389
390void NNTPfolderItem::contextMenuSelected(int which) 390void NNTPfolderItem::contextMenuSelected(int which)
391{ 391{
392 AccountView * view = (AccountView*)listView(); 392 AccountView * view = (AccountView*)listView();
393 switch (which) 393 switch (which)
394 { 394 {
395 case 0: 395 case 0:
396 /* must be 'cause pop3 lists are cached */ 396 /* must be 'cause pop3 lists are cached */
397 nntp->getWrapper()->logout(); 397 nntp->getWrapper()->logout();
398 view->refreshCurrent(); 398 view->refreshCurrent();
399 break; 399 break;
400 case 1: 400 case 1:
401 downloadMails(); 401 downloadMails();
402 break; 402 break;
403 default: 403 default:
404 break; 404 break;
405 } 405 }
406} 406}
407 407
408/** 408/**
409 * IMAP Account stuff 409 * IMAP Account stuff
410 */ 410 */
411IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent ) 411IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent )
412 : AccountViewItem( parent ) 412 : AccountViewItem( parent )
413{ 413{
414 account = a; 414 account = a;
415 wrapper = AbstractMail::getWrapper( account ); 415 wrapper = AbstractMail::getWrapper( account );
416 SETPIX(PIXMAP_IMAPFOLDER); 416 SETPIX(PIXMAP_IMAPFOLDER);
417 setText( 0, account->getAccountName() ); 417 setText( 0, account->getAccountName() );
418 setOpen( true ); 418 setOpen( true );
419} 419}
420 420
421IMAPviewItem::~IMAPviewItem() 421IMAPviewItem::~IMAPviewItem()
422{ 422{
423 delete wrapper; 423 delete wrapper;
424} 424}
425 425
426AbstractMail *IMAPviewItem::getWrapper() 426AbstractMail *IMAPviewItem::getWrapper()
427{ 427{
428 return wrapper; 428 return wrapper;
429} 429}
430 430
431void IMAPviewItem::refresh(QList<RecMail>&) 431void IMAPviewItem::refresh(QValueList<RecMailP>&)
432{ 432{
433 refreshFolders(false); 433 refreshFolders(false);
434} 434}
435 435
436const QStringList&IMAPviewItem::subFolders() 436const QStringList&IMAPviewItem::subFolders()
437{ 437{
438 return currentFolders; 438 return currentFolders;
439} 439}
440 440
441void IMAPviewItem::refreshFolders(bool force) 441void IMAPviewItem::refreshFolders(bool force)
442{ 442{
443 if (childCount()>0 && force==false) return; 443 if (childCount()>0 && force==false) return;
444 if (account->getOffline()) return; 444 if (account->getOffline()) return;
445 445
446 removeChilds(); 446 removeChilds();
447 currentFolders.clear(); 447 currentFolders.clear();
448 QValueList<FolderP> * folders = wrapper->listFolders(); 448 QValueList<FolderP> * folders = wrapper->listFolders();
449 449
450 QValueList<FolderP>::Iterator it; 450 QValueList<FolderP>::Iterator it;
451 QListViewItem*item = 0; 451 QListViewItem*item = 0;
452 QListViewItem*titem = 0; 452 QListViewItem*titem = 0;
453 QString fname,del,search; 453 QString fname,del,search;
454 int pos; 454 int pos;
455 455
456 for ( it = folders->begin(); it!=folders->end(); ++it) 456 for ( it = folders->begin(); it!=folders->end(); ++it)
457 { 457 {
458 if ((*it)->getDisplayName().lower()=="inbox") 458 if ((*it)->getDisplayName().lower()=="inbox")
459 { 459 {
460 item = new IMAPfolderItem( (*it), this , item ); 460 item = new IMAPfolderItem( (*it), this , item );
461 folders->remove(it); 461 folders->remove(it);
462 qDebug("inbox found"); 462 qDebug("inbox found");
463 break; 463 break;
464 } 464 }
465 } 465 }
466 for ( it = folders->begin(); it!=folders->end(); ++it) 466 for ( it = folders->begin(); it!=folders->end(); ++it)
467 { 467 {
468 fname = (*it)->getDisplayName(); 468 fname = (*it)->getDisplayName();
469 currentFolders.append((*it)->getName()); 469 currentFolders.append((*it)->getName());
470 pos = fname.findRev((*it)->Separator()); 470 pos = fname.findRev((*it)->Separator());
471 if (pos != -1) 471 if (pos != -1)
472 { 472 {
473 fname = fname.left(pos); 473 fname = fname.left(pos);
474 } 474 }
475 IMAPfolderItem*pitem = (IMAPfolderItem*)findSubItem(fname); 475 IMAPfolderItem*pitem = (IMAPfolderItem*)findSubItem(fname);
476 if (pitem) 476 if (pitem)
477 { 477 {
478 titem = item; 478 titem = item;
479 item = new IMAPfolderItem( (*it),pitem,pitem->firstChild(),this); 479 item = new IMAPfolderItem( (*it),pitem,pitem->firstChild(),this);
480 /* setup the short name */ 480 /* setup the short name */
481 item->setText(0,(*it)->getDisplayName().right((*it)->getDisplayName().length()-pos-1)); 481 item->setText(0,(*it)->getDisplayName().right((*it)->getDisplayName().length()-pos-1));
482 item = titem; 482 item = titem;
483 } 483 }
484 else 484 else
485 { 485 {
486 item = new IMAPfolderItem( (*it), this , item ); 486 item = new IMAPfolderItem( (*it), this , item );
487 } 487 }
488 } 488 }
489 delete folders; 489 delete folders;
490} 490}
491 491
492QPopupMenu * IMAPviewItem::getContextMenu() 492QPopupMenu * IMAPviewItem::getContextMenu()
493{ 493{
494 QPopupMenu *m = new QPopupMenu(0); 494 QPopupMenu *m = new QPopupMenu(0);
495 if (m) 495 if (m)
496 { 496 {
497 if (!account->getOffline()) 497 if (!account->getOffline())
498 { 498 {
499 m->insertItem(QObject::tr("Refresh folder list",contextName),0); 499 m->insertItem(QObject::tr("Refresh folder list",contextName),0);
500 m->insertItem(QObject::tr("Create new folder",contextName),1); 500 m->insertItem(QObject::tr("Create new folder",contextName),1);
501 m->insertSeparator(); 501 m->insertSeparator();
502 m->insertItem(QObject::tr("Disconnect",contextName),2); 502 m->insertItem(QObject::tr("Disconnect",contextName),2);
503 m->insertItem(QObject::tr("Set offline",contextName),3); 503 m->insertItem(QObject::tr("Set offline",contextName),3);
504 } 504 }
505 else 505 else
506 { 506 {
507 m->insertItem(QObject::tr("Set online",contextName),3); 507 m->insertItem(QObject::tr("Set online",contextName),3);
508 } 508 }
509 } 509 }
510 return m; 510 return m;
511} 511}
512 512
513void IMAPviewItem::createNewFolder() 513void IMAPviewItem::createNewFolder()
514{ 514{
515 Newmdirdlg ndirdlg; 515 Newmdirdlg ndirdlg;
516 if ( QPEApplication::execDialog( &ndirdlg )) 516 if ( QPEApplication::execDialog( &ndirdlg ))
517 { 517 {
518 QString ndir = ndirdlg.Newdir(); 518 QString ndir = ndirdlg.Newdir();
519 bool makesubs = ndirdlg.subpossible(); 519 bool makesubs = ndirdlg.subpossible();
520 QString delemiter = "/"; 520 QString delemiter = "/";
521 IMAPfolderItem*item = (IMAPfolderItem*)firstChild(); 521 IMAPfolderItem*item = (IMAPfolderItem*)firstChild();
522 if (item) 522 if (item)
523 { 523 {
524 delemiter = item->Delemiter(); 524 delemiter = item->Delemiter();
525 } 525 }
526 if (wrapper->createMbox(ndir,0,delemiter,makesubs)) 526 if (wrapper->createMbox(ndir,0,delemiter,makesubs))
527 { 527 {
528 refreshFolders(true); 528 refreshFolders(true);
529 } 529 }
530 } 530 }
531} 531}
532 532
533void IMAPviewItem::contextMenuSelected(int id) 533void IMAPviewItem::contextMenuSelected(int id)
534{ 534{
535 qDebug("Id selected: %i",id); 535 qDebug("Id selected: %i",id);
536 switch (id) 536 switch (id)
537 { 537 {
538 case 0: 538 case 0:
539 refreshFolders(true); 539 refreshFolders(true);
540 break; 540 break;
541 case 1: 541 case 1:
542 createNewFolder(); 542 createNewFolder();
543 break; 543 break;
544 case 2: 544 case 2:
545 removeChilds(); 545 removeChilds();
546 wrapper->logout(); 546 wrapper->logout();
547 break; 547 break;
548 case 3: 548 case 3:
549 if (account->getOffline()==false) 549 if (account->getOffline()==false)
550 { 550 {
551 removeChilds(); 551 removeChilds();
552 wrapper->logout(); 552 wrapper->logout();
553 } 553 }
554 account->setOffline(!account->getOffline()); 554 account->setOffline(!account->getOffline());
555 account->save(); 555 account->save();
556 SETPIX(PIXMAP_IMAPFOLDER); 556 SETPIX(PIXMAP_IMAPFOLDER);
557 refreshFolders(false); 557 refreshFolders(false);
558 break; 558 break;
559 default: 559 default:
560 break; 560 break;
561 } 561 }
562} 562}
563 563
564RecBody IMAPviewItem::fetchBody(const RecMail&) 564RecBody IMAPviewItem::fetchBody(const RecMailP&)
565{ 565{
566 return RecBody(); 566 return RecBody();
567} 567}
568 568
569bool IMAPviewItem::offline() 569bool IMAPviewItem::offline()
570{ 570{
571 return account->getOffline(); 571 return account->getOffline();
572} 572}
573 573
574IMAPfolderItem::IMAPfolderItem( const FolderP& folderInit, IMAPviewItem *parent , QListViewItem*after ) 574IMAPfolderItem::IMAPfolderItem( const FolderP& folderInit, IMAPviewItem *parent , QListViewItem*after )
575 : AccountViewItem( folderInit, parent , after ) 575 : AccountViewItem( folderInit, parent , after )
576{ 576{
577 imap = parent; 577 imap = parent;
578 if (folder->getDisplayName().lower()!="inbox") 578 if (folder->getDisplayName().lower()!="inbox")
579 { 579 {
580 setPixmap( 0, PIXMAP_IMAPFOLDER ); 580 setPixmap( 0, PIXMAP_IMAPFOLDER );
581 } 581 }
582 else 582 else
583 { 583 {
584 setPixmap( 0, PIXMAP_INBOXFOLDER); 584 setPixmap( 0, PIXMAP_INBOXFOLDER);
585 } 585 }
586 setText( 0, folder->getDisplayName() ); 586 setText( 0, folder->getDisplayName() );
587} 587}
588 588
589IMAPfolderItem::IMAPfolderItem(const FolderP &folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ) 589IMAPfolderItem::IMAPfolderItem(const FolderP &folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master )
590 : AccountViewItem(folderInit, parent,after ) 590 : AccountViewItem(folderInit, parent,after )
591{ 591{
592 imap = master; 592 imap = master;
593 if (folder->getDisplayName().lower()!="inbox") 593 if (folder->getDisplayName().lower()!="inbox")
594 { 594 {
595 setPixmap( 0, PIXMAP_IMAPFOLDER ); 595 setPixmap( 0, PIXMAP_IMAPFOLDER );
596 } 596 }
597 else 597 else
598 { 598 {
599 setPixmap( 0, PIXMAP_INBOXFOLDER); 599 setPixmap( 0, PIXMAP_INBOXFOLDER);
600 } 600 }
601 setText( 0, folder->getDisplayName() ); 601 setText( 0, folder->getDisplayName() );
602} 602}
603 603
604IMAPfolderItem::~IMAPfolderItem() 604IMAPfolderItem::~IMAPfolderItem()
605{} 605{}
606 606
607const QString& IMAPfolderItem::Delemiter()const 607const QString& IMAPfolderItem::Delemiter()const
608{ 608{
609 return folder->Separator(); 609 return folder->Separator();
610} 610}
611 611
612void IMAPfolderItem::refresh(QList<RecMail>&target) 612void IMAPfolderItem::refresh(QValueList<RecMailP>&target)
613{ 613{
614 if (folder->may_select()) 614 if (folder->may_select())
615 { 615 {
616 imap->getWrapper()->listMessages( folder->getName(),target ); 616 imap->getWrapper()->listMessages( folder->getName(),target );
617 } 617 }
618 else 618 else
619 { 619 {
620 target.clear(); 620 target.clear();
621 } 621 }
622} 622}
623 623
624RecBody IMAPfolderItem::fetchBody(const RecMail&aMail) 624RecBody IMAPfolderItem::fetchBody(const RecMailP&aMail)
625{ 625{
626 return imap->getWrapper()->fetchBody(aMail); 626 return imap->getWrapper()->fetchBody(aMail);
627} 627}
628 628
629QPopupMenu * IMAPfolderItem::getContextMenu() 629QPopupMenu * IMAPfolderItem::getContextMenu()
630{ 630{
631 QPopupMenu *m = new QPopupMenu(0); 631 QPopupMenu *m = new QPopupMenu(0);
632 if (m) 632 if (m)
633 { 633 {
634 if (folder->may_select()) 634 if (folder->may_select())
635 { 635 {
636 m->insertItem(QObject::tr("Refresh header list",contextName),0); 636 m->insertItem(QObject::tr("Refresh header list",contextName),0);
637 m->insertItem(QObject::tr("Move/Copie all mails",contextName),4); 637 m->insertItem(QObject::tr("Move/Copie all mails",contextName),4);
638 m->insertItem(QObject::tr("Delete all mails",contextName),1); 638 m->insertItem(QObject::tr("Delete all mails",contextName),1);
639 } 639 }
640 if (folder->no_inferior()==false) 640 if (folder->no_inferior()==false)
641 { 641 {
642 m->insertItem(QObject::tr("Create new subfolder",contextName),2); 642 m->insertItem(QObject::tr("Create new subfolder",contextName),2);
643 } 643 }
644 if (folder->getDisplayName().lower()!="inbox") 644 if (folder->getDisplayName().lower()!="inbox")
645 { 645 {
646 m->insertItem(QObject::tr("Delete folder",contextName),3); 646 m->insertItem(QObject::tr("Delete folder",contextName),3);
647 } 647 }
648 } 648 }
649 return m; 649 return m;
650} 650}
651 651
652void IMAPfolderItem::createNewFolder() 652void IMAPfolderItem::createNewFolder()
653{ 653{
654 Newmdirdlg ndirdlg; 654 Newmdirdlg ndirdlg;
655 if ( QPEApplication::execDialog( &ndirdlg ) ) 655 if ( QPEApplication::execDialog( &ndirdlg ) )
656 { 656 {
657 QString ndir = ndirdlg.Newdir(); 657 QString ndir = ndirdlg.Newdir();
658 bool makesubs = ndirdlg.subpossible(); 658 bool makesubs = ndirdlg.subpossible();
659 QString delemiter = Delemiter(); 659 QString delemiter = Delemiter();
660 if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) 660 if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs))
661 { 661 {
662 imap->refreshFolders(true); 662 imap->refreshFolders(true);
663 } 663 }
664 } 664 }
665} 665}
666 666
667void IMAPfolderItem::deleteFolder() 667void IMAPfolderItem::deleteFolder()
668{ 668{
669 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), 669 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
670 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), 670 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()),
671 QObject::tr("Yes",contextName), 671 QObject::tr("Yes",contextName),
672 QObject::tr("No",contextName),QString::null,1,1); 672 QObject::tr("No",contextName),QString::null,1,1);
673 qDebug("Auswahl: %i",yesno); 673 qDebug("Auswahl: %i",yesno);
674 if (yesno == 0) 674 if (yesno == 0)
675 { 675 {
676 if (imap->getWrapper()->deleteMbox(folder)) 676 if (imap->getWrapper()->deleteMbox(folder))
677 { 677 {
678 QListView*v=listView(); 678 QListView*v=listView();
679 IMAPviewItem * box = imap; 679 IMAPviewItem * box = imap;
680 /* be carefull - after that this object is destroyd so don't use 680 /* be carefull - after that this object is destroyd so don't use
681 * any member of it after that call!!*/ 681 * any member of it after that call!!*/
682 imap->refreshFolders(true); 682 imap->refreshFolders(true);
683 if (v) 683 if (v)
684 { 684 {
685 v->setSelected(box,true); 685 v->setSelected(box,true);
686 } 686 }
687 } 687 }
688 } 688 }
689} 689}
690 690
691void IMAPfolderItem::downloadMails() 691void IMAPfolderItem::downloadMails()
692{ 692{
693 AccountView*bl = imap->accountView(); 693 AccountView*bl = imap->accountView();
694 if (!bl) return; 694 if (!bl) return;
695 bl->downloadMails(folder,imap->getWrapper()); 695 bl->downloadMails(folder,imap->getWrapper());
696} 696}
697 697
698void IMAPfolderItem::contextMenuSelected(int id) 698void IMAPfolderItem::contextMenuSelected(int id)
699{ 699{
700 qDebug("Selected id: %i",id); 700 qDebug("Selected id: %i",id);
701 AccountView * view = (AccountView*)listView(); 701 AccountView * view = (AccountView*)listView();
702 switch(id) 702 switch(id)
703 { 703 {
704 case 0: 704 case 0:
705 view->refreshCurrent(); 705 view->refreshCurrent();
706 break; 706 break;
707 case 1: 707 case 1:
708 deleteAllMail(imap->getWrapper(),folder); 708 deleteAllMail(imap->getWrapper(),folder);
709 break; 709 break;
710 case 2: 710 case 2:
711 createNewFolder(); 711 createNewFolder();
712 break; 712 break;
713 case 3: 713 case 3:
714 deleteFolder(); 714 deleteFolder();
715 break; 715 break;
716 case 4: 716 case 4:
717 downloadMails(); 717 downloadMails();
718 break; 718 break;
719 default: 719 default:
720 break; 720 break;
721 } 721 }
722} 722}
723 723
724/** 724/**
725 * MH Account stuff 725 * MH Account stuff
726 */ 726 */
727/* MH is a little bit different - the top folder can contains messages other than in IMAP and 727/* MH is a little bit different - the top folder can contains messages other than in IMAP and
728 POP3 and MBOX */ 728 POP3 and MBOX */
729MHviewItem::MHviewItem( const QString&aPath, AccountView *parent ) 729MHviewItem::MHviewItem( const QString&aPath, AccountView *parent )
730 : AccountViewItem( parent ) 730 : AccountViewItem( parent )
731{ 731{
732 m_Path = aPath; 732 m_Path = aPath;
733 /* be carefull - the space within settext is wanted - thats why the string twice */ 733 /* be carefull - the space within settext is wanted - thats why the string twice */
734 wrapper = AbstractMail::getWrapper( m_Path,"Local Folders"); 734 wrapper = AbstractMail::getWrapper( m_Path,"Local Folders");
735 setPixmap( 0, PIXMAP_LOCALFOLDER ); 735 setPixmap( 0, PIXMAP_LOCALFOLDER );
736 setText( 0, " Local Folders" ); 736 setText( 0, " Local Folders" );
737 setOpen( true ); 737 setOpen( true );
738 folder = 0; 738 folder = 0;
739} 739}
740 740
741MHviewItem::~MHviewItem() 741MHviewItem::~MHviewItem()
742{ 742{
743 delete wrapper; 743 delete wrapper;
744} 744}
745 745
746AbstractMail *MHviewItem::getWrapper() 746AbstractMail *MHviewItem::getWrapper()
747{ 747{
748 return wrapper; 748 return wrapper;
749} 749}
750 750
751void MHviewItem::refresh( QList<RecMail> & target) 751void MHviewItem::refresh( QValueList<RecMailP> & target)
752{ 752{
753 refresh(false); 753 refresh(false);
754 getWrapper()->listMessages( "",target ); 754 getWrapper()->listMessages( "",target );
755} 755}
756 756
757void MHviewItem::refresh(bool force) 757void MHviewItem::refresh(bool force)
758{ 758{
759 if (childCount()>0 && force==false) return; 759 if (childCount()>0 && force==false) return;
760 removeChilds(); 760 removeChilds();
761 currentFolders.clear(); 761 currentFolders.clear();
762 QValueList<FolderP> *folders = wrapper->listFolders(); 762 QValueList<FolderP> *folders = wrapper->listFolders();
763 QValueList<FolderP>::ConstIterator it; 763 QValueList<FolderP>::ConstIterator it;
764 MHfolderItem*item = 0; 764 MHfolderItem*item = 0;
765 MHfolderItem*pmaster = 0; 765 MHfolderItem*pmaster = 0;
766 QString fname = ""; 766 QString fname = "";
767 int pos; 767 int pos;
768 for ( it = folders->begin(); it!=folders->end(); ++it) 768 for ( it = folders->begin(); it!=folders->end(); ++it)
769 { 769 {
770 fname = (*it)->getDisplayName(); 770 fname = (*it)->getDisplayName();
771 /* this folder itself */ 771 /* this folder itself */
772 if (fname=="/") 772 if (fname=="/")
773 { 773 {
774 currentFolders.append(fname); 774 currentFolders.append(fname);
775 folder = (*it); 775 folder = (*it);
776 continue; 776 continue;
777 } 777 }
778 currentFolders.append(fname); 778 currentFolders.append(fname);
779 pos = fname.findRev("/"); 779 pos = fname.findRev("/");
780 if (pos > 0) 780 if (pos > 0)
781 { 781 {
782 fname = fname.left(pos); 782 fname = fname.left(pos);
783 pmaster = (MHfolderItem*)findSubItem(fname); 783 pmaster = (MHfolderItem*)findSubItem(fname);
784 } 784 }
785 else 785 else
786 { 786 {
787 pmaster = 0; 787 pmaster = 0;
788 } 788 }
789 if (pmaster) 789 if (pmaster)
790 { 790 {
791 item = new MHfolderItem( (*it), pmaster, item, this ); 791 item = new MHfolderItem( (*it), pmaster, item, this );
792 } 792 }
793 else 793 else
794 { 794 {
795 item = new MHfolderItem( (*it), this , item ); 795 item = new MHfolderItem( (*it), this , item );
796 } 796 }
797 item->setSelectable((*it)->may_select()); 797 item->setSelectable((*it)->may_select());
798 } 798 }
799 delete folders; 799 delete folders;
800} 800}
801 801
802RecBody MHviewItem::fetchBody( const RecMail &mail ) 802RecBody MHviewItem::fetchBody( const RecMailP &mail )
803{ 803{
804 qDebug( "MH fetchBody" ); 804 qDebug( "MH fetchBody" );
805 return wrapper->fetchBody( mail ); 805 return wrapper->fetchBody( mail );
806} 806}
807 807
808QPopupMenu * MHviewItem::getContextMenu() 808QPopupMenu * MHviewItem::getContextMenu()
809{ 809{
810 QPopupMenu *m = new QPopupMenu(0); 810 QPopupMenu *m = new QPopupMenu(0);
811 if (m) 811 if (m)
812 { 812 {
813 m->insertItem(QObject::tr("Refresh folder list",contextName),0); 813 m->insertItem(QObject::tr("Refresh folder list",contextName),0);
814 m->insertItem(QObject::tr("Create new folder",contextName),1); 814 m->insertItem(QObject::tr("Create new folder",contextName),1);
815 m->insertItem(QObject::tr("Delete all mails",contextName),2); 815 m->insertItem(QObject::tr("Delete all mails",contextName),2);
816 m->insertItem(QObject::tr("Move/Copie all mails",contextName),3); 816 m->insertItem(QObject::tr("Move/Copie all mails",contextName),3);
817 } 817 }
818 return m; 818 return m;
819} 819}
820 820
821void MHviewItem::createFolder() 821void MHviewItem::createFolder()
822{ 822{
823 Newmdirdlg ndirdlg(0,0,true); 823 Newmdirdlg ndirdlg(0,0,true);
824 if ( QPEApplication::execDialog( &ndirdlg ) ) 824 if ( QPEApplication::execDialog( &ndirdlg ) )
825 { 825 {
826 QString ndir = ndirdlg.Newdir(); 826 QString ndir = ndirdlg.Newdir();
827 if (wrapper->createMbox(ndir)) 827 if (wrapper->createMbox(ndir))
828 { 828 {
829 refresh(true); 829 refresh(true);
830 } 830 }
831 } 831 }
832} 832}
833 833
834void MHviewItem::downloadMails() 834void MHviewItem::downloadMails()
835{ 835{
836 AccountView*bl = accountView(); 836 AccountView*bl = accountView();
837 if (!bl) return; 837 if (!bl) return;
838 bl->downloadMails(folder,getWrapper()); 838 bl->downloadMails(folder,getWrapper());
839} 839}
840 840
841QStringList MHviewItem::subFolders() 841QStringList MHviewItem::subFolders()
842{ 842{
843 return currentFolders; 843 return currentFolders;
844} 844}
845 845
846void MHviewItem::contextMenuSelected(int which) 846void MHviewItem::contextMenuSelected(int which)
847{ 847{
848 switch (which) 848 switch (which)
849 { 849 {
850 case 0: 850 case 0:
851 refresh(true); 851 refresh(true);
852 break; 852 break;
853 case 1: 853 case 1:
854 createFolder(); 854 createFolder();
855 break; 855 break;
856 case 2: 856 case 2:
857 deleteAllMail(getWrapper(),folder); 857 deleteAllMail(getWrapper(),folder);
858 break; 858 break;
859 case 3: 859 case 3:
860 downloadMails(); 860 downloadMails();
861 break; 861 break;
862 default: 862 default:
863 break; 863 break;
864 } 864 }
865} 865}
866 866
867MHfolderItem::~MHfolderItem() 867MHfolderItem::~MHfolderItem()
868{} 868{}
869 869
870MHfolderItem::MHfolderItem( const FolderP &folderInit, MHviewItem *parent , QListViewItem*after ) 870MHfolderItem::MHfolderItem( const FolderP &folderInit, MHviewItem *parent , QListViewItem*after )
871 : AccountViewItem(folderInit, parent,after ) 871 : AccountViewItem(folderInit, parent,after )
872{ 872{
873 mbox = parent; 873 mbox = parent;
874 initName(); 874 initName();
875} 875}
876 876
877MHfolderItem::MHfolderItem(const FolderP& folderInit, MHfolderItem *parent, QListViewItem*after, MHviewItem*master) 877MHfolderItem::MHfolderItem(const FolderP& folderInit, MHfolderItem *parent, QListViewItem*after, MHviewItem*master)
878 : AccountViewItem(folderInit, parent,after ) 878 : AccountViewItem(folderInit, parent,after )
879{ 879{
880 folder = folderInit; 880 folder = folderInit;
881 mbox = master; 881 mbox = master;
882 initName(); 882 initName();
883} 883}
884 884
885void MHfolderItem::initName() 885void MHfolderItem::initName()
886{ 886{
887 QString bName = folder->getDisplayName(); 887 QString bName = folder->getDisplayName();
888 if (bName.startsWith("/")&&bName.length()>1) 888 if (bName.startsWith("/")&&bName.length()>1)
889 { 889 {
890 bName.replace(0,1,""); 890 bName.replace(0,1,"");
891 } 891 }
892 int pos = bName.findRev("/"); 892 int pos = bName.findRev("/");
893 if (pos > 0) 893 if (pos > 0)
894 { 894 {
895 bName.replace(0,pos+1,""); 895 bName.replace(0,pos+1,"");
896 } 896 }
897 if (bName.lower() == "outgoing") 897 if (bName.lower() == "outgoing")
898 { 898 {
899 setPixmap( 0, PIXMAP_OUTBOXFOLDER ); 899 setPixmap( 0, PIXMAP_OUTBOXFOLDER );
900 } 900 }
901 else if (bName.lower() == "inbox") 901 else if (bName.lower() == "inbox")
902 { 902 {
903 setPixmap( 0, PIXMAP_INBOXFOLDER); 903 setPixmap( 0, PIXMAP_INBOXFOLDER);
904 } else if (bName.lower() == "drafts") { 904 } else if (bName.lower() == "drafts") {
905 setPixmap(0, Resource::loadPixmap("inline/edit")); 905 setPixmap(0, Resource::loadPixmap("inline/edit"));
906 } else { 906 } else {
907 setPixmap( 0, PIXMAP_MBOXFOLDER ); 907 setPixmap( 0, PIXMAP_MBOXFOLDER );
908 } 908 }
909 setText( 0, bName ); 909 setText( 0, bName );
910} 910}
911 911
912const FolderP&MHfolderItem::getFolder()const 912const FolderP&MHfolderItem::getFolder()const
913{ 913{
914 return folder; 914 return folder;
915} 915}
916 916
917void MHfolderItem::refresh(QList<RecMail>&target) 917void MHfolderItem::refresh(QValueList<RecMailP>&target)
918{ 918{
919 if (folder->may_select()) 919 if (folder->may_select())
920 mbox->getWrapper()->listMessages( folder->getName(),target ); 920 mbox->getWrapper()->listMessages( folder->getName(),target );
921} 921}
922 922
923RecBody MHfolderItem::fetchBody(const RecMail&aMail) 923RecBody MHfolderItem::fetchBody(const RecMailP&aMail)
924{ 924{
925 return mbox->getWrapper()->fetchBody(aMail); 925 return mbox->getWrapper()->fetchBody(aMail);
926} 926}
927 927
928void MHfolderItem::deleteFolder() 928void MHfolderItem::deleteFolder()
929{ 929{
930 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), 930 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
931 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), 931 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()),
932 QObject::tr("Yes",contextName), 932 QObject::tr("Yes",contextName),
933 QObject::tr("No",contextName),QString::null,1,1); 933 QObject::tr("No",contextName),QString::null,1,1);
934 qDebug("Auswahl: %i",yesno); 934 qDebug("Auswahl: %i",yesno);
935 if (yesno == 0) 935 if (yesno == 0)
936 { 936 {
937 if (mbox->getWrapper()->deleteMbox(folder)) 937 if (mbox->getWrapper()->deleteMbox(folder))
938 { 938 {
939 QListView*v=listView(); 939 QListView*v=listView();
940 MHviewItem * box = mbox; 940 MHviewItem * box = mbox;
941 /* be carefull - after that this object is destroyd so don't use 941 /* be carefull - after that this object is destroyd so don't use
942 * any member of it after that call!!*/ 942 * any member of it after that call!!*/
943 mbox->refresh(true); 943 mbox->refresh(true);
944 if (v) 944 if (v)
945 { 945 {
946 v->setSelected(box,true); 946 v->setSelected(box,true);
947 } 947 }
948 } 948 }
949 } 949 }
950} 950}
951 951
952QPopupMenu * MHfolderItem::getContextMenu() 952QPopupMenu * MHfolderItem::getContextMenu()
953{ 953{
954 QPopupMenu *m = new QPopupMenu(0); 954 QPopupMenu *m = new QPopupMenu(0);
955 if (m) 955 if (m)
956 { 956 {
957 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); 957 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2);
958 m->insertItem(QObject::tr("Delete all mails",contextName),0); 958 m->insertItem(QObject::tr("Delete all mails",contextName),0);
959 m->insertItem(QObject::tr("Create new subfolder",contextName),3); 959 m->insertItem(QObject::tr("Create new subfolder",contextName),3);
960 m->insertItem(QObject::tr("Delete folder",contextName),1); 960 m->insertItem(QObject::tr("Delete folder",contextName),1);
961 } 961 }
962 return m; 962 return m;
963} 963}
964 964
965void MHfolderItem::downloadMails() 965void MHfolderItem::downloadMails()
966{ 966{
967 AccountView*bl = mbox->accountView(); 967 AccountView*bl = mbox->accountView();
968 if (!bl) return; 968 if (!bl) return;
969 bl->downloadMails(folder,mbox->getWrapper()); 969 bl->downloadMails(folder,mbox->getWrapper());
970} 970}
971 971
972void MHfolderItem::createFolder() 972void MHfolderItem::createFolder()
973{ 973{
974 Newmdirdlg ndirdlg(0,0,true); 974 Newmdirdlg ndirdlg(0,0,true);
975 if ( QPEApplication::execDialog( &ndirdlg ) ) 975 if ( QPEApplication::execDialog( &ndirdlg ) )
976 { 976 {
977 QString ndir = ndirdlg.Newdir(); 977 QString ndir = ndirdlg.Newdir();
978 if (mbox->getWrapper()->createMbox(ndir,folder)) 978 if (mbox->getWrapper()->createMbox(ndir,folder))
979 { 979 {
980 QListView*v=listView(); 980 QListView*v=listView();
981 MHviewItem * box = mbox; 981 MHviewItem * box = mbox;
982 /* be carefull - after that this object is destroyd so don't use 982 /* be carefull - after that this object is destroyd so don't use
983 * any member of it after that call!!*/ 983 * any member of it after that call!!*/
984 mbox->refresh(true); 984 mbox->refresh(true);
985 if (v) 985 if (v)
986 { 986 {
987 v->setSelected(box,true); 987 v->setSelected(box,true);
988 } 988 }
989 } 989 }
990 } 990 }
991} 991}
992 992
993void MHfolderItem::contextMenuSelected(int which) 993void MHfolderItem::contextMenuSelected(int which)
994{ 994{
995 switch(which) 995 switch(which)
996 { 996 {
997 case 0: 997 case 0:
998 deleteAllMail(mbox->getWrapper(),folder); 998 deleteAllMail(mbox->getWrapper(),folder);
999 break; 999 break;
1000 case 1: 1000 case 1:
1001 deleteFolder(); 1001 deleteFolder();
1002 break; 1002 break;
1003 case 2: 1003 case 2:
1004 downloadMails(); 1004 downloadMails();
1005 break; 1005 break;
1006 case 3: 1006 case 3:
1007 createFolder(); 1007 createFolder();
1008 break; 1008 break;
1009 default: 1009 default:
1010 break; 1010 break;
1011 } 1011 }
1012} 1012}
1013 1013
1014bool MHfolderItem::isDraftfolder() 1014bool MHfolderItem::isDraftfolder()
1015{ 1015{
1016 if (folder && folder->getName()==AbstractMail::defaultLocalfolder()+"/"+AbstractMail::draftFolder()) return true; 1016 if (folder && folder->getName()==AbstractMail::defaultLocalfolder()+"/"+AbstractMail::draftFolder()) return true;
1017 return false; 1017 return false;
1018} 1018}
1019 1019
1020/** 1020/**
1021 * Generic stuff 1021 * Generic stuff
1022 */ 1022 */
1023 1023
1024const QString AccountViewItem::contextName="AccountViewItem"; 1024const QString AccountViewItem::contextName="AccountViewItem";
1025 1025
1026AccountViewItem::AccountViewItem( AccountView *parent ) 1026AccountViewItem::AccountViewItem( AccountView *parent )
1027 : QListViewItem( parent ) 1027 : QListViewItem( parent )
1028{ 1028{
1029 init(); 1029 init();
1030 m_Backlink = parent; 1030 m_Backlink = parent;
1031} 1031}
1032 1032
1033AccountViewItem::AccountViewItem( QListViewItem *parent) 1033AccountViewItem::AccountViewItem( QListViewItem *parent)
1034 : QListViewItem( parent),folder(0) 1034 : QListViewItem( parent),folder(0)
1035{ 1035{
1036 init(); 1036 init();
1037} 1037}
1038 1038
1039AccountViewItem::AccountViewItem( QListViewItem *parent , QListViewItem*after ) 1039AccountViewItem::AccountViewItem( QListViewItem *parent , QListViewItem*after )
1040 :QListViewItem( parent,after ),folder(0) 1040 :QListViewItem( parent,after ),folder(0)
1041{ 1041{
1042 init(); 1042 init();
1043} 1043}
1044 1044
1045AccountViewItem::AccountViewItem( const Opie::osmart_pointer<Folder>&folderInit,QListViewItem *parent , QListViewItem*after ) 1045AccountViewItem::AccountViewItem( const Opie::OSmartPointer<Folder>&folderInit,QListViewItem *parent , QListViewItem*after )
1046 :QListViewItem( parent,after ),folder(folderInit) 1046 :QListViewItem( parent,after ),folder(folderInit)
1047{ 1047{
1048 init(); 1048 init();
1049} 1049}
1050 1050
1051void AccountViewItem::init() 1051void AccountViewItem::init()
1052{ 1052{
1053 m_Backlink = 0; 1053 m_Backlink = 0;
1054} 1054}
1055 1055
1056AccountViewItem::~AccountViewItem() 1056AccountViewItem::~AccountViewItem()
1057{ 1057{
1058 folder = 0; 1058 folder = 0;
1059} 1059}
1060 1060
1061AccountView*AccountViewItem::accountView() 1061AccountView*AccountViewItem::accountView()
1062{ 1062{
1063 return m_Backlink; 1063 return m_Backlink;
1064} 1064}
1065 1065
1066void AccountViewItem::deleteAllMail(AbstractMail*wrapper,const FolderP&folder) 1066void AccountViewItem::deleteAllMail(AbstractMail*wrapper,const FolderP&folder)
1067{ 1067{
1068 if (!wrapper) return; 1068 if (!wrapper) return;
1069 QString fname=""; 1069 QString fname="";
1070 if (folder) fname = folder->getDisplayName(); 1070 if (folder) fname = folder->getDisplayName();
1071 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName), 1071 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName),
1072 QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName). 1072 QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName).
1073 arg(fname), 1073 arg(fname),
1074 QObject::tr("Yes",contextName), 1074 QObject::tr("Yes",contextName),
1075 QObject::tr("No",contextName),QString::null,1,1); 1075 QObject::tr("No",contextName),QString::null,1,1);
1076 qDebug("Auswahl: %i",yesno); 1076 qDebug("Auswahl: %i",yesno);
1077 if (yesno == 0) 1077 if (yesno == 0)
1078 { 1078 {
1079 if (wrapper->deleteAllMail(folder)) 1079 if (wrapper->deleteAllMail(folder))
1080 { 1080 {
1081 AccountView * view = (AccountView*)listView(); 1081 AccountView * view = (AccountView*)listView();
1082 if (view) view->refreshCurrent(); 1082 if (view) view->refreshCurrent();
1083 } 1083 }
1084 } 1084 }
1085} 1085}
1086 1086
1087void AccountViewItem::removeChilds() 1087void AccountViewItem::removeChilds()
1088{ 1088{
1089 QListViewItem *child = firstChild(); 1089 QListViewItem *child = firstChild();
1090 while ( child ) 1090 while ( child )
1091 { 1091 {
1092 QListViewItem *tmp = child; 1092 QListViewItem *tmp = child;
1093 child = child->nextSibling(); 1093 child = child->nextSibling();
1094 delete tmp; 1094 delete tmp;
1095 } 1095 }
1096} 1096}
1097 1097
1098bool AccountViewItem::matchName(const QString&name)const 1098bool AccountViewItem::matchName(const QString&name)const
1099{ 1099{
1100 if (!folder) return false; 1100 if (!folder) return false;
1101 return folder->getDisplayName()==name; 1101 return folder->getDisplayName()==name;
1102} 1102}
1103 1103
1104 1104
1105AccountViewItem*AccountViewItem::findSubItem(const QString&path,AccountViewItem*start) 1105AccountViewItem*AccountViewItem::findSubItem(const QString&path,AccountViewItem*start)
1106{ 1106{
1107 AccountViewItem*pitem,*sitem; 1107 AccountViewItem*pitem,*sitem;
1108 if (!start) pitem = (AccountViewItem*)firstChild(); 1108 if (!start) pitem = (AccountViewItem*)firstChild();
1109 else pitem = (AccountViewItem*)start->firstChild(); 1109 else pitem = (AccountViewItem*)start->firstChild();
1110 while (pitem) 1110 while (pitem)
1111 { 1111 {
1112 if (pitem->matchName(path)) 1112 if (pitem->matchName(path))
1113 { 1113 {
1114 break; 1114 break;
1115 } 1115 }
1116 if (pitem->childCount()>0) 1116 if (pitem->childCount()>0)
1117 { 1117 {
1118 sitem = findSubItem(path,pitem); 1118 sitem = findSubItem(path,pitem);
1119 if (sitem) 1119 if (sitem)
1120 { 1120 {
1121 pitem = sitem; 1121 pitem = sitem;
1122 break; 1122 break;
1123 } 1123 }
1124 } 1124 }
1125 pitem=(AccountViewItem*)pitem->nextSibling(); 1125 pitem=(AccountViewItem*)pitem->nextSibling();
1126 } 1126 }
1127 return pitem; 1127 return pitem;
1128} 1128}
1129 1129
1130bool AccountViewItem::isDraftfolder() 1130bool AccountViewItem::isDraftfolder()
1131{ 1131{
1132 return false; 1132 return false;
1133} 1133}
diff --git a/noncore/net/mail/accountitem.h b/noncore/net/mail/accountitem.h
index 8f712f5..276eae0 100644
--- a/noncore/net/mail/accountitem.h
+++ b/noncore/net/mail/accountitem.h
@@ -1,210 +1,210 @@
1#ifndef __ACCOUNT_ITEM 1#ifndef __ACCOUNT_ITEM
2#define __ACCOUNT_ITEM 2#define __ACCOUNT_ITEM
3 3
4#include <qlistview.h> 4#include <qlistview.h>
5#include <qlist.h> 5#include <qlist.h>
6#include <opie2/osmart_pointer.h> 6#include <opie2/osmartpointer.h>
7 7
8class POP3wrapper; 8class POP3wrapper;
9class RecMail; 9class RecMail;
10class RecBody; 10class RecBody;
11class QPopupMenu; 11class QPopupMenu;
12class Selectstore; 12class Selectstore;
13class AccountView; 13class AccountView;
14class POP3account; 14class POP3account;
15class NNTPaccount; 15class NNTPaccount;
16class IMAPaccount; 16class IMAPaccount;
17class AbstractMail; 17class AbstractMail;
18class Folder; 18class Folder;
19 19
20class AccountViewItem : public QListViewItem 20class AccountViewItem : public QListViewItem
21{ 21{
22 22
23public: 23public:
24 AccountViewItem( AccountView *parent ); 24 AccountViewItem( AccountView *parent );
25 AccountViewItem( QListViewItem *parent); 25 AccountViewItem( QListViewItem *parent);
26 AccountViewItem( QListViewItem *parent , QListViewItem*after ); 26 AccountViewItem( QListViewItem *parent , QListViewItem*after );
27 AccountViewItem( const Opie::osmart_pointer<Folder>&folderInit,QListViewItem *parent , QListViewItem*after ); 27 AccountViewItem( const Opie::OSmartPointer<Folder>&folderInit,QListViewItem *parent , QListViewItem*after );
28 28
29 virtual ~AccountViewItem(); 29 virtual ~AccountViewItem();
30 virtual void refresh(QList<RecMail>&)=0; 30 virtual void refresh(QValueList<Opie::OSmartPointer<RecMail> >&)=0;
31 virtual RecBody fetchBody(const RecMail&)=0; 31 virtual RecBody fetchBody(const Opie::OSmartPointer<RecMail>&)=0;
32 virtual QPopupMenu * getContextMenu(){return 0;}; 32 virtual QPopupMenu * getContextMenu(){return 0;};
33 virtual void contextMenuSelected(int){} 33 virtual void contextMenuSelected(int){}
34 virtual AccountView*accountView(); 34 virtual AccountView*accountView();
35 virtual bool matchName(const QString&name)const; 35 virtual bool matchName(const QString&name)const;
36 virtual bool isDraftfolder(); 36 virtual bool isDraftfolder();
37 37
38protected: 38protected:
39 AccountViewItem*findSubItem(const QString&path,AccountViewItem*start=0); 39 AccountViewItem*findSubItem(const QString&path,AccountViewItem*start=0);
40 virtual void init(); 40 virtual void init();
41 virtual void removeChilds(); 41 virtual void removeChilds();
42 virtual void deleteAllMail(AbstractMail*wrapper,const Opie::osmart_pointer<Folder>&f); 42 virtual void deleteAllMail(AbstractMail*wrapper,const Opie::OSmartPointer<Folder>&f);
43 static const QString contextName; 43 static const QString contextName;
44 AccountView*m_Backlink; 44 AccountView*m_Backlink;
45 Opie::osmart_pointer<Folder> folder; 45 Opie::OSmartPointer<Folder> folder;
46}; 46};
47 47
48class POP3viewItem : public AccountViewItem 48class POP3viewItem : public AccountViewItem
49{ 49{
50 50
51public: 51public:
52 POP3viewItem( POP3account *a, AccountView *parent ); 52 POP3viewItem( POP3account *a, AccountView *parent );
53 virtual ~POP3viewItem(); 53 virtual ~POP3viewItem();
54 virtual void refresh( QList<RecMail> &target ); 54 virtual void refresh(QValueList<Opie::OSmartPointer<RecMail> >&target );
55 virtual RecBody fetchBody( const RecMail &mail ); 55 virtual RecBody fetchBody( const Opie::OSmartPointer<RecMail> &mail );
56 AbstractMail *getWrapper(); 56 AbstractMail *getWrapper();
57 virtual QPopupMenu * getContextMenu(); 57 virtual QPopupMenu * getContextMenu();
58 virtual void contextMenuSelected(int); 58 virtual void contextMenuSelected(int);
59 59
60protected: 60protected:
61 POP3account *account; 61 POP3account *account;
62 virtual void refresh(); 62 virtual void refresh();
63 AbstractMail *wrapper; 63 AbstractMail *wrapper;
64 void disconnect(); 64 void disconnect();
65 void setOnOffline(); 65 void setOnOffline();
66}; 66};
67 67
68class POP3folderItem : public AccountViewItem 68class POP3folderItem : public AccountViewItem
69{ 69{
70 70
71public: 71public:
72 POP3folderItem( const Opie::osmart_pointer<Folder>&folder, POP3viewItem *parent , QListViewItem*after ); 72 POP3folderItem( const Opie::OSmartPointer<Folder>&folder, POP3viewItem *parent , QListViewItem*after );
73 virtual ~POP3folderItem(); 73 virtual ~POP3folderItem();
74 virtual void refresh(QList<RecMail>&); 74 virtual void refresh(QValueList<Opie::OSmartPointer<RecMail> >&);
75 virtual RecBody fetchBody(const RecMail&); 75 virtual RecBody fetchBody(const Opie::OSmartPointer<RecMail>&);
76 virtual QPopupMenu * getContextMenu(); 76 virtual QPopupMenu * getContextMenu();
77 virtual void contextMenuSelected(int); 77 virtual void contextMenuSelected(int);
78 78
79protected: 79protected:
80 void downloadMails(); 80 void downloadMails();
81 POP3viewItem *pop3; 81 POP3viewItem *pop3;
82}; 82};
83 83
84 84
85class NNTPviewItem : public AccountViewItem 85class NNTPviewItem : public AccountViewItem
86{ 86{
87 87
88public: 88public:
89 NNTPviewItem( NNTPaccount *a, AccountView *parent ); 89 NNTPviewItem( NNTPaccount *a, AccountView *parent );
90 virtual ~NNTPviewItem(); 90 virtual ~NNTPviewItem();
91 virtual void refresh( QList<RecMail> &target ); 91 virtual void refresh(QValueList<Opie::OSmartPointer<RecMail> >&target );
92 virtual RecBody fetchBody( const RecMail &mail ); 92 virtual RecBody fetchBody( const Opie::OSmartPointer<RecMail> &mail );
93 AbstractMail *getWrapper(); 93 AbstractMail *getWrapper();
94 virtual QPopupMenu * getContextMenu(); 94 virtual QPopupMenu * getContextMenu();
95 virtual void contextMenuSelected(int); 95 virtual void contextMenuSelected(int);
96 96
97protected: 97protected:
98 NNTPaccount *account; 98 NNTPaccount *account;
99 virtual void refresh(); 99 virtual void refresh();
100 AbstractMail *wrapper; 100 AbstractMail *wrapper;
101 void disconnect(); 101 void disconnect();
102 void setOnOffline(); 102 void setOnOffline();
103 void subscribeGroups(); 103 void subscribeGroups();
104}; 104};
105 105
106class NNTPfolderItem : public AccountViewItem 106class NNTPfolderItem : public AccountViewItem
107{ 107{
108 108
109public: 109public:
110 NNTPfolderItem(const Opie::osmart_pointer<Folder>&folder, NNTPviewItem *parent , QListViewItem*after ); 110 NNTPfolderItem(const Opie::OSmartPointer<Folder>&folder, NNTPviewItem *parent , QListViewItem*after );
111 virtual ~NNTPfolderItem(); 111 virtual ~NNTPfolderItem();
112 virtual void refresh(QList<RecMail>&); 112 virtual void refresh(QValueList<Opie::OSmartPointer<RecMail> >&);
113 virtual RecBody fetchBody(const RecMail&); 113 virtual RecBody fetchBody(const Opie::OSmartPointer<RecMail>&);
114 virtual QPopupMenu * getContextMenu(); 114 virtual QPopupMenu * getContextMenu();
115 virtual void contextMenuSelected(int); 115 virtual void contextMenuSelected(int);
116 116
117protected: 117protected:
118 void downloadMails(); 118 void downloadMails();
119 NNTPviewItem *nntp; 119 NNTPviewItem *nntp;
120}; 120};
121 121
122 122
123 123
124class IMAPviewItem : public AccountViewItem 124class IMAPviewItem : public AccountViewItem
125{ 125{
126 friend class IMAPfolderItem; 126 friend class IMAPfolderItem;
127public: 127public:
128 IMAPviewItem( IMAPaccount *a, AccountView *parent ); 128 IMAPviewItem( IMAPaccount *a, AccountView *parent );
129 virtual ~IMAPviewItem(); 129 virtual ~IMAPviewItem();
130 virtual void refresh(QList<RecMail>&); 130 virtual void refresh(QValueList<Opie::OSmartPointer<RecMail> >&);
131 virtual RecBody fetchBody(const RecMail&); 131 virtual RecBody fetchBody(const Opie::OSmartPointer<RecMail>&);
132 AbstractMail *getWrapper(); 132 AbstractMail *getWrapper();
133 virtual QPopupMenu * getContextMenu(); 133 virtual QPopupMenu * getContextMenu();
134 virtual void contextMenuSelected(int); 134 virtual void contextMenuSelected(int);
135 const QStringList&subFolders(); 135 const QStringList&subFolders();
136 virtual void refreshFolders(bool force=false); 136 virtual void refreshFolders(bool force=false);
137 bool offline(); 137 bool offline();
138 138
139protected: 139protected:
140 virtual void createNewFolder(); 140 virtual void createNewFolder();
141 IMAPaccount *account; 141 IMAPaccount *account;
142 AbstractMail *wrapper; 142 AbstractMail *wrapper;
143 QStringList currentFolders; 143 QStringList currentFolders;
144}; 144};
145 145
146class IMAPfolderItem : public AccountViewItem 146class IMAPfolderItem : public AccountViewItem
147{ 147{
148 148
149public: 149public:
150 IMAPfolderItem( const Opie::osmart_pointer<Folder>&folder, IMAPviewItem *parent , QListViewItem*after ); 150 IMAPfolderItem( const Opie::OSmartPointer<Folder>&folder, IMAPviewItem *parent , QListViewItem*after );
151 IMAPfolderItem( const Opie::osmart_pointer<Folder>&folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ); 151 IMAPfolderItem( const Opie::OSmartPointer<Folder>&folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master );
152 virtual ~IMAPfolderItem(); 152 virtual ~IMAPfolderItem();
153 virtual void refresh(QList<RecMail>&); 153 virtual void refresh(QValueList<Opie::OSmartPointer<RecMail> >&);
154 virtual RecBody fetchBody(const RecMail&); 154 virtual RecBody fetchBody(const Opie::OSmartPointer<RecMail>&);
155 virtual QPopupMenu * getContextMenu(); 155 virtual QPopupMenu * getContextMenu();
156 virtual void contextMenuSelected(int); 156 virtual void contextMenuSelected(int);
157 virtual const QString& Delemiter()const; 157 virtual const QString& Delemiter()const;
158protected: 158protected:
159 virtual void createNewFolder(); 159 virtual void createNewFolder();
160 virtual void deleteFolder(); 160 virtual void deleteFolder();
161 virtual void downloadMails(); 161 virtual void downloadMails();
162 IMAPviewItem *imap; 162 IMAPviewItem *imap;
163}; 163};
164 164
165class MHviewItem : public AccountViewItem 165class MHviewItem : public AccountViewItem
166{ 166{
167 friend class MHfolderItem; 167 friend class MHfolderItem;
168 168
169public: 169public:
170 MHviewItem( const QString&aMboxPath, AccountView *parent ); 170 MHviewItem( const QString&aMboxPath, AccountView *parent );
171 virtual ~MHviewItem(); 171 virtual ~MHviewItem();
172 virtual void refresh( QList<RecMail> &target ); 172 virtual void refresh(QValueList<Opie::OSmartPointer<RecMail> >&target );
173 virtual RecBody fetchBody( const RecMail &mail ); 173 virtual RecBody fetchBody( const Opie::OSmartPointer<RecMail> &mail );
174 AbstractMail *getWrapper(); 174 AbstractMail *getWrapper();
175 virtual QPopupMenu * getContextMenu(); 175 virtual QPopupMenu * getContextMenu();
176 virtual void contextMenuSelected(int); 176 virtual void contextMenuSelected(int);
177 QStringList subFolders(); 177 QStringList subFolders();
178 virtual void refresh(bool force=false); 178 virtual void refresh(bool force=false);
179 179
180protected: 180protected:
181 void downloadMails(); 181 void downloadMails();
182 virtual void createFolder(); 182 virtual void createFolder();
183 QString m_Path; 183 QString m_Path;
184 AbstractMail *wrapper; 184 AbstractMail *wrapper;
185 QStringList currentFolders; 185 QStringList currentFolders;
186}; 186};
187 187
188class MHfolderItem : public AccountViewItem 188class MHfolderItem : public AccountViewItem
189{ 189{
190 190
191public: 191public:
192 MHfolderItem( const Opie::osmart_pointer<Folder>&folder, MHviewItem *parent , QListViewItem*after ); 192 MHfolderItem( const Opie::OSmartPointer<Folder>&folder, MHviewItem *parent , QListViewItem*after );
193 MHfolderItem( const Opie::osmart_pointer<Folder>&folder, MHfolderItem *parent, QListViewItem*after, MHviewItem*master); 193 MHfolderItem( const Opie::OSmartPointer<Folder>&folder, MHfolderItem *parent, QListViewItem*after, MHviewItem*master);
194 virtual ~MHfolderItem(); 194 virtual ~MHfolderItem();
195 virtual void refresh(QList<RecMail>&); 195 virtual void refresh(QValueList<Opie::OSmartPointer<RecMail> >&);
196 virtual RecBody fetchBody(const RecMail&); 196 virtual RecBody fetchBody(const Opie::OSmartPointer<RecMail>&);
197 virtual QPopupMenu * getContextMenu(); 197 virtual QPopupMenu * getContextMenu();
198 virtual void contextMenuSelected(int); 198 virtual void contextMenuSelected(int);
199 virtual const Opie::osmart_pointer<Folder>&getFolder()const; 199 virtual const Opie::OSmartPointer<Folder>&getFolder()const;
200 virtual bool isDraftfolder(); 200 virtual bool isDraftfolder();
201 201
202protected: 202protected:
203 void downloadMails(); 203 void downloadMails();
204 virtual void createFolder(); 204 virtual void createFolder();
205 virtual void deleteFolder(); 205 virtual void deleteFolder();
206 void initName(); 206 void initName();
207 MHviewItem *mbox; 207 MHviewItem *mbox;
208}; 208};
209 209
210#endif 210#endif
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp
index 297f553..26107ff 100644
--- a/noncore/net/mail/accountview.cpp
+++ b/noncore/net/mail/accountview.cpp
@@ -1,177 +1,175 @@
1 1
2#include "accountview.h" 2#include "accountview.h"
3#include "accountitem.h" 3#include "accountitem.h"
4#include "selectstore.h" 4#include "selectstore.h"
5 5
6/* OPIE */ 6/* OPIE */
7#include <libmailwrapper/settings.h> 7#include <libmailwrapper/settings.h>
8#include <libmailwrapper/mailwrapper.h> 8#include <libmailwrapper/mailwrapper.h>
9#include <libmailwrapper/mailtypes.h> 9#include <libmailwrapper/mailtypes.h>
10#include <libmailwrapper/abstractmail.h> 10#include <libmailwrapper/abstractmail.h>
11#include <qpe/qpeapplication.h> 11#include <qpe/qpeapplication.h>
12 12
13/* QT */ 13/* QT */
14#include <qmessagebox.h> 14#include <qmessagebox.h>
15#include <qpopupmenu.h> 15#include <qpopupmenu.h>
16 16
17AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) 17AccountView::AccountView( QWidget *parent, const char *name, WFlags flags )
18 : QListView( parent, name, flags ) 18 : QListView( parent, name, flags )
19{ 19{
20 connect( this, SIGNAL( selectionChanged(QListViewItem*) ), 20 connect( this, SIGNAL( selectionChanged(QListViewItem*) ),
21 SLOT( refresh(QListViewItem*) ) ); 21 SLOT( refresh(QListViewItem*) ) );
22 connect( this, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),this, 22 connect( this, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),this,
23 SLOT( slotHold(int,QListViewItem*,const QPoint&,int) ) ); 23 SLOT( slotHold(int,QListViewItem*,const QPoint&,int) ) );
24 setSorting(0); 24 setSorting(0);
25} 25}
26 26
27AccountView::~AccountView() 27AccountView::~AccountView()
28{ 28{
29 imapAccounts.clear(); 29 imapAccounts.clear();
30 mhAccounts.clear(); 30 mhAccounts.clear();
31} 31}
32 32
33void AccountView::slotContextMenu(int id) 33void AccountView::slotContextMenu(int id)
34{ 34{
35 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); 35 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem());
36 if (!view) return; 36 if (!view) return;
37 view->contextMenuSelected(id); 37 view->contextMenuSelected(id);
38} 38}
39 39
40void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int) 40void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int)
41{ 41{
42 if (button==1) {return;} 42 if (button==1) {return;}
43 if (!item) return; 43 if (!item) return;
44 AccountViewItem *view = static_cast<AccountViewItem *>(item); 44 AccountViewItem *view = static_cast<AccountViewItem *>(item);
45 QPopupMenu*m = view->getContextMenu(); 45 QPopupMenu*m = view->getContextMenu();
46 if (!m) return; 46 if (!m) return;
47 connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int))); 47 connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int)));
48 m->setFocus(); 48 m->setFocus();
49 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); 49 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
50 delete m; 50 delete m;
51} 51}
52 52
53void AccountView::populate( QList<Account> list ) 53void AccountView::populate( QList<Account> list )
54{ 54{
55 clear(); 55 clear();
56 56
57 imapAccounts.clear(); 57 imapAccounts.clear();
58 mhAccounts.clear(); 58 mhAccounts.clear();
59 59
60 mhAccounts.append(new MHviewItem(AbstractMail::defaultLocalfolder(),this)); 60 mhAccounts.append(new MHviewItem(AbstractMail::defaultLocalfolder(),this));
61 61
62 Account *it; 62 Account *it;
63 for ( it = list.first(); it; it = list.next() ) 63 for ( it = list.first(); it; it = list.next() )
64 { 64 {
65 if ( it->getType() == MAILLIB::A_IMAP ) 65 if ( it->getType() == MAILLIB::A_IMAP )
66 { 66 {
67 IMAPaccount *imap = static_cast<IMAPaccount *>(it); 67 IMAPaccount *imap = static_cast<IMAPaccount *>(it);
68 qDebug( "added IMAP " + imap->getAccountName() ); 68 qDebug( "added IMAP " + imap->getAccountName() );
69 imapAccounts.append(new IMAPviewItem( imap, this )); 69 imapAccounts.append(new IMAPviewItem( imap, this ));
70 } 70 }
71 else if ( it->getType() == MAILLIB::A_POP3 ) 71 else if ( it->getType() == MAILLIB::A_POP3 )
72 { 72 {
73 POP3account *pop3 = static_cast<POP3account *>(it); 73 POP3account *pop3 = static_cast<POP3account *>(it);
74 qDebug( "added POP3 " + pop3->getAccountName() ); 74 qDebug( "added POP3 " + pop3->getAccountName() );
75 /* must not be hold 'cause it isn't required */ 75 /* must not be hold 'cause it isn't required */
76 (void) new POP3viewItem( pop3, this ); 76 (void) new POP3viewItem( pop3, this );
77 } 77 }
78 else if ( it->getType() == MAILLIB::A_NNTP ) 78 else if ( it->getType() == MAILLIB::A_NNTP )
79 { 79 {
80 NNTPaccount *nntp = static_cast<NNTPaccount *>(it); 80 NNTPaccount *nntp = static_cast<NNTPaccount *>(it);
81 qDebug( "added NNTP " + nntp->getAccountName() ); 81 qDebug( "added NNTP " + nntp->getAccountName() );
82 /* must not be hold 'cause it isn't required */ 82 /* must not be hold 'cause it isn't required */
83 (void) new NNTPviewItem( nntp, this ); 83 (void) new NNTPviewItem( nntp, this );
84 } 84 }
85 } 85 }
86} 86}
87 87
88void AccountView::refresh(QListViewItem *item) 88void AccountView::refresh(QListViewItem *item)
89{ 89{
90 90
91 qDebug("AccountView refresh..."); 91 qDebug("AccountView refresh...");
92 if ( item ) 92 if ( item )
93 { 93 {
94 m_currentItem = item; 94 m_currentItem = item;
95 QList<RecMail> headerlist; 95 QValueList<RecMailP> headerlist;
96 headerlist.setAutoDelete(true);
97 AccountViewItem *view = static_cast<AccountViewItem *>(item); 96 AccountViewItem *view = static_cast<AccountViewItem *>(item);
98 view->refresh(headerlist); 97 view->refresh(headerlist);
99 emit refreshMailview(&headerlist); 98 emit refreshMailview(headerlist);
100 } 99 }
101} 100}
102 101
103void AccountView::refreshCurrent() 102void AccountView::refreshCurrent()
104{ 103{
105 m_currentItem = currentItem(); 104 m_currentItem = currentItem();
106 if ( !m_currentItem ) return; 105 if ( !m_currentItem ) return;
107 QList<RecMail> headerlist; 106 QValueList<RecMailP> headerlist;
108 headerlist.setAutoDelete(true);
109 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); 107 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem);
110 view->refresh(headerlist); 108 view->refresh(headerlist);
111 emit refreshMailview(&headerlist); 109 emit refreshMailview(headerlist);
112} 110}
113 111
114void AccountView::refreshAll() 112void AccountView::refreshAll()
115{ 113{
116} 114}
117 115
118RecBody AccountView::fetchBody(const RecMail&aMail) 116RecBody AccountView::fetchBody(const RecMailP&aMail)
119{ 117{
120 QListViewItem*item = selectedItem (); 118 QListViewItem*item = selectedItem ();
121 if (!item) return RecBody(); 119 if (!item) return RecBody();
122 AccountViewItem *view = static_cast<AccountViewItem *>(item); 120 AccountViewItem *view = static_cast<AccountViewItem *>(item);
123 return view->fetchBody(aMail); 121 return view->fetchBody(aMail);
124} 122}
125 123
126void AccountView::setupFolderselect(Selectstore*sels) 124void AccountView::setupFolderselect(Selectstore*sels)
127{ 125{
128 QPEApplication::showDialog( sels ); 126 QPEApplication::showDialog( sels );
129 QStringList sFolders; 127 QStringList sFolders;
130 unsigned int i = 0; 128 unsigned int i = 0;
131 for (i=0; i < mhAccounts.count();++i) 129 for (i=0; i < mhAccounts.count();++i)
132 { 130 {
133 mhAccounts[i]->refresh(false); 131 mhAccounts[i]->refresh(false);
134 sFolders = mhAccounts[i]->subFolders(); 132 sFolders = mhAccounts[i]->subFolders();
135 sels->addAccounts(mhAccounts[i]->getWrapper(),sFolders); 133 sels->addAccounts(mhAccounts[i]->getWrapper(),sFolders);
136 } 134 }
137 for (i=0; i < imapAccounts.count();++i) 135 for (i=0; i < imapAccounts.count();++i)
138 { 136 {
139 if (imapAccounts[i]->offline()) 137 if (imapAccounts[i]->offline())
140 continue; 138 continue;
141 imapAccounts[i]->refreshFolders(false); 139 imapAccounts[i]->refreshFolders(false);
142 sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders()); 140 sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders());
143 } 141 }
144} 142}
145 143
146void AccountView::downloadMails(const FolderP&fromFolder,AbstractMail*fromWrapper) 144void AccountView::downloadMails(const FolderP&fromFolder,AbstractMail*fromWrapper)
147{ 145{
148 AbstractMail*targetMail = 0; 146 AbstractMail*targetMail = 0;
149 QString targetFolder = ""; 147 QString targetFolder = "";
150 Selectstore sels; 148 Selectstore sels;
151 setupFolderselect(&sels); 149 setupFolderselect(&sels);
152 if (!sels.exec()) return; 150 if (!sels.exec()) return;
153 targetMail = sels.currentMail(); 151 targetMail = sels.currentMail();
154 targetFolder = sels.currentFolder(); 152 targetFolder = sels.currentFolder();
155 if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) || 153 if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) ||
156 targetFolder.isEmpty()) 154 targetFolder.isEmpty())
157 { 155 {
158 return; 156 return;
159 } 157 }
160 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 158 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
161 { 159 {
162 QMessageBox::critical(0,tr("Error creating new Folder"), 160 QMessageBox::critical(0,tr("Error creating new Folder"),
163 tr("<center>Error while creating<br>new folder - breaking.</center>")); 161 tr("<center>Error while creating<br>new folder - breaking.</center>"));
164 return; 162 return;
165 } 163 }
166 qDebug("Targetfolder: %s",targetFolder.latin1()); 164 qDebug("Targetfolder: %s",targetFolder.latin1());
167 qDebug("Fromfolder: %s",fromFolder->getName().latin1()); 165 qDebug("Fromfolder: %s",fromFolder->getName().latin1());
168 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails()); 166 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails());
169 refreshCurrent(); 167 refreshCurrent();
170} 168}
171 169
172bool AccountView::currentisDraft() 170bool AccountView::currentisDraft()
173{ 171{
174 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); 172 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem());
175 if (!view) return false; 173 if (!view) return false;
176 return view->isDraftfolder(); 174 return view->isDraftfolder();
177} 175}
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h
index 3478c0b..d236058 100644
--- a/noncore/net/mail/accountview.h
+++ b/noncore/net/mail/accountview.h
@@ -1,46 +1,45 @@
1#ifndef ACCOUNTVIEW_H 1#ifndef ACCOUNTVIEW_H
2#define ACCOUNTVIEW_H 2#define ACCOUNTVIEW_H
3 3
4#include <qlistview.h> 4#include <qlistview.h>
5#include <qlist.h> 5#include <qlist.h>
6#include <opie2/osmart_pointer.h> 6#include <opie2/osmartpointer.h>
7#include <libmailwrapper/mailtypes.h>
7 8
8class Selectstore; 9class Selectstore;
9class RecMail;
10class RecBody;
11class Folder; 10class Folder;
12class AbstractMail; 11class AbstractMail;
13class Account; 12class Account;
14class IMAPviewItem; 13class IMAPviewItem;
15class MHviewItem; 14class MHviewItem;
16 15
17class AccountView : public QListView 16class AccountView : public QListView
18{ 17{
19 Q_OBJECT 18 Q_OBJECT
20 19
21public: 20public:
22 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 21 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
23 virtual ~AccountView(); 22 virtual ~AccountView();
24 virtual void populate( QList<Account> list ); 23 virtual void populate( QList<Account> list );
25 virtual RecBody fetchBody(const RecMail&aMail); 24 virtual RecBody fetchBody(const Opie::OSmartPointer<RecMail>&aMail);
26 virtual void downloadMails(const Opie::osmart_pointer<Folder>&fromFolder,AbstractMail*fromWrapper); 25 virtual void downloadMails(const Opie::OSmartPointer<Folder>&fromFolder,AbstractMail*fromWrapper);
27 virtual bool currentisDraft(); 26 virtual bool currentisDraft();
28 27
29public slots: 28public slots:
30 virtual void refreshAll(); 29 virtual void refreshAll();
31 virtual void refresh(QListViewItem *item); 30 virtual void refresh(QListViewItem *item);
32 virtual void refreshCurrent(); 31 virtual void refreshCurrent();
33 virtual void slotHold(int, QListViewItem *,const QPoint&,int); 32 virtual void slotHold(int, QListViewItem *,const QPoint&,int);
34 virtual void slotContextMenu(int id); 33 virtual void slotContextMenu(int id);
35 void setupFolderselect(Selectstore*sels); 34 void setupFolderselect(Selectstore*sels);
36 35
37signals: 36signals:
38 void refreshMailview(QList<RecMail>*); 37 void refreshMailview(const QValueList<RecMailP>& );
39 38
40protected: 39protected:
41 QListViewItem* m_currentItem; 40 QListViewItem* m_currentItem;
42 QValueList<IMAPviewItem*> imapAccounts; 41 QValueList<IMAPviewItem*> imapAccounts;
43 QValueList<MHviewItem*> mhAccounts; 42 QValueList<MHviewItem*> mhAccounts;
44}; 43};
45 44
46#endif 45#endif
diff --git a/noncore/net/mail/composemail.cpp b/noncore/net/mail/composemail.cpp
index 445cc5e..74ccc7b 100644
--- a/noncore/net/mail/composemail.cpp
+++ b/noncore/net/mail/composemail.cpp
@@ -1,300 +1,300 @@
1#include <qt.h> 1#include <qt.h>
2 2
3#include <opie2/ofiledialog.h> 3#include <opie2/ofiledialog.h>
4#include <qpe/resource.h> 4#include <qpe/resource.h>
5#include <qpe/config.h> 5#include <qpe/config.h>
6#include <qpe/global.h> 6#include <qpe/global.h>
7#include <qpe/contact.h> 7#include <qpe/contact.h>
8 8
9#include "composemail.h" 9#include "composemail.h"
10 10
11#include <libmailwrapper/smtpwrapper.h> 11#include <libmailwrapper/smtpwrapper.h>
12#include <libmailwrapper/storemail.h> 12#include <libmailwrapper/storemail.h>
13#include <libmailwrapper/abstractmail.h> 13#include <libmailwrapper/abstractmail.h>
14#include <libmailwrapper/mailtypes.h> 14#include <libmailwrapper/mailtypes.h>
15 15
16ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) 16ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags )
17 : ComposeMailUI( parent, name, modal, flags ) 17 : ComposeMailUI( parent, name, modal, flags )
18{ 18{
19 settings = s; 19 settings = s;
20 m_replyid = ""; 20 m_replyid = "";
21 21
22 QString vfilename = Global::applicationFileName("addressbook", 22 QString vfilename = Global::applicationFileName("addressbook",
23 "businesscard.vcf"); 23 "businesscard.vcf");
24 Contact c; 24 Contact c;
25 if (QFile::exists(vfilename)) { 25 if (QFile::exists(vfilename)) {
26 c = Contact::readVCard( vfilename )[0]; 26 c = Contact::readVCard( vfilename )[0];
27 } 27 }
28 28
29 QStringList mails = c.emailList(); 29 QStringList mails = c.emailList();
30 QString defmail = c.defaultEmail(); 30 QString defmail = c.defaultEmail();
31 31
32 if (defmail.length()!=0) { 32 if (defmail.length()!=0) {
33 fromBox->insertItem(defmail); 33 fromBox->insertItem(defmail);
34 } 34 }
35 QStringList::ConstIterator sit = mails.begin(); 35 QStringList::ConstIterator sit = mails.begin();
36 for (;sit!=mails.end();++sit) { 36 for (;sit!=mails.end();++sit) {
37 if ( (*sit)==defmail) 37 if ( (*sit)==defmail)
38 continue; 38 continue;
39 fromBox->insertItem((*sit)); 39 fromBox->insertItem((*sit));
40 } 40 }
41 senderNameEdit->setText(c.firstName()+" "+c.lastName()); 41 senderNameEdit->setText(c.firstName()+" "+c.lastName());
42 Config cfg( "mail" ); 42 Config cfg( "mail" );
43 cfg.setGroup( "Compose" ); 43 cfg.setGroup( "Compose" );
44 checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) ); 44 checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) );
45 45
46 attList->addColumn( tr( "Name" ) ); 46 attList->addColumn( tr( "Name" ) );
47 attList->addColumn( tr( "Size" ) ); 47 attList->addColumn( tr( "Size" ) );
48 48
49 QList<Account> accounts = settings->getAccounts(); 49 QList<Account> accounts = settings->getAccounts();
50 50
51 Account *it; 51 Account *it;
52 for ( it = accounts.first(); it; it = accounts.next() ) { 52 for ( it = accounts.first(); it; it = accounts.next() ) {
53 if ( it->getType()==MAILLIB::A_SMTP ) { 53 if ( it->getType()==MAILLIB::A_SMTP ) {
54 SMTPaccount *smtp = static_cast<SMTPaccount *>(it); 54 SMTPaccount *smtp = static_cast<SMTPaccount *>(it);
55 smtpAccountBox->insertItem( smtp->getAccountName() ); 55 smtpAccountBox->insertItem( smtp->getAccountName() );
56 smtpAccounts.append( smtp ); 56 smtpAccounts.append( smtp );
57 } 57 }
58 } 58 }
59 59
60 if ( smtpAccounts.count() > 0 ) { 60 if ( smtpAccounts.count() > 0 ) {
61 fillValues( smtpAccountBox->currentItem() ); 61 fillValues( smtpAccountBox->currentItem() );
62 } else { 62 } else {
63 QMessageBox::information( this, tr( "Problem" ), 63 QMessageBox::information( this, tr( "Problem" ),
64 tr( "<p>Please create an SMTP account first.</p>" ), 64 tr( "<p>Please create an SMTP account first.</p>" ),
65 tr( "Ok" ) ); 65 tr( "Ok" ) );
66 return; 66 return;
67 } 67 }
68 68
69 connect( smtpAccountBox, SIGNAL( activated(int) ), SLOT( fillValues(int) ) ); 69 connect( smtpAccountBox, SIGNAL( activated(int) ), SLOT( fillValues(int) ) );
70 connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); 70 connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) );
71 connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); 71 connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) );
72 connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); 72 connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) );
73 connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); 73 connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) );
74 connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); 74 connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) );
75 connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); 75 connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) );
76} 76}
77 77
78void ComposeMail::pickAddress( QLineEdit *line ) 78void ComposeMail::pickAddress( QLineEdit *line )
79{ 79{
80 QString names = AddressPicker::getNames(); 80 QString names = AddressPicker::getNames();
81 if ( line->text().isEmpty() ) { 81 if ( line->text().isEmpty() ) {
82 line->setText( names ); 82 line->setText( names );
83 } else if ( !names.isEmpty() ) { 83 } else if ( !names.isEmpty() ) {
84 line->setText( line->text() + ", " + names ); 84 line->setText( line->text() + ", " + names );
85 } 85 }
86} 86}
87 87
88 88
89void ComposeMail::setTo( const QString & to ) 89void ComposeMail::setTo( const QString & to )
90{ 90{
91 toLine->setText( to ); 91 toLine->setText( to );
92} 92}
93 93
94void ComposeMail::setSubject( const QString & subject ) 94void ComposeMail::setSubject( const QString & subject )
95{ 95{
96 subjectLine->setText( subject ); 96 subjectLine->setText( subject );
97} 97}
98 98
99void ComposeMail::setInReplyTo( const QString & messageId ) 99void ComposeMail::setInReplyTo( const QString & messageId )
100{ 100{
101 m_replyid = messageId; 101 m_replyid = messageId;
102} 102}
103 103
104void ComposeMail::setMessage( const QString & text ) 104void ComposeMail::setMessage( const QString & text )
105{ 105{
106 message->setText( text ); 106 message->setText( text );
107} 107}
108 108
109 109
110void ComposeMail::pickAddressTo() 110void ComposeMail::pickAddressTo()
111{ 111{
112 pickAddress( toLine ); 112 pickAddress( toLine );
113} 113}
114 114
115void ComposeMail::pickAddressCC() 115void ComposeMail::pickAddressCC()
116{ 116{
117 pickAddress( ccLine ); 117 pickAddress( ccLine );
118} 118}
119 119
120void ComposeMail::pickAddressBCC() 120void ComposeMail::pickAddressBCC()
121{ 121{
122 pickAddress( bccLine ); 122 pickAddress( bccLine );
123} 123}
124 124
125void ComposeMail::pickAddressReply() 125void ComposeMail::pickAddressReply()
126{ 126{
127 pickAddress( replyLine ); 127 pickAddress( replyLine );
128} 128}
129 129
130void ComposeMail::fillValues( int ) 130void ComposeMail::fillValues( int )
131{ 131{
132#if 0 132#if 0
133 SMTPaccount *smtp = smtpAccounts.at( current ); 133 SMTPaccount *smtp = smtpAccounts.at( current );
134 ccLine->clear(); 134 ccLine->clear();
135 if ( smtp->getUseCC() ) { 135 if ( smtp->getUseCC() ) {
136 ccLine->setText( smtp->getCC() ); 136 ccLine->setText( smtp->getCC() );
137 } 137 }
138 bccLine->clear(); 138 bccLine->clear();
139 if ( smtp->getUseBCC() ) { 139 if ( smtp->getUseBCC() ) {
140 bccLine->setText( smtp->getBCC() ); 140 bccLine->setText( smtp->getBCC() );
141 } 141 }
142 replyLine->clear(); 142 replyLine->clear();
143 if ( smtp->getUseReply() ) { 143 if ( smtp->getUseReply() ) {
144 replyLine->setText( smtp->getReply() ); 144 replyLine->setText( smtp->getReply() );
145 } 145 }
146 sigMultiLine->setText( smtp->getSignature() ); 146 sigMultiLine->setText( smtp->getSignature() );
147#endif 147#endif
148} 148}
149 149
150void ComposeMail::slotAdjustColumns() 150void ComposeMail::slotAdjustColumns()
151{ 151{
152 int currPage = tabWidget->currentPageIndex(); 152 int currPage = tabWidget->currentPageIndex();
153 153
154 tabWidget->showPage( attachTab ); 154 tabWidget->showPage( attachTab );
155 attList->setColumnWidth( 0, attList->visibleWidth() - 80 ); 155 attList->setColumnWidth( 0, attList->visibleWidth() - 80 );
156 attList->setColumnWidth( 1, 80 ); 156 attList->setColumnWidth( 1, 80 );
157 157
158 tabWidget->setCurrentPage( currPage ); 158 tabWidget->setCurrentPage( currPage );
159} 159}
160 160
161void ComposeMail::addAttachment() 161void ComposeMail::addAttachment()
162{ 162{
163 DocLnk lnk = Opie::OFileDialog::getOpenFileName( 1, "/" ); 163 DocLnk lnk = Opie::OFileDialog::getOpenFileName( 1, "/" );
164 if ( !lnk.name().isEmpty() ) { 164 if ( !lnk.name().isEmpty() ) {
165 Attachment *att = new Attachment( lnk ); 165 Attachment *att = new Attachment( lnk );
166 (void) new AttachViewItem( attList, att ); 166 (void) new AttachViewItem( attList, att );
167 } 167 }
168} 168}
169 169
170void ComposeMail::removeAttachment() 170void ComposeMail::removeAttachment()
171{ 171{
172 if ( !attList->currentItem() ) { 172 if ( !attList->currentItem() ) {
173 QMessageBox::information( this, tr( "Error" ), 173 QMessageBox::information( this, tr( "Error" ),
174 tr( "<p>Please select a File.</p>" ), 174 tr( "<p>Please select a File.</p>" ),
175 tr( "Ok" ) ); 175 tr( "Ok" ) );
176 } else { 176 } else {
177 attList->takeItem( attList->currentItem() ); 177 attList->takeItem( attList->currentItem() );
178 } 178 }
179} 179}
180 180
181void ComposeMail::accept() 181void ComposeMail::accept()
182{ 182{
183 if ( checkBoxLater->isChecked() ) { 183 if ( checkBoxLater->isChecked() ) {
184 qDebug( "Send later" ); 184 qDebug( "Send later" );
185 } 185 }
186 186
187#if 0 187#if 0
188 qDebug( "Sending Mail with " + 188 qDebug( "Sending Mail with " +
189 smtpAccounts.at( smtpAccountBox->currentItem() )->getAccountName() ); 189 smtpAccounts.at( smtpAccountBox->currentItem() )->getAccountName() );
190#endif 190#endif
191 Opie::osmart_pointer<Mail> mail=new Mail; 191 Opie::OSmartPointer<Mail> mail=new Mail;
192 192
193 SMTPaccount *smtp = smtpAccounts.at( smtpAccountBox->currentItem() ); 193 SMTPaccount *smtp = smtpAccounts.at( smtpAccountBox->currentItem() );
194 mail->setMail(fromBox->currentText()); 194 mail->setMail(fromBox->currentText());
195 195
196 if ( !toLine->text().isEmpty() ) { 196 if ( !toLine->text().isEmpty() ) {
197 mail->setTo( toLine->text() ); 197 mail->setTo( toLine->text() );
198 } else { 198 } else {
199 QMessageBox::warning(0,tr("Sending mail"), 199 QMessageBox::warning(0,tr("Sending mail"),
200 tr("No Receiver spezified" ) ); 200 tr("No Receiver spezified" ) );
201 return; 201 return;
202 } 202 }
203 mail->setName(senderNameEdit->text()); 203 mail->setName(senderNameEdit->text());
204 mail->setCC( ccLine->text() ); 204 mail->setCC( ccLine->text() );
205 mail->setBCC( bccLine->text() ); 205 mail->setBCC( bccLine->text() );
206 mail->setReply( replyLine->text() ); 206 mail->setReply( replyLine->text() );
207 mail->setSubject( subjectLine->text() ); 207 mail->setSubject( subjectLine->text() );
208 if (!m_replyid.isEmpty()) { 208 if (!m_replyid.isEmpty()) {
209 QStringList ids; 209 QStringList ids;
210 ids.append(m_replyid); 210 ids.append(m_replyid);
211 mail->setInreply(ids); 211 mail->setInreply(ids);
212 } 212 }
213 QString txt = message->text(); 213 QString txt = message->text();
214 if ( !sigMultiLine->text().isEmpty() ) { 214 if ( !sigMultiLine->text().isEmpty() ) {
215 txt.append( "\n--\n" ); 215 txt.append( "\n--\n" );
216 txt.append( sigMultiLine->text() ); 216 txt.append( sigMultiLine->text() );
217 } 217 }
218 mail->setMessage( txt ); 218 mail->setMessage( txt );
219 AttachViewItem *it = (AttachViewItem *) attList->firstChild(); 219 AttachViewItem *it = (AttachViewItem *) attList->firstChild();
220 while ( it != NULL ) { 220 while ( it != NULL ) {
221 mail->addAttachment( it->getAttachment() ); 221 mail->addAttachment( it->getAttachment() );
222 it = (AttachViewItem *) it->nextSibling(); 222 it = (AttachViewItem *) it->nextSibling();
223 } 223 }
224 224
225 SMTPwrapper wrapper( smtp ); 225 SMTPwrapper wrapper( smtp );
226 wrapper.sendMail( mail,checkBoxLater->isChecked() ); 226 wrapper.sendMail( mail,checkBoxLater->isChecked() );
227 227
228 QDialog::accept(); 228 QDialog::accept();
229} 229}
230 230
231void ComposeMail::reject() 231void ComposeMail::reject()
232{ 232{
233 int yesno = QMessageBox::warning(0,tr("Store message"), 233 int yesno = QMessageBox::warning(0,tr("Store message"),
234 tr("Store message into drafts?"), 234 tr("Store message into drafts?"),
235 tr("Yes"), 235 tr("Yes"),
236 tr("No"),QString::null,0,1); 236 tr("No"),QString::null,0,1);
237 237
238 if (yesno == 0) { 238 if (yesno == 0) {
239 Opie::osmart_pointer<Mail> mail=new Mail(); 239 Opie::OSmartPointer<Mail> mail=new Mail();
240 mail->setMail(fromBox->currentText()); 240 mail->setMail(fromBox->currentText());
241 mail->setTo( toLine->text() ); 241 mail->setTo( toLine->text() );
242 mail->setName(senderNameEdit->text()); 242 mail->setName(senderNameEdit->text());
243 mail->setCC( ccLine->text() ); 243 mail->setCC( ccLine->text() );
244 mail->setBCC( bccLine->text() ); 244 mail->setBCC( bccLine->text() );
245 mail->setReply( replyLine->text() ); 245 mail->setReply( replyLine->text() );
246 mail->setSubject( subjectLine->text() ); 246 mail->setSubject( subjectLine->text() );
247 if (!m_replyid.isEmpty()) { 247 if (!m_replyid.isEmpty()) {
248 QStringList ids; 248 QStringList ids;
249 ids.append(m_replyid); 249 ids.append(m_replyid);
250 mail->setInreply(ids); 250 mail->setInreply(ids);
251 } 251 }
252 QString txt = message->text(); 252 QString txt = message->text();
253 if ( !sigMultiLine->text().isEmpty() ) { 253 if ( !sigMultiLine->text().isEmpty() ) {
254 txt.append( "\n--\n" ); 254 txt.append( "\n--\n" );
255 txt.append( sigMultiLine->text() ); 255 txt.append( sigMultiLine->text() );
256 } 256 }
257 qDebug(txt); 257 qDebug(txt);
258 mail->setMessage( txt ); 258 mail->setMessage( txt );
259 259
260 /* only use the default drafts folder name! */ 260 /* only use the default drafts folder name! */
261 Storemail wrapper(AbstractMail::draftFolder()); 261 Storemail wrapper(AbstractMail::draftFolder());
262 wrapper.storeMail(mail); 262 wrapper.storeMail(mail);
263 263
264 AttachViewItem *it = (AttachViewItem *) attList->firstChild(); 264 AttachViewItem *it = (AttachViewItem *) attList->firstChild();
265 /* attachments we will ignore! */ 265 /* attachments we will ignore! */
266 if ( it != NULL ) { 266 if ( it != NULL ) {
267 QMessageBox::warning(0,tr("Store message"), 267 QMessageBox::warning(0,tr("Store message"),
268 tr("<center>Attachments will not be stored in \"Draft\" folder</center>")); 268 tr("<center>Attachments will not be stored in \"Draft\" folder</center>"));
269 } 269 }
270 } 270 }
271 QDialog::reject(); 271 QDialog::reject();
272} 272}
273 273
274ComposeMail::~ComposeMail() 274ComposeMail::~ComposeMail()
275{ 275{
276} 276}
277 277
278void ComposeMail::reEditMail(const RecMail&current) 278void ComposeMail::reEditMail(const RecMailP&current)
279{ 279{
280 RecMail data = current; 280 RecMailP data = current;
281 message->setText(data.Wrapper()->fetchBody(current).Bodytext()); 281 message->setText(data->Wrapper()->fetchBody(current).Bodytext());
282 subjectLine->setText( data.getSubject()); 282 subjectLine->setText( data->getSubject());
283 toLine->setText(data.To().join(",")); 283 toLine->setText(data->To().join(","));
284 ccLine->setText(data.CC().join(",")); 284 ccLine->setText(data->CC().join(","));
285 bccLine->setText(data.Bcc().join(",")); 285 bccLine->setText(data->Bcc().join(","));
286 replyLine->setText(data.Replyto()); 286 replyLine->setText(data->Replyto());
287} 287}
288 288
289AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) 289AttachViewItem::AttachViewItem( QListView *parent, Attachment *att )
290 : QListViewItem( parent ) 290 : QListViewItem( parent )
291{ 291{
292 attachment = att; 292 attachment = att;
293 qDebug( att->getMimeType() ); 293 qDebug( att->getMimeType() );
294 setPixmap( 0, attachment->getDocLnk().pixmap().isNull() ? 294 setPixmap( 0, attachment->getDocLnk().pixmap().isNull() ?
295 Resource::loadPixmap( "UnknownDocument-14" ) : 295 Resource::loadPixmap( "UnknownDocument-14" ) :
296 attachment->getDocLnk().pixmap() ); 296 attachment->getDocLnk().pixmap() );
297 setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() ); 297 setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() );
298 setText( 1, QString::number( att->getSize() ) ); 298 setText( 1, QString::number( att->getSize() ) );
299} 299}
300 300
diff --git a/noncore/net/mail/composemail.h b/noncore/net/mail/composemail.h
index 1b9fc79..c12eb30 100644
--- a/noncore/net/mail/composemail.h
+++ b/noncore/net/mail/composemail.h
@@ -1,79 +1,81 @@
1#ifndef COMPOSEMAIL_H 1#ifndef COMPOSEMAIL_H
2#define COMPOSEMAIL_H 2#define COMPOSEMAIL_H
3 3
4#include <qlineedit.h> 4#include <qlineedit.h>
5#include <qlistview.h> 5#include <qlistview.h>
6 6
7#include "composemailui.h" 7#include "composemailui.h"
8#include "addresspickerui.h" 8#include "addresspickerui.h"
9#include <libmailwrapper/settings.h> 9#include <libmailwrapper/settings.h>
10#include <libmailwrapper/mailwrapper.h> 10#include <libmailwrapper/mailwrapper.h>
11 11
12class RecMail;
12 13
14#include <opie2/osmartpointer.h>
13 15
14class AddressPicker : public AddressPickerUI 16class AddressPicker : public AddressPickerUI
15{ 17{
16 Q_OBJECT 18 Q_OBJECT
17 19
18public: 20public:
19 AddressPicker( QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags flags = 0 ); 21 AddressPicker( QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags flags = 0 );
20 static QString getNames(); 22 static QString getNames();
21 23
22protected: 24protected:
23 QString selectedNames; 25 QString selectedNames;
24 void accept(); 26 void accept();
25 27
26}; 28};
27 29
28class RecMail; 30class RecMail;
29 31
30class ComposeMail : public ComposeMailUI 32class ComposeMail : public ComposeMailUI
31{ 33{
32 Q_OBJECT 34 Q_OBJECT
33 35
34public: 36public:
35 ComposeMail( Settings *s, QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags flags = 0 ); 37 ComposeMail( Settings *s, QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags flags = 0 );
36 virtual ~ComposeMail(); 38 virtual ~ComposeMail();
37 39
38 void reEditMail(const RecMail&current); 40 void reEditMail(const Opie::OSmartPointer<RecMail>&current);
39 41
40public slots: 42public slots:
41 void slotAdjustColumns(); 43 void slotAdjustColumns();
42 44
43 void setTo( const QString & to ); 45 void setTo( const QString & to );
44 void setSubject( const QString & subject ); 46 void setSubject( const QString & subject );
45 void setInReplyTo( const QString & messageId ); 47 void setInReplyTo( const QString & messageId );
46 void setMessage( const QString & text ); 48 void setMessage( const QString & text );
47 49
48protected slots: 50protected slots:
49 void accept(); 51 void accept();
50 void reject(); 52 void reject();
51 53
52private slots: 54private slots:
53 void fillValues( int current ); 55 void fillValues( int current );
54 void pickAddress( QLineEdit *line ); 56 void pickAddress( QLineEdit *line );
55 void pickAddressTo(); 57 void pickAddressTo();
56 void pickAddressCC(); 58 void pickAddressCC();
57 void pickAddressBCC(); 59 void pickAddressBCC();
58 void pickAddressReply(); 60 void pickAddressReply();
59 void addAttachment(); 61 void addAttachment();
60 void removeAttachment(); 62 void removeAttachment();
61 63
62protected: 64protected:
63 Settings *settings; 65 Settings *settings;
64 QList<SMTPaccount> smtpAccounts; 66 QList<SMTPaccount> smtpAccounts;
65 QString m_replyid; 67 QString m_replyid;
66}; 68};
67 69
68class AttachViewItem : public QListViewItem 70class AttachViewItem : public QListViewItem
69{ 71{
70public: 72public:
71 AttachViewItem( QListView *parent, Attachment *att ); 73 AttachViewItem( QListView *parent, Attachment *att );
72 Attachment *getAttachment() { return attachment; } 74 Attachment *getAttachment() { return attachment; }
73 75
74private: 76private:
75 Attachment *attachment; 77 Attachment *attachment;
76 78
77}; 79};
78 80
79#endif 81#endif
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp
index 7e6d383..68a7a4d 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.cpp
+++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp
@@ -1,167 +1,167 @@
1#include "abstractmail.h" 1#include "abstractmail.h"
2#include "imapwrapper.h" 2#include "imapwrapper.h"
3#include "pop3wrapper.h" 3#include "pop3wrapper.h"
4#include "nntpwrapper.h" 4#include "nntpwrapper.h"
5#include "mhwrapper.h" 5#include "mhwrapper.h"
6#include "mailtypes.h" 6#include "mailtypes.h"
7 7
8#include <qfile.h> 8#include <qfile.h>
9#include <qtextstream.h> 9#include <qtextstream.h>
10#include <stdlib.h> 10#include <stdlib.h>
11#include <libetpan/mailmime_content.h> 11#include <libetpan/mailmime_content.h>
12#include <libetpan/mailmime.h> 12#include <libetpan/mailmime.h>
13 13
14AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 14AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
15{ 15{
16 return new IMAPwrapper(a); 16 return new IMAPwrapper(a);
17} 17}
18 18
19AbstractMail* AbstractMail::getWrapper(POP3account *a) 19AbstractMail* AbstractMail::getWrapper(POP3account *a)
20{ 20{
21 return new POP3wrapper(a); 21 return new POP3wrapper(a);
22} 22}
23 23
24AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) 24AbstractMail* AbstractMail::getWrapper(NNTPaccount *a)
25{ 25{
26 return new NNTPwrapper(a); 26 return new NNTPwrapper(a);
27} 27}
28 28
29AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) 29AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name)
30{ 30{
31 return new MHwrapper(a,name); 31 return new MHwrapper(a,name);
32} 32}
33 33
34AbstractMail* AbstractMail::getWrapper(Account*a) 34AbstractMail* AbstractMail::getWrapper(Account*a)
35{ 35{
36 if (!a) return 0; 36 if (!a) return 0;
37 switch (a->getType()) { 37 switch (a->getType()) {
38 case MAILLIB::A_IMAP: 38 case MAILLIB::A_IMAP:
39 return new IMAPwrapper((IMAPaccount*)a); 39 return new IMAPwrapper((IMAPaccount*)a);
40 break; 40 break;
41 case MAILLIB::A_POP3: 41 case MAILLIB::A_POP3:
42 return new POP3wrapper((POP3account*)a); 42 return new POP3wrapper((POP3account*)a);
43 break; 43 break;
44 case MAILLIB::A_NNTP: 44 case MAILLIB::A_NNTP:
45 return new NNTPwrapper((NNTPaccount*)a); 45 return new NNTPwrapper((NNTPaccount*)a);
46 break; 46 break;
47 default: 47 default:
48 return 0; 48 return 0;
49 } 49 }
50} 50}
51 51
52encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 52encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
53{ 53{
54 qDebug("Decode string start"); 54 qDebug("Decode string start");
55 char*result_text; 55 char*result_text;
56 size_t index = 0; 56 size_t index = 0;
57 /* reset for recursive use! */ 57 /* reset for recursive use! */
58 size_t target_length = 0; 58 size_t target_length = 0;
59 result_text = 0; 59 result_text = 0;
60 int mimetype = MAILMIME_MECHANISM_7BIT; 60 int mimetype = MAILMIME_MECHANISM_7BIT;
61 if (enc.lower()=="quoted-printable") { 61 if (enc.lower()=="quoted-printable") {
62 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 62 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
63 } else if (enc.lower()=="base64") { 63 } else if (enc.lower()=="base64") {
64 mimetype = MAILMIME_MECHANISM_BASE64; 64 mimetype = MAILMIME_MECHANISM_BASE64;
65 } else if (enc.lower()=="8bit") { 65 } else if (enc.lower()=="8bit") {
66 mimetype = MAILMIME_MECHANISM_8BIT; 66 mimetype = MAILMIME_MECHANISM_8BIT;
67 } else if (enc.lower()=="binary") { 67 } else if (enc.lower()=="binary") {
68 mimetype = MAILMIME_MECHANISM_BINARY; 68 mimetype = MAILMIME_MECHANISM_BINARY;
69 } 69 }
70 70
71 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 71 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
72 &result_text,&target_length); 72 &result_text,&target_length);
73 73
74 encodedString* result = new encodedString(); 74 encodedString* result = new encodedString();
75 if (err == MAILIMF_NO_ERROR) { 75 if (err == MAILIMF_NO_ERROR) {
76 result->setContent(result_text,target_length); 76 result->setContent(result_text,target_length);
77 } 77 }
78 qDebug("Decode string finished"); 78 qDebug("Decode string finished");
79 return result; 79 return result;
80} 80}
81 81
82QString AbstractMail::convert_String(const char*text) 82QString AbstractMail::convert_String(const char*text)
83{ 83{
84 size_t index = 0; 84 //size_t index = 0;
85 char*res = 0; 85 char*res = 0;
86 int err = MAILIMF_NO_ERROR; 86 int err = MAILIMF_NO_ERROR;
87 87
88 QString result(text); 88 QString result(text);
89 89
90 /* due a bug in libetpan it isn't usable this moment */ 90 /* due a bug in libetpan it isn't usable this moment */
91/* int err = mailmime_encoded_phrase_parse("iso-8859-1", 91/* int err = mailmime_encoded_phrase_parse("iso-8859-1",
92 text, strlen(text),&index, "iso-8859-1",&res);*/ 92 text, strlen(text),&index, "iso-8859-1",&res);*/
93 //qDebug("Input: %s",text); 93 //qDebug("Input: %s",text);
94 if (err == MAILIMF_NO_ERROR && res && strlen(res)) { 94 if (err == MAILIMF_NO_ERROR && res && strlen(res)) {
95// result = QString(res); 95// result = QString(res);
96// qDebug("Res: %s, length: %i",res,strlen(res)); 96// qDebug("Res: %s, length: %i",res,strlen(res));
97 } 97 }
98 if (res) free(res); 98 if (res) free(res);
99 return result; 99 return result;
100} 100}
101 101
102/* cp & paste from launcher */ 102/* cp & paste from launcher */
103QString AbstractMail::gen_attachment_id() 103QString AbstractMail::gen_attachment_id()
104{ 104{
105 QFile file( "/proc/sys/kernel/random/uuid" ); 105 QFile file( "/proc/sys/kernel/random/uuid" );
106 if (!file.open(IO_ReadOnly ) ) 106 if (!file.open(IO_ReadOnly ) )
107 return QString::null; 107 return QString::null;
108 108
109 QTextStream stream(&file); 109 QTextStream stream(&file);
110 110
111 return "{" + stream.read().stripWhiteSpace() + "}"; 111 return "{" + stream.read().stripWhiteSpace() + "}";
112} 112}
113 113
114int AbstractMail::createMbox(const QString&,const FolderP&,const QString& delemiter,bool) 114int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool)
115{ 115{
116 return 0; 116 return 0;
117} 117}
118 118
119QString AbstractMail::defaultLocalfolder() 119QString AbstractMail::defaultLocalfolder()
120{ 120{
121 QString f = getenv( "HOME" ); 121 QString f = getenv( "HOME" );
122 f += "/Applications/opiemail/localmail"; 122 f += "/Applications/opiemail/localmail";
123 return f; 123 return f;
124} 124}
125 125
126QString AbstractMail::draftFolder() 126QString AbstractMail::draftFolder()
127{ 127{
128 return QString("Drafts"); 128 return QString("Drafts");
129} 129}
130 130
131/* temporary - will be removed when implemented in all classes */ 131/* temporary - will be removed when implemented in all classes */
132void AbstractMail::deleteMails(const QString &,QList<RecMail> &) 132void AbstractMail::deleteMails(const QString &,const QValueList<Opie::OSmartPointer<RecMail> > &)
133{ 133{
134} 134}
135 135
136void AbstractMail::mvcpAllMails(const FolderP&fromFolder, 136void AbstractMail::mvcpAllMails(const FolderP&fromFolder,
137 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 137 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
138{ 138{
139 QList<RecMail> t; 139 QValueList<RecMailP> t;
140 listMessages(fromFolder->getName(),t); 140 listMessages(fromFolder->getName(),t);
141 encodedString*st = 0; 141 encodedString*st = 0;
142 while (t.count()>0) { 142 while (t.count()>0) {
143 RecMail*r = t.at(0); 143 RecMailP r = (*t.begin());
144 st = fetchRawBody(*r); 144 st = fetchRawBody(r);
145 if (st) { 145 if (st) {
146 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 146 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
147 delete st; 147 delete st;
148 } 148 }
149 t.removeFirst(); 149 t.remove(t.begin());
150 } 150 }
151 if (moveit) { 151 if (moveit) {
152 deleteAllMail(fromFolder); 152 deleteAllMail(fromFolder);
153 } 153 }
154} 154}
155 155
156void AbstractMail::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 156void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
157{ 157{
158 encodedString*st = 0; 158 encodedString*st = 0;
159 st = fetchRawBody(mail); 159 st = fetchRawBody(mail);
160 if (st) { 160 if (st) {
161 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 161 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
162 delete st; 162 delete st;
163 } 163 }
164 if (moveit) { 164 if (moveit) {
165 deleteMail(mail); 165 deleteMail(mail);
166 } 166 }
167} 167}
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h
index d911468..b03d757 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.h
+++ b/noncore/net/mail/libmailwrapper/abstractmail.h
@@ -1,74 +1,72 @@
1#ifndef __abstract_mail_ 1#ifndef __abstract_mail_
2#define __abstract_mail_ 2#define __abstract_mail_
3 3
4#include "maildefines.h" 4#include "maildefines.h"
5 5
6#include "settings.h" 6#include "settings.h"
7 7
8#include <qobject.h> 8#include <qobject.h>
9#include <opie2/osmart_pointer.h> 9#include <opie2/osmartpointer.h>
10#include "mailtypes.h"
10 11
11class RecMail;
12class RecBody;
13class RecPart;
14class IMAPwrapper; 12class IMAPwrapper;
15class POP3wrapper; 13class POP3wrapper;
16class Folder; 14class Folder;
17class encodedString; 15class encodedString;
18struct folderStat; 16struct folderStat;
19 17
20class AbstractMail:public QObject 18class AbstractMail:public QObject
21{ 19{
22 Q_OBJECT 20 Q_OBJECT
23public: 21public:
24 AbstractMail(){}; 22 AbstractMail(){};
25 virtual ~AbstractMail(){} 23 virtual ~AbstractMail(){}
26 virtual QValueList<Opie::osmart_pointer<Folder> >* listFolders()=0; 24 virtual QValueList<Opie::OSmartPointer<Folder> >* listFolders()=0;
27 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; 25 virtual void listMessages(const QString & mailbox,QValueList<RecMailP>&target )=0;
28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0; 26 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0;
29 virtual RecBody fetchBody(const RecMail&mail)=0; 27 virtual RecBody fetchBody(const RecMailP&mail)=0;
30 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; 28 virtual QString fetchTextPart(const RecMailP&mail,const RecPart&part)=0;
31 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; 29 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPart&part)=0;
32 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; 30 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPart&part)=0;
33 virtual encodedString* fetchRawBody(const RecMail&mail)=0; 31 virtual encodedString* fetchRawBody(const RecMailP&mail)=0;
34 32
35 virtual void deleteMail(const RecMail&mail)=0; 33 virtual void deleteMail(const RecMailP&mail)=0;
36 virtual void answeredMail(const RecMail&mail)=0; 34 virtual void answeredMail(const RecMailP&mail)=0;
37 virtual int deleteAllMail(const Opie::osmart_pointer<Folder>&)=0; 35 virtual int deleteAllMail(const Opie::OSmartPointer<Folder>&)=0;
38 virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); 36 virtual void deleteMails(const QString & FolderName,const QValueList<Opie::OSmartPointer<RecMail> >&target);
39 virtual int deleteMbox(const Opie::osmart_pointer<Folder>&)=0; 37 virtual int deleteMbox(const Opie::OSmartPointer<Folder>&)=0;
40 virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0; 38 virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0;
41 39
42 virtual void mvcpAllMails(const Opie::osmart_pointer<Folder>&fromFolder, 40 virtual void mvcpAllMails(const Opie::OSmartPointer<Folder>&fromFolder,
43 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 41 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
44 virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 42 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
45 43
46 virtual void cleanMimeCache(){}; 44 virtual void cleanMimeCache(){};
47 /* mail box methods */ 45 /* mail box methods */
48 /* parameter is the box to create. 46 /* parameter is the box to create.
49 * if the implementing subclass has prefixes, 47 * if the implementing subclass has prefixes,
50 * them has to be appended automatic. 48 * them has to be appended automatic.
51 */ 49 */
52 virtual int createMbox(const QString&,const Opie::osmart_pointer<Folder>&parentfolder=0, 50 virtual int createMbox(const QString&,const Opie::OSmartPointer<Folder>&parentfolder=0,
53 const QString& delemiter="/",bool getsubfolder=false); 51 const QString& delemiter="/",bool getsubfolder=false);
54 virtual void logout()=0; 52 virtual void logout()=0;
55 53
56 static AbstractMail* getWrapper(IMAPaccount *a); 54 static AbstractMail* getWrapper(IMAPaccount *a);
57 static AbstractMail* getWrapper(POP3account *a); 55 static AbstractMail* getWrapper(POP3account *a);
58 static AbstractMail* getWrapper(NNTPaccount *a); 56 static AbstractMail* getWrapper(NNTPaccount *a);
59 /* mbox only! */ 57 /* mbox only! */
60 static AbstractMail* getWrapper(const QString&a,const QString&name="Local Folders"); 58 static AbstractMail* getWrapper(const QString&a,const QString&name="Local Folders");
61 static AbstractMail* getWrapper(Account*a); 59 static AbstractMail* getWrapper(Account*a);
62 60
63 static QString defaultLocalfolder(); 61 static QString defaultLocalfolder();
64 static QString draftFolder(); 62 static QString draftFolder();
65 63
66 virtual MAILLIB::ATYPE getType()const=0; 64 virtual MAILLIB::ATYPE getType()const=0;
67 virtual const QString&getName()const=0; 65 virtual const QString&getName()const=0;
68 66
69protected: 67protected:
70 static encodedString*decode_String(const encodedString*text,const QString&enc); 68 static encodedString*decode_String(const encodedString*text,const QString&enc);
71 static QString convert_String(const char*text); 69 static QString convert_String(const char*text);
72 static QString gen_attachment_id(); 70 static QString gen_attachment_id();
73}; 71};
74#endif 72#endif
diff --git a/noncore/net/mail/libmailwrapper/generatemail.cpp b/noncore/net/mail/libmailwrapper/generatemail.cpp
index 4f7ec0c..cb7ccc0 100644
--- a/noncore/net/mail/libmailwrapper/generatemail.cpp
+++ b/noncore/net/mail/libmailwrapper/generatemail.cpp
@@ -1,467 +1,467 @@
1#include "generatemail.h" 1#include "generatemail.h"
2#include "mailwrapper.h" 2#include "mailwrapper.h"
3 3
4#include <libetpan/libetpan.h> 4#include <libetpan/libetpan.h>
5 5
6#include <qt.h> 6#include <qt.h>
7 7
8const char* Generatemail::USER_AGENT="OpieMail v0.6"; 8const char* Generatemail::USER_AGENT="OpieMail v0.6";
9 9
10Generatemail::Generatemail() 10Generatemail::Generatemail()
11{ 11{
12} 12}
13 13
14Generatemail::~Generatemail() 14Generatemail::~Generatemail()
15{ 15{
16} 16}
17 17
18void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) { 18void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) {
19 clistiter *it, *it2; 19 clistiter *it, *it2;
20 20
21 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { 21 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) {
22 mailimf_address *addr; 22 mailimf_address *addr;
23 addr = (mailimf_address *) it->data; 23 addr = (mailimf_address *) it->data;
24 24
25 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { 25 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) {
26 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); 26 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL );
27 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { 27 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) {
28 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; 28 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list;
29 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { 29 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
30 mailimf_mailbox *mbox; 30 mailimf_mailbox *mbox;
31 mbox = (mailimf_mailbox *) it2->data; 31 mbox = (mailimf_mailbox *) it2->data;
32 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); 32 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL );
33 } 33 }
34 } 34 }
35 } 35 }
36} 36}
37 37
38char *Generatemail::getFrom( mailimf_field *ffrom) { 38char *Generatemail::getFrom( mailimf_field *ffrom) {
39 char *from = NULL; 39 char *from = NULL;
40 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) 40 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM)
41 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { 41 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) {
42 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; 42 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list;
43 clistiter *it; 43 clistiter *it;
44 for ( it = clist_begin( cl ); it; it = it->next ) { 44 for ( it = clist_begin( cl ); it; it = it->next ) {
45 mailimf_mailbox *mb = (mailimf_mailbox *) it->data; 45 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
46 from = strdup( mb->mb_addr_spec ); 46 from = strdup( mb->mb_addr_spec );
47 } 47 }
48 } 48 }
49 49
50 return from; 50 return from;
51} 51}
52 52
53char *Generatemail::getFrom( mailmime *mail ) { 53char *Generatemail::getFrom( mailmime *mail ) {
54 /* no need to delete - its just a pointer to structure content */ 54 /* no need to delete - its just a pointer to structure content */
55 mailimf_field *ffrom = 0; 55 mailimf_field *ffrom = 0;
56 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); 56 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
57 return getFrom(ffrom); 57 return getFrom(ffrom);
58} 58}
59 59
60mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) { 60mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) {
61 mailimf_field *field; 61 mailimf_field *field;
62 clistiter *it; 62 clistiter *it;
63 63
64 it = clist_begin( fields->fld_list ); 64 it = clist_begin( fields->fld_list );
65 while ( it ) { 65 while ( it ) {
66 field = (mailimf_field *) it->data; 66 field = (mailimf_field *) it->data;
67 if ( field->fld_type == type ) { 67 if ( field->fld_type == type ) {
68 return field; 68 return field;
69 } 69 }
70 it = it->next; 70 it = it->next;
71 } 71 }
72 72
73 return NULL; 73 return NULL;
74} 74}
75 75
76mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) { 76mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) {
77 mailimf_address_list *addresses; 77 mailimf_address_list *addresses;
78 78
79 if ( addr.isEmpty() ) 79 if ( addr.isEmpty() )
80 return NULL; 80 return NULL;
81 81
82 addresses = mailimf_address_list_new_empty(); 82 addresses = mailimf_address_list_new_empty();
83 83
84 bool literal_open = false; 84 bool literal_open = false;
85 unsigned int startpos = 0; 85 unsigned int startpos = 0;
86 QStringList list; 86 QStringList list;
87 QString s; 87 QString s;
88 unsigned int i = 0; 88 unsigned int i = 0;
89 for (; i < addr.length();++i) { 89 for (; i < addr.length();++i) {
90 switch (addr[i]) { 90 switch (addr[i]) {
91 case '\"': 91 case '\"':
92 literal_open = !literal_open; 92 literal_open = !literal_open;
93 break; 93 break;
94 case ',': 94 case ',':
95 if (!literal_open) { 95 if (!literal_open) {
96 s = addr.mid(startpos,i-startpos); 96 s = addr.mid(startpos,i-startpos);
97 if (!s.isEmpty()) { 97 if (!s.isEmpty()) {
98 list.append(s); 98 list.append(s);
99 qDebug("Appended %s",s.latin1()); 99 qDebug("Appended %s",s.latin1());
100 } 100 }
101 // !!!! this is a MUST BE! 101 // !!!! this is a MUST BE!
102 startpos = ++i; 102 startpos = ++i;
103 } 103 }
104 break; 104 break;
105 default: 105 default:
106 break; 106 break;
107 } 107 }
108 } 108 }
109 s = addr.mid(startpos,i-startpos); 109 s = addr.mid(startpos,i-startpos);
110 if (!s.isEmpty()) { 110 if (!s.isEmpty()) {
111 list.append(s); 111 list.append(s);
112 qDebug("Appended %s",s.latin1()); 112 qDebug("Appended %s",s.latin1());
113 } 113 }
114 QStringList::Iterator it; 114 QStringList::Iterator it;
115 for ( it = list.begin(); it != list.end(); it++ ) { 115 for ( it = list.begin(); it != list.end(); it++ ) {
116 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); 116 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() );
117 if ( err != MAILIMF_NO_ERROR ) { 117 if ( err != MAILIMF_NO_ERROR ) {
118 qDebug( "Error parsing" ); 118 qDebug( "Error parsing" );
119 qDebug( *it ); 119 qDebug( *it );
120 } else { 120 } else {
121 qDebug( "Parse success! %s",(*it).latin1()); 121 qDebug( "Parse success! %s",(*it).latin1());
122 } 122 }
123 } 123 }
124 return addresses; 124 return addresses;
125} 125}
126 126
127mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) { 127mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) {
128 mailmime * filePart = 0; 128 mailmime * filePart = 0;
129 mailmime_fields * fields = 0; 129 mailmime_fields * fields = 0;
130 mailmime_content * content = 0; 130 mailmime_content * content = 0;
131 mailmime_parameter * param = 0; 131 mailmime_parameter * param = 0;
132 char*name = 0; 132 char*name = 0;
133 char*file = 0; 133 char*file = 0;
134 int err; 134 int err;
135 135
136 int pos = filename.findRev( '/' ); 136 int pos = filename.findRev( '/' );
137 137
138 if (filename.length()>0) { 138 if (filename.length()>0) {
139 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 139 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
140 name = strdup( tmp.latin1() ); // just filename 140 name = strdup( tmp.latin1() ); // just filename
141 file = strdup( filename.latin1() ); // full name with path 141 file = strdup( filename.latin1() ); // full name with path
142 } 142 }
143 143
144 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; 144 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
145 int mechanism = MAILMIME_MECHANISM_BASE64; 145 int mechanism = MAILMIME_MECHANISM_BASE64;
146 146
147 if ( mimetype.startsWith( "text/" ) ) { 147 if ( mimetype.startsWith( "text/" ) ) {
148 param = mailmime_parameter_new( strdup( "charset" ), 148 param = mailmime_parameter_new( strdup( "charset" ),
149 strdup( "iso-8859-1" ) ); 149 strdup( "iso-8859-1" ) );
150 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 150 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
151 } 151 }
152 152
153 fields = mailmime_fields_new_filename( 153 fields = mailmime_fields_new_filename(
154 disptype, name, 154 disptype, name,
155 mechanism ); 155 mechanism );
156 content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); 156 content = mailmime_content_new_with_str( (char*)mimetype.latin1() );
157 if (content!=0 && fields != 0) { 157 if (content!=0 && fields != 0) {
158 if (param) { 158 if (param) {
159 clist_append(content->ct_parameters,param); 159 clist_append(content->ct_parameters,param);
160 param = 0; 160 param = 0;
161 } 161 }
162 if (filename.length()>0) { 162 if (filename.length()>0) {
163 QFileInfo f(filename); 163 QFileInfo f(filename);
164 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); 164 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1()));
165 clist_append(content->ct_parameters,param); 165 clist_append(content->ct_parameters,param);
166 param = 0; 166 param = 0;
167 } 167 }
168 filePart = mailmime_new_empty( content, fields ); 168 filePart = mailmime_new_empty( content, fields );
169 } 169 }
170 if (filePart) { 170 if (filePart) {
171 if (filename.length()>0) { 171 if (filename.length()>0) {
172 err = mailmime_set_body_file( filePart, file ); 172 err = mailmime_set_body_file( filePart, file );
173 } else { 173 } else {
174 err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); 174 err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length());
175 } 175 }
176 if (err != MAILIMF_NO_ERROR) { 176 if (err != MAILIMF_NO_ERROR) {
177 qDebug("Error setting body with file %s",file); 177 qDebug("Error setting body with file %s",file);
178 mailmime_free( filePart ); 178 mailmime_free( filePart );
179 filePart = 0; 179 filePart = 0;
180 } 180 }
181 } 181 }
182 182
183 if (!filePart) { 183 if (!filePart) {
184 if ( param != NULL ) { 184 if ( param != NULL ) {
185 mailmime_parameter_free( param ); 185 mailmime_parameter_free( param );
186 } 186 }
187 if (content) { 187 if (content) {
188 mailmime_content_free( content ); 188 mailmime_content_free( content );
189 } 189 }
190 if (fields) { 190 if (fields) {
191 mailmime_fields_free( fields ); 191 mailmime_fields_free( fields );
192 } else { 192 } else {
193 if (name) { 193 if (name) {
194 free( name ); 194 free( name );
195 } 195 }
196 if (file) { 196 if (file) {
197 free( file ); 197 free( file );
198 } 198 }
199 } 199 }
200 } 200 }
201 return filePart; // Success :) 201 return filePart; // Success :)
202 202
203} 203}
204 204
205void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) { 205void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) {
206 const Attachment *it; 206 const Attachment *it;
207 unsigned int count = files.count(); 207 unsigned int count = files.count();
208 qDebug("List contains %i values",count); 208 qDebug("List contains %i values",count);
209 for ( unsigned int i = 0; i < count; ++i ) { 209 for ( unsigned int i = 0; i < count; ++i ) {
210 qDebug( "Adding file" ); 210 qDebug( "Adding file" );
211 mailmime *filePart; 211 mailmime *filePart;
212 int err; 212 int err;
213 it = ((QList<Attachment>)files).at(i); 213 it = ((QList<Attachment>)files).at(i);
214 214
215 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); 215 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" );
216 if ( filePart == NULL ) { 216 if ( filePart == NULL ) {
217 qDebug( "addFileParts: error adding file:" ); 217 qDebug( "addFileParts: error adding file:" );
218 qDebug( it->getFileName() ); 218 qDebug( it->getFileName() );
219 continue; 219 continue;
220 } 220 }
221 err = mailmime_smart_add_part( message, filePart ); 221 err = mailmime_smart_add_part( message, filePart );
222 if ( err != MAILIMF_NO_ERROR ) { 222 if ( err != MAILIMF_NO_ERROR ) {
223 mailmime_free( filePart ); 223 mailmime_free( filePart );
224 qDebug("error smart add"); 224 qDebug("error smart add");
225 } 225 }
226 } 226 }
227} 227}
228 228
229mailmime *Generatemail::buildTxtPart(const QString&str ) { 229mailmime *Generatemail::buildTxtPart(const QString&str ) {
230 mailmime *txtPart; 230 mailmime *txtPart;
231 mailmime_fields *fields; 231 mailmime_fields *fields;
232 mailmime_content *content; 232 mailmime_content *content;
233 mailmime_parameter *param; 233 mailmime_parameter *param;
234 int err; 234 int err;
235 235
236 param = mailmime_parameter_new( strdup( "charset" ), 236 param = mailmime_parameter_new( strdup( "charset" ),
237 strdup( "iso-8859-1" ) ); 237 strdup( "iso-8859-1" ) );
238 if ( param == NULL ) 238 if ( param == NULL )
239 goto err_free; 239 goto err_free;
240 240
241 content = mailmime_content_new_with_str( "text/plain" ); 241 content = mailmime_content_new_with_str( "text/plain" );
242 if ( content == NULL ) 242 if ( content == NULL )
243 goto err_free_param; 243 goto err_free_param;
244 244
245 err = clist_append( content->ct_parameters, param ); 245 err = clist_append( content->ct_parameters, param );
246 if ( err != MAILIMF_NO_ERROR ) 246 if ( err != MAILIMF_NO_ERROR )
247 goto err_free_content; 247 goto err_free_content;
248 248
249 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); 249 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT);
250 if ( fields == NULL ) 250 if ( fields == NULL )
251 goto err_free_content; 251 goto err_free_content;
252 252
253 txtPart = mailmime_new_empty( content, fields ); 253 txtPart = mailmime_new_empty( content, fields );
254 if ( txtPart == NULL ) 254 if ( txtPart == NULL )
255 goto err_free_fields; 255 goto err_free_fields;
256 256
257 err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); 257 err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() );
258 if ( err != MAILIMF_NO_ERROR ) 258 if ( err != MAILIMF_NO_ERROR )
259 goto err_free_txtPart; 259 goto err_free_txtPart;
260 260
261 return txtPart; // Success :) 261 return txtPart; // Success :)
262 262
263err_free_txtPart: 263err_free_txtPart:
264 mailmime_free( txtPart ); 264 mailmime_free( txtPart );
265err_free_fields: 265err_free_fields:
266 mailmime_fields_free( fields ); 266 mailmime_fields_free( fields );
267err_free_content: 267err_free_content:
268 mailmime_content_free( content ); 268 mailmime_content_free( content );
269err_free_param: 269err_free_param:
270 mailmime_parameter_free( param ); 270 mailmime_parameter_free( param );
271err_free: 271err_free:
272 qDebug( "buildTxtPart - error" ); 272 qDebug( "buildTxtPart - error" );
273 273
274 return NULL; // Error :( 274 return NULL; // Error :(
275} 275}
276 276
277mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) { 277mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) {
278 return mailimf_mailbox_new( strdup( name.latin1() ), 278 return mailimf_mailbox_new( strdup( name.latin1() ),
279 strdup( mail.latin1() ) ); 279 strdup( mail.latin1() ) );
280} 280}
281 281
282mailimf_fields *Generatemail::createImfFields(const Opie::osmart_pointer<Mail>&mail ) 282mailimf_fields *Generatemail::createImfFields(const Opie::OSmartPointer<Mail>&mail )
283{ 283{
284 mailimf_fields *fields = NULL; 284 mailimf_fields *fields = NULL;
285 mailimf_field *xmailer = NULL; 285 mailimf_field *xmailer = NULL;
286 mailimf_mailbox *sender=0,*fromBox=0; 286 mailimf_mailbox *sender=0,*fromBox=0;
287 mailimf_mailbox_list *from=0; 287 mailimf_mailbox_list *from=0;
288 mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; 288 mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0;
289 clist*in_reply_to = 0; 289 clist*in_reply_to = 0;
290 char *subject = strdup( mail->getSubject().latin1() ); 290 char *subject = strdup( mail->getSubject().latin1() );
291 int err; 291 int err;
292 int res = 1; 292 int res = 1;
293 293
294 sender = newMailbox( mail->getName(), mail->getMail() ); 294 sender = newMailbox( mail->getName(), mail->getMail() );
295 if ( sender == NULL ) { 295 if ( sender == NULL ) {
296 res = 0; 296 res = 0;
297 } 297 }
298 298
299 if (res) { 299 if (res) {
300 fromBox = newMailbox( mail->getName(), mail->getMail() ); 300 fromBox = newMailbox( mail->getName(), mail->getMail() );
301 } 301 }
302 if ( fromBox == NULL ) { 302 if ( fromBox == NULL ) {
303 res = 0; 303 res = 0;
304 } 304 }
305 305
306 if (res) { 306 if (res) {
307 from = mailimf_mailbox_list_new_empty(); 307 from = mailimf_mailbox_list_new_empty();
308 } 308 }
309 if ( from == NULL ) { 309 if ( from == NULL ) {
310 res = 0; 310 res = 0;
311 } 311 }
312 312
313 if (res && from) { 313 if (res && from) {
314 err = mailimf_mailbox_list_add( from, fromBox ); 314 err = mailimf_mailbox_list_add( from, fromBox );
315 if ( err != MAILIMF_NO_ERROR ) { 315 if ( err != MAILIMF_NO_ERROR ) {
316 res = 0; 316 res = 0;
317 } 317 }
318 } 318 }
319 319
320 if (res) to = parseAddresses( mail->getTo() ); 320 if (res) to = parseAddresses( mail->getTo() );
321 if (res) cc = parseAddresses( mail->getCC() ); 321 if (res) cc = parseAddresses( mail->getCC() );
322 if (res) bcc = parseAddresses( mail->getBCC() ); 322 if (res) bcc = parseAddresses( mail->getBCC() );
323 if (res) reply = parseAddresses( mail->getReply() ); 323 if (res) reply = parseAddresses( mail->getReply() );
324 324
325 if (res && mail->Inreply().count()>0) { 325 if (res && mail->Inreply().count()>0) {
326 in_reply_to = clist_new(); 326 in_reply_to = clist_new();
327 char*c_reply; 327 char*c_reply;
328 unsigned int nsize = 0; 328 unsigned int nsize = 0;
329 for (QStringList::ConstIterator it=mail->Inreply().begin(); 329 for (QStringList::ConstIterator it=mail->Inreply().begin();
330 it != mail->Inreply().end();++it) { 330 it != mail->Inreply().end();++it) {
331 if ((*it).isEmpty()) 331 if ((*it).isEmpty())
332 continue; 332 continue;
333 QString h((*it)); 333 QString h((*it));
334 while (h.length()>0 && h[0]=='<') { 334 while (h.length()>0 && h[0]=='<') {
335 h.remove(0,1); 335 h.remove(0,1);
336 } 336 }
337 while (h.length()>0 && h[h.length()-1]=='>') { 337 while (h.length()>0 && h[h.length()-1]=='>') {
338 h.remove(h.length()-1,1); 338 h.remove(h.length()-1,1);
339 } 339 }
340 if (h.isEmpty()) continue; 340 if (h.isEmpty()) continue;
341 nsize = strlen(h.latin1()); 341 nsize = strlen(h.latin1());
342 /* yes! must be malloc! */ 342 /* yes! must be malloc! */
343 c_reply = (char*)malloc( (nsize+1)*sizeof(char)); 343 c_reply = (char*)malloc( (nsize+1)*sizeof(char));
344 memset(c_reply,0,nsize+1); 344 memset(c_reply,0,nsize+1);
345 memcpy(c_reply,h.latin1(),nsize); 345 memcpy(c_reply,h.latin1(),nsize);
346 clist_append(in_reply_to,c_reply); 346 clist_append(in_reply_to,c_reply);
347 qDebug("In reply to: %s",c_reply); 347 qDebug("In reply to: %s",c_reply);
348 } 348 }
349 } 349 }
350 350
351 if (res) { 351 if (res) {
352 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, 352 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
353 in_reply_to, NULL, subject ); 353 in_reply_to, NULL, subject );
354 if ( fields == NULL ) { 354 if ( fields == NULL ) {
355 qDebug("Error creating mailimf fields"); 355 qDebug("Error creating mailimf fields");
356 res = 0; 356 res = 0;
357 } 357 }
358 } 358 }
359 if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), 359 if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
360 strdup( USER_AGENT ) ); 360 strdup( USER_AGENT ) );
361 if ( xmailer == NULL ) { 361 if ( xmailer == NULL ) {
362 res = 0; 362 res = 0;
363 } else { 363 } else {
364 err = mailimf_fields_add( fields, xmailer ); 364 err = mailimf_fields_add( fields, xmailer );
365 if ( err != MAILIMF_NO_ERROR ) { 365 if ( err != MAILIMF_NO_ERROR ) {
366 res = 0; 366 res = 0;
367 } 367 }
368 } 368 }
369 if (!res ) { 369 if (!res ) {
370 if (xmailer) { 370 if (xmailer) {
371 mailimf_field_free( xmailer ); 371 mailimf_field_free( xmailer );
372 xmailer = NULL; 372 xmailer = NULL;
373 } 373 }
374 if (fields) { 374 if (fields) {
375 mailimf_fields_free( fields ); 375 mailimf_fields_free( fields );
376 fields = NULL; 376 fields = NULL;
377 } else { 377 } else {
378 if (reply) 378 if (reply)
379 mailimf_address_list_free( reply ); 379 mailimf_address_list_free( reply );
380 if (bcc) 380 if (bcc)
381 mailimf_address_list_free( bcc ); 381 mailimf_address_list_free( bcc );
382 if (cc) 382 if (cc)
383 mailimf_address_list_free( cc ); 383 mailimf_address_list_free( cc );
384 if (to) 384 if (to)
385 mailimf_address_list_free( to ); 385 mailimf_address_list_free( to );
386 if (fromBox) { 386 if (fromBox) {
387 mailimf_mailbox_free( fromBox ); 387 mailimf_mailbox_free( fromBox );
388 } else if (from) { 388 } else if (from) {
389 mailimf_mailbox_list_free( from ); 389 mailimf_mailbox_list_free( from );
390 } 390 }
391 if (sender) { 391 if (sender) {
392 mailimf_mailbox_free( sender ); 392 mailimf_mailbox_free( sender );
393 } 393 }
394 if (subject) { 394 if (subject) {
395 free( subject ); 395 free( subject );
396 } 396 }
397 } 397 }
398 } 398 }
399 return fields; 399 return fields;
400} 400}
401 401
402mailmime *Generatemail::createMimeMail(const Opie::osmart_pointer<Mail> &mail ) { 402mailmime *Generatemail::createMimeMail(const Opie::OSmartPointer<Mail> &mail ) {
403 mailmime *message, *txtPart; 403 mailmime *message, *txtPart;
404 mailimf_fields *fields; 404 mailimf_fields *fields;
405 int err; 405 int err;
406 406
407 fields = createImfFields( mail ); 407 fields = createImfFields( mail );
408 if ( fields == NULL ) 408 if ( fields == NULL )
409 goto err_free; 409 goto err_free;
410 410
411 message = mailmime_new_message_data( NULL ); 411 message = mailmime_new_message_data( NULL );
412 if ( message == NULL ) 412 if ( message == NULL )
413 goto err_free_fields; 413 goto err_free_fields;
414 414
415 mailmime_set_imf_fields( message, fields ); 415 mailmime_set_imf_fields( message, fields );
416 416
417 txtPart = buildTxtPart( mail->getMessage() ); 417 txtPart = buildTxtPart( mail->getMessage() );
418 418
419 if ( txtPart == NULL ) 419 if ( txtPart == NULL )
420 goto err_free_message; 420 goto err_free_message;
421 421
422 err = mailmime_smart_add_part( message, txtPart ); 422 err = mailmime_smart_add_part( message, txtPart );
423 if ( err != MAILIMF_NO_ERROR ) 423 if ( err != MAILIMF_NO_ERROR )
424 goto err_free_txtPart; 424 goto err_free_txtPart;
425 425
426 addFileParts( message, mail->getAttachments() ); 426 addFileParts( message, mail->getAttachments() );
427 427
428 return message; // Success :) 428 return message; // Success :)
429 429
430err_free_txtPart: 430err_free_txtPart:
431 mailmime_free( txtPart ); 431 mailmime_free( txtPart );
432err_free_message: 432err_free_message:
433 mailmime_free( message ); 433 mailmime_free( message );
434err_free_fields: 434err_free_fields:
435 mailimf_fields_free( fields ); 435 mailimf_fields_free( fields );
436err_free: 436err_free:
437 qDebug( "createMimeMail: error" ); 437 qDebug( "createMimeMail: error" );
438 438
439 return NULL; // Error :( 439 return NULL; // Error :(
440} 440}
441 441
442clist *Generatemail::createRcptList( mailimf_fields *fields ) { 442clist *Generatemail::createRcptList( mailimf_fields *fields ) {
443 clist *rcptList; 443 clist *rcptList;
444 mailimf_field *field; 444 mailimf_field *field;
445 445
446 rcptList = esmtp_address_list_new(); 446 rcptList = esmtp_address_list_new();
447 447
448 field = getField( fields, MAILIMF_FIELD_TO ); 448 field = getField( fields, MAILIMF_FIELD_TO );
449 if ( field && (field->fld_type == MAILIMF_FIELD_TO) 449 if ( field && (field->fld_type == MAILIMF_FIELD_TO)
450 && field->fld_data.fld_to->to_addr_list ) { 450 && field->fld_data.fld_to->to_addr_list ) {
451 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); 451 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
452 } 452 }
453 453
454 field = getField( fields, MAILIMF_FIELD_CC ); 454 field = getField( fields, MAILIMF_FIELD_CC );
455 if ( field && (field->fld_type == MAILIMF_FIELD_CC) 455 if ( field && (field->fld_type == MAILIMF_FIELD_CC)
456 && field->fld_data.fld_cc->cc_addr_list ) { 456 && field->fld_data.fld_cc->cc_addr_list ) {
457 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); 457 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
458 } 458 }
459 459
460 field = getField( fields, MAILIMF_FIELD_BCC ); 460 field = getField( fields, MAILIMF_FIELD_BCC );
461 if ( field && (field->fld_type == MAILIMF_FIELD_BCC) 461 if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
462 && field->fld_data.fld_bcc->bcc_addr_list ) { 462 && field->fld_data.fld_bcc->bcc_addr_list ) {
463 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); 463 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
464 } 464 }
465 465
466 return rcptList; 466 return rcptList;
467} 467}
diff --git a/noncore/net/mail/libmailwrapper/generatemail.h b/noncore/net/mail/libmailwrapper/generatemail.h
index 409a55e..c246a2a 100644
--- a/noncore/net/mail/libmailwrapper/generatemail.h
+++ b/noncore/net/mail/libmailwrapper/generatemail.h
@@ -1,46 +1,46 @@
1#ifndef __GENERATE_MAIL_H 1#ifndef __GENERATE_MAIL_H
2#define __GENERATE_MAIL_H 2#define __GENERATE_MAIL_H
3 3
4#include <qpe/applnk.h> 4#include <qpe/applnk.h>
5 5
6#include <qobject.h> 6#include <qobject.h>
7#include <libetpan/clist.h> 7#include <libetpan/clist.h>
8 8
9#include <opie2/osmart_pointer.h> 9#include <opie2/osmartpointer.h>
10 10
11class Mail; 11class Mail;
12class RecMail; 12class RecMail;
13class Attachment; 13class Attachment;
14struct mailimf_fields; 14struct mailimf_fields;
15struct mailimf_field; 15struct mailimf_field;
16struct mailimf_mailbox; 16struct mailimf_mailbox;
17struct mailmime; 17struct mailmime;
18struct mailimf_address_list; 18struct mailimf_address_list;
19class progressMailSend; 19class progressMailSend;
20struct mailsmtp; 20struct mailsmtp;
21 21
22class Generatemail : public QObject 22class Generatemail : public QObject
23{ 23{
24 Q_OBJECT 24 Q_OBJECT
25public: 25public:
26 Generatemail(); 26 Generatemail();
27 virtual ~Generatemail(); 27 virtual ~Generatemail();
28 28
29protected: 29protected:
30 static void addRcpts( clist *list, mailimf_address_list *addr_list ); 30 static void addRcpts( clist *list, mailimf_address_list *addr_list );
31 static char *getFrom( mailmime *mail ); 31 static char *getFrom( mailmime *mail );
32 static char *getFrom( mailimf_field *ffrom); 32 static char *getFrom( mailimf_field *ffrom);
33 static mailimf_field *getField( mailimf_fields *fields, int type ); 33 static mailimf_field *getField( mailimf_fields *fields, int type );
34 mailimf_address_list *parseAddresses(const QString&addr ); 34 mailimf_address_list *parseAddresses(const QString&addr );
35 void addFileParts( mailmime *message,const QList<Attachment>&files ); 35 void addFileParts( mailmime *message,const QList<Attachment>&files );
36 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); 36 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content);
37 mailmime *buildTxtPart(const QString&str ); 37 mailmime *buildTxtPart(const QString&str );
38 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 38 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
39 mailimf_fields *createImfFields(const Opie::osmart_pointer<Mail> &mail ); 39 mailimf_fields *createImfFields(const Opie::OSmartPointer<Mail> &mail );
40 mailmime *createMimeMail(const Opie::osmart_pointer<Mail>&mail ); 40 mailmime *createMimeMail(const Opie::OSmartPointer<Mail>&mail );
41 clist *createRcptList( mailimf_fields *fields ); 41 clist *createRcptList( mailimf_fields *fields );
42 42
43 static const char* USER_AGENT; 43 static const char* USER_AGENT;
44}; 44};
45 45
46#endif 46#endif
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
index 6c8a5a1..ee2c8cd 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
@@ -1,475 +1,475 @@
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; 9 m_storage = 0;
10 m_folder = 0; 10 m_folder = 0;
11} 11}
12 12
13Genericwrapper::~Genericwrapper() 13Genericwrapper::~Genericwrapper()
14{ 14{
15 if (m_folder) { 15 if (m_folder) {
16 mailfolder_free(m_folder); 16 mailfolder_free(m_folder);
17 } 17 }
18 if (m_storage) { 18 if (m_storage) {
19 mailstorage_free(m_storage); 19 mailstorage_free(m_storage);
20 } 20 }
21 cleanMimeCache(); 21 cleanMimeCache();
22} 22}
23 23
24void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) 24void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime)
25{ 25{
26 if (!mime) { 26 if (!mime) {
27 return; 27 return;
28 } 28 }
29 mailmime_field*field = 0; 29 mailmime_field*field = 0;
30 mailmime_single_fields fields; 30 mailmime_single_fields fields;
31 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 31 memset(&fields, 0, sizeof(struct mailmime_single_fields));
32 if (mime->mm_mime_fields != NULL) { 32 if (mime->mm_mime_fields != NULL) {
33 mailmime_single_fields_init(&fields, mime->mm_mime_fields, 33 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
34 mime->mm_content_type); 34 mime->mm_content_type);
35 } 35 }
36 36
37 mailmime_content*type = fields.fld_content; 37 mailmime_content*type = fields.fld_content;
38 clistcell*current; 38 clistcell*current;
39 if (!type) { 39 if (!type) {
40 target.setType("text"); 40 target.setType("text");
41 target.setSubtype("plain"); 41 target.setSubtype("plain");
42 } else { 42 } else {
43 target.setSubtype(type->ct_subtype); 43 target.setSubtype(type->ct_subtype);
44 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { 44 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
45 case MAILMIME_DISCRETE_TYPE_TEXT: 45 case MAILMIME_DISCRETE_TYPE_TEXT:
46 target.setType("text"); 46 target.setType("text");
47 break; 47 break;
48 case MAILMIME_DISCRETE_TYPE_IMAGE: 48 case MAILMIME_DISCRETE_TYPE_IMAGE:
49 target.setType("image"); 49 target.setType("image");
50 break; 50 break;
51 case MAILMIME_DISCRETE_TYPE_AUDIO: 51 case MAILMIME_DISCRETE_TYPE_AUDIO:
52 target.setType("audio"); 52 target.setType("audio");
53 break; 53 break;
54 case MAILMIME_DISCRETE_TYPE_VIDEO: 54 case MAILMIME_DISCRETE_TYPE_VIDEO:
55 target.setType("video"); 55 target.setType("video");
56 break; 56 break;
57 case MAILMIME_DISCRETE_TYPE_APPLICATION: 57 case MAILMIME_DISCRETE_TYPE_APPLICATION:
58 target.setType("application"); 58 target.setType("application");
59 break; 59 break;
60 case MAILMIME_DISCRETE_TYPE_EXTENSION: 60 case MAILMIME_DISCRETE_TYPE_EXTENSION:
61 default: 61 default:
62 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { 62 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) {
63 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);
64 } 64 }
65 break; 65 break;
66 } 66 }
67 if (type->ct_parameters) { 67 if (type->ct_parameters) {
68 fillParameters(target,type->ct_parameters); 68 fillParameters(target,type->ct_parameters);
69 } 69 }
70 } 70 }
71 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { 71 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) {
72 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)) {
73 field = (mailmime_field*)current->data; 73 field = (mailmime_field*)current->data;
74 switch(field->fld_type) { 74 switch(field->fld_type) {
75 case MAILMIME_FIELD_TRANSFER_ENCODING: 75 case MAILMIME_FIELD_TRANSFER_ENCODING:
76 target.setEncoding(getencoding(field->fld_data.fld_encoding)); 76 target.setEncoding(getencoding(field->fld_data.fld_encoding));
77 break; 77 break;
78 case MAILMIME_FIELD_ID: 78 case MAILMIME_FIELD_ID:
79 target.setIdentifier(field->fld_data.fld_id); 79 target.setIdentifier(field->fld_data.fld_id);
80 break; 80 break;
81 case MAILMIME_FIELD_DESCRIPTION: 81 case MAILMIME_FIELD_DESCRIPTION:
82 target.setDescription(field->fld_data.fld_description); 82 target.setDescription(field->fld_data.fld_description);
83 break; 83 break;
84 default: 84 default:
85 break; 85 break;
86 } 86 }
87 } 87 }
88 } 88 }
89} 89}
90 90
91void Genericwrapper::fillParameters(RecPart&target,clist*parameters) 91void Genericwrapper::fillParameters(RecPart&target,clist*parameters)
92{ 92{
93 if (!parameters) {return;} 93 if (!parameters) {return;}
94 clistcell*current=0; 94 clistcell*current=0;
95 mailmime_parameter*param; 95 mailmime_parameter*param;
96 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { 96 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) {
97 param = (mailmime_parameter*)current->data; 97 param = (mailmime_parameter*)current->data;
98 if (param) { 98 if (param) {
99 target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 99 target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
100 } 100 }
101 } 101 }
102} 102}
103 103
104QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) 104QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
105{ 105{
106 QString enc="7bit"; 106 QString enc="7bit";
107 if (!aEnc) return enc; 107 if (!aEnc) return enc;
108 switch(aEnc->enc_type) { 108 switch(aEnc->enc_type) {
109 case MAILMIME_MECHANISM_7BIT: 109 case MAILMIME_MECHANISM_7BIT:
110 enc = "7bit"; 110 enc = "7bit";
111 break; 111 break;
112 case MAILMIME_MECHANISM_8BIT: 112 case MAILMIME_MECHANISM_8BIT:
113 enc = "8bit"; 113 enc = "8bit";
114 break; 114 break;
115 case MAILMIME_MECHANISM_BINARY: 115 case MAILMIME_MECHANISM_BINARY:
116 enc = "binary"; 116 enc = "binary";
117 break; 117 break;
118 case MAILMIME_MECHANISM_QUOTED_PRINTABLE: 118 case MAILMIME_MECHANISM_QUOTED_PRINTABLE:
119 enc = "quoted-printable"; 119 enc = "quoted-printable";
120 break; 120 break;
121 case MAILMIME_MECHANISM_BASE64: 121 case MAILMIME_MECHANISM_BASE64:
122 enc = "base64"; 122 enc = "base64";
123 break; 123 break;
124 case MAILMIME_MECHANISM_TOKEN: 124 case MAILMIME_MECHANISM_TOKEN:
125 default: 125 default:
126 if (aEnc->enc_token) { 126 if (aEnc->enc_token) {
127 enc = QString(aEnc->enc_token); 127 enc = QString(aEnc->enc_token);
128 } 128 }
129 break; 129 break;
130 } 130 }
131 return enc; 131 return enc;
132} 132}
133 133
134void 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)
135{ 135{
136 if (current_rec >= 10) { 136 if (current_rec >= 10) {
137 qDebug("too deep recursion!"); 137 qDebug("too deep recursion!");
138 } 138 }
139 if (!message || !mime) { 139 if (!message || !mime) {
140 return; 140 return;
141 } 141 }
142 int r; 142 int r;
143 char*data = 0; 143 char*data = 0;
144 size_t len; 144 size_t len;
145 clistiter * cur = 0; 145 clistiter * cur = 0;
146 QString b; 146 QString b;
147 RecPart part; 147 RecPart part;
148 148
149 switch (mime->mm_type) { 149 switch (mime->mm_type) {
150 case MAILMIME_SINGLE: 150 case MAILMIME_SINGLE:
151 { 151 {
152 QValueList<int>countlist = recList; 152 QValueList<int>countlist = recList;
153 countlist.append(current_count); 153 countlist.append(current_count);
154 r = mailmessage_fetch_section(message,mime,&data,&len); 154 r = mailmessage_fetch_section(message,mime,&data,&len);
155 part.setSize(len); 155 part.setSize(len);
156 part.setPositionlist(countlist); 156 part.setPositionlist(countlist);
157 b = gen_attachment_id(); 157 b = gen_attachment_id();
158 part.setIdentifier(b); 158 part.setIdentifier(b);
159 fillSingleBody(part,message,mime); 159 fillSingleBody(part,message,mime);
160 if (part.Type()=="text" && target.Bodytext().isNull()) { 160 if (part.Type()=="text" && target.Bodytext().isNull()) {
161 encodedString*rs = new encodedString(); 161 encodedString*rs = new encodedString();
162 rs->setContent(data,len); 162 rs->setContent(data,len);
163 encodedString*res = decode_String(rs,part.Encoding()); 163 encodedString*res = decode_String(rs,part.Encoding());
164 if (countlist.count()>2) { 164 if (countlist.count()>2) {
165 bodyCache[b]=rs; 165 bodyCache[b]=rs;
166 target.addPart(part); 166 target.addPart(part);
167 } else { 167 } else {
168 delete rs; 168 delete rs;
169 } 169 }
170 b = QString(res->Content()); 170 b = QString(res->Content());
171 delete res; 171 delete res;
172 target.setBodytext(b); 172 target.setBodytext(b);
173 target.setDescription(part); 173 target.setDescription(part);
174 } else { 174 } else {
175 bodyCache[b]=new encodedString(data,len); 175 bodyCache[b]=new encodedString(data,len);
176 target.addPart(part); 176 target.addPart(part);
177 } 177 }
178 } 178 }
179 break; 179 break;
180 case MAILMIME_MULTIPLE: 180 case MAILMIME_MULTIPLE:
181 { 181 {
182 unsigned int ccount = 1; 182 unsigned int ccount = 1;
183 mailmime*cbody=0; 183 mailmime*cbody=0;
184 QValueList<int>countlist = recList; 184 QValueList<int>countlist = recList;
185 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)) {
186 cbody = (mailmime*)clist_content(cur); 186 cbody = (mailmime*)clist_content(cur);
187 if (cbody->mm_type==MAILMIME_MULTIPLE) { 187 if (cbody->mm_type==MAILMIME_MULTIPLE) {
188 RecPart targetPart; 188 RecPart targetPart;
189 targetPart.setType("multipart"); 189 targetPart.setType("multipart");
190 countlist.append(current_count); 190 countlist.append(current_count);
191 targetPart.setPositionlist(countlist); 191 targetPart.setPositionlist(countlist);
192 target.addPart(targetPart); 192 target.addPart(targetPart);
193 } 193 }
194 traverseBody(target,message, cbody,countlist,current_rec+1,ccount); 194 traverseBody(target,message, cbody,countlist,current_rec+1,ccount);
195 if (cbody->mm_type==MAILMIME_MULTIPLE) { 195 if (cbody->mm_type==MAILMIME_MULTIPLE) {
196 countlist = recList; 196 countlist = recList;
197 } 197 }
198 ++ccount; 198 ++ccount;
199 } 199 }
200 } 200 }
201 break; 201 break;
202 case MAILMIME_MESSAGE: 202 case MAILMIME_MESSAGE:
203 { 203 {
204 QValueList<int>countlist = recList; 204 QValueList<int>countlist = recList;
205 countlist.append(current_count); 205 countlist.append(current_count);
206 /* 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 */
207 if (current_rec > 0) { 207 if (current_rec > 0) {
208 part.setPositionlist(countlist); 208 part.setPositionlist(countlist);
209 r = mailmessage_fetch_section(message,mime,&data,&len); 209 r = mailmessage_fetch_section(message,mime,&data,&len);
210 part.setSize(len); 210 part.setSize(len);
211 part.setPositionlist(countlist); 211 part.setPositionlist(countlist);
212 b = gen_attachment_id(); 212 b = gen_attachment_id();
213 part.setIdentifier(b); 213 part.setIdentifier(b);
214 part.setType("message"); 214 part.setType("message");
215 part.setSubtype("rfc822"); 215 part.setSubtype("rfc822");
216 bodyCache[b]=new encodedString(data,len); 216 bodyCache[b]=new encodedString(data,len);
217 target.addPart(part); 217 target.addPart(part);
218 } 218 }
219 if (mime->mm_data.mm_message.mm_msg_mime != NULL) { 219 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
220 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);
221 } 221 }
222 } 222 }
223 break; 223 break;
224 } 224 }
225} 225}
226 226
227RecBody Genericwrapper::parseMail( mailmessage * msg ) 227RecBody Genericwrapper::parseMail( mailmessage * msg )
228{ 228{
229 int err = MAILIMF_NO_ERROR; 229 int err = MAILIMF_NO_ERROR;
230 mailmime_single_fields fields; 230 mailmime_single_fields fields;
231 /* is bound to msg and will be freed there */ 231 /* is bound to msg and will be freed there */
232 mailmime * mime=0; 232 mailmime * mime=0;
233 RecBody body; 233 RecBody body;
234 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 234 memset(&fields, 0, sizeof(struct mailmime_single_fields));
235 err = mailmessage_get_bodystructure(msg,&mime); 235 err = mailmessage_get_bodystructure(msg,&mime);
236 QValueList<int>recList; 236 QValueList<int>recList;
237 traverseBody(body,msg,mime,recList); 237 traverseBody(body,msg,mime,recList);
238 return body; 238 return body;
239} 239}
240 240
241QString Genericwrapper::parseDateTime( mailimf_date_time *date ) 241QString Genericwrapper::parseDateTime( mailimf_date_time *date )
242{ 242{
243 char tmp[23]; 243 char tmp[23];
244 244
245 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 245 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
246 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 246 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
247 247
248 return QString( tmp ); 248 return QString( tmp );
249} 249}
250 250
251QString Genericwrapper::parseAddressList( mailimf_address_list *list ) 251QString Genericwrapper::parseAddressList( mailimf_address_list *list )
252{ 252{
253 QString result( "" ); 253 QString result( "" );
254 254
255 bool first = true; 255 bool first = true;
256 if (list == 0) return result; 256 if (list == 0) return result;
257 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 257 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
258 mailimf_address *addr = (mailimf_address *) current->data; 258 mailimf_address *addr = (mailimf_address *) current->data;
259 259
260 if ( !first ) { 260 if ( !first ) {
261 result.append( "," ); 261 result.append( "," );
262 } else { 262 } else {
263 first = false; 263 first = false;
264 } 264 }
265 265
266 switch ( addr->ad_type ) { 266 switch ( addr->ad_type ) {
267 case MAILIMF_ADDRESS_MAILBOX: 267 case MAILIMF_ADDRESS_MAILBOX:
268 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 268 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
269 break; 269 break;
270 case MAILIMF_ADDRESS_GROUP: 270 case MAILIMF_ADDRESS_GROUP:
271 result.append( parseGroup( addr->ad_data.ad_group ) ); 271 result.append( parseGroup( addr->ad_data.ad_group ) );
272 break; 272 break;
273 default: 273 default:
274 qDebug( "Generic: unkown mailimf address type" ); 274 qDebug( "Generic: unkown mailimf address type" );
275 break; 275 break;
276 } 276 }
277 } 277 }
278 278
279 return result; 279 return result;
280} 280}
281 281
282QString Genericwrapper::parseGroup( mailimf_group *group ) 282QString Genericwrapper::parseGroup( mailimf_group *group )
283{ 283{
284 QString result( "" ); 284 QString result( "" );
285 285
286 result.append( group->grp_display_name ); 286 result.append( group->grp_display_name );
287 result.append( ": " ); 287 result.append( ": " );
288 288
289 if ( group->grp_mb_list != NULL ) { 289 if ( group->grp_mb_list != NULL ) {
290 result.append( parseMailboxList( group->grp_mb_list ) ); 290 result.append( parseMailboxList( group->grp_mb_list ) );
291 } 291 }
292 292
293 result.append( ";" ); 293 result.append( ";" );
294 294
295 return result; 295 return result;
296} 296}
297 297
298QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) 298QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
299{ 299{
300 QString result( "" ); 300 QString result( "" );
301 301
302 if ( box->mb_display_name == NULL ) { 302 if ( box->mb_display_name == NULL ) {
303 result.append( box->mb_addr_spec ); 303 result.append( box->mb_addr_spec );
304 } else { 304 } else {
305 result.append( convert_String(box->mb_display_name).latin1() ); 305 result.append( convert_String(box->mb_display_name).latin1() );
306 result.append( " <" ); 306 result.append( " <" );
307 result.append( box->mb_addr_spec ); 307 result.append( box->mb_addr_spec );
308 result.append( ">" ); 308 result.append( ">" );
309 } 309 }
310 310
311 return result; 311 return result;
312} 312}
313 313
314QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) 314QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
315{ 315{
316 QString result( "" ); 316 QString result( "" );
317 317
318 bool first = true; 318 bool first = true;
319 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 319 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
320 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 320 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
321 321
322 if ( !first ) { 322 if ( !first ) {
323 result.append( "," ); 323 result.append( "," );
324 } else { 324 } else {
325 first = false; 325 first = false;
326 } 326 }
327 327
328 result.append( parseMailbox( box ) ); 328 result.append( parseMailbox( box ) );
329 } 329 }
330 330
331 return result; 331 return result;
332} 332}
333 333
334encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part) 334encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPart&part)
335{ 335{
336 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); 336 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
337 if (it==bodyCache.end()) return new encodedString(); 337 if (it==bodyCache.end()) return new encodedString();
338 encodedString*t = decode_String(it.data(),part.Encoding()); 338 encodedString*t = decode_String(it.data(),part.Encoding());
339 return t; 339 return t;
340} 340}
341 341
342encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 342encodedString* Genericwrapper::fetchRawPart(const RecMailP&mail,const RecPart&part)
343{ 343{
344 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); 344 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
345 if (it==bodyCache.end()) return new encodedString(); 345 if (it==bodyCache.end()) return new encodedString();
346 encodedString*t = it.data(); 346 encodedString*t = it.data();
347 return t; 347 return t;
348} 348}
349 349
350QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 350QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPart&part)
351{ 351{
352 encodedString*t = fetchDecodedPart(mail,part); 352 encodedString*t = fetchDecodedPart(mail,part);
353 QString text=t->Content(); 353 QString text=t->Content();
354 delete t; 354 delete t;
355 return text; 355 return text;
356} 356}
357 357
358void Genericwrapper::cleanMimeCache() 358void Genericwrapper::cleanMimeCache()
359{ 359{
360 QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); 360 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
361 for (;it!=bodyCache.end();++it) { 361 for (;it!=bodyCache.end();++it) {
362 encodedString*t = it.data(); 362 encodedString*t = it.data();
363 //it.setValue(0); 363 //it.setValue(0);
364 if (t) delete t; 364 if (t) delete t;
365 } 365 }
366 bodyCache.clear(); 366 bodyCache.clear();
367 qDebug("Genericwrapper: cache cleaned"); 367 qDebug("Genericwrapper: cache cleaned");
368} 368}
369 369
370QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) 370QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies)
371{ 371{
372 QStringList res; 372 QStringList res;
373 if (!in_replies || !in_replies->mid_list) return res; 373 if (!in_replies || !in_replies->mid_list) return res;
374 clistiter * current = 0; 374 clistiter * current = 0;
375 for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { 375 for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) {
376 QString h((char*)current->data); 376 QString h((char*)current->data);
377 while (h.length()>0 && h[0]=='<') { 377 while (h.length()>0 && h[0]=='<') {
378 h.remove(0,1); 378 h.remove(0,1);
379 } 379 }
380 while (h.length()>0 && h[h.length()-1]=='>') { 380 while (h.length()>0 && h[h.length()-1]=='>') {
381 h.remove(h.length()-1,1); 381 h.remove(h.length()-1,1);
382 } 382 }
383 if (h.length()>0) { 383 if (h.length()>0) {
384 res.append(h); 384 res.append(h);
385 } 385 }
386 } 386 }
387 return res; 387 return res;
388} 388}
389 389
390void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox,bool mbox_as_to) 390void Genericwrapper::parseList(QValueList<Opie::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to)
391{ 391{
392 int r; 392 int r;
393 mailmessage_list * env_list = 0; 393 mailmessage_list * env_list = 0;
394 r = mailsession_get_messages_list(session,&env_list); 394 r = mailsession_get_messages_list(session,&env_list);
395 if (r != MAIL_NO_ERROR) { 395 if (r != MAIL_NO_ERROR) {
396 qDebug("Error message list"); 396 qDebug("Error message list");
397 return; 397 return;
398 } 398 }
399 r = mailsession_get_envelopes_list(session, env_list); 399 r = mailsession_get_envelopes_list(session, env_list);
400 if (r != MAIL_NO_ERROR) { 400 if (r != MAIL_NO_ERROR) {
401 qDebug("Error filling message list"); 401 qDebug("Error filling message list");
402 if (env_list) { 402 if (env_list) {
403 mailmessage_list_free(env_list); 403 mailmessage_list_free(env_list);
404 } 404 }
405 return; 405 return;
406 } 406 }
407 mailimf_references * refs = 0; 407 mailimf_references * refs = 0;
408 mailimf_in_reply_to * in_replies = 0; 408 mailimf_in_reply_to * in_replies = 0;
409 uint32_t i = 0; 409 uint32_t i = 0;
410 for(; i < carray_count(env_list->msg_tab) ; ++i) { 410 for(; i < carray_count(env_list->msg_tab) ; ++i) {
411 mailmessage * msg; 411 mailmessage * msg;
412 QBitArray mFlags(7); 412 QBitArray mFlags(7);
413 msg = (mailmessage*)carray_get(env_list->msg_tab, i); 413 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
414 if (msg->msg_fields == NULL) { 414 if (msg->msg_fields == NULL) {
415 //qDebug("could not fetch envelope of message %i", i); 415 //qDebug("could not fetch envelope of message %i", i);
416 continue; 416 continue;
417 } 417 }
418 RecMail * mail = new RecMail(); 418 RecMailP mail = new RecMail();
419 mail->setWrapper(this); 419 mail->setWrapper(this);
420 mail_flags * flag_result = 0; 420 mail_flags * flag_result = 0;
421 r = mailmessage_get_flags(msg,&flag_result); 421 r = mailmessage_get_flags(msg,&flag_result);
422 if (r == MAIL_ERROR_NOT_IMPLEMENTED) { 422 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
423 mFlags.setBit(FLAG_SEEN); 423 mFlags.setBit(FLAG_SEEN);
424 } 424 }
425 mailimf_single_fields single_fields; 425 mailimf_single_fields single_fields;
426 mailimf_single_fields_init(&single_fields, msg->msg_fields); 426 mailimf_single_fields_init(&single_fields, msg->msg_fields);
427 mail->setMsgsize(msg->msg_size); 427 mail->setMsgsize(msg->msg_size);
428 mail->setFlags(mFlags); 428 mail->setFlags(mFlags);
429 mail->setMbox(mailbox); 429 mail->setMbox(mailbox);
430 mail->setNumber(msg->msg_index); 430 mail->setNumber(msg->msg_index);
431 if (single_fields.fld_subject) 431 if (single_fields.fld_subject)
432 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); 432 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
433 if (single_fields.fld_from) 433 if (single_fields.fld_from)
434 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); 434 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
435 if (!mbox_as_to) { 435 if (!mbox_as_to) {
436 if (single_fields.fld_to) 436 if (single_fields.fld_to)
437 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); 437 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
438 } else { 438 } else {
439 mail->setTo(mailbox); 439 mail->setTo(mailbox);
440 } 440 }
441 if (single_fields.fld_cc) 441 if (single_fields.fld_cc)
442 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); 442 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) );
443 if (single_fields.fld_bcc) 443 if (single_fields.fld_bcc)
444 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); 444 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) );
445 if (single_fields.fld_orig_date) 445 if (single_fields.fld_orig_date)
446 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); 446 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) );
447 // crashes when accessing pop3 account? 447 // crashes when accessing pop3 account?
448 if (single_fields.fld_message_id->mid_value) { 448 if (single_fields.fld_message_id->mid_value) {
449 mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); 449 mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
450 qDebug("Msgid == %s",mail->Msgid().latin1()); 450 qDebug("Msgid == %s",mail->Msgid().latin1());
451 } 451 }
452 452
453 if (single_fields.fld_reply_to) { 453 if (single_fields.fld_reply_to) {
454 QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); 454 QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list);
455 if (t.count()>0) { 455 if (t.count()>0) {
456 mail->setReplyto(t[0]); 456 mail->setReplyto(t[0]);
457 } 457 }
458 } 458 }
459#if 0 459#if 0
460 refs = single_fields.fld_references; 460 refs = single_fields.fld_references;
461 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 461 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
462 char * text = (char*)refs->mid_list->first->data; 462 char * text = (char*)refs->mid_list->first->data;
463 mail->setReplyto(QString(text)); 463 mail->setReplyto(QString(text));
464 } 464 }
465#endif 465#endif
466 if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list && 466 if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list &&
467 clist_count(single_fields.fld_in_reply_to->mid_list)) { 467 clist_count(single_fields.fld_in_reply_to->mid_list)) {
468 mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); 468 mail->setInreply(parseInreplies(single_fields.fld_in_reply_to));
469 } 469 }
470 target.append(mail); 470 target.append(mail);
471 } 471 }
472 if (env_list) { 472 if (env_list) {
473 mailmessage_list_free(env_list); 473 mailmessage_list_free(env_list);
474 } 474 }
475} 475}
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.h b/noncore/net/mail/libmailwrapper/genericwrapper.h
index d0db45a..f9968d1 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.h
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.h
@@ -1,67 +1,67 @@
1#ifndef __GENERIC_WRAPPER_H 1#ifndef __GENERIC_WRAPPER_H
2#define __GENERIC_WRAPPER_H 2#define __GENERIC_WRAPPER_H
3 3
4#include "abstractmail.h" 4#include "abstractmail.h"
5#include <qmap.h> 5#include <qmap.h>
6#include <qstring.h> 6#include <qstring.h>
7#include <libetpan/clist.h> 7#include <libetpan/clist.h>
8 8
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; 22struct mailstorage;
23struct mailfolder; 23struct mailfolder;
24struct mailimf_in_reply_to; 24struct mailimf_in_reply_to;
25 25
26/* this class hold just the funs shared between 26/* this class hold just the funs shared between
27 * mbox and pop3 (later mh, too) mail access. 27 * mbox and pop3 (later mh, too) mail access.
28 * it is not desigend to make a instance of it! 28 * it is not desigend to make a instance of it!
29 */ 29 */
30class Genericwrapper : public AbstractMail 30class Genericwrapper : public AbstractMail
31{ 31{
32 Q_OBJECT 32 Q_OBJECT
33public: 33public:
34 Genericwrapper(); 34 Genericwrapper();
35 virtual ~Genericwrapper(); 35 virtual ~Genericwrapper();
36 36
37 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 37 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPart&part);
38 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 38 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPart&part);
39 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 39 virtual QString fetchTextPart(const RecMailP&mail,const RecPart&part);
40 virtual void cleanMimeCache(); 40 virtual void cleanMimeCache();
41 virtual int deleteMbox(const Opie::osmart_pointer<Folder>&){return 1;} 41 virtual int deleteMbox(const Opie::OSmartPointer<Folder>&){return 1;}
42 virtual void logout(){}; 42 virtual void logout(){};
43 virtual void storeMessage(const char*msg,size_t length, const QString&folder){}; 43 virtual void storeMessage(const char*msg,size_t length, const QString&folder){};
44 44
45protected: 45protected:
46 RecBody parseMail( mailmessage * msg ); 46 RecBody parseMail( mailmessage * msg );
47 QString parseMailboxList( mailimf_mailbox_list *list ); 47 QString parseMailboxList( mailimf_mailbox_list *list );
48 QString parseMailbox( mailimf_mailbox *box ); 48 QString parseMailbox( mailimf_mailbox *box );
49 QString parseGroup( mailimf_group *group ); 49 QString parseGroup( mailimf_group *group );
50 QString parseAddressList( mailimf_address_list *list ); 50 QString parseAddressList( mailimf_address_list *list );
51 QString parseDateTime( mailimf_date_time *date ); 51 QString parseDateTime( mailimf_date_time *date );
52 52
53 void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=1); 53 void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=1);
54 static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); 54 static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime);
55 static void fillParameters(RecPart&target,clist*parameters); 55 static void fillParameters(RecPart&target,clist*parameters);
56 static QString getencoding(mailmime_mechanism*aEnc); 56 static QString getencoding(mailmime_mechanism*aEnc);
57 virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox,bool mbox_as_to=false); 57 virtual void parseList(QValueList<Opie::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to=false);
58 QStringList parseInreplies(mailimf_in_reply_to * in_replies); 58 QStringList parseInreplies(mailimf_in_reply_to * in_replies);
59 59
60 QString msgTempName; 60 QString msgTempName;
61 unsigned int last_msg_id; 61 unsigned int last_msg_id;
62 QMap<QString,encodedString*> bodyCache; 62 QMap<QString,encodedString*> bodyCache;
63 mailstorage * m_storage; 63 mailstorage * m_storage;
64 mailfolder*m_folder; 64 mailfolder*m_folder;
65}; 65};
66 66
67#endif 67#endif
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 3b3be0f..071e734 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,1185 +1,1184 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <libetpan/libetpan.h> 2#include <libetpan/libetpan.h>
3#include <qpe/global.h> 3#include <qpe/global.h>
4 4
5#include "imapwrapper.h" 5#include "imapwrapper.h"
6#include "mailtypes.h" 6#include "mailtypes.h"
7#include "logindialog.h" 7#include "logindialog.h"
8 8
9IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 9IMAPwrapper::IMAPwrapper( IMAPaccount *a )
10 : AbstractMail() 10 : AbstractMail()
11{ 11{
12 account = a; 12 account = a;
13 m_imap = 0; 13 m_imap = 0;
14 m_Lastmbox = ""; 14 m_Lastmbox = "";
15} 15}
16 16
17IMAPwrapper::~IMAPwrapper() 17IMAPwrapper::~IMAPwrapper()
18{ 18{
19 logout(); 19 logout();
20} 20}
21 21
22/* to avoid to often select statements in loops etc. 22/* to avoid to often select statements in loops etc.
23 we trust that we are logged in and connection is established!*/ 23 we trust that we are logged in and connection is established!*/
24int IMAPwrapper::selectMbox(const QString&mbox) 24int IMAPwrapper::selectMbox(const QString&mbox)
25{ 25{
26 if (mbox == m_Lastmbox) { 26 if (mbox == m_Lastmbox) {
27 return MAILIMAP_NO_ERROR; 27 return MAILIMAP_NO_ERROR;
28 } 28 }
29 int err = mailimap_select( m_imap, (char*)mbox.latin1()); 29 int err = mailimap_select( m_imap, (char*)mbox.latin1());
30 if ( err != MAILIMAP_NO_ERROR ) { 30 if ( err != MAILIMAP_NO_ERROR ) {
31 qDebug("error selecting mailbox: %s",m_imap->imap_response); 31 qDebug("error selecting mailbox: %s",m_imap->imap_response);
32 m_Lastmbox = ""; 32 m_Lastmbox = "";
33 return err; 33 return err;
34 } 34 }
35 m_Lastmbox = mbox; 35 m_Lastmbox = mbox;
36 return err; 36 return err;
37} 37}
38 38
39void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 39void IMAPwrapper::imap_progress( size_t current, size_t maximum )
40{ 40{
41 qDebug( "IMAP: %i of %i", current, maximum ); 41 qDebug( "IMAP: %i of %i", current, maximum );
42} 42}
43 43
44bool IMAPwrapper::start_tls(bool force_tls) 44bool IMAPwrapper::start_tls(bool force_tls)
45{ 45{
46 int err; 46 int err;
47 bool try_tls; 47 bool try_tls;
48 mailimap_capability_data * cap_data = 0; 48 mailimap_capability_data * cap_data = 0;
49 49
50 err = mailimap_capability(m_imap,&cap_data); 50 err = mailimap_capability(m_imap,&cap_data);
51 if (err != MAILIMAP_NO_ERROR) { 51 if (err != MAILIMAP_NO_ERROR) {
52 Global::statusMessage("error getting capabilities!"); 52 Global::statusMessage("error getting capabilities!");
53 qDebug("error getting capabilities!"); 53 qDebug("error getting capabilities!");
54 return false; 54 return false;
55 } 55 }
56 clistiter * cur; 56 clistiter * cur;
57 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { 57 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
58 struct mailimap_capability * cap; 58 struct mailimap_capability * cap;
59 cap = (struct mailimap_capability *)clist_content(cur); 59 cap = (struct mailimap_capability *)clist_content(cur);
60 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { 60 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
61 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { 61 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
62 try_tls = true; 62 try_tls = true;
63 break; 63 break;
64 } 64 }
65 } 65 }
66 } 66 }
67 if (cap_data) { 67 if (cap_data) {
68 mailimap_capability_data_free(cap_data); 68 mailimap_capability_data_free(cap_data);
69 } 69 }
70 if (try_tls) { 70 if (try_tls) {
71 err = mailimap_starttls(m_imap); 71 err = mailimap_starttls(m_imap);
72 if (err != MAILIMAP_NO_ERROR && force_tls) { 72 if (err != MAILIMAP_NO_ERROR && force_tls) {
73 Global::statusMessage(tr("Server has no TLS support!")); 73 Global::statusMessage(tr("Server has no TLS support!"));
74 qDebug("Server has no TLS support!"); 74 qDebug("Server has no TLS support!");
75 try_tls = false; 75 try_tls = false;
76 } else { 76 } else {
77 mailstream_low * low; 77 mailstream_low * low;
78 mailstream_low * new_low; 78 mailstream_low * new_low;
79 low = mailstream_get_low(m_imap->imap_stream); 79 low = mailstream_get_low(m_imap->imap_stream);
80 if (!low) { 80 if (!low) {
81 try_tls = false; 81 try_tls = false;
82 } else { 82 } else {
83 int fd = mailstream_low_get_fd(low); 83 int fd = mailstream_low_get_fd(low);
84 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 84 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
85 mailstream_low_free(low); 85 mailstream_low_free(low);
86 mailstream_set_low(m_imap->imap_stream, new_low); 86 mailstream_set_low(m_imap->imap_stream, new_low);
87 } else { 87 } else {
88 try_tls = false; 88 try_tls = false;
89 } 89 }
90 } 90 }
91 } 91 }
92 } 92 }
93 return try_tls; 93 return try_tls;
94} 94}
95 95
96void IMAPwrapper::login() 96void IMAPwrapper::login()
97{ 97{
98 const char *server, *user, *pass; 98 const char *server, *user, *pass;
99 uint16_t port; 99 uint16_t port;
100 int err = MAILIMAP_NO_ERROR; 100 int err = MAILIMAP_NO_ERROR;
101 101
102 if (account->getOffline()) return; 102 if (account->getOffline()) return;
103 /* we are connected this moment */ 103 /* we are connected this moment */
104 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 104 /* TODO: setup a timer holding the line or if connection closed - delete the value */
105 if (m_imap) { 105 if (m_imap) {
106 err = mailimap_noop(m_imap); 106 err = mailimap_noop(m_imap);
107 if (err!=MAILIMAP_NO_ERROR) { 107 if (err!=MAILIMAP_NO_ERROR) {
108 logout(); 108 logout();
109 } else { 109 } else {
110 mailstream_flush(m_imap->imap_stream); 110 mailstream_flush(m_imap->imap_stream);
111 return; 111 return;
112 } 112 }
113 } 113 }
114 server = account->getServer().latin1(); 114 server = account->getServer().latin1();
115 port = account->getPort().toUInt(); 115 port = account->getPort().toUInt();
116 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 116 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
117 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 117 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
118 login.show(); 118 login.show();
119 if ( QDialog::Accepted == login.exec() ) { 119 if ( QDialog::Accepted == login.exec() ) {
120 // ok 120 // ok
121 user = login.getUser().latin1(); 121 user = login.getUser().latin1();
122 pass = login.getPassword().latin1(); 122 pass = login.getPassword().latin1();
123 } else { 123 } else {
124 // cancel 124 // cancel
125 qDebug( "IMAP: Login canceled" ); 125 qDebug( "IMAP: Login canceled" );
126 return; 126 return;
127 } 127 }
128 } else { 128 } else {
129 user = account->getUser().latin1(); 129 user = account->getUser().latin1();
130 pass = account->getPassword().latin1(); 130 pass = account->getPassword().latin1();
131 } 131 }
132 132
133 m_imap = mailimap_new( 20, &imap_progress ); 133 m_imap = mailimap_new( 20, &imap_progress );
134 134
135 /* connect */ 135 /* connect */
136 bool ssl = false; 136 bool ssl = false;
137 bool try_tls = false; 137 bool try_tls = false;
138 bool force_tls = false; 138 bool force_tls = false;
139 139
140 if ( account->ConnectionType() == 2 ) { 140 if ( account->ConnectionType() == 2 ) {
141 ssl = true; 141 ssl = true;
142 } 142 }
143 if (account->ConnectionType()==1) { 143 if (account->ConnectionType()==1) {
144 force_tls = true; 144 force_tls = true;
145 } 145 }
146 146
147 if ( ssl ) { 147 if ( ssl ) {
148 qDebug( "using ssl" ); 148 qDebug( "using ssl" );
149 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 149 err = mailimap_ssl_connect( m_imap, (char*)server, port );
150 } else { 150 } else {
151 err = mailimap_socket_connect( m_imap, (char*)server, port ); 151 err = mailimap_socket_connect( m_imap, (char*)server, port );
152 } 152 }
153 153
154 if ( err != MAILIMAP_NO_ERROR && 154 if ( err != MAILIMAP_NO_ERROR &&
155 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 155 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
156 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 156 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
157 QString failure = ""; 157 QString failure = "";
158 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 158 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
159 failure="Connection refused"; 159 failure="Connection refused";
160 } else { 160 } else {
161 failure="Unknown failure"; 161 failure="Unknown failure";
162 } 162 }
163 Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); 163 Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
164 mailimap_free( m_imap ); 164 mailimap_free( m_imap );
165 m_imap = 0; 165 m_imap = 0;
166 return; 166 return;
167 } 167 }
168 168
169 if (!ssl) { 169 if (!ssl) {
170 try_tls = start_tls(force_tls); 170 try_tls = start_tls(force_tls);
171 } 171 }
172 172
173 bool ok = true; 173 bool ok = true;
174 if (force_tls && !try_tls) { 174 if (force_tls && !try_tls) {
175 Global::statusMessage(tr("Server has no TLS support!")); 175 Global::statusMessage(tr("Server has no TLS support!"));
176 qDebug("Server has no TLS support!"); 176 qDebug("Server has no TLS support!");
177 ok = false; 177 ok = false;
178 } 178 }
179 179
180 180
181 /* login */ 181 /* login */
182 182
183 if (ok) { 183 if (ok) {
184 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 184 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
185 if ( err != MAILIMAP_NO_ERROR ) { 185 if ( err != MAILIMAP_NO_ERROR ) {
186 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); 186 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
187 ok = false; 187 ok = false;
188 } 188 }
189 } 189 }
190 if (!ok) { 190 if (!ok) {
191 err = mailimap_close( m_imap ); 191 err = mailimap_close( m_imap );
192 mailimap_free( m_imap ); 192 mailimap_free( m_imap );
193 m_imap = 0; 193 m_imap = 0;
194 } 194 }
195} 195}
196 196
197void IMAPwrapper::logout() 197void IMAPwrapper::logout()
198{ 198{
199 int err = MAILIMAP_NO_ERROR; 199 int err = MAILIMAP_NO_ERROR;
200 if (!m_imap) return; 200 if (!m_imap) return;
201 err = mailimap_logout( m_imap ); 201 err = mailimap_logout( m_imap );
202 err = mailimap_close( m_imap ); 202 err = mailimap_close( m_imap );
203 mailimap_free( m_imap ); 203 mailimap_free( m_imap );
204 m_imap = 0; 204 m_imap = 0;
205 m_Lastmbox = ""; 205 m_Lastmbox = "";
206} 206}
207 207
208void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 208void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::OSmartPointer<RecMail> > &target )
209{ 209{
210 int err = MAILIMAP_NO_ERROR; 210 int err = MAILIMAP_NO_ERROR;
211 clist *result = 0; 211 clist *result = 0;
212 clistcell *current; 212 clistcell *current;
213 mailimap_fetch_type *fetchType = 0; 213 mailimap_fetch_type *fetchType = 0;
214 mailimap_set *set = 0; 214 mailimap_set *set = 0;
215 215
216 login(); 216 login();
217 if (!m_imap) { 217 if (!m_imap) {
218 return; 218 return;
219 } 219 }
220 /* select mailbox READONLY for operations */ 220 /* select mailbox READONLY for operations */
221 err = selectMbox(mailbox); 221 err = selectMbox(mailbox);
222 if ( err != MAILIMAP_NO_ERROR ) { 222 if ( err != MAILIMAP_NO_ERROR ) {
223 return; 223 return;
224 } 224 }
225 225
226 int last = m_imap->imap_selection_info->sel_exists; 226 int last = m_imap->imap_selection_info->sel_exists;
227 227
228 if (last == 0) { 228 if (last == 0) {
229 Global::statusMessage(tr("Mailbox has no mails")); 229 Global::statusMessage(tr("Mailbox has no mails"));
230 return; 230 return;
231 } else { 231 } else {
232 } 232 }
233 233
234 /* the range has to start at 1!!! not with 0!!!! */ 234 /* the range has to start at 1!!! not with 0!!!! */
235 set = mailimap_set_new_interval( 1, last ); 235 set = mailimap_set_new_interval( 1, last );
236 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 236 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
237 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 237 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
238 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 238 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
239 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 239 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
240 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 240 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
241 241
242 err = mailimap_fetch( m_imap, set, fetchType, &result ); 242 err = mailimap_fetch( m_imap, set, fetchType, &result );
243 mailimap_set_free( set ); 243 mailimap_set_free( set );
244 mailimap_fetch_type_free( fetchType ); 244 mailimap_fetch_type_free( fetchType );
245 245
246 QString date,subject,from; 246 QString date,subject,from;
247 247
248 if ( err == MAILIMAP_NO_ERROR ) { 248 if ( err == MAILIMAP_NO_ERROR ) {
249 mailimap_msg_att * msg_att; 249 mailimap_msg_att * msg_att;
250 int i = 0; 250 int i = 0;
251 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 251 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
252 ++i; 252 ++i;
253 msg_att = (mailimap_msg_att*)current->data; 253 msg_att = (mailimap_msg_att*)current->data;
254 RecMail*m = parse_list_result(msg_att); 254 RecMail*m = parse_list_result(msg_att);
255 if (m) { 255 if (m) {
256 m->setNumber(i); 256 m->setNumber(i);
257 m->setMbox(mailbox); 257 m->setMbox(mailbox);
258 m->setWrapper(this); 258 m->setWrapper(this);
259 target.append(m); 259 target.append(m);
260 } 260 }
261 } 261 }
262 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); 262 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count()));
263 } else { 263 } else {
264 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); 264 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
265 } 265 }
266 if (result) mailimap_fetch_list_free(result); 266 if (result) mailimap_fetch_list_free(result);
267} 267}
268 268
269QValueList<Opie::osmart_pointer<Folder> >* IMAPwrapper::listFolders() 269QValueList<Opie::OSmartPointer<Folder> >* IMAPwrapper::listFolders()
270{ 270{
271 const char *path, *mask; 271 const char *path, *mask;
272 int err = MAILIMAP_NO_ERROR; 272 int err = MAILIMAP_NO_ERROR;
273 clist *result = 0; 273 clist *result = 0;
274 clistcell *current = 0; 274 clistcell *current = 0;
275 clistcell*cur_flag = 0; 275 clistcell*cur_flag = 0;
276 mailimap_mbx_list_flags*bflags = 0; 276 mailimap_mbx_list_flags*bflags = 0;
277 277
278 QValueList<FolderP>* folders = new QValueList<FolderP>(); 278 QValueList<FolderP>* folders = new QValueList<FolderP>();
279 login(); 279 login();
280 if (!m_imap) { 280 if (!m_imap) {
281 return folders; 281 return folders;
282 } 282 }
283 283
284/* 284/*
285 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 285 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
286 * We must not forget to filter them out in next loop! 286 * We must not forget to filter them out in next loop!
287 * it seems like ugly code. and yes - it is ugly code. but the best way. 287 * it seems like ugly code. and yes - it is ugly code. but the best way.
288 */ 288 */
289 QString temp; 289 QString temp;
290 mask = "INBOX" ; 290 mask = "INBOX" ;
291 mailimap_mailbox_list *list; 291 mailimap_mailbox_list *list;
292 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 292 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
293 QString del; 293 QString del;
294 bool selectable = true; 294 bool selectable = true;
295 bool no_inferiors = false; 295 bool no_inferiors = false;
296 if ( err == MAILIMAP_NO_ERROR ) { 296 if ( err == MAILIMAP_NO_ERROR ) {
297 current = result->first; 297 current = result->first;
298 for ( int i = result->count; i > 0; i-- ) { 298 for ( int i = result->count; i > 0; i-- ) {
299 list = (mailimap_mailbox_list *) current->data; 299 list = (mailimap_mailbox_list *) current->data;
300 // it is better use the deep copy mechanism of qt itself 300 // it is better use the deep copy mechanism of qt itself
301 // instead of using strdup! 301 // instead of using strdup!
302 temp = list->mb_name; 302 temp = list->mb_name;
303 del = list->mb_delimiter; 303 del = list->mb_delimiter;
304 current = current->next; 304 current = current->next;
305 if ( (bflags = list->mb_flag) ) { 305 if ( (bflags = list->mb_flag) ) {
306 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 306 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
307 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 307 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
308 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 308 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
309 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 309 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
310 no_inferiors = true; 310 no_inferiors = true;
311 } 311 }
312 } 312 }
313 } 313 }
314 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 314 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
315 } 315 }
316 } else { 316 } else {
317 qDebug("error fetching folders: %s",m_imap->imap_response); 317 qDebug("error fetching folders: %s",m_imap->imap_response);
318 } 318 }
319 mailimap_list_result_free( result ); 319 mailimap_list_result_free( result );
320 320
321/* 321/*
322 * second stage - get the other then inbox folders 322 * second stage - get the other then inbox folders
323 */ 323 */
324 mask = "*" ; 324 mask = "*" ;
325 path = account->getPrefix().latin1(); 325 path = account->getPrefix().latin1();
326 if (!path) path = ""; 326 if (!path) path = "";
327 qDebug(path); 327 qDebug(path);
328 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 328 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
329 if ( err == MAILIMAP_NO_ERROR ) { 329 if ( err == MAILIMAP_NO_ERROR ) {
330 current = result->first; 330 current = result->first;
331 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 331 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
332 no_inferiors = false; 332 no_inferiors = false;
333 list = (mailimap_mailbox_list *) current->data; 333 list = (mailimap_mailbox_list *) current->data;
334 // it is better use the deep copy mechanism of qt itself 334 // it is better use the deep copy mechanism of qt itself
335 // instead of using strdup! 335 // instead of using strdup!
336 temp = list->mb_name; 336 temp = list->mb_name;
337 if (temp.lower()=="inbox") 337 if (temp.lower()=="inbox")
338 continue; 338 continue;
339 if (temp.lower()==account->getPrefix().lower()) 339 if (temp.lower()==account->getPrefix().lower())
340 continue; 340 continue;
341 if ( (bflags = list->mb_flag) ) { 341 if ( (bflags = list->mb_flag) ) {
342 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 342 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
343 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 343 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
344 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 344 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
345 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 345 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
346 no_inferiors = true; 346 no_inferiors = true;
347 } 347 }
348 } 348 }
349 } 349 }
350 del = list->mb_delimiter; 350 del = list->mb_delimiter;
351 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 351 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
352 } 352 }
353 } else { 353 } else {
354 qDebug("error fetching folders %s",m_imap->imap_response); 354 qDebug("error fetching folders %s",m_imap->imap_response);
355 } 355 }
356 if (result) mailimap_list_result_free( result ); 356 if (result) mailimap_list_result_free( result );
357 return folders; 357 return folders;
358} 358}
359 359
360RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 360RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
361{ 361{
362 RecMail * m = 0; 362 RecMail * m = 0;
363 mailimap_msg_att_item *item=0; 363 mailimap_msg_att_item *item=0;
364 clistcell *current,*c,*cf; 364 clistcell *current,*c,*cf;
365 mailimap_msg_att_dynamic*flist; 365 mailimap_msg_att_dynamic*flist;
366 mailimap_flag_fetch*cflag; 366 mailimap_flag_fetch*cflag;
367 int size; 367 int size;
368 QBitArray mFlags(7); 368 QBitArray mFlags(7);
369 QStringList addresslist; 369 QStringList addresslist;
370 370
371 if (!m_att) { 371 if (!m_att) {
372 return m; 372 return m;
373 } 373 }
374 m = new RecMail(); 374 m = new RecMail();
375 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 375 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
376 current = c; 376 current = c;
377 size = 0; 377 size = 0;
378 item = (mailimap_msg_att_item*)current->data; 378 item = (mailimap_msg_att_item*)current->data;
379 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 379 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
380 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 380 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
381 if (!flist->att_list) { 381 if (!flist->att_list) {
382 continue; 382 continue;
383 } 383 }
384 cf = flist->att_list->first; 384 cf = flist->att_list->first;
385 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 385 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
386 cflag = (mailimap_flag_fetch*)cf->data; 386 cflag = (mailimap_flag_fetch*)cf->data;
387 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 387 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
388 switch (cflag->fl_flag->fl_type) { 388 switch (cflag->fl_flag->fl_type) {
389 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 389 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
390 mFlags.setBit(FLAG_ANSWERED); 390 mFlags.setBit(FLAG_ANSWERED);
391 break; 391 break;
392 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 392 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
393 mFlags.setBit(FLAG_FLAGGED); 393 mFlags.setBit(FLAG_FLAGGED);
394 break; 394 break;
395 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 395 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
396 mFlags.setBit(FLAG_DELETED); 396 mFlags.setBit(FLAG_DELETED);
397 break; 397 break;
398 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 398 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
399 mFlags.setBit(FLAG_SEEN); 399 mFlags.setBit(FLAG_SEEN);
400 break; 400 break;
401 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 401 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
402 mFlags.setBit(FLAG_DRAFT); 402 mFlags.setBit(FLAG_DRAFT);
403 break; 403 break;
404 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 404 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
405 break; 405 break;
406 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 406 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
407 break; 407 break;
408 default: 408 default:
409 break; 409 break;
410 } 410 }
411 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 411 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
412 mFlags.setBit(FLAG_RECENT); 412 mFlags.setBit(FLAG_RECENT);
413 } 413 }
414 } 414 }
415 continue; 415 continue;
416 } 416 }
417 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 417 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
418 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 418 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
419 m->setDate(head->env_date); 419 m->setDate(head->env_date);
420 m->setSubject(convert_String((const char*)head->env_subject)); 420 m->setSubject(convert_String((const char*)head->env_subject));
421 //m->setSubject(head->env_subject); 421 //m->setSubject(head->env_subject);
422 if (head->env_from!=NULL) { 422 if (head->env_from!=NULL) {
423 addresslist = address_list_to_stringlist(head->env_from->frm_list); 423 addresslist = address_list_to_stringlist(head->env_from->frm_list);
424 if (addresslist.count()) { 424 if (addresslist.count()) {
425 m->setFrom(addresslist.first()); 425 m->setFrom(addresslist.first());
426 } 426 }
427 } 427 }
428 if (head->env_to!=NULL) { 428 if (head->env_to!=NULL) {
429 addresslist = address_list_to_stringlist(head->env_to->to_list); 429 addresslist = address_list_to_stringlist(head->env_to->to_list);
430 m->setTo(addresslist); 430 m->setTo(addresslist);
431 } 431 }
432 if (head->env_cc!=NULL) { 432 if (head->env_cc!=NULL) {
433 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 433 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
434 m->setCC(addresslist); 434 m->setCC(addresslist);
435 } 435 }
436 if (head->env_bcc!=NULL) { 436 if (head->env_bcc!=NULL) {
437 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 437 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
438 m->setBcc(addresslist); 438 m->setBcc(addresslist);
439 } 439 }
440 /* reply to address, eg. email. */ 440 /* reply to address, eg. email. */
441 if (head->env_reply_to!=NULL) { 441 if (head->env_reply_to!=NULL) {
442 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 442 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
443 if (addresslist.count()) { 443 if (addresslist.count()) {
444 m->setReplyto(addresslist.first()); 444 m->setReplyto(addresslist.first());
445 } 445 }
446 } 446 }
447 if (head->env_in_reply_to!=NULL) { 447 if (head->env_in_reply_to!=NULL) {
448 QString h(head->env_in_reply_to); 448 QString h(head->env_in_reply_to);
449 while (h.length()>0 && h[0]=='<') { 449 while (h.length()>0 && h[0]=='<') {
450 h.remove(0,1); 450 h.remove(0,1);
451 } 451 }
452 while (h.length()>0 && h[h.length()-1]=='>') { 452 while (h.length()>0 && h[h.length()-1]=='>') {
453 h.remove(h.length()-1,1); 453 h.remove(h.length()-1,1);
454 } 454 }
455 if (h.length()>0) { 455 if (h.length()>0) {
456 m->setInreply(QStringList(h)); 456 m->setInreply(QStringList(h));
457 } 457 }
458 } 458 }
459 if (head->env_message_id) { 459 if (head->env_message_id) {
460 m->setMsgid(QString(head->env_message_id)); 460 m->setMsgid(QString(head->env_message_id));
461 } 461 }
462 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 462 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
463#if 0 463#if 0
464 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 464 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
465 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 465 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
466 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); 466 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec);
467 qDebug(da.toString()); 467 qDebug(da.toString());
468#endif 468#endif
469 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 469 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
470 size = item->att_data.att_static->att_data.att_rfc822_size; 470 size = item->att_data.att_static->att_data.att_rfc822_size;
471 } 471 }
472 } 472 }
473 /* msg is already deleted */ 473 /* msg is already deleted */
474 if (mFlags.testBit(FLAG_DELETED) && m) { 474 if (mFlags.testBit(FLAG_DELETED) && m) {
475 delete m; 475 delete m;
476 m = 0; 476 m = 0;
477 } 477 }
478 if (m) { 478 if (m) {
479 m->setFlags(mFlags); 479 m->setFlags(mFlags);
480 m->setMsgsize(size); 480 m->setMsgsize(size);
481 } 481 }
482 return m; 482 return m;
483} 483}
484 484
485RecBody IMAPwrapper::fetchBody(const RecMail&mail) 485RecBody IMAPwrapper::fetchBody(const RecMailP&mail)
486{ 486{
487 RecBody body; 487 RecBody body;
488 const char *mb; 488 const char *mb;
489 int err = MAILIMAP_NO_ERROR; 489 int err = MAILIMAP_NO_ERROR;
490 clist *result = 0; 490 clist *result = 0;
491 clistcell *current; 491 clistcell *current;
492 mailimap_fetch_att *fetchAtt = 0; 492 mailimap_fetch_att *fetchAtt = 0;
493 mailimap_fetch_type *fetchType = 0; 493 mailimap_fetch_type *fetchType = 0;
494 mailimap_set *set = 0; 494 mailimap_set *set = 0;
495 mailimap_body*body_desc = 0; 495 mailimap_body*body_desc = 0;
496 496
497 mb = mail.getMbox().latin1(); 497 mb = mail->getMbox().latin1();
498 498
499 login(); 499 login();
500 if (!m_imap) { 500 if (!m_imap) {
501 return body; 501 return body;
502 } 502 }
503 err = selectMbox(mail.getMbox()); 503 err = selectMbox(mail->getMbox());
504 if ( err != MAILIMAP_NO_ERROR ) { 504 if ( err != MAILIMAP_NO_ERROR ) {
505 return body; 505 return body;
506 } 506 }
507 507
508 /* the range has to start at 1!!! not with 0!!!! */ 508 /* the range has to start at 1!!! not with 0!!!! */
509 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 509 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() );
510 fetchAtt = mailimap_fetch_att_new_bodystructure(); 510 fetchAtt = mailimap_fetch_att_new_bodystructure();
511 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 511 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
512 err = mailimap_fetch( m_imap, set, fetchType, &result ); 512 err = mailimap_fetch( m_imap, set, fetchType, &result );
513 mailimap_set_free( set ); 513 mailimap_set_free( set );
514 mailimap_fetch_type_free( fetchType ); 514 mailimap_fetch_type_free( fetchType );
515 515
516 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 516 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
517 mailimap_msg_att * msg_att; 517 mailimap_msg_att * msg_att;
518 msg_att = (mailimap_msg_att*)current->data; 518 msg_att = (mailimap_msg_att*)current->data;
519 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 519 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
520 QValueList<int> path; 520 QValueList<int> path;
521 body_desc = item->att_data.att_static->att_data.att_body; 521 body_desc = item->att_data.att_static->att_data.att_body;
522 traverseBody(mail,body_desc,body,0,path); 522 traverseBody(mail,body_desc,body,0,path);
523 } else { 523 } else {
524 qDebug("error fetching body: %s",m_imap->imap_response); 524 qDebug("error fetching body: %s",m_imap->imap_response);
525 } 525 }
526 if (result) mailimap_fetch_list_free(result); 526 if (result) mailimap_fetch_list_free(result);
527 return body; 527 return body;
528} 528}
529 529
530QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 530QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
531{ 531{
532 QStringList l; 532 QStringList l;
533 QString from; 533 QString from;
534 bool named_from; 534 bool named_from;
535 clistcell *current = NULL; 535 clistcell *current = NULL;
536 mailimap_address * current_address=NULL; 536 mailimap_address * current_address=NULL;
537 if (!list) { 537 if (!list) {
538 return l; 538 return l;
539 } 539 }
540 unsigned int count = 0; 540 unsigned int count = 0;
541 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 541 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
542 from = ""; 542 from = "";
543 named_from = false; 543 named_from = false;
544 current_address=(mailimap_address*)current->data; 544 current_address=(mailimap_address*)current->data;
545 if (current_address->ad_personal_name){ 545 if (current_address->ad_personal_name){
546 from+=convert_String((const char*)current_address->ad_personal_name); 546 from+=convert_String((const char*)current_address->ad_personal_name);
547 from+=" "; 547 from+=" ";
548 named_from = true; 548 named_from = true;
549 } 549 }
550 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 550 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
551 from+="<"; 551 from+="<";
552 } 552 }
553 if (current_address->ad_mailbox_name) { 553 if (current_address->ad_mailbox_name) {
554 from+=QString(current_address->ad_mailbox_name); 554 from+=QString(current_address->ad_mailbox_name);
555 from+="@"; 555 from+="@";
556 } 556 }
557 if (current_address->ad_host_name) { 557 if (current_address->ad_host_name) {
558 from+=QString(current_address->ad_host_name); 558 from+=QString(current_address->ad_host_name);
559 } 559 }
560 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 560 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
561 from+=">"; 561 from+=">";
562 } 562 }
563 l.append(QString(from)); 563 l.append(QString(from));
564 if (++count > 99) { 564 if (++count > 99) {
565 break; 565 break;
566 } 566 }
567 } 567 }
568 return l; 568 return l;
569} 569}
570 570
571encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 571encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call)
572{ 572{
573 encodedString*res=new encodedString; 573 encodedString*res=new encodedString;
574 int err; 574 int err;
575 mailimap_fetch_type *fetchType; 575 mailimap_fetch_type *fetchType;
576 mailimap_set *set; 576 mailimap_set *set;
577 clistcell*current,*cur; 577 clistcell*current,*cur;
578 mailimap_section_part * section_part = 0; 578 mailimap_section_part * section_part = 0;
579 mailimap_section_spec * section_spec = 0; 579 mailimap_section_spec * section_spec = 0;
580 mailimap_section * section = 0; 580 mailimap_section * section = 0;
581 mailimap_fetch_att * fetch_att = 0; 581 mailimap_fetch_att * fetch_att = 0;
582 582
583 login(); 583 login();
584 if (!m_imap) { 584 if (!m_imap) {
585 return res; 585 return res;
586 } 586 }
587 if (!internal_call) { 587 if (!internal_call) {
588 err = selectMbox(mail.getMbox()); 588 err = selectMbox(mail->getMbox());
589 if ( err != MAILIMAP_NO_ERROR ) { 589 if ( err != MAILIMAP_NO_ERROR ) {
590 return res; 590 return res;
591 } 591 }
592 } 592 }
593 set = mailimap_set_new_single(mail.getNumber()); 593 set = mailimap_set_new_single(mail->getNumber());
594 594
595 clist*id_list = 0; 595 clist*id_list = 0;
596 596
597 /* if path == empty then its a request for the whole rfc822 mail and generates 597 /* if path == empty then its a request for the whole rfc822 mail and generates
598 a "fetch <id> (body[])" statement on imap server */ 598 a "fetch <id> (body[])" statement on imap server */
599 if (path.count()>0 ) { 599 if (path.count()>0 ) {
600 id_list = clist_new(); 600 id_list = clist_new();
601 for (unsigned j=0; j < path.count();++j) { 601 for (unsigned j=0; j < path.count();++j) {
602 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 602 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
603 *p_id = path[j]; 603 *p_id = path[j];
604 clist_append(id_list,p_id); 604 clist_append(id_list,p_id);
605 } 605 }
606 section_part = mailimap_section_part_new(id_list); 606 section_part = mailimap_section_part_new(id_list);
607 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 607 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
608 } 608 }
609 609
610 section = mailimap_section_new(section_spec); 610 section = mailimap_section_new(section_spec);
611 fetch_att = mailimap_fetch_att_new_body_section(section); 611 fetch_att = mailimap_fetch_att_new_body_section(section);
612 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 612 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
613 613
614 clist*result = 0; 614 clist*result = 0;
615 615
616 err = mailimap_fetch( m_imap, set, fetchType, &result ); 616 err = mailimap_fetch( m_imap, set, fetchType, &result );
617 mailimap_set_free( set ); 617 mailimap_set_free( set );
618 mailimap_fetch_type_free( fetchType ); 618 mailimap_fetch_type_free( fetchType );
619 619
620 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 620 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
621 mailimap_msg_att * msg_att; 621 mailimap_msg_att * msg_att;
622 msg_att = (mailimap_msg_att*)current->data; 622 msg_att = (mailimap_msg_att*)current->data;
623 mailimap_msg_att_item*msg_att_item; 623 mailimap_msg_att_item*msg_att_item;
624 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 624 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
625 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 625 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
626 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 626 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
627 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 627 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
628 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 628 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
629 /* detach - we take over the content */ 629 /* detach - we take over the content */
630 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 630 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
631 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 631 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
632 } 632 }
633 } 633 }
634 } 634 }
635 } else { 635 } else {
636 qDebug("error fetching text: %s",m_imap->imap_response); 636 qDebug("error fetching text: %s",m_imap->imap_response);
637 } 637 }
638 if (result) mailimap_fetch_list_free(result); 638 if (result) mailimap_fetch_list_free(result);
639 return res; 639 return res;
640} 640}
641 641
642/* current_recursion is for recursive calls. 642/* current_recursion is for recursive calls.
643 current_count means the position inside the internal loop! */ 643 current_count means the position inside the internal loop! */
644void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, 644void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBody&target_body,
645 int current_recursion,QValueList<int>recList,int current_count) 645 int current_recursion,QValueList<int>recList,int current_count)
646{ 646{
647 if (!body || current_recursion>=10) { 647 if (!body || current_recursion>=10) {
648 return; 648 return;
649 } 649 }
650 switch (body->bd_type) { 650 switch (body->bd_type) {
651 case MAILIMAP_BODY_1PART: 651 case MAILIMAP_BODY_1PART:
652 { 652 {
653 QValueList<int>countlist = recList; 653 QValueList<int>countlist = recList;
654 countlist.append(current_count); 654 countlist.append(current_count);
655 RecPart currentPart; 655 RecPart currentPart;
656 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 656 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
657 QString id(""); 657 QString id("");
658 currentPart.setPositionlist(countlist); 658 currentPart.setPositionlist(countlist);
659 for (unsigned int j = 0; j < countlist.count();++j) { 659 for (unsigned int j = 0; j < countlist.count();++j) {
660 id+=(j>0?" ":""); 660 id+=(j>0?" ":"");
661 id+=QString("%1").arg(countlist[j]); 661 id+=QString("%1").arg(countlist[j]);
662 } 662 }
663 qDebug("ID = %s",id.latin1()); 663 qDebug("ID = %s",id.latin1());
664 currentPart.setIdentifier(id); 664 currentPart.setIdentifier(id);
665 fillSinglePart(currentPart,part1); 665 fillSinglePart(currentPart,part1);
666 /* important: Check for is NULL 'cause a body can be empty! 666 /* important: Check for is NULL 'cause a body can be empty!
667 And we put it only into the mail if it is the FIRST part */ 667 And we put it only into the mail if it is the FIRST part */
668 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { 668 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) {
669 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); 669 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding());
670 target_body.setDescription(currentPart); 670 target_body.setDescription(currentPart);
671 target_body.setBodytext(body_text); 671 target_body.setBodytext(body_text);
672 if (countlist.count()>1) { 672 if (countlist.count()>1) {
673 target_body.addPart(currentPart); 673 target_body.addPart(currentPart);
674 } 674 }
675 } else { 675 } else {
676 target_body.addPart(currentPart); 676 target_body.addPart(currentPart);
677 } 677 }
678 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 678 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
679 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); 679 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
680 } 680 }
681 } 681 }
682 break; 682 break;
683 case MAILIMAP_BODY_MPART: 683 case MAILIMAP_BODY_MPART:
684 { 684 {
685 QValueList<int>countlist = recList; 685 QValueList<int>countlist = recList;
686 clistcell*current=0; 686 clistcell*current=0;
687 mailimap_body*current_body=0; 687 mailimap_body*current_body=0;
688 unsigned int ccount = 1; 688 unsigned int ccount = 1;
689 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 689 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
690 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 690 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
691 current_body = (mailimap_body*)current->data; 691 current_body = (mailimap_body*)current->data;
692 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 692 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
693 RecPart targetPart; 693 RecPart targetPart;
694 targetPart.setType("multipart"); 694 targetPart.setType("multipart");
695 fillMultiPart(targetPart,mailDescription); 695 fillMultiPart(targetPart,mailDescription);
696 countlist.append(current_count); 696 countlist.append(current_count);
697 targetPart.setPositionlist(countlist); 697 targetPart.setPositionlist(countlist);
698 target_body.addPart(targetPart); 698 target_body.addPart(targetPart);
699 QString id(""); 699 QString id("");
700 for (unsigned int j = 0; j < countlist.count();++j) { 700 for (unsigned int j = 0; j < countlist.count();++j) {
701 id+=(j>0?" ":""); 701 id+=(j>0?" ":"");
702 id+=QString("%1").arg(countlist[j]); 702 id+=QString("%1").arg(countlist[j]);
703 } 703 }
704 qDebug("ID(mpart) = %s",id.latin1()); 704 qDebug("ID(mpart) = %s",id.latin1());
705 } 705 }
706 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); 706 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
707 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 707 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
708 countlist = recList; 708 countlist = recList;
709 } 709 }
710 ++ccount; 710 ++ccount;
711 } 711 }
712 } 712 }
713 break; 713 break;
714 default: 714 default:
715 break; 715 break;
716 } 716 }
717} 717}
718 718
719void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 719void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
720{ 720{
721 if (!Description) { 721 if (!Description) {
722 return; 722 return;
723 } 723 }
724 switch (Description->bd_type) { 724 switch (Description->bd_type) {
725 case MAILIMAP_BODY_TYPE_1PART_TEXT: 725 case MAILIMAP_BODY_TYPE_1PART_TEXT:
726 target_part.setType("text"); 726 target_part.setType("text");
727 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 727 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
728 break; 728 break;
729 case MAILIMAP_BODY_TYPE_1PART_BASIC: 729 case MAILIMAP_BODY_TYPE_1PART_BASIC:
730 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 730 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
731 break; 731 break;
732 case MAILIMAP_BODY_TYPE_1PART_MSG: 732 case MAILIMAP_BODY_TYPE_1PART_MSG:
733 target_part.setType("message"); 733 target_part.setType("message");
734 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 734 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
735 break; 735 break;
736 default: 736 default:
737 break; 737 break;
738 } 738 }
739} 739}
740 740
741void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 741void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
742{ 742{
743 if (!which) { 743 if (!which) {
744 return; 744 return;
745 } 745 }
746 QString sub; 746 QString sub;
747 sub = which->bd_media_text; 747 sub = which->bd_media_text;
748 qDebug("Type= text/%s",which->bd_media_text); 748 qDebug("Type= text/%s",which->bd_media_text);
749 target_part.setSubtype(sub.lower()); 749 target_part.setSubtype(sub.lower());
750 target_part.setLines(which->bd_lines); 750 target_part.setLines(which->bd_lines);
751 fillBodyFields(target_part,which->bd_fields); 751 fillBodyFields(target_part,which->bd_fields);
752} 752}
753 753
754void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 754void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
755{ 755{
756 if (!which) { 756 if (!which) {
757 return; 757 return;
758 } 758 }
759 target_part.setSubtype("rfc822"); 759 target_part.setSubtype("rfc822");
760 qDebug("Message part"); 760 qDebug("Message part");
761 /* we set this type to text/plain */ 761 /* we set this type to text/plain */
762 target_part.setLines(which->bd_lines); 762 target_part.setLines(which->bd_lines);
763 fillBodyFields(target_part,which->bd_fields); 763 fillBodyFields(target_part,which->bd_fields);
764} 764}
765 765
766void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which) 766void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which)
767{ 767{
768 if (!which) return; 768 if (!which) return;
769 QString sub = which->bd_media_subtype; 769 QString sub = which->bd_media_subtype;
770 target_part.setSubtype(sub.lower()); 770 target_part.setSubtype(sub.lower());
771 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { 771 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
772 clistcell*cur = 0; 772 clistcell*cur = 0;
773 mailimap_single_body_fld_param*param=0; 773 mailimap_single_body_fld_param*param=0;
774 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 774 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
775 param = (mailimap_single_body_fld_param*)cur->data; 775 param = (mailimap_single_body_fld_param*)cur->data;
776 if (param) { 776 if (param) {
777 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 777 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
778 } 778 }
779 } 779 }
780 } 780 }
781} 781}
782 782
783void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 783void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
784{ 784{
785 if (!which) { 785 if (!which) {
786 return; 786 return;
787 } 787 }
788 QString type,sub; 788 QString type,sub;
789 switch (which->bd_media_basic->med_type) { 789 switch (which->bd_media_basic->med_type) {
790 case MAILIMAP_MEDIA_BASIC_APPLICATION: 790 case MAILIMAP_MEDIA_BASIC_APPLICATION:
791 type = "application"; 791 type = "application";
792 break; 792 break;
793 case MAILIMAP_MEDIA_BASIC_AUDIO: 793 case MAILIMAP_MEDIA_BASIC_AUDIO:
794 type = "audio"; 794 type = "audio";
795 break; 795 break;
796 case MAILIMAP_MEDIA_BASIC_IMAGE: 796 case MAILIMAP_MEDIA_BASIC_IMAGE:
797 type = "image"; 797 type = "image";
798 break; 798 break;
799 case MAILIMAP_MEDIA_BASIC_MESSAGE: 799 case MAILIMAP_MEDIA_BASIC_MESSAGE:
800 type = "message"; 800 type = "message";
801 break; 801 break;
802 case MAILIMAP_MEDIA_BASIC_VIDEO: 802 case MAILIMAP_MEDIA_BASIC_VIDEO:
803 type = "video"; 803 type = "video";
804 break; 804 break;
805 case MAILIMAP_MEDIA_BASIC_OTHER: 805 case MAILIMAP_MEDIA_BASIC_OTHER:
806 default: 806 default:
807 if (which->bd_media_basic->med_basic_type) { 807 if (which->bd_media_basic->med_basic_type) {
808 type = which->bd_media_basic->med_basic_type; 808 type = which->bd_media_basic->med_basic_type;
809 } else { 809 } else {
810 type = ""; 810 type = "";
811 } 811 }
812 break; 812 break;
813 } 813 }
814 if (which->bd_media_basic->med_subtype) { 814 if (which->bd_media_basic->med_subtype) {
815 sub = which->bd_media_basic->med_subtype; 815 sub = which->bd_media_basic->med_subtype;
816 } else { 816 } else {
817 sub = ""; 817 sub = "";
818 } 818 }
819 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 819 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
820 target_part.setType(type.lower()); 820 target_part.setType(type.lower());
821 target_part.setSubtype(sub.lower()); 821 target_part.setSubtype(sub.lower());
822 fillBodyFields(target_part,which->bd_fields); 822 fillBodyFields(target_part,which->bd_fields);
823} 823}
824 824
825void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 825void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
826{ 826{
827 if (!which) return; 827 if (!which) return;
828 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 828 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
829 clistcell*cur; 829 clistcell*cur;
830 mailimap_single_body_fld_param*param=0; 830 mailimap_single_body_fld_param*param=0;
831 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 831 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
832 param = (mailimap_single_body_fld_param*)cur->data; 832 param = (mailimap_single_body_fld_param*)cur->data;
833 if (param) { 833 if (param) {
834 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 834 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
835 } 835 }
836 } 836 }
837 } 837 }
838 mailimap_body_fld_enc*enc = which->bd_encoding; 838 mailimap_body_fld_enc*enc = which->bd_encoding;
839 QString encoding(""); 839 QString encoding("");
840 switch (enc->enc_type) { 840 switch (enc->enc_type) {
841 case MAILIMAP_BODY_FLD_ENC_7BIT: 841 case MAILIMAP_BODY_FLD_ENC_7BIT:
842 encoding = "7bit"; 842 encoding = "7bit";
843 break; 843 break;
844 case MAILIMAP_BODY_FLD_ENC_8BIT: 844 case MAILIMAP_BODY_FLD_ENC_8BIT:
845 encoding = "8bit"; 845 encoding = "8bit";
846 break; 846 break;
847 case MAILIMAP_BODY_FLD_ENC_BINARY: 847 case MAILIMAP_BODY_FLD_ENC_BINARY:
848 encoding="binary"; 848 encoding="binary";
849 break; 849 break;
850 case MAILIMAP_BODY_FLD_ENC_BASE64: 850 case MAILIMAP_BODY_FLD_ENC_BASE64:
851 encoding="base64"; 851 encoding="base64";
852 break; 852 break;
853 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 853 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
854 encoding="quoted-printable"; 854 encoding="quoted-printable";
855 break; 855 break;
856 case MAILIMAP_BODY_FLD_ENC_OTHER: 856 case MAILIMAP_BODY_FLD_ENC_OTHER:
857 default: 857 default:
858 if (enc->enc_value) { 858 if (enc->enc_value) {
859 char*t=enc->enc_value; 859 char*t=enc->enc_value;
860 encoding=QString(enc->enc_value); 860 encoding=QString(enc->enc_value);
861 enc->enc_value=0L; 861 enc->enc_value=0L;
862 free(t); 862 free(t);
863 } 863 }
864 } 864 }
865 if (which->bd_description) { 865 if (which->bd_description) {
866 target_part.setDescription(QString(which->bd_description)); 866 target_part.setDescription(QString(which->bd_description));
867 } 867 }
868 target_part.setEncoding(encoding); 868 target_part.setEncoding(encoding);
869 target_part.setSize(which->bd_size); 869 target_part.setSize(which->bd_size);
870} 870}
871 871
872void IMAPwrapper::deleteMail(const RecMail&mail) 872void IMAPwrapper::deleteMail(const RecMailP&mail)
873{ 873{
874 mailimap_flag_list*flist; 874 mailimap_flag_list*flist;
875 mailimap_set *set; 875 mailimap_set *set;
876 mailimap_store_att_flags * store_flags; 876 mailimap_store_att_flags * store_flags;
877 int err; 877 int err;
878 login(); 878 login();
879 if (!m_imap) { 879 if (!m_imap) {
880 return; 880 return;
881 } 881 }
882 err = selectMbox(mail.getMbox()); 882 err = selectMbox(mail->getMbox());
883 if ( err != MAILIMAP_NO_ERROR ) { 883 if ( err != MAILIMAP_NO_ERROR ) {
884 return; 884 return;
885 } 885 }
886 flist = mailimap_flag_list_new_empty(); 886 flist = mailimap_flag_list_new_empty();
887 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 887 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
888 store_flags = mailimap_store_att_flags_new_set_flags(flist); 888 store_flags = mailimap_store_att_flags_new_set_flags(flist);
889 set = mailimap_set_new_single(mail.getNumber()); 889 set = mailimap_set_new_single(mail->getNumber());
890 err = mailimap_store(m_imap,set,store_flags); 890 err = mailimap_store(m_imap,set,store_flags);
891 mailimap_set_free( set ); 891 mailimap_set_free( set );
892 mailimap_store_att_flags_free(store_flags); 892 mailimap_store_att_flags_free(store_flags);
893 893
894 if (err != MAILIMAP_NO_ERROR) { 894 if (err != MAILIMAP_NO_ERROR) {
895 qDebug("error deleting mail: %s",m_imap->imap_response); 895 qDebug("error deleting mail: %s",m_imap->imap_response);
896 return; 896 return;
897 } 897 }
898 qDebug("deleting mail: %s",m_imap->imap_response); 898 qDebug("deleting mail: %s",m_imap->imap_response);
899 /* should we realy do that at this moment? */ 899 /* should we realy do that at this moment? */
900 err = mailimap_expunge(m_imap); 900 err = mailimap_expunge(m_imap);
901 if (err != MAILIMAP_NO_ERROR) { 901 if (err != MAILIMAP_NO_ERROR) {
902 qDebug("error deleting mail: %s",m_imap->imap_response); 902 qDebug("error deleting mail: %s",m_imap->imap_response);
903 } 903 }
904 qDebug("Delete successfull %s",m_imap->imap_response); 904 qDebug("Delete successfull %s",m_imap->imap_response);
905} 905}
906 906
907void IMAPwrapper::answeredMail(const RecMail&mail) 907void IMAPwrapper::answeredMail(const RecMailP&mail)
908{ 908{
909 mailimap_flag_list*flist; 909 mailimap_flag_list*flist;
910 mailimap_set *set; 910 mailimap_set *set;
911 mailimap_store_att_flags * store_flags; 911 mailimap_store_att_flags * store_flags;
912 int err; 912 int err;
913 login(); 913 login();
914 if (!m_imap) { 914 if (!m_imap) {
915 return; 915 return;
916 } 916 }
917 err = selectMbox(mail.getMbox()); 917 err = selectMbox(mail->getMbox());
918 if ( err != MAILIMAP_NO_ERROR ) { 918 if ( err != MAILIMAP_NO_ERROR ) {
919 return; 919 return;
920 } 920 }
921 flist = mailimap_flag_list_new_empty(); 921 flist = mailimap_flag_list_new_empty();
922 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 922 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
923 store_flags = mailimap_store_att_flags_new_add_flags(flist); 923 store_flags = mailimap_store_att_flags_new_add_flags(flist);
924 set = mailimap_set_new_single(mail.getNumber()); 924 set = mailimap_set_new_single(mail->getNumber());
925 err = mailimap_store(m_imap,set,store_flags); 925 err = mailimap_store(m_imap,set,store_flags);
926 mailimap_set_free( set ); 926 mailimap_set_free( set );
927 mailimap_store_att_flags_free(store_flags); 927 mailimap_store_att_flags_free(store_flags);
928 928
929 if (err != MAILIMAP_NO_ERROR) { 929 if (err != MAILIMAP_NO_ERROR) {
930 qDebug("error marking mail: %s",m_imap->imap_response); 930 qDebug("error marking mail: %s",m_imap->imap_response);
931 return; 931 return;
932 } 932 }
933} 933}
934 934
935QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 935QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
936{ 936{
937 QString body(""); 937 QString body("");
938 encodedString*res = fetchRawPart(mail,path,internal_call); 938 encodedString*res = fetchRawPart(mail,path,internal_call);
939 encodedString*r = decode_String(res,enc); 939 encodedString*r = decode_String(res,enc);
940 delete res; 940 delete res;
941 if (r) { 941 if (r) {
942 if (r->Length()>0) { 942 if (r->Length()>0) {
943 body = r->Content(); 943 body = r->Content();
944 } 944 }
945 delete r; 945 delete r;
946 } 946 }
947 return body; 947 return body;
948} 948}
949 949
950QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 950QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPart&part)
951{ 951{
952 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); 952 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
953} 953}
954 954
955encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) 955encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPart&part)
956{ 956{
957 encodedString*res = fetchRawPart(mail,part.Positionlist(),false); 957 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
958 encodedString*r = decode_String(res,part.Encoding()); 958 encodedString*r = decode_String(res,part.Encoding());
959 delete res; 959 delete res;
960 return r; 960 return r;
961} 961}
962 962
963encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 963encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPart&part)
964{ 964{
965 return fetchRawPart(mail,part.Positionlist(),false); 965 return fetchRawPart(mail,part.Positionlist(),false);
966} 966}
967 967
968int IMAPwrapper::deleteAllMail(const FolderP&folder) 968int IMAPwrapper::deleteAllMail(const FolderP&folder)
969{ 969{
970 login(); 970 login();
971 if (!m_imap) { 971 if (!m_imap) {
972 return 0; 972 return 0;
973 } 973 }
974 mailimap_flag_list*flist; 974 mailimap_flag_list*flist;
975 mailimap_set *set; 975 mailimap_set *set;
976 mailimap_store_att_flags * store_flags; 976 mailimap_store_att_flags * store_flags;
977 int err = selectMbox(folder->getName()); 977 int err = selectMbox(folder->getName());
978 if ( err != MAILIMAP_NO_ERROR ) { 978 if ( err != MAILIMAP_NO_ERROR ) {
979 return 0; 979 return 0;
980 } 980 }
981 981
982 int last = m_imap->imap_selection_info->sel_exists; 982 int last = m_imap->imap_selection_info->sel_exists;
983 if (last == 0) { 983 if (last == 0) {
984 Global::statusMessage(tr("Mailbox has no mails!")); 984 Global::statusMessage(tr("Mailbox has no mails!"));
985 return 0; 985 return 0;
986 } 986 }
987 flist = mailimap_flag_list_new_empty(); 987 flist = mailimap_flag_list_new_empty();
988 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 988 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
989 store_flags = mailimap_store_att_flags_new_set_flags(flist); 989 store_flags = mailimap_store_att_flags_new_set_flags(flist);
990 set = mailimap_set_new_interval( 1, last ); 990 set = mailimap_set_new_interval( 1, last );
991 err = mailimap_store(m_imap,set,store_flags); 991 err = mailimap_store(m_imap,set,store_flags);
992 mailimap_set_free( set ); 992 mailimap_set_free( set );
993 mailimap_store_att_flags_free(store_flags); 993 mailimap_store_att_flags_free(store_flags);
994 if (err != MAILIMAP_NO_ERROR) { 994 if (err != MAILIMAP_NO_ERROR) {
995 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 995 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
996 return 0; 996 return 0;
997 } 997 }
998 qDebug("deleting mail: %s",m_imap->imap_response); 998 qDebug("deleting mail: %s",m_imap->imap_response);
999 /* should we realy do that at this moment? */ 999 /* should we realy do that at this moment? */
1000 err = mailimap_expunge(m_imap); 1000 err = mailimap_expunge(m_imap);
1001 if (err != MAILIMAP_NO_ERROR) { 1001 if (err != MAILIMAP_NO_ERROR) {
1002 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 1002 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
1003 return 0; 1003 return 0;
1004 } 1004 }
1005 qDebug("Delete successfull %s",m_imap->imap_response); 1005 qDebug("Delete successfull %s",m_imap->imap_response);
1006 return 1; 1006 return 1;
1007} 1007}
1008 1008
1009int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) 1009int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder)
1010{ 1010{
1011 if (folder.length()==0) return 0; 1011 if (folder.length()==0) return 0;
1012 login(); 1012 login();
1013 if (!m_imap) {return 0;} 1013 if (!m_imap) {return 0;}
1014 QString pre = account->getPrefix(); 1014 QString pre = account->getPrefix();
1015 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { 1015 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
1016 pre+=delemiter; 1016 pre+=delemiter;
1017 } 1017 }
1018 if (parentfolder) { 1018 if (parentfolder) {
1019 pre += parentfolder->getDisplayName()+delemiter; 1019 pre += parentfolder->getDisplayName()+delemiter;
1020 } 1020 }
1021 pre+=folder; 1021 pre+=folder;
1022 if (getsubfolder) { 1022 if (getsubfolder) {
1023 if (delemiter.length()>0) { 1023 if (delemiter.length()>0) {
1024 pre+=delemiter; 1024 pre+=delemiter;
1025 } else { 1025 } else {
1026 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); 1026 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre));
1027 return 0; 1027 return 0;
1028 } 1028 }
1029 } 1029 }
1030 qDebug("Creating %s",pre.latin1()); 1030 qDebug("Creating %s",pre.latin1());
1031 int res = mailimap_create(m_imap,pre.latin1()); 1031 int res = mailimap_create(m_imap,pre.latin1());
1032 if (res != MAILIMAP_NO_ERROR) { 1032 if (res != MAILIMAP_NO_ERROR) {
1033 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1033 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
1034 return 0; 1034 return 0;
1035 } 1035 }
1036 return 1; 1036 return 1;
1037} 1037}
1038 1038
1039int IMAPwrapper::deleteMbox(const FolderP&folder) 1039int IMAPwrapper::deleteMbox(const FolderP&folder)
1040{ 1040{
1041 if (!folder) return 0; 1041 if (!folder) return 0;
1042 login(); 1042 login();
1043 if (!m_imap) {return 0;} 1043 if (!m_imap) {return 0;}
1044 int res = mailimap_delete(m_imap,folder->getName()); 1044 int res = mailimap_delete(m_imap,folder->getName());
1045 if (res != MAILIMAP_NO_ERROR) { 1045 if (res != MAILIMAP_NO_ERROR) {
1046 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1046 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
1047 return 0; 1047 return 0;
1048 } 1048 }
1049 return 1; 1049 return 1;
1050} 1050}
1051 1051
1052void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 1052void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
1053{ 1053{
1054 mailimap_status_att_list * att_list =0; 1054 mailimap_status_att_list * att_list =0;
1055 mailimap_mailbox_data_status * status=0; 1055 mailimap_mailbox_data_status * status=0;
1056 clistiter * cur = 0; 1056 clistiter * cur = 0;
1057 int r = 0; 1057 int r = 0;
1058 int res = 0;
1059 target_stat.message_count = 0; 1058 target_stat.message_count = 0;
1060 target_stat.message_unseen = 0; 1059 target_stat.message_unseen = 0;
1061 target_stat.message_recent = 0; 1060 target_stat.message_recent = 0;
1062 login(); 1061 login();
1063 if (!m_imap) { 1062 if (!m_imap) {
1064 return; 1063 return;
1065 } 1064 }
1066 att_list = mailimap_status_att_list_new_empty(); 1065 att_list = mailimap_status_att_list_new_empty();
1067 if (!att_list) return; 1066 if (!att_list) return;
1068 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 1067 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
1069 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 1068 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
1070 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 1069 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
1071 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 1070 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
1072 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { 1071 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
1073 for (cur = clist_begin(status->st_info_list); 1072 for (cur = clist_begin(status->st_info_list);
1074 cur != NULL ; cur = clist_next(cur)) { 1073 cur != NULL ; cur = clist_next(cur)) {
1075 mailimap_status_info * status_info; 1074 mailimap_status_info * status_info;
1076 status_info = (mailimap_status_info *)clist_content(cur); 1075 status_info = (mailimap_status_info *)clist_content(cur);
1077 switch (status_info->st_att) { 1076 switch (status_info->st_att) {
1078 case MAILIMAP_STATUS_ATT_MESSAGES: 1077 case MAILIMAP_STATUS_ATT_MESSAGES:
1079 target_stat.message_count = status_info->st_value; 1078 target_stat.message_count = status_info->st_value;
1080 break; 1079 break;
1081 case MAILIMAP_STATUS_ATT_RECENT: 1080 case MAILIMAP_STATUS_ATT_RECENT:
1082 target_stat.message_recent = status_info->st_value; 1081 target_stat.message_recent = status_info->st_value;
1083 break; 1082 break;
1084 case MAILIMAP_STATUS_ATT_UNSEEN: 1083 case MAILIMAP_STATUS_ATT_UNSEEN:
1085 target_stat.message_unseen = status_info->st_value; 1084 target_stat.message_unseen = status_info->st_value;
1086 break; 1085 break;
1087 } 1086 }
1088 } 1087 }
1089 } else { 1088 } else {
1090 qDebug("Error retrieving status"); 1089 qDebug("Error retrieving status");
1091 } 1090 }
1092 if (status) mailimap_mailbox_data_status_free(status); 1091 if (status) mailimap_mailbox_data_status_free(status);
1093 if (att_list) mailimap_status_att_list_free(att_list); 1092 if (att_list) mailimap_status_att_list_free(att_list);
1094} 1093}
1095 1094
1096void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 1095void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
1097{ 1096{
1098 login(); 1097 login();
1099 if (!m_imap) return; 1098 if (!m_imap) return;
1100 if (!msg) return; 1099 if (!msg) return;
1101 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); 1100 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
1102 if (r != MAILIMAP_NO_ERROR) { 1101 if (r != MAILIMAP_NO_ERROR) {
1103 Global::statusMessage("Error storing mail!"); 1102 Global::statusMessage("Error storing mail!");
1104 } 1103 }
1105} 1104}
1106 1105
1107MAILLIB::ATYPE IMAPwrapper::getType()const 1106MAILLIB::ATYPE IMAPwrapper::getType()const
1108{ 1107{
1109 return account->getType(); 1108 return account->getType();
1110} 1109}
1111 1110
1112const QString&IMAPwrapper::getName()const 1111const QString&IMAPwrapper::getName()const
1113{ 1112{
1114 qDebug("Get name: %s",account->getAccountName().latin1()); 1113 qDebug("Get name: %s",account->getAccountName().latin1());
1115 return account->getAccountName(); 1114 return account->getAccountName();
1116} 1115}
1117 1116
1118encodedString* IMAPwrapper::fetchRawBody(const RecMail&mail) 1117encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail)
1119{ 1118{
1120 // dummy 1119 // dummy
1121 QValueList<int> path; 1120 QValueList<int> path;
1122 return fetchRawPart(mail,path,false); 1121 return fetchRawPart(mail,path,false);
1123} 1122}
1124 1123
1125void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, 1124void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder,
1126 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 1125 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
1127{ 1126{
1128 if (targetWrapper != this) { 1127 if (targetWrapper != this) {
1129 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); 1128 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit);
1130 qDebug("Using generic"); 1129 qDebug("Using generic");
1131 return; 1130 return;
1132 } 1131 }
1133 mailimap_set *set = 0; 1132 mailimap_set *set = 0;
1134 login(); 1133 login();
1135 if (!m_imap) { 1134 if (!m_imap) {
1136 return; 1135 return;
1137 } 1136 }
1138 int err = selectMbox(fromFolder->getName()); 1137 int err = selectMbox(fromFolder->getName());
1139 if ( err != MAILIMAP_NO_ERROR ) { 1138 if ( err != MAILIMAP_NO_ERROR ) {
1140 return; 1139 return;
1141 } 1140 }
1142 int last = m_imap->imap_selection_info->sel_exists; 1141 int last = m_imap->imap_selection_info->sel_exists;
1143 set = mailimap_set_new_interval( 1, last ); 1142 set = mailimap_set_new_interval( 1, last );
1144 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1143 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1145 mailimap_set_free( set ); 1144 mailimap_set_free( set );
1146 if ( err != MAILIMAP_NO_ERROR ) { 1145 if ( err != MAILIMAP_NO_ERROR ) {
1147 QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); 1146 QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response);
1148 Global::statusMessage(error_msg); 1147 Global::statusMessage(error_msg);
1149 qDebug(error_msg); 1148 qDebug(error_msg);
1150 return; 1149 return;
1151 } 1150 }
1152 if (moveit) { 1151 if (moveit) {
1153 deleteAllMail(fromFolder); 1152 deleteAllMail(fromFolder);
1154 } 1153 }
1155} 1154}
1156 1155
1157void IMAPwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 1156void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
1158{ 1157{
1159 if (targetWrapper != this) { 1158 if (targetWrapper != this) {
1160 qDebug("Using generic"); 1159 qDebug("Using generic");
1161 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); 1160 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit);
1162 return; 1161 return;
1163 } 1162 }
1164 mailimap_set *set = 0; 1163 mailimap_set *set = 0;
1165 login(); 1164 login();
1166 if (!m_imap) { 1165 if (!m_imap) {
1167 return; 1166 return;
1168 } 1167 }
1169 int err = selectMbox(mail.getMbox()); 1168 int err = selectMbox(mail->getMbox());
1170 if ( err != MAILIMAP_NO_ERROR ) { 1169 if ( err != MAILIMAP_NO_ERROR ) {
1171 return; 1170 return;
1172 } 1171 }
1173 set = mailimap_set_new_single(mail.getNumber()); 1172 set = mailimap_set_new_single(mail->getNumber());
1174 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1173 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1175 mailimap_set_free( set ); 1174 mailimap_set_free( set );
1176 if ( err != MAILIMAP_NO_ERROR ) { 1175 if ( err != MAILIMAP_NO_ERROR ) {
1177 QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); 1176 QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response);
1178 Global::statusMessage(error_msg); 1177 Global::statusMessage(error_msg);
1179 qDebug(error_msg); 1178 qDebug(error_msg);
1180 return; 1179 return;
1181 } 1180 }
1182 if (moveit) { 1181 if (moveit) {
1183 deleteMail(mail); 1182 deleteMail(mail);
1184 } 1183 }
1185} 1184}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index 15f049f..3bd5967 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -1,80 +1,80 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "abstractmail.h" 6#include "abstractmail.h"
7#include <libetpan/clist.h> 7#include <libetpan/clist.h>
8 8
9struct mailimap; 9struct mailimap;
10struct mailimap_body; 10struct mailimap_body;
11struct mailimap_body_type_1part; 11struct mailimap_body_type_1part;
12struct mailimap_body_type_text; 12struct mailimap_body_type_text;
13struct mailimap_body_type_basic; 13struct mailimap_body_type_basic;
14struct mailimap_body_type_msg; 14struct mailimap_body_type_msg;
15struct mailimap_body_type_mpart; 15struct mailimap_body_type_mpart;
16struct mailimap_body_fields; 16struct mailimap_body_fields;
17struct mailimap_msg_att; 17struct mailimap_msg_att;
18class encodedString; 18class encodedString;
19 19
20class IMAPwrapper : public AbstractMail 20class IMAPwrapper : public AbstractMail
21{ 21{
22 Q_OBJECT 22 Q_OBJECT
23public: 23public:
24 IMAPwrapper( IMAPaccount *a ); 24 IMAPwrapper( IMAPaccount *a );
25 virtual ~IMAPwrapper(); 25 virtual ~IMAPwrapper();
26 virtual QValueList<Opie::osmart_pointer<Folder> >* listFolders(); 26 virtual QValueList<Opie::OSmartPointer<Folder> >* listFolders();
27 virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); 27 virtual void listMessages(const QString & mailbox,QValueList<Opie::OSmartPointer<RecMail> >&target );
28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
29 29
30 virtual void deleteMail(const RecMail&mail); 30 virtual void deleteMail(const RecMailP&mail);
31 virtual void answeredMail(const RecMail&mail); 31 virtual void answeredMail(const RecMailP&mail);
32 virtual int deleteAllMail(const Opie::osmart_pointer<Folder>&folder); 32 virtual int deleteAllMail(const Opie::OSmartPointer<Folder>&folder);
33 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 33 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
34 virtual void mvcpAllMails(const Opie::osmart_pointer<Folder>&fromFolder, 34 virtual void mvcpAllMails(const Opie::OSmartPointer<Folder>&fromFolder,
35 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 35 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
36 virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 36 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
37 37
38 virtual RecBody fetchBody(const RecMail&mail); 38 virtual RecBody fetchBody(const RecMailP&mail);
39 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 39 virtual QString fetchTextPart(const RecMailP&mail,const RecPart&part);
40 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 40 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPart&part);
41 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 41 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPart&part);
42 virtual encodedString* fetchRawBody(const RecMail&mail); 42 virtual encodedString* fetchRawBody(const RecMailP&mail);
43 43
44 virtual int createMbox(const QString&,const Opie::osmart_pointer<Folder>&parentfolder=0, 44 virtual int createMbox(const QString&,const Opie::OSmartPointer<Folder>&parentfolder=0,
45 const QString& delemiter="/",bool getsubfolder=false); 45 const QString& delemiter="/",bool getsubfolder=false);
46 virtual int deleteMbox(const Opie::osmart_pointer<Folder>&folder); 46 virtual int deleteMbox(const Opie::OSmartPointer<Folder>&folder);
47 47
48 static void imap_progress( size_t current, size_t maximum ); 48 static void imap_progress( size_t current, size_t maximum );
49 49
50 virtual void logout(); 50 virtual void logout();
51 virtual MAILLIB::ATYPE getType()const; 51 virtual MAILLIB::ATYPE getType()const;
52 virtual const QString&getName()const; 52 virtual const QString&getName()const;
53 53
54protected: 54protected:
55 RecMail*parse_list_result(mailimap_msg_att*); 55 RecMail*parse_list_result(mailimap_msg_att*);
56 void login(); 56 void login();
57 bool start_tls(bool force=true); 57 bool start_tls(bool force=true);
58 58
59 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); 59 virtual QString fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
60 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); 60 virtual encodedString*fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call);
61 int selectMbox(const QString&mbox); 61 int selectMbox(const QString&mbox);
62 62
63 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 63 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
64 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 64 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
65 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 65 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
66 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); 66 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
67 void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which); 67 void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which);
68 void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1); 68 void traverseBody(const RecMailP&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1);
69 69
70 /* just helpers */ 70 /* just helpers */
71 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 71 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
72 static QStringList address_list_to_stringlist(clist*list); 72 static QStringList address_list_to_stringlist(clist*list);
73 73
74 74
75 IMAPaccount *account; 75 IMAPaccount *account;
76 mailimap *m_imap; 76 mailimap *m_imap;
77 QString m_Lastmbox; 77 QString m_Lastmbox;
78}; 78};
79 79
80#endif 80#endif
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.cpp b/noncore/net/mail/libmailwrapper/mailtypes.cpp
index 49b3caa..7dd7e58 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.cpp
+++ b/noncore/net/mail/libmailwrapper/mailtypes.cpp
@@ -1,369 +1,369 @@
1#include "mailtypes.h" 1#include "mailtypes.h"
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4RecMail::RecMail() 4RecMail::RecMail()
5 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7) 5 :Opie::ORefCount(),subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7)
6{ 6{
7 init(); 7 init();
8} 8}
9 9
10RecMail::RecMail(const RecMail&old) 10RecMail::RecMail(const RecMail&old)
11 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) 11 :Opie::ORefCount(),subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7)
12{ 12{
13 init(); 13 init();
14 copy_old(old); 14 copy_old(old);
15 qDebug("Copy constructor RecMail"); 15 qDebug("Copy constructor RecMail");
16} 16}
17 17
18RecMail::~RecMail() 18RecMail::~RecMail()
19{ 19{
20 wrapper = 0; 20 wrapper = 0;
21} 21}
22 22
23void RecMail::copy_old(const RecMail&old) 23void RecMail::copy_old(const RecMail&old)
24{ 24{
25 subject = old.subject; 25 subject = old.subject;
26 date = old.date; 26 date = old.date;
27 mbox = old.mbox; 27 mbox = old.mbox;
28 msg_id = old.msg_id; 28 msg_id = old.msg_id;
29 msg_size = old.msg_size; 29 msg_size = old.msg_size;
30 msg_number = old.msg_number; 30 msg_number = old.msg_number;
31 from = old.from; 31 from = old.from;
32 msg_flags = old.msg_flags; 32 msg_flags = old.msg_flags;
33 to = old.to; 33 to = old.to;
34 cc = old.cc; 34 cc = old.cc;
35 bcc = old.bcc; 35 bcc = old.bcc;
36 wrapper = old.wrapper; 36 wrapper = old.wrapper;
37 in_reply_to = old.in_reply_to; 37 in_reply_to = old.in_reply_to;
38 references = old.references; 38 references = old.references;
39 replyto = old.replyto; 39 replyto = old.replyto;
40} 40}
41 41
42void RecMail::init() 42void RecMail::init()
43{ 43{
44 to.clear(); 44 to.clear();
45 cc.clear(); 45 cc.clear();
46 bcc.clear(); 46 bcc.clear();
47 in_reply_to.clear(); 47 in_reply_to.clear();
48 references.clear(); 48 references.clear();
49 wrapper = 0; 49 wrapper = 0;
50} 50}
51 51
52void RecMail::setWrapper(AbstractMail*awrapper) 52void RecMail::setWrapper(AbstractMail*awrapper)
53{ 53{
54 wrapper = awrapper; 54 wrapper = awrapper;
55} 55}
56 56
57AbstractMail* RecMail::Wrapper() 57AbstractMail* RecMail::Wrapper()
58{ 58{
59 return wrapper; 59 return wrapper;
60} 60}
61 61
62void RecMail::setTo(const QStringList&list) 62void RecMail::setTo(const QStringList&list)
63{ 63{
64 to = list; 64 to = list;
65} 65}
66 66
67const QStringList&RecMail::To()const 67const QStringList&RecMail::To()const
68{ 68{
69 return to; 69 return to;
70} 70}
71 71
72void RecMail::setCC(const QStringList&list) 72void RecMail::setCC(const QStringList&list)
73{ 73{
74 cc = list; 74 cc = list;
75} 75}
76 76
77const QStringList&RecMail::CC()const 77const QStringList&RecMail::CC()const
78{ 78{
79 return cc; 79 return cc;
80} 80}
81 81
82void RecMail::setBcc(const QStringList&list) 82void RecMail::setBcc(const QStringList&list)
83{ 83{
84 bcc = list; 84 bcc = list;
85} 85}
86 86
87const QStringList& RecMail::Bcc()const 87const QStringList& RecMail::Bcc()const
88{ 88{
89 return bcc; 89 return bcc;
90} 90}
91 91
92void RecMail::setInreply(const QStringList&list) 92void RecMail::setInreply(const QStringList&list)
93{ 93{
94 in_reply_to = list; 94 in_reply_to = list;
95} 95}
96 96
97const QStringList& RecMail::Inreply()const 97const QStringList& RecMail::Inreply()const
98{ 98{
99 return in_reply_to; 99 return in_reply_to;
100} 100}
101 101
102void RecMail::setReferences(const QStringList&list) 102void RecMail::setReferences(const QStringList&list)
103{ 103{
104 references = list; 104 references = list;
105} 105}
106 106
107const QStringList& RecMail::References()const 107const QStringList& RecMail::References()const
108{ 108{
109 return references; 109 return references;
110} 110}
111 111
112RecPart::RecPart() 112RecPart::RecPart()
113 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0) 113 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0)
114{ 114{
115 m_Parameters.clear(); 115 m_Parameters.clear();
116 m_poslist.clear(); 116 m_poslist.clear();
117} 117}
118 118
119RecPart::~RecPart() 119RecPart::~RecPart()
120{ 120{
121} 121}
122 122
123void RecPart::setSize(unsigned int size) 123void RecPart::setSize(unsigned int size)
124{ 124{
125 m_size = size; 125 m_size = size;
126} 126}
127 127
128const unsigned int RecPart::Size()const 128const unsigned int RecPart::Size()const
129{ 129{
130 return m_size; 130 return m_size;
131} 131}
132 132
133void RecPart::setLines(unsigned int lines) 133void RecPart::setLines(unsigned int lines)
134{ 134{
135 m_lines = lines; 135 m_lines = lines;
136} 136}
137 137
138const unsigned int RecPart::Lines()const 138const unsigned int RecPart::Lines()const
139{ 139{
140 return m_lines; 140 return m_lines;
141} 141}
142 142
143const QString& RecPart::Type()const 143const QString& RecPart::Type()const
144{ 144{
145 return m_type; 145 return m_type;
146} 146}
147 147
148void RecPart::setType(const QString&type) 148void RecPart::setType(const QString&type)
149{ 149{
150 m_type = type; 150 m_type = type;
151} 151}
152 152
153const QString& RecPart::Subtype()const 153const QString& RecPart::Subtype()const
154{ 154{
155 return m_subtype; 155 return m_subtype;
156} 156}
157 157
158void RecPart::setSubtype(const QString&subtype) 158void RecPart::setSubtype(const QString&subtype)
159{ 159{
160 m_subtype = subtype; 160 m_subtype = subtype;
161} 161}
162 162
163const QString& RecPart::Identifier()const 163const QString& RecPart::Identifier()const
164{ 164{
165 return m_identifier; 165 return m_identifier;
166} 166}
167 167
168void RecPart::setIdentifier(const QString&identifier) 168void RecPart::setIdentifier(const QString&identifier)
169{ 169{
170 m_identifier = identifier; 170 m_identifier = identifier;
171} 171}
172 172
173const QString& RecPart::Encoding()const 173const QString& RecPart::Encoding()const
174{ 174{
175 return m_encoding; 175 return m_encoding;
176} 176}
177 177
178void RecPart::setEncoding(const QString&encoding) 178void RecPart::setEncoding(const QString&encoding)
179{ 179{
180 m_encoding = encoding; 180 m_encoding = encoding;
181} 181}
182 182
183const QString& RecPart::Description()const 183const QString& RecPart::Description()const
184{ 184{
185 return m_description; 185 return m_description;
186} 186}
187 187
188void RecPart::setDescription(const QString&desc) 188void RecPart::setDescription(const QString&desc)
189{ 189{
190 m_description = desc; 190 m_description = desc;
191} 191}
192 192
193void RecPart::setParameters(const part_plist_t&list) 193void RecPart::setParameters(const part_plist_t&list)
194{ 194{
195 m_Parameters = list; 195 m_Parameters = list;
196} 196}
197 197
198const part_plist_t& RecPart::Parameters()const 198const part_plist_t& RecPart::Parameters()const
199{ 199{
200 return m_Parameters; 200 return m_Parameters;
201} 201}
202 202
203void RecPart::addParameter(const QString&key,const QString&value) 203void RecPart::addParameter(const QString&key,const QString&value)
204{ 204{
205 m_Parameters[key]=value; 205 m_Parameters[key]=value;
206} 206}
207 207
208const QString RecPart::searchParamter(const QString&key)const 208const QString RecPart::searchParamter(const QString&key)const
209{ 209{
210 QString value(""); 210 QString value("");
211 part_plist_t::ConstIterator it = m_Parameters.find(key); 211 part_plist_t::ConstIterator it = m_Parameters.find(key);
212 if (it != m_Parameters.end()) { 212 if (it != m_Parameters.end()) {
213 value = it.data(); 213 value = it.data();
214 } 214 }
215 return value; 215 return value;
216} 216}
217 217
218void RecPart::setPositionlist(const QValueList<int>&poslist) 218void RecPart::setPositionlist(const QValueList<int>&poslist)
219{ 219{
220 m_poslist = poslist; 220 m_poslist = poslist;
221} 221}
222 222
223const QValueList<int>& RecPart::Positionlist()const 223const QValueList<int>& RecPart::Positionlist()const
224{ 224{
225 return m_poslist; 225 return m_poslist;
226} 226}
227 227
228RecBody::RecBody() 228RecBody::RecBody()
229 : m_BodyText(),m_PartsList(),m_description() 229 : m_BodyText(),m_PartsList(),m_description()
230{ 230{
231 m_PartsList.clear(); 231 m_PartsList.clear();
232} 232}
233 233
234RecBody::~RecBody() 234RecBody::~RecBody()
235{ 235{
236} 236}
237 237
238void RecBody::setBodytext(const QString&bodyText) 238void RecBody::setBodytext(const QString&bodyText)
239{ 239{
240 m_BodyText = bodyText; 240 m_BodyText = bodyText;
241} 241}
242 242
243const QString& RecBody::Bodytext()const 243const QString& RecBody::Bodytext()const
244{ 244{
245 return m_BodyText; 245 return m_BodyText;
246} 246}
247 247
248void RecBody::setParts(const QValueList<RecPart>&parts) 248void RecBody::setParts(const QValueList<RecPart>&parts)
249{ 249{
250 m_PartsList.clear(); 250 m_PartsList.clear();
251 m_PartsList = parts; 251 m_PartsList = parts;
252} 252}
253 253
254const QValueList<RecPart>& RecBody::Parts()const 254const QValueList<RecPart>& RecBody::Parts()const
255{ 255{
256 return m_PartsList; 256 return m_PartsList;
257} 257}
258 258
259void RecBody::addPart(const RecPart& part) 259void RecBody::addPart(const RecPart& part)
260{ 260{
261 m_PartsList.append(part); 261 m_PartsList.append(part);
262} 262}
263 263
264void RecBody::setDescription(const RecPart&des) 264void RecBody::setDescription(const RecPart&des)
265{ 265{
266 m_description = des; 266 m_description = des;
267} 267}
268 268
269const RecPart& RecBody::Description()const 269const RecPart& RecBody::Description()const
270{ 270{
271 return m_description; 271 return m_description;
272} 272}
273 273
274/* handling encoded content */ 274/* handling encoded content */
275encodedString::encodedString() 275encodedString::encodedString()
276{ 276{
277 init(); 277 init();
278} 278}
279 279
280encodedString::encodedString(const char*nContent,unsigned int nSize) 280encodedString::encodedString(const char*nContent,unsigned int nSize)
281{ 281{
282 init(); 282 init();
283 setContent(nContent,nSize); 283 setContent(nContent,nSize);
284} 284}
285 285
286encodedString::encodedString(char*nContent,unsigned int nSize) 286encodedString::encodedString(char*nContent,unsigned int nSize)
287{ 287{
288 init(); 288 init();
289 setContent(nContent,nSize); 289 setContent(nContent,nSize);
290} 290}
291 291
292encodedString::encodedString(const encodedString&old) 292encodedString::encodedString(const encodedString&old)
293{ 293{
294 init(); 294 init();
295 copy_old(old); 295 copy_old(old);
296 qDebug("encodedeString: copy constructor!"); 296 qDebug("encodedeString: copy constructor!");
297} 297}
298 298
299encodedString& encodedString::operator=(const encodedString&old) 299encodedString& encodedString::operator=(const encodedString&old)
300{ 300{
301 init(); 301 init();
302 copy_old(old); 302 copy_old(old);
303 qDebug("encodedString: assign operator!"); 303 qDebug("encodedString: assign operator!");
304 return *this; 304 return *this;
305} 305}
306 306
307encodedString::~encodedString() 307encodedString::~encodedString()
308{ 308{
309 clean(); 309 clean();
310} 310}
311 311
312void encodedString::init() 312void encodedString::init()
313{ 313{
314 content = 0; 314 content = 0;
315 size = 0; 315 size = 0;
316} 316}
317 317
318void encodedString::clean() 318void encodedString::clean()
319{ 319{
320 if (content) { 320 if (content) {
321 free(content); 321 free(content);
322 } 322 }
323 content = 0; 323 content = 0;
324 size = 0; 324 size = 0;
325} 325}
326 326
327void encodedString::copy_old(const encodedString&old) 327void encodedString::copy_old(const encodedString&old)
328{ 328{
329 clean(); 329 clean();
330 if (old.size>0 && old.content) { 330 if (old.size>0 && old.content) {
331 content = (char*)malloc(old.size*sizeof(char)); 331 content = (char*)malloc(old.size*sizeof(char));
332 memcpy(content,old.content,size); 332 memcpy(content,old.content,size);
333 size = old.size; 333 size = old.size;
334 } 334 }
335} 335}
336 336
337const char*encodedString::Content()const 337const char*encodedString::Content()const
338{ 338{
339 return content; 339 return content;
340} 340}
341 341
342const int encodedString::Length()const 342const int encodedString::Length()const
343{ 343{
344 return size; 344 return size;
345} 345}
346 346
347void encodedString::setContent(const char*nContent,int nSize) 347void encodedString::setContent(const char*nContent,int nSize)
348{ 348{
349 if (nSize>0 && nContent) { 349 if (nSize>0 && nContent) {
350 content = (char*)malloc(nSize*sizeof(char)); 350 content = (char*)malloc(nSize*sizeof(char));
351 memcpy(content,nContent,nSize); 351 memcpy(content,nContent,nSize);
352 size = nSize; 352 size = nSize;
353 } 353 }
354} 354}
355 355
356void encodedString::setContent(char*nContent,int nSize) 356void encodedString::setContent(char*nContent,int nSize)
357{ 357{
358 content = nContent; 358 content = nContent;
359 size = nSize; 359 size = nSize;
360} 360}
361 361
362folderStat&folderStat::operator=(const folderStat&old) 362folderStat&folderStat::operator=(const folderStat&old)
363{ 363{
364 message_count = old.message_count; 364 message_count = old.message_count;
365 message_unseen = old.message_unseen; 365 message_unseen = old.message_unseen;
366 message_recent = old.message_recent; 366 message_recent = old.message_recent;
367 return *this; 367 return *this;
368} 368}
369 369
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.h b/noncore/net/mail/libmailwrapper/mailtypes.h
index 10d367f..dc10de6 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.h
+++ b/noncore/net/mail/libmailwrapper/mailtypes.h
@@ -1,197 +1,200 @@
1#ifndef __MAIL_TYPES_H 1#ifndef __MAIL_TYPES_H
2#define __MAIL_TYPES_H 2#define __MAIL_TYPES_H
3 3
4#define FLAG_ANSWERED 0 4#define FLAG_ANSWERED 0
5#define FLAG_FLAGGED 1 5#define FLAG_FLAGGED 1
6#define FLAG_DELETED 2 6#define FLAG_DELETED 2
7#define FLAG_SEEN 3 7#define FLAG_SEEN 3
8#define FLAG_DRAFT 4 8#define FLAG_DRAFT 4
9#define FLAG_RECENT 5 9#define FLAG_RECENT 5
10 10
11#include <opie2/osmartpointer.h>
12
11#include <qbitarray.h> 13#include <qbitarray.h>
12#include <qstring.h> 14#include <qstring.h>
13#include <qstringlist.h> 15#include <qstringlist.h>
14#include <qmap.h> 16#include <qmap.h>
15#include <qvaluelist.h> 17#include <qvaluelist.h>
16 18
17class AbstractMail; 19class AbstractMail;
18/* a class to describe mails in a mailbox */ 20/* a class to describe mails in a mailbox */
19/* Attention! 21/* Attention!
20 From programmers point of view it would make sense to 22 From programmers point of view it would make sense to
21 store the mail body into this class, too. 23 store the mail body into this class, too.
22 But: not from the point of view of the device. 24 But: not from the point of view of the device.
23 Mailbodies can be real large. So we request them when 25 Mailbodies can be real large. So we request them when
24 needed from the mail-wrapper class direct from the server itself 26 needed from the mail-wrapper class direct from the server itself
25 (imap) or from a file-based cache (pop3?) 27 (imap) or from a file-based cache (pop3?)
26 So there is no interface "const QString&body()" but you should 28 So there is no interface "const QString&body()" but you should
27 make a request to the mailwrapper with this class as parameter to 29 make a request to the mailwrapper with this class as parameter to
28 get the body. Same words for the attachments. 30 get the body. Same words for the attachments.
29*/ 31*/
30class RecMail 32class RecMail:public Opie::ORefCount
31{ 33{
32public: 34public:
33 RecMail(); 35 RecMail();
34 RecMail(const RecMail&old); 36 RecMail(const RecMail&old);
35 virtual ~RecMail(); 37 virtual ~RecMail();
36 38
37 const int getNumber()const{return msg_number;} 39 const unsigned int getNumber()const{return msg_number;}
38 void setNumber(int number){msg_number=number;} 40 void setNumber(unsigned int number){msg_number=number;}
39 const QString&getDate()const{ return date; } 41 const QString&getDate()const{ return date; }
40 void setDate( const QString&a ) { date = a; } 42 void setDate( const QString&a ) { date = a; }
41 const QString&getFrom()const{ return from; } 43 const QString&getFrom()const{ return from; }
42 void setFrom( const QString&a ) { from = a; } 44 void setFrom( const QString&a ) { from = a; }
43 const QString&getSubject()const { return subject; } 45 const QString&getSubject()const { return subject; }
44 void setSubject( const QString&s ) { subject = s; } 46 void setSubject( const QString&s ) { subject = s; }
45 const QString&getMbox()const{return mbox;} 47 const QString&getMbox()const{return mbox;}
46 void setMbox(const QString&box){mbox = box;} 48 void setMbox(const QString&box){mbox = box;}
47 void setMsgid(const QString&id){msg_id=id;} 49 void setMsgid(const QString&id){msg_id=id;}
48 const QString&Msgid()const{return msg_id;} 50 const QString&Msgid()const{return msg_id;}
49 void setReplyto(const QString&reply){replyto=reply;} 51 void setReplyto(const QString&reply){replyto=reply;}
50 const QString&Replyto()const{return replyto;} 52 const QString&Replyto()const{return replyto;}
51 void setMsgsize(int size){msg_size = size;} 53 void setMsgsize(unsigned int size){msg_size = size;}
52 const int Msgsize()const{return msg_size;} 54 const unsigned int Msgsize()const{return msg_size;}
53 55
54 56
55 void setTo(const QStringList&list); 57 void setTo(const QStringList&list);
56 const QStringList&To()const; 58 const QStringList&To()const;
57 void setCC(const QStringList&list); 59 void setCC(const QStringList&list);
58 const QStringList&CC()const; 60 const QStringList&CC()const;
59 void setBcc(const QStringList&list); 61 void setBcc(const QStringList&list);
60 const QStringList&Bcc()const; 62 const QStringList&Bcc()const;
61 void setInreply(const QStringList&list); 63 void setInreply(const QStringList&list);
62 const QStringList&Inreply()const; 64 const QStringList&Inreply()const;
63 void setReferences(const QStringList&list); 65 void setReferences(const QStringList&list);
64 const QStringList&References()const; 66 const QStringList&References()const;
65 67
66 const QBitArray&getFlags()const{return msg_flags;} 68 const QBitArray&getFlags()const{return msg_flags;}
67 void setFlags(const QBitArray&flags){msg_flags = flags;} 69 void setFlags(const QBitArray&flags){msg_flags = flags;}
68 70
69 void setWrapper(AbstractMail*wrapper); 71 void setWrapper(AbstractMail*wrapper);
70 AbstractMail* Wrapper(); 72 AbstractMail* Wrapper();
71 73
72protected: 74protected:
73 QString subject,date,from,mbox,msg_id,replyto; 75 QString subject,date,from,mbox,msg_id,replyto;
74 int msg_number,msg_size; 76 unsigned int msg_number,msg_size;
75 QBitArray msg_flags; 77 QBitArray msg_flags;
76 QStringList to,cc,bcc,in_reply_to,references; 78 QStringList to,cc,bcc,in_reply_to,references;
77 AbstractMail*wrapper; 79 AbstractMail*wrapper;
78 void init(); 80 void init();
79 void copy_old(const RecMail&old); 81 void copy_old(const RecMail&old);
80}; 82};
81 83
84typedef Opie::OSmartPointer<RecMail> RecMailP;
82typedef QMap<QString,QString> part_plist_t; 85typedef QMap<QString,QString> part_plist_t;
83 86
84class RecPart 87class RecPart
85{ 88{
86protected: 89protected:
87 QString m_type,m_subtype,m_identifier,m_encoding,m_description; 90 QString m_type,m_subtype,m_identifier,m_encoding,m_description;
88 unsigned int m_lines,m_size; 91 unsigned int m_lines,m_size;
89 part_plist_t m_Parameters; 92 part_plist_t m_Parameters;
90 /* describes the position in the mail */ 93 /* describes the position in the mail */
91 QValueList<int> m_poslist; 94 QValueList<int> m_poslist;
92 95
93public: 96public:
94 RecPart(); 97 RecPart();
95 virtual ~RecPart(); 98 virtual ~RecPart();
96 99
97 const QString&Type()const; 100 const QString&Type()const;
98 void setType(const QString&type); 101 void setType(const QString&type);
99 const QString&Subtype()const; 102 const QString&Subtype()const;
100 void setSubtype(const QString&subtype); 103 void setSubtype(const QString&subtype);
101 const QString&Identifier()const; 104 const QString&Identifier()const;
102 void setIdentifier(const QString&identifier); 105 void setIdentifier(const QString&identifier);
103 const QString&Encoding()const; 106 const QString&Encoding()const;
104 void setEncoding(const QString&encoding); 107 void setEncoding(const QString&encoding);
105 const QString&Description()const; 108 const QString&Description()const;
106 void setDescription(const QString&desc); 109 void setDescription(const QString&desc);
107 void setLines(unsigned int lines); 110 void setLines(unsigned int lines);
108 const unsigned int Lines()const; 111 const unsigned int Lines()const;
109 void setSize(unsigned int size); 112 void setSize(unsigned int size);
110 const unsigned int Size()const; 113 const unsigned int Size()const;
111 114
112 115
113 void setParameters(const part_plist_t&list); 116 void setParameters(const part_plist_t&list);
114 const part_plist_t&Parameters()const; 117 const part_plist_t&Parameters()const;
115 void addParameter(const QString&key,const QString&value); 118 void addParameter(const QString&key,const QString&value);
116 const QString searchParamter(const QString&key)const; 119 const QString searchParamter(const QString&key)const;
117 void setPositionlist(const QValueList<int>&poslist); 120 void setPositionlist(const QValueList<int>&poslist);
118 const QValueList<int>& Positionlist()const; 121 const QValueList<int>& Positionlist()const;
119}; 122};
120 123
121class RecBody 124class RecBody
122{ 125{
123protected: 126protected:
124 QString m_BodyText; 127 QString m_BodyText;
125 QValueList<RecPart> m_PartsList; 128 QValueList<RecPart> m_PartsList;
126 RecPart m_description; 129 RecPart m_description;
127 130
128public: 131public:
129 RecBody(); 132 RecBody();
130 virtual ~RecBody(); 133 virtual ~RecBody();
131 void setBodytext(const QString&); 134 void setBodytext(const QString&);
132 const QString& Bodytext()const; 135 const QString& Bodytext()const;
133 136
134 void setDescription(const RecPart&des); 137 void setDescription(const RecPart&des);
135 const RecPart& Description()const; 138 const RecPart& Description()const;
136 139
137 void setParts(const QValueList<RecPart>&parts); 140 void setParts(const QValueList<RecPart>&parts);
138 const QValueList<RecPart>& Parts()const; 141 const QValueList<RecPart>& Parts()const;
139 void addPart(const RecPart&part); 142 void addPart(const RecPart&part);
140}; 143};
141 144
142class encodedString 145class encodedString
143{ 146{
144public: 147public:
145 encodedString(); 148 encodedString();
146 /* 149 /*
147 creates an new content string. 150 creates an new content string.
148 it makes a deep copy of it! 151 it makes a deep copy of it!
149 */ 152 */
150 encodedString(const char*nContent,unsigned int length); 153 encodedString(const char*nContent,unsigned int length);
151 /* 154 /*
152 Take over the nContent. Means: it will just copy the pointer, not the content. 155 Take over the nContent. Means: it will just copy the pointer, not the content.
153 so make sure: No one else frees the string, the string has allocated with 156 so make sure: No one else frees the string, the string has allocated with
154 malloc for compatibility with c-based libs 157 malloc for compatibility with c-based libs
155 */ 158 */
156 encodedString(char*nContent,unsigned int nSize); 159 encodedString(char*nContent,unsigned int nSize);
157 /* copy construkor - makes ALWAYS a deep copy!!!! */ 160 /* copy construkor - makes ALWAYS a deep copy!!!! */
158 encodedString(const encodedString&old); 161 encodedString(const encodedString&old);
159 /* assign operator - makes ALWAYS a deep copy!!!! */ 162 /* assign operator - makes ALWAYS a deep copy!!!! */
160 encodedString& operator=(const encodedString&old); 163 encodedString& operator=(const encodedString&old);
161 /* destructor - cleans the content */ 164 /* destructor - cleans the content */
162 virtual ~encodedString(); 165 virtual ~encodedString();
163 166
164 /* returns a pointer to the content - do not delete yoursel! */ 167 /* returns a pointer to the content - do not delete yoursel! */
165 const char*Content()const; 168 const char*Content()const;
166 /* returns the lengths of the content 'cause it must not be a null-terminated string! */ 169 /* returns the lengths of the content 'cause it must not be a null-terminated string! */
167 const int Length()const; 170 const int Length()const;
168 171
169 /* 172 /*
170 makes a deep copy of nContent! 173 makes a deep copy of nContent!
171 */ 174 */
172 void setContent(const char*nContent,int nSize); 175 void setContent(const char*nContent,int nSize);
173 /* 176 /*
174 Take over the nContent. Means: it will just copy the pointer, not the content. 177 Take over the nContent. Means: it will just copy the pointer, not the content.
175 so make sure: No one else frees the string, the string has allocated with 178 so make sure: No one else frees the string, the string has allocated with
176 malloc for compatibility with c-based libs 179 malloc for compatibility with c-based libs
177 */ 180 */
178 void setContent(char*nContent,int nSize); 181 void setContent(char*nContent,int nSize);
179 182
180protected: 183protected:
181 char * content; 184 char * content;
182 unsigned int size; 185 unsigned int size;
183 186
184 void init(); 187 void init();
185 void copy_old(const encodedString&old); 188 void copy_old(const encodedString&old);
186 void clean(); 189 void clean();
187}; 190};
188 191
189struct folderStat 192struct folderStat
190{ 193{
191 unsigned int message_count; 194 unsigned int message_count;
192 unsigned int message_unseen; 195 unsigned int message_unseen;
193 unsigned int message_recent; 196 unsigned int message_recent;
194 folderStat&operator=(const folderStat&old); 197 folderStat&operator=(const folderStat&old);
195}; 198};
196 199
197#endif 200#endif
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
index c71d69f..9bf2fd3 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
@@ -1,178 +1,178 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <sys/stat.h> 2#include <sys/stat.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <fcntl.h> 5#include <fcntl.h>
6#include <string.h> 6#include <string.h>
7#include <qdir.h> 7#include <qdir.h>
8 8
9#include "mailwrapper.h" 9#include "mailwrapper.h"
10//#include "logindialog.h" 10//#include "logindialog.h"
11//#include "defines.h" 11//#include "defines.h"
12 12
13#define UNDEFINED 64 13#define UNDEFINED 64
14#define MAXLINE 76 14#define MAXLINE 76
15#define UTF16MASK 0x03FFUL 15#define UTF16MASK 0x03FFUL
16#define UTF16SHIFT 10 16#define UTF16SHIFT 10
17#define UTF16BASE 0x10000UL 17#define UTF16BASE 0x10000UL
18#define UTF16HIGHSTART 0xD800UL 18#define UTF16HIGHSTART 0xD800UL
19#define UTF16HIGHEND 0xDBFFUL 19#define UTF16HIGHEND 0xDBFFUL
20#define UTF16LOSTART 0xDC00UL 20#define UTF16LOSTART 0xDC00UL
21#define UTF16LOEND 0xDFFFUL 21#define UTF16LOEND 0xDFFFUL
22 22
23 23
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 prefix = "";
36} 36}
37 37
38Folder::~Folder() 38Folder::~Folder()
39{ 39{
40} 40}
41 41
42const QString& Folder::Separator()const 42const QString& Folder::Separator()const
43{ 43{
44 return separator; 44 return separator;
45} 45}
46 46
47IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&aprefix ) 47IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&aprefix )
48 : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf) 48 : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf)
49{ 49{
50 // Decode IMAP foldername 50 // Decode IMAP foldername
51 nameDisplay = IMAPFolder::decodeFolderName( name ); 51 nameDisplay = IMAPFolder::decodeFolderName( name );
52 /* 52 /*
53 qDebug( "folder " + name + " - displayed as " + nameDisplay ); 53 qDebug( "folder " + name + " - displayed as " + nameDisplay );
54 */ 54 */
55 prefix = aprefix; 55 prefix = aprefix;
56 56
57 if (prefix.length()>0) { 57 if (prefix.length()>0) {
58 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { 58 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) {
59 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); 59 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length());
60 } 60 }
61 } 61 }
62} 62}
63 63
64IMAPFolder::~IMAPFolder() 64IMAPFolder::~IMAPFolder()
65{ 65{
66} 66}
67 67
68static unsigned char base64chars[] = 68static unsigned char base64chars[] =
69 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; 69 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
70 70
71/** 71/**
72 * Decodes base64 encoded parts of the imapfolder name 72 * Decodes base64 encoded parts of the imapfolder name
73 * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc 73 * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc
74 */ 74 */
75QString IMAPFolder::decodeFolderName( const QString &name ) 75QString IMAPFolder::decodeFolderName( const QString &name )
76{ 76{
77 unsigned char c, i, bitcount; 77 unsigned char c, i, bitcount;
78 unsigned long ucs4, utf16, bitbuf; 78 unsigned long ucs4, utf16, bitbuf;
79 unsigned char base64[256], utf8[6]; 79 unsigned char base64[256], utf8[6];
80 unsigned long srcPtr = 0; 80 unsigned long srcPtr = 0;
81 QCString dst = ""; 81 QCString dst = "";
82 QCString src = name.ascii(); 82 QCString src = name.ascii();
83 83
84 /* initialize modified base64 decoding table */ 84 /* initialize modified base64 decoding table */
85 memset(base64, UNDEFINED, sizeof(base64)); 85 memset(base64, UNDEFINED, sizeof(base64));
86 for (i = 0; i < sizeof(base64chars); ++i) { 86 for (i = 0; i < sizeof(base64chars); ++i) {
87 base64[(int)base64chars[i]] = i; 87 base64[(int)base64chars[i]] = i;
88 } 88 }
89 89
90 /* loop until end of string */ 90 /* loop until end of string */
91 while (srcPtr < src.length ()) { 91 while (srcPtr < src.length ()) {
92 c = src[srcPtr++]; 92 c = src[srcPtr++];
93 /* deal with literal characters and &- */ 93 /* deal with literal characters and &- */
94 if (c != '&' || src[srcPtr] == '-') { 94 if (c != '&' || src[srcPtr] == '-') {
95 /* encode literally */ 95 /* encode literally */
96 dst += c; 96 dst += c;
97 /* skip over the '-' if this is an &- sequence */ 97 /* skip over the '-' if this is an &- sequence */
98 if (c == '&') 98 if (c == '&')
99 srcPtr++; 99 srcPtr++;
100 } else { 100 } else {
101 /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */ 101 /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */
102 bitbuf = 0; 102 bitbuf = 0;
103 bitcount = 0; 103 bitcount = 0;
104 ucs4 = 0; 104 ucs4 = 0;
105 while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) { 105 while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) {
106 ++srcPtr; 106 ++srcPtr;
107 bitbuf = (bitbuf << 6) | c; 107 bitbuf = (bitbuf << 6) | c;
108 bitcount += 6; 108 bitcount += 6;
109 /* enough bits for a UTF-16 character? */ 109 /* enough bits for a UTF-16 character? */
110 if (bitcount >= 16) { 110 if (bitcount >= 16) {
111 bitcount -= 16; 111 bitcount -= 16;
112 utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; 112 utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff;
113 /* convert UTF16 to UCS4 */ 113 /* convert UTF16 to UCS4 */
114 if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { 114 if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) {
115 ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; 115 ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT;
116 continue; 116 continue;
117 } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { 117 } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) {
118 ucs4 += utf16 - UTF16LOSTART + UTF16BASE; 118 ucs4 += utf16 - UTF16LOSTART + UTF16BASE;
119 } else { 119 } else {
120 ucs4 = utf16; 120 ucs4 = utf16;
121 } 121 }
122 /* convert UTF-16 range of UCS4 to UTF-8 */ 122 /* convert UTF-16 range of UCS4 to UTF-8 */
123 if (ucs4 <= 0x7fUL) { 123 if (ucs4 <= 0x7fUL) {
124 utf8[0] = ucs4; 124 utf8[0] = ucs4;
125 i = 1; 125 i = 1;
126 } else if (ucs4 <= 0x7ffUL) { 126 } else if (ucs4 <= 0x7ffUL) {
127 utf8[0] = 0xc0 | (ucs4 >> 6); 127 utf8[0] = 0xc0 | (ucs4 >> 6);
128 utf8[1] = 0x80 | (ucs4 & 0x3f); 128 utf8[1] = 0x80 | (ucs4 & 0x3f);
129 i = 2; 129 i = 2;
130 } else if (ucs4 <= 0xffffUL) { 130 } else if (ucs4 <= 0xffffUL) {
131 utf8[0] = 0xe0 | (ucs4 >> 12); 131 utf8[0] = 0xe0 | (ucs4 >> 12);
132 utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f); 132 utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f);
133 utf8[2] = 0x80 | (ucs4 & 0x3f); 133 utf8[2] = 0x80 | (ucs4 & 0x3f);
134 i = 3; 134 i = 3;
135 } else { 135 } else {
136 utf8[0] = 0xf0 | (ucs4 >> 18); 136 utf8[0] = 0xf0 | (ucs4 >> 18);
137 utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f); 137 utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f);
138 utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f); 138 utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f);
139 utf8[3] = 0x80 | (ucs4 & 0x3f); 139 utf8[3] = 0x80 | (ucs4 & 0x3f);
140 i = 4; 140 i = 4;
141 } 141 }
142 /* copy it */ 142 /* copy it */
143 for (c = 0; c < i; ++c) { 143 for (c = 0; c < i; ++c) {
144 dst += utf8[c]; 144 dst += utf8[c];
145 } 145 }
146 } 146 }
147 } 147 }
148 /* skip over trailing '-' in modified UTF-7 encoding */ 148 /* skip over trailing '-' in modified UTF-7 encoding */
149 if (src[srcPtr] == '-') 149 if (src[srcPtr] == '-')
150 ++srcPtr; 150 ++srcPtr;
151 } 151 }
152 } 152 }
153 153
154 return QString::fromUtf8( dst.data() ); 154 return QString::fromUtf8( dst.data() );
155} 155}
156 156
157Mail::Mail() 157Mail::Mail()
158 :Opie::oref_count(),name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") 158 :Opie::ORefCount(),name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("")
159{ 159{
160} 160}
161 161
162MHFolder::MHFolder(const QString&disp_name,const QString&mbox) 162MHFolder::MHFolder(const QString&disp_name,const QString&mbox)
163 : Folder( disp_name,"/" ) 163 : Folder( disp_name,"/" )
164{ 164{
165 separator = "/"; 165 separator = "/";
166 name = mbox; 166 name = mbox;
167 if (!disp_name.startsWith("/") && disp_name.length()>0) 167 if (!disp_name.startsWith("/") && disp_name.length()>0)
168 name+="/"; 168 name+="/";
169 name+=disp_name; 169 name+=disp_name;
170 if (disp_name.length()==0) { 170 if (disp_name.length()==0) {
171 nameDisplay = separator; 171 nameDisplay = separator;
172 } 172 }
173 prefix = mbox; 173 prefix = mbox;
174} 174}
175 175
176MHFolder::~MHFolder() 176MHFolder::~MHFolder()
177{ 177{
178} 178}
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h
index 3b3bb32..6bf0078 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.h
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.h
@@ -1,106 +1,106 @@
1#ifndef MAILWRAPPER_H 1#ifndef MAILWRAPPER_H
2#define MAILWRAPPER_H 2#define MAILWRAPPER_H
3 3
4#include <qpe/applnk.h> 4#include <qpe/applnk.h>
5 5
6#include <qbitarray.h> 6#include <qbitarray.h>
7#include <qdatetime.h> 7#include <qdatetime.h>
8 8
9#include "settings.h" 9#include "settings.h"
10 10
11#include <opie2/osmart_pointer.h> 11#include <opie2/osmartpointer.h>
12 12
13class Attachment 13class Attachment
14{ 14{
15public: 15public:
16 Attachment( DocLnk lnk ); 16 Attachment( DocLnk lnk );
17 virtual ~Attachment(){} 17 virtual ~Attachment(){}
18 const QString getFileName()const{ return doc.file(); } 18 const QString getFileName()const{ return doc.file(); }
19 const QString getName()const{ return doc.name(); } 19 const QString getName()const{ return doc.name(); }
20 const QString getMimeType()const{ return doc.type(); } 20 const QString getMimeType()const{ return doc.type(); }
21 const QPixmap getPixmap()const{ return doc.pixmap(); } 21 const QPixmap getPixmap()const{ return doc.pixmap(); }
22 const int getSize()const { return size; } 22 const int getSize()const { return size; }
23 DocLnk getDocLnk() { return doc; } 23 DocLnk getDocLnk() { return doc; }
24 24
25protected: 25protected:
26 DocLnk doc; 26 DocLnk doc;
27 int size; 27 int size;
28 28
29}; 29};
30 30
31class Mail:public Opie::oref_count 31class Mail:public Opie::ORefCount
32{ 32{
33public: 33public:
34 Mail(); 34 Mail();
35 /* Possible that this destructor must not be declared virtual 35 /* Possible that this destructor must not be declared virtual
36 * 'cause it seems that it will never have some child classes. 36 * 'cause it seems that it will never have some child classes.
37 * in this case this object will not get a virtual table -> memory and 37 * in this case this object will not get a virtual table -> memory and
38 * speed will be a little bit better? 38 * speed will be a little bit better?
39 */ 39 */
40 virtual ~Mail(){} 40 virtual ~Mail(){}
41 void addAttachment( Attachment *att ) { attList.append( att ); } 41 void addAttachment( Attachment *att ) { attList.append( att ); }
42 const QList<Attachment>& getAttachments()const { return attList; } 42 const QList<Attachment>& getAttachments()const { return attList; }
43 void removeAttachment( Attachment *att ) { attList.remove( att ); } 43 void removeAttachment( Attachment *att ) { attList.remove( att ); }
44 const QString&getName()const { return name; } 44 const QString&getName()const { return name; }
45 void setName( QString s ) { name = s; } 45 void setName( QString s ) { name = s; }
46 const QString&getMail()const{ return mail; } 46 const QString&getMail()const{ return mail; }
47 void setMail( const QString&s ) { mail = s; } 47 void setMail( const QString&s ) { mail = s; }
48 const QString&getTo()const{ return to; } 48 const QString&getTo()const{ return to; }
49 void setTo( const QString&s ) { to = s; } 49 void setTo( const QString&s ) { to = s; }
50 const QString&getCC()const{ return cc; } 50 const QString&getCC()const{ return cc; }
51 void setCC( const QString&s ) { cc = s; } 51 void setCC( const QString&s ) { cc = s; }
52 const QString&getBCC()const { return bcc; } 52 const QString&getBCC()const { return bcc; }
53 void setBCC( const QString&s ) { bcc = s; } 53 void setBCC( const QString&s ) { bcc = s; }
54 const QString&getMessage()const { return message; } 54 const QString&getMessage()const { return message; }
55 void setMessage( const QString&s ) { message = s; } 55 void setMessage( const QString&s ) { message = s; }
56 const QString&getSubject()const { return subject; } 56 const QString&getSubject()const { return subject; }
57 void setSubject( const QString&s ) { subject = s; } 57 void setSubject( const QString&s ) { subject = s; }
58 const QString&getReply()const{ return reply; } 58 const QString&getReply()const{ return reply; }
59 void setReply( const QString&a ) { reply = a; } 59 void setReply( const QString&a ) { reply = a; }
60 void setInreply(const QStringList&list){m_in_reply_to = list;} 60 void setInreply(const QStringList&list){m_in_reply_to = list;}
61 const QStringList&Inreply()const{return m_in_reply_to;} 61 const QStringList&Inreply()const{return m_in_reply_to;}
62 62
63private: 63private:
64 QList<Attachment> attList; 64 QList<Attachment> attList;
65 QString name, mail, to, cc, bcc, reply, subject, message; 65 QString name, mail, to, cc, bcc, reply, subject, message;
66 QStringList m_in_reply_to; 66 QStringList m_in_reply_to;
67}; 67};
68 68
69class Folder:public Opie::oref_count 69class Folder:public Opie::ORefCount
70{ 70{
71public: 71public:
72 Folder( const QString&init_name,const QString&sep ); 72 Folder( const QString&init_name,const QString&sep );
73 virtual ~Folder(); 73 virtual ~Folder();
74 const QString&getDisplayName()const { return nameDisplay; } 74 const QString&getDisplayName()const { return nameDisplay; }
75 const QString&getName()const { return name; } 75 const QString&getName()const { return name; }
76 const QString&getPrefix()const{return prefix; } 76 const QString&getPrefix()const{return prefix; }
77 virtual bool may_select()const{return true;} 77 virtual bool may_select()const{return true;}
78 virtual bool no_inferior()const{return true;} 78 virtual bool no_inferior()const{return true;}
79 const QString&Separator()const; 79 const QString&Separator()const;
80 80
81protected: 81protected:
82 QString nameDisplay, name, separator,prefix; 82 QString nameDisplay, name, separator,prefix;
83}; 83};
84 84
85typedef Opie::osmart_pointer<Folder> FolderP; 85typedef Opie::OSmartPointer<Folder> FolderP;
86 86
87class MHFolder : public Folder 87class MHFolder : public Folder
88{ 88{
89public: 89public:
90 MHFolder(const QString&disp_name,const QString&mbox); 90 MHFolder(const QString&disp_name,const QString&mbox);
91 virtual ~MHFolder(); 91 virtual ~MHFolder();
92}; 92};
93 93
94class IMAPFolder : public Folder 94class IMAPFolder : public Folder
95{ 95{
96 public: 96 public:
97 IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" ); 97 IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" );
98 virtual ~IMAPFolder(); 98 virtual ~IMAPFolder();
99 virtual bool may_select()const{return m_MaySelect;} 99 virtual bool may_select()const{return m_MaySelect;}
100 virtual bool no_inferior()const{return m_NoInferior;} 100 virtual bool no_inferior()const{return m_NoInferior;}
101 private: 101 private:
102 static QString decodeFolderName( const QString &name ); 102 static QString decodeFolderName( const QString &name );
103 bool m_MaySelect,m_NoInferior; 103 bool m_MaySelect,m_NoInferior;
104}; 104};
105 105
106#endif 106#endif
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp
index 9ff3de2..5e6b714 100644
--- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp
@@ -1,334 +1,335 @@
1#include "mboxwrapper.h" 1#include "mboxwrapper.h"
2#include "mailtypes.h" 2#include "mailtypes.h"
3#include "mailwrapper.h" 3#include "mailwrapper.h"
4#include <libetpan/libetpan.h> 4#include <libetpan/libetpan.h>
5#include <qdir.h> 5#include <qdir.h>
6#include <stdlib.h> 6#include <stdlib.h>
7#include <qpe/global.h> 7#include <qpe/global.h>
8 8
9MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name) 9MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name)
10 : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name) 10 : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name)
11{ 11{
12 QDir dir(MBOXPath); 12 QDir dir(MBOXPath);
13 if (!dir.exists()) { 13 if (!dir.exists()) {
14 dir.mkdir(MBOXPath); 14 dir.mkdir(MBOXPath);
15 } 15 }
16} 16}
17 17
18MBOXwrapper::~MBOXwrapper() 18MBOXwrapper::~MBOXwrapper()
19{ 19{
20} 20}
21 21
22void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) 22void MBOXwrapper::listMessages(const QString & mailbox, QValueList<RecMailP> &target )
23{ 23{
24 mailstorage*storage = mailstorage_new(NULL); 24 mailstorage*storage = mailstorage_new(NULL);
25 QString p = MBOXPath+"/"; 25 QString p = MBOXPath+"/";
26 p+=mailbox; 26 p+=mailbox;
27 27
28 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 28 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
29 mailfolder*folder; 29 mailfolder*folder;
30 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 30 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
31 r = mailfolder_connect(folder); 31 r = mailfolder_connect(folder);
32 if (r != MAIL_NO_ERROR) { 32 if (r != MAIL_NO_ERROR) {
33 qDebug("Error initializing mbox"); 33 qDebug("Error initializing mbox");
34 mailfolder_free(folder); 34 mailfolder_free(folder);
35 mailstorage_free(storage); 35 mailstorage_free(storage);
36 return; 36 return;
37 } 37 }
38 38
39 parseList(target,folder->fld_session,mailbox); 39 parseList(target,folder->fld_session,mailbox);
40 40
41 mailfolder_disconnect(folder); 41 mailfolder_disconnect(folder);
42 mailfolder_free(folder); 42 mailfolder_free(folder);
43 mailstorage_free(storage); 43 mailstorage_free(storage);
44 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); 44 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count()));
45} 45}
46 46
47QValueList<Opie::osmart_pointer<Folder> >* MBOXwrapper::listFolders() 47QValueList<Opie::OSmartPointer<Folder> >* MBOXwrapper::listFolders()
48{ 48{
49 QValueList<Opie::osmart_pointer<Folder> >* folders = new QValueList<Opie::osmart_pointer<Folder> >(); 49 QValueList<Opie::OSmartPointer<Folder> >* folders = new QValueList<Opie::OSmartPointer<Folder> >();
50 QDir dir(MBOXPath); 50 QDir dir(MBOXPath);
51 if (!dir.exists()) return folders; 51 if (!dir.exists()) return folders;
52 dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); 52 dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable);
53 QStringList entries = dir.entryList(); 53 QStringList entries = dir.entryList();
54 QStringList::ConstIterator it = entries.begin(); 54 QStringList::ConstIterator it = entries.begin();
55 for (;it!=entries.end();++it) { 55 for (;it!=entries.end();++it) {
56 FolderP inb=new Folder(*it,"/"); 56 FolderP inb=new Folder(*it,"/");
57 folders->append(inb); 57 folders->append(inb);
58 } 58 }
59 return folders; 59 return folders;
60} 60}
61 61
62void MBOXwrapper::deleteMail(const RecMail&mail) 62void MBOXwrapper::deleteMail(const RecMailP & mail)
63{ 63{
64 mailstorage*storage = mailstorage_new(NULL); 64 mailstorage*storage = mailstorage_new(NULL);
65 QString p = MBOXPath+"/"; 65 QString p = MBOXPath+"/";
66 p+=mail.getMbox(); 66 p+=mail->getMbox();
67 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 67 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
68 mailfolder*folder; 68 mailfolder*folder;
69 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 69 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
70 r = mailfolder_connect(folder); 70 r = mailfolder_connect(folder);
71 if (r != MAIL_NO_ERROR) { 71 if (r != MAIL_NO_ERROR) {
72 qDebug("Error initializing mbox"); 72 qDebug("Error initializing mbox");
73 mailfolder_free(folder); 73 mailfolder_free(folder);
74 mailstorage_free(storage); 74 mailstorage_free(storage);
75 return; 75 return;
76 } 76 }
77 r = mailsession_remove_message(folder->fld_session,mail.getNumber()); 77 r = mailsession_remove_message(folder->fld_session,mail->getNumber());
78 if (r != MAIL_NO_ERROR) { 78 if (r != MAIL_NO_ERROR) {
79 qDebug("error deleting mail"); 79 qDebug("error deleting mail");
80 } 80 }
81 mailfolder_free(folder); 81 mailfolder_free(folder);
82 mailstorage_free(storage); 82 mailstorage_free(storage);
83} 83}
84 84
85void MBOXwrapper::answeredMail(const RecMail&) 85void MBOXwrapper::answeredMail(const RecMailP&)
86{ 86{
87} 87}
88 88
89RecBody MBOXwrapper::fetchBody( const RecMail &mail ) 89RecBody MBOXwrapper::fetchBody( const RecMailP &mail )
90{ 90{
91 RecBody body; 91 RecBody body;
92 mailstorage*storage = mailstorage_new(NULL); 92 mailstorage*storage = mailstorage_new(NULL);
93 QString p = MBOXPath+"/"; 93 QString p = MBOXPath+"/";
94 p+=mail.getMbox(); 94 p+=mail->getMbox();
95 mailmessage * msg; 95 mailmessage * msg;
96 char*data=0; 96 char*data=0;
97 size_t size; 97 size_t size;
98 98
99 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 99 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
100 mailfolder*folder; 100 mailfolder*folder;
101 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 101 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
102 r = mailfolder_connect(folder); 102 r = mailfolder_connect(folder);
103 if (r != MAIL_NO_ERROR) { 103 if (r != MAIL_NO_ERROR) {
104 qDebug("Error initializing mbox"); 104 qDebug("Error initializing mbox");
105 mailfolder_free(folder); 105 mailfolder_free(folder);
106 mailstorage_free(storage); 106 mailstorage_free(storage);
107 return body; 107 return body;
108 } 108 }
109 r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); 109 r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg);
110 if (r != MAIL_NO_ERROR) { 110 if (r != MAIL_NO_ERROR) {
111 qDebug("Error fetching mail %i",mail.getNumber()); 111 qDebug("Error fetching mail %i",mail->getNumber());
112 mailfolder_free(folder); 112 mailfolder_free(folder);
113 mailstorage_free(storage); 113 mailstorage_free(storage);
114 return body; 114 return body;
115 } 115 }
116 r = mailmessage_fetch(msg,&data,&size); 116 r = mailmessage_fetch(msg,&data,&size);
117 if (r != MAIL_NO_ERROR) { 117 if (r != MAIL_NO_ERROR) {
118 qDebug("Error fetching mail %i",mail.getNumber()); 118 qDebug("Error fetching mail %i",mail->getNumber());
119 mailfolder_free(folder); 119 mailfolder_free(folder);
120 mailstorage_free(storage); 120 mailstorage_free(storage);
121 mailmessage_free(msg); 121 mailmessage_free(msg);
122 return body; 122 return body;
123 } 123 }
124 body = parseMail(msg); 124 body = parseMail(msg);
125 mailmessage_fetch_result_free(msg,data); 125 mailmessage_fetch_result_free(msg,data);
126 mailfolder_free(folder); 126 mailfolder_free(folder);
127 mailstorage_free(storage); 127 mailstorage_free(storage);
128 128
129 return body; 129 return body;
130} 130}
131 131
132void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) 132void MBOXwrapper::mbox_progress( size_t current, size_t maximum )
133{ 133{
134 qDebug("MBOX %i von %i",current,maximum); 134 qDebug("MBOX %i von %i",current,maximum);
135} 135}
136 136
137int MBOXwrapper::createMbox(const QString&folder,const FolderP&,const QString&,bool ) 137int MBOXwrapper::createMbox(const QString&folder,const FolderP&,const QString&,bool )
138{ 138{
139 QString p = MBOXPath+"/"; 139 QString p = MBOXPath+"/";
140 p+=folder; 140 p+=folder;
141 QFileInfo fi(p); 141 QFileInfo fi(p);
142 if (fi.exists()) { 142 if (fi.exists()) {
143 Global::statusMessage(tr("Mailbox exists.")); 143 Global::statusMessage(tr("Mailbox exists."));
144 return 0; 144 return 0;
145 } 145 }
146 mailmbox_folder*f = 0; 146 mailmbox_folder*f = 0;
147 if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { 147 if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) {
148 Global::statusMessage(tr("Error init folder")); 148 Global::statusMessage(tr("Error init folder"));
149 return 0; 149 return 0;
150 } 150 }
151 if (f) mailmbox_done(f); 151 if (f) mailmbox_done(f);
152 return 1; 152 return 1;
153} 153}
154 154
155void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 155void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
156{ 156{
157 QString p = MBOXPath+"/"; 157 QString p = MBOXPath+"/";
158 p+=folder; 158 p+=folder;
159 mailmbox_folder*f = 0; 159 mailmbox_folder*f = 0;
160 int r = mailmbox_init(p.latin1(),0,1,0,&f); 160 int r = mailmbox_init(p.latin1(),0,1,0,&f);
161 if (r != MAIL_NO_ERROR) { 161 if (r != MAIL_NO_ERROR) {
162 Global::statusMessage(tr("Error init folder")); 162 Global::statusMessage(tr("Error init folder"));
163 return; 163 return;
164 } 164 }
165 r = mailmbox_append_message(f,msg,length); 165 r = mailmbox_append_message(f,msg,length);
166 if (r != MAIL_NO_ERROR) { 166 if (r != MAIL_NO_ERROR) {
167 Global::statusMessage(tr("Error writing to message folder")); 167 Global::statusMessage(tr("Error writing to message folder"));
168 } 168 }
169 mailmbox_done(f); 169 mailmbox_done(f);
170} 170}
171 171
172encodedString* MBOXwrapper::fetchRawBody(const RecMail&mail) 172encodedString* MBOXwrapper::fetchRawBody(const RecMailP&mail)
173{ 173{
174 RecBody body; 174 RecBody body;
175 mailstorage*storage = mailstorage_new(NULL); 175 mailstorage*storage = mailstorage_new(NULL);
176 QString p = MBOXPath+"/"; 176 QString p = MBOXPath+"/";
177 p+=mail.getMbox(); 177 p+=mail->getMbox();
178 mailmessage * msg; 178 mailmessage * msg;
179 char*data=0; 179 char*data=0;
180 size_t size; 180 size_t size;
181 181
182 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 182 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
183 mailfolder*folder; 183 mailfolder*folder;
184 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 184 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
185 r = mailfolder_connect(folder); 185 r = mailfolder_connect(folder);
186 if (r != MAIL_NO_ERROR) { 186 if (r != MAIL_NO_ERROR) {
187 Global::statusMessage(tr("Error initializing mbox")); 187 Global::statusMessage(tr("Error initializing mbox"));
188 mailfolder_free(folder); 188 mailfolder_free(folder);
189 mailstorage_free(storage); 189 mailstorage_free(storage);
190 return 0; 190 return 0;
191 } 191 }
192 r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); 192 r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg);
193 if (r != MAIL_NO_ERROR) { 193 if (r != MAIL_NO_ERROR) {
194 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); 194 Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber()));
195 mailfolder_free(folder); 195 mailfolder_free(folder);
196 mailstorage_free(storage); 196 mailstorage_free(storage);
197 return 0; 197 return 0;
198 } 198 }
199 r = mailmessage_fetch(msg,&data,&size); 199 r = mailmessage_fetch(msg,&data,&size);
200 if (r != MAIL_NO_ERROR) { 200 if (r != MAIL_NO_ERROR) {
201 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); 201 Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber()));
202 mailfolder_free(folder); 202 mailfolder_free(folder);
203 mailstorage_free(storage); 203 mailstorage_free(storage);
204 mailmessage_free(msg); 204 mailmessage_free(msg);
205 return 0; 205 return 0;
206 } 206 }
207 encodedString*result = new encodedString(data,size); 207 encodedString*result = new encodedString(data,size);
208 208
209 mailfolder_free(folder); 209 mailfolder_free(folder);
210 mailstorage_free(storage); 210 mailstorage_free(storage);
211 mailmessage_free(msg); 211 mailmessage_free(msg);
212 return result; 212 return result;
213} 213}
214 214
215void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) 215void MBOXwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target)
216{ 216{
217 QString p = MBOXPath+"/"; 217 QString p = MBOXPath+"/";
218 p+=mailbox; 218 p+=mailbox;
219 mailmbox_folder*f = 0; 219 mailmbox_folder*f = 0;
220 int r = mailmbox_init(p.latin1(),0,1,0,&f); 220 int r = mailmbox_init(p.latin1(),0,1,0,&f);
221 if (r != MAIL_NO_ERROR) { 221 if (r != MAIL_NO_ERROR) {
222 qDebug("Error init folder"); 222 qDebug("Error init folder");
223 return; 223 return;
224 } 224 }
225 deleteMails(f,target); 225 deleteMails(f,target);
226 mailmbox_done(f); 226 mailmbox_done(f);
227} 227}
228 228
229void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target) 229void MBOXwrapper::deleteMails(mailmbox_folder*f,const QValueList<RecMailP> &target)
230{ 230{
231 if (!f) return; 231 if (!f) return;
232 int r; 232 int r;
233 for (unsigned int i=0; i < target.count();++i) { 233 QValueList<RecMailP>::ConstIterator it;
234 r = mailmbox_delete_msg(f,target.at(i)->getNumber()); 234 for (it=target.begin(); it != target.end();++it) {
235 r = mailmbox_delete_msg(f,(*it)->getNumber());
235 if (r!=MAILMBOX_NO_ERROR) { 236 if (r!=MAILMBOX_NO_ERROR) {
236 qDebug("error delete mail"); 237 qDebug("error delete mail");
237 } 238 }
238 } 239 }
239 r = mailmbox_expunge(f); 240 r = mailmbox_expunge(f);
240 if (r != MAILMBOX_NO_ERROR) { 241 if (r != MAILMBOX_NO_ERROR) {
241 qDebug("error expunge mailbox"); 242 qDebug("error expunge mailbox");
242 } 243 }
243} 244}
244 245
245int MBOXwrapper::deleteAllMail(const FolderP&tfolder) 246int MBOXwrapper::deleteAllMail(const FolderP&tfolder)
246{ 247{
247 if (!tfolder) return 0; 248 if (!tfolder) return 0;
248 QString p = MBOXPath+"/"+tfolder->getDisplayName(); 249 QString p = MBOXPath+"/"+tfolder->getDisplayName();
249 int res = 1; 250 int res = 1;
250 251
251 mailfolder*folder = 0; 252 mailfolder*folder = 0;
252 mailmessage_list*l=0; 253 mailmessage_list*l=0;
253 mailstorage*storage = mailstorage_new(NULL); 254 mailstorage*storage = mailstorage_new(NULL);
254 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 255 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
255 if (r != MAIL_NO_ERROR) { 256 if (r != MAIL_NO_ERROR) {
256 Global::statusMessage(tr("Error initializing mbox")); 257 Global::statusMessage(tr("Error initializing mbox"));
257 res = 0; 258 res = 0;
258 } 259 }
259 if (res) { 260 if (res) {
260 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 261 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
261 r = mailfolder_connect(folder); 262 r = mailfolder_connect(folder);
262 if (r != MAIL_NO_ERROR) { 263 if (r != MAIL_NO_ERROR) {
263 Global::statusMessage(tr("Error initializing mbox")); 264 Global::statusMessage(tr("Error initializing mbox"));
264 res = 0; 265 res = 0;
265 } 266 }
266 } 267 }
267 if (res) { 268 if (res) {
268 r = mailsession_get_messages_list(folder->fld_session,&l); 269 r = mailsession_get_messages_list(folder->fld_session,&l);
269 if (r != MAIL_NO_ERROR) { 270 if (r != MAIL_NO_ERROR) {
270 qDebug("Error message list"); 271 qDebug("Error message list");
271 res=0; 272 res=0;
272 } 273 }
273 } 274 }
274 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { 275 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
275 r = mailsession_remove_message(folder->fld_session,i+1); 276 r = mailsession_remove_message(folder->fld_session,i+1);
276 if (r != MAIL_NO_ERROR) { 277 if (r != MAIL_NO_ERROR) {
277 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 278 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
278 res = 0; 279 res = 0;
279 break; 280 break;
280 } 281 }
281 } 282 }
282 if (l) mailmessage_list_free(l); 283 if (l) mailmessage_list_free(l);
283 if (folder) mailfolder_free(folder); 284 if (folder) mailfolder_free(folder);
284 if (storage) mailstorage_free(storage); 285 if (storage) mailstorage_free(storage);
285 return res; 286 return res;
286} 287}
287 288
288int MBOXwrapper::deleteMbox(const FolderP&tfolder) 289int MBOXwrapper::deleteMbox(const FolderP&tfolder)
289{ 290{
290 if (!tfolder) return 0; 291 if (!tfolder) return 0;
291 QString p = MBOXPath+"/"+tfolder->getDisplayName(); 292 QString p = MBOXPath+"/"+tfolder->getDisplayName();
292 QFile fi(p); 293 QFile fi(p);
293 if (!fi.exists()) { 294 if (!fi.exists()) {
294 Global::statusMessage(tr("Mailbox doesn't exist.")); 295 Global::statusMessage(tr("Mailbox doesn't exist."));
295 return 0; 296 return 0;
296 } 297 }
297 if (!fi.remove()) { 298 if (!fi.remove()) {
298 Global::statusMessage(tr("Error deleting Mailbox.")); 299 Global::statusMessage(tr("Error deleting Mailbox."));
299 return 0; 300 return 0;
300 } 301 }
301 return 1; 302 return 1;
302} 303}
303 304
304void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 305void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
305{ 306{
306 mailfolder*folder = 0; 307 mailfolder*folder = 0;
307 mailstorage*storage = mailstorage_new(NULL); 308 mailstorage*storage = mailstorage_new(NULL);
308 target_stat.message_count = 0; 309 target_stat.message_count = 0;
309 target_stat.message_unseen = 0; 310 target_stat.message_unseen = 0;
310 target_stat.message_recent = 0; 311 target_stat.message_recent = 0;
311 QString p = MBOXPath+"/"+mailbox; 312 QString p = MBOXPath+"/"+mailbox;
312 QFile fi(p); 313 QFile fi(p);
313 if (!fi.exists()) { 314 if (!fi.exists()) {
314 Global::statusMessage(tr("Mailbox doesn't exist.")); 315 Global::statusMessage(tr("Mailbox doesn't exist."));
315 return; 316 return;
316 } 317 }
317 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 318 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
318 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 319 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
319 r = mailfolder_connect(folder); 320 r = mailfolder_connect(folder);
320 r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, 321 r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count,
321 &target_stat.message_recent,&target_stat.message_unseen); 322 &target_stat.message_recent,&target_stat.message_unseen);
322 if (folder) mailfolder_free(folder); 323 if (folder) mailfolder_free(folder);
323 if (storage) mailstorage_free(storage); 324 if (storage) mailstorage_free(storage);
324} 325}
325 326
326MAILLIB::ATYPE MBOXwrapper::getType()const 327MAILLIB::ATYPE MBOXwrapper::getType()const
327{ 328{
328 return MAILLIB::A_MBOX; 329 return MAILLIB::A_MBOX;
329} 330}
330 331
331const QString&MBOXwrapper::getName()const 332const QString&MBOXwrapper::getName()const
332{ 333{
333 return MBOXName; 334 return MBOXName;
334} 335}
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.h b/noncore/net/mail/libmailwrapper/mboxwrapper.h
index c3d9b50..33eeb1e 100644
--- a/noncore/net/mail/libmailwrapper/mboxwrapper.h
+++ b/noncore/net/mail/libmailwrapper/mboxwrapper.h
@@ -1,48 +1,46 @@
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;
8class RecBody;
9class encodedString; 7class encodedString;
10struct mailmbox_folder; 8struct mailmbox_folder;
11 9
12class MBOXwrapper : public Genericwrapper 10class MBOXwrapper : public Genericwrapper
13{ 11{
14 Q_OBJECT 12 Q_OBJECT
15 13
16public: 14public:
17 MBOXwrapper(const QString & dir,const QString&name); 15 MBOXwrapper(const QString & dir,const QString&name);
18 virtual ~MBOXwrapper(); 16 virtual ~MBOXwrapper();
19 17
20 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 18 virtual void listMessages(const QString & mailbox, QValueList<RecMailP>&target );
21 virtual QValueList<Opie::osmart_pointer<Folder> >* listFolders(); 19 virtual QValueList<Opie::OSmartPointer<Folder> >* listFolders();
22 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 20 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
23 21
24 virtual void deleteMail(const RecMail&mail); 22 virtual void deleteMail(const RecMailP&mail);
25 virtual void answeredMail(const RecMail&mail); 23 virtual void answeredMail(const RecMailP&mail);
26 24
27 virtual int createMbox(const QString&folder,const Opie::osmart_pointer<Folder>&f=0, 25 virtual int createMbox(const QString&folder,const Opie::OSmartPointer<Folder>&f=0,
28 const QString&d="",bool s=false); 26 const QString&d="",bool s=false);
29 virtual int deleteMbox(const Opie::osmart_pointer<Folder>&); 27 virtual int deleteMbox(const Opie::OSmartPointer<Folder>&);
30 28
31 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 29 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
32 30
33 virtual RecBody fetchBody( const RecMail &mail ); 31 virtual RecBody fetchBody( const RecMailP &mail );
34 static void mbox_progress( size_t current, size_t maximum ); 32 static void mbox_progress( size_t current, size_t maximum );
35 33
36 virtual encodedString* fetchRawBody(const RecMail&mail); 34 virtual encodedString* fetchRawBody(const RecMailP&mail);
37 virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); 35 virtual void deleteMails(const QString & FolderName,const QValueList<RecMailP> &target);
38 virtual int deleteAllMail(const Opie::osmart_pointer<Folder>&); 36 virtual int deleteAllMail(const Opie::OSmartPointer<Folder>&);
39 virtual MAILLIB::ATYPE getType()const; 37 virtual MAILLIB::ATYPE getType()const;
40 virtual const QString&getName()const; 38 virtual const QString&getName()const;
41 39
42protected: 40protected:
43 static void deleteMails(mailmbox_folder*f,QList<RecMail> &target); 41 static void deleteMails(mailmbox_folder*f,const QValueList<RecMailP> &target);
44 QString MBOXPath; 42 QString MBOXPath;
45 QString MBOXName; 43 QString MBOXName;
46}; 44};
47 45
48#endif 46#endif
diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.cpp b/noncore/net/mail/libmailwrapper/mhwrapper.cpp
index aaaa20a..0b00a2e 100644
--- a/noncore/net/mail/libmailwrapper/mhwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mhwrapper.cpp
@@ -1,443 +1,441 @@
1#include "mhwrapper.h" 1#include "mhwrapper.h"
2#include "mailtypes.h" 2#include "mailtypes.h"
3#include "mailwrapper.h" 3#include "mailwrapper.h"
4#include <libetpan/libetpan.h> 4#include <libetpan/libetpan.h>
5#include <qdir.h> 5#include <qdir.h>
6#include <qmessagebox.h> 6#include <qmessagebox.h>
7#include <stdlib.h> 7#include <stdlib.h>
8#include <qpe/global.h> 8#include <qpe/global.h>
9#include <opie2/oprocess.h> 9#include <opie2/oprocess.h>
10 10
11MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) 11MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name)
12 : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) 12 : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name)
13{ 13{
14 if (MHPath.length()>0) { 14 if (MHPath.length()>0) {
15 if (MHPath[MHPath.length()-1]=='/') { 15 if (MHPath[MHPath.length()-1]=='/') {
16 MHPath=MHPath.left(MHPath.length()-1); 16 MHPath=MHPath.left(MHPath.length()-1);
17 } 17 }
18 qDebug(MHPath); 18 qDebug(MHPath);
19 QDir dir(MHPath); 19 QDir dir(MHPath);
20 if (!dir.exists()) { 20 if (!dir.exists()) {
21 dir.mkdir(MHPath); 21 dir.mkdir(MHPath);
22 } 22 }
23 init_storage(); 23 init_storage();
24 } 24 }
25} 25}
26 26
27void MHwrapper::init_storage() 27void MHwrapper::init_storage()
28{ 28{
29 int r; 29 int r;
30 QString pre = MHPath; 30 QString pre = MHPath;
31 if (!m_storage) { 31 if (!m_storage) {
32 m_storage = mailstorage_new(NULL); 32 m_storage = mailstorage_new(NULL);
33 r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); 33 r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0);
34 if (r != MAIL_NO_ERROR) { 34 if (r != MAIL_NO_ERROR) {
35 qDebug("error initializing storage"); 35 qDebug("error initializing storage");
36 mailstorage_free(m_storage); 36 mailstorage_free(m_storage);
37 m_storage = 0; 37 m_storage = 0;
38 return; 38 return;
39 } 39 }
40 } 40 }
41 r = mailstorage_connect(m_storage); 41 r = mailstorage_connect(m_storage);
42 if (r!=MAIL_NO_ERROR) { 42 if (r!=MAIL_NO_ERROR) {
43 qDebug("error connecting storage"); 43 qDebug("error connecting storage");
44 mailstorage_free(m_storage); 44 mailstorage_free(m_storage);
45 m_storage = 0; 45 m_storage = 0;
46 } 46 }
47} 47}
48 48
49void MHwrapper::clean_storage() 49void MHwrapper::clean_storage()
50{ 50{
51 if (m_storage) { 51 if (m_storage) {
52 mailstorage_disconnect(m_storage); 52 mailstorage_disconnect(m_storage);
53 mailstorage_free(m_storage); 53 mailstorage_free(m_storage);
54 m_storage = 0; 54 m_storage = 0;
55 } 55 }
56} 56}
57 57
58MHwrapper::~MHwrapper() 58MHwrapper::~MHwrapper()
59{ 59{
60 clean_storage(); 60 clean_storage();
61} 61}
62 62
63void MHwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) 63void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::OSmartPointer<RecMail> > &target )
64{ 64{
65 init_storage(); 65 init_storage();
66 if (!m_storage) { 66 if (!m_storage) {
67 return; 67 return;
68 } 68 }
69 QString f = buildPath(mailbox); 69 QString f = buildPath(mailbox);
70 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); 70 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
71 if (r!=MAIL_NO_ERROR) { 71 if (r!=MAIL_NO_ERROR) {
72 qDebug("listMessages: error selecting folder!"); 72 qDebug("listMessages: error selecting folder!");
73 return; 73 return;
74 } 74 }
75 parseList(target,m_storage->sto_session,f); 75 parseList(target,m_storage->sto_session,f);
76 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); 76 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count()));
77} 77}
78 78
79QValueList<Opie::osmart_pointer<Folder> >* MHwrapper::listFolders() 79QValueList<Opie::OSmartPointer<Folder> >* MHwrapper::listFolders()
80{ 80{
81 QValueList<Opie::osmart_pointer<Folder> >* folders = new QValueList<Opie::osmart_pointer<Folder> >(); 81 QValueList<Opie::OSmartPointer<Folder> >* folders = new QValueList<Opie::OSmartPointer<Folder> >();
82 /* this is needed! */ 82 /* this is needed! */
83 if (m_storage) mailstorage_disconnect(m_storage); 83 if (m_storage) mailstorage_disconnect(m_storage);
84 init_storage(); 84 init_storage();
85 if (!m_storage) { 85 if (!m_storage) {
86 return folders; 86 return folders;
87 } 87 }
88 mail_list*flist = 0; 88 mail_list*flist = 0;
89 clistcell*current=0; 89 clistcell*current=0;
90 int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); 90 int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist);
91 if (r != MAIL_NO_ERROR || !flist) { 91 if (r != MAIL_NO_ERROR || !flist) {
92 qDebug("error getting folder list"); 92 qDebug("error getting folder list");
93 return folders; 93 return folders;
94 } 94 }
95 for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { 95 for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) {
96 QString t = (char*)current->data; 96 QString t = (char*)current->data;
97 t.replace(0,MHPath.length(),""); 97 t.replace(0,MHPath.length(),"");
98 folders->append(new MHFolder(t,MHPath)); 98 folders->append(new MHFolder(t,MHPath));
99 } 99 }
100 mail_list_free(flist); 100 mail_list_free(flist);
101 return folders; 101 return folders;
102} 102}
103 103
104void MHwrapper::deleteMail(const RecMail&mail) 104void MHwrapper::deleteMail(const RecMailP&mail)
105{ 105{
106 init_storage(); 106 init_storage();
107 if (!m_storage) { 107 if (!m_storage) {
108 return; 108 return;
109 } 109 }
110 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); 110 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
111 if (r!=MAIL_NO_ERROR) { 111 if (r!=MAIL_NO_ERROR) {
112 qDebug("error selecting folder!"); 112 qDebug("error selecting folder!");
113 return; 113 return;
114 } 114 }
115 r = mailsession_remove_message(m_storage->sto_session,mail.getNumber()); 115 r = mailsession_remove_message(m_storage->sto_session,mail->getNumber());
116 if (r != MAIL_NO_ERROR) { 116 if (r != MAIL_NO_ERROR) {
117 qDebug("error deleting mail"); 117 qDebug("error deleting mail");
118 } 118 }
119} 119}
120 120
121void MHwrapper::answeredMail(const RecMail&) 121void MHwrapper::answeredMail(const RecMailP&)
122{ 122{
123} 123}
124 124
125RecBody MHwrapper::fetchBody( const RecMail &mail ) 125RecBody MHwrapper::fetchBody( const RecMailP &mail )
126{ 126{
127 RecBody body; 127 RecBody body;
128 init_storage(); 128 init_storage();
129 if (!m_storage) { 129 if (!m_storage) {
130 return body; 130 return body;
131 } 131 }
132 mailmessage * msg; 132 mailmessage * msg;
133 char*data=0; 133 char*data=0;
134 size_t size;
135 134
136 /* mail should hold the complete path! */ 135 /* mail should hold the complete path! */
137 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); 136 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
138 if (r != MAIL_NO_ERROR) { 137 if (r != MAIL_NO_ERROR) {
139 return body; 138 return body;
140 } 139 }
141 r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg); 140 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg);
142 if (r != MAIL_NO_ERROR) { 141 if (r != MAIL_NO_ERROR) {
143 qDebug("Error fetching mail %i",mail.getNumber()); 142 qDebug("Error fetching mail %i",mail->getNumber());
144 return body; 143 return body;
145 } 144 }
146 body = parseMail(msg); 145 body = parseMail(msg);
147 mailmessage_fetch_result_free(msg,data); 146 mailmessage_fetch_result_free(msg,data);
148 return body; 147 return body;
149} 148}
150 149
151void MHwrapper::mbox_progress( size_t current, size_t maximum ) 150void MHwrapper::mbox_progress( size_t current, size_t maximum )
152{ 151{
153 qDebug("MH %i von %i",current,maximum); 152 qDebug("MH %i von %i",current,maximum);
154} 153}
155 154
156QString MHwrapper::buildPath(const QString&p) 155QString MHwrapper::buildPath(const QString&p)
157{ 156{
158 QString f=""; 157 QString f="";
159 if (p.length()==0||p=="/") 158 if (p.length()==0||p=="/")
160 return MHPath; 159 return MHPath;
161 if (!p.startsWith(MHPath)) { 160 if (!p.startsWith(MHPath)) {
162 f+=MHPath; 161 f+=MHPath;
163 } 162 }
164 if (!p.startsWith("/")) { 163 if (!p.startsWith("/")) {
165 f+="/"; 164 f+="/";
166 } 165 }
167 f+=p; 166 f+=p;
168 return f; 167 return f;
169} 168}
170 169
171int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool ) 170int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool )
172{ 171{
173 init_storage(); 172 init_storage();
174 if (!m_storage) { 173 if (!m_storage) {
175 return 0; 174 return 0;
176 } 175 }
177 QString f; 176 QString f;
178 if (!pfolder) { 177 if (!pfolder) {
179 // toplevel folder 178 // toplevel folder
180 f = buildPath(folder); 179 f = buildPath(folder);
181 } else { 180 } else {
182 f = pfolder->getName(); 181 f = pfolder->getName();
183 f+="/"; 182 f+="/";
184 f+=folder; 183 f+=folder;
185 } 184 }
186 qDebug(f); 185 qDebug(f);
187 int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); 186 int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1());
188 if (r != MAIL_NO_ERROR) { 187 if (r != MAIL_NO_ERROR) {
189 qDebug("error creating folder %i",r); 188 qDebug("error creating folder %i",r);
190 return 0; 189 return 0;
191 } 190 }
192 qDebug("Folder created"); 191 qDebug("Folder created");
193 return 1; 192 return 1;
194} 193}
195 194
196void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) 195void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder)
197{ 196{
198 init_storage(); 197 init_storage();
199 if (!m_storage) { 198 if (!m_storage) {
200 return; 199 return;
201 } 200 }
202 QString f = buildPath(Folder); 201 QString f = buildPath(Folder);
203 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); 202 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
204 if (r!=MAIL_NO_ERROR) { 203 if (r!=MAIL_NO_ERROR) {
205 qDebug("error selecting folder!"); 204 qDebug("error selecting folder!");
206 return; 205 return;
207 } 206 }
208 r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); 207 r = mailsession_append_message(m_storage->sto_session,(char*)msg,length);
209 if (r!=MAIL_NO_ERROR) { 208 if (r!=MAIL_NO_ERROR) {
210 qDebug("error storing mail"); 209 qDebug("error storing mail");
211 } 210 }
212 return; 211 return;
213} 212}
214 213
215encodedString* MHwrapper::fetchRawBody(const RecMail&mail) 214encodedString* MHwrapper::fetchRawBody(const RecMailP&mail)
216{ 215{
217 encodedString*result = 0; 216 encodedString*result = 0;
218 init_storage(); 217 init_storage();
219 if (!m_storage) { 218 if (!m_storage) {
220 return result; 219 return result;
221 } 220 }
222 mailmessage * msg = 0; 221 mailmessage * msg = 0;
223 char*data=0; 222 char*data=0;
224 size_t size; 223 size_t size;
225 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); 224 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
226 if (r!=MAIL_NO_ERROR) { 225 if (r!=MAIL_NO_ERROR) {
227 qDebug("error selecting folder!"); 226 qDebug("error selecting folder!");
228 return result; 227 return result;
229 } 228 }
230 r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg); 229 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg);
231 if (r != MAIL_NO_ERROR) { 230 if (r != MAIL_NO_ERROR) {
232 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); 231 Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber()));
233 return 0; 232 return 0;
234 } 233 }
235 r = mailmessage_fetch(msg,&data,&size); 234 r = mailmessage_fetch(msg,&data,&size);
236 if (r != MAIL_NO_ERROR) { 235 if (r != MAIL_NO_ERROR) {
237 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); 236 Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber()));
238 if (msg) mailmessage_free(msg); 237 if (msg) mailmessage_free(msg);
239 return 0; 238 return 0;
240 } 239 }
241 result = new encodedString(data,size); 240 result = new encodedString(data,size);
242 if (msg) mailmessage_free(msg); 241 if (msg) mailmessage_free(msg);
243 return result; 242 return result;
244} 243}
245 244
246void MHwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) 245void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target)
247{ 246{
248 QString f = buildPath(mailbox); 247 QString f = buildPath(mailbox);
249 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); 248 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
250 if (r!=MAIL_NO_ERROR) { 249 if (r!=MAIL_NO_ERROR) {
251 qDebug("deleteMails: error selecting folder!"); 250 qDebug("deleteMails: error selecting folder!");
252 return; 251 return;
253 } 252 }
254 RecMail*c = 0; 253 QValueList<RecMailP>::ConstIterator it;
255 for (unsigned int i=0; i < target.count();++i) { 254 for (it=target.begin(); it!=target.end();++it) {
256 c = target.at(i); 255 r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber());
257 r = mailsession_remove_message(m_storage->sto_session,c->getNumber());
258 if (r != MAIL_NO_ERROR) { 256 if (r != MAIL_NO_ERROR) {
259 qDebug("error deleting mail"); 257 qDebug("error deleting mail");
260 break; 258 break;
261 } 259 }
262 } 260 }
263} 261}
264 262
265int MHwrapper::deleteAllMail(const FolderP&tfolder) 263int MHwrapper::deleteAllMail(const FolderP&tfolder)
266{ 264{
267 init_storage(); 265 init_storage();
268 if (!m_storage) { 266 if (!m_storage) {
269 return 0; 267 return 0;
270 } 268 }
271 int res = 1; 269 int res = 1;
272 if (!tfolder) return 0; 270 if (!tfolder) return 0;
273 int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); 271 int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1());
274 if (r!=MAIL_NO_ERROR) { 272 if (r!=MAIL_NO_ERROR) {
275 qDebug("error selecting folder!"); 273 qDebug("error selecting folder!");
276 return 0; 274 return 0;
277 } 275 }
278 mailmessage_list*l=0; 276 mailmessage_list*l=0;
279 r = mailsession_get_messages_list(m_storage->sto_session,&l); 277 r = mailsession_get_messages_list(m_storage->sto_session,&l);
280 if (r != MAIL_NO_ERROR) { 278 if (r != MAIL_NO_ERROR) {
281 qDebug("Error message list"); 279 qDebug("Error message list");
282 res = 0; 280 res = 0;
283 } 281 }
284 unsigned j = 0; 282 unsigned j = 0;
285 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { 283 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
286 mailmessage * msg; 284 mailmessage * msg;
287 msg = (mailmessage*)carray_get(l->msg_tab, i); 285 msg = (mailmessage*)carray_get(l->msg_tab, i);
288 j = msg->msg_index; 286 j = msg->msg_index;
289 r = mailsession_remove_message(m_storage->sto_session,j); 287 r = mailsession_remove_message(m_storage->sto_session,j);
290 if (r != MAIL_NO_ERROR) { 288 if (r != MAIL_NO_ERROR) {
291 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 289 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
292 res = 0; 290 res = 0;
293 break; 291 break;
294 } 292 }
295 } 293 }
296 if (l) mailmessage_list_free(l); 294 if (l) mailmessage_list_free(l);
297 return res; 295 return res;
298} 296}
299 297
300int MHwrapper::deleteMbox(const FolderP&tfolder) 298int MHwrapper::deleteMbox(const FolderP&tfolder)
301{ 299{
302 init_storage(); 300 init_storage();
303 if (!m_storage) { 301 if (!m_storage) {
304 return 0; 302 return 0;
305 } 303 }
306 if (!tfolder) return 0; 304 if (!tfolder) return 0;
307 if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; 305 if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0;
308 306
309 int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); 307 int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1());
310 308
311 if (r != MAIL_NO_ERROR) { 309 if (r != MAIL_NO_ERROR) {
312 qDebug("error deleting mail box"); 310 qDebug("error deleting mail box");
313 return 0; 311 return 0;
314 } 312 }
315 QString cmd = "rm -rf "+tfolder->getName(); 313 QString cmd = "rm -rf "+tfolder->getName();
316 QStringList command; 314 QStringList command;
317 command << "/bin/sh"; 315 command << "/bin/sh";
318 command << "-c"; 316 command << "-c";
319 command << cmd.latin1(); 317 command << cmd.latin1();
320 OProcess *process = new OProcess(); 318 OProcess *process = new OProcess();
321 319
322 connect(process, SIGNAL(processExited(OProcess*)), 320 connect(process, SIGNAL(processExited(OProcess*)),
323 this, SLOT( processEnded(OProcess*))); 321 this, SLOT( processEnded(OProcess*)));
324 connect(process, SIGNAL( receivedStderr(OProcess*,char*,int)), 322 connect(process, SIGNAL( receivedStderr(OProcess*,char*,int)),
325 this, SLOT( oprocessStderr(OProcess*,char*,int))); 323 this, SLOT( oprocessStderr(OProcess*,char*,int)));
326 324
327 *process << command; 325 *process << command;
328 removeMboxfailed = false; 326 removeMboxfailed = false;
329 if(!process->start(OProcess::Block, OProcess::All) ) { 327 if(!process->start(OProcess::Block, OProcess::All) ) {
330 qDebug("could not start process"); 328 qDebug("could not start process");
331 return 0; 329 return 0;
332 } 330 }
333 qDebug("mail box deleted"); 331 qDebug("mail box deleted");
334 return 1; 332 return 1;
335} 333}
336 334
337void MHwrapper::processEnded(OProcess *p) 335void MHwrapper::processEnded(OProcess *p)
338{ 336{
339 if (p) delete p; 337 if (p) delete p;
340} 338}
341 339
342void MHwrapper::oprocessStderr(OProcess*, char *buffer, int ) 340void MHwrapper::oprocessStderr(OProcess*, char *buffer, int )
343{ 341{
344 QString lineStr = buffer; 342 QString lineStr = buffer;
345 QMessageBox::warning( 0, tr("Error"), lineStr ,tr("Ok") ); 343 QMessageBox::warning( 0, tr("Error"), lineStr ,tr("Ok") );
346 removeMboxfailed = true; 344 removeMboxfailed = true;
347} 345}
348 346
349void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 347void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
350{ 348{
351 init_storage(); 349 init_storage();
352 if (!m_storage) { 350 if (!m_storage) {
353 return; 351 return;
354 } 352 }
355 target_stat.message_count = 0; 353 target_stat.message_count = 0;
356 target_stat.message_unseen = 0; 354 target_stat.message_unseen = 0;
357 target_stat.message_recent = 0; 355 target_stat.message_recent = 0;
358 QString f = buildPath(mailbox); 356 QString f = buildPath(mailbox);
359 int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, 357 int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count,
360 &target_stat.message_recent,&target_stat.message_unseen); 358 &target_stat.message_recent,&target_stat.message_unseen);
361 if (r != MAIL_NO_ERROR) { 359 if (r != MAIL_NO_ERROR) {
362 Global::statusMessage(tr("Error retrieving status")); 360 Global::statusMessage(tr("Error retrieving status"));
363 } 361 }
364} 362}
365 363
366MAILLIB::ATYPE MHwrapper::getType()const 364MAILLIB::ATYPE MHwrapper::getType()const
367{ 365{
368 return MAILLIB::A_MH; 366 return MAILLIB::A_MH;
369} 367}
370 368
371const QString&MHwrapper::getName()const 369const QString&MHwrapper::getName()const
372{ 370{
373 return MHName; 371 return MHName;
374} 372}
375void MHwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 373void MHwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
376{ 374{
377 init_storage(); 375 init_storage();
378 if (!m_storage) { 376 if (!m_storage) {
379 return; 377 return;
380 } 378 }
381 if (targetWrapper != this) { 379 if (targetWrapper != this) {
382 qDebug("Using generic"); 380 qDebug("Using generic");
383 Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); 381 Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit);
384 return; 382 return;
385 } 383 }
386 qDebug("Using internal routines for move/copy"); 384 qDebug("Using internal routines for move/copy");
387 QString tf = buildPath(targetFolder); 385 QString tf = buildPath(targetFolder);
388 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); 386 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
389 if (r != MAIL_NO_ERROR) { 387 if (r != MAIL_NO_ERROR) {
390 qDebug("Error selecting source mailbox"); 388 qDebug("Error selecting source mailbox");
391 return; 389 return;
392 } 390 }
393 if (moveit) { 391 if (moveit) {
394 r = mailsession_move_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1()); 392 r = mailsession_move_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1());
395 } else { 393 } else {
396 r = mailsession_copy_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1()); 394 r = mailsession_copy_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1());
397 } 395 }
398 if (r != MAIL_NO_ERROR) { 396 if (r != MAIL_NO_ERROR) {
399 qDebug("Error copy/moving mail internal (%i)",r); 397 qDebug("Error copy/moving mail internal (%i)",r);
400 } 398 }
401} 399}
402 400
403void MHwrapper::mvcpAllMails(const FolderP&fromFolder, 401void MHwrapper::mvcpAllMails(const FolderP&fromFolder,
404 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 402 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
405{ 403{
406 init_storage(); 404 init_storage();
407 if (!m_storage) { 405 if (!m_storage) {
408 return; 406 return;
409 } 407 }
410 if (targetWrapper != this) { 408 if (targetWrapper != this) {
411 qDebug("Using generic"); 409 qDebug("Using generic");
412 Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); 410 Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit);
413 return; 411 return;
414 } 412 }
415 if (!fromFolder) return; 413 if (!fromFolder) return;
416 int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1()); 414 int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1());
417 if (r!=MAIL_NO_ERROR) { 415 if (r!=MAIL_NO_ERROR) {
418 qDebug("error selecting source folder!"); 416 qDebug("error selecting source folder!");
419 return; 417 return;
420 } 418 }
421 QString tf = buildPath(targetFolder); 419 QString tf = buildPath(targetFolder);
422 mailmessage_list*l=0; 420 mailmessage_list*l=0;
423 r = mailsession_get_messages_list(m_storage->sto_session,&l); 421 r = mailsession_get_messages_list(m_storage->sto_session,&l);
424 if (r != MAIL_NO_ERROR) { 422 if (r != MAIL_NO_ERROR) {
425 qDebug("Error message list"); 423 qDebug("Error message list");
426 } 424 }
427 unsigned j = 0; 425 unsigned j = 0;
428 for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) { 426 for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) {
429 mailmessage * msg; 427 mailmessage * msg;
430 msg = (mailmessage*)carray_get(l->msg_tab, i); 428 msg = (mailmessage*)carray_get(l->msg_tab, i);
431 j = msg->msg_index; 429 j = msg->msg_index;
432 if (moveit) { 430 if (moveit) {
433 r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1()); 431 r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1());
434 } else { 432 } else {
435 r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1()); 433 r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1());
436 } 434 }
437 if (r != MAIL_NO_ERROR) { 435 if (r != MAIL_NO_ERROR) {
438 qDebug("Error copy/moving mail internal (%i)",r); 436 qDebug("Error copy/moving mail internal (%i)",r);
439 break; 437 break;
440 } 438 }
441 } 439 }
442 if (l) mailmessage_list_free(l); 440 if (l) mailmessage_list_free(l);
443} 441}
diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.h b/noncore/net/mail/libmailwrapper/mhwrapper.h
index c7c8183..208cf2f 100644
--- a/noncore/net/mail/libmailwrapper/mhwrapper.h
+++ b/noncore/net/mail/libmailwrapper/mhwrapper.h
@@ -1,62 +1,60 @@
1#ifndef __MH_WRAPPER_H 1#ifndef __MH_WRAPPER_H
2#define __MH_WRAPPER_H 2#define __MH_WRAPPER_H
3 3
4#include "maildefines.h" 4#include "maildefines.h"
5 5
6#include "genericwrapper.h" 6#include "genericwrapper.h"
7#include <qstring.h> 7#include <qstring.h>
8 8
9class RecMail;
10class RecBody;
11class encodedString; 9class encodedString;
12struct mailmbox_folder; 10struct mailmbox_folder;
13class OProcess; 11class OProcess;
14 12
15class MHwrapper : public Genericwrapper 13class MHwrapper : public Genericwrapper
16{ 14{
17 Q_OBJECT 15 Q_OBJECT
18public: 16public:
19 MHwrapper(const QString & dir,const QString&name); 17 MHwrapper(const QString & dir,const QString&name);
20 virtual ~MHwrapper(); 18 virtual ~MHwrapper();
21 19
22 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 20 virtual void listMessages(const QString & mailbox, QValueList<Opie::OSmartPointer<RecMail> > &target );
23 virtual QValueList<Opie::osmart_pointer<Folder> >* listFolders(); 21 virtual QValueList<Opie::OSmartPointer<Folder> >* listFolders();
24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 22 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
25 23
26 virtual void deleteMail(const RecMail&mail); 24 virtual void deleteMail(const RecMailP&mail);
27 virtual void answeredMail(const RecMail&mail); 25 virtual void answeredMail(const RecMailP&mail);
28 virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 26 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
29 virtual void mvcpAllMails(const Opie::osmart_pointer<Folder>&fromFolder, 27 virtual void mvcpAllMails(const Opie::OSmartPointer<Folder>&fromFolder,
30 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 28 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
31 29
32 virtual int createMbox(const QString&folder,const Opie::osmart_pointer<Folder>&f=0, 30 virtual int createMbox(const QString&folder,const Opie::OSmartPointer<Folder>&f=0,
33 const QString&d="",bool s=false); 31 const QString&d="",bool s=false);
34 virtual int deleteMbox(const Opie::osmart_pointer<Folder>&); 32 virtual int deleteMbox(const Opie::OSmartPointer<Folder>&);
35 33
36 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 34 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
37 35
38 virtual RecBody fetchBody( const RecMail &mail ); 36 virtual RecBody fetchBody( const RecMailP &mail );
39 static void mbox_progress( size_t current, size_t maximum ); 37 static void mbox_progress( size_t current, size_t maximum );
40 38
41 virtual encodedString* fetchRawBody(const RecMail&mail); 39 virtual encodedString* fetchRawBody(const RecMailP&mail);
42 virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); 40 virtual void deleteMails(const QString & FolderName,const QValueList<Opie::OSmartPointer<RecMail> > &target);
43 virtual int deleteAllMail(const Opie::osmart_pointer<Folder>&); 41 virtual int deleteAllMail(const Opie::OSmartPointer<Folder>&);
44 virtual MAILLIB::ATYPE getType()const; 42 virtual MAILLIB::ATYPE getType()const;
45 virtual const QString&getName()const; 43 virtual const QString&getName()const;
46 44
47public slots: 45public slots:
48 /* for deleting maildirs we are using a system call */ 46 /* for deleting maildirs we are using a system call */
49 virtual void oprocessStderr(OProcess*, char *buffer, int ); 47 virtual void oprocessStderr(OProcess*, char *buffer, int );
50 virtual void processEnded(OProcess *); 48 virtual void processEnded(OProcess *);
51protected: 49protected:
52 QString buildPath(const QString&p); 50 QString buildPath(const QString&p);
53 QString MHPath; 51 QString MHPath;
54 QString MHName; 52 QString MHName;
55 53
56 void init_storage(); 54 void init_storage();
57 void clean_storage(); 55 void clean_storage();
58 56
59 bool removeMboxfailed; 57 bool removeMboxfailed;
60}; 58};
61 59
62#endif 60#endif
diff --git a/noncore/net/mail/libmailwrapper/nntpwrapper.cpp b/noncore/net/mail/libmailwrapper/nntpwrapper.cpp
index 2ec052c..c0b3eec 100644
--- a/noncore/net/mail/libmailwrapper/nntpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/nntpwrapper.cpp
@@ -1,283 +1,283 @@
1#include "nntpwrapper.h" 1#include "nntpwrapper.h"
2#include "logindialog.h" 2#include "logindialog.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4 4
5#include <qfile.h> 5#include <qfile.h>
6 6
7#include <stdlib.h> 7#include <stdlib.h>
8 8
9#include <libetpan/libetpan.h> 9#include <libetpan/libetpan.h>
10 10
11 11
12#define HARD_MSG_SIZE_LIMIT 5242880 12#define HARD_MSG_SIZE_LIMIT 5242880
13 13
14NNTPwrapper::NNTPwrapper( NNTPaccount *a ) 14NNTPwrapper::NNTPwrapper( NNTPaccount *a )
15: Genericwrapper() { 15: Genericwrapper() {
16 account = a; 16 account = a;
17 m_nntp = NULL; 17 m_nntp = NULL;
18 msgTempName = a->getFileName()+"_msg_cache"; 18 msgTempName = a->getFileName()+"_msg_cache";
19 last_msg_id = 0; 19 last_msg_id = 0;
20} 20}
21 21
22NNTPwrapper::~NNTPwrapper() { 22NNTPwrapper::~NNTPwrapper() {
23 logout(); 23 logout();
24 QFile msg_cache(msgTempName); 24 QFile msg_cache(msgTempName);
25 if (msg_cache.exists()) { 25 if (msg_cache.exists()) {
26 msg_cache.remove(); 26 msg_cache.remove();
27 } 27 }
28} 28}
29 29
30void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) { 30void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) {
31 qDebug( "NNTP: %i of %i", current, maximum ); 31 qDebug( "NNTP: %i of %i", current, maximum );
32} 32}
33 33
34 34
35RecBody NNTPwrapper::fetchBody( const RecMail &mail ) { 35RecBody NNTPwrapper::fetchBody( const RecMailP &mail ) {
36 int err = NEWSNNTP_NO_ERROR; 36 int err = NEWSNNTP_NO_ERROR;
37 char *message = 0; 37 char *message = 0;
38 size_t length = 0; 38 size_t length = 0;
39 39
40 login(); 40 login();
41 if ( !m_nntp ) { 41 if ( !m_nntp ) {
42 return RecBody(); 42 return RecBody();
43 } 43 }
44 44
45 RecBody body; 45 RecBody body;
46 mailmessage * mailmsg; 46 mailmessage * mailmsg;
47 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { 47 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) {
48 qDebug("Message to large: %i",mail.Msgsize()); 48 qDebug("Message to large: %i",mail->Msgsize());
49 return body; 49 return body;
50 } 50 }
51 51
52 QFile msg_cache(msgTempName); 52 QFile msg_cache(msgTempName);
53 53
54 cleanMimeCache(); 54 cleanMimeCache();
55 55
56 if (mail.getNumber()!=last_msg_id) { 56 if (mail->getNumber()!=last_msg_id) {
57 if (msg_cache.exists()) { 57 if (msg_cache.exists()) {
58 msg_cache.remove(); 58 msg_cache.remove();
59 } 59 }
60 msg_cache.open(IO_ReadWrite|IO_Truncate); 60 msg_cache.open(IO_ReadWrite|IO_Truncate);
61 last_msg_id = mail.getNumber(); 61 last_msg_id = mail->getNumber();
62 err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg); 62 err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg);
63 err = mailmessage_fetch(mailmsg,&message,&length); 63 err = mailmessage_fetch(mailmsg,&message,&length);
64 msg_cache.writeBlock(message,length); 64 msg_cache.writeBlock(message,length);
65 } else { 65 } else {
66 QString msg=""; 66 QString msg="";
67 msg_cache.open(IO_ReadOnly); 67 msg_cache.open(IO_ReadOnly);
68 message = new char[4096]; 68 message = new char[4096];
69 memset(message,0,4096); 69 memset(message,0,4096);
70 while (msg_cache.readBlock(message,4095)>0) { 70 while (msg_cache.readBlock(message,4095)>0) {
71 msg+=message; 71 msg+=message;
72 memset(message,0,4096); 72 memset(message,0,4096);
73 } 73 }
74 delete message; 74 delete message;
75 message = (char*)malloc(msg.length()+1*sizeof(char)); 75 message = (char*)malloc(msg.length()+1*sizeof(char));
76 memset(message,0,msg.length()+1); 76 memset(message,0,msg.length()+1);
77 memcpy(message,msg.latin1(),msg.length()); 77 memcpy(message,msg.latin1(),msg.length());
78 /* transform to libetpan stuff */ 78 /* transform to libetpan stuff */
79 mailmsg = mailmessage_new(); 79 mailmsg = mailmessage_new();
80 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 80 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
81 generic_message_t * msg_data; 81 generic_message_t * msg_data;
82 msg_data = (generic_message_t *)mailmsg->msg_data; 82 msg_data = (generic_message_t *)mailmsg->msg_data;
83 msg_data->msg_fetched = 1; 83 msg_data->msg_fetched = 1;
84 msg_data->msg_message = message; 84 msg_data->msg_message = message;
85 msg_data->msg_length = strlen(message); 85 msg_data->msg_length = strlen(message);
86 } 86 }
87 body = parseMail(mailmsg); 87 body = parseMail(mailmsg);
88 88
89 /* clean up */ 89 /* clean up */
90 if (mailmsg) 90 if (mailmsg)
91 mailmessage_free(mailmsg); 91 mailmessage_free(mailmsg);
92 if (message) 92 if (message)
93 free(message); 93 free(message);
94 94
95 return body; 95 return body;
96} 96}
97 97
98 98
99void NNTPwrapper::listMessages(const QString & which, QList<RecMail> &target ) 99void NNTPwrapper::listMessages(const QString & which, QValueList<Opie::OSmartPointer<RecMail> > &target )
100{ 100{
101 login(); 101 login();
102 if (!m_nntp) 102 if (!m_nntp)
103 return; 103 return;
104 uint32_t res_messages,res_recent,res_unseen; 104 uint32_t res_messages,res_recent,res_unseen;
105 mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen); 105 mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen);
106 parseList(target,m_nntp->sto_session,which,true); 106 parseList(target,m_nntp->sto_session,which,true);
107} 107}
108 108
109void NNTPwrapper::login() 109void NNTPwrapper::login()
110{ 110{
111 if (account->getOffline()) 111 if (account->getOffline())
112 return; 112 return;
113 /* we'll hold the line */ 113 /* we'll hold the line */
114 if ( m_nntp != NULL ) 114 if ( m_nntp != NULL )
115 return; 115 return;
116 116
117 const char *server, *user, *pass; 117 const char *server, *user, *pass;
118 QString User,Pass; 118 QString User,Pass;
119 uint16_t port; 119 uint16_t port;
120 int err = NEWSNNTP_NO_ERROR; 120 int err = NEWSNNTP_NO_ERROR;
121 121
122 server = account->getServer().latin1(); 122 server = account->getServer().latin1();
123 port = account->getPort().toUInt(); 123 port = account->getPort().toUInt();
124 124
125 user = pass = 0; 125 user = pass = 0;
126 126
127 if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) { 127 if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) {
128 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 128 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
129 login.show(); 129 login.show();
130 if ( QDialog::Accepted == login.exec() ) { 130 if ( QDialog::Accepted == login.exec() ) {
131 // ok 131 // ok
132 User = login.getUser().latin1(); 132 User = login.getUser().latin1();
133 Pass = login.getPassword().latin1(); 133 Pass = login.getPassword().latin1();
134 } else { 134 } else {
135 // cancel 135 // cancel
136 qDebug( "NNTP: Login canceled" ); 136 qDebug( "NNTP: Login canceled" );
137 return; 137 return;
138 } 138 }
139 } else { 139 } else {
140 User = account->getUser().latin1(); 140 User = account->getUser().latin1();
141 Pass = account->getPassword().latin1(); 141 Pass = account->getPassword().latin1();
142 } 142 }
143 143
144 if (User.isEmpty()) { 144 if (User.isEmpty()) {
145 user=0; 145 user=0;
146 pass = 0; 146 pass = 0;
147 } else { 147 } else {
148 user=User.latin1(); 148 user=User.latin1();
149 pass=Pass.latin1(); 149 pass=Pass.latin1();
150 } 150 }
151 // bool ssl = account->getSSL(); 151 // bool ssl = account->getSSL();
152 152
153 m_nntp=mailstorage_new(NULL); 153 m_nntp=mailstorage_new(NULL);
154 154
155 int conntypeset = account->ConnectionType(); 155 int conntypeset = account->ConnectionType();
156 int conntype = 0; 156 int conntype = 0;
157 if ( conntypeset == 3 ) { 157 if ( conntypeset == 3 ) {
158 conntype = CONNECTION_TYPE_COMMAND; 158 conntype = CONNECTION_TYPE_COMMAND;
159 } else if ( conntypeset == 2 ) { 159 } else if ( conntypeset == 2 ) {
160 conntype = CONNECTION_TYPE_TLS; 160 conntype = CONNECTION_TYPE_TLS;
161 } else if ( conntypeset == 1 ) { 161 } else if ( conntypeset == 1 ) {
162 conntype = CONNECTION_TYPE_STARTTLS; 162 conntype = CONNECTION_TYPE_STARTTLS;
163 } else if ( conntypeset == 0 ) { 163 } else if ( conntypeset == 0 ) {
164 conntype = CONNECTION_TYPE_TRY_STARTTLS; 164 conntype = CONNECTION_TYPE_TRY_STARTTLS;
165 } 165 }
166 166
167 nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN, 167 nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN,
168 (char*)user,(char*)pass,0,0,0); 168 (char*)user,(char*)pass,0,0,0);
169 169
170 err = mailstorage_connect( m_nntp ); 170 err = mailstorage_connect( m_nntp );
171 171
172 if (err != NEWSNNTP_NO_ERROR) { 172 if (err != NEWSNNTP_NO_ERROR) {
173 qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) ); 173 qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) );
174 // Global::statusMessage(tr("Error initializing folder")); 174 // Global::statusMessage(tr("Error initializing folder"));
175 mailstorage_free(m_nntp); 175 mailstorage_free(m_nntp);
176 m_nntp = 0; 176 m_nntp = 0;
177 177
178 } 178 }
179 179
180} 180}
181 181
182void NNTPwrapper::logout() 182void NNTPwrapper::logout()
183{ 183{
184 int err = NEWSNNTP_NO_ERROR; 184 int err = NEWSNNTP_NO_ERROR;
185 if ( m_nntp == NULL ) 185 if ( m_nntp == NULL )
186 return; 186 return;
187 mailstorage_free(m_nntp); 187 mailstorage_free(m_nntp);
188 m_nntp = 0; 188 m_nntp = 0;
189} 189}
190 190
191QValueList<Opie::osmart_pointer<Folder> >* NNTPwrapper::listFolders() { 191QValueList<Opie::OSmartPointer<Folder> >* NNTPwrapper::listFolders() {
192 192
193 QValueList<Opie::osmart_pointer<Folder> >* folders = new QValueList<Opie::osmart_pointer<Folder> >(); 193 QValueList<Opie::OSmartPointer<Folder> >* folders = new QValueList<Opie::OSmartPointer<Folder> >();
194 QStringList groups; 194 QStringList groups;
195 if (account) { 195 if (account) {
196 groups = account->getGroups(); 196 groups = account->getGroups();
197 } 197 }
198 for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) { 198 for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) {
199 folders->append(new Folder((*it),".")); 199 folders->append(new Folder((*it),"."));
200 } 200 }
201 return folders; 201 return folders;
202} 202}
203 203
204/* we made this method in raw nntp access of etpan and not via generic interface 204/* we made this method in raw nntp access of etpan and not via generic interface
205 * 'cause in that case there will be doubled copy operations. eg. the etpan would 205 * 'cause in that case there will be doubled copy operations. eg. the etpan would
206 * copy that stuff into its own structures and we must copy it into useable c++ 206 * copy that stuff into its own structures and we must copy it into useable c++
207 * structures for our frontend. this would not make sense, so it is better to reimplement 207 * structures for our frontend. this would not make sense, so it is better to reimplement
208 * the stuff from generic interface of etpan but copy it direct to qt classes. 208 * the stuff from generic interface of etpan but copy it direct to qt classes.
209 */ 209 */
210QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) { 210QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) {
211 login(); 211 login();
212 QStringList res; 212 QStringList res;
213 clist *result = 0; 213 clist *result = 0;
214 clistcell *current = 0; 214 clistcell *current = 0;
215 newsnntp_group_description *group; 215 newsnntp_group_description *group;
216 216
217 if ( m_nntp ) { 217 if ( m_nntp ) {
218 mailsession * session = m_nntp->sto_session; 218 mailsession * session = m_nntp->sto_session;
219 newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; 219 newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session;
220 int err = NEWSNNTP_NO_ERROR; 220 int err = NEWSNNTP_NO_ERROR;
221 if (mask.isEmpty()) { 221 if (mask.isEmpty()) {
222 err = newsnntp_list(news, &result); 222 err = newsnntp_list(news, &result);
223 } else { 223 } else {
224 /* taken from generic wrapper of etpan */ 224 /* taken from generic wrapper of etpan */
225 QString nmask = mask+".*"; 225 QString nmask = mask+".*";
226 err = newsnntp_list_active(news, nmask.latin1(), &result); 226 err = newsnntp_list_active(news, nmask.latin1(), &result);
227 } 227 }
228 if ( err == NEWSNNTP_NO_ERROR && result) { 228 if ( err == NEWSNNTP_NO_ERROR && result) {
229 for ( current=clist_begin(result);current!=NULL;current=clist_next(current) ) { 229 for ( current=clist_begin(result);current!=NULL;current=clist_next(current) ) {
230 group = ( newsnntp_group_description* ) current->data; 230 group = ( newsnntp_group_description* ) current->data;
231 if (!group||!group->grp_name||strlen(group->grp_name)==0) continue; 231 if (!group||!group->grp_name||strlen(group->grp_name)==0) continue;
232 res.append(group->grp_name); 232 res.append(group->grp_name);
233 } 233 }
234 } 234 }
235 } 235 }
236 if (result) { 236 if (result) {
237 newsnntp_list_free(result); 237 newsnntp_list_free(result);
238 } 238 }
239 return res; 239 return res;
240} 240}
241 241
242void NNTPwrapper::answeredMail(const RecMail&) {} 242void NNTPwrapper::answeredMail(const RecMailP&) {}
243 243
244void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) { 244void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) {
245 login(); 245 login();
246 target_stat.message_count = 0; 246 target_stat.message_count = 0;
247 target_stat.message_unseen = 0; 247 target_stat.message_unseen = 0;
248 target_stat.message_recent = 0; 248 target_stat.message_recent = 0;
249 if (!m_nntp) 249 if (!m_nntp)
250 return; 250 return;
251 int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count, 251 int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count,
252 &target_stat.message_recent,&target_stat.message_unseen); 252 &target_stat.message_recent,&target_stat.message_unseen);
253} 253}
254 254
255 255
256encodedString* NNTPwrapper::fetchRawBody(const RecMail&mail) { 256encodedString* NNTPwrapper::fetchRawBody(const RecMailP&mail) {
257 char*target=0; 257 char*target=0;
258 size_t length=0; 258 size_t length=0;
259 encodedString*res = 0; 259 encodedString*res = 0;
260 mailmessage * mailmsg = 0; 260 mailmessage * mailmsg = 0;
261 int err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg); 261 int err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg);
262 err = mailmessage_fetch(mailmsg,&target,&length); 262 err = mailmessage_fetch(mailmsg,&target,&length);
263 if (mailmsg) 263 if (mailmsg)
264 mailmessage_free(mailmsg); 264 mailmessage_free(mailmsg);
265 if (target) { 265 if (target) {
266 res = new encodedString(target,length); 266 res = new encodedString(target,length);
267 } 267 }
268 return res; 268 return res;
269} 269}
270 270
271MAILLIB::ATYPE NNTPwrapper::getType()const { 271MAILLIB::ATYPE NNTPwrapper::getType()const {
272 return account->getType(); 272 return account->getType();
273} 273}
274 274
275const QString&NNTPwrapper::getName()const{ 275const QString&NNTPwrapper::getName()const{
276 return account->getAccountName(); 276 return account->getAccountName();
277} 277}
278 278
279void NNTPwrapper::deleteMail(const RecMail&) { 279void NNTPwrapper::deleteMail(const RecMailP&) {
280} 280}
281 281
282int NNTPwrapper::deleteAllMail(const FolderP&) { 282int NNTPwrapper::deleteAllMail(const FolderP&) {
283} 283}
diff --git a/noncore/net/mail/libmailwrapper/nntpwrapper.h b/noncore/net/mail/libmailwrapper/nntpwrapper.h
index d3a384a..a7e4b95 100644
--- a/noncore/net/mail/libmailwrapper/nntpwrapper.h
+++ b/noncore/net/mail/libmailwrapper/nntpwrapper.h
@@ -1,48 +1,48 @@
1#ifndef __NNTPWRAPPER 1#ifndef __NNTPWRAPPER
2#define __NNTPWRAPPER 2#define __NNTPWRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include "genericwrapper.h" 5#include "genericwrapper.h"
6#include <qstring.h> 6#include <qstring.h>
7#include <libetpan/clist.h> 7#include <libetpan/clist.h>
8 8
9class encodedString; 9class encodedString;
10struct mailstorage; 10struct mailstorage;
11struct mailfolder; 11struct mailfolder;
12 12
13class NNTPwrapper : public Genericwrapper 13class NNTPwrapper : public Genericwrapper
14{ 14{
15 15
16 Q_OBJECT 16 Q_OBJECT
17 17
18public: 18public:
19 NNTPwrapper( NNTPaccount *a ); 19 NNTPwrapper( NNTPaccount *a );
20 virtual ~NNTPwrapper(); 20 virtual ~NNTPwrapper();
21 21
22 /* mailbox will be ignored */ 22 /* mailbox will be ignored */
23 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 23 virtual void listMessages(const QString & mailbox, QValueList<Opie::OSmartPointer<RecMail> > &target );
24 /* should only get the subscribed one */ 24 /* should only get the subscribed one */
25 virtual QValueList<Opie::osmart_pointer<Folder> >* listFolders(); 25 virtual QValueList<Opie::OSmartPointer<Folder> >* listFolders();
26 /* mailbox will be ignored */ 26 /* mailbox will be ignored */
27 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 27 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
28 QStringList listAllNewsgroups(const QString&mask = QString::null); 28 QStringList listAllNewsgroups(const QString&mask = QString::null);
29 virtual void deleteMail(const RecMail&mail); 29 virtual void deleteMail(const RecMailP&mail);
30 virtual void answeredMail(const RecMail&mail); 30 virtual void answeredMail(const RecMailP&mail);
31 virtual int deleteAllMail(const Opie::osmart_pointer<Folder>&); 31 virtual int deleteAllMail(const Opie::OSmartPointer<Folder>&);
32 32
33 virtual RecBody fetchBody( const RecMail &mail ); 33 virtual RecBody fetchBody( const RecMailP &mail );
34 virtual encodedString* fetchRawBody(const RecMail&mail); 34 virtual encodedString* fetchRawBody(const RecMailP&mail);
35 virtual void logout(); 35 virtual void logout();
36 virtual MAILLIB::ATYPE getType()const; 36 virtual MAILLIB::ATYPE getType()const;
37 virtual const QString&getName()const; 37 virtual const QString&getName()const;
38 static void nntp_progress( size_t current, size_t maximum ); 38 static void nntp_progress( size_t current, size_t maximum );
39 39
40protected: 40protected:
41 void login(); 41 void login();
42 NNTPaccount *account; 42 NNTPaccount *account;
43 mailstorage* m_nntp; 43 mailstorage* m_nntp;
44 44
45 45
46}; 46};
47 47
48#endif 48#endif
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 7bf7ed2..6737d6c 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -1,254 +1,256 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include "pop3wrapper.h" 2#include "pop3wrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include "logindialog.h" 4#include "logindialog.h"
5#include <libetpan/libetpan.h> 5#include <libetpan/libetpan.h>
6#include <qpe/global.h> 6#include <qpe/global.h>
7#include <qfile.h> 7#include <qfile.h>
8//#include <qstring.h> 8//#include <qstring.h>
9 9
10/* we don't fetch messages larger than 5 MB */ 10/* we don't fetch messages larger than 5 MB */
11#define HARD_MSG_SIZE_LIMIT 5242880 11#define HARD_MSG_SIZE_LIMIT 5242880
12 12
13POP3wrapper::POP3wrapper( POP3account *a ) 13POP3wrapper::POP3wrapper( POP3account *a )
14: Genericwrapper() { 14: Genericwrapper() {
15 account = a; 15 account = a;
16 m_pop3 = NULL; 16 m_pop3 = NULL;
17 msgTempName = a->getFileName()+"_msg_cache"; 17 msgTempName = a->getFileName()+"_msg_cache";
18 last_msg_id = 0; 18 last_msg_id = 0;
19} 19}
20 20
21POP3wrapper::~POP3wrapper() { 21POP3wrapper::~POP3wrapper() {
22 logout(); 22 logout();
23 QFile msg_cache(msgTempName); 23 QFile msg_cache(msgTempName);
24 if (msg_cache.exists()) { 24 if (msg_cache.exists()) {
25 msg_cache.remove(); 25 msg_cache.remove();
26 } 26 }
27} 27}
28 28
29void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { 29void POP3wrapper::pop3_progress( size_t current, size_t maximum ) {
30 qDebug( "POP3: %i of %i", current, maximum ); 30 qDebug( "POP3: %i of %i", current, maximum );
31} 31}
32 32
33RecBody POP3wrapper::fetchBody( const RecMail &mail ) { 33RecBody POP3wrapper::fetchBody( const RecMailP &mail ) {
34 int err = MAILPOP3_NO_ERROR; 34 int err = MAILPOP3_NO_ERROR;
35 char *message = 0; 35 char *message = 0;
36 size_t length = 0; 36 size_t length = 0;
37 37
38 login(); 38 login();
39 if ( !m_pop3 ) { 39 if ( !m_pop3 ) {
40 return RecBody(); 40 return RecBody();
41 } 41 }
42 42
43 RecBody body; 43 RecBody body;
44 mailmessage * mailmsg; 44 mailmessage * mailmsg;
45 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { 45 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) {
46 qDebug("Message to large: %i",mail.Msgsize()); 46 qDebug("Message to large: %i",mail->Msgsize());
47 return body; 47 return body;
48 } 48 }
49 49
50 QFile msg_cache(msgTempName); 50 QFile msg_cache(msgTempName);
51 51
52 cleanMimeCache(); 52 cleanMimeCache();
53 53
54 if (mail.getNumber()!=last_msg_id) { 54 if (mail->getNumber()!=last_msg_id) {
55 if (msg_cache.exists()) { 55 if (msg_cache.exists()) {
56 msg_cache.remove(); 56 msg_cache.remove();
57 } 57 }
58 msg_cache.open(IO_ReadWrite|IO_Truncate); 58 msg_cache.open(IO_ReadWrite|IO_Truncate);
59 last_msg_id = mail.getNumber(); 59 last_msg_id = mail->getNumber();
60 err = mailsession_get_message(m_pop3->sto_session, mail.getNumber(), &mailmsg); 60 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
61 err = mailmessage_fetch(mailmsg,&message,&length); 61 err = mailmessage_fetch(mailmsg,&message,&length);
62 msg_cache.writeBlock(message,length); 62 msg_cache.writeBlock(message,length);
63 } else { 63 } else {
64 QString msg=""; 64 QString msg="";
65 msg_cache.open(IO_ReadOnly); 65 msg_cache.open(IO_ReadOnly);
66 message = new char[4096]; 66 message = new char[4096];
67 memset(message,0,4096); 67 memset(message,0,4096);
68 while (msg_cache.readBlock(message,4095)>0) { 68 while (msg_cache.readBlock(message,4095)>0) {
69 msg+=message; 69 msg+=message;
70 memset(message,0,4096); 70 memset(message,0,4096);
71 } 71 }
72 delete message; 72 delete message;
73 message = (char*)malloc(msg.length()+1*sizeof(char)); 73 message = (char*)malloc(msg.length()+1*sizeof(char));
74 memset(message,0,msg.length()+1); 74 memset(message,0,msg.length()+1);
75 memcpy(message,msg.latin1(),msg.length()); 75 memcpy(message,msg.latin1(),msg.length());
76 /* transform to libetpan stuff */ 76 /* transform to libetpan stuff */
77 mailmsg = mailmessage_new(); 77 mailmsg = mailmessage_new();
78 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 78 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
79 generic_message_t * msg_data; 79 generic_message_t * msg_data;
80 msg_data = (generic_message_t *)mailmsg->msg_data; 80 msg_data = (generic_message_t *)mailmsg->msg_data;
81 msg_data->msg_fetched = 1; 81 msg_data->msg_fetched = 1;
82 msg_data->msg_message = message; 82 msg_data->msg_message = message;
83 msg_data->msg_length = strlen(message); 83 msg_data->msg_length = strlen(message);
84 } 84 }
85 body = parseMail(mailmsg); 85 body = parseMail(mailmsg);
86 86
87 /* clean up */ 87 /* clean up */
88 if (mailmsg) 88 if (mailmsg)
89 mailmessage_free(mailmsg); 89 mailmessage_free(mailmsg);
90 if (message) 90 if (message)
91 free(message); 91 free(message);
92 92
93 return body; 93 return body;
94} 94}
95 95
96void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 96void POP3wrapper::listMessages(const QString &, QValueList<Opie::OSmartPointer<RecMail> > &target )
97{ 97{
98 login(); 98 login();
99 if (!m_pop3) 99 if (!m_pop3)
100 return; 100 return;
101 uint32_t res_messages,res_recent,res_unseen; 101 uint32_t res_messages,res_recent,res_unseen;
102 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); 102 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen);
103 parseList(target,m_pop3->sto_session,"INBOX"); 103 parseList(target,m_pop3->sto_session,"INBOX");
104 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); 104 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages));
105} 105}
106 106
107void POP3wrapper::login() 107void POP3wrapper::login()
108{ 108{
109 if (account->getOffline()) 109 if (account->getOffline())
110 return; 110 return;
111 /* we'll hold the line */ 111 /* we'll hold the line */
112 if ( m_pop3 != NULL ) 112 if ( m_pop3 != NULL )
113 return; 113 return;
114 114
115 const char *server, *user, *pass; 115 const char *server, *user, *pass;
116 uint16_t port; 116 uint16_t port;
117 int err = MAILPOP3_NO_ERROR; 117 int err = MAILPOP3_NO_ERROR;
118 118
119 server = account->getServer().latin1(); 119 server = account->getServer().latin1();
120 port = account->getPort().toUInt(); 120 port = account->getPort().toUInt();
121 121
122 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 122 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
123 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 123 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
124 login.show(); 124 login.show();
125 if ( QDialog::Accepted == login.exec() ) { 125 if ( QDialog::Accepted == login.exec() ) {
126 // ok 126 // ok
127 user = login.getUser().latin1(); 127 user = login.getUser().latin1();
128 pass = login.getPassword().latin1(); 128 pass = login.getPassword().latin1();
129 } else { 129 } else {
130 // cancel 130 // cancel
131 qDebug( "POP3: Login canceled" ); 131 qDebug( "POP3: Login canceled" );
132 return; 132 return;
133 } 133 }
134 } else { 134 } else {
135 user = account->getUser().latin1(); 135 user = account->getUser().latin1();
136 pass = account->getPassword().latin1(); 136 pass = account->getPassword().latin1();
137 } 137 }
138 138
139 // bool ssl = account->getSSL(); 139 // bool ssl = account->getSSL();
140 140
141 m_pop3=mailstorage_new(NULL); 141 m_pop3=mailstorage_new(NULL);
142 142
143 int conntypeset = account->ConnectionType(); 143 int conntypeset = account->ConnectionType();
144 int conntype = 0; 144 int conntype = 0;
145 if ( conntypeset == 3 ) { 145 if ( conntypeset == 3 ) {
146 conntype = CONNECTION_TYPE_COMMAND; 146 conntype = CONNECTION_TYPE_COMMAND;
147 } else if ( conntypeset == 2 ) { 147 } else if ( conntypeset == 2 ) {
148 conntype = CONNECTION_TYPE_TLS; 148 conntype = CONNECTION_TYPE_TLS;
149 } else if ( conntypeset == 1 ) { 149 } else if ( conntypeset == 1 ) {
150 conntype = CONNECTION_TYPE_STARTTLS; 150 conntype = CONNECTION_TYPE_STARTTLS;
151 } else if ( conntypeset == 0 ) { 151 } else if ( conntypeset == 0 ) {
152 conntype = CONNECTION_TYPE_TRY_STARTTLS; 152 conntype = CONNECTION_TYPE_TRY_STARTTLS;
153 } 153 }
154 154
155 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); 155 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN);
156 156
157 pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, 157 pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN,
158 (char*)user,(char*)pass,0,0,0); 158 (char*)user,(char*)pass,0,0,0);
159 159
160 160
161 err = mailstorage_connect(m_pop3); 161 err = mailstorage_connect(m_pop3);
162 if (err != MAIL_NO_ERROR) { 162 if (err != MAIL_NO_ERROR) {
163 qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) ); 163 qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) );
164 Global::statusMessage(tr("Error initializing folder")); 164 Global::statusMessage(tr("Error initializing folder"));
165 mailstorage_free(m_pop3); 165 mailstorage_free(m_pop3);
166 m_pop3 = 0; 166 m_pop3 = 0;
167 } 167 }
168} 168}
169 169
170void POP3wrapper::logout() 170void POP3wrapper::logout()
171{ 171{
172 int err = MAILPOP3_NO_ERROR;
173 if ( m_pop3 == NULL ) 172 if ( m_pop3 == NULL )
174 return; 173 return;
175 mailstorage_free(m_pop3); 174 mailstorage_free(m_pop3);
176 m_pop3 = 0; 175 m_pop3 = 0;
177} 176}
178 177
179 178
180QValueList<Opie::osmart_pointer<Folder> >* POP3wrapper::listFolders() { 179QValueList<Opie::OSmartPointer<Folder> >* POP3wrapper::listFolders() {
181 QValueList<Opie::osmart_pointer<Folder> >* folders = new QValueList<FolderP>(); 180 QValueList<Opie::OSmartPointer<Folder> >* folders = new QValueList<FolderP>();
182 FolderP inb=new Folder("INBOX","/"); 181 FolderP inb=new Folder("INBOX","/");
183 folders->append(inb); 182 folders->append(inb);
184 return folders; 183 return folders;
185} 184}
186 185
187void POP3wrapper::deleteMail(const RecMail&mail) { 186void POP3wrapper::deleteMail(const RecMailP&mail) {
188 login(); 187 login();
189 if (!m_pop3) 188 if (!m_pop3)
190 return; 189 return;
191 int err = mailsession_remove_message(m_pop3->sto_session,mail.getNumber()); 190 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber());
192 if (err != MAIL_NO_ERROR) { 191 if (err != MAIL_NO_ERROR) {
193 Global::statusMessage(tr("error deleting mail")); 192 Global::statusMessage(tr("error deleting mail"));
194 } 193 }
195} 194}
196 195
197void POP3wrapper::answeredMail(const RecMail&) {} 196void POP3wrapper::answeredMail(const RecMailP&) {}
198 197
199int POP3wrapper::deleteAllMail(const FolderP&) { 198int POP3wrapper::deleteAllMail(const FolderP&) {
200 login(); 199 login();
201 if (!m_pop3) 200 if (!m_pop3)
202 return 0; 201 return 0;
203 int res = 1; 202 int res = 1;
204 203
205 uint32_t result = 0; 204 uint32_t result = 0;
206 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); 205 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result);
207 if (err != MAIL_NO_ERROR) { 206 if (err != MAIL_NO_ERROR) {
208 Global::statusMessage(tr("Error getting folder info")); 207 Global::statusMessage(tr("Error getting folder info"));
209 return 0; 208 return 0;
210 } 209 }
211 for (unsigned int i = 0; i < result; ++i) { 210 for (unsigned int i = 0; i < result; ++i) {
212 err = mailsession_remove_message(m_pop3->sto_session,i+1); 211 err = mailsession_remove_message(m_pop3->sto_session,i+1);
213 if (err != MAIL_NO_ERROR) { 212 if (err != MAIL_NO_ERROR) {
214 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 213 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
215 res=0; 214 res=0;
216 } 215 }
217 break; 216 break;
218 } 217 }
219 return res; 218 return res;
220} 219}
221 220
222void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { 221void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) {
223 login(); 222 login();
224 target_stat.message_count = 0; 223 target_stat.message_count = 0;
225 target_stat.message_unseen = 0; 224 target_stat.message_unseen = 0;
226 target_stat.message_recent = 0; 225 target_stat.message_recent = 0;
227 if (!m_pop3) 226 if (!m_pop3)
228 return; 227 return;
229 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, 228 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count,
230 &target_stat.message_recent,&target_stat.message_unseen); 229 &target_stat.message_recent,&target_stat.message_unseen);
230 if (r != MAIL_NO_ERROR) {
231 qDebug("error getting folter status.");
232 }
231} 233}
232 234
233encodedString* POP3wrapper::fetchRawBody(const RecMail&mail) { 235encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) {
234 char*target=0; 236 char*target=0;
235 size_t length=0; 237 size_t length=0;
236 encodedString*res = 0; 238 encodedString*res = 0;
237 mailmessage * mailmsg = 0; 239 mailmessage * mailmsg = 0;
238 int err = mailsession_get_message(m_pop3->sto_session, mail.getNumber(), &mailmsg); 240 int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
239 err = mailmessage_fetch(mailmsg,&target,&length); 241 err = mailmessage_fetch(mailmsg,&target,&length);
240 if (mailmsg) 242 if (mailmsg)
241 mailmessage_free(mailmsg); 243 mailmessage_free(mailmsg);
242 if (target) { 244 if (target) {
243 res = new encodedString(target,length); 245 res = new encodedString(target,length);
244 } 246 }
245 return res; 247 return res;
246} 248}
247 249
248MAILLIB::ATYPE POP3wrapper::getType()const { 250MAILLIB::ATYPE POP3wrapper::getType()const {
249 return account->getType(); 251 return account->getType();
250} 252}
251 253
252const QString&POP3wrapper::getName()const{ 254const QString&POP3wrapper::getName()const{
253 return account->getAccountName(); 255 return account->getAccountName();
254} 256}
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h
index e4afb94..31eb6f1 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.h
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h
@@ -1,42 +1,42 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include "genericwrapper.h" 5#include "genericwrapper.h"
6#include <qstring.h> 6#include <qstring.h>
7 7
8class encodedString; 8class encodedString;
9struct mailstorage; 9struct mailstorage;
10struct mailfolder; 10struct mailfolder;
11 11
12class POP3wrapper : public Genericwrapper 12class POP3wrapper : public Genericwrapper
13{ 13{
14 Q_OBJECT 14 Q_OBJECT
15 15
16public: 16public:
17 POP3wrapper( POP3account *a ); 17 POP3wrapper( POP3account *a );
18 virtual ~POP3wrapper(); 18 virtual ~POP3wrapper();
19 /* mailbox will be ignored */ 19 /* mailbox will be ignored */
20 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 20 virtual void listMessages(const QString & mailbox, QValueList<Opie::OSmartPointer<RecMail> > &target );
21 virtual QValueList<Opie::osmart_pointer<Folder> >* listFolders(); 21 virtual QValueList<Opie::OSmartPointer<Folder> >* listFolders();
22 /* mailbox will be ignored */ 22 /* mailbox will be ignored */
23 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 23 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
24 24
25 virtual void deleteMail(const RecMail&mail); 25 virtual void deleteMail(const RecMailP&mail);
26 virtual void answeredMail(const RecMail&mail); 26 virtual void answeredMail(const RecMailP&mail);
27 virtual int deleteAllMail(const Opie::osmart_pointer<Folder>&); 27 virtual int deleteAllMail(const Opie::OSmartPointer<Folder>&);
28 28
29 virtual RecBody fetchBody( const RecMail &mail ); 29 virtual RecBody fetchBody( const RecMailP &mail );
30 virtual encodedString* fetchRawBody(const RecMail&mail); 30 virtual encodedString* fetchRawBody(const RecMailP&mail);
31 virtual void logout(); 31 virtual void logout();
32 virtual MAILLIB::ATYPE getType()const; 32 virtual MAILLIB::ATYPE getType()const;
33 virtual const QString&getName()const; 33 virtual const QString&getName()const;
34 static void pop3_progress( size_t current, size_t maximum ); 34 static void pop3_progress( size_t current, size_t maximum );
35 35
36protected: 36protected:
37 void login(); 37 void login();
38 POP3account *account; 38 POP3account *account;
39 mailstorage*m_pop3; 39 mailstorage*m_pop3;
40}; 40};
41 41
42#endif 42#endif
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
index afc5618..86673aa 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
@@ -1,456 +1,454 @@
1#include "smtpwrapper.h" 1#include "smtpwrapper.h"
2#include "mailwrapper.h" 2#include "mailwrapper.h"
3#include "abstractmail.h" 3#include "abstractmail.h"
4#include "logindialog.h" 4#include "logindialog.h"
5#include "mailtypes.h" 5#include "mailtypes.h"
6#include "sendmailprogress.h" 6#include "sendmailprogress.h"
7 7
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 15
16progressMailSend*SMTPwrapper::sendProgress = 0; 16progressMailSend*SMTPwrapper::sendProgress = 0;
17 17
18SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) 18SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp )
19 : Generatemail() 19 : Generatemail()
20{ 20{
21 m_SmtpAccount = aSmtp; 21 m_SmtpAccount = aSmtp;
22 Config cfg( "mail" ); 22 Config cfg( "mail" );
23 cfg.setGroup( "Status" ); 23 cfg.setGroup( "Status" );
24 m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); 24 m_queuedMail = cfg.readNumEntry( "outgoing", 0 );
25 emit queuedMails( m_queuedMail ); 25 emit queuedMails( m_queuedMail );
26 connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); 26 connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) );
27 m_smtp = 0; 27 m_smtp = 0;
28} 28}
29 29
30SMTPwrapper::~SMTPwrapper() 30SMTPwrapper::~SMTPwrapper()
31{ 31{
32 disc_server(); 32 disc_server();
33} 33}
34 34
35void SMTPwrapper::emitQCop( int queued ) { 35void SMTPwrapper::emitQCop( int queued ) {
36 QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); 36 QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" );
37 env << queued; 37 env << queued;
38} 38}
39 39
40QString SMTPwrapper::mailsmtpError( int errnum ) { 40QString SMTPwrapper::mailsmtpError( int errnum ) {
41 switch ( errnum ) { 41 switch ( errnum ) {
42 case MAILSMTP_NO_ERROR: 42 case MAILSMTP_NO_ERROR:
43 return tr( "No error" ); 43 return tr( "No error" );
44 case MAILSMTP_ERROR_UNEXPECTED_CODE: 44 case MAILSMTP_ERROR_UNEXPECTED_CODE:
45 return tr( "Unexpected error code" ); 45 return tr( "Unexpected error code" );
46 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 46 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
47 return tr( "Service not available" ); 47 return tr( "Service not available" );
48 case MAILSMTP_ERROR_STREAM: 48 case MAILSMTP_ERROR_STREAM:
49 return tr( "Stream error" ); 49 return tr( "Stream error" );
50 case MAILSMTP_ERROR_HOSTNAME: 50 case MAILSMTP_ERROR_HOSTNAME:
51 return tr( "gethostname() failed" ); 51 return tr( "gethostname() failed" );
52 case MAILSMTP_ERROR_NOT_IMPLEMENTED: 52 case MAILSMTP_ERROR_NOT_IMPLEMENTED:
53 return tr( "Not implemented" ); 53 return tr( "Not implemented" );
54 case MAILSMTP_ERROR_ACTION_NOT_TAKEN: 54 case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
55 return tr( "Error, action not taken" ); 55 return tr( "Error, action not taken" );
56 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: 56 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
57 return tr( "Data exceeds storage allocation" ); 57 return tr( "Data exceeds storage allocation" );
58 case MAILSMTP_ERROR_IN_PROCESSING: 58 case MAILSMTP_ERROR_IN_PROCESSING:
59 return tr( "Error in processing" ); 59 return tr( "Error in processing" );
60 case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: 60 case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED:
61 return tr( "Starttls not supported" ); 61 return tr( "Starttls not supported" );
62 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 62 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
63 // return tr( "Insufficient system storage" ); 63 // return tr( "Insufficient system storage" );
64 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 64 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
65 return tr( "Mailbox unavailable" ); 65 return tr( "Mailbox unavailable" );
66 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: 66 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
67 return tr( "Mailbox name not allowed" ); 67 return tr( "Mailbox name not allowed" );
68 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: 68 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
69 return tr( "Bad command sequence" ); 69 return tr( "Bad command sequence" );
70 case MAILSMTP_ERROR_USER_NOT_LOCAL: 70 case MAILSMTP_ERROR_USER_NOT_LOCAL:
71 return tr( "User not local" ); 71 return tr( "User not local" );
72 case MAILSMTP_ERROR_TRANSACTION_FAILED: 72 case MAILSMTP_ERROR_TRANSACTION_FAILED:
73 return tr( "Transaction failed" ); 73 return tr( "Transaction failed" );
74 case MAILSMTP_ERROR_MEMORY: 74 case MAILSMTP_ERROR_MEMORY:
75 return tr( "Memory error" ); 75 return tr( "Memory error" );
76 case MAILSMTP_ERROR_CONNECTION_REFUSED: 76 case MAILSMTP_ERROR_CONNECTION_REFUSED:
77 return tr( "Connection refused" ); 77 return tr( "Connection refused" );
78 default: 78 default:
79 return tr( "Unknown error code" ); 79 return tr( "Unknown error code" );
80 } 80 }
81} 81}
82 82
83 83
84void SMTPwrapper::progress( size_t current, size_t maximum ) { 84void SMTPwrapper::progress( size_t current, size_t maximum ) {
85 if (SMTPwrapper::sendProgress) { 85 if (SMTPwrapper::sendProgress) {
86 SMTPwrapper::sendProgress->setSingleMail(current, maximum ); 86 SMTPwrapper::sendProgress->setSingleMail(current, maximum );
87 qApp->processEvents(); 87 qApp->processEvents();
88 } 88 }
89} 89}
90 90
91void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { 91void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) {
92 if (!mail) 92 if (!mail)
93 return; 93 return;
94 QString localfolders = AbstractMail::defaultLocalfolder(); 94 QString localfolders = AbstractMail::defaultLocalfolder();
95 AbstractMail*wrap = AbstractMail::getWrapper(localfolders); 95 AbstractMail*wrap = AbstractMail::getWrapper(localfolders);
96 wrap->createMbox(box); 96 wrap->createMbox(box);
97 wrap->storeMessage(mail,length,box); 97 wrap->storeMessage(mail,length,box);
98 delete wrap; 98 delete wrap;
99} 99}
100 100
101void SMTPwrapper::smtpSend( mailmime *mail,bool later) { 101void SMTPwrapper::smtpSend( mailmime *mail,bool later) {
102 clist *rcpts = 0; 102 clist *rcpts = 0;
103 char *from, *data; 103 char *from, *data;
104 size_t size; 104 size_t size;
105 105
106 from = data = 0; 106 from = data = 0;
107 107
108 mailmessage * msg = 0; 108 mailmessage * msg = 0;
109 msg = mime_message_init(mail); 109 msg = mime_message_init(mail);
110 mime_message_set_tmpdir(msg,getenv( "HOME" )); 110 mime_message_set_tmpdir(msg,getenv( "HOME" ));
111 int r = mailmessage_fetch(msg,&data,&size); 111 int r = mailmessage_fetch(msg,&data,&size);
112 mime_message_detach_mime(msg); 112 mime_message_detach_mime(msg);
113 mailmessage_free(msg); 113 mailmessage_free(msg);
114 if (r != MAIL_NO_ERROR || !data) { 114 if (r != MAIL_NO_ERROR || !data) {
115 if (data) 115 if (data)
116 free(data); 116 free(data);
117 qDebug("Error fetching mime..."); 117 qDebug("Error fetching mime...");
118 return; 118 return;
119 } 119 }
120 msg = 0; 120 msg = 0;
121 if (later) { 121 if (later) {
122 storeMail(data,size,"Outgoing"); 122 storeMail(data,size,"Outgoing");
123 if (data) 123 if (data)
124 free( data ); 124 free( data );
125 Config cfg( "mail" ); 125 Config cfg( "mail" );
126 cfg.setGroup( "Status" ); 126 cfg.setGroup( "Status" );
127 cfg.writeEntry( "outgoing", ++m_queuedMail ); 127 cfg.writeEntry( "outgoing", ++m_queuedMail );
128 emit queuedMails( m_queuedMail ); 128 emit queuedMails( m_queuedMail );
129 return; 129 return;
130 } 130 }
131 from = getFrom( mail ); 131 from = getFrom( mail );
132 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 132 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
133 smtpSend(from,rcpts,data,size); 133 smtpSend(from,rcpts,data,size);
134 if (data) { 134 if (data) {
135 free(data); 135 free(data);
136 } 136 }
137 if (from) { 137 if (from) {
138 free(from); 138 free(from);
139 } 139 }
140 if (rcpts) 140 if (rcpts)
141 smtp_address_list_free( rcpts ); 141 smtp_address_list_free( rcpts );
142} 142}
143 143
144void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) 144void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage)
145{ 145{
146 if (data) { 146 if (data) {
147 storeMail(data,size,"Sendfailed"); 147 storeMail(data,size,"Sendfailed");
148 } 148 }
149 if (failuremessage) { 149 if (failuremessage) {
150 QMessageBox::critical(0,tr("Error sending mail"), 150 QMessageBox::critical(0,tr("Error sending mail"),
151 tr("<center>%1</center>").arg(failuremessage)); 151 tr("<center>%1</center>").arg(failuremessage));
152 } 152 }
153} 153}
154 154
155int SMTPwrapper::start_smtp_tls() 155int SMTPwrapper::start_smtp_tls()
156{ 156{
157 if (!m_smtp) { 157 if (!m_smtp) {
158 return MAILSMTP_ERROR_IN_PROCESSING; 158 return MAILSMTP_ERROR_IN_PROCESSING;
159 } 159 }
160 int err = mailesmtp_starttls(m_smtp); 160 int err = mailesmtp_starttls(m_smtp);
161 if (err != MAILSMTP_NO_ERROR) return err; 161 if (err != MAILSMTP_NO_ERROR) return err;
162 mailstream_low * low; 162 mailstream_low * low;
163 mailstream_low * new_low; 163 mailstream_low * new_low;
164 low = mailstream_get_low(m_smtp->stream); 164 low = mailstream_get_low(m_smtp->stream);
165 if (!low) { 165 if (!low) {
166 return MAILSMTP_ERROR_IN_PROCESSING; 166 return MAILSMTP_ERROR_IN_PROCESSING;
167 } 167 }
168 int fd = mailstream_low_get_fd(low); 168 int fd = mailstream_low_get_fd(low);
169 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 169 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
170 mailstream_low_free(low); 170 mailstream_low_free(low);
171 mailstream_set_low(m_smtp->stream, new_low); 171 mailstream_set_low(m_smtp->stream, new_low);
172 } else { 172 } else {
173 return MAILSMTP_ERROR_IN_PROCESSING; 173 return MAILSMTP_ERROR_IN_PROCESSING;
174 } 174 }
175 return err; 175 return err;
176} 176}
177 177
178void SMTPwrapper::connect_server() 178void SMTPwrapper::connect_server()
179{ 179{
180 const char *server, *user, *pass; 180 const char *server, *user, *pass;
181 bool ssl; 181 bool ssl;
182 uint16_t port; 182 uint16_t port;
183 ssl = false; 183 ssl = false;
184 bool try_tls = true; 184 bool try_tls = true;
185 bool force_tls=false; 185 bool force_tls=false;
186 server = user = pass = 0; 186 server = user = pass = 0;
187 QString failuretext = ""; 187 QString failuretext = "";
188 188
189 if (m_smtp || !m_SmtpAccount) { 189 if (m_smtp || !m_SmtpAccount) {
190 return; 190 return;
191 } 191 }
192 server = m_SmtpAccount->getServer().latin1(); 192 server = m_SmtpAccount->getServer().latin1();
193 if ( m_SmtpAccount->ConnectionType() == 2 ) { 193 if ( m_SmtpAccount->ConnectionType() == 2 ) {
194 ssl = true; 194 ssl = true;
195 try_tls = false; 195 try_tls = false;
196 } else if (m_SmtpAccount->ConnectionType() == 1) { 196 } else if (m_SmtpAccount->ConnectionType() == 1) {
197 force_tls = true; 197 force_tls = true;
198 } 198 }
199 int result = 1; 199 int result = 1;
200 port = m_SmtpAccount->getPort().toUInt(); 200 port = m_SmtpAccount->getPort().toUInt();
201 201
202 m_smtp = mailsmtp_new( 20, &progress ); 202 m_smtp = mailsmtp_new( 20, &progress );
203 if ( m_smtp == NULL ) { 203 if ( m_smtp == NULL ) {
204 /* no failure message cause this happens when problems with memory - than we 204 /* no failure message cause this happens when problems with memory - than we
205 we can not display any messagebox */ 205 we can not display any messagebox */
206 return; 206 return;
207 } 207 }
208 208
209 int err = MAILSMTP_NO_ERROR; 209 int err = MAILSMTP_NO_ERROR;
210 qDebug( "Servername %s at port %i", server, port ); 210 qDebug( "Servername %s at port %i", server, port );
211 if ( ssl ) { 211 if ( ssl ) {
212 qDebug( "SSL session" ); 212 qDebug( "SSL session" );
213 err = mailsmtp_ssl_connect( m_smtp, server, port ); 213 err = mailsmtp_ssl_connect( m_smtp, server, port );
214 } else { 214 } else {
215 qDebug( "No SSL session" ); 215 qDebug( "No SSL session" );
216 err = mailsmtp_socket_connect( m_smtp, server, port ); 216 err = mailsmtp_socket_connect( m_smtp, server, port );
217 } 217 }
218 if ( err != MAILSMTP_NO_ERROR ) { 218 if ( err != MAILSMTP_NO_ERROR ) {
219 qDebug("Error init connection"); 219 qDebug("Error init connection");
220 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); 220 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err));
221 result = 0; 221 result = 0;
222 } 222 }
223 223
224 /* switch to tls after init 'cause there it will send the ehlo */ 224 /* switch to tls after init 'cause there it will send the ehlo */
225 if (result) { 225 if (result) {
226 err = mailsmtp_init( m_smtp ); 226 err = mailsmtp_init( m_smtp );
227 if (err != MAILSMTP_NO_ERROR) { 227 if (err != MAILSMTP_NO_ERROR) {
228 result = 0; 228 result = 0;
229 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); 229 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err));
230 } 230 }
231 } 231 }
232 232
233 if (try_tls) { 233 if (try_tls) {
234 err = start_smtp_tls(); 234 err = start_smtp_tls();
235 if (err != MAILSMTP_NO_ERROR) { 235 if (err != MAILSMTP_NO_ERROR) {
236 try_tls = false; 236 try_tls = false;
237 } else { 237 } else {
238 err = mailesmtp_ehlo(m_smtp); 238 err = mailesmtp_ehlo(m_smtp);
239 } 239 }
240 } 240 }
241 241
242 if (!try_tls && force_tls) { 242 if (!try_tls && force_tls) {
243 result = 0; 243 result = 0;
244 failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); 244 failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err));
245 } 245 }
246 246
247 if (result==1 && m_SmtpAccount->getLogin() ) { 247 if (result==1 && m_SmtpAccount->getLogin() ) {
248 qDebug("smtp with auth"); 248 qDebug("smtp with auth");
249 if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { 249 if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) {
250 // get'em 250 // get'em
251 LoginDialog login( m_SmtpAccount->getUser(), 251 LoginDialog login( m_SmtpAccount->getUser(),
252 m_SmtpAccount->getPassword(), NULL, 0, true ); 252 m_SmtpAccount->getPassword(), NULL, 0, true );
253 login.show(); 253 login.show();
254 if ( QDialog::Accepted == login.exec() ) { 254 if ( QDialog::Accepted == login.exec() ) {
255 // ok 255 // ok
256 user = login.getUser().latin1(); 256 user = login.getUser().latin1();
257 pass = login.getPassword().latin1(); 257 pass = login.getPassword().latin1();
258 } else { 258 } else {
259 result = 0; 259 result = 0;
260 failuretext=tr("Login aborted - storing mail to localfolder"); 260 failuretext=tr("Login aborted - storing mail to localfolder");
261 } 261 }
262 } else { 262 } else {
263 user = m_SmtpAccount->getUser().latin1(); 263 user = m_SmtpAccount->getUser().latin1();
264 pass = m_SmtpAccount->getPassword().latin1(); 264 pass = m_SmtpAccount->getPassword().latin1();
265 } 265 }
266 qDebug( "session->auth: %i", m_smtp->auth); 266 qDebug( "session->auth: %i", m_smtp->auth);
267 if (result) { 267 if (result) {
268 err = mailsmtp_auth( m_smtp, (char*)user, (char*)pass ); 268 err = mailsmtp_auth( m_smtp, (char*)user, (char*)pass );
269 if ( err == MAILSMTP_NO_ERROR ) { 269 if ( err == MAILSMTP_NO_ERROR ) {
270 qDebug("auth ok"); 270 qDebug("auth ok");
271 } else { 271 } else {
272 failuretext = tr("Authentification failed"); 272 failuretext = tr("Authentification failed");
273 result = 0; 273 result = 0;
274 } 274 }
275 } 275 }
276 } 276 }
277} 277}
278 278
279void SMTPwrapper::disc_server() 279void SMTPwrapper::disc_server()
280{ 280{
281 if (m_smtp) { 281 if (m_smtp) {
282 mailsmtp_quit( m_smtp ); 282 mailsmtp_quit( m_smtp );
283 mailsmtp_free( m_smtp ); 283 mailsmtp_free( m_smtp );
284 m_smtp = 0; 284 m_smtp = 0;
285 } 285 }
286} 286}
287 287
288int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) 288int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size )
289{ 289{
290 int err,result; 290 int err,result;
291 QString failuretext = ""; 291 QString failuretext = "";
292 292
293 connect_server(); 293 connect_server();
294 294
295 result = 1; 295 result = 1;
296 if (m_smtp) { 296 if (m_smtp) {
297 err = mailsmtp_send( m_smtp, from, rcpts, data, size ); 297 err = mailsmtp_send( m_smtp, from, rcpts, data, size );
298 if ( err != MAILSMTP_NO_ERROR ) { 298 if ( err != MAILSMTP_NO_ERROR ) {
299 failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); 299 failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err));
300 result = 0; 300 result = 0;
301 } 301 }
302 } else { 302 } else {
303 result = 0; 303 result = 0;
304 } 304 }
305 305
306 if (!result) { 306 if (!result) {
307 storeFailedMail(data,size,failuretext); 307 storeFailedMail(data,size,failuretext);
308 } else { 308 } else {
309 qDebug( "Mail sent." ); 309 qDebug( "Mail sent." );
310 storeMail(data,size,"Sent"); 310 storeMail(data,size,"Sent");
311 } 311 }
312 return result; 312 return result;
313} 313}
314 314
315void SMTPwrapper::sendMail(const Opie::osmart_pointer<Mail>&mail,bool later ) 315void SMTPwrapper::sendMail(const Opie::OSmartPointer<Mail>&mail,bool later )
316{ 316{
317 mailmime * mimeMail; 317 mailmime * mimeMail;
318 318
319 mimeMail = createMimeMail(mail ); 319 mimeMail = createMimeMail(mail );
320 if ( mimeMail == NULL ) { 320 if ( mimeMail == NULL ) {
321 qDebug( "sendMail: error creating mime mail" ); 321 qDebug( "sendMail: error creating mime mail" );
322 } else { 322 } else {
323 sendProgress = new progressMailSend(); 323 sendProgress = new progressMailSend();
324 sendProgress->show(); 324 sendProgress->show();
325 sendProgress->setMaxMails(1); 325 sendProgress->setMaxMails(1);
326 smtpSend( mimeMail,later); 326 smtpSend( mimeMail,later);
327 qDebug("Clean up done"); 327 qDebug("Clean up done");
328 sendProgress->hide(); 328 sendProgress->hide();
329 delete sendProgress; 329 delete sendProgress;
330 sendProgress = 0; 330 sendProgress = 0;
331 mailmime_free( mimeMail ); 331 mailmime_free( mimeMail );
332 } 332 }
333} 333}
334 334
335int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,RecMail*which) { 335int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) {
336 size_t curTok = 0; 336 size_t curTok = 0;
337 mailimf_fields *fields = 0; 337 mailimf_fields *fields = 0;
338 mailimf_field*ffrom = 0; 338 mailimf_field*ffrom = 0;
339 clist *rcpts = 0; 339 clist *rcpts = 0;
340 char*from = 0; 340 char*from = 0;
341 int res = 0; 341 int res = 0;
342 342
343 encodedString * data = wrap->fetchRawBody(*which); 343 encodedString * data = wrap->fetchRawBody(which);
344 if (!data) 344 if (!data)
345 return 0; 345 return 0;
346 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); 346 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields );
347 if (err != MAILIMF_NO_ERROR) { 347 if (err != MAILIMF_NO_ERROR) {
348 delete data; 348 delete data;
349 delete wrap; 349 delete wrap;
350 return 0; 350 return 0;
351 } 351 }
352 352
353 rcpts = createRcptList( fields ); 353 rcpts = createRcptList( fields );
354 ffrom = getField(fields, MAILIMF_FIELD_FROM ); 354 ffrom = getField(fields, MAILIMF_FIELD_FROM );
355 from = getFrom(ffrom); 355 from = getFrom(ffrom);
356 356
357 if (rcpts && from) { 357 if (rcpts && from) {
358 res = smtpSend(from,rcpts,data->Content(),data->Length()); 358 res = smtpSend(from,rcpts,data->Content(),data->Length());
359 } 359 }
360 if (fields) { 360 if (fields) {
361 mailimf_fields_free(fields); 361 mailimf_fields_free(fields);
362 fields = 0; 362 fields = 0;
363 } 363 }
364 if (data) { 364 if (data) {
365 delete data; 365 delete data;
366 } 366 }
367 if (from) { 367 if (from) {
368 free(from); 368 free(from);
369 } 369 }
370 if (rcpts) { 370 if (rcpts) {
371 smtp_address_list_free( rcpts ); 371 smtp_address_list_free( rcpts );
372 } 372 }
373 return res; 373 return res;
374} 374}
375 375
376/* this is a special fun */ 376/* this is a special fun */
377bool SMTPwrapper::flushOutbox() { 377bool SMTPwrapper::flushOutbox() {
378 bool returnValue = true; 378 bool returnValue = true;
379 379
380 qDebug("Sending the queue"); 380 qDebug("Sending the queue");
381 if (!m_SmtpAccount) { 381 if (!m_SmtpAccount) {
382 qDebug("No smtp account given"); 382 qDebug("No smtp account given");
383 return false; 383 return false;
384 } 384 }
385 385
386 bool reset_user_value = false; 386 bool reset_user_value = false;
387 QString localfolders = AbstractMail::defaultLocalfolder(); 387 QString localfolders = AbstractMail::defaultLocalfolder();
388 AbstractMail*wrap = AbstractMail::getWrapper(localfolders); 388 AbstractMail*wrap = AbstractMail::getWrapper(localfolders);
389 if (!wrap) { 389 if (!wrap) {
390 qDebug("memory error"); 390 qDebug("memory error");
391 return false; 391 return false;
392 } 392 }
393 QString oldPw, oldUser; 393 QString oldPw, oldUser;
394 QList<RecMail> mailsToSend; 394 QValueList<RecMailP> mailsToSend;
395 QList<RecMail> mailsToRemove; 395 QValueList<RecMailP> mailsToRemove;
396 QString mbox("Outgoing"); 396 QString mbox("Outgoing");
397 wrap->listMessages(mbox,mailsToSend); 397 wrap->listMessages(mbox,mailsToSend);
398 if (mailsToSend.count()==0) { 398 if (mailsToSend.count()==0) {
399 delete wrap; 399 delete wrap;
400 qDebug("No mails to send"); 400 qDebug("No mails to send");
401 return false; 401 return false;
402 } 402 }
403 403
404 oldPw = m_SmtpAccount->getPassword(); 404 oldPw = m_SmtpAccount->getPassword();
405 oldUser = m_SmtpAccount->getUser(); 405 oldUser = m_SmtpAccount->getUser();
406 if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { 406 if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) {
407 // get'em 407 // get'em
408 QString user,pass; 408 QString user,pass;
409 LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); 409 LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true );
410 login.show(); 410 login.show();
411 if ( QDialog::Accepted == login.exec() ) { 411 if ( QDialog::Accepted == login.exec() ) {
412 // ok 412 // ok
413 user = login.getUser().latin1(); 413 user = login.getUser().latin1();
414 pass = login.getPassword().latin1(); 414 pass = login.getPassword().latin1();
415 reset_user_value = true; 415 reset_user_value = true;
416 m_SmtpAccount->setUser(user); 416 m_SmtpAccount->setUser(user);
417 m_SmtpAccount->setPassword(pass); 417 m_SmtpAccount->setPassword(pass);
418 } else { 418 } else {
419 return true; 419 return true;
420 } 420 }
421 } 421 }
422 422
423 423
424 mailsToSend.setAutoDelete(false);
425 sendProgress = new progressMailSend(); 424 sendProgress = new progressMailSend();
426 sendProgress->show(); 425 sendProgress->show();
427 sendProgress->setMaxMails(mailsToSend.count()); 426 sendProgress->setMaxMails(mailsToSend.count());
428 427
429 while (mailsToSend.count()>0) { 428 while (mailsToSend.count()>0) {
430 if (sendQueuedMail(wrap,mailsToSend.at(0))==0) { 429 if (sendQueuedMail(wrap, (*mailsToSend.begin()))==0) {
431 QMessageBox::critical(0,tr("Error sending mail"), 430 QMessageBox::critical(0,tr("Error sending mail"),
432 tr("Error sending queued mail - breaking")); 431 tr("Error sending queued mail - breaking"));
433 returnValue = false; 432 returnValue = false;
434 break; 433 break;
435 } 434 }
436 mailsToRemove.append(mailsToSend.at(0)); 435 mailsToRemove.append((*mailsToSend.begin()));
437 mailsToSend.removeFirst(); 436 mailsToSend.remove(mailsToSend.begin());
438 sendProgress->setCurrentMails(mailsToRemove.count()); 437 sendProgress->setCurrentMails(mailsToRemove.count());
439 } 438 }
440 if (reset_user_value) { 439 if (reset_user_value) {
441 m_SmtpAccount->setUser(oldUser); 440 m_SmtpAccount->setUser(oldUser);
442 m_SmtpAccount->setPassword(oldPw); 441 m_SmtpAccount->setPassword(oldPw);
443 } 442 }
444 Config cfg( "mail" ); 443 Config cfg( "mail" );
445 cfg.setGroup( "Status" ); 444 cfg.setGroup( "Status" );
446 m_queuedMail = 0; 445 m_queuedMail = 0;
447 cfg.writeEntry( "outgoing", m_queuedMail ); 446 cfg.writeEntry( "outgoing", m_queuedMail );
448 emit queuedMails( m_queuedMail ); 447 emit queuedMails( m_queuedMail );
449 sendProgress->hide(); 448 sendProgress->hide();
450 delete sendProgress; 449 delete sendProgress;
451 sendProgress = 0; 450 sendProgress = 0;
452 wrap->deleteMails(mbox,mailsToRemove); 451 wrap->deleteMails(mbox,mailsToRemove);
453 mailsToSend.setAutoDelete(true);
454 delete wrap; 452 delete wrap;
455 return returnValue; 453 return returnValue;
456} 454}
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h
index 08bde74..71ae35c 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.h
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h
@@ -1,63 +1,63 @@
1// -*- Mode: C++; -*- 1// -*- Mode: C++; -*-
2#ifndef SMTPwrapper_H 2#ifndef SMTPwrapper_H
3#define SMTPwrapper_H 3#define SMTPwrapper_H
4 4
5#include <qpe/applnk.h> 5#include <qpe/applnk.h>
6 6
7#include <qbitarray.h> 7#include <qbitarray.h>
8#include <qdatetime.h> 8#include <qdatetime.h>
9#include <libetpan/clist.h> 9#include <libetpan/clist.h>
10 10
11#include "settings.h" 11#include "settings.h"
12#include "generatemail.h" 12#include "generatemail.h"
13 13
14#include <opie2/osmart_pointer.h> 14#include <opie2/osmartpointer.h>
15 15
16class SMTPaccount; 16class SMTPaccount;
17class AbstractMail; 17class AbstractMail;
18 18
19class SMTPwrapper : public Generatemail 19class SMTPwrapper : public Generatemail
20{ 20{
21 Q_OBJECT 21 Q_OBJECT
22 22
23public: 23public:
24 SMTPwrapper(SMTPaccount * aSmtp); 24 SMTPwrapper(SMTPaccount * aSmtp);
25 virtual ~SMTPwrapper(); 25 virtual ~SMTPwrapper();
26 void sendMail(const Opie::osmart_pointer<Mail>& mail,bool later=false ); 26 void sendMail(const Opie::OSmartPointer<Mail>& mail,bool later=false );
27 bool flushOutbox(); 27 bool flushOutbox();
28 28
29 static progressMailSend*sendProgress; 29 static progressMailSend*sendProgress;
30 30
31signals: 31signals:
32 void queuedMails( int ); 32 void queuedMails( int );
33 33
34protected: 34protected:
35 mailsmtp *m_smtp; 35 mailsmtp *m_smtp;
36 SMTPaccount * m_SmtpAccount; 36 SMTPaccount * m_SmtpAccount;
37 37
38 void connect_server(); 38 void connect_server();
39 void disc_server(); 39 void disc_server();
40 int start_smtp_tls(); 40 int start_smtp_tls();
41 41
42 42
43 void smtpSend( mailmime *mail,bool later); 43 void smtpSend( mailmime *mail,bool later);
44 44
45 static void storeMail(const char*mail, size_t length, const QString&box); 45 static void storeMail(const char*mail, size_t length, const QString&box);
46 static QString mailsmtpError( int err ); 46 static QString mailsmtpError( int err );
47 static void progress( size_t current, size_t maximum ); 47 static void progress( size_t current, size_t maximum );
48 48
49 int smtpSend(char*from,clist*rcpts,const char*data,size_t size); 49 int smtpSend(char*from,clist*rcpts,const char*data,size_t size);
50 50
51 void storeMail(mailmime*mail, const QString&box); 51 void storeMail(mailmime*mail, const QString&box);
52 52
53 int sendQueuedMail(AbstractMail*wrap,RecMail*which); 53 int sendQueuedMail(AbstractMail*wrap,const Opie::OSmartPointer<RecMail>&which);
54 void storeFailedMail(const char*data,unsigned int size, const char*failuremessage); 54 void storeFailedMail(const char*data,unsigned int size, const char*failuremessage);
55 55
56 int m_queuedMail; 56 int m_queuedMail;
57 57
58protected slots: 58protected slots:
59 void emitQCop( int queued ); 59 void emitQCop( int queued );
60 60
61}; 61};
62 62
63#endif 63#endif
diff --git a/noncore/net/mail/libmailwrapper/storemail.cpp b/noncore/net/mail/libmailwrapper/storemail.cpp
index 052e0f1..595e7fc 100644
--- a/noncore/net/mail/libmailwrapper/storemail.cpp
+++ b/noncore/net/mail/libmailwrapper/storemail.cpp
@@ -1,90 +1,90 @@
1#include "storemail.h" 1#include "storemail.h"
2#include "mailwrapper.h" 2#include "mailwrapper.h"
3#include "settings.h" 3#include "settings.h"
4#include "abstractmail.h" 4#include "abstractmail.h"
5 5
6#include <libetpan/libetpan.h> 6#include <libetpan/libetpan.h>
7 7
8#include <qstring.h> 8#include <qstring.h>
9 9
10#include <stdlib.h> 10#include <stdlib.h>
11 11
12Storemail::Storemail(Account*aAccount,const QString&aFolder) 12Storemail::Storemail(Account*aAccount,const QString&aFolder)
13 : Generatemail() 13 : Generatemail()
14{ 14{
15 wrapper = 0; 15 wrapper = 0;
16 m_Account = aAccount; 16 m_Account = aAccount;
17 m_tfolder = aFolder; 17 m_tfolder = aFolder;
18 wrapper = AbstractMail::getWrapper(m_Account); 18 wrapper = AbstractMail::getWrapper(m_Account);
19 if (wrapper) { 19 if (wrapper) {
20 wrapper->createMbox(m_tfolder); 20 wrapper->createMbox(m_tfolder);
21 } 21 }
22} 22}
23 23
24Storemail::Storemail(const QString&dir,const QString&aFolder) 24Storemail::Storemail(const QString&dir,const QString&aFolder)
25 : Generatemail() 25 : Generatemail()
26{ 26{
27 wrapper = 0; 27 wrapper = 0;
28 m_Account = 0; 28 m_Account = 0;
29 m_tfolder = aFolder; 29 m_tfolder = aFolder;
30 wrapper = AbstractMail::getWrapper(dir); 30 wrapper = AbstractMail::getWrapper(dir);
31 if (wrapper) { 31 if (wrapper) {
32 wrapper->createMbox(m_tfolder); 32 wrapper->createMbox(m_tfolder);
33 } 33 }
34} 34}
35 35
36Storemail::Storemail(const QString&aFolder) 36Storemail::Storemail(const QString&aFolder)
37 : Generatemail() 37 : Generatemail()
38{ 38{
39 wrapper = 0; 39 wrapper = 0;
40 m_Account = 0; 40 m_Account = 0;
41 m_tfolder = aFolder; 41 m_tfolder = aFolder;
42 wrapper = AbstractMail::getWrapper(AbstractMail::defaultLocalfolder()); 42 wrapper = AbstractMail::getWrapper(AbstractMail::defaultLocalfolder());
43 if (wrapper) { 43 if (wrapper) {
44 wrapper->createMbox(m_tfolder); 44 wrapper->createMbox(m_tfolder);
45 } 45 }
46} 46}
47 47
48Storemail::~Storemail() 48Storemail::~Storemail()
49{ 49{
50} 50}
51 51
52int Storemail::storeMail(const Opie::osmart_pointer<Mail>&mail) 52int Storemail::storeMail(const Opie::OSmartPointer<Mail>&mail)
53{ 53{
54 if (!wrapper) return 0; 54 if (!wrapper) return 0;
55 int ret = 1; 55 int ret = 1;
56 56
57 mailmime * mimeMail = 0; 57 mailmime * mimeMail = 0;
58 mimeMail = createMimeMail(mail ); 58 mimeMail = createMimeMail(mail );
59 if ( mimeMail == NULL ) { 59 if ( mimeMail == NULL ) {
60 qDebug( "storeMail: error creating mime mail" ); 60 qDebug( "storeMail: error creating mime mail" );
61 return 0; 61 return 0;
62 } 62 }
63 char *data; 63 char *data;
64 size_t size; 64 size_t size;
65 data = 0; 65 data = 0;
66 66
67 mailmessage * msg = 0; 67 mailmessage * msg = 0;
68 msg = mime_message_init(mimeMail); 68 msg = mime_message_init(mimeMail);
69 mime_message_set_tmpdir(msg,getenv( "HOME" )); 69 mime_message_set_tmpdir(msg,getenv( "HOME" ));
70 int r = mailmessage_fetch(msg,&data,&size); 70 int r = mailmessage_fetch(msg,&data,&size);
71 mime_message_detach_mime(msg); 71 mime_message_detach_mime(msg);
72 mailmessage_free(msg); 72 mailmessage_free(msg);
73 msg = 0; 73 msg = 0;
74 if (r != MAIL_NO_ERROR || !data) { 74 if (r != MAIL_NO_ERROR || !data) {
75 qDebug("Error fetching mime..."); 75 qDebug("Error fetching mime...");
76 ret = 0; 76 ret = 0;
77 } 77 }
78 78
79 if (ret) { 79 if (ret) {
80 wrapper->storeMessage(data,size,m_tfolder); 80 wrapper->storeMessage(data,size,m_tfolder);
81 } 81 }
82 82
83 if (data) { 83 if (data) {
84 free(data); 84 free(data);
85 } 85 }
86 if (mimeMail) { 86 if (mimeMail) {
87 mailmime_free( mimeMail ); 87 mailmime_free( mimeMail );
88 } 88 }
89 return ret; 89 return ret;
90} 90}
diff --git a/noncore/net/mail/libmailwrapper/storemail.h b/noncore/net/mail/libmailwrapper/storemail.h
index 7d8ea3d..80c7431 100644
--- a/noncore/net/mail/libmailwrapper/storemail.h
+++ b/noncore/net/mail/libmailwrapper/storemail.h
@@ -1,29 +1,29 @@
1#ifndef __STORE_MAIL_H 1#ifndef __STORE_MAIL_H
2#define __STORE_MAIL_H 2#define __STORE_MAIL_H
3 3
4#include <qpe/applnk.h> 4#include <qpe/applnk.h>
5 5
6#include "generatemail.h" 6#include "generatemail.h"
7 7
8class Account; 8class Account;
9class Mail; 9class Mail;
10class AbstractMail; 10class AbstractMail;
11 11
12class Storemail : public Generatemail 12class Storemail : public Generatemail
13{ 13{
14 Q_OBJECT 14 Q_OBJECT
15public: 15public:
16 Storemail(Account*aAccount,const QString&aFolder); 16 Storemail(Account*aAccount,const QString&aFolder);
17 Storemail(const QString&dir,const QString&aFolder); 17 Storemail(const QString&dir,const QString&aFolder);
18 Storemail(const QString&aFolder); 18 Storemail(const QString&aFolder);
19 virtual ~Storemail(); 19 virtual ~Storemail();
20 20
21 int storeMail(const Opie::osmart_pointer<Mail>&mail); 21 int storeMail(const Opie::OSmartPointer<Mail>&mail);
22 22
23protected: 23protected:
24 Account* m_Account; 24 Account* m_Account;
25 QString m_tfolder; 25 QString m_tfolder;
26 AbstractMail*wrapper; 26 AbstractMail*wrapper;
27}; 27};
28 28
29#endif 29#endif
diff --git a/noncore/net/mail/mailistviewitem.cpp b/noncore/net/mail/mailistviewitem.cpp
index 75633ef..0b926da 100644
--- a/noncore/net/mail/mailistviewitem.cpp
+++ b/noncore/net/mail/mailistviewitem.cpp
@@ -1,72 +1,72 @@
1#include "mailistviewitem.h" 1#include "mailistviewitem.h"
2#include <libmailwrapper/abstractmail.h> 2#include <libmailwrapper/abstractmail.h>
3#include <qtextstream.h> 3#include <qtextstream.h>
4#include <qpe/resource.h> 4#include <qpe/resource.h>
5 5
6MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * item ) 6MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * item )
7 :QListViewItem(parent,item),mail_data() 7 :QListViewItem(parent,item),mail_data()
8{ 8{
9} 9}
10 10
11void MailListViewItem::showEntry() 11void MailListViewItem::showEntry()
12{ 12{
13 if ( mail_data.getFlags().testBit( FLAG_ANSWERED ) == true) { 13 if ( mail_data->getFlags().testBit( FLAG_ANSWERED ) == true) {
14 setPixmap( 0, Resource::loadPixmap( "mail/kmmsgreplied") ); 14 setPixmap( 0, Resource::loadPixmap( "mail/kmmsgreplied") );
15 } else if ( mail_data.getFlags().testBit( FLAG_SEEN ) == true ) { 15 } else if ( mail_data->getFlags().testBit( FLAG_SEEN ) == true ) {
16 /* I think it looks nicer if there are not such a log of icons but only on mails 16 /* I think it looks nicer if there are not such a log of icons but only on mails
17 replied or new - Alwin*/ 17 replied or new - Alwin*/
18 //setPixmap( 0, Resource::loadPixmap( "mail/kmmsgunseen") ); 18 //setPixmap( 0, Resource::loadPixmap( "mail/kmmsgunseen") );
19 } else { 19 } else {
20 setPixmap( 0, Resource::loadPixmap( "mail/kmmsgnew") ); 20 setPixmap( 0, Resource::loadPixmap( "mail/kmmsgnew") );
21 } 21 }
22 double s = mail_data.Msgsize(); 22 double s = mail_data->Msgsize();
23 int w; 23 int w;
24 w=0; 24 w=0;
25 25
26 while (s>1024) { 26 while (s>1024) {
27 s/=1024; 27 s/=1024;
28 ++w; 28 ++w;
29 if (w>=2) break; 29 if (w>=2) break;
30 } 30 }
31 31
32 QString q=""; 32 QString q="";
33 QString fsize=""; 33 QString fsize="";
34 switch(w) { 34 switch(w) {
35 case 1: 35 case 1:
36 q="k"; 36 q="k";
37 break; 37 break;
38 case 2: 38 case 2:
39 q="M"; 39 q="M";
40 break; 40 break;
41 default: 41 default:
42 break; 42 break;
43 } 43 }
44 44
45 { 45 {
46 QTextOStream o(&fsize); 46 QTextOStream o(&fsize);
47 if (w>0) o.precision(2); else o.precision(0); 47 if (w>0) o.precision(2); else o.precision(0);
48 o.setf(QTextStream::fixed); 48 o.setf(QTextStream::fixed);
49 o << s << " " << q << "Byte"; 49 o << s << " " << q << "Byte";
50 } 50 }
51 51
52 setText(1,mail_data.getSubject()); 52 setText(1,mail_data->getSubject());
53 setText(2,mail_data.getFrom()); 53 setText(2,mail_data->getFrom());
54 setText(3,fsize); 54 setText(3,fsize);
55 setText(4,mail_data.getDate()); 55 setText(4,mail_data->getDate());
56} 56}
57 57
58void MailListViewItem::storeData(const RecMail&data) 58void MailListViewItem::storeData(const RecMailP&data)
59{ 59{
60 mail_data = data; 60 mail_data = data;
61} 61}
62 62
63const RecMail& MailListViewItem::data()const 63const RecMailP& MailListViewItem::data()const
64{ 64{
65 return mail_data; 65 return mail_data;
66} 66}
67 67
68MAILLIB::ATYPE MailListViewItem::wrapperType() 68MAILLIB::ATYPE MailListViewItem::wrapperType()
69{ 69{
70 if (!mail_data.Wrapper()) return MAILLIB::A_UNDEFINED; 70 if (!mail_data->Wrapper()) return MAILLIB::A_UNDEFINED;
71 return mail_data.Wrapper()->getType(); 71 return mail_data->Wrapper()->getType();
72} 72}
diff --git a/noncore/net/mail/mailistviewitem.h b/noncore/net/mail/mailistviewitem.h
index f736de0..d953d83 100644
--- a/noncore/net/mail/mailistviewitem.h
+++ b/noncore/net/mail/mailistviewitem.h
@@ -1,23 +1,23 @@
1#ifndef __MAILLISTVIEWITEM_H 1#ifndef __MAILLISTVIEWITEM_H
2#define __MAILLISTVIEWITEM_H 2#define __MAILLISTVIEWITEM_H
3 3
4#include <qlistview.h> 4#include <qlistview.h>
5#include <libmailwrapper/mailtypes.h> 5#include <libmailwrapper/mailtypes.h>
6#include <libmailwrapper/maildefines.h> 6#include <libmailwrapper/maildefines.h>
7 7
8class MailListViewItem:public QListViewItem 8class MailListViewItem:public QListViewItem
9{ 9{
10public: 10public:
11 MailListViewItem(QListView * parent, MailListViewItem * after ); 11 MailListViewItem(QListView * parent, MailListViewItem * after );
12 virtual ~MailListViewItem(){} 12 virtual ~MailListViewItem(){}
13 13
14 void storeData(const RecMail&data); 14 void storeData(const RecMailP&data);
15 const RecMail&data()const; 15 const RecMailP&data()const;
16 void showEntry(); 16 void showEntry();
17 MAILLIB::ATYPE wrapperType(); 17 MAILLIB::ATYPE wrapperType();
18 18
19protected: 19protected:
20 RecMail mail_data; 20 RecMailP mail_data;
21}; 21};
22 22
23#endif 23#endif
diff --git a/noncore/net/mail/mainwindow.cpp b/noncore/net/mail/mainwindow.cpp
index bcf0866..c23ad3f 100644
--- a/noncore/net/mail/mainwindow.cpp
+++ b/noncore/net/mail/mainwindow.cpp
@@ -1,215 +1,216 @@
1#include <qlabel.h> 1#include <qlabel.h>
2#include <qvbox.h> 2#include <qvbox.h>
3#include <qheader.h> 3#include <qheader.h>
4#include <qtimer.h> 4#include <qtimer.h>
5#include <qlayout.h> 5#include <qlayout.h>
6 6
7#include <qpe/qpeapplication.h> 7#include <qpe/qpeapplication.h>
8 8
9#include "defines.h" 9#include "defines.h"
10#include "mainwindow.h" 10#include "mainwindow.h"
11 11
12 12
13MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags ) 13MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags )
14 : QMainWindow( parent, name, flags ) 14 : QMainWindow( parent, name, flags )
15{ 15{
16 16
17 setCaption( tr( "Mail" ) ); 17 setCaption( tr( "Mail" ) );
18 setToolBarsMovable( false ); 18 setToolBarsMovable( false );
19 19
20 toolBar = new QToolBar( this ); 20 toolBar = new QToolBar( this );
21 menuBar = new QMenuBar( toolBar ); 21 menuBar = new QMenuBar( toolBar );
22 mailMenu = new QPopupMenu( menuBar ); 22 mailMenu = new QPopupMenu( menuBar );
23 menuBar->insertItem( tr( "Mail" ), mailMenu ); 23 menuBar->insertItem( tr( "Mail" ), mailMenu );
24 settingsMenu = new QPopupMenu( menuBar ); 24 settingsMenu = new QPopupMenu( menuBar );
25 menuBar->insertItem( tr( "Settings" ), settingsMenu ); 25 menuBar->insertItem( tr( "Settings" ), settingsMenu );
26 26
27 addToolBar( toolBar ); 27 addToolBar( toolBar );
28 toolBar->setHorizontalStretchable( true ); 28 toolBar->setHorizontalStretchable( true );
29 29
30 QLabel *spacer = new QLabel( toolBar ); 30 QLabel *spacer = new QLabel( toolBar );
31 spacer->setBackgroundMode( QWidget::PaletteButton ); 31 spacer->setBackgroundMode( QWidget::PaletteButton );
32 toolBar->setStretchableWidget( spacer ); 32 toolBar->setStretchableWidget( spacer );
33 33
34 composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL, 34 composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL,
35 0, 0, this ); 35 0, 0, this );
36 composeMail->addTo( toolBar ); 36 composeMail->addTo( toolBar );
37 composeMail->addTo( mailMenu ); 37 composeMail->addTo( mailMenu );
38 38
39 sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED, 39 sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED,
40 0, 0, this ); 40 0, 0, this );
41 sendQueued->addTo( toolBar ); 41 sendQueued->addTo( toolBar );
42 sendQueued->addTo( mailMenu ); 42 sendQueued->addTo( mailMenu );
43 43
44 /* 44 /*
45 syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC, 45 syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC,
46 0, 0, this ); 46 0, 0, this );
47 syncFolders->addTo( toolBar ); 47 syncFolders->addTo( toolBar );
48 syncFolders->addTo( mailMenu ); 48 syncFolders->addTo( mailMenu );
49 */ 49 */
50 50
51 showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS, 51 showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS,
52 0, 0, this, 0, true ); 52 0, 0, this, 0, true );
53 showFolders->addTo( toolBar ); 53 showFolders->addTo( toolBar );
54 showFolders->addTo( mailMenu ); 54 showFolders->addTo( mailMenu );
55 showFolders->setOn( true ); 55 showFolders->setOn( true );
56 connect(showFolders, SIGNAL( toggled(bool) ), 56 connect(showFolders, SIGNAL( toggled(bool) ),
57 SLOT( slotShowFolders(bool) ) ); 57 SLOT( slotShowFolders(bool) ) );
58 58
59 /* 59 /*
60 searchMails = new QAction( tr( "Search mails" ), QIconSet( Resource::loadPixmap("find") ), 60 searchMails = new QAction( tr( "Search mails" ), QIconSet( Resource::loadPixmap("find") ),
61 0, 0, this ); 61 0, 0, this );
62 searchMails->addTo( toolBar ); 62 searchMails->addTo( toolBar );
63 searchMails->addTo( mailMenu ); 63 searchMails->addTo( mailMenu );
64 */ 64 */
65 65
66 deleteMails = new QAction(tr("Delete Mail"), QIconSet( Resource::loadPixmap("trash")), 0, 0, this); 66 deleteMails = new QAction(tr("Delete Mail"), QIconSet( Resource::loadPixmap("trash")), 0, 0, this);
67 deleteMails->addTo( toolBar ); 67 deleteMails->addTo( toolBar );
68 deleteMails->addTo( mailMenu ); 68 deleteMails->addTo( mailMenu );
69 connect( deleteMails, SIGNAL( activated() ), 69 connect( deleteMails, SIGNAL( activated() ),
70 SLOT( slotDeleteMail() ) ); 70 SLOT( slotDeleteMail() ) );
71 71
72 editSettings = new QAction( tr( "Edit settings" ), QIconSet( Resource::loadPixmap("SettingsIcon") ) , 72 editSettings = new QAction( tr( "Edit settings" ), QIconSet( Resource::loadPixmap("SettingsIcon") ) ,
73 0, 0, this ); 73 0, 0, this );
74 editSettings->addTo( settingsMenu ); 74 editSettings->addTo( settingsMenu );
75 connect( editSettings, SIGNAL( activated() ), 75 connect( editSettings, SIGNAL( activated() ),
76 SLOT( slotEditSettings() ) ); 76 SLOT( slotEditSettings() ) );
77 editAccounts = new QAction( tr( "Configure accounts" ), QIconSet( Resource::loadPixmap("mail/editaccounts") ) , 77 editAccounts = new QAction( tr( "Configure accounts" ), QIconSet( Resource::loadPixmap("mail/editaccounts") ) ,
78 0, 0, this ); 78 0, 0, this );
79 editAccounts->addTo( settingsMenu ); 79 editAccounts->addTo( settingsMenu );
80 80
81 //setCentralWidget( view ); 81 //setCentralWidget( view );
82 82
83 QVBox* wrapperBox = new QVBox( this ); 83 QVBox* wrapperBox = new QVBox( this );
84 setCentralWidget( wrapperBox ); 84 setCentralWidget( wrapperBox );
85 85
86 QWidget *view = new QWidget( wrapperBox ); 86 QWidget *view = new QWidget( wrapperBox );
87 87
88 layout = new QBoxLayout ( view, QBoxLayout::LeftToRight ); 88 layout = new QBoxLayout ( view, QBoxLayout::LeftToRight );
89 89
90 folderView = new AccountView( view ); 90 folderView = new AccountView( view );
91 folderView->header()->hide(); 91 folderView->header()->hide();
92 folderView->setRootIsDecorated( true ); 92 folderView->setRootIsDecorated( true );
93 folderView->addColumn( tr( "Mailbox" ) ); 93 folderView->addColumn( tr( "Mailbox" ) );
94 94
95 layout->addWidget( folderView ); 95 layout->addWidget( folderView );
96 96
97 mailView = new QListView( view ); 97 mailView = new QListView( view );
98 mailView->addColumn( tr( "" ) ); 98 mailView->addColumn( tr( "" ) );
99 mailView->addColumn( tr( "Subject" ),QListView::Manual ); 99 mailView->addColumn( tr( "Subject" ),QListView::Manual );
100 mailView->addColumn( tr( "Sender" ),QListView::Manual ); 100 mailView->addColumn( tr( "Sender" ),QListView::Manual );
101 mailView->addColumn( tr( "Size" ),QListView::Manual); 101 mailView->addColumn( tr( "Size" ),QListView::Manual);
102 mailView->addColumn( tr( "Date" )); 102 mailView->addColumn( tr( "Date" ));
103 mailView->setAllColumnsShowFocus(true); 103 mailView->setAllColumnsShowFocus(true);
104 mailView->setSorting(-1); 104 mailView->setSorting(-1);
105 105
106 statusWidget = new StatusWidget( wrapperBox ); 106 statusWidget = new StatusWidget( wrapperBox );
107 statusWidget->hide(); 107 statusWidget->hide();
108 108
109 layout->addWidget( mailView ); 109 layout->addWidget( mailView );
110 layout->setStretchFactor( folderView, 1 ); 110 layout->setStretchFactor( folderView, 1 );
111 layout->setStretchFactor( mailView, 2 ); 111 layout->setStretchFactor( mailView, 2 );
112 112
113 slotAdjustLayout(); 113 slotAdjustLayout();
114 114
115 QPEApplication::setStylusOperation( mailView->viewport(),QPEApplication::RightOnHold); 115 QPEApplication::setStylusOperation( mailView->viewport(),QPEApplication::RightOnHold);
116 QPEApplication::setStylusOperation( folderView->viewport(),QPEApplication::RightOnHold); 116 QPEApplication::setStylusOperation( folderView->viewport(),QPEApplication::RightOnHold);
117 117
118 connect( mailView, SIGNAL( mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ),this, 118 connect( mailView, SIGNAL( mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ),this,
119 SLOT( mailLeftClicked(int,QListViewItem*,const QPoint&,int) ) ); 119 SLOT( mailLeftClicked(int,QListViewItem*,const QPoint&,int) ) );
120 connect( mailView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),this, 120 connect( mailView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),this,
121 SLOT( mailHold(int,QListViewItem*,const QPoint&,int) ) ); 121 SLOT( mailHold(int,QListViewItem*,const QPoint&,int) ) );
122 connect(folderView, SIGNAL(refreshMailview(QList<RecMail>*)),this,SLOT(refreshMailView(QList<RecMail>*))); 122 connect(folderView, SIGNAL(refreshMailview(const QValueList<RecMailP>&)),
123 this,SLOT(refreshMailView(const QValueList<RecMailP>&)));
123 connect( composeMail, SIGNAL( activated() ), SLOT( slotComposeMail() ) ); 124 connect( composeMail, SIGNAL( activated() ), SLOT( slotComposeMail() ) );
124 connect( sendQueued, SIGNAL( activated() ), SLOT( slotSendQueued() ) ); 125 connect( sendQueued, SIGNAL( activated() ), SLOT( slotSendQueued() ) );
125// connect( searchMails, SIGNAL( activated() ), SLOT( slotSearchMails() ) ); 126// connect( searchMails, SIGNAL( activated() ), SLOT( slotSearchMails() ) );
126 connect( editAccounts, SIGNAL( activated() ), SLOT( slotEditAccounts() ) ); 127 connect( editAccounts, SIGNAL( activated() ), SLOT( slotEditAccounts() ) );
127 // Added by Stefan Eilers to allow starting by addressbook.. 128 // Added by Stefan Eilers to allow starting by addressbook..
128 // copied from old mail2 129 // copied from old mail2
129#if !defined(QT_NO_COP) 130#if !defined(QT_NO_COP)
130 connect( qApp, SIGNAL( appMessage(const QCString&,const QByteArray&) ), 131 connect( qApp, SIGNAL( appMessage(const QCString&,const QByteArray&) ),
131 this, SLOT( appMessage(const QCString&,const QByteArray&) ) ); 132 this, SLOT( appMessage(const QCString&,const QByteArray&) ) );
132#endif 133#endif
133 134
134 QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) ); 135 QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) );
135} 136}
136 137
137MainWindow::~MainWindow() 138MainWindow::~MainWindow()
138{ 139{
139} 140}
140 141
141void MainWindow::appMessage(const QCString &, const QByteArray &) 142void MainWindow::appMessage(const QCString &, const QByteArray &)
142{ 143{
143 qDebug("appMessage not reached"); 144 qDebug("appMessage not reached");
144} 145}
145 146
146void MainWindow::slotAdjustLayout() { 147void MainWindow::slotAdjustLayout() {
147 148
148 QWidget *d = QApplication::desktop(); 149 QWidget *d = QApplication::desktop();
149 150
150 if ( d->width() < d->height() ) { 151 if ( d->width() < d->height() ) {
151 layout->setDirection( QBoxLayout::TopToBottom ); 152 layout->setDirection( QBoxLayout::TopToBottom );
152 } else { 153 } else {
153 layout->setDirection( QBoxLayout::LeftToRight ); 154 layout->setDirection( QBoxLayout::LeftToRight );
154 } 155 }
155} 156}
156 157
157void MainWindow::slotAdjustColumns() 158void MainWindow::slotAdjustColumns()
158{ 159{
159 bool hidden = folderView->isHidden(); 160 bool hidden = folderView->isHidden();
160 if ( hidden ) folderView->show(); 161 if ( hidden ) folderView->show();
161 folderView->setColumnWidth( 0, folderView->visibleWidth() ); 162 folderView->setColumnWidth( 0, folderView->visibleWidth() );
162 if ( hidden ) folderView->hide(); 163 if ( hidden ) folderView->hide();
163 164
164 mailView->setColumnWidth( 0, 10 ); 165 mailView->setColumnWidth( 0, 10 );
165 mailView->setColumnWidth( 1, mailView->visibleWidth() - 130 ); 166 mailView->setColumnWidth( 1, mailView->visibleWidth() - 130 );
166 mailView->setColumnWidth( 2, 80 ); 167 mailView->setColumnWidth( 2, 80 );
167 mailView->setColumnWidth( 3, 50 ); 168 mailView->setColumnWidth( 3, 50 );
168 mailView->setColumnWidth( 4, 50 ); 169 mailView->setColumnWidth( 4, 50 );
169} 170}
170 171
171void MainWindow::slotEditSettings() 172void MainWindow::slotEditSettings()
172{ 173{
173} 174}
174 175
175void MainWindow::slotShowFolders( bool ) 176void MainWindow::slotShowFolders( bool )
176{ 177{
177 qDebug( "slotShowFolders not reached" ); 178 qDebug( "slotShowFolders not reached" );
178} 179}
179 180
180void MainWindow::refreshMailView(QList<RecMail>*) 181void MainWindow::refreshMailView(const QValueList<RecMailP>&)
181{ 182{
182 qDebug( "refreshMailView not reached" ); 183 qDebug( "refreshMailView not reached" );
183} 184}
184 185
185void MainWindow::mailLeftClicked(int, QListViewItem *,const QPoint&,int ) 186void MainWindow::mailLeftClicked(int, QListViewItem *,const QPoint&,int )
186{ 187{
187 qDebug( "mailLeftClicked not reached" ); 188 qDebug( "mailLeftClicked not reached" );
188} 189}
189 190
190void MainWindow::displayMail() 191void MainWindow::displayMail()
191{ 192{
192 qDebug("displayMail not reached"); 193 qDebug("displayMail not reached");
193} 194}
194 195
195void MainWindow::slotDeleteMail() 196void MainWindow::slotDeleteMail()
196{ 197{
197 qDebug("deleteMail not reached"); 198 qDebug("deleteMail not reached");
198} 199}
199 200
200void MainWindow::mailHold(int, QListViewItem *,const QPoint&,int ) 201void MainWindow::mailHold(int, QListViewItem *,const QPoint&,int )
201{ 202{
202 qDebug("mailHold not reached"); 203 qDebug("mailHold not reached");
203} 204}
204 205
205void MainWindow::slotSendQueued() 206void MainWindow::slotSendQueued()
206{ 207{
207} 208}
208 209
209void MainWindow::slotEditAccounts() 210void MainWindow::slotEditAccounts()
210{ 211{
211} 212}
212 213
213void MainWindow::slotComposeMail() 214void MainWindow::slotComposeMail()
214{ 215{
215} 216}
diff --git a/noncore/net/mail/mainwindow.h b/noncore/net/mail/mainwindow.h
index 1ba6299..8d004c6 100644
--- a/noncore/net/mail/mainwindow.h
+++ b/noncore/net/mail/mainwindow.h
@@ -1,53 +1,56 @@
1#ifndef MAINWINDOW_H 1#ifndef MAINWINDOW_H
2#define MAINWINDOW_H 2#define MAINWINDOW_H
3 3
4#include <qmainwindow.h> 4#include <qmainwindow.h>
5#include <qlistview.h> 5#include <qlistview.h>
6#include <qaction.h> 6#include <qaction.h>
7 7
8#include <qtoolbar.h> 8#include <qtoolbar.h>
9#include <qmenubar.h> 9#include <qmenubar.h>
10 10
11#include "accountview.h" 11#include "accountview.h"
12#include "statuswidget.h" 12#include "statuswidget.h"
13 13
14#include <libmailwrapper/mailtypes.h>
15#include <opie2/osmartpointer.h>
16
14class RecMail; 17class RecMail;
15 18
16class MainWindow : public QMainWindow 19class MainWindow : public QMainWindow
17{ 20{
18 Q_OBJECT 21 Q_OBJECT
19 22
20public: 23public:
21 MainWindow( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 24 MainWindow( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
22 virtual ~MainWindow(); 25 virtual ~MainWindow();
23 26
24public slots: 27public slots:
25 virtual void slotAdjustColumns(); 28 virtual void slotAdjustColumns();
26 virtual void appMessage(const QCString &msg, const QByteArray &data); 29 virtual void appMessage(const QCString &msg, const QByteArray &data);
27 virtual void slotComposeMail(); 30 virtual void slotComposeMail();
28 31
29protected slots: 32protected slots:
30 virtual void slotSendQueued(); 33 virtual void slotSendQueued();
31 virtual void slotEditAccounts(); 34 virtual void slotEditAccounts();
32 virtual void slotShowFolders( bool show ); 35 virtual void slotShowFolders( bool show );
33 virtual void refreshMailView(QList<RecMail>*); 36 virtual void refreshMailView(const QValueList<RecMailP>&);
34 virtual void displayMail(); 37 virtual void displayMail();
35 virtual void slotDeleteMail(); 38 virtual void slotDeleteMail();
36 virtual void mailHold(int, QListViewItem *,const QPoint&,int); 39 virtual void mailHold(int, QListViewItem *,const QPoint&,int);
37 virtual void slotAdjustLayout(); 40 virtual void slotAdjustLayout();
38 virtual void slotEditSettings(); 41 virtual void slotEditSettings();
39 virtual void mailLeftClicked( int, QListViewItem *,const QPoint&,int ); 42 virtual void mailLeftClicked( int, QListViewItem *,const QPoint&,int );
40 43
41protected: 44protected:
42 QToolBar *toolBar; 45 QToolBar *toolBar;
43 StatusWidget *statusWidget; 46 StatusWidget *statusWidget;
44 QMenuBar *menuBar; 47 QMenuBar *menuBar;
45 QPopupMenu *mailMenu, *settingsMenu; 48 QPopupMenu *mailMenu, *settingsMenu;
46 QAction *composeMail, *sendQueued, *showFolders, *searchMails, *deleteMails, 49 QAction *composeMail, *sendQueued, *showFolders, *searchMails, *deleteMails,
47 *editSettings, *editAccounts, *syncFolders; 50 *editSettings, *editAccounts, *syncFolders;
48 AccountView *folderView; 51 AccountView *folderView;
49 QListView *mailView; 52 QListView *mailView;
50 QBoxLayout *layout; 53 QBoxLayout *layout;
51}; 54};
52 55
53#endif 56#endif
diff --git a/noncore/net/mail/opiemail.cpp b/noncore/net/mail/opiemail.cpp
index d95b3c9..dd305df 100644
--- a/noncore/net/mail/opiemail.cpp
+++ b/noncore/net/mail/opiemail.cpp
@@ -1,278 +1,280 @@
1 1
2#include "settingsdialog.h" 2#include "settingsdialog.h"
3#include "opiemail.h" 3#include "opiemail.h"
4#include "editaccounts.h" 4#include "editaccounts.h"
5#include "composemail.h" 5#include "composemail.h"
6#include "mailistviewitem.h" 6#include "mailistviewitem.h"
7#include "viewmail.h" 7#include "viewmail.h"
8#include "selectstore.h" 8#include "selectstore.h"
9#include "selectsmtp.h" 9#include "selectsmtp.h"
10 10
11/* OPIE */ 11/* OPIE */
12#include <libmailwrapper/smtpwrapper.h> 12#include <libmailwrapper/smtpwrapper.h>
13#include <libmailwrapper/mailtypes.h> 13#include <libmailwrapper/mailtypes.h>
14#include <libmailwrapper/abstractmail.h> 14#include <libmailwrapper/abstractmail.h>
15#include <qpe/resource.h> 15#include <qpe/resource.h>
16#include <qpe/qpeapplication.h> 16#include <qpe/qpeapplication.h>
17 17
18/* QT */ 18/* QT */
19 19
20OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags ) 20OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags )
21 : MainWindow( parent, name, WStyle_ContextHelp ) 21 : MainWindow( parent, name, WStyle_ContextHelp )
22{ 22{
23 settings = new Settings(); 23 settings = new Settings();
24 24
25 folderView->populate( settings->getAccounts() ); 25 folderView->populate( settings->getAccounts() );
26} 26}
27 27
28OpieMail::~OpieMail() 28OpieMail::~OpieMail()
29{ 29{
30 if (settings) delete settings; 30 if (settings) delete settings;
31} 31}
32 32
33void OpieMail::appMessage(const QCString &msg, const QByteArray &data) 33void OpieMail::appMessage(const QCString &msg, const QByteArray &data)
34{ 34{
35 // copied from old mail2 35 // copied from old mail2
36 if (msg == "writeMail(QString,QString)") 36 if (msg == "writeMail(QString,QString)")
37 { 37 {
38 QDataStream stream(data,IO_ReadOnly); 38 QDataStream stream(data,IO_ReadOnly);
39 QString name, email; 39 QString name, email;
40 stream >> name >> email; 40 stream >> name >> email;
41 // removing the whitespaces at beginning and end is needed! 41 // removing the whitespaces at beginning and end is needed!
42 slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace()); 42 slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace());
43 } 43 }
44 else if (msg == "newMail()") 44 else if (msg == "newMail()")
45 { 45 {
46 slotComposeMail(); 46 slotComposeMail();
47 } 47 }
48} 48}
49 49
50void OpieMail::slotwriteMail(const QString&name,const QString&email) 50void OpieMail::slotwriteMail(const QString&name,const QString&email)
51{ 51{
52 ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp ); 52 ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp );
53 if (!email.isEmpty()) 53 if (!email.isEmpty())
54 { 54 {
55 if (!name.isEmpty()) 55 if (!name.isEmpty())
56 { 56 {
57 compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">"); 57 compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">");
58 } 58 }
59 else 59 else
60 { 60 {
61 compose.setTo(email); 61 compose.setTo(email);
62 } 62 }
63 } 63 }
64 compose.slotAdjustColumns(); 64 compose.slotAdjustColumns();
65 QPEApplication::execDialog( &compose ); 65 QPEApplication::execDialog( &compose );
66} 66}
67 67
68void OpieMail::slotComposeMail() 68void OpieMail::slotComposeMail()
69{ 69{
70 qDebug( "Compose Mail" ); 70 qDebug( "Compose Mail" );
71 slotwriteMail(0l,0l); 71 slotwriteMail(0l,0l);
72} 72}
73 73
74void OpieMail::slotSendQueued() 74void OpieMail::slotSendQueued()
75{ 75{
76 qDebug( "Send Queued" ); 76 qDebug( "Send Queued" );
77 SMTPaccount *smtp = 0; 77 SMTPaccount *smtp = 0;
78 78
79 QList<Account> list = settings->getAccounts(); 79 QList<Account> list = settings->getAccounts();
80 QList<SMTPaccount> smtpList; 80 QList<SMTPaccount> smtpList;
81 smtpList.setAutoDelete(false); 81 smtpList.setAutoDelete(false);
82 Account *it; 82 Account *it;
83 for ( it = list.first(); it; it = list.next() ) 83 for ( it = list.first(); it; it = list.next() )
84 { 84 {
85 if ( it->getType() == MAILLIB::A_SMTP ) 85 if ( it->getType() == MAILLIB::A_SMTP )
86 { 86 {
87 smtp = static_cast<SMTPaccount *>(it); 87 smtp = static_cast<SMTPaccount *>(it);
88 smtpList.append(smtp); 88 smtpList.append(smtp);
89 } 89 }
90 } 90 }
91 if (smtpList.count()==0) 91 if (smtpList.count()==0)
92 { 92 {
93 QMessageBox::information(0,tr("Info"),tr("Define a smtp account first")); 93 QMessageBox::information(0,tr("Info"),tr("Define a smtp account first"));
94 return; 94 return;
95 } 95 }
96 if (smtpList.count()==1) 96 if (smtpList.count()==1)
97 { 97 {
98 smtp = smtpList.at(0); 98 smtp = smtpList.at(0);
99 } 99 }
100 else 100 else
101 { 101 {
102 smtp = 0; 102 smtp = 0;
103 selectsmtp selsmtp; 103 selectsmtp selsmtp;
104 selsmtp.setSelectionlist(&smtpList); 104 selsmtp.setSelectionlist(&smtpList);
105 if ( QPEApplication::execDialog( &selsmtp ) == QDialog::Accepted ) 105 if ( QPEApplication::execDialog( &selsmtp ) == QDialog::Accepted )
106 { 106 {
107 smtp = selsmtp.selected_smtp(); 107 smtp = selsmtp.selected_smtp();
108 } 108 }
109 } 109 }
110 if (smtp) 110 if (smtp)
111 { 111 {
112 SMTPwrapper * wrap = new SMTPwrapper(smtp); 112 SMTPwrapper * wrap = new SMTPwrapper(smtp);
113 if ( wrap->flushOutbox() ) 113 if ( wrap->flushOutbox() )
114 { 114 {
115 QMessageBox::information(0,tr("Info"),tr("Mail queue flushed")); 115 QMessageBox::information(0,tr("Info"),tr("Mail queue flushed"));
116 } 116 }
117 delete wrap; 117 delete wrap;
118 } 118 }
119} 119}
120 120
121void OpieMail::slotSearchMails() 121void OpieMail::slotSearchMails()
122{ 122{
123 qDebug( "Search Mails" ); 123 qDebug( "Search Mails" );
124} 124}
125 125
126void OpieMail::slotEditSettings() 126void OpieMail::slotEditSettings()
127{ 127{
128 SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp ); 128 SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp );
129 QPEApplication::execDialog( &settingsDialog ); 129 QPEApplication::execDialog( &settingsDialog );
130} 130}
131 131
132void OpieMail::slotEditAccounts() 132void OpieMail::slotEditAccounts()
133{ 133{
134 qDebug( "Edit Accounts" ); 134 qDebug( "Edit Accounts" );
135 EditAccounts eaDialog( settings, this, 0, true, WStyle_ContextHelp ); 135 EditAccounts eaDialog( settings, this, 0, true, WStyle_ContextHelp );
136 eaDialog.slotAdjustColumns(); 136 eaDialog.slotAdjustColumns();
137 QPEApplication::execDialog( &eaDialog ); 137 QPEApplication::execDialog( &eaDialog );
138 if ( settings ) delete settings; 138 if ( settings ) delete settings;
139 settings = new Settings(); 139 settings = new Settings();
140 140
141 folderView->populate( settings->getAccounts() ); 141 folderView->populate( settings->getAccounts() );
142} 142}
143 143
144void OpieMail::displayMail() 144void OpieMail::displayMail()
145{ 145{
146 QListViewItem*item = mailView->currentItem(); 146 QListViewItem*item = mailView->currentItem();
147 if (!item) return; 147 if (!item) return;
148 RecMail mail = ((MailListViewItem*)item)->data(); 148 RecMailP mail = ((MailListViewItem*)item)->data();
149 RecBody body = folderView->fetchBody(mail); 149 RecBody body = folderView->fetchBody(mail);
150 ViewMail readMail( this,"", Qt::WType_Modal | WStyle_ContextHelp ); 150 ViewMail readMail( this,"", Qt::WType_Modal | WStyle_ContextHelp );
151 readMail.setBody( body ); 151 readMail.setBody( body );
152 readMail.setMail( mail ); 152 readMail.setMail( mail );
153 readMail.showMaximized(); 153 readMail.showMaximized();
154 readMail.exec(); 154 readMail.exec();
155 155
156 if ( readMail.deleted ) 156 if ( readMail.deleted )
157 { 157 {
158 folderView->refreshCurrent(); 158 folderView->refreshCurrent();
159 } 159 }
160 else 160 else
161 { 161 {
162 ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "" ) ); 162 ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "" ) );
163 } 163 }
164} 164}
165 165
166void OpieMail::slotDeleteMail() 166void OpieMail::slotDeleteMail()
167{ 167{
168 if (!mailView->currentItem()) return; 168 if (!mailView->currentItem()) return;
169 RecMail mail = ((MailListViewItem*)mailView->currentItem() )->data(); 169 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data();
170 if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail.getFrom() + " - " + mail.getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 170 if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
171 { 171 {
172 mail.Wrapper()->deleteMail( mail ); 172 mail->Wrapper()->deleteMail( mail );
173 folderView->refreshCurrent(); 173 folderView->refreshCurrent();
174 } 174 }
175} 175}
176 176
177void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int ) 177void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int )
178{ 178{
179 if (!mailView->currentItem()) return; 179 if (!mailView->currentItem()) return;
180 MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType(); 180 MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType();
181 /* just the RIGHT button - or hold on pda */ 181 /* just the RIGHT button - or hold on pda */
182 if (button!=2) {return;} 182 if (button!=2) {return;}
183 qDebug("Event right/hold"); 183 qDebug("Event right/hold");
184 if (!item) return; 184 if (!item) return;
185 QPopupMenu *m = new QPopupMenu(0); 185 QPopupMenu *m = new QPopupMenu(0);
186 if (m) 186 if (m)
187 { 187 {
188 if (mailtype==MAILLIB::A_NNTP) { 188 if (mailtype==MAILLIB::A_NNTP) {
189 m->insertItem(tr("Read this posting"),this,SLOT(displayMail())); 189 m->insertItem(tr("Read this posting"),this,SLOT(displayMail()));
190// m->insertItem(tr("Copy this posting"),this,SLOT(slotMoveCopyMail())); 190// m->insertItem(tr("Copy this posting"),this,SLOT(slotMoveCopyMail()));
191 } else { 191 } else {
192 if (folderView->currentisDraft()) { 192 if (folderView->currentisDraft()) {
193 m->insertItem(tr("Edit this mail"),this,SLOT(reEditMail())); 193 m->insertItem(tr("Edit this mail"),this,SLOT(reEditMail()));
194 } 194 }
195 m->insertItem(tr("Read this mail"),this,SLOT(displayMail())); 195 m->insertItem(tr("Read this mail"),this,SLOT(displayMail()));
196 m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail())); 196 m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail()));
197 m->insertItem(tr("Copy/Move this mail"),this,SLOT(slotMoveCopyMail())); 197 m->insertItem(tr("Copy/Move this mail"),this,SLOT(slotMoveCopyMail()));
198 } 198 }
199 m->setFocus(); 199 m->setFocus();
200 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); 200 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
201 delete m; 201 delete m;
202 } 202 }
203} 203}
204 204
205void OpieMail::slotShowFolders( bool show ) 205void OpieMail::slotShowFolders( bool show )
206{ 206{
207 qDebug( "Show Folders" ); 207 qDebug( "Show Folders" );
208 if ( show && folderView->isHidden() ) 208 if ( show && folderView->isHidden() )
209 { 209 {
210 qDebug( "-> showing" ); 210 qDebug( "-> showing" );
211 folderView->show(); 211 folderView->show();
212 } 212 }
213 else if ( !show && !folderView->isHidden() ) 213 else if ( !show && !folderView->isHidden() )
214 { 214 {
215 qDebug( "-> hiding" ); 215 qDebug( "-> hiding" );
216 folderView->hide(); 216 folderView->hide();
217 } 217 }
218} 218}
219 219
220void OpieMail::refreshMailView(QList<RecMail>*list) 220void OpieMail::refreshMailView(const QValueList<RecMailP>&list)
221{ 221{
222 MailListViewItem*item = 0; 222 MailListViewItem*item = 0;
223 mailView->clear(); 223 mailView->clear();
224 for (unsigned int i = 0; i < list->count();++i) 224
225 QValueList<RecMailP>::ConstIterator it;
226 for (it = list.begin(); it != list.end();++it)
225 { 227 {
226 item = new MailListViewItem(mailView,item); 228 item = new MailListViewItem(mailView,item);
227 item->storeData(*(list->at(i))); 229 item->storeData((*it));
228 item->showEntry(); 230 item->showEntry();
229 } 231 }
230} 232}
231 233
232void OpieMail::mailLeftClicked(int button, QListViewItem *item,const QPoint&,int ) 234void OpieMail::mailLeftClicked(int button, QListViewItem *item,const QPoint&,int )
233{ 235{
234 /* just LEFT button - or tap with stylus on pda */ 236 /* just LEFT button - or tap with stylus on pda */
235 if (button!=1) return; 237 if (button!=1) return;
236 if (!item) return; 238 if (!item) return;
237 if (folderView->currentisDraft()) { 239 if (folderView->currentisDraft()) {
238 reEditMail(); 240 reEditMail();
239 } else { 241 } else {
240 displayMail(); 242 displayMail();
241 } 243 }
242} 244}
243 245
244void OpieMail::slotMoveCopyMail() 246void OpieMail::slotMoveCopyMail()
245{ 247{
246 if (!mailView->currentItem()) return; 248 if (!mailView->currentItem()) return;
247 RecMail mail = ((MailListViewItem*)mailView->currentItem() )->data(); 249 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data();
248 AbstractMail*targetMail = 0; 250 AbstractMail*targetMail = 0;
249 QString targetFolder = ""; 251 QString targetFolder = "";
250 Selectstore sels; 252 Selectstore sels;
251 folderView->setupFolderselect(&sels); 253 folderView->setupFolderselect(&sels);
252 if (!sels.exec()) return; 254 if (!sels.exec()) return;
253 targetMail = sels.currentMail(); 255 targetMail = sels.currentMail();
254 targetFolder = sels.currentFolder(); 256 targetFolder = sels.currentFolder();
255 if ( (mail.Wrapper()==targetMail && mail.getMbox()==targetFolder) || 257 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) ||
256 targetFolder.isEmpty()) 258 targetFolder.isEmpty())
257 { 259 {
258 return; 260 return;
259 } 261 }
260 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 262 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
261 { 263 {
262 QMessageBox::critical(0,tr("Error creating new Folder"), 264 QMessageBox::critical(0,tr("Error creating new Folder"),
263 tr("<center>Error while creating<br>new folder - breaking.</center>")); 265 tr("<center>Error while creating<br>new folder - breaking.</center>"));
264 return; 266 return;
265 } 267 }
266 mail.Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails()); 268 mail->Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails());
267 folderView->refreshCurrent(); 269 folderView->refreshCurrent();
268} 270}
269 271
270void OpieMail::reEditMail() 272void OpieMail::reEditMail()
271{ 273{
272 if (!mailView->currentItem()) return; 274 if (!mailView->currentItem()) return;
273 275
274 ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp ); 276 ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp );
275 compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data()); 277 compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data());
276 compose.slotAdjustColumns(); 278 compose.slotAdjustColumns();
277 QPEApplication::execDialog( &compose ); 279 QPEApplication::execDialog( &compose );
278} 280}
diff --git a/noncore/net/mail/opiemail.h b/noncore/net/mail/opiemail.h
index 88c7ea1..b93bd60 100644
--- a/noncore/net/mail/opiemail.h
+++ b/noncore/net/mail/opiemail.h
@@ -1,40 +1,42 @@
1#ifndef OPIEMAIL_H 1#ifndef OPIEMAIL_H
2#define OPIEMAIL_H 2#define OPIEMAIL_H
3 3
4#include "mainwindow.h" 4#include "mainwindow.h"
5#include <libmailwrapper/settings.h> 5#include <libmailwrapper/settings.h>
6 6
7#include <opie2/osmartpointer.h>
8#include <libmailwrapper/mailtypes.h>
7 9
8class OpieMail : public MainWindow 10class OpieMail : public MainWindow
9{ 11{
10 Q_OBJECT 12 Q_OBJECT
11 13
12public: 14public:
13 OpieMail( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 15 OpieMail( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
14 virtual ~OpieMail(); 16 virtual ~OpieMail();
15 static QString appName() { return QString::fromLatin1("opiemail"); } 17 static QString appName() { return QString::fromLatin1("opiemail"); }
16 18
17public slots: 19public slots:
18 virtual void slotwriteMail(const QString&name,const QString&email); 20 virtual void slotwriteMail(const QString&name,const QString&email);
19 virtual void slotComposeMail(); 21 virtual void slotComposeMail();
20 virtual void appMessage(const QCString &msg, const QByteArray &data); 22 virtual void appMessage(const QCString &msg, const QByteArray &data);
21protected slots: 23protected slots:
22 virtual void slotSendQueued(); 24 virtual void slotSendQueued();
23 virtual void slotSearchMails(); 25 virtual void slotSearchMails();
24 virtual void slotEditSettings(); 26 virtual void slotEditSettings();
25 virtual void slotEditAccounts(); 27 virtual void slotEditAccounts();
26 virtual void displayMail(); 28 virtual void displayMail();
27 virtual void slotDeleteMail(); 29 virtual void slotDeleteMail();
28 virtual void mailHold(int, QListViewItem *,const QPoint&,int); 30 virtual void mailHold(int, QListViewItem *,const QPoint&,int);
29 virtual void slotShowFolders( bool show ); 31 virtual void slotShowFolders( bool show );
30 virtual void refreshMailView(QList<RecMail>*); 32 virtual void refreshMailView(const QValueList<RecMailP>&);
31 virtual void mailLeftClicked( int, QListViewItem *,const QPoint&,int ); 33 virtual void mailLeftClicked( int, QListViewItem *,const QPoint&,int );
32 virtual void slotMoveCopyMail(); 34 virtual void slotMoveCopyMail();
33 virtual void reEditMail(); 35 virtual void reEditMail();
34 36
35private: 37private:
36 Settings *settings; 38 Settings *settings;
37 39
38}; 40};
39 41
40#endif 42#endif
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp
index 78652d7..894a386 100644
--- a/noncore/net/mail/viewmail.cpp
+++ b/noncore/net/mail/viewmail.cpp
@@ -1,476 +1,476 @@
1#include "composemail.h" 1#include "composemail.h"
2#include "viewmail.h" 2#include "viewmail.h"
3 3
4/* OPIE */ 4/* OPIE */
5#include <libmailwrapper/settings.h> 5#include <libmailwrapper/settings.h>
6#include <libmailwrapper/abstractmail.h> 6#include <libmailwrapper/abstractmail.h>
7#include <libmailwrapper/mailtypes.h> 7#include <libmailwrapper/mailtypes.h>
8 8
9#include <opie2/ofiledialog.h> 9#include <opie2/ofiledialog.h>
10#include <qpe/config.h> 10#include <qpe/config.h>
11#include <qpe/qpeapplication.h> 11#include <qpe/qpeapplication.h>
12 12
13/* QT */ 13/* QT */
14#include <qtextbrowser.h> 14#include <qtextbrowser.h>
15#include <qmessagebox.h> 15#include <qmessagebox.h>
16#include <qtextstream.h> 16#include <qtextstream.h>
17#include <qaction.h> 17#include <qaction.h>
18#include <qpopupmenu.h> 18#include <qpopupmenu.h>
19#include <qfile.h> 19#include <qfile.h>
20 20
21AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, 21AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file,
22 const QString&fsize,int num,const QValueList<int>&path) 22 const QString&fsize,int num,const QValueList<int>&path)
23 : QListViewItem(parent,after),_partNum(num) 23 : QListViewItem(parent,after),_partNum(num)
24{ 24{
25 _path=path; 25 _path=path;
26 setText(0, mime); 26 setText(0, mime);
27 setText(1, desc); 27 setText(1, desc);
28 setText(2, file); 28 setText(2, file);
29 setText(3, fsize); 29 setText(3, fsize);
30} 30}
31 31
32AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, 32AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file,
33 const QString&fsize,int num,const QValueList<int>&path) 33 const QString&fsize,int num,const QValueList<int>&path)
34 : QListViewItem(parent,after),_partNum(num) 34 : QListViewItem(parent,after),_partNum(num)
35{ 35{
36 _path=path; 36 _path=path;
37 setText(0, mime); 37 setText(0, mime);
38 setText(1, desc); 38 setText(1, desc);
39 setText(2, file); 39 setText(2, file);
40 setText(3, fsize); 40 setText(3, fsize);
41} 41}
42 42
43bool AttachItem::isParentof(const QValueList<int>&path) 43bool AttachItem::isParentof(const QValueList<int>&path)
44{ 44{
45 /* if not set, then no parent */ 45 /* if not set, then no parent */
46 if (path.count()==0||_path.count()==0) return false; 46 if (path.count()==0||_path.count()==0) return false;
47 /* the parent must have one digit less then a child */ 47 /* the parent must have one digit less then a child */
48 if (path.count()!=_path.count()+1) return false; 48 if (path.count()!=_path.count()+1) return false;
49 for (unsigned int i=0; i < _path.count();++i) 49 for (unsigned int i=0; i < _path.count();++i)
50 { 50 {
51 if (_path[i]!=path[i]) return false; 51 if (_path[i]!=path[i]) return false;
52 } 52 }
53 return true; 53 return true;
54} 54}
55 55
56AttachItem* ViewMail::searchParent(const QValueList<int>&path) 56AttachItem* ViewMail::searchParent(const QValueList<int>&path)
57{ 57{
58 QListViewItemIterator it( attachments ); 58 QListViewItemIterator it( attachments );
59 for ( ; it.current(); ++it ) 59 for ( ; it.current(); ++it )
60 { 60 {
61 AttachItem*ati = (AttachItem*)it.current(); 61 AttachItem*ati = (AttachItem*)it.current();
62 if (ati->isParentof(path)) return ati; 62 if (ati->isParentof(path)) return ati;
63 } 63 }
64 return 0; 64 return 0;
65} 65}
66 66
67AttachItem* ViewMail::lastChild(AttachItem*parent) 67AttachItem* ViewMail::lastChild(AttachItem*parent)
68{ 68{
69 if (!parent) return 0; 69 if (!parent) return 0;
70 AttachItem* item = (AttachItem*)parent->firstChild(); 70 AttachItem* item = (AttachItem*)parent->firstChild();
71 if (!item) return item; 71 if (!item) return item;
72 AttachItem*temp=0; 72 AttachItem*temp=0;
73 while( (temp=(AttachItem*)item->nextSibling())) 73 while( (temp=(AttachItem*)item->nextSibling()))
74 { 74 {
75 item = temp; 75 item = temp;
76 } 76 }
77 return item; 77 return item;
78} 78}
79 79
80void ViewMail::setBody( RecBody body ) 80void ViewMail::setBody( RecBody body )
81{ 81{
82 82
83 m_body = body; 83 m_body = body;
84 m_mail[2] = body.Bodytext(); 84 m_mail[2] = body.Bodytext();
85 attachbutton->setEnabled(body.Parts().count()>0); 85 attachbutton->setEnabled(body.Parts().count()>0);
86 attachments->setEnabled(body.Parts().count()>0); 86 attachments->setEnabled(body.Parts().count()>0);
87 if (body.Parts().count()==0) 87 if (body.Parts().count()==0)
88 { 88 {
89 return; 89 return;
90 } 90 }
91 AttachItem * curItem=0; 91 AttachItem * curItem=0;
92 AttachItem * parentItem = 0; 92 AttachItem * parentItem = 0;
93 QString type=body.Description().Type()+"/"+body.Description().Subtype(); 93 QString type=body.Description().Type()+"/"+body.Description().Subtype();
94 QString desc,fsize; 94 QString desc,fsize;
95 double s = body.Description().Size(); 95 double s = body.Description().Size();
96 int w; 96 int w;
97 w=0; 97 w=0;
98 98
99 while (s>1024) 99 while (s>1024)
100 { 100 {
101 s/=1024; 101 s/=1024;
102 ++w; 102 ++w;
103 if (w>=2) break; 103 if (w>=2) break;
104 } 104 }
105 105
106 QString q=""; 106 QString q="";
107 switch(w) 107 switch(w)
108 { 108 {
109 case 1: 109 case 1:
110 q="k"; 110 q="k";
111 break; 111 break;
112 case 2: 112 case 2:
113 q="M"; 113 q="M";
114 break; 114 break;
115 default: 115 default:
116 break; 116 break;
117 } 117 }
118 118
119 { 119 {
120 /* I did not found a method to make a CONTENT reset on a QTextStream 120 /* I did not found a method to make a CONTENT reset on a QTextStream
121 so I use this construct that the stream will re-constructed in each 121 so I use this construct that the stream will re-constructed in each
122 loop. To let it work, the textstream is packed into a own area of 122 loop. To let it work, the textstream is packed into a own area of
123 code is it will be destructed after finishing its small job. 123 code is it will be destructed after finishing its small job.
124 */ 124 */
125 QTextOStream o(&fsize); 125 QTextOStream o(&fsize);
126 if (w>0) o.precision(2); else o.precision(0); 126 if (w>0) o.precision(2); else o.precision(0);
127 o.setf(QTextStream::fixed); 127 o.setf(QTextStream::fixed);
128 o << s << " " << q << "Byte"; 128 o << s << " " << q << "Byte";
129 } 129 }
130 130
131 curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body.Description().Positionlist()); 131 curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body.Description().Positionlist());
132 QString filename = ""; 132 QString filename = "";
133 133
134 for (unsigned int i = 0; i < body.Parts().count();++i) 134 for (unsigned int i = 0; i < body.Parts().count();++i)
135 { 135 {
136 filename = ""; 136 filename = "";
137 type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); 137 type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype();
138 part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); 138 part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin();
139 for (;it!=body.Parts()[i].Parameters().end();++it) 139 for (;it!=body.Parts()[i].Parameters().end();++it)
140 { 140 {
141 qDebug(it.key()); 141 qDebug(it.key());
142 if (it.key().lower()=="name") 142 if (it.key().lower()=="name")
143 { 143 {
144 filename=it.data(); 144 filename=it.data();
145 } 145 }
146 } 146 }
147 s = body.Parts()[i].Size(); 147 s = body.Parts()[i].Size();
148 w = 0; 148 w = 0;
149 while (s>1024) 149 while (s>1024)
150 { 150 {
151 s/=1024; 151 s/=1024;
152 ++w; 152 ++w;
153 if (w>=2) break; 153 if (w>=2) break;
154 } 154 }
155 switch(w) 155 switch(w)
156 { 156 {
157 case 1: 157 case 1:
158 q="k"; 158 q="k";
159 break; 159 break;
160 case 2: 160 case 2:
161 q="M"; 161 q="M";
162 break; 162 break;
163 default: 163 default:
164 q=""; 164 q="";
165 break; 165 break;
166 } 166 }
167 QTextOStream o(&fsize); 167 QTextOStream o(&fsize);
168 if (w>0) o.precision(2); else o.precision(0); 168 if (w>0) o.precision(2); else o.precision(0);
169 o.setf(QTextStream::fixed); 169 o.setf(QTextStream::fixed);
170 o << s << " " << q << "Byte"; 170 o << s << " " << q << "Byte";
171 desc = body.Parts()[i].Description(); 171 desc = body.Parts()[i].Description();
172 parentItem = searchParent(body.Parts()[i].Positionlist()); 172 parentItem = searchParent(body.Parts()[i].Positionlist());
173 if (parentItem) 173 if (parentItem)
174 { 174 {
175 AttachItem*temp = lastChild(parentItem); 175 AttachItem*temp = lastChild(parentItem);
176 if (temp) curItem = temp; 176 if (temp) curItem = temp;
177 curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist()); 177 curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist());
178 attachments->setRootIsDecorated(true); 178 attachments->setRootIsDecorated(true);
179 curItem = parentItem; 179 curItem = parentItem;
180 } 180 }
181 else 181 else
182 { 182 {
183 curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist()); 183 curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist());
184 } 184 }
185 } 185 }
186} 186}
187 187
188 188
189void ViewMail::slotShowHtml( bool state ) 189void ViewMail::slotShowHtml( bool state )
190{ 190{
191 m_showHtml = state; 191 m_showHtml = state;
192 setText(); 192 setText();
193} 193}
194 194
195void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) 195void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int )
196{ 196{
197 if (!item ) 197 if (!item )
198 return; 198 return;
199 199
200 if ( ( ( AttachItem* )item )->Partnumber() == -1 ) 200 if ( ( ( AttachItem* )item )->Partnumber() == -1 )
201 { 201 {
202 setText(); 202 setText();
203 return; 203 return;
204 } 204 }
205 QPopupMenu *menu = new QPopupMenu(); 205 QPopupMenu *menu = new QPopupMenu();
206 int ret=0; 206 int ret=0;
207 207
208 if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) 208 if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" )
209 { 209 {
210 menu->insertItem( tr( "Show Text" ), 1 ); 210 menu->insertItem( tr( "Show Text" ), 1 );
211 } 211 }
212 menu->insertItem( tr( "Save Attachment" ), 0 ); 212 menu->insertItem( tr( "Save Attachment" ), 0 );
213 menu->insertSeparator(1); 213 menu->insertSeparator(1);
214 214
215 ret = menu->exec( point, 0 ); 215 ret = menu->exec( point, 0 );
216 216
217 switch(ret) 217 switch(ret)
218 { 218 {
219 case 0: 219 case 0:
220 { 220 {
221 MimeTypes types; 221 MimeTypes types;
222 types.insert( "all", "*" ); 222 types.insert( "all", "*" );
223 QString str = Opie::OFileDialog::getSaveFileName( 1, 223 QString str = Opie::OFileDialog::getSaveFileName( 1,
224 "/", item->text( 2 ) , types, 0 ); 224 "/", item->text( 2 ) , types, 0 );
225 225
226 if( !str.isEmpty() ) 226 if( !str.isEmpty() )
227 { 227 {
228 encodedString*content = m_recMail.Wrapper()->fetchDecodedPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); 228 encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] );
229 if (content) 229 if (content)
230 { 230 {
231 QFile output(str); 231 QFile output(str);
232 output.open(IO_WriteOnly); 232 output.open(IO_WriteOnly);
233 output.writeBlock(content->Content(),content->Length()); 233 output.writeBlock(content->Content(),content->Length());
234 output.close(); 234 output.close();
235 delete content; 235 delete content;
236 } 236 }
237 } 237 }
238 } 238 }
239 break ; 239 break ;
240 240
241 case 1: 241 case 1:
242 if ( ( ( AttachItem* )item )->Partnumber() == -1 ) 242 if ( ( ( AttachItem* )item )->Partnumber() == -1 )
243 { 243 {
244 setText(); 244 setText();
245 } 245 }
246 else 246 else
247 { 247 {
248 if ( m_recMail.Wrapper() != 0l ) 248 if ( m_recMail->Wrapper() != 0l )
249 { // make sure that there is a wrapper , even after delete or simular actions 249 { // make sure that there is a wrapper , even after delete or simular actions
250 browser->setText( m_recMail.Wrapper()->fetchTextPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); 250 browser->setText( m_recMail->Wrapper()->fetchTextPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) );
251 } 251 }
252 } 252 }
253 break; 253 break;
254 } 254 }
255 delete menu; 255 delete menu;
256} 256}
257 257
258 258
259void ViewMail::setMail( RecMail mail ) 259void ViewMail::setMail( RecMailP mail )
260{ 260{
261 261
262 m_recMail = mail; 262 m_recMail = mail;
263 263
264 m_mail[0] = mail.getFrom(); 264 m_mail[0] = mail->getFrom();
265 m_mail[1] = mail.getSubject(); 265 m_mail[1] = mail->getSubject();
266 m_mail[3] = mail.getDate(); 266 m_mail[3] = mail->getDate();
267 m_mail[4] = mail.Msgid(); 267 m_mail[4] = mail->Msgid();
268 268
269 m_mail2[0] = mail.To(); 269 m_mail2[0] = mail->To();
270 m_mail2[1] = mail.CC(); 270 m_mail2[1] = mail->CC();
271 m_mail2[2] = mail.Bcc(); 271 m_mail2[2] = mail->Bcc();
272 272
273 setText(); 273 setText();
274} 274}
275 275
276 276
277 277
278ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) 278ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl)
279 : ViewMailBase(parent, name, fl), _inLoop(false) 279 : ViewMailBase(parent, name, fl), _inLoop(false)
280{ 280{
281 m_gotBody = false; 281 m_gotBody = false;
282 deleted = false; 282 deleted = false;
283 283
284 connect( reply, SIGNAL(activated()), SLOT(slotReply())); 284 connect( reply, SIGNAL(activated()), SLOT(slotReply()));
285 connect( forward, SIGNAL(activated()), SLOT(slotForward())); 285 connect( forward, SIGNAL(activated()), SLOT(slotForward()));
286 connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) ); 286 connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) );
287 connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) ); 287 connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) );
288 288
289 attachments->setEnabled(m_gotBody); 289 attachments->setEnabled(m_gotBody);
290 connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) ); 290 connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) );
291 291
292 readConfig(); 292 readConfig();
293 attachments->setSorting(-1); 293 attachments->setSorting(-1);
294} 294}
295 295
296void ViewMail::readConfig() 296void ViewMail::readConfig()
297{ 297{
298 Config cfg( "mail" ); 298 Config cfg( "mail" );
299 cfg.setGroup( "Settings" ); 299 cfg.setGroup( "Settings" );
300 m_showHtml = cfg.readBoolEntry( "showHtml", false ); 300 m_showHtml = cfg.readBoolEntry( "showHtml", false );
301 showHtml->setOn( m_showHtml ); 301 showHtml->setOn( m_showHtml );
302} 302}
303 303
304void ViewMail::setText() 304void ViewMail::setText()
305{ 305{
306 306
307 QString toString; 307 QString toString;
308 QString ccString; 308 QString ccString;
309 QString bccString; 309 QString bccString;
310 310
311 for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) 311 for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it )
312 { 312 {
313 toString += (*it); 313 toString += (*it);
314 } 314 }
315 for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) 315 for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it )
316 { 316 {
317 ccString += (*it); 317 ccString += (*it);
318 } 318 }
319 for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) 319 for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it )
320 { 320 {
321 bccString += (*it); 321 bccString += (*it);
322 } 322 }
323 323
324 setCaption( caption().arg( m_mail[0] ) ); 324 setCaption( caption().arg( m_mail[0] ) );
325 325
326 m_mailHtml = "<html><body>" 326 m_mailHtml = "<html><body>"
327 "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" 327 "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>"
328 "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" 328 "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>"
329 "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" 329 "</td></tr><tr bgcolor=\"#EEEEE6\"><td>"
330 "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" 330 "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>"
331 "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + 331 "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" +
332 tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" 332 tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>"
333 "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + 333 "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] +
334 "</td></tr></table><font face=fixed>"; 334 "</td></tr></table><font face=fixed>";
335 335
336 if ( !m_showHtml ) 336 if ( !m_showHtml )
337 { 337 {
338 browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); 338 browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" );
339 } 339 }
340 else 340 else
341 { 341 {
342 browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); 342 browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" );
343 } 343 }
344 // remove later in favor of a real handling 344 // remove later in favor of a real handling
345 m_gotBody = true; 345 m_gotBody = true;
346} 346}
347 347
348 348
349ViewMail::~ViewMail() 349ViewMail::~ViewMail()
350{ 350{
351 m_recMail.Wrapper()->cleanMimeCache(); 351 m_recMail->Wrapper()->cleanMimeCache();
352 hide(); 352 hide();
353} 353}
354 354
355void ViewMail::hide() 355void ViewMail::hide()
356{ 356{
357 QWidget::hide(); 357 QWidget::hide();
358 358
359 if (_inLoop) 359 if (_inLoop)
360 { 360 {
361 _inLoop = false; 361 _inLoop = false;
362 qApp->exit_loop(); 362 qApp->exit_loop();
363 363
364 } 364 }
365 365
366} 366}
367 367
368void ViewMail::exec() 368void ViewMail::exec()
369{ 369{
370 show(); 370 show();
371 371
372 if (!_inLoop) 372 if (!_inLoop)
373 { 373 {
374 _inLoop = true; 374 _inLoop = true;
375 qApp->enter_loop(); 375 qApp->enter_loop();
376 } 376 }
377 377
378} 378}
379 379
380QString ViewMail::deHtml(const QString &string) 380QString ViewMail::deHtml(const QString &string)
381{ 381{
382 QString string_ = string; 382 QString string_ = string;
383 string_.replace(QRegExp("&"), "&amp;"); 383 string_.replace(QRegExp("&"), "&amp;");
384 string_.replace(QRegExp("<"), "&lt;"); 384 string_.replace(QRegExp("<"), "&lt;");
385 string_.replace(QRegExp(">"), "&gt;"); 385 string_.replace(QRegExp(">"), "&gt;");
386 string_.replace(QRegExp("\\n"), "<br>"); 386 string_.replace(QRegExp("\\n"), "<br>");
387 return string_; 387 return string_;
388} 388}
389 389
390void ViewMail::slotReply() 390void ViewMail::slotReply()
391{ 391{
392 if (!m_gotBody) 392 if (!m_gotBody)
393 { 393 {
394 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); 394 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok"));
395 return; 395 return;
396 } 396 }
397 397
398 QString rtext; 398 QString rtext;
399 rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose 399 rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose
400 .arg( m_mail[0] ) 400 .arg( m_mail[0] )
401 .arg( m_mail[3] ); 401 .arg( m_mail[3] );
402 402
403 QString text = m_mail[2]; 403 QString text = m_mail[2];
404 QStringList lines = QStringList::split(QRegExp("\\n"), text); 404 QStringList lines = QStringList::split(QRegExp("\\n"), text);
405 QStringList::Iterator it; 405 QStringList::Iterator it;
406 for (it = lines.begin(); it != lines.end(); it++) 406 for (it = lines.begin(); it != lines.end(); it++)
407 { 407 {
408 rtext += "> " + *it + "\n"; 408 rtext += "> " + *it + "\n";
409 } 409 }
410 rtext += "\n"; 410 rtext += "\n";
411 411
412 QString prefix; 412 QString prefix;
413 if ( m_mail[1].find(QRegExp("^Re: .*$")) != -1) prefix = ""; 413 if ( m_mail[1].find(QRegExp("^Re: .*$")) != -1) prefix = "";
414 else prefix = "Re: "; // no i18n on purpose 414 else prefix = "Re: "; // no i18n on purpose
415 415
416 Settings *settings = new Settings(); 416 Settings *settings = new Settings();
417 ComposeMail composer( settings ,this, 0, true); 417 ComposeMail composer( settings ,this, 0, true);
418 if (m_recMail.Replyto().isEmpty()) { 418 if (m_recMail->Replyto().isEmpty()) {
419 composer.setTo( m_recMail.getFrom()); 419 composer.setTo( m_recMail->getFrom());
420 } else { 420 } else {
421 composer.setTo( m_recMail.Replyto()); 421 composer.setTo( m_recMail->Replyto());
422 } 422 }
423 composer.setSubject( prefix + m_mail[1] ); 423 composer.setSubject( prefix + m_mail[1] );
424 composer.setMessage( rtext ); 424 composer.setMessage( rtext );
425 composer.setInReplyTo(m_recMail.Msgid()); 425 composer.setInReplyTo(m_recMail->Msgid());
426 426
427 if ( QDialog::Accepted == QPEApplication::execDialog( &composer ) ) 427 if ( QDialog::Accepted == QPEApplication::execDialog( &composer ) )
428 { 428 {
429 m_recMail.Wrapper()->answeredMail(m_recMail); 429 m_recMail->Wrapper()->answeredMail(m_recMail);
430 } 430 }
431} 431}
432 432
433void ViewMail::slotForward() 433void ViewMail::slotForward()
434{ 434{
435 if (!m_gotBody) 435 if (!m_gotBody)
436 { 436 {
437 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); 437 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok"));
438 return; 438 return;
439 } 439 }
440 440
441 QString ftext; 441 QString ftext;
442 ftext += QString("\n----- Forwarded message from %1 -----\n\n") 442 ftext += QString("\n----- Forwarded message from %1 -----\n\n")
443 .arg( m_mail[0] ); 443 .arg( m_mail[0] );
444 if (!m_mail[3].isNull()) 444 if (!m_mail[3].isNull())
445 ftext += QString("Date: %1\n") 445 ftext += QString("Date: %1\n")
446 .arg( m_mail[3] ); 446 .arg( m_mail[3] );
447 if (!m_mail[0].isNull()) 447 if (!m_mail[0].isNull())
448 ftext += QString("From: %1\n") 448 ftext += QString("From: %1\n")
449 .arg( m_mail[0] ); 449 .arg( m_mail[0] );
450 if (!m_mail[1].isNull()) 450 if (!m_mail[1].isNull())
451 ftext += QString("Subject: %1\n") 451 ftext += QString("Subject: %1\n")
452 .arg( m_mail[1] ); 452 .arg( m_mail[1] );
453 453
454 ftext += QString("\n%1\n") 454 ftext += QString("\n%1\n")
455 .arg( m_mail[2]); 455 .arg( m_mail[2]);
456 456
457 ftext += QString("----- End forwarded message -----\n"); 457 ftext += QString("----- End forwarded message -----\n");
458 458
459 Settings *settings = new Settings(); 459 Settings *settings = new Settings();
460 ComposeMail composer( settings ,this, 0, true); 460 ComposeMail composer( settings ,this, 0, true);
461 composer.setSubject( "Fwd: " + m_mail[1] ); 461 composer.setSubject( "Fwd: " + m_mail[1] );
462 composer.setMessage( ftext ); 462 composer.setMessage( ftext );
463 if ( QDialog::Accepted == QPEApplication::execDialog( &composer )) 463 if ( QDialog::Accepted == QPEApplication::execDialog( &composer ))
464 { 464 {
465 } 465 }
466} 466}
467 467
468void ViewMail::slotDeleteMail( ) 468void ViewMail::slotDeleteMail( )
469{ 469{
470 if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 470 if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
471 { 471 {
472 m_recMail.Wrapper()->deleteMail( m_recMail ); 472 m_recMail->Wrapper()->deleteMail( m_recMail );
473 hide(); 473 hide();
474 deleted = true; 474 deleted = true;
475 } 475 }
476} 476}
diff --git a/noncore/net/mail/viewmail.h b/noncore/net/mail/viewmail.h
index abbd5b3..6875e3c 100644
--- a/noncore/net/mail/viewmail.h
+++ b/noncore/net/mail/viewmail.h
@@ -1,73 +1,73 @@
1#ifndef VIEWMAIL_H 1#ifndef VIEWMAIL_H
2#define VIEWMAIL_H 2#define VIEWMAIL_H
3 3
4#include <qlistview.h> 4#include <qlistview.h>
5#include <qmap.h> 5#include <qmap.h>
6#include <qstringlist.h> 6#include <qstringlist.h>
7#include <qvaluelist.h> 7#include <qvaluelist.h>
8 8
9#include "viewmailbase.h" 9#include "viewmailbase.h"
10#include <libmailwrapper/mailtypes.h> 10#include <libmailwrapper/mailtypes.h>
11 11
12 12
13class AttachItem : public QListViewItem 13class AttachItem : public QListViewItem
14{ 14{
15public: 15public:
16 AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, 16 AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file,
17 const QString&fsize,int num,const QValueList<int>&path); 17 const QString&fsize,int num,const QValueList<int>&path);
18 AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, 18 AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file,
19 const QString&fsize,int num,const QValueList<int>&path); 19 const QString&fsize,int num,const QValueList<int>&path);
20 int Partnumber() { return _partNum; } 20 int Partnumber() { return _partNum; }
21 bool isParentof(const QValueList<int>&path); 21 bool isParentof(const QValueList<int>&path);
22 22
23private: 23private:
24 int _partNum; 24 int _partNum;
25 /* needed for a better display of attachments */ 25 /* needed for a better display of attachments */
26 QValueList<int> _path; 26 QValueList<int> _path;
27}; 27};
28 28
29class ViewMail : public ViewMailBase 29class ViewMail : public ViewMailBase
30{ 30{
31 Q_OBJECT 31 Q_OBJECT
32 32
33public: 33public:
34 ViewMail( QWidget *parent = 0, const char *name = 0, WFlags fl = 0); 34 ViewMail( QWidget *parent = 0, const char *name = 0, WFlags fl = 0);
35 ~ViewMail(); 35 ~ViewMail();
36 36
37 void hide(); 37 void hide();
38 void exec(); 38 void exec();
39 void setMail( RecMail mail ); 39 void setMail( RecMailP mail );
40 void setBody( RecBody body ); 40 void setBody( RecBody body );
41 bool deleted; 41 bool deleted;
42 42
43protected: 43protected:
44 QString deHtml(const QString &string); 44 QString deHtml(const QString &string);
45 AttachItem* searchParent(const QValueList<int>&path); 45 AttachItem* searchParent(const QValueList<int>&path);
46 AttachItem* lastChild(AttachItem*parent); 46 AttachItem* lastChild(AttachItem*parent);
47 47
48protected slots: 48protected slots:
49 void slotReply(); 49 void slotReply();
50 void slotForward(); 50 void slotForward();
51 void setText(); 51 void setText();
52 void slotItemClicked( QListViewItem * item , const QPoint & point, int c ); 52 void slotItemClicked( QListViewItem * item , const QPoint & point, int c );
53 void slotDeleteMail( ); 53 void slotDeleteMail( );
54 void slotShowHtml( bool ); 54 void slotShowHtml( bool );
55 55
56private: 56private:
57 void readConfig(); 57 void readConfig();
58 58
59 bool _inLoop; 59 bool _inLoop;
60 QString m_mailHtml; 60 QString m_mailHtml;
61 bool m_gotBody; 61 bool m_gotBody;
62 RecBody m_body; 62 RecBody m_body;
63 RecMail m_recMail; 63 RecMailP m_recMail;
64 bool m_showHtml; 64 bool m_showHtml;
65 65
66 // 0 from 1 subject 2 bodytext 3 date 66 // 0 from 1 subject 2 bodytext 3 date
67 QMap <int,QString> m_mail; 67 QMap <int,QString> m_mail;
68 // 0 to 1 cc 2 bcc 68 // 0 to 1 cc 2 bcc
69 QMap <int,QStringList> m_mail2; 69 QMap <int,QStringList> m_mail2;
70 70
71}; 71};
72 72
73#endif 73#endif