-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 140 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 5 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.cpp | 140 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.h | 5 |
4 files changed, 280 insertions, 10 deletions
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index 1538d50..2aaff30 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp | |||
@@ -1,105 +1,235 @@ | |||
1 | 1 | ||
2 | #include "pop3wrapper.h" | 2 | #include "pop3wrapper.h" |
3 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
4 | #include <libetpan/mailpop3.h> | 4 | #include <libetpan/mailpop3.h> |
5 | 5 | ||
6 | POP3wrapper::POP3wrapper( POP3account *a ) | 6 | POP3wrapper::POP3wrapper( POP3account *a ) |
7 | { | 7 | { |
8 | account = a; | 8 | account = a; |
9 | m_pop3 = NULL; | 9 | m_pop3 = NULL; |
10 | } | 10 | } |
11 | 11 | ||
12 | POP3wrapper::~POP3wrapper() | 12 | POP3wrapper::~POP3wrapper() |
13 | { | 13 | { |
14 | logout(); | 14 | logout(); |
15 | } | 15 | } |
16 | 16 | ||
17 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) | 17 | void 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 | ||
22 | void POP3wrapper::listMessages( QList<RecMail> &target ) | 22 | void POP3wrapper::listMessages( QList<RecMail> &target ) |
23 | { | 23 | { |
24 | int err = MAILPOP3_NO_ERROR; | 24 | int err = MAILPOP3_NO_ERROR; |
25 | char *header; | 25 | char *header; |
26 | size_t length; | 26 | size_t length; |
27 | carray *messages; | 27 | carray *messages; |
28 | 28 | ||
29 | login(); | 29 | login(); |
30 | mailpop3_list( m_pop3, &messages ); | 30 | mailpop3_list( m_pop3, &messages ); |
31 | 31 | ||
32 | for ( int i = carray_count( messages ); i > 0; i-- ) { | 32 | for ( int i = carray_count( messages ); i > 0; i-- ) { |
33 | mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); | 33 | mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); |
34 | 34 | ||
35 | err = mailpop3_header( m_pop3, info->index, &header, &length ); | 35 | err = mailpop3_header( m_pop3, info->index, &header, &length ); |
36 | if ( err != MAILPOP3_NO_ERROR ) { | 36 | if ( err != MAILPOP3_NO_ERROR ) { |
37 | qDebug( "POP3: error retrieving header msgid: %i", info->index ); | 37 | qDebug( "POP3: error retrieving header msgid: %i", info->index ); |
38 | logout(); | 38 | logout(); |
39 | return; | 39 | return; |
40 | } | 40 | } |
41 | RecMail *mail = parseHeader( header ); | 41 | RecMail *mail = parseHeader( header ); |
42 | mail->setNumber( info->index ); | 42 | mail->setNumber( info->index ); |
43 | target.append( mail ); | 43 | target.append( mail ); |
44 | } | 44 | } |
45 | 45 | ||
46 | logout(); | 46 | logout(); |
47 | } | 47 | } |
48 | 48 | ||
49 | RecMail *POP3wrapper::parseHeader( const char *h ) | 49 | RecMail *POP3wrapper::parseHeader( const char *header ) |
50 | { | 50 | { |
51 | int err = MAILIMF_NO_ERROR; | ||
52 | size_t curTok; | ||
51 | RecMail *mail = new RecMail(); | 53 | RecMail *mail = new RecMail(); |
52 | QString header( h ); | 54 | mailimf_fields *fields; |
55 | |||
56 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); | ||
57 | for ( clistiter *current = clist_begin( fields->list ); current != NULL; current = current->next ) { | ||
58 | mailimf_field *field = (mailimf_field *) current->data; | ||
59 | switch ( field->type ) { | ||
60 | case MAILIMF_FIELD_FROM: | ||
61 | mail->setFrom( *parseMailboxList( field->field.from->mb_list ) ); | ||
62 | break; | ||
63 | case MAILIMF_FIELD_TO: | ||
64 | mail->setTo( *parseAddressList( field->field.to->addr_list ) ); | ||
65 | break; | ||
66 | case MAILIMF_FIELD_CC: | ||
67 | mail->setCC( *parseAddressList( field->field.cc->addr_list ) ); | ||
68 | break; | ||
69 | case MAILIMF_FIELD_BCC: | ||
70 | mail->setBcc( *parseAddressList( field->field.bcc->addr_list ) ); | ||
71 | break; | ||
72 | case MAILIMF_FIELD_SUBJECT: | ||
73 | mail->setSubject( QString( field->field.subject->value ) ); | ||
74 | break; | ||
75 | case MAILIMF_FIELD_ORIG_DATE: | ||
76 | mail->setDate( *parseDateTime( field->field.orig_date->date_time ) ); | ||
77 | break; | ||
78 | default: | ||
79 | break; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | return mail; | ||
84 | } | ||
53 | 85 | ||
54 | //TODO: parse header - maybe something like this is already implemented in libetpan? | 86 | QString *POP3wrapper::parseDateTime( mailimf_date_time *date ) |
55 | mail->setSubject( "Blah blubb" ); | 87 | { |
88 | char tmp[23]; | ||
89 | |||
90 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | ||
91 | date->day, date->month, date->year, date->hour, date->min, date->sec, date->zone ); | ||
92 | |||
93 | QString *result = new QString( tmp ); | ||
94 | |||
95 | return result; | ||
96 | } | ||
56 | 97 | ||
57 | return mail; | 98 | QString *POP3wrapper::parseAddressList( mailimf_address_list *list ) |
99 | { | ||
100 | QString *result = new QString( "" ); | ||
101 | |||
102 | bool first = true; | ||
103 | for ( clistiter *current = clist_begin( list->list ); current != NULL; current = current->next ) { | ||
104 | mailimf_address *addr = (mailimf_address *) current->data; | ||
105 | |||
106 | if ( !first ) { | ||
107 | result->append( "," ); | ||
108 | } else { | ||
109 | first = false; | ||
110 | } | ||
111 | |||
112 | QString *tmp; | ||
113 | |||
114 | switch ( addr->type ) { | ||
115 | case MAILIMF_ADDRESS_MAILBOX: | ||
116 | tmp = parseMailbox( addr->mailbox ); | ||
117 | result->append( *tmp ); | ||
118 | delete tmp; | ||
119 | break; | ||
120 | case MAILIMF_ADDRESS_GROUP: | ||
121 | tmp = parseGroup( addr->group ); | ||
122 | result->append( *tmp ); | ||
123 | delete tmp; | ||
124 | break; | ||
125 | default: | ||
126 | qDebug( "POP3: unkown mailimf address type" ); | ||
127 | break; | ||
128 | } | ||
129 | } | ||
130 | |||
131 | return result; | ||
132 | } | ||
133 | |||
134 | QString *POP3wrapper::parseGroup( mailimf_group *group ) | ||
135 | { | ||
136 | QString *result = new QString( "" ); | ||
137 | |||
138 | result->append( group->display_name ); | ||
139 | result->append( ": " ); | ||
140 | |||
141 | if ( group->mb_list != NULL ) { | ||
142 | QString *tmp = parseMailboxList( group->mb_list ); | ||
143 | result->append( *tmp ); | ||
144 | delete tmp; | ||
145 | } | ||
146 | |||
147 | result->append( ";" ); | ||
148 | |||
149 | return result; | ||
150 | } | ||
151 | |||
152 | QString *POP3wrapper::parseMailbox( mailimf_mailbox *box ) | ||
153 | { | ||
154 | QString *result = new QString( "" ); | ||
155 | |||
156 | if ( box->display_name == NULL ) { | ||
157 | result->append( box->addr_spec ); | ||
158 | } else { | ||
159 | result->append( box->display_name ); | ||
160 | result->append( " <" ); | ||
161 | result->append( box->addr_spec ); | ||
162 | result->append( ">" ); | ||
163 | } | ||
164 | |||
165 | return result; | ||
166 | } | ||
167 | |||
168 | QString *POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) | ||
169 | { | ||
170 | QString *result = new QString( "" ); | ||
171 | |||
172 | bool first = true; | ||
173 | for ( clistiter *current = clist_begin( list->list ); current != NULL; current = current->next ) { | ||
174 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; | ||
175 | |||
176 | if ( !first ) { | ||
177 | result->append( "," ); | ||
178 | } else { | ||
179 | first = false; | ||
180 | } | ||
181 | |||
182 | QString *tmp = parseMailbox( box ); | ||
183 | result->append( *tmp ); | ||
184 | delete tmp; | ||
185 | } | ||
186 | |||
187 | return result; | ||
58 | } | 188 | } |
59 | 189 | ||
60 | void POP3wrapper::login() | 190 | void POP3wrapper::login() |
61 | { | 191 | { |
62 | if ( m_pop3 != NULL ) logout(); | 192 | if ( m_pop3 != NULL ) logout(); |
63 | 193 | ||
64 | const char *server, *user, *pass; | 194 | const char *server, *user, *pass; |
65 | uint16_t port; | 195 | uint16_t port; |
66 | int err = MAILPOP3_NO_ERROR; | 196 | int err = MAILPOP3_NO_ERROR; |
67 | 197 | ||
68 | server = account->getServer().latin1(); | 198 | server = account->getServer().latin1(); |
69 | port = account->getPort().toUInt(); | 199 | port = account->getPort().toUInt(); |
70 | user = account->getUser().latin1(); | 200 | user = account->getUser().latin1(); |
71 | pass = account->getPassword().latin1(); | 201 | pass = account->getPassword().latin1(); |
72 | 202 | ||
73 | m_pop3 = mailpop3_new( 200, &pop3_progress ); | 203 | m_pop3 = mailpop3_new( 200, &pop3_progress ); |
74 | 204 | ||
75 | // connect | 205 | // connect |
76 | if (account->getSSL()) { | 206 | if (account->getSSL()) { |
77 | err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); | 207 | err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); |
78 | } else { | 208 | } else { |
79 | err = mailpop3_socket_connect( m_pop3, (char*)server, port ); | 209 | err = mailpop3_socket_connect( m_pop3, (char*)server, port ); |
80 | } | 210 | } |
81 | 211 | ||
82 | if ( err != MAILPOP3_NO_ERROR ) { | 212 | if ( err != MAILPOP3_NO_ERROR ) { |
83 | qDebug( "pop3: error connecting to %s\n reason: %s", server, | 213 | qDebug( "pop3: error connecting to %s\n reason: %s", server, |
84 | m_pop3->response ); | 214 | m_pop3->response ); |
85 | mailpop3_free( m_pop3 ); | 215 | mailpop3_free( m_pop3 ); |
86 | m_pop3 = NULL; | 216 | m_pop3 = NULL; |
87 | return; | 217 | return; |
88 | } | 218 | } |
89 | qDebug( "POP3: connected!" ); | 219 | qDebug( "POP3: connected!" ); |
90 | 220 | ||
91 | // login | 221 | // login |
92 | // TODO: decide if apop or plain login should be used | 222 | // TODO: decide if apop or plain login should be used |
93 | err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); | 223 | err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); |
94 | if ( err != MAILPOP3_NO_ERROR ) { | 224 | if ( err != MAILPOP3_NO_ERROR ) { |
95 | qDebug( "pop3: error logging in: %s", m_pop3->response ); | 225 | qDebug( "pop3: error logging in: %s", m_pop3->response ); |
96 | logout(); | 226 | logout(); |
97 | return; | 227 | return; |
98 | } | 228 | } |
99 | 229 | ||
100 | qDebug( "POP3: logged in!" ); | 230 | qDebug( "POP3: logged in!" ); |
101 | } | 231 | } |
102 | 232 | ||
103 | void POP3wrapper::logout() | 233 | void POP3wrapper::logout() |
104 | { | 234 | { |
105 | int err = MAILPOP3_NO_ERROR; | 235 | int err = MAILPOP3_NO_ERROR; |
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index f242746..a8937fb 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h | |||
@@ -1,29 +1,34 @@ | |||
1 | #ifndef __POP3WRAPPER | 1 | #ifndef __POP3WRAPPER |
2 | #define __POP3WRAPPER | 2 | #define __POP3WRAPPER |
3 | 3 | ||
4 | #include "mailwrapper.h" | 4 | #include "mailwrapper.h" |
5 | 5 | ||
6 | class RecMail; | 6 | class RecMail; |
7 | 7 | ||
8 | class POP3wrapper : public QObject | 8 | class POP3wrapper : public QObject |
9 | { | 9 | { |
10 | Q_OBJECT | 10 | Q_OBJECT |
11 | 11 | ||
12 | public: | 12 | public: |
13 | POP3wrapper( POP3account *a ); | 13 | POP3wrapper( POP3account *a ); |
14 | virtual ~POP3wrapper(); | 14 | virtual ~POP3wrapper(); |
15 | void listMessages( QList<RecMail> &target ); | 15 | void listMessages( QList<RecMail> &target ); |
16 | static void pop3_progress( size_t current, size_t maximum ); | 16 | static void pop3_progress( size_t current, size_t maximum ); |
17 | 17 | ||
18 | protected: | 18 | protected: |
19 | void login(); | 19 | void login(); |
20 | void logout(); | 20 | void logout(); |
21 | 21 | ||
22 | private: | 22 | private: |
23 | RecMail *parseHeader( const char *header ); | 23 | RecMail *parseHeader( const char *header ); |
24 | QString *parseMailboxList( mailimf_mailbox_list *list ); | ||
25 | QString *parseMailbox( mailimf_mailbox *box ); | ||
26 | QString *parseGroup( mailimf_group *group ); | ||
27 | QString *parseAddressList( mailimf_address_list *list ); | ||
28 | QString *parseDateTime( mailimf_date_time *date ); | ||
24 | POP3account *account; | 29 | POP3account *account; |
25 | mailpop3 *m_pop3; | 30 | mailpop3 *m_pop3; |
26 | 31 | ||
27 | }; | 32 | }; |
28 | 33 | ||
29 | #endif | 34 | #endif |
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp index 1538d50..2aaff30 100644 --- a/noncore/net/mail/pop3wrapper.cpp +++ b/noncore/net/mail/pop3wrapper.cpp | |||
@@ -1,105 +1,235 @@ | |||
1 | 1 | ||
2 | #include "pop3wrapper.h" | 2 | #include "pop3wrapper.h" |
3 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
4 | #include <libetpan/mailpop3.h> | 4 | #include <libetpan/mailpop3.h> |
5 | 5 | ||
6 | POP3wrapper::POP3wrapper( POP3account *a ) | 6 | POP3wrapper::POP3wrapper( POP3account *a ) |
7 | { | 7 | { |
8 | account = a; | 8 | account = a; |
9 | m_pop3 = NULL; | 9 | m_pop3 = NULL; |
10 | } | 10 | } |
11 | 11 | ||
12 | POP3wrapper::~POP3wrapper() | 12 | POP3wrapper::~POP3wrapper() |
13 | { | 13 | { |
14 | logout(); | 14 | logout(); |
15 | } | 15 | } |
16 | 16 | ||
17 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) | 17 | void 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 | ||
22 | void POP3wrapper::listMessages( QList<RecMail> &target ) | 22 | void POP3wrapper::listMessages( QList<RecMail> &target ) |
23 | { | 23 | { |
24 | int err = MAILPOP3_NO_ERROR; | 24 | int err = MAILPOP3_NO_ERROR; |
25 | char *header; | 25 | char *header; |
26 | size_t length; | 26 | size_t length; |
27 | carray *messages; | 27 | carray *messages; |
28 | 28 | ||
29 | login(); | 29 | login(); |
30 | mailpop3_list( m_pop3, &messages ); | 30 | mailpop3_list( m_pop3, &messages ); |
31 | 31 | ||
32 | for ( int i = carray_count( messages ); i > 0; i-- ) { | 32 | for ( int i = carray_count( messages ); i > 0; i-- ) { |
33 | mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); | 33 | mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); |
34 | 34 | ||
35 | err = mailpop3_header( m_pop3, info->index, &header, &length ); | 35 | err = mailpop3_header( m_pop3, info->index, &header, &length ); |
36 | if ( err != MAILPOP3_NO_ERROR ) { | 36 | if ( err != MAILPOP3_NO_ERROR ) { |
37 | qDebug( "POP3: error retrieving header msgid: %i", info->index ); | 37 | qDebug( "POP3: error retrieving header msgid: %i", info->index ); |
38 | logout(); | 38 | logout(); |
39 | return; | 39 | return; |
40 | } | 40 | } |
41 | RecMail *mail = parseHeader( header ); | 41 | RecMail *mail = parseHeader( header ); |
42 | mail->setNumber( info->index ); | 42 | mail->setNumber( info->index ); |
43 | target.append( mail ); | 43 | target.append( mail ); |
44 | } | 44 | } |
45 | 45 | ||
46 | logout(); | 46 | logout(); |
47 | } | 47 | } |
48 | 48 | ||
49 | RecMail *POP3wrapper::parseHeader( const char *h ) | 49 | RecMail *POP3wrapper::parseHeader( const char *header ) |
50 | { | 50 | { |
51 | int err = MAILIMF_NO_ERROR; | ||
52 | size_t curTok; | ||
51 | RecMail *mail = new RecMail(); | 53 | RecMail *mail = new RecMail(); |
52 | QString header( h ); | 54 | mailimf_fields *fields; |
55 | |||
56 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); | ||
57 | for ( clistiter *current = clist_begin( fields->list ); current != NULL; current = current->next ) { | ||
58 | mailimf_field *field = (mailimf_field *) current->data; | ||
59 | switch ( field->type ) { | ||
60 | case MAILIMF_FIELD_FROM: | ||
61 | mail->setFrom( *parseMailboxList( field->field.from->mb_list ) ); | ||
62 | break; | ||
63 | case MAILIMF_FIELD_TO: | ||
64 | mail->setTo( *parseAddressList( field->field.to->addr_list ) ); | ||
65 | break; | ||
66 | case MAILIMF_FIELD_CC: | ||
67 | mail->setCC( *parseAddressList( field->field.cc->addr_list ) ); | ||
68 | break; | ||
69 | case MAILIMF_FIELD_BCC: | ||
70 | mail->setBcc( *parseAddressList( field->field.bcc->addr_list ) ); | ||
71 | break; | ||
72 | case MAILIMF_FIELD_SUBJECT: | ||
73 | mail->setSubject( QString( field->field.subject->value ) ); | ||
74 | break; | ||
75 | case MAILIMF_FIELD_ORIG_DATE: | ||
76 | mail->setDate( *parseDateTime( field->field.orig_date->date_time ) ); | ||
77 | break; | ||
78 | default: | ||
79 | break; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | return mail; | ||
84 | } | ||
53 | 85 | ||
54 | //TODO: parse header - maybe something like this is already implemented in libetpan? | 86 | QString *POP3wrapper::parseDateTime( mailimf_date_time *date ) |
55 | mail->setSubject( "Blah blubb" ); | 87 | { |
88 | char tmp[23]; | ||
89 | |||
90 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | ||
91 | date->day, date->month, date->year, date->hour, date->min, date->sec, date->zone ); | ||
92 | |||
93 | QString *result = new QString( tmp ); | ||
94 | |||
95 | return result; | ||
96 | } | ||
56 | 97 | ||
57 | return mail; | 98 | QString *POP3wrapper::parseAddressList( mailimf_address_list *list ) |
99 | { | ||
100 | QString *result = new QString( "" ); | ||
101 | |||
102 | bool first = true; | ||
103 | for ( clistiter *current = clist_begin( list->list ); current != NULL; current = current->next ) { | ||
104 | mailimf_address *addr = (mailimf_address *) current->data; | ||
105 | |||
106 | if ( !first ) { | ||
107 | result->append( "," ); | ||
108 | } else { | ||
109 | first = false; | ||
110 | } | ||
111 | |||
112 | QString *tmp; | ||
113 | |||
114 | switch ( addr->type ) { | ||
115 | case MAILIMF_ADDRESS_MAILBOX: | ||
116 | tmp = parseMailbox( addr->mailbox ); | ||
117 | result->append( *tmp ); | ||
118 | delete tmp; | ||
119 | break; | ||
120 | case MAILIMF_ADDRESS_GROUP: | ||
121 | tmp = parseGroup( addr->group ); | ||
122 | result->append( *tmp ); | ||
123 | delete tmp; | ||
124 | break; | ||
125 | default: | ||
126 | qDebug( "POP3: unkown mailimf address type" ); | ||
127 | break; | ||
128 | } | ||
129 | } | ||
130 | |||
131 | return result; | ||
132 | } | ||
133 | |||
134 | QString *POP3wrapper::parseGroup( mailimf_group *group ) | ||
135 | { | ||
136 | QString *result = new QString( "" ); | ||
137 | |||
138 | result->append( group->display_name ); | ||
139 | result->append( ": " ); | ||
140 | |||
141 | if ( group->mb_list != NULL ) { | ||
142 | QString *tmp = parseMailboxList( group->mb_list ); | ||
143 | result->append( *tmp ); | ||
144 | delete tmp; | ||
145 | } | ||
146 | |||
147 | result->append( ";" ); | ||
148 | |||
149 | return result; | ||
150 | } | ||
151 | |||
152 | QString *POP3wrapper::parseMailbox( mailimf_mailbox *box ) | ||
153 | { | ||
154 | QString *result = new QString( "" ); | ||
155 | |||
156 | if ( box->display_name == NULL ) { | ||
157 | result->append( box->addr_spec ); | ||
158 | } else { | ||
159 | result->append( box->display_name ); | ||
160 | result->append( " <" ); | ||
161 | result->append( box->addr_spec ); | ||
162 | result->append( ">" ); | ||
163 | } | ||
164 | |||
165 | return result; | ||
166 | } | ||
167 | |||
168 | QString *POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) | ||
169 | { | ||
170 | QString *result = new QString( "" ); | ||
171 | |||
172 | bool first = true; | ||
173 | for ( clistiter *current = clist_begin( list->list ); current != NULL; current = current->next ) { | ||
174 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; | ||
175 | |||
176 | if ( !first ) { | ||
177 | result->append( "," ); | ||
178 | } else { | ||
179 | first = false; | ||
180 | } | ||
181 | |||
182 | QString *tmp = parseMailbox( box ); | ||
183 | result->append( *tmp ); | ||
184 | delete tmp; | ||
185 | } | ||
186 | |||
187 | return result; | ||
58 | } | 188 | } |
59 | 189 | ||
60 | void POP3wrapper::login() | 190 | void POP3wrapper::login() |
61 | { | 191 | { |
62 | if ( m_pop3 != NULL ) logout(); | 192 | if ( m_pop3 != NULL ) logout(); |
63 | 193 | ||
64 | const char *server, *user, *pass; | 194 | const char *server, *user, *pass; |
65 | uint16_t port; | 195 | uint16_t port; |
66 | int err = MAILPOP3_NO_ERROR; | 196 | int err = MAILPOP3_NO_ERROR; |
67 | 197 | ||
68 | server = account->getServer().latin1(); | 198 | server = account->getServer().latin1(); |
69 | port = account->getPort().toUInt(); | 199 | port = account->getPort().toUInt(); |
70 | user = account->getUser().latin1(); | 200 | user = account->getUser().latin1(); |
71 | pass = account->getPassword().latin1(); | 201 | pass = account->getPassword().latin1(); |
72 | 202 | ||
73 | m_pop3 = mailpop3_new( 200, &pop3_progress ); | 203 | m_pop3 = mailpop3_new( 200, &pop3_progress ); |
74 | 204 | ||
75 | // connect | 205 | // connect |
76 | if (account->getSSL()) { | 206 | if (account->getSSL()) { |
77 | err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); | 207 | err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); |
78 | } else { | 208 | } else { |
79 | err = mailpop3_socket_connect( m_pop3, (char*)server, port ); | 209 | err = mailpop3_socket_connect( m_pop3, (char*)server, port ); |
80 | } | 210 | } |
81 | 211 | ||
82 | if ( err != MAILPOP3_NO_ERROR ) { | 212 | if ( err != MAILPOP3_NO_ERROR ) { |
83 | qDebug( "pop3: error connecting to %s\n reason: %s", server, | 213 | qDebug( "pop3: error connecting to %s\n reason: %s", server, |
84 | m_pop3->response ); | 214 | m_pop3->response ); |
85 | mailpop3_free( m_pop3 ); | 215 | mailpop3_free( m_pop3 ); |
86 | m_pop3 = NULL; | 216 | m_pop3 = NULL; |
87 | return; | 217 | return; |
88 | } | 218 | } |
89 | qDebug( "POP3: connected!" ); | 219 | qDebug( "POP3: connected!" ); |
90 | 220 | ||
91 | // login | 221 | // login |
92 | // TODO: decide if apop or plain login should be used | 222 | // TODO: decide if apop or plain login should be used |
93 | err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); | 223 | err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); |
94 | if ( err != MAILPOP3_NO_ERROR ) { | 224 | if ( err != MAILPOP3_NO_ERROR ) { |
95 | qDebug( "pop3: error logging in: %s", m_pop3->response ); | 225 | qDebug( "pop3: error logging in: %s", m_pop3->response ); |
96 | logout(); | 226 | logout(); |
97 | return; | 227 | return; |
98 | } | 228 | } |
99 | 229 | ||
100 | qDebug( "POP3: logged in!" ); | 230 | qDebug( "POP3: logged in!" ); |
101 | } | 231 | } |
102 | 232 | ||
103 | void POP3wrapper::logout() | 233 | void POP3wrapper::logout() |
104 | { | 234 | { |
105 | int err = MAILPOP3_NO_ERROR; | 235 | int err = MAILPOP3_NO_ERROR; |
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h index f242746..a8937fb 100644 --- a/noncore/net/mail/pop3wrapper.h +++ b/noncore/net/mail/pop3wrapper.h | |||
@@ -1,29 +1,34 @@ | |||
1 | #ifndef __POP3WRAPPER | 1 | #ifndef __POP3WRAPPER |
2 | #define __POP3WRAPPER | 2 | #define __POP3WRAPPER |
3 | 3 | ||
4 | #include "mailwrapper.h" | 4 | #include "mailwrapper.h" |
5 | 5 | ||
6 | class RecMail; | 6 | class RecMail; |
7 | 7 | ||
8 | class POP3wrapper : public QObject | 8 | class POP3wrapper : public QObject |
9 | { | 9 | { |
10 | Q_OBJECT | 10 | Q_OBJECT |
11 | 11 | ||
12 | public: | 12 | public: |
13 | POP3wrapper( POP3account *a ); | 13 | POP3wrapper( POP3account *a ); |
14 | virtual ~POP3wrapper(); | 14 | virtual ~POP3wrapper(); |
15 | void listMessages( QList<RecMail> &target ); | 15 | void listMessages( QList<RecMail> &target ); |
16 | static void pop3_progress( size_t current, size_t maximum ); | 16 | static void pop3_progress( size_t current, size_t maximum ); |
17 | 17 | ||
18 | protected: | 18 | protected: |
19 | void login(); | 19 | void login(); |
20 | void logout(); | 20 | void logout(); |
21 | 21 | ||
22 | private: | 22 | private: |
23 | RecMail *parseHeader( const char *header ); | 23 | RecMail *parseHeader( const char *header ); |
24 | QString *parseMailboxList( mailimf_mailbox_list *list ); | ||
25 | QString *parseMailbox( mailimf_mailbox *box ); | ||
26 | QString *parseGroup( mailimf_group *group ); | ||
27 | QString *parseAddressList( mailimf_address_list *list ); | ||
28 | QString *parseDateTime( mailimf_date_time *date ); | ||
24 | POP3account *account; | 29 | POP3account *account; |
25 | mailpop3 *m_pop3; | 30 | mailpop3 *m_pop3; |
26 | 31 | ||
27 | }; | 32 | }; |
28 | 33 | ||
29 | #endif | 34 | #endif |