Diffstat (limited to 'kmicromail/libmailwrapper/settings.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/settings.cpp | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/kmicromail/libmailwrapper/settings.cpp b/kmicromail/libmailwrapper/settings.cpp index 19093b1..8f909f9 100644 --- a/kmicromail/libmailwrapper/settings.cpp +++ b/kmicromail/libmailwrapper/settings.cpp | |||
@@ -1,51 +1,55 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <qdir.h> | 2 | #include <qdir.h> |
3 | 3 | ||
4 | #include <qtextcodec.h> | ||
5 | #include <qtextstream.h> | ||
6 | #include <qfile.h> | ||
7 | |||
4 | //#include <opie2/odebug.h> | 8 | //#include <opie2/odebug.h> |
5 | #include <kconfig.h> | 9 | #include <kconfig.h> |
6 | 10 | ||
7 | #include <kstandarddirs.h> | 11 | #include <kstandarddirs.h> |
8 | #include "settings.h" | 12 | #include "settings.h" |
9 | //#include "defines.h" | 13 | //#include "defines.h" |
10 | 14 | ||
11 | #define IMAP_PORT "143" | 15 | #define IMAP_PORT "143" |
12 | #define IMAP_SSL_PORT "993" | 16 | #define IMAP_SSL_PORT "993" |
13 | #define SMTP_PORT "25" | 17 | #define SMTP_PORT "25" |
14 | #define SMTP_SSL_PORT "465" | 18 | #define SMTP_SSL_PORT "465" |
15 | #define POP3_PORT "110" | 19 | #define POP3_PORT "110" |
16 | #define POP3_SSL_PORT "995" | 20 | #define POP3_SSL_PORT "995" |
17 | #define NNTP_PORT "119" | 21 | #define NNTP_PORT "119" |
18 | #define NNTP_SSL_PORT "563" | 22 | #define NNTP_SSL_PORT "563" |
19 | 23 | ||
20 | 24 | ||
21 | Settings::Settings() | 25 | Settings::Settings() |
22 | : QObject() | 26 | : QObject() |
23 | { | 27 | { |
24 | accounts.setAutoDelete( true ); ; | 28 | accounts.setAutoDelete( true ); ; |
25 | updateAccounts(); | 29 | updateAccounts(); |
26 | //qDebug("++++++++++++++++++new settings "); | 30 | //qDebug("++++++++++++++++++new settings "); |
27 | } | 31 | } |
28 | 32 | ||
29 | void Settings::checkDirectory() | 33 | void Settings::checkDirectory() |
30 | { | 34 | { |
31 | return; | 35 | return; |
32 | locateLocal("data", "kopiemail" ); | 36 | locateLocal("data", "kopiemail" ); |
33 | /* | 37 | /* |
34 | if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { | 38 | if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { |
35 | system( "mkdir -p $HOME/Applications/opiemail" ); | 39 | system( "mkdir -p $HOME/Applications/opiemail" ); |
36 | qDebug("$HOME/Applications/opiemail created "); | 40 | qDebug("$HOME/Applications/opiemail created "); |
37 | } | 41 | } |
38 | */ | 42 | */ |
39 | } | 43 | } |
40 | 44 | ||
41 | QList<Account> Settings::getAccounts() | 45 | QList<Account> Settings::getAccounts() |
42 | { | 46 | { |
43 | return accounts; | 47 | return accounts; |
44 | } | 48 | } |
45 | 49 | ||
46 | void Settings::addAccount( Account *account ) | 50 | void Settings::addAccount( Account *account ) |
47 | { | 51 | { |
48 | accounts.append( account ); | 52 | accounts.append( account ); |
49 | } | 53 | } |
50 | 54 | ||
51 | void Settings::delAccount( Account *account ) | 55 | void Settings::delAccount( Account *account ) |
@@ -321,140 +325,180 @@ void POP3account::save() | |||
321 | conf->writeEntry( "ConnectionType", connectionType ); | 325 | conf->writeEntry( "ConnectionType", connectionType ); |
322 | conf->writeEntry( "User", user ); | 326 | conf->writeEntry( "User", user ); |
323 | //conf->writeEntryCrypt( "Password", password ); | 327 | //conf->writeEntryCrypt( "Password", password ); |
324 | conf->writeEntry( "FolderHistory",getPasswordList() ); | 328 | conf->writeEntry( "FolderHistory",getPasswordList() ); |
325 | conf->writeEntry( "Offline",offline); | 329 | conf->writeEntry( "Offline",offline); |
326 | conf->writeEntry( "LocalFolder", localFolder ); | 330 | conf->writeEntry( "LocalFolder", localFolder ); |
327 | conf->writeEntry( "MaxSize", maxMailSize ); | 331 | conf->writeEntry( "MaxSize", maxMailSize ); |
328 | QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); | 332 | QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); |
329 | int lf = dt.secsTo ( lastFetch ); | 333 | int lf = dt.secsTo ( lastFetch ); |
330 | conf->writeEntry( "LastFetch", lf ); | 334 | conf->writeEntry( "LastFetch", lf ); |
331 | conf->writeEntry( "LeaveOnServer", leaveOnServer); | 335 | conf->writeEntry( "LeaveOnServer", leaveOnServer); |
332 | conf->sync(); | 336 | conf->sync(); |
333 | delete conf; | 337 | delete conf; |
334 | } | 338 | } |
335 | 339 | ||
336 | 340 | ||
337 | QString POP3account::getFileName() | 341 | QString POP3account::getFileName() |
338 | { | 342 | { |
339 | return locateLocal("data", "kopiemail" ) +"/pop3-" + file; | 343 | return locateLocal("data", "kopiemail" ) +"/pop3-" + file; |
340 | } | 344 | } |
341 | 345 | ||
342 | SMTPaccount::SMTPaccount() | 346 | SMTPaccount::SMTPaccount() |
343 | : Account() | 347 | : Account() |
344 | { | 348 | { |
345 | file = SMTPaccount::getUniqueFileName(); | 349 | file = SMTPaccount::getUniqueFileName(); |
346 | accountName = "New SMTP Account"; | 350 | accountName = "New SMTP Account"; |
347 | ssl = false; | 351 | ssl = false; |
348 | connectionType = 1; | 352 | connectionType = 1; |
349 | login = false; | 353 | login = false; |
350 | useCC = false; | 354 | useCC = false; |
351 | useBCC = false; | 355 | useBCC = false; |
352 | useReply = false; | 356 | useReply = false; |
353 | type = MAILLIB::A_SMTP; | 357 | type = MAILLIB::A_SMTP; |
354 | port = SMTP_PORT; | 358 | port = SMTP_PORT; |
355 | } | 359 | } |
356 | 360 | ||
357 | SMTPaccount::SMTPaccount( QString filename ) | 361 | SMTPaccount::SMTPaccount( QString filename ) |
358 | : Account() | 362 | : Account() |
359 | { | 363 | { |
360 | file = filename; | 364 | file = filename; |
361 | accountName = "New SMTP Account"; | 365 | accountName = "New SMTP Account"; |
362 | ssl = false; | 366 | ssl = false; |
363 | connectionType = 1; | 367 | connectionType = 1; |
364 | login = false; | 368 | login = false; |
365 | type = MAILLIB::A_SMTP; | 369 | type = MAILLIB::A_SMTP; |
366 | port = SMTP_PORT; | 370 | port = SMTP_PORT; |
367 | } | 371 | } |
368 | 372 | ||
373 | QString SMTPaccount::getSignature() | ||
374 | { | ||
375 | QFileInfo fi ( signature ); | ||
376 | if ( ! fi.exists() ) | ||
377 | return QString(); | ||
378 | |||
379 | QFile file( signature ); | ||
380 | if (!file.open( IO_ReadOnly ) ) { | ||
381 | return QString(); | ||
382 | |||
383 | } | ||
384 | QTextStream ts( &file ); | ||
385 | ts.setCodec( QTextCodec::codecForName("utf8") ); | ||
386 | QString text = ts.read(); | ||
387 | file.close(); | ||
388 | |||
389 | return text; | ||
390 | |||
391 | } | ||
392 | void SMTPaccount::setSignature( QString b ) | ||
393 | { | ||
394 | |||
395 | QFileInfo fi ( signature ); | ||
396 | if ( ! fi.exists() ) { | ||
397 | QString filedir( locateLocal("data", "kopiemail" ) ); | ||
398 | signature = filedir+ "/" + getAccountName() +".sig"; | ||
399 | qDebug("new sig %s ", signature.latin1()); | ||
400 | save(); | ||
401 | } | ||
402 | QFile fileIn( signature ); | ||
403 | if (!fileIn.open( IO_WriteOnly ) ) { | ||
404 | qDebug("OM: Cannot write signature file %s ", signature.latin1() ); | ||
405 | return ; | ||
406 | } | ||
407 | QTextStream tsIn( &fileIn ); | ||
408 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | ||
409 | tsIn << b ; | ||
410 | fileIn.close(); | ||
411 | } | ||
369 | QString SMTPaccount::getUniqueFileName() | 412 | QString SMTPaccount::getUniqueFileName() |
370 | { | 413 | { |
371 | int num = 0; | 414 | int num = 0; |
372 | QString unique; | 415 | QString unique; |
373 | 416 | ||
374 | QDir dir( locateLocal("data", "kopiemail" ) ); | 417 | QDir dir( locateLocal("data", "kopiemail" ) ); |
375 | 418 | ||
376 | QStringList imap = dir.entryList( "smtp-*" ); | 419 | QStringList imap = dir.entryList( "smtp-*" ); |
377 | do { | 420 | do { |
378 | unique.setNum( num++ ); | 421 | unique.setNum( num++ ); |
379 | } while ( imap.contains( "smtp-" + unique ) > 0 ); | 422 | } while ( imap.contains( "smtp-" + unique ) > 0 ); |
380 | 423 | ||
381 | return unique; | 424 | return unique; |
382 | } | 425 | } |
383 | 426 | ||
384 | void SMTPaccount::read() | 427 | void SMTPaccount::read() |
385 | { | 428 | { |
386 | KConfig *conf = new KConfig( getFileName() ); | 429 | KConfig *conf = new KConfig( getFileName() ); |
387 | conf->setGroup( "SMTP Account" ); | 430 | conf->setGroup( "SMTP Account" ); |
388 | accountName = conf->readEntry( "Account" ); | 431 | accountName = conf->readEntry( "Account" ); |
389 | server = conf->readEntry( "Server" ); | 432 | server = conf->readEntry( "Server" ); |
390 | port = conf->readEntry( "Port" ); | 433 | port = conf->readEntry( "Port" ); |
391 | ssl = conf->readBoolEntry( "SSL" ); | 434 | ssl = conf->readBoolEntry( "SSL" ); |
392 | connectionType = conf->readNumEntry( "ConnectionType" ); | 435 | connectionType = conf->readNumEntry( "ConnectionType" ); |
393 | login = conf->readBoolEntry( "Login" ); | 436 | login = conf->readBoolEntry( "Login" ); |
394 | user = conf->readEntry( "User" ); | 437 | user = conf->readEntry( "User" ); |
395 | //password = conf->readEntryCrypt( "Password" ); | 438 | signature = conf->readEntry( "SigFile" ); |
396 | setPasswordList( conf->readListEntry( "FolderHistory")); | 439 | setPasswordList( conf->readListEntry( "FolderHistory")); |
397 | delete conf; | 440 | delete conf; |
398 | } | 441 | } |
399 | 442 | ||
400 | void SMTPaccount::save() | 443 | void SMTPaccount::save() |
401 | { | 444 | { |
402 | Settings::checkDirectory(); | 445 | Settings::checkDirectory(); |
403 | 446 | ||
404 | KConfig *conf = new KConfig( getFileName() ); | 447 | KConfig *conf = new KConfig( getFileName() ); |
405 | conf->setGroup( "SMTP Account" ); | 448 | conf->setGroup( "SMTP Account" ); |
406 | conf->writeEntry( "Account", accountName ); | 449 | conf->writeEntry( "Account", accountName ); |
407 | conf->writeEntry( "Server", server ); | 450 | conf->writeEntry( "Server", server ); |
408 | conf->writeEntry( "Port", port ); | 451 | conf->writeEntry( "Port", port ); |
409 | conf->writeEntry( "SSL", ssl ); | 452 | conf->writeEntry( "SSL", ssl ); |
410 | conf->writeEntry( "ConnectionType", connectionType ); | 453 | conf->writeEntry( "ConnectionType", connectionType ); |
411 | conf->writeEntry( "Login", login ); | 454 | conf->writeEntry( "Login", login ); |
412 | conf->writeEntry( "User", user ); | 455 | conf->writeEntry( "User", user ); |
456 | conf->writeEntry( "SigFile", signature ); | ||
413 | //conf->writeEntryCrypt( "Password", password ); | 457 | //conf->writeEntryCrypt( "Password", password ); |
414 | conf->writeEntry( "FolderHistory",getPasswordList() ); | 458 | conf->writeEntry( "FolderHistory",getPasswordList() ); |
415 | conf->sync(); | 459 | conf->sync(); |
416 | delete conf; | 460 | delete conf; |
417 | } | 461 | } |
418 | 462 | ||
419 | 463 | ||
420 | QString SMTPaccount::getFileName() | 464 | QString SMTPaccount::getFileName() |
421 | { | 465 | { |
422 | return locateLocal("data", "kopiemail" ) +"/smtp-" + file; | 466 | return locateLocal("data", "kopiemail" ) +"/smtp-" + file; |
423 | } | 467 | } |
424 | 468 | ||
425 | NNTPaccount::NNTPaccount() | 469 | NNTPaccount::NNTPaccount() |
426 | : Account() | 470 | : Account() |
427 | { | 471 | { |
428 | file = NNTPaccount::getUniqueFileName(); | 472 | file = NNTPaccount::getUniqueFileName(); |
429 | accountName = "New NNTP Account"; | 473 | accountName = "New NNTP Account"; |
430 | ssl = false; | 474 | ssl = false; |
431 | login = false; | 475 | login = false; |
432 | type = MAILLIB::A_NNTP; | 476 | type = MAILLIB::A_NNTP; |
433 | port = NNTP_PORT; | 477 | port = NNTP_PORT; |
434 | } | 478 | } |
435 | 479 | ||
436 | NNTPaccount::NNTPaccount( QString filename ) | 480 | NNTPaccount::NNTPaccount( QString filename ) |
437 | : Account() | 481 | : Account() |
438 | { | 482 | { |
439 | file = filename; | 483 | file = filename; |
440 | accountName = "New NNTP Account"; | 484 | accountName = "New NNTP Account"; |
441 | ssl = false; | 485 | ssl = false; |
442 | login = false; | 486 | login = false; |
443 | type = MAILLIB::A_NNTP; | 487 | type = MAILLIB::A_NNTP; |
444 | port = NNTP_PORT; | 488 | port = NNTP_PORT; |
445 | } | 489 | } |
446 | 490 | ||
447 | QString NNTPaccount::getUniqueFileName() | 491 | QString NNTPaccount::getUniqueFileName() |
448 | { | 492 | { |
449 | int num = 0; | 493 | int num = 0; |
450 | QString unique; | 494 | QString unique; |
451 | 495 | ||
452 | QDir dir( locateLocal("data", "kopiemail" ) ); | 496 | QDir dir( locateLocal("data", "kopiemail" ) ); |
453 | 497 | ||
454 | QStringList imap = dir.entryList( "nntp-*" ); | 498 | QStringList imap = dir.entryList( "nntp-*" ); |
455 | do { | 499 | do { |
456 | unique.setNum( num++ ); | 500 | unique.setNum( num++ ); |
457 | } while ( imap.contains( "nntp-" + unique ) > 0 ); | 501 | } while ( imap.contains( "nntp-" + unique ) > 0 ); |
458 | 502 | ||
459 | return unique; | 503 | return unique; |
460 | } | 504 | } |