summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-15 02:28:22 (UTC)
committer alwin <alwin>2003-12-15 02:28:22 (UTC)
commit07590207a8306d0184e3c331a71f41a58ccbc96f (patch) (unidiff)
tree0735d5bf28615f407c2b17f68a7acda078649312
parent1413ec0f3f1ed40fad087dfa413585f9fdf03400 (diff)
downloadopie-07590207a8306d0184e3c331a71f41a58ccbc96f.zip
opie-07590207a8306d0184e3c331a71f41a58ccbc96f.tar.gz
opie-07590207a8306d0184e3c331a71f41a58ccbc96f.tar.bz2
pop3wrapper now works in first stage and doesn't segfault anymore
Display an INBOX folder for pop3 accounts to get an more monoton mail interface for different types of mail server. Inbox - Folder get another icon than the other.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/accountview.cpp60
-rw-r--r--noncore/net/mail/accountview.h16
-rw-r--r--noncore/net/mail/defines.h2
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp57
-rw-r--r--noncore/net/mail/pop3wrapper.cpp57
5 files changed, 153 insertions, 39 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp
index d725b87..8e21d39 100644
--- a/noncore/net/mail/accountview.cpp
+++ b/noncore/net/mail/accountview.cpp
@@ -1,177 +1,227 @@
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
24void POP3viewItem::refresh( QList<RecMail> &target ) 24AbstractMail *POP3viewItem::getWrapper()
25{ 25{
26 qDebug( "POP3: refresh" ); 26 return wrapper;
27 wrapper->listMessages("INBOX", target );
28} 27}
29 28
29void POP3viewItem::refresh( QList<RecMail> & )
30{
31 QList<Folder> *folders = wrapper->listFolders();
32 QListViewItem *child = firstChild();
33 while ( child ) {
34 QListViewItem *tmp = child;
35 child = child->nextSibling();
36 delete tmp;
37 }
38 Folder *it;
39 QListViewItem*item = 0;
40 for ( it = folders->first(); it; it = folders->next() ) {
41 item = new POP3folderItem( it, this , item );
42 item->setSelectable(it->may_select());
43 }
44 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
45 folders->setAutoDelete(false);
46 delete folders;
47}
30 48
31RecBody POP3viewItem::fetchBody( const RecMail &mail ) 49RecBody POP3viewItem::fetchBody( const RecMail &mail )
32{ 50{
33 qDebug( "POP3 fetchBody" ); 51 qDebug( "POP3 fetchBody" );
34 return wrapper->fetchBody( mail ); 52 return wrapper->fetchBody( mail );
35} 53}
36 54
55POP3folderItem::~POP3folderItem()
56{
57 delete folder;
58}
59
60POP3folderItem::POP3folderItem( Folder *folderInit, POP3viewItem *parent , QListViewItem*after )
61 : AccountViewItem( parent,after )
62{
63 folder = folderInit;
64 pop3 = parent;
65 if (folder->getDisplayName().lower()!="inbox") {
66 setPixmap( 0, PIXMAP_POP3FOLDER );
67 } else {
68 setPixmap( 0, PIXMAP_INBOXFOLDER);
69 }
70 setText( 0, folder->getDisplayName() );
71}
72
73void POP3folderItem::refresh(QList<RecMail>&target)
74{
75 if (folder->may_select())
76 pop3->getWrapper()->listMessages( folder->getName(),target );
77}
78
79RecBody POP3folderItem::fetchBody(const RecMail&aMail)
80{
81 return pop3->getWrapper()->fetchBody(aMail);
82}
83
37/** 84/**
38 * IMAP Account stuff 85 * IMAP Account stuff
39 */ 86 */
40
41IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent ) 87IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent )
42 : AccountViewItem( parent ) 88 : AccountViewItem( parent )
43{ 89{
44 account = a; 90 account = a;
45 wrapper = AbstractMail::getWrapper( account ); 91 wrapper = AbstractMail::getWrapper( account );
46 setPixmap( 0, PIXMAP_IMAPFOLDER ); 92 setPixmap( 0, PIXMAP_IMAPFOLDER );
47 setText( 0, account->getAccountName() ); 93 setText( 0, account->getAccountName() );
48 setOpen( true ); 94 setOpen( true );
49} 95}
50 96
51IMAPviewItem::~IMAPviewItem() 97IMAPviewItem::~IMAPviewItem()
52{ 98{
53 delete wrapper; 99 delete wrapper;
54} 100}
55 101
56AbstractMail *IMAPviewItem::getWrapper() 102AbstractMail *IMAPviewItem::getWrapper()
57{ 103{
58 return wrapper; 104 return wrapper;
59} 105}
60 106
61void IMAPviewItem::refresh(QList<RecMail>&) 107void IMAPviewItem::refresh(QList<RecMail>&)
62{ 108{
63 QList<Folder> *folders = wrapper->listFolders(); 109 QList<Folder> *folders = wrapper->listFolders();
64 110
65 QListViewItem *child = firstChild(); 111 QListViewItem *child = firstChild();
66 while ( child ) { 112 while ( child ) {
67 QListViewItem *tmp = child; 113 QListViewItem *tmp = child;
68 child = child->nextSibling(); 114 child = child->nextSibling();
69 delete tmp; 115 delete tmp;
70 } 116 }
71 117
72 Folder *it; 118 Folder *it;
73 QListViewItem*item = 0; 119 QListViewItem*item = 0;
74 for ( it = folders->first(); it; it = folders->next() ) { 120 for ( it = folders->first(); it; it = folders->next() ) {
75 item = new IMAPfolderItem( it, this , item ); 121 item = new IMAPfolderItem( it, this , item );
76 item->setSelectable(it->may_select()); 122 item->setSelectable(it->may_select());
77 } 123 }
78 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 124 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
79 folders->setAutoDelete(false); 125 folders->setAutoDelete(false);
80 delete folders; 126 delete folders;
81} 127}
82 128
83RecBody IMAPviewItem::fetchBody(const RecMail&) 129RecBody IMAPviewItem::fetchBody(const RecMail&)
84{ 130{
85 return RecBody(); 131 return RecBody();
86} 132}
87 133
88IMAPfolderItem::~IMAPfolderItem() 134IMAPfolderItem::~IMAPfolderItem()
89{ 135{
90 delete folder; 136 delete folder;
91} 137}
92 138
93IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after ) 139IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after )
94 : AccountViewItem( parent,after ) 140 : AccountViewItem( parent,after )
95{ 141{
96 folder = folderInit; 142 folder = folderInit;
97 imap = parent; 143 imap = parent;
98 setPixmap( 0, PIXMAP_IMAPFOLDER ); 144 if (folder->getDisplayName().lower()!="inbox") {
145 setPixmap( 0, PIXMAP_IMAPFOLDER );
146 } else {
147 setPixmap( 0, PIXMAP_INBOXFOLDER);
148 }
99 setText( 0, folder->getDisplayName() ); 149 setText( 0, folder->getDisplayName() );
100} 150}
101 151
102void IMAPfolderItem::refresh(QList<RecMail>&target) 152void IMAPfolderItem::refresh(QList<RecMail>&target)
103{ 153{
104 if (folder->may_select()) 154 if (folder->may_select())
105 imap->getWrapper()->listMessages( folder->getName(),target ); 155 imap->getWrapper()->listMessages( folder->getName(),target );
106} 156}
107 157
108RecBody IMAPfolderItem::fetchBody(const RecMail&aMail) 158RecBody IMAPfolderItem::fetchBody(const RecMail&aMail)
109{ 159{
110 return imap->getWrapper()->fetchBody(aMail); 160 return imap->getWrapper()->fetchBody(aMail);
111} 161}
112 162
113/** 163/**
114 * Generic stuff 164 * Generic stuff
115 */ 165 */
116 166
117AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) 167AccountView::AccountView( QWidget *parent, const char *name, WFlags flags )
118 : QListView( parent, name, flags ) 168 : QListView( parent, name, flags )
119{ 169{
120 connect( this, SIGNAL( selectionChanged( QListViewItem * ) ), 170 connect( this, SIGNAL( selectionChanged( QListViewItem * ) ),
121 SLOT( refresh( QListViewItem * ) ) ); 171 SLOT( refresh( QListViewItem * ) ) );
122 setSorting(-1); 172 setSorting(-1);
123} 173}
124 174
125void AccountView::populate( QList<Account> list ) 175void AccountView::populate( QList<Account> list )
126{ 176{
127 clear(); 177 clear();
128 178
129 Account *it; 179 Account *it;
130 for ( it = list.first(); it; it = list.next() ) { 180 for ( it = list.first(); it; it = list.next() ) {
131 if ( it->getType().compare( "IMAP" ) == 0 ) { 181 if ( it->getType().compare( "IMAP" ) == 0 ) {
132 IMAPaccount *imap = static_cast<IMAPaccount *>(it); 182 IMAPaccount *imap = static_cast<IMAPaccount *>(it);
133 qDebug( "added IMAP " + imap->getAccountName() ); 183 qDebug( "added IMAP " + imap->getAccountName() );
134 (void) new IMAPviewItem( imap, this ); 184 (void) new IMAPviewItem( imap, this );
135 } else if ( it->getType().compare( "POP3" ) == 0 ) { 185 } else if ( it->getType().compare( "POP3" ) == 0 ) {
136 POP3account *pop3 = static_cast<POP3account *>(it); 186 POP3account *pop3 = static_cast<POP3account *>(it);
137 qDebug( "added POP3 " + pop3->getAccountName() ); 187 qDebug( "added POP3 " + pop3->getAccountName() );
138 (void) new POP3viewItem( pop3, this ); 188 (void) new POP3viewItem( pop3, this );
139 } 189 }
140 } 190 }
141} 191}
142 192
143void AccountView::refresh(QListViewItem *item) { 193void AccountView::refresh(QListViewItem *item) {
144 194
145 qDebug("AccountView refresh..."); 195 qDebug("AccountView refresh...");
146 if ( item ) { 196 if ( item ) {
147 m_currentItem = item; 197 m_currentItem = item;
148 QList<RecMail> headerlist; 198 QList<RecMail> headerlist;
149 headerlist.setAutoDelete(true); 199 headerlist.setAutoDelete(true);
150 AccountViewItem *view = static_cast<AccountViewItem *>(item); 200 AccountViewItem *view = static_cast<AccountViewItem *>(item);
151 view->refresh(headerlist); 201 view->refresh(headerlist);
152 emit refreshMailview(&headerlist); 202 emit refreshMailview(&headerlist);
153 } 203 }
154} 204}
155 205
156void AccountView::refreshCurrent() 206void AccountView::refreshCurrent()
157{ 207{
158 if ( !m_currentItem ) return; 208 if ( !m_currentItem ) return;
159 QList<RecMail> headerlist; 209 QList<RecMail> headerlist;
160 headerlist.setAutoDelete(true); 210 headerlist.setAutoDelete(true);
161 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); 211 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem);
162 view->refresh(headerlist); 212 view->refresh(headerlist);
163 emit refreshMailview(&headerlist); 213 emit refreshMailview(&headerlist);
164} 214}
165 215
166void AccountView::refreshAll() 216void AccountView::refreshAll()
167{ 217{
168 218
169} 219}
170 220
171RecBody AccountView::fetchBody(const RecMail&aMail) 221RecBody AccountView::fetchBody(const RecMail&aMail)
172{ 222{
173 QListViewItem*item = selectedItem (); 223 QListViewItem*item = selectedItem ();
174 if (!item) return RecBody(); 224 if (!item) return RecBody();
175 AccountViewItem *view = static_cast<AccountViewItem *>(item); 225 AccountViewItem *view = static_cast<AccountViewItem *>(item);
176 return view->fetchBody(aMail); 226 return view->fetchBody(aMail);
177} 227}
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h
index 04f9b7a..d035af4 100644
--- a/noncore/net/mail/accountview.h
+++ b/noncore/net/mail/accountview.h
@@ -1,90 +1,102 @@
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 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
42{
43
44public:
45 POP3folderItem( Folder *folder, POP3viewItem *parent , QListViewItem*after );
46 ~POP3folderItem();
47 virtual void refresh(QList<RecMail>&);
48 virtual RecBody fetchBody(const RecMail&);
49private:
50 Folder *folder;
51 POP3viewItem *pop3;
52};
53
41class IMAPviewItem : public AccountViewItem 54class IMAPviewItem : public AccountViewItem
42{ 55{
43 56
44public: 57public:
45 IMAPviewItem( IMAPaccount *a, QListView *parent ); 58 IMAPviewItem( IMAPaccount *a, QListView *parent );
46 ~IMAPviewItem(); 59 ~IMAPviewItem();
47 virtual void refresh(QList<RecMail>&); 60 virtual void refresh(QList<RecMail>&);
48 virtual RecBody fetchBody(const RecMail&); 61 virtual RecBody fetchBody(const RecMail&);
49 AbstractMail *getWrapper(); 62 AbstractMail *getWrapper();
50private: 63private:
51 IMAPaccount *account; 64 IMAPaccount *account;
52 AbstractMail *wrapper; 65 AbstractMail *wrapper;
53}; 66};
54 67
55class IMAPfolderItem : public AccountViewItem 68class IMAPfolderItem : public AccountViewItem
56{ 69{
57 70
58public: 71public:
59 IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after ); 72 IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after );
60 ~IMAPfolderItem(); 73 ~IMAPfolderItem();
61 virtual void refresh(QList<RecMail>&); 74 virtual void refresh(QList<RecMail>&);
62 virtual RecBody fetchBody(const RecMail&); 75 virtual RecBody fetchBody(const RecMail&);
63private: 76private:
64 Folder *folder; 77 Folder *folder;
65 IMAPviewItem *imap; 78 IMAPviewItem *imap;
66
67}; 79};
68 80
69class AccountView : public QListView 81class AccountView : public QListView
70{ 82{
71 Q_OBJECT 83 Q_OBJECT
72 84
73public: 85public:
74 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 86 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
75 void populate( QList<Account> list ); 87 void populate( QList<Account> list );
76 RecBody fetchBody(const RecMail&aMail); 88 RecBody fetchBody(const RecMail&aMail);
77 89
78public slots: 90public slots:
79 void refreshAll(); 91 void refreshAll();
80 void refresh(QListViewItem *item); 92 void refresh(QListViewItem *item);
81 void refreshCurrent(); 93 void refreshCurrent();
82 94
83signals: 95signals:
84 void refreshMailview(QList<RecMail>*); 96 void refreshMailview(QList<RecMail>*);
85 97
86private: 98private:
87 QListViewItem* m_currentItem; 99 QListViewItem* m_currentItem;
88}; 100};
89 101
90#endif 102#endif
diff --git a/noncore/net/mail/defines.h b/noncore/net/mail/defines.h
index 679459d..c849f1a 100644
--- a/noncore/net/mail/defines.h
+++ b/noncore/net/mail/defines.h
@@ -1,38 +1,40 @@
1#ifndef DEFINE_CONSTANTS_H 1#ifndef DEFINE_CONSTANTS_H
2#define DEFINE_CONSTANTS_H 2#define DEFINE_CONSTANTS_H
3 3
4#include <qpe/resource.h> 4#include <qpe/resource.h>
5 5
6#define USER_AGENT "OpieMail v0.0.1-alpha" 6#define USER_AGENT "OpieMail v0.0.1-alpha"
7 7
8#define PIC_COMPOSEMAIL "opiemail/composemail" 8#define PIC_COMPOSEMAIL "opiemail/composemail"
9#define PIC_SENDQUEUED "opiemail/sendqueued" 9#define PIC_SENDQUEUED "opiemail/sendqueued"
10#define PIC_SHOWFOLDERS "opiemail/showfolders" 10#define PIC_SHOWFOLDERS "opiemail/showfolders"
11#define PIC_SEARCHMAILS "opiemail/searchmails" 11#define PIC_SEARCHMAILS "opiemail/searchmails"
12#define PIC_EDITSETTINGS "opiemail/editsettings" 12#define PIC_EDITSETTINGS "opiemail/editsettings"
13#define PIC_EDITACCOUNTS "opiemail/editaccounts" 13#define PIC_EDITACCOUNTS "opiemail/editaccounts"
14#define PIC_SYNC "opiemail/sync" 14#define PIC_SYNC "opiemail/sync"
15#define PIC_IMAPFOLDER "opiemail/imapfolder" 15#define PIC_IMAPFOLDER "opiemail/imapfolder"
16#define PIC_POP3FOLDER "opiemail/pop3folder" 16#define PIC_POP3FOLDER "opiemail/pop3folder"
17#define PIC_INBOXFOLDER "opiemail/inbox"
17 18
18#define ICON_COMPOSEMAIL QIconSet( Resource::loadPixmap( PIC_COMPOSEMAIL ) ) 19#define ICON_COMPOSEMAIL QIconSet( Resource::loadPixmap( PIC_COMPOSEMAIL ) )
19#define ICON_SENDQUEUED QIconSet( Resource::loadPixmap( PIC_SENDQUEUED ) ) 20#define ICON_SENDQUEUED QIconSet( Resource::loadPixmap( PIC_SENDQUEUED ) )
20#define ICON_SHOWFOLDERS QIconSet( Resource::loadPixmap( PIC_SHOWFOLDERS ) ) 21#define ICON_SHOWFOLDERS QIconSet( Resource::loadPixmap( PIC_SHOWFOLDERS ) )
21#define ICON_SEARCHMAILS QIconSet( Resource::loadPixmap( PIC_SEARCHMAILS ) ) 22#define ICON_SEARCHMAILS QIconSet( Resource::loadPixmap( PIC_SEARCHMAILS ) )
22#define ICON_EDITSETTINGS QIconSet( Resource::loadPixmap( PIC_EDITSETTINGS ) ) 23#define ICON_EDITSETTINGS QIconSet( Resource::loadPixmap( PIC_EDITSETTINGS ) )
23#define ICON_EDITACCOUNTS QIconSet( Resource::loadPixmap( PIC_EDITACCOUNTS ) ) 24#define ICON_EDITACCOUNTS QIconSet( Resource::loadPixmap( PIC_EDITACCOUNTS ) )
24#define ICON_SYNC QIconSet( Resource::loadPixmap( PIC_SYNC ) ) 25#define ICON_SYNC QIconSet( Resource::loadPixmap( PIC_SYNC ) )
25 26
26#define PIXMAP_IMAPFOLDER QPixmap( Resource::loadPixmap( PIC_IMAPFOLDER ) ) 27#define PIXMAP_IMAPFOLDER QPixmap( Resource::loadPixmap( PIC_IMAPFOLDER ) )
27#define PIXMAP_POP3FOLDER QPixmap( Resource::loadPixmap( PIC_POP3FOLDER ) ) 28#define PIXMAP_POP3FOLDER QPixmap( Resource::loadPixmap( PIC_POP3FOLDER ) )
29#define PIXMAP_INBOXFOLDER QPixmap( Resource::loadPixmap( PIC_INBOXFOLDER) )
28 30
29#define IMAP_PORT "143" 31#define IMAP_PORT "143"
30#define IMAP_SSL_PORT "993" 32#define IMAP_SSL_PORT "993"
31#define SMTP_PORT "25" 33#define SMTP_PORT "25"
32#define SMTP_SSL_PORT "465" 34#define SMTP_SSL_PORT "465"
33#define POP3_PORT "110" 35#define POP3_PORT "110"
34#define POP3_SSL_PORT "995" 36#define POP3_SSL_PORT "995"
35#define NNTP_PORT "119" 37#define NNTP_PORT "119"
36#define NNTP_SSL_PORT "563" 38#define NNTP_SSL_PORT "563"
37 39
38#endif 40#endif
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 46c854b..2411399 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -1,293 +1,318 @@
1 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; 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 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
47 mailimf_message *result; 47 size_t curTok = 0;
48 mailimf_message *result = 0;
48 RecBody body; 49 RecBody body;
49 50
50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); 51 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
51 if ( err != MAILIMF_NO_ERROR ) return body; 52 if ( err != MAILIMF_NO_ERROR ) {
53 if (result) mailimf_message_free(result);
54 return body;
55 }
52 56
53 if ( result && result->msg_body && result->msg_body->bd_text ) { 57 if ( result && result->msg_body && result->msg_body->bd_text ) {
54 qDebug( "POP3: bodytext found" ); 58 qDebug( "POP3: bodytext found" );
55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan. 59 // when curTok isn't set to 0 this line will fault! 'cause upper line faults!
56 body.setBodytext( QString( result->msg_body->bd_text ) ); 60 body.setBodytext( QString( result->msg_body->bd_text ) );
57 } 61 }
58 62 if (result) mailimf_message_free(result);
59 return body; 63 return body;
60} 64}
61 65
62void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 66void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
63{ 67{
64 int err = MAILPOP3_NO_ERROR; 68 int err = MAILPOP3_NO_ERROR;
65 char *header; 69 char * header = 0;
66 size_t length; 70 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
67 carray *messages; 71 size_t length = 0;
72 carray * messages = 0;
68 73
69 login(); 74 login();
70 if (!m_pop3) return; 75 if (!m_pop3) return;
71 mailpop3_list( m_pop3, &messages ); 76 mailpop3_list( m_pop3, &messages );
72 77
73 for ( int i = carray_count( messages ); i > 0; i-- ) { 78 //for ( int i = carray_count( messages ); i > 0; i-- ) {
74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); 79 for (unsigned int i = 0; i < carray_count(messages);++i) {
75 80 mailpop3_msg_info *info;
81 int r = mailpop3_get_msg_info(m_pop3,i+1,&info);
76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 82 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
77 if ( err != MAILPOP3_NO_ERROR ) { 83 if ( err != MAILPOP3_NO_ERROR ) {
78 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); 84 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
85 free(header);
79 logout(); 86 logout();
80 return; 87 return;
81 } 88 }
82 RecMail *mail = parseHeader( header ); 89 RecMail *mail = parseHeader( header );
83 mail->setNumber( info->msg_index ); 90 mail->setNumber( info->msg_index );
84 mail->setWrapper(this); 91 mail->setWrapper(this);
85 target.append( mail ); 92 target.append( mail );
93 free(header);
86 } 94 }
87
88 logout(); 95 logout();
89} 96}
90 97
91RecMail *POP3wrapper::parseHeader( const char *header ) 98RecMail *POP3wrapper::parseHeader( const char *header )
92{ 99{
93 int err = MAILIMF_NO_ERROR; 100 int err = MAILIMF_NO_ERROR;
94 size_t curTok; 101 size_t curTok = 0;
95 RecMail *mail = new RecMail(); 102 RecMail *mail = new RecMail();
96 mailimf_fields *fields; 103 mailimf_fields *fields;
97 104 mailimf_references * refs;
105 mailimf_keywords*keys;
106
98 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 107 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
99 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 ) {
100 mailimf_field *field = (mailimf_field *) current->data; 109 mailimf_field *field = (mailimf_field *) current->data;
101 switch ( field->fld_type ) { 110 switch ( field->fld_type ) {
102 case MAILIMF_FIELD_FROM: 111 case MAILIMF_FIELD_FROM:
103 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 112 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
104 break; 113 break;
105 case MAILIMF_FIELD_TO: 114 case MAILIMF_FIELD_TO:
106 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 115 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
107 break; 116 break;
108 case MAILIMF_FIELD_CC: 117 case MAILIMF_FIELD_CC:
109 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 118 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
110 break; 119 break;
111 case MAILIMF_FIELD_BCC: 120 case MAILIMF_FIELD_BCC:
112 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 121 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
113 break; 122 break;
114 case MAILIMF_FIELD_SUBJECT: 123 case MAILIMF_FIELD_SUBJECT:
115 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); 124 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) );
116 break; 125 break;
117 case MAILIMF_FIELD_ORIG_DATE: 126 case MAILIMF_FIELD_ORIG_DATE:
118 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 ) );
119 break; 128 break;
129 case MAILIMF_FIELD_MESSAGE_ID:
130 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value));
131 break;
132 case MAILIMF_FIELD_REFERENCES:
133 refs = field->fld_data.fld_references;
134 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
135 char * text = (char*)refs->mid_list->first->data;
136 mail->setReplyto(QString(text));
137 }
138 break;
139 case MAILIMF_FIELD_KEYWORDS:
140 keys = field->fld_data.fld_keywords;
141 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
142 qDebug("Keyword: %s",(char*)cur->data);
143 }
144 break;
120 default: 145 default:
121 break; 146 break;
122 } 147 }
123 } 148 }
124 149 if (fields) mailimf_fields_free(fields);
125 return mail; 150 return mail;
126} 151}
127 152
128QString POP3wrapper::parseDateTime( mailimf_date_time *date ) 153QString POP3wrapper::parseDateTime( mailimf_date_time *date )
129{ 154{
130 char tmp[23]; 155 char tmp[23];
131 156
132 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 157 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
133 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 158 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
134 159
135 return QString( tmp ); 160 return QString( tmp );
136} 161}
137 162
138QString POP3wrapper::parseAddressList( mailimf_address_list *list ) 163QString POP3wrapper::parseAddressList( mailimf_address_list *list )
139{ 164{
140 QString result( "" ); 165 QString result( "" );
141 166
142 bool first = true; 167 bool first = true;
143 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 168 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
144 mailimf_address *addr = (mailimf_address *) current->data; 169 mailimf_address *addr = (mailimf_address *) current->data;
145 170
146 if ( !first ) { 171 if ( !first ) {
147 result.append( "," ); 172 result.append( "," );
148 } else { 173 } else {
149 first = false; 174 first = false;
150 } 175 }
151 176
152 switch ( addr->ad_type ) { 177 switch ( addr->ad_type ) {
153 case MAILIMF_ADDRESS_MAILBOX: 178 case MAILIMF_ADDRESS_MAILBOX:
154 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 179 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
155 break; 180 break;
156 case MAILIMF_ADDRESS_GROUP: 181 case MAILIMF_ADDRESS_GROUP:
157 result.append( parseGroup( addr->ad_data.ad_group ) ); 182 result.append( parseGroup( addr->ad_data.ad_group ) );
158 break; 183 break;
159 default: 184 default:
160 qDebug( "POP3: unkown mailimf address type" ); 185 qDebug( "POP3: unkown mailimf address type" );
161 break; 186 break;
162 } 187 }
163 } 188 }
164 189
165 return result; 190 return result;
166} 191}
167 192
168QString POP3wrapper::parseGroup( mailimf_group *group ) 193QString POP3wrapper::parseGroup( mailimf_group *group )
169{ 194{
170 QString result( "" ); 195 QString result( "" );
171 196
172 result.append( group->grp_display_name ); 197 result.append( group->grp_display_name );
173 result.append( ": " ); 198 result.append( ": " );
174 199
175 if ( group->grp_mb_list != NULL ) { 200 if ( group->grp_mb_list != NULL ) {
176 result.append( parseMailboxList( group->grp_mb_list ) ); 201 result.append( parseMailboxList( group->grp_mb_list ) );
177 } 202 }
178 203
179 result.append( ";" ); 204 result.append( ";" );
180 205
181 return result; 206 return result;
182} 207}
183 208
184QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) 209QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
185{ 210{
186 QString result( "" ); 211 QString result( "" );
187 212
188 if ( box->mb_display_name == NULL ) { 213 if ( box->mb_display_name == NULL ) {
189 result.append( box->mb_addr_spec ); 214 result.append( box->mb_addr_spec );
190 } else { 215 } else {
191 result.append( box->mb_display_name ); 216 result.append( box->mb_display_name );
192 result.append( " <" ); 217 result.append( " <" );
193 result.append( box->mb_addr_spec ); 218 result.append( box->mb_addr_spec );
194 result.append( ">" ); 219 result.append( ">" );
195 } 220 }
196 221
197 return result; 222 return result;
198} 223}
199 224
200QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) 225QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
201{ 226{
202 QString result( "" ); 227 QString result( "" );
203 228
204 bool first = true; 229 bool first = true;
205 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 230 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
206 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 231 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
207 232
208 if ( !first ) { 233 if ( !first ) {
209 result.append( "," ); 234 result.append( "," );
210 } else { 235 } else {
211 first = false; 236 first = false;
212 } 237 }
213 238
214 result.append( parseMailbox( box ) ); 239 result.append( parseMailbox( box ) );
215 } 240 }
216 241
217 return result; 242 return result;
218} 243}
219 244
220void POP3wrapper::login() 245void POP3wrapper::login()
221{ 246{
222 if ( m_pop3 != NULL ) logout(); 247 if ( m_pop3 != NULL ) logout();
223 248
224 const char *server, *user, *pass; 249 const char *server, *user, *pass;
225 uint16_t port; 250 uint16_t port;
226 int err = MAILPOP3_NO_ERROR; 251 int err = MAILPOP3_NO_ERROR;
227 252
228 server = account->getServer().latin1(); 253 server = account->getServer().latin1();
229 port = account->getPort().toUInt(); 254 port = account->getPort().toUInt();
230 user = account->getUser().latin1(); 255 user = account->getUser().latin1();
231 pass = account->getPassword().latin1(); 256 pass = account->getPassword().latin1();
232 257
233 m_pop3 = mailpop3_new( 200, &pop3_progress ); 258 m_pop3 = mailpop3_new( 200, &pop3_progress );
234 259
235 // connect 260 // connect
236 if (account->getSSL()) { 261 if (account->getSSL()) {
237 err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); 262 err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
238 } else { 263 } else {
239 err = mailpop3_socket_connect( m_pop3, (char*)server, port ); 264 err = mailpop3_socket_connect( m_pop3, (char*)server, port );
240 } 265 }
241 266
242 if ( err != MAILPOP3_NO_ERROR ) { 267 if ( err != MAILPOP3_NO_ERROR ) {
243 qDebug( "pop3: error connecting to %s\n reason: %s", server, 268 qDebug( "pop3: error connecting to %s\n reason: %s", server,
244 m_pop3->pop3_response ); 269 m_pop3->pop3_response );
245 mailpop3_free( m_pop3 ); 270 mailpop3_free( m_pop3 );
246 m_pop3 = NULL; 271 m_pop3 = NULL;
247 return; 272 return;
248 } 273 }
249 qDebug( "POP3: connected!" ); 274 qDebug( "POP3: connected!" );
250 275
251 // login 276 // login
252 // TODO: decide if apop or plain login should be used 277 // TODO: decide if apop or plain login should be used
253 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 278 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
254 if ( err != MAILPOP3_NO_ERROR ) { 279 if ( err != MAILPOP3_NO_ERROR ) {
255 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); 280 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response );
256 logout(); 281 logout();
257 return; 282 return;
258 } 283 }
259 284
260 qDebug( "POP3: logged in!" ); 285 qDebug( "POP3: logged in!" );
261} 286}
262 287
263void POP3wrapper::logout() 288void POP3wrapper::logout()
264{ 289{
265 int err = MAILPOP3_NO_ERROR; 290 int err = MAILPOP3_NO_ERROR;
266 if ( m_pop3 == NULL ) return; 291 if ( m_pop3 == NULL ) return;
267 err = mailpop3_quit( m_pop3 ); 292 err = mailpop3_quit( m_pop3 );
268 mailpop3_free( m_pop3 ); 293 mailpop3_free( m_pop3 );
269 m_pop3 = NULL; 294 m_pop3 = NULL;
270} 295}
271 296
272 297
273QList<Folder>* POP3wrapper::listFolders() 298QList<Folder>* POP3wrapper::listFolders()
274{ 299{
275 QList<Folder> * folders = new QList<Folder>(); 300 QList<Folder> * folders = new QList<Folder>();
276 folders->setAutoDelete( false ); 301 folders->setAutoDelete( false );
277 Folder*inb=new Folder("INBOX"); 302 Folder*inb=new Folder("INBOX");
278 folders->append(inb); 303 folders->append(inb);
279 return folders; 304 return folders;
280} 305}
281 306
282QString POP3wrapper::fetchPart(const RecMail&,const RecPart&) 307QString POP3wrapper::fetchPart(const RecMail&,const RecPart&)
283{ 308{
284 return ""; 309 return "";
285} 310}
286 311
287void POP3wrapper::deleteMail(const RecMail&) 312void POP3wrapper::deleteMail(const RecMail&)
288{ 313{
289} 314}
290 315
291void POP3wrapper::answeredMail(const RecMail&) 316void POP3wrapper::answeredMail(const RecMail&)
292{ 317{
293} 318}
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index 46c854b..2411399 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -1,293 +1,318 @@
1 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; 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 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
47 mailimf_message *result; 47 size_t curTok = 0;
48 mailimf_message *result = 0;
48 RecBody body; 49 RecBody body;
49 50
50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); 51 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
51 if ( err != MAILIMF_NO_ERROR ) return body; 52 if ( err != MAILIMF_NO_ERROR ) {
53 if (result) mailimf_message_free(result);
54 return body;
55 }
52 56
53 if ( result && result->msg_body && result->msg_body->bd_text ) { 57 if ( result && result->msg_body && result->msg_body->bd_text ) {
54 qDebug( "POP3: bodytext found" ); 58 qDebug( "POP3: bodytext found" );
55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan. 59 // when curTok isn't set to 0 this line will fault! 'cause upper line faults!
56 body.setBodytext( QString( result->msg_body->bd_text ) ); 60 body.setBodytext( QString( result->msg_body->bd_text ) );
57 } 61 }
58 62 if (result) mailimf_message_free(result);
59 return body; 63 return body;
60} 64}
61 65
62void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 66void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
63{ 67{
64 int err = MAILPOP3_NO_ERROR; 68 int err = MAILPOP3_NO_ERROR;
65 char *header; 69 char * header = 0;
66 size_t length; 70 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
67 carray *messages; 71 size_t length = 0;
72 carray * messages = 0;
68 73
69 login(); 74 login();
70 if (!m_pop3) return; 75 if (!m_pop3) return;
71 mailpop3_list( m_pop3, &messages ); 76 mailpop3_list( m_pop3, &messages );
72 77
73 for ( int i = carray_count( messages ); i > 0; i-- ) { 78 //for ( int i = carray_count( messages ); i > 0; i-- ) {
74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); 79 for (unsigned int i = 0; i < carray_count(messages);++i) {
75 80 mailpop3_msg_info *info;
81 int r = mailpop3_get_msg_info(m_pop3,i+1,&info);
76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 82 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
77 if ( err != MAILPOP3_NO_ERROR ) { 83 if ( err != MAILPOP3_NO_ERROR ) {
78 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); 84 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
85 free(header);
79 logout(); 86 logout();
80 return; 87 return;
81 } 88 }
82 RecMail *mail = parseHeader( header ); 89 RecMail *mail = parseHeader( header );
83 mail->setNumber( info->msg_index ); 90 mail->setNumber( info->msg_index );
84 mail->setWrapper(this); 91 mail->setWrapper(this);
85 target.append( mail ); 92 target.append( mail );
93 free(header);
86 } 94 }
87
88 logout(); 95 logout();
89} 96}
90 97
91RecMail *POP3wrapper::parseHeader( const char *header ) 98RecMail *POP3wrapper::parseHeader( const char *header )
92{ 99{
93 int err = MAILIMF_NO_ERROR; 100 int err = MAILIMF_NO_ERROR;
94 size_t curTok; 101 size_t curTok = 0;
95 RecMail *mail = new RecMail(); 102 RecMail *mail = new RecMail();
96 mailimf_fields *fields; 103 mailimf_fields *fields;
97 104 mailimf_references * refs;
105 mailimf_keywords*keys;
106
98 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 107 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
99 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 ) {
100 mailimf_field *field = (mailimf_field *) current->data; 109 mailimf_field *field = (mailimf_field *) current->data;
101 switch ( field->fld_type ) { 110 switch ( field->fld_type ) {
102 case MAILIMF_FIELD_FROM: 111 case MAILIMF_FIELD_FROM:
103 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 112 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
104 break; 113 break;
105 case MAILIMF_FIELD_TO: 114 case MAILIMF_FIELD_TO:
106 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 115 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
107 break; 116 break;
108 case MAILIMF_FIELD_CC: 117 case MAILIMF_FIELD_CC:
109 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 118 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
110 break; 119 break;
111 case MAILIMF_FIELD_BCC: 120 case MAILIMF_FIELD_BCC:
112 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 121 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
113 break; 122 break;
114 case MAILIMF_FIELD_SUBJECT: 123 case MAILIMF_FIELD_SUBJECT:
115 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); 124 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) );
116 break; 125 break;
117 case MAILIMF_FIELD_ORIG_DATE: 126 case MAILIMF_FIELD_ORIG_DATE:
118 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 ) );
119 break; 128 break;
129 case MAILIMF_FIELD_MESSAGE_ID:
130 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value));
131 break;
132 case MAILIMF_FIELD_REFERENCES:
133 refs = field->fld_data.fld_references;
134 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
135 char * text = (char*)refs->mid_list->first->data;
136 mail->setReplyto(QString(text));
137 }
138 break;
139 case MAILIMF_FIELD_KEYWORDS:
140 keys = field->fld_data.fld_keywords;
141 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
142 qDebug("Keyword: %s",(char*)cur->data);
143 }
144 break;
120 default: 145 default:
121 break; 146 break;
122 } 147 }
123 } 148 }
124 149 if (fields) mailimf_fields_free(fields);
125 return mail; 150 return mail;
126} 151}
127 152
128QString POP3wrapper::parseDateTime( mailimf_date_time *date ) 153QString POP3wrapper::parseDateTime( mailimf_date_time *date )
129{ 154{
130 char tmp[23]; 155 char tmp[23];
131 156
132 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 157 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
133 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 158 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
134 159
135 return QString( tmp ); 160 return QString( tmp );
136} 161}
137 162
138QString POP3wrapper::parseAddressList( mailimf_address_list *list ) 163QString POP3wrapper::parseAddressList( mailimf_address_list *list )
139{ 164{
140 QString result( "" ); 165 QString result( "" );
141 166
142 bool first = true; 167 bool first = true;
143 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 168 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
144 mailimf_address *addr = (mailimf_address *) current->data; 169 mailimf_address *addr = (mailimf_address *) current->data;
145 170
146 if ( !first ) { 171 if ( !first ) {
147 result.append( "," ); 172 result.append( "," );
148 } else { 173 } else {
149 first = false; 174 first = false;
150 } 175 }
151 176
152 switch ( addr->ad_type ) { 177 switch ( addr->ad_type ) {
153 case MAILIMF_ADDRESS_MAILBOX: 178 case MAILIMF_ADDRESS_MAILBOX:
154 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 179 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
155 break; 180 break;
156 case MAILIMF_ADDRESS_GROUP: 181 case MAILIMF_ADDRESS_GROUP:
157 result.append( parseGroup( addr->ad_data.ad_group ) ); 182 result.append( parseGroup( addr->ad_data.ad_group ) );
158 break; 183 break;
159 default: 184 default:
160 qDebug( "POP3: unkown mailimf address type" ); 185 qDebug( "POP3: unkown mailimf address type" );
161 break; 186 break;
162 } 187 }
163 } 188 }
164 189
165 return result; 190 return result;
166} 191}
167 192
168QString POP3wrapper::parseGroup( mailimf_group *group ) 193QString POP3wrapper::parseGroup( mailimf_group *group )
169{ 194{
170 QString result( "" ); 195 QString result( "" );
171 196
172 result.append( group->grp_display_name ); 197 result.append( group->grp_display_name );
173 result.append( ": " ); 198 result.append( ": " );
174 199
175 if ( group->grp_mb_list != NULL ) { 200 if ( group->grp_mb_list != NULL ) {
176 result.append( parseMailboxList( group->grp_mb_list ) ); 201 result.append( parseMailboxList( group->grp_mb_list ) );
177 } 202 }
178 203
179 result.append( ";" ); 204 result.append( ";" );
180 205
181 return result; 206 return result;
182} 207}
183 208
184QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) 209QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
185{ 210{
186 QString result( "" ); 211 QString result( "" );
187 212
188 if ( box->mb_display_name == NULL ) { 213 if ( box->mb_display_name == NULL ) {
189 result.append( box->mb_addr_spec ); 214 result.append( box->mb_addr_spec );
190 } else { 215 } else {
191 result.append( box->mb_display_name ); 216 result.append( box->mb_display_name );
192 result.append( " <" ); 217 result.append( " <" );
193 result.append( box->mb_addr_spec ); 218 result.append( box->mb_addr_spec );
194 result.append( ">" ); 219 result.append( ">" );
195 } 220 }
196 221
197 return result; 222 return result;
198} 223}
199 224
200QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) 225QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
201{ 226{
202 QString result( "" ); 227 QString result( "" );
203 228
204 bool first = true; 229 bool first = true;
205 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 230 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
206 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 231 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
207 232
208 if ( !first ) { 233 if ( !first ) {
209 result.append( "," ); 234 result.append( "," );
210 } else { 235 } else {
211 first = false; 236 first = false;
212 } 237 }
213 238
214 result.append( parseMailbox( box ) ); 239 result.append( parseMailbox( box ) );
215 } 240 }
216 241
217 return result; 242 return result;
218} 243}
219 244
220void POP3wrapper::login() 245void POP3wrapper::login()
221{ 246{
222 if ( m_pop3 != NULL ) logout(); 247 if ( m_pop3 != NULL ) logout();
223 248
224 const char *server, *user, *pass; 249 const char *server, *user, *pass;
225 uint16_t port; 250 uint16_t port;
226 int err = MAILPOP3_NO_ERROR; 251 int err = MAILPOP3_NO_ERROR;
227 252
228 server = account->getServer().latin1(); 253 server = account->getServer().latin1();
229 port = account->getPort().toUInt(); 254 port = account->getPort().toUInt();
230 user = account->getUser().latin1(); 255 user = account->getUser().latin1();
231 pass = account->getPassword().latin1(); 256 pass = account->getPassword().latin1();
232 257
233 m_pop3 = mailpop3_new( 200, &pop3_progress ); 258 m_pop3 = mailpop3_new( 200, &pop3_progress );
234 259
235 // connect 260 // connect
236 if (account->getSSL()) { 261 if (account->getSSL()) {
237 err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); 262 err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
238 } else { 263 } else {
239 err = mailpop3_socket_connect( m_pop3, (char*)server, port ); 264 err = mailpop3_socket_connect( m_pop3, (char*)server, port );
240 } 265 }
241 266
242 if ( err != MAILPOP3_NO_ERROR ) { 267 if ( err != MAILPOP3_NO_ERROR ) {
243 qDebug( "pop3: error connecting to %s\n reason: %s", server, 268 qDebug( "pop3: error connecting to %s\n reason: %s", server,
244 m_pop3->pop3_response ); 269 m_pop3->pop3_response );
245 mailpop3_free( m_pop3 ); 270 mailpop3_free( m_pop3 );
246 m_pop3 = NULL; 271 m_pop3 = NULL;
247 return; 272 return;
248 } 273 }
249 qDebug( "POP3: connected!" ); 274 qDebug( "POP3: connected!" );
250 275
251 // login 276 // login
252 // TODO: decide if apop or plain login should be used 277 // TODO: decide if apop or plain login should be used
253 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 278 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
254 if ( err != MAILPOP3_NO_ERROR ) { 279 if ( err != MAILPOP3_NO_ERROR ) {
255 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); 280 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response );
256 logout(); 281 logout();
257 return; 282 return;
258 } 283 }
259 284
260 qDebug( "POP3: logged in!" ); 285 qDebug( "POP3: logged in!" );
261} 286}
262 287
263void POP3wrapper::logout() 288void POP3wrapper::logout()
264{ 289{
265 int err = MAILPOP3_NO_ERROR; 290 int err = MAILPOP3_NO_ERROR;
266 if ( m_pop3 == NULL ) return; 291 if ( m_pop3 == NULL ) return;
267 err = mailpop3_quit( m_pop3 ); 292 err = mailpop3_quit( m_pop3 );
268 mailpop3_free( m_pop3 ); 293 mailpop3_free( m_pop3 );
269 m_pop3 = NULL; 294 m_pop3 = NULL;
270} 295}
271 296
272 297
273QList<Folder>* POP3wrapper::listFolders() 298QList<Folder>* POP3wrapper::listFolders()
274{ 299{
275 QList<Folder> * folders = new QList<Folder>(); 300 QList<Folder> * folders = new QList<Folder>();
276 folders->setAutoDelete( false ); 301 folders->setAutoDelete( false );
277 Folder*inb=new Folder("INBOX"); 302 Folder*inb=new Folder("INBOX");
278 folders->append(inb); 303 folders->append(inb);
279 return folders; 304 return folders;
280} 305}
281 306
282QString POP3wrapper::fetchPart(const RecMail&,const RecPart&) 307QString POP3wrapper::fetchPart(const RecMail&,const RecPart&)
283{ 308{
284 return ""; 309 return "";
285} 310}
286 311
287void POP3wrapper::deleteMail(const RecMail&) 312void POP3wrapper::deleteMail(const RecMail&)
288{ 313{
289} 314}
290 315
291void POP3wrapper::answeredMail(const RecMail&) 316void POP3wrapper::answeredMail(const RecMail&)
292{ 317{
293} 318}