Diffstat (limited to 'kmicromail/libmailwrapper/settings.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/settings.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/kmicromail/libmailwrapper/settings.cpp b/kmicromail/libmailwrapper/settings.cpp index 9436d43..fc01528 100644 --- a/kmicromail/libmailwrapper/settings.cpp +++ b/kmicromail/libmailwrapper/settings.cpp | |||
@@ -1,544 +1,544 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <qdir.h> | 2 | #include <qdir.h> |
3 | 3 | ||
4 | #include <qtextcodec.h> | 4 | #include <qtextcodec.h> |
5 | #include <qtextstream.h> | 5 | #include <q3textstream.h> |
6 | #include <qfile.h> | 6 | #include <qfile.h> |
7 | 7 | ||
8 | //#include <opie2/odebug.h> | 8 | //#include <opie2/odebug.h> |
9 | #include <kconfig.h> | 9 | #include <kconfig.h> |
10 | 10 | ||
11 | #include <kstandarddirs.h> | 11 | #include <kstandarddirs.h> |
12 | #include "settings.h" | 12 | #include "settings.h" |
13 | //#include "defines.h" | 13 | //#include "defines.h" |
14 | 14 | ||
15 | #define IMAP_PORT "143" | 15 | #define IMAP_PORT "143" |
16 | #define IMAP_SSL_PORT "993" | 16 | #define IMAP_SSL_PORT "993" |
17 | #define SMTP_PORT "25" | 17 | #define SMTP_PORT "25" |
18 | #define SMTP_SSL_PORT "465" | 18 | #define SMTP_SSL_PORT "465" |
19 | #define POP3_PORT "110" | 19 | #define POP3_PORT "110" |
20 | #define POP3_SSL_PORT "995" | 20 | #define POP3_SSL_PORT "995" |
21 | #define NNTP_PORT "119" | 21 | #define NNTP_PORT "119" |
22 | #define NNTP_SSL_PORT "563" | 22 | #define NNTP_SSL_PORT "563" |
23 | 23 | ||
24 | 24 | ||
25 | Settings::Settings() | 25 | Settings::Settings() |
26 | : QObject() | 26 | : QObject() |
27 | { | 27 | { |
28 | accounts.setAutoDelete( true ); ; | 28 | accounts.setAutoDelete( true ); ; |
29 | updateAccounts(); | 29 | updateAccounts(); |
30 | //qDebug("++++++++++++++++++new settings "); | 30 | //qDebug("++++++++++++++++++new settings "); |
31 | } | 31 | } |
32 | 32 | ||
33 | void Settings::checkDirectory() | 33 | void Settings::checkDirectory() |
34 | { | 34 | { |
35 | return; | 35 | return; |
36 | locateLocal("data", "kopiemail" ); | 36 | locateLocal("data", "kopiemail" ); |
37 | /* | 37 | /* |
38 | if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { | 38 | if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { |
39 | system( "mkdir -p $HOME/Applications/opiemail" ); | 39 | system( "mkdir -p $HOME/Applications/opiemail" ); |
40 | qDebug("$HOME/Applications/opiemail created "); | 40 | qDebug("$HOME/Applications/opiemail created "); |
41 | } | 41 | } |
42 | */ | 42 | */ |
43 | } | 43 | } |
44 | 44 | ||
45 | QList<Account> Settings::getAccounts() | 45 | QList<Account> Settings::getAccounts() |
46 | { | 46 | { |
47 | return accounts; | 47 | return accounts; |
48 | } | 48 | } |
49 | 49 | ||
50 | void Settings::addAccount( Account *account ) | 50 | void Settings::addAccount( Account *account ) |
51 | { | 51 | { |
52 | accounts.append( account ); | 52 | accounts.append( account ); |
53 | } | 53 | } |
54 | 54 | ||
55 | void Settings::delAccount( Account *account ) | 55 | void Settings::delAccount( Account *account ) |
56 | { | 56 | { |
57 | account->remove(); | 57 | account->remove(); |
58 | accounts.remove( account ); | 58 | accounts.remove( account ); |
59 | } | 59 | } |
60 | 60 | ||
61 | void Settings::updateAccounts() | 61 | void Settings::updateAccounts() |
62 | { | 62 | { |
63 | accounts.clear(); | 63 | accounts.clear(); |
64 | QDir dir( locateLocal("data", "kopiemail" ) ); | 64 | QDir dir( locateLocal("data", "kopiemail" ) ); |
65 | QStringList::Iterator it; | 65 | QStringList::Iterator it; |
66 | 66 | ||
67 | QStringList imap = dir.entryList( "imap-*" ); | 67 | QStringList imap = dir.entryList( "imap-*" ); |
68 | for ( it = imap.begin(); it != imap.end(); it++ ) { | 68 | for ( it = imap.begin(); it != imap.end(); it++ ) { |
69 | IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); | 69 | IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); |
70 | accounts.append( account ); | 70 | accounts.append( account ); |
71 | } | 71 | } |
72 | 72 | ||
73 | QStringList pop3 = dir.entryList( "pop3-*" ); | 73 | QStringList pop3 = dir.entryList( "pop3-*" ); |
74 | for ( it = pop3.begin(); it != pop3.end(); it++ ) { | 74 | for ( it = pop3.begin(); it != pop3.end(); it++ ) { |
75 | POP3account *account = new POP3account( (*it).replace(0, 5, "") ); | 75 | POP3account *account = new POP3account( (*it).replace(0, 5, "") ); |
76 | accounts.append( account ); | 76 | accounts.append( account ); |
77 | } | 77 | } |
78 | 78 | ||
79 | QStringList smtp = dir.entryList( "smtp-*" ); | 79 | QStringList smtp = dir.entryList( "smtp-*" ); |
80 | for ( it = smtp.begin(); it != smtp.end(); it++ ) { | 80 | for ( it = smtp.begin(); it != smtp.end(); it++ ) { |
81 | SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); | 81 | SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); |
82 | accounts.append( account ); | 82 | accounts.append( account ); |
83 | } | 83 | } |
84 | 84 | ||
85 | QStringList nntp = dir.entryList( "nntp-*" ); | 85 | QStringList nntp = dir.entryList( "nntp-*" ); |
86 | for ( it = nntp.begin(); it != nntp.end(); it++ ) { | 86 | for ( it = nntp.begin(); it != nntp.end(); it++ ) { |
87 | NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); | 87 | NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); |
88 | accounts.append( account ); | 88 | accounts.append( account ); |
89 | } | 89 | } |
90 | 90 | ||
91 | readAccounts(); | 91 | readAccounts(); |
92 | } | 92 | } |
93 | 93 | ||
94 | void Settings::saveAccounts() | 94 | void Settings::saveAccounts() |
95 | { | 95 | { |
96 | checkDirectory(); | 96 | checkDirectory(); |
97 | Account *it; | 97 | Account *it; |
98 | 98 | ||
99 | for ( it = accounts.first(); it; it = accounts.next() ) { | 99 | for ( it = accounts.first(); it; it = accounts.next() ) { |
100 | it->save(); | 100 | it->save(); |
101 | } | 101 | } |
102 | } | 102 | } |
103 | 103 | ||
104 | void Settings::readAccounts() | 104 | void Settings::readAccounts() |
105 | { | 105 | { |
106 | checkDirectory(); | 106 | checkDirectory(); |
107 | Account *it; | 107 | Account *it; |
108 | 108 | ||
109 | for ( it = accounts.first(); it; it = accounts.next() ) { | 109 | for ( it = accounts.first(); it; it = accounts.next() ) { |
110 | it->read(); | 110 | it->read(); |
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | Account::Account() | 114 | Account::Account() |
115 | { | 115 | { |
116 | accountName = "changeMe"; | 116 | accountName = "changeMe"; |
117 | type = MAILLIB::A_UNDEFINED; | 117 | type = MAILLIB::A_UNDEFINED; |
118 | ssl = false; | 118 | ssl = false; |
119 | connectionType = 1; | 119 | connectionType = 1; |
120 | offline = false; | 120 | offline = false; |
121 | maxMailSize = 0; | 121 | maxMailSize = 0; |
122 | leaveOnServer = false; | 122 | leaveOnServer = false; |
123 | } | 123 | } |
124 | 124 | ||
125 | void Account::remove() | 125 | void Account::remove() |
126 | { | 126 | { |
127 | QFile file( getFileName() ); | 127 | QFile file( getFileName() ); |
128 | file.remove(); | 128 | file.remove(); |
129 | } | 129 | } |
130 | 130 | ||
131 | void Account::setPasswordList(const QStringList &str) | 131 | void Account::setPasswordList(const QStringList &str) |
132 | { | 132 | { |
133 | password = ""; | 133 | password = ""; |
134 | int i; | 134 | int i; |
135 | for ( i = 0; i < str.count() ; ++i ) { | 135 | for ( i = 0; i < str.count() ; ++i ) { |
136 | QChar c ( (str[i].toUInt()-131)/(str.count()- (i%3))); | 136 | QChar c ( (str[i].toUInt()-131)/(str.count()- (i%3))); |
137 | password.append( c ); | 137 | password.append( c ); |
138 | } | 138 | } |
139 | //qDebug("password %s ", password.latin1()); | 139 | //qDebug("password %s ", password.latin1()); |
140 | } | 140 | } |
141 | QStringList Account::getPasswordList() | 141 | QStringList Account::getPasswordList() |
142 | { | 142 | { |
143 | int i; | 143 | int i; |
144 | int len = password.length(); | 144 | int len = password.length(); |
145 | QStringList str; | 145 | QStringList str; |
146 | 146 | ||
147 | for ( i = 0; i < len ; ++i ) { | 147 | for ( i = 0; i < len ; ++i ) { |
148 | int val = password.at(i).unicode()*(len-(i%3))+131; | 148 | int val = password.at(i).unicode()*(len-(i%3))+131; |
149 | str.append( QString::number( val ) ); | 149 | str.append( QString::number( val ) ); |
150 | // qDebug("append %s ", str[i].latin1()); | 150 | // qDebug("append %s ", str[i].latin1()); |
151 | } | 151 | } |
152 | return str; | 152 | return str; |
153 | } | 153 | } |
154 | 154 | ||
155 | IMAPaccount::IMAPaccount() | 155 | IMAPaccount::IMAPaccount() |
156 | : Account() | 156 | : Account() |
157 | { | 157 | { |
158 | file = IMAPaccount::getUniqueFileName(); | 158 | file = IMAPaccount::getUniqueFileName(); |
159 | accountName = "New IMAP Account"; | 159 | accountName = "New IMAP Account"; |
160 | ssl = false; | 160 | ssl = false; |
161 | connectionType = 1; | 161 | connectionType = 1; |
162 | type = MAILLIB::A_IMAP; | 162 | type = MAILLIB::A_IMAP; |
163 | port = IMAP_PORT; | 163 | port = IMAP_PORT; |
164 | } | 164 | } |
165 | 165 | ||
166 | IMAPaccount::IMAPaccount( QString filename ) | 166 | IMAPaccount::IMAPaccount( QString filename ) |
167 | : Account() | 167 | : Account() |
168 | { | 168 | { |
169 | file = filename; | 169 | file = filename; |
170 | accountName = "New IMAP Account"; | 170 | accountName = "New IMAP Account"; |
171 | ssl = false; | 171 | ssl = false; |
172 | connectionType = 1; | 172 | connectionType = 1; |
173 | type = MAILLIB::A_IMAP; | 173 | type = MAILLIB::A_IMAP; |
174 | port = IMAP_PORT; | 174 | port = IMAP_PORT; |
175 | } | 175 | } |
176 | 176 | ||
177 | QString IMAPaccount::getUniqueFileName() | 177 | QString IMAPaccount::getUniqueFileName() |
178 | { | 178 | { |
179 | int num = 0; | 179 | int num = 0; |
180 | QString unique; | 180 | QString unique; |
181 | 181 | ||
182 | QDir dir( locateLocal("data", "kopiemail" ) ); | 182 | QDir dir( locateLocal("data", "kopiemail" ) ); |
183 | 183 | ||
184 | QStringList imap = dir.entryList( "imap-*" ); | 184 | QStringList imap = dir.entryList( "imap-*" ); |
185 | do { | 185 | do { |
186 | unique.setNum( num++ ); | 186 | unique.setNum( num++ ); |
187 | } while ( imap.contains( "imap-" + unique ) > 0 ); | 187 | } while ( imap.contains( "imap-" + unique ) > 0 ); |
188 | 188 | ||
189 | return unique; | 189 | return unique; |
190 | } | 190 | } |
191 | 191 | ||
192 | void IMAPaccount::read() | 192 | void IMAPaccount::read() |
193 | { | 193 | { |
194 | KConfig *conf = new KConfig( getFileName() ); | 194 | KConfig *conf = new KConfig( getFileName() ); |
195 | conf->setGroup( "IMAP Account" ); | 195 | conf->setGroup( "IMAP Account" ); |
196 | accountName = conf->readEntry( "Account","" ); | 196 | accountName = conf->readEntry( "Account","" ); |
197 | if (accountName.isNull()) accountName = ""; | 197 | if (accountName.isNull()) accountName = ""; |
198 | server = conf->readEntry( "Server","" ); | 198 | server = conf->readEntry( "Server","" ); |
199 | if (server.isNull()) server=""; | 199 | if (server.isNull()) server=""; |
200 | port = conf->readEntry( "Port","" ); | 200 | port = conf->readEntry( "Port","" ); |
201 | if (port.isNull()) port="143"; | 201 | if (port.isNull()) port="143"; |
202 | connectionType = conf->readNumEntry( "ConnectionType" ); | 202 | connectionType = conf->readNumEntry( "ConnectionType" ); |
203 | ssl = conf->readBoolEntry( "SSL",false ); | 203 | ssl = conf->readBoolEntry( "SSL",false ); |
204 | user = conf->readEntry( "User","" ); | 204 | user = conf->readEntry( "User","" ); |
205 | if (user.isNull()) user = ""; | 205 | if (user.isNull()) user = ""; |
206 | //password = conf->readEntryCrypt( "Password","" ); | 206 | //password = conf->readEntryCrypt( "Password","" ); |
207 | setPasswordList( conf->readListEntry( "FolderHistory")); | 207 | setPasswordList( conf->readListEntry( "FolderHistory")); |
208 | if (password.isNull()) password = ""; | 208 | if (password.isNull()) password = ""; |
209 | prefix = conf->readEntry("MailPrefix",""); | 209 | prefix = conf->readEntry("MailPrefix",""); |
210 | if (prefix.isNull()) prefix = ""; | 210 | if (prefix.isNull()) prefix = ""; |
211 | offline = conf->readBoolEntry("Offline",false); | 211 | offline = conf->readBoolEntry("Offline",false); |
212 | localFolder = conf->readEntry( "LocalFolder" ); | 212 | localFolder = conf->readEntry( "LocalFolder" ); |
213 | maxMailSize = conf->readNumEntry( "MaxSize",0 ); | 213 | maxMailSize = conf->readNumEntry( "MaxSize",0 ); |
214 | int lf = conf->readNumEntry( "LastFetch",0 ); | 214 | int lf = conf->readNumEntry( "LastFetch",0 ); |
215 | QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); | 215 | QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); |
216 | leaveOnServer = conf->readBoolEntry("LeaveOnServer",false); | 216 | leaveOnServer = conf->readBoolEntry("LeaveOnServer",false); |
217 | if ( lf < 0 ) lf = 0; | 217 | if ( lf < 0 ) lf = 0; |
218 | lastFetch = dt.addSecs( lf ); | 218 | lastFetch = dt.addSecs( lf ); |
219 | delete conf; | 219 | delete conf; |
220 | } | 220 | } |
221 | 221 | ||
222 | void IMAPaccount::save() | 222 | void IMAPaccount::save() |
223 | { | 223 | { |
224 | 224 | ||
225 | Settings::checkDirectory(); | 225 | Settings::checkDirectory(); |
226 | 226 | ||
227 | KConfig *conf = new KConfig( getFileName() ); | 227 | KConfig *conf = new KConfig( getFileName() ); |
228 | conf->setGroup( "IMAP Account" ); | 228 | conf->setGroup( "IMAP Account" ); |
229 | conf->writeEntry( "Account", accountName ); | 229 | conf->writeEntry( "Account", accountName ); |
230 | conf->writeEntry( "Server", server ); | 230 | conf->writeEntry( "Server", server ); |
231 | conf->writeEntry( "Port", port ); | 231 | conf->writeEntry( "Port", port ); |
232 | conf->writeEntry( "SSL", ssl ); | 232 | conf->writeEntry( "SSL", ssl ); |
233 | conf->writeEntry( "ConnectionType", connectionType ); | 233 | conf->writeEntry( "ConnectionType", connectionType ); |
234 | conf->writeEntry( "User", user ); | 234 | conf->writeEntry( "User", user ); |
235 | //conf->writeEntryCrypt( "Password", password ); | 235 | //conf->writeEntryCrypt( "Password", password ); |
236 | conf->writeEntry( "FolderHistory",getPasswordList() ); | 236 | conf->writeEntry( "FolderHistory",getPasswordList() ); |
237 | conf->writeEntry( "MailPrefix",prefix); | 237 | conf->writeEntry( "MailPrefix",prefix); |
238 | conf->writeEntry( "Offline",offline); | 238 | conf->writeEntry( "Offline",offline); |
239 | conf->writeEntry( "LocalFolder", localFolder ); | 239 | conf->writeEntry( "LocalFolder", localFolder ); |
240 | conf->writeEntry( "MaxSize", maxMailSize ); | 240 | conf->writeEntry( "MaxSize", maxMailSize ); |
241 | QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); | 241 | QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); |
242 | int lf = dt.secsTo ( lastFetch ); | 242 | int lf = dt.secsTo ( lastFetch ); |
243 | conf->writeEntry( "LastFetch", lf ); | 243 | conf->writeEntry( "LastFetch", lf ); |
244 | conf->writeEntry( "LeaveOnServer", leaveOnServer); | 244 | conf->writeEntry( "LeaveOnServer", leaveOnServer); |
245 | conf->sync(); | 245 | conf->sync(); |
246 | delete conf; | 246 | delete conf; |
247 | } | 247 | } |
248 | 248 | ||
249 | 249 | ||
250 | QString IMAPaccount::getFileName() | 250 | QString IMAPaccount::getFileName() |
251 | { | 251 | { |
252 | return locateLocal("data", "kopiemail" ) +"/imap-" + file; | 252 | return locateLocal("data", "kopiemail" ) +"/imap-" + file; |
253 | } | 253 | } |
254 | 254 | ||
255 | POP3account::POP3account() | 255 | POP3account::POP3account() |
256 | : Account() | 256 | : Account() |
257 | { | 257 | { |
258 | file = POP3account::getUniqueFileName(); | 258 | file = POP3account::getUniqueFileName(); |
259 | accountName = "New POP3 Account"; | 259 | accountName = "New POP3 Account"; |
260 | ssl = false; | 260 | ssl = false; |
261 | connectionType = 1; | 261 | connectionType = 1; |
262 | type = MAILLIB::A_POP3; | 262 | type = MAILLIB::A_POP3; |
263 | port = POP3_PORT; | 263 | port = POP3_PORT; |
264 | } | 264 | } |
265 | 265 | ||
266 | POP3account::POP3account( QString filename ) | 266 | POP3account::POP3account( QString filename ) |
267 | : Account() | 267 | : Account() |
268 | { | 268 | { |
269 | file = filename; | 269 | file = filename; |
270 | accountName = "New POP3 Account"; | 270 | accountName = "New POP3 Account"; |
271 | ssl = false; | 271 | ssl = false; |
272 | connectionType = 1; | 272 | connectionType = 1; |
273 | type = MAILLIB::A_POP3; | 273 | type = MAILLIB::A_POP3; |
274 | port = POP3_PORT; | 274 | port = POP3_PORT; |
275 | } | 275 | } |
276 | 276 | ||
277 | QString POP3account::getUniqueFileName() | 277 | QString POP3account::getUniqueFileName() |
278 | { | 278 | { |
279 | int num = 0; | 279 | int num = 0; |
280 | QString unique; | 280 | QString unique; |
281 | 281 | ||
282 | QDir dir( locateLocal("data", "kopiemail" ) ); | 282 | QDir dir( locateLocal("data", "kopiemail" ) ); |
283 | 283 | ||
284 | QStringList imap = dir.entryList( "pop3-*" ); | 284 | QStringList imap = dir.entryList( "pop3-*" ); |
285 | do { | 285 | do { |
286 | unique.setNum( num++ ); | 286 | unique.setNum( num++ ); |
287 | } while ( imap.contains( "pop3-" + unique ) > 0 ); | 287 | } while ( imap.contains( "pop3-" + unique ) > 0 ); |
288 | 288 | ||
289 | return unique; | 289 | return unique; |
290 | } | 290 | } |
291 | 291 | ||
292 | void POP3account::read() | 292 | void POP3account::read() |
293 | { | 293 | { |
294 | KConfig *conf = new KConfig( getFileName()); | 294 | KConfig *conf = new KConfig( getFileName()); |
295 | conf->setGroup( "POP3 Account" ); | 295 | conf->setGroup( "POP3 Account" ); |
296 | accountName = conf->readEntry( "Account" ); | 296 | accountName = conf->readEntry( "Account" ); |
297 | server = conf->readEntry( "Server" ); | 297 | server = conf->readEntry( "Server" ); |
298 | port = conf->readEntry( "Port" ); | 298 | port = conf->readEntry( "Port" ); |
299 | ssl = conf->readBoolEntry( "SSL" ); | 299 | ssl = conf->readBoolEntry( "SSL" ); |
300 | connectionType = conf->readNumEntry( "ConnectionType" ); | 300 | connectionType = conf->readNumEntry( "ConnectionType" ); |
301 | user = conf->readEntry( "User" ); | 301 | user = conf->readEntry( "User" ); |
302 | //password = conf->readEntryCrypt( "Password" ); | 302 | //password = conf->readEntryCrypt( "Password" ); |
303 | setPasswordList( conf->readListEntry( "FolderHistory")); | 303 | setPasswordList( conf->readListEntry( "FolderHistory")); |
304 | offline = conf->readBoolEntry("Offline",false); | 304 | offline = conf->readBoolEntry("Offline",false); |
305 | localFolder = conf->readEntry( "LocalFolder" ); | 305 | localFolder = conf->readEntry( "LocalFolder" ); |
306 | maxMailSize = conf->readNumEntry( "MaxSize",0 ); | 306 | maxMailSize = conf->readNumEntry( "MaxSize",0 ); |
307 | int lf = conf->readNumEntry( "LastFetch",0 ); | 307 | int lf = conf->readNumEntry( "LastFetch",0 ); |
308 | QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); | 308 | QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); |
309 | leaveOnServer = conf->readBoolEntry("LeaveOnServer",false); | 309 | leaveOnServer = conf->readBoolEntry("LeaveOnServer",false); |
310 | lastFetch = dt.addSecs( lf ); | 310 | lastFetch = dt.addSecs( lf ); |
311 | delete conf; | 311 | delete conf; |
312 | } | 312 | } |
313 | 313 | ||
314 | void POP3account::save() | 314 | void POP3account::save() |
315 | { | 315 | { |
316 | Settings::checkDirectory(); | 316 | Settings::checkDirectory(); |
317 | 317 | ||
318 | KConfig *conf = new KConfig( getFileName() ); | 318 | KConfig *conf = new KConfig( getFileName() ); |
319 | conf->setGroup( "POP3 Account" ); | 319 | conf->setGroup( "POP3 Account" ); |
320 | conf->writeEntry( "Account", accountName ); | 320 | conf->writeEntry( "Account", accountName ); |
321 | conf->writeEntry( "Server", server ); | 321 | conf->writeEntry( "Server", server ); |
322 | conf->writeEntry( "Port", port ); | 322 | conf->writeEntry( "Port", port ); |
323 | conf->writeEntry( "SSL", ssl ); | 323 | conf->writeEntry( "SSL", ssl ); |
324 | conf->writeEntry( "ConnectionType", connectionType ); | 324 | conf->writeEntry( "ConnectionType", connectionType ); |
325 | conf->writeEntry( "User", user ); | 325 | conf->writeEntry( "User", user ); |
326 | //conf->writeEntryCrypt( "Password", password ); | 326 | //conf->writeEntryCrypt( "Password", password ); |
327 | conf->writeEntry( "FolderHistory",getPasswordList() ); | 327 | conf->writeEntry( "FolderHistory",getPasswordList() ); |
328 | conf->writeEntry( "Offline",offline); | 328 | conf->writeEntry( "Offline",offline); |
329 | conf->writeEntry( "LocalFolder", localFolder ); | 329 | conf->writeEntry( "LocalFolder", localFolder ); |
330 | conf->writeEntry( "MaxSize", maxMailSize ); | 330 | conf->writeEntry( "MaxSize", maxMailSize ); |
331 | QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); | 331 | QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); |
332 | int lf = dt.secsTo ( lastFetch ); | 332 | int lf = dt.secsTo ( lastFetch ); |
333 | conf->writeEntry( "LastFetch", lf ); | 333 | conf->writeEntry( "LastFetch", lf ); |
334 | conf->writeEntry( "LeaveOnServer", leaveOnServer); | 334 | conf->writeEntry( "LeaveOnServer", leaveOnServer); |
335 | conf->sync(); | 335 | conf->sync(); |
336 | delete conf; | 336 | delete conf; |
337 | } | 337 | } |
338 | 338 | ||
339 | 339 | ||
340 | QString POP3account::getFileName() | 340 | QString POP3account::getFileName() |
341 | { | 341 | { |
342 | return locateLocal("data", "kopiemail" ) +"/pop3-" + file; | 342 | return locateLocal("data", "kopiemail" ) +"/pop3-" + file; |
343 | } | 343 | } |
344 | 344 | ||
345 | SMTPaccount::SMTPaccount() | 345 | SMTPaccount::SMTPaccount() |
346 | : Account() | 346 | : Account() |
347 | { | 347 | { |
348 | file = SMTPaccount::getUniqueFileName(); | 348 | file = SMTPaccount::getUniqueFileName(); |
349 | accountName = "New SMTP Account"; | 349 | accountName = "New SMTP Account"; |
350 | ssl = false; | 350 | ssl = false; |
351 | connectionType = 1; | 351 | connectionType = 1; |
352 | login = false; | 352 | login = false; |
353 | useCC = false; | 353 | useCC = false; |
354 | useBCC = false; | 354 | useBCC = false; |
355 | useReply = false; | 355 | useReply = false; |
356 | type = MAILLIB::A_SMTP; | 356 | type = MAILLIB::A_SMTP; |
357 | port = SMTP_PORT; | 357 | port = SMTP_PORT; |
358 | } | 358 | } |
359 | 359 | ||
360 | SMTPaccount::SMTPaccount( QString filename ) | 360 | SMTPaccount::SMTPaccount( QString filename ) |
361 | : Account() | 361 | : Account() |
362 | { | 362 | { |
363 | file = filename; | 363 | file = filename; |
364 | accountName = "New SMTP Account"; | 364 | accountName = "New SMTP Account"; |
365 | ssl = false; | 365 | ssl = false; |
366 | connectionType = 1; | 366 | connectionType = 1; |
367 | login = false; | 367 | login = false; |
368 | type = MAILLIB::A_SMTP; | 368 | type = MAILLIB::A_SMTP; |
369 | port = SMTP_PORT; | 369 | port = SMTP_PORT; |
370 | } | 370 | } |
371 | 371 | ||
372 | QString SMTPaccount::getSignature() | 372 | QString SMTPaccount::getSignature() |
373 | { | 373 | { |
374 | QFileInfo fi ( signature ); | 374 | QFileInfo fi ( signature ); |
375 | if ( ! fi.exists() ) | 375 | if ( ! fi.exists() ) |
376 | return QString(); | 376 | return QString(); |
377 | 377 | ||
378 | QFile file( signature ); | 378 | QFile file( signature ); |
379 | if (!file.open( IO_ReadOnly ) ) { | 379 | if (!file.open( QIODevice::ReadOnly ) ) { |
380 | return QString(); | 380 | return QString(); |
381 | 381 | ||
382 | } | 382 | } |
383 | QTextStream ts( &file ); | 383 | Q3TextStream ts( &file ); |
384 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 384 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
385 | QString text = ts.read(); | 385 | QString text = ts.read(); |
386 | file.close(); | 386 | file.close(); |
387 | 387 | ||
388 | return text; | 388 | return text; |
389 | 389 | ||
390 | } | 390 | } |
391 | void SMTPaccount::setSignature( QString b ) | 391 | void SMTPaccount::setSignature( QString b ) |
392 | { | 392 | { |
393 | 393 | ||
394 | QFileInfo fi ( signature ); | 394 | QFileInfo fi ( signature ); |
395 | if ( ! fi.exists() ) { | 395 | if ( ! fi.exists() ) { |
396 | QString filedir( locateLocal("data", "kopiemail" ) ); | 396 | QString filedir( locateLocal("data", "kopiemail" ) ); |
397 | signature = filedir+ "/" + getAccountName() +".sig"; | 397 | signature = filedir+ "/" + getAccountName() +".sig"; |
398 | qDebug("new sig %s ", signature.latin1()); | 398 | qDebug("new sig %s ", signature.latin1()); |
399 | save(); | 399 | save(); |
400 | } | 400 | } |
401 | QFile fileIn( signature ); | 401 | QFile fileIn( signature ); |
402 | if (!fileIn.open( IO_WriteOnly ) ) { | 402 | if (!fileIn.open( QIODevice::WriteOnly ) ) { |
403 | qDebug("OM: Cannot write signature file %s ", signature.latin1() ); | 403 | qDebug("OM: Cannot write signature file %s ", signature.latin1() ); |
404 | return ; | 404 | return ; |
405 | } | 405 | } |
406 | QTextStream tsIn( &fileIn ); | 406 | Q3TextStream tsIn( &fileIn ); |
407 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | 407 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); |
408 | tsIn << b ; | 408 | tsIn << b ; |
409 | fileIn.close(); | 409 | fileIn.close(); |
410 | } | 410 | } |
411 | QString SMTPaccount::getUniqueFileName() | 411 | QString SMTPaccount::getUniqueFileName() |
412 | { | 412 | { |
413 | int num = 0; | 413 | int num = 0; |
414 | QString unique; | 414 | QString unique; |
415 | 415 | ||
416 | QDir dir( locateLocal("data", "kopiemail" ) ); | 416 | QDir dir( locateLocal("data", "kopiemail" ) ); |
417 | 417 | ||
418 | QStringList imap = dir.entryList( "smtp-*" ); | 418 | QStringList imap = dir.entryList( "smtp-*" ); |
419 | do { | 419 | do { |
420 | unique.setNum( num++ ); | 420 | unique.setNum( num++ ); |
421 | } while ( imap.contains( "smtp-" + unique ) > 0 ); | 421 | } while ( imap.contains( "smtp-" + unique ) > 0 ); |
422 | 422 | ||
423 | return unique; | 423 | return unique; |
424 | } | 424 | } |
425 | 425 | ||
426 | void SMTPaccount::read() | 426 | void SMTPaccount::read() |
427 | { | 427 | { |
428 | KConfig *conf = new KConfig( getFileName() ); | 428 | KConfig *conf = new KConfig( getFileName() ); |
429 | conf->setGroup( "SMTP Account" ); | 429 | conf->setGroup( "SMTP Account" ); |
430 | accountName = conf->readEntry( "Account" ); | 430 | accountName = conf->readEntry( "Account" ); |
431 | server = conf->readEntry( "Server" ); | 431 | server = conf->readEntry( "Server" ); |
432 | port = conf->readEntry( "Port" ); | 432 | port = conf->readEntry( "Port" ); |
433 | ssl = conf->readBoolEntry( "SSL" ); | 433 | ssl = conf->readBoolEntry( "SSL" ); |
434 | connectionType = conf->readNumEntry( "ConnectionType" ); | 434 | connectionType = conf->readNumEntry( "ConnectionType" ); |
435 | login = conf->readBoolEntry( "Login" ); | 435 | login = conf->readBoolEntry( "Login" ); |
436 | user = conf->readEntry( "User" ); | 436 | user = conf->readEntry( "User" ); |
437 | signature = conf->readEntry( "SigFile" ); | 437 | signature = conf->readEntry( "SigFile" ); |
438 | setPasswordList( conf->readListEntry( "FolderHistory")); | 438 | setPasswordList( conf->readListEntry( "FolderHistory")); |
439 | delete conf; | 439 | delete conf; |
440 | } | 440 | } |
441 | 441 | ||
442 | void SMTPaccount::save() | 442 | void SMTPaccount::save() |
443 | { | 443 | { |
444 | Settings::checkDirectory(); | 444 | Settings::checkDirectory(); |
445 | 445 | ||
446 | KConfig *conf = new KConfig( getFileName() ); | 446 | KConfig *conf = new KConfig( getFileName() ); |
447 | conf->setGroup( "SMTP Account" ); | 447 | conf->setGroup( "SMTP Account" ); |
448 | conf->writeEntry( "Account", accountName ); | 448 | conf->writeEntry( "Account", accountName ); |
449 | conf->writeEntry( "Server", server ); | 449 | conf->writeEntry( "Server", server ); |
450 | conf->writeEntry( "Port", port ); | 450 | conf->writeEntry( "Port", port ); |
451 | conf->writeEntry( "SSL", ssl ); | 451 | conf->writeEntry( "SSL", ssl ); |
452 | conf->writeEntry( "ConnectionType", connectionType ); | 452 | conf->writeEntry( "ConnectionType", connectionType ); |
453 | conf->writeEntry( "Login", login ); | 453 | conf->writeEntry( "Login", login ); |
454 | conf->writeEntry( "User", user ); | 454 | conf->writeEntry( "User", user ); |
455 | conf->writeEntry( "SigFile", signature ); | 455 | conf->writeEntry( "SigFile", signature ); |
456 | //conf->writeEntryCrypt( "Password", password ); | 456 | //conf->writeEntryCrypt( "Password", password ); |
457 | conf->writeEntry( "FolderHistory",getPasswordList() ); | 457 | conf->writeEntry( "FolderHistory",getPasswordList() ); |
458 | conf->sync(); | 458 | conf->sync(); |
459 | delete conf; | 459 | delete conf; |
460 | } | 460 | } |
461 | 461 | ||
462 | 462 | ||
463 | QString SMTPaccount::getFileName() | 463 | QString SMTPaccount::getFileName() |
464 | { | 464 | { |
465 | return locateLocal("data", "kopiemail" ) +"/smtp-" + file; | 465 | return locateLocal("data", "kopiemail" ) +"/smtp-" + file; |
466 | } | 466 | } |
467 | 467 | ||
468 | NNTPaccount::NNTPaccount() | 468 | NNTPaccount::NNTPaccount() |
469 | : Account() | 469 | : Account() |
470 | { | 470 | { |
471 | file = NNTPaccount::getUniqueFileName(); | 471 | file = NNTPaccount::getUniqueFileName(); |
472 | accountName = "New NNTP Account"; | 472 | accountName = "New NNTP Account"; |
473 | ssl = false; | 473 | ssl = false; |
474 | login = false; | 474 | login = false; |
475 | type = MAILLIB::A_NNTP; | 475 | type = MAILLIB::A_NNTP; |
476 | port = NNTP_PORT; | 476 | port = NNTP_PORT; |
477 | } | 477 | } |
478 | 478 | ||
479 | NNTPaccount::NNTPaccount( QString filename ) | 479 | NNTPaccount::NNTPaccount( QString filename ) |
480 | : Account() | 480 | : Account() |
481 | { | 481 | { |
482 | file = filename; | 482 | file = filename; |
483 | accountName = "New NNTP Account"; | 483 | accountName = "New NNTP Account"; |
484 | ssl = false; | 484 | ssl = false; |
485 | login = false; | 485 | login = false; |
486 | type = MAILLIB::A_NNTP; | 486 | type = MAILLIB::A_NNTP; |
487 | port = NNTP_PORT; | 487 | port = NNTP_PORT; |
488 | } | 488 | } |
489 | 489 | ||
490 | QString NNTPaccount::getUniqueFileName() | 490 | QString NNTPaccount::getUniqueFileName() |
491 | { | 491 | { |
492 | int num = 0; | 492 | int num = 0; |
493 | QString unique; | 493 | QString unique; |
494 | 494 | ||
495 | QDir dir( locateLocal("data", "kopiemail" ) ); | 495 | QDir dir( locateLocal("data", "kopiemail" ) ); |
496 | 496 | ||
497 | QStringList imap = dir.entryList( "nntp-*" ); | 497 | QStringList imap = dir.entryList( "nntp-*" ); |
498 | do { | 498 | do { |
499 | unique.setNum( num++ ); | 499 | unique.setNum( num++ ); |
500 | } while ( imap.contains( "nntp-" + unique ) > 0 ); | 500 | } while ( imap.contains( "nntp-" + unique ) > 0 ); |
501 | 501 | ||
502 | return unique; | 502 | return unique; |
503 | } | 503 | } |
504 | 504 | ||
505 | void NNTPaccount::read() | 505 | void NNTPaccount::read() |
506 | { | 506 | { |
507 | KConfig *conf = new KConfig( getFileName() ); | 507 | KConfig *conf = new KConfig( getFileName() ); |
508 | conf->setGroup( "NNTP Account" ); | 508 | conf->setGroup( "NNTP Account" ); |
509 | accountName = conf->readEntry( "Account" ); | 509 | accountName = conf->readEntry( "Account" ); |
510 | server = conf->readEntry( "Server" ); | 510 | server = conf->readEntry( "Server" ); |
511 | port = conf->readEntry( "Port" ); | 511 | port = conf->readEntry( "Port" ); |
512 | ssl = conf->readBoolEntry( "SSL" ); | 512 | ssl = conf->readBoolEntry( "SSL" ); |
513 | login = conf->readBoolEntry( "Login" ); | 513 | login = conf->readBoolEntry( "Login" ); |
514 | user = conf->readEntry( "User" ); | 514 | user = conf->readEntry( "User" ); |
515 | //password = conf->readEntryCrypt( "Password" ); | 515 | //password = conf->readEntryCrypt( "Password" ); |
516 | setPasswordList( conf->readListEntry( "FolderHistory")); | 516 | setPasswordList( conf->readListEntry( "FolderHistory")); |
517 | subscribedGroups = conf->readListEntry( "Subscribed"); | 517 | subscribedGroups = conf->readListEntry( "Subscribed"); |
518 | delete conf; | 518 | delete conf; |
519 | } | 519 | } |
520 | 520 | ||
521 | void NNTPaccount::save() | 521 | void NNTPaccount::save() |
522 | { | 522 | { |
523 | Settings::checkDirectory(); | 523 | Settings::checkDirectory(); |
524 | 524 | ||
525 | KConfig *conf = new KConfig( getFileName() ); | 525 | KConfig *conf = new KConfig( getFileName() ); |
526 | conf->setGroup( "NNTP Account" ); | 526 | conf->setGroup( "NNTP Account" ); |
527 | conf->writeEntry( "Account", accountName ); | 527 | conf->writeEntry( "Account", accountName ); |
528 | conf->writeEntry( "Server", server ); | 528 | conf->writeEntry( "Server", server ); |
529 | conf->writeEntry( "Port", port ); | 529 | conf->writeEntry( "Port", port ); |
530 | conf->writeEntry( "SSL", ssl ); | 530 | conf->writeEntry( "SSL", ssl ); |
531 | conf->writeEntry( "Login", login ); | 531 | conf->writeEntry( "Login", login ); |
532 | conf->writeEntry( "User", user ); | 532 | conf->writeEntry( "User", user ); |
533 | //conf->writeEntryCrypt( "Password", password ); | 533 | //conf->writeEntryCrypt( "Password", password ); |
534 | conf->writeEntry( "FolderHistory",getPasswordList() ); | 534 | conf->writeEntry( "FolderHistory",getPasswordList() ); |
535 | conf->writeEntry( "Subscribed" , subscribedGroups ); | 535 | conf->writeEntry( "Subscribed" , subscribedGroups ); |
536 | conf->sync(); | 536 | conf->sync(); |
537 | delete conf; | 537 | delete conf; |
538 | } | 538 | } |
539 | 539 | ||
540 | 540 | ||
541 | QString NNTPaccount::getFileName() | 541 | QString NNTPaccount::getFileName() |
542 | { | 542 | { |
543 | return locateLocal("data", "kopiemail" ) +"/nntp-" + file; | 543 | return locateLocal("data", "kopiemail" ) +"/nntp-" + file; |
544 | } | 544 | } |