summaryrefslogtreecommitdiff
path: root/noncore/net/mail/libmailwrapper
authoralwin <alwin>2004-10-24 00:55:14 (UTC)
committer alwin <alwin>2004-10-24 00:55:14 (UTC)
commit9755bc969d17fc683791abc5c6fbd50fa3112486 (patch) (unidiff)
tree0fdcf7b52b2f4627dd3efcd7330b116c4d9c4d98 /noncore/net/mail/libmailwrapper
parent12eed25c7f18285f0e342d49fd3c41eb4b14e151 (diff)
downloadopie-9755bc969d17fc683791abc5c6fbd50fa3112486.zip
opie-9755bc969d17fc683791abc5c6fbd50fa3112486.tar.gz
opie-9755bc969d17fc683791abc5c6fbd50fa3112486.tar.bz2
new options for pop3 accounts
KATE eated a lot of last spaces in files some tryouts
Diffstat (limited to 'noncore/net/mail/libmailwrapper') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.cpp13
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp20
-rw-r--r--noncore/net/mail/libmailwrapper/mhwrapper.cpp0
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp9
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h2
-rw-r--r--noncore/net/mail/libmailwrapper/settings.cpp29
-rw-r--r--noncore/net/mail/libmailwrapper/settings.h7
7 files changed, 66 insertions, 14 deletions
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
index 1caa375..5ec9415 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
@@ -1,53 +1,55 @@
1#include "genericwrapper.h" 1#include "genericwrapper.h"
2#include <libetpan/libetpan.h> 2#include <libetpan/libetpan.h>
3#include "mailtypes.h" 3#include "mailtypes.h"
4 4
5#include <opie2/odebug.h> 5#include <opie2/odebug.h>
6#include <qpe/timestring.h>
7#include <qdatetime.h>
6 8
7using namespace Opie::Core; 9using namespace Opie::Core;
8Genericwrapper::Genericwrapper() 10Genericwrapper::Genericwrapper()
9 : AbstractMail() 11 : AbstractMail()
10{ 12{
11 bodyCache.clear(); 13 bodyCache.clear();
12 m_storage = 0; 14 m_storage = 0;
13 m_folder = 0; 15 m_folder = 0;
14} 16}
15 17
16Genericwrapper::~Genericwrapper() 18Genericwrapper::~Genericwrapper()
17{ 19{
18 if (m_folder) { 20 if (m_folder) {
19 mailfolder_free(m_folder); 21 mailfolder_free(m_folder);
20 } 22 }
21 if (m_storage) { 23 if (m_storage) {
22 mailstorage_free(m_storage); 24 mailstorage_free(m_storage);
23 } 25 }
24 cleanMimeCache(); 26 cleanMimeCache();
25} 27}
26 28
27void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) 29void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime)
28{ 30{
29 if (!mime) { 31 if (!mime) {
30 return; 32 return;
31 } 33 }
32 mailmime_field*field = 0; 34 mailmime_field*field = 0;
33 mailmime_single_fields fields; 35 mailmime_single_fields fields;
34 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 36 memset(&fields, 0, sizeof(struct mailmime_single_fields));
35 if (mime->mm_mime_fields != NULL) { 37 if (mime->mm_mime_fields != NULL) {
36 mailmime_single_fields_init(&fields, mime->mm_mime_fields, 38 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
37 mime->mm_content_type); 39 mime->mm_content_type);
38 } 40 }
39 41
40 mailmime_content*type = fields.fld_content; 42 mailmime_content*type = fields.fld_content;
41 clistcell*current; 43 clistcell*current;
42 if (!type) { 44 if (!type) {
43 target->setType("text"); 45 target->setType("text");
44 target->setSubtype("plain"); 46 target->setSubtype("plain");
45 } else { 47 } else {
46 target->setSubtype(type->ct_subtype); 48 target->setSubtype(type->ct_subtype);
47 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { 49 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
48 case MAILMIME_DISCRETE_TYPE_TEXT: 50 case MAILMIME_DISCRETE_TYPE_TEXT:
49 target->setType("text"); 51 target->setType("text");
50 break; 52 break;
51 case MAILMIME_DISCRETE_TYPE_IMAGE: 53 case MAILMIME_DISCRETE_TYPE_IMAGE:
52 target->setType("image"); 54 target->setType("image");
53 break; 55 break;
@@ -198,102 +200,101 @@ void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*m
198 if (cbody->mm_type==MAILMIME_MULTIPLE) { 200 if (cbody->mm_type==MAILMIME_MULTIPLE) {
199 countlist = recList; 201 countlist = recList;
200 } 202 }
201 ++ccount; 203 ++ccount;
202 } 204 }
203 } 205 }
204 break; 206 break;
205 case MAILMIME_MESSAGE: 207 case MAILMIME_MESSAGE:
206 { 208 {
207 QValueList<int>countlist = recList; 209 QValueList<int>countlist = recList;
208 countlist.append(current_count); 210 countlist.append(current_count);
209 /* the own header is always at recursion 0 - we don't need that */ 211 /* the own header is always at recursion 0 - we don't need that */
210 if (current_rec > 0) { 212 if (current_rec > 0) {
211 part->setPositionlist(countlist); 213 part->setPositionlist(countlist);
212 r = mailmessage_fetch_section(message,mime,&data,&len); 214 r = mailmessage_fetch_section(message,mime,&data,&len);
213 part->setSize(len); 215 part->setSize(len);
214 part->setPositionlist(countlist); 216 part->setPositionlist(countlist);
215 b = gen_attachment_id(); 217 b = gen_attachment_id();
216 part->setIdentifier(b); 218 part->setIdentifier(b);
217 part->setType("message"); 219 part->setType("message");
218 part->setSubtype("rfc822"); 220 part->setSubtype("rfc822");
219 bodyCache[b]=new encodedString(data,len); 221 bodyCache[b]=new encodedString(data,len);
220 target->addPart(part); 222 target->addPart(part);
221 } 223 }
222 if (mime->mm_data.mm_message.mm_msg_mime != NULL) { 224 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
223 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); 225 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1);
224 } 226 }
225 } 227 }
226 break; 228 break;
227 } 229 }
228} 230}
229 231
230RecBodyP Genericwrapper::parseMail( mailmessage * msg ) 232RecBodyP Genericwrapper::parseMail( mailmessage * msg )
231{ 233{
232 int err = MAILIMF_NO_ERROR; 234 int err = MAILIMF_NO_ERROR;
233 mailmime_single_fields fields; 235 mailmime_single_fields fields;
234 /* is bound to msg and will be freed there */ 236 /* is bound to msg and will be freed there */
235 mailmime * mime=0; 237 mailmime * mime=0;
236 RecBodyP body = new RecBody(); 238 RecBodyP body = new RecBody();
237 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 239 memset(&fields, 0, sizeof(struct mailmime_single_fields));
238 err = mailmessage_get_bodystructure(msg,&mime); 240 err = mailmessage_get_bodystructure(msg,&mime);
239 QValueList<int>recList; 241 QValueList<int>recList;
240 traverseBody(body,msg,mime,recList); 242 traverseBody(body,msg,mime,recList);
241 return body; 243 return body;
242} 244}
243 245
244QString Genericwrapper::parseDateTime( mailimf_date_time *date ) 246QString Genericwrapper::parseDateTime( mailimf_date_time *date )
245{ 247{
246 char tmp[23]; 248 QDateTime da(QDate(date->dt_year,date->dt_month,date->dt_day),QTime(date->dt_hour,date->dt_min,date->dt_sec));
247 249 QString timestring = TimeString::numberDateString(QDate(date->dt_year,date->dt_month,date->dt_day))+" ";
248 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 250 timestring+=TimeString::timeString(QTime(date->dt_hour,date->dt_min,date->dt_sec))+" ";
249 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 251 timestring.sprintf(timestring+" %+05i",date->dt_zone);
250 252 return timestring;
251 return QString( tmp );
252} 253}
253 254
254QString Genericwrapper::parseAddressList( mailimf_address_list *list ) 255QString Genericwrapper::parseAddressList( mailimf_address_list *list )
255{ 256{
256 QString result( "" ); 257 QString result( "" );
257 258
258 bool first = true; 259 bool first = true;
259 if (list == 0) return result; 260 if (list == 0) return result;
260 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 261 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
261 mailimf_address *addr = (mailimf_address *) current->data; 262 mailimf_address *addr = (mailimf_address *) current->data;
262 263
263 if ( !first ) { 264 if ( !first ) {
264 result.append( "," ); 265 result.append( "," );
265 } else { 266 } else {
266 first = false; 267 first = false;
267 } 268 }
268 269
269 switch ( addr->ad_type ) { 270 switch ( addr->ad_type ) {
270 case MAILIMF_ADDRESS_MAILBOX: 271 case MAILIMF_ADDRESS_MAILBOX:
271 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 272 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
272 break; 273 break;
273 case MAILIMF_ADDRESS_GROUP: 274 case MAILIMF_ADDRESS_GROUP:
274 result.append( parseGroup( addr->ad_data.ad_group ) ); 275 result.append( parseGroup( addr->ad_data.ad_group ) );
275 break; 276 break;
276 default: 277 default:
277 odebug << "Generic: unkown mailimf address type" << oendl; 278 odebug << "Generic: unkown mailimf address type" << oendl;
278 break; 279 break;
279 } 280 }
280 } 281 }
281 282
282 return result; 283 return result;
283} 284}
284 285
285QString Genericwrapper::parseGroup( mailimf_group *group ) 286QString Genericwrapper::parseGroup( mailimf_group *group )
286{ 287{
287 QString result( "" ); 288 QString result( "" );
288 289
289 result.append( group->grp_display_name ); 290 result.append( group->grp_display_name );
290 result.append( ": " ); 291 result.append( ": " );
291 292
292 if ( group->grp_mb_list != NULL ) { 293 if ( group->grp_mb_list != NULL ) {
293 result.append( parseMailboxList( group->grp_mb_list ) ); 294 result.append( parseMailboxList( group->grp_mb_list ) );
294 } 295 }
295 296
296 result.append( ";" ); 297 result.append( ";" );
297 298
298 return result; 299 return result;
299} 300}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 9b7c0e0..fe75a15 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -192,102 +192,106 @@ void IMAPwrapper::login()
192 } 192 }
193 } 193 }
194 if (!ok) { 194 if (!ok) {
195 err = mailimap_close( m_imap ); 195 err = mailimap_close( m_imap );
196 mailimap_free( m_imap ); 196 mailimap_free( m_imap );
197 m_imap = 0; 197 m_imap = 0;
198 } 198 }
199} 199}
200 200
201void IMAPwrapper::logout() 201void IMAPwrapper::logout()
202{ 202{
203 int err = MAILIMAP_NO_ERROR; 203 int err = MAILIMAP_NO_ERROR;
204 if (!m_imap) return; 204 if (!m_imap) return;
205 err = mailimap_logout( m_imap ); 205 err = mailimap_logout( m_imap );
206 err = mailimap_close( m_imap ); 206 err = mailimap_close( m_imap );
207 mailimap_free( m_imap ); 207 mailimap_free( m_imap );
208 m_imap = 0; 208 m_imap = 0;
209 m_Lastmbox = ""; 209 m_Lastmbox = "";
210} 210}
211 211
212void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) 212void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target )
213{ 213{
214 int err = MAILIMAP_NO_ERROR; 214 int err = MAILIMAP_NO_ERROR;
215 clist *result = 0; 215 clist *result = 0;
216 clistcell *current; 216 clistcell *current;
217 mailimap_fetch_type *fetchType = 0; 217 mailimap_fetch_type *fetchType = 0;
218 mailimap_set *set = 0; 218 mailimap_set *set = 0;
219 219
220 login(); 220 login();
221 if (!m_imap) { 221 if (!m_imap) {
222 return; 222 return;
223 } 223 }
224 /* select mailbox READONLY for operations */ 224 /* select mailbox READONLY for operations */
225 err = selectMbox(mailbox); 225 err = selectMbox(mailbox);
226 if ( err != MAILIMAP_NO_ERROR ) { 226 if ( err != MAILIMAP_NO_ERROR ) {
227 return; 227 return;
228 } 228 }
229 229
230 int last = m_imap->imap_selection_info->sel_exists; 230 int last = m_imap->imap_selection_info->sel_exists;
231 231
232 if (last == 0) { 232 if (last == 0) {
233 Global::statusMessage(tr("Mailbox has no mails")); 233 Global::statusMessage(tr("Mailbox has no mails"));
234 return; 234 return;
235 } else { 235 } else {
236 } 236 }
237 237
238 /* the range has to start at 1!!! not with 0!!!! */ 238 /* the range has to start at 1!!! not with 0!!!! */
239 set = mailimap_set_new_interval( 1, last ); 239 set = mailimap_set_new_interval( 1, last );
240
241
242 fetchType = mailimap_fetch_type_new_all();
243/*
240 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 244 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
241 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 245 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
242 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 246 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
243 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 247 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
244 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 248 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
245 249*/
246 err = mailimap_fetch( m_imap, set, fetchType, &result ); 250 err = mailimap_fetch( m_imap, set, fetchType, &result );
247 mailimap_set_free( set ); 251 mailimap_set_free( set );
248 mailimap_fetch_type_free( fetchType ); 252 mailimap_fetch_type_free( fetchType );
249 253
250 QString date,subject,from; 254 QString date,subject,from;
251 255
252 if ( err == MAILIMAP_NO_ERROR ) { 256 if ( err == MAILIMAP_NO_ERROR ) {
253 mailimap_msg_att * msg_att; 257 mailimap_msg_att * msg_att;
254 int i = 0; 258 int i = 0;
255 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 259 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
256 ++i; 260 ++i;
257 msg_att = (mailimap_msg_att*)current->data; 261 msg_att = (mailimap_msg_att*)current->data;
258 RecMail*m = parse_list_result(msg_att); 262 RecMail*m = parse_list_result(msg_att);
259 if (m) { 263 if (m) {
260 m->setNumber(i); 264 m->setNumber(i);
261 m->setMbox(mailbox); 265 m->setMbox(mailbox);
262 m->setWrapper(this); 266 m->setWrapper(this);
263 target.append(m); 267 target.append(m);
264 } 268 }
265 } 269 }
266 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); 270 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count()));
267 } else { 271 } else {
268 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); 272 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
269 } 273 }
270 if (result) mailimap_fetch_list_free(result); 274 if (result) mailimap_fetch_list_free(result);
271} 275}
272 276
273QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() 277QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders()
274{ 278{
275 const char *path, *mask; 279 const char *path, *mask;
276 int err = MAILIMAP_NO_ERROR; 280 int err = MAILIMAP_NO_ERROR;
277 clist *result = 0; 281 clist *result = 0;
278 clistcell *current = 0; 282 clistcell *current = 0;
279 clistcell*cur_flag = 0; 283 clistcell*cur_flag = 0;
280 mailimap_mbx_list_flags*bflags = 0; 284 mailimap_mbx_list_flags*bflags = 0;
281 285
282 QValueList<FolderP>* folders = new QValueList<FolderP>(); 286 QValueList<FolderP>* folders = new QValueList<FolderP>();
283 login(); 287 login();
284 if (!m_imap) { 288 if (!m_imap) {
285 return folders; 289 return folders;
286 } 290 }
287 291
288/* 292/*
289 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 293 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
290 * We must not forget to filter them out in next loop! 294 * We must not forget to filter them out in next loop!
291 * it seems like ugly code. and yes - it is ugly code. but the best way. 295 * it seems like ugly code. and yes - it is ugly code. but the best way.
292 */ 296 */
293 QString temp; 297 QString temp;
@@ -330,203 +334,209 @@ QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders()
330 if (!path) path = ""; 334 if (!path) path = "";
331 odebug << path << oendl; 335 odebug << path << oendl;
332 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 336 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
333 if ( err == MAILIMAP_NO_ERROR ) { 337 if ( err == MAILIMAP_NO_ERROR ) {
334 current = result->first; 338 current = result->first;
335 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 339 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
336 no_inferiors = false; 340 no_inferiors = false;
337 list = (mailimap_mailbox_list *) current->data; 341 list = (mailimap_mailbox_list *) current->data;
338 // it is better use the deep copy mechanism of qt itself 342 // it is better use the deep copy mechanism of qt itself
339 // instead of using strdup! 343 // instead of using strdup!
340 temp = list->mb_name; 344 temp = list->mb_name;
341 if (temp.lower()=="inbox") 345 if (temp.lower()=="inbox")
342 continue; 346 continue;
343 if (temp.lower()==account->getPrefix().lower()) 347 if (temp.lower()==account->getPrefix().lower())
344 continue; 348 continue;
345 if ( (bflags = list->mb_flag) ) { 349 if ( (bflags = list->mb_flag) ) {
346 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 350 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
347 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 351 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
348 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 352 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
349 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 353 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
350 no_inferiors = true; 354 no_inferiors = true;
351 } 355 }
352 } 356 }
353 } 357 }
354 del = list->mb_delimiter; 358 del = list->mb_delimiter;
355 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 359 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
356 } 360 }
357 } else { 361 } else {
358 odebug << "error fetching folders " << m_imap->imap_response << "" << oendl; 362 odebug << "error fetching folders " << m_imap->imap_response << "" << oendl;
359 } 363 }
360 if (result) mailimap_list_result_free( result ); 364 if (result) mailimap_list_result_free( result );
361 return folders; 365 return folders;
362} 366}
363 367
364RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 368RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
365{ 369{
366 RecMail * m = 0; 370 RecMail * m = 0;
367 mailimap_msg_att_item *item=0; 371 mailimap_msg_att_item *item=0;
368 clistcell *current,*c,*cf; 372 clistcell *current,*c,*cf;
369 mailimap_msg_att_dynamic*flist; 373 mailimap_msg_att_dynamic*flist;
370 mailimap_flag_fetch*cflag; 374 mailimap_flag_fetch*cflag;
371 int size; 375 int size;
372 QBitArray mFlags(7); 376 QBitArray mFlags(7);
373 QStringList addresslist; 377 QStringList addresslist;
374 378
375 if (!m_att) { 379 if (!m_att) {
376 return m; 380 return m;
377 } 381 }
382 size = 0;
378 m = new RecMail(); 383 m = new RecMail();
379 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 384 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
380 current = c; 385 current = c;
381 size = 0;
382 item = (mailimap_msg_att_item*)current->data; 386 item = (mailimap_msg_att_item*)current->data;
383 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 387 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
384 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 388 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
385 if (!flist->att_list) { 389 if (!flist->att_list) {
386 continue; 390 continue;
387 } 391 }
388 cf = flist->att_list->first; 392 cf = flist->att_list->first;
389 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 393 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
390 cflag = (mailimap_flag_fetch*)cf->data; 394 cflag = (mailimap_flag_fetch*)cf->data;
391 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 395 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
392 switch (cflag->fl_flag->fl_type) { 396 switch (cflag->fl_flag->fl_type) {
393 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 397 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
394 mFlags.setBit(FLAG_ANSWERED); 398 mFlags.setBit(FLAG_ANSWERED);
395 break; 399 break;
396 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 400 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
397 mFlags.setBit(FLAG_FLAGGED); 401 mFlags.setBit(FLAG_FLAGGED);
398 break; 402 break;
399 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 403 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
400 mFlags.setBit(FLAG_DELETED); 404 mFlags.setBit(FLAG_DELETED);
401 break; 405 break;
402 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 406 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
403 mFlags.setBit(FLAG_SEEN); 407 mFlags.setBit(FLAG_SEEN);
404 break; 408 break;
405 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 409 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
406 mFlags.setBit(FLAG_DRAFT); 410 mFlags.setBit(FLAG_DRAFT);
407 break; 411 break;
408 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 412 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
409 break; 413 break;
410 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 414 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
411 break; 415 break;
412 default: 416 default:
413 break; 417 break;
414 } 418 }
415 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 419 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
416 mFlags.setBit(FLAG_RECENT); 420 mFlags.setBit(FLAG_RECENT);
417 } 421 }
418 } 422 }
419 continue; 423 continue;
420 } 424 }
421 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 425 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
422 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 426 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
423 m->setDate(head->env_date); 427 m->setDate(head->env_date);
424 m->setSubject(convert_String((const char*)head->env_subject)); 428 m->setSubject(convert_String((const char*)head->env_subject));
425 //m->setSubject(head->env_subject); 429 //m->setSubject(head->env_subject);
426 if (head->env_from!=NULL) { 430 if (head->env_from!=NULL) {
427 addresslist = address_list_to_stringlist(head->env_from->frm_list); 431 addresslist = address_list_to_stringlist(head->env_from->frm_list);
428 if (addresslist.count()) { 432 if (addresslist.count()) {
429 m->setFrom(addresslist.first()); 433 m->setFrom(addresslist.first());
430 } 434 }
431 } 435 }
432 if (head->env_to!=NULL) { 436 if (head->env_to!=NULL) {
433 addresslist = address_list_to_stringlist(head->env_to->to_list); 437 addresslist = address_list_to_stringlist(head->env_to->to_list);
434 m->setTo(addresslist); 438 m->setTo(addresslist);
435 } 439 }
436 if (head->env_cc!=NULL) { 440 if (head->env_cc!=NULL) {
437 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 441 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
438 m->setCC(addresslist); 442 m->setCC(addresslist);
439 } 443 }
440 if (head->env_bcc!=NULL) { 444 if (head->env_bcc!=NULL) {
441 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 445 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
442 m->setBcc(addresslist); 446 m->setBcc(addresslist);
443 } 447 }
444 /* reply to address, eg. email. */ 448 /* reply to address, eg. email. */
445 if (head->env_reply_to!=NULL) { 449 if (head->env_reply_to!=NULL) {
446 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 450 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
447 if (addresslist.count()) { 451 if (addresslist.count()) {
448 m->setReplyto(addresslist.first()); 452 m->setReplyto(addresslist.first());
449 } 453 }
450 } 454 }
451 if (head->env_in_reply_to!=NULL) { 455 if (head->env_in_reply_to!=NULL) {
452 QString h(head->env_in_reply_to); 456 QString h(head->env_in_reply_to);
453 while (h.length()>0 && h[0]=='<') { 457 while (h.length()>0 && h[0]=='<') {
454 h.remove(0,1); 458 h.remove(0,1);
455 } 459 }
456 while (h.length()>0 && h[h.length()-1]=='>') { 460 while (h.length()>0 && h[h.length()-1]=='>') {
457 h.remove(h.length()-1,1); 461 h.remove(h.length()-1,1);
458 } 462 }
459 if (h.length()>0) { 463 if (h.length()>0) {
460 m->setInreply(QStringList(h)); 464 m->setInreply(QStringList(h));
461 } 465 }
462 } 466 }
463 if (head->env_message_id) { 467 if (head->env_message_id) {
464 m->setMsgid(QString(head->env_message_id)); 468 m->setMsgid(QString(head->env_message_id));
465 } 469 }
466 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 470 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
467#if 0 471#if 0
468 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 472 mailimap_date_time*date = item->att_data.att_static->att_data.att_internal_date;
473 if (date->dt_sec>60 || date->dt_sec<0) date->dt_sec=0;
474 //QDateTime da(QDate(d->dt_year,date->dt_month,date->dt_day),QTime(date->dt_hour,date->dt_min,date->dt_sec));
475 QString timestring = TimeString::numberDateString(QDate(date->dt_year,date->dt_month,date->dt_day))+" ";
476 timestring+=TimeString::timeString(QTime(date->dt_hour,date->dt_min,date->dt_sec))+" ";
477 timestring.sprintf(timestring+" %+05i",date->dt_zone);
478 m->setDate(timestring);
469 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 479 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
470 odebug << "" << d->dt_year << " " << d->dt_month << " " << d->dt_day << " - " << d->dt_hour << " " << d->dt_min << " " << d->dt_sec << "" << oendl; 480 odebug << "" << d->dt_year << " " << d->dt_month << " " << d->dt_day << " - " << d->dt_hour << " " << d->dt_min << " " << d->dt_sec << "" << oendl;
471 odebug << da.toString() << oendl; 481 odebug << da.toString() << oendl;
472#endif 482#endif
473 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 483 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
474 size = item->att_data.att_static->att_data.att_rfc822_size; 484 //size = item->att_data.att_static->att_data.att_rfc822_size;
485 m->setMsgsize(item->att_data.att_static->att_data.att_rfc822_size);
475 } 486 }
476 } 487 }
477 /* msg is already deleted */ 488 /* msg is already deleted */
478 if (mFlags.testBit(FLAG_DELETED) && m) { 489 if (mFlags.testBit(FLAG_DELETED) && m) {
479 delete m; 490 delete m;
480 m = 0; 491 m = 0;
481 } 492 }
482 if (m) { 493 if (m) {
483 m->setFlags(mFlags); 494 m->setFlags(mFlags);
484 m->setMsgsize(size);
485 } 495 }
486 return m; 496 return m;
487} 497}
488 498
489RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) 499RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail)
490{ 500{
491 RecBodyP body = new RecBody(); 501 RecBodyP body = new RecBody();
492 const char *mb; 502 const char *mb;
493 int err = MAILIMAP_NO_ERROR; 503 int err = MAILIMAP_NO_ERROR;
494 clist *result = 0; 504 clist *result = 0;
495 clistcell *current; 505 clistcell *current;
496 mailimap_fetch_att *fetchAtt = 0; 506 mailimap_fetch_att *fetchAtt = 0;
497 mailimap_fetch_type *fetchType = 0; 507 mailimap_fetch_type *fetchType = 0;
498 mailimap_set *set = 0; 508 mailimap_set *set = 0;
499 mailimap_body*body_desc = 0; 509 mailimap_body*body_desc = 0;
500 510
501 mb = mail->getMbox().latin1(); 511 mb = mail->getMbox().latin1();
502 512
503 login(); 513 login();
504 if (!m_imap) { 514 if (!m_imap) {
505 return body; 515 return body;
506 } 516 }
507 err = selectMbox(mail->getMbox()); 517 err = selectMbox(mail->getMbox());
508 if ( err != MAILIMAP_NO_ERROR ) { 518 if ( err != MAILIMAP_NO_ERROR ) {
509 return body; 519 return body;
510 } 520 }
511 521
512 /* the range has to start at 1!!! not with 0!!!! */ 522 /* the range has to start at 1!!! not with 0!!!! */
513 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); 523 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() );
514 fetchAtt = mailimap_fetch_att_new_bodystructure(); 524 fetchAtt = mailimap_fetch_att_new_bodystructure();
515 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 525 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
516 err = mailimap_fetch( m_imap, set, fetchType, &result ); 526 err = mailimap_fetch( m_imap, set, fetchType, &result );
517 mailimap_set_free( set ); 527 mailimap_set_free( set );
518 mailimap_fetch_type_free( fetchType ); 528 mailimap_fetch_type_free( fetchType );
519 529
520 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 530 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
521 mailimap_msg_att * msg_att; 531 mailimap_msg_att * msg_att;
522 msg_att = (mailimap_msg_att*)current->data; 532 msg_att = (mailimap_msg_att*)current->data;
523 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 533 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
524 QValueList<int> path; 534 QValueList<int> path;
525 body_desc = item->att_data.att_static->att_data.att_body; 535 body_desc = item->att_data.att_static->att_data.att_body;
526 traverseBody(mail,body_desc,body,0,path); 536 traverseBody(mail,body_desc,body,0,path);
527 } else { 537 } else {
528 odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; 538 odebug << "error fetching body: " << m_imap->imap_response << "" << oendl;
529 } 539 }
530 if (result) mailimap_fetch_list_free(result); 540 if (result) mailimap_fetch_list_free(result);
531 return body; 541 return body;
532} 542}
diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.cpp b/noncore/net/mail/libmailwrapper/mhwrapper.cpp
index 403afcf..765a21c 100644
--- a/noncore/net/mail/libmailwrapper/mhwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mhwrapper.cpp
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 3cfd1ee..2d66fc9 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -1,97 +1,104 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include "pop3wrapper.h" 2#include "pop3wrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include "logindialog.h" 4#include "logindialog.h"
5#include <libetpan/libetpan.h> 5#include <libetpan/libetpan.h>
6 6
7#include <opie2/odebug.h> 7#include <opie2/odebug.h>
8#include <qpe/global.h> 8#include <qpe/global.h>
9#include <qfile.h> 9#include <qfile.h>
10#include <qmessagebox.h>
10 11
11/* we don't fetch messages larger than 5 MB */ 12/* we don't fetch messages larger than 5 MB */
12#define HARD_MSG_SIZE_LIMIT 5242880 13#define HARD_MSG_SIZE_LIMIT 5242880
13 14
14using namespace Opie::Core; 15using namespace Opie::Core;
15POP3wrapper::POP3wrapper( POP3account *a ) 16POP3wrapper::POP3wrapper( POP3account *a )
16: Genericwrapper() { 17: Genericwrapper() {
17 account = a; 18 account = a;
18 m_pop3 = NULL; 19 m_pop3 = NULL;
19 msgTempName = a->getFileName()+"_msg_cache"; 20 msgTempName = a->getFileName()+"_msg_cache";
20 last_msg_id = 0; 21 last_msg_id = 0;
22 m_maxsize = account->getMaxSize();
23 m_checksize = account->getCheckMaxSize();
21} 24}
22 25
23POP3wrapper::~POP3wrapper() { 26POP3wrapper::~POP3wrapper() {
24 logout(); 27 logout();
25 QFile msg_cache(msgTempName); 28 QFile msg_cache(msgTempName);
26 if (msg_cache.exists()) { 29 if (msg_cache.exists()) {
27 msg_cache.remove(); 30 msg_cache.remove();
28 } 31 }
29} 32}
30 33
31void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { 34void POP3wrapper::pop3_progress( size_t current, size_t maximum ) {
32 odebug << "POP3: " << current << " of " << maximum << "" << oendl; 35 odebug << "POP3: " << current << " of " << maximum << "" << oendl;
33} 36}
34 37
35RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { 38RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) {
36 int err = MAILPOP3_NO_ERROR; 39 int err = MAILPOP3_NO_ERROR;
37 char *message = 0; 40 char *message = 0;
38 size_t length = 0; 41 size_t length = 0;
39 42
40 RecBodyP body = new RecBody(); 43 RecBodyP body = new RecBody();
41 44
42 login(); 45 login();
43 if ( !m_pop3 ) { 46 if ( !m_pop3 ) {
44 return body; 47 return body;
45 } 48 }
46 49
47 mailmessage * mailmsg; 50 mailmessage * mailmsg;
48 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { 51 if (mail->Msgsize()/1024>m_maxsize && m_checksize && mail->getNumber()!=last_msg_id) {
52 QString quest = QString(tr("Download mail?\nIt is %1 kByte but your limit is %2 kByte")).arg(mail->Msgsize()/1024).arg(m_maxsize);
53 int yesno = QMessageBox::warning(0,tr("Download message"),
54 quest,tr("Yes"),tr("No"),QString::null,0,1);
49 odebug << "Message to large: " << mail->Msgsize() << "" << oendl; 55 odebug << "Message to large: " << mail->Msgsize() << "" << oendl;
56 if (yesno==1)
50 return body; 57 return body;
51 } 58 }
52 59
53 QFile msg_cache(msgTempName); 60 QFile msg_cache(msgTempName);
54 61
55 cleanMimeCache(); 62 cleanMimeCache();
56 63
57 if (mail->getNumber()!=last_msg_id) { 64 if (mail->getNumber()!=last_msg_id) {
58 if (msg_cache.exists()) { 65 if (msg_cache.exists()) {
59 msg_cache.remove(); 66 msg_cache.remove();
60 } 67 }
61 msg_cache.open(IO_ReadWrite|IO_Truncate); 68 msg_cache.open(IO_ReadWrite|IO_Truncate);
62 last_msg_id = mail->getNumber(); 69 last_msg_id = mail->getNumber();
63 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); 70 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
64 err = mailmessage_fetch(mailmsg,&message,&length); 71 err = mailmessage_fetch(mailmsg,&message,&length);
65 msg_cache.writeBlock(message,length); 72 msg_cache.writeBlock(message,length);
66 } else { 73 } else {
67 QString msg=""; 74 QString msg="";
68 msg_cache.open(IO_ReadOnly); 75 msg_cache.open(IO_ReadOnly);
69 message = new char[4096]; 76 message = new char[4096];
70 memset(message,0,4096); 77 memset(message,0,4096);
71 while (msg_cache.readBlock(message,4095)>0) { 78 while (msg_cache.readBlock(message,4095)>0) {
72 msg+=message; 79 msg+=message;
73 memset(message,0,4096); 80 memset(message,0,4096);
74 } 81 }
75 delete message; 82 delete message;
76 message = (char*)malloc(msg.length()+1*sizeof(char)); 83 message = (char*)malloc(msg.length()+1*sizeof(char));
77 memset(message,0,msg.length()+1); 84 memset(message,0,msg.length()+1);
78 memcpy(message,msg.latin1(),msg.length()); 85 memcpy(message,msg.latin1(),msg.length());
79 /* transform to libetpan stuff */ 86 /* transform to libetpan stuff */
80 mailmsg = mailmessage_new(); 87 mailmsg = mailmessage_new();
81 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 88 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
82 generic_message_t * msg_data; 89 generic_message_t * msg_data;
83 msg_data = (generic_message_t *)mailmsg->msg_data; 90 msg_data = (generic_message_t *)mailmsg->msg_data;
84 msg_data->msg_fetched = 1; 91 msg_data->msg_fetched = 1;
85 msg_data->msg_message = message; 92 msg_data->msg_message = message;
86 msg_data->msg_length = strlen(message); 93 msg_data->msg_length = strlen(message);
87 } 94 }
88 body = parseMail(mailmsg); 95 body = parseMail(mailmsg);
89 96
90 /* clean up */ 97 /* clean up */
91 if (mailmsg) 98 if (mailmsg)
92 mailmessage_free(mailmsg); 99 mailmessage_free(mailmsg);
93 if (message) 100 if (message)
94 free(message); 101 free(message);
95 102
96 return body; 103 return body;
97} 104}
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h
index 5101fa5..8c36cf9 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.h
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h
@@ -1,42 +1,44 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include "genericwrapper.h" 5#include "genericwrapper.h"
6#include <qstring.h> 6#include <qstring.h>
7 7
8class encodedString; 8class encodedString;
9struct mailstorage; 9struct mailstorage;
10struct mailfolder; 10struct mailfolder;
11 11
12class POP3wrapper : public Genericwrapper 12class POP3wrapper : public Genericwrapper
13{ 13{
14 Q_OBJECT 14 Q_OBJECT
15 15
16public: 16public:
17 POP3wrapper( POP3account *a ); 17 POP3wrapper( POP3account *a );
18 virtual ~POP3wrapper(); 18 virtual ~POP3wrapper();
19 /* mailbox will be ignored */ 19 /* mailbox will be ignored */
20 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ); 20 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target );
21 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 21 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
22 /* mailbox will be ignored */ 22 /* mailbox will be ignored */
23 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 23 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
24 24
25 virtual void deleteMail(const RecMailP&mail); 25 virtual void deleteMail(const RecMailP&mail);
26 virtual void answeredMail(const RecMailP&mail); 26 virtual void answeredMail(const RecMailP&mail);
27 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); 27 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&);
28 28
29 virtual RecBodyP fetchBody( const RecMailP &mail ); 29 virtual RecBodyP fetchBody( const RecMailP &mail );
30 virtual encodedString* fetchRawBody(const RecMailP&mail); 30 virtual encodedString* fetchRawBody(const RecMailP&mail);
31 virtual void logout(); 31 virtual void logout();
32 virtual MAILLIB::ATYPE getType()const; 32 virtual MAILLIB::ATYPE getType()const;
33 virtual const QString&getName()const; 33 virtual const QString&getName()const;
34 static void pop3_progress( size_t current, size_t maximum ); 34 static void pop3_progress( size_t current, size_t maximum );
35 35
36protected: 36protected:
37 void login(); 37 void login();
38 POP3account *account; 38 POP3account *account;
39 mailstorage*m_pop3; 39 mailstorage*m_pop3;
40 int m_maxsize;
41 bool m_checksize;
40}; 42};
41 43
42#endif 44#endif
diff --git a/noncore/net/mail/libmailwrapper/settings.cpp b/noncore/net/mail/libmailwrapper/settings.cpp
index 3c9b25c..09be91b 100644
--- a/noncore/net/mail/libmailwrapper/settings.cpp
+++ b/noncore/net/mail/libmailwrapper/settings.cpp
@@ -1,67 +1,66 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <qdir.h> 2#include <qdir.h>
3 3
4#include <opie2/odebug.h> 4#include <opie2/odebug.h>
5#include <qpe/config.h> 5#include <qpe/config.h>
6 6
7#include "settings.h" 7#include "settings.h"
8//#include "defines.h" 8//#include "defines.h"
9 9
10#define IMAP_PORT "143" 10#define IMAP_PORT "143"
11#define IMAP_SSL_PORT "993" 11#define IMAP_SSL_PORT "993"
12#define SMTP_PORT "25" 12#define SMTP_PORT "25"
13#define SMTP_SSL_PORT "465" 13#define SMTP_SSL_PORT "465"
14#define POP3_PORT "110" 14#define POP3_PORT "110"
15#define POP3_SSL_PORT "995" 15#define POP3_SSL_PORT "995"
16#define NNTP_PORT "119" 16#define NNTP_PORT "119"
17#define NNTP_SSL_PORT "563" 17#define NNTP_SSL_PORT "563"
18 18
19
20Settings::Settings() 19Settings::Settings()
21 : QObject() 20 : QObject()
22{ 21{
23 updateAccounts(); 22 updateAccounts();
24} 23}
25 24
26void Settings::checkDirectory() 25void Settings::checkDirectory()
27{ 26{
28 if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { 27 if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) {
29 system( "mkdir -p $HOME/Applications/opiemail" ); 28 system( "mkdir -p $HOME/Applications/opiemail" );
30 odebug << "$HOME/Applications/opiemail created" << oendl; 29 odebug << "$HOME/Applications/opiemail created" << oendl;
31 } 30 }
32} 31}
33 32
34QList<Account> Settings::getAccounts() 33QList<Account> Settings::getAccounts()
35{ 34{
36 return accounts; 35 return accounts;
37} 36}
38 37
39void Settings::addAccount( Account *account ) 38void Settings::addAccount( Account *account )
40{ 39{
41 accounts.append( account ); 40 accounts.append( account );
42} 41}
43 42
44void Settings::delAccount( Account *account ) 43void Settings::delAccount( Account *account )
45{ 44{
46 accounts.remove( account ); 45 accounts.remove( account );
47 account->remove(); 46 account->remove();
48} 47}
49 48
50void Settings::updateAccounts() 49void Settings::updateAccounts()
51{ 50{
52 accounts.clear(); 51 accounts.clear();
53 QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); 52 QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" );
54 QStringList::Iterator it; 53 QStringList::Iterator it;
55 54
56 QStringList imap = dir.entryList( "imap-*" ); 55 QStringList imap = dir.entryList( "imap-*" );
57 for ( it = imap.begin(); it != imap.end(); it++ ) { 56 for ( it = imap.begin(); it != imap.end(); it++ ) {
58 odebug << "Added IMAP account" << oendl; 57 odebug << "Added IMAP account" << oendl;
59 IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); 58 IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") );
60 accounts.append( account ); 59 accounts.append( account );
61 } 60 }
62 61
63 QStringList pop3 = dir.entryList( "pop3-*" ); 62 QStringList pop3 = dir.entryList( "pop3-*" );
64 for ( it = pop3.begin(); it != pop3.end(); it++ ) { 63 for ( it = pop3.begin(); it != pop3.end(); it++ ) {
65 odebug << "Added POP account" << oendl; 64 odebug << "Added POP account" << oendl;
66 POP3account *account = new POP3account( (*it).replace(0, 5, "") ); 65 POP3account *account = new POP3account( (*it).replace(0, 5, "") );
67 accounts.append( account ); 66 accounts.append( account );
@@ -168,164 +167,192 @@ void IMAPaccount::read()
168 if (port.isNull()) port="143"; 167 if (port.isNull()) port="143";
169 connectionType = conf->readNumEntry( "ConnectionType" ); 168 connectionType = conf->readNumEntry( "ConnectionType" );
170 ssl = conf->readBoolEntry( "SSL",false ); 169 ssl = conf->readBoolEntry( "SSL",false );
171 user = conf->readEntry( "User","" ); 170 user = conf->readEntry( "User","" );
172 if (user.isNull()) user = ""; 171 if (user.isNull()) user = "";
173 password = conf->readEntryCrypt( "Password","" ); 172 password = conf->readEntryCrypt( "Password","" );
174 if (password.isNull()) password = ""; 173 if (password.isNull()) password = "";
175 prefix = conf->readEntry("MailPrefix",""); 174 prefix = conf->readEntry("MailPrefix","");
176 if (prefix.isNull()) prefix = ""; 175 if (prefix.isNull()) prefix = "";
177 offline = conf->readBoolEntry("Offline",false); 176 offline = conf->readBoolEntry("Offline",false);
178 delete conf; 177 delete conf;
179} 178}
180 179
181void IMAPaccount::save() 180void IMAPaccount::save()
182{ 181{
183 odebug << "saving " + getFileName() << oendl; 182 odebug << "saving " + getFileName() << oendl;
184 Settings::checkDirectory(); 183 Settings::checkDirectory();
185 184
186 Config *conf = new Config( getFileName(), Config::File ); 185 Config *conf = new Config( getFileName(), Config::File );
187 conf->setGroup( "IMAP Account" ); 186 conf->setGroup( "IMAP Account" );
188 conf->writeEntry( "Account", accountName ); 187 conf->writeEntry( "Account", accountName );
189 conf->writeEntry( "Server", server ); 188 conf->writeEntry( "Server", server );
190 conf->writeEntry( "Port", port ); 189 conf->writeEntry( "Port", port );
191 conf->writeEntry( "SSL", ssl ); 190 conf->writeEntry( "SSL", ssl );
192 conf->writeEntry( "ConnectionType", connectionType ); 191 conf->writeEntry( "ConnectionType", connectionType );
193 conf->writeEntry( "User", user ); 192 conf->writeEntry( "User", user );
194 conf->writeEntryCrypt( "Password", password ); 193 conf->writeEntryCrypt( "Password", password );
195 conf->writeEntry( "MailPrefix",prefix); 194 conf->writeEntry( "MailPrefix",prefix);
196 conf->writeEntry( "Offline",offline); 195 conf->writeEntry( "Offline",offline);
197 conf->write(); 196 conf->write();
198 delete conf; 197 delete conf;
199} 198}
200 199
201 200
202QString IMAPaccount::getFileName() 201QString IMAPaccount::getFileName()
203{ 202{
204 return (QString) getenv( "HOME" ) + "/Applications/opiemail/imap-" + file; 203 return (QString) getenv( "HOME" ) + "/Applications/opiemail/imap-" + file;
205} 204}
206 205
207POP3account::POP3account() 206POP3account::POP3account()
208 : Account() 207 : Account()
209{ 208{
210 file = POP3account::getUniqueFileName(); 209 file = POP3account::getUniqueFileName();
211 accountName = "New POP3 Account"; 210 accountName = "New POP3 Account";
212 ssl = false; 211 ssl = false;
213 connectionType = 1; 212 connectionType = 1;
214 type = MAILLIB::A_POP3; 213 type = MAILLIB::A_POP3;
215 port = POP3_PORT; 214 port = POP3_PORT;
215 m_CheckSize = true;
216 m_MaxSize = 1024;
216} 217}
217 218
218POP3account::POP3account( QString filename ) 219POP3account::POP3account( QString filename )
219 : Account() 220 : Account()
220{ 221{
221 file = filename; 222 file = filename;
222 accountName = "New POP3 Account"; 223 accountName = "New POP3 Account";
223 ssl = false; 224 ssl = false;
224 connectionType = 1; 225 connectionType = 1;
225 type = MAILLIB::A_POP3; 226 type = MAILLIB::A_POP3;
226 port = POP3_PORT; 227 port = POP3_PORT;
228 m_CheckSize = true;
229 m_MaxSize = 1024;
227} 230}
228 231
229QString POP3account::getUniqueFileName() 232QString POP3account::getUniqueFileName()
230{ 233{
231 int num = 0; 234 int num = 0;
232 QString unique; 235 QString unique;
233 236
234 QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); 237 QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" );
235 238
236 QStringList imap = dir.entryList( "pop3-*" ); 239 QStringList imap = dir.entryList( "pop3-*" );
237 do { 240 do {
238 unique.setNum( num++ ); 241 unique.setNum( num++ );
239 } while ( imap.contains( "pop3-" + unique ) > 0 ); 242 } while ( imap.contains( "pop3-" + unique ) > 0 );
240 243
241 return unique; 244 return unique;
242} 245}
243 246
244void POP3account::read() 247void POP3account::read()
245{ 248{
246 Config *conf = new Config( getFileName(), Config::File ); 249 Config *conf = new Config( getFileName(), Config::File );
247 conf->setGroup( "POP3 Account" ); 250 conf->setGroup( "POP3 Account" );
248 accountName = conf->readEntry( "Account" ); 251 accountName = conf->readEntry( "Account" );
249 server = conf->readEntry( "Server" ); 252 server = conf->readEntry( "Server" );
250 port = conf->readEntry( "Port" ); 253 port = conf->readEntry( "Port" );
251 ssl = conf->readBoolEntry( "SSL" ); 254 ssl = conf->readBoolEntry( "SSL" );
252 connectionType = conf->readNumEntry( "ConnectionType" ); 255 connectionType = conf->readNumEntry( "ConnectionType" );
253 user = conf->readEntry( "User" ); 256 user = conf->readEntry( "User" );
254 password = conf->readEntryCrypt( "Password" ); 257 password = conf->readEntryCrypt( "Password" );
255 offline = conf->readBoolEntry("Offline",false); 258 offline = conf->readBoolEntry("Offline",false);
259 m_CheckSize = conf->readBoolEntry("Checkmaxsize",true);
260 m_MaxSize = conf->readNumEntry("Maxsize",1024);
256 delete conf; 261 delete conf;
257} 262}
258 263
259void POP3account::save() 264void POP3account::save()
260{ 265{
261 odebug << "saving " + getFileName() << oendl; 266 odebug << "saving " + getFileName() << oendl;
262 Settings::checkDirectory(); 267 Settings::checkDirectory();
263 268
264 Config *conf = new Config( getFileName(), Config::File ); 269 Config *conf = new Config( getFileName(), Config::File );
265 conf->setGroup( "POP3 Account" ); 270 conf->setGroup( "POP3 Account" );
266 conf->writeEntry( "Account", accountName ); 271 conf->writeEntry( "Account", accountName );
267 conf->writeEntry( "Server", server ); 272 conf->writeEntry( "Server", server );
268 conf->writeEntry( "Port", port ); 273 conf->writeEntry( "Port", port );
269 conf->writeEntry( "SSL", ssl ); 274 conf->writeEntry( "SSL", ssl );
270 conf->writeEntry( "ConnectionType", connectionType ); 275 conf->writeEntry( "ConnectionType", connectionType );
271 conf->writeEntry( "User", user ); 276 conf->writeEntry( "User", user );
272 conf->writeEntryCrypt( "Password", password ); 277 conf->writeEntryCrypt( "Password", password );
273 conf->writeEntry( "Offline",offline); 278 conf->writeEntry( "Offline",offline);
279 conf->writeEntry("Checkmaxsize",m_CheckSize);
280 conf->writeEntry("Maxsize",m_MaxSize);
274 conf->write(); 281 conf->write();
275 delete conf; 282 delete conf;
276} 283}
277 284
278 285
279QString POP3account::getFileName() 286QString POP3account::getFileName()
280{ 287{
281 return (QString) getenv( "HOME" ) + "/Applications/opiemail/pop3-" + file; 288 return (QString) getenv( "HOME" ) + "/Applications/opiemail/pop3-" + file;
282} 289}
283 290
291bool POP3account::getCheckMaxSize()const
292{
293 return m_CheckSize;
294}
295
296void POP3account::setCheckMaxSize(bool aValue)
297{
298 m_CheckSize = aValue;
299}
300
301int POP3account::getMaxSize()const
302{
303 return m_MaxSize;
304}
305
306void POP3account::setMaxSize(int aValue)
307{
308 m_MaxSize = aValue;
309}
310
284SMTPaccount::SMTPaccount() 311SMTPaccount::SMTPaccount()
285 : Account() 312 : Account()
286{ 313{
287 file = SMTPaccount::getUniqueFileName(); 314 file = SMTPaccount::getUniqueFileName();
288 accountName = "New SMTP Account"; 315 accountName = "New SMTP Account";
289 ssl = false; 316 ssl = false;
290 connectionType = 1; 317 connectionType = 1;
291 login = false; 318 login = false;
292 useCC = false; 319 useCC = false;
293 useBCC = false; 320 useBCC = false;
294 useReply = false; 321 useReply = false;
295 type = MAILLIB::A_SMTP; 322 type = MAILLIB::A_SMTP;
296 port = SMTP_PORT; 323 port = SMTP_PORT;
297} 324}
298 325
299SMTPaccount::SMTPaccount( QString filename ) 326SMTPaccount::SMTPaccount( QString filename )
300 : Account() 327 : Account()
301{ 328{
302 file = filename; 329 file = filename;
303 accountName = "New SMTP Account"; 330 accountName = "New SMTP Account";
304 ssl = false; 331 ssl = false;
305 connectionType = 1; 332 connectionType = 1;
306 login = false; 333 login = false;
307 type = MAILLIB::A_SMTP; 334 type = MAILLIB::A_SMTP;
308 port = SMTP_PORT; 335 port = SMTP_PORT;
309} 336}
310 337
311QString SMTPaccount::getUniqueFileName() 338QString SMTPaccount::getUniqueFileName()
312{ 339{
313 int num = 0; 340 int num = 0;
314 QString unique; 341 QString unique;
315 342
316 QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); 343 QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" );
317 344
318 QStringList imap = dir.entryList( "smtp-*" ); 345 QStringList imap = dir.entryList( "smtp-*" );
319 do { 346 do {
320 unique.setNum( num++ ); 347 unique.setNum( num++ );
321 } while ( imap.contains( "smtp-" + unique ) > 0 ); 348 } while ( imap.contains( "smtp-" + unique ) > 0 );
322 349
323 return unique; 350 return unique;
324} 351}
325 352
326void SMTPaccount::read() 353void SMTPaccount::read()
327{ 354{
328 Config *conf = new Config( getFileName(), Config::File ); 355 Config *conf = new Config( getFileName(), Config::File );
329 conf->setGroup( "SMTP Account" ); 356 conf->setGroup( "SMTP Account" );
330 accountName = conf->readEntry( "Account" ); 357 accountName = conf->readEntry( "Account" );
331 server = conf->readEntry( "Server" ); 358 server = conf->readEntry( "Server" );
diff --git a/noncore/net/mail/libmailwrapper/settings.h b/noncore/net/mail/libmailwrapper/settings.h
index bf27b97..8683a05 100644
--- a/noncore/net/mail/libmailwrapper/settings.h
+++ b/noncore/net/mail/libmailwrapper/settings.h
@@ -44,100 +44,105 @@ public:
44 void setOffline(bool b) {offline = b;} 44 void setOffline(bool b) {offline = b;}
45 bool getOffline()const{return offline;} 45 bool getOffline()const{return offline;}
46 46
47 virtual QString getFileName() { return accountName; } 47 virtual QString getFileName() { return accountName; }
48 virtual void read() { odebug << "base reading..." << oendl; } 48 virtual void read() { odebug << "base reading..." << oendl; }
49 virtual void save() { odebug << "base saving..." << oendl; } 49 virtual void save() { odebug << "base saving..." << oendl; }
50 50
51protected: 51protected:
52 QString accountName, server, port, user, password; 52 QString accountName, server, port, user, password;
53 bool ssl; 53 bool ssl;
54 int connectionType; 54 int connectionType;
55 bool offline; 55 bool offline;
56 MAILLIB::ATYPE type; 56 MAILLIB::ATYPE type;
57}; 57};
58 58
59class IMAPaccount : public Account 59class IMAPaccount : public Account
60{ 60{
61 61
62public: 62public:
63 IMAPaccount(); 63 IMAPaccount();
64 IMAPaccount( QString filename ); 64 IMAPaccount( QString filename );
65 65
66 static QString getUniqueFileName(); 66 static QString getUniqueFileName();
67 67
68 virtual void read(); 68 virtual void read();
69 virtual void save(); 69 virtual void save();
70 virtual QString getFileName(); 70 virtual QString getFileName();
71 71
72 void setPrefix(const QString&str) {prefix=str;} 72 void setPrefix(const QString&str) {prefix=str;}
73 const QString&getPrefix()const{return prefix;} 73 const QString&getPrefix()const{return prefix;}
74 74
75private: 75private:
76 QString file,prefix; 76 QString file,prefix;
77 77
78}; 78};
79 79
80class POP3account : public Account 80class POP3account : public Account
81{ 81{
82 82
83public: 83public:
84 POP3account(); 84 POP3account();
85 POP3account( QString filename ); 85 POP3account( QString filename );
86 86
87 static QString getUniqueFileName(); 87 static QString getUniqueFileName();
88 88
89 virtual void read(); 89 virtual void read();
90 virtual void save(); 90 virtual void save();
91 virtual QString getFileName(); 91 virtual QString getFileName();
92 virtual bool getCheckMaxSize()const;
93 virtual void setCheckMaxSize(bool);
94 virtual int getMaxSize()const;
95 virtual void setMaxSize(int);
92 96
93private: 97private:
94 QString file; 98 QString file;
95 99 bool m_CheckSize;
100 int m_MaxSize;
96}; 101};
97 102
98class SMTPaccount : public Account 103class SMTPaccount : public Account
99{ 104{
100 105
101public: 106public:
102 SMTPaccount(); 107 SMTPaccount();
103 SMTPaccount( QString filename ); 108 SMTPaccount( QString filename );
104 109
105 static QString getUniqueFileName(); 110 static QString getUniqueFileName();
106 111
107 virtual void read(); 112 virtual void read();
108 virtual void save(); 113 virtual void save();
109 virtual QString getFileName(); 114 virtual QString getFileName();
110 115
111 void setLogin( bool b ) { login = b; } 116 void setLogin( bool b ) { login = b; }
112 bool getLogin() { return login; } 117 bool getLogin() { return login; }
113 118
114private: 119private:
115 QString file, name, mail, org, cc, bcc, reply, signature; 120 QString file, name, mail, org, cc, bcc, reply, signature;
116 bool useCC, useBCC, useReply, login; 121 bool useCC, useBCC, useReply, login;
117 122
118}; 123};
119 124
120class NNTPaccount : public Account 125class NNTPaccount : public Account
121{ 126{
122 127
123public: 128public:
124 NNTPaccount(); 129 NNTPaccount();
125 NNTPaccount( QString filename ); 130 NNTPaccount( QString filename );
126 131
127 static QString getUniqueFileName(); 132 static QString getUniqueFileName();
128 133
129 virtual void read(); 134 virtual void read();
130 virtual void save(); 135 virtual void save();
131 virtual QString getFileName(); 136 virtual QString getFileName();
132 137
133 void setLogin( bool b ) { login = b; } 138 void setLogin( bool b ) { login = b; }
134 bool getLogin() { return login; } 139 bool getLogin() { return login; }
135 140
136 void setGroups( QStringList list ) { subscribedGroups = list; } 141 void setGroups( QStringList list ) { subscribedGroups = list; }
137 QStringList getGroups() { return subscribedGroups; } 142 QStringList getGroups() { return subscribedGroups; }
138 143
139private: 144private:
140 QString file; 145 QString file;
141 bool login; 146 bool login;
142 QStringList subscribedGroups; 147 QStringList subscribedGroups;
143 148