summaryrefslogtreecommitdiff
authoralwin <alwin>2004-01-04 16:33:39 (UTC)
committer alwin <alwin>2004-01-04 16:33:39 (UTC)
commit6ee1d5d35243f611e0a848d454bfa309b8de0fc9 (patch) (unidiff)
treea07cc2d85da3df79904f363da262834f64b64736
parent59fee003137f5fd7782e3a42159e53424d100e67 (diff)
downloadopie-6ee1d5d35243f611e0a848d454bfa309b8de0fc9.zip
opie-6ee1d5d35243f611e0a848d454bfa309b8de0fc9.tar.gz
opie-6ee1d5d35243f611e0a848d454bfa309b8de0fc9.tar.bz2
- added start of status class
- unification of (public) mailwrapper interfaces - preparition for message store/transfer
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.h12
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.h3
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp15
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h5
-rw-r--r--noncore/net/mail/libmailwrapper/libmailwrapper.pro16
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp8
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h4
7 files changed, 46 insertions, 17 deletions
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h
index ca9caed..a070fb0 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.h
+++ b/noncore/net/mail/libmailwrapper/abstractmail.h
@@ -1,55 +1,57 @@
1#ifndef __abstract_mail_ 1#ifndef __abstract_mail_
2#define __abstract_mail_ 2#define __abstract_mail_
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include "settings.h" 5#include "settings.h"
6 6
7class RecMail; 7class RecMail;
8class RecBody; 8class RecBody;
9class RecPart; 9class RecPart;
10class IMAPwrapper; 10class IMAPwrapper;
11class POP3wrapper; 11class POP3wrapper;
12class Folder; 12class Folder;
13class encodedString; 13class encodedString;
14struct folderStat; 14struct folderStat;
15 15
16class AbstractMail:public QObject 16class AbstractMail:public QObject
17{ 17{
18 Q_OBJECT 18 Q_OBJECT
19public: 19public:
20 AbstractMail(){}; 20 AbstractMail(){};
21 virtual ~AbstractMail(){} 21 virtual ~AbstractMail(){}
22 virtual QList<Folder>* listFolders()=0; 22 virtual QList<Folder>* listFolders()=0;
23 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; 23 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0; 24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0;
25 virtual RecBody fetchBody(const RecMail&mail)=0; 25 virtual RecBody fetchBody(const RecMail&mail)=0;
26 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; 26 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
27 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; 27 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
28 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; 28 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
29 29
30 virtual void deleteMail(const RecMail&mail)=0; 30 virtual void deleteMail(const RecMail&mail)=0;
31 virtual void answeredMail(const RecMail&mail)=0; 31 virtual void answeredMail(const RecMail&mail)=0;
32 virtual void cleanMimeCache(){}; 32 virtual int deleteAllMail(const Folder*)=0;
33 virtual int deleteAllMail(const Folder*){return 1;} 33 virtual int deleteMbox(const Folder*)=0;
34 virtual int deleteMbox(const Folder*){return 1;} 34 virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0;
35 35
36 virtual void cleanMimeCache(){};
36 /* mail box methods */ 37 /* mail box methods */
37 /* parameter is the box to create. 38 /* parameter is the box to create.
38 * if the implementing subclass has prefixes, 39 * if the implementing subclass has prefixes,
39 * them has to be appended automatic. 40 * them has to be appended automatic.
40 */ 41 */
41 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); 42 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
42 43 virtual void logout()=0;
44
43 static AbstractMail* getWrapper(IMAPaccount *a); 45 static AbstractMail* getWrapper(IMAPaccount *a);
44 static AbstractMail* getWrapper(POP3account *a); 46 static AbstractMail* getWrapper(POP3account *a);
45 /* mbox only! */ 47 /* mbox only! */
46 static AbstractMail* getWrapper(const QString&a); 48 static AbstractMail* getWrapper(const QString&a);
47 49
48 static QString defaultLocalfolder(); 50 static QString defaultLocalfolder();
49 51
50protected: 52protected:
51 static encodedString*decode_String(const encodedString*text,const QString&enc); 53 static encodedString*decode_String(const encodedString*text,const QString&enc);
52 static QString convert_String(const char*text); 54 static QString convert_String(const char*text);
53 static QString gen_attachment_id(); 55 static QString gen_attachment_id();
54}; 56};
55#endif 57#endif
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.h b/noncore/net/mail/libmailwrapper/genericwrapper.h
index 32b75c8..1d65c0a 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.h
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.h
@@ -1,59 +1,62 @@
1#ifndef __GENERIC_WRAPPER_H 1#ifndef __GENERIC_WRAPPER_H
2#define __GENERIC_WRAPPER_H 2#define __GENERIC_WRAPPER_H
3 3
4#include "abstractmail.h" 4#include "abstractmail.h"
5#include <qmap.h> 5#include <qmap.h>
6#include <qstring.h> 6#include <qstring.h>
7#include <libetpan/clist.h> 7#include <libetpan/clist.h>
8 8
9class RecMail; 9class RecMail;
10class RecBody; 10class RecBody;
11class encodedString; 11class encodedString;
12struct mailpop3; 12struct mailpop3;
13struct mailmessage; 13struct mailmessage;
14struct mailmime; 14struct mailmime;
15struct mailmime_mechanism; 15struct mailmime_mechanism;
16struct mailimf_mailbox_list; 16struct mailimf_mailbox_list;
17struct mailimf_mailbox; 17struct mailimf_mailbox;
18struct mailimf_date_time; 18struct mailimf_date_time;
19struct mailimf_group; 19struct mailimf_group;
20struct mailimf_address_list; 20struct mailimf_address_list;
21struct mailsession; 21struct mailsession;
22 22
23/* this class hold just the funs shared between 23/* this class hold just the funs shared between
24 * mbox and pop3 (later mh, too) mail access. 24 * mbox and pop3 (later mh, too) mail access.
25 * it is not desigend to make a instance of it! 25 * it is not desigend to make a instance of it!
26 */ 26 */
27class Genericwrapper : public AbstractMail 27class Genericwrapper : public AbstractMail
28{ 28{
29 Q_OBJECT 29 Q_OBJECT
30public: 30public:
31 Genericwrapper(); 31 Genericwrapper();
32 virtual ~Genericwrapper(); 32 virtual ~Genericwrapper();
33 33
34 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 34 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
35 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 35 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
36 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 36 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
37 virtual void cleanMimeCache(); 37 virtual void cleanMimeCache();
38 virtual int deleteMbox(const Folder*){return 1;}
39 virtual void logout(){};
40 virtual void storeMessage(const char*msg,size_t length, const QString&folder){};
38 41
39protected: 42protected:
40 RecMail *parseHeader( const char *header ); 43 RecMail *parseHeader( const char *header );
41 RecBody parseMail( mailmessage * msg ); 44 RecBody parseMail( mailmessage * msg );
42 QString parseMailboxList( mailimf_mailbox_list *list ); 45 QString parseMailboxList( mailimf_mailbox_list *list );
43 QString parseMailbox( mailimf_mailbox *box ); 46 QString parseMailbox( mailimf_mailbox *box );
44 QString parseGroup( mailimf_group *group ); 47 QString parseGroup( mailimf_group *group );
45 QString parseAddressList( mailimf_address_list *list ); 48 QString parseAddressList( mailimf_address_list *list );
46 QString parseDateTime( mailimf_date_time *date ); 49 QString parseDateTime( mailimf_date_time *date );
47 50
48 void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=1); 51 void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=1);
49 static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); 52 static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime);
50 static void fillParameters(RecPart&target,clist*parameters); 53 static void fillParameters(RecPart&target,clist*parameters);
51 static QString getencoding(mailmime_mechanism*aEnc); 54 static QString getencoding(mailmime_mechanism*aEnc);
52 virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox); 55 virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox);
53 56
54 QString msgTempName; 57 QString msgTempName;
55 unsigned int last_msg_id; 58 unsigned int last_msg_id;
56 QMap<QString,encodedString*> bodyCache; 59 QMap<QString,encodedString*> bodyCache;
57}; 60};
58 61
59#endif 62#endif
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index f1d42c2..0c1e05e 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,243 +1,243 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <libetpan/libetpan.h> 2#include <libetpan/libetpan.h>
3#include <qpe/global.h> 3#include <qpe/global.h>
4 4
5#include "imapwrapper.h" 5#include "imapwrapper.h"
6#include "mailtypes.h" 6#include "mailtypes.h"
7#include "logindialog.h" 7#include "logindialog.h"
8 8
9IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 9IMAPwrapper::IMAPwrapper( IMAPaccount *a )
10 : AbstractMail() 10 : AbstractMail()
11{ 11{
12 account = a; 12 account = a;
13 m_imap = 0; 13 m_imap = 0;
14} 14}
15 15
16IMAPwrapper::~IMAPwrapper() 16IMAPwrapper::~IMAPwrapper()
17{ 17{
18 logout(); 18 logout();
19} 19}
20 20
21void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 21void IMAPwrapper::imap_progress( size_t current, size_t maximum )
22{ 22{
23 qDebug( "IMAP: %i of %i", current, maximum ); 23 qDebug( "IMAP: %i of %i", current, maximum );
24} 24}
25 25
26void IMAPwrapper::login() 26void IMAPwrapper::login()
27{ 27{
28 const char *server, *user, *pass; 28 const char *server, *user, *pass;
29 uint16_t port; 29 uint16_t port;
30 int err = MAILIMAP_NO_ERROR; 30 int err = MAILIMAP_NO_ERROR;
31 31
32 /* we are connected this moment */ 32 /* we are connected this moment */
33 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 33 /* TODO: setup a timer holding the line or if connection closed - delete the value */
34 if (m_imap) { 34 if (m_imap) {
35 err = mailimap_noop(m_imap); 35 err = mailimap_noop(m_imap);
36 if (err!=MAILIMAP_NO_ERROR) { 36 if (err!=MAILIMAP_NO_ERROR) {
37 logout(); 37 logout();
38 } else { 38 } else {
39 mailstream_flush(m_imap->imap_stream); 39 mailstream_flush(m_imap->imap_stream);
40 return; 40 return;
41 } 41 }
42 } 42 }
43 server = account->getServer().latin1(); 43 server = account->getServer().latin1();
44 port = account->getPort().toUInt(); 44 port = account->getPort().toUInt();
45 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 45 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
46 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 46 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
47 login.show(); 47 login.show();
48 if ( QDialog::Accepted == login.exec() ) { 48 if ( QDialog::Accepted == login.exec() ) {
49 // ok 49 // ok
50 user = strdup( login.getUser().latin1() ); 50 user = login.getUser().latin1();
51 pass = strdup( login.getPassword().latin1() ); 51 pass = login.getPassword().latin1();
52 } else { 52 } else {
53 // cancel 53 // cancel
54 qDebug( "IMAP: Login canceled" ); 54 qDebug( "IMAP: Login canceled" );
55 return; 55 return;
56 } 56 }
57 } else { 57 } else {
58 user = account->getUser().latin1(); 58 user = account->getUser().latin1();
59 pass = account->getPassword().latin1(); 59 pass = account->getPassword().latin1();
60 } 60 }
61 61
62 m_imap = mailimap_new( 20, &imap_progress ); 62 m_imap = mailimap_new( 20, &imap_progress );
63 63
64 /* connect */ 64 /* connect */
65 if (account->getSSL()) { 65 if (account->getSSL()) {
66 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 66 err = mailimap_ssl_connect( m_imap, (char*)server, port );
67 } else { 67 } else {
68 err = mailimap_socket_connect( m_imap, (char*)server, port ); 68 err = mailimap_socket_connect( m_imap, (char*)server, port );
69 } 69 }
70 70
71 if ( err != MAILIMAP_NO_ERROR && 71 if ( err != MAILIMAP_NO_ERROR &&
72 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 72 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
73 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 73 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
74 QString failure = ""; 74 QString failure = "";
75 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 75 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
76 failure="Connection refused"; 76 failure="Connection refused";
77 } else { 77 } else {
78 failure="Unknown failure"; 78 failure="Unknown failure";
79 } 79 }
80 Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); 80 Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
81 mailimap_free( m_imap ); 81 mailimap_free( m_imap );
82 m_imap = 0; 82 m_imap = 0;
83 return; 83 return;
84 } 84 }
85 85
86 /* login */ 86 /* login */
87 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 87 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
88 if ( err != MAILIMAP_NO_ERROR ) { 88 if ( err != MAILIMAP_NO_ERROR ) {
89 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); 89 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
90 err = mailimap_close( m_imap ); 90 err = mailimap_close( m_imap );
91 mailimap_free( m_imap ); 91 mailimap_free( m_imap );
92 m_imap = 0; 92 m_imap = 0;
93 } 93 }
94} 94}
95 95
96void IMAPwrapper::logout() 96void IMAPwrapper::logout()
97{ 97{
98 int err = MAILIMAP_NO_ERROR; 98 int err = MAILIMAP_NO_ERROR;
99 if (!m_imap) return; 99 if (!m_imap) return;
100 err = mailimap_logout( m_imap ); 100 err = mailimap_logout( m_imap );
101 err = mailimap_close( m_imap ); 101 err = mailimap_close( m_imap );
102 mailimap_free( m_imap ); 102 mailimap_free( m_imap );
103 m_imap = 0; 103 m_imap = 0;
104} 104}
105 105
106void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 106void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
107{ 107{
108 const char *mb = 0; 108 const char *mb = 0;
109 int err = MAILIMAP_NO_ERROR; 109 int err = MAILIMAP_NO_ERROR;
110 clist *result = 0; 110 clist *result = 0;
111 clistcell *current; 111 clistcell *current;
112// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 112// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
113 mailimap_fetch_type *fetchType = 0; 113 mailimap_fetch_type *fetchType = 0;
114 mailimap_set *set = 0; 114 mailimap_set *set = 0;
115 115
116 mb = mailbox.latin1(); 116 mb = mailbox.latin1();
117 login(); 117 login();
118 if (!m_imap) { 118 if (!m_imap) {
119 return; 119 return;
120 } 120 }
121 /* select mailbox READONLY for operations */ 121 /* select mailbox READONLY for operations */
122 err = mailimap_examine( m_imap, (char*)mb); 122 err = mailimap_examine( m_imap, (char*)mb);
123 if ( err != MAILIMAP_NO_ERROR ) { 123 if ( err != MAILIMAP_NO_ERROR ) {
124 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response)); 124 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response));
125 return; 125 return;
126 } 126 }
127 127
128 int last = m_imap->imap_selection_info->sel_exists; 128 int last = m_imap->imap_selection_info->sel_exists;
129 129
130 if (last == 0) { 130 if (last == 0) {
131 Global::statusMessage(tr("Mailbox has no mails")); 131 Global::statusMessage(tr("Mailbox has no mails"));
132 return; 132 return;
133 } else { 133 } else {
134 Global::statusMessage(tr("Mailbox has %1 mails").arg(last)); 134 Global::statusMessage(tr("Mailbox has %1 mails").arg(last));
135 } 135 }
136 136
137 /* the range has to start at 1!!! not with 0!!!! */ 137 /* the range has to start at 1!!! not with 0!!!! */
138 set = mailimap_set_new_interval( 1, last ); 138 set = mailimap_set_new_interval( 1, last );
139 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 139 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
140 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 140 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
141 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 141 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
142 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 142 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
143 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 143 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
144 144
145 err = mailimap_fetch( m_imap, set, fetchType, &result ); 145 err = mailimap_fetch( m_imap, set, fetchType, &result );
146 mailimap_set_free( set ); 146 mailimap_set_free( set );
147 mailimap_fetch_type_free( fetchType ); 147 mailimap_fetch_type_free( fetchType );
148 148
149 QString date,subject,from; 149 QString date,subject,from;
150 150
151 if ( err == MAILIMAP_NO_ERROR ) { 151 if ( err == MAILIMAP_NO_ERROR ) {
152 mailimap_msg_att * msg_att; 152 mailimap_msg_att * msg_att;
153 int i = 0; 153 int i = 0;
154 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 154 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
155 ++i; 155 ++i;
156 msg_att = (mailimap_msg_att*)current->data; 156 msg_att = (mailimap_msg_att*)current->data;
157 RecMail*m = parse_list_result(msg_att); 157 RecMail*m = parse_list_result(msg_att);
158 if (m) { 158 if (m) {
159 m->setNumber(i); 159 m->setNumber(i);
160 m->setMbox(mailbox); 160 m->setMbox(mailbox);
161 m->setWrapper(this); 161 m->setWrapper(this);
162 target.append(m); 162 target.append(m);
163 } 163 }
164 } 164 }
165 } else { 165 } else {
166 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); 166 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
167 } 167 }
168 if (result) mailimap_fetch_list_free(result); 168 if (result) mailimap_fetch_list_free(result);
169} 169}
170 170
171QList<Folder>* IMAPwrapper::listFolders() 171QList<Folder>* IMAPwrapper::listFolders()
172{ 172{
173 const char *path, *mask; 173 const char *path, *mask;
174 int err = MAILIMAP_NO_ERROR; 174 int err = MAILIMAP_NO_ERROR;
175 clist *result = 0; 175 clist *result = 0;
176 clistcell *current = 0; 176 clistcell *current = 0;
177 clistcell*cur_flag = 0; 177 clistcell*cur_flag = 0;
178 mailimap_mbx_list_flags*bflags = 0; 178 mailimap_mbx_list_flags*bflags = 0;
179 179
180 QList<Folder> * folders = new QList<Folder>(); 180 QList<Folder> * folders = new QList<Folder>();
181 folders->setAutoDelete( false ); 181 folders->setAutoDelete( false );
182 login(); 182 login();
183 if (!m_imap) { 183 if (!m_imap) {
184 return folders; 184 return folders;
185 } 185 }
186 186
187/* 187/*
188 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 188 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
189 * We must not forget to filter them out in next loop! 189 * We must not forget to filter them out in next loop!
190 * it seems like ugly code. and yes - it is ugly code. but the best way. 190 * it seems like ugly code. and yes - it is ugly code. but the best way.
191 */ 191 */
192 QString temp; 192 QString temp;
193 mask = "INBOX" ; 193 mask = "INBOX" ;
194 mailimap_mailbox_list *list; 194 mailimap_mailbox_list *list;
195 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 195 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
196 QString del; 196 QString del;
197 bool selectable = true; 197 bool selectable = true;
198 bool no_inferiors = false; 198 bool no_inferiors = false;
199 if ( err == MAILIMAP_NO_ERROR ) { 199 if ( err == MAILIMAP_NO_ERROR ) {
200 current = result->first; 200 current = result->first;
201 for ( int i = result->count; i > 0; i-- ) { 201 for ( int i = result->count; i > 0; i-- ) {
202 list = (mailimap_mailbox_list *) current->data; 202 list = (mailimap_mailbox_list *) current->data;
203 // it is better use the deep copy mechanism of qt itself 203 // it is better use the deep copy mechanism of qt itself
204 // instead of using strdup! 204 // instead of using strdup!
205 temp = list->mb_name; 205 temp = list->mb_name;
206 del = list->mb_delimiter; 206 del = list->mb_delimiter;
207 current = current->next; 207 current = current->next;
208 if ( (bflags = list->mb_flag) ) { 208 if ( (bflags = list->mb_flag) ) {
209 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 209 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
210 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 210 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
211 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 211 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
212 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 212 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
213 no_inferiors = true; 213 no_inferiors = true;
214 } 214 }
215 } 215 }
216 } 216 }
217 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 217 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
218 } 218 }
219 } else { 219 } else {
220 qDebug("error fetching folders: %s",m_imap->imap_response); 220 qDebug("error fetching folders: %s",m_imap->imap_response);
221 } 221 }
222 mailimap_list_result_free( result ); 222 mailimap_list_result_free( result );
223 223
224/* 224/*
225 * second stage - get the other then inbox folders 225 * second stage - get the other then inbox folders
226 */ 226 */
227 mask = "*" ; 227 mask = "*" ;
228 path = account->getPrefix().latin1(); 228 path = account->getPrefix().latin1();
229 if (!path) path = ""; 229 if (!path) path = "";
230 qDebug(path); 230 qDebug(path);
231 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 231 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
232 if ( err == MAILIMAP_NO_ERROR ) { 232 if ( err == MAILIMAP_NO_ERROR ) {
233 current = result->first; 233 current = result->first;
234 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 234 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
235 no_inferiors = false; 235 no_inferiors = false;
236 list = (mailimap_mailbox_list *) current->data; 236 list = (mailimap_mailbox_list *) current->data;
237 // it is better use the deep copy mechanism of qt itself 237 // it is better use the deep copy mechanism of qt itself
238 // instead of using strdup! 238 // instead of using strdup!
239 temp = list->mb_name; 239 temp = list->mb_name;
240 if (temp.lower()=="inbox") 240 if (temp.lower()=="inbox")
241 continue; 241 continue;
242 if (temp.lower()==account->getPrefix().lower()) 242 if (temp.lower()==account->getPrefix().lower())
243 continue; 243 continue;
@@ -785,192 +785,203 @@ void IMAPwrapper::deleteMail(const RecMail&mail)
785 if (err != MAILIMAP_NO_ERROR) { 785 if (err != MAILIMAP_NO_ERROR) {
786 qDebug("error deleting mail: %s",m_imap->imap_response); 786 qDebug("error deleting mail: %s",m_imap->imap_response);
787 } 787 }
788 qDebug("Delete successfull %s",m_imap->imap_response); 788 qDebug("Delete successfull %s",m_imap->imap_response);
789} 789}
790 790
791void IMAPwrapper::answeredMail(const RecMail&mail) 791void IMAPwrapper::answeredMail(const RecMail&mail)
792{ 792{
793 mailimap_flag_list*flist; 793 mailimap_flag_list*flist;
794 mailimap_set *set; 794 mailimap_set *set;
795 mailimap_store_att_flags * store_flags; 795 mailimap_store_att_flags * store_flags;
796 int err; 796 int err;
797 login(); 797 login();
798 if (!m_imap) { 798 if (!m_imap) {
799 return; 799 return;
800 } 800 }
801 const char *mb = mail.getMbox().latin1(); 801 const char *mb = mail.getMbox().latin1();
802 err = mailimap_select( m_imap, (char*)mb); 802 err = mailimap_select( m_imap, (char*)mb);
803 if ( err != MAILIMAP_NO_ERROR ) { 803 if ( err != MAILIMAP_NO_ERROR ) {
804 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); 804 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response);
805 return; 805 return;
806 } 806 }
807 flist = mailimap_flag_list_new_empty(); 807 flist = mailimap_flag_list_new_empty();
808 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 808 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
809 store_flags = mailimap_store_att_flags_new_add_flags(flist); 809 store_flags = mailimap_store_att_flags_new_add_flags(flist);
810 set = mailimap_set_new_single(mail.getNumber()); 810 set = mailimap_set_new_single(mail.getNumber());
811 err = mailimap_store(m_imap,set,store_flags); 811 err = mailimap_store(m_imap,set,store_flags);
812 mailimap_set_free( set ); 812 mailimap_set_free( set );
813 mailimap_store_att_flags_free(store_flags); 813 mailimap_store_att_flags_free(store_flags);
814 814
815 if (err != MAILIMAP_NO_ERROR) { 815 if (err != MAILIMAP_NO_ERROR) {
816 qDebug("error marking mail: %s",m_imap->imap_response); 816 qDebug("error marking mail: %s",m_imap->imap_response);
817 return; 817 return;
818 } 818 }
819} 819}
820 820
821QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 821QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
822{ 822{
823 QString body(""); 823 QString body("");
824 encodedString*res = fetchRawPart(mail,path,internal_call); 824 encodedString*res = fetchRawPart(mail,path,internal_call);
825 encodedString*r = decode_String(res,enc); 825 encodedString*r = decode_String(res,enc);
826 delete res; 826 delete res;
827 if (r) { 827 if (r) {
828 if (r->Length()>0) { 828 if (r->Length()>0) {
829 body = r->Content(); 829 body = r->Content();
830 } 830 }
831 delete r; 831 delete r;
832 } 832 }
833 return body; 833 return body;
834} 834}
835 835
836QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 836QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
837{ 837{
838 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); 838 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
839} 839}
840 840
841encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) 841encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
842{ 842{
843 encodedString*res = fetchRawPart(mail,part.Positionlist(),false); 843 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
844 encodedString*r = decode_String(res,part.Encoding()); 844 encodedString*r = decode_String(res,part.Encoding());
845 delete res; 845 delete res;
846 return r; 846 return r;
847} 847}
848 848
849encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 849encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
850{ 850{
851 return fetchRawPart(mail,part.Positionlist(),false); 851 return fetchRawPart(mail,part.Positionlist(),false);
852} 852}
853 853
854int IMAPwrapper::deleteAllMail(const Folder*folder) 854int IMAPwrapper::deleteAllMail(const Folder*folder)
855{ 855{
856 login(); 856 login();
857 if (!m_imap) { 857 if (!m_imap) {
858 return 0; 858 return 0;
859 } 859 }
860 mailimap_flag_list*flist; 860 mailimap_flag_list*flist;
861 mailimap_set *set; 861 mailimap_set *set;
862 mailimap_store_att_flags * store_flags; 862 mailimap_store_att_flags * store_flags;
863 int err = mailimap_select( m_imap, folder->getName().latin1()); 863 int err = mailimap_select( m_imap, folder->getName().latin1());
864 if ( err != MAILIMAP_NO_ERROR ) { 864 if ( err != MAILIMAP_NO_ERROR ) {
865 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response)); 865 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response));
866 return 0; 866 return 0;
867 } 867 }
868 int last = m_imap->imap_selection_info->sel_exists; 868 int last = m_imap->imap_selection_info->sel_exists;
869 if (last == 0) { 869 if (last == 0) {
870 Global::statusMessage(tr("Mailbox has no mails!")); 870 Global::statusMessage(tr("Mailbox has no mails!"));
871 return 0; 871 return 0;
872 } 872 }
873 flist = mailimap_flag_list_new_empty(); 873 flist = mailimap_flag_list_new_empty();
874 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 874 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
875 store_flags = mailimap_store_att_flags_new_set_flags(flist); 875 store_flags = mailimap_store_att_flags_new_set_flags(flist);
876 set = mailimap_set_new_interval( 1, last ); 876 set = mailimap_set_new_interval( 1, last );
877 err = mailimap_store(m_imap,set,store_flags); 877 err = mailimap_store(m_imap,set,store_flags);
878 mailimap_set_free( set ); 878 mailimap_set_free( set );
879 mailimap_store_att_flags_free(store_flags); 879 mailimap_store_att_flags_free(store_flags);
880 if (err != MAILIMAP_NO_ERROR) { 880 if (err != MAILIMAP_NO_ERROR) {
881 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 881 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
882 return 0; 882 return 0;
883 } 883 }
884 qDebug("deleting mail: %s",m_imap->imap_response); 884 qDebug("deleting mail: %s",m_imap->imap_response);
885 /* should we realy do that at this moment? */ 885 /* should we realy do that at this moment? */
886 err = mailimap_expunge(m_imap); 886 err = mailimap_expunge(m_imap);
887 if (err != MAILIMAP_NO_ERROR) { 887 if (err != MAILIMAP_NO_ERROR) {
888 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 888 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
889 return 0; 889 return 0;
890 } 890 }
891 qDebug("Delete successfull %s",m_imap->imap_response); 891 qDebug("Delete successfull %s",m_imap->imap_response);
892 return 1; 892 return 1;
893} 893}
894 894
895int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) 895int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder)
896{ 896{
897 if (folder.length()==0) return 0; 897 if (folder.length()==0) return 0;
898 login(); 898 login();
899 if (!m_imap) {return 0;} 899 if (!m_imap) {return 0;}
900 QString pre = account->getPrefix(); 900 QString pre = account->getPrefix();
901 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { 901 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
902 pre+=delemiter; 902 pre+=delemiter;
903 } 903 }
904 if (parentfolder) { 904 if (parentfolder) {
905 pre += parentfolder->getDisplayName()+delemiter; 905 pre += parentfolder->getDisplayName()+delemiter;
906 } 906 }
907 pre+=folder; 907 pre+=folder;
908 if (getsubfolder) { 908 if (getsubfolder) {
909 if (delemiter.length()>0) { 909 if (delemiter.length()>0) {
910 pre+=delemiter; 910 pre+=delemiter;
911 } else { 911 } else {
912 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); 912 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre));
913 return 0; 913 return 0;
914 } 914 }
915 } 915 }
916 qDebug("Creating %s",pre.latin1()); 916 qDebug("Creating %s",pre.latin1());
917 int res = mailimap_create(m_imap,pre.latin1()); 917 int res = mailimap_create(m_imap,pre.latin1());
918 if (res != MAILIMAP_NO_ERROR) { 918 if (res != MAILIMAP_NO_ERROR) {
919 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 919 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
920 return 0; 920 return 0;
921 } 921 }
922 return 1; 922 return 1;
923} 923}
924 924
925int IMAPwrapper::deleteMbox(const Folder*folder) 925int IMAPwrapper::deleteMbox(const Folder*folder)
926{ 926{
927 if (!folder) return 0; 927 if (!folder) return 0;
928 login(); 928 login();
929 if (!m_imap) {return 0;} 929 if (!m_imap) {return 0;}
930 int res = mailimap_delete(m_imap,folder->getName()); 930 int res = mailimap_delete(m_imap,folder->getName());
931 if (res != MAILIMAP_NO_ERROR) { 931 if (res != MAILIMAP_NO_ERROR) {
932 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 932 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
933 return 0; 933 return 0;
934 } 934 }
935 return 1; 935 return 1;
936} 936}
937 937
938void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 938void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
939{ 939{
940 mailimap_status_att_list * att_list =0; 940 mailimap_status_att_list * att_list =0;
941 mailimap_mailbox_data_status * status=0; 941 mailimap_mailbox_data_status * status=0;
942 clistiter * cur = 0; 942 clistiter * cur = 0;
943 int r = 0; 943 int r = 0;
944 int res = 0; 944 int res = 0;
945 target_stat.message_count = 0; 945 target_stat.message_count = 0;
946 target_stat.message_unseen = 0; 946 target_stat.message_unseen = 0;
947 target_stat.message_recent = 0; 947 target_stat.message_recent = 0;
948 login(); 948 login();
949 if (!m_imap) { 949 if (!m_imap) {
950 return; 950 return;
951 } 951 }
952 att_list = mailimap_status_att_list_new_empty(); 952 att_list = mailimap_status_att_list_new_empty();
953 if (!att_list) return; 953 if (!att_list) return;
954 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 954 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
955 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 955 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
956 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 956 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
957 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 957 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
958 for (cur = clist_begin(status->st_info_list); 958 for (cur = clist_begin(status->st_info_list);
959 cur != NULL ; cur = clist_next(cur)) { 959 cur != NULL ; cur = clist_next(cur)) {
960 mailimap_status_info * status_info; 960 mailimap_status_info * status_info;
961 status_info = (mailimap_status_info *)clist_content(cur); 961 status_info = (mailimap_status_info *)clist_content(cur);
962 switch (status_info->st_att) { 962 switch (status_info->st_att) {
963 case MAILIMAP_STATUS_ATT_MESSAGES: 963 case MAILIMAP_STATUS_ATT_MESSAGES:
964 target_stat.message_count = status_info->st_value; 964 target_stat.message_count = status_info->st_value;
965 break; 965 break;
966 case MAILIMAP_STATUS_ATT_RECENT: 966 case MAILIMAP_STATUS_ATT_RECENT:
967 target_stat.message_recent = status_info->st_value; 967 target_stat.message_recent = status_info->st_value;
968 break; 968 break;
969 case MAILIMAP_STATUS_ATT_UNSEEN: 969 case MAILIMAP_STATUS_ATT_UNSEEN:
970 target_stat.message_unseen = status_info->st_value; 970 target_stat.message_unseen = status_info->st_value;
971 break; 971 break;
972 } 972 }
973 } 973 }
974 mailimap_mailbox_data_status_free(status); 974 mailimap_mailbox_data_status_free(status);
975 mailimap_status_att_list_free(att_list); 975 mailimap_status_att_list_free(att_list);
976} 976}
977
978void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
979{
980 login();
981 if (!m_imap) return;
982 if (!msg) return;
983 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
984 if (r != MAILIMAP_NO_ERROR) {
985 Global::statusMessage("Error storing mail!");
986 }
987}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index 8f5a2b5..a97f12d 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -1,68 +1,69 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "abstractmail.h" 6#include "abstractmail.h"
7#include <libetpan/clist.h> 7#include <libetpan/clist.h>
8 8
9struct mailimap; 9struct mailimap;
10struct mailimap_body; 10struct mailimap_body;
11struct mailimap_body_type_1part; 11struct mailimap_body_type_1part;
12struct mailimap_body_type_text; 12struct mailimap_body_type_text;
13struct mailimap_body_type_basic; 13struct mailimap_body_type_basic;
14struct mailimap_body_type_msg; 14struct mailimap_body_type_msg;
15struct mailimap_body_type_mpart; 15struct mailimap_body_type_mpart;
16struct mailimap_body_fields; 16struct mailimap_body_fields;
17struct mailimap_msg_att; 17struct mailimap_msg_att;
18class encodedString; 18class encodedString;
19 19
20class IMAPwrapper : public AbstractMail 20class IMAPwrapper : public AbstractMail
21{ 21{
22 Q_OBJECT 22 Q_OBJECT
23public: 23public:
24 IMAPwrapper( IMAPaccount *a ); 24 IMAPwrapper( IMAPaccount *a );
25 virtual ~IMAPwrapper(); 25 virtual ~IMAPwrapper();
26 virtual QList<Folder>* listFolders(); 26 virtual QList<Folder>* listFolders();
27 virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); 27 virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
29 29
30 virtual void deleteMail(const RecMail&mail); 30 virtual void deleteMail(const RecMail&mail);
31 virtual void answeredMail(const RecMail&mail); 31 virtual void answeredMail(const RecMail&mail);
32 virtual int deleteAllMail(const Folder*folder); 32 virtual int deleteAllMail(const Folder*folder);
33 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
33 34
34 virtual RecBody fetchBody(const RecMail&mail); 35 virtual RecBody fetchBody(const RecMail&mail);
35 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 36 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
36 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 37 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
37 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 38 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
38 39
39 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); 40 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
40 virtual int deleteMbox(const Folder*folder); 41 virtual int deleteMbox(const Folder*folder);
41 42
42 static void imap_progress( size_t current, size_t maximum ); 43 static void imap_progress( size_t current, size_t maximum );
43 44
45 virtual void logout();
44protected: 46protected:
45 RecMail*parse_list_result(mailimap_msg_att*); 47 RecMail*parse_list_result(mailimap_msg_att*);
46 void login(); 48 void login();
47 void logout();
48 49
49 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); 50 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
50 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); 51 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call);
51 52
52 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 53 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
53 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 54 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
54 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 55 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
55 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); 56 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
56 void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which); 57 void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which);
57 void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1); 58 void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1);
58 59
59 /* just helpers */ 60 /* just helpers */
60 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 61 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
61 static QStringList address_list_to_stringlist(clist*list); 62 static QStringList address_list_to_stringlist(clist*list);
62 63
63 64
64 IMAPaccount *account; 65 IMAPaccount *account;
65 mailimap *m_imap; 66 mailimap *m_imap;
66}; 67};
67 68
68#endif 69#endif
diff --git a/noncore/net/mail/libmailwrapper/libmailwrapper.pro b/noncore/net/mail/libmailwrapper/libmailwrapper.pro
index 4b4a4f1..18583bb 100644
--- a/noncore/net/mail/libmailwrapper/libmailwrapper.pro
+++ b/noncore/net/mail/libmailwrapper/libmailwrapper.pro
@@ -1,44 +1,46 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on debug 2CONFIG += qt warn_on debug
3 3
4HEADERS = mailwrapper.h \ 4HEADERS = mailwrapper.h \
5 imapwrapper.h \ 5 imapwrapper.h \
6 mailtypes.h \ 6 mailtypes.h \
7 pop3wrapper.h \ 7 pop3wrapper.h \
8 abstractmail.h \ 8 abstractmail.h \
9 smtpwrapper.h \ 9 smtpwrapper.h \
10 genericwrapper.h \ 10 genericwrapper.h \
11 mboxwrapper.h \ 11 mboxwrapper.h \
12 settings.h \ 12 settings.h \
13 logindialog.h \ 13 logindialog.h \
14 sendmailprogress.h 14 sendmailprogress.h \
15 statusmail.h
15 16
16SOURCES = imapwrapper.cpp \ 17SOURCES = imapwrapper.cpp \
17 mailwrapper.cpp \ 18 mailwrapper.cpp \
18 mailtypes.cpp \ 19 mailtypes.cpp \
19 pop3wrapper.cpp \ 20 pop3wrapper.cpp \
20 abstractmail.cpp \ 21 abstractmail.cpp \
21 smtpwrapper.cpp \ 22 smtpwrapper.cpp \
22 genericwrapper.cpp \ 23 genericwrapper.cpp \
23 mboxwrapper.cpp \ 24 mboxwrapper.cpp \
24 settings.cpp \ 25 settings.cpp \
25 logindialog.cpp \ 26 logindialog.cpp \
26 sendmailprogress.cpp 27 sendmailprogress.cpp \
28 statusmail.cpp
27 29
28 INTERFACES = logindialogui.ui \ 30 INTERFACES = logindialogui.ui \
29 sendmailprogressui.ui 31 sendmailprogressui.ui
30 32
31 33
32INCLUDEPATH += $(OPIEDIR)/include 34INCLUDEPATH += $(OPIEDIR)/include
33 35
34CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX ) 36CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX )
35contains( CONFTEST, y ){ 37contains( CONFTEST, y ){
36 LIBS += -lqpe -letpan -lssl -lcrypto -liconv 38 LIBS += -lqpe -letpan -lssl -lcrypto -liconv
37}else{ 39}else{
38 LIBS += -lqpe -letpan -lssl -lcrypto 40 LIBS += -lqpe -letpan -lssl -lcrypto
39} 41}
40 42
41DESTDIR = $(OPIEDIR)/lib$(PROJMAK) 43DESTDIR = $(OPIEDIR)/lib$(PROJMAK)
42TARGET = mailwrapper 44TARGET = mailwrapper
43 45
44include ( $(OPIEDIR)/include.pro ) 46include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index d76d82a..b4eca6f 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -38,192 +38,200 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail )
38{ 38{
39 int err = MAILPOP3_NO_ERROR; 39 int err = MAILPOP3_NO_ERROR;
40 char *message = 0; 40 char *message = 0;
41 size_t length = 0; 41 size_t length = 0;
42 42
43 login(); 43 login();
44 if ( !m_pop3 ) { 44 if ( !m_pop3 ) {
45 return RecBody(); 45 return RecBody();
46 } 46 }
47 47
48 RecBody body; 48 RecBody body;
49 mailmessage * mailmsg; 49 mailmessage * mailmsg;
50 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { 50 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
51 qDebug("Message to large: %i",mail.Msgsize()); 51 qDebug("Message to large: %i",mail.Msgsize());
52 return body; 52 return body;
53 } 53 }
54 54
55 QFile msg_cache(msgTempName); 55 QFile msg_cache(msgTempName);
56 56
57 cleanMimeCache(); 57 cleanMimeCache();
58 58
59 if (mail.getNumber()!=last_msg_id) { 59 if (mail.getNumber()!=last_msg_id) {
60 if (msg_cache.exists()) { 60 if (msg_cache.exists()) {
61 msg_cache.remove(); 61 msg_cache.remove();
62 } 62 }
63 msg_cache.open(IO_ReadWrite|IO_Truncate); 63 msg_cache.open(IO_ReadWrite|IO_Truncate);
64 last_msg_id = mail.getNumber(); 64 last_msg_id = mail.getNumber();
65 err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); 65 err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg);
66 err = mailmessage_fetch(mailmsg,&message,&length); 66 err = mailmessage_fetch(mailmsg,&message,&length);
67 msg_cache.writeBlock(message,length); 67 msg_cache.writeBlock(message,length);
68 } else { 68 } else {
69 QString msg=""; 69 QString msg="";
70 msg_cache.open(IO_ReadOnly); 70 msg_cache.open(IO_ReadOnly);
71 message = new char[4096]; 71 message = new char[4096];
72 memset(message,0,4096); 72 memset(message,0,4096);
73 while (msg_cache.readBlock(message,4095)>0) { 73 while (msg_cache.readBlock(message,4095)>0) {
74 msg+=message; 74 msg+=message;
75 memset(message,0,4096); 75 memset(message,0,4096);
76 } 76 }
77 delete message; 77 delete message;
78 message = (char*)malloc(msg.length()+1*sizeof(char)); 78 message = (char*)malloc(msg.length()+1*sizeof(char));
79 memset(message,0,msg.length()+1); 79 memset(message,0,msg.length()+1);
80 memcpy(message,msg.latin1(),msg.length()); 80 memcpy(message,msg.latin1(),msg.length());
81 /* transform to libetpan stuff */ 81 /* transform to libetpan stuff */
82 mailmsg = mailmessage_new(); 82 mailmsg = mailmessage_new();
83 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 83 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
84 generic_message_t * msg_data; 84 generic_message_t * msg_data;
85 msg_data = (generic_message_t *)mailmsg->msg_data; 85 msg_data = (generic_message_t *)mailmsg->msg_data;
86 msg_data->msg_fetched = 1; 86 msg_data->msg_fetched = 1;
87 msg_data->msg_message = message; 87 msg_data->msg_message = message;
88 msg_data->msg_length = strlen(message); 88 msg_data->msg_length = strlen(message);
89 } 89 }
90 body = parseMail(mailmsg); 90 body = parseMail(mailmsg);
91 91
92 /* clean up */ 92 /* clean up */
93 if (mailmsg) mailmessage_free(mailmsg); 93 if (mailmsg) mailmessage_free(mailmsg);
94 if (message) free(message); 94 if (message) free(message);
95 95
96 return body; 96 return body;
97} 97}
98 98
99void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 99void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
100{ 100{
101 login(); 101 login();
102 if (!m_pop3) return; 102 if (!m_pop3) return;
103 uint32_t res_messages,res_recent,res_unseen; 103 uint32_t res_messages,res_recent,res_unseen;
104 mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen); 104 mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen);
105 parseList(target,m_folder->fld_session,"INBOX"); 105 parseList(target,m_folder->fld_session,"INBOX");
106 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); 106 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages));
107} 107}
108 108
109void POP3wrapper::login() 109void POP3wrapper::login()
110{ 110{
111 /* we'll hold the line */ 111 /* we'll hold the line */
112 if ( m_pop3 != NULL ) return; 112 if ( m_pop3 != NULL ) return;
113 113
114 const char *server, *user, *pass; 114 const char *server, *user, *pass;
115 uint16_t port; 115 uint16_t port;
116 int err = MAILPOP3_NO_ERROR; 116 int err = MAILPOP3_NO_ERROR;
117 117
118 server = account->getServer().latin1(); 118 server = account->getServer().latin1();
119 port = account->getPort().toUInt(); 119 port = account->getPort().toUInt();
120 120
121 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 121 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
122 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 122 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
123 login.show(); 123 login.show();
124 if ( QDialog::Accepted == login.exec() ) { 124 if ( QDialog::Accepted == login.exec() ) {
125 // ok 125 // ok
126 user = login.getUser().latin1(); 126 user = login.getUser().latin1();
127 pass = login.getPassword().latin1(); 127 pass = login.getPassword().latin1();
128 } else { 128 } else {
129 // cancel 129 // cancel
130 qDebug( "POP3: Login canceled" ); 130 qDebug( "POP3: Login canceled" );
131 return; 131 return;
132 } 132 }
133 } else { 133 } else {
134 user = account->getUser().latin1(); 134 user = account->getUser().latin1();
135 pass = account->getPassword().latin1(); 135 pass = account->getPassword().latin1();
136 } 136 }
137 137
138 bool ssl = account->getSSL(); 138 bool ssl = account->getSSL();
139 139
140 m_pop3=mailstorage_new(NULL); 140 m_pop3=mailstorage_new(NULL);
141 pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,CONNECTION_TYPE_TRY_STARTTLS,POP3_AUTH_TYPE_TRY_APOP, 141 pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,CONNECTION_TYPE_TRY_STARTTLS,POP3_AUTH_TYPE_TRY_APOP,
142 (char*)user,(char*)pass,0,0,0); 142 (char*)user,(char*)pass,0,0,0);
143 143
144 m_folder = mailfolder_new(m_pop3, NULL, NULL); 144 m_folder = mailfolder_new(m_pop3, NULL, NULL);
145 145
146 if (m_folder==0) { 146 if (m_folder==0) {
147 Global::statusMessage(tr("Error initializing folder")); 147 Global::statusMessage(tr("Error initializing folder"));
148 mailstorage_free(m_pop3); 148 mailstorage_free(m_pop3);
149 m_pop3 = NULL; 149 m_pop3 = NULL;
150 return; 150 return;
151 } 151 }
152 err = mailfolder_connect(m_folder); 152 err = mailfolder_connect(m_folder);
153 if (err != MAIL_NO_ERROR) { 153 if (err != MAIL_NO_ERROR) {
154 Global::statusMessage(tr("Error initializing folder")); 154 Global::statusMessage(tr("Error initializing folder"));
155 mailfolder_free(m_folder); 155 mailfolder_free(m_folder);
156 m_folder = 0; 156 m_folder = 0;
157 mailstorage_free(m_pop3); 157 mailstorage_free(m_pop3);
158 m_pop3 = 0; 158 m_pop3 = 0;
159 } 159 }
160 qDebug( "POP3: logged in!" ); 160 qDebug( "POP3: logged in!" );
161} 161}
162 162
163void POP3wrapper::logout() 163void POP3wrapper::logout()
164{ 164{
165 int err = MAILPOP3_NO_ERROR; 165 int err = MAILPOP3_NO_ERROR;
166 if ( m_pop3 == NULL ) return; 166 if ( m_pop3 == NULL ) return;
167 mailfolder_free(m_folder); 167 mailfolder_free(m_folder);
168 m_folder = 0; 168 m_folder = 0;
169 mailstorage_free(m_pop3); 169 mailstorage_free(m_pop3);
170 m_pop3 = 0; 170 m_pop3 = 0;
171} 171}
172 172
173 173
174QList<Folder>* POP3wrapper::listFolders() 174QList<Folder>* POP3wrapper::listFolders()
175{ 175{
176 QList<Folder> * folders = new QList<Folder>(); 176 QList<Folder> * folders = new QList<Folder>();
177 folders->setAutoDelete( false ); 177 folders->setAutoDelete( false );
178 Folder*inb=new Folder("INBOX","/"); 178 Folder*inb=new Folder("INBOX","/");
179 folders->append(inb); 179 folders->append(inb);
180 return folders; 180 return folders;
181} 181}
182 182
183void POP3wrapper::deleteMail(const RecMail&mail) 183void POP3wrapper::deleteMail(const RecMail&mail)
184{ 184{
185 login(); 185 login();
186 if (!m_pop3) return; 186 if (!m_pop3) return;
187 int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber()); 187 int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber());
188 if (err != MAIL_NO_ERROR) { 188 if (err != MAIL_NO_ERROR) {
189 Global::statusMessage(tr("error deleting mail")); 189 Global::statusMessage(tr("error deleting mail"));
190 } 190 }
191} 191}
192 192
193void POP3wrapper::answeredMail(const RecMail&) 193void POP3wrapper::answeredMail(const RecMail&)
194{ 194{
195} 195}
196 196
197int POP3wrapper::deleteAllMail(const Folder*) 197int POP3wrapper::deleteAllMail(const Folder*)
198{ 198{
199 login(); 199 login();
200 if (!m_pop3) return 0; 200 if (!m_pop3) return 0;
201 int res = 1; 201 int res = 1;
202 202
203 uint32_t result = 0; 203 uint32_t result = 0;
204 int err = mailsession_messages_number(m_folder->fld_session,NULL,&result); 204 int err = mailsession_messages_number(m_folder->fld_session,NULL,&result);
205 if (err != MAIL_NO_ERROR) { 205 if (err != MAIL_NO_ERROR) {
206 Global::statusMessage(tr("Error getting folder info")); 206 Global::statusMessage(tr("Error getting folder info"));
207 return 0; 207 return 0;
208 } 208 }
209 for (unsigned int i = 0; i < result; ++i) { 209 for (unsigned int i = 0; i < result; ++i) {
210 err = mailsession_remove_message(m_folder->fld_session,i+1); 210 err = mailsession_remove_message(m_folder->fld_session,i+1);
211 if (err != MAIL_NO_ERROR) { 211 if (err != MAIL_NO_ERROR) {
212 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 212 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
213 res=0; 213 res=0;
214 } 214 }
215 break; 215 break;
216 } 216 }
217 return res; 217 return res;
218} 218}
219 219
220void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) 220void POP3wrapper::statusFolder(folderStat&target_stat,const QString&)
221{ 221{
222 login(); 222 login();
223 target_stat.message_count = 0; 223 target_stat.message_count = 0;
224 target_stat.message_unseen = 0; 224 target_stat.message_unseen = 0;
225 target_stat.message_recent = 0; 225 target_stat.message_recent = 0;
226 if (!m_pop3) return; 226 if (!m_pop3) return;
227 int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count, 227 int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count,
228 &target_stat.message_recent,&target_stat.message_unseen); 228 &target_stat.message_recent,&target_stat.message_unseen);
229} 229}
230
231void POP3wrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length)
232{
233 mailmessage * mailmsg = 0;
234 int err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg);
235 err = mailmessage_fetch(mailmsg,target,length);
236 if (mailmsg) mailmessage_free(mailmsg);
237}
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h
index 536cadc..9cba101 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.h
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h
@@ -1,39 +1,41 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include "genericwrapper.h" 5#include "genericwrapper.h"
6#include <qstring.h> 6#include <qstring.h>
7 7
8struct mailstorage; 8struct mailstorage;
9struct mailfolder; 9struct mailfolder;
10 10
11class POP3wrapper : public Genericwrapper 11class POP3wrapper : public Genericwrapper
12{ 12{
13 Q_OBJECT 13 Q_OBJECT
14 14
15public: 15public:
16 POP3wrapper( POP3account *a ); 16 POP3wrapper( POP3account *a );
17 virtual ~POP3wrapper(); 17 virtual ~POP3wrapper();
18 /* mailbox will be ignored */ 18 /* mailbox will be ignored */
19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
20 virtual QList<Folder>* listFolders(); 20 virtual QList<Folder>* listFolders();
21 /* mailbox will be ignored */ 21 /* mailbox will be ignored */
22 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 22 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
23 23
24 virtual void deleteMail(const RecMail&mail); 24 virtual void deleteMail(const RecMail&mail);
25 virtual void answeredMail(const RecMail&mail); 25 virtual void answeredMail(const RecMail&mail);
26 virtual int deleteAllMail(const Folder*); 26 virtual int deleteAllMail(const Folder*);
27 27
28 virtual RecBody fetchBody( const RecMail &mail ); 28 virtual RecBody fetchBody( const RecMail &mail );
29 virtual void fetchRawBody(const RecMail&mail,char**target,size_t*length);
30 virtual void logout();
31
29 static void pop3_progress( size_t current, size_t maximum ); 32 static void pop3_progress( size_t current, size_t maximum );
30 33
31protected: 34protected:
32 void login(); 35 void login();
33 void logout();
34 POP3account *account; 36 POP3account *account;
35 mailstorage*m_pop3; 37 mailstorage*m_pop3;
36 mailfolder*m_folder; 38 mailfolder*m_folder;
37}; 39};
38 40
39#endif 41#endif