author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /kmicromail/libmailwrapper/genericwrapper.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-p1.zip kdepimpi-p1.tar.gz kdepimpi-p1.tar.bz2 |
initial public commit of qt4 portp1
Diffstat (limited to 'kmicromail/libmailwrapper/genericwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/genericwrapper.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp index 0b6adf7..633ab42 100644 --- a/kmicromail/libmailwrapper/genericwrapper.cpp +++ b/kmicromail/libmailwrapper/genericwrapper.cpp | |||
@@ -1,546 +1,548 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #include "genericwrapper.h" | 2 | #include "genericwrapper.h" |
3 | #include <libetpan/libetpan.h> | 3 | #include <libetpan/libetpan.h> |
4 | #include "mailtypes.h" | 4 | #include "mailtypes.h" |
5 | 5 | ||
6 | #include <kconfig.h> | 6 | #include <kconfig.h> |
7 | #include <kglobal.h> | 7 | #include <kglobal.h> |
8 | #include <kstandarddirs.h> | 8 | #include <kstandarddirs.h> |
9 | //Added by qt3to4: | ||
10 | #include <Q3ValueList> | ||
9 | 11 | ||
10 | 12 | ||
11 | using namespace Opie::Core; | 13 | using namespace Opie::Core; |
12 | Genericwrapper::Genericwrapper() | 14 | Genericwrapper::Genericwrapper() |
13 | : AbstractMail() | 15 | : AbstractMail() |
14 | { | 16 | { |
15 | bodyCache.clear(); | 17 | bodyCache.clear(); |
16 | m_storage = 0; | 18 | m_storage = 0; |
17 | m_folder = 0; | 19 | m_folder = 0; |
18 | } | 20 | } |
19 | 21 | ||
20 | Genericwrapper::~Genericwrapper() | 22 | Genericwrapper::~Genericwrapper() |
21 | { | 23 | { |
22 | if (m_folder) { | 24 | if (m_folder) { |
23 | mailfolder_free(m_folder); | 25 | mailfolder_free(m_folder); |
24 | } | 26 | } |
25 | if (m_storage) { | 27 | if (m_storage) { |
26 | mailstorage_free(m_storage); | 28 | mailstorage_free(m_storage); |
27 | } | 29 | } |
28 | cleanMimeCache(); | 30 | cleanMimeCache(); |
29 | } | 31 | } |
30 | const QDateTime Genericwrapper::parseDateTime( mailimf_date_time *date ) | 32 | const QDateTime Genericwrapper::parseDateTime( mailimf_date_time *date ) |
31 | { | 33 | { |
32 | 34 | ||
33 | QDate da (date->dt_year,date->dt_month, date->dt_day ); | 35 | QDate da (date->dt_year,date->dt_month, date->dt_day ); |
34 | QTime ti ( date->dt_hour, date->dt_min, date->dt_sec ); | 36 | QTime ti ( date->dt_hour, date->dt_min, date->dt_sec ); |
35 | QDateTime dt ( da ,ti ); | 37 | QDateTime dt ( da ,ti ); |
36 | int addsec = -date->dt_zone*36; | 38 | int addsec = -date->dt_zone*36; |
37 | //qDebug("adsec1 %d ",addsec ); | 39 | //qDebug("adsec1 %d ",addsec ); |
38 | dt = dt.addSecs( addsec ); | 40 | dt = dt.addSecs( addsec ); |
39 | int off = KGlobal::locale()->localTimeOffset( dt ); | 41 | int off = KGlobal::locale()->localTimeOffset( dt ); |
40 | //qDebug("adsec2 %d ",off*60 ); | 42 | //qDebug("adsec2 %d ",off*60 ); |
41 | 43 | ||
42 | dt = dt.addSecs( off*60 ); | 44 | dt = dt.addSecs( off*60 ); |
43 | return dt; | 45 | return dt; |
44 | #if 0 | 46 | #if 0 |
45 | QString ret; | 47 | QString ret; |
46 | if ( dt.date() == QDate::currentDate () ) | 48 | if ( dt.date() == QDate::currentDate () ) |
47 | ret = KGlobal::locale()->formatTime( dt.time(),true); | 49 | ret = KGlobal::locale()->formatTime( dt.time(),true); |
48 | 50 | ||
49 | else { | 51 | else { |
50 | ret = KGlobal::locale()->formatDateTime( dt,true,true); | 52 | ret = KGlobal::locale()->formatDateTime( dt,true,true); |
51 | } | 53 | } |
52 | #endif | 54 | #endif |
53 | #if 0 | 55 | #if 0 |
54 | if ( off < 0 ) | 56 | if ( off < 0 ) |
55 | ret += " -"; | 57 | ret += " -"; |
56 | else | 58 | else |
57 | ret += " +"; | 59 | ret += " +"; |
58 | ret += QString::number( off / 60 ); | 60 | ret += QString::number( off / 60 ); |
59 | ret += "h"; | 61 | ret += "h"; |
60 | #endif | 62 | #endif |
61 | #if 0 | 63 | #if 0 |
62 | char tmp[23]; | 64 | char tmp[23]; |
63 | 65 | ||
64 | // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | 66 | // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", |
65 | // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); | 67 | // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); |
66 | snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i", | 68 | snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i", |
67 | date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); | 69 | date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); |
68 | 70 | ||
69 | 71 | ||
70 | return QString( tmp ); | 72 | return QString( tmp ); |
71 | #endif | 73 | #endif |
72 | //return ret; | 74 | //return ret; |
73 | } | 75 | } |
74 | 76 | ||
75 | void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) | 77 | void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) |
76 | { | 78 | { |
77 | if (!mime) { | 79 | if (!mime) { |
78 | return; | 80 | return; |
79 | } | 81 | } |
80 | mailmime_field*field = 0; | 82 | mailmime_field*field = 0; |
81 | mailmime_single_fields fields; | 83 | mailmime_single_fields fields; |
82 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 84 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
83 | if (mime->mm_mime_fields != NULL) { | 85 | if (mime->mm_mime_fields != NULL) { |
84 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, | 86 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, |
85 | mime->mm_content_type); | 87 | mime->mm_content_type); |
86 | } | 88 | } |
87 | 89 | ||
88 | mailmime_content*type = fields.fld_content; | 90 | mailmime_content*type = fields.fld_content; |
89 | clistcell*current; | 91 | clistcell*current; |
90 | if (!type) { | 92 | if (!type) { |
91 | target->setType("text"); | 93 | target->setType("text"); |
92 | target->setSubtype("plain"); | 94 | target->setSubtype("plain"); |
93 | } else { | 95 | } else { |
94 | target->setSubtype(type->ct_subtype); | 96 | target->setSubtype(type->ct_subtype); |
95 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { | 97 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { |
96 | case MAILMIME_DISCRETE_TYPE_TEXT: | 98 | case MAILMIME_DISCRETE_TYPE_TEXT: |
97 | target->setType("text"); | 99 | target->setType("text"); |
98 | break; | 100 | break; |
99 | case MAILMIME_DISCRETE_TYPE_IMAGE: | 101 | case MAILMIME_DISCRETE_TYPE_IMAGE: |
100 | target->setType("image"); | 102 | target->setType("image"); |
101 | break; | 103 | break; |
102 | case MAILMIME_DISCRETE_TYPE_AUDIO: | 104 | case MAILMIME_DISCRETE_TYPE_AUDIO: |
103 | target->setType("audio"); | 105 | target->setType("audio"); |
104 | break; | 106 | break; |
105 | case MAILMIME_DISCRETE_TYPE_VIDEO: | 107 | case MAILMIME_DISCRETE_TYPE_VIDEO: |
106 | target->setType("video"); | 108 | target->setType("video"); |
107 | break; | 109 | break; |
108 | case MAILMIME_DISCRETE_TYPE_APPLICATION: | 110 | case MAILMIME_DISCRETE_TYPE_APPLICATION: |
109 | target->setType("application"); | 111 | target->setType("application"); |
110 | break; | 112 | break; |
111 | case MAILMIME_DISCRETE_TYPE_EXTENSION: | 113 | case MAILMIME_DISCRETE_TYPE_EXTENSION: |
112 | default: | 114 | default: |
113 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { | 115 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { |
114 | target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); | 116 | target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); |
115 | } | 117 | } |
116 | break; | 118 | break; |
117 | } | 119 | } |
118 | if (type->ct_parameters) { | 120 | if (type->ct_parameters) { |
119 | fillParameters(target,type->ct_parameters); | 121 | fillParameters(target,type->ct_parameters); |
120 | } | 122 | } |
121 | } | 123 | } |
122 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { | 124 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { |
123 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { | 125 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { |
124 | field = (mailmime_field*)current->data; | 126 | field = (mailmime_field*)current->data; |
125 | switch(field->fld_type) { | 127 | switch(field->fld_type) { |
126 | case MAILMIME_FIELD_TRANSFER_ENCODING: | 128 | case MAILMIME_FIELD_TRANSFER_ENCODING: |
127 | target->setEncoding(getencoding(field->fld_data.fld_encoding)); | 129 | target->setEncoding(getencoding(field->fld_data.fld_encoding)); |
128 | break; | 130 | break; |
129 | case MAILMIME_FIELD_ID: | 131 | case MAILMIME_FIELD_ID: |
130 | target->setIdentifier(field->fld_data.fld_id); | 132 | target->setIdentifier(field->fld_data.fld_id); |
131 | break; | 133 | break; |
132 | case MAILMIME_FIELD_DESCRIPTION: | 134 | case MAILMIME_FIELD_DESCRIPTION: |
133 | target->setDescription(field->fld_data.fld_description); | 135 | target->setDescription(field->fld_data.fld_description); |
134 | break; | 136 | break; |
135 | default: | 137 | default: |
136 | break; | 138 | break; |
137 | } | 139 | } |
138 | } | 140 | } |
139 | } | 141 | } |
140 | } | 142 | } |
141 | 143 | ||
142 | void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) | 144 | void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) |
143 | { | 145 | { |
144 | if (!parameters) {return;} | 146 | if (!parameters) {return;} |
145 | clistcell*current=0; | 147 | clistcell*current=0; |
146 | mailmime_parameter*param; | 148 | mailmime_parameter*param; |
147 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { | 149 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { |
148 | param = (mailmime_parameter*)current->data; | 150 | param = (mailmime_parameter*)current->data; |
149 | if (param) { | 151 | if (param) { |
150 | target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 152 | target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
151 | } | 153 | } |
152 | } | 154 | } |
153 | } | 155 | } |
154 | 156 | ||
155 | QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) | 157 | QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) |
156 | { | 158 | { |
157 | QString enc="7bit"; | 159 | QString enc="7bit"; |
158 | if (!aEnc) return enc; | 160 | if (!aEnc) return enc; |
159 | switch(aEnc->enc_type) { | 161 | switch(aEnc->enc_type) { |
160 | case MAILMIME_MECHANISM_7BIT: | 162 | case MAILMIME_MECHANISM_7BIT: |
161 | enc = "7bit"; | 163 | enc = "7bit"; |
162 | break; | 164 | break; |
163 | case MAILMIME_MECHANISM_8BIT: | 165 | case MAILMIME_MECHANISM_8BIT: |
164 | enc = "8bit"; | 166 | enc = "8bit"; |
165 | break; | 167 | break; |
166 | case MAILMIME_MECHANISM_BINARY: | 168 | case MAILMIME_MECHANISM_BINARY: |
167 | enc = "binary"; | 169 | enc = "binary"; |
168 | break; | 170 | break; |
169 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: | 171 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: |
170 | enc = "quoted-printable"; | 172 | enc = "quoted-printable"; |
171 | break; | 173 | break; |
172 | case MAILMIME_MECHANISM_BASE64: | 174 | case MAILMIME_MECHANISM_BASE64: |
173 | enc = "base64"; | 175 | enc = "base64"; |
174 | break; | 176 | break; |
175 | case MAILMIME_MECHANISM_TOKEN: | 177 | case MAILMIME_MECHANISM_TOKEN: |
176 | default: | 178 | default: |
177 | if (aEnc->enc_token) { | 179 | if (aEnc->enc_token) { |
178 | enc = QString(aEnc->enc_token); | 180 | enc = QString(aEnc->enc_token); |
179 | } | 181 | } |
180 | break; | 182 | break; |
181 | } | 183 | } |
182 | return enc; | 184 | return enc; |
183 | } | 185 | } |
184 | 186 | ||
185 | void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) | 187 | void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,Q3ValueList<int>recList,unsigned int current_rec,int current_count) |
186 | { | 188 | { |
187 | if (current_rec >= 10) { | 189 | if (current_rec >= 10) { |
188 | ; // odebug << "too deep recursion!" << oendl; | 190 | ; // odebug << "too deep recursion!" << oendl; |
189 | } | 191 | } |
190 | if (!message || !mime) { | 192 | if (!message || !mime) { |
191 | return; | 193 | return; |
192 | } | 194 | } |
193 | int r; | 195 | int r; |
194 | char*data = 0; | 196 | char*data = 0; |
195 | size_t len; | 197 | size_t len; |
196 | clistiter * cur = 0; | 198 | clistiter * cur = 0; |
197 | QString b; | 199 | QString b; |
198 | RecPartP part = new RecPart(); | 200 | RecPartP part = new RecPart(); |
199 | 201 | ||
200 | switch (mime->mm_type) { | 202 | switch (mime->mm_type) { |
201 | case MAILMIME_SINGLE: | 203 | case MAILMIME_SINGLE: |
202 | { | 204 | { |
203 | QValueList<int>countlist = recList; | 205 | Q3ValueList<int>countlist = recList; |
204 | countlist.append(current_count); | 206 | countlist.append(current_count); |
205 | r = mailmessage_fetch_section(message,mime,&data,&len); | 207 | r = mailmessage_fetch_section(message,mime,&data,&len); |
206 | part->setSize(len); | 208 | part->setSize(len); |
207 | part->setPositionlist(countlist); | 209 | part->setPositionlist(countlist); |
208 | b = gen_attachment_id(); | 210 | b = gen_attachment_id(); |
209 | part->setIdentifier(b); | 211 | part->setIdentifier(b); |
210 | fillSingleBody(part,message,mime); | 212 | fillSingleBody(part,message,mime); |
211 | if (part->Type()=="text" && target->Bodytext().isNull()) { | 213 | if (part->Type()=="text" && target->Bodytext().isNull()) { |
212 | encodedString*rs = new encodedString(); | 214 | encodedString*rs = new encodedString(); |
213 | rs->setContent(data,len); | 215 | rs->setContent(data,len); |
214 | encodedString*res = decode_String(rs,part->Encoding()); | 216 | encodedString*res = decode_String(rs,part->Encoding()); |
215 | if (countlist.count()>2) { | 217 | if (countlist.count()>2) { |
216 | bodyCache[b]=rs; | 218 | bodyCache[b]=rs; |
217 | target->addPart(part); | 219 | target->addPart(part); |
218 | } else { | 220 | } else { |
219 | delete rs; | 221 | delete rs; |
220 | } | 222 | } |
221 | b = QString(res->Content()); | 223 | b = QString(res->Content()); |
222 | delete res; | 224 | delete res; |
223 | size_t index = 0; | 225 | size_t index = 0; |
224 | char*resu = 0; | 226 | char*resu = 0; |
225 | int err = MAILIMF_NO_ERROR; | 227 | int err = MAILIMF_NO_ERROR; |
226 | QString charset = part->searchParamter( "charset"); | 228 | QString charset = part->searchParamter( "charset"); |
227 | qDebug("CHARSET %s ",charset.latin1() ); | 229 | qDebug("CHARSET %s ",charset.latin1() ); |
228 | #if 0 | 230 | #if 0 |
229 | if (false ) { | 231 | if (false ) { |
230 | //if ( !charset.isEmpty() ) { | 232 | //if ( !charset.isEmpty() ) { |
231 | target->setCharset( charset ); | 233 | target->setCharset( charset ); |
232 | err = mailmime_encoded_phrase_parse(charset.latin1(), | 234 | err = mailmime_encoded_phrase_parse(charset.latin1(), |
233 | b.latin1(), b.length(),&index, "utf-8",&resu); | 235 | b.latin1(), b.length(),&index, "utf-8",&resu); |
234 | if (err == MAILIMF_NO_ERROR && resu && strlen(resu)) { | 236 | if (err == MAILIMF_NO_ERROR && resu && strlen(resu)) { |
235 | //qDebug("res %d %s ", index, resu); | 237 | //qDebug("res %d %s ", index, resu); |
236 | b = QString::fromUtf8(resu); | 238 | b = QString::fromUtf8(resu); |
237 | } | 239 | } |
238 | if (resu) free(resu); | 240 | if (resu) free(resu); |
239 | } | 241 | } |
240 | #endif | 242 | #endif |
241 | target->setBodytext(b); | 243 | target->setBodytext(b); |
242 | target->setDescription(part); | 244 | target->setDescription(part); |
243 | } else { | 245 | } else { |
244 | bodyCache[b]=new encodedString(data,len); | 246 | bodyCache[b]=new encodedString(data,len); |
245 | target->addPart(part); | 247 | target->addPart(part); |
246 | } | 248 | } |
247 | } | 249 | } |
248 | break; | 250 | break; |
249 | case MAILMIME_MULTIPLE: | 251 | case MAILMIME_MULTIPLE: |
250 | { | 252 | { |
251 | unsigned int ccount = 1; | 253 | unsigned int ccount = 1; |
252 | mailmime*cbody=0; | 254 | mailmime*cbody=0; |
253 | QValueList<int>countlist = recList; | 255 | Q3ValueList<int>countlist = recList; |
254 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { | 256 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { |
255 | cbody = (mailmime*)clist_content(cur); | 257 | cbody = (mailmime*)clist_content(cur); |
256 | if (cbody->mm_type==MAILMIME_MULTIPLE) { | 258 | if (cbody->mm_type==MAILMIME_MULTIPLE) { |
257 | RecPartP targetPart = new RecPart(); | 259 | RecPartP targetPart = new RecPart(); |
258 | targetPart->setType("multipart"); | 260 | targetPart->setType("multipart"); |
259 | countlist.append(current_count); | 261 | countlist.append(current_count); |
260 | targetPart->setPositionlist(countlist); | 262 | targetPart->setPositionlist(countlist); |
261 | target->addPart(targetPart); | 263 | target->addPart(targetPart); |
262 | } | 264 | } |
263 | traverseBody(target,message, cbody,countlist,current_rec+1,ccount); | 265 | traverseBody(target,message, cbody,countlist,current_rec+1,ccount); |
264 | if (cbody->mm_type==MAILMIME_MULTIPLE) { | 266 | if (cbody->mm_type==MAILMIME_MULTIPLE) { |
265 | countlist = recList; | 267 | countlist = recList; |
266 | } | 268 | } |
267 | ++ccount; | 269 | ++ccount; |
268 | } | 270 | } |
269 | } | 271 | } |
270 | break; | 272 | break; |
271 | case MAILMIME_MESSAGE: | 273 | case MAILMIME_MESSAGE: |
272 | { | 274 | { |
273 | QValueList<int>countlist = recList; | 275 | Q3ValueList<int>countlist = recList; |
274 | countlist.append(current_count); | 276 | countlist.append(current_count); |
275 | /* the own header is always at recursion 0 - we don't need that */ | 277 | /* the own header is always at recursion 0 - we don't need that */ |
276 | if (current_rec > 0) { | 278 | if (current_rec > 0) { |
277 | part->setPositionlist(countlist); | 279 | part->setPositionlist(countlist); |
278 | r = mailmessage_fetch_section(message,mime,&data,&len); | 280 | r = mailmessage_fetch_section(message,mime,&data,&len); |
279 | part->setSize(len); | 281 | part->setSize(len); |
280 | part->setPositionlist(countlist); | 282 | part->setPositionlist(countlist); |
281 | b = gen_attachment_id(); | 283 | b = gen_attachment_id(); |
282 | part->setIdentifier(b); | 284 | part->setIdentifier(b); |
283 | part->setType("message"); | 285 | part->setType("message"); |
284 | part->setSubtype("rfc822"); | 286 | part->setSubtype("rfc822"); |
285 | bodyCache[b]=new encodedString(data,len); | 287 | bodyCache[b]=new encodedString(data,len); |
286 | target->addPart(part); | 288 | target->addPart(part); |
287 | } | 289 | } |
288 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { | 290 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { |
289 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); | 291 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); |
290 | } | 292 | } |
291 | } | 293 | } |
292 | break; | 294 | break; |
293 | } | 295 | } |
294 | } | 296 | } |
295 | 297 | ||
296 | RecBodyP Genericwrapper::parseMail( mailmessage * msg ) | 298 | RecBodyP Genericwrapper::parseMail( mailmessage * msg ) |
297 | { | 299 | { |
298 | int err = MAILIMF_NO_ERROR; | 300 | int err = MAILIMF_NO_ERROR; |
299 | //mailmime_single_fields fields; | 301 | //mailmime_single_fields fields; |
300 | /* is bound to msg and will be freed there */ | 302 | /* is bound to msg and will be freed there */ |
301 | mailmime * mime=0; | 303 | mailmime * mime=0; |
302 | RecBodyP body = new RecBody(); | 304 | RecBodyP body = new RecBody(); |
303 | //memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 305 | //memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
304 | err = mailmessage_get_bodystructure(msg,&mime); | 306 | err = mailmessage_get_bodystructure(msg,&mime); |
305 | QValueList<int>recList; | 307 | Q3ValueList<int>recList; |
306 | traverseBody(body,msg,mime,recList); | 308 | traverseBody(body,msg,mime,recList); |
307 | return body; | 309 | return body; |
308 | } | 310 | } |
309 | 311 | ||
310 | 312 | ||
311 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) | 313 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) |
312 | { | 314 | { |
313 | QString result( "" ); | 315 | QString result( "" ); |
314 | 316 | ||
315 | bool first = true; | 317 | bool first = true; |
316 | if (list == 0) return result; | 318 | if (list == 0) return result; |
317 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { | 319 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { |
318 | mailimf_address *addr = (mailimf_address *) current->data; | 320 | mailimf_address *addr = (mailimf_address *) current->data; |
319 | 321 | ||
320 | if ( !first ) { | 322 | if ( !first ) { |
321 | result.append( "," ); | 323 | result.append( "," ); |
322 | } else { | 324 | } else { |
323 | first = false; | 325 | first = false; |
324 | } | 326 | } |
325 | 327 | ||
326 | switch ( addr->ad_type ) { | 328 | switch ( addr->ad_type ) { |
327 | case MAILIMF_ADDRESS_MAILBOX: | 329 | case MAILIMF_ADDRESS_MAILBOX: |
328 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); | 330 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); |
329 | break; | 331 | break; |
330 | case MAILIMF_ADDRESS_GROUP: | 332 | case MAILIMF_ADDRESS_GROUP: |
331 | result.append( parseGroup( addr->ad_data.ad_group ) ); | 333 | result.append( parseGroup( addr->ad_data.ad_group ) ); |
332 | break; | 334 | break; |
333 | default: | 335 | default: |
334 | ; // odebug << "Generic: unkown mailimf address type" << oendl; | 336 | ; // odebug << "Generic: unkown mailimf address type" << oendl; |
335 | break; | 337 | break; |
336 | } | 338 | } |
337 | } | 339 | } |
338 | 340 | ||
339 | return result; | 341 | return result; |
340 | } | 342 | } |
341 | 343 | ||
342 | QString Genericwrapper::parseGroup( mailimf_group *group ) | 344 | QString Genericwrapper::parseGroup( mailimf_group *group ) |
343 | { | 345 | { |
344 | QString result( "" ); | 346 | QString result( "" ); |
345 | 347 | ||
346 | result.append( group->grp_display_name ); | 348 | result.append( group->grp_display_name ); |
347 | result.append( ": " ); | 349 | result.append( ": " ); |
348 | 350 | ||
349 | if ( group->grp_mb_list != NULL ) { | 351 | if ( group->grp_mb_list != NULL ) { |
350 | result.append( parseMailboxList( group->grp_mb_list ) ); | 352 | result.append( parseMailboxList( group->grp_mb_list ) ); |
351 | } | 353 | } |
352 | 354 | ||
353 | result.append( ";" ); | 355 | result.append( ";" ); |
354 | 356 | ||
355 | return result; | 357 | return result; |
356 | } | 358 | } |
357 | 359 | ||
358 | QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) | 360 | QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) |
359 | { | 361 | { |
360 | QString result( "" ); | 362 | QString result( "" ); |
361 | 363 | ||
362 | if ( box->mb_display_name == NULL ) { | 364 | if ( box->mb_display_name == NULL ) { |
363 | result.append( convert_String(box->mb_addr_spec) ); | 365 | result.append( convert_String(box->mb_addr_spec) ); |
364 | } else { | 366 | } else { |
365 | result.append( convert_String(box->mb_display_name) ); | 367 | result.append( convert_String(box->mb_display_name) ); |
366 | result.append( " <" ); | 368 | result.append( " <" ); |
367 | result.append( convert_String( box->mb_addr_spec) ); | 369 | result.append( convert_String( box->mb_addr_spec) ); |
368 | result.append( ">" ); | 370 | result.append( ">" ); |
369 | } | 371 | } |
370 | 372 | ||
371 | return result; | 373 | return result; |
372 | } | 374 | } |
373 | 375 | ||
374 | QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) | 376 | QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) |
375 | { | 377 | { |
376 | QString result( "" ); | 378 | QString result( "" ); |
377 | 379 | ||
378 | bool first = true; | 380 | bool first = true; |
379 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { | 381 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { |
380 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; | 382 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; |
381 | 383 | ||
382 | if ( !first ) { | 384 | if ( !first ) { |
383 | result.append( "," ); | 385 | result.append( "," ); |
384 | } else { | 386 | } else { |
385 | first = false; | 387 | first = false; |
386 | } | 388 | } |
387 | 389 | ||
388 | result.append( parseMailbox( box ) ); | 390 | result.append( parseMailbox( box ) ); |
389 | } | 391 | } |
390 | 392 | ||
391 | return result; | 393 | return result; |
392 | } | 394 | } |
393 | 395 | ||
394 | encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) | 396 | encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) |
395 | { | 397 | { |
396 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); | 398 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); |
397 | if (it==bodyCache.end()) return new encodedString(); | 399 | if (it==bodyCache.end()) return new encodedString(); |
398 | encodedString*t = decode_String(it.data(),part->Encoding()); | 400 | encodedString*t = decode_String(it.data(),part->Encoding()); |
399 | return t; | 401 | return t; |
400 | } | 402 | } |
401 | 403 | ||
402 | encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) | 404 | encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) |
403 | { | 405 | { |
404 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); | 406 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); |
405 | if (it==bodyCache.end()) return new encodedString(); | 407 | if (it==bodyCache.end()) return new encodedString(); |
406 | encodedString*t = it.data(); | 408 | encodedString*t = it.data(); |
407 | return t; | 409 | return t; |
408 | } | 410 | } |
409 | 411 | ||
410 | QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) | 412 | QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) |
411 | { | 413 | { |
412 | encodedString*t = fetchDecodedPart(mail,part); | 414 | encodedString*t = fetchDecodedPart(mail,part); |
413 | QString text=t->Content(); | 415 | QString text=t->Content(); |
414 | delete t; | 416 | delete t; |
415 | return text; | 417 | return text; |
416 | } | 418 | } |
417 | 419 | ||
418 | void Genericwrapper::cleanMimeCache() | 420 | void Genericwrapper::cleanMimeCache() |
419 | { | 421 | { |
420 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); | 422 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); |
421 | for (;it!=bodyCache.end();++it) { | 423 | for (;it!=bodyCache.end();++it) { |
422 | encodedString*t = it.data(); | 424 | encodedString*t = it.data(); |
423 | //it.setValue(0); | 425 | //it.setValue(0); |
424 | if (t) delete t; | 426 | if (t) delete t; |
425 | } | 427 | } |
426 | bodyCache.clear(); | 428 | bodyCache.clear(); |
427 | ; // odebug << "Genericwrapper: cache cleaned" << oendl; | 429 | ; // odebug << "Genericwrapper: cache cleaned" << oendl; |
428 | } | 430 | } |
429 | 431 | ||
430 | QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) | 432 | QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) |
431 | { | 433 | { |
432 | QStringList res; | 434 | QStringList res; |
433 | if (!in_replies || !in_replies->mid_list) return res; | 435 | if (!in_replies || !in_replies->mid_list) return res; |
434 | clistiter * current = 0; | 436 | clistiter * current = 0; |
435 | for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { | 437 | for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { |
436 | QString h((char*)current->data); | 438 | QString h((char*)current->data); |
437 | while (h.length()>0 && h[0]=='<') { | 439 | while (h.length()>0 && h[0]=='<') { |
438 | h.remove(0,1); | 440 | h.remove(0,1); |
439 | } | 441 | } |
440 | while (h.length()>0 && h[h.length()-1]=='>') { | 442 | while (h.length()>0 && h[h.length()-1]=='>') { |
441 | h.remove(h.length()-1,1); | 443 | h.remove(h.length()-1,1); |
442 | } | 444 | } |
443 | if (h.length()>0) { | 445 | if (h.length()>0) { |
444 | res.append(h); | 446 | res.append(h); |
445 | } | 447 | } |
446 | } | 448 | } |
447 | return res; | 449 | return res; |
448 | } | 450 | } |
449 | 451 | ||
450 | void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb) | 452 | void Genericwrapper::parseList(Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb) |
451 | { | 453 | { |
452 | int r; | 454 | int r; |
453 | mailmessage_list * env_list = 0; | 455 | mailmessage_list * env_list = 0; |
454 | r = mailsession_get_messages_list(session,&env_list); | 456 | r = mailsession_get_messages_list(session,&env_list); |
455 | if (r != MAIL_NO_ERROR) { | 457 | if (r != MAIL_NO_ERROR) { |
456 | ; // odebug << "Error message list" << oendl; | 458 | ; // odebug << "Error message list" << oendl; |
457 | return; | 459 | return; |
458 | } | 460 | } |
459 | r = mailsession_get_envelopes_list(session, env_list); | 461 | r = mailsession_get_envelopes_list(session, env_list); |
460 | if (r != MAIL_NO_ERROR) { | 462 | if (r != MAIL_NO_ERROR) { |
461 | ; // odebug << "Error filling message list" << oendl; | 463 | ; // odebug << "Error filling message list" << oendl; |
462 | if (env_list) { | 464 | if (env_list) { |
463 | mailmessage_list_free(env_list); | 465 | mailmessage_list_free(env_list); |
464 | } | 466 | } |
465 | return; | 467 | return; |
466 | } | 468 | } |
467 | mailimf_references * refs = 0; | 469 | mailimf_references * refs = 0; |
468 | mailimf_in_reply_to * in_replies = 0; | 470 | mailimf_in_reply_to * in_replies = 0; |
469 | uint32_t i = 0; | 471 | uint32_t i = 0; |
470 | for(; i < carray_count(env_list->msg_tab) ; ++i) { | 472 | for(; i < carray_count(env_list->msg_tab) ; ++i) { |
471 | mailmessage * msg; | 473 | mailmessage * msg; |
472 | QBitArray mFlags(7); | 474 | QBitArray mFlags(7); |
473 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); | 475 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); |
474 | if (msg->msg_fields == NULL) { | 476 | if (msg->msg_fields == NULL) { |
475 | //; // odebug << "could not fetch envelope of message " << i << "" << oendl; | 477 | //; // odebug << "could not fetch envelope of message " << i << "" << oendl; |
476 | continue; | 478 | continue; |
477 | } | 479 | } |
478 | RecMailP mail = new RecMail(); | 480 | RecMailP mail = new RecMail(); |
479 | mail->setWrapper(this); | 481 | mail->setWrapper(this); |
480 | mail_flags * flag_result = 0; | 482 | mail_flags * flag_result = 0; |
481 | r = mailmessage_get_flags(msg,&flag_result); | 483 | r = mailmessage_get_flags(msg,&flag_result); |
482 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { | 484 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { |
483 | mFlags.setBit(FLAG_SEEN); | 485 | mFlags.setBit(FLAG_SEEN); |
484 | } | 486 | } |
485 | mailimf_single_fields single_fields; | 487 | mailimf_single_fields single_fields; |
486 | mailimf_single_fields_init(&single_fields, msg->msg_fields); | 488 | mailimf_single_fields_init(&single_fields, msg->msg_fields); |
487 | mail->setMsgsize(msg->msg_size); | 489 | mail->setMsgsize(msg->msg_size); |
488 | mail->setFlags(mFlags); | 490 | mail->setFlags(mFlags); |
489 | mail->setMbox(mailbox); | 491 | mail->setMbox(mailbox); |
490 | mail->setNumber(msg->msg_index); | 492 | mail->setNumber(msg->msg_index); |
491 | if (single_fields.fld_subject) | 493 | if (single_fields.fld_subject) |
492 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); | 494 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); |
493 | if (single_fields.fld_from) { | 495 | if (single_fields.fld_from) { |
494 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); | 496 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); |
495 | } | 497 | } |
496 | if (!mbox_as_to) { | 498 | if (!mbox_as_to) { |
497 | if (single_fields.fld_to) | 499 | if (single_fields.fld_to) |
498 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); | 500 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); |
499 | } else { | 501 | } else { |
500 | mail->setTo(mailbox); | 502 | mail->setTo(mailbox); |
501 | } | 503 | } |
502 | if (single_fields.fld_cc) | 504 | if (single_fields.fld_cc) |
503 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); | 505 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); |
504 | if (single_fields.fld_bcc) | 506 | if (single_fields.fld_bcc) |
505 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); | 507 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); |
506 | if (single_fields.fld_orig_date) { | 508 | if (single_fields.fld_orig_date) { |
507 | QDateTime dt = Genericwrapper::parseDateTime( single_fields.fld_orig_date->dt_date_time ); | 509 | QDateTime dt = Genericwrapper::parseDateTime( single_fields.fld_orig_date->dt_date_time ); |
508 | QString ret; | 510 | QString ret; |
509 | if ( dt.date() == QDate::currentDate () ) | 511 | if ( dt.date() == QDate::currentDate () ) |
510 | ret = KGlobal::locale()->formatTime( dt.time(),true); | 512 | ret = KGlobal::locale()->formatTime( dt.time(),true); |
511 | else { | 513 | else { |
512 | ret = KGlobal::locale()->formatDateTime( dt,true,true); | 514 | ret = KGlobal::locale()->formatDateTime( dt,true,true); |
513 | } | 515 | } |
514 | mail->setDate( ret ); | 516 | mail->setDate( ret ); |
515 | char tmp[20]; | 517 | char tmp[20]; |
516 | snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", | 518 | snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", |
517 | dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); | 519 | dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); |
518 | //qDebug(" iso %s ", tmp); | 520 | //qDebug(" iso %s ", tmp); |
519 | mail->setIsoDate( QString( tmp ) ); | 521 | mail->setIsoDate( QString( tmp ) ); |
520 | } | 522 | } |
521 | // crashes when accessing pop3 account? | 523 | // crashes when accessing pop3 account? |
522 | if (single_fields.fld_message_id) { | 524 | if (single_fields.fld_message_id) { |
523 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); | 525 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); |
524 | ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl; | 526 | ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl; |
525 | } | 527 | } |
526 | if (single_fields.fld_reply_to) { | 528 | if (single_fields.fld_reply_to) { |
527 | QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); | 529 | QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); |
528 | if (t.count()>0) { | 530 | if (t.count()>0) { |
529 | mail->setReplyto(t[0]); | 531 | mail->setReplyto(t[0]); |
530 | } | 532 | } |
531 | } | 533 | } |
532 | #if 0 | 534 | #if 0 |
533 | refs = single_fields.fld_references; | 535 | refs = single_fields.fld_references; |
534 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | 536 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { |
535 | char * text = (char*)refs->mid_list->first->data; | 537 | char * text = (char*)refs->mid_list->first->data; |
536 | mail->setReplyto(QString(text)); | 538 | mail->setReplyto(QString(text)); |
537 | } | 539 | } |
538 | #endif | 540 | #endif |
539 | if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list && | 541 | if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list && |
540 | clist_count(single_fields.fld_in_reply_to->mid_list)) { | 542 | clist_count(single_fields.fld_in_reply_to->mid_list)) { |
541 | mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); | 543 | mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); |
542 | } | 544 | } |
543 | if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 ) | 545 | if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 ) |
544 | target.append(mail); | 546 | target.append(mail); |
545 | } | 547 | } |
546 | if (env_list) { | 548 | if (env_list) { |