-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 69 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 7 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.cpp | 69 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.h | 7 |
4 files changed, 128 insertions, 24 deletions
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index 4508a95..30f80ff 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp | |||
@@ -1,155 +1,206 @@ | |||
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> | ||
6 | #include <qfile.h> | ||
5 | 7 | ||
6 | POP3wrapper::POP3wrapper( POP3account *a ) | 8 | POP3wrapper::POP3wrapper( POP3account *a ) |
7 | { | 9 | { |
8 | account = a; | 10 | account = a; |
9 | m_pop3 = NULL; | 11 | m_pop3 = NULL; |
12 | msgTempName = a->getFileName()+"_msg_cache"; | ||
13 | last_msg_id = 0; | ||
10 | } | 14 | } |
11 | 15 | ||
12 | POP3wrapper::~POP3wrapper() | 16 | POP3wrapper::~POP3wrapper() |
13 | { | 17 | { |
14 | logout(); | 18 | logout(); |
19 | QFile msg_cache(msgTempName); | ||
20 | if (msg_cache.exists()) { | ||
21 | msg_cache.remove(); | ||
22 | } | ||
15 | } | 23 | } |
16 | 24 | ||
17 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) | 25 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) |
18 | { | 26 | { |
19 | //qDebug( "POP3: %i of %i", current, maximum ); | 27 | //qDebug( "POP3: %i of %i", current, maximum ); |
20 | } | 28 | } |
21 | 29 | ||
22 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) | 30 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) |
23 | { | 31 | { |
24 | int err = MAILPOP3_NO_ERROR; | 32 | int err = MAILPOP3_NO_ERROR; |
25 | char *message; | 33 | char *message; |
26 | size_t length = 0; | 34 | size_t length = 0; |
27 | 35 | ||
28 | login(); | 36 | login(); |
29 | if ( !m_pop3 ) return RecBody(); | 37 | if ( !m_pop3 ) { |
30 | |||
31 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); | ||
32 | if ( err != MAILPOP3_NO_ERROR ) { | ||
33 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); | ||
34 | return RecBody(); | 38 | return RecBody(); |
35 | } | 39 | } |
40 | RecBody body; | ||
36 | 41 | ||
37 | return parseBody( message ); | 42 | QFile msg_cache(msgTempName); |
43 | |||
44 | if (mail.getNumber()!=last_msg_id) { | ||
45 | if (msg_cache.exists()) { | ||
46 | msg_cache.remove(); | ||
47 | } | ||
48 | msg_cache.open(IO_ReadWrite|IO_Truncate); | ||
49 | last_msg_id = mail.getNumber(); | ||
50 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); | ||
51 | if ( err != MAILPOP3_NO_ERROR ) { | ||
52 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); | ||
53 | last_msg_id = 0; | ||
54 | return RecBody(); | ||
55 | } | ||
56 | msg_cache.writeBlock(message,length); | ||
57 | } else { | ||
58 | QString msg=""; | ||
59 | msg_cache.open(IO_ReadOnly); | ||
60 | message = new char[4096]; | ||
61 | memset(message,0,4096); | ||
62 | while (msg_cache.readBlock(message,4095)>0) { | ||
63 | msg+=message; | ||
64 | memset(message,0,4096); | ||
65 | } | ||
66 | delete message; | ||
67 | message = (char*)malloc(msg.length()+1*sizeof(char)); | ||
68 | memset(message,0,msg.length()+1); | ||
69 | memcpy(message,msg.latin1(),msg.length()); | ||
70 | } | ||
71 | body = parseMail(message); | ||
72 | free(message); | ||
73 | return body; | ||
38 | } | 74 | } |
39 | 75 | ||
40 | RecBody POP3wrapper::parseBody( const char *message ) | 76 | RecBody POP3wrapper::parseMail( char *message ) |
41 | { | 77 | { |
42 | int err = MAILIMF_NO_ERROR; | 78 | int err = MAILIMF_NO_ERROR; |
43 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ | 79 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ |
44 | size_t curTok = 0; | 80 | size_t curTok = 0; |
45 | mailimf_message *result = 0; | 81 | mailimf_message *result = 0; |
46 | RecBody body; | 82 | RecBody body; |
47 | 83 | ||
84 | |||
48 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); | 85 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); |
49 | if ( err != MAILIMF_NO_ERROR ) { | 86 | if ( err != MAILIMF_NO_ERROR ) { |
50 | if (result) mailimf_message_free(result); | 87 | if (result) mailimf_message_free(result); |
51 | return body; | 88 | return body; |
52 | } | 89 | } |
53 | 90 | ||
91 | struct mailimf_body * b = 0; | ||
92 | struct mailimf_fields * f = 0; | ||
93 | |||
94 | |||
54 | if ( result && result->msg_body && result->msg_body->bd_text ) { | 95 | if ( result && result->msg_body && result->msg_body->bd_text ) { |
55 | qDebug( "POP3: bodytext found" ); | 96 | qDebug( "POP3: bodytext found" ); |
56 | // when curTok isn't set to 0 this line will fault! 'cause upper line faults! | 97 | // when curTok isn't set to 0 this line will fault! 'cause upper line faults! |
57 | body.setBodytext( QString( result->msg_body->bd_text ) ); | 98 | body.setBodytext( QString( result->msg_body->bd_text ) ); |
99 | #if 0 | ||
100 | curTok = 0; | ||
101 | mailmime_content*mresult = 0; | ||
102 | size_t index = 0; | ||
103 | mailmime_content_parse(result->msg_body->bd_text, | ||
104 | strlen(result->msg_body->bd_text),&index,&mresult); | ||
105 | if (mresult) { | ||
106 | mailmime_content_free(mresult); | ||
107 | } | ||
108 | #endif | ||
109 | mailimf_message_free(result); | ||
58 | } | 110 | } |
59 | if (result) mailimf_message_free(result); | ||
60 | return body; | 111 | return body; |
61 | } | 112 | } |
62 | 113 | ||
63 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) | 114 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) |
64 | { | 115 | { |
65 | int err = MAILPOP3_NO_ERROR; | 116 | int err = MAILPOP3_NO_ERROR; |
66 | char * header = 0; | 117 | char * header = 0; |
67 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ | 118 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ |
68 | size_t length = 0; | 119 | size_t length = 0; |
69 | carray * messages = 0; | 120 | carray * messages = 0; |
70 | 121 | ||
71 | login(); | 122 | login(); |
72 | if (!m_pop3) return; | 123 | if (!m_pop3) return; |
73 | mailpop3_list( m_pop3, &messages ); | 124 | mailpop3_list( m_pop3, &messages ); |
74 | 125 | ||
75 | for (unsigned int i = 0; i < carray_count(messages);++i) { | 126 | for (unsigned int i = 0; i < carray_count(messages);++i) { |
76 | mailpop3_msg_info *info; | 127 | mailpop3_msg_info *info; |
77 | err = mailpop3_get_msg_info(m_pop3,i+1,&info); | 128 | err = mailpop3_get_msg_info(m_pop3,i+1,&info); |
78 | if (info->msg_deleted) | 129 | if (info->msg_deleted) |
79 | continue; | 130 | continue; |
80 | err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); | 131 | err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); |
81 | if ( err != MAILPOP3_NO_ERROR ) { | 132 | if ( err != MAILPOP3_NO_ERROR ) { |
82 | qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); | 133 | qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); |
83 | free(header); | 134 | free(header); |
84 | return; | 135 | return; |
85 | } | 136 | } |
86 | RecMail *mail = parseHeader( header ); | 137 | RecMail *mail = parseHeader( header ); |
87 | mail->setNumber( info->msg_index ); | 138 | mail->setNumber( info->msg_index ); |
88 | mail->setWrapper(this); | 139 | mail->setWrapper(this); |
89 | mail->setMsgsize(info->msg_size); | 140 | mail->setMsgsize(info->msg_size); |
90 | target.append( mail ); | 141 | target.append( mail ); |
91 | free(header); | 142 | free(header); |
92 | } | 143 | } |
93 | } | 144 | } |
94 | 145 | ||
95 | RecMail *POP3wrapper::parseHeader( const char *header ) | 146 | RecMail *POP3wrapper::parseHeader( const char *header ) |
96 | { | 147 | { |
97 | int err = MAILIMF_NO_ERROR; | 148 | int err = MAILIMF_NO_ERROR; |
98 | size_t curTok = 0; | 149 | size_t curTok = 0; |
99 | RecMail *mail = new RecMail(); | 150 | RecMail *mail = new RecMail(); |
100 | mailimf_fields *fields; | 151 | mailimf_fields *fields; |
101 | mailimf_references * refs; | 152 | mailimf_references * refs; |
102 | mailimf_keywords*keys; | 153 | mailimf_keywords*keys; |
103 | QString status; | 154 | QString status; |
104 | QString value; | 155 | QString value; |
105 | QBitArray mFlags(7); | 156 | QBitArray mFlags(7); |
106 | 157 | ||
107 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); | 158 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); |
108 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { | 159 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { |
109 | mailimf_field *field = (mailimf_field *) current->data; | 160 | mailimf_field *field = (mailimf_field *) current->data; |
110 | switch ( field->fld_type ) { | 161 | switch ( field->fld_type ) { |
111 | case MAILIMF_FIELD_FROM: | 162 | case MAILIMF_FIELD_FROM: |
112 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); | 163 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); |
113 | break; | 164 | break; |
114 | case MAILIMF_FIELD_TO: | 165 | case MAILIMF_FIELD_TO: |
115 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); | 166 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); |
116 | break; | 167 | break; |
117 | case MAILIMF_FIELD_CC: | 168 | case MAILIMF_FIELD_CC: |
118 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); | 169 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); |
119 | break; | 170 | break; |
120 | case MAILIMF_FIELD_BCC: | 171 | case MAILIMF_FIELD_BCC: |
121 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); | 172 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); |
122 | break; | 173 | break; |
123 | case MAILIMF_FIELD_SUBJECT: | 174 | case MAILIMF_FIELD_SUBJECT: |
124 | mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); | 175 | mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); |
125 | break; | 176 | break; |
126 | case MAILIMF_FIELD_ORIG_DATE: | 177 | case MAILIMF_FIELD_ORIG_DATE: |
127 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); | 178 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); |
128 | break; | 179 | break; |
129 | case MAILIMF_FIELD_MESSAGE_ID: | 180 | case MAILIMF_FIELD_MESSAGE_ID: |
130 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); | 181 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); |
131 | break; | 182 | break; |
132 | case MAILIMF_FIELD_REFERENCES: | 183 | case MAILIMF_FIELD_REFERENCES: |
133 | refs = field->fld_data.fld_references; | 184 | refs = field->fld_data.fld_references; |
134 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | 185 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { |
135 | char * text = (char*)refs->mid_list->first->data; | 186 | char * text = (char*)refs->mid_list->first->data; |
136 | mail->setReplyto(QString(text)); | 187 | mail->setReplyto(QString(text)); |
137 | } | 188 | } |
138 | break; | 189 | break; |
139 | case MAILIMF_FIELD_KEYWORDS: | 190 | case MAILIMF_FIELD_KEYWORDS: |
140 | keys = field->fld_data.fld_keywords; | 191 | keys = field->fld_data.fld_keywords; |
141 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { | 192 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { |
142 | qDebug("Keyword: %s",(char*)cur->data); | 193 | qDebug("Keyword: %s",(char*)cur->data); |
143 | } | 194 | } |
144 | break; | 195 | break; |
145 | case MAILIMF_FIELD_OPTIONAL_FIELD: | 196 | case MAILIMF_FIELD_OPTIONAL_FIELD: |
146 | status = field->fld_data.fld_optional_field->fld_name; | 197 | status = field->fld_data.fld_optional_field->fld_name; |
147 | value = field->fld_data.fld_optional_field->fld_value; | 198 | value = field->fld_data.fld_optional_field->fld_value; |
148 | if (status.lower()=="status") { | 199 | if (status.lower()=="status") { |
149 | if (value.lower()=="ro") { | 200 | if (value.lower()=="ro") { |
150 | mFlags.setBit(FLAG_SEEN); | 201 | mFlags.setBit(FLAG_SEEN); |
151 | } | 202 | } |
152 | } else if (status.lower()=="x-status") { | 203 | } else if (status.lower()=="x-status") { |
153 | qDebug("X-Status: %s",value.latin1()); | 204 | qDebug("X-Status: %s",value.latin1()); |
154 | if (value.lower()=="a") { | 205 | if (value.lower()=="a") { |
155 | 206 | ||
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index 8d3adda..a05021c 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h | |||
@@ -1,48 +1,49 @@ | |||
1 | #ifndef __POP3WRAPPER | 1 | #ifndef __POP3WRAPPER |
2 | #define __POP3WRAPPER | 2 | #define __POP3WRAPPER |
3 | 3 | ||
4 | #include "mailwrapper.h" | 4 | #include "mailwrapper.h" |
5 | #include "abstractmail.h" | 5 | #include "abstractmail.h" |
6 | 6 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | class encodedString; | 9 | class encodedString; |
10 | struct mailpop3; | 10 | struct mailpop3; |
11 | 11 | ||
12 | class POP3wrapper : public AbstractMail | 12 | class POP3wrapper : public AbstractMail |
13 | { | 13 | { |
14 | Q_OBJECT | 14 | Q_OBJECT |
15 | 15 | ||
16 | public: | 16 | public: |
17 | POP3wrapper( POP3account *a ); | 17 | POP3wrapper( POP3account *a ); |
18 | virtual ~POP3wrapper(); | 18 | virtual ~POP3wrapper(); |
19 | /* mailbox will be ignored */ | 19 | /* mailbox will be ignored */ |
20 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 20 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
21 | virtual QList<Folder>* listFolders(); | 21 | virtual QList<Folder>* listFolders(); |
22 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); | 22 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); |
23 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); | 23 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); |
24 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); | 24 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); |
25 | 25 | ||
26 | virtual void deleteMail(const RecMail&mail); | 26 | virtual void deleteMail(const RecMail&mail); |
27 | virtual void answeredMail(const RecMail&mail); | 27 | virtual void answeredMail(const RecMail&mail); |
28 | 28 | ||
29 | RecBody fetchBody( const RecMail &mail ); | 29 | RecBody fetchBody( const RecMail &mail ); |
30 | static void pop3_progress( size_t current, size_t maximum ); | 30 | static void pop3_progress( size_t current, size_t maximum ); |
31 | 31 | ||
32 | protected: | 32 | protected: |
33 | void login(); | 33 | void login(); |
34 | void logout(); | 34 | void logout(); |
35 | 35 | ||
36 | private: | ||
37 | RecMail *parseHeader( const char *header ); | 36 | RecMail *parseHeader( const char *header ); |
38 | RecBody parseBody( const char *message ); | 37 | RecBody parseMail( char *message ); |
39 | QString parseMailboxList( mailimf_mailbox_list *list ); | 38 | QString parseMailboxList( mailimf_mailbox_list *list ); |
40 | QString parseMailbox( mailimf_mailbox *box ); | 39 | QString parseMailbox( mailimf_mailbox *box ); |
41 | QString parseGroup( mailimf_group *group ); | 40 | QString parseGroup( mailimf_group *group ); |
42 | QString parseAddressList( mailimf_address_list *list ); | 41 | QString parseAddressList( mailimf_address_list *list ); |
43 | QString parseDateTime( mailimf_date_time *date ); | 42 | QString parseDateTime( mailimf_date_time *date ); |
44 | POP3account *account; | 43 | POP3account *account; |
45 | mailpop3 *m_pop3; | 44 | mailpop3 *m_pop3; |
45 | QString msgTempName; | ||
46 | unsigned int last_msg_id; | ||
46 | }; | 47 | }; |
47 | 48 | ||
48 | #endif | 49 | #endif |
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp index 4508a95..30f80ff 100644 --- a/noncore/net/mail/pop3wrapper.cpp +++ b/noncore/net/mail/pop3wrapper.cpp | |||
@@ -1,155 +1,206 @@ | |||
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> | ||
6 | #include <qfile.h> | ||
5 | 7 | ||
6 | POP3wrapper::POP3wrapper( POP3account *a ) | 8 | POP3wrapper::POP3wrapper( POP3account *a ) |
7 | { | 9 | { |
8 | account = a; | 10 | account = a; |
9 | m_pop3 = NULL; | 11 | m_pop3 = NULL; |
12 | msgTempName = a->getFileName()+"_msg_cache"; | ||
13 | last_msg_id = 0; | ||
10 | } | 14 | } |
11 | 15 | ||
12 | POP3wrapper::~POP3wrapper() | 16 | POP3wrapper::~POP3wrapper() |
13 | { | 17 | { |
14 | logout(); | 18 | logout(); |
19 | QFile msg_cache(msgTempName); | ||
20 | if (msg_cache.exists()) { | ||
21 | msg_cache.remove(); | ||
22 | } | ||
15 | } | 23 | } |
16 | 24 | ||
17 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) | 25 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) |
18 | { | 26 | { |
19 | //qDebug( "POP3: %i of %i", current, maximum ); | 27 | //qDebug( "POP3: %i of %i", current, maximum ); |
20 | } | 28 | } |
21 | 29 | ||
22 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) | 30 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) |
23 | { | 31 | { |
24 | int err = MAILPOP3_NO_ERROR; | 32 | int err = MAILPOP3_NO_ERROR; |
25 | char *message; | 33 | char *message; |
26 | size_t length = 0; | 34 | size_t length = 0; |
27 | 35 | ||
28 | login(); | 36 | login(); |
29 | if ( !m_pop3 ) return RecBody(); | 37 | if ( !m_pop3 ) { |
30 | |||
31 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); | ||
32 | if ( err != MAILPOP3_NO_ERROR ) { | ||
33 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); | ||
34 | return RecBody(); | 38 | return RecBody(); |
35 | } | 39 | } |
40 | RecBody body; | ||
36 | 41 | ||
37 | return parseBody( message ); | 42 | QFile msg_cache(msgTempName); |
43 | |||
44 | if (mail.getNumber()!=last_msg_id) { | ||
45 | if (msg_cache.exists()) { | ||
46 | msg_cache.remove(); | ||
47 | } | ||
48 | msg_cache.open(IO_ReadWrite|IO_Truncate); | ||
49 | last_msg_id = mail.getNumber(); | ||
50 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); | ||
51 | if ( err != MAILPOP3_NO_ERROR ) { | ||
52 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); | ||
53 | last_msg_id = 0; | ||
54 | return RecBody(); | ||
55 | } | ||
56 | msg_cache.writeBlock(message,length); | ||
57 | } else { | ||
58 | QString msg=""; | ||
59 | msg_cache.open(IO_ReadOnly); | ||
60 | message = new char[4096]; | ||
61 | memset(message,0,4096); | ||
62 | while (msg_cache.readBlock(message,4095)>0) { | ||
63 | msg+=message; | ||
64 | memset(message,0,4096); | ||
65 | } | ||
66 | delete message; | ||
67 | message = (char*)malloc(msg.length()+1*sizeof(char)); | ||
68 | memset(message,0,msg.length()+1); | ||
69 | memcpy(message,msg.latin1(),msg.length()); | ||
70 | } | ||
71 | body = parseMail(message); | ||
72 | free(message); | ||
73 | return body; | ||
38 | } | 74 | } |
39 | 75 | ||
40 | RecBody POP3wrapper::parseBody( const char *message ) | 76 | RecBody POP3wrapper::parseMail( char *message ) |
41 | { | 77 | { |
42 | int err = MAILIMF_NO_ERROR; | 78 | int err = MAILIMF_NO_ERROR; |
43 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ | 79 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ |
44 | size_t curTok = 0; | 80 | size_t curTok = 0; |
45 | mailimf_message *result = 0; | 81 | mailimf_message *result = 0; |
46 | RecBody body; | 82 | RecBody body; |
47 | 83 | ||
84 | |||
48 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); | 85 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); |
49 | if ( err != MAILIMF_NO_ERROR ) { | 86 | if ( err != MAILIMF_NO_ERROR ) { |
50 | if (result) mailimf_message_free(result); | 87 | if (result) mailimf_message_free(result); |
51 | return body; | 88 | return body; |
52 | } | 89 | } |
53 | 90 | ||
91 | struct mailimf_body * b = 0; | ||
92 | struct mailimf_fields * f = 0; | ||
93 | |||
94 | |||
54 | if ( result && result->msg_body && result->msg_body->bd_text ) { | 95 | if ( result && result->msg_body && result->msg_body->bd_text ) { |
55 | qDebug( "POP3: bodytext found" ); | 96 | qDebug( "POP3: bodytext found" ); |
56 | // when curTok isn't set to 0 this line will fault! 'cause upper line faults! | 97 | // when curTok isn't set to 0 this line will fault! 'cause upper line faults! |
57 | body.setBodytext( QString( result->msg_body->bd_text ) ); | 98 | body.setBodytext( QString( result->msg_body->bd_text ) ); |
99 | #if 0 | ||
100 | curTok = 0; | ||
101 | mailmime_content*mresult = 0; | ||
102 | size_t index = 0; | ||
103 | mailmime_content_parse(result->msg_body->bd_text, | ||
104 | strlen(result->msg_body->bd_text),&index,&mresult); | ||
105 | if (mresult) { | ||
106 | mailmime_content_free(mresult); | ||
107 | } | ||
108 | #endif | ||
109 | mailimf_message_free(result); | ||
58 | } | 110 | } |
59 | if (result) mailimf_message_free(result); | ||
60 | return body; | 111 | return body; |
61 | } | 112 | } |
62 | 113 | ||
63 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) | 114 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) |
64 | { | 115 | { |
65 | int err = MAILPOP3_NO_ERROR; | 116 | int err = MAILPOP3_NO_ERROR; |
66 | char * header = 0; | 117 | char * header = 0; |
67 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ | 118 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ |
68 | size_t length = 0; | 119 | size_t length = 0; |
69 | carray * messages = 0; | 120 | carray * messages = 0; |
70 | 121 | ||
71 | login(); | 122 | login(); |
72 | if (!m_pop3) return; | 123 | if (!m_pop3) return; |
73 | mailpop3_list( m_pop3, &messages ); | 124 | mailpop3_list( m_pop3, &messages ); |
74 | 125 | ||
75 | for (unsigned int i = 0; i < carray_count(messages);++i) { | 126 | for (unsigned int i = 0; i < carray_count(messages);++i) { |
76 | mailpop3_msg_info *info; | 127 | mailpop3_msg_info *info; |
77 | err = mailpop3_get_msg_info(m_pop3,i+1,&info); | 128 | err = mailpop3_get_msg_info(m_pop3,i+1,&info); |
78 | if (info->msg_deleted) | 129 | if (info->msg_deleted) |
79 | continue; | 130 | continue; |
80 | err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); | 131 | err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); |
81 | if ( err != MAILPOP3_NO_ERROR ) { | 132 | if ( err != MAILPOP3_NO_ERROR ) { |
82 | qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); | 133 | qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); |
83 | free(header); | 134 | free(header); |
84 | return; | 135 | return; |
85 | } | 136 | } |
86 | RecMail *mail = parseHeader( header ); | 137 | RecMail *mail = parseHeader( header ); |
87 | mail->setNumber( info->msg_index ); | 138 | mail->setNumber( info->msg_index ); |
88 | mail->setWrapper(this); | 139 | mail->setWrapper(this); |
89 | mail->setMsgsize(info->msg_size); | 140 | mail->setMsgsize(info->msg_size); |
90 | target.append( mail ); | 141 | target.append( mail ); |
91 | free(header); | 142 | free(header); |
92 | } | 143 | } |
93 | } | 144 | } |
94 | 145 | ||
95 | RecMail *POP3wrapper::parseHeader( const char *header ) | 146 | RecMail *POP3wrapper::parseHeader( const char *header ) |
96 | { | 147 | { |
97 | int err = MAILIMF_NO_ERROR; | 148 | int err = MAILIMF_NO_ERROR; |
98 | size_t curTok = 0; | 149 | size_t curTok = 0; |
99 | RecMail *mail = new RecMail(); | 150 | RecMail *mail = new RecMail(); |
100 | mailimf_fields *fields; | 151 | mailimf_fields *fields; |
101 | mailimf_references * refs; | 152 | mailimf_references * refs; |
102 | mailimf_keywords*keys; | 153 | mailimf_keywords*keys; |
103 | QString status; | 154 | QString status; |
104 | QString value; | 155 | QString value; |
105 | QBitArray mFlags(7); | 156 | QBitArray mFlags(7); |
106 | 157 | ||
107 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); | 158 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); |
108 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { | 159 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { |
109 | mailimf_field *field = (mailimf_field *) current->data; | 160 | mailimf_field *field = (mailimf_field *) current->data; |
110 | switch ( field->fld_type ) { | 161 | switch ( field->fld_type ) { |
111 | case MAILIMF_FIELD_FROM: | 162 | case MAILIMF_FIELD_FROM: |
112 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); | 163 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); |
113 | break; | 164 | break; |
114 | case MAILIMF_FIELD_TO: | 165 | case MAILIMF_FIELD_TO: |
115 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); | 166 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); |
116 | break; | 167 | break; |
117 | case MAILIMF_FIELD_CC: | 168 | case MAILIMF_FIELD_CC: |
118 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); | 169 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); |
119 | break; | 170 | break; |
120 | case MAILIMF_FIELD_BCC: | 171 | case MAILIMF_FIELD_BCC: |
121 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); | 172 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); |
122 | break; | 173 | break; |
123 | case MAILIMF_FIELD_SUBJECT: | 174 | case MAILIMF_FIELD_SUBJECT: |
124 | mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); | 175 | mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); |
125 | break; | 176 | break; |
126 | case MAILIMF_FIELD_ORIG_DATE: | 177 | case MAILIMF_FIELD_ORIG_DATE: |
127 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); | 178 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); |
128 | break; | 179 | break; |
129 | case MAILIMF_FIELD_MESSAGE_ID: | 180 | case MAILIMF_FIELD_MESSAGE_ID: |
130 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); | 181 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); |
131 | break; | 182 | break; |
132 | case MAILIMF_FIELD_REFERENCES: | 183 | case MAILIMF_FIELD_REFERENCES: |
133 | refs = field->fld_data.fld_references; | 184 | refs = field->fld_data.fld_references; |
134 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | 185 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { |
135 | char * text = (char*)refs->mid_list->first->data; | 186 | char * text = (char*)refs->mid_list->first->data; |
136 | mail->setReplyto(QString(text)); | 187 | mail->setReplyto(QString(text)); |
137 | } | 188 | } |
138 | break; | 189 | break; |
139 | case MAILIMF_FIELD_KEYWORDS: | 190 | case MAILIMF_FIELD_KEYWORDS: |
140 | keys = field->fld_data.fld_keywords; | 191 | keys = field->fld_data.fld_keywords; |
141 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { | 192 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { |
142 | qDebug("Keyword: %s",(char*)cur->data); | 193 | qDebug("Keyword: %s",(char*)cur->data); |
143 | } | 194 | } |
144 | break; | 195 | break; |
145 | case MAILIMF_FIELD_OPTIONAL_FIELD: | 196 | case MAILIMF_FIELD_OPTIONAL_FIELD: |
146 | status = field->fld_data.fld_optional_field->fld_name; | 197 | status = field->fld_data.fld_optional_field->fld_name; |
147 | value = field->fld_data.fld_optional_field->fld_value; | 198 | value = field->fld_data.fld_optional_field->fld_value; |
148 | if (status.lower()=="status") { | 199 | if (status.lower()=="status") { |
149 | if (value.lower()=="ro") { | 200 | if (value.lower()=="ro") { |
150 | mFlags.setBit(FLAG_SEEN); | 201 | mFlags.setBit(FLAG_SEEN); |
151 | } | 202 | } |
152 | } else if (status.lower()=="x-status") { | 203 | } else if (status.lower()=="x-status") { |
153 | qDebug("X-Status: %s",value.latin1()); | 204 | qDebug("X-Status: %s",value.latin1()); |
154 | if (value.lower()=="a") { | 205 | if (value.lower()=="a") { |
155 | 206 | ||
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h index 8d3adda..a05021c 100644 --- a/noncore/net/mail/pop3wrapper.h +++ b/noncore/net/mail/pop3wrapper.h | |||
@@ -1,48 +1,49 @@ | |||
1 | #ifndef __POP3WRAPPER | 1 | #ifndef __POP3WRAPPER |
2 | #define __POP3WRAPPER | 2 | #define __POP3WRAPPER |
3 | 3 | ||
4 | #include "mailwrapper.h" | 4 | #include "mailwrapper.h" |
5 | #include "abstractmail.h" | 5 | #include "abstractmail.h" |
6 | 6 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | class encodedString; | 9 | class encodedString; |
10 | struct mailpop3; | 10 | struct mailpop3; |
11 | 11 | ||
12 | class POP3wrapper : public AbstractMail | 12 | class POP3wrapper : public AbstractMail |
13 | { | 13 | { |
14 | Q_OBJECT | 14 | Q_OBJECT |
15 | 15 | ||
16 | public: | 16 | public: |
17 | POP3wrapper( POP3account *a ); | 17 | POP3wrapper( POP3account *a ); |
18 | virtual ~POP3wrapper(); | 18 | virtual ~POP3wrapper(); |
19 | /* mailbox will be ignored */ | 19 | /* mailbox will be ignored */ |
20 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 20 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
21 | virtual QList<Folder>* listFolders(); | 21 | virtual QList<Folder>* listFolders(); |
22 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); | 22 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); |
23 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); | 23 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); |
24 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); | 24 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); |
25 | 25 | ||
26 | virtual void deleteMail(const RecMail&mail); | 26 | virtual void deleteMail(const RecMail&mail); |
27 | virtual void answeredMail(const RecMail&mail); | 27 | virtual void answeredMail(const RecMail&mail); |
28 | 28 | ||
29 | RecBody fetchBody( const RecMail &mail ); | 29 | RecBody fetchBody( const RecMail &mail ); |
30 | static void pop3_progress( size_t current, size_t maximum ); | 30 | static void pop3_progress( size_t current, size_t maximum ); |
31 | 31 | ||
32 | protected: | 32 | protected: |
33 | void login(); | 33 | void login(); |
34 | void logout(); | 34 | void logout(); |
35 | 35 | ||
36 | private: | ||
37 | RecMail *parseHeader( const char *header ); | 36 | RecMail *parseHeader( const char *header ); |
38 | RecBody parseBody( const char *message ); | 37 | RecBody parseMail( char *message ); |
39 | QString parseMailboxList( mailimf_mailbox_list *list ); | 38 | QString parseMailboxList( mailimf_mailbox_list *list ); |
40 | QString parseMailbox( mailimf_mailbox *box ); | 39 | QString parseMailbox( mailimf_mailbox *box ); |
41 | QString parseGroup( mailimf_group *group ); | 40 | QString parseGroup( mailimf_group *group ); |
42 | QString parseAddressList( mailimf_address_list *list ); | 41 | QString parseAddressList( mailimf_address_list *list ); |
43 | QString parseDateTime( mailimf_date_time *date ); | 42 | QString parseDateTime( mailimf_date_time *date ); |
44 | POP3account *account; | 43 | POP3account *account; |
45 | mailpop3 *m_pop3; | 44 | mailpop3 *m_pop3; |
45 | QString msgTempName; | ||
46 | unsigned int last_msg_id; | ||
46 | }; | 47 | }; |
47 | 48 | ||
48 | #endif | 49 | #endif |