-rw-r--r-- | kmicromail/libmailwrapper/mhwrapper.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/kmicromail/libmailwrapper/mhwrapper.cpp b/kmicromail/libmailwrapper/mhwrapper.cpp index 982d7a6..787e85d 100644 --- a/kmicromail/libmailwrapper/mhwrapper.cpp +++ b/kmicromail/libmailwrapper/mhwrapper.cpp | |||
@@ -83,229 +83,236 @@ void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSm | |||
83 | QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() | 83 | QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() |
84 | { | 84 | { |
85 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); | 85 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); |
86 | /* this is needed! */ | 86 | /* this is needed! */ |
87 | if (m_storage) mailstorage_disconnect(m_storage); | 87 | if (m_storage) mailstorage_disconnect(m_storage); |
88 | init_storage(); | 88 | init_storage(); |
89 | if (!m_storage) { | 89 | if (!m_storage) { |
90 | return folders; | 90 | return folders; |
91 | } | 91 | } |
92 | mail_list*flist = 0; | 92 | mail_list*flist = 0; |
93 | clistcell*current=0; | 93 | clistcell*current=0; |
94 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); | 94 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); |
95 | if (r != MAIL_NO_ERROR || !flist) { | 95 | if (r != MAIL_NO_ERROR || !flist) { |
96 | qDebug("error getting folder list "); | 96 | qDebug("error getting folder list "); |
97 | return folders; | 97 | return folders; |
98 | } | 98 | } |
99 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { | 99 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { |
100 | QString t = (char*)current->data; | 100 | QString t = (char*)current->data; |
101 | t.replace(0,MHPath.length(),""); | 101 | t.replace(0,MHPath.length(),""); |
102 | folders->append(new MHFolder(t,MHPath)); | 102 | folders->append(new MHFolder(t,MHPath)); |
103 | } | 103 | } |
104 | mail_list_free(flist); | 104 | mail_list_free(flist); |
105 | return folders; | 105 | return folders; |
106 | } | 106 | } |
107 | 107 | ||
108 | void MHwrapper::deleteMail(const RecMailP&mail) | 108 | void MHwrapper::deleteMail(const RecMailP&mail) |
109 | { | 109 | { |
110 | init_storage(); | 110 | init_storage(); |
111 | if (!m_storage) { | 111 | if (!m_storage) { |
112 | return; | 112 | return; |
113 | } | 113 | } |
114 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 114 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
115 | if (r!=MAIL_NO_ERROR) { | 115 | if (r!=MAIL_NO_ERROR) { |
116 | qDebug("error selecting folder! "); | 116 | qDebug("error selecting folder! "); |
117 | return; | 117 | return; |
118 | } | 118 | } |
119 | r = mailsession_remove_message(m_storage->sto_session,mail->getNumber()); | 119 | r = mailsession_remove_message(m_storage->sto_session,mail->getNumber()); |
120 | if (r != MAIL_NO_ERROR) { | 120 | if (r != MAIL_NO_ERROR) { |
121 | qDebug("error deleting mail "); | 121 | qDebug("error deleting mail "); |
122 | } | 122 | } |
123 | } | 123 | } |
124 | 124 | ||
125 | void MHwrapper::answeredMail(const RecMailP&) | 125 | void MHwrapper::answeredMail(const RecMailP&) |
126 | { | 126 | { |
127 | } | 127 | } |
128 | 128 | ||
129 | RecBodyP MHwrapper::fetchBody( const RecMailP &mail ) | 129 | RecBodyP MHwrapper::fetchBody( const RecMailP &mail ) |
130 | { | 130 | { |
131 | qDebug("MHwrapper::fetchBody "); | 131 | qDebug("MHwrapper::fetchBody "); |
132 | RecBodyP body = new RecBody(); | 132 | RecBodyP body = new RecBody(); |
133 | init_storage(); | 133 | init_storage(); |
134 | if (!m_storage) { | 134 | if (!m_storage) { |
135 | return body; | 135 | return body; |
136 | } | 136 | } |
137 | mailmessage * msg; | 137 | mailmessage * msg; |
138 | char*data=0; | 138 | char*data=0; |
139 | 139 | ||
140 | /* mail should hold the complete path! */ | 140 | /* mail should hold the complete path! */ |
141 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 141 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
142 | if (r != MAIL_NO_ERROR) { | 142 | if (r != MAIL_NO_ERROR) { |
143 | return body; | 143 | return body; |
144 | } | 144 | } |
145 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); | 145 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); |
146 | if (r != MAIL_NO_ERROR) { | 146 | if (r != MAIL_NO_ERROR) { |
147 | qDebug("Error fetching mail "); | 147 | qDebug("Error fetching mail "); |
148 | 148 | ||
149 | return body; | 149 | return body; |
150 | } | 150 | } |
151 | body = parseMail(msg); | 151 | body = parseMail(msg); |
152 | mailmessage_fetch_result_free(msg,data); | 152 | mailmessage_fetch_result_free(msg,data); |
153 | return body; | 153 | return body; |
154 | } | 154 | } |
155 | 155 | ||
156 | void MHwrapper::mbox_progress( size_t current, size_t maximum ) | 156 | void MHwrapper::mbox_progress( size_t current, size_t maximum ) |
157 | { | 157 | { |
158 | qDebug("MBox Progress %d of %d",current,maximum ); | 158 | qDebug("MBox Progress %d of %d",current,maximum ); |
159 | //odebug << "MH " << current << " von " << maximum << "" << oendl; | 159 | //odebug << "MH " << current << " von " << maximum << "" << oendl; |
160 | } | 160 | } |
161 | 161 | ||
162 | QString MHwrapper::buildPath(const QString&p) | 162 | QString MHwrapper::buildPath(const QString&p) |
163 | { | 163 | { |
164 | QString f=""; | 164 | QString f=""; |
165 | if (p.length()==0||p=="/") | 165 | if (p.length()==0||p=="/") |
166 | return MHPath; | 166 | return MHPath; |
167 | if (!p.startsWith(MHPath)) { | 167 | if (!p.startsWith(MHPath)) { |
168 | f+=MHPath; | 168 | f+=MHPath; |
169 | } | 169 | } |
170 | if (!p.startsWith("/")) { | 170 | if (!p.startsWith("/")) { |
171 | f+="/"; | 171 | f+="/"; |
172 | } | 172 | } |
173 | f+=p; | 173 | f+=p; |
174 | return f; | 174 | return f; |
175 | } | 175 | } |
176 | 176 | ||
177 | int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool ) | 177 | int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool ) |
178 | { | 178 | { |
179 | init_storage(); | 179 | |
180 | if (!m_storage) { | ||
181 | return 0; | ||
182 | } | ||
183 | QString f; | 180 | QString f; |
184 | if (!pfolder) { | 181 | if (!pfolder) { |
185 | // toplevel folder | 182 | // toplevel folder |
186 | f = buildPath(folder); | 183 | f = buildPath(folder); |
187 | } else { | 184 | } else { |
188 | f = pfolder->getName(); | 185 | f = pfolder->getName(); |
189 | f+="/"; | 186 | f+="/"; |
190 | f+=folder; | 187 | f+=folder; |
191 | } | 188 | } |
192 | 189 | QFileInfo fi ( f ); | |
190 | if ( fi. exists () ) { | ||
191 | qDebug("folder exists "); | ||
192 | return 1; | ||
193 | } | ||
194 | qDebug("creating folder ---%s--- ",f.latin1() ); | ||
195 | init_storage(); | ||
196 | if (!m_storage) { | ||
197 | return 0; | ||
198 | } | ||
193 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); | 199 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); |
194 | if (r != MAIL_NO_ERROR) { | 200 | if (r != MAIL_NO_ERROR) { |
195 | qDebug("error creating folder "); | 201 | qDebug("error %d creating folder %s", r, f.latin1()); |
196 | return 0; | 202 | return 0; |
197 | } | 203 | } |
198 | return 1; | 204 | return 1; |
199 | } | 205 | } |
200 | 206 | ||
201 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) | 207 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) |
202 | { | 208 | { |
203 | init_storage(); | 209 | init_storage(); |
204 | if (!m_storage) { | 210 | if (!m_storage) { |
205 | return; | 211 | return; |
206 | } | 212 | } |
207 | QString f = buildPath(Folder); | 213 | QString f = buildPath(Folder); |
208 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 214 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
209 | if (r!=MAIL_NO_ERROR) { | 215 | if (r!=MAIL_NO_ERROR) { |
210 | qDebug("error selecting folder! "); | 216 | qDebug("error selecting folder %d", r); |
211 | return; | 217 | return; |
212 | } | 218 | } |
213 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); | 219 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); |
214 | if (r!=MAIL_NO_ERROR) { | 220 | if (r!=MAIL_NO_ERROR) { |
215 | qDebug("error storing mail "); | 221 | if ( r != MAIL_ERROR_APPEND ) |
222 | qDebug("error storing mail %d", r); | ||
216 | } | 223 | } |
217 | return; | 224 | return; |
218 | } | 225 | } |
219 | 226 | ||
220 | encodedString* MHwrapper::fetchRawBody(const RecMailP&mail) | 227 | encodedString* MHwrapper::fetchRawBody(const RecMailP&mail) |
221 | { | 228 | { |
222 | encodedString*result = 0; | 229 | encodedString*result = 0; |
223 | init_storage(); | 230 | init_storage(); |
224 | if (!m_storage) { | 231 | if (!m_storage) { |
225 | return result; | 232 | return result; |
226 | } | 233 | } |
227 | mailmessage * msg = 0; | 234 | mailmessage * msg = 0; |
228 | char*data=0; | 235 | char*data=0; |
229 | size_t size; | 236 | size_t size; |
230 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 237 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
231 | if (r!=MAIL_NO_ERROR) { | 238 | if (r!=MAIL_NO_ERROR) { |
232 | qDebug("error selecting folder! "); | 239 | qDebug("error selecting folder! "); |
233 | return result; | 240 | return result; |
234 | } | 241 | } |
235 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); | 242 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); |
236 | if (r != MAIL_NO_ERROR) { | 243 | if (r != MAIL_NO_ERROR) { |
237 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); | 244 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); |
238 | return 0; | 245 | return 0; |
239 | } | 246 | } |
240 | r = mailmessage_fetch(msg,&data,&size); | 247 | r = mailmessage_fetch(msg,&data,&size); |
241 | if (r != MAIL_NO_ERROR) { | 248 | if (r != MAIL_NO_ERROR) { |
242 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); | 249 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); |
243 | if (msg) mailmessage_free(msg); | 250 | if (msg) mailmessage_free(msg); |
244 | return 0; | 251 | return 0; |
245 | } | 252 | } |
246 | result = new encodedString(data,size); | 253 | result = new encodedString(data,size); |
247 | if (msg) mailmessage_free(msg); | 254 | if (msg) mailmessage_free(msg); |
248 | return result; | 255 | return result; |
249 | } | 256 | } |
250 | 257 | ||
251 | void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) | 258 | void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) |
252 | { | 259 | { |
253 | QString f = buildPath(mailbox); | 260 | QString f = buildPath(mailbox); |
254 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 261 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
255 | if (r!=MAIL_NO_ERROR) { | 262 | if (r!=MAIL_NO_ERROR) { |
256 | qDebug("deleteMails: error selecting folder! "); | 263 | qDebug("deleteMails: error selecting folder! "); |
257 | return; | 264 | return; |
258 | } | 265 | } |
259 | QValueList<RecMailP>::ConstIterator it; | 266 | QValueList<RecMailP>::ConstIterator it; |
260 | for (it=target.begin(); it!=target.end();++it) { | 267 | for (it=target.begin(); it!=target.end();++it) { |
261 | r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber()); | 268 | r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber()); |
262 | if (r != MAIL_NO_ERROR) { | 269 | if (r != MAIL_NO_ERROR) { |
263 | qDebug("error deleting mail "); | 270 | qDebug("error deleting mail "); |
264 | break; | 271 | break; |
265 | } | 272 | } |
266 | } | 273 | } |
267 | } | 274 | } |
268 | 275 | ||
269 | int MHwrapper::deleteAllMail(const FolderP&tfolder) | 276 | int MHwrapper::deleteAllMail(const FolderP&tfolder) |
270 | { | 277 | { |
271 | init_storage(); | 278 | init_storage(); |
272 | if (!m_storage) { | 279 | if (!m_storage) { |
273 | return 0; | 280 | return 0; |
274 | } | 281 | } |
275 | int res = 1; | 282 | int res = 1; |
276 | if (!tfolder) return 0; | 283 | if (!tfolder) return 0; |
277 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | 284 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); |
278 | if (r!=MAIL_NO_ERROR) { | 285 | if (r!=MAIL_NO_ERROR) { |
279 | qDebug("error selecting folder! "); | 286 | qDebug("error selecting folder! "); |
280 | return 0; | 287 | return 0; |
281 | } | 288 | } |
282 | mailmessage_list*l=0; | 289 | mailmessage_list*l=0; |
283 | r = mailsession_get_messages_list(m_storage->sto_session,&l); | 290 | r = mailsession_get_messages_list(m_storage->sto_session,&l); |
284 | if (r != MAIL_NO_ERROR) { | 291 | if (r != MAIL_NO_ERROR) { |
285 | qDebug("Error message list "); | 292 | qDebug("Error message list "); |
286 | res = 0; | 293 | res = 0; |
287 | } | 294 | } |
288 | unsigned j = 0; | 295 | unsigned j = 0; |
289 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | 296 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { |
290 | mailmessage * msg; | 297 | mailmessage * msg; |
291 | msg = (mailmessage*)carray_get(l->msg_tab, i); | 298 | msg = (mailmessage*)carray_get(l->msg_tab, i); |
292 | j = msg->msg_index; | 299 | j = msg->msg_index; |
293 | r = mailsession_remove_message(m_storage->sto_session,j); | 300 | r = mailsession_remove_message(m_storage->sto_session,j); |
294 | if (r != MAIL_NO_ERROR) { | 301 | if (r != MAIL_NO_ERROR) { |
295 | Global::statusMessage(i18n("Error deleting mail %1").arg(i+1)); | 302 | Global::statusMessage(i18n("Error deleting mail %1").arg(i+1)); |
296 | res = 0; | 303 | res = 0; |
297 | break; | 304 | break; |
298 | } | 305 | } |
299 | } | 306 | } |
300 | if (l) mailmessage_list_free(l); | 307 | if (l) mailmessage_list_free(l); |
301 | return res; | 308 | return res; |
302 | } | 309 | } |
303 | bool MHwrapper::rmDir(QString folder) // absolute path! | 310 | bool MHwrapper::rmDir(QString folder) // absolute path! |
304 | { | 311 | { |
305 | QDir dir ( folder ); | 312 | QDir dir ( folder ); |
306 | if ( !dir.exists() ) | 313 | if ( !dir.exists() ) |
307 | return false; | 314 | return false; |
308 | int i; | 315 | int i; |
309 | // qDebug("rmdir %s ",folder.latin1()); | 316 | // qDebug("rmdir %s ",folder.latin1()); |
310 | QStringList list = dir.entryList(QDir::Dirs|QDir::Files|QDir::NoSymLinks|QDir::Hidden ); | 317 | QStringList list = dir.entryList(QDir::Dirs|QDir::Files|QDir::NoSymLinks|QDir::Hidden ); |
311 | for (i=0; i<list.count(); i++ ) { | 318 | for (i=0; i<list.count(); i++ ) { |