summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/accountview.cpp5
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.cpp7
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.h2
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp6
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.h1
5 files changed, 15 insertions, 6 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp
index 2ce89db..77fa706 100644
--- a/noncore/net/mail/accountview.cpp
+++ b/noncore/net/mail/accountview.cpp
@@ -1,669 +1,668 @@
1#include <stdlib.h>
2#include "accountview.h" 1#include "accountview.h"
3#include <libmailwrapper/mailtypes.h> 2#include <libmailwrapper/mailtypes.h>
3#include <libmailwrapper/abstractmail.h>
4#include "defines.h" 4#include "defines.h"
5#include "newmaildir.h" 5#include "newmaildir.h"
6#include <qmessagebox.h> 6#include <qmessagebox.h>
7#include <qpopupmenu.h> 7#include <qpopupmenu.h>
8 8
9/** 9/**
10 * POP3 Account stuff 10 * POP3 Account stuff
11 */ 11 */
12POP3viewItem::POP3viewItem( POP3account *a, QListView *parent ) 12POP3viewItem::POP3viewItem( POP3account *a, QListView *parent )
13 : AccountViewItem( parent ) 13 : AccountViewItem( parent )
14{ 14{
15 account = a; 15 account = a;
16 wrapper = AbstractMail::getWrapper( account ); 16 wrapper = AbstractMail::getWrapper( account );
17 setPixmap( 0, PIXMAP_POP3FOLDER ); 17 setPixmap( 0, PIXMAP_POP3FOLDER );
18 setText( 0, account->getAccountName() ); 18 setText( 0, account->getAccountName() );
19 setOpen( true ); 19 setOpen( true );
20} 20}
21 21
22POP3viewItem::~POP3viewItem() 22POP3viewItem::~POP3viewItem()
23{ 23{
24 delete wrapper; 24 delete wrapper;
25} 25}
26 26
27AbstractMail *POP3viewItem::getWrapper() 27AbstractMail *POP3viewItem::getWrapper()
28{ 28{
29 return wrapper; 29 return wrapper;
30} 30}
31 31
32void POP3viewItem::refresh( QList<RecMail> & ) 32void POP3viewItem::refresh( QList<RecMail> & )
33{ 33{
34 QList<Folder> *folders = wrapper->listFolders(); 34 QList<Folder> *folders = wrapper->listFolders();
35 QListViewItem *child = firstChild(); 35 QListViewItem *child = firstChild();
36 while ( child ) { 36 while ( child ) {
37 QListViewItem *tmp = child; 37 QListViewItem *tmp = child;
38 child = child->nextSibling(); 38 child = child->nextSibling();
39 delete tmp; 39 delete tmp;
40 } 40 }
41 Folder *it; 41 Folder *it;
42 QListViewItem*item = 0; 42 QListViewItem*item = 0;
43 for ( it = folders->first(); it; it = folders->next() ) { 43 for ( it = folders->first(); it; it = folders->next() ) {
44 item = new POP3folderItem( it, this , item ); 44 item = new POP3folderItem( it, this , item );
45 item->setSelectable(it->may_select()); 45 item->setSelectable(it->may_select());
46 } 46 }
47 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 47 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
48 folders->setAutoDelete(false); 48 folders->setAutoDelete(false);
49 delete folders; 49 delete folders;
50} 50}
51 51
52RecBody POP3viewItem::fetchBody( const RecMail &mail ) 52RecBody POP3viewItem::fetchBody( const RecMail &mail )
53{ 53{
54 qDebug( "POP3 fetchBody" ); 54 qDebug( "POP3 fetchBody" );
55 return wrapper->fetchBody( mail ); 55 return wrapper->fetchBody( mail );
56} 56}
57 57
58POP3folderItem::~POP3folderItem() 58POP3folderItem::~POP3folderItem()
59{ 59{
60 delete folder; 60 delete folder;
61} 61}
62 62
63POP3folderItem::POP3folderItem( Folder *folderInit, POP3viewItem *parent , QListViewItem*after ) 63POP3folderItem::POP3folderItem( Folder *folderInit, POP3viewItem *parent , QListViewItem*after )
64 : AccountViewItem( parent,after ) 64 : AccountViewItem( parent,after )
65{ 65{
66 folder = folderInit; 66 folder = folderInit;
67 pop3 = parent; 67 pop3 = parent;
68 if (folder->getDisplayName().lower()!="inbox") { 68 if (folder->getDisplayName().lower()!="inbox") {
69 setPixmap( 0, PIXMAP_POP3FOLDER ); 69 setPixmap( 0, PIXMAP_POP3FOLDER );
70 } else { 70 } else {
71 setPixmap( 0, PIXMAP_INBOXFOLDER); 71 setPixmap( 0, PIXMAP_INBOXFOLDER);
72 } 72 }
73 setText( 0, folder->getDisplayName() ); 73 setText( 0, folder->getDisplayName() );
74} 74}
75 75
76void POP3folderItem::refresh(QList<RecMail>&target) 76void POP3folderItem::refresh(QList<RecMail>&target)
77{ 77{
78 if (folder->may_select()) 78 if (folder->may_select())
79 pop3->getWrapper()->listMessages( folder->getName(),target ); 79 pop3->getWrapper()->listMessages( folder->getName(),target );
80} 80}
81 81
82RecBody POP3folderItem::fetchBody(const RecMail&aMail) 82RecBody POP3folderItem::fetchBody(const RecMail&aMail)
83{ 83{
84 return pop3->getWrapper()->fetchBody(aMail); 84 return pop3->getWrapper()->fetchBody(aMail);
85} 85}
86 86
87QPopupMenu * POP3folderItem::getContextMenu() 87QPopupMenu * POP3folderItem::getContextMenu()
88{ 88{
89 QPopupMenu *m = new QPopupMenu(0); 89 QPopupMenu *m = new QPopupMenu(0);
90 if (m) { 90 if (m) {
91 m->insertItem(QObject::tr("Refresh header list",contextName),0); 91 m->insertItem(QObject::tr("Refresh header list",contextName),0);
92 m->insertItem(QObject::tr("Delete all mails",contextName),1); 92 m->insertItem(QObject::tr("Delete all mails",contextName),1);
93 } 93 }
94 return m; 94 return m;
95} 95}
96 96
97void POP3folderItem::contextMenuSelected(int which) 97void POP3folderItem::contextMenuSelected(int which)
98{ 98{
99 AccountView * view = (AccountView*)listView(); 99 AccountView * view = (AccountView*)listView();
100 switch (which) { 100 switch (which) {
101 case 0: 101 case 0:
102 view->refreshCurrent(); 102 view->refreshCurrent();
103 break; 103 break;
104 case 1: 104 case 1:
105 deleteAllMail(pop3->getWrapper(),folder); 105 deleteAllMail(pop3->getWrapper(),folder);
106 break; 106 break;
107 default: 107 default:
108 break; 108 break;
109 } 109 }
110} 110}
111 111
112/** 112/**
113 * IMAP Account stuff 113 * IMAP Account stuff
114 */ 114 */
115IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent ) 115IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent )
116 : AccountViewItem( parent ) 116 : AccountViewItem( parent )
117{ 117{
118 account = a; 118 account = a;
119 wrapper = AbstractMail::getWrapper( account ); 119 wrapper = AbstractMail::getWrapper( account );
120 setPixmap( 0, PIXMAP_IMAPFOLDER ); 120 setPixmap( 0, PIXMAP_IMAPFOLDER );
121 setText( 0, account->getAccountName() ); 121 setText( 0, account->getAccountName() );
122 setOpen( true ); 122 setOpen( true );
123} 123}
124 124
125IMAPviewItem::~IMAPviewItem() 125IMAPviewItem::~IMAPviewItem()
126{ 126{
127 delete wrapper; 127 delete wrapper;
128} 128}
129 129
130AbstractMail *IMAPviewItem::getWrapper() 130AbstractMail *IMAPviewItem::getWrapper()
131{ 131{
132 return wrapper; 132 return wrapper;
133} 133}
134 134
135IMAPfolderItem*IMAPviewItem::findSubItem(const QString&path,IMAPfolderItem*start) 135IMAPfolderItem*IMAPviewItem::findSubItem(const QString&path,IMAPfolderItem*start)
136{ 136{
137 IMAPfolderItem*pitem,*sitem; 137 IMAPfolderItem*pitem,*sitem;
138 if (!start) pitem = (IMAPfolderItem*)firstChild(); 138 if (!start) pitem = (IMAPfolderItem*)firstChild();
139 else pitem = (IMAPfolderItem*)start->firstChild(); 139 else pitem = (IMAPfolderItem*)start->firstChild();
140 while (pitem) { 140 while (pitem) {
141 if (pitem->matchName(path)) { 141 if (pitem->matchName(path)) {
142 break; 142 break;
143 } 143 }
144 if (pitem->childCount()>0) { 144 if (pitem->childCount()>0) {
145 sitem = findSubItem(path,pitem); 145 sitem = findSubItem(path,pitem);
146 if (sitem) { 146 if (sitem) {
147 pitem = sitem; 147 pitem = sitem;
148 break; 148 break;
149 } 149 }
150 } 150 }
151 pitem=(IMAPfolderItem*)pitem->nextSibling(); 151 pitem=(IMAPfolderItem*)pitem->nextSibling();
152 } 152 }
153 return pitem; 153 return pitem;
154} 154}
155 155
156void IMAPviewItem::refresh(QList<RecMail>&) 156void IMAPviewItem::refresh(QList<RecMail>&)
157{ 157{
158 refreshFolders(false); 158 refreshFolders(false);
159} 159}
160 160
161void IMAPviewItem::refreshFolders(bool force) 161void IMAPviewItem::refreshFolders(bool force)
162{ 162{
163 if (childCount()>0 && force==false) return; 163 if (childCount()>0 && force==false) return;
164 QList<Folder> *folders = wrapper->listFolders(); 164 QList<Folder> *folders = wrapper->listFolders();
165 165
166 QListViewItem *child = firstChild(); 166 QListViewItem *child = firstChild();
167 while ( child ) { 167 while ( child ) {
168 QListViewItem *tmp = child; 168 QListViewItem *tmp = child;
169 child = child->nextSibling(); 169 child = child->nextSibling();
170 delete tmp; 170 delete tmp;
171 } 171 }
172 172
173 Folder *it; 173 Folder *it;
174 QListViewItem*item = 0; 174 QListViewItem*item = 0;
175 QListViewItem*titem = 0; 175 QListViewItem*titem = 0;
176 QString fname,del,search; 176 QString fname,del,search;
177 int pos; 177 int pos;
178 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 178 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
179 folders->setAutoDelete(false); 179 folders->setAutoDelete(false);
180 180
181 for ( it = folders->first(); it; it = folders->next() ) { 181 for ( it = folders->first(); it; it = folders->next() ) {
182 if (it->getDisplayName().lower()=="inbox") { 182 if (it->getDisplayName().lower()=="inbox") {
183 item = new IMAPfolderItem( it, this , item ); 183 item = new IMAPfolderItem( it, this , item );
184 folders->remove(it); 184 folders->remove(it);
185 qDebug("inbox found"); 185 qDebug("inbox found");
186 break; 186 break;
187 } 187 }
188 } 188 }
189 for ( it = folders->first(); it; it = folders->next() ) { 189 for ( it = folders->first(); it; it = folders->next() ) {
190 fname = it->getDisplayName(); 190 fname = it->getDisplayName();
191 pos = fname.findRev(it->Separator()); 191 pos = fname.findRev(it->Separator());
192 if (pos != -1) { 192 if (pos != -1) {
193 fname = fname.left(pos); 193 fname = fname.left(pos);
194 } 194 }
195 IMAPfolderItem*pitem = findSubItem(fname); 195 IMAPfolderItem*pitem = findSubItem(fname);
196 if (pitem) { 196 if (pitem) {
197 titem = item; 197 titem = item;
198 item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this); 198 item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this);
199 /* setup the short name */ 199 /* setup the short name */
200 item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1)); 200 item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1));
201 item = titem; 201 item = titem;
202 } else { 202 } else {
203 item = new IMAPfolderItem( it, this , item ); 203 item = new IMAPfolderItem( it, this , item );
204 } 204 }
205 } 205 }
206 delete folders; 206 delete folders;
207} 207}
208 208
209QPopupMenu * IMAPviewItem::getContextMenu() 209QPopupMenu * IMAPviewItem::getContextMenu()
210{ 210{
211 QPopupMenu *m = new QPopupMenu(0); 211 QPopupMenu *m = new QPopupMenu(0);
212 if (m) { 212 if (m) {
213 m->insertItem(QObject::tr("Refresh folder list",contextName),0); 213 m->insertItem(QObject::tr("Refresh folder list",contextName),0);
214 m->insertItem(QObject::tr("Create new folder",contextName),1); 214 m->insertItem(QObject::tr("Create new folder",contextName),1);
215 m->insertSeparator(); 215 m->insertSeparator();
216 m->insertItem(QObject::tr("Disconnect",contextName),2); 216 m->insertItem(QObject::tr("Disconnect",contextName),2);
217 } 217 }
218 return m; 218 return m;
219} 219}
220 220
221void IMAPviewItem::createNewFolder() 221void IMAPviewItem::createNewFolder()
222{ 222{
223 Newmdirdlg ndirdlg; 223 Newmdirdlg ndirdlg;
224 ndirdlg.showMaximized(); 224 ndirdlg.showMaximized();
225 if (ndirdlg.exec()) { 225 if (ndirdlg.exec()) {
226 QString ndir = ndirdlg.Newdir(); 226 QString ndir = ndirdlg.Newdir();
227 bool makesubs = ndirdlg.subpossible(); 227 bool makesubs = ndirdlg.subpossible();
228 QString delemiter = "/"; 228 QString delemiter = "/";
229 IMAPfolderItem*item = (IMAPfolderItem*)firstChild(); 229 IMAPfolderItem*item = (IMAPfolderItem*)firstChild();
230 if (item) { 230 if (item) {
231 delemiter = item->Delemiter(); 231 delemiter = item->Delemiter();
232 } 232 }
233 if (wrapper->createMbox(ndir,0,delemiter,makesubs)) { 233 if (wrapper->createMbox(ndir,0,delemiter,makesubs)) {
234 refreshFolders(true); 234 refreshFolders(true);
235 } 235 }
236 } 236 }
237} 237}
238 238
239void IMAPviewItem::contextMenuSelected(int id) 239void IMAPviewItem::contextMenuSelected(int id)
240{ 240{
241 qDebug("Id selected: %i",id); 241 qDebug("Id selected: %i",id);
242 switch (id) { 242 switch (id) {
243 case 0: 243 case 0:
244 refreshFolders(true); 244 refreshFolders(true);
245 break; 245 break;
246 case 1: 246 case 1:
247 createNewFolder(); 247 createNewFolder();
248 break; 248 break;
249 default: 249 default:
250 break; 250 break;
251 } 251 }
252} 252}
253 253
254RecBody IMAPviewItem::fetchBody(const RecMail&) 254RecBody IMAPviewItem::fetchBody(const RecMail&)
255{ 255{
256 return RecBody(); 256 return RecBody();
257} 257}
258 258
259IMAPfolderItem::~IMAPfolderItem() 259IMAPfolderItem::~IMAPfolderItem()
260{ 260{
261 delete folder; 261 delete folder;
262} 262}
263 263
264IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after ) 264IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after )
265 : AccountViewItem( parent , after ) 265 : AccountViewItem( parent , after )
266{ 266{
267 folder = folderInit; 267 folder = folderInit;
268 imap = parent; 268 imap = parent;
269 if (folder->getDisplayName().lower()!="inbox") { 269 if (folder->getDisplayName().lower()!="inbox") {
270 setPixmap( 0, PIXMAP_IMAPFOLDER ); 270 setPixmap( 0, PIXMAP_IMAPFOLDER );
271 } else { 271 } else {
272 setPixmap( 0, PIXMAP_INBOXFOLDER); 272 setPixmap( 0, PIXMAP_INBOXFOLDER);
273 } 273 }
274 setText( 0, folder->getDisplayName() ); 274 setText( 0, folder->getDisplayName() );
275} 275}
276 276
277IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ) 277IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master )
278 : AccountViewItem( parent,after ) 278 : AccountViewItem( parent,after )
279{ 279{
280 folder = folderInit; 280 folder = folderInit;
281 imap = master; 281 imap = master;
282 if (folder->getDisplayName().lower()!="inbox") { 282 if (folder->getDisplayName().lower()!="inbox") {
283 setPixmap( 0, PIXMAP_IMAPFOLDER ); 283 setPixmap( 0, PIXMAP_IMAPFOLDER );
284 } else { 284 } else {
285 setPixmap( 0, PIXMAP_INBOXFOLDER); 285 setPixmap( 0, PIXMAP_INBOXFOLDER);
286 } 286 }
287 setText( 0, folder->getDisplayName() ); 287 setText( 0, folder->getDisplayName() );
288} 288}
289 289
290const QString& IMAPfolderItem::Delemiter()const 290const QString& IMAPfolderItem::Delemiter()const
291{ 291{
292 return folder->Separator(); 292 return folder->Separator();
293} 293}
294 294
295bool IMAPfolderItem::matchName(const QString&name)const 295bool IMAPfolderItem::matchName(const QString&name)const
296{ 296{
297 return folder->getDisplayName()==name; 297 return folder->getDisplayName()==name;
298} 298}
299 299
300void IMAPfolderItem::refresh(QList<RecMail>&target) 300void IMAPfolderItem::refresh(QList<RecMail>&target)
301{ 301{
302 if (folder->may_select()) { 302 if (folder->may_select()) {
303 imap->getWrapper()->listMessages( folder->getName(),target ); 303 imap->getWrapper()->listMessages( folder->getName(),target );
304 } else { 304 } else {
305 target.clear(); 305 target.clear();
306 } 306 }
307} 307}
308 308
309RecBody IMAPfolderItem::fetchBody(const RecMail&aMail) 309RecBody IMAPfolderItem::fetchBody(const RecMail&aMail)
310{ 310{
311 return imap->getWrapper()->fetchBody(aMail); 311 return imap->getWrapper()->fetchBody(aMail);
312} 312}
313 313
314QPopupMenu * IMAPfolderItem::getContextMenu() 314QPopupMenu * IMAPfolderItem::getContextMenu()
315{ 315{
316 QPopupMenu *m = new QPopupMenu(0); 316 QPopupMenu *m = new QPopupMenu(0);
317 if (m) { 317 if (m) {
318 if (folder->may_select()) { 318 if (folder->may_select()) {
319 m->insertItem(QObject::tr("Refresh header list",contextName),0); 319 m->insertItem(QObject::tr("Refresh header list",contextName),0);
320 m->insertItem(QObject::tr("Delete all mails",contextName),1); 320 m->insertItem(QObject::tr("Delete all mails",contextName),1);
321 } 321 }
322 if (folder->no_inferior()==false) { 322 if (folder->no_inferior()==false) {
323 m->insertItem(QObject::tr("Create new subfolder",contextName),2); 323 m->insertItem(QObject::tr("Create new subfolder",contextName),2);
324 } 324 }
325 if (folder->getDisplayName().lower()!="inbox") { 325 if (folder->getDisplayName().lower()!="inbox") {
326 m->insertItem(QObject::tr("Delete folder",contextName),3); 326 m->insertItem(QObject::tr("Delete folder",contextName),3);
327 } 327 }
328 } 328 }
329 return m; 329 return m;
330} 330}
331 331
332void IMAPfolderItem::createNewFolder() 332void IMAPfolderItem::createNewFolder()
333{ 333{
334 Newmdirdlg ndirdlg; 334 Newmdirdlg ndirdlg;
335 ndirdlg.showMaximized(); 335 ndirdlg.showMaximized();
336 if (ndirdlg.exec()) { 336 if (ndirdlg.exec()) {
337 QString ndir = ndirdlg.Newdir(); 337 QString ndir = ndirdlg.Newdir();
338 bool makesubs = ndirdlg.subpossible(); 338 bool makesubs = ndirdlg.subpossible();
339 QString delemiter = Delemiter(); 339 QString delemiter = Delemiter();
340 if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) { 340 if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) {
341 imap->refreshFolders(true); 341 imap->refreshFolders(true);
342 } 342 }
343 } 343 }
344} 344}
345 345
346void IMAPfolderItem::deleteFolder() 346void IMAPfolderItem::deleteFolder()
347{ 347{
348 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), 348 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
349 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), 349 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()),
350 QObject::tr("Yes",contextName), 350 QObject::tr("Yes",contextName),
351 QObject::tr("No",contextName),QString::null,1,1); 351 QObject::tr("No",contextName),QString::null,1,1);
352 qDebug("Auswahl: %i",yesno); 352 qDebug("Auswahl: %i",yesno);
353 if (yesno == 0) { 353 if (yesno == 0) {
354 if (imap->getWrapper()->deleteMbox(folder)) { 354 if (imap->getWrapper()->deleteMbox(folder)) {
355 QListView*v=listView(); 355 QListView*v=listView();
356 IMAPviewItem * box = imap; 356 IMAPviewItem * box = imap;
357 /* be carefull - after that this object is destroyd so don't use 357 /* be carefull - after that this object is destroyd so don't use
358 * any member of it after that call!!*/ 358 * any member of it after that call!!*/
359 imap->refreshFolders(true); 359 imap->refreshFolders(true);
360 if (v) { 360 if (v) {
361 v->setSelected(box,true); 361 v->setSelected(box,true);
362 } 362 }
363 } 363 }
364 } 364 }
365} 365}
366 366
367void IMAPfolderItem::contextMenuSelected(int id) 367void IMAPfolderItem::contextMenuSelected(int id)
368{ 368{
369 qDebug("Selected id: %i",id); 369 qDebug("Selected id: %i",id);
370 AccountView * view = (AccountView*)listView(); 370 AccountView * view = (AccountView*)listView();
371 switch(id) { 371 switch(id) {
372 case 0: 372 case 0:
373 view->refreshCurrent(); 373 view->refreshCurrent();
374 break; 374 break;
375 case 1: 375 case 1:
376 deleteAllMail(imap->getWrapper(),folder); 376 deleteAllMail(imap->getWrapper(),folder);
377 break; 377 break;
378 case 2: 378 case 2:
379 createNewFolder(); 379 createNewFolder();
380 break; 380 break;
381 case 3: 381 case 3:
382 deleteFolder(); 382 deleteFolder();
383 break; 383 break;
384 default: 384 default:
385 break; 385 break;
386 } 386 }
387} 387}
388 388
389/** 389/**
390 * Generic stuff 390 * Generic stuff
391 */ 391 */
392 392
393const QString AccountViewItem::contextName="AccountViewItem"; 393const QString AccountViewItem::contextName="AccountViewItem";
394 394
395void AccountViewItem::deleteAllMail(AbstractMail*wrapper,Folder*folder) 395void AccountViewItem::deleteAllMail(AbstractMail*wrapper,Folder*folder)
396{ 396{
397 if (!wrapper) return; 397 if (!wrapper) return;
398 QString fname=""; 398 QString fname="";
399 if (folder) fname = folder->getDisplayName(); 399 if (folder) fname = folder->getDisplayName();
400 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName), 400 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName),
401 QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName). 401 QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName).
402 arg(fname), 402 arg(fname),
403 QObject::tr("Yes",contextName), 403 QObject::tr("Yes",contextName),
404 QObject::tr("No",contextName),QString::null,1,1); 404 QObject::tr("No",contextName),QString::null,1,1);
405 qDebug("Auswahl: %i",yesno); 405 qDebug("Auswahl: %i",yesno);
406 if (yesno == 0) { 406 if (yesno == 0) {
407 if (wrapper->deleteAllMail(folder)) { 407 if (wrapper->deleteAllMail(folder)) {
408 AccountView * view = (AccountView*)listView(); 408 AccountView * view = (AccountView*)listView();
409 if (view) view->refreshCurrent(); 409 if (view) view->refreshCurrent();
410 } 410 }
411 } 411 }
412} 412}
413 413
414AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) 414AccountView::AccountView( QWidget *parent, const char *name, WFlags flags )
415 : QListView( parent, name, flags ) 415 : QListView( parent, name, flags )
416{ 416{
417 connect( this, SIGNAL( selectionChanged( QListViewItem * ) ), 417 connect( this, SIGNAL( selectionChanged( QListViewItem * ) ),
418 SLOT( refresh( QListViewItem * ) ) ); 418 SLOT( refresh( QListViewItem * ) ) );
419 connect( this, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this, 419 connect( this, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this,
420 SLOT( slotHold( int, QListViewItem *,const QPoint&,int ) ) ); 420 SLOT( slotHold( int, QListViewItem *,const QPoint&,int ) ) );
421 421
422 setSorting(0); 422 setSorting(0);
423} 423}
424 424
425void AccountView::slotContextMenu(int id) 425void AccountView::slotContextMenu(int id)
426{ 426{
427 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); 427 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem());
428 if (!view) return; 428 if (!view) return;
429 view->contextMenuSelected(id); 429 view->contextMenuSelected(id);
430} 430}
431 431
432void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int) 432void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int)
433{ 433{
434 if (button==1) {return;} 434 if (button==1) {return;}
435 if (!item) return; 435 if (!item) return;
436 AccountViewItem *view = static_cast<AccountViewItem *>(item); 436 AccountViewItem *view = static_cast<AccountViewItem *>(item);
437 QPopupMenu*m = view->getContextMenu(); 437 QPopupMenu*m = view->getContextMenu();
438 if (!m) return; 438 if (!m) return;
439 connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int))); 439 connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int)));
440 m->setFocus(); 440 m->setFocus();
441 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); 441 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
442 delete m; 442 delete m;
443} 443}
444 444
445void AccountView::populate( QList<Account> list ) 445void AccountView::populate( QList<Account> list )
446{ 446{
447 clear(); 447 clear();
448 448
449 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); 449 (void) new MBOXviewItem(AbstractMail::defaultLocalfolder(),this);
450 (void) new MBOXviewItem(localfolders,this);
451 450
452 Account *it; 451 Account *it;
453 for ( it = list.first(); it; it = list.next() ) { 452 for ( it = list.first(); it; it = list.next() ) {
454 if ( it->getType().compare( "IMAP" ) == 0 ) { 453 if ( it->getType().compare( "IMAP" ) == 0 ) {
455 IMAPaccount *imap = static_cast<IMAPaccount *>(it); 454 IMAPaccount *imap = static_cast<IMAPaccount *>(it);
456 qDebug( "added IMAP " + imap->getAccountName() ); 455 qDebug( "added IMAP " + imap->getAccountName() );
457 (void) new IMAPviewItem( imap, this ); 456 (void) new IMAPviewItem( imap, this );
458 } else if ( it->getType().compare( "POP3" ) == 0 ) { 457 } else if ( it->getType().compare( "POP3" ) == 0 ) {
459 POP3account *pop3 = static_cast<POP3account *>(it); 458 POP3account *pop3 = static_cast<POP3account *>(it);
460 qDebug( "added POP3 " + pop3->getAccountName() ); 459 qDebug( "added POP3 " + pop3->getAccountName() );
461 (void) new POP3viewItem( pop3, this ); 460 (void) new POP3viewItem( pop3, this );
462 } 461 }
463 } 462 }
464} 463}
465 464
466void AccountView::refresh(QListViewItem *item) { 465void AccountView::refresh(QListViewItem *item) {
467 466
468 qDebug("AccountView refresh..."); 467 qDebug("AccountView refresh...");
469 if ( item ) { 468 if ( item ) {
470 m_currentItem = item; 469 m_currentItem = item;
471 QList<RecMail> headerlist; 470 QList<RecMail> headerlist;
472 headerlist.setAutoDelete(true); 471 headerlist.setAutoDelete(true);
473 AccountViewItem *view = static_cast<AccountViewItem *>(item); 472 AccountViewItem *view = static_cast<AccountViewItem *>(item);
474 view->refresh(headerlist); 473 view->refresh(headerlist);
475 emit refreshMailview(&headerlist); 474 emit refreshMailview(&headerlist);
476 } 475 }
477} 476}
478 477
479void AccountView::refreshCurrent() 478void AccountView::refreshCurrent()
480{ 479{
481 m_currentItem = currentItem(); 480 m_currentItem = currentItem();
482 if ( !m_currentItem ) return; 481 if ( !m_currentItem ) return;
483 QList<RecMail> headerlist; 482 QList<RecMail> headerlist;
484 headerlist.setAutoDelete(true); 483 headerlist.setAutoDelete(true);
485 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); 484 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem);
486 view->refresh(headerlist); 485 view->refresh(headerlist);
487 emit refreshMailview(&headerlist); 486 emit refreshMailview(&headerlist);
488} 487}
489 488
490void AccountView::refreshAll() 489void AccountView::refreshAll()
491{ 490{
492 491
493} 492}
494 493
495RecBody AccountView::fetchBody(const RecMail&aMail) 494RecBody AccountView::fetchBody(const RecMail&aMail)
496{ 495{
497 QListViewItem*item = selectedItem (); 496 QListViewItem*item = selectedItem ();
498 if (!item) return RecBody(); 497 if (!item) return RecBody();
499 AccountViewItem *view = static_cast<AccountViewItem *>(item); 498 AccountViewItem *view = static_cast<AccountViewItem *>(item);
500 return view->fetchBody(aMail); 499 return view->fetchBody(aMail);
501} 500}
502 501
503/** 502/**
504 * MBOX Account stuff 503 * MBOX Account stuff
505 */ 504 */
506 505
507MBOXviewItem::MBOXviewItem( const QString&aPath, QListView *parent ) 506MBOXviewItem::MBOXviewItem( const QString&aPath, QListView *parent )
508 : AccountViewItem( parent ) 507 : AccountViewItem( parent )
509{ 508{
510 m_Path = aPath; 509 m_Path = aPath;
511 wrapper = AbstractMail::getWrapper( m_Path ); 510 wrapper = AbstractMail::getWrapper( m_Path );
512 setPixmap( 0, PIXMAP_LOCALFOLDER ); 511 setPixmap( 0, PIXMAP_LOCALFOLDER );
513 setText( 0, " Local Folders" ); 512 setText( 0, " Local Folders" );
514 setOpen( true ); 513 setOpen( true );
515} 514}
516 515
517MBOXviewItem::~MBOXviewItem() 516MBOXviewItem::~MBOXviewItem()
518{ 517{
519 delete wrapper; 518 delete wrapper;
520} 519}
521 520
522AbstractMail *MBOXviewItem::getWrapper() 521AbstractMail *MBOXviewItem::getWrapper()
523{ 522{
524 return wrapper; 523 return wrapper;
525} 524}
526 525
527void MBOXviewItem::refresh( QList<RecMail> & ) 526void MBOXviewItem::refresh( QList<RecMail> & )
528{ 527{
529 refresh(false); 528 refresh(false);
530} 529}
531 530
532void MBOXviewItem::refresh(bool force) 531void MBOXviewItem::refresh(bool force)
533{ 532{
534 if (childCount()>0 && force==false) return; 533 if (childCount()>0 && force==false) return;
535 QList<Folder> *folders = wrapper->listFolders(); 534 QList<Folder> *folders = wrapper->listFolders();
536 QListViewItem *child = firstChild(); 535 QListViewItem *child = firstChild();
537 while ( child ) { 536 while ( child ) {
538 QListViewItem *tmp = child; 537 QListViewItem *tmp = child;
539 child = child->nextSibling(); 538 child = child->nextSibling();
540 delete tmp; 539 delete tmp;
541 } 540 }
542 Folder *it; 541 Folder *it;
543 QListViewItem*item = 0; 542 QListViewItem*item = 0;
544 for ( it = folders->first(); it; it = folders->next() ) { 543 for ( it = folders->first(); it; it = folders->next() ) {
545 item = new MBOXfolderItem( it, this , item ); 544 item = new MBOXfolderItem( it, this , item );
546 item->setSelectable(it->may_select()); 545 item->setSelectable(it->may_select());
547 } 546 }
548 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 547 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
549 folders->setAutoDelete(false); 548 folders->setAutoDelete(false);
550 delete folders; 549 delete folders;
551} 550}
552 551
553RecBody MBOXviewItem::fetchBody( const RecMail &mail ) 552RecBody MBOXviewItem::fetchBody( const RecMail &mail )
554{ 553{
555 qDebug( "MBOX fetchBody" ); 554 qDebug( "MBOX fetchBody" );
556 return wrapper->fetchBody( mail ); 555 return wrapper->fetchBody( mail );
557} 556}
558 557
559QPopupMenu * MBOXviewItem::getContextMenu() 558QPopupMenu * MBOXviewItem::getContextMenu()
560{ 559{
561 QPopupMenu *m = new QPopupMenu(0); 560 QPopupMenu *m = new QPopupMenu(0);
562 if (m) { 561 if (m) {
563 m->insertItem(QObject::tr("Refresh folder list",contextName),0); 562 m->insertItem(QObject::tr("Refresh folder list",contextName),0);
564 m->insertItem(QObject::tr("Create new folder",contextName),1); 563 m->insertItem(QObject::tr("Create new folder",contextName),1);
565 } 564 }
566 return m; 565 return m;
567} 566}
568 567
569void MBOXviewItem::createFolder() 568void MBOXviewItem::createFolder()
570{ 569{
571 Newmdirdlg ndirdlg(0,0,true); 570 Newmdirdlg ndirdlg(0,0,true);
572 ndirdlg.showMaximized(); 571 ndirdlg.showMaximized();
573 if (ndirdlg.exec()) { 572 if (ndirdlg.exec()) {
574 QString ndir = ndirdlg.Newdir(); 573 QString ndir = ndirdlg.Newdir();
575 if (wrapper->createMbox(ndir)) { 574 if (wrapper->createMbox(ndir)) {
576 refresh(true); 575 refresh(true);
577 } 576 }
578 } 577 }
579} 578}
580 579
581void MBOXviewItem::contextMenuSelected(int which) 580void MBOXviewItem::contextMenuSelected(int which)
582{ 581{
583 switch (which) { 582 switch (which) {
584 case 0: 583 case 0:
585 refresh(true); 584 refresh(true);
586 break; 585 break;
587 case 1: 586 case 1:
588 createFolder(); 587 createFolder();
589 break; 588 break;
590 default: 589 default:
591 break; 590 break;
592 } 591 }
593} 592}
594 593
595MBOXfolderItem::~MBOXfolderItem() 594MBOXfolderItem::~MBOXfolderItem()
596{ 595{
597 delete folder; 596 delete folder;
598} 597}
599 598
600MBOXfolderItem::MBOXfolderItem( Folder *folderInit, MBOXviewItem *parent , QListViewItem*after ) 599MBOXfolderItem::MBOXfolderItem( Folder *folderInit, MBOXviewItem *parent , QListViewItem*after )
601 : AccountViewItem( parent,after ) 600 : AccountViewItem( parent,after )
602{ 601{
603 folder = folderInit; 602 folder = folderInit;
604 mbox = parent; 603 mbox = parent;
605 if (folder->getDisplayName().lower() == "outgoing") { 604 if (folder->getDisplayName().lower() == "outgoing") {
606 setPixmap( 0, PIXMAP_OUTBOXFOLDER ); 605 setPixmap( 0, PIXMAP_OUTBOXFOLDER );
607 } else if (folder->getDisplayName().lower() == "inbox") { 606 } else if (folder->getDisplayName().lower() == "inbox") {
608 setPixmap( 0, PIXMAP_INBOXFOLDER); 607 setPixmap( 0, PIXMAP_INBOXFOLDER);
609 } else { 608 } else {
610 setPixmap( 0, PIXMAP_MBOXFOLDER ); 609 setPixmap( 0, PIXMAP_MBOXFOLDER );
611 } 610 }
612 setText( 0, folder->getDisplayName() ); 611 setText( 0, folder->getDisplayName() );
613} 612}
614 613
615void MBOXfolderItem::refresh(QList<RecMail>&target) 614void MBOXfolderItem::refresh(QList<RecMail>&target)
616{ 615{
617 if (folder->may_select()) 616 if (folder->may_select())
618 mbox->getWrapper()->listMessages( folder->getName(),target ); 617 mbox->getWrapper()->listMessages( folder->getName(),target );
619} 618}
620 619
621RecBody MBOXfolderItem::fetchBody(const RecMail&aMail) 620RecBody MBOXfolderItem::fetchBody(const RecMail&aMail)
622{ 621{
623 return mbox->getWrapper()->fetchBody(aMail); 622 return mbox->getWrapper()->fetchBody(aMail);
624} 623}
625 624
626void MBOXfolderItem::deleteFolder() 625void MBOXfolderItem::deleteFolder()
627{ 626{
628 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), 627 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
629 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), 628 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()),
630 QObject::tr("Yes",contextName), 629 QObject::tr("Yes",contextName),
631 QObject::tr("No",contextName),QString::null,1,1); 630 QObject::tr("No",contextName),QString::null,1,1);
632 qDebug("Auswahl: %i",yesno); 631 qDebug("Auswahl: %i",yesno);
633 if (yesno == 0) { 632 if (yesno == 0) {
634 if (mbox->getWrapper()->deleteMbox(folder)) { 633 if (mbox->getWrapper()->deleteMbox(folder)) {
635 QListView*v=listView(); 634 QListView*v=listView();
636 MBOXviewItem * box = mbox; 635 MBOXviewItem * box = mbox;
637 /* be carefull - after that this object is destroyd so don't use 636 /* be carefull - after that this object is destroyd so don't use
638 * any member of it after that call!!*/ 637 * any member of it after that call!!*/
639 mbox->refresh(true); 638 mbox->refresh(true);
640 if (v) { 639 if (v) {
641 v->setSelected(box,true); 640 v->setSelected(box,true);
642 } 641 }
643 } 642 }
644 } 643 }
645} 644}
646 645
647QPopupMenu * MBOXfolderItem::getContextMenu() 646QPopupMenu * MBOXfolderItem::getContextMenu()
648{ 647{
649 QPopupMenu *m = new QPopupMenu(0); 648 QPopupMenu *m = new QPopupMenu(0);
650 if (m) { 649 if (m) {
651 m->insertItem(QObject::tr("Delete all mails",contextName),0); 650 m->insertItem(QObject::tr("Delete all mails",contextName),0);
652 m->insertItem(QObject::tr("Delete folder",contextName),1); 651 m->insertItem(QObject::tr("Delete folder",contextName),1);
653 } 652 }
654 return m; 653 return m;
655} 654}
656 655
657void MBOXfolderItem::contextMenuSelected(int which) 656void MBOXfolderItem::contextMenuSelected(int which)
658{ 657{
659 switch(which) { 658 switch(which) {
660 case 0: 659 case 0:
661 deleteAllMail(mbox->getWrapper(),folder); 660 deleteAllMail(mbox->getWrapper(),folder);
662 break; 661 break;
663 case 1: 662 case 1:
664 deleteFolder(); 663 deleteFolder();
665 break; 664 break;
666 default: 665 default:
667 break; 666 break;
668 } 667 }
669} 668}
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp
index f303d72..80d0b52 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.cpp
+++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp
@@ -1,94 +1,101 @@
1#include "abstractmail.h" 1#include "abstractmail.h"
2#include "imapwrapper.h" 2#include "imapwrapper.h"
3#include "pop3wrapper.h" 3#include "pop3wrapper.h"
4#include "mboxwrapper.h" 4#include "mboxwrapper.h"
5#include "mailtypes.h" 5#include "mailtypes.h"
6 6
7#include <qstring.h> 7#include <qstring.h>
8#include <qfile.h> 8#include <qfile.h>
9#include <qtextstream.h> 9#include <qtextstream.h>
10#include <stdlib.h> 10#include <stdlib.h>
11#include <libetpan/mailmime_content.h> 11#include <libetpan/mailmime_content.h>
12#include <libetpan/mailmime.h> 12#include <libetpan/mailmime.h>
13 13
14AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 14AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
15{ 15{
16 return new IMAPwrapper(a); 16 return new IMAPwrapper(a);
17} 17}
18 18
19AbstractMail* AbstractMail::getWrapper(POP3account *a) 19AbstractMail* AbstractMail::getWrapper(POP3account *a)
20{ 20{
21 return new POP3wrapper(a); 21 return new POP3wrapper(a);
22} 22}
23 23
24AbstractMail* AbstractMail::getWrapper(const QString&a) 24AbstractMail* AbstractMail::getWrapper(const QString&a)
25{ 25{
26 return new MBOXwrapper(a); 26 return new MBOXwrapper(a);
27} 27}
28 28
29encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 29encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
30{ 30{
31 qDebug("Decode string start"); 31 qDebug("Decode string start");
32 char*result_text; 32 char*result_text;
33 size_t index = 0; 33 size_t index = 0;
34 /* reset for recursive use! */ 34 /* reset for recursive use! */
35 size_t target_length = 0; 35 size_t target_length = 0;
36 result_text = 0; 36 result_text = 0;
37 int mimetype = MAILMIME_MECHANISM_7BIT; 37 int mimetype = MAILMIME_MECHANISM_7BIT;
38 if (enc.lower()=="quoted-printable") { 38 if (enc.lower()=="quoted-printable") {
39 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 39 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
40 } else if (enc.lower()=="base64") { 40 } else if (enc.lower()=="base64") {
41 mimetype = MAILMIME_MECHANISM_BASE64; 41 mimetype = MAILMIME_MECHANISM_BASE64;
42 } else if (enc.lower()=="8bit") { 42 } else if (enc.lower()=="8bit") {
43 mimetype = MAILMIME_MECHANISM_8BIT; 43 mimetype = MAILMIME_MECHANISM_8BIT;
44 } else if (enc.lower()=="binary") { 44 } else if (enc.lower()=="binary") {
45 mimetype = MAILMIME_MECHANISM_BINARY; 45 mimetype = MAILMIME_MECHANISM_BINARY;
46 } 46 }
47 47
48 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 48 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
49 &result_text,&target_length); 49 &result_text,&target_length);
50 50
51 encodedString* result = new encodedString(); 51 encodedString* result = new encodedString();
52 if (err == MAILIMF_NO_ERROR) { 52 if (err == MAILIMF_NO_ERROR) {
53 result->setContent(result_text,target_length); 53 result->setContent(result_text,target_length);
54 } 54 }
55 qDebug("Decode string finished"); 55 qDebug("Decode string finished");
56 return result; 56 return result;
57} 57}
58 58
59QString AbstractMail::convert_String(const char*text) 59QString AbstractMail::convert_String(const char*text)
60{ 60{
61 size_t index = 0; 61 size_t index = 0;
62 char*res = 0; 62 char*res = 0;
63 63
64 /* attention - doesn't work with arm systems! */ 64 /* attention - doesn't work with arm systems! */
65 int err = mailmime_encoded_phrase_parse("iso-8859-1", 65 int err = mailmime_encoded_phrase_parse("iso-8859-1",
66 text, strlen(text),&index, "iso-8859-1",&res); 66 text, strlen(text),&index, "iso-8859-1",&res);
67 if (err != MAILIMF_NO_ERROR) { 67 if (err != MAILIMF_NO_ERROR) {
68 if (res) free(res); 68 if (res) free(res);
69 return QString(text); 69 return QString(text);
70 } 70 }
71 if (res) { 71 if (res) {
72 QString result(res); 72 QString result(res);
73 free(res); 73 free(res);
74 return result; 74 return result;
75 } 75 }
76 return QString(text); 76 return QString(text);
77} 77}
78 78
79/* cp & paste from launcher */ 79/* cp & paste from launcher */
80QString AbstractMail::gen_attachment_id() 80QString AbstractMail::gen_attachment_id()
81{ 81{
82 QFile file( "/proc/sys/kernel/random/uuid" ); 82 QFile file( "/proc/sys/kernel/random/uuid" );
83 if (!file.open(IO_ReadOnly ) ) 83 if (!file.open(IO_ReadOnly ) )
84 return QString::null; 84 return QString::null;
85 85
86 QTextStream stream(&file); 86 QTextStream stream(&file);
87 87
88 return "{" + stream.read().stripWhiteSpace() + "}"; 88 return "{" + stream.read().stripWhiteSpace() + "}";
89} 89}
90 90
91int AbstractMail::createMbox(const QString&,const Folder*,const QString& delemiter,bool) 91int AbstractMail::createMbox(const QString&,const Folder*,const QString& delemiter,bool)
92{ 92{
93 return 0; 93 return 0;
94} 94}
95
96QString AbstractMail::defaultLocalfolder()
97{
98 QString f = getenv( "HOME" );
99 f += "/Applications/opiemail/localmail";
100 return f;
101}
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h
index dab9e10..ca9caed 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.h
+++ b/noncore/net/mail/libmailwrapper/abstractmail.h
@@ -1,53 +1,55 @@
1#ifndef __abstract_mail_ 1#ifndef __abstract_mail_
2#define __abstract_mail_ 2#define __abstract_mail_
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include "settings.h" 5#include "settings.h"
6 6
7class RecMail; 7class RecMail;
8class RecBody; 8class RecBody;
9class RecPart; 9class RecPart;
10class IMAPwrapper; 10class IMAPwrapper;
11class POP3wrapper; 11class POP3wrapper;
12class Folder; 12class Folder;
13class encodedString; 13class encodedString;
14struct folderStat; 14struct folderStat;
15 15
16class AbstractMail:public QObject 16class AbstractMail:public QObject
17{ 17{
18 Q_OBJECT 18 Q_OBJECT
19public: 19public:
20 AbstractMail(){}; 20 AbstractMail(){};
21 virtual ~AbstractMail(){} 21 virtual ~AbstractMail(){}
22 virtual QList<Folder>* listFolders()=0; 22 virtual QList<Folder>* listFolders()=0;
23 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; 23 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0; 24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0;
25 virtual RecBody fetchBody(const RecMail&mail)=0; 25 virtual RecBody fetchBody(const RecMail&mail)=0;
26 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; 26 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
27 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; 27 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
28 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; 28 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
29 29
30 virtual void deleteMail(const RecMail&mail)=0; 30 virtual void deleteMail(const RecMail&mail)=0;
31 virtual void answeredMail(const RecMail&mail)=0; 31 virtual void answeredMail(const RecMail&mail)=0;
32 virtual void cleanMimeCache(){}; 32 virtual void cleanMimeCache(){};
33 virtual int deleteAllMail(const Folder*){return 1;} 33 virtual int deleteAllMail(const Folder*){return 1;}
34 virtual int deleteMbox(const Folder*){return 1;} 34 virtual int deleteMbox(const Folder*){return 1;}
35 35
36 /* mail box methods */ 36 /* mail box methods */
37 /* parameter is the box to create. 37 /* parameter is the box to create.
38 * if the implementing subclass has prefixes, 38 * if the implementing subclass has prefixes,
39 * them has to be appended automatic. 39 * them has to be appended automatic.
40 */ 40 */
41 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); 41 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
42 42
43 static AbstractMail* getWrapper(IMAPaccount *a); 43 static AbstractMail* getWrapper(IMAPaccount *a);
44 static AbstractMail* getWrapper(POP3account *a); 44 static AbstractMail* getWrapper(POP3account *a);
45 /* mbox only! */ 45 /* mbox only! */
46 static AbstractMail* getWrapper(const QString&a); 46 static AbstractMail* getWrapper(const QString&a);
47 47
48 static QString defaultLocalfolder();
49
48protected: 50protected:
49 static encodedString*decode_String(const encodedString*text,const QString&enc); 51 static encodedString*decode_String(const encodedString*text,const QString&enc);
50 static QString convert_String(const char*text); 52 static QString convert_String(const char*text);
51 static QString gen_attachment_id(); 53 static QString gen_attachment_id();
52}; 54};
53#endif 55#endif
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
index b9c4ff2..e054365 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
@@ -1,734 +1,734 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <sys/stat.h> 2#include <sys/stat.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <fcntl.h> 5#include <fcntl.h>
6#include <string.h> 6#include <string.h>
7#include <qdir.h> 7#include <qdir.h>
8#include <qt.h> 8#include <qt.h>
9 9
10#include <qpe/config.h> 10#include <qpe/config.h>
11#include <qpe/qcopenvelope_qws.h> 11#include <qpe/qcopenvelope_qws.h>
12 12
13#include <libetpan/libetpan.h> 13#include <libetpan/libetpan.h>
14 14
15#include "smtpwrapper.h" 15#include "smtpwrapper.h"
16#include "mailwrapper.h" 16#include "mailwrapper.h"
17#include "mboxwrapper.h" 17#include "mboxwrapper.h"
18#include "logindialog.h" 18#include "logindialog.h"
19#include "mailtypes.h" 19#include "mailtypes.h"
20//#include "defines.h" 20//#include "defines.h"
21#include "sendmailprogress.h" 21#include "sendmailprogress.h"
22 22
23#define USER_AGENT "OpieMail v0.1" 23const char* SMTPwrapper::USER_AGENT="OpieMail v0.3";
24 24
25progressMailSend*SMTPwrapper::sendProgress = 0; 25progressMailSend*SMTPwrapper::sendProgress = 0;
26 26
27SMTPwrapper::SMTPwrapper( Settings *s ) 27SMTPwrapper::SMTPwrapper( Settings *s )
28 : QObject() 28 : QObject()
29{ 29{
30 settings = s; 30 settings = s;
31 Config cfg( "mail" ); 31 Config cfg( "mail" );
32 cfg.setGroup( "Status" ); 32 cfg.setGroup( "Status" );
33 m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); 33 m_queuedMail = cfg.readNumEntry( "outgoing", 0 );
34 emit queuedMails( m_queuedMail ); 34 emit queuedMails( m_queuedMail );
35 connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) ); 35 connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) );
36} 36}
37 37
38void SMTPwrapper::emitQCop( int queued ) { 38void SMTPwrapper::emitQCop( int queued ) {
39 QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); 39 QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" );
40 env << queued; 40 env << queued;
41} 41}
42 42
43QString SMTPwrapper::mailsmtpError( int errnum ) 43QString SMTPwrapper::mailsmtpError( int errnum )
44{ 44{
45 switch ( errnum ) { 45 switch ( errnum ) {
46 case MAILSMTP_NO_ERROR: 46 case MAILSMTP_NO_ERROR:
47 return tr( "No error" ); 47 return tr( "No error" );
48 case MAILSMTP_ERROR_UNEXPECTED_CODE: 48 case MAILSMTP_ERROR_UNEXPECTED_CODE:
49 return tr( "Unexpected error code" ); 49 return tr( "Unexpected error code" );
50 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 50 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
51 return tr( "Service not available" ); 51 return tr( "Service not available" );
52 case MAILSMTP_ERROR_STREAM: 52 case MAILSMTP_ERROR_STREAM:
53 return tr( "Stream error" ); 53 return tr( "Stream error" );
54 case MAILSMTP_ERROR_HOSTNAME: 54 case MAILSMTP_ERROR_HOSTNAME:
55 return tr( "gethostname() failed" ); 55 return tr( "gethostname() failed" );
56 case MAILSMTP_ERROR_NOT_IMPLEMENTED: 56 case MAILSMTP_ERROR_NOT_IMPLEMENTED:
57 return tr( "Not implemented" ); 57 return tr( "Not implemented" );
58 case MAILSMTP_ERROR_ACTION_NOT_TAKEN: 58 case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
59 return tr( "Error, action not taken" ); 59 return tr( "Error, action not taken" );
60 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: 60 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
61 return tr( "Data exceeds storage allocation" ); 61 return tr( "Data exceeds storage allocation" );
62 case MAILSMTP_ERROR_IN_PROCESSING: 62 case MAILSMTP_ERROR_IN_PROCESSING:
63 return tr( "Error in processing" ); 63 return tr( "Error in processing" );
64 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 64 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
65 // return tr( "Insufficient system storage" ); 65 // return tr( "Insufficient system storage" );
66 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 66 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
67 return tr( "Mailbox unavailable" ); 67 return tr( "Mailbox unavailable" );
68 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: 68 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
69 return tr( "Mailbox name not allowed" ); 69 return tr( "Mailbox name not allowed" );
70 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: 70 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
71 return tr( "Bad command sequence" ); 71 return tr( "Bad command sequence" );
72 case MAILSMTP_ERROR_USER_NOT_LOCAL: 72 case MAILSMTP_ERROR_USER_NOT_LOCAL:
73 return tr( "User not local" ); 73 return tr( "User not local" );
74 case MAILSMTP_ERROR_TRANSACTION_FAILED: 74 case MAILSMTP_ERROR_TRANSACTION_FAILED:
75 return tr( "Transaction failed" ); 75 return tr( "Transaction failed" );
76 case MAILSMTP_ERROR_MEMORY: 76 case MAILSMTP_ERROR_MEMORY:
77 return tr( "Memory error" ); 77 return tr( "Memory error" );
78 case MAILSMTP_ERROR_CONNECTION_REFUSED: 78 case MAILSMTP_ERROR_CONNECTION_REFUSED:
79 return tr( "Connection refused" ); 79 return tr( "Connection refused" );
80 default: 80 default:
81 return tr( "Unknown error code" ); 81 return tr( "Unknown error code" );
82 } 82 }
83} 83}
84 84
85mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) 85mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail )
86{ 86{
87 return mailimf_mailbox_new( strdup( name.latin1() ), 87 return mailimf_mailbox_new( strdup( name.latin1() ),
88 strdup( mail.latin1() ) ); 88 strdup( mail.latin1() ) );
89} 89}
90 90
91mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) 91mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr )
92{ 92{
93 mailimf_address_list *addresses; 93 mailimf_address_list *addresses;
94 94
95 if ( addr.isEmpty() ) return NULL; 95 if ( addr.isEmpty() ) return NULL;
96 96
97 addresses = mailimf_address_list_new_empty(); 97 addresses = mailimf_address_list_new_empty();
98 98
99 bool literal_open = false; 99 bool literal_open = false;
100 unsigned int startpos = 0; 100 unsigned int startpos = 0;
101 QStringList list; 101 QStringList list;
102 QString s; 102 QString s;
103 unsigned int i = 0; 103 unsigned int i = 0;
104 for (; i < addr.length();++i) { 104 for (; i < addr.length();++i) {
105 switch (addr[i]) { 105 switch (addr[i]) {
106 case '\"': 106 case '\"':
107 literal_open = !literal_open; 107 literal_open = !literal_open;
108 break; 108 break;
109 case ',': 109 case ',':
110 if (!literal_open) { 110 if (!literal_open) {
111 s = addr.mid(startpos,i-startpos); 111 s = addr.mid(startpos,i-startpos);
112 if (!s.isEmpty()) { 112 if (!s.isEmpty()) {
113 list.append(s); 113 list.append(s);
114 qDebug("Appended %s",s.latin1()); 114 qDebug("Appended %s",s.latin1());
115 } 115 }
116 // !!!! this is a MUST BE! 116 // !!!! this is a MUST BE!
117 startpos = ++i; 117 startpos = ++i;
118 } 118 }
119 break; 119 break;
120 default: 120 default:
121 break; 121 break;
122 } 122 }
123 } 123 }
124 s = addr.mid(startpos,i-startpos); 124 s = addr.mid(startpos,i-startpos);
125 if (!s.isEmpty()) { 125 if (!s.isEmpty()) {
126 list.append(s); 126 list.append(s);
127 qDebug("Appended %s",s.latin1()); 127 qDebug("Appended %s",s.latin1());
128 } 128 }
129 QStringList::Iterator it; 129 QStringList::Iterator it;
130 for ( it = list.begin(); it != list.end(); it++ ) { 130 for ( it = list.begin(); it != list.end(); it++ ) {
131 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); 131 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() );
132 if ( err != MAILIMF_NO_ERROR ) { 132 if ( err != MAILIMF_NO_ERROR ) {
133 qDebug( "Error parsing" ); 133 qDebug( "Error parsing" );
134 qDebug( *it ); 134 qDebug( *it );
135 } else { 135 } else {
136 qDebug( "Parse success! %s",(*it).latin1()); 136 qDebug( "Parse success! %s",(*it).latin1());
137 } 137 }
138 } 138 }
139 return addresses; 139 return addresses;
140} 140}
141 141
142mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) 142mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail )
143{ 143{
144 mailimf_fields *fields; 144 mailimf_fields *fields;
145 mailimf_field *xmailer; 145 mailimf_field *xmailer;
146 mailimf_mailbox *sender=0,*fromBox=0; 146 mailimf_mailbox *sender=0,*fromBox=0;
147 mailimf_mailbox_list *from=0; 147 mailimf_mailbox_list *from=0;
148 mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; 148 mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0;
149 char *subject = strdup( mail.getSubject().latin1() ); 149 char *subject = strdup( mail.getSubject().latin1() );
150 int err; 150 int err;
151 151
152 sender = newMailbox( mail.getName(), mail.getMail() ); 152 sender = newMailbox( mail.getName(), mail.getMail() );
153 if ( sender == NULL ) goto err_free; 153 if ( sender == NULL ) goto err_free;
154 154
155 fromBox = newMailbox( mail.getName(), mail.getMail() ); 155 fromBox = newMailbox( mail.getName(), mail.getMail() );
156 if ( fromBox == NULL ) goto err_free_sender; 156 if ( fromBox == NULL ) goto err_free_sender;
157 157
158 from = mailimf_mailbox_list_new_empty(); 158 from = mailimf_mailbox_list_new_empty();
159 if ( from == NULL ) goto err_free_fromBox; 159 if ( from == NULL ) goto err_free_fromBox;
160 160
161 err = mailimf_mailbox_list_add( from, fromBox ); 161 err = mailimf_mailbox_list_add( from, fromBox );
162 if ( err != MAILIMF_NO_ERROR ) goto err_free_from; 162 if ( err != MAILIMF_NO_ERROR ) goto err_free_from;
163 163
164 to = parseAddresses( mail.getTo() ); 164 to = parseAddresses( mail.getTo() );
165 if ( to == NULL ) goto err_free_from; 165 if ( to == NULL ) goto err_free_from;
166 166
167 cc = parseAddresses( mail.getCC() ); 167 cc = parseAddresses( mail.getCC() );
168 bcc = parseAddresses( mail.getBCC() ); 168 bcc = parseAddresses( mail.getBCC() );
169 reply = parseAddresses( mail.getReply() ); 169 reply = parseAddresses( mail.getReply() );
170 170
171 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, 171 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
172 NULL, NULL, subject ); 172 NULL, NULL, subject );
173 if ( fields == NULL ) goto err_free_reply; 173 if ( fields == NULL ) goto err_free_reply;
174 174
175 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), 175 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
176 strdup( USER_AGENT ) ); 176 strdup( USER_AGENT ) );
177 if ( xmailer == NULL ) goto err_free_fields; 177 if ( xmailer == NULL ) goto err_free_fields;
178 178
179 err = mailimf_fields_add( fields, xmailer ); 179 err = mailimf_fields_add( fields, xmailer );
180 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; 180 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer;
181 181
182 return fields; // Success :) 182 return fields; // Success :)
183 183
184err_free_xmailer: 184err_free_xmailer:
185 if (xmailer) mailimf_field_free( xmailer ); 185 if (xmailer) mailimf_field_free( xmailer );
186err_free_fields: 186err_free_fields:
187 if (fields) mailimf_fields_free( fields ); 187 if (fields) mailimf_fields_free( fields );
188err_free_reply: 188err_free_reply:
189 if (reply) mailimf_address_list_free( reply ); 189 if (reply) mailimf_address_list_free( reply );
190 if (bcc) mailimf_address_list_free( bcc ); 190 if (bcc) mailimf_address_list_free( bcc );
191 if (cc) mailimf_address_list_free( cc ); 191 if (cc) mailimf_address_list_free( cc );
192 if (to) mailimf_address_list_free( to ); 192 if (to) mailimf_address_list_free( to );
193err_free_from: 193err_free_from:
194 if (from) mailimf_mailbox_list_free( from ); 194 if (from) mailimf_mailbox_list_free( from );
195err_free_fromBox: 195err_free_fromBox:
196 mailimf_mailbox_free( fromBox ); 196 mailimf_mailbox_free( fromBox );
197err_free_sender: 197err_free_sender:
198 if (sender) mailimf_mailbox_free( sender ); 198 if (sender) mailimf_mailbox_free( sender );
199err_free: 199err_free:
200 if (subject) free( subject ); 200 if (subject) free( subject );
201 qDebug( "createImfFields - error" ); 201 qDebug( "createImfFields - error" );
202 202
203 return NULL; // Error :( 203 return NULL; // Error :(
204} 204}
205 205
206mailmime *SMTPwrapper::buildTxtPart(const QString&str ) 206mailmime *SMTPwrapper::buildTxtPart(const QString&str )
207{ 207{
208 mailmime *txtPart; 208 mailmime *txtPart;
209 mailmime_fields *fields; 209 mailmime_fields *fields;
210 mailmime_content *content; 210 mailmime_content *content;
211 mailmime_parameter *param; 211 mailmime_parameter *param;
212 int err; 212 int err;
213 213
214 param = mailmime_parameter_new( strdup( "charset" ), 214 param = mailmime_parameter_new( strdup( "charset" ),
215 strdup( "iso-8859-1" ) ); 215 strdup( "iso-8859-1" ) );
216 if ( param == NULL ) goto err_free; 216 if ( param == NULL ) goto err_free;
217 217
218 content = mailmime_content_new_with_str( "text/plain" ); 218 content = mailmime_content_new_with_str( "text/plain" );
219 if ( content == NULL ) goto err_free_param; 219 if ( content == NULL ) goto err_free_param;
220 220
221 err = clist_append( content->ct_parameters, param ); 221 err = clist_append( content->ct_parameters, param );
222 if ( err != MAILIMF_NO_ERROR ) goto err_free_content; 222 if ( err != MAILIMF_NO_ERROR ) goto err_free_content;
223 223
224 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); 224 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT);
225 if ( fields == NULL ) goto err_free_content; 225 if ( fields == NULL ) goto err_free_content;
226 226
227 txtPart = mailmime_new_empty( content, fields ); 227 txtPart = mailmime_new_empty( content, fields );
228 if ( txtPart == NULL ) goto err_free_fields; 228 if ( txtPart == NULL ) goto err_free_fields;
229 229
230 err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); 230 err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() );
231 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 231 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
232 232
233 return txtPart; // Success :) 233 return txtPart; // Success :)
234 234
235err_free_txtPart: 235err_free_txtPart:
236 mailmime_free( txtPart ); 236 mailmime_free( txtPart );
237err_free_fields: 237err_free_fields:
238 mailmime_fields_free( fields ); 238 mailmime_fields_free( fields );
239err_free_content: 239err_free_content:
240 mailmime_content_free( content ); 240 mailmime_content_free( content );
241err_free_param: 241err_free_param:
242 mailmime_parameter_free( param ); 242 mailmime_parameter_free( param );
243err_free: 243err_free:
244 qDebug( "buildTxtPart - error" ); 244 qDebug( "buildTxtPart - error" );
245 245
246 return NULL; // Error :( 246 return NULL; // Error :(
247} 247}
248 248
249mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) 249mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent )
250{ 250{
251 mailmime * filePart = 0; 251 mailmime * filePart = 0;
252 mailmime_fields * fields = 0; 252 mailmime_fields * fields = 0;
253 mailmime_content * content = 0; 253 mailmime_content * content = 0;
254 mailmime_parameter * param = 0; 254 mailmime_parameter * param = 0;
255 char*name = 0; 255 char*name = 0;
256 char*file = 0; 256 char*file = 0;
257 int err; 257 int err;
258 258
259 int pos = filename.findRev( '/' ); 259 int pos = filename.findRev( '/' );
260 260
261 if (filename.length()>0) { 261 if (filename.length()>0) {
262 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 262 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
263 name = strdup( tmp.latin1() ); // just filename 263 name = strdup( tmp.latin1() ); // just filename
264 file = strdup( filename.latin1() ); // full name with path 264 file = strdup( filename.latin1() ); // full name with path
265 } 265 }
266 266
267 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; 267 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
268 int mechanism = MAILMIME_MECHANISM_BASE64; 268 int mechanism = MAILMIME_MECHANISM_BASE64;
269 269
270 if ( mimetype.startsWith( "text/" ) ) { 270 if ( mimetype.startsWith( "text/" ) ) {
271 param = mailmime_parameter_new( strdup( "charset" ), 271 param = mailmime_parameter_new( strdup( "charset" ),
272 strdup( "iso-8859-1" ) ); 272 strdup( "iso-8859-1" ) );
273 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 273 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
274 } 274 }
275 275
276 fields = mailmime_fields_new_filename( 276 fields = mailmime_fields_new_filename(
277 disptype, name, 277 disptype, name,
278 mechanism ); 278 mechanism );
279 content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); 279 content = mailmime_content_new_with_str( (char*)mimetype.latin1() );
280 if (content!=0 && fields != 0) { 280 if (content!=0 && fields != 0) {
281 if (param) { 281 if (param) {
282 clist_append(content->ct_parameters,param); 282 clist_append(content->ct_parameters,param);
283 param = 0; 283 param = 0;
284 } 284 }
285 if (filename.length()>0) { 285 if (filename.length()>0) {
286 QFileInfo f(filename); 286 QFileInfo f(filename);
287 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); 287 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1()));
288 clist_append(content->ct_parameters,param); 288 clist_append(content->ct_parameters,param);
289 param = 0; 289 param = 0;
290 } 290 }
291 filePart = mailmime_new_empty( content, fields ); 291 filePart = mailmime_new_empty( content, fields );
292 } 292 }
293 if (filePart) { 293 if (filePart) {
294 if (filename.length()>0) { 294 if (filename.length()>0) {
295 err = mailmime_set_body_file( filePart, file ); 295 err = mailmime_set_body_file( filePart, file );
296 } else { 296 } else {
297 err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); 297 err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length());
298 } 298 }
299 if (err != MAILIMF_NO_ERROR) { 299 if (err != MAILIMF_NO_ERROR) {
300 qDebug("Error setting body with file %s",file); 300 qDebug("Error setting body with file %s",file);
301 mailmime_free( filePart ); 301 mailmime_free( filePart );
302 filePart = 0; 302 filePart = 0;
303 } 303 }
304 } 304 }
305 305
306 if (!filePart) { 306 if (!filePart) {
307 if ( param != NULL ) { 307 if ( param != NULL ) {
308 mailmime_parameter_free( param ); 308 mailmime_parameter_free( param );
309 } 309 }
310 if (content) { 310 if (content) {
311 mailmime_content_free( content ); 311 mailmime_content_free( content );
312 } 312 }
313 if (fields) { 313 if (fields) {
314 mailmime_fields_free( fields ); 314 mailmime_fields_free( fields );
315 } else { 315 } else {
316 if (name) { 316 if (name) {
317 free( name ); 317 free( name );
318 } 318 }
319 if (file) { 319 if (file) {
320 free( file ); 320 free( file );
321 } 321 }
322 } 322 }
323 } 323 }
324 return filePart; // Success :) 324 return filePart; // Success :)
325 325
326} 326}
327 327
328void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) 328void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files )
329{ 329{
330 const Attachment *it; 330 const Attachment *it;
331 unsigned int count = files.count(); 331 unsigned int count = files.count();
332 qDebug("List contains %i values",count); 332 qDebug("List contains %i values",count);
333 for ( unsigned int i = 0; i < count; ++i ) { 333 for ( unsigned int i = 0; i < count; ++i ) {
334 qDebug( "Adding file" ); 334 qDebug( "Adding file" );
335 mailmime *filePart; 335 mailmime *filePart;
336 int err; 336 int err;
337 it = ((QList<Attachment>)files).at(i); 337 it = ((QList<Attachment>)files).at(i);
338 338
339 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); 339 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" );
340 if ( filePart == NULL ) { 340 if ( filePart == NULL ) {
341 qDebug( "addFileParts: error adding file:" ); 341 qDebug( "addFileParts: error adding file:" );
342 qDebug( it->getFileName() ); 342 qDebug( it->getFileName() );
343 continue; 343 continue;
344 } 344 }
345 err = mailmime_smart_add_part( message, filePart ); 345 err = mailmime_smart_add_part( message, filePart );
346 if ( err != MAILIMF_NO_ERROR ) { 346 if ( err != MAILIMF_NO_ERROR ) {
347 mailmime_free( filePart ); 347 mailmime_free( filePart );
348 qDebug("error smart add"); 348 qDebug("error smart add");
349 } 349 }
350 } 350 }
351} 351}
352 352
353mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) 353mailmime *SMTPwrapper::createMimeMail(const Mail &mail )
354{ 354{
355 mailmime *message, *txtPart; 355 mailmime *message, *txtPart;
356 mailimf_fields *fields; 356 mailimf_fields *fields;
357 int err; 357 int err;
358 358
359 fields = createImfFields( mail ); 359 fields = createImfFields( mail );
360 if ( fields == NULL ) goto err_free; 360 if ( fields == NULL ) goto err_free;
361 361
362 message = mailmime_new_message_data( NULL ); 362 message = mailmime_new_message_data( NULL );
363 if ( message == NULL ) goto err_free_fields; 363 if ( message == NULL ) goto err_free_fields;
364 364
365 mailmime_set_imf_fields( message, fields ); 365 mailmime_set_imf_fields( message, fields );
366 366
367 txtPart = buildTxtPart( mail.getMessage() ); 367 txtPart = buildTxtPart( mail.getMessage() );
368 368
369 if ( txtPart == NULL ) goto err_free_message; 369 if ( txtPart == NULL ) goto err_free_message;
370 370
371 err = mailmime_smart_add_part( message, txtPart ); 371 err = mailmime_smart_add_part( message, txtPart );
372 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 372 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
373 373
374 addFileParts( message, mail.getAttachments() ); 374 addFileParts( message, mail.getAttachments() );
375 375
376 return message; // Success :) 376 return message; // Success :)
377 377
378err_free_txtPart: 378err_free_txtPart:
379 mailmime_free( txtPart ); 379 mailmime_free( txtPart );
380err_free_message: 380err_free_message:
381 mailmime_free( message ); 381 mailmime_free( message );
382err_free_fields: 382err_free_fields:
383 mailimf_fields_free( fields ); 383 mailimf_fields_free( fields );
384err_free: 384err_free:
385 qDebug( "createMimeMail: error" ); 385 qDebug( "createMimeMail: error" );
386 386
387 return NULL; // Error :( 387 return NULL; // Error :(
388} 388}
389 389
390mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) 390mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type )
391{ 391{
392 mailimf_field *field; 392 mailimf_field *field;
393 clistiter *it; 393 clistiter *it;
394 394
395 it = clist_begin( fields->fld_list ); 395 it = clist_begin( fields->fld_list );
396 while ( it ) { 396 while ( it ) {
397 field = (mailimf_field *) it->data; 397 field = (mailimf_field *) it->data;
398 if ( field->fld_type == type ) { 398 if ( field->fld_type == type ) {
399 return field; 399 return field;
400 } 400 }
401 it = it->next; 401 it = it->next;
402 } 402 }
403 403
404 return NULL; 404 return NULL;
405} 405}
406 406
407void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) 407void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list )
408{ 408{
409 clistiter *it, *it2; 409 clistiter *it, *it2;
410 410
411 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { 411 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) {
412 mailimf_address *addr; 412 mailimf_address *addr;
413 addr = (mailimf_address *) it->data; 413 addr = (mailimf_address *) it->data;
414 414
415 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { 415 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) {
416 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); 416 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL );
417 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { 417 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) {
418 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; 418 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list;
419 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { 419 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
420 mailimf_mailbox *mbox; 420 mailimf_mailbox *mbox;
421 mbox = (mailimf_mailbox *) it2->data; 421 mbox = (mailimf_mailbox *) it2->data;
422 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); 422 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL );
423 } 423 }
424 } 424 }
425 } 425 }
426} 426}
427 427
428clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) 428clist *SMTPwrapper::createRcptList( mailimf_fields *fields )
429{ 429{
430 clist *rcptList; 430 clist *rcptList;
431 mailimf_field *field; 431 mailimf_field *field;
432 432
433 rcptList = esmtp_address_list_new(); 433 rcptList = esmtp_address_list_new();
434 434
435 field = getField( fields, MAILIMF_FIELD_TO ); 435 field = getField( fields, MAILIMF_FIELD_TO );
436 if ( field && (field->fld_type == MAILIMF_FIELD_TO) 436 if ( field && (field->fld_type == MAILIMF_FIELD_TO)
437 && field->fld_data.fld_to->to_addr_list ) { 437 && field->fld_data.fld_to->to_addr_list ) {
438 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); 438 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
439 } 439 }
440 440
441 field = getField( fields, MAILIMF_FIELD_CC ); 441 field = getField( fields, MAILIMF_FIELD_CC );
442 if ( field && (field->fld_type == MAILIMF_FIELD_CC) 442 if ( field && (field->fld_type == MAILIMF_FIELD_CC)
443 && field->fld_data.fld_cc->cc_addr_list ) { 443 && field->fld_data.fld_cc->cc_addr_list ) {
444 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); 444 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
445 } 445 }
446 446
447 field = getField( fields, MAILIMF_FIELD_BCC ); 447 field = getField( fields, MAILIMF_FIELD_BCC );
448 if ( field && (field->fld_type == MAILIMF_FIELD_BCC) 448 if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
449 && field->fld_data.fld_bcc->bcc_addr_list ) { 449 && field->fld_data.fld_bcc->bcc_addr_list ) {
450 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); 450 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
451 } 451 }
452 452
453 return rcptList; 453 return rcptList;
454} 454}
455 455
456char *SMTPwrapper::getFrom( mailimf_field *ffrom) 456char *SMTPwrapper::getFrom( mailimf_field *ffrom)
457{ 457{
458 char *from = NULL; 458 char *from = NULL;
459 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) 459 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM)
460 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { 460 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) {
461 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; 461 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list;
462 clistiter *it; 462 clistiter *it;
463 for ( it = clist_begin( cl ); it; it = it->next ) { 463 for ( it = clist_begin( cl ); it; it = it->next ) {
464 mailimf_mailbox *mb = (mailimf_mailbox *) it->data; 464 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
465 from = strdup( mb->mb_addr_spec ); 465 from = strdup( mb->mb_addr_spec );
466 } 466 }
467 } 467 }
468 468
469 return from; 469 return from;
470} 470}
471 471
472char *SMTPwrapper::getFrom( mailmime *mail ) 472char *SMTPwrapper::getFrom( mailmime *mail )
473{ 473{
474 /* no need to delete - its just a pointer to structure content */ 474 /* no need to delete - its just a pointer to structure content */
475 mailimf_field *ffrom = 0; 475 mailimf_field *ffrom = 0;
476 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); 476 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
477 return getFrom(ffrom); 477 return getFrom(ffrom);
478} 478}
479 479
480void SMTPwrapper::progress( size_t current, size_t maximum ) 480void SMTPwrapper::progress( size_t current, size_t maximum )
481{ 481{
482 if (SMTPwrapper::sendProgress) { 482 if (SMTPwrapper::sendProgress) {
483 SMTPwrapper::sendProgress->setSingleMail(current, maximum ); 483 SMTPwrapper::sendProgress->setSingleMail(current, maximum );
484 qApp->processEvents(); 484 qApp->processEvents();
485 } 485 }
486} 486}
487 487
488void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) 488void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box)
489{ 489{
490 if (!mail) return; 490 if (!mail) return;
491 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); 491 QString localfolders = AbstractMail::defaultLocalfolder();
492 MBOXwrapper*wrap = new MBOXwrapper(localfolders); 492 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
493 wrap->storeMessage(mail,length,box); 493 wrap->storeMessage(mail,length,box);
494 delete wrap; 494 delete wrap;
495} 495}
496 496
497void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) 497void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
498{ 498{
499 clist *rcpts = 0; 499 clist *rcpts = 0;
500 char *from, *data; 500 char *from, *data;
501 size_t size; 501 size_t size;
502 502
503 if ( smtp == NULL ) { 503 if ( smtp == NULL ) {
504 return; 504 return;
505 } 505 }
506 from = data = 0; 506 from = data = 0;
507 507
508 mailmessage * msg = 0; 508 mailmessage * msg = 0;
509 msg = mime_message_init(mail); 509 msg = mime_message_init(mail);
510 mime_message_set_tmpdir(msg,getenv( "HOME" )); 510 mime_message_set_tmpdir(msg,getenv( "HOME" ));
511 int r = mailmessage_fetch(msg,&data,&size); 511 int r = mailmessage_fetch(msg,&data,&size);
512 mime_message_detach_mime(msg); 512 mime_message_detach_mime(msg);
513 mailmessage_free(msg); 513 mailmessage_free(msg);
514 if (r != MAIL_NO_ERROR || !data) { 514 if (r != MAIL_NO_ERROR || !data) {
515 if (data) free(data); 515 if (data) free(data);
516 qDebug("Error fetching mime..."); 516 qDebug("Error fetching mime...");
517 return; 517 return;
518 } 518 }
519 QString tmp = data; 519 QString tmp = data;
520 tmp.replace(QRegExp("\r+",true,false),""); 520 tmp.replace(QRegExp("\r+",true,false),"");
521 msg = 0; 521 msg = 0;
522 if (later) { 522 if (later) {
523 storeMail((char*)tmp.data(),tmp.length(),"Outgoing"); 523 storeMail((char*)tmp.data(),tmp.length(),"Outgoing");
524 if (data) free( data ); 524 if (data) free( data );
525 Config cfg( "mail" ); 525 Config cfg( "mail" );
526 cfg.setGroup( "Status" ); 526 cfg.setGroup( "Status" );
527 cfg.writeEntry( "outgoing", ++m_queuedMail ); 527 cfg.writeEntry( "outgoing", ++m_queuedMail );
528 emit queuedMails( m_queuedMail ); 528 emit queuedMails( m_queuedMail );
529 return; 529 return;
530 } 530 }
531 from = getFrom( mail ); 531 from = getFrom( mail );
532 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 532 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
533 smtpSend(from,rcpts,data,size,smtp); 533 smtpSend(from,rcpts,data,size,smtp);
534 if (data) {free(data);} 534 if (data) {free(data);}
535 if (from) {free(from);} 535 if (from) {free(from);}
536 if (rcpts) smtp_address_list_free( rcpts ); 536 if (rcpts) smtp_address_list_free( rcpts );
537} 537}
538 538
539int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) 539int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp )
540{ 540{
541 char *server, *user, *pass; 541 char *server, *user, *pass;
542 bool ssl; 542 bool ssl;
543 uint16_t port; 543 uint16_t port;
544 mailsmtp *session; 544 mailsmtp *session;
545 int err,result; 545 int err,result;
546 546
547 result = 1; 547 result = 1;
548 server = user = pass = 0; 548 server = user = pass = 0;
549 server = strdup( smtp->getServer().latin1() ); 549 server = strdup( smtp->getServer().latin1() );
550 ssl = smtp->getSSL(); 550 ssl = smtp->getSSL();
551 port = smtp->getPort().toUInt(); 551 port = smtp->getPort().toUInt();
552 552
553 session = mailsmtp_new( 20, &progress ); 553 session = mailsmtp_new( 20, &progress );
554 if ( session == NULL ) goto free_mem; 554 if ( session == NULL ) goto free_mem;
555 555
556 qDebug( "Servername %s at port %i", server, port ); 556 qDebug( "Servername %s at port %i", server, port );
557 if ( ssl ) { 557 if ( ssl ) {
558 qDebug( "SSL session" ); 558 qDebug( "SSL session" );
559 err = mailsmtp_ssl_connect( session, server, port ); 559 err = mailsmtp_ssl_connect( session, server, port );
560 } else { 560 } else {
561 qDebug( "No SSL session" ); 561 qDebug( "No SSL session" );
562 err = mailsmtp_socket_connect( session, server, port ); 562 err = mailsmtp_socket_connect( session, server, port );
563 } 563 }
564 if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;} 564 if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;}
565 565
566 err = mailsmtp_init( session ); 566 err = mailsmtp_init( session );
567 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} 567 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;}
568 568
569 qDebug( "INIT OK" ); 569 qDebug( "INIT OK" );
570 570
571 if ( smtp->getLogin() ) { 571 if ( smtp->getLogin() ) {
572 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { 572 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
573 // get'em 573 // get'em
574 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); 574 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true );
575 login.show(); 575 login.show();
576 if ( QDialog::Accepted == login.exec() ) { 576 if ( QDialog::Accepted == login.exec() ) {
577 // ok 577 // ok
578 user = strdup( login.getUser().latin1() ); 578 user = strdup( login.getUser().latin1() );
579 pass = strdup( login.getPassword().latin1() ); 579 pass = strdup( login.getPassword().latin1() );
580 } else { 580 } else {
581 result = 0; goto free_con_session; 581 result = 0; goto free_con_session;
582 } 582 }
583 } else { 583 } else {
584 user = strdup( smtp->getUser().latin1() ); 584 user = strdup( smtp->getUser().latin1() );
585 pass = strdup( smtp->getPassword().latin1() ); 585 pass = strdup( smtp->getPassword().latin1() );
586 } 586 }
587 qDebug( "session->auth: %i", session->auth); 587 qDebug( "session->auth: %i", session->auth);
588 err = mailsmtp_auth( session, user, pass ); 588 err = mailsmtp_auth( session, user, pass );
589 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); 589 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
590 qDebug( "Done auth!" ); 590 qDebug( "Done auth!" );
591 } 591 }
592 592
593 err = mailsmtp_send( session, from, rcpts, data, size ); 593 err = mailsmtp_send( session, from, rcpts, data, size );
594 if ( err != MAILSMTP_NO_ERROR ) { 594 if ( err != MAILSMTP_NO_ERROR ) {
595 qDebug("Error sending mail: %s",mailsmtpError(err).latin1()); 595 qDebug("Error sending mail: %s",mailsmtpError(err).latin1());
596 result = 0; goto free_con_session; 596 result = 0; goto free_con_session;
597 } 597 }
598 598
599 qDebug( "Mail sent." ); 599 qDebug( "Mail sent." );
600 storeMail(data,size,"Sent"); 600 storeMail(data,size,"Sent");
601 601
602free_con_session: 602free_con_session:
603 mailsmtp_quit( session ); 603 mailsmtp_quit( session );
604free_mem_session: 604free_mem_session:
605 mailsmtp_free( session ); 605 mailsmtp_free( session );
606free_mem: 606free_mem:
607 if (server) free( server ); 607 if (server) free( server );
608 if ( smtp->getLogin() ) { 608 if ( smtp->getLogin() ) {
609 free( user ); 609 free( user );
610 free( pass ); 610 free( pass );
611 } 611 }
612 return result; 612 return result;
613} 613}
614 614
615void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) 615void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later )
616{ 616{
617 mailmime * mimeMail; 617 mailmime * mimeMail;
618 618
619 SMTPaccount *smtp = aSmtp; 619 SMTPaccount *smtp = aSmtp;
620 620
621 if (!later && !smtp) { 621 if (!later && !smtp) {
622 qDebug("Didn't get any send method - giving up"); 622 qDebug("Didn't get any send method - giving up");
623 return; 623 return;
624 } 624 }
625 mimeMail = createMimeMail(mail ); 625 mimeMail = createMimeMail(mail );
626 if ( mimeMail == NULL ) { 626 if ( mimeMail == NULL ) {
627 qDebug( "sendMail: error creating mime mail" ); 627 qDebug( "sendMail: error creating mime mail" );
628 } else { 628 } else {
629 sendProgress = new progressMailSend(); 629 sendProgress = new progressMailSend();
630 sendProgress->show(); 630 sendProgress->show();
631 sendProgress->setMaxMails(1); 631 sendProgress->setMaxMails(1);
632 smtpSend( mimeMail,later,smtp); 632 smtpSend( mimeMail,later,smtp);
633 qDebug("Clean up done"); 633 qDebug("Clean up done");
634 sendProgress->hide(); 634 sendProgress->hide();
635 delete sendProgress; 635 delete sendProgress;
636 sendProgress = 0; 636 sendProgress = 0;
637 mailmime_free( mimeMail ); 637 mailmime_free( mimeMail );
638 } 638 }
639} 639}
640 640
641int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) 641int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
642{ 642{
643 char*data = 0; 643 char*data = 0;
644 size_t length = 0; 644 size_t length = 0;
645 size_t curTok = 0; 645 size_t curTok = 0;
646 mailimf_fields *fields = 0; 646 mailimf_fields *fields = 0;
647 mailimf_field*ffrom = 0; 647 mailimf_field*ffrom = 0;
648 clist *rcpts = 0; 648 clist *rcpts = 0;
649 char*from = 0; 649 char*from = 0;
650 int res = 0; 650 int res = 0;
651 651
652 wrap->fetchRawBody(*which,&data,&length); 652 wrap->fetchRawBody(*which,&data,&length);
653 if (!data) return 0; 653 if (!data) return 0;
654 int err = mailimf_fields_parse( data, length, &curTok, &fields ); 654 int err = mailimf_fields_parse( data, length, &curTok, &fields );
655 if (err != MAILIMF_NO_ERROR) { 655 if (err != MAILIMF_NO_ERROR) {
656 free(data); 656 free(data);
657 delete wrap; 657 delete wrap;
658 return 0; 658 return 0;
659 } 659 }
660 660
661 rcpts = createRcptList( fields ); 661 rcpts = createRcptList( fields );
662 ffrom = getField(fields, MAILIMF_FIELD_FROM ); 662 ffrom = getField(fields, MAILIMF_FIELD_FROM );
663 from = getFrom(ffrom); 663 from = getFrom(ffrom);
664 664
665 qDebug("Size: %i vs. %i",length,strlen(data)); 665 qDebug("Size: %i vs. %i",length,strlen(data));
666 if (rcpts && from) { 666 if (rcpts && from) {
667 res = smtpSend(from,rcpts,data,length,smtp ); 667 res = smtpSend(from,rcpts,data,length,smtp );
668 } 668 }
669 if (fields) { 669 if (fields) {
670 mailimf_fields_free(fields); 670 mailimf_fields_free(fields);
671 fields = 0; 671 fields = 0;
672 } 672 }
673 if (data) { 673 if (data) {
674 free(data); 674 free(data);
675 } 675 }
676 if (from) { 676 if (from) {
677 free(from); 677 free(from);
678 } 678 }
679 if (rcpts) { 679 if (rcpts) {
680 smtp_address_list_free( rcpts ); 680 smtp_address_list_free( rcpts );
681 } 681 }
682 return res; 682 return res;
683} 683}
684 684
685/* this is a special fun */ 685/* this is a special fun */
686bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) 686bool SMTPwrapper::flushOutbox(SMTPaccount*smtp)
687{ 687{
688 bool returnValue = true; 688 bool returnValue = true;
689 689
690 if (!smtp) return false; 690 if (!smtp) return false;
691 691
692 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); 692 QString localfolders = AbstractMail::defaultLocalfolder();
693 MBOXwrapper*wrap = new MBOXwrapper(localfolders); 693 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
694 if (!wrap) { 694 if (!wrap) {
695 qDebug("memory error"); 695 qDebug("memory error");
696 return false; 696 return false;
697 } 697 }
698 QList<RecMail> mailsToSend; 698 QList<RecMail> mailsToSend;
699 QList<RecMail> mailsToRemove; 699 QList<RecMail> mailsToRemove;
700 QString mbox("Outgoing"); 700 QString mbox("Outgoing");
701 wrap->listMessages(mbox,mailsToSend); 701 wrap->listMessages(mbox,mailsToSend);
702 if (mailsToSend.count()==0) { 702 if (mailsToSend.count()==0) {
703 delete wrap; 703 delete wrap;
704 return false; 704 return false;
705 } 705 }
706 mailsToSend.setAutoDelete(false); 706 mailsToSend.setAutoDelete(false);
707 sendProgress = new progressMailSend(); 707 sendProgress = new progressMailSend();
708 sendProgress->show(); 708 sendProgress->show();
709 sendProgress->setMaxMails(mailsToSend.count()); 709 sendProgress->setMaxMails(mailsToSend.count());
710 710
711 while (mailsToSend.count()>0) { 711 while (mailsToSend.count()>0) {
712 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { 712 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) {
713 QMessageBox::critical(0,tr("Error sending mail"), 713 QMessageBox::critical(0,tr("Error sending mail"),
714 tr("Error sending queued mail - breaking")); 714 tr("Error sending queued mail - breaking"));
715 returnValue = false; 715 returnValue = false;
716 break; 716 break;
717 } 717 }
718 mailsToRemove.append(mailsToSend.at(0)); 718 mailsToRemove.append(mailsToSend.at(0));
719 mailsToSend.removeFirst(); 719 mailsToSend.removeFirst();
720 sendProgress->setCurrentMails(mailsToRemove.count()); 720 sendProgress->setCurrentMails(mailsToRemove.count());
721 } 721 }
722 Config cfg( "mail" ); 722 Config cfg( "mail" );
723 cfg.setGroup( "Status" ); 723 cfg.setGroup( "Status" );
724 m_queuedMail = 0; 724 m_queuedMail = 0;
725 cfg.writeEntry( "outgoing", m_queuedMail ); 725 cfg.writeEntry( "outgoing", m_queuedMail );
726 emit queuedMails( m_queuedMail ); 726 emit queuedMails( m_queuedMail );
727 sendProgress->hide(); 727 sendProgress->hide();
728 delete sendProgress; 728 delete sendProgress;
729 sendProgress = 0; 729 sendProgress = 0;
730 wrap->deleteMails(mbox,mailsToRemove); 730 wrap->deleteMails(mbox,mailsToRemove);
731 mailsToSend.setAutoDelete(true); 731 mailsToSend.setAutoDelete(true);
732 delete wrap; 732 delete wrap;
733 return returnValue; 733 return returnValue;
734} 734}
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h
index 05becf2..4a4352f 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.h
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h
@@ -1,71 +1,72 @@
1#ifndef SMTPwrapper_H 1#ifndef SMTPwrapper_H
2#define SMTPwrapper_H 2#define SMTPwrapper_H
3 3
4#include <qpe/applnk.h> 4#include <qpe/applnk.h>
5 5
6#include <qbitarray.h> 6#include <qbitarray.h>
7#include <qdatetime.h> 7#include <qdatetime.h>
8#include <libetpan/clist.h> 8#include <libetpan/clist.h>
9 9
10#include "settings.h" 10#include "settings.h"
11 11
12class Mail; 12class Mail;
13class MBOXwrapper; 13class MBOXwrapper;
14class RecMail; 14class RecMail;
15class Attachment; 15class Attachment;
16struct mailimf_fields; 16struct mailimf_fields;
17struct mailimf_field; 17struct mailimf_field;
18struct mailimf_mailbox; 18struct mailimf_mailbox;
19struct mailmime; 19struct mailmime;
20struct mailimf_address_list; 20struct mailimf_address_list;
21class progressMailSend; 21class progressMailSend;
22 22
23class SMTPwrapper : public QObject 23class SMTPwrapper : public QObject
24{ 24{
25 Q_OBJECT 25 Q_OBJECT
26 26
27public: 27public:
28 SMTPwrapper( Settings *s ); 28 SMTPwrapper( Settings *s );
29 virtual ~SMTPwrapper(){} 29 virtual ~SMTPwrapper(){}
30 void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false ); 30 void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false );
31 bool flushOutbox(SMTPaccount*smtp); 31 bool flushOutbox(SMTPaccount*smtp);
32 32
33 static progressMailSend*sendProgress; 33 static progressMailSend*sendProgress;
34 34
35signals: 35signals:
36 void queuedMails( int ); 36 void queuedMails( int );
37 37
38protected: 38protected:
39 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 39 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
40 mailimf_fields *createImfFields(const Mail &mail ); 40 mailimf_fields *createImfFields(const Mail &mail );
41 mailmime *createMimeMail(const Mail&mail ); 41 mailmime *createMimeMail(const Mail&mail );
42 42
43 mailimf_address_list *parseAddresses(const QString&addr ); 43 mailimf_address_list *parseAddresses(const QString&addr );
44 void addFileParts( mailmime *message,const QList<Attachment>&files ); 44 void addFileParts( mailmime *message,const QList<Attachment>&files );
45 mailmime *buildTxtPart(const QString&str ); 45 mailmime *buildTxtPart(const QString&str );
46 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); 46 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content);
47 void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); 47 void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp );
48 clist *createRcptList( mailimf_fields *fields ); 48 clist *createRcptList( mailimf_fields *fields );
49 49
50 static void storeMail(char*mail, size_t length, const QString&box); 50 static void storeMail(char*mail, size_t length, const QString&box);
51 static QString mailsmtpError( int err ); 51 static QString mailsmtpError( int err );
52 static void progress( size_t current, size_t maximum ); 52 static void progress( size_t current, size_t maximum );
53 static void addRcpts( clist *list, mailimf_address_list *addr_list ); 53 static void addRcpts( clist *list, mailimf_address_list *addr_list );
54 static char *getFrom( mailmime *mail ); 54 static char *getFrom( mailmime *mail );
55 static char *getFrom( mailimf_field *ffrom); 55 static char *getFrom( mailimf_field *ffrom);
56 static mailimf_field *getField( mailimf_fields *fields, int type ); 56 static mailimf_field *getField( mailimf_fields *fields, int type );
57 int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); 57 int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp );
58 58
59 void storeMail(mailmime*mail, const QString&box); 59 void storeMail(mailmime*mail, const QString&box);
60 Settings *settings; 60 Settings *settings;
61 61
62 int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which); 62 int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which);
63 63
64 int m_queuedMail; 64 int m_queuedMail;
65 static const char* USER_AGENT;
65 66
66protected slots: 67protected slots:
67 void emitQCop( int queued ); 68 void emitQCop( int queued );
68 69
69}; 70};
70 71
71#endif 72#endif