Diffstat (limited to 'noncore/net/mail/libmailwrapper/genericwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/genericwrapper.cpp | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp index f428415..0c68280 100644 --- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp | |||
@@ -13,100 +13,100 @@ Genericwrapper::Genericwrapper() | |||
13 | 13 | ||
14 | Genericwrapper::~Genericwrapper() | 14 | Genericwrapper::~Genericwrapper() |
15 | { | 15 | { |
16 | if (m_folder) { | 16 | if (m_folder) { |
17 | mailfolder_free(m_folder); | 17 | mailfolder_free(m_folder); |
18 | } | 18 | } |
19 | if (m_storage) { | 19 | if (m_storage) { |
20 | mailstorage_free(m_storage); | 20 | mailstorage_free(m_storage); |
21 | } | 21 | } |
22 | cleanMimeCache(); | 22 | cleanMimeCache(); |
23 | } | 23 | } |
24 | 24 | ||
25 | void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) | 25 | void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) |
26 | { | 26 | { |
27 | if (!mime) { | 27 | if (!mime) { |
28 | return; | 28 | return; |
29 | } | 29 | } |
30 | mailmime_field*field = 0; | 30 | mailmime_field*field = 0; |
31 | mailmime_single_fields fields; | 31 | mailmime_single_fields fields; |
32 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 32 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
33 | if (mime->mm_mime_fields != NULL) { | 33 | if (mime->mm_mime_fields != NULL) { |
34 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, | 34 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, |
35 | mime->mm_content_type); | 35 | mime->mm_content_type); |
36 | } | 36 | } |
37 | 37 | ||
38 | mailmime_content*type = fields.fld_content; | 38 | mailmime_content*type = fields.fld_content; |
39 | clistcell*current; | 39 | clistcell*current; |
40 | if (!type) { | 40 | if (!type) { |
41 | target.setType("text"); | 41 | target->setType("text"); |
42 | target.setSubtype("plain"); | 42 | target->setSubtype("plain"); |
43 | } else { | 43 | } else { |
44 | target.setSubtype(type->ct_subtype); | 44 | target->setSubtype(type->ct_subtype); |
45 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { | 45 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { |
46 | case MAILMIME_DISCRETE_TYPE_TEXT: | 46 | case MAILMIME_DISCRETE_TYPE_TEXT: |
47 | target.setType("text"); | 47 | target->setType("text"); |
48 | break; | 48 | break; |
49 | case MAILMIME_DISCRETE_TYPE_IMAGE: | 49 | case MAILMIME_DISCRETE_TYPE_IMAGE: |
50 | target.setType("image"); | 50 | target->setType("image"); |
51 | break; | 51 | break; |
52 | case MAILMIME_DISCRETE_TYPE_AUDIO: | 52 | case MAILMIME_DISCRETE_TYPE_AUDIO: |
53 | target.setType("audio"); | 53 | target->setType("audio"); |
54 | break; | 54 | break; |
55 | case MAILMIME_DISCRETE_TYPE_VIDEO: | 55 | case MAILMIME_DISCRETE_TYPE_VIDEO: |
56 | target.setType("video"); | 56 | target->setType("video"); |
57 | break; | 57 | break; |
58 | case MAILMIME_DISCRETE_TYPE_APPLICATION: | 58 | case MAILMIME_DISCRETE_TYPE_APPLICATION: |
59 | target.setType("application"); | 59 | target->setType("application"); |
60 | break; | 60 | break; |
61 | case MAILMIME_DISCRETE_TYPE_EXTENSION: | 61 | case MAILMIME_DISCRETE_TYPE_EXTENSION: |
62 | default: | 62 | default: |
63 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { | 63 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { |
64 | target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); | 64 | target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); |
65 | } | 65 | } |
66 | break; | 66 | break; |
67 | } | 67 | } |
68 | if (type->ct_parameters) { | 68 | if (type->ct_parameters) { |
69 | fillParameters(target,type->ct_parameters); | 69 | fillParameters(target,type->ct_parameters); |
70 | } | 70 | } |
71 | } | 71 | } |
72 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { | 72 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { |
73 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { | 73 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { |
74 | field = (mailmime_field*)current->data; | 74 | field = (mailmime_field*)current->data; |
75 | switch(field->fld_type) { | 75 | switch(field->fld_type) { |
76 | case MAILMIME_FIELD_TRANSFER_ENCODING: | 76 | case MAILMIME_FIELD_TRANSFER_ENCODING: |
77 | target.setEncoding(getencoding(field->fld_data.fld_encoding)); | 77 | target->setEncoding(getencoding(field->fld_data.fld_encoding)); |
78 | break; | 78 | break; |
79 | case MAILMIME_FIELD_ID: | 79 | case MAILMIME_FIELD_ID: |
80 | target.setIdentifier(field->fld_data.fld_id); | 80 | target->setIdentifier(field->fld_data.fld_id); |
81 | break; | 81 | break; |
82 | case MAILMIME_FIELD_DESCRIPTION: | 82 | case MAILMIME_FIELD_DESCRIPTION: |
83 | target.setDescription(field->fld_data.fld_description); | 83 | target->setDescription(field->fld_data.fld_description); |
84 | break; | 84 | break; |
85 | default: | 85 | default: |
86 | break; | 86 | break; |
87 | } | 87 | } |
88 | } | 88 | } |
89 | } | 89 | } |
90 | } | 90 | } |
91 | 91 | ||
92 | void Genericwrapper::fillParameters(RecPart&target,clist*parameters) | 92 | void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) |
93 | { | 93 | { |
94 | if (!parameters) {return;} | 94 | if (!parameters) {return;} |
95 | clistcell*current=0; | 95 | clistcell*current=0; |
96 | mailmime_parameter*param; | 96 | mailmime_parameter*param; |
97 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { | 97 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { |
98 | param = (mailmime_parameter*)current->data; | 98 | param = (mailmime_parameter*)current->data; |
99 | if (param) { | 99 | if (param) { |
100 | target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 100 | target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
101 | } | 101 | } |
102 | } | 102 | } |
103 | } | 103 | } |
104 | 104 | ||
105 | QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) | 105 | QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) |
106 | { | 106 | { |
107 | QString enc="7bit"; | 107 | QString enc="7bit"; |
108 | if (!aEnc) return enc; | 108 | if (!aEnc) return enc; |
109 | switch(aEnc->enc_type) { | 109 | switch(aEnc->enc_type) { |
110 | case MAILMIME_MECHANISM_7BIT: | 110 | case MAILMIME_MECHANISM_7BIT: |
111 | enc = "7bit"; | 111 | enc = "7bit"; |
112 | break; | 112 | break; |
@@ -123,124 +123,124 @@ QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) | |||
123 | enc = "base64"; | 123 | enc = "base64"; |
124 | break; | 124 | break; |
125 | case MAILMIME_MECHANISM_TOKEN: | 125 | case MAILMIME_MECHANISM_TOKEN: |
126 | default: | 126 | default: |
127 | if (aEnc->enc_token) { | 127 | if (aEnc->enc_token) { |
128 | enc = QString(aEnc->enc_token); | 128 | enc = QString(aEnc->enc_token); |
129 | } | 129 | } |
130 | break; | 130 | break; |
131 | } | 131 | } |
132 | return enc; | 132 | return enc; |
133 | } | 133 | } |
134 | 134 | ||
135 | void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) | 135 | void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) |
136 | { | 136 | { |
137 | if (current_rec >= 10) { | 137 | if (current_rec >= 10) { |
138 | qDebug("too deep recursion!"); | 138 | qDebug("too deep recursion!"); |
139 | } | 139 | } |
140 | if (!message || !mime) { | 140 | if (!message || !mime) { |
141 | return; | 141 | return; |
142 | } | 142 | } |
143 | int r; | 143 | int r; |
144 | char*data = 0; | 144 | char*data = 0; |
145 | size_t len; | 145 | size_t len; |
146 | clistiter * cur = 0; | 146 | clistiter * cur = 0; |
147 | QString b; | 147 | QString b; |
148 | RecPart part; | 148 | RecPartP part = new RecPart(); |
149 | 149 | ||
150 | switch (mime->mm_type) { | 150 | switch (mime->mm_type) { |
151 | case MAILMIME_SINGLE: | 151 | case MAILMIME_SINGLE: |
152 | { | 152 | { |
153 | QValueList<int>countlist = recList; | 153 | QValueList<int>countlist = recList; |
154 | countlist.append(current_count); | 154 | countlist.append(current_count); |
155 | r = mailmessage_fetch_section(message,mime,&data,&len); | 155 | r = mailmessage_fetch_section(message,mime,&data,&len); |
156 | part.setSize(len); | 156 | part->setSize(len); |
157 | part.setPositionlist(countlist); | 157 | part->setPositionlist(countlist); |
158 | b = gen_attachment_id(); | 158 | b = gen_attachment_id(); |
159 | part.setIdentifier(b); | 159 | part->setIdentifier(b); |
160 | fillSingleBody(part,message,mime); | 160 | fillSingleBody(part,message,mime); |
161 | if (part.Type()=="text" && target.Bodytext().isNull()) { | 161 | if (part->Type()=="text" && target->Bodytext().isNull()) { |
162 | encodedString*rs = new encodedString(); | 162 | encodedString*rs = new encodedString(); |
163 | rs->setContent(data,len); | 163 | rs->setContent(data,len); |
164 | encodedString*res = decode_String(rs,part.Encoding()); | 164 | encodedString*res = decode_String(rs,part->Encoding()); |
165 | if (countlist.count()>2) { | 165 | if (countlist.count()>2) { |
166 | bodyCache[b]=rs; | 166 | bodyCache[b]=rs; |
167 | target.addPart(part); | 167 | target->addPart(part); |
168 | } else { | 168 | } else { |
169 | delete rs; | 169 | delete rs; |
170 | } | 170 | } |
171 | b = QString(res->Content()); | 171 | b = QString(res->Content()); |
172 | delete res; | 172 | delete res; |
173 | target.setBodytext(b); | 173 | target->setBodytext(b); |
174 | target.setDescription(part); | 174 | target->setDescription(part); |
175 | } else { | 175 | } else { |
176 | bodyCache[b]=new encodedString(data,len); | 176 | bodyCache[b]=new encodedString(data,len); |
177 | target.addPart(part); | 177 | target->addPart(part); |
178 | } | 178 | } |
179 | } | 179 | } |
180 | break; | 180 | break; |
181 | case MAILMIME_MULTIPLE: | 181 | case MAILMIME_MULTIPLE: |
182 | { | 182 | { |
183 | unsigned int ccount = 1; | 183 | unsigned int ccount = 1; |
184 | mailmime*cbody=0; | 184 | mailmime*cbody=0; |
185 | QValueList<int>countlist = recList; | 185 | QValueList<int>countlist = recList; |
186 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { | 186 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { |
187 | cbody = (mailmime*)clist_content(cur); | 187 | cbody = (mailmime*)clist_content(cur); |
188 | if (cbody->mm_type==MAILMIME_MULTIPLE) { | 188 | if (cbody->mm_type==MAILMIME_MULTIPLE) { |
189 | RecPart targetPart; | 189 | RecPartP targetPart = new RecPart(); |
190 | targetPart.setType("multipart"); | 190 | targetPart->setType("multipart"); |
191 | countlist.append(current_count); | 191 | countlist.append(current_count); |
192 | targetPart.setPositionlist(countlist); | 192 | targetPart->setPositionlist(countlist); |
193 | target.addPart(targetPart); | 193 | target->addPart(targetPart); |
194 | } | 194 | } |
195 | traverseBody(target,message, cbody,countlist,current_rec+1,ccount); | 195 | traverseBody(target,message, cbody,countlist,current_rec+1,ccount); |
196 | if (cbody->mm_type==MAILMIME_MULTIPLE) { | 196 | if (cbody->mm_type==MAILMIME_MULTIPLE) { |
197 | countlist = recList; | 197 | countlist = recList; |
198 | } | 198 | } |
199 | ++ccount; | 199 | ++ccount; |
200 | } | 200 | } |
201 | } | 201 | } |
202 | break; | 202 | break; |
203 | case MAILMIME_MESSAGE: | 203 | case MAILMIME_MESSAGE: |
204 | { | 204 | { |
205 | QValueList<int>countlist = recList; | 205 | QValueList<int>countlist = recList; |
206 | countlist.append(current_count); | 206 | countlist.append(current_count); |
207 | /* the own header is always at recursion 0 - we don't need that */ | 207 | /* the own header is always at recursion 0 - we don't need that */ |
208 | if (current_rec > 0) { | 208 | if (current_rec > 0) { |
209 | part.setPositionlist(countlist); | 209 | part->setPositionlist(countlist); |
210 | r = mailmessage_fetch_section(message,mime,&data,&len); | 210 | r = mailmessage_fetch_section(message,mime,&data,&len); |
211 | part.setSize(len); | 211 | part->setSize(len); |
212 | part.setPositionlist(countlist); | 212 | part->setPositionlist(countlist); |
213 | b = gen_attachment_id(); | 213 | b = gen_attachment_id(); |
214 | part.setIdentifier(b); | 214 | part->setIdentifier(b); |
215 | part.setType("message"); | 215 | part->setType("message"); |
216 | part.setSubtype("rfc822"); | 216 | part->setSubtype("rfc822"); |
217 | bodyCache[b]=new encodedString(data,len); | 217 | bodyCache[b]=new encodedString(data,len); |
218 | target.addPart(part); | 218 | target->addPart(part); |
219 | } | 219 | } |
220 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { | 220 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { |
221 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); | 221 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); |
222 | } | 222 | } |
223 | } | 223 | } |
224 | break; | 224 | break; |
225 | } | 225 | } |
226 | } | 226 | } |
227 | 227 | ||
228 | RecBody Genericwrapper::parseMail( mailmessage * msg ) | 228 | RecBodyP Genericwrapper::parseMail( mailmessage * msg ) |
229 | { | 229 | { |
230 | int err = MAILIMF_NO_ERROR; | 230 | int err = MAILIMF_NO_ERROR; |
231 | mailmime_single_fields fields; | 231 | mailmime_single_fields fields; |
232 | /* is bound to msg and will be freed there */ | 232 | /* is bound to msg and will be freed there */ |
233 | mailmime * mime=0; | 233 | mailmime * mime=0; |
234 | RecBody body; | 234 | RecBodyP body = new RecBody(); |
235 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 235 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
236 | err = mailmessage_get_bodystructure(msg,&mime); | 236 | err = mailmessage_get_bodystructure(msg,&mime); |
237 | QValueList<int>recList; | 237 | QValueList<int>recList; |
238 | traverseBody(body,msg,mime,recList); | 238 | traverseBody(body,msg,mime,recList); |
239 | return body; | 239 | return body; |
240 | } | 240 | } |
241 | 241 | ||
242 | QString Genericwrapper::parseDateTime( mailimf_date_time *date ) | 242 | QString Genericwrapper::parseDateTime( mailimf_date_time *date ) |
243 | { | 243 | { |
244 | char tmp[23]; | 244 | char tmp[23]; |
245 | 245 | ||
246 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | 246 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", |
@@ -323,41 +323,41 @@ QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) | |||
323 | if ( !first ) { | 323 | if ( !first ) { |
324 | result.append( "," ); | 324 | result.append( "," ); |
325 | } else { | 325 | } else { |
326 | first = false; | 326 | first = false; |
327 | } | 327 | } |
328 | 328 | ||
329 | result.append( parseMailbox( box ) ); | 329 | result.append( parseMailbox( box ) ); |
330 | } | 330 | } |
331 | 331 | ||
332 | return result; | 332 | return result; |
333 | } | 333 | } |
334 | 334 | ||
335 | encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPart&part) | 335 | encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) |
336 | { | 336 | { |
337 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); | 337 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); |
338 | if (it==bodyCache.end()) return new encodedString(); | 338 | if (it==bodyCache.end()) return new encodedString(); |
339 | encodedString*t = decode_String(it.data(),part.Encoding()); | 339 | encodedString*t = decode_String(it.data(),part->Encoding()); |
340 | return t; | 340 | return t; |
341 | } | 341 | } |
342 | 342 | ||
343 | encodedString* Genericwrapper::fetchRawPart(const RecMailP&mail,const RecPart&part) | 343 | encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) |
344 | { | 344 | { |
345 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); | 345 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); |
346 | if (it==bodyCache.end()) return new encodedString(); | 346 | if (it==bodyCache.end()) return new encodedString(); |
347 | encodedString*t = it.data(); | 347 | encodedString*t = it.data(); |
348 | return t; | 348 | return t; |
349 | } | 349 | } |
350 | 350 | ||
351 | QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPart&part) | 351 | QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) |
352 | { | 352 | { |
353 | encodedString*t = fetchDecodedPart(mail,part); | 353 | encodedString*t = fetchDecodedPart(mail,part); |
354 | QString text=t->Content(); | 354 | QString text=t->Content(); |
355 | delete t; | 355 | delete t; |
356 | return text; | 356 | return text; |
357 | } | 357 | } |
358 | 358 | ||
359 | void Genericwrapper::cleanMimeCache() | 359 | void Genericwrapper::cleanMimeCache() |
360 | { | 360 | { |
361 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); | 361 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); |
362 | for (;it!=bodyCache.end();++it) { | 362 | for (;it!=bodyCache.end();++it) { |
363 | encodedString*t = it.data(); | 363 | encodedString*t = it.data(); |