summaryrefslogtreecommitdiff
authorjgf <jgf>2003-12-10 11:56:23 (UTC)
committer jgf <jgf>2003-12-10 11:56:23 (UTC)
commitb09fe710918a447f37c7ec92a6becb9953ada063 (patch) (unidiff)
tree0f3a056b961697e4694cf45c49003a34b3a691ce
parent9f974b45ef133d807f8441d84cfebe9b51865499 (diff)
downloadopie-b09fe710918a447f37c7ec92a6becb9953ada063.zip
opie-b09fe710918a447f37c7ec92a6becb9953ada063.tar.gz
opie-b09fe710918a447f37c7ec92a6becb9953ada063.tar.bz2
first working listMessages
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp140
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h5
-rw-r--r--noncore/net/mail/pop3wrapper.cpp140
-rw-r--r--noncore/net/mail/pop3wrapper.h5
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
@@ -43,21 +43,151 @@ void POP3wrapper::listMessages( QList<RecMail> &target )
43 target.append( mail ); 43 target.append( mail );
44 } 44 }
45 45
46 logout(); 46 logout();
47} 47}
48 48
49RecMail *POP3wrapper::parseHeader( const char *h ) 49RecMail *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? 86QString *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; 98QString *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
134QString *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
152QString *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
168QString *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
60void POP3wrapper::login() 190void POP3wrapper::login()
61{ 191{
62 if ( m_pop3 != NULL ) logout(); 192 if ( m_pop3 != NULL ) logout();
63 193
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
@@ -18,12 +18,17 @@ public:
18protected: 18protected:
19 void login(); 19 void login();
20 void logout(); 20 void logout();
21 21
22private: 22private:
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
@@ -43,21 +43,151 @@ void POP3wrapper::listMessages( QList<RecMail> &target )
43 target.append( mail ); 43 target.append( mail );
44 } 44 }
45 45
46 logout(); 46 logout();
47} 47}
48 48
49RecMail *POP3wrapper::parseHeader( const char *h ) 49RecMail *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? 86QString *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; 98QString *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
134QString *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
152QString *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
168QString *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
60void POP3wrapper::login() 190void POP3wrapper::login()
61{ 191{
62 if ( m_pop3 != NULL ) logout(); 192 if ( m_pop3 != NULL ) logout();
63 193
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
@@ -18,12 +18,17 @@ public:
18protected: 18protected:
19 void login(); 19 void login();
20 void logout(); 20 void logout();
21 21
22private: 22private:
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