summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-17 00:30:31 (UTC)
committer alwin <alwin>2003-12-17 00:30:31 (UTC)
commita928f1fc8469124e10a7042846d258401e41f7d6 (patch) (unidiff)
tree225db6d7356d3ff3a0a3f3768c2fc0fa10360edc
parent27151bb106e2cbd7f649dae228189ebcaccd7aac (diff)
downloadopie-a928f1fc8469124e10a7042846d258401e41f7d6.zip
opie-a928f1fc8469124e10a7042846d258401e41f7d6.tar.gz
opie-a928f1fc8469124e10a7042846d258401e41f7d6.tar.bz2
imap folder will be displayed more structured
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/accountview.cpp69
-rw-r--r--noncore/net/mail/accountview.h2
-rw-r--r--noncore/net/mail/imapwrapper.cpp7
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp7
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.cpp11
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.h7
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp2
-rw-r--r--noncore/net/mail/mailwrapper.cpp11
-rw-r--r--noncore/net/mail/mailwrapper.h7
-rw-r--r--noncore/net/mail/pop3wrapper.cpp2
10 files changed, 100 insertions, 25 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp
index 8e21d39..b6bf298 100644
--- a/noncore/net/mail/accountview.cpp
+++ b/noncore/net/mail/accountview.cpp
@@ -1,227 +1,282 @@
1#include "accountview.h" 1#include "accountview.h"
2#include "mailtypes.h" 2#include "mailtypes.h"
3#include "defines.h" 3#include "defines.h"
4 4
5 5
6/** 6/**
7 * POP3 Account stuff 7 * POP3 Account stuff
8 */ 8 */
9 9
10POP3viewItem::POP3viewItem( POP3account *a, QListView *parent ) 10POP3viewItem::POP3viewItem( POP3account *a, QListView *parent )
11 : AccountViewItem( parent ) 11 : AccountViewItem( parent )
12{ 12{
13 account = a; 13 account = a;
14 wrapper = AbstractMail::getWrapper( account ); 14 wrapper = AbstractMail::getWrapper( account );
15 setPixmap( 0, PIXMAP_POP3FOLDER ); 15 setPixmap( 0, PIXMAP_POP3FOLDER );
16 setText( 0, account->getAccountName() ); 16 setText( 0, account->getAccountName() );
17} 17}
18 18
19POP3viewItem::~POP3viewItem() 19POP3viewItem::~POP3viewItem()
20{ 20{
21 delete wrapper; 21 delete wrapper;
22} 22}
23 23
24AbstractMail *POP3viewItem::getWrapper() 24AbstractMail *POP3viewItem::getWrapper()
25{ 25{
26 return wrapper; 26 return wrapper;
27} 27}
28 28
29void POP3viewItem::refresh( QList<RecMail> & ) 29void POP3viewItem::refresh( QList<RecMail> & )
30{ 30{
31 QList<Folder> *folders = wrapper->listFolders(); 31 QList<Folder> *folders = wrapper->listFolders();
32 QListViewItem *child = firstChild(); 32 QListViewItem *child = firstChild();
33 while ( child ) { 33 while ( child ) {
34 QListViewItem *tmp = child; 34 QListViewItem *tmp = child;
35 child = child->nextSibling(); 35 child = child->nextSibling();
36 delete tmp; 36 delete tmp;
37 } 37 }
38 Folder *it; 38 Folder *it;
39 QListViewItem*item = 0; 39 QListViewItem*item = 0;
40 for ( it = folders->first(); it; it = folders->next() ) { 40 for ( it = folders->first(); it; it = folders->next() ) {
41 item = new POP3folderItem( it, this , item ); 41 item = new POP3folderItem( it, this , item );
42 item->setSelectable(it->may_select()); 42 item->setSelectable(it->may_select());
43 } 43 }
44 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 44 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
45 folders->setAutoDelete(false); 45 folders->setAutoDelete(false);
46 delete folders; 46 delete folders;
47} 47}
48 48
49RecBody POP3viewItem::fetchBody( const RecMail &mail ) 49RecBody POP3viewItem::fetchBody( const RecMail &mail )
50{ 50{
51 qDebug( "POP3 fetchBody" ); 51 qDebug( "POP3 fetchBody" );
52 return wrapper->fetchBody( mail ); 52 return wrapper->fetchBody( mail );
53} 53}
54 54
55POP3folderItem::~POP3folderItem() 55POP3folderItem::~POP3folderItem()
56{ 56{
57 delete folder; 57 delete folder;
58} 58}
59 59
60POP3folderItem::POP3folderItem( Folder *folderInit, POP3viewItem *parent , QListViewItem*after ) 60POP3folderItem::POP3folderItem( Folder *folderInit, POP3viewItem *parent , QListViewItem*after )
61 : AccountViewItem( parent,after ) 61 : AccountViewItem( parent,after )
62{ 62{
63 folder = folderInit; 63 folder = folderInit;
64 pop3 = parent; 64 pop3 = parent;
65 if (folder->getDisplayName().lower()!="inbox") { 65 if (folder->getDisplayName().lower()!="inbox") {
66 setPixmap( 0, PIXMAP_POP3FOLDER ); 66 setPixmap( 0, PIXMAP_POP3FOLDER );
67 } else { 67 } else {
68 setPixmap( 0, PIXMAP_INBOXFOLDER); 68 setPixmap( 0, PIXMAP_INBOXFOLDER);
69 } 69 }
70 setText( 0, folder->getDisplayName() ); 70 setText( 0, folder->getDisplayName() );
71} 71}
72 72
73void POP3folderItem::refresh(QList<RecMail>&target) 73void POP3folderItem::refresh(QList<RecMail>&target)
74{ 74{
75 if (folder->may_select()) 75 if (folder->may_select())
76 pop3->getWrapper()->listMessages( folder->getName(),target ); 76 pop3->getWrapper()->listMessages( folder->getName(),target );
77} 77}
78 78
79RecBody POP3folderItem::fetchBody(const RecMail&aMail) 79RecBody POP3folderItem::fetchBody(const RecMail&aMail)
80{ 80{
81 return pop3->getWrapper()->fetchBody(aMail); 81 return pop3->getWrapper()->fetchBody(aMail);
82} 82}
83 83
84/** 84/**
85 * IMAP Account stuff 85 * IMAP Account stuff
86 */ 86 */
87IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent ) 87IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent )
88 : AccountViewItem( parent ) 88 : AccountViewItem( parent )
89{ 89{
90 account = a; 90 account = a;
91 wrapper = AbstractMail::getWrapper( account ); 91 wrapper = AbstractMail::getWrapper( account );
92 setPixmap( 0, PIXMAP_IMAPFOLDER ); 92 setPixmap( 0, PIXMAP_IMAPFOLDER );
93 setText( 0, account->getAccountName() ); 93 setText( 0, account->getAccountName() );
94 setOpen( true ); 94 setOpen( true );
95} 95}
96 96
97IMAPviewItem::~IMAPviewItem() 97IMAPviewItem::~IMAPviewItem()
98{ 98{
99 delete wrapper; 99 delete wrapper;
100} 100}
101 101
102AbstractMail *IMAPviewItem::getWrapper() 102AbstractMail *IMAPviewItem::getWrapper()
103{ 103{
104 return wrapper; 104 return wrapper;
105} 105}
106 106
107void IMAPviewItem::refresh(QList<RecMail>&) 107void IMAPviewItem::refresh(QList<RecMail>&)
108{ 108{
109 if (childCount()>0) return;
109 QList<Folder> *folders = wrapper->listFolders(); 110 QList<Folder> *folders = wrapper->listFolders();
110 111
111 QListViewItem *child = firstChild(); 112 QListViewItem *child = firstChild();
112 while ( child ) { 113 while ( child ) {
113 QListViewItem *tmp = child; 114 QListViewItem *tmp = child;
114 child = child->nextSibling(); 115 child = child->nextSibling();
115 delete tmp; 116 delete tmp;
116 } 117 }
117 118
118 Folder *it; 119 Folder *it;
119 QListViewItem*item = 0; 120 QListViewItem*item = 0;
120 for ( it = folders->first(); it; it = folders->next() ) { 121 QListViewItem*titem = 0;
121 item = new IMAPfolderItem( it, this , item ); 122 QListViewItem*inboxitem = 0;
122 item->setSelectable(it->may_select()); 123 QString fname,del,search;
123 } 124 int pos;
124 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 125 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
125 folders->setAutoDelete(false); 126 folders->setAutoDelete(false);
127
128 for ( it = folders->first(); it; it = folders->next() ) {
129 if (it->getDisplayName().lower()=="inbox") {
130 inboxitem = new IMAPfolderItem( it, this , item );
131 folders->remove(it);
132 qDebug("inbox found");
133 break;
134 }
135 }
136
137 for ( it = folders->first(); it; it = folders->next() ) {
138 fname = it->getDisplayName();
139 pos = fname.findRev(it->Separator());
140 if (pos != -1) {
141 fname = fname.left(pos);
142 qDebug(fname);
143 }
144 IMAPfolderItem*pitem = (IMAPfolderItem*)firstChild();
145 while (pitem) {
146 if (pitem->matchName(fname)) {
147 break;
148 }
149 pitem=(IMAPfolderItem*)pitem->nextSibling();
150 }
151 if (pitem) {
152 titem = item;
153 item = new IMAPfolderItem(it,pitem,item,this);
154 item->setSelectable(it->may_select());
155 /* setup the short name */
156 item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1));
157 item = titem;
158 } else {
159 item = new IMAPfolderItem( it, this , (inboxitem?inboxitem:item) );
160 item->setSelectable(it->may_select());
161 }
162 }
126 delete folders; 163 delete folders;
127} 164}
128 165
129RecBody IMAPviewItem::fetchBody(const RecMail&) 166RecBody IMAPviewItem::fetchBody(const RecMail&)
130{ 167{
131 return RecBody(); 168 return RecBody();
132} 169}
133 170
134IMAPfolderItem::~IMAPfolderItem() 171IMAPfolderItem::~IMAPfolderItem()
135{ 172{
136 delete folder; 173 delete folder;
137} 174}
138 175
139IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after ) 176IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after )
140 : AccountViewItem( parent,after ) 177 : AccountViewItem( parent )
141{ 178{
142 folder = folderInit; 179 folder = folderInit;
143 imap = parent; 180 imap = parent;
144 if (folder->getDisplayName().lower()!="inbox") { 181 if (folder->getDisplayName().lower()!="inbox") {
145 setPixmap( 0, PIXMAP_IMAPFOLDER ); 182 setPixmap( 0, PIXMAP_IMAPFOLDER );
146 } else { 183 } else {
147 setPixmap( 0, PIXMAP_INBOXFOLDER); 184 setPixmap( 0, PIXMAP_INBOXFOLDER);
148 } 185 }
149 setText( 0, folder->getDisplayName() ); 186 setText( 0, folder->getDisplayName() );
150} 187}
151 188
189IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master )
190 : AccountViewItem( parent,after )
191{
192 folder = folderInit;
193 imap = master;
194 if (folder->getDisplayName().lower()!="inbox") {
195 setPixmap( 0, PIXMAP_IMAPFOLDER );
196 } else {
197 setPixmap( 0, PIXMAP_INBOXFOLDER);
198 }
199 setText( 0, folder->getDisplayName() );
200}
201
202bool IMAPfolderItem::matchName(const QString&name)const
203{
204 return folder->getDisplayName()==name;
205}
206
152void IMAPfolderItem::refresh(QList<RecMail>&target) 207void IMAPfolderItem::refresh(QList<RecMail>&target)
153{ 208{
154 if (folder->may_select()) 209 if (folder->may_select())
155 imap->getWrapper()->listMessages( folder->getName(),target ); 210 imap->getWrapper()->listMessages( folder->getName(),target );
156} 211}
157 212
158RecBody IMAPfolderItem::fetchBody(const RecMail&aMail) 213RecBody IMAPfolderItem::fetchBody(const RecMail&aMail)
159{ 214{
160 return imap->getWrapper()->fetchBody(aMail); 215 return imap->getWrapper()->fetchBody(aMail);
161} 216}
162 217
163/** 218/**
164 * Generic stuff 219 * Generic stuff
165 */ 220 */
166 221
167AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) 222AccountView::AccountView( QWidget *parent, const char *name, WFlags flags )
168 : QListView( parent, name, flags ) 223 : QListView( parent, name, flags )
169{ 224{
170 connect( this, SIGNAL( selectionChanged( QListViewItem * ) ), 225 connect( this, SIGNAL( selectionChanged( QListViewItem * ) ),
171 SLOT( refresh( QListViewItem * ) ) ); 226 SLOT( refresh( QListViewItem * ) ) );
172 setSorting(-1); 227 setSorting(0);
173} 228}
174 229
175void AccountView::populate( QList<Account> list ) 230void AccountView::populate( QList<Account> list )
176{ 231{
177 clear(); 232 clear();
178 233
179 Account *it; 234 Account *it;
180 for ( it = list.first(); it; it = list.next() ) { 235 for ( it = list.first(); it; it = list.next() ) {
181 if ( it->getType().compare( "IMAP" ) == 0 ) { 236 if ( it->getType().compare( "IMAP" ) == 0 ) {
182 IMAPaccount *imap = static_cast<IMAPaccount *>(it); 237 IMAPaccount *imap = static_cast<IMAPaccount *>(it);
183 qDebug( "added IMAP " + imap->getAccountName() ); 238 qDebug( "added IMAP " + imap->getAccountName() );
184 (void) new IMAPviewItem( imap, this ); 239 (void) new IMAPviewItem( imap, this );
185 } else if ( it->getType().compare( "POP3" ) == 0 ) { 240 } else if ( it->getType().compare( "POP3" ) == 0 ) {
186 POP3account *pop3 = static_cast<POP3account *>(it); 241 POP3account *pop3 = static_cast<POP3account *>(it);
187 qDebug( "added POP3 " + pop3->getAccountName() ); 242 qDebug( "added POP3 " + pop3->getAccountName() );
188 (void) new POP3viewItem( pop3, this ); 243 (void) new POP3viewItem( pop3, this );
189 } 244 }
190 } 245 }
191} 246}
192 247
193void AccountView::refresh(QListViewItem *item) { 248void AccountView::refresh(QListViewItem *item) {
194 249
195 qDebug("AccountView refresh..."); 250 qDebug("AccountView refresh...");
196 if ( item ) { 251 if ( item ) {
197 m_currentItem = item; 252 m_currentItem = item;
198 QList<RecMail> headerlist; 253 QList<RecMail> headerlist;
199 headerlist.setAutoDelete(true); 254 headerlist.setAutoDelete(true);
200 AccountViewItem *view = static_cast<AccountViewItem *>(item); 255 AccountViewItem *view = static_cast<AccountViewItem *>(item);
201 view->refresh(headerlist); 256 view->refresh(headerlist);
202 emit refreshMailview(&headerlist); 257 emit refreshMailview(&headerlist);
203 } 258 }
204} 259}
205 260
206void AccountView::refreshCurrent() 261void AccountView::refreshCurrent()
207{ 262{
208 if ( !m_currentItem ) return; 263 if ( !m_currentItem ) return;
209 QList<RecMail> headerlist; 264 QList<RecMail> headerlist;
210 headerlist.setAutoDelete(true); 265 headerlist.setAutoDelete(true);
211 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); 266 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem);
212 view->refresh(headerlist); 267 view->refresh(headerlist);
213 emit refreshMailview(&headerlist); 268 emit refreshMailview(&headerlist);
214} 269}
215 270
216void AccountView::refreshAll() 271void AccountView::refreshAll()
217{ 272{
218 273
219} 274}
220 275
221RecBody AccountView::fetchBody(const RecMail&aMail) 276RecBody AccountView::fetchBody(const RecMail&aMail)
222{ 277{
223 QListViewItem*item = selectedItem (); 278 QListViewItem*item = selectedItem ();
224 if (!item) return RecBody(); 279 if (!item) return RecBody();
225 AccountViewItem *view = static_cast<AccountViewItem *>(item); 280 AccountViewItem *view = static_cast<AccountViewItem *>(item);
226 return view->fetchBody(aMail); 281 return view->fetchBody(aMail);
227} 282}
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h
index d035af4..a57935f 100644
--- a/noncore/net/mail/accountview.h
+++ b/noncore/net/mail/accountview.h
@@ -1,102 +1,104 @@
1#ifndef ACCOUNTVIEW_H 1#ifndef ACCOUNTVIEW_H
2#define ACCOUNTVIEW_H 2#define ACCOUNTVIEW_H
3 3
4#include <qlistview.h> 4#include <qlistview.h>
5#include <qlist.h> 5#include <qlist.h>
6 6
7#include "settings.h" 7#include "settings.h"
8#include "mailwrapper.h" 8#include "mailwrapper.h"
9#include "abstractmail.h" 9#include "abstractmail.h"
10 10
11class POP3wrapper; 11class POP3wrapper;
12class RecMail; 12class RecMail;
13class RecBody; 13class RecBody;
14 14
15class AccountViewItem : public QListViewItem 15class AccountViewItem : public QListViewItem
16{ 16{
17 17
18public: 18public:
19 AccountViewItem( QListView *parent ) : QListViewItem( parent ) {} 19 AccountViewItem( QListView *parent ) : QListViewItem( parent ) {}
20 AccountViewItem( QListViewItem *parent) : QListViewItem( parent) {} 20 AccountViewItem( QListViewItem *parent) : QListViewItem( parent) {}
21 AccountViewItem( QListViewItem *parent , QListViewItem*after ) : QListViewItem( parent,after ) {} 21 AccountViewItem( QListViewItem *parent , QListViewItem*after ) : QListViewItem( parent,after ) {}
22 virtual void refresh(QList<RecMail>&)=0; 22 virtual void refresh(QList<RecMail>&)=0;
23 virtual RecBody fetchBody(const RecMail&)=0; 23 virtual RecBody fetchBody(const RecMail&)=0;
24}; 24};
25 25
26class POP3viewItem : public AccountViewItem 26class POP3viewItem : public AccountViewItem
27{ 27{
28 28
29public: 29public:
30 POP3viewItem( POP3account *a, QListView *parent ); 30 POP3viewItem( POP3account *a, QListView *parent );
31 ~POP3viewItem(); 31 ~POP3viewItem();
32 virtual void refresh( QList<RecMail> &target ); 32 virtual void refresh( QList<RecMail> &target );
33 virtual RecBody fetchBody( const RecMail &mail ); 33 virtual RecBody fetchBody( const RecMail &mail );
34 AbstractMail *getWrapper(); 34 AbstractMail *getWrapper();
35private: 35private:
36 POP3account *account; 36 POP3account *account;
37 AbstractMail *wrapper; 37 AbstractMail *wrapper;
38 38
39}; 39};
40 40
41class POP3folderItem : public AccountViewItem 41class POP3folderItem : public AccountViewItem
42{ 42{
43 43
44public: 44public:
45 POP3folderItem( Folder *folder, POP3viewItem *parent , QListViewItem*after ); 45 POP3folderItem( Folder *folder, POP3viewItem *parent , QListViewItem*after );
46 ~POP3folderItem(); 46 ~POP3folderItem();
47 virtual void refresh(QList<RecMail>&); 47 virtual void refresh(QList<RecMail>&);
48 virtual RecBody fetchBody(const RecMail&); 48 virtual RecBody fetchBody(const RecMail&);
49private: 49private:
50 Folder *folder; 50 Folder *folder;
51 POP3viewItem *pop3; 51 POP3viewItem *pop3;
52}; 52};
53 53
54class IMAPviewItem : public AccountViewItem 54class IMAPviewItem : public AccountViewItem
55{ 55{
56 56
57public: 57public:
58 IMAPviewItem( IMAPaccount *a, QListView *parent ); 58 IMAPviewItem( IMAPaccount *a, QListView *parent );
59 ~IMAPviewItem(); 59 ~IMAPviewItem();
60 virtual void refresh(QList<RecMail>&); 60 virtual void refresh(QList<RecMail>&);
61 virtual RecBody fetchBody(const RecMail&); 61 virtual RecBody fetchBody(const RecMail&);
62 AbstractMail *getWrapper(); 62 AbstractMail *getWrapper();
63private: 63private:
64 IMAPaccount *account; 64 IMAPaccount *account;
65 AbstractMail *wrapper; 65 AbstractMail *wrapper;
66}; 66};
67 67
68class IMAPfolderItem : public AccountViewItem 68class IMAPfolderItem : public AccountViewItem
69{ 69{
70 70
71public: 71public:
72 IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after ); 72 IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after );
73 IMAPfolderItem( Folder *folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master );
73 ~IMAPfolderItem(); 74 ~IMAPfolderItem();
74 virtual void refresh(QList<RecMail>&); 75 virtual void refresh(QList<RecMail>&);
75 virtual RecBody fetchBody(const RecMail&); 76 virtual RecBody fetchBody(const RecMail&);
77 bool matchName(const QString&name)const;
76private: 78private:
77 Folder *folder; 79 Folder *folder;
78 IMAPviewItem *imap; 80 IMAPviewItem *imap;
79}; 81};
80 82
81class AccountView : public QListView 83class AccountView : public QListView
82{ 84{
83 Q_OBJECT 85 Q_OBJECT
84 86
85public: 87public:
86 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 88 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
87 void populate( QList<Account> list ); 89 void populate( QList<Account> list );
88 RecBody fetchBody(const RecMail&aMail); 90 RecBody fetchBody(const RecMail&aMail);
89 91
90public slots: 92public slots:
91 void refreshAll(); 93 void refreshAll();
92 void refresh(QListViewItem *item); 94 void refresh(QListViewItem *item);
93 void refreshCurrent(); 95 void refreshCurrent();
94 96
95signals: 97signals:
96 void refreshMailview(QList<RecMail>*); 98 void refreshMailview(QList<RecMail>*);
97 99
98private: 100private:
99 QListViewItem* m_currentItem; 101 QListViewItem* m_currentItem;
100}; 102};
101 103
102#endif 104#endif
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index d56d7f9..8a86c95 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -1,800 +1,803 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include "imapwrapper.h" 4#include "imapwrapper.h"
5#include "mailtypes.h" 5#include "mailtypes.h"
6#include <libetpan/mailimap.h> 6#include <libetpan/mailimap.h>
7 7
8IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 8IMAPwrapper::IMAPwrapper( IMAPaccount *a )
9 : AbstractMail() 9 : AbstractMail()
10{ 10{
11 account = a; 11 account = a;
12 m_imap = 0; 12 m_imap = 0;
13} 13}
14 14
15IMAPwrapper::~IMAPwrapper() 15IMAPwrapper::~IMAPwrapper()
16{ 16{
17 logout(); 17 logout();
18} 18}
19 19
20void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 20void IMAPwrapper::imap_progress( size_t current, size_t maximum )
21{ 21{
22 qDebug( "IMAP: %i of %i", current, maximum ); 22 qDebug( "IMAP: %i of %i", current, maximum );
23} 23}
24 24
25void IMAPwrapper::login() 25void IMAPwrapper::login()
26{ 26{
27 const char *server, *user, *pass; 27 const char *server, *user, *pass;
28 uint16_t port; 28 uint16_t port;
29 int err = MAILIMAP_NO_ERROR; 29 int err = MAILIMAP_NO_ERROR;
30 30
31 /* we are connected this moment */ 31 /* we are connected this moment */
32 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 32 /* TODO: setup a timer holding the line or if connection closed - delete the value */
33 if (m_imap) { 33 if (m_imap) {
34 mailstream_flush(m_imap->imap_stream); 34 mailstream_flush(m_imap->imap_stream);
35 return; 35 return;
36 } 36 }
37 server = account->getServer().latin1(); 37 server = account->getServer().latin1();
38 port = account->getPort().toUInt(); 38 port = account->getPort().toUInt();
39 user = account->getUser().latin1(); 39 user = account->getUser().latin1();
40 pass = account->getPassword().latin1(); 40 pass = account->getPassword().latin1();
41 41
42 m_imap = mailimap_new( 20, &imap_progress ); 42 m_imap = mailimap_new( 20, &imap_progress );
43 /* connect */ 43 /* connect */
44 if (account->getSSL()) { 44 if (account->getSSL()) {
45 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 45 err = mailimap_ssl_connect( m_imap, (char*)server, port );
46 } else { 46 } else {
47 err = mailimap_socket_connect( m_imap, (char*)server, port ); 47 err = mailimap_socket_connect( m_imap, (char*)server, port );
48 } 48 }
49 49
50 if ( err != MAILIMAP_NO_ERROR && 50 if ( err != MAILIMAP_NO_ERROR &&
51 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 51 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
53 qDebug("error connecting server: %s",m_imap->imap_response); 53 qDebug("error connecting server: %s",m_imap->imap_response);
54 mailimap_free( m_imap ); 54 mailimap_free( m_imap );
55 m_imap = 0; 55 m_imap = 0;
56 return; 56 return;
57 } 57 }
58 58
59 /* login */ 59 /* login */
60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
61 if ( err != MAILIMAP_NO_ERROR ) { 61 if ( err != MAILIMAP_NO_ERROR ) {
62 qDebug("error logging in imap: %s",m_imap->imap_response); 62 qDebug("error logging in imap: %s",m_imap->imap_response);
63 err = mailimap_close( m_imap ); 63 err = mailimap_close( m_imap );
64 mailimap_free( m_imap ); 64 mailimap_free( m_imap );
65 m_imap = 0; 65 m_imap = 0;
66 } 66 }
67} 67}
68 68
69void IMAPwrapper::logout() 69void IMAPwrapper::logout()
70{ 70{
71 int err = MAILIMAP_NO_ERROR; 71 int err = MAILIMAP_NO_ERROR;
72 if (!m_imap) return; 72 if (!m_imap) return;
73 err = mailimap_logout( m_imap ); 73 err = mailimap_logout( m_imap );
74 err = mailimap_close( m_imap ); 74 err = mailimap_close( m_imap );
75 mailimap_free( m_imap ); 75 mailimap_free( m_imap );
76 m_imap = 0; 76 m_imap = 0;
77} 77}
78 78
79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
80{ 80{
81 const char *mb; 81 const char *mb;
82 int err = MAILIMAP_NO_ERROR; 82 int err = MAILIMAP_NO_ERROR;
83 clist *result; 83 clist *result;
84 clistcell *current; 84 clistcell *current;
85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
86 mailimap_fetch_type *fetchType; 86 mailimap_fetch_type *fetchType;
87 mailimap_set *set; 87 mailimap_set *set;
88 88
89 mb = mailbox.latin1(); 89 mb = mailbox.latin1();
90 login(); 90 login();
91 if (!m_imap) { 91 if (!m_imap) {
92 return; 92 return;
93 } 93 }
94 /* select mailbox READONLY for operations */ 94 /* select mailbox READONLY for operations */
95 err = mailimap_examine( m_imap, (char*)mb); 95 err = mailimap_examine( m_imap, (char*)mb);
96 if ( err != MAILIMAP_NO_ERROR ) { 96 if ( err != MAILIMAP_NO_ERROR ) {
97 qDebug("error selecting mailbox: %s",m_imap->imap_response); 97 qDebug("error selecting mailbox: %s",m_imap->imap_response);
98 return; 98 return;
99 } 99 }
100 100
101 int last = m_imap->imap_selection_info->sel_exists; 101 int last = m_imap->imap_selection_info->sel_exists;
102 102
103 if (last == 0) { 103 if (last == 0) {
104 qDebug("mailbox has no mails"); 104 qDebug("mailbox has no mails");
105 return; 105 return;
106 } 106 }
107 107
108 result = clist_new(); 108 result = clist_new();
109 /* the range has to start at 1!!! not with 0!!!! */ 109 /* the range has to start at 1!!! not with 0!!!! */
110 set = mailimap_set_new_interval( 1, last ); 110 set = mailimap_set_new_interval( 1, last );
111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
116 116
117 err = mailimap_fetch( m_imap, set, fetchType, &result ); 117 err = mailimap_fetch( m_imap, set, fetchType, &result );
118 mailimap_set_free( set ); 118 mailimap_set_free( set );
119 mailimap_fetch_type_free( fetchType ); 119 mailimap_fetch_type_free( fetchType );
120 120
121 QString date,subject,from; 121 QString date,subject,from;
122 122
123 if ( err == MAILIMAP_NO_ERROR ) { 123 if ( err == MAILIMAP_NO_ERROR ) {
124 124
125 mailimap_msg_att * msg_att; 125 mailimap_msg_att * msg_att;
126 int i = 0; 126 int i = 0;
127 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 127 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
128 ++i; 128 ++i;
129 msg_att = (mailimap_msg_att*)current->data; 129 msg_att = (mailimap_msg_att*)current->data;
130 RecMail*m = parse_list_result(msg_att); 130 RecMail*m = parse_list_result(msg_att);
131 if (m) { 131 if (m) {
132 m->setNumber(i); 132 m->setNumber(i);
133 m->setMbox(mailbox); 133 m->setMbox(mailbox);
134 m->setWrapper(this); 134 m->setWrapper(this);
135 target.append(m); 135 target.append(m);
136 } 136 }
137 } 137 }
138 } else { 138 } else {
139 qDebug("Error fetching headers: %s",m_imap->imap_response); 139 qDebug("Error fetching headers: %s",m_imap->imap_response);
140 } 140 }
141 mailimap_fetch_list_free(result); 141 mailimap_fetch_list_free(result);
142} 142}
143 143
144QList<Folder>* IMAPwrapper::listFolders() 144QList<Folder>* IMAPwrapper::listFolders()
145{ 145{
146 const char *path, *mask; 146 const char *path, *mask;
147 int err = MAILIMAP_NO_ERROR; 147 int err = MAILIMAP_NO_ERROR;
148 clist *result; 148 clist *result;
149 clistcell *current; 149 clistcell *current;
150 150
151 QList<Folder> * folders = new QList<Folder>(); 151 QList<Folder> * folders = new QList<Folder>();
152 folders->setAutoDelete( false ); 152 folders->setAutoDelete( false );
153 login(); 153 login();
154 if (!m_imap) { 154 if (!m_imap) {
155 return folders; 155 return folders;
156 } 156 }
157 157
158/* 158/*
159 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 159 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
160 * We must not forget to filter them out in next loop! 160 * We must not forget to filter them out in next loop!
161 * it seems like ugly code. and yes - it is ugly code. but the best way. 161 * it seems like ugly code. and yes - it is ugly code. but the best way.
162 */ 162 */
163 QString temp; 163 QString temp;
164 mask = "INBOX" ; 164 mask = "INBOX" ;
165 result = clist_new(); 165 result = clist_new();
166 mailimap_mailbox_list *list; 166 mailimap_mailbox_list *list;
167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
168 QString del;
168 if ( err == MAILIMAP_NO_ERROR ) { 169 if ( err == MAILIMAP_NO_ERROR ) {
169 current = result->first; 170 current = result->first;
170 for ( int i = result->count; i > 0; i-- ) { 171 for ( int i = result->count; i > 0; i-- ) {
171 list = (mailimap_mailbox_list *) current->data; 172 list = (mailimap_mailbox_list *) current->data;
172 // it is better use the deep copy mechanism of qt itself 173 // it is better use the deep copy mechanism of qt itself
173 // instead of using strdup! 174 // instead of using strdup!
174 temp = list->mb_name; 175 temp = list->mb_name;
175 folders->append( new IMAPFolder(temp)); 176 del = list->mb_delimiter;
177 folders->append( new IMAPFolder(temp,del,true,account->getPrefix()));
176 current = current->next; 178 current = current->next;
177 } 179 }
178 } else { 180 } else {
179 qDebug("error fetching folders: %s",m_imap->imap_response); 181 qDebug("error fetching folders: %s",m_imap->imap_response);
180 } 182 }
181 mailimap_list_result_free( result ); 183 mailimap_list_result_free( result );
182 184
183/* 185/*
184 * second stage - get the other then inbox folders 186 * second stage - get the other then inbox folders
185 */ 187 */
186 mask = "*" ; 188 mask = "*" ;
187 path = account->getPrefix().latin1(); 189 path = account->getPrefix().latin1();
188 if (!path) path = ""; 190 if (!path) path = "";
189 result = clist_new(); 191 result = clist_new();
190 qDebug(path); 192 qDebug(path);
191 bool selectable = true; 193 bool selectable = true;
192 mailimap_mbx_list_flags*bflags; 194 mailimap_mbx_list_flags*bflags;
193 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 195 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
194 if ( err == MAILIMAP_NO_ERROR ) { 196 if ( err == MAILIMAP_NO_ERROR ) {
195 current = result->first; 197 current = result->first;
196 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 198 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
197 list = (mailimap_mailbox_list *) current->data; 199 list = (mailimap_mailbox_list *) current->data;
198 // it is better use the deep copy mechanism of qt itself 200 // it is better use the deep copy mechanism of qt itself
199 // instead of using strdup! 201 // instead of using strdup!
200 temp = list->mb_name; 202 temp = list->mb_name;
201 if (temp.lower()=="inbox") 203 if (temp.lower()=="inbox")
202 continue; 204 continue;
203 if (temp.lower()==account->getPrefix().lower()) 205 if (temp.lower()==account->getPrefix().lower())
204 continue; 206 continue;
205 if ( (bflags = list->mb_flag) ) { 207 if ( (bflags = list->mb_flag) ) {
206 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 208 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
207 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 209 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
208 } 210 }
209 folders->append(new IMAPFolder(temp,selectable,account->getPrefix())); 211 del = list->mb_delimiter;
212 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix()));
210 } 213 }
211 } else { 214 } else {
212 qDebug("error fetching folders %s",m_imap->imap_response); 215 qDebug("error fetching folders %s",m_imap->imap_response);
213 } 216 }
214 mailimap_list_result_free( result ); 217 mailimap_list_result_free( result );
215 return folders; 218 return folders;
216} 219}
217 220
218RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 221RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
219{ 222{
220 RecMail * m = 0; 223 RecMail * m = 0;
221 mailimap_msg_att_item *item=0; 224 mailimap_msg_att_item *item=0;
222 clistcell *current,*c,*cf; 225 clistcell *current,*c,*cf;
223 mailimap_msg_att_dynamic*flist; 226 mailimap_msg_att_dynamic*flist;
224 mailimap_flag_fetch*cflag; 227 mailimap_flag_fetch*cflag;
225 int size; 228 int size;
226 QBitArray mFlags(7); 229 QBitArray mFlags(7);
227 QStringList addresslist; 230 QStringList addresslist;
228 231
229 if (!m_att) { 232 if (!m_att) {
230 return m; 233 return m;
231 } 234 }
232 m = new RecMail(); 235 m = new RecMail();
233 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 236 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
234 current = c; 237 current = c;
235 size = 0; 238 size = 0;
236 item = (mailimap_msg_att_item*)current->data; 239 item = (mailimap_msg_att_item*)current->data;
237 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 240 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
238 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 241 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
239 if (!flist->att_list) { 242 if (!flist->att_list) {
240 continue; 243 continue;
241 } 244 }
242 cf = flist->att_list->first; 245 cf = flist->att_list->first;
243 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 246 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
244 cflag = (mailimap_flag_fetch*)cf->data; 247 cflag = (mailimap_flag_fetch*)cf->data;
245 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 248 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
246 switch (cflag->fl_flag->fl_type) { 249 switch (cflag->fl_flag->fl_type) {
247 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 250 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
248 mFlags.setBit(FLAG_ANSWERED); 251 mFlags.setBit(FLAG_ANSWERED);
249 break; 252 break;
250 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 253 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
251 mFlags.setBit(FLAG_FLAGGED); 254 mFlags.setBit(FLAG_FLAGGED);
252 break; 255 break;
253 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 256 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
254 mFlags.setBit(FLAG_DELETED); 257 mFlags.setBit(FLAG_DELETED);
255 break; 258 break;
256 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 259 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
257 mFlags.setBit(FLAG_SEEN); 260 mFlags.setBit(FLAG_SEEN);
258 break; 261 break;
259 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 262 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
260 mFlags.setBit(FLAG_DRAFT); 263 mFlags.setBit(FLAG_DRAFT);
261 break; 264 break;
262 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 265 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
263 break; 266 break;
264 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 267 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
265 break; 268 break;
266 default: 269 default:
267 break; 270 break;
268 } 271 }
269 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 272 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
270 mFlags.setBit(FLAG_RECENT); 273 mFlags.setBit(FLAG_RECENT);
271 } 274 }
272 } 275 }
273 continue; 276 continue;
274 } 277 }
275 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 278 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
276 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 279 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
277 m->setDate(head->env_date); 280 m->setDate(head->env_date);
278 m->setSubject(head->env_subject); 281 m->setSubject(head->env_subject);
279 if (head->env_from!=NULL) { 282 if (head->env_from!=NULL) {
280 addresslist = address_list_to_stringlist(head->env_from->frm_list); 283 addresslist = address_list_to_stringlist(head->env_from->frm_list);
281 if (addresslist.count()) { 284 if (addresslist.count()) {
282 m->setFrom(addresslist.first()); 285 m->setFrom(addresslist.first());
283 } 286 }
284 } 287 }
285 if (head->env_to!=NULL) { 288 if (head->env_to!=NULL) {
286 addresslist = address_list_to_stringlist(head->env_to->to_list); 289 addresslist = address_list_to_stringlist(head->env_to->to_list);
287 m->setTo(addresslist); 290 m->setTo(addresslist);
288 } 291 }
289 if (head->env_cc!=NULL) { 292 if (head->env_cc!=NULL) {
290 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 293 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
291 m->setCC(addresslist); 294 m->setCC(addresslist);
292 } 295 }
293 if (head->env_bcc!=NULL) { 296 if (head->env_bcc!=NULL) {
294 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 297 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
295 m->setBcc(addresslist); 298 m->setBcc(addresslist);
296 } 299 }
297 if (head->env_reply_to!=NULL) { 300 if (head->env_reply_to!=NULL) {
298 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 301 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
299 if (addresslist.count()) { 302 if (addresslist.count()) {
300 m->setReplyto(addresslist.first()); 303 m->setReplyto(addresslist.first());
301 } 304 }
302 } 305 }
303 m->setMsgid(QString(head->env_message_id)); 306 m->setMsgid(QString(head->env_message_id));
304 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 307 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
305#if 0 308#if 0
306 309
307 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 310 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
308 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 311 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
309 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); 312 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);
310 qDebug(da.toString()); 313 qDebug(da.toString());
311#endif 314#endif
312 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 315 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
313 size = item->att_data.att_static->att_data.att_rfc822_size; 316 size = item->att_data.att_static->att_data.att_rfc822_size;
314 } 317 }
315 } 318 }
316 /* msg is already deleted */ 319 /* msg is already deleted */
317 if (mFlags.testBit(FLAG_DELETED) && m) { 320 if (mFlags.testBit(FLAG_DELETED) && m) {
318 delete m; 321 delete m;
319 m = 0; 322 m = 0;
320 } 323 }
321 if (m) { 324 if (m) {
322 m->setFlags(mFlags); 325 m->setFlags(mFlags);
323 m->setMsgsize(size); 326 m->setMsgsize(size);
324 } 327 }
325 return m; 328 return m;
326} 329}
327 330
328RecBody IMAPwrapper::fetchBody(const RecMail&mail) 331RecBody IMAPwrapper::fetchBody(const RecMail&mail)
329{ 332{
330 RecBody body; 333 RecBody body;
331 const char *mb; 334 const char *mb;
332 int err = MAILIMAP_NO_ERROR; 335 int err = MAILIMAP_NO_ERROR;
333 clist *result; 336 clist *result;
334 clistcell *current; 337 clistcell *current;
335 mailimap_fetch_att *fetchAtt; 338 mailimap_fetch_att *fetchAtt;
336 mailimap_fetch_type *fetchType; 339 mailimap_fetch_type *fetchType;
337 mailimap_set *set; 340 mailimap_set *set;
338 mailimap_body*body_desc; 341 mailimap_body*body_desc;
339 342
340 mb = mail.getMbox().latin1(); 343 mb = mail.getMbox().latin1();
341 344
342 login(); 345 login();
343 if (!m_imap) { 346 if (!m_imap) {
344 return body; 347 return body;
345 } 348 }
346 349
347 err = mailimap_select( m_imap, (char*)mb); 350 err = mailimap_select( m_imap, (char*)mb);
348 if ( err != MAILIMAP_NO_ERROR ) { 351 if ( err != MAILIMAP_NO_ERROR ) {
349 qDebug("error selecting mailbox: %s",m_imap->imap_response); 352 qDebug("error selecting mailbox: %s",m_imap->imap_response);
350 return body; 353 return body;
351 } 354 }
352 355
353 result = clist_new(); 356 result = clist_new();
354 /* the range has to start at 1!!! not with 0!!!! */ 357 /* the range has to start at 1!!! not with 0!!!! */
355 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 358 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
356 fetchAtt = mailimap_fetch_att_new_bodystructure(); 359 fetchAtt = mailimap_fetch_att_new_bodystructure();
357 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 360 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
358 err = mailimap_fetch( m_imap, set, fetchType, &result ); 361 err = mailimap_fetch( m_imap, set, fetchType, &result );
359 mailimap_set_free( set ); 362 mailimap_set_free( set );
360 mailimap_fetch_type_free( fetchType ); 363 mailimap_fetch_type_free( fetchType );
361 364
362 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 365 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
363 mailimap_msg_att * msg_att; 366 mailimap_msg_att * msg_att;
364 msg_att = (mailimap_msg_att*)current->data; 367 msg_att = (mailimap_msg_att*)current->data;
365 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 368 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
366 body_desc = item->att_data.att_static->att_data.att_body; 369 body_desc = item->att_data.att_static->att_data.att_body;
367 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 370 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
368 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 371 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
369 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 372 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
370 qDebug("Mulitpart mail"); 373 qDebug("Mulitpart mail");
371 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 374 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
372 } 375 }
373 } else { 376 } else {
374 qDebug("error fetching body: %s",m_imap->imap_response); 377 qDebug("error fetching body: %s",m_imap->imap_response);
375 } 378 }
376 mailimap_fetch_list_free(result); 379 mailimap_fetch_list_free(result);
377 return body; 380 return body;
378} 381}
379 382
380/* this routine is just called when the mail has only ONE part. 383/* this routine is just called when the mail has only ONE part.
381 for filling the parts of a multi-part-message there are other 384 for filling the parts of a multi-part-message there are other
382 routines 'cause we can not simply fetch the whole body. */ 385 routines 'cause we can not simply fetch the whole body. */
383void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 386void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
384{ 387{
385 if (!mailDescription) { 388 if (!mailDescription) {
386 return; 389 return;
387 } 390 }
388 QString sub,body_text; 391 QString sub,body_text;
389 RecPart singlePart; 392 RecPart singlePart;
390 QValueList<int> path; 393 QValueList<int> path;
391 fillSinglePart(singlePart,mailDescription); 394 fillSinglePart(singlePart,mailDescription);
392 switch (mailDescription->bd_type) { 395 switch (mailDescription->bd_type) {
393 case MAILIMAP_BODY_TYPE_1PART_MSG: 396 case MAILIMAP_BODY_TYPE_1PART_MSG:
394 path.append(1); 397 path.append(1);
395 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 398 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
396 target_body.setBodytext(body_text); 399 target_body.setBodytext(body_text);
397 target_body.setDescription(singlePart); 400 target_body.setDescription(singlePart);
398 break; 401 break;
399 case MAILIMAP_BODY_TYPE_1PART_TEXT: 402 case MAILIMAP_BODY_TYPE_1PART_TEXT:
400 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 403 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
401 path.append(1); 404 path.append(1);
402 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 405 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
403 target_body.setBodytext(body_text); 406 target_body.setBodytext(body_text);
404 target_body.setDescription(singlePart); 407 target_body.setDescription(singlePart);
405 break; 408 break;
406 case MAILIMAP_BODY_TYPE_1PART_BASIC: 409 case MAILIMAP_BODY_TYPE_1PART_BASIC:
407 qDebug("Single attachment"); 410 qDebug("Single attachment");
408 target_body.setBodytext(""); 411 target_body.setBodytext("");
409 target_body.addPart(singlePart); 412 target_body.addPart(singlePart);
410 break; 413 break;
411 default: 414 default:
412 break; 415 break;
413 } 416 }
414 417
415 return; 418 return;
416} 419}
417 420
418QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 421QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
419{ 422{
420 QStringList l; 423 QStringList l;
421 QString from; 424 QString from;
422 bool named_from; 425 bool named_from;
423 clistcell *current = NULL; 426 clistcell *current = NULL;
424 mailimap_address * current_address=NULL; 427 mailimap_address * current_address=NULL;
425 if (!list) { 428 if (!list) {
426 return l; 429 return l;
427 } 430 }
428 unsigned int count = 0; 431 unsigned int count = 0;
429 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 432 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
430 from = ""; 433 from = "";
431 named_from = false; 434 named_from = false;
432 current_address=(mailimap_address*)current->data; 435 current_address=(mailimap_address*)current->data;
433 if (current_address->ad_personal_name){ 436 if (current_address->ad_personal_name){
434 from+=QString(current_address->ad_personal_name); 437 from+=QString(current_address->ad_personal_name);
435 from+=" "; 438 from+=" ";
436 named_from = true; 439 named_from = true;
437 } 440 }
438 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 441 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
439 from+="<"; 442 from+="<";
440 } 443 }
441 if (current_address->ad_mailbox_name) { 444 if (current_address->ad_mailbox_name) {
442 from+=QString(current_address->ad_mailbox_name); 445 from+=QString(current_address->ad_mailbox_name);
443 from+="@"; 446 from+="@";
444 } 447 }
445 if (current_address->ad_host_name) { 448 if (current_address->ad_host_name) {
446 from+=QString(current_address->ad_host_name); 449 from+=QString(current_address->ad_host_name);
447 } 450 }
448 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 451 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
449 from+=">"; 452 from+=">";
450 } 453 }
451 l.append(QString(from)); 454 l.append(QString(from));
452 if (++count > 99) { 455 if (++count > 99) {
453 break; 456 break;
454 } 457 }
455 } 458 }
456 return l; 459 return l;
457} 460}
458 461
459encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 462encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
460{ 463{
461 encodedString*res=new encodedString; 464 encodedString*res=new encodedString;
462 const char*mb; 465 const char*mb;
463 int err; 466 int err;
464 mailimap_fetch_type *fetchType; 467 mailimap_fetch_type *fetchType;
465 mailimap_set *set; 468 mailimap_set *set;
466 clistcell*current,*cur; 469 clistcell*current,*cur;
467 470
468 login(); 471 login();
469 if (!m_imap) { 472 if (!m_imap) {
470 return res; 473 return res;
471 } 474 }
472 if (!internal_call) { 475 if (!internal_call) {
473 mb = mail.getMbox().latin1(); 476 mb = mail.getMbox().latin1();
474 err = mailimap_select( m_imap, (char*)mb); 477 err = mailimap_select( m_imap, (char*)mb);
475 if ( err != MAILIMAP_NO_ERROR ) { 478 if ( err != MAILIMAP_NO_ERROR ) {
476 qDebug("error selecting mailbox: %s",m_imap->imap_response); 479 qDebug("error selecting mailbox: %s",m_imap->imap_response);
477 return res; 480 return res;
478 } 481 }
479 } 482 }
480 set = mailimap_set_new_single(mail.getNumber()); 483 set = mailimap_set_new_single(mail.getNumber());
481 clist*id_list=clist_new(); 484 clist*id_list=clist_new();
482 for (unsigned j=0; j < path.count();++j) { 485 for (unsigned j=0; j < path.count();++j) {
483 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 486 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
484 *p_id = path[j]; 487 *p_id = path[j];
485 clist_append(id_list,p_id); 488 clist_append(id_list,p_id);
486 } 489 }
487 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 490 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
488 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 491 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
489 mailimap_section * section = mailimap_section_new(section_spec); 492 mailimap_section * section = mailimap_section_new(section_spec);
490 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 493 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
491 494
492 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 495 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
493 496
494 clist*result = clist_new(); 497 clist*result = clist_new();
495 498
496 err = mailimap_fetch( m_imap, set, fetchType, &result ); 499 err = mailimap_fetch( m_imap, set, fetchType, &result );
497 mailimap_set_free( set ); 500 mailimap_set_free( set );
498 mailimap_fetch_type_free( fetchType ); 501 mailimap_fetch_type_free( fetchType );
499 502
500 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 503 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
501 mailimap_msg_att * msg_att; 504 mailimap_msg_att * msg_att;
502 msg_att = (mailimap_msg_att*)current->data; 505 msg_att = (mailimap_msg_att*)current->data;
503 mailimap_msg_att_item*msg_att_item; 506 mailimap_msg_att_item*msg_att_item;
504 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 507 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
505 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 508 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
506 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 509 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
507 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 510 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
508 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 511 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
509 /* detach - we take over the content */ 512 /* detach - we take over the content */
510 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 513 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
511 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 514 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
512 } 515 }
513 } 516 }
514 } 517 }
515 } else { 518 } else {
516 qDebug("error fetching text: %s",m_imap->imap_response); 519 qDebug("error fetching text: %s",m_imap->imap_response);
517 } 520 }
518 mailimap_fetch_list_free(result); 521 mailimap_fetch_list_free(result);
519 return res; 522 return res;
520} 523}
521 524
522void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 525void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
523{ 526{
524 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 527 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
525 if (!mailDescription||current_recursion==10) { 528 if (!mailDescription||current_recursion==10) {
526 return; 529 return;
527 } 530 }
528 clistcell*current; 531 clistcell*current;
529 mailimap_body*current_body; 532 mailimap_body*current_body;
530 unsigned int count = 0; 533 unsigned int count = 0;
531 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 534 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
532 /* the point in the message */ 535 /* the point in the message */
533 ++count; 536 ++count;
534 current_body = (mailimap_body*)current->data; 537 current_body = (mailimap_body*)current->data;
535 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 538 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
536 QValueList<int>clist = recList; 539 QValueList<int>clist = recList;
537 clist.append(count); 540 clist.append(count);
538 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 541 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
539 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 542 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
540 RecPart currentPart; 543 RecPart currentPart;
541 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 544 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
542 QValueList<int>clist = recList; 545 QValueList<int>clist = recList;
543 clist.append(count); 546 clist.append(count);
544 /* important: Check for is NULL 'cause a body can be empty! */ 547 /* important: Check for is NULL 'cause a body can be empty! */
545 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 548 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
546 QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding()); 549 QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding());
547 target_body.setDescription(currentPart); 550 target_body.setDescription(currentPart);
548 target_body.setBodytext(body_text); 551 target_body.setBodytext(body_text);
549 } else { 552 } else {
550 QString id(""); 553 QString id("");
551 for (unsigned int j = 0; j < clist.count();++j) { 554 for (unsigned int j = 0; j < clist.count();++j) {
552 id+=(j>0?" ":""); 555 id+=(j>0?" ":"");
553 id+=QString("%1").arg(clist[j]); 556 id+=QString("%1").arg(clist[j]);
554 } 557 }
555 qDebug("ID= %s",id.latin1()); 558 qDebug("ID= %s",id.latin1());
556 currentPart.setIdentifier(id); 559 currentPart.setIdentifier(id);
557 currentPart.setPositionlist(clist); 560 currentPart.setPositionlist(clist);
558 target_body.addPart(currentPart); 561 target_body.addPart(currentPart);
559 } 562 }
560 } 563 }
561 } 564 }
562} 565}
563 566
564void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 567void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
565{ 568{
566 if (!Description) { 569 if (!Description) {
567 return; 570 return;
568 } 571 }
569 switch (Description->bd_type) { 572 switch (Description->bd_type) {
570 case MAILIMAP_BODY_TYPE_1PART_TEXT: 573 case MAILIMAP_BODY_TYPE_1PART_TEXT:
571 target_part.setType("text"); 574 target_part.setType("text");
572 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 575 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
573 break; 576 break;
574 case MAILIMAP_BODY_TYPE_1PART_BASIC: 577 case MAILIMAP_BODY_TYPE_1PART_BASIC:
575 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 578 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
576 break; 579 break;
577 case MAILIMAP_BODY_TYPE_1PART_MSG: 580 case MAILIMAP_BODY_TYPE_1PART_MSG:
578 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 581 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
579 break; 582 break;
580 default: 583 default:
581 break; 584 break;
582 } 585 }
583} 586}
584 587
585void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 588void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
586{ 589{
587 if (!which) { 590 if (!which) {
588 return; 591 return;
589 } 592 }
590 QString sub; 593 QString sub;
591 sub = which->bd_media_text; 594 sub = which->bd_media_text;
592 target_part.setSubtype(sub.lower()); 595 target_part.setSubtype(sub.lower());
593 target_part.setLines(which->bd_lines); 596 target_part.setLines(which->bd_lines);
594 fillBodyFields(target_part,which->bd_fields); 597 fillBodyFields(target_part,which->bd_fields);
595} 598}
596 599
597void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 600void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
598{ 601{
599 if (!which) { 602 if (!which) {
600 return; 603 return;
601 } 604 }
602// QString sub; 605// QString sub;
603// sub = which->bd_media_text; 606// sub = which->bd_media_text;
604// target_part.setSubtype(sub.lower()); 607// target_part.setSubtype(sub.lower());
605 qDebug("Message part"); 608 qDebug("Message part");
606 /* we set this type to text/plain */ 609 /* we set this type to text/plain */
607 target_part.setType("text"); 610 target_part.setType("text");
608 target_part.setSubtype("plain"); 611 target_part.setSubtype("plain");
609 target_part.setLines(which->bd_lines); 612 target_part.setLines(which->bd_lines);
610 fillBodyFields(target_part,which->bd_fields); 613 fillBodyFields(target_part,which->bd_fields);
611} 614}
612 615
613void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 616void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
614{ 617{
615 if (!which) { 618 if (!which) {
616 return; 619 return;
617 } 620 }
618 QString type,sub; 621 QString type,sub;
619 switch (which->bd_media_basic->med_type) { 622 switch (which->bd_media_basic->med_type) {
620 case MAILIMAP_MEDIA_BASIC_APPLICATION: 623 case MAILIMAP_MEDIA_BASIC_APPLICATION:
621 type = "application"; 624 type = "application";
622 break; 625 break;
623 case MAILIMAP_MEDIA_BASIC_AUDIO: 626 case MAILIMAP_MEDIA_BASIC_AUDIO:
624 type = "audio"; 627 type = "audio";
625 break; 628 break;
626 case MAILIMAP_MEDIA_BASIC_IMAGE: 629 case MAILIMAP_MEDIA_BASIC_IMAGE:
627 type = "image"; 630 type = "image";
628 break; 631 break;
629 case MAILIMAP_MEDIA_BASIC_MESSAGE: 632 case MAILIMAP_MEDIA_BASIC_MESSAGE:
630 type = "message"; 633 type = "message";
631 break; 634 break;
632 case MAILIMAP_MEDIA_BASIC_VIDEO: 635 case MAILIMAP_MEDIA_BASIC_VIDEO:
633 type = "video"; 636 type = "video";
634 break; 637 break;
635 case MAILIMAP_MEDIA_BASIC_OTHER: 638 case MAILIMAP_MEDIA_BASIC_OTHER:
636 default: 639 default:
637 if (which->bd_media_basic->med_basic_type) { 640 if (which->bd_media_basic->med_basic_type) {
638 type = which->bd_media_basic->med_basic_type; 641 type = which->bd_media_basic->med_basic_type;
639 } else { 642 } else {
640 type = ""; 643 type = "";
641 } 644 }
642 break; 645 break;
643 } 646 }
644 if (which->bd_media_basic->med_subtype) { 647 if (which->bd_media_basic->med_subtype) {
645 sub = which->bd_media_basic->med_subtype; 648 sub = which->bd_media_basic->med_subtype;
646 } else { 649 } else {
647 sub = ""; 650 sub = "";
648 } 651 }
649 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 652 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
650 target_part.setType(type.lower()); 653 target_part.setType(type.lower());
651 target_part.setSubtype(sub.lower()); 654 target_part.setSubtype(sub.lower());
652 fillBodyFields(target_part,which->bd_fields); 655 fillBodyFields(target_part,which->bd_fields);
653} 656}
654 657
655void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 658void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
656{ 659{
657 if (!which) return; 660 if (!which) return;
658 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 661 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
659 clistcell*cur; 662 clistcell*cur;
660 mailimap_single_body_fld_param*param=0; 663 mailimap_single_body_fld_param*param=0;
661 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 664 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
662 param = (mailimap_single_body_fld_param*)cur->data; 665 param = (mailimap_single_body_fld_param*)cur->data;
663 if (param) { 666 if (param) {
664 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 667 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
665 } 668 }
666 } 669 }
667 } 670 }
668 mailimap_body_fld_enc*enc = which->bd_encoding; 671 mailimap_body_fld_enc*enc = which->bd_encoding;
669 QString encoding(""); 672 QString encoding("");
670 switch (enc->enc_type) { 673 switch (enc->enc_type) {
671 case MAILIMAP_BODY_FLD_ENC_7BIT: 674 case MAILIMAP_BODY_FLD_ENC_7BIT:
672 encoding = "7bit"; 675 encoding = "7bit";
673 break; 676 break;
674 case MAILIMAP_BODY_FLD_ENC_8BIT: 677 case MAILIMAP_BODY_FLD_ENC_8BIT:
675 encoding = "8bit"; 678 encoding = "8bit";
676 break; 679 break;
677 case MAILIMAP_BODY_FLD_ENC_BINARY: 680 case MAILIMAP_BODY_FLD_ENC_BINARY:
678 encoding="binary"; 681 encoding="binary";
679 break; 682 break;
680 case MAILIMAP_BODY_FLD_ENC_BASE64: 683 case MAILIMAP_BODY_FLD_ENC_BASE64:
681 encoding="base64"; 684 encoding="base64";
682 break; 685 break;
683 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 686 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
684 encoding="quoted-printable"; 687 encoding="quoted-printable";
685 break; 688 break;
686 case MAILIMAP_BODY_FLD_ENC_OTHER: 689 case MAILIMAP_BODY_FLD_ENC_OTHER:
687 default: 690 default:
688 if (enc->enc_value) { 691 if (enc->enc_value) {
689 char*t=enc->enc_value; 692 char*t=enc->enc_value;
690 encoding=QString(enc->enc_value); 693 encoding=QString(enc->enc_value);
691 enc->enc_value=0L; 694 enc->enc_value=0L;
692 free(t); 695 free(t);
693 } 696 }
694 } 697 }
695 if (which->bd_description) { 698 if (which->bd_description) {
696 target_part.setDescription(QString(which->bd_description)); 699 target_part.setDescription(QString(which->bd_description));
697 } 700 }
698 target_part.setEncoding(encoding); 701 target_part.setEncoding(encoding);
699 target_part.setSize(which->bd_size); 702 target_part.setSize(which->bd_size);
700} 703}
701 704
702void IMAPwrapper::deleteMail(const RecMail&mail) 705void IMAPwrapper::deleteMail(const RecMail&mail)
703{ 706{
704 mailimap_flag_list*flist; 707 mailimap_flag_list*flist;
705 mailimap_set *set; 708 mailimap_set *set;
706 mailimap_store_att_flags * store_flags; 709 mailimap_store_att_flags * store_flags;
707 int err; 710 int err;
708 login(); 711 login();
709 if (!m_imap) { 712 if (!m_imap) {
710 return; 713 return;
711 } 714 }
712 const char *mb = mail.getMbox().latin1(); 715 const char *mb = mail.getMbox().latin1();
713 err = mailimap_select( m_imap, (char*)mb); 716 err = mailimap_select( m_imap, (char*)mb);
714 if ( err != MAILIMAP_NO_ERROR ) { 717 if ( err != MAILIMAP_NO_ERROR ) {
715 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); 718 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
716 return; 719 return;
717 } 720 }
718 flist = mailimap_flag_list_new_empty(); 721 flist = mailimap_flag_list_new_empty();
719 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 722 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
720 store_flags = mailimap_store_att_flags_new_set_flags(flist); 723 store_flags = mailimap_store_att_flags_new_set_flags(flist);
721 set = mailimap_set_new_single(mail.getNumber()); 724 set = mailimap_set_new_single(mail.getNumber());
722 err = mailimap_store(m_imap,set,store_flags); 725 err = mailimap_store(m_imap,set,store_flags);
723 mailimap_set_free( set ); 726 mailimap_set_free( set );
724 mailimap_store_att_flags_free(store_flags); 727 mailimap_store_att_flags_free(store_flags);
725 728
726 if (err != MAILIMAP_NO_ERROR) { 729 if (err != MAILIMAP_NO_ERROR) {
727 qDebug("error deleting mail: %s",m_imap->imap_response); 730 qDebug("error deleting mail: %s",m_imap->imap_response);
728 return; 731 return;
729 } 732 }
730 qDebug("deleting mail: %s",m_imap->imap_response); 733 qDebug("deleting mail: %s",m_imap->imap_response);
731 /* should we realy do that at this moment? */ 734 /* should we realy do that at this moment? */
732 err = mailimap_expunge(m_imap); 735 err = mailimap_expunge(m_imap);
733 if (err != MAILIMAP_NO_ERROR) { 736 if (err != MAILIMAP_NO_ERROR) {
734 qDebug("error deleting mail: %s",m_imap->imap_response); 737 qDebug("error deleting mail: %s",m_imap->imap_response);
735 } 738 }
736 qDebug("Delete successfull %s",m_imap->imap_response); 739 qDebug("Delete successfull %s",m_imap->imap_response);
737} 740}
738 741
739void IMAPwrapper::answeredMail(const RecMail&mail) 742void IMAPwrapper::answeredMail(const RecMail&mail)
740{ 743{
741 mailimap_flag_list*flist; 744 mailimap_flag_list*flist;
742 mailimap_set *set; 745 mailimap_set *set;
743 mailimap_store_att_flags * store_flags; 746 mailimap_store_att_flags * store_flags;
744 int err; 747 int err;
745 login(); 748 login();
746 if (!m_imap) { 749 if (!m_imap) {
747 return; 750 return;
748 } 751 }
749 const char *mb = mail.getMbox().latin1(); 752 const char *mb = mail.getMbox().latin1();
750 err = mailimap_select( m_imap, (char*)mb); 753 err = mailimap_select( m_imap, (char*)mb);
751 if ( err != MAILIMAP_NO_ERROR ) { 754 if ( err != MAILIMAP_NO_ERROR ) {
752 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); 755 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response);
753 return; 756 return;
754 } 757 }
755 flist = mailimap_flag_list_new_empty(); 758 flist = mailimap_flag_list_new_empty();
756 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 759 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
757 store_flags = mailimap_store_att_flags_new_add_flags(flist); 760 store_flags = mailimap_store_att_flags_new_add_flags(flist);
758 set = mailimap_set_new_single(mail.getNumber()); 761 set = mailimap_set_new_single(mail.getNumber());
759 err = mailimap_store(m_imap,set,store_flags); 762 err = mailimap_store(m_imap,set,store_flags);
760 mailimap_set_free( set ); 763 mailimap_set_free( set );
761 mailimap_store_att_flags_free(store_flags); 764 mailimap_store_att_flags_free(store_flags);
762 765
763 if (err != MAILIMAP_NO_ERROR) { 766 if (err != MAILIMAP_NO_ERROR) {
764 qDebug("error marking mail: %s",m_imap->imap_response); 767 qDebug("error marking mail: %s",m_imap->imap_response);
765 return; 768 return;
766 } 769 }
767} 770}
768 771
769QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 772QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
770{ 773{
771 QString body(""); 774 QString body("");
772 encodedString*res = fetchRawPart(mail,path,internal_call); 775 encodedString*res = fetchRawPart(mail,path,internal_call);
773 encodedString*r = decode_String(res,enc); 776 encodedString*r = decode_String(res,enc);
774 delete res; 777 delete res;
775 if (r) { 778 if (r) {
776 if (r->Length()>0) { 779 if (r->Length()>0) {
777 body = r->Content(); 780 body = r->Content();
778 } 781 }
779 delete r; 782 delete r;
780 } 783 }
781 return body; 784 return body;
782} 785}
783 786
784QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 787QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
785{ 788{
786 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); 789 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
787} 790}
788 791
789encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) 792encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
790{ 793{
791 encodedString*res = fetchRawPart(mail,part.Positionlist(),false); 794 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
792 encodedString*r = decode_String(res,part.Encoding()); 795 encodedString*r = decode_String(res,part.Encoding());
793 delete res; 796 delete res;
794 return r; 797 return r;
795} 798}
796 799
797encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 800encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
798{ 801{
799 return fetchRawPart(mail,part.Positionlist(),false); 802 return fetchRawPart(mail,part.Positionlist(),false);
800} 803}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index d56d7f9..8a86c95 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,800 +1,803 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include "imapwrapper.h" 4#include "imapwrapper.h"
5#include "mailtypes.h" 5#include "mailtypes.h"
6#include <libetpan/mailimap.h> 6#include <libetpan/mailimap.h>
7 7
8IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 8IMAPwrapper::IMAPwrapper( IMAPaccount *a )
9 : AbstractMail() 9 : AbstractMail()
10{ 10{
11 account = a; 11 account = a;
12 m_imap = 0; 12 m_imap = 0;
13} 13}
14 14
15IMAPwrapper::~IMAPwrapper() 15IMAPwrapper::~IMAPwrapper()
16{ 16{
17 logout(); 17 logout();
18} 18}
19 19
20void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 20void IMAPwrapper::imap_progress( size_t current, size_t maximum )
21{ 21{
22 qDebug( "IMAP: %i of %i", current, maximum ); 22 qDebug( "IMAP: %i of %i", current, maximum );
23} 23}
24 24
25void IMAPwrapper::login() 25void IMAPwrapper::login()
26{ 26{
27 const char *server, *user, *pass; 27 const char *server, *user, *pass;
28 uint16_t port; 28 uint16_t port;
29 int err = MAILIMAP_NO_ERROR; 29 int err = MAILIMAP_NO_ERROR;
30 30
31 /* we are connected this moment */ 31 /* we are connected this moment */
32 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 32 /* TODO: setup a timer holding the line or if connection closed - delete the value */
33 if (m_imap) { 33 if (m_imap) {
34 mailstream_flush(m_imap->imap_stream); 34 mailstream_flush(m_imap->imap_stream);
35 return; 35 return;
36 } 36 }
37 server = account->getServer().latin1(); 37 server = account->getServer().latin1();
38 port = account->getPort().toUInt(); 38 port = account->getPort().toUInt();
39 user = account->getUser().latin1(); 39 user = account->getUser().latin1();
40 pass = account->getPassword().latin1(); 40 pass = account->getPassword().latin1();
41 41
42 m_imap = mailimap_new( 20, &imap_progress ); 42 m_imap = mailimap_new( 20, &imap_progress );
43 /* connect */ 43 /* connect */
44 if (account->getSSL()) { 44 if (account->getSSL()) {
45 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 45 err = mailimap_ssl_connect( m_imap, (char*)server, port );
46 } else { 46 } else {
47 err = mailimap_socket_connect( m_imap, (char*)server, port ); 47 err = mailimap_socket_connect( m_imap, (char*)server, port );
48 } 48 }
49 49
50 if ( err != MAILIMAP_NO_ERROR && 50 if ( err != MAILIMAP_NO_ERROR &&
51 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 51 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
53 qDebug("error connecting server: %s",m_imap->imap_response); 53 qDebug("error connecting server: %s",m_imap->imap_response);
54 mailimap_free( m_imap ); 54 mailimap_free( m_imap );
55 m_imap = 0; 55 m_imap = 0;
56 return; 56 return;
57 } 57 }
58 58
59 /* login */ 59 /* login */
60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
61 if ( err != MAILIMAP_NO_ERROR ) { 61 if ( err != MAILIMAP_NO_ERROR ) {
62 qDebug("error logging in imap: %s",m_imap->imap_response); 62 qDebug("error logging in imap: %s",m_imap->imap_response);
63 err = mailimap_close( m_imap ); 63 err = mailimap_close( m_imap );
64 mailimap_free( m_imap ); 64 mailimap_free( m_imap );
65 m_imap = 0; 65 m_imap = 0;
66 } 66 }
67} 67}
68 68
69void IMAPwrapper::logout() 69void IMAPwrapper::logout()
70{ 70{
71 int err = MAILIMAP_NO_ERROR; 71 int err = MAILIMAP_NO_ERROR;
72 if (!m_imap) return; 72 if (!m_imap) return;
73 err = mailimap_logout( m_imap ); 73 err = mailimap_logout( m_imap );
74 err = mailimap_close( m_imap ); 74 err = mailimap_close( m_imap );
75 mailimap_free( m_imap ); 75 mailimap_free( m_imap );
76 m_imap = 0; 76 m_imap = 0;
77} 77}
78 78
79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
80{ 80{
81 const char *mb; 81 const char *mb;
82 int err = MAILIMAP_NO_ERROR; 82 int err = MAILIMAP_NO_ERROR;
83 clist *result; 83 clist *result;
84 clistcell *current; 84 clistcell *current;
85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
86 mailimap_fetch_type *fetchType; 86 mailimap_fetch_type *fetchType;
87 mailimap_set *set; 87 mailimap_set *set;
88 88
89 mb = mailbox.latin1(); 89 mb = mailbox.latin1();
90 login(); 90 login();
91 if (!m_imap) { 91 if (!m_imap) {
92 return; 92 return;
93 } 93 }
94 /* select mailbox READONLY for operations */ 94 /* select mailbox READONLY for operations */
95 err = mailimap_examine( m_imap, (char*)mb); 95 err = mailimap_examine( m_imap, (char*)mb);
96 if ( err != MAILIMAP_NO_ERROR ) { 96 if ( err != MAILIMAP_NO_ERROR ) {
97 qDebug("error selecting mailbox: %s",m_imap->imap_response); 97 qDebug("error selecting mailbox: %s",m_imap->imap_response);
98 return; 98 return;
99 } 99 }
100 100
101 int last = m_imap->imap_selection_info->sel_exists; 101 int last = m_imap->imap_selection_info->sel_exists;
102 102
103 if (last == 0) { 103 if (last == 0) {
104 qDebug("mailbox has no mails"); 104 qDebug("mailbox has no mails");
105 return; 105 return;
106 } 106 }
107 107
108 result = clist_new(); 108 result = clist_new();
109 /* the range has to start at 1!!! not with 0!!!! */ 109 /* the range has to start at 1!!! not with 0!!!! */
110 set = mailimap_set_new_interval( 1, last ); 110 set = mailimap_set_new_interval( 1, last );
111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
116 116
117 err = mailimap_fetch( m_imap, set, fetchType, &result ); 117 err = mailimap_fetch( m_imap, set, fetchType, &result );
118 mailimap_set_free( set ); 118 mailimap_set_free( set );
119 mailimap_fetch_type_free( fetchType ); 119 mailimap_fetch_type_free( fetchType );
120 120
121 QString date,subject,from; 121 QString date,subject,from;
122 122
123 if ( err == MAILIMAP_NO_ERROR ) { 123 if ( err == MAILIMAP_NO_ERROR ) {
124 124
125 mailimap_msg_att * msg_att; 125 mailimap_msg_att * msg_att;
126 int i = 0; 126 int i = 0;
127 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 127 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
128 ++i; 128 ++i;
129 msg_att = (mailimap_msg_att*)current->data; 129 msg_att = (mailimap_msg_att*)current->data;
130 RecMail*m = parse_list_result(msg_att); 130 RecMail*m = parse_list_result(msg_att);
131 if (m) { 131 if (m) {
132 m->setNumber(i); 132 m->setNumber(i);
133 m->setMbox(mailbox); 133 m->setMbox(mailbox);
134 m->setWrapper(this); 134 m->setWrapper(this);
135 target.append(m); 135 target.append(m);
136 } 136 }
137 } 137 }
138 } else { 138 } else {
139 qDebug("Error fetching headers: %s",m_imap->imap_response); 139 qDebug("Error fetching headers: %s",m_imap->imap_response);
140 } 140 }
141 mailimap_fetch_list_free(result); 141 mailimap_fetch_list_free(result);
142} 142}
143 143
144QList<Folder>* IMAPwrapper::listFolders() 144QList<Folder>* IMAPwrapper::listFolders()
145{ 145{
146 const char *path, *mask; 146 const char *path, *mask;
147 int err = MAILIMAP_NO_ERROR; 147 int err = MAILIMAP_NO_ERROR;
148 clist *result; 148 clist *result;
149 clistcell *current; 149 clistcell *current;
150 150
151 QList<Folder> * folders = new QList<Folder>(); 151 QList<Folder> * folders = new QList<Folder>();
152 folders->setAutoDelete( false ); 152 folders->setAutoDelete( false );
153 login(); 153 login();
154 if (!m_imap) { 154 if (!m_imap) {
155 return folders; 155 return folders;
156 } 156 }
157 157
158/* 158/*
159 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 159 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
160 * We must not forget to filter them out in next loop! 160 * We must not forget to filter them out in next loop!
161 * it seems like ugly code. and yes - it is ugly code. but the best way. 161 * it seems like ugly code. and yes - it is ugly code. but the best way.
162 */ 162 */
163 QString temp; 163 QString temp;
164 mask = "INBOX" ; 164 mask = "INBOX" ;
165 result = clist_new(); 165 result = clist_new();
166 mailimap_mailbox_list *list; 166 mailimap_mailbox_list *list;
167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
168 QString del;
168 if ( err == MAILIMAP_NO_ERROR ) { 169 if ( err == MAILIMAP_NO_ERROR ) {
169 current = result->first; 170 current = result->first;
170 for ( int i = result->count; i > 0; i-- ) { 171 for ( int i = result->count; i > 0; i-- ) {
171 list = (mailimap_mailbox_list *) current->data; 172 list = (mailimap_mailbox_list *) current->data;
172 // it is better use the deep copy mechanism of qt itself 173 // it is better use the deep copy mechanism of qt itself
173 // instead of using strdup! 174 // instead of using strdup!
174 temp = list->mb_name; 175 temp = list->mb_name;
175 folders->append( new IMAPFolder(temp)); 176 del = list->mb_delimiter;
177 folders->append( new IMAPFolder(temp,del,true,account->getPrefix()));
176 current = current->next; 178 current = current->next;
177 } 179 }
178 } else { 180 } else {
179 qDebug("error fetching folders: %s",m_imap->imap_response); 181 qDebug("error fetching folders: %s",m_imap->imap_response);
180 } 182 }
181 mailimap_list_result_free( result ); 183 mailimap_list_result_free( result );
182 184
183/* 185/*
184 * second stage - get the other then inbox folders 186 * second stage - get the other then inbox folders
185 */ 187 */
186 mask = "*" ; 188 mask = "*" ;
187 path = account->getPrefix().latin1(); 189 path = account->getPrefix().latin1();
188 if (!path) path = ""; 190 if (!path) path = "";
189 result = clist_new(); 191 result = clist_new();
190 qDebug(path); 192 qDebug(path);
191 bool selectable = true; 193 bool selectable = true;
192 mailimap_mbx_list_flags*bflags; 194 mailimap_mbx_list_flags*bflags;
193 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 195 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
194 if ( err == MAILIMAP_NO_ERROR ) { 196 if ( err == MAILIMAP_NO_ERROR ) {
195 current = result->first; 197 current = result->first;
196 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 198 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
197 list = (mailimap_mailbox_list *) current->data; 199 list = (mailimap_mailbox_list *) current->data;
198 // it is better use the deep copy mechanism of qt itself 200 // it is better use the deep copy mechanism of qt itself
199 // instead of using strdup! 201 // instead of using strdup!
200 temp = list->mb_name; 202 temp = list->mb_name;
201 if (temp.lower()=="inbox") 203 if (temp.lower()=="inbox")
202 continue; 204 continue;
203 if (temp.lower()==account->getPrefix().lower()) 205 if (temp.lower()==account->getPrefix().lower())
204 continue; 206 continue;
205 if ( (bflags = list->mb_flag) ) { 207 if ( (bflags = list->mb_flag) ) {
206 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 208 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
207 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 209 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
208 } 210 }
209 folders->append(new IMAPFolder(temp,selectable,account->getPrefix())); 211 del = list->mb_delimiter;
212 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix()));
210 } 213 }
211 } else { 214 } else {
212 qDebug("error fetching folders %s",m_imap->imap_response); 215 qDebug("error fetching folders %s",m_imap->imap_response);
213 } 216 }
214 mailimap_list_result_free( result ); 217 mailimap_list_result_free( result );
215 return folders; 218 return folders;
216} 219}
217 220
218RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 221RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
219{ 222{
220 RecMail * m = 0; 223 RecMail * m = 0;
221 mailimap_msg_att_item *item=0; 224 mailimap_msg_att_item *item=0;
222 clistcell *current,*c,*cf; 225 clistcell *current,*c,*cf;
223 mailimap_msg_att_dynamic*flist; 226 mailimap_msg_att_dynamic*flist;
224 mailimap_flag_fetch*cflag; 227 mailimap_flag_fetch*cflag;
225 int size; 228 int size;
226 QBitArray mFlags(7); 229 QBitArray mFlags(7);
227 QStringList addresslist; 230 QStringList addresslist;
228 231
229 if (!m_att) { 232 if (!m_att) {
230 return m; 233 return m;
231 } 234 }
232 m = new RecMail(); 235 m = new RecMail();
233 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 236 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
234 current = c; 237 current = c;
235 size = 0; 238 size = 0;
236 item = (mailimap_msg_att_item*)current->data; 239 item = (mailimap_msg_att_item*)current->data;
237 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 240 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
238 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 241 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
239 if (!flist->att_list) { 242 if (!flist->att_list) {
240 continue; 243 continue;
241 } 244 }
242 cf = flist->att_list->first; 245 cf = flist->att_list->first;
243 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 246 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
244 cflag = (mailimap_flag_fetch*)cf->data; 247 cflag = (mailimap_flag_fetch*)cf->data;
245 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 248 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
246 switch (cflag->fl_flag->fl_type) { 249 switch (cflag->fl_flag->fl_type) {
247 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 250 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
248 mFlags.setBit(FLAG_ANSWERED); 251 mFlags.setBit(FLAG_ANSWERED);
249 break; 252 break;
250 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 253 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
251 mFlags.setBit(FLAG_FLAGGED); 254 mFlags.setBit(FLAG_FLAGGED);
252 break; 255 break;
253 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 256 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
254 mFlags.setBit(FLAG_DELETED); 257 mFlags.setBit(FLAG_DELETED);
255 break; 258 break;
256 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 259 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
257 mFlags.setBit(FLAG_SEEN); 260 mFlags.setBit(FLAG_SEEN);
258 break; 261 break;
259 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 262 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
260 mFlags.setBit(FLAG_DRAFT); 263 mFlags.setBit(FLAG_DRAFT);
261 break; 264 break;
262 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 265 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
263 break; 266 break;
264 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 267 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
265 break; 268 break;
266 default: 269 default:
267 break; 270 break;
268 } 271 }
269 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 272 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
270 mFlags.setBit(FLAG_RECENT); 273 mFlags.setBit(FLAG_RECENT);
271 } 274 }
272 } 275 }
273 continue; 276 continue;
274 } 277 }
275 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 278 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
276 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 279 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
277 m->setDate(head->env_date); 280 m->setDate(head->env_date);
278 m->setSubject(head->env_subject); 281 m->setSubject(head->env_subject);
279 if (head->env_from!=NULL) { 282 if (head->env_from!=NULL) {
280 addresslist = address_list_to_stringlist(head->env_from->frm_list); 283 addresslist = address_list_to_stringlist(head->env_from->frm_list);
281 if (addresslist.count()) { 284 if (addresslist.count()) {
282 m->setFrom(addresslist.first()); 285 m->setFrom(addresslist.first());
283 } 286 }
284 } 287 }
285 if (head->env_to!=NULL) { 288 if (head->env_to!=NULL) {
286 addresslist = address_list_to_stringlist(head->env_to->to_list); 289 addresslist = address_list_to_stringlist(head->env_to->to_list);
287 m->setTo(addresslist); 290 m->setTo(addresslist);
288 } 291 }
289 if (head->env_cc!=NULL) { 292 if (head->env_cc!=NULL) {
290 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 293 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
291 m->setCC(addresslist); 294 m->setCC(addresslist);
292 } 295 }
293 if (head->env_bcc!=NULL) { 296 if (head->env_bcc!=NULL) {
294 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 297 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
295 m->setBcc(addresslist); 298 m->setBcc(addresslist);
296 } 299 }
297 if (head->env_reply_to!=NULL) { 300 if (head->env_reply_to!=NULL) {
298 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 301 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
299 if (addresslist.count()) { 302 if (addresslist.count()) {
300 m->setReplyto(addresslist.first()); 303 m->setReplyto(addresslist.first());
301 } 304 }
302 } 305 }
303 m->setMsgid(QString(head->env_message_id)); 306 m->setMsgid(QString(head->env_message_id));
304 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 307 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
305#if 0 308#if 0
306 309
307 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 310 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
308 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 311 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
309 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); 312 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);
310 qDebug(da.toString()); 313 qDebug(da.toString());
311#endif 314#endif
312 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 315 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
313 size = item->att_data.att_static->att_data.att_rfc822_size; 316 size = item->att_data.att_static->att_data.att_rfc822_size;
314 } 317 }
315 } 318 }
316 /* msg is already deleted */ 319 /* msg is already deleted */
317 if (mFlags.testBit(FLAG_DELETED) && m) { 320 if (mFlags.testBit(FLAG_DELETED) && m) {
318 delete m; 321 delete m;
319 m = 0; 322 m = 0;
320 } 323 }
321 if (m) { 324 if (m) {
322 m->setFlags(mFlags); 325 m->setFlags(mFlags);
323 m->setMsgsize(size); 326 m->setMsgsize(size);
324 } 327 }
325 return m; 328 return m;
326} 329}
327 330
328RecBody IMAPwrapper::fetchBody(const RecMail&mail) 331RecBody IMAPwrapper::fetchBody(const RecMail&mail)
329{ 332{
330 RecBody body; 333 RecBody body;
331 const char *mb; 334 const char *mb;
332 int err = MAILIMAP_NO_ERROR; 335 int err = MAILIMAP_NO_ERROR;
333 clist *result; 336 clist *result;
334 clistcell *current; 337 clistcell *current;
335 mailimap_fetch_att *fetchAtt; 338 mailimap_fetch_att *fetchAtt;
336 mailimap_fetch_type *fetchType; 339 mailimap_fetch_type *fetchType;
337 mailimap_set *set; 340 mailimap_set *set;
338 mailimap_body*body_desc; 341 mailimap_body*body_desc;
339 342
340 mb = mail.getMbox().latin1(); 343 mb = mail.getMbox().latin1();
341 344
342 login(); 345 login();
343 if (!m_imap) { 346 if (!m_imap) {
344 return body; 347 return body;
345 } 348 }
346 349
347 err = mailimap_select( m_imap, (char*)mb); 350 err = mailimap_select( m_imap, (char*)mb);
348 if ( err != MAILIMAP_NO_ERROR ) { 351 if ( err != MAILIMAP_NO_ERROR ) {
349 qDebug("error selecting mailbox: %s",m_imap->imap_response); 352 qDebug("error selecting mailbox: %s",m_imap->imap_response);
350 return body; 353 return body;
351 } 354 }
352 355
353 result = clist_new(); 356 result = clist_new();
354 /* the range has to start at 1!!! not with 0!!!! */ 357 /* the range has to start at 1!!! not with 0!!!! */
355 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 358 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
356 fetchAtt = mailimap_fetch_att_new_bodystructure(); 359 fetchAtt = mailimap_fetch_att_new_bodystructure();
357 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 360 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
358 err = mailimap_fetch( m_imap, set, fetchType, &result ); 361 err = mailimap_fetch( m_imap, set, fetchType, &result );
359 mailimap_set_free( set ); 362 mailimap_set_free( set );
360 mailimap_fetch_type_free( fetchType ); 363 mailimap_fetch_type_free( fetchType );
361 364
362 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 365 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
363 mailimap_msg_att * msg_att; 366 mailimap_msg_att * msg_att;
364 msg_att = (mailimap_msg_att*)current->data; 367 msg_att = (mailimap_msg_att*)current->data;
365 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 368 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
366 body_desc = item->att_data.att_static->att_data.att_body; 369 body_desc = item->att_data.att_static->att_data.att_body;
367 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 370 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
368 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 371 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
369 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 372 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
370 qDebug("Mulitpart mail"); 373 qDebug("Mulitpart mail");
371 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 374 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
372 } 375 }
373 } else { 376 } else {
374 qDebug("error fetching body: %s",m_imap->imap_response); 377 qDebug("error fetching body: %s",m_imap->imap_response);
375 } 378 }
376 mailimap_fetch_list_free(result); 379 mailimap_fetch_list_free(result);
377 return body; 380 return body;
378} 381}
379 382
380/* this routine is just called when the mail has only ONE part. 383/* this routine is just called when the mail has only ONE part.
381 for filling the parts of a multi-part-message there are other 384 for filling the parts of a multi-part-message there are other
382 routines 'cause we can not simply fetch the whole body. */ 385 routines 'cause we can not simply fetch the whole body. */
383void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 386void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
384{ 387{
385 if (!mailDescription) { 388 if (!mailDescription) {
386 return; 389 return;
387 } 390 }
388 QString sub,body_text; 391 QString sub,body_text;
389 RecPart singlePart; 392 RecPart singlePart;
390 QValueList<int> path; 393 QValueList<int> path;
391 fillSinglePart(singlePart,mailDescription); 394 fillSinglePart(singlePart,mailDescription);
392 switch (mailDescription->bd_type) { 395 switch (mailDescription->bd_type) {
393 case MAILIMAP_BODY_TYPE_1PART_MSG: 396 case MAILIMAP_BODY_TYPE_1PART_MSG:
394 path.append(1); 397 path.append(1);
395 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 398 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
396 target_body.setBodytext(body_text); 399 target_body.setBodytext(body_text);
397 target_body.setDescription(singlePart); 400 target_body.setDescription(singlePart);
398 break; 401 break;
399 case MAILIMAP_BODY_TYPE_1PART_TEXT: 402 case MAILIMAP_BODY_TYPE_1PART_TEXT:
400 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 403 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
401 path.append(1); 404 path.append(1);
402 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 405 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
403 target_body.setBodytext(body_text); 406 target_body.setBodytext(body_text);
404 target_body.setDescription(singlePart); 407 target_body.setDescription(singlePart);
405 break; 408 break;
406 case MAILIMAP_BODY_TYPE_1PART_BASIC: 409 case MAILIMAP_BODY_TYPE_1PART_BASIC:
407 qDebug("Single attachment"); 410 qDebug("Single attachment");
408 target_body.setBodytext(""); 411 target_body.setBodytext("");
409 target_body.addPart(singlePart); 412 target_body.addPart(singlePart);
410 break; 413 break;
411 default: 414 default:
412 break; 415 break;
413 } 416 }
414 417
415 return; 418 return;
416} 419}
417 420
418QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 421QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
419{ 422{
420 QStringList l; 423 QStringList l;
421 QString from; 424 QString from;
422 bool named_from; 425 bool named_from;
423 clistcell *current = NULL; 426 clistcell *current = NULL;
424 mailimap_address * current_address=NULL; 427 mailimap_address * current_address=NULL;
425 if (!list) { 428 if (!list) {
426 return l; 429 return l;
427 } 430 }
428 unsigned int count = 0; 431 unsigned int count = 0;
429 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 432 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
430 from = ""; 433 from = "";
431 named_from = false; 434 named_from = false;
432 current_address=(mailimap_address*)current->data; 435 current_address=(mailimap_address*)current->data;
433 if (current_address->ad_personal_name){ 436 if (current_address->ad_personal_name){
434 from+=QString(current_address->ad_personal_name); 437 from+=QString(current_address->ad_personal_name);
435 from+=" "; 438 from+=" ";
436 named_from = true; 439 named_from = true;
437 } 440 }
438 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 441 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
439 from+="<"; 442 from+="<";
440 } 443 }
441 if (current_address->ad_mailbox_name) { 444 if (current_address->ad_mailbox_name) {
442 from+=QString(current_address->ad_mailbox_name); 445 from+=QString(current_address->ad_mailbox_name);
443 from+="@"; 446 from+="@";
444 } 447 }
445 if (current_address->ad_host_name) { 448 if (current_address->ad_host_name) {
446 from+=QString(current_address->ad_host_name); 449 from+=QString(current_address->ad_host_name);
447 } 450 }
448 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 451 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
449 from+=">"; 452 from+=">";
450 } 453 }
451 l.append(QString(from)); 454 l.append(QString(from));
452 if (++count > 99) { 455 if (++count > 99) {
453 break; 456 break;
454 } 457 }
455 } 458 }
456 return l; 459 return l;
457} 460}
458 461
459encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 462encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
460{ 463{
461 encodedString*res=new encodedString; 464 encodedString*res=new encodedString;
462 const char*mb; 465 const char*mb;
463 int err; 466 int err;
464 mailimap_fetch_type *fetchType; 467 mailimap_fetch_type *fetchType;
465 mailimap_set *set; 468 mailimap_set *set;
466 clistcell*current,*cur; 469 clistcell*current,*cur;
467 470
468 login(); 471 login();
469 if (!m_imap) { 472 if (!m_imap) {
470 return res; 473 return res;
471 } 474 }
472 if (!internal_call) { 475 if (!internal_call) {
473 mb = mail.getMbox().latin1(); 476 mb = mail.getMbox().latin1();
474 err = mailimap_select( m_imap, (char*)mb); 477 err = mailimap_select( m_imap, (char*)mb);
475 if ( err != MAILIMAP_NO_ERROR ) { 478 if ( err != MAILIMAP_NO_ERROR ) {
476 qDebug("error selecting mailbox: %s",m_imap->imap_response); 479 qDebug("error selecting mailbox: %s",m_imap->imap_response);
477 return res; 480 return res;
478 } 481 }
479 } 482 }
480 set = mailimap_set_new_single(mail.getNumber()); 483 set = mailimap_set_new_single(mail.getNumber());
481 clist*id_list=clist_new(); 484 clist*id_list=clist_new();
482 for (unsigned j=0; j < path.count();++j) { 485 for (unsigned j=0; j < path.count();++j) {
483 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 486 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
484 *p_id = path[j]; 487 *p_id = path[j];
485 clist_append(id_list,p_id); 488 clist_append(id_list,p_id);
486 } 489 }
487 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 490 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
488 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 491 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
489 mailimap_section * section = mailimap_section_new(section_spec); 492 mailimap_section * section = mailimap_section_new(section_spec);
490 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 493 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
491 494
492 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 495 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
493 496
494 clist*result = clist_new(); 497 clist*result = clist_new();
495 498
496 err = mailimap_fetch( m_imap, set, fetchType, &result ); 499 err = mailimap_fetch( m_imap, set, fetchType, &result );
497 mailimap_set_free( set ); 500 mailimap_set_free( set );
498 mailimap_fetch_type_free( fetchType ); 501 mailimap_fetch_type_free( fetchType );
499 502
500 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 503 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
501 mailimap_msg_att * msg_att; 504 mailimap_msg_att * msg_att;
502 msg_att = (mailimap_msg_att*)current->data; 505 msg_att = (mailimap_msg_att*)current->data;
503 mailimap_msg_att_item*msg_att_item; 506 mailimap_msg_att_item*msg_att_item;
504 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 507 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
505 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 508 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
506 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 509 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
507 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 510 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
508 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 511 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
509 /* detach - we take over the content */ 512 /* detach - we take over the content */
510 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 513 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
511 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 514 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
512 } 515 }
513 } 516 }
514 } 517 }
515 } else { 518 } else {
516 qDebug("error fetching text: %s",m_imap->imap_response); 519 qDebug("error fetching text: %s",m_imap->imap_response);
517 } 520 }
518 mailimap_fetch_list_free(result); 521 mailimap_fetch_list_free(result);
519 return res; 522 return res;
520} 523}
521 524
522void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 525void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
523{ 526{
524 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 527 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
525 if (!mailDescription||current_recursion==10) { 528 if (!mailDescription||current_recursion==10) {
526 return; 529 return;
527 } 530 }
528 clistcell*current; 531 clistcell*current;
529 mailimap_body*current_body; 532 mailimap_body*current_body;
530 unsigned int count = 0; 533 unsigned int count = 0;
531 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 534 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
532 /* the point in the message */ 535 /* the point in the message */
533 ++count; 536 ++count;
534 current_body = (mailimap_body*)current->data; 537 current_body = (mailimap_body*)current->data;
535 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 538 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
536 QValueList<int>clist = recList; 539 QValueList<int>clist = recList;
537 clist.append(count); 540 clist.append(count);
538 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 541 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
539 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 542 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
540 RecPart currentPart; 543 RecPart currentPart;
541 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 544 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
542 QValueList<int>clist = recList; 545 QValueList<int>clist = recList;
543 clist.append(count); 546 clist.append(count);
544 /* important: Check for is NULL 'cause a body can be empty! */ 547 /* important: Check for is NULL 'cause a body can be empty! */
545 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 548 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
546 QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding()); 549 QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding());
547 target_body.setDescription(currentPart); 550 target_body.setDescription(currentPart);
548 target_body.setBodytext(body_text); 551 target_body.setBodytext(body_text);
549 } else { 552 } else {
550 QString id(""); 553 QString id("");
551 for (unsigned int j = 0; j < clist.count();++j) { 554 for (unsigned int j = 0; j < clist.count();++j) {
552 id+=(j>0?" ":""); 555 id+=(j>0?" ":"");
553 id+=QString("%1").arg(clist[j]); 556 id+=QString("%1").arg(clist[j]);
554 } 557 }
555 qDebug("ID= %s",id.latin1()); 558 qDebug("ID= %s",id.latin1());
556 currentPart.setIdentifier(id); 559 currentPart.setIdentifier(id);
557 currentPart.setPositionlist(clist); 560 currentPart.setPositionlist(clist);
558 target_body.addPart(currentPart); 561 target_body.addPart(currentPart);
559 } 562 }
560 } 563 }
561 } 564 }
562} 565}
563 566
564void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 567void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
565{ 568{
566 if (!Description) { 569 if (!Description) {
567 return; 570 return;
568 } 571 }
569 switch (Description->bd_type) { 572 switch (Description->bd_type) {
570 case MAILIMAP_BODY_TYPE_1PART_TEXT: 573 case MAILIMAP_BODY_TYPE_1PART_TEXT:
571 target_part.setType("text"); 574 target_part.setType("text");
572 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 575 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
573 break; 576 break;
574 case MAILIMAP_BODY_TYPE_1PART_BASIC: 577 case MAILIMAP_BODY_TYPE_1PART_BASIC:
575 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 578 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
576 break; 579 break;
577 case MAILIMAP_BODY_TYPE_1PART_MSG: 580 case MAILIMAP_BODY_TYPE_1PART_MSG:
578 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 581 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
579 break; 582 break;
580 default: 583 default:
581 break; 584 break;
582 } 585 }
583} 586}
584 587
585void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 588void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
586{ 589{
587 if (!which) { 590 if (!which) {
588 return; 591 return;
589 } 592 }
590 QString sub; 593 QString sub;
591 sub = which->bd_media_text; 594 sub = which->bd_media_text;
592 target_part.setSubtype(sub.lower()); 595 target_part.setSubtype(sub.lower());
593 target_part.setLines(which->bd_lines); 596 target_part.setLines(which->bd_lines);
594 fillBodyFields(target_part,which->bd_fields); 597 fillBodyFields(target_part,which->bd_fields);
595} 598}
596 599
597void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 600void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
598{ 601{
599 if (!which) { 602 if (!which) {
600 return; 603 return;
601 } 604 }
602// QString sub; 605// QString sub;
603// sub = which->bd_media_text; 606// sub = which->bd_media_text;
604// target_part.setSubtype(sub.lower()); 607// target_part.setSubtype(sub.lower());
605 qDebug("Message part"); 608 qDebug("Message part");
606 /* we set this type to text/plain */ 609 /* we set this type to text/plain */
607 target_part.setType("text"); 610 target_part.setType("text");
608 target_part.setSubtype("plain"); 611 target_part.setSubtype("plain");
609 target_part.setLines(which->bd_lines); 612 target_part.setLines(which->bd_lines);
610 fillBodyFields(target_part,which->bd_fields); 613 fillBodyFields(target_part,which->bd_fields);
611} 614}
612 615
613void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 616void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
614{ 617{
615 if (!which) { 618 if (!which) {
616 return; 619 return;
617 } 620 }
618 QString type,sub; 621 QString type,sub;
619 switch (which->bd_media_basic->med_type) { 622 switch (which->bd_media_basic->med_type) {
620 case MAILIMAP_MEDIA_BASIC_APPLICATION: 623 case MAILIMAP_MEDIA_BASIC_APPLICATION:
621 type = "application"; 624 type = "application";
622 break; 625 break;
623 case MAILIMAP_MEDIA_BASIC_AUDIO: 626 case MAILIMAP_MEDIA_BASIC_AUDIO:
624 type = "audio"; 627 type = "audio";
625 break; 628 break;
626 case MAILIMAP_MEDIA_BASIC_IMAGE: 629 case MAILIMAP_MEDIA_BASIC_IMAGE:
627 type = "image"; 630 type = "image";
628 break; 631 break;
629 case MAILIMAP_MEDIA_BASIC_MESSAGE: 632 case MAILIMAP_MEDIA_BASIC_MESSAGE:
630 type = "message"; 633 type = "message";
631 break; 634 break;
632 case MAILIMAP_MEDIA_BASIC_VIDEO: 635 case MAILIMAP_MEDIA_BASIC_VIDEO:
633 type = "video"; 636 type = "video";
634 break; 637 break;
635 case MAILIMAP_MEDIA_BASIC_OTHER: 638 case MAILIMAP_MEDIA_BASIC_OTHER:
636 default: 639 default:
637 if (which->bd_media_basic->med_basic_type) { 640 if (which->bd_media_basic->med_basic_type) {
638 type = which->bd_media_basic->med_basic_type; 641 type = which->bd_media_basic->med_basic_type;
639 } else { 642 } else {
640 type = ""; 643 type = "";
641 } 644 }
642 break; 645 break;
643 } 646 }
644 if (which->bd_media_basic->med_subtype) { 647 if (which->bd_media_basic->med_subtype) {
645 sub = which->bd_media_basic->med_subtype; 648 sub = which->bd_media_basic->med_subtype;
646 } else { 649 } else {
647 sub = ""; 650 sub = "";
648 } 651 }
649 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 652 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
650 target_part.setType(type.lower()); 653 target_part.setType(type.lower());
651 target_part.setSubtype(sub.lower()); 654 target_part.setSubtype(sub.lower());
652 fillBodyFields(target_part,which->bd_fields); 655 fillBodyFields(target_part,which->bd_fields);
653} 656}
654 657
655void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 658void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
656{ 659{
657 if (!which) return; 660 if (!which) return;
658 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 661 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
659 clistcell*cur; 662 clistcell*cur;
660 mailimap_single_body_fld_param*param=0; 663 mailimap_single_body_fld_param*param=0;
661 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 664 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
662 param = (mailimap_single_body_fld_param*)cur->data; 665 param = (mailimap_single_body_fld_param*)cur->data;
663 if (param) { 666 if (param) {
664 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 667 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
665 } 668 }
666 } 669 }
667 } 670 }
668 mailimap_body_fld_enc*enc = which->bd_encoding; 671 mailimap_body_fld_enc*enc = which->bd_encoding;
669 QString encoding(""); 672 QString encoding("");
670 switch (enc->enc_type) { 673 switch (enc->enc_type) {
671 case MAILIMAP_BODY_FLD_ENC_7BIT: 674 case MAILIMAP_BODY_FLD_ENC_7BIT:
672 encoding = "7bit"; 675 encoding = "7bit";
673 break; 676 break;
674 case MAILIMAP_BODY_FLD_ENC_8BIT: 677 case MAILIMAP_BODY_FLD_ENC_8BIT:
675 encoding = "8bit"; 678 encoding = "8bit";
676 break; 679 break;
677 case MAILIMAP_BODY_FLD_ENC_BINARY: 680 case MAILIMAP_BODY_FLD_ENC_BINARY:
678 encoding="binary"; 681 encoding="binary";
679 break; 682 break;
680 case MAILIMAP_BODY_FLD_ENC_BASE64: 683 case MAILIMAP_BODY_FLD_ENC_BASE64:
681 encoding="base64"; 684 encoding="base64";
682 break; 685 break;
683 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 686 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
684 encoding="quoted-printable"; 687 encoding="quoted-printable";
685 break; 688 break;
686 case MAILIMAP_BODY_FLD_ENC_OTHER: 689 case MAILIMAP_BODY_FLD_ENC_OTHER:
687 default: 690 default:
688 if (enc->enc_value) { 691 if (enc->enc_value) {
689 char*t=enc->enc_value; 692 char*t=enc->enc_value;
690 encoding=QString(enc->enc_value); 693 encoding=QString(enc->enc_value);
691 enc->enc_value=0L; 694 enc->enc_value=0L;
692 free(t); 695 free(t);
693 } 696 }
694 } 697 }
695 if (which->bd_description) { 698 if (which->bd_description) {
696 target_part.setDescription(QString(which->bd_description)); 699 target_part.setDescription(QString(which->bd_description));
697 } 700 }
698 target_part.setEncoding(encoding); 701 target_part.setEncoding(encoding);
699 target_part.setSize(which->bd_size); 702 target_part.setSize(which->bd_size);
700} 703}
701 704
702void IMAPwrapper::deleteMail(const RecMail&mail) 705void IMAPwrapper::deleteMail(const RecMail&mail)
703{ 706{
704 mailimap_flag_list*flist; 707 mailimap_flag_list*flist;
705 mailimap_set *set; 708 mailimap_set *set;
706 mailimap_store_att_flags * store_flags; 709 mailimap_store_att_flags * store_flags;
707 int err; 710 int err;
708 login(); 711 login();
709 if (!m_imap) { 712 if (!m_imap) {
710 return; 713 return;
711 } 714 }
712 const char *mb = mail.getMbox().latin1(); 715 const char *mb = mail.getMbox().latin1();
713 err = mailimap_select( m_imap, (char*)mb); 716 err = mailimap_select( m_imap, (char*)mb);
714 if ( err != MAILIMAP_NO_ERROR ) { 717 if ( err != MAILIMAP_NO_ERROR ) {
715 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); 718 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
716 return; 719 return;
717 } 720 }
718 flist = mailimap_flag_list_new_empty(); 721 flist = mailimap_flag_list_new_empty();
719 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 722 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
720 store_flags = mailimap_store_att_flags_new_set_flags(flist); 723 store_flags = mailimap_store_att_flags_new_set_flags(flist);
721 set = mailimap_set_new_single(mail.getNumber()); 724 set = mailimap_set_new_single(mail.getNumber());
722 err = mailimap_store(m_imap,set,store_flags); 725 err = mailimap_store(m_imap,set,store_flags);
723 mailimap_set_free( set ); 726 mailimap_set_free( set );
724 mailimap_store_att_flags_free(store_flags); 727 mailimap_store_att_flags_free(store_flags);
725 728
726 if (err != MAILIMAP_NO_ERROR) { 729 if (err != MAILIMAP_NO_ERROR) {
727 qDebug("error deleting mail: %s",m_imap->imap_response); 730 qDebug("error deleting mail: %s",m_imap->imap_response);
728 return; 731 return;
729 } 732 }
730 qDebug("deleting mail: %s",m_imap->imap_response); 733 qDebug("deleting mail: %s",m_imap->imap_response);
731 /* should we realy do that at this moment? */ 734 /* should we realy do that at this moment? */
732 err = mailimap_expunge(m_imap); 735 err = mailimap_expunge(m_imap);
733 if (err != MAILIMAP_NO_ERROR) { 736 if (err != MAILIMAP_NO_ERROR) {
734 qDebug("error deleting mail: %s",m_imap->imap_response); 737 qDebug("error deleting mail: %s",m_imap->imap_response);
735 } 738 }
736 qDebug("Delete successfull %s",m_imap->imap_response); 739 qDebug("Delete successfull %s",m_imap->imap_response);
737} 740}
738 741
739void IMAPwrapper::answeredMail(const RecMail&mail) 742void IMAPwrapper::answeredMail(const RecMail&mail)
740{ 743{
741 mailimap_flag_list*flist; 744 mailimap_flag_list*flist;
742 mailimap_set *set; 745 mailimap_set *set;
743 mailimap_store_att_flags * store_flags; 746 mailimap_store_att_flags * store_flags;
744 int err; 747 int err;
745 login(); 748 login();
746 if (!m_imap) { 749 if (!m_imap) {
747 return; 750 return;
748 } 751 }
749 const char *mb = mail.getMbox().latin1(); 752 const char *mb = mail.getMbox().latin1();
750 err = mailimap_select( m_imap, (char*)mb); 753 err = mailimap_select( m_imap, (char*)mb);
751 if ( err != MAILIMAP_NO_ERROR ) { 754 if ( err != MAILIMAP_NO_ERROR ) {
752 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); 755 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response);
753 return; 756 return;
754 } 757 }
755 flist = mailimap_flag_list_new_empty(); 758 flist = mailimap_flag_list_new_empty();
756 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 759 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
757 store_flags = mailimap_store_att_flags_new_add_flags(flist); 760 store_flags = mailimap_store_att_flags_new_add_flags(flist);
758 set = mailimap_set_new_single(mail.getNumber()); 761 set = mailimap_set_new_single(mail.getNumber());
759 err = mailimap_store(m_imap,set,store_flags); 762 err = mailimap_store(m_imap,set,store_flags);
760 mailimap_set_free( set ); 763 mailimap_set_free( set );
761 mailimap_store_att_flags_free(store_flags); 764 mailimap_store_att_flags_free(store_flags);
762 765
763 if (err != MAILIMAP_NO_ERROR) { 766 if (err != MAILIMAP_NO_ERROR) {
764 qDebug("error marking mail: %s",m_imap->imap_response); 767 qDebug("error marking mail: %s",m_imap->imap_response);
765 return; 768 return;
766 } 769 }
767} 770}
768 771
769QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 772QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
770{ 773{
771 QString body(""); 774 QString body("");
772 encodedString*res = fetchRawPart(mail,path,internal_call); 775 encodedString*res = fetchRawPart(mail,path,internal_call);
773 encodedString*r = decode_String(res,enc); 776 encodedString*r = decode_String(res,enc);
774 delete res; 777 delete res;
775 if (r) { 778 if (r) {
776 if (r->Length()>0) { 779 if (r->Length()>0) {
777 body = r->Content(); 780 body = r->Content();
778 } 781 }
779 delete r; 782 delete r;
780 } 783 }
781 return body; 784 return body;
782} 785}
783 786
784QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 787QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
785{ 788{
786 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); 789 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
787} 790}
788 791
789encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) 792encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
790{ 793{
791 encodedString*res = fetchRawPart(mail,part.Positionlist(),false); 794 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
792 encodedString*r = decode_String(res,part.Encoding()); 795 encodedString*r = decode_String(res,part.Encoding());
793 delete res; 796 delete res;
794 return r; 797 return r;
795} 798}
796 799
797encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 800encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
798{ 801{
799 return fetchRawPart(mail,part.Positionlist(),false); 802 return fetchRawPart(mail,part.Positionlist(),false);
800} 803}
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
index 96602c2..858283f 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
@@ -1,639 +1,644 @@
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 "mail.h" 11//#include "mail.h"
12#include "defines.h" 12#include "defines.h"
13 13
14Attachment::Attachment( DocLnk lnk ) 14Attachment::Attachment( DocLnk lnk )
15{ 15{
16 doc = lnk; 16 doc = lnk;
17 size = QFileInfo( doc.file() ).size(); 17 size = QFileInfo( doc.file() ).size();
18} 18}
19 19
20Folder::Folder(const QString&tmp_name ) 20Folder::Folder(const QString&tmp_name, const QString&sep )
21{ 21{
22 name = tmp_name; 22 name = tmp_name;
23 nameDisplay = name; 23 nameDisplay = name;
24 24
25 for ( int pos = nameDisplay.find( '&' ); pos != -1; 25 for ( int pos = nameDisplay.find( '&' ); pos != -1;
26 pos = nameDisplay.find( '&' ) ) { 26 pos = nameDisplay.find( '&' ) ) {
27 int end = nameDisplay.find( '-' ); 27 int end = nameDisplay.find( '-' );
28 if ( end == -1 || end <= pos ) break; 28 if ( end == -1 || end <= pos ) break;
29 QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 ); 29 QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 );
30 // TODO: do real base64 decoding here ! 30 // TODO: do real base64 decoding here !
31 if ( str64.compare( "APw" ) == 0 ) { 31 if ( str64.compare( "APw" ) == 0 ) {
32 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" ); 32 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" );
33 } else if ( str64.compare( "APY" ) == 0 ) { 33 } else if ( str64.compare( "APY" ) == 0 ) {
34 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" ); 34 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" );
35 } 35 }
36 } 36 }
37 qDebug( "folder " + name + " - displayed as " + nameDisplay ); 37 qDebug( "folder " + name + " - displayed as " + nameDisplay );
38 separator = sep;
38} 39}
39 40
41const QString& Folder::Separator()const
42{
43 return separator;
44}
40 45
41IMAPFolder::IMAPFolder(const QString&name,bool select,const QString&prefix ) 46IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix )
42 : Folder( name ),m_MaySelect(select) 47 : Folder( name,sep ),m_MaySelect(select)
43{ 48{
44 if (prefix.length()>0) { 49 if (prefix.length()>0) {
45 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { 50 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) {
46 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); 51 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length());
47 } 52 }
48 } 53 }
49} 54}
50 55
51MailWrapper::MailWrapper( Settings *s ) 56MailWrapper::MailWrapper( Settings *s )
52 : QObject() 57 : QObject()
53{ 58{
54 settings = s; 59 settings = s;
55} 60}
56 61
57QString MailWrapper::mailsmtpError( int errnum ) 62QString MailWrapper::mailsmtpError( int errnum )
58{ 63{
59 switch ( errnum ) { 64 switch ( errnum ) {
60 case MAILSMTP_NO_ERROR: 65 case MAILSMTP_NO_ERROR:
61 return tr( "No error" ); 66 return tr( "No error" );
62 case MAILSMTP_ERROR_UNEXPECTED_CODE: 67 case MAILSMTP_ERROR_UNEXPECTED_CODE:
63 return tr( "Unexpected error code" ); 68 return tr( "Unexpected error code" );
64 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 69 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
65 return tr( "Service not available" ); 70 return tr( "Service not available" );
66 case MAILSMTP_ERROR_STREAM: 71 case MAILSMTP_ERROR_STREAM:
67 return tr( "Stream error" ); 72 return tr( "Stream error" );
68 case MAILSMTP_ERROR_HOSTNAME: 73 case MAILSMTP_ERROR_HOSTNAME:
69 return tr( "gethostname() failed" ); 74 return tr( "gethostname() failed" );
70 case MAILSMTP_ERROR_NOT_IMPLEMENTED: 75 case MAILSMTP_ERROR_NOT_IMPLEMENTED:
71 return tr( "Not implemented" ); 76 return tr( "Not implemented" );
72 case MAILSMTP_ERROR_ACTION_NOT_TAKEN: 77 case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
73 return tr( "Error, action not taken" ); 78 return tr( "Error, action not taken" );
74 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: 79 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
75 return tr( "Data exceeds storage allocation" ); 80 return tr( "Data exceeds storage allocation" );
76 case MAILSMTP_ERROR_IN_PROCESSING: 81 case MAILSMTP_ERROR_IN_PROCESSING:
77 return tr( "Error in processing" ); 82 return tr( "Error in processing" );
78 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 83 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
79 // return tr( "Insufficient system storage" ); 84 // return tr( "Insufficient system storage" );
80 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 85 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
81 return tr( "Mailbox unavailable" ); 86 return tr( "Mailbox unavailable" );
82 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: 87 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
83 return tr( "Mailbox name not allowed" ); 88 return tr( "Mailbox name not allowed" );
84 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: 89 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
85 return tr( "Bad command sequence" ); 90 return tr( "Bad command sequence" );
86 case MAILSMTP_ERROR_USER_NOT_LOCAL: 91 case MAILSMTP_ERROR_USER_NOT_LOCAL:
87 return tr( "User not local" ); 92 return tr( "User not local" );
88 case MAILSMTP_ERROR_TRANSACTION_FAILED: 93 case MAILSMTP_ERROR_TRANSACTION_FAILED:
89 return tr( "Transaction failed" ); 94 return tr( "Transaction failed" );
90 case MAILSMTP_ERROR_MEMORY: 95 case MAILSMTP_ERROR_MEMORY:
91 return tr( "Memory error" ); 96 return tr( "Memory error" );
92 case MAILSMTP_ERROR_CONNECTION_REFUSED: 97 case MAILSMTP_ERROR_CONNECTION_REFUSED:
93 return tr( "Connection refused" ); 98 return tr( "Connection refused" );
94 default: 99 default:
95 return tr( "Unknown error code" ); 100 return tr( "Unknown error code" );
96 } 101 }
97} 102}
98 103
99mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail ) 104mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail )
100{ 105{
101 return mailimf_mailbox_new( strdup( name.latin1() ), 106 return mailimf_mailbox_new( strdup( name.latin1() ),
102 strdup( mail.latin1() ) ); 107 strdup( mail.latin1() ) );
103} 108}
104 109
105mailimf_address_list *MailWrapper::parseAddresses(const QString&addr ) 110mailimf_address_list *MailWrapper::parseAddresses(const QString&addr )
106{ 111{
107 mailimf_address_list *addresses; 112 mailimf_address_list *addresses;
108 113
109 if ( addr.isEmpty() ) return NULL; 114 if ( addr.isEmpty() ) return NULL;
110 115
111 addresses = mailimf_address_list_new_empty(); 116 addresses = mailimf_address_list_new_empty();
112 117
113 QStringList list = QStringList::split( ',', addr ); 118 QStringList list = QStringList::split( ',', addr );
114 QStringList::Iterator it; 119 QStringList::Iterator it;
115 for ( it = list.begin(); it != list.end(); it++ ) { 120 for ( it = list.begin(); it != list.end(); it++ ) {
116 char *str = strdup( (*it).latin1() ); 121 char *str = strdup( (*it).latin1() );
117 int err = mailimf_address_list_add_parse( addresses, str ); 122 int err = mailimf_address_list_add_parse( addresses, str );
118 if ( err != MAILIMF_NO_ERROR ) { 123 if ( err != MAILIMF_NO_ERROR ) {
119 qDebug( "Error parsing" ); 124 qDebug( "Error parsing" );
120 qDebug( *it ); 125 qDebug( *it );
121 free( str ); 126 free( str );
122 } else { 127 } else {
123 qDebug( "Parse success! :)" ); 128 qDebug( "Parse success! :)" );
124 } 129 }
125 } 130 }
126 131
127 return addresses; 132 return addresses;
128} 133}
129 134
130mailimf_fields *MailWrapper::createImfFields( Mail *mail ) 135mailimf_fields *MailWrapper::createImfFields( Mail *mail )
131{ 136{
132 mailimf_fields *fields; 137 mailimf_fields *fields;
133 mailimf_field *xmailer; 138 mailimf_field *xmailer;
134 mailimf_mailbox *sender, *fromBox; 139 mailimf_mailbox *sender, *fromBox;
135 mailimf_mailbox_list *from; 140 mailimf_mailbox_list *from;
136 mailimf_address_list *to, *cc, *bcc, *reply; 141 mailimf_address_list *to, *cc, *bcc, *reply;
137 char *subject = strdup( mail->getSubject().latin1() ); 142 char *subject = strdup( mail->getSubject().latin1() );
138 int err; 143 int err;
139 144
140 sender = newMailbox( mail->getName(), mail->getMail() ); 145 sender = newMailbox( mail->getName(), mail->getMail() );
141 if ( sender == NULL ) goto err_free; 146 if ( sender == NULL ) goto err_free;
142 147
143 fromBox = newMailbox( mail->getName(), mail->getMail() ); 148 fromBox = newMailbox( mail->getName(), mail->getMail() );
144 if ( fromBox == NULL ) goto err_free_sender; 149 if ( fromBox == NULL ) goto err_free_sender;
145 150
146 from = mailimf_mailbox_list_new_empty(); 151 from = mailimf_mailbox_list_new_empty();
147 if ( from == NULL ) goto err_free_fromBox; 152 if ( from == NULL ) goto err_free_fromBox;
148 153
149 err = mailimf_mailbox_list_add( from, fromBox ); 154 err = mailimf_mailbox_list_add( from, fromBox );
150 if ( err != MAILIMF_NO_ERROR ) goto err_free_from; 155 if ( err != MAILIMF_NO_ERROR ) goto err_free_from;
151 156
152 to = parseAddresses( mail->getTo() ); 157 to = parseAddresses( mail->getTo() );
153 if ( to == NULL ) goto err_free_from; 158 if ( to == NULL ) goto err_free_from;
154 159
155 cc = parseAddresses( mail->getCC() ); 160 cc = parseAddresses( mail->getCC() );
156 bcc = parseAddresses( mail->getBCC() ); 161 bcc = parseAddresses( mail->getBCC() );
157 reply = parseAddresses( mail->getReply() ); 162 reply = parseAddresses( mail->getReply() );
158 163
159 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, 164 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
160 NULL, NULL, subject ); 165 NULL, NULL, subject );
161 if ( fields == NULL ) goto err_free_reply; 166 if ( fields == NULL ) goto err_free_reply;
162 167
163 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), 168 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
164 strdup( USER_AGENT ) ); 169 strdup( USER_AGENT ) );
165 if ( xmailer == NULL ) goto err_free_fields; 170 if ( xmailer == NULL ) goto err_free_fields;
166 171
167 err = mailimf_fields_add( fields, xmailer ); 172 err = mailimf_fields_add( fields, xmailer );
168 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; 173 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer;
169 174
170 return fields; // Success :) 175 return fields; // Success :)
171 176
172err_free_xmailer: 177err_free_xmailer:
173 mailimf_field_free( xmailer ); 178 mailimf_field_free( xmailer );
174err_free_fields: 179err_free_fields:
175 mailimf_fields_free( fields ); 180 mailimf_fields_free( fields );
176err_free_reply: 181err_free_reply:
177 mailimf_address_list_free( reply ); 182 mailimf_address_list_free( reply );
178 mailimf_address_list_free( bcc ); 183 mailimf_address_list_free( bcc );
179 mailimf_address_list_free( cc ); 184 mailimf_address_list_free( cc );
180 mailimf_address_list_free( to ); 185 mailimf_address_list_free( to );
181err_free_from: 186err_free_from:
182 mailimf_mailbox_list_free( from ); 187 mailimf_mailbox_list_free( from );
183err_free_fromBox: 188err_free_fromBox:
184 mailimf_mailbox_free( fromBox ); 189 mailimf_mailbox_free( fromBox );
185err_free_sender: 190err_free_sender:
186 mailimf_mailbox_free( sender ); 191 mailimf_mailbox_free( sender );
187err_free: 192err_free:
188 free( subject ); 193 free( subject );
189 qDebug( "createImfFields - error" ); 194 qDebug( "createImfFields - error" );
190 195
191 return NULL; // Error :( 196 return NULL; // Error :(
192} 197}
193 198
194mailmime *MailWrapper::buildTxtPart( QString str ) 199mailmime *MailWrapper::buildTxtPart( QString str )
195{ 200{
196 mailmime *txtPart; 201 mailmime *txtPart;
197 mailmime_fields *fields; 202 mailmime_fields *fields;
198 mailmime_content *content; 203 mailmime_content *content;
199 mailmime_parameter *param; 204 mailmime_parameter *param;
200 char *txt = strdup( str.latin1() ); 205 char *txt = strdup( str.latin1() );
201 int err; 206 int err;
202 207
203 param = mailmime_parameter_new( strdup( "charset" ), 208 param = mailmime_parameter_new( strdup( "charset" ),
204 strdup( "iso-8859-1" ) ); 209 strdup( "iso-8859-1" ) );
205 if ( param == NULL ) goto err_free; 210 if ( param == NULL ) goto err_free;
206 211
207 content = mailmime_content_new_with_str( "text/plain" ); 212 content = mailmime_content_new_with_str( "text/plain" );
208 if ( content == NULL ) goto err_free_param; 213 if ( content == NULL ) goto err_free_param;
209 214
210 err = clist_append( content->ct_parameters, param ); 215 err = clist_append( content->ct_parameters, param );
211 if ( err != MAILIMF_NO_ERROR ) goto err_free_content; 216 if ( err != MAILIMF_NO_ERROR ) goto err_free_content;
212 217
213 fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); 218 fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT );
214 if ( fields == NULL ) goto err_free_content; 219 if ( fields == NULL ) goto err_free_content;
215 220
216 txtPart = mailmime_new_empty( content, fields ); 221 txtPart = mailmime_new_empty( content, fields );
217 if ( txtPart == NULL ) goto err_free_fields; 222 if ( txtPart == NULL ) goto err_free_fields;
218 223
219 err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); 224 err = mailmime_set_body_text( txtPart, txt, strlen( txt ) );
220 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 225 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
221 226
222 return txtPart; // Success :) 227 return txtPart; // Success :)
223 228
224err_free_txtPart: 229err_free_txtPart:
225 mailmime_free( txtPart ); 230 mailmime_free( txtPart );
226err_free_fields: 231err_free_fields:
227 mailmime_fields_free( fields ); 232 mailmime_fields_free( fields );
228err_free_content: 233err_free_content:
229 mailmime_content_free( content ); 234 mailmime_content_free( content );
230err_free_param: 235err_free_param:
231 mailmime_parameter_free( param ); 236 mailmime_parameter_free( param );
232err_free: 237err_free:
233 free( txt ); 238 free( txt );
234 qDebug( "buildTxtPart - error" ); 239 qDebug( "buildTxtPart - error" );
235 240
236 return NULL; // Error :( 241 return NULL; // Error :(
237} 242}
238 243
239mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype ) 244mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype )
240{ 245{
241 mailmime * filePart; 246 mailmime * filePart;
242 mailmime_fields * fields; 247 mailmime_fields * fields;
243 mailmime_content * content; 248 mailmime_content * content;
244 mailmime_parameter * param = NULL; 249 mailmime_parameter * param = NULL;
245 int err; 250 int err;
246 251
247 int pos = filename.findRev( '/' ); 252 int pos = filename.findRev( '/' );
248 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 253 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
249 char *name = strdup( tmp.latin1() ); // just filename 254 char *name = strdup( tmp.latin1() ); // just filename
250 char *file = strdup( filename.latin1() ); // full name with path 255 char *file = strdup( filename.latin1() ); // full name with path
251 char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain 256 char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain
252 257
253 fields = mailmime_fields_new_filename( 258 fields = mailmime_fields_new_filename(
254 MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, 259 MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name,
255 MAILMIME_MECHANISM_BASE64 ); 260 MAILMIME_MECHANISM_BASE64 );
256 if ( fields == NULL ) goto err_free; 261 if ( fields == NULL ) goto err_free;
257 262
258 content = mailmime_content_new_with_str( mime ); 263 content = mailmime_content_new_with_str( mime );
259 if ( content == NULL ) goto err_free_fields; 264 if ( content == NULL ) goto err_free_fields;
260 265
261 if ( mimetype.compare( "text/plain" ) == 0 ) { 266 if ( mimetype.compare( "text/plain" ) == 0 ) {
262 param = mailmime_parameter_new( strdup( "charset" ), 267 param = mailmime_parameter_new( strdup( "charset" ),
263 strdup( "iso-8859-1" ) ); 268 strdup( "iso-8859-1" ) );
264 if ( param == NULL ) goto err_free_content; 269 if ( param == NULL ) goto err_free_content;
265 270
266 err = clist_append( content->ct_parameters, param ); 271 err = clist_append( content->ct_parameters, param );
267 if ( err != MAILIMF_NO_ERROR ) goto err_free_param; 272 if ( err != MAILIMF_NO_ERROR ) goto err_free_param;
268 } 273 }
269 274
270 filePart = mailmime_new_empty( content, fields ); 275 filePart = mailmime_new_empty( content, fields );
271 if ( filePart == NULL ) goto err_free_param; 276 if ( filePart == NULL ) goto err_free_param;
272 277
273 err = mailmime_set_body_file( filePart, file ); 278 err = mailmime_set_body_file( filePart, file );
274 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; 279 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart;
275 280
276 return filePart; // Success :) 281 return filePart; // Success :)
277 282
278err_free_filePart: 283err_free_filePart:
279 mailmime_free( filePart ); 284 mailmime_free( filePart );
280err_free_param: 285err_free_param:
281 if ( param != NULL ) mailmime_parameter_free( param ); 286 if ( param != NULL ) mailmime_parameter_free( param );
282err_free_content: 287err_free_content:
283 mailmime_content_free( content ); 288 mailmime_content_free( content );
284err_free_fields: 289err_free_fields:
285 mailmime_fields_free( fields ); 290 mailmime_fields_free( fields );
286err_free: 291err_free:
287 free( name ); 292 free( name );
288 free( mime ); 293 free( mime );
289 free( file ); 294 free( file );
290 qDebug( "buildFilePart - error" ); 295 qDebug( "buildFilePart - error" );
291 296
292 return NULL; // Error :( 297 return NULL; // Error :(
293} 298}
294 299
295void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) 300void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files )
296{ 301{
297 Attachment *it; 302 Attachment *it;
298 for ( it = files.first(); it; it = files.next() ) { 303 for ( it = files.first(); it; it = files.next() ) {
299 qDebug( "Adding file" ); 304 qDebug( "Adding file" );
300 mailmime *filePart; 305 mailmime *filePart;
301 int err; 306 int err;
302 307
303 filePart = buildFilePart( it->getFileName(), it->getMimeType() ); 308 filePart = buildFilePart( it->getFileName(), it->getMimeType() );
304 if ( filePart == NULL ) goto err_free; 309 if ( filePart == NULL ) goto err_free;
305 310
306 err = mailmime_smart_add_part( message, filePart ); 311 err = mailmime_smart_add_part( message, filePart );
307 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; 312 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart;
308 313
309 continue; // Success :) 314 continue; // Success :)
310 315
311 err_free_filePart: 316 err_free_filePart:
312 mailmime_free( filePart ); 317 mailmime_free( filePart );
313 err_free: 318 err_free:
314 qDebug( "addFileParts: error adding file:" ); 319 qDebug( "addFileParts: error adding file:" );
315 qDebug( it->getFileName() ); 320 qDebug( it->getFileName() );
316 } 321 }
317} 322}
318 323
319mailmime *MailWrapper::createMimeMail( Mail *mail ) 324mailmime *MailWrapper::createMimeMail( Mail *mail )
320{ 325{
321 mailmime *message, *txtPart; 326 mailmime *message, *txtPart;
322 mailimf_fields *fields; 327 mailimf_fields *fields;
323 int err; 328 int err;
324 329
325 fields = createImfFields( mail ); 330 fields = createImfFields( mail );
326 if ( fields == NULL ) goto err_free; 331 if ( fields == NULL ) goto err_free;
327 332
328 message = mailmime_new_message_data( NULL ); 333 message = mailmime_new_message_data( NULL );
329 if ( message == NULL ) goto err_free_fields; 334 if ( message == NULL ) goto err_free_fields;
330 335
331 mailmime_set_imf_fields( message, fields ); 336 mailmime_set_imf_fields( message, fields );
332 337
333 txtPart = buildTxtPart( mail->getMessage() ); 338 txtPart = buildTxtPart( mail->getMessage() );
334 if ( txtPart == NULL ) goto err_free_message; 339 if ( txtPart == NULL ) goto err_free_message;
335 340
336 err = mailmime_smart_add_part( message, txtPart ); 341 err = mailmime_smart_add_part( message, txtPart );
337 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 342 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
338 343
339 addFileParts( message, mail->getAttachments() ); 344 addFileParts( message, mail->getAttachments() );
340 345
341 return message; // Success :) 346 return message; // Success :)
342 347
343err_free_txtPart: 348err_free_txtPart:
344 mailmime_free( txtPart ); 349 mailmime_free( txtPart );
345err_free_message: 350err_free_message:
346 mailmime_free( message ); 351 mailmime_free( message );
347err_free_fields: 352err_free_fields:
348 mailimf_fields_free( fields ); 353 mailimf_fields_free( fields );
349err_free: 354err_free:
350 qDebug( "createMimeMail: error" ); 355 qDebug( "createMimeMail: error" );
351 356
352 return NULL; // Error :( 357 return NULL; // Error :(
353} 358}
354 359
355mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type ) 360mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type )
356{ 361{
357 mailimf_field *field; 362 mailimf_field *field;
358 clistiter *it; 363 clistiter *it;
359 364
360 it = clist_begin( fields->fld_list ); 365 it = clist_begin( fields->fld_list );
361 while ( it ) { 366 while ( it ) {
362 field = (mailimf_field *) it->data; 367 field = (mailimf_field *) it->data;
363 if ( field->fld_type == type ) { 368 if ( field->fld_type == type ) {
364 return field; 369 return field;
365 } 370 }
366 it = it->next; 371 it = it->next;
367 } 372 }
368 373
369 return NULL; 374 return NULL;
370} 375}
371 376
372static void addRcpts( clist *list, mailimf_address_list *addr_list ) 377static void addRcpts( clist *list, mailimf_address_list *addr_list )
373{ 378{
374 clistiter *it, *it2; 379 clistiter *it, *it2;
375 380
376 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { 381 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) {
377 mailimf_address *addr; 382 mailimf_address *addr;
378 addr = (mailimf_address *) it->data; 383 addr = (mailimf_address *) it->data;
379 384
380 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { 385 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) {
381 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); 386 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL );
382 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { 387 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) {
383 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; 388 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list;
384 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { 389 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
385 mailimf_mailbox *mbox; 390 mailimf_mailbox *mbox;
386 mbox = (mailimf_mailbox *) it2->data; 391 mbox = (mailimf_mailbox *) it2->data;
387 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); 392 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL );
388 } 393 }
389 } 394 }
390 } 395 }
391} 396}
392 397
393clist *MailWrapper::createRcptList( mailimf_fields *fields ) 398clist *MailWrapper::createRcptList( mailimf_fields *fields )
394{ 399{
395 clist *rcptList; 400 clist *rcptList;
396 mailimf_field *field; 401 mailimf_field *field;
397 402
398 rcptList = esmtp_address_list_new(); 403 rcptList = esmtp_address_list_new();
399 404
400 field = getField( fields, MAILIMF_FIELD_TO ); 405 field = getField( fields, MAILIMF_FIELD_TO );
401 if ( field && (field->fld_type == MAILIMF_FIELD_TO) 406 if ( field && (field->fld_type == MAILIMF_FIELD_TO)
402 && field->fld_data.fld_to->to_addr_list ) { 407 && field->fld_data.fld_to->to_addr_list ) {
403 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); 408 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
404 } 409 }
405 410
406 field = getField( fields, MAILIMF_FIELD_CC ); 411 field = getField( fields, MAILIMF_FIELD_CC );
407 if ( field && (field->fld_type == MAILIMF_FIELD_CC) 412 if ( field && (field->fld_type == MAILIMF_FIELD_CC)
408 && field->fld_data.fld_cc->cc_addr_list ) { 413 && field->fld_data.fld_cc->cc_addr_list ) {
409 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); 414 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
410 } 415 }
411 416
412 field = getField( fields, MAILIMF_FIELD_BCC ); 417 field = getField( fields, MAILIMF_FIELD_BCC );
413 if ( field && (field->fld_type == MAILIMF_FIELD_BCC) 418 if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
414 && field->fld_data.fld_bcc->bcc_addr_list ) { 419 && field->fld_data.fld_bcc->bcc_addr_list ) {
415 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); 420 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
416 } 421 }
417 422
418 return rcptList; 423 return rcptList;
419} 424}
420 425
421char *MailWrapper::getFrom( mailmime *mail ) 426char *MailWrapper::getFrom( mailmime *mail )
422{ 427{
423 char *from = NULL; 428 char *from = NULL;
424 429
425 mailimf_field *ffrom; 430 mailimf_field *ffrom;
426 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); 431 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
427 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) 432 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM)
428 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { 433 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) {
429 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; 434 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list;
430 clistiter *it; 435 clistiter *it;
431 for ( it = clist_begin( cl ); it; it = it->next ) { 436 for ( it = clist_begin( cl ); it; it = it->next ) {
432 mailimf_mailbox *mb = (mailimf_mailbox *) it->data; 437 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
433 from = strdup( mb->mb_addr_spec ); 438 from = strdup( mb->mb_addr_spec );
434 } 439 }
435 } 440 }
436 441
437 return from; 442 return from;
438} 443}
439 444
440SMTPaccount *MailWrapper::getAccount( QString from ) 445SMTPaccount *MailWrapper::getAccount( QString from )
441{ 446{
442 SMTPaccount *smtp; 447 SMTPaccount *smtp;
443 448
444 QList<Account> list = settings->getAccounts(); 449 QList<Account> list = settings->getAccounts();
445 Account *it; 450 Account *it;
446 for ( it = list.first(); it; it = list.next() ) { 451 for ( it = list.first(); it; it = list.next() ) {
447 if ( it->getType().compare( "SMTP" ) == 0 ) { 452 if ( it->getType().compare( "SMTP" ) == 0 ) {
448 smtp = static_cast<SMTPaccount *>(it); 453 smtp = static_cast<SMTPaccount *>(it);
449 if ( smtp->getMail().compare( from ) == 0 ) { 454 if ( smtp->getMail().compare( from ) == 0 ) {
450 qDebug( "SMTPaccount found for" ); 455 qDebug( "SMTPaccount found for" );
451 qDebug( from ); 456 qDebug( from );
452 return smtp; 457 return smtp;
453 } 458 }
454 } 459 }
455 } 460 }
456 461
457 return NULL; 462 return NULL;
458} 463}
459 464
460QString MailWrapper::getTmpFile() { 465QString MailWrapper::getTmpFile() {
461 int num = 0; 466 int num = 0;
462 QString unique; 467 QString unique;
463 468
464 QDir dir( "/tmp" ); 469 QDir dir( "/tmp" );
465 QStringList::Iterator it; 470 QStringList::Iterator it;
466 471
467 QStringList list = dir.entryList( "opiemail-tmp-*" ); 472 QStringList list = dir.entryList( "opiemail-tmp-*" );
468 do { 473 do {
469 unique.setNum( num++ ); 474 unique.setNum( num++ );
470 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); 475 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 );
471 476
472 return "/tmp/opiemail-tmp-" + unique; 477 return "/tmp/opiemail-tmp-" + unique;
473} 478}
474 479
475void MailWrapper::writeToFile( QString file, mailmime *mail ) 480void MailWrapper::writeToFile( QString file, mailmime *mail )
476{ 481{
477 FILE *f; 482 FILE *f;
478 int err, col = 0; 483 int err, col = 0;
479 484
480 f = fopen( file.latin1(), "w" ); 485 f = fopen( file.latin1(), "w" );
481 if ( f == NULL ) { 486 if ( f == NULL ) {
482 qDebug( "writeToFile: error opening file" ); 487 qDebug( "writeToFile: error opening file" );
483 return; 488 return;
484 } 489 }
485 490
486 err = mailmime_write( f, &col, mail ); 491 err = mailmime_write( f, &col, mail );
487 if ( err != MAILIMF_NO_ERROR ) { 492 if ( err != MAILIMF_NO_ERROR ) {
488 fclose( f ); 493 fclose( f );
489 qDebug( "writeToFile: error writing mailmime" ); 494 qDebug( "writeToFile: error writing mailmime" );
490 return; 495 return;
491 } 496 }
492 497
493 fclose( f ); 498 fclose( f );
494} 499}
495 500
496void MailWrapper::readFromFile( QString file, char **data, size_t *size ) 501void MailWrapper::readFromFile( QString file, char **data, size_t *size )
497{ 502{
498 char *buf; 503 char *buf;
499 struct stat st; 504 struct stat st;
500 int fd, count = 0, total = 0; 505 int fd, count = 0, total = 0;
501 506
502 fd = open( file.latin1(), O_RDONLY, 0 ); 507 fd = open( file.latin1(), O_RDONLY, 0 );
503 if ( fd == -1 ) return; 508 if ( fd == -1 ) return;
504 509
505 if ( fstat( fd, &st ) != 0 ) goto err_close; 510 if ( fstat( fd, &st ) != 0 ) goto err_close;
506 if ( !st.st_size ) goto err_close; 511 if ( !st.st_size ) goto err_close;
507 512
508 buf = (char *) malloc( st.st_size ); 513 buf = (char *) malloc( st.st_size );
509 if ( !buf ) goto err_close; 514 if ( !buf ) goto err_close;
510 515
511 while ( ( total < st.st_size ) && ( count >= 0 ) ) { 516 while ( ( total < st.st_size ) && ( count >= 0 ) ) {
512 count = read( fd, buf + total, st.st_size - total ); 517 count = read( fd, buf + total, st.st_size - total );
513 total += count; 518 total += count;
514 } 519 }
515 if ( count < 0 ) goto err_free; 520 if ( count < 0 ) goto err_free;
516 521
517 *data = buf; 522 *data = buf;
518 *size = st.st_size; 523 *size = st.st_size;
519 524
520 close( fd ); 525 close( fd );
521 526
522 return; // Success :) 527 return; // Success :)
523 528
524err_free: 529err_free:
525 free( buf ); 530 free( buf );
526err_close: 531err_close:
527 close( fd ); 532 close( fd );
528} 533}
529 534
530void progress( size_t current, size_t maximum ) 535void progress( size_t current, size_t maximum )
531{ 536{
532 qDebug( "Current: %i of %i", current, maximum ); 537 qDebug( "Current: %i of %i", current, maximum );
533} 538}
534 539
535void MailWrapper::smtpSend( mailmime *mail ) 540void MailWrapper::smtpSend( mailmime *mail )
536{ 541{
537 mailsmtp *session; 542 mailsmtp *session;
538 clist *rcpts; 543 clist *rcpts;
539 char *from, *data, *server, *user = NULL, *pass = NULL; 544 char *from, *data, *server, *user = NULL, *pass = NULL;
540 size_t size; 545 size_t size;
541 int err; 546 int err;
542 bool ssl; 547 bool ssl;
543 uint16_t port; 548 uint16_t port;
544 549
545 550
546 from = getFrom( mail ); 551 from = getFrom( mail );
547 SMTPaccount *smtp = getAccount( from ); 552 SMTPaccount *smtp = getAccount( from );
548 if ( smtp == NULL ) { 553 if ( smtp == NULL ) {
549 free(from); 554 free(from);
550 return; 555 return;
551 } 556 }
552 server = strdup( smtp->getServer().latin1() ); 557 server = strdup( smtp->getServer().latin1() );
553 ssl = smtp->getSSL(); 558 ssl = smtp->getSSL();
554 port = smtp->getPort().toUInt(); 559 port = smtp->getPort().toUInt();
555 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 560 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
556 561
557 QString file = getTmpFile(); 562 QString file = getTmpFile();
558 writeToFile( file, mail ); 563 writeToFile( file, mail );
559 readFromFile( file, &data, &size ); 564 readFromFile( file, &data, &size );
560 QFile f( file ); 565 QFile f( file );
561 f.remove(); 566 f.remove();
562 567
563 session = mailsmtp_new( 20, &progress ); 568 session = mailsmtp_new( 20, &progress );
564 if ( session == NULL ) goto free_mem; 569 if ( session == NULL ) goto free_mem;
565 570
566 qDebug( "Servername %s at port %i", server, port ); 571 qDebug( "Servername %s at port %i", server, port );
567 if ( ssl ) { 572 if ( ssl ) {
568 qDebug( "SSL session" ); 573 qDebug( "SSL session" );
569 err = mailsmtp_ssl_connect( session, server, port ); 574 err = mailsmtp_ssl_connect( session, server, port );
570 } else { 575 } else {
571 qDebug( "No SSL session" ); 576 qDebug( "No SSL session" );
572 err = mailsmtp_socket_connect( session, server, port ); 577 err = mailsmtp_socket_connect( session, server, port );
573 } 578 }
574 if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; 579 if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session;
575 580
576 err = mailsmtp_init( session ); 581 err = mailsmtp_init( session );
577 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; 582 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session;
578 583
579 qDebug( "INIT OK" ); 584 qDebug( "INIT OK" );
580 585
581 if ( smtp->getLogin() ) { 586 if ( smtp->getLogin() ) {
582 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { 587 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
583 // get'em 588 // get'em
584 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); 589 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true );
585 login.show(); 590 login.show();
586 if ( QDialog::Accepted == login.exec() ) { 591 if ( QDialog::Accepted == login.exec() ) {
587 // ok 592 // ok
588 user = strdup( login.getUser().latin1() ); 593 user = strdup( login.getUser().latin1() );
589 pass = strdup( login.getPassword().latin1() ); 594 pass = strdup( login.getPassword().latin1() );
590 } else { 595 } else {
591 goto free_con_session; 596 goto free_con_session;
592 } 597 }
593 } else { 598 } else {
594 user = strdup( smtp->getUser().latin1() ); 599 user = strdup( smtp->getUser().latin1() );
595 pass = strdup( smtp->getPassword().latin1() ); 600 pass = strdup( smtp->getPassword().latin1() );
596 } 601 }
597 qDebug( "session->auth: %i", session->auth); 602 qDebug( "session->auth: %i", session->auth);
598 err = mailsmtp_auth( session, user, pass ); 603 err = mailsmtp_auth( session, user, pass );
599 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); 604 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
600 qDebug( "Done auth!" ); 605 qDebug( "Done auth!" );
601 } 606 }
602 607
603 err = mailsmtp_send( session, from, rcpts, data, size ); 608 err = mailsmtp_send( session, from, rcpts, data, size );
604 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; 609 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session;
605 610
606 qDebug( "Mail sent." ); 611 qDebug( "Mail sent." );
607 612
608free_con_session: 613free_con_session:
609 mailsmtp_quit( session ); 614 mailsmtp_quit( session );
610free_mem_session: 615free_mem_session:
611 mailsmtp_free( session ); 616 mailsmtp_free( session );
612free_mem: 617free_mem:
613 smtp_address_list_free( rcpts ); 618 smtp_address_list_free( rcpts );
614 free( data ); 619 free( data );
615 free( server ); 620 free( server );
616 if ( smtp->getLogin() ) { 621 if ( smtp->getLogin() ) {
617 free( user ); 622 free( user );
618 free( pass ); 623 free( pass );
619 } 624 }
620 free( from ); 625 free( from );
621} 626}
622 627
623void MailWrapper::sendMail( Mail mail ) 628void MailWrapper::sendMail( Mail mail )
624{ 629{
625 mailmime *mimeMail; 630 mailmime *mimeMail;
626 631
627 mimeMail = createMimeMail( &mail ); 632 mimeMail = createMimeMail( &mail );
628 if ( mimeMail == NULL ) { 633 if ( mimeMail == NULL ) {
629 qDebug( "sendMail: error creating mime mail" ); 634 qDebug( "sendMail: error creating mime mail" );
630 } else { 635 } else {
631 smtpSend( mimeMail ); 636 smtpSend( mimeMail );
632 mailmime_free( mimeMail ); 637 mailmime_free( mimeMail );
633 } 638 }
634} 639}
635 640
636Mail::Mail() 641Mail::Mail()
637 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") 642 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("")
638{ 643{
639} 644}
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h
index 6994dd8..d78f8e9 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.h
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.h
@@ -1,123 +1,124 @@
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 <libetpan/mailmime.h> 6#include <libetpan/mailmime.h>
7#include <libetpan/mailimf.h> 7#include <libetpan/mailimf.h>
8#include <libetpan/mailsmtp.h> 8#include <libetpan/mailsmtp.h>
9#include <libetpan/mailstorage.h> 9#include <libetpan/mailstorage.h>
10#include <libetpan/maildriver.h> 10#include <libetpan/maildriver.h>
11#include <qbitarray.h> 11#include <qbitarray.h>
12#include <qdatetime.h> 12#include <qdatetime.h>
13 13
14#include "settings.h" 14#include "settings.h"
15 15
16class Attachment 16class Attachment
17{ 17{
18public: 18public:
19 Attachment( DocLnk lnk ); 19 Attachment( DocLnk lnk );
20 virtual ~Attachment(){} 20 virtual ~Attachment(){}
21 const QString getFileName()const{ return doc.file(); } 21 const QString getFileName()const{ return doc.file(); }
22 const QString getName()const{ return doc.name(); } 22 const QString getName()const{ return doc.name(); }
23 const QString getMimeType()const{ return doc.type(); } 23 const QString getMimeType()const{ return doc.type(); }
24 const QPixmap getPixmap()const{ return doc.pixmap(); } 24 const QPixmap getPixmap()const{ return doc.pixmap(); }
25 const int getSize()const { return size; } 25 const int getSize()const { return size; }
26 DocLnk getDocLnk() { return doc; } 26 DocLnk getDocLnk() { return doc; }
27 27
28protected: 28protected:
29 DocLnk doc; 29 DocLnk doc;
30 int size; 30 int size;
31 31
32}; 32};
33 33
34class Mail 34class Mail
35{ 35{
36public: 36public:
37 Mail(); 37 Mail();
38 /* Possible that this destructor must not be declared virtual 38 /* Possible that this destructor must not be declared virtual
39 * 'cause it seems that it will never have some child classes. 39 * 'cause it seems that it will never have some child classes.
40 * in this case this object will not get a virtual table -> memory and 40 * in this case this object will not get a virtual table -> memory and
41 * speed will be a little bit better? 41 * speed will be a little bit better?
42 */ 42 */
43 virtual ~Mail(){} 43 virtual ~Mail(){}
44 void addAttachment( Attachment *att ) { attList.append( att ); } 44 void addAttachment( Attachment *att ) { attList.append( att ); }
45 const QList<Attachment>& getAttachments()const { return attList; } 45 const QList<Attachment>& getAttachments()const { return attList; }
46 void removeAttachment( Attachment *att ) { attList.remove( att ); } 46 void removeAttachment( Attachment *att ) { attList.remove( att ); }
47 const QString&getName()const { return name; } 47 const QString&getName()const { return name; }
48 void setName( QString s ) { name = s; } 48 void setName( QString s ) { name = s; }
49 const QString&getMail()const{ return mail; } 49 const QString&getMail()const{ return mail; }
50 void setMail( const QString&s ) { mail = s; } 50 void setMail( const QString&s ) { mail = s; }
51 const QString&getTo()const{ return to; } 51 const QString&getTo()const{ return to; }
52 void setTo( const QString&s ) { to = s; } 52 void setTo( const QString&s ) { to = s; }
53 const QString&getCC()const{ return cc; } 53 const QString&getCC()const{ return cc; }
54 void setCC( const QString&s ) { cc = s; } 54 void setCC( const QString&s ) { cc = s; }
55 const QString&getBCC()const { return bcc; } 55 const QString&getBCC()const { return bcc; }
56 void setBCC( const QString&s ) { bcc = s; } 56 void setBCC( const QString&s ) { bcc = s; }
57 const QString&getMessage()const { return message; } 57 const QString&getMessage()const { return message; }
58 void setMessage( const QString&s ) { message = s; } 58 void setMessage( const QString&s ) { message = s; }
59 const QString&getSubject()const { return subject; } 59 const QString&getSubject()const { return subject; }
60 void setSubject( const QString&s ) { subject = s; } 60 void setSubject( const QString&s ) { subject = s; }
61 const QString&getReply()const{ return reply; } 61 const QString&getReply()const{ return reply; }
62 void setReply( const QString&a ) { reply = a; } 62 void setReply( const QString&a ) { reply = a; }
63 63
64private: 64private:
65 QList<Attachment> attList; 65 QList<Attachment> attList;
66 QString name, mail, to, cc, bcc, reply, subject, message; 66 QString name, mail, to, cc, bcc, reply, subject, message;
67}; 67};
68 68
69class Folder : public QObject 69class Folder : public QObject
70{ 70{
71 Q_OBJECT 71 Q_OBJECT
72 72
73public: 73public:
74 Folder( const QString&init_name ); 74 Folder( const QString&init_name,const QString&sep );
75 const QString&getDisplayName()const { return nameDisplay; } 75 const QString&getDisplayName()const { return nameDisplay; }
76 const QString&getName()const { return name; } 76 const QString&getName()const { return name; }
77 virtual bool may_select()const{return true;}; 77 virtual bool may_select()const{return true;};
78 const QString&Separator()const;
78 79
79protected: 80protected:
80 QString nameDisplay, name; 81 QString nameDisplay, name, separator;
81 82
82}; 83};
83 84
84class IMAPFolder : public Folder 85class IMAPFolder : public Folder
85{ 86{
86 public: 87 public:
87 IMAPFolder(const QString&name,bool select=true,const QString&prefix="" ); 88 IMAPFolder(const QString&name, const QString&sep, bool select=true,const QString&prefix="" );
88 virtual bool may_select()const{return m_MaySelect;} 89 virtual bool may_select()const{return m_MaySelect;}
89 private: 90 private:
90 bool m_MaySelect; 91 bool m_MaySelect;
91}; 92};
92 93
93class MailWrapper : public QObject 94class MailWrapper : public QObject
94{ 95{
95 Q_OBJECT 96 Q_OBJECT
96 97
97public: 98public:
98 MailWrapper( Settings *s ); 99 MailWrapper( Settings *s );
99 void sendMail( Mail mail ); 100 void sendMail( Mail mail );
100 101
101private: 102private:
102 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 103 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
103 mailimf_address_list *parseAddresses(const QString&addr ); 104 mailimf_address_list *parseAddresses(const QString&addr );
104 mailimf_fields *createImfFields( Mail *mail ); 105 mailimf_fields *createImfFields( Mail *mail );
105 mailmime *buildTxtPart( QString str ); 106 mailmime *buildTxtPart( QString str );
106 mailmime *buildFilePart( QString filename, QString mimetype ); 107 mailmime *buildFilePart( QString filename, QString mimetype );
107 void addFileParts( mailmime *message, QList<Attachment> files ); 108 void addFileParts( mailmime *message, QList<Attachment> files );
108 mailmime *createMimeMail( Mail *mail ); 109 mailmime *createMimeMail( Mail *mail );
109 void smtpSend( mailmime *mail ); 110 void smtpSend( mailmime *mail );
110 mailimf_field *getField( mailimf_fields *fields, int type ); 111 mailimf_field *getField( mailimf_fields *fields, int type );
111 clist *createRcptList( mailimf_fields *fields ); 112 clist *createRcptList( mailimf_fields *fields );
112 char *getFrom( mailmime *mail ); 113 char *getFrom( mailmime *mail );
113 SMTPaccount *getAccount( QString from ); 114 SMTPaccount *getAccount( QString from );
114 void writeToFile( QString file, mailmime *mail ); 115 void writeToFile( QString file, mailmime *mail );
115 void readFromFile( QString file, char **data, size_t *size ); 116 void readFromFile( QString file, char **data, size_t *size );
116 static QString mailsmtpError( int err ); 117 static QString mailsmtpError( int err );
117 static QString getTmpFile(); 118 static QString getTmpFile();
118 119
119 Settings *settings; 120 Settings *settings;
120 121
121}; 122};
122 123
123#endif 124#endif
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 075d8c7..4508a95 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -1,358 +1,358 @@
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 <libetpan/mailpop3.h> 4#include <libetpan/mailpop3.h>
5 5
6POP3wrapper::POP3wrapper( POP3account *a ) 6POP3wrapper::POP3wrapper( POP3account *a )
7{ 7{
8 account = a; 8 account = a;
9 m_pop3 = NULL; 9 m_pop3 = NULL;
10} 10}
11 11
12POP3wrapper::~POP3wrapper() 12POP3wrapper::~POP3wrapper()
13{ 13{
14 logout(); 14 logout();
15} 15}
16 16
17void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 17void POP3wrapper::pop3_progress( size_t current, size_t maximum )
18{ 18{
19 //qDebug( "POP3: %i of %i", current, maximum ); 19 //qDebug( "POP3: %i of %i", current, maximum );
20} 20}
21 21
22RecBody POP3wrapper::fetchBody( const RecMail &mail ) 22RecBody POP3wrapper::fetchBody( const RecMail &mail )
23{ 23{
24 int err = MAILPOP3_NO_ERROR; 24 int err = MAILPOP3_NO_ERROR;
25 char *message; 25 char *message;
26 size_t length = 0; 26 size_t length = 0;
27 27
28 login(); 28 login();
29 if ( !m_pop3 ) return RecBody(); 29 if ( !m_pop3 ) return RecBody();
30 30
31 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); 31 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
32 if ( err != MAILPOP3_NO_ERROR ) { 32 if ( err != MAILPOP3_NO_ERROR ) {
33 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); 33 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
34 return RecBody(); 34 return RecBody();
35 } 35 }
36 36
37 return parseBody( message ); 37 return parseBody( message );
38} 38}
39 39
40RecBody POP3wrapper::parseBody( const char *message ) 40RecBody POP3wrapper::parseBody( const char *message )
41{ 41{
42 int err = MAILIMF_NO_ERROR; 42 int err = MAILIMF_NO_ERROR;
43 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 43 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
44 size_t curTok = 0; 44 size_t curTok = 0;
45 mailimf_message *result = 0; 45 mailimf_message *result = 0;
46 RecBody body; 46 RecBody body;
47 47
48 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); 48 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
49 if ( err != MAILIMF_NO_ERROR ) { 49 if ( err != MAILIMF_NO_ERROR ) {
50 if (result) mailimf_message_free(result); 50 if (result) mailimf_message_free(result);
51 return body; 51 return body;
52 } 52 }
53 53
54 if ( result && result->msg_body && result->msg_body->bd_text ) { 54 if ( result && result->msg_body && result->msg_body->bd_text ) {
55 qDebug( "POP3: bodytext found" ); 55 qDebug( "POP3: bodytext found" );
56 // when curTok isn't set to 0 this line will fault! 'cause upper line faults! 56 // when curTok isn't set to 0 this line will fault! 'cause upper line faults!
57 body.setBodytext( QString( result->msg_body->bd_text ) ); 57 body.setBodytext( QString( result->msg_body->bd_text ) );
58 } 58 }
59 if (result) mailimf_message_free(result); 59 if (result) mailimf_message_free(result);
60 return body; 60 return body;
61} 61}
62 62
63void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 63void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
64{ 64{
65 int err = MAILPOP3_NO_ERROR; 65 int err = MAILPOP3_NO_ERROR;
66 char * header = 0; 66 char * header = 0;
67 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 67 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
68 size_t length = 0; 68 size_t length = 0;
69 carray * messages = 0; 69 carray * messages = 0;
70 70
71 login(); 71 login();
72 if (!m_pop3) return; 72 if (!m_pop3) return;
73 mailpop3_list( m_pop3, &messages ); 73 mailpop3_list( m_pop3, &messages );
74 74
75 for (unsigned int i = 0; i < carray_count(messages);++i) { 75 for (unsigned int i = 0; i < carray_count(messages);++i) {
76 mailpop3_msg_info *info; 76 mailpop3_msg_info *info;
77 err = mailpop3_get_msg_info(m_pop3,i+1,&info); 77 err = mailpop3_get_msg_info(m_pop3,i+1,&info);
78 if (info->msg_deleted) 78 if (info->msg_deleted)
79 continue; 79 continue;
80 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 80 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
81 if ( err != MAILPOP3_NO_ERROR ) { 81 if ( err != MAILPOP3_NO_ERROR ) {
82 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); 82 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
83 free(header); 83 free(header);
84 return; 84 return;
85 } 85 }
86 RecMail *mail = parseHeader( header ); 86 RecMail *mail = parseHeader( header );
87 mail->setNumber( info->msg_index ); 87 mail->setNumber( info->msg_index );
88 mail->setWrapper(this); 88 mail->setWrapper(this);
89 mail->setMsgsize(info->msg_size); 89 mail->setMsgsize(info->msg_size);
90 target.append( mail ); 90 target.append( mail );
91 free(header); 91 free(header);
92 } 92 }
93} 93}
94 94
95RecMail *POP3wrapper::parseHeader( const char *header ) 95RecMail *POP3wrapper::parseHeader( const char *header )
96{ 96{
97 int err = MAILIMF_NO_ERROR; 97 int err = MAILIMF_NO_ERROR;
98 size_t curTok = 0; 98 size_t curTok = 0;
99 RecMail *mail = new RecMail(); 99 RecMail *mail = new RecMail();
100 mailimf_fields *fields; 100 mailimf_fields *fields;
101 mailimf_references * refs; 101 mailimf_references * refs;
102 mailimf_keywords*keys; 102 mailimf_keywords*keys;
103 QString status; 103 QString status;
104 QString value; 104 QString value;
105 QBitArray mFlags(7); 105 QBitArray mFlags(7);
106 106
107 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 107 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
108 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 108 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
109 mailimf_field *field = (mailimf_field *) current->data; 109 mailimf_field *field = (mailimf_field *) current->data;
110 switch ( field->fld_type ) { 110 switch ( field->fld_type ) {
111 case MAILIMF_FIELD_FROM: 111 case MAILIMF_FIELD_FROM:
112 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 112 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
113 break; 113 break;
114 case MAILIMF_FIELD_TO: 114 case MAILIMF_FIELD_TO:
115 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 115 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
116 break; 116 break;
117 case MAILIMF_FIELD_CC: 117 case MAILIMF_FIELD_CC:
118 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 118 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
119 break; 119 break;
120 case MAILIMF_FIELD_BCC: 120 case MAILIMF_FIELD_BCC:
121 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 121 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
122 break; 122 break;
123 case MAILIMF_FIELD_SUBJECT: 123 case MAILIMF_FIELD_SUBJECT:
124 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); 124 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) );
125 break; 125 break;
126 case MAILIMF_FIELD_ORIG_DATE: 126 case MAILIMF_FIELD_ORIG_DATE:
127 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 127 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
128 break; 128 break;
129 case MAILIMF_FIELD_MESSAGE_ID: 129 case MAILIMF_FIELD_MESSAGE_ID:
130 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); 130 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value));
131 break; 131 break;
132 case MAILIMF_FIELD_REFERENCES: 132 case MAILIMF_FIELD_REFERENCES:
133 refs = field->fld_data.fld_references; 133 refs = field->fld_data.fld_references;
134 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 134 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
135 char * text = (char*)refs->mid_list->first->data; 135 char * text = (char*)refs->mid_list->first->data;
136 mail->setReplyto(QString(text)); 136 mail->setReplyto(QString(text));
137 } 137 }
138 break; 138 break;
139 case MAILIMF_FIELD_KEYWORDS: 139 case MAILIMF_FIELD_KEYWORDS:
140 keys = field->fld_data.fld_keywords; 140 keys = field->fld_data.fld_keywords;
141 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { 141 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
142 qDebug("Keyword: %s",(char*)cur->data); 142 qDebug("Keyword: %s",(char*)cur->data);
143 } 143 }
144 break; 144 break;
145 case MAILIMF_FIELD_OPTIONAL_FIELD: 145 case MAILIMF_FIELD_OPTIONAL_FIELD:
146 status = field->fld_data.fld_optional_field->fld_name; 146 status = field->fld_data.fld_optional_field->fld_name;
147 value = field->fld_data.fld_optional_field->fld_value; 147 value = field->fld_data.fld_optional_field->fld_value;
148 if (status.lower()=="status") { 148 if (status.lower()=="status") {
149 if (value.lower()=="ro") { 149 if (value.lower()=="ro") {
150 mFlags.setBit(FLAG_SEEN); 150 mFlags.setBit(FLAG_SEEN);
151 } 151 }
152 } else if (status.lower()=="x-status") { 152 } else if (status.lower()=="x-status") {
153 qDebug("X-Status: %s",value.latin1()); 153 qDebug("X-Status: %s",value.latin1());
154 if (value.lower()=="a") { 154 if (value.lower()=="a") {
155 155
156 mFlags.setBit(FLAG_ANSWERED); 156 mFlags.setBit(FLAG_ANSWERED);
157 } 157 }
158 } else { 158 } else {
159// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, 159// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name,
160// field->fld_data.fld_optional_field->fld_value); 160// field->fld_data.fld_optional_field->fld_value);
161 } 161 }
162 break; 162 break;
163 default: 163 default:
164 qDebug("Non parsed field"); 164 qDebug("Non parsed field");
165 break; 165 break;
166 } 166 }
167 } 167 }
168 if (fields) mailimf_fields_free(fields); 168 if (fields) mailimf_fields_free(fields);
169 mail->setFlags(mFlags); 169 mail->setFlags(mFlags);
170 return mail; 170 return mail;
171} 171}
172 172
173QString POP3wrapper::parseDateTime( mailimf_date_time *date ) 173QString POP3wrapper::parseDateTime( mailimf_date_time *date )
174{ 174{
175 char tmp[23]; 175 char tmp[23];
176 176
177 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 177 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
178 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 178 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
179 179
180 return QString( tmp ); 180 return QString( tmp );
181} 181}
182 182
183QString POP3wrapper::parseAddressList( mailimf_address_list *list ) 183QString POP3wrapper::parseAddressList( mailimf_address_list *list )
184{ 184{
185 QString result( "" ); 185 QString result( "" );
186 186
187 bool first = true; 187 bool first = true;
188 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 188 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
189 mailimf_address *addr = (mailimf_address *) current->data; 189 mailimf_address *addr = (mailimf_address *) current->data;
190 190
191 if ( !first ) { 191 if ( !first ) {
192 result.append( "," ); 192 result.append( "," );
193 } else { 193 } else {
194 first = false; 194 first = false;
195 } 195 }
196 196
197 switch ( addr->ad_type ) { 197 switch ( addr->ad_type ) {
198 case MAILIMF_ADDRESS_MAILBOX: 198 case MAILIMF_ADDRESS_MAILBOX:
199 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 199 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
200 break; 200 break;
201 case MAILIMF_ADDRESS_GROUP: 201 case MAILIMF_ADDRESS_GROUP:
202 result.append( parseGroup( addr->ad_data.ad_group ) ); 202 result.append( parseGroup( addr->ad_data.ad_group ) );
203 break; 203 break;
204 default: 204 default:
205 qDebug( "POP3: unkown mailimf address type" ); 205 qDebug( "POP3: unkown mailimf address type" );
206 break; 206 break;
207 } 207 }
208 } 208 }
209 209
210 return result; 210 return result;
211} 211}
212 212
213QString POP3wrapper::parseGroup( mailimf_group *group ) 213QString POP3wrapper::parseGroup( mailimf_group *group )
214{ 214{
215 QString result( "" ); 215 QString result( "" );
216 216
217 result.append( group->grp_display_name ); 217 result.append( group->grp_display_name );
218 result.append( ": " ); 218 result.append( ": " );
219 219
220 if ( group->grp_mb_list != NULL ) { 220 if ( group->grp_mb_list != NULL ) {
221 result.append( parseMailboxList( group->grp_mb_list ) ); 221 result.append( parseMailboxList( group->grp_mb_list ) );
222 } 222 }
223 223
224 result.append( ";" ); 224 result.append( ";" );
225 225
226 return result; 226 return result;
227} 227}
228 228
229QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) 229QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
230{ 230{
231 QString result( "" ); 231 QString result( "" );
232 232
233 if ( box->mb_display_name == NULL ) { 233 if ( box->mb_display_name == NULL ) {
234 result.append( box->mb_addr_spec ); 234 result.append( box->mb_addr_spec );
235 } else { 235 } else {
236 result.append( box->mb_display_name ); 236 result.append( box->mb_display_name );
237 result.append( " <" ); 237 result.append( " <" );
238 result.append( box->mb_addr_spec ); 238 result.append( box->mb_addr_spec );
239 result.append( ">" ); 239 result.append( ">" );
240 } 240 }
241 241
242 return result; 242 return result;
243} 243}
244 244
245QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) 245QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
246{ 246{
247 QString result( "" ); 247 QString result( "" );
248 248
249 bool first = true; 249 bool first = true;
250 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 250 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
251 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 251 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
252 252
253 if ( !first ) { 253 if ( !first ) {
254 result.append( "," ); 254 result.append( "," );
255 } else { 255 } else {
256 first = false; 256 first = false;
257 } 257 }
258 258
259 result.append( parseMailbox( box ) ); 259 result.append( parseMailbox( box ) );
260 } 260 }
261 261
262 return result; 262 return result;
263} 263}
264 264
265void POP3wrapper::login() 265void POP3wrapper::login()
266{ 266{
267 /* we'll hold the line */ 267 /* we'll hold the line */
268 if ( m_pop3 != NULL ) return; 268 if ( m_pop3 != NULL ) return;
269 269
270 const char *server, *user, *pass; 270 const char *server, *user, *pass;
271 uint16_t port; 271 uint16_t port;
272 int err = MAILPOP3_NO_ERROR; 272 int err = MAILPOP3_NO_ERROR;
273 273
274 server = account->getServer().latin1(); 274 server = account->getServer().latin1();
275 port = account->getPort().toUInt(); 275 port = account->getPort().toUInt();
276 user = account->getUser().latin1(); 276 user = account->getUser().latin1();
277 pass = account->getPassword().latin1(); 277 pass = account->getPassword().latin1();
278 278
279 m_pop3 = mailpop3_new( 200, &pop3_progress ); 279 m_pop3 = mailpop3_new( 200, &pop3_progress );
280 280
281 // connect 281 // connect
282 if (account->getSSL()) { 282 if (account->getSSL()) {
283 err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); 283 err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
284 } else { 284 } else {
285 err = mailpop3_socket_connect( m_pop3, (char*)server, port ); 285 err = mailpop3_socket_connect( m_pop3, (char*)server, port );
286 } 286 }
287 287
288 if ( err != MAILPOP3_NO_ERROR ) { 288 if ( err != MAILPOP3_NO_ERROR ) {
289 qDebug( "pop3: error connecting to %s\n reason: %s", server, 289 qDebug( "pop3: error connecting to %s\n reason: %s", server,
290 m_pop3->pop3_response ); 290 m_pop3->pop3_response );
291 mailpop3_free( m_pop3 ); 291 mailpop3_free( m_pop3 );
292 m_pop3 = NULL; 292 m_pop3 = NULL;
293 return; 293 return;
294 } 294 }
295 qDebug( "POP3: connected!" ); 295 qDebug( "POP3: connected!" );
296 296
297 // login 297 // login
298 // TODO: decide if apop or plain login should be used 298 // TODO: decide if apop or plain login should be used
299 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 299 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
300 if ( err != MAILPOP3_NO_ERROR ) { 300 if ( err != MAILPOP3_NO_ERROR ) {
301 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); 301 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response );
302 logout(); 302 logout();
303 return; 303 return;
304 } 304 }
305 305
306 qDebug( "POP3: logged in!" ); 306 qDebug( "POP3: logged in!" );
307} 307}
308 308
309void POP3wrapper::logout() 309void POP3wrapper::logout()
310{ 310{
311 int err = MAILPOP3_NO_ERROR; 311 int err = MAILPOP3_NO_ERROR;
312 if ( m_pop3 == NULL ) return; 312 if ( m_pop3 == NULL ) return;
313 err = mailpop3_quit( m_pop3 ); 313 err = mailpop3_quit( m_pop3 );
314 mailpop3_free( m_pop3 ); 314 mailpop3_free( m_pop3 );
315 m_pop3 = NULL; 315 m_pop3 = NULL;
316} 316}
317 317
318 318
319QList<Folder>* POP3wrapper::listFolders() 319QList<Folder>* POP3wrapper::listFolders()
320{ 320{
321 /* TODO: integrate MH directories 321 /* TODO: integrate MH directories
322 but not before version 0.1 ;) 322 but not before version 0.1 ;)
323 */ 323 */
324 QList<Folder> * folders = new QList<Folder>(); 324 QList<Folder> * folders = new QList<Folder>();
325 folders->setAutoDelete( false ); 325 folders->setAutoDelete( false );
326 Folder*inb=new Folder("INBOX"); 326 Folder*inb=new Folder("INBOX","/");
327 folders->append(inb); 327 folders->append(inb);
328 return folders; 328 return folders;
329} 329}
330 330
331QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&) 331QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&)
332{ 332{
333 return ""; 333 return "";
334} 334}
335 335
336void POP3wrapper::deleteMail(const RecMail&mail) 336void POP3wrapper::deleteMail(const RecMail&mail)
337{ 337{
338 login(); 338 login();
339 if (!m_pop3) return; 339 if (!m_pop3) return;
340 int err = mailpop3_dele(m_pop3,mail.getNumber()); 340 int err = mailpop3_dele(m_pop3,mail.getNumber());
341 if (err != MAILPOP3_NO_ERROR) { 341 if (err != MAILPOP3_NO_ERROR) {
342 qDebug("error deleting mail"); 342 qDebug("error deleting mail");
343 } 343 }
344} 344}
345 345
346void POP3wrapper::answeredMail(const RecMail&) 346void POP3wrapper::answeredMail(const RecMail&)
347{ 347{
348} 348}
349 349
350encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&) 350encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&)
351{ 351{
352 return new encodedString(); 352 return new encodedString();
353} 353}
354 354
355encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&) 355encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&)
356{ 356{
357 return new encodedString(); 357 return new encodedString();
358} 358}
diff --git a/noncore/net/mail/mailwrapper.cpp b/noncore/net/mail/mailwrapper.cpp
index 96602c2..858283f 100644
--- a/noncore/net/mail/mailwrapper.cpp
+++ b/noncore/net/mail/mailwrapper.cpp
@@ -1,639 +1,644 @@
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 "mail.h" 11//#include "mail.h"
12#include "defines.h" 12#include "defines.h"
13 13
14Attachment::Attachment( DocLnk lnk ) 14Attachment::Attachment( DocLnk lnk )
15{ 15{
16 doc = lnk; 16 doc = lnk;
17 size = QFileInfo( doc.file() ).size(); 17 size = QFileInfo( doc.file() ).size();
18} 18}
19 19
20Folder::Folder(const QString&tmp_name ) 20Folder::Folder(const QString&tmp_name, const QString&sep )
21{ 21{
22 name = tmp_name; 22 name = tmp_name;
23 nameDisplay = name; 23 nameDisplay = name;
24 24
25 for ( int pos = nameDisplay.find( '&' ); pos != -1; 25 for ( int pos = nameDisplay.find( '&' ); pos != -1;
26 pos = nameDisplay.find( '&' ) ) { 26 pos = nameDisplay.find( '&' ) ) {
27 int end = nameDisplay.find( '-' ); 27 int end = nameDisplay.find( '-' );
28 if ( end == -1 || end <= pos ) break; 28 if ( end == -1 || end <= pos ) break;
29 QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 ); 29 QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 );
30 // TODO: do real base64 decoding here ! 30 // TODO: do real base64 decoding here !
31 if ( str64.compare( "APw" ) == 0 ) { 31 if ( str64.compare( "APw" ) == 0 ) {
32 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" ); 32 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" );
33 } else if ( str64.compare( "APY" ) == 0 ) { 33 } else if ( str64.compare( "APY" ) == 0 ) {
34 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" ); 34 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" );
35 } 35 }
36 } 36 }
37 qDebug( "folder " + name + " - displayed as " + nameDisplay ); 37 qDebug( "folder " + name + " - displayed as " + nameDisplay );
38 separator = sep;
38} 39}
39 40
41const QString& Folder::Separator()const
42{
43 return separator;
44}
40 45
41IMAPFolder::IMAPFolder(const QString&name,bool select,const QString&prefix ) 46IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix )
42 : Folder( name ),m_MaySelect(select) 47 : Folder( name,sep ),m_MaySelect(select)
43{ 48{
44 if (prefix.length()>0) { 49 if (prefix.length()>0) {
45 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { 50 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) {
46 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); 51 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length());
47 } 52 }
48 } 53 }
49} 54}
50 55
51MailWrapper::MailWrapper( Settings *s ) 56MailWrapper::MailWrapper( Settings *s )
52 : QObject() 57 : QObject()
53{ 58{
54 settings = s; 59 settings = s;
55} 60}
56 61
57QString MailWrapper::mailsmtpError( int errnum ) 62QString MailWrapper::mailsmtpError( int errnum )
58{ 63{
59 switch ( errnum ) { 64 switch ( errnum ) {
60 case MAILSMTP_NO_ERROR: 65 case MAILSMTP_NO_ERROR:
61 return tr( "No error" ); 66 return tr( "No error" );
62 case MAILSMTP_ERROR_UNEXPECTED_CODE: 67 case MAILSMTP_ERROR_UNEXPECTED_CODE:
63 return tr( "Unexpected error code" ); 68 return tr( "Unexpected error code" );
64 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 69 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
65 return tr( "Service not available" ); 70 return tr( "Service not available" );
66 case MAILSMTP_ERROR_STREAM: 71 case MAILSMTP_ERROR_STREAM:
67 return tr( "Stream error" ); 72 return tr( "Stream error" );
68 case MAILSMTP_ERROR_HOSTNAME: 73 case MAILSMTP_ERROR_HOSTNAME:
69 return tr( "gethostname() failed" ); 74 return tr( "gethostname() failed" );
70 case MAILSMTP_ERROR_NOT_IMPLEMENTED: 75 case MAILSMTP_ERROR_NOT_IMPLEMENTED:
71 return tr( "Not implemented" ); 76 return tr( "Not implemented" );
72 case MAILSMTP_ERROR_ACTION_NOT_TAKEN: 77 case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
73 return tr( "Error, action not taken" ); 78 return tr( "Error, action not taken" );
74 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: 79 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
75 return tr( "Data exceeds storage allocation" ); 80 return tr( "Data exceeds storage allocation" );
76 case MAILSMTP_ERROR_IN_PROCESSING: 81 case MAILSMTP_ERROR_IN_PROCESSING:
77 return tr( "Error in processing" ); 82 return tr( "Error in processing" );
78 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 83 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
79 // return tr( "Insufficient system storage" ); 84 // return tr( "Insufficient system storage" );
80 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 85 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
81 return tr( "Mailbox unavailable" ); 86 return tr( "Mailbox unavailable" );
82 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: 87 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
83 return tr( "Mailbox name not allowed" ); 88 return tr( "Mailbox name not allowed" );
84 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: 89 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
85 return tr( "Bad command sequence" ); 90 return tr( "Bad command sequence" );
86 case MAILSMTP_ERROR_USER_NOT_LOCAL: 91 case MAILSMTP_ERROR_USER_NOT_LOCAL:
87 return tr( "User not local" ); 92 return tr( "User not local" );
88 case MAILSMTP_ERROR_TRANSACTION_FAILED: 93 case MAILSMTP_ERROR_TRANSACTION_FAILED:
89 return tr( "Transaction failed" ); 94 return tr( "Transaction failed" );
90 case MAILSMTP_ERROR_MEMORY: 95 case MAILSMTP_ERROR_MEMORY:
91 return tr( "Memory error" ); 96 return tr( "Memory error" );
92 case MAILSMTP_ERROR_CONNECTION_REFUSED: 97 case MAILSMTP_ERROR_CONNECTION_REFUSED:
93 return tr( "Connection refused" ); 98 return tr( "Connection refused" );
94 default: 99 default:
95 return tr( "Unknown error code" ); 100 return tr( "Unknown error code" );
96 } 101 }
97} 102}
98 103
99mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail ) 104mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail )
100{ 105{
101 return mailimf_mailbox_new( strdup( name.latin1() ), 106 return mailimf_mailbox_new( strdup( name.latin1() ),
102 strdup( mail.latin1() ) ); 107 strdup( mail.latin1() ) );
103} 108}
104 109
105mailimf_address_list *MailWrapper::parseAddresses(const QString&addr ) 110mailimf_address_list *MailWrapper::parseAddresses(const QString&addr )
106{ 111{
107 mailimf_address_list *addresses; 112 mailimf_address_list *addresses;
108 113
109 if ( addr.isEmpty() ) return NULL; 114 if ( addr.isEmpty() ) return NULL;
110 115
111 addresses = mailimf_address_list_new_empty(); 116 addresses = mailimf_address_list_new_empty();
112 117
113 QStringList list = QStringList::split( ',', addr ); 118 QStringList list = QStringList::split( ',', addr );
114 QStringList::Iterator it; 119 QStringList::Iterator it;
115 for ( it = list.begin(); it != list.end(); it++ ) { 120 for ( it = list.begin(); it != list.end(); it++ ) {
116 char *str = strdup( (*it).latin1() ); 121 char *str = strdup( (*it).latin1() );
117 int err = mailimf_address_list_add_parse( addresses, str ); 122 int err = mailimf_address_list_add_parse( addresses, str );
118 if ( err != MAILIMF_NO_ERROR ) { 123 if ( err != MAILIMF_NO_ERROR ) {
119 qDebug( "Error parsing" ); 124 qDebug( "Error parsing" );
120 qDebug( *it ); 125 qDebug( *it );
121 free( str ); 126 free( str );
122 } else { 127 } else {
123 qDebug( "Parse success! :)" ); 128 qDebug( "Parse success! :)" );
124 } 129 }
125 } 130 }
126 131
127 return addresses; 132 return addresses;
128} 133}
129 134
130mailimf_fields *MailWrapper::createImfFields( Mail *mail ) 135mailimf_fields *MailWrapper::createImfFields( Mail *mail )
131{ 136{
132 mailimf_fields *fields; 137 mailimf_fields *fields;
133 mailimf_field *xmailer; 138 mailimf_field *xmailer;
134 mailimf_mailbox *sender, *fromBox; 139 mailimf_mailbox *sender, *fromBox;
135 mailimf_mailbox_list *from; 140 mailimf_mailbox_list *from;
136 mailimf_address_list *to, *cc, *bcc, *reply; 141 mailimf_address_list *to, *cc, *bcc, *reply;
137 char *subject = strdup( mail->getSubject().latin1() ); 142 char *subject = strdup( mail->getSubject().latin1() );
138 int err; 143 int err;
139 144
140 sender = newMailbox( mail->getName(), mail->getMail() ); 145 sender = newMailbox( mail->getName(), mail->getMail() );
141 if ( sender == NULL ) goto err_free; 146 if ( sender == NULL ) goto err_free;
142 147
143 fromBox = newMailbox( mail->getName(), mail->getMail() ); 148 fromBox = newMailbox( mail->getName(), mail->getMail() );
144 if ( fromBox == NULL ) goto err_free_sender; 149 if ( fromBox == NULL ) goto err_free_sender;
145 150
146 from = mailimf_mailbox_list_new_empty(); 151 from = mailimf_mailbox_list_new_empty();
147 if ( from == NULL ) goto err_free_fromBox; 152 if ( from == NULL ) goto err_free_fromBox;
148 153
149 err = mailimf_mailbox_list_add( from, fromBox ); 154 err = mailimf_mailbox_list_add( from, fromBox );
150 if ( err != MAILIMF_NO_ERROR ) goto err_free_from; 155 if ( err != MAILIMF_NO_ERROR ) goto err_free_from;
151 156
152 to = parseAddresses( mail->getTo() ); 157 to = parseAddresses( mail->getTo() );
153 if ( to == NULL ) goto err_free_from; 158 if ( to == NULL ) goto err_free_from;
154 159
155 cc = parseAddresses( mail->getCC() ); 160 cc = parseAddresses( mail->getCC() );
156 bcc = parseAddresses( mail->getBCC() ); 161 bcc = parseAddresses( mail->getBCC() );
157 reply = parseAddresses( mail->getReply() ); 162 reply = parseAddresses( mail->getReply() );
158 163
159 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, 164 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
160 NULL, NULL, subject ); 165 NULL, NULL, subject );
161 if ( fields == NULL ) goto err_free_reply; 166 if ( fields == NULL ) goto err_free_reply;
162 167
163 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), 168 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
164 strdup( USER_AGENT ) ); 169 strdup( USER_AGENT ) );
165 if ( xmailer == NULL ) goto err_free_fields; 170 if ( xmailer == NULL ) goto err_free_fields;
166 171
167 err = mailimf_fields_add( fields, xmailer ); 172 err = mailimf_fields_add( fields, xmailer );
168 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; 173 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer;
169 174
170 return fields; // Success :) 175 return fields; // Success :)
171 176
172err_free_xmailer: 177err_free_xmailer:
173 mailimf_field_free( xmailer ); 178 mailimf_field_free( xmailer );
174err_free_fields: 179err_free_fields:
175 mailimf_fields_free( fields ); 180 mailimf_fields_free( fields );
176err_free_reply: 181err_free_reply:
177 mailimf_address_list_free( reply ); 182 mailimf_address_list_free( reply );
178 mailimf_address_list_free( bcc ); 183 mailimf_address_list_free( bcc );
179 mailimf_address_list_free( cc ); 184 mailimf_address_list_free( cc );
180 mailimf_address_list_free( to ); 185 mailimf_address_list_free( to );
181err_free_from: 186err_free_from:
182 mailimf_mailbox_list_free( from ); 187 mailimf_mailbox_list_free( from );
183err_free_fromBox: 188err_free_fromBox:
184 mailimf_mailbox_free( fromBox ); 189 mailimf_mailbox_free( fromBox );
185err_free_sender: 190err_free_sender:
186 mailimf_mailbox_free( sender ); 191 mailimf_mailbox_free( sender );
187err_free: 192err_free:
188 free( subject ); 193 free( subject );
189 qDebug( "createImfFields - error" ); 194 qDebug( "createImfFields - error" );
190 195
191 return NULL; // Error :( 196 return NULL; // Error :(
192} 197}
193 198
194mailmime *MailWrapper::buildTxtPart( QString str ) 199mailmime *MailWrapper::buildTxtPart( QString str )
195{ 200{
196 mailmime *txtPart; 201 mailmime *txtPart;
197 mailmime_fields *fields; 202 mailmime_fields *fields;
198 mailmime_content *content; 203 mailmime_content *content;
199 mailmime_parameter *param; 204 mailmime_parameter *param;
200 char *txt = strdup( str.latin1() ); 205 char *txt = strdup( str.latin1() );
201 int err; 206 int err;
202 207
203 param = mailmime_parameter_new( strdup( "charset" ), 208 param = mailmime_parameter_new( strdup( "charset" ),
204 strdup( "iso-8859-1" ) ); 209 strdup( "iso-8859-1" ) );
205 if ( param == NULL ) goto err_free; 210 if ( param == NULL ) goto err_free;
206 211
207 content = mailmime_content_new_with_str( "text/plain" ); 212 content = mailmime_content_new_with_str( "text/plain" );
208 if ( content == NULL ) goto err_free_param; 213 if ( content == NULL ) goto err_free_param;
209 214
210 err = clist_append( content->ct_parameters, param ); 215 err = clist_append( content->ct_parameters, param );
211 if ( err != MAILIMF_NO_ERROR ) goto err_free_content; 216 if ( err != MAILIMF_NO_ERROR ) goto err_free_content;
212 217
213 fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); 218 fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT );
214 if ( fields == NULL ) goto err_free_content; 219 if ( fields == NULL ) goto err_free_content;
215 220
216 txtPart = mailmime_new_empty( content, fields ); 221 txtPart = mailmime_new_empty( content, fields );
217 if ( txtPart == NULL ) goto err_free_fields; 222 if ( txtPart == NULL ) goto err_free_fields;
218 223
219 err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); 224 err = mailmime_set_body_text( txtPart, txt, strlen( txt ) );
220 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 225 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
221 226
222 return txtPart; // Success :) 227 return txtPart; // Success :)
223 228
224err_free_txtPart: 229err_free_txtPart:
225 mailmime_free( txtPart ); 230 mailmime_free( txtPart );
226err_free_fields: 231err_free_fields:
227 mailmime_fields_free( fields ); 232 mailmime_fields_free( fields );
228err_free_content: 233err_free_content:
229 mailmime_content_free( content ); 234 mailmime_content_free( content );
230err_free_param: 235err_free_param:
231 mailmime_parameter_free( param ); 236 mailmime_parameter_free( param );
232err_free: 237err_free:
233 free( txt ); 238 free( txt );
234 qDebug( "buildTxtPart - error" ); 239 qDebug( "buildTxtPart - error" );
235 240
236 return NULL; // Error :( 241 return NULL; // Error :(
237} 242}
238 243
239mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype ) 244mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype )
240{ 245{
241 mailmime * filePart; 246 mailmime * filePart;
242 mailmime_fields * fields; 247 mailmime_fields * fields;
243 mailmime_content * content; 248 mailmime_content * content;
244 mailmime_parameter * param = NULL; 249 mailmime_parameter * param = NULL;
245 int err; 250 int err;
246 251
247 int pos = filename.findRev( '/' ); 252 int pos = filename.findRev( '/' );
248 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 253 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
249 char *name = strdup( tmp.latin1() ); // just filename 254 char *name = strdup( tmp.latin1() ); // just filename
250 char *file = strdup( filename.latin1() ); // full name with path 255 char *file = strdup( filename.latin1() ); // full name with path
251 char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain 256 char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain
252 257
253 fields = mailmime_fields_new_filename( 258 fields = mailmime_fields_new_filename(
254 MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, 259 MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name,
255 MAILMIME_MECHANISM_BASE64 ); 260 MAILMIME_MECHANISM_BASE64 );
256 if ( fields == NULL ) goto err_free; 261 if ( fields == NULL ) goto err_free;
257 262
258 content = mailmime_content_new_with_str( mime ); 263 content = mailmime_content_new_with_str( mime );
259 if ( content == NULL ) goto err_free_fields; 264 if ( content == NULL ) goto err_free_fields;
260 265
261 if ( mimetype.compare( "text/plain" ) == 0 ) { 266 if ( mimetype.compare( "text/plain" ) == 0 ) {
262 param = mailmime_parameter_new( strdup( "charset" ), 267 param = mailmime_parameter_new( strdup( "charset" ),
263 strdup( "iso-8859-1" ) ); 268 strdup( "iso-8859-1" ) );
264 if ( param == NULL ) goto err_free_content; 269 if ( param == NULL ) goto err_free_content;
265 270
266 err = clist_append( content->ct_parameters, param ); 271 err = clist_append( content->ct_parameters, param );
267 if ( err != MAILIMF_NO_ERROR ) goto err_free_param; 272 if ( err != MAILIMF_NO_ERROR ) goto err_free_param;
268 } 273 }
269 274
270 filePart = mailmime_new_empty( content, fields ); 275 filePart = mailmime_new_empty( content, fields );
271 if ( filePart == NULL ) goto err_free_param; 276 if ( filePart == NULL ) goto err_free_param;
272 277
273 err = mailmime_set_body_file( filePart, file ); 278 err = mailmime_set_body_file( filePart, file );
274 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; 279 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart;
275 280
276 return filePart; // Success :) 281 return filePart; // Success :)
277 282
278err_free_filePart: 283err_free_filePart:
279 mailmime_free( filePart ); 284 mailmime_free( filePart );
280err_free_param: 285err_free_param:
281 if ( param != NULL ) mailmime_parameter_free( param ); 286 if ( param != NULL ) mailmime_parameter_free( param );
282err_free_content: 287err_free_content:
283 mailmime_content_free( content ); 288 mailmime_content_free( content );
284err_free_fields: 289err_free_fields:
285 mailmime_fields_free( fields ); 290 mailmime_fields_free( fields );
286err_free: 291err_free:
287 free( name ); 292 free( name );
288 free( mime ); 293 free( mime );
289 free( file ); 294 free( file );
290 qDebug( "buildFilePart - error" ); 295 qDebug( "buildFilePart - error" );
291 296
292 return NULL; // Error :( 297 return NULL; // Error :(
293} 298}
294 299
295void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) 300void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files )
296{ 301{
297 Attachment *it; 302 Attachment *it;
298 for ( it = files.first(); it; it = files.next() ) { 303 for ( it = files.first(); it; it = files.next() ) {
299 qDebug( "Adding file" ); 304 qDebug( "Adding file" );
300 mailmime *filePart; 305 mailmime *filePart;
301 int err; 306 int err;
302 307
303 filePart = buildFilePart( it->getFileName(), it->getMimeType() ); 308 filePart = buildFilePart( it->getFileName(), it->getMimeType() );
304 if ( filePart == NULL ) goto err_free; 309 if ( filePart == NULL ) goto err_free;
305 310
306 err = mailmime_smart_add_part( message, filePart ); 311 err = mailmime_smart_add_part( message, filePart );
307 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; 312 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart;
308 313
309 continue; // Success :) 314 continue; // Success :)
310 315
311 err_free_filePart: 316 err_free_filePart:
312 mailmime_free( filePart ); 317 mailmime_free( filePart );
313 err_free: 318 err_free:
314 qDebug( "addFileParts: error adding file:" ); 319 qDebug( "addFileParts: error adding file:" );
315 qDebug( it->getFileName() ); 320 qDebug( it->getFileName() );
316 } 321 }
317} 322}
318 323
319mailmime *MailWrapper::createMimeMail( Mail *mail ) 324mailmime *MailWrapper::createMimeMail( Mail *mail )
320{ 325{
321 mailmime *message, *txtPart; 326 mailmime *message, *txtPart;
322 mailimf_fields *fields; 327 mailimf_fields *fields;
323 int err; 328 int err;
324 329
325 fields = createImfFields( mail ); 330 fields = createImfFields( mail );
326 if ( fields == NULL ) goto err_free; 331 if ( fields == NULL ) goto err_free;
327 332
328 message = mailmime_new_message_data( NULL ); 333 message = mailmime_new_message_data( NULL );
329 if ( message == NULL ) goto err_free_fields; 334 if ( message == NULL ) goto err_free_fields;
330 335
331 mailmime_set_imf_fields( message, fields ); 336 mailmime_set_imf_fields( message, fields );
332 337
333 txtPart = buildTxtPart( mail->getMessage() ); 338 txtPart = buildTxtPart( mail->getMessage() );
334 if ( txtPart == NULL ) goto err_free_message; 339 if ( txtPart == NULL ) goto err_free_message;
335 340
336 err = mailmime_smart_add_part( message, txtPart ); 341 err = mailmime_smart_add_part( message, txtPart );
337 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 342 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
338 343
339 addFileParts( message, mail->getAttachments() ); 344 addFileParts( message, mail->getAttachments() );
340 345
341 return message; // Success :) 346 return message; // Success :)
342 347
343err_free_txtPart: 348err_free_txtPart:
344 mailmime_free( txtPart ); 349 mailmime_free( txtPart );
345err_free_message: 350err_free_message:
346 mailmime_free( message ); 351 mailmime_free( message );
347err_free_fields: 352err_free_fields:
348 mailimf_fields_free( fields ); 353 mailimf_fields_free( fields );
349err_free: 354err_free:
350 qDebug( "createMimeMail: error" ); 355 qDebug( "createMimeMail: error" );
351 356
352 return NULL; // Error :( 357 return NULL; // Error :(
353} 358}
354 359
355mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type ) 360mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type )
356{ 361{
357 mailimf_field *field; 362 mailimf_field *field;
358 clistiter *it; 363 clistiter *it;
359 364
360 it = clist_begin( fields->fld_list ); 365 it = clist_begin( fields->fld_list );
361 while ( it ) { 366 while ( it ) {
362 field = (mailimf_field *) it->data; 367 field = (mailimf_field *) it->data;
363 if ( field->fld_type == type ) { 368 if ( field->fld_type == type ) {
364 return field; 369 return field;
365 } 370 }
366 it = it->next; 371 it = it->next;
367 } 372 }
368 373
369 return NULL; 374 return NULL;
370} 375}
371 376
372static void addRcpts( clist *list, mailimf_address_list *addr_list ) 377static void addRcpts( clist *list, mailimf_address_list *addr_list )
373{ 378{
374 clistiter *it, *it2; 379 clistiter *it, *it2;
375 380
376 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { 381 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) {
377 mailimf_address *addr; 382 mailimf_address *addr;
378 addr = (mailimf_address *) it->data; 383 addr = (mailimf_address *) it->data;
379 384
380 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { 385 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) {
381 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); 386 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL );
382 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { 387 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) {
383 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; 388 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list;
384 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { 389 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
385 mailimf_mailbox *mbox; 390 mailimf_mailbox *mbox;
386 mbox = (mailimf_mailbox *) it2->data; 391 mbox = (mailimf_mailbox *) it2->data;
387 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); 392 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL );
388 } 393 }
389 } 394 }
390 } 395 }
391} 396}
392 397
393clist *MailWrapper::createRcptList( mailimf_fields *fields ) 398clist *MailWrapper::createRcptList( mailimf_fields *fields )
394{ 399{
395 clist *rcptList; 400 clist *rcptList;
396 mailimf_field *field; 401 mailimf_field *field;
397 402
398 rcptList = esmtp_address_list_new(); 403 rcptList = esmtp_address_list_new();
399 404
400 field = getField( fields, MAILIMF_FIELD_TO ); 405 field = getField( fields, MAILIMF_FIELD_TO );
401 if ( field && (field->fld_type == MAILIMF_FIELD_TO) 406 if ( field && (field->fld_type == MAILIMF_FIELD_TO)
402 && field->fld_data.fld_to->to_addr_list ) { 407 && field->fld_data.fld_to->to_addr_list ) {
403 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); 408 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
404 } 409 }
405 410
406 field = getField( fields, MAILIMF_FIELD_CC ); 411 field = getField( fields, MAILIMF_FIELD_CC );
407 if ( field && (field->fld_type == MAILIMF_FIELD_CC) 412 if ( field && (field->fld_type == MAILIMF_FIELD_CC)
408 && field->fld_data.fld_cc->cc_addr_list ) { 413 && field->fld_data.fld_cc->cc_addr_list ) {
409 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); 414 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
410 } 415 }
411 416
412 field = getField( fields, MAILIMF_FIELD_BCC ); 417 field = getField( fields, MAILIMF_FIELD_BCC );
413 if ( field && (field->fld_type == MAILIMF_FIELD_BCC) 418 if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
414 && field->fld_data.fld_bcc->bcc_addr_list ) { 419 && field->fld_data.fld_bcc->bcc_addr_list ) {
415 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); 420 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
416 } 421 }
417 422
418 return rcptList; 423 return rcptList;
419} 424}
420 425
421char *MailWrapper::getFrom( mailmime *mail ) 426char *MailWrapper::getFrom( mailmime *mail )
422{ 427{
423 char *from = NULL; 428 char *from = NULL;
424 429
425 mailimf_field *ffrom; 430 mailimf_field *ffrom;
426 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); 431 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
427 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) 432 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM)
428 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { 433 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) {
429 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; 434 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list;
430 clistiter *it; 435 clistiter *it;
431 for ( it = clist_begin( cl ); it; it = it->next ) { 436 for ( it = clist_begin( cl ); it; it = it->next ) {
432 mailimf_mailbox *mb = (mailimf_mailbox *) it->data; 437 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
433 from = strdup( mb->mb_addr_spec ); 438 from = strdup( mb->mb_addr_spec );
434 } 439 }
435 } 440 }
436 441
437 return from; 442 return from;
438} 443}
439 444
440SMTPaccount *MailWrapper::getAccount( QString from ) 445SMTPaccount *MailWrapper::getAccount( QString from )
441{ 446{
442 SMTPaccount *smtp; 447 SMTPaccount *smtp;
443 448
444 QList<Account> list = settings->getAccounts(); 449 QList<Account> list = settings->getAccounts();
445 Account *it; 450 Account *it;
446 for ( it = list.first(); it; it = list.next() ) { 451 for ( it = list.first(); it; it = list.next() ) {
447 if ( it->getType().compare( "SMTP" ) == 0 ) { 452 if ( it->getType().compare( "SMTP" ) == 0 ) {
448 smtp = static_cast<SMTPaccount *>(it); 453 smtp = static_cast<SMTPaccount *>(it);
449 if ( smtp->getMail().compare( from ) == 0 ) { 454 if ( smtp->getMail().compare( from ) == 0 ) {
450 qDebug( "SMTPaccount found for" ); 455 qDebug( "SMTPaccount found for" );
451 qDebug( from ); 456 qDebug( from );
452 return smtp; 457 return smtp;
453 } 458 }
454 } 459 }
455 } 460 }
456 461
457 return NULL; 462 return NULL;
458} 463}
459 464
460QString MailWrapper::getTmpFile() { 465QString MailWrapper::getTmpFile() {
461 int num = 0; 466 int num = 0;
462 QString unique; 467 QString unique;
463 468
464 QDir dir( "/tmp" ); 469 QDir dir( "/tmp" );
465 QStringList::Iterator it; 470 QStringList::Iterator it;
466 471
467 QStringList list = dir.entryList( "opiemail-tmp-*" ); 472 QStringList list = dir.entryList( "opiemail-tmp-*" );
468 do { 473 do {
469 unique.setNum( num++ ); 474 unique.setNum( num++ );
470 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); 475 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 );
471 476
472 return "/tmp/opiemail-tmp-" + unique; 477 return "/tmp/opiemail-tmp-" + unique;
473} 478}
474 479
475void MailWrapper::writeToFile( QString file, mailmime *mail ) 480void MailWrapper::writeToFile( QString file, mailmime *mail )
476{ 481{
477 FILE *f; 482 FILE *f;
478 int err, col = 0; 483 int err, col = 0;
479 484
480 f = fopen( file.latin1(), "w" ); 485 f = fopen( file.latin1(), "w" );
481 if ( f == NULL ) { 486 if ( f == NULL ) {
482 qDebug( "writeToFile: error opening file" ); 487 qDebug( "writeToFile: error opening file" );
483 return; 488 return;
484 } 489 }
485 490
486 err = mailmime_write( f, &col, mail ); 491 err = mailmime_write( f, &col, mail );
487 if ( err != MAILIMF_NO_ERROR ) { 492 if ( err != MAILIMF_NO_ERROR ) {
488 fclose( f ); 493 fclose( f );
489 qDebug( "writeToFile: error writing mailmime" ); 494 qDebug( "writeToFile: error writing mailmime" );
490 return; 495 return;
491 } 496 }
492 497
493 fclose( f ); 498 fclose( f );
494} 499}
495 500
496void MailWrapper::readFromFile( QString file, char **data, size_t *size ) 501void MailWrapper::readFromFile( QString file, char **data, size_t *size )
497{ 502{
498 char *buf; 503 char *buf;
499 struct stat st; 504 struct stat st;
500 int fd, count = 0, total = 0; 505 int fd, count = 0, total = 0;
501 506
502 fd = open( file.latin1(), O_RDONLY, 0 ); 507 fd = open( file.latin1(), O_RDONLY, 0 );
503 if ( fd == -1 ) return; 508 if ( fd == -1 ) return;
504 509
505 if ( fstat( fd, &st ) != 0 ) goto err_close; 510 if ( fstat( fd, &st ) != 0 ) goto err_close;
506 if ( !st.st_size ) goto err_close; 511 if ( !st.st_size ) goto err_close;
507 512
508 buf = (char *) malloc( st.st_size ); 513 buf = (char *) malloc( st.st_size );
509 if ( !buf ) goto err_close; 514 if ( !buf ) goto err_close;
510 515
511 while ( ( total < st.st_size ) && ( count >= 0 ) ) { 516 while ( ( total < st.st_size ) && ( count >= 0 ) ) {
512 count = read( fd, buf + total, st.st_size - total ); 517 count = read( fd, buf + total, st.st_size - total );
513 total += count; 518 total += count;
514 } 519 }
515 if ( count < 0 ) goto err_free; 520 if ( count < 0 ) goto err_free;
516 521
517 *data = buf; 522 *data = buf;
518 *size = st.st_size; 523 *size = st.st_size;
519 524
520 close( fd ); 525 close( fd );
521 526
522 return; // Success :) 527 return; // Success :)
523 528
524err_free: 529err_free:
525 free( buf ); 530 free( buf );
526err_close: 531err_close:
527 close( fd ); 532 close( fd );
528} 533}
529 534
530void progress( size_t current, size_t maximum ) 535void progress( size_t current, size_t maximum )
531{ 536{
532 qDebug( "Current: %i of %i", current, maximum ); 537 qDebug( "Current: %i of %i", current, maximum );
533} 538}
534 539
535void MailWrapper::smtpSend( mailmime *mail ) 540void MailWrapper::smtpSend( mailmime *mail )
536{ 541{
537 mailsmtp *session; 542 mailsmtp *session;
538 clist *rcpts; 543 clist *rcpts;
539 char *from, *data, *server, *user = NULL, *pass = NULL; 544 char *from, *data, *server, *user = NULL, *pass = NULL;
540 size_t size; 545 size_t size;
541 int err; 546 int err;
542 bool ssl; 547 bool ssl;
543 uint16_t port; 548 uint16_t port;
544 549
545 550
546 from = getFrom( mail ); 551 from = getFrom( mail );
547 SMTPaccount *smtp = getAccount( from ); 552 SMTPaccount *smtp = getAccount( from );
548 if ( smtp == NULL ) { 553 if ( smtp == NULL ) {
549 free(from); 554 free(from);
550 return; 555 return;
551 } 556 }
552 server = strdup( smtp->getServer().latin1() ); 557 server = strdup( smtp->getServer().latin1() );
553 ssl = smtp->getSSL(); 558 ssl = smtp->getSSL();
554 port = smtp->getPort().toUInt(); 559 port = smtp->getPort().toUInt();
555 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 560 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
556 561
557 QString file = getTmpFile(); 562 QString file = getTmpFile();
558 writeToFile( file, mail ); 563 writeToFile( file, mail );
559 readFromFile( file, &data, &size ); 564 readFromFile( file, &data, &size );
560 QFile f( file ); 565 QFile f( file );
561 f.remove(); 566 f.remove();
562 567
563 session = mailsmtp_new( 20, &progress ); 568 session = mailsmtp_new( 20, &progress );
564 if ( session == NULL ) goto free_mem; 569 if ( session == NULL ) goto free_mem;
565 570
566 qDebug( "Servername %s at port %i", server, port ); 571 qDebug( "Servername %s at port %i", server, port );
567 if ( ssl ) { 572 if ( ssl ) {
568 qDebug( "SSL session" ); 573 qDebug( "SSL session" );
569 err = mailsmtp_ssl_connect( session, server, port ); 574 err = mailsmtp_ssl_connect( session, server, port );
570 } else { 575 } else {
571 qDebug( "No SSL session" ); 576 qDebug( "No SSL session" );
572 err = mailsmtp_socket_connect( session, server, port ); 577 err = mailsmtp_socket_connect( session, server, port );
573 } 578 }
574 if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; 579 if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session;
575 580
576 err = mailsmtp_init( session ); 581 err = mailsmtp_init( session );
577 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; 582 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session;
578 583
579 qDebug( "INIT OK" ); 584 qDebug( "INIT OK" );
580 585
581 if ( smtp->getLogin() ) { 586 if ( smtp->getLogin() ) {
582 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { 587 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
583 // get'em 588 // get'em
584 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); 589 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true );
585 login.show(); 590 login.show();
586 if ( QDialog::Accepted == login.exec() ) { 591 if ( QDialog::Accepted == login.exec() ) {
587 // ok 592 // ok
588 user = strdup( login.getUser().latin1() ); 593 user = strdup( login.getUser().latin1() );
589 pass = strdup( login.getPassword().latin1() ); 594 pass = strdup( login.getPassword().latin1() );
590 } else { 595 } else {
591 goto free_con_session; 596 goto free_con_session;
592 } 597 }
593 } else { 598 } else {
594 user = strdup( smtp->getUser().latin1() ); 599 user = strdup( smtp->getUser().latin1() );
595 pass = strdup( smtp->getPassword().latin1() ); 600 pass = strdup( smtp->getPassword().latin1() );
596 } 601 }
597 qDebug( "session->auth: %i", session->auth); 602 qDebug( "session->auth: %i", session->auth);
598 err = mailsmtp_auth( session, user, pass ); 603 err = mailsmtp_auth( session, user, pass );
599 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); 604 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
600 qDebug( "Done auth!" ); 605 qDebug( "Done auth!" );
601 } 606 }
602 607
603 err = mailsmtp_send( session, from, rcpts, data, size ); 608 err = mailsmtp_send( session, from, rcpts, data, size );
604 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; 609 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session;
605 610
606 qDebug( "Mail sent." ); 611 qDebug( "Mail sent." );
607 612
608free_con_session: 613free_con_session:
609 mailsmtp_quit( session ); 614 mailsmtp_quit( session );
610free_mem_session: 615free_mem_session:
611 mailsmtp_free( session ); 616 mailsmtp_free( session );
612free_mem: 617free_mem:
613 smtp_address_list_free( rcpts ); 618 smtp_address_list_free( rcpts );
614 free( data ); 619 free( data );
615 free( server ); 620 free( server );
616 if ( smtp->getLogin() ) { 621 if ( smtp->getLogin() ) {
617 free( user ); 622 free( user );
618 free( pass ); 623 free( pass );
619 } 624 }
620 free( from ); 625 free( from );
621} 626}
622 627
623void MailWrapper::sendMail( Mail mail ) 628void MailWrapper::sendMail( Mail mail )
624{ 629{
625 mailmime *mimeMail; 630 mailmime *mimeMail;
626 631
627 mimeMail = createMimeMail( &mail ); 632 mimeMail = createMimeMail( &mail );
628 if ( mimeMail == NULL ) { 633 if ( mimeMail == NULL ) {
629 qDebug( "sendMail: error creating mime mail" ); 634 qDebug( "sendMail: error creating mime mail" );
630 } else { 635 } else {
631 smtpSend( mimeMail ); 636 smtpSend( mimeMail );
632 mailmime_free( mimeMail ); 637 mailmime_free( mimeMail );
633 } 638 }
634} 639}
635 640
636Mail::Mail() 641Mail::Mail()
637 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") 642 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("")
638{ 643{
639} 644}
diff --git a/noncore/net/mail/mailwrapper.h b/noncore/net/mail/mailwrapper.h
index 6994dd8..d78f8e9 100644
--- a/noncore/net/mail/mailwrapper.h
+++ b/noncore/net/mail/mailwrapper.h
@@ -1,123 +1,124 @@
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 <libetpan/mailmime.h> 6#include <libetpan/mailmime.h>
7#include <libetpan/mailimf.h> 7#include <libetpan/mailimf.h>
8#include <libetpan/mailsmtp.h> 8#include <libetpan/mailsmtp.h>
9#include <libetpan/mailstorage.h> 9#include <libetpan/mailstorage.h>
10#include <libetpan/maildriver.h> 10#include <libetpan/maildriver.h>
11#include <qbitarray.h> 11#include <qbitarray.h>
12#include <qdatetime.h> 12#include <qdatetime.h>
13 13
14#include "settings.h" 14#include "settings.h"
15 15
16class Attachment 16class Attachment
17{ 17{
18public: 18public:
19 Attachment( DocLnk lnk ); 19 Attachment( DocLnk lnk );
20 virtual ~Attachment(){} 20 virtual ~Attachment(){}
21 const QString getFileName()const{ return doc.file(); } 21 const QString getFileName()const{ return doc.file(); }
22 const QString getName()const{ return doc.name(); } 22 const QString getName()const{ return doc.name(); }
23 const QString getMimeType()const{ return doc.type(); } 23 const QString getMimeType()const{ return doc.type(); }
24 const QPixmap getPixmap()const{ return doc.pixmap(); } 24 const QPixmap getPixmap()const{ return doc.pixmap(); }
25 const int getSize()const { return size; } 25 const int getSize()const { return size; }
26 DocLnk getDocLnk() { return doc; } 26 DocLnk getDocLnk() { return doc; }
27 27
28protected: 28protected:
29 DocLnk doc; 29 DocLnk doc;
30 int size; 30 int size;
31 31
32}; 32};
33 33
34class Mail 34class Mail
35{ 35{
36public: 36public:
37 Mail(); 37 Mail();
38 /* Possible that this destructor must not be declared virtual 38 /* Possible that this destructor must not be declared virtual
39 * 'cause it seems that it will never have some child classes. 39 * 'cause it seems that it will never have some child classes.
40 * in this case this object will not get a virtual table -> memory and 40 * in this case this object will not get a virtual table -> memory and
41 * speed will be a little bit better? 41 * speed will be a little bit better?
42 */ 42 */
43 virtual ~Mail(){} 43 virtual ~Mail(){}
44 void addAttachment( Attachment *att ) { attList.append( att ); } 44 void addAttachment( Attachment *att ) { attList.append( att ); }
45 const QList<Attachment>& getAttachments()const { return attList; } 45 const QList<Attachment>& getAttachments()const { return attList; }
46 void removeAttachment( Attachment *att ) { attList.remove( att ); } 46 void removeAttachment( Attachment *att ) { attList.remove( att ); }
47 const QString&getName()const { return name; } 47 const QString&getName()const { return name; }
48 void setName( QString s ) { name = s; } 48 void setName( QString s ) { name = s; }
49 const QString&getMail()const{ return mail; } 49 const QString&getMail()const{ return mail; }
50 void setMail( const QString&s ) { mail = s; } 50 void setMail( const QString&s ) { mail = s; }
51 const QString&getTo()const{ return to; } 51 const QString&getTo()const{ return to; }
52 void setTo( const QString&s ) { to = s; } 52 void setTo( const QString&s ) { to = s; }
53 const QString&getCC()const{ return cc; } 53 const QString&getCC()const{ return cc; }
54 void setCC( const QString&s ) { cc = s; } 54 void setCC( const QString&s ) { cc = s; }
55 const QString&getBCC()const { return bcc; } 55 const QString&getBCC()const { return bcc; }
56 void setBCC( const QString&s ) { bcc = s; } 56 void setBCC( const QString&s ) { bcc = s; }
57 const QString&getMessage()const { return message; } 57 const QString&getMessage()const { return message; }
58 void setMessage( const QString&s ) { message = s; } 58 void setMessage( const QString&s ) { message = s; }
59 const QString&getSubject()const { return subject; } 59 const QString&getSubject()const { return subject; }
60 void setSubject( const QString&s ) { subject = s; } 60 void setSubject( const QString&s ) { subject = s; }
61 const QString&getReply()const{ return reply; } 61 const QString&getReply()const{ return reply; }
62 void setReply( const QString&a ) { reply = a; } 62 void setReply( const QString&a ) { reply = a; }
63 63
64private: 64private:
65 QList<Attachment> attList; 65 QList<Attachment> attList;
66 QString name, mail, to, cc, bcc, reply, subject, message; 66 QString name, mail, to, cc, bcc, reply, subject, message;
67}; 67};
68 68
69class Folder : public QObject 69class Folder : public QObject
70{ 70{
71 Q_OBJECT 71 Q_OBJECT
72 72
73public: 73public:
74 Folder( const QString&init_name ); 74 Folder( const QString&init_name,const QString&sep );
75 const QString&getDisplayName()const { return nameDisplay; } 75 const QString&getDisplayName()const { return nameDisplay; }
76 const QString&getName()const { return name; } 76 const QString&getName()const { return name; }
77 virtual bool may_select()const{return true;}; 77 virtual bool may_select()const{return true;};
78 const QString&Separator()const;
78 79
79protected: 80protected:
80 QString nameDisplay, name; 81 QString nameDisplay, name, separator;
81 82
82}; 83};
83 84
84class IMAPFolder : public Folder 85class IMAPFolder : public Folder
85{ 86{
86 public: 87 public:
87 IMAPFolder(const QString&name,bool select=true,const QString&prefix="" ); 88 IMAPFolder(const QString&name, const QString&sep, bool select=true,const QString&prefix="" );
88 virtual bool may_select()const{return m_MaySelect;} 89 virtual bool may_select()const{return m_MaySelect;}
89 private: 90 private:
90 bool m_MaySelect; 91 bool m_MaySelect;
91}; 92};
92 93
93class MailWrapper : public QObject 94class MailWrapper : public QObject
94{ 95{
95 Q_OBJECT 96 Q_OBJECT
96 97
97public: 98public:
98 MailWrapper( Settings *s ); 99 MailWrapper( Settings *s );
99 void sendMail( Mail mail ); 100 void sendMail( Mail mail );
100 101
101private: 102private:
102 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 103 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
103 mailimf_address_list *parseAddresses(const QString&addr ); 104 mailimf_address_list *parseAddresses(const QString&addr );
104 mailimf_fields *createImfFields( Mail *mail ); 105 mailimf_fields *createImfFields( Mail *mail );
105 mailmime *buildTxtPart( QString str ); 106 mailmime *buildTxtPart( QString str );
106 mailmime *buildFilePart( QString filename, QString mimetype ); 107 mailmime *buildFilePart( QString filename, QString mimetype );
107 void addFileParts( mailmime *message, QList<Attachment> files ); 108 void addFileParts( mailmime *message, QList<Attachment> files );
108 mailmime *createMimeMail( Mail *mail ); 109 mailmime *createMimeMail( Mail *mail );
109 void smtpSend( mailmime *mail ); 110 void smtpSend( mailmime *mail );
110 mailimf_field *getField( mailimf_fields *fields, int type ); 111 mailimf_field *getField( mailimf_fields *fields, int type );
111 clist *createRcptList( mailimf_fields *fields ); 112 clist *createRcptList( mailimf_fields *fields );
112 char *getFrom( mailmime *mail ); 113 char *getFrom( mailmime *mail );
113 SMTPaccount *getAccount( QString from ); 114 SMTPaccount *getAccount( QString from );
114 void writeToFile( QString file, mailmime *mail ); 115 void writeToFile( QString file, mailmime *mail );
115 void readFromFile( QString file, char **data, size_t *size ); 116 void readFromFile( QString file, char **data, size_t *size );
116 static QString mailsmtpError( int err ); 117 static QString mailsmtpError( int err );
117 static QString getTmpFile(); 118 static QString getTmpFile();
118 119
119 Settings *settings; 120 Settings *settings;
120 121
121}; 122};
122 123
123#endif 124#endif
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index 075d8c7..4508a95 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -1,358 +1,358 @@
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 <libetpan/mailpop3.h> 4#include <libetpan/mailpop3.h>
5 5
6POP3wrapper::POP3wrapper( POP3account *a ) 6POP3wrapper::POP3wrapper( POP3account *a )
7{ 7{
8 account = a; 8 account = a;
9 m_pop3 = NULL; 9 m_pop3 = NULL;
10} 10}
11 11
12POP3wrapper::~POP3wrapper() 12POP3wrapper::~POP3wrapper()
13{ 13{
14 logout(); 14 logout();
15} 15}
16 16
17void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 17void POP3wrapper::pop3_progress( size_t current, size_t maximum )
18{ 18{
19 //qDebug( "POP3: %i of %i", current, maximum ); 19 //qDebug( "POP3: %i of %i", current, maximum );
20} 20}
21 21
22RecBody POP3wrapper::fetchBody( const RecMail &mail ) 22RecBody POP3wrapper::fetchBody( const RecMail &mail )
23{ 23{
24 int err = MAILPOP3_NO_ERROR; 24 int err = MAILPOP3_NO_ERROR;
25 char *message; 25 char *message;
26 size_t length = 0; 26 size_t length = 0;
27 27
28 login(); 28 login();
29 if ( !m_pop3 ) return RecBody(); 29 if ( !m_pop3 ) return RecBody();
30 30
31 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); 31 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
32 if ( err != MAILPOP3_NO_ERROR ) { 32 if ( err != MAILPOP3_NO_ERROR ) {
33 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); 33 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
34 return RecBody(); 34 return RecBody();
35 } 35 }
36 36
37 return parseBody( message ); 37 return parseBody( message );
38} 38}
39 39
40RecBody POP3wrapper::parseBody( const char *message ) 40RecBody POP3wrapper::parseBody( const char *message )
41{ 41{
42 int err = MAILIMF_NO_ERROR; 42 int err = MAILIMF_NO_ERROR;
43 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 43 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
44 size_t curTok = 0; 44 size_t curTok = 0;
45 mailimf_message *result = 0; 45 mailimf_message *result = 0;
46 RecBody body; 46 RecBody body;
47 47
48 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); 48 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
49 if ( err != MAILIMF_NO_ERROR ) { 49 if ( err != MAILIMF_NO_ERROR ) {
50 if (result) mailimf_message_free(result); 50 if (result) mailimf_message_free(result);
51 return body; 51 return body;
52 } 52 }
53 53
54 if ( result && result->msg_body && result->msg_body->bd_text ) { 54 if ( result && result->msg_body && result->msg_body->bd_text ) {
55 qDebug( "POP3: bodytext found" ); 55 qDebug( "POP3: bodytext found" );
56 // when curTok isn't set to 0 this line will fault! 'cause upper line faults! 56 // when curTok isn't set to 0 this line will fault! 'cause upper line faults!
57 body.setBodytext( QString( result->msg_body->bd_text ) ); 57 body.setBodytext( QString( result->msg_body->bd_text ) );
58 } 58 }
59 if (result) mailimf_message_free(result); 59 if (result) mailimf_message_free(result);
60 return body; 60 return body;
61} 61}
62 62
63void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 63void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
64{ 64{
65 int err = MAILPOP3_NO_ERROR; 65 int err = MAILPOP3_NO_ERROR;
66 char * header = 0; 66 char * header = 0;
67 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 67 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
68 size_t length = 0; 68 size_t length = 0;
69 carray * messages = 0; 69 carray * messages = 0;
70 70
71 login(); 71 login();
72 if (!m_pop3) return; 72 if (!m_pop3) return;
73 mailpop3_list( m_pop3, &messages ); 73 mailpop3_list( m_pop3, &messages );
74 74
75 for (unsigned int i = 0; i < carray_count(messages);++i) { 75 for (unsigned int i = 0; i < carray_count(messages);++i) {
76 mailpop3_msg_info *info; 76 mailpop3_msg_info *info;
77 err = mailpop3_get_msg_info(m_pop3,i+1,&info); 77 err = mailpop3_get_msg_info(m_pop3,i+1,&info);
78 if (info->msg_deleted) 78 if (info->msg_deleted)
79 continue; 79 continue;
80 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 80 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
81 if ( err != MAILPOP3_NO_ERROR ) { 81 if ( err != MAILPOP3_NO_ERROR ) {
82 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); 82 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
83 free(header); 83 free(header);
84 return; 84 return;
85 } 85 }
86 RecMail *mail = parseHeader( header ); 86 RecMail *mail = parseHeader( header );
87 mail->setNumber( info->msg_index ); 87 mail->setNumber( info->msg_index );
88 mail->setWrapper(this); 88 mail->setWrapper(this);
89 mail->setMsgsize(info->msg_size); 89 mail->setMsgsize(info->msg_size);
90 target.append( mail ); 90 target.append( mail );
91 free(header); 91 free(header);
92 } 92 }
93} 93}
94 94
95RecMail *POP3wrapper::parseHeader( const char *header ) 95RecMail *POP3wrapper::parseHeader( const char *header )
96{ 96{
97 int err = MAILIMF_NO_ERROR; 97 int err = MAILIMF_NO_ERROR;
98 size_t curTok = 0; 98 size_t curTok = 0;
99 RecMail *mail = new RecMail(); 99 RecMail *mail = new RecMail();
100 mailimf_fields *fields; 100 mailimf_fields *fields;
101 mailimf_references * refs; 101 mailimf_references * refs;
102 mailimf_keywords*keys; 102 mailimf_keywords*keys;
103 QString status; 103 QString status;
104 QString value; 104 QString value;
105 QBitArray mFlags(7); 105 QBitArray mFlags(7);
106 106
107 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 107 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
108 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 108 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
109 mailimf_field *field = (mailimf_field *) current->data; 109 mailimf_field *field = (mailimf_field *) current->data;
110 switch ( field->fld_type ) { 110 switch ( field->fld_type ) {
111 case MAILIMF_FIELD_FROM: 111 case MAILIMF_FIELD_FROM:
112 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 112 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
113 break; 113 break;
114 case MAILIMF_FIELD_TO: 114 case MAILIMF_FIELD_TO:
115 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 115 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
116 break; 116 break;
117 case MAILIMF_FIELD_CC: 117 case MAILIMF_FIELD_CC:
118 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 118 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
119 break; 119 break;
120 case MAILIMF_FIELD_BCC: 120 case MAILIMF_FIELD_BCC:
121 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 121 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
122 break; 122 break;
123 case MAILIMF_FIELD_SUBJECT: 123 case MAILIMF_FIELD_SUBJECT:
124 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); 124 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) );
125 break; 125 break;
126 case MAILIMF_FIELD_ORIG_DATE: 126 case MAILIMF_FIELD_ORIG_DATE:
127 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 127 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
128 break; 128 break;
129 case MAILIMF_FIELD_MESSAGE_ID: 129 case MAILIMF_FIELD_MESSAGE_ID:
130 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); 130 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value));
131 break; 131 break;
132 case MAILIMF_FIELD_REFERENCES: 132 case MAILIMF_FIELD_REFERENCES:
133 refs = field->fld_data.fld_references; 133 refs = field->fld_data.fld_references;
134 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 134 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
135 char * text = (char*)refs->mid_list->first->data; 135 char * text = (char*)refs->mid_list->first->data;
136 mail->setReplyto(QString(text)); 136 mail->setReplyto(QString(text));
137 } 137 }
138 break; 138 break;
139 case MAILIMF_FIELD_KEYWORDS: 139 case MAILIMF_FIELD_KEYWORDS:
140 keys = field->fld_data.fld_keywords; 140 keys = field->fld_data.fld_keywords;
141 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { 141 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
142 qDebug("Keyword: %s",(char*)cur->data); 142 qDebug("Keyword: %s",(char*)cur->data);
143 } 143 }
144 break; 144 break;
145 case MAILIMF_FIELD_OPTIONAL_FIELD: 145 case MAILIMF_FIELD_OPTIONAL_FIELD:
146 status = field->fld_data.fld_optional_field->fld_name; 146 status = field->fld_data.fld_optional_field->fld_name;
147 value = field->fld_data.fld_optional_field->fld_value; 147 value = field->fld_data.fld_optional_field->fld_value;
148 if (status.lower()=="status") { 148 if (status.lower()=="status") {
149 if (value.lower()=="ro") { 149 if (value.lower()=="ro") {
150 mFlags.setBit(FLAG_SEEN); 150 mFlags.setBit(FLAG_SEEN);
151 } 151 }
152 } else if (status.lower()=="x-status") { 152 } else if (status.lower()=="x-status") {
153 qDebug("X-Status: %s",value.latin1()); 153 qDebug("X-Status: %s",value.latin1());
154 if (value.lower()=="a") { 154 if (value.lower()=="a") {
155 155
156 mFlags.setBit(FLAG_ANSWERED); 156 mFlags.setBit(FLAG_ANSWERED);
157 } 157 }
158 } else { 158 } else {
159// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, 159// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name,
160// field->fld_data.fld_optional_field->fld_value); 160// field->fld_data.fld_optional_field->fld_value);
161 } 161 }
162 break; 162 break;
163 default: 163 default:
164 qDebug("Non parsed field"); 164 qDebug("Non parsed field");
165 break; 165 break;
166 } 166 }
167 } 167 }
168 if (fields) mailimf_fields_free(fields); 168 if (fields) mailimf_fields_free(fields);
169 mail->setFlags(mFlags); 169 mail->setFlags(mFlags);
170 return mail; 170 return mail;
171} 171}
172 172
173QString POP3wrapper::parseDateTime( mailimf_date_time *date ) 173QString POP3wrapper::parseDateTime( mailimf_date_time *date )
174{ 174{
175 char tmp[23]; 175 char tmp[23];
176 176
177 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 177 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
178 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 178 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
179 179
180 return QString( tmp ); 180 return QString( tmp );
181} 181}
182 182
183QString POP3wrapper::parseAddressList( mailimf_address_list *list ) 183QString POP3wrapper::parseAddressList( mailimf_address_list *list )
184{ 184{
185 QString result( "" ); 185 QString result( "" );
186 186
187 bool first = true; 187 bool first = true;
188 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 188 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
189 mailimf_address *addr = (mailimf_address *) current->data; 189 mailimf_address *addr = (mailimf_address *) current->data;
190 190
191 if ( !first ) { 191 if ( !first ) {
192 result.append( "," ); 192 result.append( "," );
193 } else { 193 } else {
194 first = false; 194 first = false;
195 } 195 }
196 196
197 switch ( addr->ad_type ) { 197 switch ( addr->ad_type ) {
198 case MAILIMF_ADDRESS_MAILBOX: 198 case MAILIMF_ADDRESS_MAILBOX:
199 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 199 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
200 break; 200 break;
201 case MAILIMF_ADDRESS_GROUP: 201 case MAILIMF_ADDRESS_GROUP:
202 result.append( parseGroup( addr->ad_data.ad_group ) ); 202 result.append( parseGroup( addr->ad_data.ad_group ) );
203 break; 203 break;
204 default: 204 default:
205 qDebug( "POP3: unkown mailimf address type" ); 205 qDebug( "POP3: unkown mailimf address type" );
206 break; 206 break;
207 } 207 }
208 } 208 }
209 209
210 return result; 210 return result;
211} 211}
212 212
213QString POP3wrapper::parseGroup( mailimf_group *group ) 213QString POP3wrapper::parseGroup( mailimf_group *group )
214{ 214{
215 QString result( "" ); 215 QString result( "" );
216 216
217 result.append( group->grp_display_name ); 217 result.append( group->grp_display_name );
218 result.append( ": " ); 218 result.append( ": " );
219 219
220 if ( group->grp_mb_list != NULL ) { 220 if ( group->grp_mb_list != NULL ) {
221 result.append( parseMailboxList( group->grp_mb_list ) ); 221 result.append( parseMailboxList( group->grp_mb_list ) );
222 } 222 }
223 223
224 result.append( ";" ); 224 result.append( ";" );
225 225
226 return result; 226 return result;
227} 227}
228 228
229QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) 229QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
230{ 230{
231 QString result( "" ); 231 QString result( "" );
232 232
233 if ( box->mb_display_name == NULL ) { 233 if ( box->mb_display_name == NULL ) {
234 result.append( box->mb_addr_spec ); 234 result.append( box->mb_addr_spec );
235 } else { 235 } else {
236 result.append( box->mb_display_name ); 236 result.append( box->mb_display_name );
237 result.append( " <" ); 237 result.append( " <" );
238 result.append( box->mb_addr_spec ); 238 result.append( box->mb_addr_spec );
239 result.append( ">" ); 239 result.append( ">" );
240 } 240 }
241 241
242 return result; 242 return result;
243} 243}
244 244
245QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) 245QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
246{ 246{
247 QString result( "" ); 247 QString result( "" );
248 248
249 bool first = true; 249 bool first = true;
250 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 250 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
251 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 251 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
252 252
253 if ( !first ) { 253 if ( !first ) {
254 result.append( "," ); 254 result.append( "," );
255 } else { 255 } else {
256 first = false; 256 first = false;
257 } 257 }
258 258
259 result.append( parseMailbox( box ) ); 259 result.append( parseMailbox( box ) );
260 } 260 }
261 261
262 return result; 262 return result;
263} 263}
264 264
265void POP3wrapper::login() 265void POP3wrapper::login()
266{ 266{
267 /* we'll hold the line */ 267 /* we'll hold the line */
268 if ( m_pop3 != NULL ) return; 268 if ( m_pop3 != NULL ) return;
269 269
270 const char *server, *user, *pass; 270 const char *server, *user, *pass;
271 uint16_t port; 271 uint16_t port;
272 int err = MAILPOP3_NO_ERROR; 272 int err = MAILPOP3_NO_ERROR;
273 273
274 server = account->getServer().latin1(); 274 server = account->getServer().latin1();
275 port = account->getPort().toUInt(); 275 port = account->getPort().toUInt();
276 user = account->getUser().latin1(); 276 user = account->getUser().latin1();
277 pass = account->getPassword().latin1(); 277 pass = account->getPassword().latin1();
278 278
279 m_pop3 = mailpop3_new( 200, &pop3_progress ); 279 m_pop3 = mailpop3_new( 200, &pop3_progress );
280 280
281 // connect 281 // connect
282 if (account->getSSL()) { 282 if (account->getSSL()) {
283 err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); 283 err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
284 } else { 284 } else {
285 err = mailpop3_socket_connect( m_pop3, (char*)server, port ); 285 err = mailpop3_socket_connect( m_pop3, (char*)server, port );
286 } 286 }
287 287
288 if ( err != MAILPOP3_NO_ERROR ) { 288 if ( err != MAILPOP3_NO_ERROR ) {
289 qDebug( "pop3: error connecting to %s\n reason: %s", server, 289 qDebug( "pop3: error connecting to %s\n reason: %s", server,
290 m_pop3->pop3_response ); 290 m_pop3->pop3_response );
291 mailpop3_free( m_pop3 ); 291 mailpop3_free( m_pop3 );
292 m_pop3 = NULL; 292 m_pop3 = NULL;
293 return; 293 return;
294 } 294 }
295 qDebug( "POP3: connected!" ); 295 qDebug( "POP3: connected!" );
296 296
297 // login 297 // login
298 // TODO: decide if apop or plain login should be used 298 // TODO: decide if apop or plain login should be used
299 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 299 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
300 if ( err != MAILPOP3_NO_ERROR ) { 300 if ( err != MAILPOP3_NO_ERROR ) {
301 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); 301 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response );
302 logout(); 302 logout();
303 return; 303 return;
304 } 304 }
305 305
306 qDebug( "POP3: logged in!" ); 306 qDebug( "POP3: logged in!" );
307} 307}
308 308
309void POP3wrapper::logout() 309void POP3wrapper::logout()
310{ 310{
311 int err = MAILPOP3_NO_ERROR; 311 int err = MAILPOP3_NO_ERROR;
312 if ( m_pop3 == NULL ) return; 312 if ( m_pop3 == NULL ) return;
313 err = mailpop3_quit( m_pop3 ); 313 err = mailpop3_quit( m_pop3 );
314 mailpop3_free( m_pop3 ); 314 mailpop3_free( m_pop3 );
315 m_pop3 = NULL; 315 m_pop3 = NULL;
316} 316}
317 317
318 318
319QList<Folder>* POP3wrapper::listFolders() 319QList<Folder>* POP3wrapper::listFolders()
320{ 320{
321 /* TODO: integrate MH directories 321 /* TODO: integrate MH directories
322 but not before version 0.1 ;) 322 but not before version 0.1 ;)
323 */ 323 */
324 QList<Folder> * folders = new QList<Folder>(); 324 QList<Folder> * folders = new QList<Folder>();
325 folders->setAutoDelete( false ); 325 folders->setAutoDelete( false );
326 Folder*inb=new Folder("INBOX"); 326 Folder*inb=new Folder("INBOX","/");
327 folders->append(inb); 327 folders->append(inb);
328 return folders; 328 return folders;
329} 329}
330 330
331QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&) 331QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&)
332{ 332{
333 return ""; 333 return "";
334} 334}
335 335
336void POP3wrapper::deleteMail(const RecMail&mail) 336void POP3wrapper::deleteMail(const RecMail&mail)
337{ 337{
338 login(); 338 login();
339 if (!m_pop3) return; 339 if (!m_pop3) return;
340 int err = mailpop3_dele(m_pop3,mail.getNumber()); 340 int err = mailpop3_dele(m_pop3,mail.getNumber());
341 if (err != MAILPOP3_NO_ERROR) { 341 if (err != MAILPOP3_NO_ERROR) {
342 qDebug("error deleting mail"); 342 qDebug("error deleting mail");
343 } 343 }
344} 344}
345 345
346void POP3wrapper::answeredMail(const RecMail&) 346void POP3wrapper::answeredMail(const RecMail&)
347{ 347{
348} 348}
349 349
350encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&) 350encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&)
351{ 351{
352 return new encodedString(); 352 return new encodedString();
353} 353}
354 354
355encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&) 355encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&)
356{ 356{
357 return new encodedString(); 357 return new encodedString();
358} 358}