-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 1 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.cpp | 1 |
2 files changed, 2 insertions, 0 deletions
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index 2aaff30..72f3c36 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp | |||
@@ -1,157 +1,158 @@ | |||
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 | if (!m_pop3) return; | ||
30 | mailpop3_list( m_pop3, &messages ); | 31 | mailpop3_list( m_pop3, &messages ); |
31 | 32 | ||
32 | for ( int i = carray_count( messages ); i > 0; i-- ) { | 33 | for ( int i = carray_count( messages ); i > 0; i-- ) { |
33 | mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); | 34 | mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); |
34 | 35 | ||
35 | err = mailpop3_header( m_pop3, info->index, &header, &length ); | 36 | err = mailpop3_header( m_pop3, info->index, &header, &length ); |
36 | if ( err != MAILPOP3_NO_ERROR ) { | 37 | if ( err != MAILPOP3_NO_ERROR ) { |
37 | qDebug( "POP3: error retrieving header msgid: %i", info->index ); | 38 | qDebug( "POP3: error retrieving header msgid: %i", info->index ); |
38 | logout(); | 39 | logout(); |
39 | return; | 40 | return; |
40 | } | 41 | } |
41 | RecMail *mail = parseHeader( header ); | 42 | RecMail *mail = parseHeader( header ); |
42 | mail->setNumber( info->index ); | 43 | mail->setNumber( info->index ); |
43 | target.append( mail ); | 44 | target.append( mail ); |
44 | } | 45 | } |
45 | 46 | ||
46 | logout(); | 47 | logout(); |
47 | } | 48 | } |
48 | 49 | ||
49 | RecMail *POP3wrapper::parseHeader( const char *header ) | 50 | RecMail *POP3wrapper::parseHeader( const char *header ) |
50 | { | 51 | { |
51 | int err = MAILIMF_NO_ERROR; | 52 | int err = MAILIMF_NO_ERROR; |
52 | size_t curTok; | 53 | size_t curTok; |
53 | RecMail *mail = new RecMail(); | 54 | RecMail *mail = new RecMail(); |
54 | mailimf_fields *fields; | 55 | mailimf_fields *fields; |
55 | 56 | ||
56 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); | 57 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); |
57 | for ( clistiter *current = clist_begin( fields->list ); current != NULL; current = current->next ) { | 58 | for ( clistiter *current = clist_begin( fields->list ); current != NULL; current = current->next ) { |
58 | mailimf_field *field = (mailimf_field *) current->data; | 59 | mailimf_field *field = (mailimf_field *) current->data; |
59 | switch ( field->type ) { | 60 | switch ( field->type ) { |
60 | case MAILIMF_FIELD_FROM: | 61 | case MAILIMF_FIELD_FROM: |
61 | mail->setFrom( *parseMailboxList( field->field.from->mb_list ) ); | 62 | mail->setFrom( *parseMailboxList( field->field.from->mb_list ) ); |
62 | break; | 63 | break; |
63 | case MAILIMF_FIELD_TO: | 64 | case MAILIMF_FIELD_TO: |
64 | mail->setTo( *parseAddressList( field->field.to->addr_list ) ); | 65 | mail->setTo( *parseAddressList( field->field.to->addr_list ) ); |
65 | break; | 66 | break; |
66 | case MAILIMF_FIELD_CC: | 67 | case MAILIMF_FIELD_CC: |
67 | mail->setCC( *parseAddressList( field->field.cc->addr_list ) ); | 68 | mail->setCC( *parseAddressList( field->field.cc->addr_list ) ); |
68 | break; | 69 | break; |
69 | case MAILIMF_FIELD_BCC: | 70 | case MAILIMF_FIELD_BCC: |
70 | mail->setBcc( *parseAddressList( field->field.bcc->addr_list ) ); | 71 | mail->setBcc( *parseAddressList( field->field.bcc->addr_list ) ); |
71 | break; | 72 | break; |
72 | case MAILIMF_FIELD_SUBJECT: | 73 | case MAILIMF_FIELD_SUBJECT: |
73 | mail->setSubject( QString( field->field.subject->value ) ); | 74 | mail->setSubject( QString( field->field.subject->value ) ); |
74 | break; | 75 | break; |
75 | case MAILIMF_FIELD_ORIG_DATE: | 76 | case MAILIMF_FIELD_ORIG_DATE: |
76 | mail->setDate( *parseDateTime( field->field.orig_date->date_time ) ); | 77 | mail->setDate( *parseDateTime( field->field.orig_date->date_time ) ); |
77 | break; | 78 | break; |
78 | default: | 79 | default: |
79 | break; | 80 | break; |
80 | } | 81 | } |
81 | } | 82 | } |
82 | 83 | ||
83 | return mail; | 84 | return mail; |
84 | } | 85 | } |
85 | 86 | ||
86 | QString *POP3wrapper::parseDateTime( mailimf_date_time *date ) | 87 | QString *POP3wrapper::parseDateTime( mailimf_date_time *date ) |
87 | { | 88 | { |
88 | char tmp[23]; | 89 | char tmp[23]; |
89 | 90 | ||
90 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | 91 | 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 | date->day, date->month, date->year, date->hour, date->min, date->sec, date->zone ); |
92 | 93 | ||
93 | QString *result = new QString( tmp ); | 94 | QString *result = new QString( tmp ); |
94 | 95 | ||
95 | return result; | 96 | return result; |
96 | } | 97 | } |
97 | 98 | ||
98 | QString *POP3wrapper::parseAddressList( mailimf_address_list *list ) | 99 | QString *POP3wrapper::parseAddressList( mailimf_address_list *list ) |
99 | { | 100 | { |
100 | QString *result = new QString( "" ); | 101 | QString *result = new QString( "" ); |
101 | 102 | ||
102 | bool first = true; | 103 | bool first = true; |
103 | for ( clistiter *current = clist_begin( list->list ); current != NULL; current = current->next ) { | 104 | for ( clistiter *current = clist_begin( list->list ); current != NULL; current = current->next ) { |
104 | mailimf_address *addr = (mailimf_address *) current->data; | 105 | mailimf_address *addr = (mailimf_address *) current->data; |
105 | 106 | ||
106 | if ( !first ) { | 107 | if ( !first ) { |
107 | result->append( "," ); | 108 | result->append( "," ); |
108 | } else { | 109 | } else { |
109 | first = false; | 110 | first = false; |
110 | } | 111 | } |
111 | 112 | ||
112 | QString *tmp; | 113 | QString *tmp; |
113 | 114 | ||
114 | switch ( addr->type ) { | 115 | switch ( addr->type ) { |
115 | case MAILIMF_ADDRESS_MAILBOX: | 116 | case MAILIMF_ADDRESS_MAILBOX: |
116 | tmp = parseMailbox( addr->mailbox ); | 117 | tmp = parseMailbox( addr->mailbox ); |
117 | result->append( *tmp ); | 118 | result->append( *tmp ); |
118 | delete tmp; | 119 | delete tmp; |
119 | break; | 120 | break; |
120 | case MAILIMF_ADDRESS_GROUP: | 121 | case MAILIMF_ADDRESS_GROUP: |
121 | tmp = parseGroup( addr->group ); | 122 | tmp = parseGroup( addr->group ); |
122 | result->append( *tmp ); | 123 | result->append( *tmp ); |
123 | delete tmp; | 124 | delete tmp; |
124 | break; | 125 | break; |
125 | default: | 126 | default: |
126 | qDebug( "POP3: unkown mailimf address type" ); | 127 | qDebug( "POP3: unkown mailimf address type" ); |
127 | break; | 128 | break; |
128 | } | 129 | } |
129 | } | 130 | } |
130 | 131 | ||
131 | return result; | 132 | return result; |
132 | } | 133 | } |
133 | 134 | ||
134 | QString *POP3wrapper::parseGroup( mailimf_group *group ) | 135 | QString *POP3wrapper::parseGroup( mailimf_group *group ) |
135 | { | 136 | { |
136 | QString *result = new QString( "" ); | 137 | QString *result = new QString( "" ); |
137 | 138 | ||
138 | result->append( group->display_name ); | 139 | result->append( group->display_name ); |
139 | result->append( ": " ); | 140 | result->append( ": " ); |
140 | 141 | ||
141 | if ( group->mb_list != NULL ) { | 142 | if ( group->mb_list != NULL ) { |
142 | QString *tmp = parseMailboxList( group->mb_list ); | 143 | QString *tmp = parseMailboxList( group->mb_list ); |
143 | result->append( *tmp ); | 144 | result->append( *tmp ); |
144 | delete tmp; | 145 | delete tmp; |
145 | } | 146 | } |
146 | 147 | ||
147 | result->append( ";" ); | 148 | result->append( ";" ); |
148 | 149 | ||
149 | return result; | 150 | return result; |
150 | } | 151 | } |
151 | 152 | ||
152 | QString *POP3wrapper::parseMailbox( mailimf_mailbox *box ) | 153 | QString *POP3wrapper::parseMailbox( mailimf_mailbox *box ) |
153 | { | 154 | { |
154 | QString *result = new QString( "" ); | 155 | QString *result = new QString( "" ); |
155 | 156 | ||
156 | if ( box->display_name == NULL ) { | 157 | if ( box->display_name == NULL ) { |
157 | result->append( box->addr_spec ); | 158 | result->append( box->addr_spec ); |
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp index 2aaff30..72f3c36 100644 --- a/noncore/net/mail/pop3wrapper.cpp +++ b/noncore/net/mail/pop3wrapper.cpp | |||
@@ -1,157 +1,158 @@ | |||
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 | if (!m_pop3) return; | ||
30 | mailpop3_list( m_pop3, &messages ); | 31 | mailpop3_list( m_pop3, &messages ); |
31 | 32 | ||
32 | for ( int i = carray_count( messages ); i > 0; i-- ) { | 33 | for ( int i = carray_count( messages ); i > 0; i-- ) { |
33 | mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); | 34 | mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); |
34 | 35 | ||
35 | err = mailpop3_header( m_pop3, info->index, &header, &length ); | 36 | err = mailpop3_header( m_pop3, info->index, &header, &length ); |
36 | if ( err != MAILPOP3_NO_ERROR ) { | 37 | if ( err != MAILPOP3_NO_ERROR ) { |
37 | qDebug( "POP3: error retrieving header msgid: %i", info->index ); | 38 | qDebug( "POP3: error retrieving header msgid: %i", info->index ); |
38 | logout(); | 39 | logout(); |
39 | return; | 40 | return; |
40 | } | 41 | } |
41 | RecMail *mail = parseHeader( header ); | 42 | RecMail *mail = parseHeader( header ); |
42 | mail->setNumber( info->index ); | 43 | mail->setNumber( info->index ); |
43 | target.append( mail ); | 44 | target.append( mail ); |
44 | } | 45 | } |
45 | 46 | ||
46 | logout(); | 47 | logout(); |
47 | } | 48 | } |
48 | 49 | ||
49 | RecMail *POP3wrapper::parseHeader( const char *header ) | 50 | RecMail *POP3wrapper::parseHeader( const char *header ) |
50 | { | 51 | { |
51 | int err = MAILIMF_NO_ERROR; | 52 | int err = MAILIMF_NO_ERROR; |
52 | size_t curTok; | 53 | size_t curTok; |
53 | RecMail *mail = new RecMail(); | 54 | RecMail *mail = new RecMail(); |
54 | mailimf_fields *fields; | 55 | mailimf_fields *fields; |
55 | 56 | ||
56 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); | 57 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); |
57 | for ( clistiter *current = clist_begin( fields->list ); current != NULL; current = current->next ) { | 58 | for ( clistiter *current = clist_begin( fields->list ); current != NULL; current = current->next ) { |
58 | mailimf_field *field = (mailimf_field *) current->data; | 59 | mailimf_field *field = (mailimf_field *) current->data; |
59 | switch ( field->type ) { | 60 | switch ( field->type ) { |
60 | case MAILIMF_FIELD_FROM: | 61 | case MAILIMF_FIELD_FROM: |
61 | mail->setFrom( *parseMailboxList( field->field.from->mb_list ) ); | 62 | mail->setFrom( *parseMailboxList( field->field.from->mb_list ) ); |
62 | break; | 63 | break; |
63 | case MAILIMF_FIELD_TO: | 64 | case MAILIMF_FIELD_TO: |
64 | mail->setTo( *parseAddressList( field->field.to->addr_list ) ); | 65 | mail->setTo( *parseAddressList( field->field.to->addr_list ) ); |
65 | break; | 66 | break; |
66 | case MAILIMF_FIELD_CC: | 67 | case MAILIMF_FIELD_CC: |
67 | mail->setCC( *parseAddressList( field->field.cc->addr_list ) ); | 68 | mail->setCC( *parseAddressList( field->field.cc->addr_list ) ); |
68 | break; | 69 | break; |
69 | case MAILIMF_FIELD_BCC: | 70 | case MAILIMF_FIELD_BCC: |
70 | mail->setBcc( *parseAddressList( field->field.bcc->addr_list ) ); | 71 | mail->setBcc( *parseAddressList( field->field.bcc->addr_list ) ); |
71 | break; | 72 | break; |
72 | case MAILIMF_FIELD_SUBJECT: | 73 | case MAILIMF_FIELD_SUBJECT: |
73 | mail->setSubject( QString( field->field.subject->value ) ); | 74 | mail->setSubject( QString( field->field.subject->value ) ); |
74 | break; | 75 | break; |
75 | case MAILIMF_FIELD_ORIG_DATE: | 76 | case MAILIMF_FIELD_ORIG_DATE: |
76 | mail->setDate( *parseDateTime( field->field.orig_date->date_time ) ); | 77 | mail->setDate( *parseDateTime( field->field.orig_date->date_time ) ); |
77 | break; | 78 | break; |
78 | default: | 79 | default: |
79 | break; | 80 | break; |
80 | } | 81 | } |
81 | } | 82 | } |
82 | 83 | ||
83 | return mail; | 84 | return mail; |
84 | } | 85 | } |
85 | 86 | ||
86 | QString *POP3wrapper::parseDateTime( mailimf_date_time *date ) | 87 | QString *POP3wrapper::parseDateTime( mailimf_date_time *date ) |
87 | { | 88 | { |
88 | char tmp[23]; | 89 | char tmp[23]; |
89 | 90 | ||
90 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | 91 | 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 | date->day, date->month, date->year, date->hour, date->min, date->sec, date->zone ); |
92 | 93 | ||
93 | QString *result = new QString( tmp ); | 94 | QString *result = new QString( tmp ); |
94 | 95 | ||
95 | return result; | 96 | return result; |
96 | } | 97 | } |
97 | 98 | ||
98 | QString *POP3wrapper::parseAddressList( mailimf_address_list *list ) | 99 | QString *POP3wrapper::parseAddressList( mailimf_address_list *list ) |
99 | { | 100 | { |
100 | QString *result = new QString( "" ); | 101 | QString *result = new QString( "" ); |
101 | 102 | ||
102 | bool first = true; | 103 | bool first = true; |
103 | for ( clistiter *current = clist_begin( list->list ); current != NULL; current = current->next ) { | 104 | for ( clistiter *current = clist_begin( list->list ); current != NULL; current = current->next ) { |
104 | mailimf_address *addr = (mailimf_address *) current->data; | 105 | mailimf_address *addr = (mailimf_address *) current->data; |
105 | 106 | ||
106 | if ( !first ) { | 107 | if ( !first ) { |
107 | result->append( "," ); | 108 | result->append( "," ); |
108 | } else { | 109 | } else { |
109 | first = false; | 110 | first = false; |
110 | } | 111 | } |
111 | 112 | ||
112 | QString *tmp; | 113 | QString *tmp; |
113 | 114 | ||
114 | switch ( addr->type ) { | 115 | switch ( addr->type ) { |
115 | case MAILIMF_ADDRESS_MAILBOX: | 116 | case MAILIMF_ADDRESS_MAILBOX: |
116 | tmp = parseMailbox( addr->mailbox ); | 117 | tmp = parseMailbox( addr->mailbox ); |
117 | result->append( *tmp ); | 118 | result->append( *tmp ); |
118 | delete tmp; | 119 | delete tmp; |
119 | break; | 120 | break; |
120 | case MAILIMF_ADDRESS_GROUP: | 121 | case MAILIMF_ADDRESS_GROUP: |
121 | tmp = parseGroup( addr->group ); | 122 | tmp = parseGroup( addr->group ); |
122 | result->append( *tmp ); | 123 | result->append( *tmp ); |
123 | delete tmp; | 124 | delete tmp; |
124 | break; | 125 | break; |
125 | default: | 126 | default: |
126 | qDebug( "POP3: unkown mailimf address type" ); | 127 | qDebug( "POP3: unkown mailimf address type" ); |
127 | break; | 128 | break; |
128 | } | 129 | } |
129 | } | 130 | } |
130 | 131 | ||
131 | return result; | 132 | return result; |
132 | } | 133 | } |
133 | 134 | ||
134 | QString *POP3wrapper::parseGroup( mailimf_group *group ) | 135 | QString *POP3wrapper::parseGroup( mailimf_group *group ) |
135 | { | 136 | { |
136 | QString *result = new QString( "" ); | 137 | QString *result = new QString( "" ); |
137 | 138 | ||
138 | result->append( group->display_name ); | 139 | result->append( group->display_name ); |
139 | result->append( ": " ); | 140 | result->append( ": " ); |
140 | 141 | ||
141 | if ( group->mb_list != NULL ) { | 142 | if ( group->mb_list != NULL ) { |
142 | QString *tmp = parseMailboxList( group->mb_list ); | 143 | QString *tmp = parseMailboxList( group->mb_list ); |
143 | result->append( *tmp ); | 144 | result->append( *tmp ); |
144 | delete tmp; | 145 | delete tmp; |
145 | } | 146 | } |
146 | 147 | ||
147 | result->append( ";" ); | 148 | result->append( ";" ); |
148 | 149 | ||
149 | return result; | 150 | return result; |
150 | } | 151 | } |
151 | 152 | ||
152 | QString *POP3wrapper::parseMailbox( mailimf_mailbox *box ) | 153 | QString *POP3wrapper::parseMailbox( mailimf_mailbox *box ) |
153 | { | 154 | { |
154 | QString *result = new QString( "" ); | 155 | QString *result = new QString( "" ); |
155 | 156 | ||
156 | if ( box->display_name == NULL ) { | 157 | if ( box->display_name == NULL ) { |
157 | result->append( box->addr_spec ); | 158 | result->append( box->addr_spec ); |