-rw-r--r-- | noncore/net/mail/libmailwrapper/settings.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/noncore/net/mail/libmailwrapper/settings.cpp b/noncore/net/mail/libmailwrapper/settings.cpp index 3279f39..65ca387 100644 --- a/noncore/net/mail/libmailwrapper/settings.cpp +++ b/noncore/net/mail/libmailwrapper/settings.cpp | |||
@@ -16,192 +16,193 @@ | |||
16 | #define NNTP_SSL_PORT "563" | 16 | #define NNTP_SSL_PORT "563" |
17 | 17 | ||
18 | 18 | ||
19 | Settings::Settings() | 19 | Settings::Settings() |
20 | : QObject() | 20 | : QObject() |
21 | { | 21 | { |
22 | updateAccounts(); | 22 | updateAccounts(); |
23 | } | 23 | } |
24 | 24 | ||
25 | void Settings::checkDirectory() | 25 | void Settings::checkDirectory() |
26 | { | 26 | { |
27 | if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { | 27 | if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { |
28 | system( "mkdir -p $HOME/Applications/opiemail" ); | 28 | system( "mkdir -p $HOME/Applications/opiemail" ); |
29 | qDebug( "$HOME/Applications/opiemail created" ); | 29 | qDebug( "$HOME/Applications/opiemail created" ); |
30 | } | 30 | } |
31 | } | 31 | } |
32 | 32 | ||
33 | QList<Account> Settings::getAccounts() | 33 | QList<Account> Settings::getAccounts() |
34 | { | 34 | { |
35 | return accounts; | 35 | return accounts; |
36 | } | 36 | } |
37 | 37 | ||
38 | void Settings::addAccount( Account *account ) | 38 | void Settings::addAccount( Account *account ) |
39 | { | 39 | { |
40 | accounts.append( account ); | 40 | accounts.append( account ); |
41 | } | 41 | } |
42 | 42 | ||
43 | void Settings::delAccount( Account *account ) | 43 | void Settings::delAccount( Account *account ) |
44 | { | 44 | { |
45 | accounts.remove( account ); | 45 | accounts.remove( account ); |
46 | account->remove(); | 46 | account->remove(); |
47 | } | 47 | } |
48 | 48 | ||
49 | void Settings::updateAccounts() | 49 | void Settings::updateAccounts() |
50 | { | 50 | { |
51 | accounts.clear(); | 51 | accounts.clear(); |
52 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | 52 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); |
53 | QStringList::Iterator it; | 53 | QStringList::Iterator it; |
54 | 54 | ||
55 | QStringList imap = dir.entryList( "imap-*" ); | 55 | QStringList imap = dir.entryList( "imap-*" ); |
56 | for ( it = imap.begin(); it != imap.end(); it++ ) { | 56 | for ( it = imap.begin(); it != imap.end(); it++ ) { |
57 | qDebug( "Added IMAP account" ); | 57 | qDebug( "Added IMAP account" ); |
58 | IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); | 58 | IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); |
59 | accounts.append( account ); | 59 | accounts.append( account ); |
60 | } | 60 | } |
61 | 61 | ||
62 | QStringList pop3 = dir.entryList( "pop3-*" ); | 62 | QStringList pop3 = dir.entryList( "pop3-*" ); |
63 | for ( it = pop3.begin(); it != pop3.end(); it++ ) { | 63 | for ( it = pop3.begin(); it != pop3.end(); it++ ) { |
64 | qDebug( "Added POP account" ); | 64 | qDebug( "Added POP account" ); |
65 | POP3account *account = new POP3account( (*it).replace(0, 5, "") ); | 65 | POP3account *account = new POP3account( (*it).replace(0, 5, "") ); |
66 | accounts.append( account ); | 66 | accounts.append( account ); |
67 | } | 67 | } |
68 | 68 | ||
69 | QStringList smtp = dir.entryList( "smtp-*" ); | 69 | QStringList smtp = dir.entryList( "smtp-*" ); |
70 | for ( it = smtp.begin(); it != smtp.end(); it++ ) { | 70 | for ( it = smtp.begin(); it != smtp.end(); it++ ) { |
71 | qDebug( "Added SMTP account" ); | 71 | qDebug( "Added SMTP account" ); |
72 | SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); | 72 | SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); |
73 | accounts.append( account ); | 73 | accounts.append( account ); |
74 | } | 74 | } |
75 | 75 | ||
76 | QStringList nntp = dir.entryList( "nntp-*" ); | 76 | QStringList nntp = dir.entryList( "nntp-*" ); |
77 | for ( it = nntp.begin(); it != nntp.end(); it++ ) { | 77 | for ( it = nntp.begin(); it != nntp.end(); it++ ) { |
78 | qDebug( "Added NNTP account" ); | 78 | qDebug( "Added NNTP account" ); |
79 | NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); | 79 | NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); |
80 | accounts.append( account ); | 80 | accounts.append( account ); |
81 | } | 81 | } |
82 | 82 | ||
83 | readAccounts(); | 83 | readAccounts(); |
84 | } | 84 | } |
85 | 85 | ||
86 | void Settings::saveAccounts() | 86 | void Settings::saveAccounts() |
87 | { | 87 | { |
88 | checkDirectory(); | 88 | checkDirectory(); |
89 | Account *it; | 89 | Account *it; |
90 | 90 | ||
91 | for ( it = accounts.first(); it; it = accounts.next() ) { | 91 | for ( it = accounts.first(); it; it = accounts.next() ) { |
92 | it->save(); | 92 | it->save(); |
93 | } | 93 | } |
94 | } | 94 | } |
95 | 95 | ||
96 | void Settings::readAccounts() | 96 | void Settings::readAccounts() |
97 | { | 97 | { |
98 | checkDirectory(); | 98 | checkDirectory(); |
99 | Account *it; | 99 | Account *it; |
100 | 100 | ||
101 | for ( it = accounts.first(); it; it = accounts.next() ) { | 101 | for ( it = accounts.first(); it; it = accounts.next() ) { |
102 | it->read(); | 102 | it->read(); |
103 | } | 103 | } |
104 | } | 104 | } |
105 | 105 | ||
106 | Account::Account() | 106 | Account::Account() |
107 | { | 107 | { |
108 | accountName = "changeMe"; | 108 | accountName = "changeMe"; |
109 | type = "changeMe"; | 109 | type = "changeMe"; |
110 | ssl = false; | 110 | ssl = false; |
111 | connectionType = 1; | 111 | connectionType = 1; |
112 | offline = false; | ||
112 | } | 113 | } |
113 | 114 | ||
114 | void Account::remove() | 115 | void Account::remove() |
115 | { | 116 | { |
116 | QFile file( getFileName() ); | 117 | QFile file( getFileName() ); |
117 | file.remove(); | 118 | file.remove(); |
118 | } | 119 | } |
119 | 120 | ||
120 | IMAPaccount::IMAPaccount() | 121 | IMAPaccount::IMAPaccount() |
121 | : Account() | 122 | : Account() |
122 | { | 123 | { |
123 | file = IMAPaccount::getUniqueFileName(); | 124 | file = IMAPaccount::getUniqueFileName(); |
124 | accountName = "New IMAP Account"; | 125 | accountName = "New IMAP Account"; |
125 | ssl = false; | 126 | ssl = false; |
126 | connectionType = 1; | 127 | connectionType = 1; |
127 | type = "IMAP"; | 128 | type = "IMAP"; |
128 | port = IMAP_PORT; | 129 | port = IMAP_PORT; |
129 | } | 130 | } |
130 | 131 | ||
131 | IMAPaccount::IMAPaccount( QString filename ) | 132 | IMAPaccount::IMAPaccount( QString filename ) |
132 | : Account() | 133 | : Account() |
133 | { | 134 | { |
134 | file = filename; | 135 | file = filename; |
135 | accountName = "New IMAP Account"; | 136 | accountName = "New IMAP Account"; |
136 | ssl = false; | 137 | ssl = false; |
137 | connectionType = 1; | 138 | connectionType = 1; |
138 | type = "IMAP"; | 139 | type = "IMAP"; |
139 | port = IMAP_PORT; | 140 | port = IMAP_PORT; |
140 | } | 141 | } |
141 | 142 | ||
142 | QString IMAPaccount::getUniqueFileName() | 143 | QString IMAPaccount::getUniqueFileName() |
143 | { | 144 | { |
144 | int num = 0; | 145 | int num = 0; |
145 | QString unique; | 146 | QString unique; |
146 | 147 | ||
147 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | 148 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); |
148 | 149 | ||
149 | QStringList imap = dir.entryList( "imap-*" ); | 150 | QStringList imap = dir.entryList( "imap-*" ); |
150 | do { | 151 | do { |
151 | unique.setNum( num++ ); | 152 | unique.setNum( num++ ); |
152 | } while ( imap.contains( "imap-" + unique ) > 0 ); | 153 | } while ( imap.contains( "imap-" + unique ) > 0 ); |
153 | 154 | ||
154 | return unique; | 155 | return unique; |
155 | } | 156 | } |
156 | 157 | ||
157 | void IMAPaccount::read() | 158 | void IMAPaccount::read() |
158 | { | 159 | { |
159 | Config *conf = new Config( getFileName(), Config::File ); | 160 | Config *conf = new Config( getFileName(), Config::File ); |
160 | conf->setGroup( "IMAP Account" ); | 161 | conf->setGroup( "IMAP Account" ); |
161 | accountName = conf->readEntry( "Account","" ); | 162 | accountName = conf->readEntry( "Account","" ); |
162 | if (accountName.isNull()) accountName = ""; | 163 | if (accountName.isNull()) accountName = ""; |
163 | server = conf->readEntry( "Server","" ); | 164 | server = conf->readEntry( "Server","" ); |
164 | if (server.isNull()) server=""; | 165 | if (server.isNull()) server=""; |
165 | port = conf->readEntry( "Port","" ); | 166 | port = conf->readEntry( "Port","" ); |
166 | if (port.isNull()) port="143"; | 167 | if (port.isNull()) port="143"; |
167 | connectionType = conf->readNumEntry( "ConnectionType" ); | 168 | connectionType = conf->readNumEntry( "ConnectionType" ); |
168 | ssl = conf->readBoolEntry( "SSL",false ); | 169 | ssl = conf->readBoolEntry( "SSL",false ); |
169 | user = conf->readEntry( "User","" ); | 170 | user = conf->readEntry( "User","" ); |
170 | if (user.isNull()) user = ""; | 171 | if (user.isNull()) user = ""; |
171 | password = conf->readEntryCrypt( "Password","" ); | 172 | password = conf->readEntryCrypt( "Password","" ); |
172 | if (password.isNull()) password = ""; | 173 | if (password.isNull()) password = ""; |
173 | prefix = conf->readEntry("MailPrefix",""); | 174 | prefix = conf->readEntry("MailPrefix",""); |
174 | if (prefix.isNull()) prefix = ""; | 175 | if (prefix.isNull()) prefix = ""; |
175 | offline = conf->readBoolEntry("Offline",false); | 176 | offline = conf->readBoolEntry("Offline",false); |
176 | delete conf; | 177 | delete conf; |
177 | } | 178 | } |
178 | 179 | ||
179 | void IMAPaccount::save() | 180 | void IMAPaccount::save() |
180 | { | 181 | { |
181 | qDebug( "saving " + getFileName() ); | 182 | qDebug( "saving " + getFileName() ); |
182 | Settings::checkDirectory(); | 183 | Settings::checkDirectory(); |
183 | 184 | ||
184 | Config *conf = new Config( getFileName(), Config::File ); | 185 | Config *conf = new Config( getFileName(), Config::File ); |
185 | conf->setGroup( "IMAP Account" ); | 186 | conf->setGroup( "IMAP Account" ); |
186 | conf->writeEntry( "Account", accountName ); | 187 | conf->writeEntry( "Account", accountName ); |
187 | conf->writeEntry( "Server", server ); | 188 | conf->writeEntry( "Server", server ); |
188 | conf->writeEntry( "Port", port ); | 189 | conf->writeEntry( "Port", port ); |
189 | conf->writeEntry( "SSL", ssl ); | 190 | conf->writeEntry( "SSL", ssl ); |
190 | conf->writeEntry( "ConnectionType", connectionType ); | 191 | conf->writeEntry( "ConnectionType", connectionType ); |
191 | conf->writeEntry( "User", user ); | 192 | conf->writeEntry( "User", user ); |
192 | conf->writeEntryCrypt( "Password", password ); | 193 | conf->writeEntryCrypt( "Password", password ); |
193 | conf->writeEntry( "MailPrefix",prefix); | 194 | conf->writeEntry( "MailPrefix",prefix); |
194 | conf->writeEntry( "Offline",offline); | 195 | conf->writeEntry( "Offline",offline); |
195 | conf->write(); | 196 | conf->write(); |
196 | delete conf; | 197 | delete conf; |
197 | } | 198 | } |
198 | 199 | ||
199 | 200 | ||
200 | QString IMAPaccount::getFileName() | 201 | QString IMAPaccount::getFileName() |
201 | { | 202 | { |
202 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/imap-" + file; | 203 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/imap-" + file; |
203 | } | 204 | } |
204 | 205 | ||
205 | POP3account::POP3account() | 206 | POP3account::POP3account() |
206 | : Account() | 207 | : Account() |
207 | { | 208 | { |