Diffstat (limited to 'noncore/net/mail/libmailwrapper/pop3wrapper.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index 30f80ff..22a4c70 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp | |||
@@ -1,13 +1,17 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
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 | #include <libetpan/mailmime.h> | 5 | #include <libetpan/mailmime.h> |
6 | #include <libetpan/data_message_driver.h> | ||
6 | #include <qfile.h> | 7 | #include <qfile.h> |
7 | 8 | ||
9 | /* we don't fetch messages larger than 5 MB */ | ||
10 | #define HARD_MSG_SIZE_LIMIT 5242880 | ||
11 | |||
8 | POP3wrapper::POP3wrapper( POP3account *a ) | 12 | POP3wrapper::POP3wrapper( POP3account *a ) |
9 | { | 13 | { |
10 | account = a; | 14 | account = a; |
11 | m_pop3 = NULL; | 15 | m_pop3 = NULL; |
12 | msgTempName = a->getFileName()+"_msg_cache"; | 16 | msgTempName = a->getFileName()+"_msg_cache"; |
13 | last_msg_id = 0; | 17 | last_msg_id = 0; |
@@ -34,16 +38,21 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) | |||
34 | size_t length = 0; | 38 | size_t length = 0; |
35 | 39 | ||
36 | login(); | 40 | login(); |
37 | if ( !m_pop3 ) { | 41 | if ( !m_pop3 ) { |
38 | return RecBody(); | 42 | return RecBody(); |
39 | } | 43 | } |
44 | |||
40 | RecBody body; | 45 | RecBody body; |
41 | 46 | ||
42 | QFile msg_cache(msgTempName); | 47 | QFile msg_cache(msgTempName); |
43 | 48 | ||
49 | if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { | ||
50 | qDebug("Message to large: %i",mail.Msgsize()); | ||
51 | return body; | ||
52 | } | ||
44 | if (mail.getNumber()!=last_msg_id) { | 53 | if (mail.getNumber()!=last_msg_id) { |
45 | if (msg_cache.exists()) { | 54 | if (msg_cache.exists()) { |
46 | msg_cache.remove(); | 55 | msg_cache.remove(); |
47 | } | 56 | } |
48 | msg_cache.open(IO_ReadWrite|IO_Truncate); | 57 | msg_cache.open(IO_ReadWrite|IO_Truncate); |
49 | last_msg_id = mail.getNumber(); | 58 | last_msg_id = mail.getNumber(); |
@@ -76,25 +85,49 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) | |||
76 | RecBody POP3wrapper::parseMail( char *message ) | 85 | RecBody POP3wrapper::parseMail( char *message ) |
77 | { | 86 | { |
78 | int err = MAILIMF_NO_ERROR; | 87 | int err = MAILIMF_NO_ERROR; |
79 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ | 88 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ |
80 | size_t curTok = 0; | 89 | size_t curTok = 0; |
81 | mailimf_message *result = 0; | 90 | mailimf_message *result = 0; |
91 | mailmessage * msg=0; | ||
92 | struct mailmime * mime=0; | ||
93 | struct mailmime_single_fields fields; | ||
94 | |||
82 | RecBody body; | 95 | RecBody body; |
83 | 96 | ||
84 | 97 | ||
85 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); | 98 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); |
86 | if ( err != MAILIMF_NO_ERROR ) { | 99 | if ( err != MAILIMF_NO_ERROR ) { |
87 | if (result) mailimf_message_free(result); | 100 | if (result) mailimf_message_free(result); |
88 | return body; | 101 | return body; |
89 | } | 102 | } |
90 | 103 | ||
91 | struct mailimf_body * b = 0; | 104 | #if 0 |
92 | struct mailimf_fields * f = 0; | 105 | char*body_msg = message; |
106 | if ( result && result->msg_body && result->msg_body->bd_text ) { | ||
107 | body_msg = (char*)result->msg_body->bd_text; | ||
108 | result->msg_body->bd_text = 0; | ||
109 | } | ||
110 | |||
111 | msg = mailmessage_new(); | ||
112 | mailmessage_init(msg, NULL, data_message_driver, 0, strlen(body_msg)); | ||
113 | generic_message_t * msg_data; | ||
114 | msg_data = (generic_message_t *)msg->msg_data; | ||
115 | msg_data->msg_fetched = 1; | ||
116 | msg_data->msg_message = body_msg; | ||
117 | msg_data->msg_length = strlen(body_msg); | ||
118 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | ||
119 | err = mailmessage_get_bodystructure(msg,&mime); | ||
93 | 120 | ||
121 | if (mime->mm_mime_fields != NULL) { | ||
122 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, | ||
123 | mime->mm_content_type); | ||
124 | } | ||
125 | #endif | ||
94 | 126 | ||
127 | #if 1 | ||
95 | if ( result && result->msg_body && result->msg_body->bd_text ) { | 128 | if ( result && result->msg_body && result->msg_body->bd_text ) { |
96 | qDebug( "POP3: bodytext found" ); | 129 | qDebug( "POP3: bodytext found" ); |
97 | // when curTok isn't set to 0 this line will fault! 'cause upper line faults! | 130 | // when curTok isn't set to 0 this line will fault! 'cause upper line faults! |
98 | body.setBodytext( QString( result->msg_body->bd_text ) ); | 131 | body.setBodytext( QString( result->msg_body->bd_text ) ); |
99 | #if 0 | 132 | #if 0 |
100 | curTok = 0; | 133 | curTok = 0; |
@@ -105,12 +138,13 @@ RecBody POP3wrapper::parseMail( char *message ) | |||
105 | if (mresult) { | 138 | if (mresult) { |
106 | mailmime_content_free(mresult); | 139 | mailmime_content_free(mresult); |
107 | } | 140 | } |
108 | #endif | 141 | #endif |
109 | mailimf_message_free(result); | 142 | mailimf_message_free(result); |
110 | } | 143 | } |
144 | #endif | ||
111 | return body; | 145 | return body; |
112 | } | 146 | } |
113 | 147 | ||
114 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) | 148 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) |
115 | { | 149 | { |
116 | int err = MAILPOP3_NO_ERROR; | 150 | int err = MAILPOP3_NO_ERROR; |
@@ -169,13 +203,13 @@ RecMail *POP3wrapper::parseHeader( const char *header ) | |||
169 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); | 203 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); |
170 | break; | 204 | break; |
171 | case MAILIMF_FIELD_BCC: | 205 | case MAILIMF_FIELD_BCC: |
172 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); | 206 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); |
173 | break; | 207 | break; |
174 | case MAILIMF_FIELD_SUBJECT: | 208 | case MAILIMF_FIELD_SUBJECT: |
175 | mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); | 209 | mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); |
176 | break; | 210 | break; |
177 | case MAILIMF_FIELD_ORIG_DATE: | 211 | case MAILIMF_FIELD_ORIG_DATE: |
178 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); | 212 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); |
179 | break; | 213 | break; |
180 | case MAILIMF_FIELD_MESSAGE_ID: | 214 | case MAILIMF_FIELD_MESSAGE_ID: |
181 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); | 215 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); |
@@ -200,13 +234,12 @@ RecMail *POP3wrapper::parseHeader( const char *header ) | |||
200 | if (value.lower()=="ro") { | 234 | if (value.lower()=="ro") { |
201 | mFlags.setBit(FLAG_SEEN); | 235 | mFlags.setBit(FLAG_SEEN); |
202 | } | 236 | } |
203 | } else if (status.lower()=="x-status") { | 237 | } else if (status.lower()=="x-status") { |
204 | qDebug("X-Status: %s",value.latin1()); | 238 | qDebug("X-Status: %s",value.latin1()); |
205 | if (value.lower()=="a") { | 239 | if (value.lower()=="a") { |
206 | |||
207 | mFlags.setBit(FLAG_ANSWERED); | 240 | mFlags.setBit(FLAG_ANSWERED); |
208 | } | 241 | } |
209 | } else { | 242 | } else { |
210 | // qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, | 243 | // qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, |
211 | // field->fld_data.fld_optional_field->fld_value); | 244 | // field->fld_data.fld_optional_field->fld_value); |
212 | } | 245 | } |
@@ -281,13 +314,13 @@ QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) | |||
281 | { | 314 | { |
282 | QString result( "" ); | 315 | QString result( "" ); |
283 | 316 | ||
284 | if ( box->mb_display_name == NULL ) { | 317 | if ( box->mb_display_name == NULL ) { |
285 | result.append( box->mb_addr_spec ); | 318 | result.append( box->mb_addr_spec ); |
286 | } else { | 319 | } else { |
287 | result.append( box->mb_display_name ); | 320 | result.append( convert_String(box->mb_display_name).latin1() ); |
288 | result.append( " <" ); | 321 | result.append( " <" ); |
289 | result.append( box->mb_addr_spec ); | 322 | result.append( box->mb_addr_spec ); |
290 | result.append( ">" ); | 323 | result.append( ">" ); |
291 | } | 324 | } |
292 | 325 | ||
293 | return result; | 326 | return result; |