author | zautrix <zautrix> | 2004-09-11 16:44:49 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-11 16:44:49 (UTC) |
commit | 06be094df4e34cc41db113d8c0e78eccde5365b5 (patch) (unidiff) | |
tree | b99317f9c83886d05b83cdb49e066f414e0fde25 /kmicromail/libmailwrapper | |
parent | 53e10fa5e66620ff1eba1c9d17738103ad511c91 (diff) | |
download | kdepimpi-06be094df4e34cc41db113d8c0e78eccde5365b5.zip kdepimpi-06be094df4e34cc41db113d8c0e78eccde5365b5.tar.gz kdepimpi-06be094df4e34cc41db113d8c0e78eccde5365b5.tar.bz2 |
Mail more useful
-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.cpp | 4 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/mhwrapper.cpp | 2 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/settings.cpp | 4 |
3 files changed, 3 insertions, 7 deletions
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index 5441a9b..91332c3 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp | |||
@@ -78,193 +78,193 @@ bool IMAPwrapper::start_tls(bool force_tls) | |||
78 | 78 | ||
79 | err = mailimap_capability(m_imap,&cap_data); | 79 | err = mailimap_capability(m_imap,&cap_data); |
80 | if (err != MAILIMAP_NO_ERROR) { | 80 | if (err != MAILIMAP_NO_ERROR) { |
81 | Global::statusMessage("error getting capabilities!"); | 81 | Global::statusMessage("error getting capabilities!"); |
82 | return false; | 82 | return false; |
83 | } | 83 | } |
84 | clistiter * cur; | 84 | clistiter * cur; |
85 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { | 85 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { |
86 | struct mailimap_capability * cap; | 86 | struct mailimap_capability * cap; |
87 | cap = (struct mailimap_capability *)clist_content(cur); | 87 | cap = (struct mailimap_capability *)clist_content(cur); |
88 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { | 88 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { |
89 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { | 89 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { |
90 | try_tls = true; | 90 | try_tls = true; |
91 | break; | 91 | break; |
92 | } | 92 | } |
93 | } | 93 | } |
94 | } | 94 | } |
95 | if (cap_data) { | 95 | if (cap_data) { |
96 | mailimap_capability_data_free(cap_data); | 96 | mailimap_capability_data_free(cap_data); |
97 | } | 97 | } |
98 | if (try_tls) { | 98 | if (try_tls) { |
99 | err = mailimap_starttls(m_imap); | 99 | err = mailimap_starttls(m_imap); |
100 | if (err != MAILIMAP_NO_ERROR && force_tls) { | 100 | if (err != MAILIMAP_NO_ERROR && force_tls) { |
101 | Global::statusMessage(tr("Server has no TLS support!")); | 101 | Global::statusMessage(tr("Server has no TLS support!")); |
102 | try_tls = false; | 102 | try_tls = false; |
103 | } else { | 103 | } else { |
104 | mailstream_low * low; | 104 | mailstream_low * low; |
105 | mailstream_low * new_low; | 105 | mailstream_low * new_low; |
106 | low = mailstream_get_low(m_imap->imap_stream); | 106 | low = mailstream_get_low(m_imap->imap_stream); |
107 | if (!low) { | 107 | if (!low) { |
108 | try_tls = false; | 108 | try_tls = false; |
109 | } else { | 109 | } else { |
110 | int fd = mailstream_low_get_fd(low); | 110 | int fd = mailstream_low_get_fd(low); |
111 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 111 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
112 | mailstream_low_free(low); | 112 | mailstream_low_free(low); |
113 | mailstream_set_low(m_imap->imap_stream, new_low); | 113 | mailstream_set_low(m_imap->imap_stream, new_low); |
114 | } else { | 114 | } else { |
115 | try_tls = false; | 115 | try_tls = false; |
116 | } | 116 | } |
117 | } | 117 | } |
118 | } | 118 | } |
119 | } | 119 | } |
120 | return try_tls; | 120 | return try_tls; |
121 | } | 121 | } |
122 | 122 | ||
123 | void IMAPwrapper::login() | 123 | void IMAPwrapper::login() |
124 | { | 124 | { |
125 | QString server, user, pass; | 125 | QString server, user, pass; |
126 | uint16_t port; | 126 | uint16_t port; |
127 | int err = MAILIMAP_NO_ERROR; | 127 | int err = MAILIMAP_NO_ERROR; |
128 | 128 | ||
129 | if (account->getOffline()) return; | 129 | if (account->getOffline()) return; |
130 | /* we are connected this moment */ | 130 | /* we are connected this moment */ |
131 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 131 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
132 | if (m_imap) { | 132 | if (m_imap) { |
133 | err = mailimap_noop(m_imap); | 133 | err = mailimap_noop(m_imap); |
134 | if (err!=MAILIMAP_NO_ERROR) { | 134 | if (err!=MAILIMAP_NO_ERROR) { |
135 | logout(); | 135 | logout(); |
136 | } else { | 136 | } else { |
137 | mailstream_flush(m_imap->imap_stream); | 137 | mailstream_flush(m_imap->imap_stream); |
138 | return; | 138 | return; |
139 | } | 139 | } |
140 | } | 140 | } |
141 | server = account->getServer(); | 141 | server = account->getServer(); |
142 | port = account->getPort().toUInt(); | 142 | port = account->getPort().toUInt(); |
143 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 143 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
144 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 144 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
145 | login.show(); | 145 | login.show(); |
146 | if ( QDialog::Accepted == login.exec() ) { | 146 | if ( QDialog::Accepted == login.exec() ) { |
147 | // ok | 147 | // ok |
148 | user = login.getUser(); | 148 | user = login.getUser(); |
149 | pass = login.getPassword(); | 149 | pass = login.getPassword(); |
150 | } else { | 150 | } else { |
151 | // cancel | 151 | // cancel |
152 | return; | 152 | return; |
153 | } | 153 | } |
154 | } else { | 154 | } else { |
155 | user = account->getUser(); | 155 | user = account->getUser(); |
156 | pass = account->getPassword(); | 156 | pass = account->getPassword(); |
157 | } | 157 | } |
158 | 158 | ||
159 | m_imap = mailimap_new( 20, &imap_progress ); | 159 | m_imap = mailimap_new( 20, &imap_progress ); |
160 | 160 | ||
161 | /* connect */ | 161 | /* connect */ |
162 | bool ssl = false; | 162 | bool ssl = false; |
163 | bool try_tls = false; | 163 | bool try_tls = false; |
164 | bool force_tls = false; | 164 | bool force_tls = false; |
165 | 165 | ||
166 | if ( account->ConnectionType() == 2 ) { | 166 | if ( account->ConnectionType() == 2 ) { |
167 | ssl = true; | 167 | ssl = true; |
168 | } | 168 | } |
169 | if (account->ConnectionType()==1) { | 169 | if (account->ConnectionType()==1) { |
170 | force_tls = true; | 170 | force_tls = true; |
171 | } | 171 | } |
172 | 172 | ||
173 | if ( ssl ) { | 173 | if ( ssl ) { |
174 | qDebug("using ssl "); | 174 | //qDebug("using ssl "); |
175 | err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); | 175 | err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); |
176 | } else { | 176 | } else { |
177 | err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); | 177 | err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); |
178 | } | 178 | } |
179 | 179 | ||
180 | if ( err != MAILIMAP_NO_ERROR && | 180 | if ( err != MAILIMAP_NO_ERROR && |
181 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 181 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
182 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 182 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
183 | QString failure = ""; | 183 | QString failure = ""; |
184 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | 184 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { |
185 | failure="Connection refused"; | 185 | failure="Connection refused"; |
186 | } else { | 186 | } else { |
187 | failure="Unknown failure"; | 187 | failure="Unknown failure"; |
188 | } | 188 | } |
189 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); | 189 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); |
190 | mailimap_free( m_imap ); | 190 | mailimap_free( m_imap ); |
191 | m_imap = 0; | 191 | m_imap = 0; |
192 | return; | 192 | return; |
193 | } | 193 | } |
194 | 194 | ||
195 | if (!ssl) { | 195 | if (!ssl) { |
196 | try_tls = start_tls(force_tls); | 196 | try_tls = start_tls(force_tls); |
197 | } | 197 | } |
198 | 198 | ||
199 | bool ok = true; | 199 | bool ok = true; |
200 | if (force_tls && !try_tls) { | 200 | if (force_tls && !try_tls) { |
201 | Global::statusMessage(tr("Server has no TLS support!")); | 201 | Global::statusMessage(tr("Server has no TLS support!")); |
202 | ok = false; | 202 | ok = false; |
203 | } | 203 | } |
204 | 204 | ||
205 | 205 | ||
206 | /* login */ | 206 | /* login */ |
207 | 207 | ||
208 | if (ok) { | 208 | if (ok) { |
209 | err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); | 209 | err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); |
210 | if ( err != MAILIMAP_NO_ERROR ) { | 210 | if ( err != MAILIMAP_NO_ERROR ) { |
211 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); | 211 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); |
212 | ok = false; | 212 | ok = false; |
213 | } | 213 | } |
214 | } | 214 | } |
215 | if (!ok) { | 215 | if (!ok) { |
216 | err = mailimap_close( m_imap ); | 216 | err = mailimap_close( m_imap ); |
217 | mailimap_free( m_imap ); | 217 | mailimap_free( m_imap ); |
218 | m_imap = 0; | 218 | m_imap = 0; |
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
222 | void IMAPwrapper::logout() | 222 | void IMAPwrapper::logout() |
223 | { | 223 | { |
224 | int err = MAILIMAP_NO_ERROR; | 224 | int err = MAILIMAP_NO_ERROR; |
225 | if (!m_imap) return; | 225 | if (!m_imap) return; |
226 | err = mailimap_logout( m_imap ); | 226 | err = mailimap_logout( m_imap ); |
227 | err = mailimap_close( m_imap ); | 227 | err = mailimap_close( m_imap ); |
228 | mailimap_free( m_imap ); | 228 | mailimap_free( m_imap ); |
229 | m_imap = 0; | 229 | m_imap = 0; |
230 | m_Lastmbox = ""; | 230 | m_Lastmbox = ""; |
231 | } | 231 | } |
232 | 232 | ||
233 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) | 233 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) |
234 | { | 234 | { |
235 | int err = MAILIMAP_NO_ERROR; | 235 | int err = MAILIMAP_NO_ERROR; |
236 | clist *result = 0; | 236 | clist *result = 0; |
237 | clistcell *current; | 237 | clistcell *current; |
238 | mailimap_fetch_type *fetchType = 0; | 238 | mailimap_fetch_type *fetchType = 0; |
239 | mailimap_set *set = 0; | 239 | mailimap_set *set = 0; |
240 | 240 | ||
241 | login(); | 241 | login(); |
242 | if (!m_imap) { | 242 | if (!m_imap) { |
243 | return; | 243 | return; |
244 | } | 244 | } |
245 | /* select mailbox READONLY for operations */ | 245 | /* select mailbox READONLY for operations */ |
246 | err = selectMbox(mailbox); | 246 | err = selectMbox(mailbox); |
247 | if ( err != MAILIMAP_NO_ERROR ) { | 247 | if ( err != MAILIMAP_NO_ERROR ) { |
248 | return; | 248 | return; |
249 | } | 249 | } |
250 | 250 | ||
251 | int last = m_imap->imap_selection_info->sel_exists; | 251 | int last = m_imap->imap_selection_info->sel_exists; |
252 | 252 | ||
253 | if (last == 0) { | 253 | if (last == 0) { |
254 | Global::statusMessage(tr("Mailbox has no mails")); | 254 | Global::statusMessage(tr("Mailbox has no mails")); |
255 | return; | 255 | return; |
256 | } else { | 256 | } else { |
257 | } | 257 | } |
258 | 258 | ||
259 | Global::statusMessage(tr("Fetching header list")); | 259 | Global::statusMessage(tr("Fetching header list")); |
260 | qApp->processEvents(); | 260 | qApp->processEvents(); |
261 | /* the range has to start at 1!!! not with 0!!!! */ | 261 | /* the range has to start at 1!!! not with 0!!!! */ |
262 | set = mailimap_set_new_interval( 1, last ); | 262 | set = mailimap_set_new_interval( 1, last ); |
263 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 263 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
264 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 264 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
265 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 265 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
266 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 266 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
267 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 267 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
268 | 268 | ||
269 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 269 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
270 | mailimap_set_free( set ); | 270 | mailimap_set_free( set ); |
@@ -1154,154 +1154,154 @@ int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,cons | |||
1154 | } | 1154 | } |
1155 | return 1; | 1155 | return 1; |
1156 | } | 1156 | } |
1157 | 1157 | ||
1158 | int IMAPwrapper::deleteMbox(const FolderP&folder) | 1158 | int IMAPwrapper::deleteMbox(const FolderP&folder) |
1159 | { | 1159 | { |
1160 | if (!folder) return 0; | 1160 | if (!folder) return 0; |
1161 | login(); | 1161 | login(); |
1162 | if (!m_imap) {return 0;} | 1162 | if (!m_imap) {return 0;} |
1163 | int res = mailimap_delete(m_imap,folder->getName()); | 1163 | int res = mailimap_delete(m_imap,folder->getName()); |
1164 | if (res != MAILIMAP_NO_ERROR) { | 1164 | if (res != MAILIMAP_NO_ERROR) { |
1165 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); | 1165 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); |
1166 | return 0; | 1166 | return 0; |
1167 | } | 1167 | } |
1168 | return 1; | 1168 | return 1; |
1169 | } | 1169 | } |
1170 | 1170 | ||
1171 | void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | 1171 | void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) |
1172 | { | 1172 | { |
1173 | mailimap_status_att_list * att_list =0; | 1173 | mailimap_status_att_list * att_list =0; |
1174 | mailimap_mailbox_data_status * status=0; | 1174 | mailimap_mailbox_data_status * status=0; |
1175 | clistiter * cur = 0; | 1175 | clistiter * cur = 0; |
1176 | int r = 0; | 1176 | int r = 0; |
1177 | target_stat.message_count = 0; | 1177 | target_stat.message_count = 0; |
1178 | target_stat.message_unseen = 0; | 1178 | target_stat.message_unseen = 0; |
1179 | target_stat.message_recent = 0; | 1179 | target_stat.message_recent = 0; |
1180 | login(); | 1180 | login(); |
1181 | if (!m_imap) { | 1181 | if (!m_imap) { |
1182 | return; | 1182 | return; |
1183 | } | 1183 | } |
1184 | att_list = mailimap_status_att_list_new_empty(); | 1184 | att_list = mailimap_status_att_list_new_empty(); |
1185 | if (!att_list) return; | 1185 | if (!att_list) return; |
1186 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); | 1186 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); |
1187 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); | 1187 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); |
1188 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); | 1188 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); |
1189 | r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); | 1189 | r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); |
1190 | if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { | 1190 | if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { |
1191 | for (cur = clist_begin(status->st_info_list); | 1191 | for (cur = clist_begin(status->st_info_list); |
1192 | cur != NULL ; cur = clist_next(cur)) { | 1192 | cur != NULL ; cur = clist_next(cur)) { |
1193 | mailimap_status_info * status_info; | 1193 | mailimap_status_info * status_info; |
1194 | status_info = (mailimap_status_info *)clist_content(cur); | 1194 | status_info = (mailimap_status_info *)clist_content(cur); |
1195 | switch (status_info->st_att) { | 1195 | switch (status_info->st_att) { |
1196 | case MAILIMAP_STATUS_ATT_MESSAGES: | 1196 | case MAILIMAP_STATUS_ATT_MESSAGES: |
1197 | target_stat.message_count = status_info->st_value; | 1197 | target_stat.message_count = status_info->st_value; |
1198 | break; | 1198 | break; |
1199 | case MAILIMAP_STATUS_ATT_RECENT: | 1199 | case MAILIMAP_STATUS_ATT_RECENT: |
1200 | target_stat.message_recent = status_info->st_value; | 1200 | target_stat.message_recent = status_info->st_value; |
1201 | break; | 1201 | break; |
1202 | case MAILIMAP_STATUS_ATT_UNSEEN: | 1202 | case MAILIMAP_STATUS_ATT_UNSEEN: |
1203 | target_stat.message_unseen = status_info->st_value; | 1203 | target_stat.message_unseen = status_info->st_value; |
1204 | break; | 1204 | break; |
1205 | } | 1205 | } |
1206 | } | 1206 | } |
1207 | } else { | 1207 | } else { |
1208 | // odebug << "Error retrieving status" << oendl; | 1208 | // odebug << "Error retrieving status" << oendl; |
1209 | } | 1209 | } |
1210 | if (status) mailimap_mailbox_data_status_free(status); | 1210 | if (status) mailimap_mailbox_data_status_free(status); |
1211 | if (att_list) mailimap_status_att_list_free(att_list); | 1211 | if (att_list) mailimap_status_att_list_free(att_list); |
1212 | } | 1212 | } |
1213 | 1213 | ||
1214 | void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | 1214 | void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) |
1215 | { | 1215 | { |
1216 | login(); | 1216 | login(); |
1217 | if (!m_imap) return; | 1217 | if (!m_imap) return; |
1218 | if (!msg) return; | 1218 | if (!msg) return; |
1219 | int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); | 1219 | int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); |
1220 | if (r != MAILIMAP_NO_ERROR) { | 1220 | if (r != MAILIMAP_NO_ERROR) { |
1221 | Global::statusMessage("Error storing mail!"); | 1221 | Global::statusMessage("Error storing mail!"); |
1222 | } | 1222 | } |
1223 | } | 1223 | } |
1224 | 1224 | ||
1225 | MAILLIB::ATYPE IMAPwrapper::getType()const | 1225 | MAILLIB::ATYPE IMAPwrapper::getType()const |
1226 | { | 1226 | { |
1227 | return account->getType(); | 1227 | return account->getType(); |
1228 | } | 1228 | } |
1229 | 1229 | ||
1230 | const QString&IMAPwrapper::getName()const | 1230 | const QString&IMAPwrapper::getName()const |
1231 | { | 1231 | { |
1232 | // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; | 1232 | // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; |
1233 | return account->getAccountName(); | 1233 | return account->getAccountName(); |
1234 | } | 1234 | } |
1235 | 1235 | ||
1236 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) | 1236 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) |
1237 | { | 1237 | { |
1238 | // dummy | 1238 | // dummy |
1239 | QValueList<int> path; | 1239 | QValueList<int> path; |
1240 | return fetchRawPart(mail,path,false); | 1240 | return fetchRawPart(mail,path,false); |
1241 | } | 1241 | } |
1242 | 1242 | ||
1243 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, | 1243 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, |
1244 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) | 1244 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) |
1245 | { | 1245 | { |
1246 | if (targetWrapper != this || maxSizeInKb > 0 ) { | 1246 | if (targetWrapper != this || maxSizeInKb > 0 ) { |
1247 | mMax = 0; | 1247 | mMax = 0; |
1248 | progress( tr("Copy")); | 1248 | progress( tr("Copy")); |
1249 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); | 1249 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); |
1250 | qDebug("IMAPwrapper::mvcpAllMails::Using generic"); | 1250 | //qDebug("IMAPwrapper::mvcpAllMails::Using generic"); |
1251 | // odebug << "Using generic" << oendl; | 1251 | // odebug << "Using generic" << oendl; |
1252 | return; | 1252 | return; |
1253 | } | 1253 | } |
1254 | mailimap_set *set = 0; | 1254 | mailimap_set *set = 0; |
1255 | login(); | 1255 | login(); |
1256 | if (!m_imap) { | 1256 | if (!m_imap) { |
1257 | return; | 1257 | return; |
1258 | } | 1258 | } |
1259 | int err = selectMbox(fromFolder->getName()); | 1259 | int err = selectMbox(fromFolder->getName()); |
1260 | if ( err != MAILIMAP_NO_ERROR ) { | 1260 | if ( err != MAILIMAP_NO_ERROR ) { |
1261 | return; | 1261 | return; |
1262 | } | 1262 | } |
1263 | Global::statusMessage( tr("Copying mails on server...") ); | 1263 | Global::statusMessage( tr("Copying mails on server...") ); |
1264 | int last = m_imap->imap_selection_info->sel_exists; | 1264 | int last = m_imap->imap_selection_info->sel_exists; |
1265 | set = mailimap_set_new_interval( 1, last ); | 1265 | set = mailimap_set_new_interval( 1, last ); |
1266 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1266 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1267 | mailimap_set_free( set ); | 1267 | mailimap_set_free( set ); |
1268 | if ( err != MAILIMAP_NO_ERROR ) { | 1268 | if ( err != MAILIMAP_NO_ERROR ) { |
1269 | QString error_msg = tr("Error copy mails: %1").arg(m_imap->imap_response); | 1269 | QString error_msg = tr("Error copy mails: %1").arg(m_imap->imap_response); |
1270 | Global::statusMessage(error_msg); | 1270 | Global::statusMessage(error_msg); |
1271 | // odebug << error_msg << oendl; | 1271 | // odebug << error_msg << oendl; |
1272 | return; | 1272 | return; |
1273 | } | 1273 | } |
1274 | if (moveit) { | 1274 | if (moveit) { |
1275 | deleteAllMail(fromFolder); | 1275 | deleteAllMail(fromFolder); |
1276 | } | 1276 | } |
1277 | } | 1277 | } |
1278 | 1278 | ||
1279 | void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 1279 | void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
1280 | { | 1280 | { |
1281 | if (targetWrapper != this) { | 1281 | if (targetWrapper != this) { |
1282 | // odebug << "Using generic" << oendl; | 1282 | // odebug << "Using generic" << oendl; |
1283 | AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); | 1283 | AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); |
1284 | return; | 1284 | return; |
1285 | } | 1285 | } |
1286 | mailimap_set *set = 0; | 1286 | mailimap_set *set = 0; |
1287 | login(); | 1287 | login(); |
1288 | if (!m_imap) { | 1288 | if (!m_imap) { |
1289 | return; | 1289 | return; |
1290 | } | 1290 | } |
1291 | int err = selectMbox(mail->getMbox()); | 1291 | int err = selectMbox(mail->getMbox()); |
1292 | if ( err != MAILIMAP_NO_ERROR ) { | 1292 | if ( err != MAILIMAP_NO_ERROR ) { |
1293 | return; | 1293 | return; |
1294 | } | 1294 | } |
1295 | set = mailimap_set_new_single(mail->getNumber()); | 1295 | set = mailimap_set_new_single(mail->getNumber()); |
1296 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1296 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1297 | mailimap_set_free( set ); | 1297 | mailimap_set_free( set ); |
1298 | if ( err != MAILIMAP_NO_ERROR ) { | 1298 | if ( err != MAILIMAP_NO_ERROR ) { |
1299 | QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); | 1299 | QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); |
1300 | Global::statusMessage(error_msg); | 1300 | Global::statusMessage(error_msg); |
1301 | // odebug << error_msg << oendl; | 1301 | // odebug << error_msg << oendl; |
1302 | return; | 1302 | return; |
1303 | } | 1303 | } |
1304 | if (moveit) { | 1304 | if (moveit) { |
1305 | deleteMail(mail); | 1305 | deleteMail(mail); |
1306 | } | 1306 | } |
1307 | } | 1307 | } |
diff --git a/kmicromail/libmailwrapper/mhwrapper.cpp b/kmicromail/libmailwrapper/mhwrapper.cpp index 962dac0..641d4d9 100644 --- a/kmicromail/libmailwrapper/mhwrapper.cpp +++ b/kmicromail/libmailwrapper/mhwrapper.cpp | |||
@@ -1,293 +1,291 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #include "mhwrapper.h" | 2 | #include "mhwrapper.h" |
3 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
4 | #include "mailwrapper.h" | 4 | #include "mailwrapper.h" |
5 | #include <libetpan/libetpan.h> | 5 | #include <libetpan/libetpan.h> |
6 | #include <qdir.h> | 6 | #include <qdir.h> |
7 | #include <qmessagebox.h> | 7 | #include <qmessagebox.h> |
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | #include <qpe/global.h> | 9 | #include <qpe/global.h> |
10 | #include <oprocess.h> | 10 | #include <oprocess.h> |
11 | //#include <opie2/odebug.h> | 11 | //#include <opie2/odebug.h> |
12 | 12 | ||
13 | using namespace Opie::Core; | 13 | using namespace Opie::Core; |
14 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) | 14 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) |
15 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) | 15 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) |
16 | { | 16 | { |
17 | if (MHPath.length()>0) { | 17 | if (MHPath.length()>0) { |
18 | if (MHPath[MHPath.length()-1]=='/') { | 18 | if (MHPath[MHPath.length()-1]=='/') { |
19 | MHPath=MHPath.left(MHPath.length()-1); | 19 | MHPath=MHPath.left(MHPath.length()-1); |
20 | } | 20 | } |
21 | //odebug << MHPath << oendl; | 21 | //odebug << MHPath << oendl; |
22 | QDir dir(MHPath); | 22 | QDir dir(MHPath); |
23 | if (!dir.exists()) { | 23 | if (!dir.exists()) { |
24 | dir.mkdir(MHPath); | 24 | dir.mkdir(MHPath); |
25 | } | 25 | } |
26 | init_storage(); | 26 | init_storage(); |
27 | } | 27 | } |
28 | } | 28 | } |
29 | 29 | ||
30 | void MHwrapper::init_storage() | 30 | void MHwrapper::init_storage() |
31 | { | 31 | { |
32 | int r; | 32 | int r; |
33 | QString pre = MHPath; | 33 | QString pre = MHPath; |
34 | if (!m_storage) { | 34 | if (!m_storage) { |
35 | m_storage = mailstorage_new(NULL); | 35 | m_storage = mailstorage_new(NULL); |
36 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); | 36 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); |
37 | if (r != MAIL_NO_ERROR) { | 37 | if (r != MAIL_NO_ERROR) { |
38 | qDebug(" error init storage "); | 38 | qDebug(" error init storage "); |
39 | mailstorage_free(m_storage); | 39 | mailstorage_free(m_storage); |
40 | m_storage = 0; | 40 | m_storage = 0; |
41 | return; | 41 | return; |
42 | } | 42 | } |
43 | } | 43 | } |
44 | r = mailstorage_connect(m_storage); | 44 | r = mailstorage_connect(m_storage); |
45 | if (r!=MAIL_NO_ERROR) { | 45 | if (r!=MAIL_NO_ERROR) { |
46 | qDebug("error connecting storage "); | 46 | qDebug("error connecting storage "); |
47 | mailstorage_free(m_storage); | 47 | mailstorage_free(m_storage); |
48 | m_storage = 0; | 48 | m_storage = 0; |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | void MHwrapper::clean_storage() | 52 | void MHwrapper::clean_storage() |
53 | { | 53 | { |
54 | if (m_storage) { | 54 | if (m_storage) { |
55 | mailstorage_disconnect(m_storage); | 55 | mailstorage_disconnect(m_storage); |
56 | mailstorage_free(m_storage); | 56 | mailstorage_free(m_storage); |
57 | m_storage = 0; | 57 | m_storage = 0; |
58 | } | 58 | } |
59 | } | 59 | } |
60 | 60 | ||
61 | MHwrapper::~MHwrapper() | 61 | MHwrapper::~MHwrapper() |
62 | { | 62 | { |
63 | clean_storage(); | 63 | clean_storage(); |
64 | } | 64 | } |
65 | 65 | ||
66 | void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) | 66 | void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) |
67 | { | 67 | { |
68 | qDebug("MHwrapper::listMessages "); | ||
69 | init_storage(); | 68 | init_storage(); |
70 | if (!m_storage) { | 69 | if (!m_storage) { |
71 | return; | 70 | return; |
72 | } | 71 | } |
73 | QString f = buildPath(mailbox); | 72 | QString f = buildPath(mailbox); |
74 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 73 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
75 | if (r!=MAIL_NO_ERROR) { | 74 | if (r!=MAIL_NO_ERROR) { |
76 | qDebug("listMessages: error selecting folder! "); | 75 | qDebug("listMessages: error selecting folder! "); |
77 | return; | 76 | return; |
78 | } | 77 | } |
79 | parseList(target,m_storage->sto_session,f, false, maxSizeInKb ); | 78 | parseList(target,m_storage->sto_session,f, false, maxSizeInKb ); |
80 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); | 79 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); |
81 | } | 80 | } |
82 | 81 | ||
83 | QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() | 82 | QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() |
84 | { | 83 | { |
85 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); | 84 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); |
86 | /* this is needed! */ | 85 | /* this is needed! */ |
87 | if (m_storage) mailstorage_disconnect(m_storage); | 86 | if (m_storage) mailstorage_disconnect(m_storage); |
88 | init_storage(); | 87 | init_storage(); |
89 | if (!m_storage) { | 88 | if (!m_storage) { |
90 | return folders; | 89 | return folders; |
91 | } | 90 | } |
92 | mail_list*flist = 0; | 91 | mail_list*flist = 0; |
93 | clistcell*current=0; | 92 | clistcell*current=0; |
94 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); | 93 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); |
95 | if (r != MAIL_NO_ERROR || !flist) { | 94 | if (r != MAIL_NO_ERROR || !flist) { |
96 | qDebug("error getting folder list "); | 95 | qDebug("error getting folder list "); |
97 | return folders; | 96 | return folders; |
98 | } | 97 | } |
99 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { | 98 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { |
100 | QString t = (char*)current->data; | 99 | QString t = (char*)current->data; |
101 | t.replace(0,MHPath.length(),""); | 100 | t.replace(0,MHPath.length(),""); |
102 | folders->append(new MHFolder(t,MHPath)); | 101 | folders->append(new MHFolder(t,MHPath)); |
103 | } | 102 | } |
104 | mail_list_free(flist); | 103 | mail_list_free(flist); |
105 | return folders; | 104 | return folders; |
106 | } | 105 | } |
107 | 106 | ||
108 | void MHwrapper::deleteMail(const RecMailP&mail) | 107 | void MHwrapper::deleteMail(const RecMailP&mail) |
109 | { | 108 | { |
110 | init_storage(); | 109 | init_storage(); |
111 | if (!m_storage) { | 110 | if (!m_storage) { |
112 | return; | 111 | return; |
113 | } | 112 | } |
114 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 113 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
115 | if (r!=MAIL_NO_ERROR) { | 114 | if (r!=MAIL_NO_ERROR) { |
116 | qDebug("error selecting folder! "); | 115 | qDebug("error selecting folder! "); |
117 | return; | 116 | return; |
118 | } | 117 | } |
119 | r = mailsession_remove_message(m_storage->sto_session,mail->getNumber()); | 118 | r = mailsession_remove_message(m_storage->sto_session,mail->getNumber()); |
120 | if (r != MAIL_NO_ERROR) { | 119 | if (r != MAIL_NO_ERROR) { |
121 | qDebug("error deleting mail "); | 120 | qDebug("error deleting mail "); |
122 | } | 121 | } |
123 | } | 122 | } |
124 | 123 | ||
125 | void MHwrapper::answeredMail(const RecMailP&) | 124 | void MHwrapper::answeredMail(const RecMailP&) |
126 | { | 125 | { |
127 | } | 126 | } |
128 | 127 | ||
129 | RecBodyP MHwrapper::fetchBody( const RecMailP &mail ) | 128 | RecBodyP MHwrapper::fetchBody( const RecMailP &mail ) |
130 | { | 129 | { |
131 | RecBodyP body = new RecBody(); | 130 | RecBodyP body = new RecBody(); |
132 | init_storage(); | 131 | init_storage(); |
133 | if (!m_storage) { | 132 | if (!m_storage) { |
134 | return body; | 133 | return body; |
135 | } | 134 | } |
136 | mailmessage * msg; | 135 | mailmessage * msg; |
137 | char*data=0; | 136 | char*data=0; |
138 | 137 | ||
139 | /* mail should hold the complete path! */ | 138 | /* mail should hold the complete path! */ |
140 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 139 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
141 | if (r != MAIL_NO_ERROR) { | 140 | if (r != MAIL_NO_ERROR) { |
142 | return body; | 141 | return body; |
143 | } | 142 | } |
144 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); | 143 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); |
145 | if (r != MAIL_NO_ERROR) { | 144 | if (r != MAIL_NO_ERROR) { |
146 | qDebug("Error fetching mail "); | 145 | qDebug("Error fetching mail "); |
147 | 146 | ||
148 | return body; | 147 | return body; |
149 | } | 148 | } |
150 | body = parseMail(msg); | 149 | body = parseMail(msg); |
151 | mailmessage_fetch_result_free(msg,data); | 150 | mailmessage_fetch_result_free(msg,data); |
152 | return body; | 151 | return body; |
153 | } | 152 | } |
154 | 153 | ||
155 | void MHwrapper::mbox_progress( size_t current, size_t maximum ) | 154 | void MHwrapper::mbox_progress( size_t current, size_t maximum ) |
156 | { | 155 | { |
157 | qDebug("MBox Progress %d of %d",current,maximum ); | 156 | qDebug("MBox Progress %d of %d",current,maximum ); |
158 | //odebug << "MH " << current << " von " << maximum << "" << oendl; | 157 | //odebug << "MH " << current << " von " << maximum << "" << oendl; |
159 | } | 158 | } |
160 | 159 | ||
161 | QString MHwrapper::buildPath(const QString&p) | 160 | QString MHwrapper::buildPath(const QString&p) |
162 | { | 161 | { |
163 | QString f=""; | 162 | QString f=""; |
164 | if (p.length()==0||p=="/") | 163 | if (p.length()==0||p=="/") |
165 | return MHPath; | 164 | return MHPath; |
166 | if (!p.startsWith(MHPath)) { | 165 | if (!p.startsWith(MHPath)) { |
167 | f+=MHPath; | 166 | f+=MHPath; |
168 | } | 167 | } |
169 | if (!p.startsWith("/")) { | 168 | if (!p.startsWith("/")) { |
170 | f+="/"; | 169 | f+="/"; |
171 | } | 170 | } |
172 | f+=p; | 171 | f+=p; |
173 | return f; | 172 | return f; |
174 | } | 173 | } |
175 | 174 | ||
176 | int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool ) | 175 | int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool ) |
177 | { | 176 | { |
178 | init_storage(); | 177 | init_storage(); |
179 | if (!m_storage) { | 178 | if (!m_storage) { |
180 | return 0; | 179 | return 0; |
181 | } | 180 | } |
182 | QString f; | 181 | QString f; |
183 | if (!pfolder) { | 182 | if (!pfolder) { |
184 | // toplevel folder | 183 | // toplevel folder |
185 | f = buildPath(folder); | 184 | f = buildPath(folder); |
186 | } else { | 185 | } else { |
187 | f = pfolder->getName(); | 186 | f = pfolder->getName(); |
188 | f+="/"; | 187 | f+="/"; |
189 | f+=folder; | 188 | f+=folder; |
190 | } | 189 | } |
191 | 190 | ||
192 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); | 191 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); |
193 | if (r != MAIL_NO_ERROR) { | 192 | if (r != MAIL_NO_ERROR) { |
194 | qDebug("error creating folder "); | 193 | qDebug("error creating folder "); |
195 | return 0; | 194 | return 0; |
196 | } | 195 | } |
197 | qDebug("Folder created "); | ||
198 | return 1; | 196 | return 1; |
199 | } | 197 | } |
200 | 198 | ||
201 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) | 199 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) |
202 | { | 200 | { |
203 | init_storage(); | 201 | init_storage(); |
204 | if (!m_storage) { | 202 | if (!m_storage) { |
205 | return; | 203 | return; |
206 | } | 204 | } |
207 | QString f = buildPath(Folder); | 205 | QString f = buildPath(Folder); |
208 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 206 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
209 | if (r!=MAIL_NO_ERROR) { | 207 | if (r!=MAIL_NO_ERROR) { |
210 | qDebug("error selecting folder! "); | 208 | qDebug("error selecting folder! "); |
211 | return; | 209 | return; |
212 | } | 210 | } |
213 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); | 211 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); |
214 | if (r!=MAIL_NO_ERROR) { | 212 | if (r!=MAIL_NO_ERROR) { |
215 | qDebug("error storing mail "); | 213 | qDebug("error storing mail "); |
216 | } | 214 | } |
217 | return; | 215 | return; |
218 | } | 216 | } |
219 | 217 | ||
220 | encodedString* MHwrapper::fetchRawBody(const RecMailP&mail) | 218 | encodedString* MHwrapper::fetchRawBody(const RecMailP&mail) |
221 | { | 219 | { |
222 | encodedString*result = 0; | 220 | encodedString*result = 0; |
223 | init_storage(); | 221 | init_storage(); |
224 | if (!m_storage) { | 222 | if (!m_storage) { |
225 | return result; | 223 | return result; |
226 | } | 224 | } |
227 | mailmessage * msg = 0; | 225 | mailmessage * msg = 0; |
228 | char*data=0; | 226 | char*data=0; |
229 | size_t size; | 227 | size_t size; |
230 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 228 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
231 | if (r!=MAIL_NO_ERROR) { | 229 | if (r!=MAIL_NO_ERROR) { |
232 | qDebug("error selecting folder! "); | 230 | qDebug("error selecting folder! "); |
233 | return result; | 231 | return result; |
234 | } | 232 | } |
235 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); | 233 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); |
236 | if (r != MAIL_NO_ERROR) { | 234 | if (r != MAIL_NO_ERROR) { |
237 | Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); | 235 | Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); |
238 | return 0; | 236 | return 0; |
239 | } | 237 | } |
240 | r = mailmessage_fetch(msg,&data,&size); | 238 | r = mailmessage_fetch(msg,&data,&size); |
241 | if (r != MAIL_NO_ERROR) { | 239 | if (r != MAIL_NO_ERROR) { |
242 | Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); | 240 | Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); |
243 | if (msg) mailmessage_free(msg); | 241 | if (msg) mailmessage_free(msg); |
244 | return 0; | 242 | return 0; |
245 | } | 243 | } |
246 | result = new encodedString(data,size); | 244 | result = new encodedString(data,size); |
247 | if (msg) mailmessage_free(msg); | 245 | if (msg) mailmessage_free(msg); |
248 | return result; | 246 | return result; |
249 | } | 247 | } |
250 | 248 | ||
251 | void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) | 249 | void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) |
252 | { | 250 | { |
253 | QString f = buildPath(mailbox); | 251 | QString f = buildPath(mailbox); |
254 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 252 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
255 | if (r!=MAIL_NO_ERROR) { | 253 | if (r!=MAIL_NO_ERROR) { |
256 | qDebug("deleteMails: error selecting folder! "); | 254 | qDebug("deleteMails: error selecting folder! "); |
257 | return; | 255 | return; |
258 | } | 256 | } |
259 | QValueList<RecMailP>::ConstIterator it; | 257 | QValueList<RecMailP>::ConstIterator it; |
260 | for (it=target.begin(); it!=target.end();++it) { | 258 | for (it=target.begin(); it!=target.end();++it) { |
261 | r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber()); | 259 | r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber()); |
262 | if (r != MAIL_NO_ERROR) { | 260 | if (r != MAIL_NO_ERROR) { |
263 | qDebug("error deleting mail "); | 261 | qDebug("error deleting mail "); |
264 | break; | 262 | break; |
265 | } | 263 | } |
266 | } | 264 | } |
267 | } | 265 | } |
268 | 266 | ||
269 | int MHwrapper::deleteAllMail(const FolderP&tfolder) | 267 | int MHwrapper::deleteAllMail(const FolderP&tfolder) |
270 | { | 268 | { |
271 | init_storage(); | 269 | init_storage(); |
272 | if (!m_storage) { | 270 | if (!m_storage) { |
273 | return 0; | 271 | return 0; |
274 | } | 272 | } |
275 | int res = 1; | 273 | int res = 1; |
276 | if (!tfolder) return 0; | 274 | if (!tfolder) return 0; |
277 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | 275 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); |
278 | if (r!=MAIL_NO_ERROR) { | 276 | if (r!=MAIL_NO_ERROR) { |
279 | qDebug("error selecting folder! "); | 277 | qDebug("error selecting folder! "); |
280 | return 0; | 278 | return 0; |
281 | } | 279 | } |
282 | mailmessage_list*l=0; | 280 | mailmessage_list*l=0; |
283 | r = mailsession_get_messages_list(m_storage->sto_session,&l); | 281 | r = mailsession_get_messages_list(m_storage->sto_session,&l); |
284 | if (r != MAIL_NO_ERROR) { | 282 | if (r != MAIL_NO_ERROR) { |
285 | qDebug("Error message list "); | 283 | qDebug("Error message list "); |
286 | res = 0; | 284 | res = 0; |
287 | } | 285 | } |
288 | unsigned j = 0; | 286 | unsigned j = 0; |
289 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | 287 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { |
290 | mailmessage * msg; | 288 | mailmessage * msg; |
291 | msg = (mailmessage*)carray_get(l->msg_tab, i); | 289 | msg = (mailmessage*)carray_get(l->msg_tab, i); |
292 | j = msg->msg_index; | 290 | j = msg->msg_index; |
293 | r = mailsession_remove_message(m_storage->sto_session,j); | 291 | r = mailsession_remove_message(m_storage->sto_session,j); |
diff --git a/kmicromail/libmailwrapper/settings.cpp b/kmicromail/libmailwrapper/settings.cpp index 766eba0..40b5591 100644 --- a/kmicromail/libmailwrapper/settings.cpp +++ b/kmicromail/libmailwrapper/settings.cpp | |||
@@ -1,317 +1,315 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <qdir.h> | 2 | #include <qdir.h> |
3 | 3 | ||
4 | //#include <opie2/odebug.h> | 4 | //#include <opie2/odebug.h> |
5 | #include <kconfig.h> | 5 | #include <kconfig.h> |
6 | 6 | ||
7 | #include <kstandarddirs.h> | 7 | #include <kstandarddirs.h> |
8 | #include "settings.h" | 8 | #include "settings.h" |
9 | //#include "defines.h" | 9 | //#include "defines.h" |
10 | 10 | ||
11 | #define IMAP_PORT "143" | 11 | #define IMAP_PORT "143" |
12 | #define IMAP_SSL_PORT "993" | 12 | #define IMAP_SSL_PORT "993" |
13 | #define SMTP_PORT "25" | 13 | #define SMTP_PORT "25" |
14 | #define SMTP_SSL_PORT "465" | 14 | #define SMTP_SSL_PORT "465" |
15 | #define POP3_PORT "110" | 15 | #define POP3_PORT "110" |
16 | #define POP3_SSL_PORT "995" | 16 | #define POP3_SSL_PORT "995" |
17 | #define NNTP_PORT "119" | 17 | #define NNTP_PORT "119" |
18 | #define NNTP_SSL_PORT "563" | 18 | #define NNTP_SSL_PORT "563" |
19 | 19 | ||
20 | 20 | ||
21 | Settings::Settings() | 21 | Settings::Settings() |
22 | : QObject() | 22 | : QObject() |
23 | { | 23 | { |
24 | updateAccounts(); | 24 | updateAccounts(); |
25 | } | 25 | } |
26 | 26 | ||
27 | void Settings::checkDirectory() | 27 | void Settings::checkDirectory() |
28 | { | 28 | { |
29 | qDebug("Settings::checkDirectory() "); | ||
30 | return; | 29 | return; |
31 | locateLocal("data", "kopiemail" ); | 30 | locateLocal("data", "kopiemail" ); |
32 | /* | 31 | /* |
33 | if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { | 32 | if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { |
34 | system( "mkdir -p $HOME/Applications/opiemail" ); | 33 | system( "mkdir -p $HOME/Applications/opiemail" ); |
35 | qDebug("$HOME/Applications/opiemail created "); | 34 | qDebug("$HOME/Applications/opiemail created "); |
36 | } | 35 | } |
37 | */ | 36 | */ |
38 | } | 37 | } |
39 | 38 | ||
40 | QList<Account> Settings::getAccounts() | 39 | QList<Account> Settings::getAccounts() |
41 | { | 40 | { |
42 | return accounts; | 41 | return accounts; |
43 | } | 42 | } |
44 | 43 | ||
45 | void Settings::addAccount( Account *account ) | 44 | void Settings::addAccount( Account *account ) |
46 | { | 45 | { |
47 | accounts.append( account ); | 46 | accounts.append( account ); |
48 | } | 47 | } |
49 | 48 | ||
50 | void Settings::delAccount( Account *account ) | 49 | void Settings::delAccount( Account *account ) |
51 | { | 50 | { |
52 | accounts.remove( account ); | 51 | accounts.remove( account ); |
53 | account->remove(); | 52 | account->remove(); |
54 | } | 53 | } |
55 | 54 | ||
56 | void Settings::updateAccounts() | 55 | void Settings::updateAccounts() |
57 | { | 56 | { |
58 | accounts.clear(); | 57 | accounts.clear(); |
59 | QDir dir( locateLocal("data", "kopiemail" ) ); | 58 | QDir dir( locateLocal("data", "kopiemail" ) ); |
60 | QStringList::Iterator it; | 59 | QStringList::Iterator it; |
61 | 60 | ||
62 | QStringList imap = dir.entryList( "imap-*" ); | 61 | QStringList imap = dir.entryList( "imap-*" ); |
63 | for ( it = imap.begin(); it != imap.end(); it++ ) { | 62 | for ( it = imap.begin(); it != imap.end(); it++ ) { |
64 | IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); | 63 | IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); |
65 | accounts.append( account ); | 64 | accounts.append( account ); |
66 | } | 65 | } |
67 | 66 | ||
68 | QStringList pop3 = dir.entryList( "pop3-*" ); | 67 | QStringList pop3 = dir.entryList( "pop3-*" ); |
69 | for ( it = pop3.begin(); it != pop3.end(); it++ ) { | 68 | for ( it = pop3.begin(); it != pop3.end(); it++ ) { |
70 | POP3account *account = new POP3account( (*it).replace(0, 5, "") ); | 69 | POP3account *account = new POP3account( (*it).replace(0, 5, "") ); |
71 | accounts.append( account ); | 70 | accounts.append( account ); |
72 | } | 71 | } |
73 | 72 | ||
74 | QStringList smtp = dir.entryList( "smtp-*" ); | 73 | QStringList smtp = dir.entryList( "smtp-*" ); |
75 | for ( it = smtp.begin(); it != smtp.end(); it++ ) { | 74 | for ( it = smtp.begin(); it != smtp.end(); it++ ) { |
76 | SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); | 75 | SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); |
77 | accounts.append( account ); | 76 | accounts.append( account ); |
78 | } | 77 | } |
79 | 78 | ||
80 | QStringList nntp = dir.entryList( "nntp-*" ); | 79 | QStringList nntp = dir.entryList( "nntp-*" ); |
81 | for ( it = nntp.begin(); it != nntp.end(); it++ ) { | 80 | for ( it = nntp.begin(); it != nntp.end(); it++ ) { |
82 | NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); | 81 | NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); |
83 | accounts.append( account ); | 82 | accounts.append( account ); |
84 | } | 83 | } |
85 | 84 | ||
86 | readAccounts(); | 85 | readAccounts(); |
87 | } | 86 | } |
88 | 87 | ||
89 | void Settings::saveAccounts() | 88 | void Settings::saveAccounts() |
90 | { | 89 | { |
91 | checkDirectory(); | 90 | checkDirectory(); |
92 | Account *it; | 91 | Account *it; |
93 | 92 | ||
94 | for ( it = accounts.first(); it; it = accounts.next() ) { | 93 | for ( it = accounts.first(); it; it = accounts.next() ) { |
95 | it->save(); | 94 | it->save(); |
96 | } | 95 | } |
97 | } | 96 | } |
98 | 97 | ||
99 | void Settings::readAccounts() | 98 | void Settings::readAccounts() |
100 | { | 99 | { |
101 | checkDirectory(); | 100 | checkDirectory(); |
102 | Account *it; | 101 | Account *it; |
103 | 102 | ||
104 | for ( it = accounts.first(); it; it = accounts.next() ) { | 103 | for ( it = accounts.first(); it; it = accounts.next() ) { |
105 | it->read(); | 104 | it->read(); |
106 | } | 105 | } |
107 | } | 106 | } |
108 | 107 | ||
109 | Account::Account() | 108 | Account::Account() |
110 | { | 109 | { |
111 | accountName = "changeMe"; | 110 | accountName = "changeMe"; |
112 | type = MAILLIB::A_UNDEFINED; | 111 | type = MAILLIB::A_UNDEFINED; |
113 | ssl = false; | 112 | ssl = false; |
114 | connectionType = 1; | 113 | connectionType = 1; |
115 | offline = false; | 114 | offline = false; |
116 | maxMailSize = 0; | 115 | maxMailSize = 0; |
117 | lastFetch; | 116 | lastFetch; |
118 | leaveOnServer = false; | 117 | leaveOnServer = false; |
119 | } | 118 | } |
120 | 119 | ||
121 | void Account::remove() | 120 | void Account::remove() |
122 | { | 121 | { |
123 | QFile file( getFileName() ); | 122 | QFile file( getFileName() ); |
124 | file.remove(); | 123 | file.remove(); |
125 | } | 124 | } |
126 | 125 | ||
127 | void Account::setPasswordList(const QStringList &str) | 126 | void Account::setPasswordList(const QStringList &str) |
128 | { | 127 | { |
129 | password = ""; | 128 | password = ""; |
130 | int i; | 129 | int i; |
131 | for ( i = 0; i < str.count() ; ++i ) { | 130 | for ( i = 0; i < str.count() ; ++i ) { |
132 | QChar c ( (str[i].toUInt()-131)/(str.count()- (i%3))); | 131 | QChar c ( (str[i].toUInt()-131)/(str.count()- (i%3))); |
133 | password.append( c ); | 132 | password.append( c ); |
134 | } | 133 | } |
135 | //qDebug("password %s ", password.latin1()); | 134 | //qDebug("password %s ", password.latin1()); |
136 | } | 135 | } |
137 | QStringList Account::getPasswordList() | 136 | QStringList Account::getPasswordList() |
138 | { | 137 | { |
139 | int i; | 138 | int i; |
140 | int len = password.length(); | 139 | int len = password.length(); |
141 | QStringList str; | 140 | QStringList str; |
142 | 141 | ||
143 | for ( i = 0; i < len ; ++i ) { | 142 | for ( i = 0; i < len ; ++i ) { |
144 | int val = password.at(i).unicode()*(len-(i%3))+131; | 143 | int val = password.at(i).unicode()*(len-(i%3))+131; |
145 | str.append( QString::number( val ) ); | 144 | str.append( QString::number( val ) ); |
146 | // qDebug("append %s ", str[i].latin1()); | 145 | // qDebug("append %s ", str[i].latin1()); |
147 | } | 146 | } |
148 | return str; | 147 | return str; |
149 | } | 148 | } |
150 | 149 | ||
151 | IMAPaccount::IMAPaccount() | 150 | IMAPaccount::IMAPaccount() |
152 | : Account() | 151 | : Account() |
153 | { | 152 | { |
154 | file = IMAPaccount::getUniqueFileName(); | 153 | file = IMAPaccount::getUniqueFileName(); |
155 | accountName = "New IMAP Account"; | 154 | accountName = "New IMAP Account"; |
156 | ssl = false; | 155 | ssl = false; |
157 | connectionType = 1; | 156 | connectionType = 1; |
158 | type = MAILLIB::A_IMAP; | 157 | type = MAILLIB::A_IMAP; |
159 | port = IMAP_PORT; | 158 | port = IMAP_PORT; |
160 | } | 159 | } |
161 | 160 | ||
162 | IMAPaccount::IMAPaccount( QString filename ) | 161 | IMAPaccount::IMAPaccount( QString filename ) |
163 | : Account() | 162 | : Account() |
164 | { | 163 | { |
165 | file = filename; | 164 | file = filename; |
166 | accountName = "New IMAP Account"; | 165 | accountName = "New IMAP Account"; |
167 | ssl = false; | 166 | ssl = false; |
168 | connectionType = 1; | 167 | connectionType = 1; |
169 | type = MAILLIB::A_IMAP; | 168 | type = MAILLIB::A_IMAP; |
170 | port = IMAP_PORT; | 169 | port = IMAP_PORT; |
171 | } | 170 | } |
172 | 171 | ||
173 | QString IMAPaccount::getUniqueFileName() | 172 | QString IMAPaccount::getUniqueFileName() |
174 | { | 173 | { |
175 | int num = 0; | 174 | int num = 0; |
176 | QString unique; | 175 | QString unique; |
177 | 176 | ||
178 | QDir dir( locateLocal("data", "kopiemail" ) ); | 177 | QDir dir( locateLocal("data", "kopiemail" ) ); |
179 | 178 | ||
180 | QStringList imap = dir.entryList( "imap-*" ); | 179 | QStringList imap = dir.entryList( "imap-*" ); |
181 | do { | 180 | do { |
182 | unique.setNum( num++ ); | 181 | unique.setNum( num++ ); |
183 | } while ( imap.contains( "imap-" + unique ) > 0 ); | 182 | } while ( imap.contains( "imap-" + unique ) > 0 ); |
184 | 183 | ||
185 | return unique; | 184 | return unique; |
186 | } | 185 | } |
187 | 186 | ||
188 | void IMAPaccount::read() | 187 | void IMAPaccount::read() |
189 | { | 188 | { |
190 | KConfig *conf = new KConfig( getFileName() ); | 189 | KConfig *conf = new KConfig( getFileName() ); |
191 | conf->setGroup( "IMAP Account" ); | 190 | conf->setGroup( "IMAP Account" ); |
192 | accountName = conf->readEntry( "Account","" ); | 191 | accountName = conf->readEntry( "Account","" ); |
193 | if (accountName.isNull()) accountName = ""; | 192 | if (accountName.isNull()) accountName = ""; |
194 | server = conf->readEntry( "Server","" ); | 193 | server = conf->readEntry( "Server","" ); |
195 | if (server.isNull()) server=""; | 194 | if (server.isNull()) server=""; |
196 | port = conf->readEntry( "Port","" ); | 195 | port = conf->readEntry( "Port","" ); |
197 | if (port.isNull()) port="143"; | 196 | if (port.isNull()) port="143"; |
198 | connectionType = conf->readNumEntry( "ConnectionType" ); | 197 | connectionType = conf->readNumEntry( "ConnectionType" ); |
199 | ssl = conf->readBoolEntry( "SSL",false ); | 198 | ssl = conf->readBoolEntry( "SSL",false ); |
200 | user = conf->readEntry( "User","" ); | 199 | user = conf->readEntry( "User","" ); |
201 | if (user.isNull()) user = ""; | 200 | if (user.isNull()) user = ""; |
202 | //password = conf->readEntryCrypt( "Password","" ); | 201 | //password = conf->readEntryCrypt( "Password","" ); |
203 | setPasswordList( conf->readListEntry( "FolderHistory")); | 202 | setPasswordList( conf->readListEntry( "FolderHistory")); |
204 | if (password.isNull()) password = ""; | 203 | if (password.isNull()) password = ""; |
205 | prefix = conf->readEntry("MailPrefix",""); | 204 | prefix = conf->readEntry("MailPrefix",""); |
206 | if (prefix.isNull()) prefix = ""; | 205 | if (prefix.isNull()) prefix = ""; |
207 | offline = conf->readBoolEntry("Offline",false); | 206 | offline = conf->readBoolEntry("Offline",false); |
208 | localFolder = conf->readEntry( "LocalFolder" ); | 207 | localFolder = conf->readEntry( "LocalFolder" ); |
209 | maxMailSize = conf->readNumEntry( "MaxSize",0 ); | 208 | maxMailSize = conf->readNumEntry( "MaxSize",0 ); |
210 | int lf = conf->readNumEntry( "LastFetch",0 ); | 209 | int lf = conf->readNumEntry( "LastFetch",0 ); |
211 | QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); | 210 | QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); |
212 | leaveOnServer = conf->readBoolEntry("LeaveOnServer",false); | 211 | leaveOnServer = conf->readBoolEntry("LeaveOnServer",false); |
213 | qDebug("reading last fetch: %d ", lf); | ||
214 | if ( lf < 0 ) lf = 0; | 212 | if ( lf < 0 ) lf = 0; |
215 | lastFetch = dt.addSecs( lf ); | 213 | lastFetch = dt.addSecs( lf ); |
216 | delete conf; | 214 | delete conf; |
217 | } | 215 | } |
218 | 216 | ||
219 | void IMAPaccount::save() | 217 | void IMAPaccount::save() |
220 | { | 218 | { |
221 | qDebug("saving %s ",getFileName().latin1() ); | 219 | |
222 | Settings::checkDirectory(); | 220 | Settings::checkDirectory(); |
223 | 221 | ||
224 | KConfig *conf = new KConfig( getFileName() ); | 222 | KConfig *conf = new KConfig( getFileName() ); |
225 | conf->setGroup( "IMAP Account" ); | 223 | conf->setGroup( "IMAP Account" ); |
226 | conf->writeEntry( "Account", accountName ); | 224 | conf->writeEntry( "Account", accountName ); |
227 | conf->writeEntry( "Server", server ); | 225 | conf->writeEntry( "Server", server ); |
228 | conf->writeEntry( "Port", port ); | 226 | conf->writeEntry( "Port", port ); |
229 | conf->writeEntry( "SSL", ssl ); | 227 | conf->writeEntry( "SSL", ssl ); |
230 | conf->writeEntry( "ConnectionType", connectionType ); | 228 | conf->writeEntry( "ConnectionType", connectionType ); |
231 | conf->writeEntry( "User", user ); | 229 | conf->writeEntry( "User", user ); |
232 | //conf->writeEntryCrypt( "Password", password ); | 230 | //conf->writeEntryCrypt( "Password", password ); |
233 | conf->writeEntry( "FolderHistory",getPasswordList() ); | 231 | conf->writeEntry( "FolderHistory",getPasswordList() ); |
234 | conf->writeEntry( "MailPrefix",prefix); | 232 | conf->writeEntry( "MailPrefix",prefix); |
235 | conf->writeEntry( "Offline",offline); | 233 | conf->writeEntry( "Offline",offline); |
236 | conf->writeEntry( "LocalFolder", localFolder ); | 234 | conf->writeEntry( "LocalFolder", localFolder ); |
237 | conf->writeEntry( "MaxSize", maxMailSize ); | 235 | conf->writeEntry( "MaxSize", maxMailSize ); |
238 | QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); | 236 | QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); |
239 | int lf = dt.secsTo ( lastFetch ); | 237 | int lf = dt.secsTo ( lastFetch ); |
240 | conf->writeEntry( "LastFetch", lf ); | 238 | conf->writeEntry( "LastFetch", lf ); |
241 | conf->writeEntry( "LeaveOnServer", leaveOnServer); | 239 | conf->writeEntry( "LeaveOnServer", leaveOnServer); |
242 | conf->sync(); | 240 | conf->sync(); |
243 | delete conf; | 241 | delete conf; |
244 | } | 242 | } |
245 | 243 | ||
246 | 244 | ||
247 | QString IMAPaccount::getFileName() | 245 | QString IMAPaccount::getFileName() |
248 | { | 246 | { |
249 | return locateLocal("data", "kopiemail" ) +"/imap-" + file; | 247 | return locateLocal("data", "kopiemail" ) +"/imap-" + file; |
250 | } | 248 | } |
251 | 249 | ||
252 | POP3account::POP3account() | 250 | POP3account::POP3account() |
253 | : Account() | 251 | : Account() |
254 | { | 252 | { |
255 | file = POP3account::getUniqueFileName(); | 253 | file = POP3account::getUniqueFileName(); |
256 | accountName = "New POP3 Account"; | 254 | accountName = "New POP3 Account"; |
257 | ssl = false; | 255 | ssl = false; |
258 | connectionType = 1; | 256 | connectionType = 1; |
259 | type = MAILLIB::A_POP3; | 257 | type = MAILLIB::A_POP3; |
260 | port = POP3_PORT; | 258 | port = POP3_PORT; |
261 | } | 259 | } |
262 | 260 | ||
263 | POP3account::POP3account( QString filename ) | 261 | POP3account::POP3account( QString filename ) |
264 | : Account() | 262 | : Account() |
265 | { | 263 | { |
266 | file = filename; | 264 | file = filename; |
267 | accountName = "New POP3 Account"; | 265 | accountName = "New POP3 Account"; |
268 | ssl = false; | 266 | ssl = false; |
269 | connectionType = 1; | 267 | connectionType = 1; |
270 | type = MAILLIB::A_POP3; | 268 | type = MAILLIB::A_POP3; |
271 | port = POP3_PORT; | 269 | port = POP3_PORT; |
272 | } | 270 | } |
273 | 271 | ||
274 | QString POP3account::getUniqueFileName() | 272 | QString POP3account::getUniqueFileName() |
275 | { | 273 | { |
276 | int num = 0; | 274 | int num = 0; |
277 | QString unique; | 275 | QString unique; |
278 | 276 | ||
279 | QDir dir( locateLocal("data", "kopiemail" ) ); | 277 | QDir dir( locateLocal("data", "kopiemail" ) ); |
280 | 278 | ||
281 | QStringList imap = dir.entryList( "pop3-*" ); | 279 | QStringList imap = dir.entryList( "pop3-*" ); |
282 | do { | 280 | do { |
283 | unique.setNum( num++ ); | 281 | unique.setNum( num++ ); |
284 | } while ( imap.contains( "pop3-" + unique ) > 0 ); | 282 | } while ( imap.contains( "pop3-" + unique ) > 0 ); |
285 | 283 | ||
286 | return unique; | 284 | return unique; |
287 | } | 285 | } |
288 | 286 | ||
289 | void POP3account::read() | 287 | void POP3account::read() |
290 | { | 288 | { |
291 | KConfig *conf = new KConfig( getFileName()); | 289 | KConfig *conf = new KConfig( getFileName()); |
292 | conf->setGroup( "POP3 Account" ); | 290 | conf->setGroup( "POP3 Account" ); |
293 | accountName = conf->readEntry( "Account" ); | 291 | accountName = conf->readEntry( "Account" ); |
294 | server = conf->readEntry( "Server" ); | 292 | server = conf->readEntry( "Server" ); |
295 | port = conf->readEntry( "Port" ); | 293 | port = conf->readEntry( "Port" ); |
296 | ssl = conf->readBoolEntry( "SSL" ); | 294 | ssl = conf->readBoolEntry( "SSL" ); |
297 | connectionType = conf->readNumEntry( "ConnectionType" ); | 295 | connectionType = conf->readNumEntry( "ConnectionType" ); |
298 | user = conf->readEntry( "User" ); | 296 | user = conf->readEntry( "User" ); |
299 | //password = conf->readEntryCrypt( "Password" ); | 297 | //password = conf->readEntryCrypt( "Password" ); |
300 | setPasswordList( conf->readListEntry( "FolderHistory")); | 298 | setPasswordList( conf->readListEntry( "FolderHistory")); |
301 | offline = conf->readBoolEntry("Offline",false); | 299 | offline = conf->readBoolEntry("Offline",false); |
302 | localFolder = conf->readEntry( "LocalFolder" ); | 300 | localFolder = conf->readEntry( "LocalFolder" ); |
303 | maxMailSize = conf->readNumEntry( "MaxSize",0 ); | 301 | maxMailSize = conf->readNumEntry( "MaxSize",0 ); |
304 | int lf = conf->readNumEntry( "LastFetch",0 ); | 302 | int lf = conf->readNumEntry( "LastFetch",0 ); |
305 | QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); | 303 | QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); |
306 | leaveOnServer = conf->readBoolEntry("LeaveOnServer",false); | 304 | leaveOnServer = conf->readBoolEntry("LeaveOnServer",false); |
307 | lastFetch = dt.addSecs( lf ); | 305 | lastFetch = dt.addSecs( lf ); |
308 | delete conf; | 306 | delete conf; |
309 | } | 307 | } |
310 | 308 | ||
311 | void POP3account::save() | 309 | void POP3account::save() |
312 | { | 310 | { |
313 | Settings::checkDirectory(); | 311 | Settings::checkDirectory(); |
314 | 312 | ||
315 | KConfig *conf = new KConfig( getFileName() ); | 313 | KConfig *conf = new KConfig( getFileName() ); |
316 | conf->setGroup( "POP3 Account" ); | 314 | conf->setGroup( "POP3 Account" ); |
317 | conf->writeEntry( "Account", accountName ); | 315 | conf->writeEntry( "Account", accountName ); |