summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper/settings.cpp
authorzautrix <zautrix>2004-07-03 16:33:12 (UTC)
committer zautrix <zautrix>2004-07-03 16:33:12 (UTC)
commite3b89230f065c48c84b48c88edb6eb088374c487 (patch) (unidiff)
tree162ea2ef909a6f82ccfcedf45d80d6c821174912 /kmicromail/libmailwrapper/settings.cpp
parent2dd6ac0b2d24c91d35ce674a6c26351352df2b15 (diff)
downloadkdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.zip
kdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.tar.gz
kdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.tar.bz2
Initial revision
Diffstat (limited to 'kmicromail/libmailwrapper/settings.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/settings.cpp440
1 files changed, 440 insertions, 0 deletions
diff --git a/kmicromail/libmailwrapper/settings.cpp b/kmicromail/libmailwrapper/settings.cpp
new file mode 100644
index 0000000..bdb2a25
--- a/dev/null
+++ b/kmicromail/libmailwrapper/settings.cpp
@@ -0,0 +1,440 @@
1#include <stdlib.h>
2#include <qdir.h>
3
4//#include <opie2/odebug.h>
5#include <qpe/config.h>
6
7#include <kstandarddirs.h>
8#include "settings.h"
9//#include "defines.h"
10
11#define IMAP_PORT "143"
12#define IMAP_SSL_PORT "993"
13#define SMTP_PORT "25"
14#define SMTP_SSL_PORT "465"
15#define POP3_PORT "110"
16#define POP3_SSL_PORT "995"
17#define NNTP_PORT "119"
18#define NNTP_SSL_PORT "563"
19
20
21Settings::Settings()
22 : QObject()
23{
24 updateAccounts();
25}
26
27void Settings::checkDirectory()
28{
29 qDebug("Settings::checkDirectory() ");
30 return;
31 locateLocal("data", "kmicromail" );
32 /*
33 if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) {
34 system( "mkdir -p $HOME/Applications/opiemail" );
35 qDebug("$HOME/Applications/opiemail created ");
36 }
37 */
38}
39
40QList<Account> Settings::getAccounts()
41{
42 return accounts;
43}
44
45void Settings::addAccount( Account *account )
46{
47 accounts.append( account );
48}
49
50void Settings::delAccount( Account *account )
51{
52 accounts.remove( account );
53 account->remove();
54}
55
56void Settings::updateAccounts()
57{
58 accounts.clear();
59 QDir dir( locateLocal("data", "kmicromail" ) );
60 QStringList::Iterator it;
61
62 QStringList imap = dir.entryList( "imap-*" );
63 for ( it = imap.begin(); it != imap.end(); it++ ) {
64 IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") );
65 accounts.append( account );
66 }
67
68 QStringList pop3 = dir.entryList( "pop3-*" );
69 for ( it = pop3.begin(); it != pop3.end(); it++ ) {
70 POP3account *account = new POP3account( (*it).replace(0, 5, "") );
71 accounts.append( account );
72 }
73
74 QStringList smtp = dir.entryList( "smtp-*" );
75 for ( it = smtp.begin(); it != smtp.end(); it++ ) {
76 SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") );
77 accounts.append( account );
78 }
79
80 QStringList nntp = dir.entryList( "nntp-*" );
81 for ( it = nntp.begin(); it != nntp.end(); it++ ) {
82 NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") );
83 accounts.append( account );
84 }
85
86 readAccounts();
87}
88
89void Settings::saveAccounts()
90{
91 checkDirectory();
92 Account *it;
93
94 for ( it = accounts.first(); it; it = accounts.next() ) {
95 it->save();
96 }
97}
98
99void Settings::readAccounts()
100{
101 checkDirectory();
102 Account *it;
103
104 for ( it = accounts.first(); it; it = accounts.next() ) {
105 it->read();
106 }
107}
108
109Account::Account()
110{
111 accountName = "changeMe";
112 type = MAILLIB::A_UNDEFINED;
113 ssl = false;
114 connectionType = 1;
115 offline = false;
116}
117
118void Account::remove()
119{
120 QFile file( getFileName() );
121 file.remove();
122}
123
124IMAPaccount::IMAPaccount()
125 : Account()
126{
127 file = IMAPaccount::getUniqueFileName();
128 accountName = "New IMAP Account";
129 ssl = false;
130 connectionType = 1;
131 type = MAILLIB::A_IMAP;
132 port = IMAP_PORT;
133}
134
135IMAPaccount::IMAPaccount( QString filename )
136 : Account()
137{
138 file = filename;
139 accountName = "New IMAP Account";
140 ssl = false;
141 connectionType = 1;
142 type = MAILLIB::A_IMAP;
143 port = IMAP_PORT;
144}
145
146QString IMAPaccount::getUniqueFileName()
147{
148 int num = 0;
149 QString unique;
150
151 QDir dir( locateLocal("data", "kmicromail" ) );
152
153 QStringList imap = dir.entryList( "imap-*" );
154 do {
155 unique.setNum( num++ );
156 } while ( imap.contains( "imap-" + unique ) > 0 );
157
158 return unique;
159}
160
161void IMAPaccount::read()
162{
163 Config *conf = new Config( getFileName(), Config::File );
164 conf->setGroup( "IMAP Account" );
165 accountName = conf->readEntry( "Account","" );
166 if (accountName.isNull()) accountName = "";
167 server = conf->readEntry( "Server","" );
168 if (server.isNull()) server="";
169 port = conf->readEntry( "Port","" );
170 if (port.isNull()) port="143";
171 connectionType = conf->readNumEntry( "ConnectionType" );
172 ssl = conf->readBoolEntry( "SSL",false );
173 user = conf->readEntry( "User","" );
174 if (user.isNull()) user = "";
175 password = conf->readEntryCrypt( "Password","" );
176 if (password.isNull()) password = "";
177 prefix = conf->readEntry("MailPrefix","");
178 if (prefix.isNull()) prefix = "";
179 offline = conf->readBoolEntry("Offline",false);
180 delete conf;
181}
182
183void IMAPaccount::save()
184{
185 qDebug("saving %s ",getFileName().latin1() );
186 Settings::checkDirectory();
187
188 Config *conf = new Config( getFileName(), Config::File );
189 conf->setGroup( "IMAP Account" );
190 conf->writeEntry( "Account", accountName );
191 conf->writeEntry( "Server", server );
192 conf->writeEntry( "Port", port );
193 conf->writeEntry( "SSL", ssl );
194 conf->writeEntry( "ConnectionType", connectionType );
195 conf->writeEntry( "User", user );
196 conf->writeEntryCrypt( "Password", password );
197 conf->writeEntry( "MailPrefix",prefix);
198 conf->writeEntry( "Offline",offline);
199 conf->write();
200 delete conf;
201}
202
203
204QString IMAPaccount::getFileName()
205{
206 return locateLocal("data", "kmicromail" ) +"/imap-" + file;
207}
208
209POP3account::POP3account()
210 : Account()
211{
212 file = POP3account::getUniqueFileName();
213 accountName = "New POP3 Account";
214 ssl = false;
215 connectionType = 1;
216 type = MAILLIB::A_POP3;
217 port = POP3_PORT;
218}
219
220POP3account::POP3account( QString filename )
221 : Account()
222{
223 file = filename;
224 accountName = "New POP3 Account";
225 ssl = false;
226 connectionType = 1;
227 type = MAILLIB::A_POP3;
228 port = POP3_PORT;
229}
230
231QString POP3account::getUniqueFileName()
232{
233 int num = 0;
234 QString unique;
235
236 QDir dir( locateLocal("data", "kmicromail" ) );
237
238 QStringList imap = dir.entryList( "pop3-*" );
239 do {
240 unique.setNum( num++ );
241 } while ( imap.contains( "pop3-" + unique ) > 0 );
242
243 return unique;
244}
245
246void POP3account::read()
247{
248 Config *conf = new Config( getFileName(), Config::File );
249 conf->setGroup( "POP3 Account" );
250 accountName = conf->readEntry( "Account" );
251 server = conf->readEntry( "Server" );
252 port = conf->readEntry( "Port" );
253 ssl = conf->readBoolEntry( "SSL" );
254 connectionType = conf->readNumEntry( "ConnectionType" );
255 user = conf->readEntry( "User" );
256 password = conf->readEntryCrypt( "Password" );
257 offline = conf->readBoolEntry("Offline",false);
258 delete conf;
259}
260
261void POP3account::save()
262{
263 Settings::checkDirectory();
264
265 Config *conf = new Config( getFileName(), Config::File );
266 conf->setGroup( "POP3 Account" );
267 conf->writeEntry( "Account", accountName );
268 conf->writeEntry( "Server", server );
269 conf->writeEntry( "Port", port );
270 conf->writeEntry( "SSL", ssl );
271 conf->writeEntry( "ConnectionType", connectionType );
272 conf->writeEntry( "User", user );
273 conf->writeEntryCrypt( "Password", password );
274 conf->writeEntry( "Offline",offline);
275 conf->write();
276 delete conf;
277}
278
279
280QString POP3account::getFileName()
281{
282 return locateLocal("data", "kmicromail" ) +"/pop3-" + file;
283}
284
285SMTPaccount::SMTPaccount()
286 : Account()
287{
288 file = SMTPaccount::getUniqueFileName();
289 accountName = "New SMTP Account";
290 ssl = false;
291 connectionType = 1;
292 login = false;
293 useCC = false;
294 useBCC = false;
295 useReply = false;
296 type = MAILLIB::A_SMTP;
297 port = SMTP_PORT;
298}
299
300SMTPaccount::SMTPaccount( QString filename )
301 : Account()
302{
303 file = filename;
304 accountName = "New SMTP Account";
305 ssl = false;
306 connectionType = 1;
307 login = false;
308 type = MAILLIB::A_SMTP;
309 port = SMTP_PORT;
310}
311
312QString SMTPaccount::getUniqueFileName()
313{
314 int num = 0;
315 QString unique;
316
317 QDir dir( locateLocal("data", "kmicromail" ) );
318
319 QStringList imap = dir.entryList( "smtp-*" );
320 do {
321 unique.setNum( num++ );
322 } while ( imap.contains( "smtp-" + unique ) > 0 );
323
324 return unique;
325}
326
327void SMTPaccount::read()
328{
329 Config *conf = new Config( getFileName(), Config::File );
330 conf->setGroup( "SMTP Account" );
331 accountName = conf->readEntry( "Account" );
332 server = conf->readEntry( "Server" );
333 port = conf->readEntry( "Port" );
334 ssl = conf->readBoolEntry( "SSL" );
335 connectionType = conf->readNumEntry( "ConnectionType" );
336 login = conf->readBoolEntry( "Login" );
337 user = conf->readEntry( "User" );
338 password = conf->readEntryCrypt( "Password" );
339 delete conf;
340}
341
342void SMTPaccount::save()
343{
344 Settings::checkDirectory();
345
346 Config *conf = new Config( getFileName(), Config::File );
347 conf->setGroup( "SMTP Account" );
348 conf->writeEntry( "Account", accountName );
349 conf->writeEntry( "Server", server );
350 conf->writeEntry( "Port", port );
351 conf->writeEntry( "SSL", ssl );
352 conf->writeEntry( "ConnectionType", connectionType );
353 conf->writeEntry( "Login", login );
354 conf->writeEntry( "User", user );
355 conf->writeEntryCrypt( "Password", password );
356 conf->write();
357 delete conf;
358}
359
360
361QString SMTPaccount::getFileName()
362{
363 return locateLocal("data", "kmicromail" ) +"/smtp-" + file;
364}
365
366NNTPaccount::NNTPaccount()
367 : Account()
368{
369 file = NNTPaccount::getUniqueFileName();
370 accountName = "New NNTP Account";
371 ssl = false;
372 login = false;
373 type = MAILLIB::A_NNTP;
374 port = NNTP_PORT;
375}
376
377NNTPaccount::NNTPaccount( QString filename )
378 : Account()
379{
380 file = filename;
381 accountName = "New NNTP Account";
382 ssl = false;
383 login = false;
384 type = MAILLIB::A_NNTP;
385 port = NNTP_PORT;
386}
387
388QString NNTPaccount::getUniqueFileName()
389{
390 int num = 0;
391 QString unique;
392
393 QDir dir( locateLocal("data", "kmicromail" ) );
394
395 QStringList imap = dir.entryList( "nntp-*" );
396 do {
397 unique.setNum( num++ );
398 } while ( imap.contains( "nntp-" + unique ) > 0 );
399
400 return unique;
401}
402
403void NNTPaccount::read()
404{
405 Config *conf = new Config( getFileName(), Config::File );
406 conf->setGroup( "NNTP Account" );
407 accountName = conf->readEntry( "Account" );
408 server = conf->readEntry( "Server" );
409 port = conf->readEntry( "Port" );
410 ssl = conf->readBoolEntry( "SSL" );
411 login = conf->readBoolEntry( "Login" );
412 user = conf->readEntry( "User" );
413 password = conf->readEntryCrypt( "Password" );
414 subscribedGroups = conf->readListEntry( "Subscribed", ',' );
415 delete conf;
416}
417
418void NNTPaccount::save()
419{
420 Settings::checkDirectory();
421
422 Config *conf = new Config( getFileName(), Config::File );
423 conf->setGroup( "NNTP Account" );
424 conf->writeEntry( "Account", accountName );
425 conf->writeEntry( "Server", server );
426 conf->writeEntry( "Port", port );
427 conf->writeEntry( "SSL", ssl );
428 conf->writeEntry( "Login", login );
429 conf->writeEntry( "User", user );
430 conf->writeEntryCrypt( "Password", password );
431 conf->writeEntry( "Subscribed" , subscribedGroups, ',' );
432 conf->write();
433 delete conf;
434}
435
436
437QString NNTPaccount::getFileName()
438{
439 return locateLocal("data", "kmicromail" ) +"/nntp-" + file;
440}