summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/abstractmail.cpp13
-rw-r--r--noncore/net/mail/abstractmail.h30
-rw-r--r--noncore/net/mail/accountview.cpp16
-rw-r--r--noncore/net/mail/accountview.h15
-rw-r--r--noncore/net/mail/imapwrapper.cpp5
-rw-r--r--noncore/net/mail/imapwrapper.h17
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.cpp13
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.h30
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp5
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h17
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp21
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h11
-rw-r--r--noncore/net/mail/mail.pro6
-rw-r--r--noncore/net/mail/mainwindow.h1
-rw-r--r--noncore/net/mail/opiemail.h4
-rw-r--r--noncore/net/mail/pop3wrapper.cpp21
-rw-r--r--noncore/net/mail/pop3wrapper.h11
17 files changed, 180 insertions, 56 deletions
diff --git a/noncore/net/mail/abstractmail.cpp b/noncore/net/mail/abstractmail.cpp
new file mode 100644
index 0000000..7380c31
--- a/dev/null
+++ b/noncore/net/mail/abstractmail.cpp
@@ -0,0 +1,13 @@
1#include "abstractmail.h"
2#include "imapwrapper.h"
3#include "pop3wrapper.h"
4
5AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
6{
7 return new IMAPwrapper(a);
8}
9
10AbstractMail* AbstractMail::getWrapper(POP3account *a)
11{
12 return new POP3wrapper(a);
13}
diff --git a/noncore/net/mail/abstractmail.h b/noncore/net/mail/abstractmail.h
new file mode 100644
index 0000000..bc8938f
--- a/dev/null
+++ b/noncore/net/mail/abstractmail.h
@@ -0,0 +1,30 @@
1#ifndef __abstract_mail_
2#define __abstract_mail_
3
4#include <qobject.h>
5#include "settings.h"
6
7class RecMail;
8class RecBody;
9class RecPart;
10class IMAPwrapper;
11class POP3wrapper;
12class Folder;
13
14class AbstractMail:public QObject
15{
16 Q_OBJECT
17public:
18 AbstractMail(){};
19 virtual ~AbstractMail(){}
20 virtual QList<Folder>* listFolders()=0;
21 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
22 virtual RecBody fetchBody(const RecMail&mail)=0;
23 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false)=0;
24 virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0;
25
26 static AbstractMail* getWrapper(IMAPaccount *a);
27 static AbstractMail* getWrapper(POP3account *a);
28};
29
30#endif
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp
index c7b1eeb..1069b9f 100644
--- a/noncore/net/mail/accountview.cpp
+++ b/noncore/net/mail/accountview.cpp
@@ -1,154 +1,152 @@
1#include "accountview.h" 1#include "accountview.h"
2#include "imapwrapper.h"
3#include "pop3wrapper.h"
4#include "mailtypes.h" 2#include "mailtypes.h"
5#include "defines.h" 3#include "defines.h"
6 4
7 5
8/** 6/**
9 * POP3 Account stuff 7 * POP3 Account stuff
10 */ 8 */
11 9
12POP3viewItem::POP3viewItem( POP3account *a, QListView *parent ) 10POP3viewItem::POP3viewItem( POP3account *a, QListView *parent )
13 : AccountViewItem( parent ) 11 : AccountViewItem( parent )
14{ 12{
15 account = a; 13 account = a;
16 wrapper = new POP3wrapper( account ); 14 wrapper = AbstractMail::getWrapper( account );
17 setPixmap( 0, PIXMAP_POP3FOLDER ); 15 setPixmap( 0, PIXMAP_POP3FOLDER );
18 setText( 0, account->getAccountName() ); 16 setText( 0, account->getAccountName() );
19} 17}
20 18
21POP3viewItem::~POP3viewItem() 19POP3viewItem::~POP3viewItem()
22{ 20{
23 delete wrapper; 21 delete wrapper;
24} 22}
25 23
26void POP3viewItem::refresh( QList<RecMail> &target ) 24void POP3viewItem::refresh( QList<RecMail> &target )
27{ 25{
28 qDebug( "POP3: refresh" ); 26 qDebug( "POP3: refresh" );
29 wrapper->listMessages( target ); 27 wrapper->listMessages("INBOX", target );
30} 28}
31 29
32 30
33RecBody POP3viewItem::fetchBody( const RecMail &mail ) 31RecBody POP3viewItem::fetchBody( const RecMail &mail )
34{ 32{
35 qDebug( "POP3 fetchBody" ); 33 qDebug( "POP3 fetchBody" );
36 return wrapper->fetchBody( mail ); 34 return wrapper->fetchBody( mail );
37} 35}
38 36
39/** 37/**
40 * IMAP Account stuff 38 * IMAP Account stuff
41 */ 39 */
42 40
43IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent ) 41IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent )
44 : AccountViewItem( parent ) 42 : AccountViewItem( parent )
45{ 43{
46 account = a; 44 account = a;
47 wrapper = new IMAPwrapper( account ); 45 wrapper = AbstractMail::getWrapper( account );
48 setPixmap( 0, PIXMAP_IMAPFOLDER ); 46 setPixmap( 0, PIXMAP_IMAPFOLDER );
49 setText( 0, account->getAccountName() ); 47 setText( 0, account->getAccountName() );
50 setOpen( true ); 48 setOpen( true );
51} 49}
52 50
53IMAPviewItem::~IMAPviewItem() 51IMAPviewItem::~IMAPviewItem()
54{ 52{
55 delete wrapper; 53 delete wrapper;
56} 54}
57 55
58IMAPwrapper *IMAPviewItem::getWrapper() 56AbstractMail *IMAPviewItem::getWrapper()
59{ 57{
60 return wrapper; 58 return wrapper;
61} 59}
62 60
63void IMAPviewItem::refresh(QList<RecMail>&) 61void IMAPviewItem::refresh(QList<RecMail>&)
64{ 62{
65 QList<IMAPFolder> *folders = wrapper->listFolders(); 63 QList<Folder> *folders = wrapper->listFolders();
66 64
67 QListViewItem *child = firstChild(); 65 QListViewItem *child = firstChild();
68 while ( child ) { 66 while ( child ) {
69 QListViewItem *tmp = child; 67 QListViewItem *tmp = child;
70 child = child->nextSibling(); 68 child = child->nextSibling();
71 delete tmp; 69 delete tmp;
72 } 70 }
73 71
74 IMAPFolder *it; 72 Folder *it;
75 for ( it = folders->first(); it; it = folders->next() ) { 73 for ( it = folders->first(); it; it = folders->next() ) {
76 (void) new IMAPfolderItem( it, this ); 74 (void) new IMAPfolderItem( it, this );
77 } 75 }
78} 76}
79 77
80RecBody IMAPviewItem::fetchBody(const RecMail&) 78RecBody IMAPviewItem::fetchBody(const RecMail&)
81{ 79{
82 return RecBody(); 80 return RecBody();
83} 81}
84 82
85IMAPfolderItem::~IMAPfolderItem() 83IMAPfolderItem::~IMAPfolderItem()
86{ 84{
87 delete folder; 85 delete folder;
88} 86}
89 87
90IMAPfolderItem::IMAPfolderItem( IMAPFolder *folderInit, IMAPviewItem *parent ) 88IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent )
91 : AccountViewItem( parent ) 89 : AccountViewItem( parent )
92{ 90{
93 folder = folderInit; 91 folder = folderInit;
94 imap = parent; 92 imap = parent;
95 setPixmap( 0, PIXMAP_IMAPFOLDER ); 93 setPixmap( 0, PIXMAP_IMAPFOLDER );
96 setText( 0, folder->getDisplayName() ); 94 setText( 0, folder->getDisplayName() );
97} 95}
98 96
99void IMAPfolderItem::refresh(QList<RecMail>&target) 97void IMAPfolderItem::refresh(QList<RecMail>&target)
100{ 98{
101 imap->getWrapper()->listMessages( folder->getName(),target ); 99 imap->getWrapper()->listMessages( folder->getName(),target );
102} 100}
103 101
104RecBody IMAPfolderItem::fetchBody(const RecMail&aMail) 102RecBody IMAPfolderItem::fetchBody(const RecMail&aMail)
105{ 103{
106 return imap->getWrapper()->fetchBody(aMail); 104 return imap->getWrapper()->fetchBody(aMail);
107} 105}
108 106
109/** 107/**
110 * Generic stuff 108 * Generic stuff
111 */ 109 */
112 110
113AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) 111AccountView::AccountView( QWidget *parent, const char *name, WFlags flags )
114 : QListView( parent, name, flags ) 112 : QListView( parent, name, flags )
115{ 113{
116 connect( this, SIGNAL( clicked( QListViewItem * ) ), 114 connect( this, SIGNAL( clicked( QListViewItem * ) ),
117 SLOT( refresh( QListViewItem * ) ) ); 115 SLOT( refresh( QListViewItem * ) ) );
118} 116}
119 117
120void AccountView::populate( QList<Account> list ) 118void AccountView::populate( QList<Account> list )
121{ 119{
122 clear(); 120 clear();
123 121
124 Account *it; 122 Account *it;
125 for ( it = list.first(); it; it = list.next() ) { 123 for ( it = list.first(); it; it = list.next() ) {
126 if ( it->getType().compare( "IMAP" ) == 0 ) { 124 if ( it->getType().compare( "IMAP" ) == 0 ) {
127 IMAPaccount *imap = static_cast<IMAPaccount *>(it); 125 IMAPaccount *imap = static_cast<IMAPaccount *>(it);
128 qDebug( "added IMAP " + imap->getAccountName() ); 126 qDebug( "added IMAP " + imap->getAccountName() );
129 (void) new IMAPviewItem( imap, this ); 127 (void) new IMAPviewItem( imap, this );
130 } else if ( it->getType().compare( "POP3" ) == 0 ) { 128 } else if ( it->getType().compare( "POP3" ) == 0 ) {
131 POP3account *pop3 = static_cast<POP3account *>(it); 129 POP3account *pop3 = static_cast<POP3account *>(it);
132 qDebug( "added POP3 " + pop3->getAccountName() ); 130 qDebug( "added POP3 " + pop3->getAccountName() );
133 (void) new POP3viewItem( pop3, this ); 131 (void) new POP3viewItem( pop3, this );
134 } 132 }
135 } 133 }
136} 134}
137 135
138void AccountView::refresh(QListViewItem *item) { 136void AccountView::refresh(QListViewItem *item) {
139 qDebug("AccountView refresh..."); 137 qDebug("AccountView refresh...");
140 if ( item ) { 138 if ( item ) {
141 QList<RecMail> headerlist; 139 QList<RecMail> headerlist;
142 headerlist.setAutoDelete(true); 140 headerlist.setAutoDelete(true);
143 AccountViewItem *view = static_cast<AccountViewItem *>(item); 141 AccountViewItem *view = static_cast<AccountViewItem *>(item);
144 view->refresh(headerlist); 142 view->refresh(headerlist);
145 emit refreshMailview(&headerlist); 143 emit refreshMailview(&headerlist);
146 } 144 }
147} 145}
148 146
149void AccountView::refreshAll() 147void AccountView::refreshAll()
150{ 148{
151 149
152} 150}
153 151
154RecBody AccountView::fetchBody(const RecMail&aMail) 152RecBody AccountView::fetchBody(const RecMail&aMail)
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h
index 4cac673..83d49af 100644
--- a/noncore/net/mail/accountview.h
+++ b/noncore/net/mail/accountview.h
@@ -1,88 +1,85 @@
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 10
10class IMAPwrapper;
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 virtual void refresh(QList<RecMail>&)=0; 21 virtual void refresh(QList<RecMail>&)=0;
22 virtual RecBody fetchBody(const RecMail&)=0; 22 virtual RecBody fetchBody(const RecMail&)=0;
23}; 23};
24 24
25class POP3viewItem : public AccountViewItem 25class POP3viewItem : public AccountViewItem
26{ 26{
27 27
28public: 28public:
29 POP3viewItem( POP3account *a, QListView *parent ); 29 POP3viewItem( POP3account *a, QListView *parent );
30 ~POP3viewItem(); 30 ~POP3viewItem();
31 virtual void refresh( QList<RecMail> &target ); 31 virtual void refresh( QList<RecMail> &target );
32 virtual RecBody fetchBody( const RecMail &mail ); 32 virtual RecBody fetchBody( const RecMail &mail );
33 33
34private: 34private:
35 POP3account *account; 35 POP3account *account;
36 POP3wrapper *wrapper; 36 AbstractMail *wrapper;
37 37
38}; 38};
39 39
40class IMAPviewItem : public AccountViewItem 40class IMAPviewItem : public AccountViewItem
41{ 41{
42 42
43public: 43public:
44 IMAPviewItem( IMAPaccount *a, QListView *parent ); 44 IMAPviewItem( IMAPaccount *a, QListView *parent );
45 ~IMAPviewItem(); 45 ~IMAPviewItem();
46 virtual void refresh(QList<RecMail>&); 46 virtual void refresh(QList<RecMail>&);
47 virtual RecBody fetchBody(const RecMail&); 47 virtual RecBody fetchBody(const RecMail&);
48 IMAPwrapper *getWrapper(); 48 AbstractMail *getWrapper();
49
50private: 49private:
51 IMAPaccount *account; 50 IMAPaccount *account;
52 IMAPwrapper *wrapper; 51 AbstractMail *wrapper;
53
54}; 52};
55 53
56class IMAPfolderItem : public AccountViewItem 54class IMAPfolderItem : public AccountViewItem
57{ 55{
58 56
59public: 57public:
60 IMAPfolderItem( IMAPFolder *folder, IMAPviewItem *parent ); 58 IMAPfolderItem( Folder *folder, IMAPviewItem *parent );
61 ~IMAPfolderItem(); 59 ~IMAPfolderItem();
62 virtual void refresh(QList<RecMail>&); 60 virtual void refresh(QList<RecMail>&);
63 virtual RecBody fetchBody(const RecMail&); 61 virtual RecBody fetchBody(const RecMail&);
64
65private: 62private:
66 IMAPFolder *folder; 63 Folder *folder;
67 IMAPviewItem *imap; 64 IMAPviewItem *imap;
68 65
69}; 66};
70 67
71class AccountView : public QListView 68class AccountView : public QListView
72{ 69{
73 Q_OBJECT 70 Q_OBJECT
74 71
75public: 72public:
76 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 73 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
77 void populate( QList<Account> list ); 74 void populate( QList<Account> list );
78 RecBody fetchBody(const RecMail&aMail); 75 RecBody fetchBody(const RecMail&aMail);
79 76
80public slots: 77public slots:
81 void refreshAll(); 78 void refreshAll();
82 void refresh(QListViewItem *item); 79 void refresh(QListViewItem *item);
83 80
84signals: 81signals:
85 void refreshMailview(QList<RecMail>*); 82 void refreshMailview(QList<RecMail>*);
86}; 83};
87 84
88#endif 85#endif
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index 48e476b..e5eb335 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -1,72 +1,73 @@
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{ 10{
10 account = a; 11 account = a;
11 m_imap = 0; 12 m_imap = 0;
12} 13}
13 14
14IMAPwrapper::~IMAPwrapper() 15IMAPwrapper::~IMAPwrapper()
15{ 16{
16 logout(); 17 logout();
17} 18}
18 19
19void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 20void IMAPwrapper::imap_progress( size_t current, size_t maximum )
20{ 21{
21 qDebug( "IMAP: %i of %i", current, maximum ); 22 qDebug( "IMAP: %i of %i", current, maximum );
22} 23}
23 24
24void IMAPwrapper::login() 25void IMAPwrapper::login()
25{ 26{
26 const char *server, *user, *pass; 27 const char *server, *user, *pass;
27 uint16_t port; 28 uint16_t port;
28 int err = MAILIMAP_NO_ERROR; 29 int err = MAILIMAP_NO_ERROR;
29 30
30 /* we are connected this moment */ 31 /* we are connected this moment */
31 /* 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 */
32 if (m_imap) { 33 if (m_imap) {
33 mailstream_flush(m_imap->imap_stream); 34 mailstream_flush(m_imap->imap_stream);
34 return; 35 return;
35 } 36 }
36 server = account->getServer().latin1(); 37 server = account->getServer().latin1();
37 port = account->getPort().toUInt(); 38 port = account->getPort().toUInt();
38 user = account->getUser().latin1(); 39 user = account->getUser().latin1();
39 pass = account->getPassword().latin1(); 40 pass = account->getPassword().latin1();
40 41
41 m_imap = mailimap_new( 20, &imap_progress ); 42 m_imap = mailimap_new( 20, &imap_progress );
42 /* connect */ 43 /* connect */
43 if (account->getSSL()) { 44 if (account->getSSL()) {
44 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 45 err = mailimap_ssl_connect( m_imap, (char*)server, port );
45 } else { 46 } else {
46 err = mailimap_socket_connect( m_imap, (char*)server, port ); 47 err = mailimap_socket_connect( m_imap, (char*)server, port );
47 } 48 }
48 49
49 if ( err != MAILIMAP_NO_ERROR && 50 if ( err != MAILIMAP_NO_ERROR &&
50 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 51 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
51 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
52 qDebug("error connecting server: %s",m_imap->imap_response); 53 qDebug("error connecting server: %s",m_imap->imap_response);
53 mailimap_free( m_imap ); 54 mailimap_free( m_imap );
54 m_imap = 0; 55 m_imap = 0;
55 return; 56 return;
56 } 57 }
57 58
58 /* login */ 59 /* login */
59 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
60 if ( err != MAILIMAP_NO_ERROR ) { 61 if ( err != MAILIMAP_NO_ERROR ) {
61 qDebug("error logging in imap: %s",m_imap->imap_response); 62 qDebug("error logging in imap: %s",m_imap->imap_response);
62 err = mailimap_close( m_imap ); 63 err = mailimap_close( m_imap );
63 mailimap_free( m_imap ); 64 mailimap_free( m_imap );
64 m_imap = 0; 65 m_imap = 0;
65 } 66 }
66} 67}
67 68
68void IMAPwrapper::logout() 69void IMAPwrapper::logout()
69{ 70{
70 int err = MAILIMAP_NO_ERROR; 71 int err = MAILIMAP_NO_ERROR;
71 if (!m_imap) return; 72 if (!m_imap) return;
72 err = mailimap_logout( m_imap ); 73 err = mailimap_logout( m_imap );
@@ -78,136 +79,136 @@ void IMAPwrapper::logout()
78void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
79{ 80{
80 const char *mb; 81 const char *mb;
81 int err = MAILIMAP_NO_ERROR; 82 int err = MAILIMAP_NO_ERROR;
82 clist *result; 83 clist *result;
83 clistcell *current; 84 clistcell *current;
84// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
85 mailimap_fetch_type *fetchType; 86 mailimap_fetch_type *fetchType;
86 mailimap_set *set; 87 mailimap_set *set;
87 88
88 mb = mailbox.latin1(); 89 mb = mailbox.latin1();
89 login(); 90 login();
90 if (!m_imap) { 91 if (!m_imap) {
91 return; 92 return;
92 } 93 }
93 /* select mailbox READONLY for operations */ 94 /* select mailbox READONLY for operations */
94 err = mailimap_examine( m_imap, (char*)mb); 95 err = mailimap_examine( m_imap, (char*)mb);
95 if ( err != MAILIMAP_NO_ERROR ) { 96 if ( err != MAILIMAP_NO_ERROR ) {
96 qDebug("error selecting mailbox: %s",m_imap->imap_response); 97 qDebug("error selecting mailbox: %s",m_imap->imap_response);
97 return; 98 return;
98 } 99 }
99 100
100 int last = m_imap->imap_selection_info->sel_exists; 101 int last = m_imap->imap_selection_info->sel_exists;
101 102
102 if (last == 0) { 103 if (last == 0) {
103 qDebug("mailbox has no mails"); 104 qDebug("mailbox has no mails");
104 return; 105 return;
105 } 106 }
106 107
107 result = clist_new(); 108 result = clist_new();
108 /* the range has to start at 1!!! not with 0!!!! */ 109 /* the range has to start at 1!!! not with 0!!!! */
109 set = mailimap_set_new_interval( 1, last ); 110 set = mailimap_set_new_interval( 1, last );
110 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
111 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());
112 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());
113 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());
114 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());
115 116
116 err = mailimap_fetch( m_imap, set, fetchType, &result ); 117 err = mailimap_fetch( m_imap, set, fetchType, &result );
117 mailimap_set_free( set ); 118 mailimap_set_free( set );
118 mailimap_fetch_type_free( fetchType ); 119 mailimap_fetch_type_free( fetchType );
119 120
120 QString date,subject,from; 121 QString date,subject,from;
121 122
122 if ( err == MAILIMAP_NO_ERROR ) { 123 if ( err == MAILIMAP_NO_ERROR ) {
123 124
124 mailimap_msg_att * msg_att; 125 mailimap_msg_att * msg_att;
125 int i = 0; 126 int i = 0;
126 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 127 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
127 ++i; 128 ++i;
128 msg_att = (mailimap_msg_att*)current->data; 129 msg_att = (mailimap_msg_att*)current->data;
129 RecMail*m = parse_list_result(msg_att); 130 RecMail*m = parse_list_result(msg_att);
130 if (m) { 131 if (m) {
131 m->setNumber(i); 132 m->setNumber(i);
132 m->setMbox(mailbox); 133 m->setMbox(mailbox);
133 target.append(m); 134 target.append(m);
134 } 135 }
135 } 136 }
136 } else { 137 } else {
137 qDebug("Error fetching headers: %s",m_imap->imap_response); 138 qDebug("Error fetching headers: %s",m_imap->imap_response);
138 } 139 }
139 mailimap_fetch_list_free(result); 140 mailimap_fetch_list_free(result);
140} 141}
141 142
142QList<IMAPFolder>* IMAPwrapper::listFolders() 143QList<Folder>* IMAPwrapper::listFolders()
143{ 144{
144 const char *path, *mask; 145 const char *path, *mask;
145 int err = MAILIMAP_NO_ERROR; 146 int err = MAILIMAP_NO_ERROR;
146 clist *result; 147 clist *result;
147 clistcell *current; 148 clistcell *current;
148 149
149 QList<IMAPFolder> * folders = new QList<IMAPFolder>(); 150 QList<Folder> * folders = new QList<Folder>();
150 folders->setAutoDelete( true ); 151 folders->setAutoDelete( true );
151 login(); 152 login();
152 if (!m_imap) { 153 if (!m_imap) {
153 return folders; 154 return folders;
154 } 155 }
155 156
156/* 157/*
157 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 158 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
158 * We must not forget to filter them out in next loop! 159 * We must not forget to filter them out in next loop!
159 * it seems like ugly code. and yes - it is ugly code. but the best way. 160 * it seems like ugly code. and yes - it is ugly code. but the best way.
160 */ 161 */
161 QString temp; 162 QString temp;
162 mask = "INBOX" ; 163 mask = "INBOX" ;
163 result = clist_new(); 164 result = clist_new();
164 mailimap_mailbox_list *list; 165 mailimap_mailbox_list *list;
165 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 166 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
166 if ( err == MAILIMAP_NO_ERROR ) { 167 if ( err == MAILIMAP_NO_ERROR ) {
167 current = result->first; 168 current = result->first;
168 for ( int i = result->count; i > 0; i-- ) { 169 for ( int i = result->count; i > 0; i-- ) {
169 list = (mailimap_mailbox_list *) current->data; 170 list = (mailimap_mailbox_list *) current->data;
170 // it is better use the deep copy mechanism of qt itself 171 // it is better use the deep copy mechanism of qt itself
171 // instead of using strdup! 172 // instead of using strdup!
172 temp = list->mb_name; 173 temp = list->mb_name;
173 folders->append( new IMAPFolder(temp)); 174 folders->append( new IMAPFolder(temp));
174 current = current->next; 175 current = current->next;
175 } 176 }
176 } else { 177 } else {
177 qDebug("error fetching folders: %s",m_imap->imap_response); 178 qDebug("error fetching folders: %s",m_imap->imap_response);
178 } 179 }
179 mailimap_list_result_free( result ); 180 mailimap_list_result_free( result );
180 181
181/* 182/*
182 * second stage - get the other then inbox folders 183 * second stage - get the other then inbox folders
183 */ 184 */
184 mask = "*" ; 185 mask = "*" ;
185 path = account->getPrefix().latin1(); 186 path = account->getPrefix().latin1();
186 if (!path) path = ""; 187 if (!path) path = "";
187 result = clist_new(); 188 result = clist_new();
188 qDebug(path); 189 qDebug(path);
189 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 190 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
190 if ( err == MAILIMAP_NO_ERROR ) { 191 if ( err == MAILIMAP_NO_ERROR ) {
191 current = result->first; 192 current = result->first;
192 for ( int i = result->count; i > 0; i-- ) { 193 for ( int i = result->count; i > 0; i-- ) {
193 list = (mailimap_mailbox_list *) current->data; 194 list = (mailimap_mailbox_list *) current->data;
194 // it is better use the deep copy mechanism of qt itself 195 // it is better use the deep copy mechanism of qt itself
195 // instead of using strdup! 196 // instead of using strdup!
196 temp = list->mb_name; 197 temp = list->mb_name;
197 current = current->next; 198 current = current->next;
198 if (temp.lower()=="inbox") 199 if (temp.lower()=="inbox")
199 continue; 200 continue;
200 folders->append(new IMAPFolder(temp)); 201 folders->append(new IMAPFolder(temp));
201 202
202 } 203 }
203 } else { 204 } else {
204 qDebug("error fetching folders %s",m_imap->imap_response); 205 qDebug("error fetching folders %s",m_imap->imap_response);
205 } 206 }
206 mailimap_list_result_free( result ); 207 mailimap_list_result_free( result );
207 return folders; 208 return folders;
208} 209}
209 210
210RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 211RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
211{ 212{
212 RecMail * m = 0; 213 RecMail * m = 0;
213 mailimap_msg_att_item *item=0; 214 mailimap_msg_att_item *item=0;
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h
index 95de215..f88457a 100644
--- a/noncore/net/mail/imapwrapper.h
+++ b/noncore/net/mail/imapwrapper.h
@@ -1,55 +1,52 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "abstractmail.h"
6 7
7struct mailimap; 8struct mailimap;
8struct mailimap_body_type_1part; 9struct mailimap_body_type_1part;
9struct mailimap_body_type_text; 10struct mailimap_body_type_text;
10struct mailimap_body_type_basic; 11struct mailimap_body_type_basic;
11struct mailimap_body_type_msg; 12struct mailimap_body_type_msg;
12struct mailimap_body_type_mpart; 13struct mailimap_body_type_mpart;
13struct mailimap_body_fields; 14struct mailimap_body_fields;
14struct mailimap_msg_att; 15struct mailimap_msg_att;
15class RecMail;
16class RecBody;
17class RecPart;
18 16
19class IMAPwrapper : public QObject 17class IMAPwrapper : public AbstractMail
20{ 18{
21 Q_OBJECT 19 Q_OBJECT
22
23public: 20public:
24 IMAPwrapper( IMAPaccount *a ); 21 IMAPwrapper( IMAPaccount *a );
25 virtual ~IMAPwrapper(); 22 virtual ~IMAPwrapper();
26 QList<IMAPFolder>* listFolders(); 23 virtual QList<Folder>* listFolders();
27 void listMessages(const QString & mailbox,QList<RecMail>&target ); 24 virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
28 RecBody fetchBody(const RecMail&mail); 25 virtual RecBody fetchBody(const RecMail&mail);
29 QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false); 26 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false);
30 QString fetchPart(const RecMail&mail,const RecPart&part); 27 virtual QString fetchPart(const RecMail&mail,const RecPart&part);
31 static void imap_progress( size_t current, size_t maximum ); 28 static void imap_progress( size_t current, size_t maximum );
32 29
33protected: 30protected:
34 RecMail*parse_list_result(mailimap_msg_att*); 31 RecMail*parse_list_result(mailimap_msg_att*);
35 void login(); 32 void login();
36 void logout(); 33 void logout();
37 34
38 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); 35 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
39 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); 36 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>());
40 37
41 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 38 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
42 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 39 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
43 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 40 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
44 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); 41 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
45 42
46 /* just helpers */ 43 /* just helpers */
47 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 44 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
48 static QStringList address_list_to_stringlist(clist*list); 45 static QStringList address_list_to_stringlist(clist*list);
49 46
50private: 47private:
51 IMAPaccount *account; 48 IMAPaccount *account;
52 mailimap *m_imap; 49 mailimap *m_imap;
53}; 50};
54 51
55#endif 52#endif
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp
new file mode 100644
index 0000000..7380c31
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp
@@ -0,0 +1,13 @@
1#include "abstractmail.h"
2#include "imapwrapper.h"
3#include "pop3wrapper.h"
4
5AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
6{
7 return new IMAPwrapper(a);
8}
9
10AbstractMail* AbstractMail::getWrapper(POP3account *a)
11{
12 return new POP3wrapper(a);
13}
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h
new file mode 100644
index 0000000..bc8938f
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/abstractmail.h
@@ -0,0 +1,30 @@
1#ifndef __abstract_mail_
2#define __abstract_mail_
3
4#include <qobject.h>
5#include "settings.h"
6
7class RecMail;
8class RecBody;
9class RecPart;
10class IMAPwrapper;
11class POP3wrapper;
12class Folder;
13
14class AbstractMail:public QObject
15{
16 Q_OBJECT
17public:
18 AbstractMail(){};
19 virtual ~AbstractMail(){}
20 virtual QList<Folder>* listFolders()=0;
21 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
22 virtual RecBody fetchBody(const RecMail&mail)=0;
23 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false)=0;
24 virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0;
25
26 static AbstractMail* getWrapper(IMAPaccount *a);
27 static AbstractMail* getWrapper(POP3account *a);
28};
29
30#endif
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 48e476b..e5eb335 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,72 +1,73 @@
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{ 10{
10 account = a; 11 account = a;
11 m_imap = 0; 12 m_imap = 0;
12} 13}
13 14
14IMAPwrapper::~IMAPwrapper() 15IMAPwrapper::~IMAPwrapper()
15{ 16{
16 logout(); 17 logout();
17} 18}
18 19
19void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 20void IMAPwrapper::imap_progress( size_t current, size_t maximum )
20{ 21{
21 qDebug( "IMAP: %i of %i", current, maximum ); 22 qDebug( "IMAP: %i of %i", current, maximum );
22} 23}
23 24
24void IMAPwrapper::login() 25void IMAPwrapper::login()
25{ 26{
26 const char *server, *user, *pass; 27 const char *server, *user, *pass;
27 uint16_t port; 28 uint16_t port;
28 int err = MAILIMAP_NO_ERROR; 29 int err = MAILIMAP_NO_ERROR;
29 30
30 /* we are connected this moment */ 31 /* we are connected this moment */
31 /* 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 */
32 if (m_imap) { 33 if (m_imap) {
33 mailstream_flush(m_imap->imap_stream); 34 mailstream_flush(m_imap->imap_stream);
34 return; 35 return;
35 } 36 }
36 server = account->getServer().latin1(); 37 server = account->getServer().latin1();
37 port = account->getPort().toUInt(); 38 port = account->getPort().toUInt();
38 user = account->getUser().latin1(); 39 user = account->getUser().latin1();
39 pass = account->getPassword().latin1(); 40 pass = account->getPassword().latin1();
40 41
41 m_imap = mailimap_new( 20, &imap_progress ); 42 m_imap = mailimap_new( 20, &imap_progress );
42 /* connect */ 43 /* connect */
43 if (account->getSSL()) { 44 if (account->getSSL()) {
44 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 45 err = mailimap_ssl_connect( m_imap, (char*)server, port );
45 } else { 46 } else {
46 err = mailimap_socket_connect( m_imap, (char*)server, port ); 47 err = mailimap_socket_connect( m_imap, (char*)server, port );
47 } 48 }
48 49
49 if ( err != MAILIMAP_NO_ERROR && 50 if ( err != MAILIMAP_NO_ERROR &&
50 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 51 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
51 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
52 qDebug("error connecting server: %s",m_imap->imap_response); 53 qDebug("error connecting server: %s",m_imap->imap_response);
53 mailimap_free( m_imap ); 54 mailimap_free( m_imap );
54 m_imap = 0; 55 m_imap = 0;
55 return; 56 return;
56 } 57 }
57 58
58 /* login */ 59 /* login */
59 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
60 if ( err != MAILIMAP_NO_ERROR ) { 61 if ( err != MAILIMAP_NO_ERROR ) {
61 qDebug("error logging in imap: %s",m_imap->imap_response); 62 qDebug("error logging in imap: %s",m_imap->imap_response);
62 err = mailimap_close( m_imap ); 63 err = mailimap_close( m_imap );
63 mailimap_free( m_imap ); 64 mailimap_free( m_imap );
64 m_imap = 0; 65 m_imap = 0;
65 } 66 }
66} 67}
67 68
68void IMAPwrapper::logout() 69void IMAPwrapper::logout()
69{ 70{
70 int err = MAILIMAP_NO_ERROR; 71 int err = MAILIMAP_NO_ERROR;
71 if (!m_imap) return; 72 if (!m_imap) return;
72 err = mailimap_logout( m_imap ); 73 err = mailimap_logout( m_imap );
@@ -78,136 +79,136 @@ void IMAPwrapper::logout()
78void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
79{ 80{
80 const char *mb; 81 const char *mb;
81 int err = MAILIMAP_NO_ERROR; 82 int err = MAILIMAP_NO_ERROR;
82 clist *result; 83 clist *result;
83 clistcell *current; 84 clistcell *current;
84// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
85 mailimap_fetch_type *fetchType; 86 mailimap_fetch_type *fetchType;
86 mailimap_set *set; 87 mailimap_set *set;
87 88
88 mb = mailbox.latin1(); 89 mb = mailbox.latin1();
89 login(); 90 login();
90 if (!m_imap) { 91 if (!m_imap) {
91 return; 92 return;
92 } 93 }
93 /* select mailbox READONLY for operations */ 94 /* select mailbox READONLY for operations */
94 err = mailimap_examine( m_imap, (char*)mb); 95 err = mailimap_examine( m_imap, (char*)mb);
95 if ( err != MAILIMAP_NO_ERROR ) { 96 if ( err != MAILIMAP_NO_ERROR ) {
96 qDebug("error selecting mailbox: %s",m_imap->imap_response); 97 qDebug("error selecting mailbox: %s",m_imap->imap_response);
97 return; 98 return;
98 } 99 }
99 100
100 int last = m_imap->imap_selection_info->sel_exists; 101 int last = m_imap->imap_selection_info->sel_exists;
101 102
102 if (last == 0) { 103 if (last == 0) {
103 qDebug("mailbox has no mails"); 104 qDebug("mailbox has no mails");
104 return; 105 return;
105 } 106 }
106 107
107 result = clist_new(); 108 result = clist_new();
108 /* the range has to start at 1!!! not with 0!!!! */ 109 /* the range has to start at 1!!! not with 0!!!! */
109 set = mailimap_set_new_interval( 1, last ); 110 set = mailimap_set_new_interval( 1, last );
110 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
111 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());
112 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());
113 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());
114 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());
115 116
116 err = mailimap_fetch( m_imap, set, fetchType, &result ); 117 err = mailimap_fetch( m_imap, set, fetchType, &result );
117 mailimap_set_free( set ); 118 mailimap_set_free( set );
118 mailimap_fetch_type_free( fetchType ); 119 mailimap_fetch_type_free( fetchType );
119 120
120 QString date,subject,from; 121 QString date,subject,from;
121 122
122 if ( err == MAILIMAP_NO_ERROR ) { 123 if ( err == MAILIMAP_NO_ERROR ) {
123 124
124 mailimap_msg_att * msg_att; 125 mailimap_msg_att * msg_att;
125 int i = 0; 126 int i = 0;
126 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 127 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
127 ++i; 128 ++i;
128 msg_att = (mailimap_msg_att*)current->data; 129 msg_att = (mailimap_msg_att*)current->data;
129 RecMail*m = parse_list_result(msg_att); 130 RecMail*m = parse_list_result(msg_att);
130 if (m) { 131 if (m) {
131 m->setNumber(i); 132 m->setNumber(i);
132 m->setMbox(mailbox); 133 m->setMbox(mailbox);
133 target.append(m); 134 target.append(m);
134 } 135 }
135 } 136 }
136 } else { 137 } else {
137 qDebug("Error fetching headers: %s",m_imap->imap_response); 138 qDebug("Error fetching headers: %s",m_imap->imap_response);
138 } 139 }
139 mailimap_fetch_list_free(result); 140 mailimap_fetch_list_free(result);
140} 141}
141 142
142QList<IMAPFolder>* IMAPwrapper::listFolders() 143QList<Folder>* IMAPwrapper::listFolders()
143{ 144{
144 const char *path, *mask; 145 const char *path, *mask;
145 int err = MAILIMAP_NO_ERROR; 146 int err = MAILIMAP_NO_ERROR;
146 clist *result; 147 clist *result;
147 clistcell *current; 148 clistcell *current;
148 149
149 QList<IMAPFolder> * folders = new QList<IMAPFolder>(); 150 QList<Folder> * folders = new QList<Folder>();
150 folders->setAutoDelete( true ); 151 folders->setAutoDelete( true );
151 login(); 152 login();
152 if (!m_imap) { 153 if (!m_imap) {
153 return folders; 154 return folders;
154 } 155 }
155 156
156/* 157/*
157 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 158 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
158 * We must not forget to filter them out in next loop! 159 * We must not forget to filter them out in next loop!
159 * it seems like ugly code. and yes - it is ugly code. but the best way. 160 * it seems like ugly code. and yes - it is ugly code. but the best way.
160 */ 161 */
161 QString temp; 162 QString temp;
162 mask = "INBOX" ; 163 mask = "INBOX" ;
163 result = clist_new(); 164 result = clist_new();
164 mailimap_mailbox_list *list; 165 mailimap_mailbox_list *list;
165 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 166 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
166 if ( err == MAILIMAP_NO_ERROR ) { 167 if ( err == MAILIMAP_NO_ERROR ) {
167 current = result->first; 168 current = result->first;
168 for ( int i = result->count; i > 0; i-- ) { 169 for ( int i = result->count; i > 0; i-- ) {
169 list = (mailimap_mailbox_list *) current->data; 170 list = (mailimap_mailbox_list *) current->data;
170 // it is better use the deep copy mechanism of qt itself 171 // it is better use the deep copy mechanism of qt itself
171 // instead of using strdup! 172 // instead of using strdup!
172 temp = list->mb_name; 173 temp = list->mb_name;
173 folders->append( new IMAPFolder(temp)); 174 folders->append( new IMAPFolder(temp));
174 current = current->next; 175 current = current->next;
175 } 176 }
176 } else { 177 } else {
177 qDebug("error fetching folders: %s",m_imap->imap_response); 178 qDebug("error fetching folders: %s",m_imap->imap_response);
178 } 179 }
179 mailimap_list_result_free( result ); 180 mailimap_list_result_free( result );
180 181
181/* 182/*
182 * second stage - get the other then inbox folders 183 * second stage - get the other then inbox folders
183 */ 184 */
184 mask = "*" ; 185 mask = "*" ;
185 path = account->getPrefix().latin1(); 186 path = account->getPrefix().latin1();
186 if (!path) path = ""; 187 if (!path) path = "";
187 result = clist_new(); 188 result = clist_new();
188 qDebug(path); 189 qDebug(path);
189 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 190 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
190 if ( err == MAILIMAP_NO_ERROR ) { 191 if ( err == MAILIMAP_NO_ERROR ) {
191 current = result->first; 192 current = result->first;
192 for ( int i = result->count; i > 0; i-- ) { 193 for ( int i = result->count; i > 0; i-- ) {
193 list = (mailimap_mailbox_list *) current->data; 194 list = (mailimap_mailbox_list *) current->data;
194 // it is better use the deep copy mechanism of qt itself 195 // it is better use the deep copy mechanism of qt itself
195 // instead of using strdup! 196 // instead of using strdup!
196 temp = list->mb_name; 197 temp = list->mb_name;
197 current = current->next; 198 current = current->next;
198 if (temp.lower()=="inbox") 199 if (temp.lower()=="inbox")
199 continue; 200 continue;
200 folders->append(new IMAPFolder(temp)); 201 folders->append(new IMAPFolder(temp));
201 202
202 } 203 }
203 } else { 204 } else {
204 qDebug("error fetching folders %s",m_imap->imap_response); 205 qDebug("error fetching folders %s",m_imap->imap_response);
205 } 206 }
206 mailimap_list_result_free( result ); 207 mailimap_list_result_free( result );
207 return folders; 208 return folders;
208} 209}
209 210
210RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 211RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
211{ 212{
212 RecMail * m = 0; 213 RecMail * m = 0;
213 mailimap_msg_att_item *item=0; 214 mailimap_msg_att_item *item=0;
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index 95de215..f88457a 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -1,55 +1,52 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "abstractmail.h"
6 7
7struct mailimap; 8struct mailimap;
8struct mailimap_body_type_1part; 9struct mailimap_body_type_1part;
9struct mailimap_body_type_text; 10struct mailimap_body_type_text;
10struct mailimap_body_type_basic; 11struct mailimap_body_type_basic;
11struct mailimap_body_type_msg; 12struct mailimap_body_type_msg;
12struct mailimap_body_type_mpart; 13struct mailimap_body_type_mpart;
13struct mailimap_body_fields; 14struct mailimap_body_fields;
14struct mailimap_msg_att; 15struct mailimap_msg_att;
15class RecMail;
16class RecBody;
17class RecPart;
18 16
19class IMAPwrapper : public QObject 17class IMAPwrapper : public AbstractMail
20{ 18{
21 Q_OBJECT 19 Q_OBJECT
22
23public: 20public:
24 IMAPwrapper( IMAPaccount *a ); 21 IMAPwrapper( IMAPaccount *a );
25 virtual ~IMAPwrapper(); 22 virtual ~IMAPwrapper();
26 QList<IMAPFolder>* listFolders(); 23 virtual QList<Folder>* listFolders();
27 void listMessages(const QString & mailbox,QList<RecMail>&target ); 24 virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
28 RecBody fetchBody(const RecMail&mail); 25 virtual RecBody fetchBody(const RecMail&mail);
29 QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false); 26 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false);
30 QString fetchPart(const RecMail&mail,const RecPart&part); 27 virtual QString fetchPart(const RecMail&mail,const RecPart&part);
31 static void imap_progress( size_t current, size_t maximum ); 28 static void imap_progress( size_t current, size_t maximum );
32 29
33protected: 30protected:
34 RecMail*parse_list_result(mailimap_msg_att*); 31 RecMail*parse_list_result(mailimap_msg_att*);
35 void login(); 32 void login();
36 void logout(); 33 void logout();
37 34
38 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); 35 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
39 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); 36 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>());
40 37
41 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 38 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
42 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 39 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
43 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 40 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
44 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); 41 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
45 42
46 /* just helpers */ 43 /* just helpers */
47 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 44 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
48 static QStringList address_list_to_stringlist(clist*list); 45 static QStringList address_list_to_stringlist(clist*list);
49 46
50private: 47private:
51 IMAPaccount *account; 48 IMAPaccount *account;
52 mailimap *m_imap; 49 mailimap *m_imap;
53}; 50};
54 51
55#endif 52#endif
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index abb5a42..49c3b7a 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -1,126 +1,126 @@
1 1
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; 26 size_t length;
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 logout(); 34 logout();
35 return RecBody(); 35 return RecBody();
36 } 36 }
37 37
38 logout(); 38 logout();
39 39
40 return parseBody( message ); 40 return parseBody( message );
41} 41}
42 42
43RecBody POP3wrapper::parseBody( const char *message ) 43RecBody POP3wrapper::parseBody( const char *message )
44{ 44{
45 int err = MAILIMF_NO_ERROR; 45 int err = MAILIMF_NO_ERROR;
46 size_t curTok; 46 size_t curTok;
47 mailimf_message *result; 47 mailimf_message *result;
48 RecBody body; 48 RecBody body;
49 49
50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); 50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
51 if ( err != MAILIMF_NO_ERROR ) return body; 51 if ( err != MAILIMF_NO_ERROR ) return body;
52 52
53 if ( result && result->msg_body && result->msg_body->bd_text ) { 53 if ( result && result->msg_body && result->msg_body->bd_text ) {
54 qDebug( "POP3: bodytext found" ); 54 qDebug( "POP3: bodytext found" );
55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan. 55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan.
56 body.setBodytext( QString( result->msg_body->bd_text ) ); 56 body.setBodytext( QString( result->msg_body->bd_text ) );
57 } 57 }
58 58
59 return body; 59 return body;
60} 60}
61 61
62void POP3wrapper::listMessages( QList<RecMail> &target ) 62void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
63{ 63{
64 int err = MAILPOP3_NO_ERROR; 64 int err = MAILPOP3_NO_ERROR;
65 char *header; 65 char *header;
66 size_t length; 66 size_t length;
67 carray *messages; 67 carray *messages;
68 68
69 login(); 69 login();
70 if (!m_pop3) return; 70 if (!m_pop3) return;
71 mailpop3_list( m_pop3, &messages ); 71 mailpop3_list( m_pop3, &messages );
72 72
73 for ( int i = carray_count( messages ); i > 0; i-- ) { 73 for ( int i = carray_count( messages ); i > 0; i-- ) {
74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); 74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 );
75 75
76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
77 if ( err != MAILPOP3_NO_ERROR ) { 77 if ( err != MAILPOP3_NO_ERROR ) {
78 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); 78 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
79 logout(); 79 logout();
80 return; 80 return;
81 } 81 }
82 RecMail *mail = parseHeader( header ); 82 RecMail *mail = parseHeader( header );
83 mail->setNumber( info->msg_index ); 83 mail->setNumber( info->msg_index );
84 target.append( mail ); 84 target.append( mail );
85 } 85 }
86 86
87 logout(); 87 logout();
88} 88}
89 89
90RecMail *POP3wrapper::parseHeader( const char *header ) 90RecMail *POP3wrapper::parseHeader( const char *header )
91{ 91{
92 int err = MAILIMF_NO_ERROR; 92 int err = MAILIMF_NO_ERROR;
93 size_t curTok; 93 size_t curTok;
94 RecMail *mail = new RecMail(); 94 RecMail *mail = new RecMail();
95 mailimf_fields *fields; 95 mailimf_fields *fields;
96 96
97 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 97 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
98 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 98 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
99 mailimf_field *field = (mailimf_field *) current->data; 99 mailimf_field *field = (mailimf_field *) current->data;
100 switch ( field->fld_type ) { 100 switch ( field->fld_type ) {
101 case MAILIMF_FIELD_FROM: 101 case MAILIMF_FIELD_FROM:
102 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 102 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
103 break; 103 break;
104 case MAILIMF_FIELD_TO: 104 case MAILIMF_FIELD_TO:
105 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 105 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
106 break; 106 break;
107 case MAILIMF_FIELD_CC: 107 case MAILIMF_FIELD_CC:
108 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 108 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
109 break; 109 break;
110 case MAILIMF_FIELD_BCC: 110 case MAILIMF_FIELD_BCC:
111 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 111 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
112 break; 112 break;
113 case MAILIMF_FIELD_SUBJECT: 113 case MAILIMF_FIELD_SUBJECT:
114 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); 114 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) );
115 break; 115 break;
116 case MAILIMF_FIELD_ORIG_DATE: 116 case MAILIMF_FIELD_ORIG_DATE:
117 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 117 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
118 break; 118 break;
119 default: 119 default:
120 break; 120 break;
121 } 121 }
122 } 122 }
123 123
124 return mail; 124 return mail;
125} 125}
126 126
@@ -207,64 +207,83 @@ QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
207 if ( !first ) { 207 if ( !first ) {
208 result.append( "," ); 208 result.append( "," );
209 } else { 209 } else {
210 first = false; 210 first = false;
211 } 211 }
212 212
213 result.append( parseMailbox( box ) ); 213 result.append( parseMailbox( box ) );
214 } 214 }
215 215
216 return result; 216 return result;
217} 217}
218 218
219void POP3wrapper::login() 219void POP3wrapper::login()
220{ 220{
221 if ( m_pop3 != NULL ) logout(); 221 if ( m_pop3 != NULL ) logout();
222 222
223 const char *server, *user, *pass; 223 const char *server, *user, *pass;
224 uint16_t port; 224 uint16_t port;
225 int err = MAILPOP3_NO_ERROR; 225 int err = MAILPOP3_NO_ERROR;
226 226
227 server = account->getServer().latin1(); 227 server = account->getServer().latin1();
228 port = account->getPort().toUInt(); 228 port = account->getPort().toUInt();
229 user = account->getUser().latin1(); 229 user = account->getUser().latin1();
230 pass = account->getPassword().latin1(); 230 pass = account->getPassword().latin1();
231 231
232 m_pop3 = mailpop3_new( 200, &pop3_progress ); 232 m_pop3 = mailpop3_new( 200, &pop3_progress );
233 233
234 // connect 234 // connect
235 if (account->getSSL()) { 235 if (account->getSSL()) {
236 err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); 236 err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
237 } else { 237 } else {
238 err = mailpop3_socket_connect( m_pop3, (char*)server, port ); 238 err = mailpop3_socket_connect( m_pop3, (char*)server, port );
239 } 239 }
240 240
241 if ( err != MAILPOP3_NO_ERROR ) { 241 if ( err != MAILPOP3_NO_ERROR ) {
242 qDebug( "pop3: error connecting to %s\n reason: %s", server, 242 qDebug( "pop3: error connecting to %s\n reason: %s", server,
243 m_pop3->pop3_response ); 243 m_pop3->pop3_response );
244 mailpop3_free( m_pop3 ); 244 mailpop3_free( m_pop3 );
245 m_pop3 = NULL; 245 m_pop3 = NULL;
246 return; 246 return;
247 } 247 }
248 qDebug( "POP3: connected!" ); 248 qDebug( "POP3: connected!" );
249 249
250 // login 250 // login
251 // TODO: decide if apop or plain login should be used 251 // TODO: decide if apop or plain login should be used
252 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 252 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
253 if ( err != MAILPOP3_NO_ERROR ) { 253 if ( err != MAILPOP3_NO_ERROR ) {
254 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); 254 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response );
255 logout(); 255 logout();
256 return; 256 return;
257 } 257 }
258 258
259 qDebug( "POP3: logged in!" ); 259 qDebug( "POP3: logged in!" );
260} 260}
261 261
262void POP3wrapper::logout() 262void POP3wrapper::logout()
263{ 263{
264 int err = MAILPOP3_NO_ERROR; 264 int err = MAILPOP3_NO_ERROR;
265 if ( m_pop3 == NULL ) return; 265 if ( m_pop3 == NULL ) return;
266 err = mailpop3_quit( m_pop3 ); 266 err = mailpop3_quit( m_pop3 );
267 mailpop3_free( m_pop3 ); 267 mailpop3_free( m_pop3 );
268 m_pop3 = NULL; 268 m_pop3 = NULL;
269} 269}
270 270
271
272QList<Folder>* POP3wrapper::listFolders()
273{
274 QList<Folder> * folders = new QList<Folder>();
275 folders->setAutoDelete( true );
276 Folder*inb=new Folder("INBOX");
277 folders->append(inb);
278 return folders;
279}
280
281QString POP3wrapper::fetchPart(const RecMail&,const QValueList<int>&,bool)
282{
283 return "";
284}
285
286QString POP3wrapper::fetchPart(const RecMail&,const RecPart&)
287{
288 return "";
289}
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h
index 995bed0..3b24564 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.h
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h
@@ -1,38 +1,43 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include "abstractmail.h"
5 6
6class RecMail; 7class RecMail;
7class RecBody; 8class RecBody;
8struct mailpop3; 9struct mailpop3;
9 10
10class POP3wrapper : public QObject 11class POP3wrapper : public AbstractMail
11{ 12{
12 Q_OBJECT 13 Q_OBJECT
13 14
14public: 15public:
15 POP3wrapper( POP3account *a ); 16 POP3wrapper( POP3account *a );
16 virtual ~POP3wrapper(); 17 virtual ~POP3wrapper();
17 void listMessages( QList<RecMail> &target ); 18 /* mailbox will be ignored */
19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
20 virtual QList<Folder>* listFolders();
21 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false);
22 virtual QString fetchPart(const RecMail&mail,const RecPart&part);
23
18 RecBody fetchBody( const RecMail &mail ); 24 RecBody fetchBody( const RecMail &mail );
19 static void pop3_progress( size_t current, size_t maximum ); 25 static void pop3_progress( size_t current, size_t maximum );
20 26
21protected: 27protected:
22 void login(); 28 void login();
23 void logout(); 29 void logout();
24 30
25private: 31private:
26 RecMail *parseHeader( const char *header ); 32 RecMail *parseHeader( const char *header );
27 RecBody parseBody( const char *message ); 33 RecBody parseBody( const char *message );
28 QString parseMailboxList( mailimf_mailbox_list *list ); 34 QString parseMailboxList( mailimf_mailbox_list *list );
29 QString parseMailbox( mailimf_mailbox *box ); 35 QString parseMailbox( mailimf_mailbox *box );
30 QString parseGroup( mailimf_group *group ); 36 QString parseGroup( mailimf_group *group );
31 QString parseAddressList( mailimf_address_list *list ); 37 QString parseAddressList( mailimf_address_list *list );
32 QString parseDateTime( mailimf_date_time *date ); 38 QString parseDateTime( mailimf_date_time *date );
33 POP3account *account; 39 POP3account *account;
34 mailpop3 *m_pop3; 40 mailpop3 *m_pop3;
35
36}; 41};
37 42
38#endif 43#endif
diff --git a/noncore/net/mail/mail.pro b/noncore/net/mail/mail.pro
index 0e7cff6..e7519c6 100644
--- a/noncore/net/mail/mail.pro
+++ b/noncore/net/mail/mail.pro
@@ -1,49 +1,51 @@
1 CONFIG += qt warn_on debug quick-app 1 CONFIG += qt warn_on debug quick-app
2 2
3 HEADERS = defines.h \ 3 HEADERS = defines.h \
4 logindialog.h \ 4 logindialog.h \
5 settings.h \ 5 settings.h \
6 editaccounts.h \ 6 editaccounts.h \
7 mailwrapper.h \ 7 mailwrapper.h \
8 composemail.h \ 8 composemail.h \
9 accountview.h \ 9 accountview.h \
10 mainwindow.h \ 10 mainwindow.h \
11 viewmail.h \ 11 viewmail.h \
12 viewmailbase.h \ 12 viewmailbase.h \
13 opiemail.h \ 13 opiemail.h \
14 imapwrapper.h \ 14 imapwrapper.h \
15 mailtypes.h \ 15 mailtypes.h \
16 mailistviewitem.h \ 16 mailistviewitem.h \
17 pop3wrapper.h 17 pop3wrapper.h \
18 abstractmail.h
18 19
19 SOURCES = main.cpp \ 20 SOURCES = main.cpp \
20 opiemail.cpp \ 21 opiemail.cpp \
21 mainwindow.cpp \ 22 mainwindow.cpp \
22 accountview.cpp \ 23 accountview.cpp \
23 composemail.cpp \ 24 composemail.cpp \
24 mailwrapper.cpp \ 25 mailwrapper.cpp \
25 imapwrapper.cpp \ 26 imapwrapper.cpp \
26 addresspicker.cpp \ 27 addresspicker.cpp \
27 editaccounts.cpp \ 28 editaccounts.cpp \
28 logindialog.cpp \ 29 logindialog.cpp \
29 viewmail.cpp \ 30 viewmail.cpp \
30 viewmailbase.cpp \ 31 viewmailbase.cpp \
31 settings.cpp \ 32 settings.cpp \
32 mailtypes.cpp \ 33 mailtypes.cpp \
33 pop3wrapper.cpp 34 pop3wrapper.cpp \
35 abstractmail.cpp
34 36
35 INTERFACES = editaccountsui.ui \ 37 INTERFACES = editaccountsui.ui \
36 selectmailtypeui.ui \ 38 selectmailtypeui.ui \
37 imapconfigui.ui \ 39 imapconfigui.ui \
38 pop3configui.ui \ 40 pop3configui.ui \
39 nntpconfigui.ui \ 41 nntpconfigui.ui \
40 smtpconfigui.ui \ 42 smtpconfigui.ui \
41 addresspickerui.ui \ 43 addresspickerui.ui \
42 logindialogui.ui \ 44 logindialogui.ui \
43 composemailui.ui 45 composemailui.ui
44 46
45INCLUDEPATH += $(OPIEDIR)/include 47INCLUDEPATH += $(OPIEDIR)/include
46 LIBS += -lqpe -letpan -lssl -lcrypto -lopie 48 LIBS += -lqpe -letpan -lssl -lcrypto -lopie
47TARGET = opiemail 49TARGET = opiemail
48 50
49include ( $(OPIEDIR)/include.pro ) 51include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/net/mail/mainwindow.h b/noncore/net/mail/mainwindow.h
index 74bce5a..6c1cda0 100644
--- a/noncore/net/mail/mainwindow.h
+++ b/noncore/net/mail/mainwindow.h
@@ -1,43 +1,42 @@
1#ifndef MAINWINDOW_H 1#ifndef MAINWINDOW_H
2#define MAINWINDOW_H 2#define MAINWINDOW_H
3 3
4#include <qmainwindow.h> 4#include <qmainwindow.h>
5#include <qlistview.h> 5#include <qlistview.h>
6#include <qaction.h> 6#include <qaction.h>
7 7
8#include <qtoolbar.h> 8#include <qtoolbar.h>
9#include <qmenubar.h> 9#include <qmenubar.h>
10 10
11#include "accountview.h" 11#include "accountview.h"
12 12
13class RecMail; 13class RecMail;
14 14
15class MainWindow : public QMainWindow 15class MainWindow : public QMainWindow
16{ 16{
17 Q_OBJECT 17 Q_OBJECT
18 18
19public: 19public:
20 MainWindow( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 20 MainWindow( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
21 static QString appName() { return QString::fromLatin1("opiemail"); }
22 21
23public slots: 22public slots:
24 void slotAdjustColumns(); 23 void slotAdjustColumns();
25 24
26protected slots: 25protected slots:
27 virtual void slotShowFolders( bool show ); 26 virtual void slotShowFolders( bool show );
28 virtual void refreshMailView(QList<RecMail>*); 27 virtual void refreshMailView(QList<RecMail>*);
29 virtual void displayMail(QListViewItem*); 28 virtual void displayMail(QListViewItem*);
30 void slotAdjustLayout(); 29 void slotAdjustLayout();
31 30
32protected: 31protected:
33 QToolBar *toolBar; 32 QToolBar *toolBar;
34 QMenuBar *menuBar; 33 QMenuBar *menuBar;
35 QPopupMenu *mailMenu, *settingsMenu; 34 QPopupMenu *mailMenu, *settingsMenu;
36 QAction *composeMail, *sendQueued, *showFolders, *searchMails, 35 QAction *composeMail, *sendQueued, *showFolders, *searchMails,
37 *editSettings, *editAccounts, *syncFolders; 36 *editSettings, *editAccounts, *syncFolders;
38 AccountView *folderView; 37 AccountView *folderView;
39 QListView *mailView; 38 QListView *mailView;
40 QBoxLayout *layout; 39 QBoxLayout *layout;
41}; 40};
42 41
43#endif 42#endif
diff --git a/noncore/net/mail/opiemail.h b/noncore/net/mail/opiemail.h
index dcab47c..7bcd818 100644
--- a/noncore/net/mail/opiemail.h
+++ b/noncore/net/mail/opiemail.h
@@ -1,28 +1,26 @@
1#ifndef OPIEMAIL_H 1#ifndef OPIEMAIL_H
2#define OPIEMAIL_H 2#define OPIEMAIL_H
3 3
4#include "mainwindow.h" 4#include "mainwindow.h"
5#include "settings.h" 5#include "settings.h"
6 6
7class OpieMail : public MainWindow 7class OpieMail : public MainWindow
8{ 8{
9 Q_OBJECT 9 Q_OBJECT
10 10
11public: 11public:
12 OpieMail( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 12 OpieMail( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
13 13 static QString appName() { return QString::fromLatin1("opiemail"); }
14 static QString appName() { return QString::fromLatin1("opiemail"); }
15
16protected slots: 14protected slots:
17 void slotComposeMail(); 15 void slotComposeMail();
18 void slotSendQueued(); 16 void slotSendQueued();
19 void slotSearchMails(); 17 void slotSearchMails();
20 void slotEditSettings(); 18 void slotEditSettings();
21 void slotEditAccounts(); 19 void slotEditAccounts();
22 20
23private: 21private:
24 Settings *settings; 22 Settings *settings;
25 23
26}; 24};
27 25
28#endif 26#endif
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index abb5a42..49c3b7a 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -1,126 +1,126 @@
1 1
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; 26 size_t length;
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 logout(); 34 logout();
35 return RecBody(); 35 return RecBody();
36 } 36 }
37 37
38 logout(); 38 logout();
39 39
40 return parseBody( message ); 40 return parseBody( message );
41} 41}
42 42
43RecBody POP3wrapper::parseBody( const char *message ) 43RecBody POP3wrapper::parseBody( const char *message )
44{ 44{
45 int err = MAILIMF_NO_ERROR; 45 int err = MAILIMF_NO_ERROR;
46 size_t curTok; 46 size_t curTok;
47 mailimf_message *result; 47 mailimf_message *result;
48 RecBody body; 48 RecBody body;
49 49
50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); 50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
51 if ( err != MAILIMF_NO_ERROR ) return body; 51 if ( err != MAILIMF_NO_ERROR ) return body;
52 52
53 if ( result && result->msg_body && result->msg_body->bd_text ) { 53 if ( result && result->msg_body && result->msg_body->bd_text ) {
54 qDebug( "POP3: bodytext found" ); 54 qDebug( "POP3: bodytext found" );
55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan. 55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan.
56 body.setBodytext( QString( result->msg_body->bd_text ) ); 56 body.setBodytext( QString( result->msg_body->bd_text ) );
57 } 57 }
58 58
59 return body; 59 return body;
60} 60}
61 61
62void POP3wrapper::listMessages( QList<RecMail> &target ) 62void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
63{ 63{
64 int err = MAILPOP3_NO_ERROR; 64 int err = MAILPOP3_NO_ERROR;
65 char *header; 65 char *header;
66 size_t length; 66 size_t length;
67 carray *messages; 67 carray *messages;
68 68
69 login(); 69 login();
70 if (!m_pop3) return; 70 if (!m_pop3) return;
71 mailpop3_list( m_pop3, &messages ); 71 mailpop3_list( m_pop3, &messages );
72 72
73 for ( int i = carray_count( messages ); i > 0; i-- ) { 73 for ( int i = carray_count( messages ); i > 0; i-- ) {
74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); 74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 );
75 75
76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
77 if ( err != MAILPOP3_NO_ERROR ) { 77 if ( err != MAILPOP3_NO_ERROR ) {
78 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); 78 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
79 logout(); 79 logout();
80 return; 80 return;
81 } 81 }
82 RecMail *mail = parseHeader( header ); 82 RecMail *mail = parseHeader( header );
83 mail->setNumber( info->msg_index ); 83 mail->setNumber( info->msg_index );
84 target.append( mail ); 84 target.append( mail );
85 } 85 }
86 86
87 logout(); 87 logout();
88} 88}
89 89
90RecMail *POP3wrapper::parseHeader( const char *header ) 90RecMail *POP3wrapper::parseHeader( const char *header )
91{ 91{
92 int err = MAILIMF_NO_ERROR; 92 int err = MAILIMF_NO_ERROR;
93 size_t curTok; 93 size_t curTok;
94 RecMail *mail = new RecMail(); 94 RecMail *mail = new RecMail();
95 mailimf_fields *fields; 95 mailimf_fields *fields;
96 96
97 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 97 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
98 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 98 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
99 mailimf_field *field = (mailimf_field *) current->data; 99 mailimf_field *field = (mailimf_field *) current->data;
100 switch ( field->fld_type ) { 100 switch ( field->fld_type ) {
101 case MAILIMF_FIELD_FROM: 101 case MAILIMF_FIELD_FROM:
102 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 102 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
103 break; 103 break;
104 case MAILIMF_FIELD_TO: 104 case MAILIMF_FIELD_TO:
105 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 105 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
106 break; 106 break;
107 case MAILIMF_FIELD_CC: 107 case MAILIMF_FIELD_CC:
108 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 108 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
109 break; 109 break;
110 case MAILIMF_FIELD_BCC: 110 case MAILIMF_FIELD_BCC:
111 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 111 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
112 break; 112 break;
113 case MAILIMF_FIELD_SUBJECT: 113 case MAILIMF_FIELD_SUBJECT:
114 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); 114 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) );
115 break; 115 break;
116 case MAILIMF_FIELD_ORIG_DATE: 116 case MAILIMF_FIELD_ORIG_DATE:
117 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 117 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
118 break; 118 break;
119 default: 119 default:
120 break; 120 break;
121 } 121 }
122 } 122 }
123 123
124 return mail; 124 return mail;
125} 125}
126 126
@@ -207,64 +207,83 @@ QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
207 if ( !first ) { 207 if ( !first ) {
208 result.append( "," ); 208 result.append( "," );
209 } else { 209 } else {
210 first = false; 210 first = false;
211 } 211 }
212 212
213 result.append( parseMailbox( box ) ); 213 result.append( parseMailbox( box ) );
214 } 214 }
215 215
216 return result; 216 return result;
217} 217}
218 218
219void POP3wrapper::login() 219void POP3wrapper::login()
220{ 220{
221 if ( m_pop3 != NULL ) logout(); 221 if ( m_pop3 != NULL ) logout();
222 222
223 const char *server, *user, *pass; 223 const char *server, *user, *pass;
224 uint16_t port; 224 uint16_t port;
225 int err = MAILPOP3_NO_ERROR; 225 int err = MAILPOP3_NO_ERROR;
226 226
227 server = account->getServer().latin1(); 227 server = account->getServer().latin1();
228 port = account->getPort().toUInt(); 228 port = account->getPort().toUInt();
229 user = account->getUser().latin1(); 229 user = account->getUser().latin1();
230 pass = account->getPassword().latin1(); 230 pass = account->getPassword().latin1();
231 231
232 m_pop3 = mailpop3_new( 200, &pop3_progress ); 232 m_pop3 = mailpop3_new( 200, &pop3_progress );
233 233
234 // connect 234 // connect
235 if (account->getSSL()) { 235 if (account->getSSL()) {
236 err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); 236 err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
237 } else { 237 } else {
238 err = mailpop3_socket_connect( m_pop3, (char*)server, port ); 238 err = mailpop3_socket_connect( m_pop3, (char*)server, port );
239 } 239 }
240 240
241 if ( err != MAILPOP3_NO_ERROR ) { 241 if ( err != MAILPOP3_NO_ERROR ) {
242 qDebug( "pop3: error connecting to %s\n reason: %s", server, 242 qDebug( "pop3: error connecting to %s\n reason: %s", server,
243 m_pop3->pop3_response ); 243 m_pop3->pop3_response );
244 mailpop3_free( m_pop3 ); 244 mailpop3_free( m_pop3 );
245 m_pop3 = NULL; 245 m_pop3 = NULL;
246 return; 246 return;
247 } 247 }
248 qDebug( "POP3: connected!" ); 248 qDebug( "POP3: connected!" );
249 249
250 // login 250 // login
251 // TODO: decide if apop or plain login should be used 251 // TODO: decide if apop or plain login should be used
252 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 252 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
253 if ( err != MAILPOP3_NO_ERROR ) { 253 if ( err != MAILPOP3_NO_ERROR ) {
254 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); 254 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response );
255 logout(); 255 logout();
256 return; 256 return;
257 } 257 }
258 258
259 qDebug( "POP3: logged in!" ); 259 qDebug( "POP3: logged in!" );
260} 260}
261 261
262void POP3wrapper::logout() 262void POP3wrapper::logout()
263{ 263{
264 int err = MAILPOP3_NO_ERROR; 264 int err = MAILPOP3_NO_ERROR;
265 if ( m_pop3 == NULL ) return; 265 if ( m_pop3 == NULL ) return;
266 err = mailpop3_quit( m_pop3 ); 266 err = mailpop3_quit( m_pop3 );
267 mailpop3_free( m_pop3 ); 267 mailpop3_free( m_pop3 );
268 m_pop3 = NULL; 268 m_pop3 = NULL;
269} 269}
270 270
271
272QList<Folder>* POP3wrapper::listFolders()
273{
274 QList<Folder> * folders = new QList<Folder>();
275 folders->setAutoDelete( true );
276 Folder*inb=new Folder("INBOX");
277 folders->append(inb);
278 return folders;
279}
280
281QString POP3wrapper::fetchPart(const RecMail&,const QValueList<int>&,bool)
282{
283 return "";
284}
285
286QString POP3wrapper::fetchPart(const RecMail&,const RecPart&)
287{
288 return "";
289}
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h
index 995bed0..3b24564 100644
--- a/noncore/net/mail/pop3wrapper.h
+++ b/noncore/net/mail/pop3wrapper.h
@@ -1,38 +1,43 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include "abstractmail.h"
5 6
6class RecMail; 7class RecMail;
7class RecBody; 8class RecBody;
8struct mailpop3; 9struct mailpop3;
9 10
10class POP3wrapper : public QObject 11class POP3wrapper : public AbstractMail
11{ 12{
12 Q_OBJECT 13 Q_OBJECT
13 14
14public: 15public:
15 POP3wrapper( POP3account *a ); 16 POP3wrapper( POP3account *a );
16 virtual ~POP3wrapper(); 17 virtual ~POP3wrapper();
17 void listMessages( QList<RecMail> &target ); 18 /* mailbox will be ignored */
19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
20 virtual QList<Folder>* listFolders();
21 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false);
22 virtual QString fetchPart(const RecMail&mail,const RecPart&part);
23
18 RecBody fetchBody( const RecMail &mail ); 24 RecBody fetchBody( const RecMail &mail );
19 static void pop3_progress( size_t current, size_t maximum ); 25 static void pop3_progress( size_t current, size_t maximum );
20 26
21protected: 27protected:
22 void login(); 28 void login();
23 void logout(); 29 void logout();
24 30
25private: 31private:
26 RecMail *parseHeader( const char *header ); 32 RecMail *parseHeader( const char *header );
27 RecBody parseBody( const char *message ); 33 RecBody parseBody( const char *message );
28 QString parseMailboxList( mailimf_mailbox_list *list ); 34 QString parseMailboxList( mailimf_mailbox_list *list );
29 QString parseMailbox( mailimf_mailbox *box ); 35 QString parseMailbox( mailimf_mailbox *box );
30 QString parseGroup( mailimf_group *group ); 36 QString parseGroup( mailimf_group *group );
31 QString parseAddressList( mailimf_address_list *list ); 37 QString parseAddressList( mailimf_address_list *list );
32 QString parseDateTime( mailimf_date_time *date ); 38 QString parseDateTime( mailimf_date_time *date );
33 POP3account *account; 39 POP3account *account;
34 mailpop3 *m_pop3; 40 mailpop3 *m_pop3;
35
36}; 41};
37 42
38#endif 43#endif