-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 | |||
@@ -33,41 +33,171 @@ void POP3wrapper::listMessages( QList<RecMail> &target ) | |||
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 ); |
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 | |||
@@ -8,22 +8,27 @@ class RecMail; | |||
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 | |||
@@ -33,41 +33,171 @@ void POP3wrapper::listMessages( QList<RecMail> &target ) | |||
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 ); |
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 | |||
@@ -8,22 +8,27 @@ class RecMail; | |||
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 |