summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-09 16:59:57 (UTC)
committer alwin <alwin>2003-12-09 16:59:57 (UTC)
commit1999708f1480dbdd19e73671fbd9e422883839b6 (patch) (unidiff)
tree633887e98f12d63455faa5065c0f6a3cc0fb290d
parentc6b105a7bf2bfffa847fd84c422ae9a3850c682f (diff)
downloadopie-1999708f1480dbdd19e73671fbd9e422883839b6.zip
opie-1999708f1480dbdd19e73671fbd9e422883839b6.tar.gz
opie-1999708f1480dbdd19e73671fbd9e422883839b6.tar.bz2
some interface changes
split class defines into more files
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/accountview.cpp18
-rw-r--r--noncore/net/mail/accountview.h19
-rw-r--r--noncore/net/mail/imapwrapper.cpp12
-rw-r--r--noncore/net/mail/imapwrapper.h7
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp12
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h7
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.cpp129
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.h98
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.cpp12
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.h54
-rw-r--r--noncore/net/mail/mail.pro7
-rw-r--r--noncore/net/mail/mailistviewitem.h21
-rw-r--r--noncore/net/mail/mailtypes.cpp129
-rw-r--r--noncore/net/mail/mailtypes.h98
-rw-r--r--noncore/net/mail/mailwrapper.cpp12
-rw-r--r--noncore/net/mail/mailwrapper.h54
-rw-r--r--noncore/net/mail/mainwindow.cpp34
-rw-r--r--noncore/net/mail/mainwindow.h19
18 files changed, 551 insertions, 191 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp
index 1bde886..df9fc11 100644
--- a/noncore/net/mail/accountview.cpp
+++ b/noncore/net/mail/accountview.cpp
@@ -1,111 +1,115 @@
1#include "accountview.h" 1#include "accountview.h"
2#include "imapwrapper.h" 2#include "imapwrapper.h"
3#include "mailtypes.h"
3#include "defines.h" 4#include "defines.h"
4 5
5IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent ) 6IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent )
6 : AccountViewItem( parent ) 7 : AccountViewItem( parent )
7{ 8{
8 account = a; 9 account = a;
9 wrapper = new IMAPwrapper( account ); 10 wrapper = new IMAPwrapper( account );
10 setPixmap( 0, PIXMAP_IMAPFOLDER ); 11 setPixmap( 0, PIXMAP_IMAPFOLDER );
11 setText( 0, account->getAccountName() ); 12 setText( 0, account->getAccountName() );
12 setOpen( true ); 13 setOpen( true );
13} 14}
14 15
15IMAPviewItem::~IMAPviewItem() 16IMAPviewItem::~IMAPviewItem()
16{ 17{
17 delete wrapper; 18 delete wrapper;
18} 19}
19 20
20IMAPwrapper *IMAPviewItem::getWrapper() 21IMAPwrapper *IMAPviewItem::getWrapper()
21{ 22{
22 return wrapper; 23 return wrapper;
23} 24}
24 25
25void IMAPviewItem::refresh(Maillist&) 26void IMAPviewItem::refresh(QList<RecMail>&)
26{ 27{
27 QList<IMAPFolder> *folders = wrapper->listFolders(); 28 QList<IMAPFolder> *folders = wrapper->listFolders();
28 29
29 QListViewItem *child = firstChild(); 30 QListViewItem *child = firstChild();
30 while ( child ) { 31 while ( child ) {
31 QListViewItem *tmp = child; 32 QListViewItem *tmp = child;
32 child = child->nextSibling(); 33 child = child->nextSibling();
33 delete tmp; 34 delete tmp;
34 } 35 }
35 36
36 IMAPFolder *it; 37 IMAPFolder *it;
37 for ( it = folders->first(); it; it = folders->next() ) { 38 for ( it = folders->first(); it; it = folders->next() ) {
38 (void) new IMAPfolderItem( it, this ); 39 (void) new IMAPfolderItem( it, this );
39 } 40 }
40} 41}
41 42
43RecBody IMAPviewItem::fetchBody(const RecMail&)
44{
45 return RecBody();
46}
42 47
43IMAPfolderItem::~IMAPfolderItem() 48IMAPfolderItem::~IMAPfolderItem()
44{ 49{
45 delete folder; 50 delete folder;
46} 51}
47 52
48IMAPfolderItem::IMAPfolderItem( IMAPFolder *folderInit, IMAPviewItem *parent ) 53IMAPfolderItem::IMAPfolderItem( IMAPFolder *folderInit, IMAPviewItem *parent )
49 : AccountViewItem( parent ) 54 : AccountViewItem( parent )
50{ 55{
51 folder = folderInit; 56 folder = folderInit;
52 imap = parent; 57 imap = parent;
53 setPixmap( 0, PIXMAP_IMAPFOLDER ); 58 setPixmap( 0, PIXMAP_IMAPFOLDER );
54 setText( 0, folder->getDisplayName() ); 59 setText( 0, folder->getDisplayName() );
55} 60}
56 61
57void IMAPfolderItem::refresh(Maillist&target) 62void IMAPfolderItem::refresh(QList<RecMail>&target)
58{ 63{
59 imap->getWrapper()->listMessages( folder->getName(),target ); 64 imap->getWrapper()->listMessages( folder->getName(),target );
60} 65}
61 66
62QString IMAPfolderItem::fetchBody(const RecMail&aMail) 67RecBody IMAPfolderItem::fetchBody(const RecMail&aMail)
63{ 68{
64 return imap->getWrapper()->fetchBody(aMail); 69 return imap->getWrapper()->fetchBody(aMail);
65} 70}
66 71
67AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) 72AccountView::AccountView( QWidget *parent, const char *name, WFlags flags )
68 : QListView( parent, name, flags ) 73 : QListView( parent, name, flags )
69{ 74{
70 connect( this, SIGNAL( clicked( QListViewItem * ) ), 75 connect( this, SIGNAL( clicked( QListViewItem * ) ),
71 SLOT( refresh( QListViewItem * ) ) ); 76 SLOT( refresh( QListViewItem * ) ) );
72} 77}
73 78
74void AccountView::populate( QList<Account> list ) 79void AccountView::populate( QList<Account> list )
75{ 80{
76 clear(); 81 clear();
77 82
78 Account *it; 83 Account *it;
79 for ( it = list.first(); it; it = list.next() ) { 84 for ( it = list.first(); it; it = list.next() ) {
80 if ( it->getType().compare( "IMAP" ) == 0 ) { 85 if ( it->getType().compare( "IMAP" ) == 0 ) {
81 IMAPaccount *imap = static_cast<IMAPaccount *>(it); 86 IMAPaccount *imap = static_cast<IMAPaccount *>(it);
82 qDebug( "added IMAP " + imap->getAccountName() ); 87 qDebug( "added IMAP " + imap->getAccountName() );
83 (void) new IMAPviewItem( imap, this ); 88 (void) new IMAPviewItem( imap, this );
84 } 89 }
85 } 90 }
86} 91}
87 92
88void AccountView::refresh(QListViewItem *item) { 93void AccountView::refresh(QListViewItem *item) {
89 qDebug("AccountView refresh..."); 94 qDebug("AccountView refresh...");
90 if ( item ) { 95 if ( item ) {
91 Maillist headerlist; 96 QList<RecMail> headerlist;
92 headerlist.setAutoDelete(true); 97 headerlist.setAutoDelete(true);
93 AccountViewItem *view = static_cast<AccountViewItem *>(item); 98 AccountViewItem *view = static_cast<AccountViewItem *>(item);
94 view->refresh(headerlist); 99 view->refresh(headerlist);
95 emit refreshMailview(&headerlist); 100 emit refreshMailview(&headerlist);
96 } 101 }
97} 102}
98 103
99void AccountView::refreshAll() 104void AccountView::refreshAll()
100{ 105{
101 106
102} 107}
103 108
104QString AccountView::fetchBody(const RecMail&aMail) 109RecBody AccountView::fetchBody(const RecMail&aMail)
105{ 110{
106 QString Body;
107 QListViewItem*item = selectedItem (); 111 QListViewItem*item = selectedItem ();
108 if (!item) return Body; 112 if (!item) return RecBody();
109 AccountViewItem *view = static_cast<AccountViewItem *>(item); 113 AccountViewItem *view = static_cast<AccountViewItem *>(item);
110 return view->fetchBody(aMail); 114 return view->fetchBody(aMail);
111} 115}
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h
index 2bc8023..805c2b3 100644
--- a/noncore/net/mail/accountview.h
+++ b/noncore/net/mail/accountview.h
@@ -1,69 +1,72 @@
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 6
6#include "settings.h" 7#include "settings.h"
7#include "mailwrapper.h" 8#include "mailwrapper.h"
8 9
9class IMAPwrapper; 10class IMAPwrapper;
11class RecMail;
12class RecBody;
10 13
11class AccountViewItem : public QListViewItem 14class AccountViewItem : public QListViewItem
12{ 15{
13 16
14public: 17public:
15 AccountViewItem( QListView *parent ) : QListViewItem( parent ) {} 18 AccountViewItem( QListView *parent ) : QListViewItem( parent ) {}
16 AccountViewItem( QListViewItem *parent ) : QListViewItem( parent ) {} 19 AccountViewItem( QListViewItem *parent ) : QListViewItem( parent ) {}
17 virtual void refresh(Maillist&)=0; 20 virtual void refresh(QList<RecMail>&)=0;
18 virtual QString fetchBody(const RecMail&)=0; 21 virtual RecBody fetchBody(const RecMail&)=0;
19}; 22};
20 23
21class IMAPviewItem : public AccountViewItem 24class IMAPviewItem : public AccountViewItem
22{ 25{
23 26
24public: 27public:
25 IMAPviewItem( IMAPaccount *a, QListView *parent ); 28 IMAPviewItem( IMAPaccount *a, QListView *parent );
26 ~IMAPviewItem(); 29 ~IMAPviewItem();
27 virtual void refresh(Maillist&); 30 virtual void refresh(QList<RecMail>&);
28 virtual QString fetchBody(const RecMail&){return "";} 31 virtual RecBody fetchBody(const RecMail&);
29 IMAPwrapper *getWrapper(); 32 IMAPwrapper *getWrapper();
30 33
31private: 34private:
32 IMAPaccount *account; 35 IMAPaccount *account;
33 IMAPwrapper *wrapper; 36 IMAPwrapper *wrapper;
34 37
35}; 38};
36 39
37class IMAPfolderItem : public AccountViewItem 40class IMAPfolderItem : public AccountViewItem
38{ 41{
39 42
40public: 43public:
41 IMAPfolderItem( IMAPFolder *folder, IMAPviewItem *parent ); 44 IMAPfolderItem( IMAPFolder *folder, IMAPviewItem *parent );
42 ~IMAPfolderItem(); 45 ~IMAPfolderItem();
43 virtual void refresh(Maillist&); 46 virtual void refresh(QList<RecMail>&);
44 virtual QString fetchBody(const RecMail&); 47 virtual RecBody fetchBody(const RecMail&);
45 48
46private: 49private:
47 IMAPFolder *folder; 50 IMAPFolder *folder;
48 IMAPviewItem *imap; 51 IMAPviewItem *imap;
49 52
50}; 53};
51 54
52class AccountView : public QListView 55class AccountView : public QListView
53{ 56{
54 Q_OBJECT 57 Q_OBJECT
55 58
56public: 59public:
57 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 60 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
58 void populate( QList<Account> list ); 61 void populate( QList<Account> list );
59 QString fetchBody(const RecMail&aMail); 62 RecBody fetchBody(const RecMail&aMail);
60 63
61public slots: 64public slots:
62 void refreshAll(); 65 void refreshAll();
63 void refresh(QListViewItem *item); 66 void refresh(QListViewItem *item);
64 67
65signals: 68signals:
66 void refreshMailview(Maillist*); 69 void refreshMailview(QList<RecMail>*);
67}; 70};
68 71
69#endif 72#endif
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index 1acc036..725dcc9 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -1,195 +1,196 @@
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 <libetpan/mailimap.h> 6#include <libetpan/mailimap.h>
6 7
7IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 8IMAPwrapper::IMAPwrapper( IMAPaccount *a )
8{ 9{
9 account = a; 10 account = a;
10 m_imap = 0; 11 m_imap = 0;
11} 12}
12 13
13IMAPwrapper::~IMAPwrapper() 14IMAPwrapper::~IMAPwrapper()
14{ 15{
15 logout(); 16 logout();
16} 17}
17 18
18void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 19void IMAPwrapper::imap_progress( size_t current, size_t maximum )
19{ 20{
20 qDebug( "IMAP: %i of %i", current, maximum ); 21 qDebug( "IMAP: %i of %i", current, maximum );
21} 22}
22 23
23void IMAPwrapper::login() 24void IMAPwrapper::login()
24{ 25{
25 logout(); 26 logout();
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 server = account->getServer().latin1(); 31 server = account->getServer().latin1();
31 port = account->getPort().toUInt(); 32 port = account->getPort().toUInt();
32 user = account->getUser().latin1(); 33 user = account->getUser().latin1();
33 pass = account->getPassword().latin1(); 34 pass = account->getPassword().latin1();
34 35
35 m_imap = mailimap_new( 20, &imap_progress ); 36 m_imap = mailimap_new( 20, &imap_progress );
36 /* connect */ 37 /* connect */
37 err = mailimap_socket_connect( m_imap, (char*)server, port ); 38 err = mailimap_socket_connect( m_imap, (char*)server, port );
38 if ( err != MAILIMAP_NO_ERROR && 39 if ( err != MAILIMAP_NO_ERROR &&
39 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 40 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
40 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 41 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
41 qDebug("error connecting server: %s",m_imap->response); 42 qDebug("error connecting server: %s",m_imap->response);
42 mailimap_free( m_imap ); 43 mailimap_free( m_imap );
43 m_imap = 0; 44 m_imap = 0;
44 return; 45 return;
45 } 46 }
46 47
47 /* login */ 48 /* login */
48 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 49 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
49 if ( err != MAILIMAP_NO_ERROR ) { 50 if ( err != MAILIMAP_NO_ERROR ) {
50 qDebug("error logging in imap: %s",m_imap->response); 51 qDebug("error logging in imap: %s",m_imap->response);
51 err = mailimap_close( m_imap ); 52 err = mailimap_close( m_imap );
52 mailimap_free( m_imap ); 53 mailimap_free( m_imap );
53 m_imap = 0; 54 m_imap = 0;
54 } 55 }
55} 56}
56 57
57void IMAPwrapper::logout() 58void IMAPwrapper::logout()
58{ 59{
59 int err = MAILIMAP_NO_ERROR; 60 int err = MAILIMAP_NO_ERROR;
60 if (!m_imap) return; 61 if (!m_imap) return;
61 err = mailimap_logout( m_imap ); 62 err = mailimap_logout( m_imap );
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
67void IMAPwrapper::listMessages(const QString&mailbox,Maillist&target ) 68void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
68{ 69{
69 const char *mb; 70 const char *mb;
70 int err = MAILIMAP_NO_ERROR; 71 int err = MAILIMAP_NO_ERROR;
71 clist *result; 72 clist *result;
72 clistcell *current; 73 clistcell *current;
73 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; 74 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate;
74 mailimap_fetch_type *fetchType; 75 mailimap_fetch_type *fetchType;
75 mailimap_set *set; 76 mailimap_set *set;
76 77
77 mb = mailbox.latin1(); 78 mb = mailbox.latin1();
78 login(); 79 login();
79 if (!m_imap) { 80 if (!m_imap) {
80 return; 81 return;
81 } 82 }
82 /* select mailbox READONLY for operations */ 83 /* select mailbox READONLY for operations */
83 err = mailimap_examine( m_imap, (char*)mb); 84 err = mailimap_examine( m_imap, (char*)mb);
84 if ( err != MAILIMAP_NO_ERROR ) { 85 if ( err != MAILIMAP_NO_ERROR ) {
85 qDebug("error selecting mailbox: %s",m_imap->response); 86 qDebug("error selecting mailbox: %s",m_imap->response);
86 logout(); 87 logout();
87 return; 88 return;
88 } 89 }
89 90
90 int last = m_imap->selection_info->exists; 91 int last = m_imap->selection_info->exists;
91 92
92 if (last == 0) { 93 if (last == 0) {
93 qDebug("mailbox has no mails"); 94 qDebug("mailbox has no mails");
94 logout(); 95 logout();
95 return; 96 return;
96 } 97 }
97 98
98 result = clist_new(); 99 result = clist_new();
99 /* the range has to start at 1!!! not with 0!!!! */ 100 /* the range has to start at 1!!! not with 0!!!! */
100 set = mailimap_set_new_interval( 1, last ); 101 set = mailimap_set_new_interval( 1, last );
101 fetchAtt = mailimap_fetch_att_new_envelope(); 102 fetchAtt = mailimap_fetch_att_new_envelope();
102 fetchAttFlags = mailimap_fetch_att_new_flags(); 103 fetchAttFlags = mailimap_fetch_att_new_flags();
103 fetchAttDate = mailimap_fetch_att_new_internaldate(); 104 fetchAttDate = mailimap_fetch_att_new_internaldate();
104 105
105 //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 106 //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
106 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 107 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
107 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); 108 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt);
108 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); 109 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags);
109 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); 110 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate);
110 111
111 err = mailimap_fetch( m_imap, set, fetchType, &result ); 112 err = mailimap_fetch( m_imap, set, fetchType, &result );
112 mailimap_set_free( set ); 113 mailimap_set_free( set );
113 /* cleans up the fetch_att's too! */ 114 /* cleans up the fetch_att's too! */
114 mailimap_fetch_type_free( fetchType ); 115 mailimap_fetch_type_free( fetchType );
115 116
116 QString date,subject,from; 117 QString date,subject,from;
117 118
118 if ( err == MAILIMAP_NO_ERROR ) { 119 if ( err == MAILIMAP_NO_ERROR ) {
119 current = clist_begin(result); 120 current = clist_begin(result);
120 mailimap_msg_att * msg_att; 121 mailimap_msg_att * msg_att;
121 int i = 0; 122 int i = 0;
122 while ( current != 0 ) { 123 while ( current != 0 ) {
123 ++i; 124 ++i;
124 msg_att = (mailimap_msg_att*)current->data; 125 msg_att = (mailimap_msg_att*)current->data;
125 RecMail*m = parse_list_result(msg_att); 126 RecMail*m = parse_list_result(msg_att);
126 if (m) { 127 if (m) {
127 m->setNumber(i); 128 m->setNumber(i);
128 m->setMbox(mailbox); 129 m->setMbox(mailbox);
129 target.append(m); 130 target.append(m);
130 } 131 }
131 current = current->next; 132 current = current->next;
132 } 133 }
133 } else { 134 } else {
134 qDebug("Error fetching headers: %s",m_imap->response); 135 qDebug("Error fetching headers: %s",m_imap->response);
135 } 136 }
136 logout(); 137 logout();
137 clist_free(result); 138 clist_free(result);
138} 139}
139 140
140QList<IMAPFolder>* IMAPwrapper::listFolders() 141QList<IMAPFolder>* IMAPwrapper::listFolders()
141{ 142{
142 const char *path, *mask; 143 const char *path, *mask;
143 int err = MAILIMAP_NO_ERROR; 144 int err = MAILIMAP_NO_ERROR;
144 clist *result; 145 clist *result;
145 clistcell *current; 146 clistcell *current;
146 147
147 QList<IMAPFolder> * folders = new QList<IMAPFolder>(); 148 QList<IMAPFolder> * folders = new QList<IMAPFolder>();
148 folders->setAutoDelete( true ); 149 folders->setAutoDelete( true );
149 login(); 150 login();
150 if (!m_imap) { 151 if (!m_imap) {
151 return folders; 152 return folders;
152 } 153 }
153 154
154/* 155/*
155 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 156 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
156 * We must not forget to filter them out in next loop! 157 * We must not forget to filter them out in next loop!
157 * it seems like ugly code. and yes - it is ugly code. but the best way. 158 * it seems like ugly code. and yes - it is ugly code. but the best way.
158 */ 159 */
159 QString temp; 160 QString temp;
160 mask = "INBOX" ; 161 mask = "INBOX" ;
161 result = clist_new(); 162 result = clist_new();
162 mailimap_mailbox_list *list; 163 mailimap_mailbox_list *list;
163 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 164 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
164 if ( err == MAILIMAP_NO_ERROR ) { 165 if ( err == MAILIMAP_NO_ERROR ) {
165 current = result->first; 166 current = result->first;
166 for ( int i = result->count; i > 0; i-- ) { 167 for ( int i = result->count; i > 0; i-- ) {
167 list = (mailimap_mailbox_list *) current->data; 168 list = (mailimap_mailbox_list *) current->data;
168 // it is better use the deep copy mechanism of qt itself 169 // it is better use the deep copy mechanism of qt itself
169 // instead of using strdup! 170 // instead of using strdup!
170 temp = list->mb; 171 temp = list->mb;
171 folders->append( new IMAPFolder(temp)); 172 folders->append( new IMAPFolder(temp));
172 current = current->next; 173 current = current->next;
173 } 174 }
174 } else { 175 } else {
175 qDebug("error fetching folders: %s",m_imap->response); 176 qDebug("error fetching folders: %s",m_imap->response);
176 } 177 }
177 mailimap_list_result_free( result ); 178 mailimap_list_result_free( result );
178 179
179/* 180/*
180 * second stage - get the other then inbox folders 181 * second stage - get the other then inbox folders
181 */ 182 */
182 mask = "*" ; 183 mask = "*" ;
183 path = account->getPrefix().latin1(); 184 path = account->getPrefix().latin1();
184 result = clist_new(); 185 result = clist_new();
185 qDebug(path); 186 qDebug(path);
186 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 187 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
187 if ( err == MAILIMAP_NO_ERROR ) { 188 if ( err == MAILIMAP_NO_ERROR ) {
188 current = result->first; 189 current = result->first;
189 for ( int i = result->count; i > 0; i-- ) { 190 for ( int i = result->count; i > 0; i-- ) {
190 list = (mailimap_mailbox_list *) current->data; 191 list = (mailimap_mailbox_list *) current->data;
191 // it is better use the deep copy mechanism of qt itself 192 // it is better use the deep copy mechanism of qt itself
192 // instead of using strdup! 193 // instead of using strdup!
193 temp = list->mb; 194 temp = list->mb;
194 current = current->next; 195 current = current->next;
195 if (temp.lower()=="inbox") 196 if (temp.lower()=="inbox")
@@ -204,287 +205,290 @@ QList<IMAPFolder>* IMAPwrapper::listFolders()
204 return folders; 205 return folders;
205} 206}
206 207
207RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 208RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
208{ 209{
209 RecMail * m = 0; 210 RecMail * m = 0;
210 mailimap_msg_att_item *item=0; 211 mailimap_msg_att_item *item=0;
211 bool named_from = false; 212 bool named_from = false;
212 QString from,date,subject; 213 QString from,date,subject;
213 date = from = subject = ""; 214 date = from = subject = "";
214 clistcell *current,*c,*cf, *current_from = NULL; 215 clistcell *current,*c,*cf, *current_from = NULL;
215 mailimap_address * current_address = NULL; 216 mailimap_address * current_address = NULL;
216 mailimap_msg_att_dynamic*flist; 217 mailimap_msg_att_dynamic*flist;
217 mailimap_flag_fetch*cflag; 218 mailimap_flag_fetch*cflag;
218 QBitArray mFlags(7); 219 QBitArray mFlags(7);
219 220
220 if (!m_att) { 221 if (!m_att) {
221 return m; 222 return m;
222 } 223 }
223 224
224#if 0 225#if 0
225 MAILIMAP_FLAG_KEYWORD, /* keyword flag */ 226 MAILIMAP_FLAG_KEYWORD, /* keyword flag */
226 MAILIMAP_FLAG_EXTENSION, /* \extension flag */ 227 MAILIMAP_FLAG_EXTENSION, /* \extension flag */
227#endif 228#endif
228 c = clist_begin(m_att->list); 229 c = clist_begin(m_att->list);
229 while ( c ) { 230 while ( c ) {
230 current = c; 231 current = c;
231 c = c->next; 232 c = c->next;
232 item = (mailimap_msg_att_item*)current->data; 233 item = (mailimap_msg_att_item*)current->data;
233 if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 234 if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
234 flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; 235 flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn;
235 if (!flist->list) { 236 if (!flist->list) {
236 continue; 237 continue;
237 } 238 }
238 cf = flist->list->first; 239 cf = flist->list->first;
239 while (cf) { 240 while (cf) {
240 cflag = (mailimap_flag_fetch*)cf->data; 241 cflag = (mailimap_flag_fetch*)cf->data;
241 if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { 242 if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) {
242 switch (cflag->flag->type) { 243 switch (cflag->flag->type) {
243 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 244 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
244 mFlags.setBit(FLAG_ANSWERED); 245 mFlags.setBit(FLAG_ANSWERED);
245 break; 246 break;
246 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 247 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
247 mFlags.setBit(FLAG_FLAGGED); 248 mFlags.setBit(FLAG_FLAGGED);
248 break; 249 break;
249 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 250 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
250 mFlags.setBit(FLAG_DELETED); 251 mFlags.setBit(FLAG_DELETED);
251 break; 252 break;
252 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 253 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
253 mFlags.setBit(FLAG_SEEN); 254 mFlags.setBit(FLAG_SEEN);
254 break; 255 break;
255 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 256 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
256 mFlags.setBit(FLAG_DRAFT); 257 mFlags.setBit(FLAG_DRAFT);
257 break; 258 break;
258 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 259 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
259 break; 260 break;
260 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 261 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
261 break; 262 break;
262 default: 263 default:
263 break; 264 break;
264 } 265 }
265 } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { 266 } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) {
266 mFlags.setBit(FLAG_RECENT); 267 mFlags.setBit(FLAG_RECENT);
267 } 268 }
268 cf = cf->next; 269 cf = cf->next;
269 } 270 }
270 continue; 271 continue;
271 } 272 }
272 if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { 273 if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) {
273 qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); 274 qDebug( "header: \n%s", item->msg_att_static->rfc822_header );
274 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { 275 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) {
275 mailimap_envelope * head = item->msg_att_static->env; 276 mailimap_envelope * head = item->msg_att_static->env;
276 date = head->date; 277 date = head->date;
277 subject = head->subject; 278 subject = head->subject;
278 if (head->from!=NULL) 279 if (head->from!=NULL)
279 current_from = head->from->list->first; 280 current_from = head->from->list->first;
280 while (current_from != NULL) { 281 while (current_from != NULL) {
281 from = ""; 282 from = "";
282 named_from = false; 283 named_from = false;
283 current_address=(mailimap_address*)current_from->data; 284 current_address=(mailimap_address*)current_from->data;
284 current_from = current_from->next; 285 current_from = current_from->next;
285 if (current_address->personal_name){ 286 if (current_address->personal_name){
286 from+=QString(current_address->personal_name); 287 from+=QString(current_address->personal_name);
287 from+=" "; 288 from+=" ";
288 named_from = true; 289 named_from = true;
289 } 290 }
290 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 291 if (named_from && (current_address->mailbox_name || current_address->host_name)) {
291 from+="<"; 292 from+="<";
292 } 293 }
293 if (current_address->mailbox_name) { 294 if (current_address->mailbox_name) {
294 from+=QString(current_address->mailbox_name); 295 from+=QString(current_address->mailbox_name);
295 from+="@"; 296 from+="@";
296 } 297 }
297 if (current_address->host_name) { 298 if (current_address->host_name) {
298 from+=QString(current_address->host_name); 299 from+=QString(current_address->host_name);
299 } 300 }
300 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 301 if (named_from && (current_address->mailbox_name || current_address->host_name)) {
301 from+=">"; 302 from+=">";
302 } 303 }
303 } 304 }
304 qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s", 305 qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s",
305 from.latin1(), 306 from.latin1(),
306 subject.latin1(),date.latin1()); 307 subject.latin1(),date.latin1());
307 m = new RecMail(); 308 m = new RecMail();
308 m->setSubject(subject); 309 m->setSubject(subject);
309 m->setFrom(from); 310 m->setFrom(from);
310 m->setDate(date); 311 m->setDate(date);
311 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { 312 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) {
312 mailimap_date_time*d = item->msg_att_static->internal_date; 313 mailimap_date_time*d = item->msg_att_static->internal_date;
313 QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); 314 QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec));
314 qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec); 315 qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec);
315 qDebug(da.toString()); 316 qDebug(da.toString());
316 } else { 317 } else {
317 qDebug("Another type"); 318 qDebug("Another type");
318 } 319 }
319 } 320 }
320 /* msg is already deleted */ 321 /* msg is already deleted */
321 if (mFlags.testBit(FLAG_DELETED) && m) { 322 if (mFlags.testBit(FLAG_DELETED) && m) {
322 delete m; 323 delete m;
323 m = 0; 324 m = 0;
324 } 325 }
325 if (m) { 326 if (m) {
326 m->setFlags(mFlags); 327 m->setFlags(mFlags);
327 } 328 }
328 return m; 329 return m;
329} 330}
330 331
331#if 1 332#if 1
332QString IMAPwrapper::fetchBody(const RecMail&mail) 333RecBody IMAPwrapper::fetchBody(const RecMail&mail)
333{ 334{
334 QString body = ""; 335 RecBody body;
336 QString body_text;
337
335 const char *mb; 338 const char *mb;
336 int err = MAILIMAP_NO_ERROR; 339 int err = MAILIMAP_NO_ERROR;
337 clist *result; 340 clist *result;
338 clistcell *current; 341 clistcell *current;
339 mailimap_fetch_att *fetchAtt; 342 mailimap_fetch_att *fetchAtt;
340 mailimap_fetch_type *fetchType; 343 mailimap_fetch_type *fetchType;
341 mailimap_set *set; 344 mailimap_set *set;
342 345
343 mb = mail.getMbox().latin1(); 346 mb = mail.getMbox().latin1();
344 347
345 login(); 348 login();
346 if (!m_imap) { 349 if (!m_imap) {
347 return body; 350 return body;
348 } 351 }
349 /* select mailbox READONLY for operations */ 352 /* select mailbox READONLY for operations */
350 err = mailimap_examine( m_imap, (char*)mb); 353 err = mailimap_examine( m_imap, (char*)mb);
351 if ( err != MAILIMAP_NO_ERROR ) { 354 if ( err != MAILIMAP_NO_ERROR ) {
352 qDebug("error selecting mailbox: %s",m_imap->response); 355 qDebug("error selecting mailbox: %s",m_imap->response);
353 logout(); 356 logout();
354 return body; 357 return body;
355 } 358 }
356 result = clist_new(); 359 result = clist_new();
357 /* the range has to start at 1!!! not with 0!!!! */ 360 /* the range has to start at 1!!! not with 0!!!! */
358 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 361 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
359 fetchAtt = mailimap_fetch_att_new_rfc822_text(); 362 fetchAtt = mailimap_fetch_att_new_rfc822_text();
360 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 363 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
361 err = mailimap_fetch( m_imap, set, fetchType, &result ); 364 err = mailimap_fetch( m_imap, set, fetchType, &result );
362 mailimap_set_free( set ); 365 mailimap_set_free( set );
363 mailimap_fetch_type_free( fetchType ); 366 mailimap_fetch_type_free( fetchType );
364 367
365 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 368 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
366 mailimap_msg_att * msg_att; 369 mailimap_msg_att * msg_att;
367 msg_att = (mailimap_msg_att*)current->data; 370 msg_att = (mailimap_msg_att*)current->data;
368 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 371 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
369 372
370 if (item->msg_att_static && item->msg_att_static->rfc822_text) { 373 if (item->msg_att_static && item->msg_att_static->rfc822_text) {
371 body = item->msg_att_static->rfc822_text; 374 body_text = item->msg_att_static->rfc822_text;
375 body.setBodytext(body_text);
372 } 376 }
373 } else { 377 } else {
374 qDebug("error fetching text: %s",m_imap->response); 378 qDebug("error fetching text: %s",m_imap->response);
375 } 379 }
376 380
377 clist_free(result); 381 clist_free(result);
378 logout(); 382 logout();
379 return body; 383 return body;
380} 384}
381 385
382#else 386#else
383QString IMAPwrapper::fetchBody(const RecMail&mail) 387QString IMAPwrapper::fetchBody(const RecMail&mail)
384{ 388{
385 QString body = ""; 389 QString body = "";
386 const char *mb; 390 const char *mb;
387 int err = MAILIMAP_NO_ERROR; 391 int err = MAILIMAP_NO_ERROR;
388 clist *result; 392 clist *result;
389 clistcell *current; 393 clistcell *current;
390 mailimap_fetch_att *fetchAtt; 394 mailimap_fetch_att *fetchAtt;
391 mailimap_fetch_type *fetchType; 395 mailimap_fetch_type *fetchType;
392 mailimap_set *set; 396 mailimap_set *set;
393 mailimap_body*body_desc; 397 mailimap_body*body_desc;
394 398
395 mb = mail.getMbox().latin1(); 399 mb = mail.getMbox().latin1();
396 400
397 login(); 401 login();
398 if (!m_imap) { 402 if (!m_imap) {
399 return body; 403 return body;
400 } 404 }
401 /* select mailbox READONLY for operations */ 405 /* select mailbox READONLY for operations */
402 err = mailimap_examine( m_imap, (char*)mb); 406 err = mailimap_examine( m_imap, (char*)mb);
403 if ( err != MAILIMAP_NO_ERROR ) { 407 if ( err != MAILIMAP_NO_ERROR ) {
404 qDebug("error selecting mailbox: %s",m_imap->response); 408 qDebug("error selecting mailbox: %s",m_imap->response);
405 logout(); 409 logout();
406 return body; 410 return body;
407 } 411 }
408 result = clist_new(); 412 result = clist_new();
409 /* the range has to start at 1!!! not with 0!!!! */ 413 /* the range has to start at 1!!! not with 0!!!! */
410 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 414 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
411 fetchAtt = mailimap_fetch_att_new_body(); 415 fetchAtt = mailimap_fetch_att_new_body();
412 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 416 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
413 err = mailimap_fetch( m_imap, set, fetchType, &result ); 417 err = mailimap_fetch( m_imap, set, fetchType, &result );
414 mailimap_set_free( set ); 418 mailimap_set_free( set );
415 mailimap_fetch_type_free( fetchType ); 419 mailimap_fetch_type_free( fetchType );
416 420
417 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 421 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
418 mailimap_msg_att * msg_att; 422 mailimap_msg_att * msg_att;
419 msg_att = (mailimap_msg_att*)current->data; 423 msg_att = (mailimap_msg_att*)current->data;
420 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 424 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
421 body_desc = item->msg_att_static->body; 425 body_desc = item->msg_att_static->body;
422 if (body_desc->type==MAILIMAP_BODY_1PART) { 426 if (body_desc->type==MAILIMAP_BODY_1PART) {
423 body = searchBodyText(mail,body_desc->body_1part); 427 body = searchBodyText(mail,body_desc->body_1part);
424 } else { 428 } else {
425 } 429 }
426 430
427 } else { 431 } else {
428 qDebug("error fetching body: %s",m_imap->response); 432 qDebug("error fetching body: %s",m_imap->response);
429 } 433 }
430 434
431 clist_free(result); 435 clist_free(result);
432 logout(); 436 logout();
433 return body; 437 return body;
434} 438}
435#endif 439#endif
436 440
437QString IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription) 441QString IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription)
438{ 442{
439 QString Body=""; 443 QString Body="";
440 if (!mailDescription) { 444 if (!mailDescription) {
441 return Body; 445 return Body;
442 } 446 }
443 switch (mailDescription->type) { 447 switch (mailDescription->type) {
444 case MAILIMAP_BODY_TYPE_1PART_TEXT: 448 case MAILIMAP_BODY_TYPE_1PART_TEXT:
445 return getPlainBody(mail); 449 return getPlainBody(mail);
446 break; 450 break;
447 default: 451 default:
448 break; 452 break;
449 } 453 }
450 return Body; 454 return Body;
451} 455}
452 456
453QString IMAPwrapper::getPlainBody(const RecMail&mail) 457QString IMAPwrapper::getPlainBody(const RecMail&mail)
454{ 458{
455 QString body = ""; 459 QString body = "";
456 const char *mb; 460 const char *mb;
457 int err = MAILIMAP_NO_ERROR; 461 int err = MAILIMAP_NO_ERROR;
458 clist *result; 462 clist *result;
459 clistcell *current; 463 clistcell *current;
460 mailimap_fetch_att *fetchAtt; 464 mailimap_fetch_att *fetchAtt;
461 mailimap_fetch_type *fetchType; 465 mailimap_fetch_type *fetchType;
462 mailimap_set *set; 466 mailimap_set *set;
463 467
464 mb = mail.getMbox().latin1(); 468 mb = mail.getMbox().latin1();
465 469
466 if (!m_imap) { 470 if (!m_imap) {
467 return body; 471 return body;
468 } 472 }
469 result = clist_new(); 473 result = clist_new();
470 /* the range has to start at 1!!! not with 0!!!! */ 474 /* the range has to start at 1!!! not with 0!!!! */
471 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 475 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
472 fetchAtt = mailimap_fetch_att_new_rfc822_text(); 476 fetchAtt = mailimap_fetch_att_new_rfc822_text();
473 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 477 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
474 err = mailimap_fetch( m_imap, set, fetchType, &result ); 478 err = mailimap_fetch( m_imap, set, fetchType, &result );
475 mailimap_set_free( set ); 479 mailimap_set_free( set );
476 mailimap_fetch_type_free( fetchType ); 480 mailimap_fetch_type_free( fetchType );
477 481
478 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 482 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
479 mailimap_msg_att * msg_att; 483 mailimap_msg_att * msg_att;
480 msg_att = (mailimap_msg_att*)current->data; 484 msg_att = (mailimap_msg_att*)current->data;
481 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 485 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
482 if (item->msg_att_static && item->msg_att_static->rfc822_text) { 486 if (item->msg_att_static && item->msg_att_static->rfc822_text) {
483 body = item->msg_att_static->rfc822_text; 487 body = item->msg_att_static->rfc822_text;
484 } 488 }
485 } else { 489 } else {
486 qDebug("error fetching text: %s",m_imap->response); 490 qDebug("error fetching text: %s",m_imap->response);
487 } 491 }
488 clist_free(result); 492 clist_free(result);
489 return body; 493 return body;
490} 494}
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h
index b02d26d..1423faf 100644
--- a/noncore/net/mail/imapwrapper.h
+++ b/noncore/net/mail/imapwrapper.h
@@ -1,33 +1,36 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h>
4#include "mailwrapper.h" 5#include "mailwrapper.h"
5 6
6struct mailimap; 7struct mailimap;
7struct mailimap_body_type_1part; 8struct mailimap_body_type_1part;
9class RecMail;
10class RecBody;
8 11
9class IMAPwrapper : public QObject 12class IMAPwrapper : public QObject
10{ 13{
11 Q_OBJECT 14 Q_OBJECT
12 15
13public: 16public:
14 IMAPwrapper( IMAPaccount *a ); 17 IMAPwrapper( IMAPaccount *a );
15 virtual ~IMAPwrapper(); 18 virtual ~IMAPwrapper();
16 QList<IMAPFolder>* listFolders(); 19 QList<IMAPFolder>* listFolders();
17 void listMessages(const QString & mailbox,Maillist&target ); 20 void listMessages(const QString & mailbox,QList<RecMail>&target );
18 QString fetchBody(const RecMail&mail); 21 RecBody fetchBody(const RecMail&mail);
19 static void imap_progress( size_t current, size_t maximum ); 22 static void imap_progress( size_t current, size_t maximum );
20 23
21protected: 24protected:
22 RecMail*parse_list_result(mailimap_msg_att*); 25 RecMail*parse_list_result(mailimap_msg_att*);
23 void login(); 26 void login();
24 void logout(); 27 void logout();
25 QString searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription); 28 QString searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription);
26 QString getPlainBody(const RecMail&mail); 29 QString getPlainBody(const RecMail&mail);
27 30
28private: 31private:
29 IMAPaccount *account; 32 IMAPaccount *account;
30 mailimap *m_imap; 33 mailimap *m_imap;
31}; 34};
32 35
33#endif 36#endif
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 1acc036..725dcc9 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,195 +1,196 @@
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 <libetpan/mailimap.h> 6#include <libetpan/mailimap.h>
6 7
7IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 8IMAPwrapper::IMAPwrapper( IMAPaccount *a )
8{ 9{
9 account = a; 10 account = a;
10 m_imap = 0; 11 m_imap = 0;
11} 12}
12 13
13IMAPwrapper::~IMAPwrapper() 14IMAPwrapper::~IMAPwrapper()
14{ 15{
15 logout(); 16 logout();
16} 17}
17 18
18void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 19void IMAPwrapper::imap_progress( size_t current, size_t maximum )
19{ 20{
20 qDebug( "IMAP: %i of %i", current, maximum ); 21 qDebug( "IMAP: %i of %i", current, maximum );
21} 22}
22 23
23void IMAPwrapper::login() 24void IMAPwrapper::login()
24{ 25{
25 logout(); 26 logout();
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 server = account->getServer().latin1(); 31 server = account->getServer().latin1();
31 port = account->getPort().toUInt(); 32 port = account->getPort().toUInt();
32 user = account->getUser().latin1(); 33 user = account->getUser().latin1();
33 pass = account->getPassword().latin1(); 34 pass = account->getPassword().latin1();
34 35
35 m_imap = mailimap_new( 20, &imap_progress ); 36 m_imap = mailimap_new( 20, &imap_progress );
36 /* connect */ 37 /* connect */
37 err = mailimap_socket_connect( m_imap, (char*)server, port ); 38 err = mailimap_socket_connect( m_imap, (char*)server, port );
38 if ( err != MAILIMAP_NO_ERROR && 39 if ( err != MAILIMAP_NO_ERROR &&
39 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 40 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
40 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 41 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
41 qDebug("error connecting server: %s",m_imap->response); 42 qDebug("error connecting server: %s",m_imap->response);
42 mailimap_free( m_imap ); 43 mailimap_free( m_imap );
43 m_imap = 0; 44 m_imap = 0;
44 return; 45 return;
45 } 46 }
46 47
47 /* login */ 48 /* login */
48 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 49 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
49 if ( err != MAILIMAP_NO_ERROR ) { 50 if ( err != MAILIMAP_NO_ERROR ) {
50 qDebug("error logging in imap: %s",m_imap->response); 51 qDebug("error logging in imap: %s",m_imap->response);
51 err = mailimap_close( m_imap ); 52 err = mailimap_close( m_imap );
52 mailimap_free( m_imap ); 53 mailimap_free( m_imap );
53 m_imap = 0; 54 m_imap = 0;
54 } 55 }
55} 56}
56 57
57void IMAPwrapper::logout() 58void IMAPwrapper::logout()
58{ 59{
59 int err = MAILIMAP_NO_ERROR; 60 int err = MAILIMAP_NO_ERROR;
60 if (!m_imap) return; 61 if (!m_imap) return;
61 err = mailimap_logout( m_imap ); 62 err = mailimap_logout( m_imap );
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
67void IMAPwrapper::listMessages(const QString&mailbox,Maillist&target ) 68void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
68{ 69{
69 const char *mb; 70 const char *mb;
70 int err = MAILIMAP_NO_ERROR; 71 int err = MAILIMAP_NO_ERROR;
71 clist *result; 72 clist *result;
72 clistcell *current; 73 clistcell *current;
73 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; 74 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate;
74 mailimap_fetch_type *fetchType; 75 mailimap_fetch_type *fetchType;
75 mailimap_set *set; 76 mailimap_set *set;
76 77
77 mb = mailbox.latin1(); 78 mb = mailbox.latin1();
78 login(); 79 login();
79 if (!m_imap) { 80 if (!m_imap) {
80 return; 81 return;
81 } 82 }
82 /* select mailbox READONLY for operations */ 83 /* select mailbox READONLY for operations */
83 err = mailimap_examine( m_imap, (char*)mb); 84 err = mailimap_examine( m_imap, (char*)mb);
84 if ( err != MAILIMAP_NO_ERROR ) { 85 if ( err != MAILIMAP_NO_ERROR ) {
85 qDebug("error selecting mailbox: %s",m_imap->response); 86 qDebug("error selecting mailbox: %s",m_imap->response);
86 logout(); 87 logout();
87 return; 88 return;
88 } 89 }
89 90
90 int last = m_imap->selection_info->exists; 91 int last = m_imap->selection_info->exists;
91 92
92 if (last == 0) { 93 if (last == 0) {
93 qDebug("mailbox has no mails"); 94 qDebug("mailbox has no mails");
94 logout(); 95 logout();
95 return; 96 return;
96 } 97 }
97 98
98 result = clist_new(); 99 result = clist_new();
99 /* the range has to start at 1!!! not with 0!!!! */ 100 /* the range has to start at 1!!! not with 0!!!! */
100 set = mailimap_set_new_interval( 1, last ); 101 set = mailimap_set_new_interval( 1, last );
101 fetchAtt = mailimap_fetch_att_new_envelope(); 102 fetchAtt = mailimap_fetch_att_new_envelope();
102 fetchAttFlags = mailimap_fetch_att_new_flags(); 103 fetchAttFlags = mailimap_fetch_att_new_flags();
103 fetchAttDate = mailimap_fetch_att_new_internaldate(); 104 fetchAttDate = mailimap_fetch_att_new_internaldate();
104 105
105 //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 106 //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
106 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 107 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
107 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); 108 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt);
108 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); 109 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags);
109 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); 110 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate);
110 111
111 err = mailimap_fetch( m_imap, set, fetchType, &result ); 112 err = mailimap_fetch( m_imap, set, fetchType, &result );
112 mailimap_set_free( set ); 113 mailimap_set_free( set );
113 /* cleans up the fetch_att's too! */ 114 /* cleans up the fetch_att's too! */
114 mailimap_fetch_type_free( fetchType ); 115 mailimap_fetch_type_free( fetchType );
115 116
116 QString date,subject,from; 117 QString date,subject,from;
117 118
118 if ( err == MAILIMAP_NO_ERROR ) { 119 if ( err == MAILIMAP_NO_ERROR ) {
119 current = clist_begin(result); 120 current = clist_begin(result);
120 mailimap_msg_att * msg_att; 121 mailimap_msg_att * msg_att;
121 int i = 0; 122 int i = 0;
122 while ( current != 0 ) { 123 while ( current != 0 ) {
123 ++i; 124 ++i;
124 msg_att = (mailimap_msg_att*)current->data; 125 msg_att = (mailimap_msg_att*)current->data;
125 RecMail*m = parse_list_result(msg_att); 126 RecMail*m = parse_list_result(msg_att);
126 if (m) { 127 if (m) {
127 m->setNumber(i); 128 m->setNumber(i);
128 m->setMbox(mailbox); 129 m->setMbox(mailbox);
129 target.append(m); 130 target.append(m);
130 } 131 }
131 current = current->next; 132 current = current->next;
132 } 133 }
133 } else { 134 } else {
134 qDebug("Error fetching headers: %s",m_imap->response); 135 qDebug("Error fetching headers: %s",m_imap->response);
135 } 136 }
136 logout(); 137 logout();
137 clist_free(result); 138 clist_free(result);
138} 139}
139 140
140QList<IMAPFolder>* IMAPwrapper::listFolders() 141QList<IMAPFolder>* IMAPwrapper::listFolders()
141{ 142{
142 const char *path, *mask; 143 const char *path, *mask;
143 int err = MAILIMAP_NO_ERROR; 144 int err = MAILIMAP_NO_ERROR;
144 clist *result; 145 clist *result;
145 clistcell *current; 146 clistcell *current;
146 147
147 QList<IMAPFolder> * folders = new QList<IMAPFolder>(); 148 QList<IMAPFolder> * folders = new QList<IMAPFolder>();
148 folders->setAutoDelete( true ); 149 folders->setAutoDelete( true );
149 login(); 150 login();
150 if (!m_imap) { 151 if (!m_imap) {
151 return folders; 152 return folders;
152 } 153 }
153 154
154/* 155/*
155 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 156 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
156 * We must not forget to filter them out in next loop! 157 * We must not forget to filter them out in next loop!
157 * it seems like ugly code. and yes - it is ugly code. but the best way. 158 * it seems like ugly code. and yes - it is ugly code. but the best way.
158 */ 159 */
159 QString temp; 160 QString temp;
160 mask = "INBOX" ; 161 mask = "INBOX" ;
161 result = clist_new(); 162 result = clist_new();
162 mailimap_mailbox_list *list; 163 mailimap_mailbox_list *list;
163 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 164 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
164 if ( err == MAILIMAP_NO_ERROR ) { 165 if ( err == MAILIMAP_NO_ERROR ) {
165 current = result->first; 166 current = result->first;
166 for ( int i = result->count; i > 0; i-- ) { 167 for ( int i = result->count; i > 0; i-- ) {
167 list = (mailimap_mailbox_list *) current->data; 168 list = (mailimap_mailbox_list *) current->data;
168 // it is better use the deep copy mechanism of qt itself 169 // it is better use the deep copy mechanism of qt itself
169 // instead of using strdup! 170 // instead of using strdup!
170 temp = list->mb; 171 temp = list->mb;
171 folders->append( new IMAPFolder(temp)); 172 folders->append( new IMAPFolder(temp));
172 current = current->next; 173 current = current->next;
173 } 174 }
174 } else { 175 } else {
175 qDebug("error fetching folders: %s",m_imap->response); 176 qDebug("error fetching folders: %s",m_imap->response);
176 } 177 }
177 mailimap_list_result_free( result ); 178 mailimap_list_result_free( result );
178 179
179/* 180/*
180 * second stage - get the other then inbox folders 181 * second stage - get the other then inbox folders
181 */ 182 */
182 mask = "*" ; 183 mask = "*" ;
183 path = account->getPrefix().latin1(); 184 path = account->getPrefix().latin1();
184 result = clist_new(); 185 result = clist_new();
185 qDebug(path); 186 qDebug(path);
186 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 187 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
187 if ( err == MAILIMAP_NO_ERROR ) { 188 if ( err == MAILIMAP_NO_ERROR ) {
188 current = result->first; 189 current = result->first;
189 for ( int i = result->count; i > 0; i-- ) { 190 for ( int i = result->count; i > 0; i-- ) {
190 list = (mailimap_mailbox_list *) current->data; 191 list = (mailimap_mailbox_list *) current->data;
191 // it is better use the deep copy mechanism of qt itself 192 // it is better use the deep copy mechanism of qt itself
192 // instead of using strdup! 193 // instead of using strdup!
193 temp = list->mb; 194 temp = list->mb;
194 current = current->next; 195 current = current->next;
195 if (temp.lower()=="inbox") 196 if (temp.lower()=="inbox")
@@ -204,287 +205,290 @@ QList<IMAPFolder>* IMAPwrapper::listFolders()
204 return folders; 205 return folders;
205} 206}
206 207
207RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 208RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
208{ 209{
209 RecMail * m = 0; 210 RecMail * m = 0;
210 mailimap_msg_att_item *item=0; 211 mailimap_msg_att_item *item=0;
211 bool named_from = false; 212 bool named_from = false;
212 QString from,date,subject; 213 QString from,date,subject;
213 date = from = subject = ""; 214 date = from = subject = "";
214 clistcell *current,*c,*cf, *current_from = NULL; 215 clistcell *current,*c,*cf, *current_from = NULL;
215 mailimap_address * current_address = NULL; 216 mailimap_address * current_address = NULL;
216 mailimap_msg_att_dynamic*flist; 217 mailimap_msg_att_dynamic*flist;
217 mailimap_flag_fetch*cflag; 218 mailimap_flag_fetch*cflag;
218 QBitArray mFlags(7); 219 QBitArray mFlags(7);
219 220
220 if (!m_att) { 221 if (!m_att) {
221 return m; 222 return m;
222 } 223 }
223 224
224#if 0 225#if 0
225 MAILIMAP_FLAG_KEYWORD, /* keyword flag */ 226 MAILIMAP_FLAG_KEYWORD, /* keyword flag */
226 MAILIMAP_FLAG_EXTENSION, /* \extension flag */ 227 MAILIMAP_FLAG_EXTENSION, /* \extension flag */
227#endif 228#endif
228 c = clist_begin(m_att->list); 229 c = clist_begin(m_att->list);
229 while ( c ) { 230 while ( c ) {
230 current = c; 231 current = c;
231 c = c->next; 232 c = c->next;
232 item = (mailimap_msg_att_item*)current->data; 233 item = (mailimap_msg_att_item*)current->data;
233 if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 234 if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
234 flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; 235 flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn;
235 if (!flist->list) { 236 if (!flist->list) {
236 continue; 237 continue;
237 } 238 }
238 cf = flist->list->first; 239 cf = flist->list->first;
239 while (cf) { 240 while (cf) {
240 cflag = (mailimap_flag_fetch*)cf->data; 241 cflag = (mailimap_flag_fetch*)cf->data;
241 if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { 242 if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) {
242 switch (cflag->flag->type) { 243 switch (cflag->flag->type) {
243 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 244 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
244 mFlags.setBit(FLAG_ANSWERED); 245 mFlags.setBit(FLAG_ANSWERED);
245 break; 246 break;
246 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 247 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
247 mFlags.setBit(FLAG_FLAGGED); 248 mFlags.setBit(FLAG_FLAGGED);
248 break; 249 break;
249 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 250 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
250 mFlags.setBit(FLAG_DELETED); 251 mFlags.setBit(FLAG_DELETED);
251 break; 252 break;
252 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 253 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
253 mFlags.setBit(FLAG_SEEN); 254 mFlags.setBit(FLAG_SEEN);
254 break; 255 break;
255 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 256 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
256 mFlags.setBit(FLAG_DRAFT); 257 mFlags.setBit(FLAG_DRAFT);
257 break; 258 break;
258 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 259 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
259 break; 260 break;
260 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 261 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
261 break; 262 break;
262 default: 263 default:
263 break; 264 break;
264 } 265 }
265 } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { 266 } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) {
266 mFlags.setBit(FLAG_RECENT); 267 mFlags.setBit(FLAG_RECENT);
267 } 268 }
268 cf = cf->next; 269 cf = cf->next;
269 } 270 }
270 continue; 271 continue;
271 } 272 }
272 if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { 273 if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) {
273 qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); 274 qDebug( "header: \n%s", item->msg_att_static->rfc822_header );
274 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { 275 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) {
275 mailimap_envelope * head = item->msg_att_static->env; 276 mailimap_envelope * head = item->msg_att_static->env;
276 date = head->date; 277 date = head->date;
277 subject = head->subject; 278 subject = head->subject;
278 if (head->from!=NULL) 279 if (head->from!=NULL)
279 current_from = head->from->list->first; 280 current_from = head->from->list->first;
280 while (current_from != NULL) { 281 while (current_from != NULL) {
281 from = ""; 282 from = "";
282 named_from = false; 283 named_from = false;
283 current_address=(mailimap_address*)current_from->data; 284 current_address=(mailimap_address*)current_from->data;
284 current_from = current_from->next; 285 current_from = current_from->next;
285 if (current_address->personal_name){ 286 if (current_address->personal_name){
286 from+=QString(current_address->personal_name); 287 from+=QString(current_address->personal_name);
287 from+=" "; 288 from+=" ";
288 named_from = true; 289 named_from = true;
289 } 290 }
290 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 291 if (named_from && (current_address->mailbox_name || current_address->host_name)) {
291 from+="<"; 292 from+="<";
292 } 293 }
293 if (current_address->mailbox_name) { 294 if (current_address->mailbox_name) {
294 from+=QString(current_address->mailbox_name); 295 from+=QString(current_address->mailbox_name);
295 from+="@"; 296 from+="@";
296 } 297 }
297 if (current_address->host_name) { 298 if (current_address->host_name) {
298 from+=QString(current_address->host_name); 299 from+=QString(current_address->host_name);
299 } 300 }
300 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 301 if (named_from && (current_address->mailbox_name || current_address->host_name)) {
301 from+=">"; 302 from+=">";
302 } 303 }
303 } 304 }
304 qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s", 305 qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s",
305 from.latin1(), 306 from.latin1(),
306 subject.latin1(),date.latin1()); 307 subject.latin1(),date.latin1());
307 m = new RecMail(); 308 m = new RecMail();
308 m->setSubject(subject); 309 m->setSubject(subject);
309 m->setFrom(from); 310 m->setFrom(from);
310 m->setDate(date); 311 m->setDate(date);
311 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { 312 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) {
312 mailimap_date_time*d = item->msg_att_static->internal_date; 313 mailimap_date_time*d = item->msg_att_static->internal_date;
313 QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); 314 QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec));
314 qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec); 315 qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec);
315 qDebug(da.toString()); 316 qDebug(da.toString());
316 } else { 317 } else {
317 qDebug("Another type"); 318 qDebug("Another type");
318 } 319 }
319 } 320 }
320 /* msg is already deleted */ 321 /* msg is already deleted */
321 if (mFlags.testBit(FLAG_DELETED) && m) { 322 if (mFlags.testBit(FLAG_DELETED) && m) {
322 delete m; 323 delete m;
323 m = 0; 324 m = 0;
324 } 325 }
325 if (m) { 326 if (m) {
326 m->setFlags(mFlags); 327 m->setFlags(mFlags);
327 } 328 }
328 return m; 329 return m;
329} 330}
330 331
331#if 1 332#if 1
332QString IMAPwrapper::fetchBody(const RecMail&mail) 333RecBody IMAPwrapper::fetchBody(const RecMail&mail)
333{ 334{
334 QString body = ""; 335 RecBody body;
336 QString body_text;
337
335 const char *mb; 338 const char *mb;
336 int err = MAILIMAP_NO_ERROR; 339 int err = MAILIMAP_NO_ERROR;
337 clist *result; 340 clist *result;
338 clistcell *current; 341 clistcell *current;
339 mailimap_fetch_att *fetchAtt; 342 mailimap_fetch_att *fetchAtt;
340 mailimap_fetch_type *fetchType; 343 mailimap_fetch_type *fetchType;
341 mailimap_set *set; 344 mailimap_set *set;
342 345
343 mb = mail.getMbox().latin1(); 346 mb = mail.getMbox().latin1();
344 347
345 login(); 348 login();
346 if (!m_imap) { 349 if (!m_imap) {
347 return body; 350 return body;
348 } 351 }
349 /* select mailbox READONLY for operations */ 352 /* select mailbox READONLY for operations */
350 err = mailimap_examine( m_imap, (char*)mb); 353 err = mailimap_examine( m_imap, (char*)mb);
351 if ( err != MAILIMAP_NO_ERROR ) { 354 if ( err != MAILIMAP_NO_ERROR ) {
352 qDebug("error selecting mailbox: %s",m_imap->response); 355 qDebug("error selecting mailbox: %s",m_imap->response);
353 logout(); 356 logout();
354 return body; 357 return body;
355 } 358 }
356 result = clist_new(); 359 result = clist_new();
357 /* the range has to start at 1!!! not with 0!!!! */ 360 /* the range has to start at 1!!! not with 0!!!! */
358 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 361 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
359 fetchAtt = mailimap_fetch_att_new_rfc822_text(); 362 fetchAtt = mailimap_fetch_att_new_rfc822_text();
360 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 363 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
361 err = mailimap_fetch( m_imap, set, fetchType, &result ); 364 err = mailimap_fetch( m_imap, set, fetchType, &result );
362 mailimap_set_free( set ); 365 mailimap_set_free( set );
363 mailimap_fetch_type_free( fetchType ); 366 mailimap_fetch_type_free( fetchType );
364 367
365 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 368 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
366 mailimap_msg_att * msg_att; 369 mailimap_msg_att * msg_att;
367 msg_att = (mailimap_msg_att*)current->data; 370 msg_att = (mailimap_msg_att*)current->data;
368 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 371 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
369 372
370 if (item->msg_att_static && item->msg_att_static->rfc822_text) { 373 if (item->msg_att_static && item->msg_att_static->rfc822_text) {
371 body = item->msg_att_static->rfc822_text; 374 body_text = item->msg_att_static->rfc822_text;
375 body.setBodytext(body_text);
372 } 376 }
373 } else { 377 } else {
374 qDebug("error fetching text: %s",m_imap->response); 378 qDebug("error fetching text: %s",m_imap->response);
375 } 379 }
376 380
377 clist_free(result); 381 clist_free(result);
378 logout(); 382 logout();
379 return body; 383 return body;
380} 384}
381 385
382#else 386#else
383QString IMAPwrapper::fetchBody(const RecMail&mail) 387QString IMAPwrapper::fetchBody(const RecMail&mail)
384{ 388{
385 QString body = ""; 389 QString body = "";
386 const char *mb; 390 const char *mb;
387 int err = MAILIMAP_NO_ERROR; 391 int err = MAILIMAP_NO_ERROR;
388 clist *result; 392 clist *result;
389 clistcell *current; 393 clistcell *current;
390 mailimap_fetch_att *fetchAtt; 394 mailimap_fetch_att *fetchAtt;
391 mailimap_fetch_type *fetchType; 395 mailimap_fetch_type *fetchType;
392 mailimap_set *set; 396 mailimap_set *set;
393 mailimap_body*body_desc; 397 mailimap_body*body_desc;
394 398
395 mb = mail.getMbox().latin1(); 399 mb = mail.getMbox().latin1();
396 400
397 login(); 401 login();
398 if (!m_imap) { 402 if (!m_imap) {
399 return body; 403 return body;
400 } 404 }
401 /* select mailbox READONLY for operations */ 405 /* select mailbox READONLY for operations */
402 err = mailimap_examine( m_imap, (char*)mb); 406 err = mailimap_examine( m_imap, (char*)mb);
403 if ( err != MAILIMAP_NO_ERROR ) { 407 if ( err != MAILIMAP_NO_ERROR ) {
404 qDebug("error selecting mailbox: %s",m_imap->response); 408 qDebug("error selecting mailbox: %s",m_imap->response);
405 logout(); 409 logout();
406 return body; 410 return body;
407 } 411 }
408 result = clist_new(); 412 result = clist_new();
409 /* the range has to start at 1!!! not with 0!!!! */ 413 /* the range has to start at 1!!! not with 0!!!! */
410 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 414 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
411 fetchAtt = mailimap_fetch_att_new_body(); 415 fetchAtt = mailimap_fetch_att_new_body();
412 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 416 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
413 err = mailimap_fetch( m_imap, set, fetchType, &result ); 417 err = mailimap_fetch( m_imap, set, fetchType, &result );
414 mailimap_set_free( set ); 418 mailimap_set_free( set );
415 mailimap_fetch_type_free( fetchType ); 419 mailimap_fetch_type_free( fetchType );
416 420
417 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 421 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
418 mailimap_msg_att * msg_att; 422 mailimap_msg_att * msg_att;
419 msg_att = (mailimap_msg_att*)current->data; 423 msg_att = (mailimap_msg_att*)current->data;
420 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 424 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
421 body_desc = item->msg_att_static->body; 425 body_desc = item->msg_att_static->body;
422 if (body_desc->type==MAILIMAP_BODY_1PART) { 426 if (body_desc->type==MAILIMAP_BODY_1PART) {
423 body = searchBodyText(mail,body_desc->body_1part); 427 body = searchBodyText(mail,body_desc->body_1part);
424 } else { 428 } else {
425 } 429 }
426 430
427 } else { 431 } else {
428 qDebug("error fetching body: %s",m_imap->response); 432 qDebug("error fetching body: %s",m_imap->response);
429 } 433 }
430 434
431 clist_free(result); 435 clist_free(result);
432 logout(); 436 logout();
433 return body; 437 return body;
434} 438}
435#endif 439#endif
436 440
437QString IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription) 441QString IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription)
438{ 442{
439 QString Body=""; 443 QString Body="";
440 if (!mailDescription) { 444 if (!mailDescription) {
441 return Body; 445 return Body;
442 } 446 }
443 switch (mailDescription->type) { 447 switch (mailDescription->type) {
444 case MAILIMAP_BODY_TYPE_1PART_TEXT: 448 case MAILIMAP_BODY_TYPE_1PART_TEXT:
445 return getPlainBody(mail); 449 return getPlainBody(mail);
446 break; 450 break;
447 default: 451 default:
448 break; 452 break;
449 } 453 }
450 return Body; 454 return Body;
451} 455}
452 456
453QString IMAPwrapper::getPlainBody(const RecMail&mail) 457QString IMAPwrapper::getPlainBody(const RecMail&mail)
454{ 458{
455 QString body = ""; 459 QString body = "";
456 const char *mb; 460 const char *mb;
457 int err = MAILIMAP_NO_ERROR; 461 int err = MAILIMAP_NO_ERROR;
458 clist *result; 462 clist *result;
459 clistcell *current; 463 clistcell *current;
460 mailimap_fetch_att *fetchAtt; 464 mailimap_fetch_att *fetchAtt;
461 mailimap_fetch_type *fetchType; 465 mailimap_fetch_type *fetchType;
462 mailimap_set *set; 466 mailimap_set *set;
463 467
464 mb = mail.getMbox().latin1(); 468 mb = mail.getMbox().latin1();
465 469
466 if (!m_imap) { 470 if (!m_imap) {
467 return body; 471 return body;
468 } 472 }
469 result = clist_new(); 473 result = clist_new();
470 /* the range has to start at 1!!! not with 0!!!! */ 474 /* the range has to start at 1!!! not with 0!!!! */
471 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 475 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
472 fetchAtt = mailimap_fetch_att_new_rfc822_text(); 476 fetchAtt = mailimap_fetch_att_new_rfc822_text();
473 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 477 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
474 err = mailimap_fetch( m_imap, set, fetchType, &result ); 478 err = mailimap_fetch( m_imap, set, fetchType, &result );
475 mailimap_set_free( set ); 479 mailimap_set_free( set );
476 mailimap_fetch_type_free( fetchType ); 480 mailimap_fetch_type_free( fetchType );
477 481
478 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 482 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
479 mailimap_msg_att * msg_att; 483 mailimap_msg_att * msg_att;
480 msg_att = (mailimap_msg_att*)current->data; 484 msg_att = (mailimap_msg_att*)current->data;
481 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 485 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
482 if (item->msg_att_static && item->msg_att_static->rfc822_text) { 486 if (item->msg_att_static && item->msg_att_static->rfc822_text) {
483 body = item->msg_att_static->rfc822_text; 487 body = item->msg_att_static->rfc822_text;
484 } 488 }
485 } else { 489 } else {
486 qDebug("error fetching text: %s",m_imap->response); 490 qDebug("error fetching text: %s",m_imap->response);
487 } 491 }
488 clist_free(result); 492 clist_free(result);
489 return body; 493 return body;
490} 494}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index b02d26d..1423faf 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -1,33 +1,36 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h>
4#include "mailwrapper.h" 5#include "mailwrapper.h"
5 6
6struct mailimap; 7struct mailimap;
7struct mailimap_body_type_1part; 8struct mailimap_body_type_1part;
9class RecMail;
10class RecBody;
8 11
9class IMAPwrapper : public QObject 12class IMAPwrapper : public QObject
10{ 13{
11 Q_OBJECT 14 Q_OBJECT
12 15
13public: 16public:
14 IMAPwrapper( IMAPaccount *a ); 17 IMAPwrapper( IMAPaccount *a );
15 virtual ~IMAPwrapper(); 18 virtual ~IMAPwrapper();
16 QList<IMAPFolder>* listFolders(); 19 QList<IMAPFolder>* listFolders();
17 void listMessages(const QString & mailbox,Maillist&target ); 20 void listMessages(const QString & mailbox,QList<RecMail>&target );
18 QString fetchBody(const RecMail&mail); 21 RecBody fetchBody(const RecMail&mail);
19 static void imap_progress( size_t current, size_t maximum ); 22 static void imap_progress( size_t current, size_t maximum );
20 23
21protected: 24protected:
22 RecMail*parse_list_result(mailimap_msg_att*); 25 RecMail*parse_list_result(mailimap_msg_att*);
23 void login(); 26 void login();
24 void logout(); 27 void logout();
25 QString searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription); 28 QString searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription);
26 QString getPlainBody(const RecMail&mail); 29 QString getPlainBody(const RecMail&mail);
27 30
28private: 31private:
29 IMAPaccount *account; 32 IMAPaccount *account;
30 mailimap *m_imap; 33 mailimap *m_imap;
31}; 34};
32 35
33#endif 36#endif
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.cpp b/noncore/net/mail/libmailwrapper/mailtypes.cpp
new file mode 100644
index 0000000..9f2c9e3
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/mailtypes.cpp
@@ -0,0 +1,129 @@
1#include "mailtypes.h"
2
3
4RecMail::RecMail()
5 :subject(""),date(""),mbox(""),msg_number(0),msg_flags(7)
6{
7}
8
9void RecMail::setTo(const QStringList&list)
10{
11 to = list;
12}
13
14const QStringList&RecMail::To()const
15{
16 return to;
17}
18
19void RecMail::setCC(const QStringList&list)
20{
21 cc = list;
22}
23
24const QStringList&RecMail::CC()const
25{
26 return cc;
27}
28
29void RecMail::setBcc(const QStringList&list)
30{
31 bcc = list;
32}
33
34const QStringList& RecMail::Bcc()const
35{
36 return bcc;
37}
38
39
40RecPart::RecPart()
41 : m_type(""),m_subtype(""),m_identifier(""),m_encoding("")
42{
43}
44
45RecPart::RecPart(const QString&identifier,const QString&type,const QString&subtype,const QString&encoding)
46 : m_type(type),m_subtype(subtype),m_identifier(identifier),m_encoding(encoding)
47{
48}
49
50RecPart::~RecPart()
51{
52}
53
54const QString& RecPart::Type()const
55{
56 return m_type;
57}
58
59void RecPart::setType(const QString&type)
60{
61 m_type = type;
62}
63
64const QString& RecPart::Subtype()const
65{
66 return m_subtype;
67}
68
69void RecPart::setSubtype(const QString&subtype)
70{
71 m_subtype = subtype;
72}
73
74const QString& RecPart::Identifier()const
75{
76 return m_identifier;
77}
78
79void RecPart::setIdentifier(const QString&identifier)
80{
81 m_identifier = identifier;
82}
83
84const QString& RecPart::Encoding()const
85{
86 return m_encoding;
87}
88
89void RecPart::setEncoding(const QString&encoding)
90{
91 m_encoding = encoding;
92}
93
94RecBody::RecBody()
95 : m_BodyText(""),m_PartsList()
96{
97 m_PartsList.setAutoDelete(true);
98}
99
100RecBody::~RecBody()
101{
102}
103
104void RecBody::setBodytext(const QString&bodyText)
105{
106 m_BodyText = bodyText;
107}
108
109const QString& RecBody::Bodytext()const
110{
111 return m_BodyText;
112}
113
114void RecBody::setParts(const QList<RecPart>&parts)
115{
116 m_PartsList = parts;
117 m_PartsList.setAutoDelete(true);
118}
119
120const QList<RecPart>& RecBody::Parts()const
121{
122 return m_PartsList;
123}
124
125void RecBody::addPart(const RecPart& part)
126{
127 RecPart*p = new RecPart(part);
128 m_PartsList.append(p);
129}
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.h b/noncore/net/mail/libmailwrapper/mailtypes.h
new file mode 100644
index 0000000..bb6a483
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/mailtypes.h
@@ -0,0 +1,98 @@
1#ifndef __MAIL_TYPES_H
2#define __MAIL_TYPES_H
3
4#define FLAG_ANSWERED 0
5#define FLAG_FLAGGED 1
6#define FLAG_DELETED 2
7#define FLAG_SEEN 3
8#define FLAG_DRAFT 4
9#define FLAG_RECENT 5
10
11#include <qlist.h>
12#include <qbitarray.h>
13#include <qstring.h>
14#include <qstringlist.h>
15
16/* a class to describe mails in a mailbox */
17/* Attention!
18 From programmers point of view it would make sense to
19 store the mail body into this class, too.
20 But: not from the point of view of the device.
21 Mailbodies can be real large. So we request them when
22 needed from the mail-wrapper class direct from the server itself
23 (imap) or from a file-based cache (pop3?)
24 So there is no interface "const QString&body()" but you should
25 make a request to the mailwrapper with this class as parameter to
26 get the body. Same words for the attachments.
27*/
28class RecMail
29{
30public:
31 RecMail();
32 virtual ~RecMail(){}
33
34 const int getNumber()const{return msg_number;}
35 void setNumber(int number){msg_number=number;}
36 const QString&getDate()const{ return date; }
37 void setDate( const QString&a ) { date = a; }
38 const QString&getFrom()const{ return from; }
39 void setFrom( const QString&a ) { from = a; }
40 const QString&getSubject()const { return subject; }
41 void setSubject( const QString&s ) { subject = s; }
42 const QString&getMbox()const{return mbox;}
43 void setMbox(const QString&box){mbox = box;}
44
45 void setTo(const QStringList&list);
46 const QStringList&To()const;
47 void setCC(const QStringList&list);
48 const QStringList&CC()const;
49 void setBcc(const QStringList&list);
50 const QStringList&Bcc()const;
51
52 const QBitArray&getFlags()const{return msg_flags;}
53 void setFlags(const QBitArray&flags){msg_flags = flags;}
54
55protected:
56 QString subject,date,from,mbox;
57 int msg_number;
58 QBitArray msg_flags;
59 QStringList to,cc,bcc;
60};
61
62class RecPart
63{
64protected:
65 QString m_type,m_subtype,m_identifier,m_encoding;
66public:
67 RecPart();
68 RecPart(const QString&identifier,const QString&type="",const QString&subtype="",const QString&encoding="BASE64");
69 virtual ~RecPart();
70
71 const QString&Type()const;
72 void setType(const QString&type);
73 const QString&Subtype()const;
74 void setSubtype(const QString&subtype);
75 const QString&Identifier()const;
76 void setIdentifier(const QString&identifier);
77 const QString&Encoding()const;
78 void setEncoding(const QString&encoding);
79};
80
81class RecBody
82{
83protected:
84 QString m_BodyText;
85 QList<RecPart> m_PartsList;
86
87public:
88 RecBody();
89 virtual ~RecBody();
90 void setBodytext(const QString&);
91 const QString& Bodytext()const;
92
93 void setParts(const QList<RecPart>&parts);
94 const QList<RecPart>& Parts()const;
95 void addPart(const RecPart&part);
96};
97
98#endif
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
index 7f67cd8..898e9d6 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
@@ -502,140 +502,128 @@ void MailWrapper::readFromFile( QString file, char **data, size_t *size )
502 count = read( fd, buf + total, st.st_size - total ); 502 count = read( fd, buf + total, st.st_size - total );
503 total += count; 503 total += count;
504 } 504 }
505 if ( count < 0 ) goto err_free; 505 if ( count < 0 ) goto err_free;
506 506
507 *data = buf; 507 *data = buf;
508 *size = st.st_size; 508 *size = st.st_size;
509 509
510 close( fd ); 510 close( fd );
511 511
512 return; // Success :) 512 return; // Success :)
513 513
514err_free: 514err_free:
515 free( buf ); 515 free( buf );
516err_close: 516err_close:
517 close( fd ); 517 close( fd );
518} 518}
519 519
520void progress( size_t current, size_t maximum ) 520void progress( size_t current, size_t maximum )
521{ 521{
522 qDebug( "Current: %i of %i", current, maximum ); 522 qDebug( "Current: %i of %i", current, maximum );
523} 523}
524 524
525void MailWrapper::smtpSend( mailmime *mail ) 525void MailWrapper::smtpSend( mailmime *mail )
526{ 526{
527 mailsmtp *session; 527 mailsmtp *session;
528 clist *rcpts; 528 clist *rcpts;
529 char *from, *data, *server, *user = NULL, *pass = NULL; 529 char *from, *data, *server, *user = NULL, *pass = NULL;
530 size_t size; 530 size_t size;
531 int err; 531 int err;
532 bool ssl; 532 bool ssl;
533 uint16_t port; 533 uint16_t port;
534 534
535 535
536 from = getFrom( mail ); 536 from = getFrom( mail );
537 SMTPaccount *smtp = getAccount( from ); 537 SMTPaccount *smtp = getAccount( from );
538 if ( smtp == NULL ) { 538 if ( smtp == NULL ) {
539 free(from); 539 free(from);
540 return; 540 return;
541 } 541 }
542 server = strdup( smtp->getServer().latin1() ); 542 server = strdup( smtp->getServer().latin1() );
543 ssl = smtp->getSSL(); 543 ssl = smtp->getSSL();
544 port = smtp->getPort().toUInt(); 544 port = smtp->getPort().toUInt();
545 rcpts = createRcptList( mail->fields ); 545 rcpts = createRcptList( mail->fields );
546 546
547 QString file = getTmpFile(); 547 QString file = getTmpFile();
548 writeToFile( file, mail ); 548 writeToFile( file, mail );
549 readFromFile( file, &data, &size ); 549 readFromFile( file, &data, &size );
550 QFile f( file ); 550 QFile f( file );
551 f.remove(); 551 f.remove();
552 552
553 session = mailsmtp_new( 20, &progress ); 553 session = mailsmtp_new( 20, &progress );
554 if ( session == NULL ) goto free_mem; 554 if ( session == NULL ) goto free_mem;
555 555
556 qDebug( "Servername %s at port %i", server, port ); 556 qDebug( "Servername %s at port %i", server, port );
557 if ( ssl ) { 557 if ( ssl ) {
558 qDebug( "SSL session" ); 558 qDebug( "SSL session" );
559 err = mailsmtp_ssl_connect( session, server, port ); 559 err = mailsmtp_ssl_connect( session, server, port );
560 } else { 560 } else {
561 qDebug( "No SSL session" ); 561 qDebug( "No SSL session" );
562 err = mailsmtp_socket_connect( session, server, port ); 562 err = mailsmtp_socket_connect( session, server, port );
563 } 563 }
564 if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; 564 if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session;
565 565
566 err = mailsmtp_init( session ); 566 err = mailsmtp_init( session );
567 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; 567 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session;
568 568
569 qDebug( "INIT OK" ); 569 qDebug( "INIT OK" );
570 570
571 if ( smtp->getLogin() ) { 571 if ( smtp->getLogin() ) {
572 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { 572 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
573 // get'em 573 // get'em
574 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); 574 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true );
575 login.show(); 575 login.show();
576 if ( QDialog::Accepted == login.exec() ) { 576 if ( QDialog::Accepted == login.exec() ) {
577 // ok 577 // ok
578 user = strdup( login.getUser().latin1() ); 578 user = strdup( login.getUser().latin1() );
579 pass = strdup( login.getPassword().latin1() ); 579 pass = strdup( login.getPassword().latin1() );
580 } else { 580 } else {
581 goto free_con_session; 581 goto free_con_session;
582 } 582 }
583 } else { 583 } else {
584 user = strdup( smtp->getUser().latin1() ); 584 user = strdup( smtp->getUser().latin1() );
585 pass = strdup( smtp->getPassword().latin1() ); 585 pass = strdup( smtp->getPassword().latin1() );
586 } 586 }
587 qDebug( "session->auth: %i", session->auth); 587 qDebug( "session->auth: %i", session->auth);
588 err = mailsmtp_auth( session, user, pass ); 588 err = mailsmtp_auth( session, user, pass );
589 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); 589 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
590 qDebug( "Done auth!" ); 590 qDebug( "Done auth!" );
591 } 591 }
592 592
593 err = mailsmtp_send( session, from, rcpts, data, size ); 593 err = mailsmtp_send( session, from, rcpts, data, size );
594 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; 594 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session;
595 595
596 qDebug( "Mail sent." ); 596 qDebug( "Mail sent." );
597 597
598free_con_session: 598free_con_session:
599 mailsmtp_quit( session ); 599 mailsmtp_quit( session );
600free_mem_session: 600free_mem_session:
601 mailsmtp_free( session ); 601 mailsmtp_free( session );
602free_mem: 602free_mem:
603 smtp_address_list_free( rcpts ); 603 smtp_address_list_free( rcpts );
604 free( data ); 604 free( data );
605 free( server ); 605 free( server );
606 if ( smtp->getLogin() ) { 606 if ( smtp->getLogin() ) {
607 free( user ); 607 free( user );
608 free( pass ); 608 free( pass );
609 } 609 }
610 free( from ); 610 free( from );
611} 611}
612 612
613void MailWrapper::sendMail( Mail mail ) 613void MailWrapper::sendMail( Mail mail )
614{ 614{
615 mailmime *mimeMail; 615 mailmime *mimeMail;
616 616
617 mimeMail = createMimeMail( &mail ); 617 mimeMail = createMimeMail( &mail );
618 if ( mimeMail == NULL ) { 618 if ( mimeMail == NULL ) {
619 qDebug( "sendMail: error creating mime mail" ); 619 qDebug( "sendMail: error creating mime mail" );
620 } else { 620 } else {
621 smtpSend( mimeMail ); 621 smtpSend( mimeMail );
622 mailmime_free( mimeMail ); 622 mailmime_free( mimeMail );
623 } 623 }
624} 624}
625 625
626Mail::Mail() 626Mail::Mail()
627 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") 627 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("")
628{ 628{
629} 629}
630
631RecMail::RecMail()
632 :subject(""),date(""),mbox(""),msg_number(0),msg_flags(7)
633{
634}
635
636#if 0
637void RecMail::setDate(const QString&aDate)
638{
639 mDate = QDateTime::fromString(aDate);
640}
641#endif
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h
index 332034f..34fd5c5 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.h
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.h
@@ -1,177 +1,123 @@
1#ifndef MAILWRAPPER_H 1#ifndef MAILWRAPPER_H
2#define MAILWRAPPER_H 2#define MAILWRAPPER_H
3 3
4#include <qpe/applnk.h> 4#include <qpe/applnk.h>
5 5
6#include <libetpan/mailmime.h> 6#include <libetpan/mailmime.h>
7#include <libetpan/mailimf.h> 7#include <libetpan/mailimf.h>
8#include <libetpan/mailsmtp.h> 8#include <libetpan/mailsmtp.h>
9#include <libetpan/mailstorage.h> 9#include <libetpan/mailstorage.h>
10#include <libetpan/maildriver.h> 10#include <libetpan/maildriver.h>
11#include <qbitarray.h> 11#include <qbitarray.h>
12#include <qdatetime.h> 12#include <qdatetime.h>
13 13
14#include "settings.h" 14#include "settings.h"
15 15
16class Attachment 16class Attachment
17{ 17{
18public: 18public:
19 Attachment( DocLnk lnk ); 19 Attachment( DocLnk lnk );
20 virtual ~Attachment(){} 20 virtual ~Attachment(){}
21 const QString getFileName()const{ return doc.file(); } 21 const QString getFileName()const{ return doc.file(); }
22 const QString getName()const{ return doc.name(); } 22 const QString getName()const{ return doc.name(); }
23 const QString getMimeType()const{ return doc.type(); } 23 const QString getMimeType()const{ return doc.type(); }
24 const QPixmap getPixmap()const{ return doc.pixmap(); } 24 const QPixmap getPixmap()const{ return doc.pixmap(); }
25 const int getSize()const { return size; } 25 const int getSize()const { return size; }
26 DocLnk getDocLnk() { return doc; } 26 DocLnk getDocLnk() { return doc; }
27 27
28protected: 28protected:
29 DocLnk doc; 29 DocLnk doc;
30 int size; 30 int size;
31 31
32}; 32};
33 33
34#define FLAG_ANSWERED 0
35#define FLAG_FLAGGED 1
36#define FLAG_DELETED 2
37#define FLAG_SEEN 3
38#define FLAG_DRAFT 4
39#define FLAG_RECENT 5
40
41/* a class to describe mails in a mailbox */
42/* Attention!
43 From programmers point of view it would make sense to
44 store the mail body into this class, too.
45 But: not from the point of view of the device.
46 Mailbodies can be real large. So we request them when
47 needed from the mail-wrapper class direct from the server itself
48 (imap) or from a file-based cache (pop3?)
49 So there is no interface "const QString&body()" but you should
50 make a request to the mailwrapper with this class as parameter to
51 get the body. Same words for the attachments.
52*/
53class RecMail
54{
55public:
56 RecMail();
57 virtual ~RecMail(){}
58
59 const int getNumber()const{return msg_number;}
60 void setNumber(int number){msg_number=number;}
61 const QString&getDate()const{ return date; }
62 void setDate( const QString&a ) { date = a; }
63 const QString&getFrom()const{ return from; }
64 void setFrom( const QString&a ) { from = a; }
65 const QString&getSubject()const { return subject; }
66 void setSubject( const QString&s ) { subject = s; }
67 const QString&getMbox()const{return mbox;}
68 void setMbox(const QString&box){mbox = box;}
69 const QBitArray&getFlags()const{return msg_flags;}
70 void setFlags(const QBitArray&flags){msg_flags = flags;}
71
72#if 0
73 void setDate(const QString&dstring);
74 void setDate(const QDateTime&date){mDate = date;}
75 QString getDate()const{return mDate.toString();}
76#endif
77protected:
78 QString subject,date,from,mbox;
79 int msg_number;
80 QBitArray msg_flags;
81#if 0
82 QDateTime mDate;
83#endif
84};
85
86typedef QList<RecMail> Maillist;
87
88class Mail 34class Mail
89{ 35{
90public: 36public:
91 Mail(); 37 Mail();
92 /* Possible that this destructor must not be declared virtual 38 /* Possible that this destructor must not be declared virtual
93 * 'cause it seems that it will never have some child classes. 39 * 'cause it seems that it will never have some child classes.
94 * in this case this object will not get a virtual table -> memory and 40 * in this case this object will not get a virtual table -> memory and
95 * speed will be a little bit better? 41 * speed will be a little bit better?
96 */ 42 */
97 virtual ~Mail(){} 43 virtual ~Mail(){}
98 void addAttachment( Attachment *att ) { attList.append( att ); } 44 void addAttachment( Attachment *att ) { attList.append( att ); }
99 const QList<Attachment>& getAttachments()const { return attList; } 45 const QList<Attachment>& getAttachments()const { return attList; }
100 void removeAttachment( Attachment *att ) { attList.remove( att ); } 46 void removeAttachment( Attachment *att ) { attList.remove( att ); }
101 const QString&getName()const { return name; } 47 const QString&getName()const { return name; }
102 void setName( QString s ) { name = s; } 48 void setName( QString s ) { name = s; }
103 const QString&getMail()const{ return mail; } 49 const QString&getMail()const{ return mail; }
104 void setMail( const QString&s ) { mail = s; } 50 void setMail( const QString&s ) { mail = s; }
105 const QString&getTo()const{ return to; } 51 const QString&getTo()const{ return to; }
106 void setTo( const QString&s ) { to = s; } 52 void setTo( const QString&s ) { to = s; }
107 const QString&getCC()const{ return cc; } 53 const QString&getCC()const{ return cc; }
108 void setCC( const QString&s ) { cc = s; } 54 void setCC( const QString&s ) { cc = s; }
109 const QString&getBCC()const { return bcc; } 55 const QString&getBCC()const { return bcc; }
110 void setBCC( const QString&s ) { bcc = s; } 56 void setBCC( const QString&s ) { bcc = s; }
111 const QString&getMessage()const { return message; } 57 const QString&getMessage()const { return message; }
112 void setMessage( const QString&s ) { message = s; } 58 void setMessage( const QString&s ) { message = s; }
113 const QString&getSubject()const { return subject; } 59 const QString&getSubject()const { return subject; }
114 void setSubject( const QString&s ) { subject = s; } 60 void setSubject( const QString&s ) { subject = s; }
115 const QString&getReply()const{ return reply; } 61 const QString&getReply()const{ return reply; }
116 void setReply( const QString&a ) { reply = a; } 62 void setReply( const QString&a ) { reply = a; }
117 63
118private: 64private:
119 QList<Attachment> attList; 65 QList<Attachment> attList;
120 QString name, mail, to, cc, bcc, reply, subject, message; 66 QString name, mail, to, cc, bcc, reply, subject, message;
121}; 67};
122 68
123class Folder : public QObject 69class Folder : public QObject
124{ 70{
125 Q_OBJECT 71 Q_OBJECT
126 72
127public: 73public:
128 Folder( const QString&init_name ); 74 Folder( const QString&init_name );
129 const QString&getDisplayName()const { return nameDisplay; } 75 const QString&getDisplayName()const { return nameDisplay; }
130 const QString&getName()const { return name; } 76 const QString&getName()const { return name; }
131 virtual bool may_select()const{return true;}; 77 virtual bool may_select()const{return true;};
132 78
133private: 79private:
134 QString nameDisplay, name; 80 QString nameDisplay, name;
135 81
136}; 82};
137 83
138class IMAPFolder : public Folder 84class IMAPFolder : public Folder
139{ 85{
140 public: 86 public:
141 IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {} 87 IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {}
142 virtual bool may_select()const{return m_MaySelect;} 88 virtual bool may_select()const{return m_MaySelect;}
143 private: 89 private:
144 bool m_MaySelect; 90 bool m_MaySelect;
145}; 91};
146 92
147class MailWrapper : public QObject 93class MailWrapper : public QObject
148{ 94{
149 Q_OBJECT 95 Q_OBJECT
150 96
151public: 97public:
152 MailWrapper( Settings *s ); 98 MailWrapper( Settings *s );
153 void sendMail( Mail mail ); 99 void sendMail( Mail mail );
154 100
155private: 101private:
156 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 102 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
157 mailimf_address_list *parseAddresses(const QString&addr ); 103 mailimf_address_list *parseAddresses(const QString&addr );
158 mailimf_fields *createImfFields( Mail *mail ); 104 mailimf_fields *createImfFields( Mail *mail );
159 mailmime *buildTxtPart( QString str ); 105 mailmime *buildTxtPart( QString str );
160 mailmime *buildFilePart( QString filename, QString mimetype ); 106 mailmime *buildFilePart( QString filename, QString mimetype );
161 void addFileParts( mailmime *message, QList<Attachment> files ); 107 void addFileParts( mailmime *message, QList<Attachment> files );
162 mailmime *createMimeMail( Mail *mail ); 108 mailmime *createMimeMail( Mail *mail );
163 void smtpSend( mailmime *mail ); 109 void smtpSend( mailmime *mail );
164 mailimf_field *getField( mailimf_fields *fields, int type ); 110 mailimf_field *getField( mailimf_fields *fields, int type );
165 clist *createRcptList( mailimf_fields *fields ); 111 clist *createRcptList( mailimf_fields *fields );
166 char *getFrom( mailmime *mail ); 112 char *getFrom( mailmime *mail );
167 SMTPaccount *getAccount( QString from ); 113 SMTPaccount *getAccount( QString from );
168 void writeToFile( QString file, mailmime *mail ); 114 void writeToFile( QString file, mailmime *mail );
169 void readFromFile( QString file, char **data, size_t *size ); 115 void readFromFile( QString file, char **data, size_t *size );
170 static QString mailsmtpError( int err ); 116 static QString mailsmtpError( int err );
171 static QString getTmpFile(); 117 static QString getTmpFile();
172 118
173 Settings *settings; 119 Settings *settings;
174 120
175}; 121};
176 122
177#endif 123#endif
diff --git a/noncore/net/mail/mail.pro b/noncore/net/mail/mail.pro
index 3ae1ddc..55d95ba 100644
--- a/noncore/net/mail/mail.pro
+++ b/noncore/net/mail/mail.pro
@@ -1,44 +1,47 @@
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 \
16 mailistviewitem.h
15 17
16 SOURCES = main.cpp \ 18 SOURCES = main.cpp \
17 opiemail.cpp \ 19 opiemail.cpp \
18 mainwindow.cpp \ 20 mainwindow.cpp \
19 accountview.cpp \ 21 accountview.cpp \
20 composemail.cpp \ 22 composemail.cpp \
21 mailwrapper.cpp \ 23 mailwrapper.cpp \
22 imapwrapper.cpp \ 24 imapwrapper.cpp \
23 addresspicker.cpp \ 25 addresspicker.cpp \
24 editaccounts.cpp \ 26 editaccounts.cpp \
25 logindialog.cpp \ 27 logindialog.cpp \
26 viewmail.cpp \ 28 viewmail.cpp \
27 viewmailbase.cpp \ 29 viewmailbase.cpp \
28 settings.cpp 30 settings.cpp \
31 mailtypes.cpp
29 32
30 INTERFACES = editaccountsui.ui \ 33 INTERFACES = editaccountsui.ui \
31 selectmailtypeui.ui \ 34 selectmailtypeui.ui \
32 imapconfigui.ui \ 35 imapconfigui.ui \
33 pop3configui.ui \ 36 pop3configui.ui \
34 nntpconfigui.ui \ 37 nntpconfigui.ui \
35 smtpconfigui.ui \ 38 smtpconfigui.ui \
36 addresspickerui.ui \ 39 addresspickerui.ui \
37 logindialogui.ui \ 40 logindialogui.ui \
38 composemailui.ui 41 composemailui.ui
39 42
40INCLUDEPATH += $(OPIEDIR)/include 43INCLUDEPATH += $(OPIEDIR)/include
41 LIBS += -lqpe -lopie -letpan -lssl -lcrypto -ldb 44 LIBS += -lqpe -lopie -letpan -lssl -lcrypto -ldb
42TARGET = opiemail 45TARGET = opiemail
43 46
44include ( $(OPIEDIR)/include.pro ) 47include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/net/mail/mailistviewitem.h b/noncore/net/mail/mailistviewitem.h
new file mode 100644
index 0000000..60bfdda
--- a/dev/null
+++ b/noncore/net/mail/mailistviewitem.h
@@ -0,0 +1,21 @@
1#ifndef __MAILLISTVIEWITEM_H
2#define __MAILLISTVIEWITEM_H
3
4#include <qlistview.h>
5#include "mailtypes.h"
6
7class MailListViewItem:public QListViewItem
8{
9public:
10 MailListViewItem(QListView * parent, MailListViewItem * after );
11 virtual ~MailListViewItem(){}
12
13 void storeData(const RecMail&data);
14 const RecMail&data()const;
15 void showEntry();
16
17protected:
18 RecMail mail_data;
19};
20
21#endif
diff --git a/noncore/net/mail/mailtypes.cpp b/noncore/net/mail/mailtypes.cpp
new file mode 100644
index 0000000..9f2c9e3
--- a/dev/null
+++ b/noncore/net/mail/mailtypes.cpp
@@ -0,0 +1,129 @@
1#include "mailtypes.h"
2
3
4RecMail::RecMail()
5 :subject(""),date(""),mbox(""),msg_number(0),msg_flags(7)
6{
7}
8
9void RecMail::setTo(const QStringList&list)
10{
11 to = list;
12}
13
14const QStringList&RecMail::To()const
15{
16 return to;
17}
18
19void RecMail::setCC(const QStringList&list)
20{
21 cc = list;
22}
23
24const QStringList&RecMail::CC()const
25{
26 return cc;
27}
28
29void RecMail::setBcc(const QStringList&list)
30{
31 bcc = list;
32}
33
34const QStringList& RecMail::Bcc()const
35{
36 return bcc;
37}
38
39
40RecPart::RecPart()
41 : m_type(""),m_subtype(""),m_identifier(""),m_encoding("")
42{
43}
44
45RecPart::RecPart(const QString&identifier,const QString&type,const QString&subtype,const QString&encoding)
46 : m_type(type),m_subtype(subtype),m_identifier(identifier),m_encoding(encoding)
47{
48}
49
50RecPart::~RecPart()
51{
52}
53
54const QString& RecPart::Type()const
55{
56 return m_type;
57}
58
59void RecPart::setType(const QString&type)
60{
61 m_type = type;
62}
63
64const QString& RecPart::Subtype()const
65{
66 return m_subtype;
67}
68
69void RecPart::setSubtype(const QString&subtype)
70{
71 m_subtype = subtype;
72}
73
74const QString& RecPart::Identifier()const
75{
76 return m_identifier;
77}
78
79void RecPart::setIdentifier(const QString&identifier)
80{
81 m_identifier = identifier;
82}
83
84const QString& RecPart::Encoding()const
85{
86 return m_encoding;
87}
88
89void RecPart::setEncoding(const QString&encoding)
90{
91 m_encoding = encoding;
92}
93
94RecBody::RecBody()
95 : m_BodyText(""),m_PartsList()
96{
97 m_PartsList.setAutoDelete(true);
98}
99
100RecBody::~RecBody()
101{
102}
103
104void RecBody::setBodytext(const QString&bodyText)
105{
106 m_BodyText = bodyText;
107}
108
109const QString& RecBody::Bodytext()const
110{
111 return m_BodyText;
112}
113
114void RecBody::setParts(const QList<RecPart>&parts)
115{
116 m_PartsList = parts;
117 m_PartsList.setAutoDelete(true);
118}
119
120const QList<RecPart>& RecBody::Parts()const
121{
122 return m_PartsList;
123}
124
125void RecBody::addPart(const RecPart& part)
126{
127 RecPart*p = new RecPart(part);
128 m_PartsList.append(p);
129}
diff --git a/noncore/net/mail/mailtypes.h b/noncore/net/mail/mailtypes.h
new file mode 100644
index 0000000..bb6a483
--- a/dev/null
+++ b/noncore/net/mail/mailtypes.h
@@ -0,0 +1,98 @@
1#ifndef __MAIL_TYPES_H
2#define __MAIL_TYPES_H
3
4#define FLAG_ANSWERED 0
5#define FLAG_FLAGGED 1
6#define FLAG_DELETED 2
7#define FLAG_SEEN 3
8#define FLAG_DRAFT 4
9#define FLAG_RECENT 5
10
11#include <qlist.h>
12#include <qbitarray.h>
13#include <qstring.h>
14#include <qstringlist.h>
15
16/* a class to describe mails in a mailbox */
17/* Attention!
18 From programmers point of view it would make sense to
19 store the mail body into this class, too.
20 But: not from the point of view of the device.
21 Mailbodies can be real large. So we request them when
22 needed from the mail-wrapper class direct from the server itself
23 (imap) or from a file-based cache (pop3?)
24 So there is no interface "const QString&body()" but you should
25 make a request to the mailwrapper with this class as parameter to
26 get the body. Same words for the attachments.
27*/
28class RecMail
29{
30public:
31 RecMail();
32 virtual ~RecMail(){}
33
34 const int getNumber()const{return msg_number;}
35 void setNumber(int number){msg_number=number;}
36 const QString&getDate()const{ return date; }
37 void setDate( const QString&a ) { date = a; }
38 const QString&getFrom()const{ return from; }
39 void setFrom( const QString&a ) { from = a; }
40 const QString&getSubject()const { return subject; }
41 void setSubject( const QString&s ) { subject = s; }
42 const QString&getMbox()const{return mbox;}
43 void setMbox(const QString&box){mbox = box;}
44
45 void setTo(const QStringList&list);
46 const QStringList&To()const;
47 void setCC(const QStringList&list);
48 const QStringList&CC()const;
49 void setBcc(const QStringList&list);
50 const QStringList&Bcc()const;
51
52 const QBitArray&getFlags()const{return msg_flags;}
53 void setFlags(const QBitArray&flags){msg_flags = flags;}
54
55protected:
56 QString subject,date,from,mbox;
57 int msg_number;
58 QBitArray msg_flags;
59 QStringList to,cc,bcc;
60};
61
62class RecPart
63{
64protected:
65 QString m_type,m_subtype,m_identifier,m_encoding;
66public:
67 RecPart();
68 RecPart(const QString&identifier,const QString&type="",const QString&subtype="",const QString&encoding="BASE64");
69 virtual ~RecPart();
70
71 const QString&Type()const;
72 void setType(const QString&type);
73 const QString&Subtype()const;
74 void setSubtype(const QString&subtype);
75 const QString&Identifier()const;
76 void setIdentifier(const QString&identifier);
77 const QString&Encoding()const;
78 void setEncoding(const QString&encoding);
79};
80
81class RecBody
82{
83protected:
84 QString m_BodyText;
85 QList<RecPart> m_PartsList;
86
87public:
88 RecBody();
89 virtual ~RecBody();
90 void setBodytext(const QString&);
91 const QString& Bodytext()const;
92
93 void setParts(const QList<RecPart>&parts);
94 const QList<RecPart>& Parts()const;
95 void addPart(const RecPart&part);
96};
97
98#endif
diff --git a/noncore/net/mail/mailwrapper.cpp b/noncore/net/mail/mailwrapper.cpp
index 7f67cd8..898e9d6 100644
--- a/noncore/net/mail/mailwrapper.cpp
+++ b/noncore/net/mail/mailwrapper.cpp
@@ -502,140 +502,128 @@ void MailWrapper::readFromFile( QString file, char **data, size_t *size )
502 count = read( fd, buf + total, st.st_size - total ); 502 count = read( fd, buf + total, st.st_size - total );
503 total += count; 503 total += count;
504 } 504 }
505 if ( count < 0 ) goto err_free; 505 if ( count < 0 ) goto err_free;
506 506
507 *data = buf; 507 *data = buf;
508 *size = st.st_size; 508 *size = st.st_size;
509 509
510 close( fd ); 510 close( fd );
511 511
512 return; // Success :) 512 return; // Success :)
513 513
514err_free: 514err_free:
515 free( buf ); 515 free( buf );
516err_close: 516err_close:
517 close( fd ); 517 close( fd );
518} 518}
519 519
520void progress( size_t current, size_t maximum ) 520void progress( size_t current, size_t maximum )
521{ 521{
522 qDebug( "Current: %i of %i", current, maximum ); 522 qDebug( "Current: %i of %i", current, maximum );
523} 523}
524 524
525void MailWrapper::smtpSend( mailmime *mail ) 525void MailWrapper::smtpSend( mailmime *mail )
526{ 526{
527 mailsmtp *session; 527 mailsmtp *session;
528 clist *rcpts; 528 clist *rcpts;
529 char *from, *data, *server, *user = NULL, *pass = NULL; 529 char *from, *data, *server, *user = NULL, *pass = NULL;
530 size_t size; 530 size_t size;
531 int err; 531 int err;
532 bool ssl; 532 bool ssl;
533 uint16_t port; 533 uint16_t port;
534 534
535 535
536 from = getFrom( mail ); 536 from = getFrom( mail );
537 SMTPaccount *smtp = getAccount( from ); 537 SMTPaccount *smtp = getAccount( from );
538 if ( smtp == NULL ) { 538 if ( smtp == NULL ) {
539 free(from); 539 free(from);
540 return; 540 return;
541 } 541 }
542 server = strdup( smtp->getServer().latin1() ); 542 server = strdup( smtp->getServer().latin1() );
543 ssl = smtp->getSSL(); 543 ssl = smtp->getSSL();
544 port = smtp->getPort().toUInt(); 544 port = smtp->getPort().toUInt();
545 rcpts = createRcptList( mail->fields ); 545 rcpts = createRcptList( mail->fields );
546 546
547 QString file = getTmpFile(); 547 QString file = getTmpFile();
548 writeToFile( file, mail ); 548 writeToFile( file, mail );
549 readFromFile( file, &data, &size ); 549 readFromFile( file, &data, &size );
550 QFile f( file ); 550 QFile f( file );
551 f.remove(); 551 f.remove();
552 552
553 session = mailsmtp_new( 20, &progress ); 553 session = mailsmtp_new( 20, &progress );
554 if ( session == NULL ) goto free_mem; 554 if ( session == NULL ) goto free_mem;
555 555
556 qDebug( "Servername %s at port %i", server, port ); 556 qDebug( "Servername %s at port %i", server, port );
557 if ( ssl ) { 557 if ( ssl ) {
558 qDebug( "SSL session" ); 558 qDebug( "SSL session" );
559 err = mailsmtp_ssl_connect( session, server, port ); 559 err = mailsmtp_ssl_connect( session, server, port );
560 } else { 560 } else {
561 qDebug( "No SSL session" ); 561 qDebug( "No SSL session" );
562 err = mailsmtp_socket_connect( session, server, port ); 562 err = mailsmtp_socket_connect( session, server, port );
563 } 563 }
564 if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; 564 if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session;
565 565
566 err = mailsmtp_init( session ); 566 err = mailsmtp_init( session );
567 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; 567 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session;
568 568
569 qDebug( "INIT OK" ); 569 qDebug( "INIT OK" );
570 570
571 if ( smtp->getLogin() ) { 571 if ( smtp->getLogin() ) {
572 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { 572 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
573 // get'em 573 // get'em
574 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); 574 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true );
575 login.show(); 575 login.show();
576 if ( QDialog::Accepted == login.exec() ) { 576 if ( QDialog::Accepted == login.exec() ) {
577 // ok 577 // ok
578 user = strdup( login.getUser().latin1() ); 578 user = strdup( login.getUser().latin1() );
579 pass = strdup( login.getPassword().latin1() ); 579 pass = strdup( login.getPassword().latin1() );
580 } else { 580 } else {
581 goto free_con_session; 581 goto free_con_session;
582 } 582 }
583 } else { 583 } else {
584 user = strdup( smtp->getUser().latin1() ); 584 user = strdup( smtp->getUser().latin1() );
585 pass = strdup( smtp->getPassword().latin1() ); 585 pass = strdup( smtp->getPassword().latin1() );
586 } 586 }
587 qDebug( "session->auth: %i", session->auth); 587 qDebug( "session->auth: %i", session->auth);
588 err = mailsmtp_auth( session, user, pass ); 588 err = mailsmtp_auth( session, user, pass );
589 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); 589 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
590 qDebug( "Done auth!" ); 590 qDebug( "Done auth!" );
591 } 591 }
592 592
593 err = mailsmtp_send( session, from, rcpts, data, size ); 593 err = mailsmtp_send( session, from, rcpts, data, size );
594 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; 594 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session;
595 595
596 qDebug( "Mail sent." ); 596 qDebug( "Mail sent." );
597 597
598free_con_session: 598free_con_session:
599 mailsmtp_quit( session ); 599 mailsmtp_quit( session );
600free_mem_session: 600free_mem_session:
601 mailsmtp_free( session ); 601 mailsmtp_free( session );
602free_mem: 602free_mem:
603 smtp_address_list_free( rcpts ); 603 smtp_address_list_free( rcpts );
604 free( data ); 604 free( data );
605 free( server ); 605 free( server );
606 if ( smtp->getLogin() ) { 606 if ( smtp->getLogin() ) {
607 free( user ); 607 free( user );
608 free( pass ); 608 free( pass );
609 } 609 }
610 free( from ); 610 free( from );
611} 611}
612 612
613void MailWrapper::sendMail( Mail mail ) 613void MailWrapper::sendMail( Mail mail )
614{ 614{
615 mailmime *mimeMail; 615 mailmime *mimeMail;
616 616
617 mimeMail = createMimeMail( &mail ); 617 mimeMail = createMimeMail( &mail );
618 if ( mimeMail == NULL ) { 618 if ( mimeMail == NULL ) {
619 qDebug( "sendMail: error creating mime mail" ); 619 qDebug( "sendMail: error creating mime mail" );
620 } else { 620 } else {
621 smtpSend( mimeMail ); 621 smtpSend( mimeMail );
622 mailmime_free( mimeMail ); 622 mailmime_free( mimeMail );
623 } 623 }
624} 624}
625 625
626Mail::Mail() 626Mail::Mail()
627 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") 627 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("")
628{ 628{
629} 629}
630
631RecMail::RecMail()
632 :subject(""),date(""),mbox(""),msg_number(0),msg_flags(7)
633{
634}
635
636#if 0
637void RecMail::setDate(const QString&aDate)
638{
639 mDate = QDateTime::fromString(aDate);
640}
641#endif
diff --git a/noncore/net/mail/mailwrapper.h b/noncore/net/mail/mailwrapper.h
index 332034f..34fd5c5 100644
--- a/noncore/net/mail/mailwrapper.h
+++ b/noncore/net/mail/mailwrapper.h
@@ -1,177 +1,123 @@
1#ifndef MAILWRAPPER_H 1#ifndef MAILWRAPPER_H
2#define MAILWRAPPER_H 2#define MAILWRAPPER_H
3 3
4#include <qpe/applnk.h> 4#include <qpe/applnk.h>
5 5
6#include <libetpan/mailmime.h> 6#include <libetpan/mailmime.h>
7#include <libetpan/mailimf.h> 7#include <libetpan/mailimf.h>
8#include <libetpan/mailsmtp.h> 8#include <libetpan/mailsmtp.h>
9#include <libetpan/mailstorage.h> 9#include <libetpan/mailstorage.h>
10#include <libetpan/maildriver.h> 10#include <libetpan/maildriver.h>
11#include <qbitarray.h> 11#include <qbitarray.h>
12#include <qdatetime.h> 12#include <qdatetime.h>
13 13
14#include "settings.h" 14#include "settings.h"
15 15
16class Attachment 16class Attachment
17{ 17{
18public: 18public:
19 Attachment( DocLnk lnk ); 19 Attachment( DocLnk lnk );
20 virtual ~Attachment(){} 20 virtual ~Attachment(){}
21 const QString getFileName()const{ return doc.file(); } 21 const QString getFileName()const{ return doc.file(); }
22 const QString getName()const{ return doc.name(); } 22 const QString getName()const{ return doc.name(); }
23 const QString getMimeType()const{ return doc.type(); } 23 const QString getMimeType()const{ return doc.type(); }
24 const QPixmap getPixmap()const{ return doc.pixmap(); } 24 const QPixmap getPixmap()const{ return doc.pixmap(); }
25 const int getSize()const { return size; } 25 const int getSize()const { return size; }
26 DocLnk getDocLnk() { return doc; } 26 DocLnk getDocLnk() { return doc; }
27 27
28protected: 28protected:
29 DocLnk doc; 29 DocLnk doc;
30 int size; 30 int size;
31 31
32}; 32};
33 33
34#define FLAG_ANSWERED 0
35#define FLAG_FLAGGED 1
36#define FLAG_DELETED 2
37#define FLAG_SEEN 3
38#define FLAG_DRAFT 4
39#define FLAG_RECENT 5
40
41/* a class to describe mails in a mailbox */
42/* Attention!
43 From programmers point of view it would make sense to
44 store the mail body into this class, too.
45 But: not from the point of view of the device.
46 Mailbodies can be real large. So we request them when
47 needed from the mail-wrapper class direct from the server itself
48 (imap) or from a file-based cache (pop3?)
49 So there is no interface "const QString&body()" but you should
50 make a request to the mailwrapper with this class as parameter to
51 get the body. Same words for the attachments.
52*/
53class RecMail
54{
55public:
56 RecMail();
57 virtual ~RecMail(){}
58
59 const int getNumber()const{return msg_number;}
60 void setNumber(int number){msg_number=number;}
61 const QString&getDate()const{ return date; }
62 void setDate( const QString&a ) { date = a; }
63 const QString&getFrom()const{ return from; }
64 void setFrom( const QString&a ) { from = a; }
65 const QString&getSubject()const { return subject; }
66 void setSubject( const QString&s ) { subject = s; }
67 const QString&getMbox()const{return mbox;}
68 void setMbox(const QString&box){mbox = box;}
69 const QBitArray&getFlags()const{return msg_flags;}
70 void setFlags(const QBitArray&flags){msg_flags = flags;}
71
72#if 0
73 void setDate(const QString&dstring);
74 void setDate(const QDateTime&date){mDate = date;}
75 QString getDate()const{return mDate.toString();}
76#endif
77protected:
78 QString subject,date,from,mbox;
79 int msg_number;
80 QBitArray msg_flags;
81#if 0
82 QDateTime mDate;
83#endif
84};
85
86typedef QList<RecMail> Maillist;
87
88class Mail 34class Mail
89{ 35{
90public: 36public:
91 Mail(); 37 Mail();
92 /* Possible that this destructor must not be declared virtual 38 /* Possible that this destructor must not be declared virtual
93 * 'cause it seems that it will never have some child classes. 39 * 'cause it seems that it will never have some child classes.
94 * in this case this object will not get a virtual table -> memory and 40 * in this case this object will not get a virtual table -> memory and
95 * speed will be a little bit better? 41 * speed will be a little bit better?
96 */ 42 */
97 virtual ~Mail(){} 43 virtual ~Mail(){}
98 void addAttachment( Attachment *att ) { attList.append( att ); } 44 void addAttachment( Attachment *att ) { attList.append( att ); }
99 const QList<Attachment>& getAttachments()const { return attList; } 45 const QList<Attachment>& getAttachments()const { return attList; }
100 void removeAttachment( Attachment *att ) { attList.remove( att ); } 46 void removeAttachment( Attachment *att ) { attList.remove( att ); }
101 const QString&getName()const { return name; } 47 const QString&getName()const { return name; }
102 void setName( QString s ) { name = s; } 48 void setName( QString s ) { name = s; }
103 const QString&getMail()const{ return mail; } 49 const QString&getMail()const{ return mail; }
104 void setMail( const QString&s ) { mail = s; } 50 void setMail( const QString&s ) { mail = s; }
105 const QString&getTo()const{ return to; } 51 const QString&getTo()const{ return to; }
106 void setTo( const QString&s ) { to = s; } 52 void setTo( const QString&s ) { to = s; }
107 const QString&getCC()const{ return cc; } 53 const QString&getCC()const{ return cc; }
108 void setCC( const QString&s ) { cc = s; } 54 void setCC( const QString&s ) { cc = s; }
109 const QString&getBCC()const { return bcc; } 55 const QString&getBCC()const { return bcc; }
110 void setBCC( const QString&s ) { bcc = s; } 56 void setBCC( const QString&s ) { bcc = s; }
111 const QString&getMessage()const { return message; } 57 const QString&getMessage()const { return message; }
112 void setMessage( const QString&s ) { message = s; } 58 void setMessage( const QString&s ) { message = s; }
113 const QString&getSubject()const { return subject; } 59 const QString&getSubject()const { return subject; }
114 void setSubject( const QString&s ) { subject = s; } 60 void setSubject( const QString&s ) { subject = s; }
115 const QString&getReply()const{ return reply; } 61 const QString&getReply()const{ return reply; }
116 void setReply( const QString&a ) { reply = a; } 62 void setReply( const QString&a ) { reply = a; }
117 63
118private: 64private:
119 QList<Attachment> attList; 65 QList<Attachment> attList;
120 QString name, mail, to, cc, bcc, reply, subject, message; 66 QString name, mail, to, cc, bcc, reply, subject, message;
121}; 67};
122 68
123class Folder : public QObject 69class Folder : public QObject
124{ 70{
125 Q_OBJECT 71 Q_OBJECT
126 72
127public: 73public:
128 Folder( const QString&init_name ); 74 Folder( const QString&init_name );
129 const QString&getDisplayName()const { return nameDisplay; } 75 const QString&getDisplayName()const { return nameDisplay; }
130 const QString&getName()const { return name; } 76 const QString&getName()const { return name; }
131 virtual bool may_select()const{return true;}; 77 virtual bool may_select()const{return true;};
132 78
133private: 79private:
134 QString nameDisplay, name; 80 QString nameDisplay, name;
135 81
136}; 82};
137 83
138class IMAPFolder : public Folder 84class IMAPFolder : public Folder
139{ 85{
140 public: 86 public:
141 IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {} 87 IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {}
142 virtual bool may_select()const{return m_MaySelect;} 88 virtual bool may_select()const{return m_MaySelect;}
143 private: 89 private:
144 bool m_MaySelect; 90 bool m_MaySelect;
145}; 91};
146 92
147class MailWrapper : public QObject 93class MailWrapper : public QObject
148{ 94{
149 Q_OBJECT 95 Q_OBJECT
150 96
151public: 97public:
152 MailWrapper( Settings *s ); 98 MailWrapper( Settings *s );
153 void sendMail( Mail mail ); 99 void sendMail( Mail mail );
154 100
155private: 101private:
156 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 102 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
157 mailimf_address_list *parseAddresses(const QString&addr ); 103 mailimf_address_list *parseAddresses(const QString&addr );
158 mailimf_fields *createImfFields( Mail *mail ); 104 mailimf_fields *createImfFields( Mail *mail );
159 mailmime *buildTxtPart( QString str ); 105 mailmime *buildTxtPart( QString str );
160 mailmime *buildFilePart( QString filename, QString mimetype ); 106 mailmime *buildFilePart( QString filename, QString mimetype );
161 void addFileParts( mailmime *message, QList<Attachment> files ); 107 void addFileParts( mailmime *message, QList<Attachment> files );
162 mailmime *createMimeMail( Mail *mail ); 108 mailmime *createMimeMail( Mail *mail );
163 void smtpSend( mailmime *mail ); 109 void smtpSend( mailmime *mail );
164 mailimf_field *getField( mailimf_fields *fields, int type ); 110 mailimf_field *getField( mailimf_fields *fields, int type );
165 clist *createRcptList( mailimf_fields *fields ); 111 clist *createRcptList( mailimf_fields *fields );
166 char *getFrom( mailmime *mail ); 112 char *getFrom( mailmime *mail );
167 SMTPaccount *getAccount( QString from ); 113 SMTPaccount *getAccount( QString from );
168 void writeToFile( QString file, mailmime *mail ); 114 void writeToFile( QString file, mailmime *mail );
169 void readFromFile( QString file, char **data, size_t *size ); 115 void readFromFile( QString file, char **data, size_t *size );
170 static QString mailsmtpError( int err ); 116 static QString mailsmtpError( int err );
171 static QString getTmpFile(); 117 static QString getTmpFile();
172 118
173 Settings *settings; 119 Settings *settings;
174 120
175}; 121};
176 122
177#endif 123#endif
diff --git a/noncore/net/mail/mainwindow.cpp b/noncore/net/mail/mainwindow.cpp
index 7af7d83..b25db97 100644
--- a/noncore/net/mail/mainwindow.cpp
+++ b/noncore/net/mail/mainwindow.cpp
@@ -1,171 +1,177 @@
1#include <qlabel.h> 1#include <qlabel.h>
2#include <qvbox.h> 2#include <qvbox.h>
3#include <qheader.h> 3#include <qheader.h>
4#include <qtimer.h> 4#include <qtimer.h>
5#include <qlayout.h> 5#include <qlayout.h>
6 6
7#include <qpe/qpeapplication.h> 7#include <qpe/qpeapplication.h>
8 8
9#include "defines.h" 9#include "defines.h"
10#include "mainwindow.h" 10#include "mainwindow.h"
11#include "viewmail.h" 11#include "viewmail.h"
12#include "mailtypes.h"
13#include "mailistviewitem.h"
12 14
13MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags ) 15MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags )
14 : QMainWindow( parent, name, flags ) 16 : QMainWindow( parent, name, flags )
15{ 17{
16 setCaption( tr( "Opie-Mail" ) ); 18 setCaption( tr( "Opie-Mail" ) );
17 setToolBarsMovable( false ); 19 setToolBarsMovable( false );
18 20
19 toolBar = new QToolBar( this ); 21 toolBar = new QToolBar( this );
20 menuBar = new QMenuBar( toolBar ); 22 menuBar = new QMenuBar( toolBar );
21 mailMenu = new QPopupMenu( menuBar ); 23 mailMenu = new QPopupMenu( menuBar );
22 menuBar->insertItem( tr( "Mail" ), mailMenu ); 24 menuBar->insertItem( tr( "Mail" ), mailMenu );
23 settingsMenu = new QPopupMenu( menuBar ); 25 settingsMenu = new QPopupMenu( menuBar );
24 menuBar->insertItem( tr( "Settings" ), settingsMenu ); 26 menuBar->insertItem( tr( "Settings" ), settingsMenu );
25 27
26 addToolBar( toolBar ); 28 addToolBar( toolBar );
27 toolBar->setHorizontalStretchable( true ); 29 toolBar->setHorizontalStretchable( true );
28 30
29 QLabel *spacer = new QLabel( toolBar ); 31 QLabel *spacer = new QLabel( toolBar );
30 spacer->setBackgroundMode( QWidget::PaletteButton ); 32 spacer->setBackgroundMode( QWidget::PaletteButton );
31 toolBar->setStretchableWidget( spacer ); 33 toolBar->setStretchableWidget( spacer );
32 34
33 composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL, 35 composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL,
34 0, 0, this ); 36 0, 0, this );
35 composeMail->addTo( toolBar ); 37 composeMail->addTo( toolBar );
36 composeMail->addTo( mailMenu ); 38 composeMail->addTo( mailMenu );
37 39
38 sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED, 40 sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED,
39 0, 0, this ); 41 0, 0, this );
40 sendQueued->addTo( toolBar ); 42 sendQueued->addTo( toolBar );
41 sendQueued->addTo( mailMenu ); 43 sendQueued->addTo( mailMenu );
42 44
43 syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC, 45 syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC,
44 0, 0, this ); 46 0, 0, this );
45 syncFolders->addTo( toolBar ); 47 syncFolders->addTo( toolBar );
46 syncFolders->addTo( mailMenu ); 48 syncFolders->addTo( mailMenu );
47 49
48 showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS, 50 showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS,
49 0, 0, this, 0, true ); 51 0, 0, this, 0, true );
50 showFolders->addTo( toolBar ); 52 showFolders->addTo( toolBar );
51 showFolders->addTo( mailMenu ); 53 showFolders->addTo( mailMenu );
52 connect(showFolders, SIGNAL( toggled( bool ) ), 54 connect(showFolders, SIGNAL( toggled( bool ) ),
53 SLOT( slotShowFolders( bool ) ) ); 55 SLOT( slotShowFolders( bool ) ) );
54 56
55 searchMails = new QAction( tr( "Search mails" ), ICON_SEARCHMAILS, 57 searchMails = new QAction( tr( "Search mails" ), ICON_SEARCHMAILS,
56 0, 0, this ); 58 0, 0, this );
57 searchMails->addTo( toolBar ); 59 searchMails->addTo( toolBar );
58 searchMails->addTo( mailMenu ); 60 searchMails->addTo( mailMenu );
59 61
60 62
61 editSettings = new QAction( tr( "Edit settings" ), ICON_EDITSETTINGS, 63 editSettings = new QAction( tr( "Edit settings" ), ICON_EDITSETTINGS,
62 0, 0, this ); 64 0, 0, this );
63 editSettings->addTo( settingsMenu ); 65 editSettings->addTo( settingsMenu );
64 66
65 editAccounts = new QAction( tr( "Configure accounts" ), ICON_EDITACCOUNTS, 67 editAccounts = new QAction( tr( "Configure accounts" ), ICON_EDITACCOUNTS,
66 0, 0, this ); 68 0, 0, this );
67 editAccounts->addTo( settingsMenu ); 69 editAccounts->addTo( settingsMenu );
68 70
69 QWidget *view = new QWidget( this ); 71 QWidget *view = new QWidget( this );
70 setCentralWidget( view ); 72 setCentralWidget( view );
71 73
72 74
73 QWidget *d = QApplication::desktop(); 75 QWidget *d = QApplication::desktop();
74 QBoxLayout *layout; 76 QBoxLayout *layout;
75 77
76 if ( d->width() < d->height() ) { 78 if ( d->width() < d->height() ) {
77 layout = new QVBoxLayout( view ); 79 layout = new QVBoxLayout( view );
78 } else { 80 } else {
79 layout = new QHBoxLayout( view ); 81 layout = new QHBoxLayout( view );
80 } 82 }
81 83
82 folderView = new AccountView( view ); 84 folderView = new AccountView( view );
83 folderView->header()->hide(); 85 folderView->header()->hide();
84 folderView->addColumn( tr( "Mailbox" ) ); 86 folderView->addColumn( tr( "Mailbox" ) );
85 folderView->hide(); 87 folderView->hide();
86 88
87 layout->addWidget( folderView ); 89 layout->addWidget( folderView );
88 90
89 mailView = new QListView( view ); 91 mailView = new QListView( view );
90 mailView->addColumn( tr( "Subject" ),QListView::Manual ); 92 mailView->addColumn( tr( "Subject" ),QListView::Manual );
91 mailView->addColumn( tr( "Sender" ),QListView::Manual ); 93 mailView->addColumn( tr( "Sender" ),QListView::Manual );
92 mailView->addColumn( tr( "Date" )); 94 mailView->addColumn( tr( "Date" ));
93 mailView->setAllColumnsShowFocus(true); 95 mailView->setAllColumnsShowFocus(true);
94 mailView->setSorting(-1); 96 mailView->setSorting(-1);
95 97
96 layout->addWidget( mailView ); 98 layout->addWidget( mailView );
97 layout->setStretchFactor( folderView, 1 ); 99 layout->setStretchFactor( folderView, 1 );
98 layout->setStretchFactor( mailView, 2 ); 100 layout->setStretchFactor( mailView, 2 );
99 101
100 connect( mailView, SIGNAL( clicked( QListViewItem * ) ),this, 102 connect( mailView, SIGNAL( clicked( QListViewItem * ) ),this,
101 SLOT( displayMail( QListViewItem * ) ) ); 103 SLOT( displayMail( QListViewItem * ) ) );
102 104
103 connect(folderView,SIGNAL(refreshMailview(Maillist*)),this,SLOT(refreshMailView(Maillist*))); 105 connect(folderView,SIGNAL(refreshMailview(QList<RecMail>*)),this,SLOT(refreshMailView(QList<RecMail>*)));
104 106
105 QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) ); 107 QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) );
106} 108}
107 109
108void MainWindow::slotAdjustColumns() 110void MainWindow::slotAdjustColumns()
109{ 111{
110 bool hidden = folderView->isHidden(); 112 bool hidden = folderView->isHidden();
111 if ( hidden ) folderView->show(); 113 if ( hidden ) folderView->show();
112 folderView->setColumnWidth( 0, folderView->visibleWidth() ); 114 folderView->setColumnWidth( 0, folderView->visibleWidth() );
113 if ( hidden ) folderView->hide(); 115 if ( hidden ) folderView->hide();
114 116
115 mailView->setColumnWidth( 0, mailView->visibleWidth() - 130 ); 117 mailView->setColumnWidth( 0, mailView->visibleWidth() - 130 );
116 mailView->setColumnWidth( 1, 80 ); 118 mailView->setColumnWidth( 1, 80 );
117 mailView->setColumnWidth( 2, 50 ); 119 mailView->setColumnWidth( 2, 50 );
118} 120}
119 121
120void MainWindow::slotShowFolders( bool show ) 122void MainWindow::slotShowFolders( bool show )
121{ 123{
122 qDebug( "Show Folders" ); 124 qDebug( "Show Folders" );
123 if ( show && folderView->isHidden() ) { 125 if ( show && folderView->isHidden() ) {
124 qDebug( "-> showing" ); 126 qDebug( "-> showing" );
125 folderView->show(); 127 folderView->show();
126 } else if ( !show && !folderView->isHidden() ) { 128 } else if ( !show && !folderView->isHidden() ) {
127 qDebug( "-> hiding" ); 129 qDebug( "-> hiding" );
128 folderView->hide(); 130 folderView->hide();
129 } 131 }
130} 132}
131 133
132void MainWindow::refreshMailView(Maillist*list) 134void MainWindow::refreshMailView(QList<RecMail>*list)
133{ 135{
134 MailListViewItem*item = 0; 136 MailListViewItem*item = 0;
135 mailView->clear(); 137 mailView->clear();
136#if 0
137 QFont f = mailView->getFont();
138 QFont bf = f;
139#endif
140 for (unsigned int i = 0; i < list->count();++i) { 138 for (unsigned int i = 0; i < list->count();++i) {
141 item = new MailListViewItem(mailView,item); 139 item = new MailListViewItem(mailView,item);
142 item->storeData(*(list->at(i))); 140 item->storeData(*(list->at(i)));
143 item->showEntry(); 141 item->showEntry();
144#if 0
145 if (!list->at(i)->getFlags().testBit(FLAG_SEEN)) {
146 item->setFont(bf);
147 }
148#endif
149 } 142 }
150} 143}
151void MainWindow::displayMail(QListViewItem*item) 144void MainWindow::displayMail(QListViewItem*item)
152{ 145{
153 if (!item) return; 146 if (!item) return;
154 qDebug("View mail"); 147 qDebug("View mail");
155 RecMail mail = ((MailListViewItem*)item)->data(); 148 RecMail mail = ((MailListViewItem*)item)->data();
156 QString body = folderView->fetchBody(mail); 149 RecBody body = folderView->fetchBody(mail);
157 150
158 ViewMail readMail( this ); 151 ViewMail readMail( this );
159 readMail.setMailInfo( mail.getFrom(), "", mail.getSubject(), "", "", body ); 152 readMail.setMailInfo( mail.getFrom(), "", mail.getSubject(), "", "", body.Bodytext() );
160 readMail.showMaximized(); 153 readMail.showMaximized();
161 readMail.exec(); 154 readMail.exec();
155}
162 156
163 qDebug(body ); 157MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * after )
158 :QListViewItem(parent,after),mail_data()
159{
164} 160}
165 161
166void MailListViewItem::showEntry() 162void MailListViewItem::showEntry()
167{ 163{
168 setText(0,mail_data.getSubject()); 164 setText(0,mail_data.getSubject());
169 setText(1,mail_data.getFrom()); 165 setText(1,mail_data.getFrom());
170 setText(2,mail_data.getDate()); 166 setText(2,mail_data.getDate());
171} 167}
168
169void MailListViewItem::storeData(const RecMail&data)
170{
171 mail_data = data;
172}
173
174const RecMail& MailListViewItem::data()const
175{
176 return mail_data;
177}
diff --git a/noncore/net/mail/mainwindow.h b/noncore/net/mail/mainwindow.h
index a5142ab..6c87261 100644
--- a/noncore/net/mail/mainwindow.h
+++ b/noncore/net/mail/mainwindow.h
@@ -1,54 +1,41 @@
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;
14
13class MainWindow : public QMainWindow 15class MainWindow : public QMainWindow
14{ 16{
15 Q_OBJECT 17 Q_OBJECT
16 18
17public: 19public:
18 MainWindow( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 20 MainWindow( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
19 21
20public slots: 22public slots:
21 void slotAdjustColumns(); 23 void slotAdjustColumns();
22 24
23protected slots: 25protected slots:
24 virtual void slotShowFolders( bool show ); 26 virtual void slotShowFolders( bool show );
25 virtual void refreshMailView(Maillist*); 27 virtual void refreshMailView(QList<RecMail>*);
26 virtual void displayMail(QListViewItem*); 28 virtual void displayMail(QListViewItem*);
27 29
28protected: 30protected:
29 QToolBar *toolBar; 31 QToolBar *toolBar;
30 QMenuBar *menuBar; 32 QMenuBar *menuBar;
31 QPopupMenu *mailMenu, *settingsMenu; 33 QPopupMenu *mailMenu, *settingsMenu;
32 QAction *composeMail, *sendQueued, *showFolders, *searchMails, 34 QAction *composeMail, *sendQueued, *showFolders, *searchMails,
33 *editSettings, *editAccounts, *syncFolders; 35 *editSettings, *editAccounts, *syncFolders;
34 AccountView *folderView; 36 AccountView *folderView;
35 QListView *mailView; 37 QListView *mailView;
36 38
37}; 39};
38 40
39class MailListViewItem:public QListViewItem
40{
41public:
42 MailListViewItem(QListView * parent, MailListViewItem * after )
43 :QListViewItem(parent,after),mail_data(){}
44 virtual ~MailListViewItem(){}
45
46 void storeData(const RecMail&data){mail_data = data;}
47 const RecMail&data()const{return mail_data;}
48 void showEntry();
49
50protected:
51 RecMail mail_data;
52};
53
54#endif 41#endif