summaryrefslogtreecommitdiff
authorjgf <jgf>2003-12-11 17:21:41 (UTC)
committer jgf <jgf>2003-12-11 17:21:41 (UTC)
commitefa09eadddc16220cc1e8a55da93115538b091bb (patch) (unidiff)
treef8186f84bd107c388507cc6a69ce5f6ce1aaccc9
parenta54fcb766991ed3d813be5f0b066998082378933 (diff)
downloadopie-efa09eadddc16220cc1e8a55da93115538b091bb.zip
opie-efa09eadddc16220cc1e8a55da93115538b091bb.tar.gz
opie-efa09eadddc16220cc1e8a55da93115538b091bb.tar.bz2
fetchBody in POP3 & weird segfault
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/accountview.cpp6
-rw-r--r--noncore/net/mail/accountview.h2
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp111
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h13
-rw-r--r--noncore/net/mail/pop3wrapper.cpp111
-rw-r--r--noncore/net/mail/pop3wrapper.h13
6 files changed, 158 insertions, 98 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp
index 6963027..c7b1eeb 100644
--- a/noncore/net/mail/accountview.cpp
+++ b/noncore/net/mail/accountview.cpp
@@ -17,36 +17,36 @@ POP3viewItem::POP3viewItem( POP3account *a, QListView *parent )
17 setPixmap( 0, PIXMAP_POP3FOLDER ); 17 setPixmap( 0, PIXMAP_POP3FOLDER );
18 setText( 0, account->getAccountName() ); 18 setText( 0, account->getAccountName() );
19} 19}
20 20
21POP3viewItem::~POP3viewItem() 21POP3viewItem::~POP3viewItem()
22{ 22{
23 delete wrapper; 23 delete wrapper;
24} 24}
25 25
26void POP3viewItem::refresh( QList<RecMail> &target ) 26void POP3viewItem::refresh( QList<RecMail> &target )
27{ 27{
28 qDebug( "POP3: refresh" ); 28 qDebug( "POP3: refresh" );
29 wrapper->listMessages( target ); 29 wrapper->listMessages( target );
30} 30}
31 31
32 32
33RecBody POP3viewItem::fetchBody( const RecMail & ) 33RecBody POP3viewItem::fetchBody( const RecMail &mail )
34{ 34{
35 qDebug( "POP3 fetchBody: IMPLEMENT ME!!" ); 35 qDebug( "POP3 fetchBody" );
36 return RecBody(); 36 return wrapper->fetchBody( mail );
37} 37}
38 38
39/** 39/**
40 * IMAP Account stuff 40 * IMAP Account stuff
41 */ 41 */
42 42
43IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent ) 43IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent )
44 : AccountViewItem( parent ) 44 : AccountViewItem( parent )
45{ 45{
46 account = a; 46 account = a;
47 wrapper = new IMAPwrapper( account ); 47 wrapper = new IMAPwrapper( account );
48 setPixmap( 0, PIXMAP_IMAPFOLDER ); 48 setPixmap( 0, PIXMAP_IMAPFOLDER );
49 setText( 0, account->getAccountName() ); 49 setText( 0, account->getAccountName() );
50 setOpen( true ); 50 setOpen( true );
51} 51}
52 52
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h
index fe832ec..4cac673 100644
--- a/noncore/net/mail/accountview.h
+++ b/noncore/net/mail/accountview.h
@@ -16,33 +16,33 @@ class AccountViewItem : public QListViewItem
16{ 16{
17 17
18public: 18public:
19 AccountViewItem( QListView *parent ) : QListViewItem( parent ) {} 19 AccountViewItem( QListView *parent ) : QListViewItem( parent ) {}
20 AccountViewItem( QListViewItem *parent ) : QListViewItem( parent ) {} 20 AccountViewItem( QListViewItem *parent ) : QListViewItem( parent ) {}
21 virtual void refresh(QList<RecMail>&)=0; 21 virtual void refresh(QList<RecMail>&)=0;
22 virtual RecBody fetchBody(const RecMail&)=0; 22 virtual RecBody fetchBody(const RecMail&)=0;
23}; 23};
24 24
25class POP3viewItem : public AccountViewItem 25class POP3viewItem : public AccountViewItem
26{ 26{
27 27
28public: 28public:
29 POP3viewItem( POP3account *a, QListView *parent ); 29 POP3viewItem( POP3account *a, QListView *parent );
30 ~POP3viewItem(); 30 ~POP3viewItem();
31 virtual void refresh( QList<RecMail> &target ); 31 virtual void refresh( QList<RecMail> &target );
32 virtual RecBody fetchBody(const RecMail & ); 32 virtual RecBody fetchBody( const RecMail &mail );
33 33
34private: 34private:
35 POP3account *account; 35 POP3account *account;
36 POP3wrapper *wrapper; 36 POP3wrapper *wrapper;
37 37
38}; 38};
39 39
40class IMAPviewItem : public AccountViewItem 40class IMAPviewItem : public AccountViewItem
41{ 41{
42 42
43public: 43public:
44 IMAPviewItem( IMAPaccount *a, QListView *parent ); 44 IMAPviewItem( IMAPaccount *a, QListView *parent );
45 ~IMAPviewItem(); 45 ~IMAPviewItem();
46 virtual void refresh(QList<RecMail>&); 46 virtual void refresh(QList<RecMail>&);
47 virtual RecBody fetchBody(const RecMail&); 47 virtual RecBody fetchBody(const RecMail&);
48 IMAPwrapper *getWrapper(); 48 IMAPwrapper *getWrapper();
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 633faf6..abb5a42 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -6,32 +6,72 @@
6POP3wrapper::POP3wrapper( POP3account *a ) 6POP3wrapper::POP3wrapper( POP3account *a )
7{ 7{
8 account = a; 8 account = a;
9 m_pop3 = NULL; 9 m_pop3 = NULL;
10} 10}
11 11
12POP3wrapper::~POP3wrapper() 12POP3wrapper::~POP3wrapper()
13{ 13{
14 logout(); 14 logout();
15} 15}
16 16
17void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 17void POP3wrapper::pop3_progress( size_t current, size_t maximum )
18{ 18{
19 qDebug( "POP3: %i of %i", current, maximum ); 19 qDebug( "POP3: %i of %i", current, maximum );
20} 20}
21 21
22RecBody POP3wrapper::fetchBody( const RecMail &mail )
23{
24 int err = MAILPOP3_NO_ERROR;
25 char *message;
26 size_t length;
27
28 login();
29 if ( !m_pop3 ) return RecBody();
30
31 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
32 if ( err != MAILPOP3_NO_ERROR ) {
33 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
34 logout();
35 return RecBody();
36 }
37
38 logout();
39
40 return parseBody( message );
41}
42
43RecBody POP3wrapper::parseBody( const char *message )
44{
45 int err = MAILIMF_NO_ERROR;
46 size_t curTok;
47 mailimf_message *result;
48 RecBody body;
49
50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
51 if ( err != MAILIMF_NO_ERROR ) return body;
52
53 if ( result && result->msg_body && result->msg_body->bd_text ) {
54 qDebug( "POP3: bodytext found" );
55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan.
56 body.setBodytext( QString( result->msg_body->bd_text ) );
57 }
58
59 return body;
60}
61
22void POP3wrapper::listMessages( QList<RecMail> &target ) 62void POP3wrapper::listMessages( QList<RecMail> &target )
23{ 63{
24 int err = MAILPOP3_NO_ERROR; 64 int err = MAILPOP3_NO_ERROR;
25 char *header; 65 char *header;
26 size_t length; 66 size_t length;
27 carray *messages; 67 carray *messages;
28 68
29 login(); 69 login();
30 if (!m_pop3) return; 70 if (!m_pop3) return;
31 mailpop3_list( m_pop3, &messages ); 71 mailpop3_list( m_pop3, &messages );
32 72
33 for ( int i = carray_count( messages ); i > 0; i-- ) { 73 for ( int i = carray_count( messages ); i > 0; i-- ) {
34 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); 74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 );
35 75
36 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
37 if ( err != MAILPOP3_NO_ERROR ) { 77 if ( err != MAILPOP3_NO_ERROR ) {
@@ -46,156 +86,144 @@ void POP3wrapper::listMessages( QList<RecMail> &target )
46 86
47 logout(); 87 logout();
48} 88}
49 89
50RecMail *POP3wrapper::parseHeader( const char *header ) 90RecMail *POP3wrapper::parseHeader( const char *header )
51{ 91{
52 int err = MAILIMF_NO_ERROR; 92 int err = MAILIMF_NO_ERROR;
53 size_t curTok; 93 size_t curTok;
54 RecMail *mail = new RecMail(); 94 RecMail *mail = new RecMail();
55 mailimf_fields *fields; 95 mailimf_fields *fields;
56 96
57 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 97 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
58 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 98 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
59 mailimf_field *field = (mailimf_field *) current->data; 99 mailimf_field *field = (mailimf_field *) current->data;
60 switch ( field->fld_type ) { 100 switch ( field->fld_type ) {
61 case MAILIMF_FIELD_FROM: 101 case MAILIMF_FIELD_FROM:
62 mail->setFrom( *parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 102 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
63 break; 103 break;
64 case MAILIMF_FIELD_TO: 104 case MAILIMF_FIELD_TO:
65 mail->setTo( *parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 105 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
66 break; 106 break;
67 case MAILIMF_FIELD_CC: 107 case MAILIMF_FIELD_CC:
68 mail->setCC( *parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 108 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
69 break; 109 break;
70 case MAILIMF_FIELD_BCC: 110 case MAILIMF_FIELD_BCC:
71 mail->setBcc( *parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 111 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
72 break; 112 break;
73 case MAILIMF_FIELD_SUBJECT: 113 case MAILIMF_FIELD_SUBJECT:
74 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); 114 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) );
75 break; 115 break;
76 case MAILIMF_FIELD_ORIG_DATE: 116 case MAILIMF_FIELD_ORIG_DATE:
77 mail->setDate( *parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 117 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
78 break; 118 break;
79 default: 119 default:
80 break; 120 break;
81 } 121 }
82 } 122 }
83 123
84 return mail; 124 return mail;
85} 125}
86 126
87QString *POP3wrapper::parseDateTime( mailimf_date_time *date ) 127QString POP3wrapper::parseDateTime( mailimf_date_time *date )
88{ 128{
89 char tmp[23]; 129 char tmp[23];
90 130
91 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 131 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
92 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 132 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
93 133
94 QString *result = new QString( tmp ); 134 return QString( tmp );
95
96 return result;
97} 135}
98 136
99QString *POP3wrapper::parseAddressList( mailimf_address_list *list ) 137QString POP3wrapper::parseAddressList( mailimf_address_list *list )
100{ 138{
101 QString *result = new QString( "" ); 139 QString result( "" );
102 140
103 bool first = true; 141 bool first = true;
104 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 142 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
105 mailimf_address *addr = (mailimf_address *) current->data; 143 mailimf_address *addr = (mailimf_address *) current->data;
106 144
107 if ( !first ) { 145 if ( !first ) {
108 result->append( "," ); 146 result.append( "," );
109 } else { 147 } else {
110 first = false; 148 first = false;
111 } 149 }
112 150
113 QString *tmp;
114
115 switch ( addr->ad_type ) { 151 switch ( addr->ad_type ) {
116 case MAILIMF_ADDRESS_MAILBOX: 152 case MAILIMF_ADDRESS_MAILBOX:
117 tmp = parseMailbox( addr->ad_data.ad_mailbox ); 153 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
118 result->append( *tmp );
119 delete tmp;
120 break; 154 break;
121 case MAILIMF_ADDRESS_GROUP: 155 case MAILIMF_ADDRESS_GROUP:
122 tmp = parseGroup( addr->ad_data.ad_group ); 156 result.append( parseGroup( addr->ad_data.ad_group ) );
123 result->append( *tmp );
124 delete tmp;
125 break; 157 break;
126 default: 158 default:
127 qDebug( "POP3: unkown mailimf address type" ); 159 qDebug( "POP3: unkown mailimf address type" );
128 break; 160 break;
129 } 161 }
130 } 162 }
131 163
132 return result; 164 return result;
133} 165}
134 166
135QString *POP3wrapper::parseGroup( mailimf_group *group ) 167QString POP3wrapper::parseGroup( mailimf_group *group )
136{ 168{
137 QString *result = new QString( "" ); 169 QString result( "" );
138 170
139 result->append( group->grp_display_name ); 171 result.append( group->grp_display_name );
140 result->append( ": " ); 172 result.append( ": " );
141 173
142 if ( group->grp_mb_list != NULL ) { 174 if ( group->grp_mb_list != NULL ) {
143 QString *tmp = parseMailboxList( group->grp_mb_list ); 175 result.append( parseMailboxList( group->grp_mb_list ) );
144 result->append( *tmp );
145 delete tmp;
146 } 176 }
147 177
148 result->append( ";" ); 178 result.append( ";" );
149 179
150 return result; 180 return result;
151} 181}
152 182
153QString *POP3wrapper::parseMailbox( mailimf_mailbox *box ) 183QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
154{ 184{
155 QString *result = new QString( "" ); 185 QString result( "" );
156 186
157 if ( box->mb_display_name == NULL ) { 187 if ( box->mb_display_name == NULL ) {
158 result->append( box->mb_addr_spec ); 188 result.append( box->mb_addr_spec );
159 } else { 189 } else {
160 result->append( box->mb_display_name ); 190 result.append( box->mb_display_name );
161 result->append( " <" ); 191 result.append( " <" );
162 result->append( box->mb_addr_spec ); 192 result.append( box->mb_addr_spec );
163 result->append( ">" ); 193 result.append( ">" );
164 } 194 }
165 195
166 return result; 196 return result;
167} 197}
168 198
169QString *POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) 199QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
170{ 200{
171 QString *result = new QString( "" ); 201 QString result( "" );
172 202
173 bool first = true; 203 bool first = true;
174 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 204 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
175 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 205 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
176 206
177 if ( !first ) { 207 if ( !first ) {
178 result->append( "," ); 208 result.append( "," );
179 } else { 209 } else {
180 first = false; 210 first = false;
181 } 211 }
182 212
183 QString *tmp = parseMailbox( box ); 213 result.append( parseMailbox( box ) );
184 result->append( *tmp );
185 delete tmp;
186 } 214 }
187 215
188 return result; 216 return result;
189} 217}
190 218
191void POP3wrapper::login() 219void POP3wrapper::login()
192{ 220{
193 if ( m_pop3 != NULL ) logout(); 221 if ( m_pop3 != NULL ) logout();
194 222
195 const char *server, *user, *pass; 223 const char *server, *user, *pass;
196 uint16_t port; 224 uint16_t port;
197 int err = MAILPOP3_NO_ERROR; 225 int err = MAILPOP3_NO_ERROR;
198 226
199 server = account->getServer().latin1(); 227 server = account->getServer().latin1();
200 port = account->getPort().toUInt(); 228 port = account->getPort().toUInt();
201 user = account->getUser().latin1(); 229 user = account->getUser().latin1();
@@ -227,17 +255,16 @@ void POP3wrapper::login()
227 logout(); 255 logout();
228 return; 256 return;
229 } 257 }
230 258
231 qDebug( "POP3: logged in!" ); 259 qDebug( "POP3: logged in!" );
232} 260}
233 261
234void POP3wrapper::logout() 262void POP3wrapper::logout()
235{ 263{
236 int err = MAILPOP3_NO_ERROR; 264 int err = MAILPOP3_NO_ERROR;
237 if ( m_pop3 == NULL ) return; 265 if ( m_pop3 == NULL ) return;
238 err = mailpop3_quit( m_pop3 ); 266 err = mailpop3_quit( m_pop3 );
239 mailpop3_free( m_pop3 ); 267 mailpop3_free( m_pop3 );
240 m_pop3 = NULL; 268 m_pop3 = NULL;
241} 269}
242 270
243
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h
index 4e4abad..995bed0 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.h
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h
@@ -1,35 +1,38 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5 5
6class RecMail; 6class RecMail;
7class RecBody;
7struct mailpop3; 8struct mailpop3;
8 9
9class POP3wrapper : public QObject 10class POP3wrapper : public QObject
10{ 11{
11 Q_OBJECT 12 Q_OBJECT
12 13
13public: 14public:
14 POP3wrapper( POP3account *a ); 15 POP3wrapper( POP3account *a );
15 virtual ~POP3wrapper(); 16 virtual ~POP3wrapper();
16 void listMessages( QList<RecMail> &target ); 17 void listMessages( QList<RecMail> &target );
18 RecBody fetchBody( const RecMail &mail );
17 static void pop3_progress( size_t current, size_t maximum ); 19 static void pop3_progress( size_t current, size_t maximum );
18 20
19protected: 21protected:
20 void login(); 22 void login();
21 void logout(); 23 void logout();
22 24
23private: 25private:
24 RecMail *parseHeader( const char *header ); 26 RecMail *parseHeader( const char *header );
25 QString *parseMailboxList( mailimf_mailbox_list *list ); 27 RecBody parseBody( const char *message );
26 QString *parseMailbox( mailimf_mailbox *box ); 28 QString parseMailboxList( mailimf_mailbox_list *list );
27 QString *parseGroup( mailimf_group *group ); 29 QString parseMailbox( mailimf_mailbox *box );
28 QString *parseAddressList( mailimf_address_list *list ); 30 QString parseGroup( mailimf_group *group );
29 QString *parseDateTime( mailimf_date_time *date ); 31 QString parseAddressList( mailimf_address_list *list );
32 QString parseDateTime( mailimf_date_time *date );
30 POP3account *account; 33 POP3account *account;
31 mailpop3 *m_pop3; 34 mailpop3 *m_pop3;
32 35
33}; 36};
34 37
35#endif 38#endif
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index 633faf6..abb5a42 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -6,32 +6,72 @@
6POP3wrapper::POP3wrapper( POP3account *a ) 6POP3wrapper::POP3wrapper( POP3account *a )
7{ 7{
8 account = a; 8 account = a;
9 m_pop3 = NULL; 9 m_pop3 = NULL;
10} 10}
11 11
12POP3wrapper::~POP3wrapper() 12POP3wrapper::~POP3wrapper()
13{ 13{
14 logout(); 14 logout();
15} 15}
16 16
17void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 17void POP3wrapper::pop3_progress( size_t current, size_t maximum )
18{ 18{
19 qDebug( "POP3: %i of %i", current, maximum ); 19 qDebug( "POP3: %i of %i", current, maximum );
20} 20}
21 21
22RecBody POP3wrapper::fetchBody( const RecMail &mail )
23{
24 int err = MAILPOP3_NO_ERROR;
25 char *message;
26 size_t length;
27
28 login();
29 if ( !m_pop3 ) return RecBody();
30
31 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
32 if ( err != MAILPOP3_NO_ERROR ) {
33 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
34 logout();
35 return RecBody();
36 }
37
38 logout();
39
40 return parseBody( message );
41}
42
43RecBody POP3wrapper::parseBody( const char *message )
44{
45 int err = MAILIMF_NO_ERROR;
46 size_t curTok;
47 mailimf_message *result;
48 RecBody body;
49
50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
51 if ( err != MAILIMF_NO_ERROR ) return body;
52
53 if ( result && result->msg_body && result->msg_body->bd_text ) {
54 qDebug( "POP3: bodytext found" );
55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan.
56 body.setBodytext( QString( result->msg_body->bd_text ) );
57 }
58
59 return body;
60}
61
22void POP3wrapper::listMessages( QList<RecMail> &target ) 62void POP3wrapper::listMessages( QList<RecMail> &target )
23{ 63{
24 int err = MAILPOP3_NO_ERROR; 64 int err = MAILPOP3_NO_ERROR;
25 char *header; 65 char *header;
26 size_t length; 66 size_t length;
27 carray *messages; 67 carray *messages;
28 68
29 login(); 69 login();
30 if (!m_pop3) return; 70 if (!m_pop3) return;
31 mailpop3_list( m_pop3, &messages ); 71 mailpop3_list( m_pop3, &messages );
32 72
33 for ( int i = carray_count( messages ); i > 0; i-- ) { 73 for ( int i = carray_count( messages ); i > 0; i-- ) {
34 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); 74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 );
35 75
36 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
37 if ( err != MAILPOP3_NO_ERROR ) { 77 if ( err != MAILPOP3_NO_ERROR ) {
@@ -46,156 +86,144 @@ void POP3wrapper::listMessages( QList<RecMail> &target )
46 86
47 logout(); 87 logout();
48} 88}
49 89
50RecMail *POP3wrapper::parseHeader( const char *header ) 90RecMail *POP3wrapper::parseHeader( const char *header )
51{ 91{
52 int err = MAILIMF_NO_ERROR; 92 int err = MAILIMF_NO_ERROR;
53 size_t curTok; 93 size_t curTok;
54 RecMail *mail = new RecMail(); 94 RecMail *mail = new RecMail();
55 mailimf_fields *fields; 95 mailimf_fields *fields;
56 96
57 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 97 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
58 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 98 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
59 mailimf_field *field = (mailimf_field *) current->data; 99 mailimf_field *field = (mailimf_field *) current->data;
60 switch ( field->fld_type ) { 100 switch ( field->fld_type ) {
61 case MAILIMF_FIELD_FROM: 101 case MAILIMF_FIELD_FROM:
62 mail->setFrom( *parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 102 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
63 break; 103 break;
64 case MAILIMF_FIELD_TO: 104 case MAILIMF_FIELD_TO:
65 mail->setTo( *parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 105 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
66 break; 106 break;
67 case MAILIMF_FIELD_CC: 107 case MAILIMF_FIELD_CC:
68 mail->setCC( *parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 108 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
69 break; 109 break;
70 case MAILIMF_FIELD_BCC: 110 case MAILIMF_FIELD_BCC:
71 mail->setBcc( *parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 111 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
72 break; 112 break;
73 case MAILIMF_FIELD_SUBJECT: 113 case MAILIMF_FIELD_SUBJECT:
74 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); 114 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) );
75 break; 115 break;
76 case MAILIMF_FIELD_ORIG_DATE: 116 case MAILIMF_FIELD_ORIG_DATE:
77 mail->setDate( *parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 117 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
78 break; 118 break;
79 default: 119 default:
80 break; 120 break;
81 } 121 }
82 } 122 }
83 123
84 return mail; 124 return mail;
85} 125}
86 126
87QString *POP3wrapper::parseDateTime( mailimf_date_time *date ) 127QString POP3wrapper::parseDateTime( mailimf_date_time *date )
88{ 128{
89 char tmp[23]; 129 char tmp[23];
90 130
91 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 131 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
92 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 132 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
93 133
94 QString *result = new QString( tmp ); 134 return QString( tmp );
95
96 return result;
97} 135}
98 136
99QString *POP3wrapper::parseAddressList( mailimf_address_list *list ) 137QString POP3wrapper::parseAddressList( mailimf_address_list *list )
100{ 138{
101 QString *result = new QString( "" ); 139 QString result( "" );
102 140
103 bool first = true; 141 bool first = true;
104 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 142 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
105 mailimf_address *addr = (mailimf_address *) current->data; 143 mailimf_address *addr = (mailimf_address *) current->data;
106 144
107 if ( !first ) { 145 if ( !first ) {
108 result->append( "," ); 146 result.append( "," );
109 } else { 147 } else {
110 first = false; 148 first = false;
111 } 149 }
112 150
113 QString *tmp;
114
115 switch ( addr->ad_type ) { 151 switch ( addr->ad_type ) {
116 case MAILIMF_ADDRESS_MAILBOX: 152 case MAILIMF_ADDRESS_MAILBOX:
117 tmp = parseMailbox( addr->ad_data.ad_mailbox ); 153 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
118 result->append( *tmp );
119 delete tmp;
120 break; 154 break;
121 case MAILIMF_ADDRESS_GROUP: 155 case MAILIMF_ADDRESS_GROUP:
122 tmp = parseGroup( addr->ad_data.ad_group ); 156 result.append( parseGroup( addr->ad_data.ad_group ) );
123 result->append( *tmp );
124 delete tmp;
125 break; 157 break;
126 default: 158 default:
127 qDebug( "POP3: unkown mailimf address type" ); 159 qDebug( "POP3: unkown mailimf address type" );
128 break; 160 break;
129 } 161 }
130 } 162 }
131 163
132 return result; 164 return result;
133} 165}
134 166
135QString *POP3wrapper::parseGroup( mailimf_group *group ) 167QString POP3wrapper::parseGroup( mailimf_group *group )
136{ 168{
137 QString *result = new QString( "" ); 169 QString result( "" );
138 170
139 result->append( group->grp_display_name ); 171 result.append( group->grp_display_name );
140 result->append( ": " ); 172 result.append( ": " );
141 173
142 if ( group->grp_mb_list != NULL ) { 174 if ( group->grp_mb_list != NULL ) {
143 QString *tmp = parseMailboxList( group->grp_mb_list ); 175 result.append( parseMailboxList( group->grp_mb_list ) );
144 result->append( *tmp );
145 delete tmp;
146 } 176 }
147 177
148 result->append( ";" ); 178 result.append( ";" );
149 179
150 return result; 180 return result;
151} 181}
152 182
153QString *POP3wrapper::parseMailbox( mailimf_mailbox *box ) 183QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
154{ 184{
155 QString *result = new QString( "" ); 185 QString result( "" );
156 186
157 if ( box->mb_display_name == NULL ) { 187 if ( box->mb_display_name == NULL ) {
158 result->append( box->mb_addr_spec ); 188 result.append( box->mb_addr_spec );
159 } else { 189 } else {
160 result->append( box->mb_display_name ); 190 result.append( box->mb_display_name );
161 result->append( " <" ); 191 result.append( " <" );
162 result->append( box->mb_addr_spec ); 192 result.append( box->mb_addr_spec );
163 result->append( ">" ); 193 result.append( ">" );
164 } 194 }
165 195
166 return result; 196 return result;
167} 197}
168 198
169QString *POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) 199QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
170{ 200{
171 QString *result = new QString( "" ); 201 QString result( "" );
172 202
173 bool first = true; 203 bool first = true;
174 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 204 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
175 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 205 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
176 206
177 if ( !first ) { 207 if ( !first ) {
178 result->append( "," ); 208 result.append( "," );
179 } else { 209 } else {
180 first = false; 210 first = false;
181 } 211 }
182 212
183 QString *tmp = parseMailbox( box ); 213 result.append( parseMailbox( box ) );
184 result->append( *tmp );
185 delete tmp;
186 } 214 }
187 215
188 return result; 216 return result;
189} 217}
190 218
191void POP3wrapper::login() 219void POP3wrapper::login()
192{ 220{
193 if ( m_pop3 != NULL ) logout(); 221 if ( m_pop3 != NULL ) logout();
194 222
195 const char *server, *user, *pass; 223 const char *server, *user, *pass;
196 uint16_t port; 224 uint16_t port;
197 int err = MAILPOP3_NO_ERROR; 225 int err = MAILPOP3_NO_ERROR;
198 226
199 server = account->getServer().latin1(); 227 server = account->getServer().latin1();
200 port = account->getPort().toUInt(); 228 port = account->getPort().toUInt();
201 user = account->getUser().latin1(); 229 user = account->getUser().latin1();
@@ -227,17 +255,16 @@ void POP3wrapper::login()
227 logout(); 255 logout();
228 return; 256 return;
229 } 257 }
230 258
231 qDebug( "POP3: logged in!" ); 259 qDebug( "POP3: logged in!" );
232} 260}
233 261
234void POP3wrapper::logout() 262void POP3wrapper::logout()
235{ 263{
236 int err = MAILPOP3_NO_ERROR; 264 int err = MAILPOP3_NO_ERROR;
237 if ( m_pop3 == NULL ) return; 265 if ( m_pop3 == NULL ) return;
238 err = mailpop3_quit( m_pop3 ); 266 err = mailpop3_quit( m_pop3 );
239 mailpop3_free( m_pop3 ); 267 mailpop3_free( m_pop3 );
240 m_pop3 = NULL; 268 m_pop3 = NULL;
241} 269}
242 270
243
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h
index 4e4abad..995bed0 100644
--- a/noncore/net/mail/pop3wrapper.h
+++ b/noncore/net/mail/pop3wrapper.h
@@ -1,35 +1,38 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5 5
6class RecMail; 6class RecMail;
7class RecBody;
7struct mailpop3; 8struct mailpop3;
8 9
9class POP3wrapper : public QObject 10class POP3wrapper : public QObject
10{ 11{
11 Q_OBJECT 12 Q_OBJECT
12 13
13public: 14public:
14 POP3wrapper( POP3account *a ); 15 POP3wrapper( POP3account *a );
15 virtual ~POP3wrapper(); 16 virtual ~POP3wrapper();
16 void listMessages( QList<RecMail> &target ); 17 void listMessages( QList<RecMail> &target );
18 RecBody fetchBody( const RecMail &mail );
17 static void pop3_progress( size_t current, size_t maximum ); 19 static void pop3_progress( size_t current, size_t maximum );
18 20
19protected: 21protected:
20 void login(); 22 void login();
21 void logout(); 23 void logout();
22 24
23private: 25private:
24 RecMail *parseHeader( const char *header ); 26 RecMail *parseHeader( const char *header );
25 QString *parseMailboxList( mailimf_mailbox_list *list ); 27 RecBody parseBody( const char *message );
26 QString *parseMailbox( mailimf_mailbox *box ); 28 QString parseMailboxList( mailimf_mailbox_list *list );
27 QString *parseGroup( mailimf_group *group ); 29 QString parseMailbox( mailimf_mailbox *box );
28 QString *parseAddressList( mailimf_address_list *list ); 30 QString parseGroup( mailimf_group *group );
29 QString *parseDateTime( mailimf_date_time *date ); 31 QString parseAddressList( mailimf_address_list *list );
32 QString parseDateTime( mailimf_date_time *date );
30 POP3account *account; 33 POP3account *account;
31 mailpop3 *m_pop3; 34 mailpop3 *m_pop3;
32 35
33}; 36};
34 37
35#endif 38#endif