summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-08-22 18:52:57 (UTC)
committer zautrix <zautrix>2005-08-22 18:52:57 (UTC)
commitcb425b4c2d027d49f964368e94a52d3ba5e6aa31 (patch) (unidiff)
treeb867e4c565aab6965059306bac24dd3ab5ca3750
parente011ace92e07174effca53b7dde20b9a5b695af0 (diff)
downloadkdepimpi-cb425b4c2d027d49f964368e94a52d3ba5e6aa31.zip
kdepimpi-cb425b4c2d027d49f964368e94a52d3ba5e6aa31.tar.gz
kdepimpi-cb425b4c2d027d49f964368e94a52d3ba5e6aa31.tar.bz2
ompi fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/accountview.cpp39
-rw-r--r--kmicromail/accountview.h1
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp6
3 files changed, 31 insertions, 15 deletions
diff --git a/kmicromail/accountview.cpp b/kmicromail/accountview.cpp
index 6227f6d..cef55ab 100644
--- a/kmicromail/accountview.cpp
+++ b/kmicromail/accountview.cpp
@@ -1,235 +1,252 @@
1 1
2#include "accountview.h" 2#include "accountview.h"
3#include "accountitem.h" 3#include "accountitem.h"
4#include "selectstore.h" 4#include "selectstore.h"
5 5
6#include <libmailwrapper/settings.h> 6#include <libmailwrapper/settings.h>
7#include <libmailwrapper/mailwrapper.h> 7#include <libmailwrapper/mailwrapper.h>
8#include <libmailwrapper/mailtypes.h> 8#include <libmailwrapper/mailtypes.h>
9#include <libmailwrapper/abstractmail.h> 9#include <libmailwrapper/abstractmail.h>
10 10
11/* OPIE */ 11/* OPIE */
12#include <qpe/qpeapplication.h> 12#include <qpe/qpeapplication.h>
13 13
14/* QT */ 14/* QT */
15#include <qmessagebox.h> 15#include <qmessagebox.h>
16#include <qpopupmenu.h> 16#include <qpopupmenu.h>
17#include <qcheckbox.h> 17#include <qcheckbox.h>
18#include <qtimer.h>
18#include <qspinbox.h> 19#include <qspinbox.h>
19#include <klocale.h> 20#include <klocale.h>
21#include <kmessagebox.h>
20 22
21using namespace Opie::Core; 23using namespace Opie::Core;
22AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) 24AccountView::AccountView( QWidget *parent, const char *name, WFlags flags )
23 : QListView( parent, name, flags ) 25 : QListView( parent, name, flags )
24{ 26{
25 connect( this, SIGNAL( selectionChanged(QListViewItem*) ), 27 //connect( this, SIGNAL( selectionChanged(QListViewItem*) ),
26 SLOT( refresh(QListViewItem*) ) ); 28 // SLOT( refresh(QListViewItem*) ) );
27 connect( this, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),this, 29 connect( this, SIGNAL( clicked(QListViewItem*) ),
28 SLOT( slotHold(int,QListViewItem*,const QPoint&,int) ) ); 30 SLOT( refresh(QListViewItem*) ) );
31 connect( this, SIGNAL( returnPressed(QListViewItem*) ),
32 SLOT( refresh(QListViewItem*) ) );
33 connect( this, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),this,
34 SLOT( slotHold(int,QListViewItem*,const QPoint&,int) ) );
29 setSorting(0); 35 setSorting(0);
30} 36}
31 37
32AccountView::~AccountView() 38AccountView::~AccountView()
33{ 39{
34 imapAccounts.clear(); 40 imapAccounts.clear();
35 mhAccounts.clear(); 41 mhAccounts.clear();
36} 42}
37 43
38void AccountView::slotContextMenu(int id) 44void AccountView::slotContextMenu(int id)
39{ 45{
40 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); 46 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem());
41 if (!view) return; 47 if (!view) return;
42 view->contextMenuSelected(id); 48 view->contextMenuSelected(id);
43} 49}
44 50
45void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int) 51void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int)
46{ 52{
47 if (button==1) {return;} 53 if (button==1) {return;}
48 if (!item) return; 54 if (!item) return;
49 AccountViewItem *view = static_cast<AccountViewItem *>(item); 55 AccountViewItem *view = static_cast<AccountViewItem *>(item);
50 QPopupMenu*m = view->getContextMenu(); 56 QPopupMenu*m = view->getContextMenu();
51 if (!m) return; 57 if (!m) return;
52 connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int))); 58 connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int)));
53 m->setFocus(); 59 m->setFocus();
54 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); 60 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
55 delete m; 61 delete m;
56} 62}
57 63
58void AccountView::populate( QList<Account> list ) 64void AccountView::populate( QList<Account> list )
59{ 65{
60 clear(); 66 clear();
61 67
62 imapAccounts.clear(); 68 imapAccounts.clear();
63 mhAccounts.clear(); 69 mhAccounts.clear();
64 70
65 mhAccounts.append(new MHviewItem(AbstractMail::defaultLocalfolder(),this)); 71 mhAccounts.append(new MHviewItem(AbstractMail::defaultLocalfolder(),this));
66 72
67 Account *it; 73 Account *it;
68 for ( it = list.first(); it; it = list.next() ) 74 for ( it = list.first(); it; it = list.next() )
69 { 75 {
70 if ( it->getType() == MAILLIB::A_IMAP ) 76 if ( it->getType() == MAILLIB::A_IMAP )
71 { 77 {
72 IMAPaccount *imap = static_cast<IMAPaccount *>(it); 78 IMAPaccount *imap = static_cast<IMAPaccount *>(it);
73 imapAccounts.append(new IMAPviewItem( imap, this )); 79 imapAccounts.append(new IMAPviewItem( imap, this ));
74 } 80 }
75 else if ( it->getType() == MAILLIB::A_POP3 ) 81 else if ( it->getType() == MAILLIB::A_POP3 )
76 { 82 {
77 POP3account *pop3 = static_cast<POP3account *>(it); 83 POP3account *pop3 = static_cast<POP3account *>(it);
78 /* must not be hold 'cause it isn't required */ 84 /* must not be hold 'cause it isn't required */
79 (void) new POP3viewItem( pop3, this ); 85 (void) new POP3viewItem( pop3, this );
80 } 86 }
81 else if ( it->getType() == MAILLIB::A_NNTP ) 87 else if ( it->getType() == MAILLIB::A_NNTP )
82 { 88 {
83 NNTPaccount *nntp = static_cast<NNTPaccount *>(it); 89 NNTPaccount *nntp = static_cast<NNTPaccount *>(it);
84 /* must not be hold 'cause it isn't required */ 90 /* must not be hold 'cause it isn't required */
85 (void) new NNTPviewItem( nntp, this ); 91 (void) new NNTPviewItem( nntp, this );
86 } 92 }
87 } 93 }
88} 94}
89 95
90void AccountView::refresh(QListViewItem *item) 96void AccountView::refresh(QListViewItem *item)
91{ 97{
92 if ( item ) 98 if ( item )
93 { 99 {
100 int result = KMessageBox::warningContinueCancel(this,
101 i18n("Refresh\n%1\n?").arg( item->text(0) ),
102 i18n("Refresh"),i18n("Refresh"),i18n("Cancel"),
103 true);
104 if (result != KMessageBox::Continue) return;
94 m_currentItem = item; 105 m_currentItem = item;
95 QValueList<RecMailP> headerlist; 106 topLevelWidget()->setCaption( i18n ( "Refreshing %1 ... please wait" ). arg ( m_currentItem->text( 0 ) ) ) ;
96 AccountViewItem *view = static_cast<AccountViewItem *>(item); 107 QTimer::singleShot( 500, this, SLOT ( refreshCurrentSelected() ) );
97 view->refresh(headerlist); 108
98 emit refreshMailview(headerlist);
99 } 109 }
100} 110}
101void AccountView::refreshOutgoing() 111void AccountView::refreshOutgoing()
102{ 112{
103 m_currentItem = currentItem(); 113 m_currentItem = currentItem();
104 if ( !m_currentItem ) return; 114 if ( !m_currentItem ) return;
105 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); 115 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem);
106 if ( !view->getFolder() ) 116 if ( !view->getFolder() )
107 return; 117 return;
108 QString bName = view->getFolder()->getDisplayName(); 118 QString bName = view->getFolder()->getDisplayName();
109 if (bName.startsWith("/")&&bName.length()>1) 119 if (bName.startsWith("/")&&bName.length()>1)
110 { 120 {
111 bName.replace(0,1,""); 121 bName.replace(0,1,"");
112 } 122 }
113 int pos = bName.findRev("/"); 123 int pos = bName.findRev("/");
114 if (pos > 0) 124 if (pos > 0)
115 { 125 {
116 bName.replace(0,pos+1,""); 126 bName.replace(0,pos+1,"");
117 } 127 }
118 //qDebug("name *%s* ",bName.lower().latin1() ); 128 //qDebug("name *%s* ",bName.lower().latin1() );
119 if ( bName.lower() == "outgoing" || bName.lower() == "sent" || bName.lower() == "sendfailed" ) { 129 if ( bName.lower() == "outgoing" || bName.lower() == "sent" || bName.lower() == "sendfailed" ) {
120 refreshCurrent(); 130 refreshCurrent();
121 // qDebug("refresh "); 131 // qDebug("refresh ");
122 } 132 }
123} 133}
124 134void AccountView::refreshCurrentSelected()
125void AccountView::refreshCurrent()
126{ 135{
127 m_currentItem = currentItem();
128 if ( !m_currentItem ) return; 136 if ( !m_currentItem ) return;
129 QValueList<RecMailP> headerlist; 137 QValueList<RecMailP> headerlist;
130 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); 138 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem);
131 view->refresh(headerlist); 139 view->refresh(headerlist);
132 emit refreshMailview(headerlist); 140 emit refreshMailview(headerlist);
141 topLevelWidget()->setCaption( i18n ( "KOpieMail/Pi" ) ) ;
142}
143
144void AccountView::refreshCurrent()
145{
146 m_currentItem = currentItem();
147 if ( !m_currentItem ) return;
148 topLevelWidget()->setCaption( i18n ( "Refreshing %1 ... please wait" ). arg ( m_currentItem->text( 0 ) ) ) ;
149 QTimer::singleShot( 500, this, SLOT ( refreshCurrentSelected() ) );
133} 150}
134 151
135void AccountView::refreshAll() 152void AccountView::refreshAll()
136{ 153{
137} 154}
138 155
139RecBodyP AccountView::fetchBody(const RecMailP&aMail) 156RecBodyP AccountView::fetchBody(const RecMailP&aMail)
140{ 157{
141 QListViewItem*item = selectedItem (); 158 QListViewItem*item = selectedItem ();
142 if (!item) return new RecBody(); 159 if (!item) return new RecBody();
143 AccountViewItem *view = static_cast<AccountViewItem *>(item); 160 AccountViewItem *view = static_cast<AccountViewItem *>(item);
144 return view->fetchBody(aMail); 161 return view->fetchBody(aMail);
145} 162}
146 163
147void AccountView::setupFolderselect(Selectstore*sels) 164void AccountView::setupFolderselect(Selectstore*sels)
148{ 165{
149 166
150#ifndef DESKTOP_VERSION 167#ifndef DESKTOP_VERSION
151 sels->showMaximized(); 168 sels->showMaximized();
152#else 169#else
153 sels->show(); 170 sels->show();
154#endif 171#endif
155 QStringList sFolders; 172 QStringList sFolders;
156 unsigned int i = 0; 173 unsigned int i = 0;
157 for (i=0; i < mhAccounts.count();++i) 174 for (i=0; i < mhAccounts.count();++i)
158 { 175 {
159 mhAccounts[i]->refresh(false); 176 mhAccounts[i]->refresh(false);
160 sFolders = mhAccounts[i]->subFolders(); 177 sFolders = mhAccounts[i]->subFolders();
161 sels->addAccounts(mhAccounts[i]->getWrapper(),sFolders); 178 sels->addAccounts(mhAccounts[i]->getWrapper(),sFolders);
162 } 179 }
163 for (i=0; i < imapAccounts.count();++i) 180 for (i=0; i < imapAccounts.count();++i)
164 { 181 {
165 if (imapAccounts[i]->offline()) 182 if (imapAccounts[i]->offline())
166 continue; 183 continue;
167 imapAccounts[i]->refreshFolders(false); 184 imapAccounts[i]->refreshFolders(false);
168 sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders()); 185 sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders());
169 } 186 }
170} 187}
171void AccountView::downloadMailsInbox(const FolderP&fromFolder,AbstractMail*fromWrapper) 188void AccountView::downloadMailsInbox(const FolderP&fromFolder,AbstractMail*fromWrapper)
172{ 189{
173#if 0 190#if 0
174 AbstractMail*targetMail = 0; 191 AbstractMail*targetMail = 0;
175 QString targetFolder = ""; 192 QString targetFolder = "";
176 Selectstore sels; 193 Selectstore sels;
177 setupFolderselect(&sels); 194 setupFolderselect(&sels);
178 if (!sels.exec()) return; 195 if (!sels.exec()) return;
179 targetMail = sels.currentMail(); 196 targetMail = sels.currentMail();
180 targetFolder = sels.currentFolder(); 197 targetFolder = sels.currentFolder();
181 if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) || 198 if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) ||
182 targetFolder.isEmpty()) 199 targetFolder.isEmpty())
183 { 200 {
184 return; 201 return;
185 } 202 }
186 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 203 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
187 { 204 {
188 QMessageBox::critical(0,i18n("Error creating new Folder"), 205 QMessageBox::critical(0,i18n("Error creating new Folder"),
189 i18n("<center>Error while creating<br>new folder - breaking.</center>")); 206 i18n("<center>Error while creating<br>new folder - breaking.</center>"));
190 return; 207 return;
191 } 208 }
192 int maxsize = 0; 209 int maxsize = 0;
193 if ( sels.useSize->isChecked()) 210 if ( sels.useSize->isChecked())
194 maxsize = sels.sizeSpinBox->value(); 211 maxsize = sels.sizeSpinBox->value();
195 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails(), maxsize); 212 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails(), maxsize);
196#endif 213#endif
197 fromWrapper->downloadNewMails( fromFolder, mhAccounts[0]->getWrapper()); 214 fromWrapper->downloadNewMails( fromFolder, mhAccounts[0]->getWrapper());
198 refreshCurrent(); 215 refreshCurrent();
199 216
200} 217}
201 218
202void AccountView::downloadMails(const FolderP&fromFolder,AbstractMail*fromWrapper) 219void AccountView::downloadMails(const FolderP&fromFolder,AbstractMail*fromWrapper)
203{ 220{
204 AbstractMail*targetMail = 0; 221 AbstractMail*targetMail = 0;
205 QString targetFolder = ""; 222 QString targetFolder = "";
206 Selectstore sels; 223 Selectstore sels;
207 setupFolderselect(&sels); 224 setupFolderselect(&sels);
208 if (!sels.exec()) return; 225 if (!sels.exec()) return;
209 targetMail = sels.currentMail(); 226 targetMail = sels.currentMail();
210 targetFolder = sels.currentFolder(); 227 targetFolder = sels.currentFolder();
211 if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) || 228 if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) ||
212 targetFolder.isEmpty()) 229 targetFolder.isEmpty())
213 { 230 {
214 return; 231 return;
215 } 232 }
216 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 233 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
217 { 234 {
218 QMessageBox::critical(0,i18n("Error creating new Folder"), 235 QMessageBox::critical(0,i18n("Error creating new Folder"),
219 i18n("<center>Error while creating<br>new folder - breaking.</center>")); 236 i18n("<center>Error while creating<br>new folder - breaking.</center>"));
220 return; 237 return;
221 } 238 }
222 int maxsize = 0; 239 int maxsize = 0;
223 if ( sels.useSize->isChecked()) 240 if ( sels.useSize->isChecked())
224 maxsize = sels.sizeSpinBox->value(); 241 maxsize = sels.sizeSpinBox->value();
225 242
226 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails(), maxsize); 243 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails(), maxsize);
227 refreshCurrent(); 244 refreshCurrent();
228} 245}
229 246
230bool AccountView::currentisDraft() 247bool AccountView::currentisDraft()
231{ 248{
232 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); 249 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem());
233 if (!view) return false; 250 if (!view) return false;
234 return view->isDraftfolder(); 251 return view->isDraftfolder();
235} 252}
diff --git a/kmicromail/accountview.h b/kmicromail/accountview.h
index e403cb8..33f3479 100644
--- a/kmicromail/accountview.h
+++ b/kmicromail/accountview.h
@@ -1,47 +1,48 @@
1#ifndef ACCOUNTVIEW_H 1#ifndef ACCOUNTVIEW_H
2#define ACCOUNTVIEW_H 2#define ACCOUNTVIEW_H
3 3
4#include <qlistview.h> 4#include <qlistview.h>
5#include <qlist.h> 5#include <qlist.h>
6#include <opie2/osmartpointer.h> 6#include <opie2/osmartpointer.h>
7#include <libmailwrapper/mailtypes.h> 7#include <libmailwrapper/mailtypes.h>
8 8
9class Selectstore; 9class Selectstore;
10class Folder; 10class Folder;
11class AbstractMail; 11class AbstractMail;
12class Account; 12class Account;
13class IMAPviewItem; 13class IMAPviewItem;
14class MHviewItem; 14class MHviewItem;
15 15
16class AccountView : public QListView 16class AccountView : public QListView
17{ 17{
18 Q_OBJECT 18 Q_OBJECT
19 19
20public: 20public:
21 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 21 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
22 virtual ~AccountView(); 22 virtual ~AccountView();
23 virtual void populate( QList<Account> list ); 23 virtual void populate( QList<Account> list );
24 virtual RecBodyP fetchBody(const Opie::Core::OSmartPointer<RecMail>&aMail); 24 virtual RecBodyP fetchBody(const Opie::Core::OSmartPointer<RecMail>&aMail);
25 virtual void downloadMails(const Opie::Core::OSmartPointer<Folder>&fromFolder,AbstractMail*fromWrapper); 25 virtual void downloadMails(const Opie::Core::OSmartPointer<Folder>&fromFolder,AbstractMail*fromWrapper);
26 virtual void downloadMailsInbox(const Opie::Core::OSmartPointer<Folder>&fromFolder,AbstractMail*fromWrapper); 26 virtual void downloadMailsInbox(const Opie::Core::OSmartPointer<Folder>&fromFolder,AbstractMail*fromWrapper);
27 virtual bool currentisDraft(); 27 virtual bool currentisDraft();
28 QValueList<MHviewItem*> allAccounts() { return mhAccounts;} 28 QValueList<MHviewItem*> allAccounts() { return mhAccounts;}
29public slots: 29public slots:
30 virtual void refreshAll(); 30 virtual void refreshAll();
31 virtual void refresh(QListViewItem *item); 31 virtual void refresh(QListViewItem *item);
32 virtual void refreshCurrent(); 32 virtual void refreshCurrent();
33 virtual void refreshCurrentSelected();
33 virtual void refreshOutgoing(); 34 virtual void refreshOutgoing();
34 virtual void slotHold(int, QListViewItem *,const QPoint&,int); 35 virtual void slotHold(int, QListViewItem *,const QPoint&,int);
35 virtual void slotContextMenu(int id); 36 virtual void slotContextMenu(int id);
36 void setupFolderselect(Selectstore*sels); 37 void setupFolderselect(Selectstore*sels);
37 38
38signals: 39signals:
39 void refreshMailview(const QValueList<RecMailP>& ); 40 void refreshMailview(const QValueList<RecMailP>& );
40 41
41protected: 42protected:
42 QListViewItem* m_currentItem; 43 QListViewItem* m_currentItem;
43 QValueList<IMAPviewItem*> imapAccounts; 44 QValueList<IMAPviewItem*> imapAccounts;
44 QValueList<MHviewItem*> mhAccounts; 45 QValueList<MHviewItem*> mhAccounts;
45}; 46};
46 47
47#endif 48#endif
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp
index 09e52b8..4f0c849 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -1,371 +1,369 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include <stdlib.h> 2#include <stdlib.h>
3#include <libetpan/libetpan.h> 3#include <libetpan/libetpan.h>
4#include <qpe/global.h> 4#include <qpe/global.h>
5#include <qapplication.h> 5#include <qapplication.h>
6#include "imapwrapper.h" 6#include "imapwrapper.h"
7#include "mailtypes.h" 7#include "mailtypes.h"
8#include "logindialog.h" 8#include "logindialog.h"
9#include <qprogressbar.h> 9#include <qprogressbar.h>
10#include "genericwrapper.h" 10#include "genericwrapper.h"
11#include <kglobal.h> 11#include <kglobal.h>
12 12
13using namespace Opie::Core; 13using namespace Opie::Core;
14int IMAPwrapper::mMax = 0; 14int IMAPwrapper::mMax = 0;
15int IMAPwrapper::mCurrent = 0; 15int IMAPwrapper::mCurrent = 0;
16 16
17IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 17IMAPwrapper::IMAPwrapper( IMAPaccount *a )
18 : AbstractMail() 18 : AbstractMail()
19{ 19{
20 account = a; 20 account = a;
21 m_imap = 0; 21 m_imap = 0;
22 m_Lastmbox = ""; 22 m_Lastmbox = "";
23 mCurrent = 0; 23 mCurrent = 0;
24 mMax = 0; 24 mMax = 0;
25} 25}
26 26
27IMAPwrapper::~IMAPwrapper() 27IMAPwrapper::~IMAPwrapper()
28{ 28{
29 logout(); 29 logout();
30} 30}
31 31
32/* to avoid to often select statements in loops etc. 32/* to avoid to often select statements in loops etc.
33 we trust that we are logged in and connection is established!*/ 33 we trust that we are logged in and connection is established!*/
34int IMAPwrapper::selectMbox(const QString&mbox) 34int IMAPwrapper::selectMbox(const QString&mbox)
35{ 35{
36 if (mbox == m_Lastmbox) { 36 if (mbox == m_Lastmbox) {
37 return MAILIMAP_NO_ERROR; 37 return MAILIMAP_NO_ERROR;
38 } 38 }
39 int err = mailimap_select( m_imap, (char*)mbox.latin1()); 39 int err = mailimap_select( m_imap, (char*)mbox.latin1());
40 if ( err != MAILIMAP_NO_ERROR ) { 40 if ( err != MAILIMAP_NO_ERROR ) {
41 m_Lastmbox = ""; 41 m_Lastmbox = "";
42 return err; 42 return err;
43 } 43 }
44 m_Lastmbox = mbox; 44 m_Lastmbox = mbox;
45 return err; 45 return err;
46} 46}
47 47
48void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 48void IMAPwrapper::imap_progress( size_t current, size_t maximum )
49{ 49{
50 qApp->processEvents();
51 return; 50 return;
52 //qDebug("imap progress %d of %d ",current,maximum ); 51 //qDebug("imap progress %d of %d ",current,maximum );
53 //Global::statusMessage(i18n("Downloading message %1 of %2").arg( current).arg(maximum)); 52 //Global::statusMessage(i18n("Downloading message %1 of %2").arg( current).arg(maximum));
54 //qApp->processEvents() 53 //qApp->processEvents()
55 static unsigned int last = 0; 54 static unsigned int last = 0;
56 if ( last != current ) 55 if ( last != current )
57 IMAPwrapper::progress(); 56 IMAPwrapper::progress();
58 last = current; 57 last = current;
59} 58}
60void IMAPwrapper::progress( QString m ) 59void IMAPwrapper::progress( QString m )
61{ 60{
62 static QString mProgrMess; 61 static QString mProgrMess;
63 if ( m != QString::null ) { 62 if ( m != QString::null ) {
64 mProgrMess = m; 63 mProgrMess = m;
65 mCurrent = 1; 64 mCurrent = 1;
66 return; 65 return;
67 } 66 }
68 QString mess; 67 QString mess;
69 //qDebug("progress "); 68 //qDebug("progress ");
70 if ( mMax ) mess = mProgrMess +i18n(" message %1 of %2").arg( mCurrent++).arg(mMax); 69 if ( mMax ) mess = mProgrMess +i18n(" message %1 of %2").arg( mCurrent++).arg(mMax);
71 else mess = mProgrMess +i18n(" message %1").arg( mCurrent++); 70 else mess = mProgrMess +i18n(" message %1").arg( mCurrent++);
72 Global::statusMessage(mess); 71 Global::statusMessage(mess);
73 //qDebug("Progress %s %s", mess.latin1(), m.latin1()); 72 //qDebug("Progress %s %s", mess.latin1(), m.latin1());
74 qApp->processEvents(); 73 qApp->processEvents();
75} 74}
76bool IMAPwrapper::start_tls(bool force_tls) 75bool IMAPwrapper::start_tls(bool force_tls)
77{ 76{
78 int err; 77 int err;
79 bool try_tls = force_tls; 78 bool try_tls = force_tls;
80 mailimap_capability_data * cap_data = 0; 79 mailimap_capability_data * cap_data = 0;
81 80
82 err = mailimap_capability(m_imap,&cap_data); 81 err = mailimap_capability(m_imap,&cap_data);
83 if (err != MAILIMAP_NO_ERROR) { 82 if (err != MAILIMAP_NO_ERROR) {
84 Global::statusMessage("error getting capabilities!"); 83 Global::statusMessage("error getting capabilities!");
85 return false; 84 return false;
86 } 85 }
87 clistiter * cur; 86 clistiter * cur;
88 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { 87 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
89 struct mailimap_capability * cap; 88 struct mailimap_capability * cap;
90 cap = (struct mailimap_capability *)clist_content(cur); 89 cap = (struct mailimap_capability *)clist_content(cur);
91 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { 90 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
92 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { 91 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
93 try_tls = true; 92 try_tls = true;
94 break; 93 break;
95 } 94 }
96 } 95 }
97 } 96 }
98 if (cap_data) { 97 if (cap_data) {
99 mailimap_capability_data_free(cap_data); 98 mailimap_capability_data_free(cap_data);
100 } 99 }
101 if (try_tls) { 100 if (try_tls) {
102 err = mailimap_starttls(m_imap); 101 err = mailimap_starttls(m_imap);
103 if (err != MAILIMAP_NO_ERROR && force_tls) { 102 if (err != MAILIMAP_NO_ERROR && force_tls) {
104 Global::statusMessage(i18n("Server has no TLS support!")); 103 Global::statusMessage(i18n("Server has no TLS support!"));
105 try_tls = false; 104 try_tls = false;
106 } else { 105 } else {
107 mailstream_low * low; 106 mailstream_low * low;
108 mailstream_low * new_low; 107 mailstream_low * new_low;
109 low = mailstream_get_low(m_imap->imap_stream); 108 low = mailstream_get_low(m_imap->imap_stream);
110 if (!low) { 109 if (!low) {
111 try_tls = false; 110 try_tls = false;
112 } else { 111 } else {
113 int fd = mailstream_low_get_fd(low); 112 int fd = mailstream_low_get_fd(low);
114 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 113 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
115 mailstream_low_free(low); 114 mailstream_low_free(low);
116 mailstream_set_low(m_imap->imap_stream, new_low); 115 mailstream_set_low(m_imap->imap_stream, new_low);
117 } else { 116 } else {
118 try_tls = false; 117 try_tls = false;
119 } 118 }
120 } 119 }
121 } 120 }
122 } 121 }
123 return try_tls; 122 return try_tls;
124} 123}
125 124
126void IMAPwrapper::login(bool tryTLS) // = true) 125void IMAPwrapper::login(bool tryTLS) // = true)
127{ 126{
128 QString server, user, pass; 127 QString server, user, pass;
129 uint16_t port; 128 uint16_t port;
130 int err = MAILIMAP_NO_ERROR; 129 int err = MAILIMAP_NO_ERROR;
131 130
132 if (account->getOffline()) return; 131 if (account->getOffline()) return;
133 /* we are connected this moment */ 132 /* we are connected this moment */
134 /* 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 */
135 if (m_imap) { 134 if (m_imap) {
136 err = mailimap_noop(m_imap); 135 err = mailimap_noop(m_imap);
137 if (err!=MAILIMAP_NO_ERROR) { 136 if (err!=MAILIMAP_NO_ERROR) {
138 logout(); 137 logout();
139 } else { 138 } else {
140 mailstream_flush(m_imap->imap_stream); 139 mailstream_flush(m_imap->imap_stream);
141 return; 140 return;
142 } 141 }
143 } 142 }
144 server = account->getServer(); 143 server = account->getServer();
145 port = account->getPort().toUInt(); 144 port = account->getPort().toUInt();
146 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 145 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
147 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 146 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
148 login.show(); 147 login.show();
149 if ( QDialog::Accepted == login.exec() ) { 148 if ( QDialog::Accepted == login.exec() ) {
150 // ok 149 // ok
151 user = login.getUser(); 150 user = login.getUser();
152 pass = login.getPassword(); 151 pass = login.getPassword();
153 } else { 152 } else {
154 // cancel 153 // cancel
155 return; 154 return;
156 } 155 }
157 } else { 156 } else {
158 user = account->getUser(); 157 user = account->getUser();
159 pass = account->getPassword(); 158 pass = account->getPassword();
160 } 159 }
161
162 m_imap = mailimap_new( 20, &imap_progress ); 160 m_imap = mailimap_new( 20, &imap_progress );
163 161
164 /* connect */ 162 /* connect */
165 bool ssl = false; 163 bool ssl = false;
166 bool try_tls = false; 164 bool try_tls = false;
167 bool force_tls = false; 165 bool force_tls = false;
168 166
169 if ( account->ConnectionType() == 2 ) { 167 if ( account->ConnectionType() == 2 ) {
170 ssl = true; 168 ssl = true;
171 } 169 }
172 if (account->ConnectionType()==1) { 170 if (account->ConnectionType()==1) {
173 force_tls = true; 171 force_tls = true;
174 } 172 }
175 173
176 if ( ssl ) { 174 if ( ssl ) {
177 qDebug("using ssl "); 175 //qDebug("using ssl ");
178 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); 176 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port );
179 qDebug("back "); 177 //qDebug("back ");
180 } else { 178 } else {
181 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); 179 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port );
182 } 180 }
183 181
184 if ( err != MAILIMAP_NO_ERROR && 182 if ( err != MAILIMAP_NO_ERROR &&
185 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 183 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
186 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 184 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
187 QString failure = ""; 185 QString failure = "";
188 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 186 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
189 failure="Connection refused"; 187 failure="Connection refused";
190 } else { 188 } else {
191 failure="Unknown failure"; 189 failure="Unknown failure";
192 } 190 }
193 Global::statusMessage(i18n("error connecting imap server: %1").arg(failure)); 191 Global::statusMessage(i18n("error connecting imap server: %1").arg(failure));
194 mailimap_free( m_imap ); 192 mailimap_free( m_imap );
195 m_imap = 0; 193 m_imap = 0;
196 return; 194 return;
197 } 195 }
198 if ( tryTLS ) { 196 if ( tryTLS ) {
199 if (!ssl) { 197 if (!ssl) {
200 try_tls = start_tls(force_tls); 198 try_tls = start_tls(force_tls);
201 } 199 }
202 } 200 }
203 bool ok = true; 201 bool ok = true;
204 if (force_tls && !try_tls) { 202 if (force_tls && !try_tls) {
205 Global::statusMessage(i18n("Server has no TLS support!")); 203 Global::statusMessage(i18n("Server has no TLS support!"));
206 ok = false; 204 ok = false;
207 } 205 }
208 206
209 207
210 /* login */ 208 /* login */
211 209
212 if (ok) { 210 if (ok) {
213 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); 211 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() );
214 if ( err != MAILIMAP_NO_ERROR ) { 212 if ( err != MAILIMAP_NO_ERROR ) {
215 if ( tryTLS && !force_tls && !try_tls ) { 213 if ( tryTLS && !force_tls && !try_tls ) {
216 err = mailimap_close( m_imap ); 214 err = mailimap_close( m_imap );
217 mailimap_free( m_imap ); 215 mailimap_free( m_imap );
218 m_imap = 0; 216 m_imap = 0;
219 login( false ); 217 login( false );
220 return; 218 return;
221 } 219 }
222 Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response)); 220 Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response));
223 ok = false; 221 ok = false;
224 } 222 }
225 } 223 }
226 if (!ok) { 224 if (!ok) {
227 err = mailimap_close( m_imap ); 225 err = mailimap_close( m_imap );
228 mailimap_free( m_imap ); 226 mailimap_free( m_imap );
229 m_imap = 0; 227 m_imap = 0;
230 } 228 }
231} 229}
232 230
233void IMAPwrapper::logout() 231void IMAPwrapper::logout()
234{ 232{
235 int err = MAILIMAP_NO_ERROR; 233 int err = MAILIMAP_NO_ERROR;
236 if (!m_imap) return; 234 if (!m_imap) return;
237 err = mailimap_logout( m_imap ); 235 err = mailimap_logout( m_imap );
238 err = mailimap_close( m_imap ); 236 err = mailimap_close( m_imap );
239 mailimap_free( m_imap ); 237 mailimap_free( m_imap );
240 m_imap = 0; 238 m_imap = 0;
241 m_Lastmbox = ""; 239 m_Lastmbox = "";
242} 240}
243 241
244void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) 242void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb)
245{ 243{
246 244
247 int tryAgain = 1; 245 int tryAgain = 1;
248 while ( tryAgain >= 0 ) { 246 while ( tryAgain >= 0 ) {
249 int err = MAILIMAP_NO_ERROR; 247 int err = MAILIMAP_NO_ERROR;
250 clist *result = 0; 248 clist *result = 0;
251 clistcell *current; 249 clistcell *current;
252 mailimap_fetch_type *fetchType = 0; 250 mailimap_fetch_type *fetchType = 0;
253 mailimap_set *set = 0; 251 mailimap_set *set = 0;
254 252
255 login(); 253 login();
256 if (!m_imap) { 254 if (!m_imap) {
257 return; 255 return;
258 } 256 }
259 /* select mailbox READONLY for operations */ 257 /* select mailbox READONLY for operations */
260 err = selectMbox(mailbox); 258 err = selectMbox(mailbox);
261 if ( err != MAILIMAP_NO_ERROR ) { 259 if ( err != MAILIMAP_NO_ERROR ) {
262 return; 260 return;
263 } 261 }
264 262
265 int last = m_imap->imap_selection_info->sel_exists; 263 int last = m_imap->imap_selection_info->sel_exists;
266 264
267 if (last == 0) { 265 if (last == 0) {
268 Global::statusMessage(i18n("Mailbox has no mails")); 266 Global::statusMessage(i18n("Mailbox has no mails"));
269 return; 267 return;
270 } else { 268 } else {
271 } 269 }
272 progress( i18n("Fetch ")); 270 progress( i18n("Fetch "));
273 mMax = last; 271 mMax = last;
274 //qDebug("last %d ", last); 272 //qDebug("last %d ", last);
275 Global::statusMessage(i18n("Fetching header list")); 273 Global::statusMessage(i18n("Fetching header list"));
276 qApp->processEvents(); 274 qApp->processEvents();
277 /* the range has to start at 1!!! not with 0!!!! */ 275 /* the range has to start at 1!!! not with 0!!!! */
278 //LR the access to web.de imap server is no working with value 1 276 //LR the access to web.de imap server is no working with value 1
279 //qDebug("interval %d - %d ", tryAgain, last-1+tryAgain ); 277 //qDebug("interval %d - %d ", tryAgain, last-1+tryAgain );
280 set = mailimap_set_new_interval( tryAgain, last ); 278 set = mailimap_set_new_interval( tryAgain, last );
281 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 279 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
282 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 280 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
283 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 281 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
284 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 282 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
285 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 283 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
286 284
287 err = mailimap_fetch( m_imap, set, fetchType, &result ); 285 err = mailimap_fetch( m_imap, set, fetchType, &result );
288 mailimap_set_free( set ); 286 mailimap_set_free( set );
289 mailimap_fetch_type_free( fetchType ); 287 mailimap_fetch_type_free( fetchType );
290 288
291 QString date,subject,from; 289 QString date,subject,from;
292 290
293 if ( err == MAILIMAP_NO_ERROR ) { 291 if ( err == MAILIMAP_NO_ERROR ) {
294 tryAgain = -1; 292 tryAgain = -1;
295 mailimap_msg_att * msg_att; 293 mailimap_msg_att * msg_att;
296 int i = 0; 294 int i = 0;
297 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 295 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
298 ++i; 296 ++i;
299 //qDebug("iii %d ",i); 297 //qDebug("iii %d ",i);
300 msg_att = (mailimap_msg_att*)current->data; 298 msg_att = (mailimap_msg_att*)current->data;
301 RecMail*m = parse_list_result(msg_att); 299 RecMail*m = parse_list_result(msg_att);
302 if (m) { 300 if (m) {
303 if ( maxSizeInKb == 0 || m->Msgsize()<=(unsigned int ) maxSizeInKb*1024 ) { 301 if ( maxSizeInKb == 0 || m->Msgsize()<=(unsigned int ) maxSizeInKb*1024 ) {
304 m->setNumber(i); 302 m->setNumber(i);
305 m->setMbox(mailbox); 303 m->setMbox(mailbox);
306 m->setWrapper(this); 304 m->setWrapper(this);
307 target.append(m); 305 target.append(m);
308 } 306 }
309 } 307 }
310 } 308 }
311 Global::statusMessage(i18n("Mailbox has %1 mails").arg(target.count())); 309 Global::statusMessage(i18n("Mailbox has %1 mails").arg(target.count()));
312 } else { 310 } else {
313 --tryAgain; 311 --tryAgain;
314 --tryAgain;//disabled tryagain by adding this line 312 --tryAgain;//disabled tryagain by adding this line
315 if ( tryAgain < 0 ) 313 if ( tryAgain < 0 )
316 Global::statusMessage(i18n("Error fetching headers: %1").arg(m_imap->imap_response)); 314 Global::statusMessage(i18n("Error fetching headers: %1").arg(m_imap->imap_response));
317 else 315 else
318 qDebug("try again... "); 316 qDebug("try again... ");
319 } 317 }
320 318
321 if (result) mailimap_fetch_list_free(result); 319 if (result) mailimap_fetch_list_free(result);
322 } 320 }
323} 321}
324 322
325QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() 323QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders()
326{ 324{
327 const char *path, *mask; 325 const char *path, *mask;
328 int err = MAILIMAP_NO_ERROR; 326 int err = MAILIMAP_NO_ERROR;
329 clist *result = 0; 327 clist *result = 0;
330 clistcell *current = 0; 328 clistcell *current = 0;
331 clistcell*cur_flag = 0; 329 clistcell*cur_flag = 0;
332 mailimap_mbx_list_flags*bflags = 0; 330 mailimap_mbx_list_flags*bflags = 0;
333 331
334 QValueList<FolderP>* folders = new QValueList<FolderP>(); 332 QValueList<FolderP>* folders = new QValueList<FolderP>();
335 login(); 333 login();
336 if (!m_imap) { 334 if (!m_imap) {
337 return folders; 335 return folders;
338 } 336 }
339 337
340/* 338/*
341 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 339 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
342 * We must not forget to filter them out in next loop! 340 * We must not forget to filter them out in next loop!
343 * it seems like ugly code. and yes - it is ugly code. but the best way. 341 * it seems like ugly code. and yes - it is ugly code. but the best way.
344 */ 342 */
345 Global::statusMessage(i18n("Fetching folder list")); 343 Global::statusMessage(i18n("Fetching folder list"));
346 qApp->processEvents(); 344 qApp->processEvents();
347 QString temp; 345 QString temp;
348 mask = "INBOX" ; 346 mask = "INBOX" ;
349 mailimap_mailbox_list *list; 347 mailimap_mailbox_list *list;
350 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 348 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
351 QString del; 349 QString del;
352 bool selectable = true; 350 bool selectable = true;
353 bool no_inferiors = false; 351 bool no_inferiors = false;
354 if ( err == MAILIMAP_NO_ERROR ) { 352 if ( err == MAILIMAP_NO_ERROR ) {
355 current = result->first; 353 current = result->first;
356 for ( int i = result->count; i > 0; i-- ) { 354 for ( int i = result->count; i > 0; i-- ) {
357 list = (mailimap_mailbox_list *) current->data; 355 list = (mailimap_mailbox_list *) current->data;
358 // it is better use the deep copy mechanism of qt itself 356 // it is better use the deep copy mechanism of qt itself
359 // instead of using strdup! 357 // instead of using strdup!
360 temp = list->mb_name; 358 temp = list->mb_name;
361 del = list->mb_delimiter; 359 del = list->mb_delimiter;
362 current = current->next; 360 current = current->next;
363 if ( (bflags = list->mb_flag) ) { 361 if ( (bflags = list->mb_flag) ) {
364 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 362 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
365 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 363 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
366 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 364 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
367 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 365 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
368 no_inferiors = true; 366 no_inferiors = true;
369 } 367 }
370 } 368 }
371 } 369 }