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