author | zautrix <zautrix> | 2005-08-22 18:52:57 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-08-22 18:52:57 (UTC) |
commit | cb425b4c2d027d49f964368e94a52d3ba5e6aa31 (patch) (unidiff) | |
tree | b867e4c565aab6965059306bac24dd3ab5ca3750 /kmicromail | |
parent | e011ace92e07174effca53b7dde20b9a5b695af0 (diff) | |
download | kdepimpi-cb425b4c2d027d49f964368e94a52d3ba5e6aa31.zip kdepimpi-cb425b4c2d027d49f964368e94a52d3ba5e6aa31.tar.gz kdepimpi-cb425b4c2d027d49f964368e94a52d3ba5e6aa31.tar.bz2 |
ompi fixes
-rw-r--r-- | kmicromail/accountview.cpp | 39 | ||||
-rw-r--r-- | kmicromail/accountview.h | 1 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.cpp | 6 |
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 | ||
21 | using namespace Opie::Core; | 23 | using namespace Opie::Core; |
22 | AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) | 24 | AccountView::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 | ||
32 | AccountView::~AccountView() | 38 | AccountView::~AccountView() |
33 | { | 39 | { |
34 | imapAccounts.clear(); | 40 | imapAccounts.clear(); |
35 | mhAccounts.clear(); | 41 | mhAccounts.clear(); |
36 | } | 42 | } |
37 | 43 | ||
38 | void AccountView::slotContextMenu(int id) | 44 | void 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 | ||
45 | void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int) | 51 | void 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 | ||
58 | void AccountView::populate( QList<Account> list ) | 64 | void 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 | ||
90 | void AccountView::refresh(QListViewItem *item) | 96 | void 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 | } |
101 | void AccountView::refreshOutgoing() | 111 | void 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 | 134 | void AccountView::refreshCurrentSelected() | |
125 | void 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 | |||
144 | void 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 | ||
135 | void AccountView::refreshAll() | 152 | void AccountView::refreshAll() |
136 | { | 153 | { |
137 | } | 154 | } |
138 | 155 | ||
139 | RecBodyP AccountView::fetchBody(const RecMailP&aMail) | 156 | RecBodyP 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 | ||
147 | void AccountView::setupFolderselect(Selectstore*sels) | 164 | void 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 | } |
171 | void AccountView::downloadMailsInbox(const FolderP&fromFolder,AbstractMail*fromWrapper) | 188 | void 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 | ||
202 | void AccountView::downloadMails(const FolderP&fromFolder,AbstractMail*fromWrapper) | 219 | void 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 | ||
230 | bool AccountView::currentisDraft() | 247 | bool 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 | ||
9 | class Selectstore; | 9 | class Selectstore; |
10 | class Folder; | 10 | class Folder; |
11 | class AbstractMail; | 11 | class AbstractMail; |
12 | class Account; | 12 | class Account; |
13 | class IMAPviewItem; | 13 | class IMAPviewItem; |
14 | class MHviewItem; | 14 | class MHviewItem; |
15 | 15 | ||
16 | class AccountView : public QListView | 16 | class AccountView : public QListView |
17 | { | 17 | { |
18 | Q_OBJECT | 18 | Q_OBJECT |
19 | 19 | ||
20 | public: | 20 | public: |
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;} |
29 | public slots: | 29 | public 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 | ||
38 | signals: | 39 | signals: |
39 | void refreshMailview(const QValueList<RecMailP>& ); | 40 | void refreshMailview(const QValueList<RecMailP>& ); |
40 | 41 | ||
41 | protected: | 42 | protected: |
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,947 +1,945 @@ | |||
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 | ||
13 | using namespace Opie::Core; | 13 | using namespace Opie::Core; |
14 | int IMAPwrapper::mMax = 0; | 14 | int IMAPwrapper::mMax = 0; |
15 | int IMAPwrapper::mCurrent = 0; | 15 | int IMAPwrapper::mCurrent = 0; |
16 | 16 | ||
17 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 17 | IMAPwrapper::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 | ||
27 | IMAPwrapper::~IMAPwrapper() | 27 | IMAPwrapper::~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!*/ |
34 | int IMAPwrapper::selectMbox(const QString&mbox) | 34 | int 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 | ||
48 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 48 | void 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 | } |
60 | void IMAPwrapper::progress( QString m ) | 59 | void 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 | } |
76 | bool IMAPwrapper::start_tls(bool force_tls) | 75 | bool 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 | ||
126 | void IMAPwrapper::login(bool tryTLS) // = true) | 125 | void 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 | ||
233 | void IMAPwrapper::logout() | 231 | void 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 | ||
244 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) | 242 | void 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 | ||
325 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() | 323 | QValueList<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 | } |
372 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 370 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
373 | } | 371 | } |
374 | } else { | 372 | } else { |
375 | qDebug("error fetching folders: "); | 373 | qDebug("error fetching folders: "); |
376 | 374 | ||
377 | } | 375 | } |
378 | mailimap_list_result_free( result ); | 376 | mailimap_list_result_free( result ); |
379 | 377 | ||
380 | /* | 378 | /* |
381 | * second stage - get the other then inbox folders | 379 | * second stage - get the other then inbox folders |
382 | */ | 380 | */ |
383 | mask = "*" ; | 381 | mask = "*" ; |
384 | path = account->getPrefix().latin1(); | 382 | path = account->getPrefix().latin1(); |
385 | if (!path) path = ""; | 383 | if (!path) path = ""; |
386 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 384 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
387 | if ( err == MAILIMAP_NO_ERROR ) { | 385 | if ( err == MAILIMAP_NO_ERROR ) { |
388 | current = result->first; | 386 | current = result->first; |
389 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 387 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
390 | no_inferiors = false; | 388 | no_inferiors = false; |
391 | list = (mailimap_mailbox_list *) current->data; | 389 | list = (mailimap_mailbox_list *) current->data; |
392 | // it is better use the deep copy mechanism of qt itself | 390 | // it is better use the deep copy mechanism of qt itself |
393 | // instead of using strdup! | 391 | // instead of using strdup! |
394 | temp = list->mb_name; | 392 | temp = list->mb_name; |
395 | if (temp.lower()=="inbox") | 393 | if (temp.lower()=="inbox") |
396 | continue; | 394 | continue; |
397 | if (temp.lower()==account->getPrefix().lower()) | 395 | if (temp.lower()==account->getPrefix().lower()) |
398 | continue; | 396 | continue; |
399 | if ( (bflags = list->mb_flag) ) { | 397 | if ( (bflags = list->mb_flag) ) { |
400 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 398 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
401 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 399 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
402 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 400 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
403 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 401 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
404 | no_inferiors = true; | 402 | no_inferiors = true; |
405 | } | 403 | } |
406 | } | 404 | } |
407 | } | 405 | } |
408 | del = list->mb_delimiter; | 406 | del = list->mb_delimiter; |
409 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 407 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
410 | } | 408 | } |
411 | } else { | 409 | } else { |
412 | qDebug("error fetching folders "); | 410 | qDebug("error fetching folders "); |
413 | 411 | ||
414 | } | 412 | } |
415 | if (result) mailimap_list_result_free( result ); | 413 | if (result) mailimap_list_result_free( result ); |
416 | return folders; | 414 | return folders; |
417 | } | 415 | } |
418 | 416 | ||
419 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 417 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
420 | { | 418 | { |
421 | RecMail * m = 0; | 419 | RecMail * m = 0; |
422 | mailimap_msg_att_item *item=0; | 420 | mailimap_msg_att_item *item=0; |
423 | clistcell *current,*c,*cf; | 421 | clistcell *current,*c,*cf; |
424 | mailimap_msg_att_dynamic*flist; | 422 | mailimap_msg_att_dynamic*flist; |
425 | mailimap_flag_fetch*cflag; | 423 | mailimap_flag_fetch*cflag; |
426 | int size = 0; | 424 | int size = 0; |
427 | QBitArray mFlags(7); | 425 | QBitArray mFlags(7); |
428 | QStringList addresslist; | 426 | QStringList addresslist; |
429 | 427 | ||
430 | if (!m_att) { | 428 | if (!m_att) { |
431 | return m; | 429 | return m; |
432 | } | 430 | } |
433 | m = new RecMail(); | 431 | m = new RecMail(); |
434 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 432 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
435 | current = c; | 433 | current = c; |
436 | size = 0; | 434 | size = 0; |
437 | item = (mailimap_msg_att_item*)current->data; | 435 | item = (mailimap_msg_att_item*)current->data; |
438 | if ( !item ) | 436 | if ( !item ) |
439 | continue; | 437 | continue; |
440 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 438 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
441 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 439 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
442 | if (!flist || !flist->att_list) { | 440 | if (!flist || !flist->att_list) { |
443 | continue; | 441 | continue; |
444 | } | 442 | } |
445 | cf = flist->att_list->first; | 443 | cf = flist->att_list->first; |
446 | if( cf ) { | 444 | if( cf ) { |
447 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 445 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
448 | cflag = (mailimap_flag_fetch*)cf->data; | 446 | cflag = (mailimap_flag_fetch*)cf->data; |
449 | if( ! cflag ) | 447 | if( ! cflag ) |
450 | qDebug("imap:NO cflag "); | 448 | qDebug("imap:NO cflag "); |
451 | else { | 449 | else { |
452 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 450 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
453 | switch (cflag->fl_flag->fl_type) { | 451 | switch (cflag->fl_flag->fl_type) { |
454 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 452 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
455 | mFlags.setBit(FLAG_ANSWERED); | 453 | mFlags.setBit(FLAG_ANSWERED); |
456 | break; | 454 | break; |
457 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 455 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
458 | mFlags.setBit(FLAG_FLAGGED); | 456 | mFlags.setBit(FLAG_FLAGGED); |
459 | break; | 457 | break; |
460 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 458 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
461 | mFlags.setBit(FLAG_DELETED); | 459 | mFlags.setBit(FLAG_DELETED); |
462 | break; | 460 | break; |
463 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 461 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
464 | mFlags.setBit(FLAG_SEEN); | 462 | mFlags.setBit(FLAG_SEEN); |
465 | break; | 463 | break; |
466 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 464 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
467 | mFlags.setBit(FLAG_DRAFT); | 465 | mFlags.setBit(FLAG_DRAFT); |
468 | break; | 466 | break; |
469 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 467 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
470 | break; | 468 | break; |
471 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 469 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
472 | break; | 470 | break; |
473 | default: | 471 | default: |
474 | break; | 472 | break; |
475 | } | 473 | } |
476 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 474 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
477 | mFlags.setBit(FLAG_RECENT); | 475 | mFlags.setBit(FLAG_RECENT); |
478 | } | 476 | } |
479 | } | 477 | } |
480 | } | 478 | } |
481 | } | 479 | } |
482 | //qDebug(" continue"); | 480 | //qDebug(" continue"); |
483 | continue; | 481 | continue; |
484 | } | 482 | } |
485 | if ( item->att_data.att_static == NULL ) | 483 | if ( item->att_data.att_static == NULL ) |
486 | continue; | 484 | continue; |
487 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 485 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
488 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 486 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
489 | if ( head == NULL ) | 487 | if ( head == NULL ) |
490 | continue; | 488 | continue; |
491 | if ( head->env_date != NULL ) { | 489 | if ( head->env_date != NULL ) { |
492 | m->setDate(head->env_date); | 490 | m->setDate(head->env_date); |
493 | //struct mailimf_date_time result; | 491 | //struct mailimf_date_time result; |
494 | struct mailimf_date_time* date;// = &result; | 492 | struct mailimf_date_time* date;// = &result; |
495 | struct mailimf_date_time **re = &date; | 493 | struct mailimf_date_time **re = &date; |
496 | size_t length = m->getDate().length(); | 494 | size_t length = m->getDate().length(); |
497 | size_t index = 0; | 495 | size_t index = 0; |
498 | if ( mailimf_date_time_parse(head->env_date, length,&index, re ) == MAILIMF_NO_ERROR ) { | 496 | if ( mailimf_date_time_parse(head->env_date, length,&index, re ) == MAILIMF_NO_ERROR ) { |
499 | //qDebug("parseDateTime "); | 497 | //qDebug("parseDateTime "); |
500 | QDateTime dt = Genericwrapper::parseDateTime( date ); | 498 | QDateTime dt = Genericwrapper::parseDateTime( date ); |
501 | QString ret; | 499 | QString ret; |
502 | if ( dt.date() == QDate::currentDate () ) | 500 | if ( dt.date() == QDate::currentDate () ) |
503 | ret = KGlobal::locale()->formatTime( dt.time(),true); | 501 | ret = KGlobal::locale()->formatTime( dt.time(),true); |
504 | else { | 502 | else { |
505 | ret = KGlobal::locale()->formatDateTime( dt,true,true); | 503 | ret = KGlobal::locale()->formatDateTime( dt,true,true); |
506 | } | 504 | } |
507 | m->setDate( ret ); | 505 | m->setDate( ret ); |
508 | char tmp[20]; | 506 | char tmp[20]; |
509 | snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", | 507 | snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", |
510 | dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); | 508 | dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); |
511 | //qDebug("%d iso %s %s ", date->dt_zone, tmp, head->env_date); | 509 | //qDebug("%d iso %s %s ", date->dt_zone, tmp, head->env_date); |
512 | m->setIsoDate( QString( tmp ) ); | 510 | m->setIsoDate( QString( tmp ) ); |
513 | mailimf_date_time_free ( date ); | 511 | mailimf_date_time_free ( date ); |
514 | } else { | 512 | } else { |
515 | m->setIsoDate(head->env_date); | 513 | m->setIsoDate(head->env_date); |
516 | } | 514 | } |
517 | } | 515 | } |
518 | if ( head->env_subject != NULL ) | 516 | if ( head->env_subject != NULL ) |
519 | m->setSubject(convert_String((const char*)head->env_subject)); | 517 | m->setSubject(convert_String((const char*)head->env_subject)); |
520 | //m->setSubject(head->env_subject); | 518 | //m->setSubject(head->env_subject); |
521 | if (head->env_from!=NULL) { | 519 | if (head->env_from!=NULL) { |
522 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 520 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
523 | if (addresslist.count()) { | 521 | if (addresslist.count()) { |
524 | m->setFrom(addresslist.first()); | 522 | m->setFrom(addresslist.first()); |
525 | } | 523 | } |
526 | } | 524 | } |
527 | if (head->env_to!=NULL) { | 525 | if (head->env_to!=NULL) { |
528 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 526 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
529 | m->setTo(addresslist); | 527 | m->setTo(addresslist); |
530 | } | 528 | } |
531 | if (head->env_cc!=NULL) { | 529 | if (head->env_cc!=NULL) { |
532 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 530 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
533 | m->setCC(addresslist); | 531 | m->setCC(addresslist); |
534 | } | 532 | } |
535 | if (head->env_bcc!=NULL) { | 533 | if (head->env_bcc!=NULL) { |
536 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 534 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
537 | m->setBcc(addresslist); | 535 | m->setBcc(addresslist); |
538 | } | 536 | } |
539 | /* reply to address, eg. email. */ | 537 | /* reply to address, eg. email. */ |
540 | if (head->env_reply_to!=NULL) { | 538 | if (head->env_reply_to!=NULL) { |
541 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 539 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
542 | if (addresslist.count()) { | 540 | if (addresslist.count()) { |
543 | m->setReplyto(addresslist.first()); | 541 | m->setReplyto(addresslist.first()); |
544 | } | 542 | } |
545 | } | 543 | } |
546 | if (head->env_in_reply_to!=NULL) { | 544 | if (head->env_in_reply_to!=NULL) { |
547 | QString h(head->env_in_reply_to); | 545 | QString h(head->env_in_reply_to); |
548 | while (h.length()>0 && h[0]=='<') { | 546 | while (h.length()>0 && h[0]=='<') { |
549 | h.remove(0,1); | 547 | h.remove(0,1); |
550 | } | 548 | } |
551 | while (h.length()>0 && h[h.length()-1]=='>') { | 549 | while (h.length()>0 && h[h.length()-1]=='>') { |
552 | h.remove(h.length()-1,1); | 550 | h.remove(h.length()-1,1); |
553 | } | 551 | } |
554 | if (h.length()>0) { | 552 | if (h.length()>0) { |
555 | m->setInreply(QStringList(h)); | 553 | m->setInreply(QStringList(h)); |
556 | } | 554 | } |
557 | } | 555 | } |
558 | if (head->env_message_id != NULL) { | 556 | if (head->env_message_id != NULL) { |
559 | m->setMsgid(QString(head->env_message_id)); | 557 | m->setMsgid(QString(head->env_message_id)); |
560 | } | 558 | } |
561 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 559 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
562 | #if 0 | 560 | #if 0 |
563 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 561 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
564 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 562 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
565 | qDebug("time %s ",da.toString().latin1() ); | 563 | qDebug("time %s ",da.toString().latin1() ); |
566 | #endif | 564 | #endif |
567 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 565 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
568 | size = item->att_data.att_static->att_data.att_rfc822_size; | 566 | size = item->att_data.att_static->att_data.att_rfc822_size; |
569 | } | 567 | } |
570 | } | 568 | } |
571 | /* msg is already deleted */ | 569 | /* msg is already deleted */ |
572 | if (mFlags.testBit(FLAG_DELETED) && m) { | 570 | if (mFlags.testBit(FLAG_DELETED) && m) { |
573 | delete m; | 571 | delete m; |
574 | m = 0; | 572 | m = 0; |
575 | } | 573 | } |
576 | if (m) { | 574 | if (m) { |
577 | m->setFlags(mFlags); | 575 | m->setFlags(mFlags); |
578 | m->setMsgsize(size); | 576 | m->setMsgsize(size); |
579 | } | 577 | } |
580 | return m; | 578 | return m; |
581 | } | 579 | } |
582 | 580 | ||
583 | RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) | 581 | RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) |
584 | { | 582 | { |
585 | RecBodyP body = new RecBody(); | 583 | RecBodyP body = new RecBody(); |
586 | const char *mb; | 584 | const char *mb; |
587 | int err = MAILIMAP_NO_ERROR; | 585 | int err = MAILIMAP_NO_ERROR; |
588 | clist *result = 0; | 586 | clist *result = 0; |
589 | clistcell *current; | 587 | clistcell *current; |
590 | mailimap_fetch_att *fetchAtt = 0; | 588 | mailimap_fetch_att *fetchAtt = 0; |
591 | mailimap_fetch_type *fetchType = 0; | 589 | mailimap_fetch_type *fetchType = 0; |
592 | mailimap_set *set = 0; | 590 | mailimap_set *set = 0; |
593 | mailimap_body*body_desc = 0; | 591 | mailimap_body*body_desc = 0; |
594 | 592 | ||
595 | mb = mail->getMbox().latin1(); | 593 | mb = mail->getMbox().latin1(); |
596 | 594 | ||
597 | login(); | 595 | login(); |
598 | if (!m_imap) { | 596 | if (!m_imap) { |
599 | return body; | 597 | return body; |
600 | } | 598 | } |
601 | err = selectMbox(mail->getMbox()); | 599 | err = selectMbox(mail->getMbox()); |
602 | if ( err != MAILIMAP_NO_ERROR ) { | 600 | if ( err != MAILIMAP_NO_ERROR ) { |
603 | return body; | 601 | return body; |
604 | } | 602 | } |
605 | 603 | ||
606 | /* the range has to start at 1!!! not with 0!!!! */ | 604 | /* the range has to start at 1!!! not with 0!!!! */ |
607 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); | 605 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); |
608 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 606 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
609 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 607 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
610 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 608 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
611 | mailimap_set_free( set ); | 609 | mailimap_set_free( set ); |
612 | mailimap_fetch_type_free( fetchType ); | 610 | mailimap_fetch_type_free( fetchType ); |
613 | 611 | ||
614 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 612 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
615 | mailimap_msg_att * msg_att; | 613 | mailimap_msg_att * msg_att; |
616 | msg_att = (mailimap_msg_att*)current->data; | 614 | msg_att = (mailimap_msg_att*)current->data; |
617 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 615 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
618 | QValueList<int> path; | 616 | QValueList<int> path; |
619 | body_desc = item->att_data.att_static->att_data.att_body; | 617 | body_desc = item->att_data.att_static->att_data.att_body; |
620 | traverseBody(mail,body_desc,body,0,path); | 618 | traverseBody(mail,body_desc,body,0,path); |
621 | } else { | 619 | } else { |
622 | qDebug("error fetching body %d (%d): %s", err, MAILIMAP_NO_ERROR, m_imap->imap_response ); | 620 | qDebug("error fetching body %d (%d): %s", err, MAILIMAP_NO_ERROR, m_imap->imap_response ); |
623 | } | 621 | } |
624 | if (result) mailimap_fetch_list_free(result); | 622 | if (result) mailimap_fetch_list_free(result); |
625 | return body; | 623 | return body; |
626 | } | 624 | } |
627 | 625 | ||
628 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 626 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
629 | { | 627 | { |
630 | QStringList l; | 628 | QStringList l; |
631 | QString from; | 629 | QString from; |
632 | bool named_from; | 630 | bool named_from; |
633 | clistcell *current = NULL; | 631 | clistcell *current = NULL; |
634 | mailimap_address * current_address=NULL; | 632 | mailimap_address * current_address=NULL; |
635 | if (!list) { | 633 | if (!list) { |
636 | return l; | 634 | return l; |
637 | } | 635 | } |
638 | unsigned int count = 0; | 636 | unsigned int count = 0; |
639 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 637 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
640 | from = ""; | 638 | from = ""; |
641 | named_from = false; | 639 | named_from = false; |
642 | current_address=(mailimap_address*)current->data; | 640 | current_address=(mailimap_address*)current->data; |
643 | if (current_address->ad_personal_name){ | 641 | if (current_address->ad_personal_name){ |
644 | from+=convert_String((const char*)current_address->ad_personal_name); | 642 | from+=convert_String((const char*)current_address->ad_personal_name); |
645 | from+=" "; | 643 | from+=" "; |
646 | named_from = true; | 644 | named_from = true; |
647 | } | 645 | } |
648 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 646 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
649 | from+="<"; | 647 | from+="<"; |
650 | } | 648 | } |
651 | if (current_address->ad_mailbox_name) { | 649 | if (current_address->ad_mailbox_name) { |
652 | from+=QString(current_address->ad_mailbox_name); | 650 | from+=QString(current_address->ad_mailbox_name); |
653 | from+="@"; | 651 | from+="@"; |
654 | } | 652 | } |
655 | if (current_address->ad_host_name) { | 653 | if (current_address->ad_host_name) { |
656 | from+=QString(current_address->ad_host_name); | 654 | from+=QString(current_address->ad_host_name); |
657 | } | 655 | } |
658 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 656 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
659 | from+=">"; | 657 | from+=">"; |
660 | } | 658 | } |
661 | l.append(QString(from)); | 659 | l.append(QString(from)); |
662 | if (++count > 99) { | 660 | if (++count > 99) { |
663 | break; | 661 | break; |
664 | } | 662 | } |
665 | } | 663 | } |
666 | return l; | 664 | return l; |
667 | } | 665 | } |
668 | 666 | ||
669 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) | 667 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) |
670 | { | 668 | { |
671 | encodedString*res=new encodedString; | 669 | encodedString*res=new encodedString; |
672 | int err; | 670 | int err; |
673 | mailimap_fetch_type *fetchType; | 671 | mailimap_fetch_type *fetchType; |
674 | mailimap_set *set; | 672 | mailimap_set *set; |
675 | clistcell*current,*cur; | 673 | clistcell*current,*cur; |
676 | mailimap_section_part * section_part = 0; | 674 | mailimap_section_part * section_part = 0; |
677 | mailimap_section_spec * section_spec = 0; | 675 | mailimap_section_spec * section_spec = 0; |
678 | mailimap_section * section = 0; | 676 | mailimap_section * section = 0; |
679 | mailimap_fetch_att * fetch_att = 0; | 677 | mailimap_fetch_att * fetch_att = 0; |
680 | 678 | ||
681 | login(); | 679 | login(); |
682 | if (!m_imap) { | 680 | if (!m_imap) { |
683 | return res; | 681 | return res; |
684 | } | 682 | } |
685 | if (!internal_call) { | 683 | if (!internal_call) { |
686 | err = selectMbox(mail->getMbox()); | 684 | err = selectMbox(mail->getMbox()); |
687 | if ( err != MAILIMAP_NO_ERROR ) { | 685 | if ( err != MAILIMAP_NO_ERROR ) { |
688 | return res; | 686 | return res; |
689 | } | 687 | } |
690 | } | 688 | } |
691 | set = mailimap_set_new_single(mail->getNumber()); | 689 | set = mailimap_set_new_single(mail->getNumber()); |
692 | 690 | ||
693 | clist*id_list = 0; | 691 | clist*id_list = 0; |
694 | 692 | ||
695 | /* if path == empty then its a request for the whole rfc822 mail and generates | 693 | /* if path == empty then its a request for the whole rfc822 mail and generates |
696 | a "fetch <id> (body[])" statement on imap server */ | 694 | a "fetch <id> (body[])" statement on imap server */ |
697 | if (path.count()>0 ) { | 695 | if (path.count()>0 ) { |
698 | id_list = clist_new(); | 696 | id_list = clist_new(); |
699 | for (unsigned j=0; j < path.count();++j) { | 697 | for (unsigned j=0; j < path.count();++j) { |
700 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 698 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
701 | *p_id = path[j]; | 699 | *p_id = path[j]; |
702 | clist_append(id_list,p_id); | 700 | clist_append(id_list,p_id); |
703 | } | 701 | } |
704 | section_part = mailimap_section_part_new(id_list); | 702 | section_part = mailimap_section_part_new(id_list); |
705 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 703 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
706 | } | 704 | } |
707 | 705 | ||
708 | section = mailimap_section_new(section_spec); | 706 | section = mailimap_section_new(section_spec); |
709 | fetch_att = mailimap_fetch_att_new_body_section(section); | 707 | fetch_att = mailimap_fetch_att_new_body_section(section); |
710 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 708 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
711 | 709 | ||
712 | clist*result = 0; | 710 | clist*result = 0; |
713 | 711 | ||
714 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 712 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
715 | mailimap_set_free( set ); | 713 | mailimap_set_free( set ); |
716 | mailimap_fetch_type_free( fetchType ); | 714 | mailimap_fetch_type_free( fetchType ); |
717 | 715 | ||
718 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 716 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
719 | mailimap_msg_att * msg_att; | 717 | mailimap_msg_att * msg_att; |
720 | msg_att = (mailimap_msg_att*)current->data; | 718 | msg_att = (mailimap_msg_att*)current->data; |
721 | mailimap_msg_att_item*msg_att_item; | 719 | mailimap_msg_att_item*msg_att_item; |
722 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 720 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
723 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 721 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
724 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 722 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
725 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 723 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
726 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 724 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
727 | /* detach - we take over the content */ | 725 | /* detach - we take over the content */ |
728 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 726 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
729 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 727 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
730 | } | 728 | } |
731 | } | 729 | } |
732 | } | 730 | } |
733 | } else { | 731 | } else { |
734 | ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; | 732 | ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; |
735 | } | 733 | } |
736 | if (result) mailimap_fetch_list_free(result); | 734 | if (result) mailimap_fetch_list_free(result); |
737 | return res; | 735 | return res; |
738 | } | 736 | } |
739 | 737 | ||
740 | /* current_recursion is for recursive calls. | 738 | /* current_recursion is for recursive calls. |
741 | current_count means the position inside the internal loop! */ | 739 | current_count means the position inside the internal loop! */ |
742 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, | 740 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, |
743 | int current_recursion,QValueList<int>recList,int current_count) | 741 | int current_recursion,QValueList<int>recList,int current_count) |
744 | { | 742 | { |
745 | if (!body || current_recursion>=10) { | 743 | if (!body || current_recursion>=10) { |
746 | return; | 744 | return; |
747 | } | 745 | } |
748 | switch (body->bd_type) { | 746 | switch (body->bd_type) { |
749 | case MAILIMAP_BODY_1PART: | 747 | case MAILIMAP_BODY_1PART: |
750 | { | 748 | { |
751 | QValueList<int>countlist = recList; | 749 | QValueList<int>countlist = recList; |
752 | countlist.append(current_count); | 750 | countlist.append(current_count); |
753 | RecPartP currentPart = new RecPart(); | 751 | RecPartP currentPart = new RecPart(); |
754 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; | 752 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; |
755 | QString id(""); | 753 | QString id(""); |
756 | currentPart->setPositionlist(countlist); | 754 | currentPart->setPositionlist(countlist); |
757 | for (unsigned int j = 0; j < countlist.count();++j) { | 755 | for (unsigned int j = 0; j < countlist.count();++j) { |
758 | id+=(j>0?" ":""); | 756 | id+=(j>0?" ":""); |
759 | id+=QString("%1").arg(countlist[j]); | 757 | id+=QString("%1").arg(countlist[j]); |
760 | } | 758 | } |
761 | //odebug << "ID = " << id.latin1() << "" << oendl; | 759 | //odebug << "ID = " << id.latin1() << "" << oendl; |
762 | currentPart->setIdentifier(id); | 760 | currentPart->setIdentifier(id); |
763 | fillSinglePart(currentPart,part1); | 761 | fillSinglePart(currentPart,part1); |
764 | /* important: Check for is NULL 'cause a body can be empty! | 762 | /* important: Check for is NULL 'cause a body can be empty! |
765 | And we put it only into the mail if it is the FIRST part */ | 763 | And we put it only into the mail if it is the FIRST part */ |
766 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { | 764 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { |
767 | QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); | 765 | QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); |
768 | 766 | ||
769 | size_t index = 0; | 767 | size_t index = 0; |
770 | char*res = 0; | 768 | char*res = 0; |
771 | int err = MAILIMF_NO_ERROR; | 769 | int err = MAILIMF_NO_ERROR; |
772 | 770 | ||
773 | QString charset = currentPart->searchParamter( "charset"); | 771 | QString charset = currentPart->searchParamter( "charset"); |
774 | qDebug("CHARSET %s ",charset.latin1() ); | 772 | qDebug("CHARSET %s ",charset.latin1() ); |
775 | if ( false ) { | 773 | if ( false ) { |
776 | //if ( !charset.isEmpty() ) { | 774 | //if ( !charset.isEmpty() ) { |
777 | target_body->setCharset( charset ); | 775 | target_body->setCharset( charset ); |
778 | //err = mailmime_encoded_phrase_parse("iso-8859-1", | 776 | //err = mailmime_encoded_phrase_parse("iso-8859-1", |
779 | // text, strlen(text),&index, "iso-8859-1",&res); | 777 | // text, strlen(text),&index, "iso-8859-1",&res); |
780 | err = mailmime_encoded_phrase_parse(charset.latin1(), | 778 | err = mailmime_encoded_phrase_parse(charset.latin1(), |
781 | body_text.latin1(), body_text.length(),&index, "utf-8",&res); | 779 | body_text.latin1(), body_text.length(),&index, "utf-8",&res); |
782 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { | 780 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { |
783 | //qDebug("res %d %s ", index, res); | 781 | //qDebug("res %d %s ", index, res); |
784 | body_text = QString::fromUtf8(res); | 782 | body_text = QString::fromUtf8(res); |
785 | } | 783 | } |
786 | if (res) free(res); | 784 | if (res) free(res); |
787 | } | 785 | } |
788 | //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() ); | 786 | //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() ); |
789 | target_body->setDescription(currentPart); | 787 | target_body->setDescription(currentPart); |
790 | target_body->setBodytext(body_text); | 788 | target_body->setBodytext(body_text); |
791 | if (countlist.count()>1) { | 789 | if (countlist.count()>1) { |
792 | target_body->addPart(currentPart); | 790 | target_body->addPart(currentPart); |
793 | } | 791 | } |
794 | } else { | 792 | } else { |
795 | target_body->addPart(currentPart); | 793 | target_body->addPart(currentPart); |
796 | } | 794 | } |
797 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { | 795 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { |
798 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); | 796 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); |
799 | } | 797 | } |
800 | } | 798 | } |
801 | break; | 799 | break; |
802 | case MAILIMAP_BODY_MPART: | 800 | case MAILIMAP_BODY_MPART: |
803 | { | 801 | { |
804 | QValueList<int>countlist = recList; | 802 | QValueList<int>countlist = recList; |
805 | clistcell*current=0; | 803 | clistcell*current=0; |
806 | mailimap_body*current_body=0; | 804 | mailimap_body*current_body=0; |
807 | unsigned int ccount = 1; | 805 | unsigned int ccount = 1; |
808 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; | 806 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; |
809 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 807 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
810 | current_body = (mailimap_body*)current->data; | 808 | current_body = (mailimap_body*)current->data; |
811 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 809 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
812 | RecPartP targetPart = new RecPart(); | 810 | RecPartP targetPart = new RecPart(); |
813 | targetPart->setType("multipart"); | 811 | targetPart->setType("multipart"); |
814 | fillMultiPart(targetPart,mailDescription); | 812 | fillMultiPart(targetPart,mailDescription); |
815 | countlist.append(current_count); | 813 | countlist.append(current_count); |
816 | targetPart->setPositionlist(countlist); | 814 | targetPart->setPositionlist(countlist); |
817 | target_body->addPart(targetPart); | 815 | target_body->addPart(targetPart); |
818 | QString id(""); | 816 | QString id(""); |
819 | for (unsigned int j = 0; j < countlist.count();++j) { | 817 | for (unsigned int j = 0; j < countlist.count();++j) { |
820 | id+=(j>0?" ":""); | 818 | id+=(j>0?" ":""); |
821 | id+=QString("%1").arg(countlist[j]); | 819 | id+=QString("%1").arg(countlist[j]); |
822 | } | 820 | } |
823 | // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; | 821 | // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; |
824 | } | 822 | } |
825 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); | 823 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); |
826 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 824 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
827 | countlist = recList; | 825 | countlist = recList; |
828 | } | 826 | } |
829 | ++ccount; | 827 | ++ccount; |
830 | } | 828 | } |
831 | } | 829 | } |
832 | break; | 830 | break; |
833 | default: | 831 | default: |
834 | break; | 832 | break; |
835 | } | 833 | } |
836 | } | 834 | } |
837 | 835 | ||
838 | void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) | 836 | void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) |
839 | { | 837 | { |
840 | if (!Description) { | 838 | if (!Description) { |
841 | return; | 839 | return; |
842 | } | 840 | } |
843 | switch (Description->bd_type) { | 841 | switch (Description->bd_type) { |
844 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 842 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
845 | target_part->setType("text"); | 843 | target_part->setType("text"); |
846 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 844 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
847 | break; | 845 | break; |
848 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 846 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
849 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 847 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
850 | break; | 848 | break; |
851 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 849 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
852 | target_part->setType("message"); | 850 | target_part->setType("message"); |
853 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 851 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
854 | break; | 852 | break; |
855 | default: | 853 | default: |
856 | break; | 854 | break; |
857 | } | 855 | } |
858 | } | 856 | } |
859 | 857 | ||
860 | void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) | 858 | void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) |
861 | { | 859 | { |
862 | if (!which) { | 860 | if (!which) { |
863 | return; | 861 | return; |
864 | } | 862 | } |
865 | QString sub; | 863 | QString sub; |
866 | sub = which->bd_media_text; | 864 | sub = which->bd_media_text; |
867 | //odebug << "Type= text/" << which->bd_media_text << "" << oendl; | 865 | //odebug << "Type= text/" << which->bd_media_text << "" << oendl; |
868 | target_part->setSubtype(sub.lower()); | 866 | target_part->setSubtype(sub.lower()); |
869 | target_part->setLines(which->bd_lines); | 867 | target_part->setLines(which->bd_lines); |
870 | fillBodyFields(target_part,which->bd_fields); | 868 | fillBodyFields(target_part,which->bd_fields); |
871 | } | 869 | } |
872 | 870 | ||
873 | void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) | 871 | void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) |
874 | { | 872 | { |
875 | if (!which) { | 873 | if (!which) { |
876 | return; | 874 | return; |
877 | } | 875 | } |
878 | target_part->setSubtype("rfc822"); | 876 | target_part->setSubtype("rfc822"); |
879 | //odebug << "Message part" << oendl; | 877 | //odebug << "Message part" << oendl; |
880 | /* we set this type to text/plain */ | 878 | /* we set this type to text/plain */ |
881 | target_part->setLines(which->bd_lines); | 879 | target_part->setLines(which->bd_lines); |
882 | fillBodyFields(target_part,which->bd_fields); | 880 | fillBodyFields(target_part,which->bd_fields); |
883 | } | 881 | } |
884 | 882 | ||
885 | void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) | 883 | void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) |
886 | { | 884 | { |
887 | if (!which) return; | 885 | if (!which) return; |
888 | QString sub = which->bd_media_subtype; | 886 | QString sub = which->bd_media_subtype; |
889 | target_part->setSubtype(sub.lower()); | 887 | target_part->setSubtype(sub.lower()); |
890 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { | 888 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { |
891 | clistcell*cur = 0; | 889 | clistcell*cur = 0; |
892 | mailimap_single_body_fld_param*param=0; | 890 | mailimap_single_body_fld_param*param=0; |
893 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 891 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
894 | param = (mailimap_single_body_fld_param*)cur->data; | 892 | param = (mailimap_single_body_fld_param*)cur->data; |
895 | if (param) { | 893 | if (param) { |
896 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 894 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
897 | } | 895 | } |
898 | } | 896 | } |
899 | } | 897 | } |
900 | } | 898 | } |
901 | 899 | ||
902 | void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) | 900 | void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) |
903 | { | 901 | { |
904 | if (!which) { | 902 | if (!which) { |
905 | return; | 903 | return; |
906 | } | 904 | } |
907 | QString type,sub; | 905 | QString type,sub; |
908 | switch (which->bd_media_basic->med_type) { | 906 | switch (which->bd_media_basic->med_type) { |
909 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 907 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
910 | type = "application"; | 908 | type = "application"; |
911 | break; | 909 | break; |
912 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 910 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
913 | type = "audio"; | 911 | type = "audio"; |
914 | break; | 912 | break; |
915 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 913 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
916 | type = "image"; | 914 | type = "image"; |
917 | break; | 915 | break; |
918 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 916 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
919 | type = "message"; | 917 | type = "message"; |
920 | break; | 918 | break; |
921 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 919 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
922 | type = "video"; | 920 | type = "video"; |
923 | break; | 921 | break; |
924 | case MAILIMAP_MEDIA_BASIC_OTHER: | 922 | case MAILIMAP_MEDIA_BASIC_OTHER: |
925 | default: | 923 | default: |
926 | if (which->bd_media_basic->med_basic_type) { | 924 | if (which->bd_media_basic->med_basic_type) { |
927 | type = which->bd_media_basic->med_basic_type; | 925 | type = which->bd_media_basic->med_basic_type; |
928 | } else { | 926 | } else { |
929 | type = ""; | 927 | type = ""; |
930 | } | 928 | } |
931 | break; | 929 | break; |
932 | } | 930 | } |
933 | if (which->bd_media_basic->med_subtype) { | 931 | if (which->bd_media_basic->med_subtype) { |
934 | sub = which->bd_media_basic->med_subtype; | 932 | sub = which->bd_media_basic->med_subtype; |
935 | } else { | 933 | } else { |
936 | sub = ""; | 934 | sub = ""; |
937 | } | 935 | } |
938 | // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; | 936 | // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; |
939 | target_part->setType(type.lower()); | 937 | target_part->setType(type.lower()); |
940 | target_part->setSubtype(sub.lower()); | 938 | target_part->setSubtype(sub.lower()); |
941 | fillBodyFields(target_part,which->bd_fields); | 939 | fillBodyFields(target_part,which->bd_fields); |
942 | } | 940 | } |
943 | 941 | ||
944 | void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) | 942 | void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) |
945 | { | 943 | { |
946 | if (!which) return; | 944 | if (!which) return; |
947 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 945 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |