summaryrefslogtreecommitdiff
path: root/noncore/unsupported/mail2/libmail/configfile.cpp
Unidiff
Diffstat (limited to 'noncore/unsupported/mail2/libmail/configfile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/mail2/libmail/configfile.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/noncore/unsupported/mail2/libmail/configfile.cpp b/noncore/unsupported/mail2/libmail/configfile.cpp
new file mode 100644
index 0000000..a5c2b49
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/configfile.cpp
@@ -0,0 +1,112 @@
1#include <qdir.h>
2
3#include <qpe/config.h>
4
5#include <stdlib.h>
6
7#include "configfile.h"
8
9ConfigFile::ConfigFile() : QObject()
10{
11 checkDirectory();
12
13 QDir dir((QString) getenv("HOME") + "/Applications/mail/accounts");
14 QStringList entries = dir.entryList("account-*");
15
16 QStringList::Iterator it;
17 for (it = entries.begin(); it != entries.end(); it++) {
18 Account account;
19
20 Config *config = new Config((QString) getenv("HOME") + "/Applications/mail/accounts/" + *it, Config::File);
21 config->setGroup("Account");
22 account.setAccountName((*it).replace(0, 8, ""));
23 account.setRealName(config->readEntry("RealName"));
24 account.setEmail(config->readEntry("Email"));
25 account.setOrg(config->readEntry("Organization"));
26 account.setImapServer(config->readEntry("ImapServer"));
27 account.setImapPort(config->readEntry("ImapPort"));
28 account.setSmtpServer(config->readEntry("SmtpServer"));
29 account.setSmtpPort(config->readEntry("SmtpPort"));
30 account.setUser(config->readEntry("User"));
31 account.setPass(rot13(config->readEntryCrypt("Pass")));
32 account.setSmtpSsl(config->readBoolEntry("SmtpSsl"));
33 account.setSmtpSslPort(config->readEntry("SmtpSslPort"));
34 account.setImapSsl(config->readBoolEntry("ImapSsl"));
35 account.setImapSslPort(config->readEntry("ImapSslPort"));
36 account.setDefaultCc(config->readBoolEntry("DefaultCc"));
37 account.setDefaultBcc(config->readBoolEntry("DefaultBcc"));
38 account.setDefaultReplyTo(config->readBoolEntry("DefaultReplyTo"));
39 account.setCc(config->readEntry("Cc"));
40 account.setBcc(config->readEntry("Bcc"));
41 account.setReplyTo(config->readEntry("ReplyTo"));
42 account.setSignature(config->readEntry("Signature").replace(QRegExp("<br>"), "\n"));
43
44 _accounts.append(account);
45 }
46}
47
48QValueList<Account> ConfigFile::getAccounts()
49{
50 ConfigFile *configFile = new ConfigFile();
51 return configFile->_accounts;
52}
53
54void ConfigFile::updateAccount(Account account)
55{
56 checkDirectory();
57 Config *config = new Config((QString) getenv("HOME") + "/Applications/mail/accounts/account-" + account.accountName(), Config::File);
58
59 config->setGroup("Account");
60 config->writeEntry("RealName", account.realName());
61 config->writeEntry("Email", account.email());
62 config->writeEntry("Organization", account.org());
63 config->writeEntry("ImapServer", account.imapServer());
64 config->writeEntry("ImapPort", account.imapPort());
65 config->writeEntry("SmtpServer", account.smtpServer());
66 config->writeEntry("SmtpPort", account.smtpPort());
67 config->writeEntry("User", account.user());
68 config->writeEntryCrypt("Pass", rot13(account.pass()));
69 config->writeEntry("SmtpSsl", account.smtpSsl());
70 config->writeEntry("SmtpSslPort", account.smtpSslPort());
71 config->writeEntry("ImapSsl", account.imapSsl());
72 config->writeEntry("ImapSslPort", account.imapSslPort());
73 config->writeEntry("DefaultCc", account.defaultCc());
74 config->writeEntry("DefaultBcc", account.defaultBcc());
75 config->writeEntry("DefaultReplyTo", account.defaultReplyTo());
76 config->writeEntry("Cc", account.cc());
77 config->writeEntry("Bcc", account.bcc());
78 config->writeEntry("ReplyTo", account.replyTo());
79 config->writeEntry("Signature", account.signature().replace(QRegExp("\\n"), "<br>"));
80
81 config->write();
82}
83
84void ConfigFile::deleteAccount(Account account)
85{
86 QFile f((QString) getenv("HOME") + "/Applications/mail/accounts/account-" + account.accountName());
87 f.remove();
88}
89
90void ConfigFile::checkDirectory()
91{
92 if (!QDir((QString) getenv("HOME") + "/Applications/mail/accounts").exists()) {
93 system("mkdir -p $HOME/Applications/mail/accounts");
94 qWarning("mail: $HOME/Applications/mail/accounts created");
95 }
96}
97
98QString ConfigFile::rot13(const QString &input)
99{
100 QString i = input;
101 int l = i.length();
102 while(l--) {
103 if (i[l] >= QChar('A') && i[l] <= QChar('M') ||
104 i[l] >= QChar('a') && i[l] <= QChar('m'))
105 i[l] = (char)((int)QChar(l[i])+13);
106 else if (i[l] >= QChar('N') && i[l] <= QChar('Z') ||
107 i[l] >= QChar('n') && i[l] <= QChar('z'))
108 i[l] = (char)((int)QChar(l[i])-13);
109 }
110 return i;
111}
112