-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 | |||
@@ -1,303 +1,304 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <qdir.h> | 2 | #include <qdir.h> |
3 | 3 | ||
4 | #include <qpe/config.h> | 4 | #include <qpe/config.h> |
5 | 5 | ||
6 | #include "settings.h" | 6 | #include "settings.h" |
7 | //#include "defines.h" | 7 | //#include "defines.h" |
8 | 8 | ||
9 | #define IMAP_PORT "143" | 9 | #define IMAP_PORT "143" |
10 | #define IMAP_SSL_PORT "993" | 10 | #define IMAP_SSL_PORT "993" |
11 | #define SMTP_PORT "25" | 11 | #define SMTP_PORT "25" |
12 | #define SMTP_SSL_PORT "465" | 12 | #define SMTP_SSL_PORT "465" |
13 | #define POP3_PORT "110" | 13 | #define POP3_PORT "110" |
14 | #define POP3_SSL_PORT "995" | 14 | #define POP3_SSL_PORT "995" |
15 | #define NNTP_PORT "119" | 15 | #define NNTP_PORT "119" |
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 | { |
208 | file = POP3account::getUniqueFileName(); | 209 | file = POP3account::getUniqueFileName(); |
209 | accountName = "New POP3 Account"; | 210 | accountName = "New POP3 Account"; |
210 | ssl = false; | 211 | ssl = false; |
211 | connectionType = 1; | 212 | connectionType = 1; |
212 | type = "POP3"; | 213 | type = "POP3"; |
213 | port = POP3_PORT; | 214 | port = POP3_PORT; |
214 | } | 215 | } |
215 | 216 | ||
216 | POP3account::POP3account( QString filename ) | 217 | POP3account::POP3account( QString filename ) |
217 | : Account() | 218 | : Account() |
218 | { | 219 | { |
219 | file = filename; | 220 | file = filename; |
220 | accountName = "New POP3 Account"; | 221 | accountName = "New POP3 Account"; |
221 | ssl = false; | 222 | ssl = false; |
222 | connectionType = 1; | 223 | connectionType = 1; |
223 | type = "POP3"; | 224 | type = "POP3"; |
224 | port = POP3_PORT; | 225 | port = POP3_PORT; |
225 | } | 226 | } |
226 | 227 | ||
227 | QString POP3account::getUniqueFileName() | 228 | QString POP3account::getUniqueFileName() |
228 | { | 229 | { |
229 | int num = 0; | 230 | int num = 0; |
230 | QString unique; | 231 | QString unique; |
231 | 232 | ||
232 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | 233 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); |
233 | 234 | ||
234 | QStringList imap = dir.entryList( "pop3-*" ); | 235 | QStringList imap = dir.entryList( "pop3-*" ); |
235 | do { | 236 | do { |
236 | unique.setNum( num++ ); | 237 | unique.setNum( num++ ); |
237 | } while ( imap.contains( "pop3-" + unique ) > 0 ); | 238 | } while ( imap.contains( "pop3-" + unique ) > 0 ); |
238 | 239 | ||
239 | return unique; | 240 | return unique; |
240 | } | 241 | } |
241 | 242 | ||
242 | void POP3account::read() | 243 | void POP3account::read() |
243 | { | 244 | { |
244 | Config *conf = new Config( getFileName(), Config::File ); | 245 | Config *conf = new Config( getFileName(), Config::File ); |
245 | conf->setGroup( "POP3 Account" ); | 246 | conf->setGroup( "POP3 Account" ); |
246 | accountName = conf->readEntry( "Account" ); | 247 | accountName = conf->readEntry( "Account" ); |
247 | server = conf->readEntry( "Server" ); | 248 | server = conf->readEntry( "Server" ); |
248 | port = conf->readEntry( "Port" ); | 249 | port = conf->readEntry( "Port" ); |
249 | ssl = conf->readBoolEntry( "SSL" ); | 250 | ssl = conf->readBoolEntry( "SSL" ); |
250 | connectionType = conf->readNumEntry( "ConnectionType" ); | 251 | connectionType = conf->readNumEntry( "ConnectionType" ); |
251 | user = conf->readEntry( "User" ); | 252 | user = conf->readEntry( "User" ); |
252 | password = conf->readEntryCrypt( "Password" ); | 253 | password = conf->readEntryCrypt( "Password" ); |
253 | offline = conf->readBoolEntry("Offline",false); | 254 | offline = conf->readBoolEntry("Offline",false); |
254 | delete conf; | 255 | delete conf; |
255 | } | 256 | } |
256 | 257 | ||
257 | void POP3account::save() | 258 | void POP3account::save() |
258 | { | 259 | { |
259 | qDebug( "saving " + getFileName() ); | 260 | qDebug( "saving " + getFileName() ); |
260 | Settings::checkDirectory(); | 261 | Settings::checkDirectory(); |
261 | 262 | ||
262 | Config *conf = new Config( getFileName(), Config::File ); | 263 | Config *conf = new Config( getFileName(), Config::File ); |
263 | conf->setGroup( "POP3 Account" ); | 264 | conf->setGroup( "POP3 Account" ); |
264 | conf->writeEntry( "Account", accountName ); | 265 | conf->writeEntry( "Account", accountName ); |
265 | conf->writeEntry( "Server", server ); | 266 | conf->writeEntry( "Server", server ); |
266 | conf->writeEntry( "Port", port ); | 267 | conf->writeEntry( "Port", port ); |
267 | conf->writeEntry( "SSL", ssl ); | 268 | conf->writeEntry( "SSL", ssl ); |
268 | conf->writeEntry( "ConnectionType", connectionType ); | 269 | conf->writeEntry( "ConnectionType", connectionType ); |
269 | conf->writeEntry( "User", user ); | 270 | conf->writeEntry( "User", user ); |
270 | conf->writeEntryCrypt( "Password", password ); | 271 | conf->writeEntryCrypt( "Password", password ); |
271 | conf->writeEntry( "Offline",offline); | 272 | conf->writeEntry( "Offline",offline); |
272 | conf->write(); | 273 | conf->write(); |
273 | delete conf; | 274 | delete conf; |
274 | } | 275 | } |
275 | 276 | ||
276 | 277 | ||
277 | QString POP3account::getFileName() | 278 | QString POP3account::getFileName() |
278 | { | 279 | { |
279 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/pop3-" + file; | 280 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/pop3-" + file; |
280 | } | 281 | } |
281 | 282 | ||
282 | SMTPaccount::SMTPaccount() | 283 | SMTPaccount::SMTPaccount() |
283 | : Account() | 284 | : Account() |
284 | { | 285 | { |
285 | file = SMTPaccount::getUniqueFileName(); | 286 | file = SMTPaccount::getUniqueFileName(); |
286 | accountName = "New SMTP Account"; | 287 | accountName = "New SMTP Account"; |
287 | ssl = false; | 288 | ssl = false; |
288 | connectionType = 1; | 289 | connectionType = 1; |
289 | login = false; | 290 | login = false; |
290 | useCC = false; | 291 | useCC = false; |
291 | useBCC = false; | 292 | useBCC = false; |
292 | useReply = false; | 293 | useReply = false; |
293 | type = "SMTP"; | 294 | type = "SMTP"; |
294 | port = SMTP_PORT; | 295 | port = SMTP_PORT; |
295 | } | 296 | } |
296 | 297 | ||
297 | SMTPaccount::SMTPaccount( QString filename ) | 298 | SMTPaccount::SMTPaccount( QString filename ) |
298 | : Account() | 299 | : Account() |
299 | { | 300 | { |
300 | file = filename; | 301 | file = filename; |
301 | accountName = "New SMTP Account"; | 302 | accountName = "New SMTP Account"; |
302 | ssl = false; | 303 | ssl = false; |
303 | connectionType = 1; | 304 | connectionType = 1; |