-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,231 +1,233 @@ | |||
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); |