-rw-r--r-- | kmicromail/libmailwrapper/settings.cpp | 46 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/settings.h | 6 |
2 files changed, 51 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,19 +1,23 @@ | |||
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 | ||
@@ -353,76 +357,116 @@ SMTPaccount::SMTPaccount() | |||
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(); |
diff --git a/kmicromail/libmailwrapper/settings.h b/kmicromail/libmailwrapper/settings.h index c996fe0..a6e95fe 100644 --- a/kmicromail/libmailwrapper/settings.h +++ b/kmicromail/libmailwrapper/settings.h | |||
@@ -114,32 +114,38 @@ private: | |||
114 | class SMTPaccount : public Account | 114 | class SMTPaccount : public Account |
115 | { | 115 | { |
116 | 116 | ||
117 | public: | 117 | public: |
118 | SMTPaccount(); | 118 | SMTPaccount(); |
119 | SMTPaccount( QString filename ); | 119 | SMTPaccount( QString filename ); |
120 | 120 | ||
121 | static QString getUniqueFileName(); | 121 | static QString getUniqueFileName(); |
122 | 122 | ||
123 | virtual void read(); | 123 | virtual void read(); |
124 | virtual void save(); | 124 | virtual void save(); |
125 | virtual QString getFileName(); | 125 | virtual QString getFileName(); |
126 | 126 | ||
127 | void setLogin( bool b ) { login = b; } | 127 | void setLogin( bool b ) { login = b; } |
128 | bool getLogin() { return login; } | 128 | bool getLogin() { return login; } |
129 | 129 | ||
130 | void setSigFile( QString b ) { signature = b; } | ||
131 | QString getSigFile() { return signature; } | ||
132 | |||
133 | QString getSignature(); | ||
134 | void setSignature( QString b ); | ||
135 | |||
130 | private: | 136 | private: |
131 | QString file, name, mail, org, cc, bcc, reply, signature; | 137 | QString file, name, mail, org, cc, bcc, reply, signature; |
132 | bool useCC, useBCC, useReply, login; | 138 | bool useCC, useBCC, useReply, login; |
133 | 139 | ||
134 | }; | 140 | }; |
135 | 141 | ||
136 | class NNTPaccount : public Account | 142 | class NNTPaccount : public Account |
137 | { | 143 | { |
138 | 144 | ||
139 | public: | 145 | public: |
140 | NNTPaccount(); | 146 | NNTPaccount(); |
141 | NNTPaccount( QString filename ); | 147 | NNTPaccount( QString filename ); |
142 | 148 | ||
143 | static QString getUniqueFileName(); | 149 | static QString getUniqueFileName(); |
144 | 150 | ||
145 | virtual void read(); | 151 | virtual void read(); |