summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper
Unidiff
Diffstat (limited to 'kmicromail/libmailwrapper') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/genericwrapper.cpp18
1 files changed, 0 insertions, 18 deletions
diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp
index 09a6447..e691082 100644
--- a/kmicromail/libmailwrapper/genericwrapper.cpp
+++ b/kmicromail/libmailwrapper/genericwrapper.cpp
@@ -1,306 +1,288 @@
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
11using namespace Opie::Core; 11using namespace Opie::Core;
12Genericwrapper::Genericwrapper() 12Genericwrapper::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
20Genericwrapper::~Genericwrapper() 20Genericwrapper::~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}
30const QDateTime Genericwrapper::parseDateTime( mailimf_date_time *date ) 30const QDateTime Genericwrapper::parseDateTime( mailimf_date_time *date )
31{ 31{
32 static bool init = false ;
33 if ( ! init ) {
34 KConfig kon ( locateLocal( "config", "korganizerrc" ) );
35 kon.setGroup("Locale");
36 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)kon.readNumEntry( "PreferredDate",0) );
37 QString dummy = kon.readEntry( "UserDateFormatShort","%aK %d.%m.%y" );// kon.readEntry( "");
38 KGlobal::locale()->setHore24Format( !kon.readNumEntry( "PreferredTime",0 ) );
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(",") ));
42 kon.setGroup("Time & Date");
43 KGlobal::locale()->setDaylightSaving( kon.readBoolEntry( "UseDaylightsaving", true ),
44 kon.readNumEntry( "DaylightsavingStart", 90),
45 kon.readNumEntry( "DaylightsavingEnd",304) );
46 KGlobal::locale()->setTimezone( kon.readEntry( "TimeZoneName" ," 00:00 Europe/London(UTC)") );
47
48 init = true;
49 32
50 }
51 QDate da (date->dt_year,date->dt_month, date->dt_day ); 33 QDate da (date->dt_year,date->dt_month, date->dt_day );
52 QTime ti ( date->dt_hour, date->dt_min, date->dt_sec ); 34 QTime ti ( date->dt_hour, date->dt_min, date->dt_sec );
53 QDateTime dt ( da ,ti ); 35 QDateTime dt ( da ,ti );
54 int addsec = -date->dt_zone*36; 36 int addsec = -date->dt_zone*36;
55 //qDebug("adsec1 %d ",addsec ); 37 //qDebug("adsec1 %d ",addsec );
56 dt = dt.addSecs( addsec ); 38 dt = dt.addSecs( addsec );
57 int off = KGlobal::locale()->localTimeOffset( dt ); 39 int off = KGlobal::locale()->localTimeOffset( dt );
58 //qDebug("adsec2 %d ",off*60 ); 40 //qDebug("adsec2 %d ",off*60 );
59 41
60 dt = dt.addSecs( off*60 ); 42 dt = dt.addSecs( off*60 );
61 return dt; 43 return dt;
62#if 0 44#if 0
63 QString ret; 45 QString ret;
64 if ( dt.date() == QDate::currentDate () ) 46 if ( dt.date() == QDate::currentDate () )
65 ret = KGlobal::locale()->formatTime( dt.time(),true); 47 ret = KGlobal::locale()->formatTime( dt.time(),true);
66 48
67 else { 49 else {
68 ret = KGlobal::locale()->formatDateTime( dt,true,true); 50 ret = KGlobal::locale()->formatDateTime( dt,true,true);
69 } 51 }
70#endif 52#endif
71#if 0 53#if 0
72 if ( off < 0 ) 54 if ( off < 0 )
73 ret += " -"; 55 ret += " -";
74 else 56 else
75 ret += " +"; 57 ret += " +";
76 ret += QString::number( off / 60 ); 58 ret += QString::number( off / 60 );
77 ret += "h"; 59 ret += "h";
78#endif 60#endif
79#if 0 61#if 0
80 char tmp[23]; 62 char tmp[23];
81 63
82 // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 64 // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
83 // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 65 // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
84 snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i", 66 snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i",
85 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 67 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
86 68
87 69
88 return QString( tmp ); 70 return QString( tmp );
89#endif 71#endif
90 //return ret; 72 //return ret;
91} 73}
92 74
93void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) 75void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime)
94{ 76{
95 if (!mime) { 77 if (!mime) {
96 return; 78 return;
97 } 79 }
98 mailmime_field*field = 0; 80 mailmime_field*field = 0;
99 mailmime_single_fields fields; 81 mailmime_single_fields fields;
100 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 82 memset(&fields, 0, sizeof(struct mailmime_single_fields));
101 if (mime->mm_mime_fields != NULL) { 83 if (mime->mm_mime_fields != NULL) {
102 mailmime_single_fields_init(&fields, mime->mm_mime_fields, 84 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
103 mime->mm_content_type); 85 mime->mm_content_type);
104 } 86 }
105 87
106 mailmime_content*type = fields.fld_content; 88 mailmime_content*type = fields.fld_content;
107 clistcell*current; 89 clistcell*current;
108 if (!type) { 90 if (!type) {
109 target->setType("text"); 91 target->setType("text");
110 target->setSubtype("plain"); 92 target->setSubtype("plain");
111 } else { 93 } else {
112 target->setSubtype(type->ct_subtype); 94 target->setSubtype(type->ct_subtype);
113 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { 95 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
114 case MAILMIME_DISCRETE_TYPE_TEXT: 96 case MAILMIME_DISCRETE_TYPE_TEXT:
115 target->setType("text"); 97 target->setType("text");
116 break; 98 break;
117 case MAILMIME_DISCRETE_TYPE_IMAGE: 99 case MAILMIME_DISCRETE_TYPE_IMAGE:
118 target->setType("image"); 100 target->setType("image");
119 break; 101 break;
120 case MAILMIME_DISCRETE_TYPE_AUDIO: 102 case MAILMIME_DISCRETE_TYPE_AUDIO:
121 target->setType("audio"); 103 target->setType("audio");
122 break; 104 break;
123 case MAILMIME_DISCRETE_TYPE_VIDEO: 105 case MAILMIME_DISCRETE_TYPE_VIDEO:
124 target->setType("video"); 106 target->setType("video");
125 break; 107 break;
126 case MAILMIME_DISCRETE_TYPE_APPLICATION: 108 case MAILMIME_DISCRETE_TYPE_APPLICATION:
127 target->setType("application"); 109 target->setType("application");
128 break; 110 break;
129 case MAILMIME_DISCRETE_TYPE_EXTENSION: 111 case MAILMIME_DISCRETE_TYPE_EXTENSION:
130 default: 112 default:
131 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { 113 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) {
132 target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); 114 target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension);
133 } 115 }
134 break; 116 break;
135 } 117 }
136 if (type->ct_parameters) { 118 if (type->ct_parameters) {
137 fillParameters(target,type->ct_parameters); 119 fillParameters(target,type->ct_parameters);
138 } 120 }
139 } 121 }
140 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { 122 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) {
141 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { 123 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) {
142 field = (mailmime_field*)current->data; 124 field = (mailmime_field*)current->data;
143 switch(field->fld_type) { 125 switch(field->fld_type) {
144 case MAILMIME_FIELD_TRANSFER_ENCODING: 126 case MAILMIME_FIELD_TRANSFER_ENCODING:
145 target->setEncoding(getencoding(field->fld_data.fld_encoding)); 127 target->setEncoding(getencoding(field->fld_data.fld_encoding));
146 break; 128 break;
147 case MAILMIME_FIELD_ID: 129 case MAILMIME_FIELD_ID:
148 target->setIdentifier(field->fld_data.fld_id); 130 target->setIdentifier(field->fld_data.fld_id);
149 break; 131 break;
150 case MAILMIME_FIELD_DESCRIPTION: 132 case MAILMIME_FIELD_DESCRIPTION:
151 target->setDescription(field->fld_data.fld_description); 133 target->setDescription(field->fld_data.fld_description);
152 break; 134 break;
153 default: 135 default:
154 break; 136 break;
155 } 137 }
156 } 138 }
157 } 139 }
158} 140}
159 141
160void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) 142void Genericwrapper::fillParameters(RecPartP&target,clist*parameters)
161{ 143{
162 if (!parameters) {return;} 144 if (!parameters) {return;}
163 clistcell*current=0; 145 clistcell*current=0;
164 mailmime_parameter*param; 146 mailmime_parameter*param;
165 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { 147 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) {
166 param = (mailmime_parameter*)current->data; 148 param = (mailmime_parameter*)current->data;
167 if (param) { 149 if (param) {
168 target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 150 target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
169 } 151 }
170 } 152 }
171} 153}
172 154
173QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) 155QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
174{ 156{
175 QString enc="7bit"; 157 QString enc="7bit";
176 if (!aEnc) return enc; 158 if (!aEnc) return enc;
177 switch(aEnc->enc_type) { 159 switch(aEnc->enc_type) {
178 case MAILMIME_MECHANISM_7BIT: 160 case MAILMIME_MECHANISM_7BIT:
179 enc = "7bit"; 161 enc = "7bit";
180 break; 162 break;
181 case MAILMIME_MECHANISM_8BIT: 163 case MAILMIME_MECHANISM_8BIT:
182 enc = "8bit"; 164 enc = "8bit";
183 break; 165 break;
184 case MAILMIME_MECHANISM_BINARY: 166 case MAILMIME_MECHANISM_BINARY:
185 enc = "binary"; 167 enc = "binary";
186 break; 168 break;
187 case MAILMIME_MECHANISM_QUOTED_PRINTABLE: 169 case MAILMIME_MECHANISM_QUOTED_PRINTABLE:
188 enc = "quoted-printable"; 170 enc = "quoted-printable";
189 break; 171 break;
190 case MAILMIME_MECHANISM_BASE64: 172 case MAILMIME_MECHANISM_BASE64:
191 enc = "base64"; 173 enc = "base64";
192 break; 174 break;
193 case MAILMIME_MECHANISM_TOKEN: 175 case MAILMIME_MECHANISM_TOKEN:
194 default: 176 default:
195 if (aEnc->enc_token) { 177 if (aEnc->enc_token) {
196 enc = QString(aEnc->enc_token); 178 enc = QString(aEnc->enc_token);
197 } 179 }
198 break; 180 break;
199 } 181 }
200 return enc; 182 return enc;
201} 183}
202 184
203void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) 185void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count)
204{ 186{
205 if (current_rec >= 10) { 187 if (current_rec >= 10) {
206 ; // odebug << "too deep recursion!" << oendl; 188 ; // odebug << "too deep recursion!" << oendl;
207 } 189 }
208 if (!message || !mime) { 190 if (!message || !mime) {
209 return; 191 return;
210 } 192 }
211 int r; 193 int r;
212 char*data = 0; 194 char*data = 0;
213 size_t len; 195 size_t len;
214 clistiter * cur = 0; 196 clistiter * cur = 0;
215 QString b; 197 QString b;
216 RecPartP part = new RecPart(); 198 RecPartP part = new RecPart();
217 199
218 switch (mime->mm_type) { 200 switch (mime->mm_type) {
219 case MAILMIME_SINGLE: 201 case MAILMIME_SINGLE:
220 { 202 {
221 QValueList<int>countlist = recList; 203 QValueList<int>countlist = recList;
222 countlist.append(current_count); 204 countlist.append(current_count);
223 r = mailmessage_fetch_section(message,mime,&data,&len); 205 r = mailmessage_fetch_section(message,mime,&data,&len);
224 part->setSize(len); 206 part->setSize(len);
225 part->setPositionlist(countlist); 207 part->setPositionlist(countlist);
226 b = gen_attachment_id(); 208 b = gen_attachment_id();
227 part->setIdentifier(b); 209 part->setIdentifier(b);
228 fillSingleBody(part,message,mime); 210 fillSingleBody(part,message,mime);
229 if (part->Type()=="text" && target->Bodytext().isNull()) { 211 if (part->Type()=="text" && target->Bodytext().isNull()) {
230 encodedString*rs = new encodedString(); 212 encodedString*rs = new encodedString();
231 rs->setContent(data,len); 213 rs->setContent(data,len);
232 encodedString*res = decode_String(rs,part->Encoding()); 214 encodedString*res = decode_String(rs,part->Encoding());
233 if (countlist.count()>2) { 215 if (countlist.count()>2) {
234 bodyCache[b]=rs; 216 bodyCache[b]=rs;
235 target->addPart(part); 217 target->addPart(part);
236 } else { 218 } else {
237 delete rs; 219 delete rs;
238 } 220 }
239 b = QString(res->Content()); 221 b = QString(res->Content());
240 delete res; 222 delete res;
241 target->setBodytext(b); 223 target->setBodytext(b);
242 target->setDescription(part); 224 target->setDescription(part);
243 } else { 225 } else {
244 bodyCache[b]=new encodedString(data,len); 226 bodyCache[b]=new encodedString(data,len);
245 target->addPart(part); 227 target->addPart(part);
246 } 228 }
247 } 229 }
248 break; 230 break;
249 case MAILMIME_MULTIPLE: 231 case MAILMIME_MULTIPLE:
250 { 232 {
251 unsigned int ccount = 1; 233 unsigned int ccount = 1;
252 mailmime*cbody=0; 234 mailmime*cbody=0;
253 QValueList<int>countlist = recList; 235 QValueList<int>countlist = recList;
254 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { 236 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
255 cbody = (mailmime*)clist_content(cur); 237 cbody = (mailmime*)clist_content(cur);
256 if (cbody->mm_type==MAILMIME_MULTIPLE) { 238 if (cbody->mm_type==MAILMIME_MULTIPLE) {
257 RecPartP targetPart = new RecPart(); 239 RecPartP targetPart = new RecPart();
258 targetPart->setType("multipart"); 240 targetPart->setType("multipart");
259 countlist.append(current_count); 241 countlist.append(current_count);
260 targetPart->setPositionlist(countlist); 242 targetPart->setPositionlist(countlist);
261 target->addPart(targetPart); 243 target->addPart(targetPart);
262 } 244 }
263 traverseBody(target,message, cbody,countlist,current_rec+1,ccount); 245 traverseBody(target,message, cbody,countlist,current_rec+1,ccount);
264 if (cbody->mm_type==MAILMIME_MULTIPLE) { 246 if (cbody->mm_type==MAILMIME_MULTIPLE) {
265 countlist = recList; 247 countlist = recList;
266 } 248 }
267 ++ccount; 249 ++ccount;
268 } 250 }
269 } 251 }
270 break; 252 break;
271 case MAILMIME_MESSAGE: 253 case MAILMIME_MESSAGE:
272 { 254 {
273 QValueList<int>countlist = recList; 255 QValueList<int>countlist = recList;
274 countlist.append(current_count); 256 countlist.append(current_count);
275 /* the own header is always at recursion 0 - we don't need that */ 257 /* the own header is always at recursion 0 - we don't need that */
276 if (current_rec > 0) { 258 if (current_rec > 0) {
277 part->setPositionlist(countlist); 259 part->setPositionlist(countlist);
278 r = mailmessage_fetch_section(message,mime,&data,&len); 260 r = mailmessage_fetch_section(message,mime,&data,&len);
279 part->setSize(len); 261 part->setSize(len);
280 part->setPositionlist(countlist); 262 part->setPositionlist(countlist);
281 b = gen_attachment_id(); 263 b = gen_attachment_id();
282 part->setIdentifier(b); 264 part->setIdentifier(b);
283 part->setType("message"); 265 part->setType("message");
284 part->setSubtype("rfc822"); 266 part->setSubtype("rfc822");
285 bodyCache[b]=new encodedString(data,len); 267 bodyCache[b]=new encodedString(data,len);
286 target->addPart(part); 268 target->addPart(part);
287 } 269 }
288 if (mime->mm_data.mm_message.mm_msg_mime != NULL) { 270 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); 271 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1);
290 } 272 }
291 } 273 }
292 break; 274 break;
293 } 275 }
294} 276}
295 277
296RecBodyP Genericwrapper::parseMail( mailmessage * msg ) 278RecBodyP Genericwrapper::parseMail( mailmessage * msg )
297{ 279{
298 int err = MAILIMF_NO_ERROR; 280 int err = MAILIMF_NO_ERROR;
299 mailmime_single_fields fields; 281 mailmime_single_fields fields;
300 /* is bound to msg and will be freed there */ 282 /* is bound to msg and will be freed there */
301 mailmime * mime=0; 283 mailmime * mime=0;
302 RecBodyP body = new RecBody(); 284 RecBodyP body = new RecBody();
303 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 285 memset(&fields, 0, sizeof(struct mailmime_single_fields));
304 err = mailmessage_get_bodystructure(msg,&mime); 286 err = mailmessage_get_bodystructure(msg,&mime);
305 QValueList<int>recList; 287 QValueList<int>recList;
306 traverseBody(body,msg,mime,recList); 288 traverseBody(body,msg,mime,recList);