summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper
authorzautrix <zautrix>2004-10-31 08:38:17 (UTC)
committer zautrix <zautrix>2004-10-31 08:38:17 (UTC)
commitf77a9457e676a11520c8f52b33265cd825db0c79 (patch) (unidiff)
treed35fc3ef29edf54f413c40621ae760407f659d0c /kmicromail/libmailwrapper
parentc48af43f15e8917a441fc8ca4e1bc3adfd1d822e (diff)
downloadkdepimpi-f77a9457e676a11520c8f52b33265cd825db0c79.zip
kdepimpi-f77a9457e676a11520c8f52b33265cd825db0c79.tar.gz
kdepimpi-f77a9457e676a11520c8f52b33265cd825db0c79.tar.bz2
added delete dir to ompi
Diffstat (limited to 'kmicromail/libmailwrapper') (more/less context) (show whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp3
-rw-r--r--kmicromail/libmailwrapper/mhwrapper.cpp55
-rw-r--r--kmicromail/libmailwrapper/mhwrapper.h1
3 files changed, 35 insertions, 24 deletions
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp
index 3aec13d..110583f 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -128,98 +128,99 @@ void IMAPwrapper::login()
128 uint16_t port; 128 uint16_t port;
129 int err = MAILIMAP_NO_ERROR; 129 int err = MAILIMAP_NO_ERROR;
130 130
131 if (account->getOffline()) return; 131 if (account->getOffline()) return;
132 /* we are connected this moment */ 132 /* we are connected this moment */
133 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 133 /* TODO: setup a timer holding the line or if connection closed - delete the value */
134 if (m_imap) { 134 if (m_imap) {
135 err = mailimap_noop(m_imap); 135 err = mailimap_noop(m_imap);
136 if (err!=MAILIMAP_NO_ERROR) { 136 if (err!=MAILIMAP_NO_ERROR) {
137 logout(); 137 logout();
138 } else { 138 } else {
139 mailstream_flush(m_imap->imap_stream); 139 mailstream_flush(m_imap->imap_stream);
140 return; 140 return;
141 } 141 }
142 } 142 }
143 server = account->getServer(); 143 server = account->getServer();
144 port = account->getPort().toUInt(); 144 port = account->getPort().toUInt();
145 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 145 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
146 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 146 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
147 login.show(); 147 login.show();
148 if ( QDialog::Accepted == login.exec() ) { 148 if ( QDialog::Accepted == login.exec() ) {
149 // ok 149 // ok
150 user = login.getUser(); 150 user = login.getUser();
151 pass = login.getPassword(); 151 pass = login.getPassword();
152 } else { 152 } else {
153 // cancel 153 // cancel
154 return; 154 return;
155 } 155 }
156 } else { 156 } else {
157 user = account->getUser(); 157 user = account->getUser();
158 pass = account->getPassword(); 158 pass = account->getPassword();
159 } 159 }
160 160
161 m_imap = mailimap_new( 20, &imap_progress ); 161 m_imap = mailimap_new( 20, &imap_progress );
162 162
163 /* connect */ 163 /* connect */
164 bool ssl = false; 164 bool ssl = false;
165 bool try_tls = false; 165 bool try_tls = false;
166 bool force_tls = false; 166 bool force_tls = false;
167 167
168 if ( account->ConnectionType() == 2 ) { 168 if ( account->ConnectionType() == 2 ) {
169 ssl = true; 169 ssl = true;
170 } 170 }
171 if (account->ConnectionType()==1) { 171 if (account->ConnectionType()==1) {
172 force_tls = true; 172 force_tls = true;
173 } 173 }
174 174
175 if ( ssl ) { 175 if ( ssl ) {
176 //qDebug("using ssl "); 176 qDebug("using ssl ");
177 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); 177 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port );
178 qDebug("back ");
178 } else { 179 } else {
179 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); 180 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port );
180 } 181 }
181 182
182 if ( err != MAILIMAP_NO_ERROR && 183 if ( err != MAILIMAP_NO_ERROR &&
183 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 184 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
184 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 185 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
185 QString failure = ""; 186 QString failure = "";
186 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 187 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
187 failure="Connection refused"; 188 failure="Connection refused";
188 } else { 189 } else {
189 failure="Unknown failure"; 190 failure="Unknown failure";
190 } 191 }
191 Global::statusMessage(i18n("error connecting imap server: %1").arg(failure)); 192 Global::statusMessage(i18n("error connecting imap server: %1").arg(failure));
192 mailimap_free( m_imap ); 193 mailimap_free( m_imap );
193 m_imap = 0; 194 m_imap = 0;
194 return; 195 return;
195 } 196 }
196 197
197 if (!ssl) { 198 if (!ssl) {
198 try_tls = start_tls(force_tls); 199 try_tls = start_tls(force_tls);
199 } 200 }
200 201
201 bool ok = true; 202 bool ok = true;
202 if (force_tls && !try_tls) { 203 if (force_tls && !try_tls) {
203 Global::statusMessage(i18n("Server has no TLS support!")); 204 Global::statusMessage(i18n("Server has no TLS support!"));
204 ok = false; 205 ok = false;
205 } 206 }
206 207
207 208
208 /* login */ 209 /* login */
209 210
210 if (ok) { 211 if (ok) {
211 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); 212 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() );
212 if ( err != MAILIMAP_NO_ERROR ) { 213 if ( err != MAILIMAP_NO_ERROR ) {
213 Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response)); 214 Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response));
214 ok = false; 215 ok = false;
215 } 216 }
216 } 217 }
217 if (!ok) { 218 if (!ok) {
218 err = mailimap_close( m_imap ); 219 err = mailimap_close( m_imap );
219 mailimap_free( m_imap ); 220 mailimap_free( m_imap );
220 m_imap = 0; 221 m_imap = 0;
221 } 222 }
222} 223}
223 224
224void IMAPwrapper::logout() 225void IMAPwrapper::logout()
225{ 226{
diff --git a/kmicromail/libmailwrapper/mhwrapper.cpp b/kmicromail/libmailwrapper/mhwrapper.cpp
index de6d220..90b5d23 100644
--- a/kmicromail/libmailwrapper/mhwrapper.cpp
+++ b/kmicromail/libmailwrapper/mhwrapper.cpp
@@ -254,136 +254,145 @@ void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &
254 if (r!=MAIL_NO_ERROR) { 254 if (r!=MAIL_NO_ERROR) {
255 qDebug("deleteMails: error selecting folder! "); 255 qDebug("deleteMails: error selecting folder! ");
256 return; 256 return;
257 } 257 }
258 QValueList<RecMailP>::ConstIterator it; 258 QValueList<RecMailP>::ConstIterator it;
259 for (it=target.begin(); it!=target.end();++it) { 259 for (it=target.begin(); it!=target.end();++it) {
260 r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber()); 260 r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber());
261 if (r != MAIL_NO_ERROR) { 261 if (r != MAIL_NO_ERROR) {
262 qDebug("error deleting mail "); 262 qDebug("error deleting mail ");
263 break; 263 break;
264 } 264 }
265 } 265 }
266} 266}
267 267
268int MHwrapper::deleteAllMail(const FolderP&tfolder) 268int MHwrapper::deleteAllMail(const FolderP&tfolder)
269{ 269{
270 init_storage(); 270 init_storage();
271 if (!m_storage) { 271 if (!m_storage) {
272 return 0; 272 return 0;
273 } 273 }
274 int res = 1; 274 int res = 1;
275 if (!tfolder) return 0; 275 if (!tfolder) return 0;
276 int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); 276 int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1());
277 if (r!=MAIL_NO_ERROR) { 277 if (r!=MAIL_NO_ERROR) {
278 qDebug("error selecting folder! "); 278 qDebug("error selecting folder! ");
279 return 0; 279 return 0;
280 } 280 }
281 mailmessage_list*l=0; 281 mailmessage_list*l=0;
282 r = mailsession_get_messages_list(m_storage->sto_session,&l); 282 r = mailsession_get_messages_list(m_storage->sto_session,&l);
283 if (r != MAIL_NO_ERROR) { 283 if (r != MAIL_NO_ERROR) {
284 qDebug("Error message list "); 284 qDebug("Error message list ");
285 res = 0; 285 res = 0;
286 } 286 }
287 unsigned j = 0; 287 unsigned j = 0;
288 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { 288 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
289 mailmessage * msg; 289 mailmessage * msg;
290 msg = (mailmessage*)carray_get(l->msg_tab, i); 290 msg = (mailmessage*)carray_get(l->msg_tab, i);
291 j = msg->msg_index; 291 j = msg->msg_index;
292 r = mailsession_remove_message(m_storage->sto_session,j); 292 r = mailsession_remove_message(m_storage->sto_session,j);
293 if (r != MAIL_NO_ERROR) { 293 if (r != MAIL_NO_ERROR) {
294 Global::statusMessage(i18n("Error deleting mail %1").arg(i+1)); 294 Global::statusMessage(i18n("Error deleting mail %1").arg(i+1));
295 res = 0; 295 res = 0;
296 break; 296 break;
297 } 297 }
298 } 298 }
299 if (l) mailmessage_list_free(l); 299 if (l) mailmessage_list_free(l);
300 return res; 300 return res;
301} 301}
302bool MHwrapper::rmDir(QString folder) // absolute path!
303{
304 QDir dir ( folder );
305 if ( !dir.exists() )
306 return false;
307 int i;
308 // qDebug("rmdir %s ",folder.latin1());
309 QStringList list = dir.entryList(QDir::Dirs|QDir::Files|QDir::NoSymLinks|QDir::Hidden );
310 for (i=0; i<list.count(); i++ ) {
311 bool result = true;
312 QString entry = folder+"/"+ list[i] ;
313 //qDebug("entry %s ",entry.latin1() );
302 314
315 QFileInfo fi ( entry );
316 if ( fi.isFile() ) {
317 //qDebug("file %s ",entry.latin1() );
318 result = QFile::remove ( entry ) ;
319 } else {
320 //qDebug("dir %s ",entry.latin1());
321 if ( list[i] != "." && list[i] != ".." )
322 result = rmDir( entry );
323 }
324 if ( ! result )
325 return false;
326 }
327 //qDebug("removing... ");
328 return QDir::root().rmdir ( folder, true );
329}
303int MHwrapper::deleteMbox(const FolderP&tfolder) 330int MHwrapper::deleteMbox(const FolderP&tfolder)
304{ 331{
305 init_storage(); 332 init_storage();
306 if (!m_storage) { 333 if (!m_storage) {
307 return 0; 334 return 0;
308 } 335 }
309 if (!tfolder) return 0; 336 if (!tfolder) return 0;
310 if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; 337 if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0;
311 338
312 int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); 339 int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1());
313 340
314 if (r != MAIL_NO_ERROR) { 341 if (r != MAIL_NO_ERROR) {
315 qDebug("error deleting mail box "); 342 qDebug("error deleting mail box ");
316 return 0; 343 return 0;
317 } 344 }
318 QString delDir = locateLocal( "apps", "kopiemail")+ "localmail"; 345 //qDebug("*****************\ndel %s %s ", delDir.latin1(),tfolder->getName().latin1() );
319 qDebug("*****************\ndel %s %s ", delDir.latin1(),tfolder->getName().latin1() ); 346 if ( !rmDir( tfolder->getName() )) {
320#if 0 347 qDebug("error deleteing folder %s ",tfolder->getName().latin1());
321 QString cmd = "rm -rf "+tfolder->getName();
322 QStringList command;
323 command << "/bin/sh";
324 command << "-c";
325 command << cmd.latin1();
326 OProcess *process = new OProcess();
327
328 /*
329 connect(process, SIGNAL(processExited(Opie::Core::OProcess*)),
330 this, SLOT( processEnded(Opie::Core::OProcess*)));
331 connect(process, SIGNAL( receivedStderr(Opie::Core::OProcess*,char*,int)),
332 this, SLOT( oprocessStderr(Opie::Core::OProcess*,char*,int)));
333 */
334 *process << command;
335 removeMboxfailed = false;
336 if(!process->start(OProcess::Block, OProcess::All) ) {
337 qDebug("could not start process ");
338 return 0;
339 } 348 }
340#endif 349 else
341 qDebug("mail box deleted "); 350 qDebug("mail box deleted %s ", tfolder->getName().latin1());
342 return 1; 351 return 1;
343} 352}
344 353
345 354
346void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 355void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
347{ 356{
348 init_storage(); 357 init_storage();
349 if (!m_storage) { 358 if (!m_storage) {
350 return; 359 return;
351 } 360 }
352 target_stat.message_count = 0; 361 target_stat.message_count = 0;
353 target_stat.message_unseen = 0; 362 target_stat.message_unseen = 0;
354 target_stat.message_recent = 0; 363 target_stat.message_recent = 0;
355 QString f = buildPath(mailbox); 364 QString f = buildPath(mailbox);
356 int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, 365 int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count,
357 &target_stat.message_recent,&target_stat.message_unseen); 366 &target_stat.message_recent,&target_stat.message_unseen);
358 if (r != MAIL_NO_ERROR) { 367 if (r != MAIL_NO_ERROR) {
359 Global::statusMessage(i18n("Error retrieving status")); 368 Global::statusMessage(i18n("Error retrieving status"));
360 } 369 }
361} 370}
362 371
363MAILLIB::ATYPE MHwrapper::getType()const 372MAILLIB::ATYPE MHwrapper::getType()const
364{ 373{
365 return MAILLIB::A_MH; 374 return MAILLIB::A_MH;
366} 375}
367 376
368const QString&MHwrapper::getName()const 377const QString&MHwrapper::getName()const
369{ 378{
370 return MHName; 379 return MHName;
371} 380}
372void MHwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 381void MHwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
373{ 382{
374 init_storage(); 383 init_storage();
375 if (!m_storage) { 384 if (!m_storage) {
376 return; 385 return;
377 } 386 }
378 if (targetWrapper != this) { 387 if (targetWrapper != this) {
379 qDebug("Using generic "); 388 qDebug("Using generic ");
380 Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); 389 Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit);
381 return; 390 return;
382 } 391 }
383 qDebug("Using internal routines for move/copy "); 392 qDebug("Using internal routines for move/copy ");
384 QString tf = buildPath(targetFolder); 393 QString tf = buildPath(targetFolder);
385 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 394 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
386 if (r != MAIL_NO_ERROR) { 395 if (r != MAIL_NO_ERROR) {
387 qDebug("Error selecting source mailbox "); 396 qDebug("Error selecting source mailbox ");
388 return; 397 return;
389 } 398 }
diff --git a/kmicromail/libmailwrapper/mhwrapper.h b/kmicromail/libmailwrapper/mhwrapper.h
index 87f8ca1..36a443a 100644
--- a/kmicromail/libmailwrapper/mhwrapper.h
+++ b/kmicromail/libmailwrapper/mhwrapper.h
@@ -6,53 +6,54 @@
6 6
7#include "genericwrapper.h" 7#include "genericwrapper.h"
8#include <qstring.h> 8#include <qstring.h>
9 9
10class encodedString; 10class encodedString;
11struct mailmbox_folder; 11struct mailmbox_folder;
12class MHwrapper : public Genericwrapper 12class MHwrapper : public Genericwrapper
13{ 13{
14 Q_OBJECT 14 Q_OBJECT
15public: 15public:
16 MHwrapper(const QString & dir,const QString&name); 16 MHwrapper(const QString & dir,const QString&name);
17 virtual ~MHwrapper(); 17 virtual ~MHwrapper();
18 18
19 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 ); 19 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 );
20 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 20 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
21 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 21 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
22 22
23 virtual void deleteMail(const RecMailP&mail); 23 virtual void deleteMail(const RecMailP&mail);
24 virtual void answeredMail(const RecMailP&mail); 24 virtual void answeredMail(const RecMailP&mail);
25 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 25 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
26 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, 26 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder,
27 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 27 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
28 28
29 virtual int createMbox(const QString&folder,const Opie::Core::OSmartPointer<Folder>&f=0, 29 virtual int createMbox(const QString&folder,const Opie::Core::OSmartPointer<Folder>&f=0,
30 const QString&d="",bool s=false); 30 const QString&d="",bool s=false);
31 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&); 31 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&);
32 32
33 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 33 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
34 34
35 virtual RecBodyP fetchBody( const RecMailP &mail ); 35 virtual RecBodyP fetchBody( const RecMailP &mail );
36 static void mbox_progress( size_t current, size_t maximum ); 36 static void mbox_progress( size_t current, size_t maximum );
37 37
38 virtual encodedString* fetchRawBody(const RecMailP&mail); 38 virtual encodedString* fetchRawBody(const RecMailP&mail);
39 virtual void deleteMails(const QString & FolderName,const QValueList<Opie::Core::OSmartPointer<RecMail> > &target); 39 virtual void deleteMails(const QString & FolderName,const QValueList<Opie::Core::OSmartPointer<RecMail> > &target);
40 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); 40 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&);
41 virtual MAILLIB::ATYPE getType()const; 41 virtual MAILLIB::ATYPE getType()const;
42 virtual const QString&getName()const; 42 virtual const QString&getName()const;
43 virtual Account* getAccount() { return 0; }; 43 virtual Account* getAccount() { return 0; };
44 44
45public slots: 45public slots:
46 46
47protected: 47protected:
48 QString buildPath(const QString&p); 48 QString buildPath(const QString&p);
49 QString MHPath; 49 QString MHPath;
50 QString MHName; 50 QString MHName;
51 51
52 void init_storage(); 52 void init_storage();
53 void clean_storage(); 53 void clean_storage();
54 bool rmDir(QString folderabspath);
54 55
55 bool removeMboxfailed; 56 bool removeMboxfailed;
56}; 57};
57 58
58#endif 59#endif