summaryrefslogtreecommitdiffabout
path: root/kmicromail
authorzautrix <zautrix>2004-09-22 03:08:05 (UTC)
committer zautrix <zautrix>2004-09-22 03:08:05 (UTC)
commitd63eac7a612a9724705bc58ad98c65c6ac052d07 (patch) (unidiff)
treedc584a0ddcbd5f828ea36b86b6af640e46e137f2 /kmicromail
parent633522024e48efc423155a04b71083a03696211d (diff)
downloadkdepimpi-d63eac7a612a9724705bc58ad98c65c6ac052d07.zip
kdepimpi-d63eac7a612a9724705bc58ad98c65c6ac052d07.tar.gz
kdepimpi-d63eac7a612a9724705bc58ad98c65c6ac052d07.tar.bz2
connected global config
Diffstat (limited to 'kmicromail') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/genericwrapper.cpp18
-rw-r--r--kmicromail/opiemail.cpp2
2 files changed, 2 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,548 +1,530 @@
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);
307 return body; 289 return body;
308} 290}
309 291
310 292
311QString Genericwrapper::parseAddressList( mailimf_address_list *list ) 293QString Genericwrapper::parseAddressList( mailimf_address_list *list )
312{ 294{
313 QString result( "" ); 295 QString result( "" );
314 296
315 bool first = true; 297 bool first = true;
316 if (list == 0) return result; 298 if (list == 0) return result;
317 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 299 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
318 mailimf_address *addr = (mailimf_address *) current->data; 300 mailimf_address *addr = (mailimf_address *) current->data;
319 301
320 if ( !first ) { 302 if ( !first ) {
321 result.append( "," ); 303 result.append( "," );
322 } else { 304 } else {
323 first = false; 305 first = false;
324 } 306 }
325 307
326 switch ( addr->ad_type ) { 308 switch ( addr->ad_type ) {
327 case MAILIMF_ADDRESS_MAILBOX: 309 case MAILIMF_ADDRESS_MAILBOX:
328 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 310 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
329 break; 311 break;
330 case MAILIMF_ADDRESS_GROUP: 312 case MAILIMF_ADDRESS_GROUP:
331 result.append( parseGroup( addr->ad_data.ad_group ) ); 313 result.append( parseGroup( addr->ad_data.ad_group ) );
332 break; 314 break;
333 default: 315 default:
334 ; // odebug << "Generic: unkown mailimf address type" << oendl; 316 ; // odebug << "Generic: unkown mailimf address type" << oendl;
335 break; 317 break;
336 } 318 }
337 } 319 }
338 320
339 return result; 321 return result;
340} 322}
341 323
342QString Genericwrapper::parseGroup( mailimf_group *group ) 324QString Genericwrapper::parseGroup( mailimf_group *group )
343{ 325{
344 QString result( "" ); 326 QString result( "" );
345 327
346 result.append( group->grp_display_name ); 328 result.append( group->grp_display_name );
347 result.append( ": " ); 329 result.append( ": " );
348 330
349 if ( group->grp_mb_list != NULL ) { 331 if ( group->grp_mb_list != NULL ) {
350 result.append( parseMailboxList( group->grp_mb_list ) ); 332 result.append( parseMailboxList( group->grp_mb_list ) );
351 } 333 }
352 334
353 result.append( ";" ); 335 result.append( ";" );
354 336
355 return result; 337 return result;
356} 338}
357 339
358QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) 340QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
359{ 341{
360 QString result( "" ); 342 QString result( "" );
361 343
362 if ( box->mb_display_name == NULL ) { 344 if ( box->mb_display_name == NULL ) {
363 result.append( box->mb_addr_spec ); 345 result.append( box->mb_addr_spec );
364 } else { 346 } else {
365 result.append( convert_String(box->mb_display_name).latin1() ); 347 result.append( convert_String(box->mb_display_name).latin1() );
366 result.append( " <" ); 348 result.append( " <" );
367 result.append( box->mb_addr_spec ); 349 result.append( box->mb_addr_spec );
368 result.append( ">" ); 350 result.append( ">" );
369 } 351 }
370 352
371 return result; 353 return result;
372} 354}
373 355
374QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) 356QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
375{ 357{
376 QString result( "" ); 358 QString result( "" );
377 359
378 bool first = true; 360 bool first = true;
379 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 361 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
380 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 362 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
381 363
382 if ( !first ) { 364 if ( !first ) {
383 result.append( "," ); 365 result.append( "," );
384 } else { 366 } else {
385 first = false; 367 first = false;
386 } 368 }
387 369
388 result.append( parseMailbox( box ) ); 370 result.append( parseMailbox( box ) );
389 } 371 }
390 372
391 return result; 373 return result;
392} 374}
393 375
394encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) 376encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part)
395{ 377{
396 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); 378 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier());
397 if (it==bodyCache.end()) return new encodedString(); 379 if (it==bodyCache.end()) return new encodedString();
398 encodedString*t = decode_String(it.data(),part->Encoding()); 380 encodedString*t = decode_String(it.data(),part->Encoding());
399 return t; 381 return t;
400} 382}
401 383
402encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) 384encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part)
403{ 385{
404 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); 386 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier());
405 if (it==bodyCache.end()) return new encodedString(); 387 if (it==bodyCache.end()) return new encodedString();
406 encodedString*t = it.data(); 388 encodedString*t = it.data();
407 return t; 389 return t;
408} 390}
409 391
410QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 392QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
411{ 393{
412 encodedString*t = fetchDecodedPart(mail,part); 394 encodedString*t = fetchDecodedPart(mail,part);
413 QString text=t->Content(); 395 QString text=t->Content();
414 delete t; 396 delete t;
415 return text; 397 return text;
416} 398}
417 399
418void Genericwrapper::cleanMimeCache() 400void Genericwrapper::cleanMimeCache()
419{ 401{
420 QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); 402 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
421 for (;it!=bodyCache.end();++it) { 403 for (;it!=bodyCache.end();++it) {
422 encodedString*t = it.data(); 404 encodedString*t = it.data();
423 //it.setValue(0); 405 //it.setValue(0);
424 if (t) delete t; 406 if (t) delete t;
425 } 407 }
426 bodyCache.clear(); 408 bodyCache.clear();
427 ; // odebug << "Genericwrapper: cache cleaned" << oendl; 409 ; // odebug << "Genericwrapper: cache cleaned" << oendl;
428} 410}
429 411
430QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) 412QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies)
431{ 413{
432 QStringList res; 414 QStringList res;
433 if (!in_replies || !in_replies->mid_list) return res; 415 if (!in_replies || !in_replies->mid_list) return res;
434 clistiter * current = 0; 416 clistiter * current = 0;
435 for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { 417 for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) {
436 QString h((char*)current->data); 418 QString h((char*)current->data);
437 while (h.length()>0 && h[0]=='<') { 419 while (h.length()>0 && h[0]=='<') {
438 h.remove(0,1); 420 h.remove(0,1);
439 } 421 }
440 while (h.length()>0 && h[h.length()-1]=='>') { 422 while (h.length()>0 && h[h.length()-1]=='>') {
441 h.remove(h.length()-1,1); 423 h.remove(h.length()-1,1);
442 } 424 }
443 if (h.length()>0) { 425 if (h.length()>0) {
444 res.append(h); 426 res.append(h);
445 } 427 }
446 } 428 }
447 return res; 429 return res;
448} 430}
449 431
450void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb) 432void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb)
451{ 433{
452 int r; 434 int r;
453 mailmessage_list * env_list = 0; 435 mailmessage_list * env_list = 0;
454 r = mailsession_get_messages_list(session,&env_list); 436 r = mailsession_get_messages_list(session,&env_list);
455 if (r != MAIL_NO_ERROR) { 437 if (r != MAIL_NO_ERROR) {
456 ; // odebug << "Error message list" << oendl; 438 ; // odebug << "Error message list" << oendl;
457 return; 439 return;
458 } 440 }
459 r = mailsession_get_envelopes_list(session, env_list); 441 r = mailsession_get_envelopes_list(session, env_list);
460 if (r != MAIL_NO_ERROR) { 442 if (r != MAIL_NO_ERROR) {
461 ; // odebug << "Error filling message list" << oendl; 443 ; // odebug << "Error filling message list" << oendl;
462 if (env_list) { 444 if (env_list) {
463 mailmessage_list_free(env_list); 445 mailmessage_list_free(env_list);
464 } 446 }
465 return; 447 return;
466 } 448 }
467 mailimf_references * refs = 0; 449 mailimf_references * refs = 0;
468 mailimf_in_reply_to * in_replies = 0; 450 mailimf_in_reply_to * in_replies = 0;
469 uint32_t i = 0; 451 uint32_t i = 0;
470 for(; i < carray_count(env_list->msg_tab) ; ++i) { 452 for(; i < carray_count(env_list->msg_tab) ; ++i) {
471 mailmessage * msg; 453 mailmessage * msg;
472 QBitArray mFlags(7); 454 QBitArray mFlags(7);
473 msg = (mailmessage*)carray_get(env_list->msg_tab, i); 455 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
474 if (msg->msg_fields == NULL) { 456 if (msg->msg_fields == NULL) {
475 //; // odebug << "could not fetch envelope of message " << i << "" << oendl; 457 //; // odebug << "could not fetch envelope of message " << i << "" << oendl;
476 continue; 458 continue;
477 } 459 }
478 RecMailP mail = new RecMail(); 460 RecMailP mail = new RecMail();
479 mail->setWrapper(this); 461 mail->setWrapper(this);
480 mail_flags * flag_result = 0; 462 mail_flags * flag_result = 0;
481 r = mailmessage_get_flags(msg,&flag_result); 463 r = mailmessage_get_flags(msg,&flag_result);
482 if (r == MAIL_ERROR_NOT_IMPLEMENTED) { 464 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
483 mFlags.setBit(FLAG_SEEN); 465 mFlags.setBit(FLAG_SEEN);
484 } 466 }
485 mailimf_single_fields single_fields; 467 mailimf_single_fields single_fields;
486 mailimf_single_fields_init(&single_fields, msg->msg_fields); 468 mailimf_single_fields_init(&single_fields, msg->msg_fields);
487 mail->setMsgsize(msg->msg_size); 469 mail->setMsgsize(msg->msg_size);
488 mail->setFlags(mFlags); 470 mail->setFlags(mFlags);
489 mail->setMbox(mailbox); 471 mail->setMbox(mailbox);
490 mail->setNumber(msg->msg_index); 472 mail->setNumber(msg->msg_index);
491 if (single_fields.fld_subject) 473 if (single_fields.fld_subject)
492 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); 474 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
493 if (single_fields.fld_from) 475 if (single_fields.fld_from)
494 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); 476 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
495 if (!mbox_as_to) { 477 if (!mbox_as_to) {
496 if (single_fields.fld_to) 478 if (single_fields.fld_to)
497 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); 479 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
498 } else { 480 } else {
499 mail->setTo(mailbox); 481 mail->setTo(mailbox);
500 } 482 }
501 if (single_fields.fld_cc) 483 if (single_fields.fld_cc)
502 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); 484 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) );
503 if (single_fields.fld_bcc) 485 if (single_fields.fld_bcc)
504 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); 486 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) );
505 if (single_fields.fld_orig_date) { 487 if (single_fields.fld_orig_date) {
506 QDateTime dt = Genericwrapper::parseDateTime( single_fields.fld_orig_date->dt_date_time ); 488 QDateTime dt = Genericwrapper::parseDateTime( single_fields.fld_orig_date->dt_date_time );
507 QString ret; 489 QString ret;
508 if ( dt.date() == QDate::currentDate () ) 490 if ( dt.date() == QDate::currentDate () )
509 ret = KGlobal::locale()->formatTime( dt.time(),true); 491 ret = KGlobal::locale()->formatTime( dt.time(),true);
510 else { 492 else {
511 ret = KGlobal::locale()->formatDateTime( dt,true,true); 493 ret = KGlobal::locale()->formatDateTime( dt,true,true);
512 } 494 }
513 mail->setDate( ret ); 495 mail->setDate( ret );
514 char tmp[20]; 496 char tmp[20];
515 snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", 497 snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i",
516 dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); 498 dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() );
517 //qDebug(" iso %s ", tmp); 499 //qDebug(" iso %s ", tmp);
518 mail->setIsoDate( QString( tmp ) ); 500 mail->setIsoDate( QString( tmp ) );
519 } 501 }
520 // crashes when accessing pop3 account? 502 // crashes when accessing pop3 account?
521 if (single_fields.fld_message_id) { 503 if (single_fields.fld_message_id) {
522 mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); 504 mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
523 ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl; 505 ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl;
524 } 506 }
525 if (single_fields.fld_reply_to) { 507 if (single_fields.fld_reply_to) {
526 QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); 508 QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list);
527 if (t.count()>0) { 509 if (t.count()>0) {
528 mail->setReplyto(t[0]); 510 mail->setReplyto(t[0]);
529 } 511 }
530 } 512 }
531#if 0 513#if 0
532 refs = single_fields.fld_references; 514 refs = single_fields.fld_references;
533 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 515 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
534 char * text = (char*)refs->mid_list->first->data; 516 char * text = (char*)refs->mid_list->first->data;
535 mail->setReplyto(QString(text)); 517 mail->setReplyto(QString(text));
536 } 518 }
537#endif 519#endif
538 if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list && 520 if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list &&
539 clist_count(single_fields.fld_in_reply_to->mid_list)) { 521 clist_count(single_fields.fld_in_reply_to->mid_list)) {
540 mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); 522 mail->setInreply(parseInreplies(single_fields.fld_in_reply_to));
541 } 523 }
542 if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 ) 524 if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 )
543 target.append(mail); 525 target.append(mail);
544 } 526 }
545 if (env_list) { 527 if (env_list) {
546 mailmessage_list_free(env_list); 528 mailmessage_list_free(env_list);
547 } 529 }
548} 530}
diff --git a/kmicromail/opiemail.cpp b/kmicromail/opiemail.cpp
index 9a1a750..164988c 100644
--- a/kmicromail/opiemail.cpp
+++ b/kmicromail/opiemail.cpp
@@ -1,466 +1,468 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2// CHANGED 2004-08-06 Lutz Rogowski 2// CHANGED 2004-08-06 Lutz Rogowski
3 3
4#include "settingsdialog.h" 4#include "settingsdialog.h"
5#include "opiemail.h" 5#include "opiemail.h"
6#include "editaccounts.h" 6#include "editaccounts.h"
7#include "composemail.h" 7#include "composemail.h"
8#include "mailistviewitem.h" 8#include "mailistviewitem.h"
9#include "viewmail.h" 9#include "viewmail.h"
10#include "selectstore.h" 10#include "selectstore.h"
11#include "selectsmtp.h" 11#include "selectsmtp.h"
12#include "accountitem.h" 12#include "accountitem.h"
13#include "koprefsdialog.h" 13#include "koprefsdialog.h"
14 14
15#include <qmessagebox.h> 15#include <qmessagebox.h>
16#include <qtimer.h> 16#include <qtimer.h>
17#include <libkdepim/externalapphandler.h> 17#include <libkdepim/externalapphandler.h>
18#include <libkdepim/kpimglobalprefs.h>
18 19
19#include <qpe/qpeapplication.h> 20#include <qpe/qpeapplication.h>
20#include <libmailwrapper/smtpwrapper.h> 21#include <libmailwrapper/smtpwrapper.h>
21#include <libmailwrapper/mailtypes.h> 22#include <libmailwrapper/mailtypes.h>
22#include <libmailwrapper/abstractmail.h> 23#include <libmailwrapper/abstractmail.h>
23/* OPIE */ 24/* OPIE */
24//#include <qpe/resource.h> 25//#include <qpe/resource.h>
25//#include <qpe/qpeapplication.h> 26//#include <qpe/qpeapplication.h>
26 27
27/* QT */ 28/* QT */
28 29
29//using namespace Opie::Core; 30//using namespace Opie::Core;
30 31
31OpieMail::OpieMail( QWidget *parent, const char *name ) 32OpieMail::OpieMail( QWidget *parent, const char *name )
32 : MainWindow( parent, name) //, WStyle_ContextHelp ) 33 : MainWindow( parent, name) //, WStyle_ContextHelp )
33{ 34{
34 settings = new Settings(); 35 settings = new Settings();
36 KPimGlobalPrefs::instance()->setGlobalConfig();
35 37
36 folderView->populate( settings->getAccounts() ); 38 folderView->populate( settings->getAccounts() );
37 39
38} 40}
39 41
40OpieMail::~OpieMail() 42OpieMail::~OpieMail()
41{ 43{
42 if (settings) delete settings; 44 if (settings) delete settings;
43} 45}
44 46
45void OpieMail::appMessage(const QCString &msg, const QByteArray &data) 47void OpieMail::appMessage(const QCString &msg, const QByteArray &data)
46{ 48{
47 49
48} 50}
49#include <stdlib.h> 51#include <stdlib.h>
50void OpieMail::message(const QCString &msg, const QByteArray &data) 52void OpieMail::message(const QCString &msg, const QByteArray &data)
51{ 53{
52 // copied from old mail2 54 // copied from old mail2
53 static int ii = 0; 55 static int ii = 0;
54 //qDebug("QCOP CALL ############################# %d ", ii); 56 //qDebug("QCOP CALL ############################# %d ", ii);
55 //QString mess ( msg ); 57 //QString mess ( msg );
56 //qDebug("Message = %s ",mess.latin1()); 58 //qDebug("Message = %s ",mess.latin1());
57 ++ii; 59 ++ii;
58 //qDebug("KM:appMessage %d *%s* %x", ii, msg.data(), this); 60 //qDebug("KM:appMessage %d *%s* %x", ii, msg.data(), this);
59 61
60 mPendingEmail = QString::null; 62 mPendingEmail = QString::null;
61 mPendingName = QString::null; 63 mPendingName = QString::null;
62 if (msg == "writeMail(QString,QString)") 64 if (msg == "writeMail(QString,QString)")
63 { 65 {
64 //qDebug("writeMail(QString,QString) "); 66 //qDebug("writeMail(QString,QString) ");
65 QDataStream stream(data,IO_ReadOnly); 67 QDataStream stream(data,IO_ReadOnly);
66 stream >> mPendingName >> mPendingEmail; 68 stream >> mPendingName >> mPendingEmail;
67 // removing the whitespaces at beginning and end is needed! 69 // removing the whitespaces at beginning and end is needed!
68 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); 70 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) );
69 } 71 }
70 else if (msg == "newMail()") 72 else if (msg == "newMail()")
71 { 73 {
72 //qDebug("slotComposeMail() "); 74 //qDebug("slotComposeMail() ");
73 // we cannot call slotComposeMail(); directly, because may be executing a QCOP call 75 // we cannot call slotComposeMail(); directly, because may be executing a QCOP call
74 // and a QCOP call does not like a processevents in his execution 76 // and a QCOP call does not like a processevents in his execution
75 // with the Qtimer we call slotComposeMail() after we reached the main event loop 77 // with the Qtimer we call slotComposeMail() after we reached the main event loop
76 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); 78 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) );
77 // slotComposeMail(); 79 // slotComposeMail();
78 } 80 }
79 else if (msg == "newMail(QString)") 81 else if (msg == "newMail(QString)")
80 { 82 {
81 //qDebug(" newMail(QString)"); 83 //qDebug(" newMail(QString)");
82 QDataStream stream(data,IO_ReadOnly); 84 QDataStream stream(data,IO_ReadOnly);
83 stream >> mPendingName; 85 stream >> mPendingName;
84 // the format is 86 // the format is
85 // NAME <EMAIL>:SUBJECT 87 // NAME <EMAIL>:SUBJECT
86 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); 88 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) );
87 } else { 89 } else {
88 mPendingData = data; 90 mPendingData = data;
89 mPendingMessage = msg; 91 mPendingMessage = msg;
90 QTimer::singleShot ( 50, this, SLOT(slotExtAppHandler() ) ); 92 QTimer::singleShot ( 50, this, SLOT(slotExtAppHandler() ) );
91 } 93 }
92 94
93 //qDebug("END OpieMail::message "); 95 //qDebug("END OpieMail::message ");
94} 96}
95void OpieMail::slotExtAppHandler() 97void OpieMail::slotExtAppHandler()
96{ 98{
97 ExternalAppHandler::instance()->appMessage ( mPendingMessage, mPendingData ); 99 ExternalAppHandler::instance()->appMessage ( mPendingMessage, mPendingData );
98} 100}
99void OpieMail::slotwriteMail2(const QString& namemail ) 101void OpieMail::slotwriteMail2(const QString& namemail )
100{ 102{
101 //qDebug("OpieMail::slotwriteMail2 "); 103 //qDebug("OpieMail::slotwriteMail2 ");
102 //qApp->processEvents(); 104 //qApp->processEvents();
103 ComposeMail compose( settings, this, 0, true ); 105 ComposeMail compose( settings, this, 0, true );
104 if ( !namemail.isEmpty() ) { 106 if ( !namemail.isEmpty() ) {
105 QString to = namemail; 107 QString to = namemail;
106 if ( namemail.find( " <") > 1 ) { 108 if ( namemail.find( " <") > 1 ) {
107 to = "\"" +to.replace( QRegExp( " <"), "\" <") ; 109 to = "\"" +to.replace( QRegExp( " <"), "\" <") ;
108 } else 110 } else
109 if ( namemail.find( "<") > 1 ) { 111 if ( namemail.find( "<") > 1 ) {
110 to = "\"" +to.replace( QRegExp( "<"), "\" <") ; 112 to = "\"" +to.replace( QRegExp( "<"), "\" <") ;
111 } 113 }
112 int sub = to.find( ">:"); 114 int sub = to.find( ">:");
113 if ( sub > 0 ) { 115 if ( sub > 0 ) {
114 compose.setTo( to.left(sub+1) ); 116 compose.setTo( to.left(sub+1) );
115 compose.setSubject( to.mid(sub+2) ); 117 compose.setSubject( to.mid(sub+2) );
116 } else 118 } else
117 compose.setTo( to ); 119 compose.setTo( to );
118 } 120 }
119 compose.slotAdjustColumns(); 121 compose.slotAdjustColumns();
120 compose.showMaximized(); 122 compose.showMaximized();
121 compose.exec(); 123 compose.exec();
122 raise(); 124 raise();
123 //qDebug("retttich "); 125 //qDebug("retttich ");
124} 126}
125void OpieMail::slotwriteMail(const QString&name,const QString&email) 127void OpieMail::slotwriteMail(const QString&name,const QString&email)
126{ 128{
127 // qDebug("OpieMail::slotwriteMail "); 129 // qDebug("OpieMail::slotwriteMail ");
128 ComposeMail compose( settings, this, 0, true ); 130 ComposeMail compose( settings, this, 0, true );
129 if (!email.isEmpty()) 131 if (!email.isEmpty())
130 { 132 {
131 if (!name.isEmpty()) 133 if (!name.isEmpty())
132 { 134 {
133 compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">"); 135 compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">");
134 } 136 }
135 else 137 else
136 { 138 {
137 compose.setTo(email); 139 compose.setTo(email);
138 } 140 }
139 } 141 }
140 compose.slotAdjustColumns(); 142 compose.slotAdjustColumns();
141 compose.showMaximized(); 143 compose.showMaximized();
142 compose.exec(); 144 compose.exec();
143 raise(); 145 raise();
144} 146}
145 147
146void OpieMail::slotComposeMail() 148void OpieMail::slotComposeMail()
147{ 149{
148 if ( mPendingEmail == QString::null && mPendingName == QString::null) 150 if ( mPendingEmail == QString::null && mPendingName == QString::null)
149 slotwriteMail2( QString () ); 151 slotwriteMail2( QString () );
150 else { 152 else {
151 if ( mPendingEmail == QString::null ) 153 if ( mPendingEmail == QString::null )
152 slotwriteMail2( mPendingName ); 154 slotwriteMail2( mPendingName );
153 else 155 else
154 slotwriteMail( mPendingName, mPendingEmail ); 156 slotwriteMail( mPendingName, mPendingEmail );
155 } 157 }
156 //slotwriteMail(0l,0l); 158 //slotwriteMail(0l,0l);
157} 159}
158 160
159void OpieMail::slotSendQueued() 161void OpieMail::slotSendQueued()
160{ 162{
161 SMTPaccount *smtp = 0; 163 SMTPaccount *smtp = 0;
162 164
163 QList<Account> list = settings->getAccounts(); 165 QList<Account> list = settings->getAccounts();
164 QList<SMTPaccount> smtpList; 166 QList<SMTPaccount> smtpList;
165 smtpList.setAutoDelete(false); 167 smtpList.setAutoDelete(false);
166 Account *it; 168 Account *it;
167 for ( it = list.first(); it; it = list.next() ) 169 for ( it = list.first(); it; it = list.next() )
168 { 170 {
169 if ( it->getType() == MAILLIB::A_SMTP ) 171 if ( it->getType() == MAILLIB::A_SMTP )
170 { 172 {
171 smtp = static_cast<SMTPaccount *>(it); 173 smtp = static_cast<SMTPaccount *>(it);
172 smtpList.append(smtp); 174 smtpList.append(smtp);
173 } 175 }
174 } 176 }
175 if (smtpList.count()==0) 177 if (smtpList.count()==0)
176 { 178 {
177 QMessageBox::information(0,tr("Info"),tr("Define a smtp account first!\n")); 179 QMessageBox::information(0,tr("Info"),tr("Define a smtp account first!\n"));
178 return; 180 return;
179 } 181 }
180 if (smtpList.count()==1) 182 if (smtpList.count()==1)
181 { 183 {
182 smtp = smtpList.at(0); 184 smtp = smtpList.at(0);
183 } 185 }
184 else 186 else
185 { 187 {
186 smtp = 0; 188 smtp = 0;
187 selectsmtp selsmtp; 189 selectsmtp selsmtp;
188 selsmtp.setSelectionlist(&smtpList); 190 selsmtp.setSelectionlist(&smtpList);
189 selsmtp.showMaximized(); 191 selsmtp.showMaximized();
190 if ( selsmtp.exec() == QDialog::Accepted ) 192 if ( selsmtp.exec() == QDialog::Accepted )
191 { 193 {
192 smtp = selsmtp.selected_smtp(); 194 smtp = selsmtp.selected_smtp();
193 } 195 }
194 } 196 }
195 if (smtp) 197 if (smtp)
196 { 198 {
197 SMTPwrapper * wrap = new SMTPwrapper(smtp); 199 SMTPwrapper * wrap = new SMTPwrapper(smtp);
198 if ( wrap->flushOutbox() ) 200 if ( wrap->flushOutbox() )
199 { 201 {
200 QMessageBox::information(0,tr("Info"),tr("Mail queue flushed")); 202 QMessageBox::information(0,tr("Info"),tr("Mail queue flushed"));
201 } 203 }
202 delete wrap; 204 delete wrap;
203 } 205 }
204} 206}
205 207
206void OpieMail::slotSearchMails() 208void OpieMail::slotSearchMails()
207{ 209{
208 qDebug("OpieMail::slotSearchMails():not implemented "); 210 qDebug("OpieMail::slotSearchMails():not implemented ");
209} 211}
210 212
211void OpieMail::slotEditSettings() 213void OpieMail::slotEditSettings()
212{ 214{
213#if 0 215#if 0
214 SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp ); 216 SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp );
215 settingsDialog.showMaximized(); 217 settingsDialog.showMaximized();
216 settingsDialog.exec(); 218 settingsDialog.exec();
217#endif 219#endif
218 KOPrefsDialog settingsDialog( this, "koprefs", true ); 220 KOPrefsDialog settingsDialog( this, "koprefs", true );
219 settingsDialog.showMaximized(); 221 settingsDialog.showMaximized();
220 settingsDialog.exec(); 222 settingsDialog.exec();
221} 223}
222 224
223void OpieMail::slotEditAccounts() 225void OpieMail::slotEditAccounts()
224{ 226{
225 EditAccounts eaDialog( settings, this, 0, true ); 227 EditAccounts eaDialog( settings, this, 0, true );
226 eaDialog.slotAdjustColumns(); 228 eaDialog.slotAdjustColumns();
227 eaDialog.showMaximized(); 229 eaDialog.showMaximized();
228 eaDialog.exec(); 230 eaDialog.exec();
229 if ( settings ) delete settings; 231 if ( settings ) delete settings;
230 settings = new Settings(); 232 settings = new Settings();
231 233
232 folderView->populate( settings->getAccounts() ); 234 folderView->populate( settings->getAccounts() );
233} 235}
234 236
235void OpieMail::displayMail() 237void OpieMail::displayMail()
236{ 238{
237 QListViewItem*item = mailView->currentItem(); 239 QListViewItem*item = mailView->currentItem();
238 if (!item) return; 240 if (!item) return;
239 RecMailP mail = ((MailListViewItem*)item)->data(); 241 RecMailP mail = ((MailListViewItem*)item)->data();
240 RecBodyP body = folderView->fetchBody(mail); 242 RecBodyP body = folderView->fetchBody(mail);
241 ViewMail readMail( this,"", Qt::WType_Modal ); 243 ViewMail readMail( this,"", Qt::WType_Modal );
242 readMail.setBody( body ); 244 readMail.setBody( body );
243 readMail.setMail( mail ); 245 readMail.setMail( mail );
244 readMail.showMaximized(); 246 readMail.showMaximized();
245 readMail.exec(); 247 readMail.exec();
246 248
247 if ( readMail.deleted ) 249 if ( readMail.deleted )
248 { 250 {
249 folderView->refreshCurrent(); 251 folderView->refreshCurrent();
250 } 252 }
251 else 253 else
252 { 254 {
253 ( (MailListViewItem*)item )->setPixmap( 0, QPixmap() ); 255 ( (MailListViewItem*)item )->setPixmap( 0, QPixmap() );
254 } 256 }
255} 257}
256void OpieMail::slotGetAllMail() 258void OpieMail::slotGetAllMail()
257{ 259{
258 QListViewItem * item = folderView->firstChild(); 260 QListViewItem * item = folderView->firstChild();
259 while ( item ){ 261 while ( item ){
260 ((AccountViewItem *)item)->contextMenuSelected( 101 ); 262 ((AccountViewItem *)item)->contextMenuSelected( 101 );
261 item = item->nextSibling (); 263 item = item->nextSibling ();
262 } 264 }
263} 265}
264void OpieMail::slotGetMail() 266void OpieMail::slotGetMail()
265{ 267{
266 QListViewItem * item = folderView->currentItem(); 268 QListViewItem * item = folderView->currentItem();
267 if ( ! item ) return; 269 if ( ! item ) return;
268 ((AccountViewItem *)item)->contextMenuSelected( 101 ); 270 ((AccountViewItem *)item)->contextMenuSelected( 101 );
269} 271}
270void OpieMail::slotDeleteMail() 272void OpieMail::slotDeleteMail()
271{ 273{
272 if (!mailView->currentItem()) return; 274 if (!mailView->currentItem()) return;
273 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); 275 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data();
274 if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 276 if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
275 { 277 {
276 mail->Wrapper()->deleteMail( mail ); 278 mail->Wrapper()->deleteMail( mail );
277 folderView->refreshCurrent(); 279 folderView->refreshCurrent();
278 } 280 }
279} 281}
280void OpieMail::slotDeleteAllMail() 282void OpieMail::slotDeleteAllMail()
281{ 283{
282 284
283 QValueList<RecMailP> t; 285 QValueList<RecMailP> t;
284 if ( QMessageBox::warning(this, tr("Delete All Mails"), tr("Do you really want to delete\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 286 if ( QMessageBox::warning(this, tr("Delete All Mails"), tr("Do you really want to delete\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
285 { 287 {
286 MailListViewItem* item = (MailListViewItem*)mailView->firstChild (); 288 MailListViewItem* item = (MailListViewItem*)mailView->firstChild ();
287 while ( item ) { 289 while ( item ) {
288 if ( item->isSelected() ) { 290 if ( item->isSelected() ) {
289 t.append( item->data() ); 291 t.append( item->data() );
290 } 292 }
291 item = (MailListViewItem*)item->nextSibling(); 293 item = (MailListViewItem*)item->nextSibling();
292 } 294 }
293 } 295 }
294 else 296 else
295 return; 297 return;
296 if ( t.count() == 0 ) 298 if ( t.count() == 0 )
297 return; 299 return;
298 RecMailP mail = t.first(); 300 RecMailP mail = t.first();
299 mail->Wrapper()->deleteMailList(t); 301 mail->Wrapper()->deleteMailList(t);
300 folderView->refreshCurrent(); 302 folderView->refreshCurrent();
301 303
302 304
303} 305}
304void OpieMail::clearSelection() 306void OpieMail::clearSelection()
305{ 307{
306 mailView->clearSelection(); 308 mailView->clearSelection();
307 309
308} 310}
309 311
310void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int ) 312void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int )
311{ 313{
312 if (!mailView->currentItem()) return; 314 if (!mailView->currentItem()) return;
313 MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType(); 315 MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType();
314 /* just the RIGHT button - or hold on pda */ 316 /* just the RIGHT button - or hold on pda */
315 if (button!=2) {return;} 317 if (button!=2) {return;}
316 if (!item) return; 318 if (!item) return;
317 QPopupMenu *m = new QPopupMenu(0); 319 QPopupMenu *m = new QPopupMenu(0);
318 if (m) 320 if (m)
319 { 321 {
320 if (mailtype==MAILLIB::A_NNTP) { 322 if (mailtype==MAILLIB::A_NNTP) {
321 m->insertItem(tr("Read this posting"),this,SLOT(displayMail())); 323 m->insertItem(tr("Read this posting"),this,SLOT(displayMail()));
322 m->insertItem(tr("Copy this posting"),this,SLOT(slotMoveCopyMail())); 324 m->insertItem(tr("Copy this posting"),this,SLOT(slotMoveCopyMail()));
323 m->insertSeparator(); 325 m->insertSeparator();
324 m->insertItem(tr("Copy all selected postings"),this,SLOT(slotMoveCopyAllMail())); 326 m->insertItem(tr("Copy all selected postings"),this,SLOT(slotMoveCopyAllMail()));
325 m->insertItem(tr("Clear selection"),this,SLOT(clearSelection())); 327 m->insertItem(tr("Clear selection"),this,SLOT(clearSelection()));
326 } else { 328 } else {
327 if (folderView->currentisDraft()) { 329 if (folderView->currentisDraft()) {
328 m->insertItem(tr("Edit this mail"),this,SLOT(reEditMail())); 330 m->insertItem(tr("Edit this mail"),this,SLOT(reEditMail()));
329 } 331 }
330 m->insertItem(tr("Read this mail"),this,SLOT(displayMail())); 332 m->insertItem(tr("Read this mail"),this,SLOT(displayMail()));
331 m->insertItem(tr("Move/Copy this mail"),this,SLOT(slotMoveCopyMail())); 333 m->insertItem(tr("Move/Copy this mail"),this,SLOT(slotMoveCopyMail()));
332 m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail())); 334 m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail()));
333 m->insertSeparator(); 335 m->insertSeparator();
334 m->insertItem(tr("Move/Copy all selected mail"),this,SLOT(slotMoveCopyAllMail())); 336 m->insertItem(tr("Move/Copy all selected mail"),this,SLOT(slotMoveCopyAllMail()));
335 m->insertItem(tr("Delete all selected mails"),this,SLOT(slotDeleteAllMail())); 337 m->insertItem(tr("Delete all selected mails"),this,SLOT(slotDeleteAllMail()));
336 m->insertItem(tr("Clear selection"),this,SLOT(clearSelection())); 338 m->insertItem(tr("Clear selection"),this,SLOT(clearSelection()));
337 } 339 }
338 m->setFocus(); 340 m->setFocus();
339 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); 341 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
340 delete m; 342 delete m;
341 } 343 }
342} 344}
343 345
344void OpieMail::slotShowFolders( bool show ) 346void OpieMail::slotShowFolders( bool show )
345{ 347{
346 if ( show && folderView->isHidden() ) 348 if ( show && folderView->isHidden() )
347 { 349 {
348 folderView->show(); 350 folderView->show();
349 } 351 }
350 else if ( !show && !folderView->isHidden() ) 352 else if ( !show && !folderView->isHidden() )
351 { 353 {
352 folderView->hide(); 354 folderView->hide();
353 } 355 }
354} 356}
355 357
356void OpieMail::refreshMailView(const QValueList<RecMailP>&list) 358void OpieMail::refreshMailView(const QValueList<RecMailP>&list)
357{ 359{
358 MailListViewItem*item = 0; 360 MailListViewItem*item = 0;
359 mailView->clear(); 361 mailView->clear();
360 362
361 QValueList<RecMailP>::ConstIterator it; 363 QValueList<RecMailP>::ConstIterator it;
362 for (it = list.begin(); it != list.end();++it) 364 for (it = list.begin(); it != list.end();++it)
363 { 365 {
364 item = new MailListViewItem(mailView,item); 366 item = new MailListViewItem(mailView,item);
365 item->storeData((*it)); 367 item->storeData((*it));
366 item->showEntry(); 368 item->showEntry();
367 } 369 }
368} 370}
369 371
370void OpieMail::mailLeftClicked( QListViewItem *item ) 372void OpieMail::mailLeftClicked( QListViewItem *item )
371{ 373{
372 mailView->clearSelection(); 374 mailView->clearSelection();
373 /* just LEFT button - or tap with stylus on pda */ 375 /* just LEFT button - or tap with stylus on pda */
374 //if (button!=1) return; 376 //if (button!=1) return;
375 if (!item) return; 377 if (!item) return;
376 if (folderView->currentisDraft()) { 378 if (folderView->currentisDraft()) {
377 reEditMail(); 379 reEditMail();
378 } else { 380 } else {
379 displayMail(); 381 displayMail();
380 } 382 }
381} 383}
382 384
383void OpieMail::slotMoveCopyMail() 385void OpieMail::slotMoveCopyMail()
384{ 386{
385 if (!mailView->currentItem()) return; 387 if (!mailView->currentItem()) return;
386 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); 388 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data();
387 AbstractMail*targetMail = 0; 389 AbstractMail*targetMail = 0;
388 QString targetFolder = ""; 390 QString targetFolder = "";
389 Selectstore sels; 391 Selectstore sels;
390 folderView->setupFolderselect(&sels); 392 folderView->setupFolderselect(&sels);
391 if (!sels.exec()) return; 393 if (!sels.exec()) return;
392 targetMail = sels.currentMail(); 394 targetMail = sels.currentMail();
393 targetFolder = sels.currentFolder(); 395 targetFolder = sels.currentFolder();
394 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || 396 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) ||
395 targetFolder.isEmpty()) 397 targetFolder.isEmpty())
396 { 398 {
397 return; 399 return;
398 } 400 }
399 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 401 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
400 { 402 {
401 QMessageBox::critical(0,tr("Error creating new Folder"), 403 QMessageBox::critical(0,tr("Error creating new Folder"),
402 tr("<center>Error while creating<br>new folder - breaking.</center>")); 404 tr("<center>Error while creating<br>new folder - breaking.</center>"));
403 return; 405 return;
404 } 406 }
405 sels.hide(); 407 sels.hide();
406 qApp->processEvents(); 408 qApp->processEvents();
407 // qDebug("hiding sels "); 409 // qDebug("hiding sels ");
408 mail->Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails()); 410 mail->Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails());
409 folderView->refreshCurrent(); 411 folderView->refreshCurrent();
410} 412}
411 413
412void OpieMail::slotMoveCopyAllMail() 414void OpieMail::slotMoveCopyAllMail()
413{ 415{
414 416
415 if (!mailView->currentItem()) return; 417 if (!mailView->currentItem()) return;
416 QValueList<RecMailP> t; 418 QValueList<RecMailP> t;
417 // if ( QMessageBox::warning(this, tr("Move/Copy all selected mails"), tr("Do you really want to copy/move\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 419 // if ( QMessageBox::warning(this, tr("Move/Copy all selected mails"), tr("Do you really want to copy/move\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
418 { 420 {
419 MailListViewItem* item = (MailListViewItem*)mailView->firstChild (); 421 MailListViewItem* item = (MailListViewItem*)mailView->firstChild ();
420 while ( item ) { 422 while ( item ) {
421 if ( item->isSelected() ) { 423 if ( item->isSelected() ) {
422 t.append( item->data() ); 424 t.append( item->data() );
423 } 425 }
424 item = (MailListViewItem*)item->nextSibling(); 426 item = (MailListViewItem*)item->nextSibling();
425 } 427 }
426 } 428 }
427 // else 429 // else
428 // return; 430 // return;
429 if ( t.count() == 0 ) 431 if ( t.count() == 0 )
430 return; 432 return;
431 RecMailP mail = t.first(); 433 RecMailP mail = t.first();
432 AbstractMail*targetMail = 0; 434 AbstractMail*targetMail = 0;
433 QString targetFolder = ""; 435 QString targetFolder = "";
434 Selectstore sels; 436 Selectstore sels;
435 folderView->setupFolderselect(&sels); 437 folderView->setupFolderselect(&sels);
436 if (!sels.exec()) return; 438 if (!sels.exec()) return;
437 targetMail = sels.currentMail(); 439 targetMail = sels.currentMail();
438 targetFolder = sels.currentFolder(); 440 targetFolder = sels.currentFolder();
439 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || 441 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) ||
440 targetFolder.isEmpty()) 442 targetFolder.isEmpty())
441 { 443 {
442 return; 444 return;
443 } 445 }
444 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 446 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
445 { 447 {
446 QMessageBox::critical(0,tr("Error creating new Folder"), 448 QMessageBox::critical(0,tr("Error creating new Folder"),
447 tr("<center>Error while creating<br>new folder - breaking.</center>")); 449 tr("<center>Error while creating<br>new folder - breaking.</center>"));
448 return; 450 return;
449 } 451 }
450 sels.hide(); 452 sels.hide();
451 qApp->processEvents(); 453 qApp->processEvents();
452 //qDebug("hiding sels "); 454 //qDebug("hiding sels ");
453 mail->Wrapper()->mvcpMailList(t,targetFolder,targetMail,sels.moveMails()); 455 mail->Wrapper()->mvcpMailList(t,targetFolder,targetMail,sels.moveMails());
454 folderView->refreshCurrent(); 456 folderView->refreshCurrent();
455} 457}
456 458
457void OpieMail::reEditMail() 459void OpieMail::reEditMail()
458{ 460{
459 if (!mailView->currentItem()) return; 461 if (!mailView->currentItem()) return;
460 462
461 ComposeMail compose( settings, this, 0, true ); 463 ComposeMail compose( settings, this, 0, true );
462 compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data()); 464 compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data());
463 compose.slotAdjustColumns(); 465 compose.slotAdjustColumns();
464 compose.showMaximized(); 466 compose.showMaximized();
465 compose.exec(); 467 compose.exec();
466} 468}