-rw-r--r-- | noncore/net/mail/accountview.cpp | 77 | ||||
-rw-r--r-- | noncore/net/mail/accountview.h | 6 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mhwrapper.cpp | 68 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mhwrapper.h | 2 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 43 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 1 |
6 files changed, 157 insertions, 40 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp index 62cbf62..3048e49 100644 --- a/noncore/net/mail/accountview.cpp +++ b/noncore/net/mail/accountview.cpp | |||
@@ -149,193 +149,192 @@ RecBody POP3folderItem::fetchBody(const RecMail&aMail) | |||
149 | 149 | ||
150 | QPopupMenu * POP3folderItem::getContextMenu() | 150 | QPopupMenu * POP3folderItem::getContextMenu() |
151 | { | 151 | { |
152 | QPopupMenu *m = new QPopupMenu(0); | 152 | QPopupMenu *m = new QPopupMenu(0); |
153 | if (m) { | 153 | if (m) { |
154 | m->insertItem(QObject::tr("Refresh header list",contextName),0); | 154 | m->insertItem(QObject::tr("Refresh header list",contextName),0); |
155 | m->insertItem(QObject::tr("Delete all mails",contextName),1); | 155 | m->insertItem(QObject::tr("Delete all mails",contextName),1); |
156 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); | 156 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); |
157 | } | 157 | } |
158 | return m; | 158 | return m; |
159 | } | 159 | } |
160 | 160 | ||
161 | void POP3folderItem::downloadMails() | 161 | void POP3folderItem::downloadMails() |
162 | { | 162 | { |
163 | AccountView*bl = pop3->accountView(); | 163 | AccountView*bl = pop3->accountView(); |
164 | if (!bl) return; | 164 | if (!bl) return; |
165 | bl->downloadMails(folder,pop3->getWrapper()); | 165 | bl->downloadMails(folder,pop3->getWrapper()); |
166 | } | 166 | } |
167 | 167 | ||
168 | void POP3folderItem::contextMenuSelected(int which) | 168 | void POP3folderItem::contextMenuSelected(int which) |
169 | { | 169 | { |
170 | AccountView * view = (AccountView*)listView(); | 170 | AccountView * view = (AccountView*)listView(); |
171 | switch (which) { | 171 | switch (which) { |
172 | case 0: | 172 | case 0: |
173 | /* must be 'cause pop3 lists are cached */ | 173 | /* must be 'cause pop3 lists are cached */ |
174 | pop3->getWrapper()->logout(); | 174 | pop3->getWrapper()->logout(); |
175 | view->refreshCurrent(); | 175 | view->refreshCurrent(); |
176 | break; | 176 | break; |
177 | case 1: | 177 | case 1: |
178 | deleteAllMail(pop3->getWrapper(),folder); | 178 | deleteAllMail(pop3->getWrapper(),folder); |
179 | break; | 179 | break; |
180 | case 2: | 180 | case 2: |
181 | downloadMails(); | 181 | downloadMails(); |
182 | break; | 182 | break; |
183 | default: | 183 | default: |
184 | break; | 184 | break; |
185 | } | 185 | } |
186 | } | 186 | } |
187 | 187 | ||
188 | /** | 188 | /** |
189 | * IMAP Account stuff | 189 | * IMAP Account stuff |
190 | */ | 190 | */ |
191 | IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent ) | 191 | IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent ) |
192 | : AccountViewItem( parent ) | 192 | : AccountViewItem( parent ) |
193 | { | 193 | { |
194 | account = a; | 194 | account = a; |
195 | wrapper = AbstractMail::getWrapper( account ); | 195 | wrapper = AbstractMail::getWrapper( account ); |
196 | SETPIX(PIXMAP_IMAPFOLDER); | 196 | SETPIX(PIXMAP_IMAPFOLDER); |
197 | setText( 0, account->getAccountName() ); | 197 | setText( 0, account->getAccountName() ); |
198 | setOpen( true ); | 198 | setOpen( true ); |
199 | } | 199 | } |
200 | 200 | ||
201 | IMAPviewItem::~IMAPviewItem() | 201 | IMAPviewItem::~IMAPviewItem() |
202 | { | 202 | { |
203 | delete wrapper; | 203 | delete wrapper; |
204 | } | 204 | } |
205 | 205 | ||
206 | AbstractMail *IMAPviewItem::getWrapper() | 206 | AbstractMail *IMAPviewItem::getWrapper() |
207 | { | 207 | { |
208 | return wrapper; | 208 | return wrapper; |
209 | } | 209 | } |
210 | 210 | ||
211 | IMAPfolderItem*IMAPviewItem::findSubItem(const QString&path,IMAPfolderItem*start) | 211 | IMAPfolderItem*IMAPviewItem::findSubItem(const QString&path,IMAPfolderItem*start) |
212 | { | 212 | { |
213 | IMAPfolderItem*pitem,*sitem; | 213 | IMAPfolderItem*pitem,*sitem; |
214 | if (!start) pitem = (IMAPfolderItem*)firstChild(); | 214 | if (!start) pitem = (IMAPfolderItem*)firstChild(); |
215 | else pitem = (IMAPfolderItem*)start->firstChild(); | 215 | else pitem = (IMAPfolderItem*)start->firstChild(); |
216 | while (pitem) { | 216 | while (pitem) { |
217 | if (pitem->matchName(path)) { | 217 | if (pitem->matchName(path)) { |
218 | break; | 218 | break; |
219 | } | 219 | } |
220 | if (pitem->childCount()>0) { | 220 | if (pitem->childCount()>0) { |
221 | sitem = findSubItem(path,pitem); | 221 | sitem = findSubItem(path,pitem); |
222 | if (sitem) { | 222 | if (sitem) { |
223 | pitem = sitem; | 223 | pitem = sitem; |
224 | break; | 224 | break; |
225 | } | 225 | } |
226 | } | 226 | } |
227 | pitem=(IMAPfolderItem*)pitem->nextSibling(); | 227 | pitem=(IMAPfolderItem*)pitem->nextSibling(); |
228 | } | 228 | } |
229 | return pitem; | 229 | return pitem; |
230 | } | 230 | } |
231 | 231 | ||
232 | void IMAPviewItem::refresh(QList<RecMail>&) | 232 | void IMAPviewItem::refresh(QList<RecMail>&) |
233 | { | 233 | { |
234 | refreshFolders(false); | 234 | refreshFolders(false); |
235 | } | 235 | } |
236 | 236 | ||
237 | void IMAPviewItem::removeChilds() | 237 | void IMAPviewItem::removeChilds() |
238 | { | 238 | { |
239 | QListViewItem *child = firstChild(); | 239 | QListViewItem *child = firstChild(); |
240 | while ( child ) { | 240 | while ( child ) { |
241 | QListViewItem *tmp = child; | 241 | QListViewItem *tmp = child; |
242 | child = child->nextSibling(); | 242 | child = child->nextSibling(); |
243 | delete tmp; | 243 | delete tmp; |
244 | } | 244 | } |
245 | |||
246 | } | 245 | } |
247 | 246 | ||
248 | const QStringList&IMAPviewItem::subFolders() | 247 | const QStringList&IMAPviewItem::subFolders() |
249 | { | 248 | { |
250 | return currentFolders; | 249 | return currentFolders; |
251 | } | 250 | } |
252 | 251 | ||
253 | void IMAPviewItem::refreshFolders(bool force) | 252 | void IMAPviewItem::refreshFolders(bool force) |
254 | { | 253 | { |
255 | if (childCount()>0 && force==false) return; | 254 | if (childCount()>0 && force==false) return; |
256 | if (account->getOffline()) return; | 255 | if (account->getOffline()) return; |
257 | 256 | ||
258 | removeChilds(); | 257 | removeChilds(); |
259 | currentFolders.clear(); | 258 | currentFolders.clear(); |
260 | QList<Folder> *folders = wrapper->listFolders(); | 259 | QList<Folder> *folders = wrapper->listFolders(); |
261 | 260 | ||
262 | Folder *it; | 261 | Folder *it; |
263 | QListViewItem*item = 0; | 262 | QListViewItem*item = 0; |
264 | QListViewItem*titem = 0; | 263 | QListViewItem*titem = 0; |
265 | QString fname,del,search; | 264 | QString fname,del,search; |
266 | int pos; | 265 | int pos; |
267 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 266 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
268 | folders->setAutoDelete(false); | 267 | folders->setAutoDelete(false); |
269 | 268 | ||
270 | for ( it = folders->first(); it; it = folders->next() ) { | 269 | for ( it = folders->first(); it; it = folders->next() ) { |
271 | if (it->getDisplayName().lower()=="inbox") { | 270 | if (it->getDisplayName().lower()=="inbox") { |
272 | item = new IMAPfolderItem( it, this , item ); | 271 | item = new IMAPfolderItem( it, this , item ); |
273 | folders->remove(it); | 272 | folders->remove(it); |
274 | qDebug("inbox found"); | 273 | qDebug("inbox found"); |
275 | break; | 274 | break; |
276 | } | 275 | } |
277 | } | 276 | } |
278 | for ( it = folders->first(); it; it = folders->next() ) { | 277 | for ( it = folders->first(); it; it = folders->next() ) { |
279 | fname = it->getDisplayName(); | 278 | fname = it->getDisplayName(); |
280 | currentFolders.append(it->getName()); | 279 | currentFolders.append(it->getName()); |
281 | pos = fname.findRev(it->Separator()); | 280 | pos = fname.findRev(it->Separator()); |
282 | if (pos != -1) { | 281 | if (pos != -1) { |
283 | fname = fname.left(pos); | 282 | fname = fname.left(pos); |
284 | } | 283 | } |
285 | IMAPfolderItem*pitem = findSubItem(fname); | 284 | IMAPfolderItem*pitem = findSubItem(fname); |
286 | if (pitem) { | 285 | if (pitem) { |
287 | titem = item; | 286 | titem = item; |
288 | item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this); | 287 | item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this); |
289 | /* setup the short name */ | 288 | /* setup the short name */ |
290 | item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1)); | 289 | item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1)); |
291 | item = titem; | 290 | item = titem; |
292 | } else { | 291 | } else { |
293 | item = new IMAPfolderItem( it, this , item ); | 292 | item = new IMAPfolderItem( it, this , item ); |
294 | } | 293 | } |
295 | } | 294 | } |
296 | delete folders; | 295 | delete folders; |
297 | } | 296 | } |
298 | 297 | ||
299 | QPopupMenu * IMAPviewItem::getContextMenu() | 298 | QPopupMenu * IMAPviewItem::getContextMenu() |
300 | { | 299 | { |
301 | QPopupMenu *m = new QPopupMenu(0); | 300 | QPopupMenu *m = new QPopupMenu(0); |
302 | if (m) { | 301 | if (m) { |
303 | if (!account->getOffline()) { | 302 | if (!account->getOffline()) { |
304 | m->insertItem(QObject::tr("Refresh folder list",contextName),0); | 303 | m->insertItem(QObject::tr("Refresh folder list",contextName),0); |
305 | m->insertItem(QObject::tr("Create new folder",contextName),1); | 304 | m->insertItem(QObject::tr("Create new folder",contextName),1); |
306 | m->insertSeparator(); | 305 | m->insertSeparator(); |
307 | m->insertItem(QObject::tr("Disconnect",contextName),2); | 306 | m->insertItem(QObject::tr("Disconnect",contextName),2); |
308 | m->insertItem(QObject::tr("Set offline",contextName),3); | 307 | m->insertItem(QObject::tr("Set offline",contextName),3); |
309 | } else { | 308 | } else { |
310 | m->insertItem(QObject::tr("Set online",contextName),3); | 309 | m->insertItem(QObject::tr("Set online",contextName),3); |
311 | } | 310 | } |
312 | } | 311 | } |
313 | return m; | 312 | return m; |
314 | } | 313 | } |
315 | 314 | ||
316 | void IMAPviewItem::createNewFolder() | 315 | void IMAPviewItem::createNewFolder() |
317 | { | 316 | { |
318 | Newmdirdlg ndirdlg; | 317 | Newmdirdlg ndirdlg; |
319 | ndirdlg.showMaximized(); | 318 | ndirdlg.showMaximized(); |
320 | if (ndirdlg.exec()) { | 319 | if (ndirdlg.exec()) { |
321 | QString ndir = ndirdlg.Newdir(); | 320 | QString ndir = ndirdlg.Newdir(); |
322 | bool makesubs = ndirdlg.subpossible(); | 321 | bool makesubs = ndirdlg.subpossible(); |
323 | QString delemiter = "/"; | 322 | QString delemiter = "/"; |
324 | IMAPfolderItem*item = (IMAPfolderItem*)firstChild(); | 323 | IMAPfolderItem*item = (IMAPfolderItem*)firstChild(); |
325 | if (item) { | 324 | if (item) { |
326 | delemiter = item->Delemiter(); | 325 | delemiter = item->Delemiter(); |
327 | } | 326 | } |
328 | if (wrapper->createMbox(ndir,0,delemiter,makesubs)) { | 327 | if (wrapper->createMbox(ndir,0,delemiter,makesubs)) { |
329 | refreshFolders(true); | 328 | refreshFolders(true); |
330 | } | 329 | } |
331 | } | 330 | } |
332 | } | 331 | } |
333 | 332 | ||
334 | void IMAPviewItem::contextMenuSelected(int id) | 333 | void IMAPviewItem::contextMenuSelected(int id) |
335 | { | 334 | { |
336 | qDebug("Id selected: %i",id); | 335 | qDebug("Id selected: %i",id); |
337 | switch (id) { | 336 | switch (id) { |
338 | case 0: | 337 | case 0: |
339 | refreshFolders(true); | 338 | refreshFolders(true); |
340 | break; | 339 | break; |
341 | case 1: | 340 | case 1: |
@@ -613,290 +612,346 @@ void AccountView::populate( QList<Account> list ) | |||
613 | for ( it = list.first(); it; it = list.next() ) { | 612 | for ( it = list.first(); it; it = list.next() ) { |
614 | if ( it->getType().compare( "IMAP" ) == 0 ) { | 613 | if ( it->getType().compare( "IMAP" ) == 0 ) { |
615 | IMAPaccount *imap = static_cast<IMAPaccount *>(it); | 614 | IMAPaccount *imap = static_cast<IMAPaccount *>(it); |
616 | qDebug( "added IMAP " + imap->getAccountName() ); | 615 | qDebug( "added IMAP " + imap->getAccountName() ); |
617 | imapAccounts.append(new IMAPviewItem( imap, this )); | 616 | imapAccounts.append(new IMAPviewItem( imap, this )); |
618 | } else if ( it->getType().compare( "POP3" ) == 0 ) { | 617 | } else if ( it->getType().compare( "POP3" ) == 0 ) { |
619 | POP3account *pop3 = static_cast<POP3account *>(it); | 618 | POP3account *pop3 = static_cast<POP3account *>(it); |
620 | qDebug( "added POP3 " + pop3->getAccountName() ); | 619 | qDebug( "added POP3 " + pop3->getAccountName() ); |
621 | /* must not be hold 'cause it isn't required */ | 620 | /* must not be hold 'cause it isn't required */ |
622 | (void) new POP3viewItem( pop3, this ); | 621 | (void) new POP3viewItem( pop3, this ); |
623 | } | 622 | } |
624 | } | 623 | } |
625 | } | 624 | } |
626 | 625 | ||
627 | void AccountView::refresh(QListViewItem *item) { | 626 | void AccountView::refresh(QListViewItem *item) { |
628 | 627 | ||
629 | qDebug("AccountView refresh..."); | 628 | qDebug("AccountView refresh..."); |
630 | if ( item ) { | 629 | if ( item ) { |
631 | m_currentItem = item; | 630 | m_currentItem = item; |
632 | QList<RecMail> headerlist; | 631 | QList<RecMail> headerlist; |
633 | headerlist.setAutoDelete(true); | 632 | headerlist.setAutoDelete(true); |
634 | AccountViewItem *view = static_cast<AccountViewItem *>(item); | 633 | AccountViewItem *view = static_cast<AccountViewItem *>(item); |
635 | view->refresh(headerlist); | 634 | view->refresh(headerlist); |
636 | emit refreshMailview(&headerlist); | 635 | emit refreshMailview(&headerlist); |
637 | } | 636 | } |
638 | } | 637 | } |
639 | 638 | ||
640 | void AccountView::refreshCurrent() | 639 | void AccountView::refreshCurrent() |
641 | { | 640 | { |
642 | m_currentItem = currentItem(); | 641 | m_currentItem = currentItem(); |
643 | if ( !m_currentItem ) return; | 642 | if ( !m_currentItem ) return; |
644 | QList<RecMail> headerlist; | 643 | QList<RecMail> headerlist; |
645 | headerlist.setAutoDelete(true); | 644 | headerlist.setAutoDelete(true); |
646 | AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); | 645 | AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); |
647 | view->refresh(headerlist); | 646 | view->refresh(headerlist); |
648 | emit refreshMailview(&headerlist); | 647 | emit refreshMailview(&headerlist); |
649 | } | 648 | } |
650 | 649 | ||
651 | void AccountView::refreshAll() | 650 | void AccountView::refreshAll() |
652 | { | 651 | { |
653 | 652 | ||
654 | } | 653 | } |
655 | 654 | ||
656 | RecBody AccountView::fetchBody(const RecMail&aMail) | 655 | RecBody AccountView::fetchBody(const RecMail&aMail) |
657 | { | 656 | { |
658 | QListViewItem*item = selectedItem (); | 657 | QListViewItem*item = selectedItem (); |
659 | if (!item) return RecBody(); | 658 | if (!item) return RecBody(); |
660 | AccountViewItem *view = static_cast<AccountViewItem *>(item); | 659 | AccountViewItem *view = static_cast<AccountViewItem *>(item); |
661 | return view->fetchBody(aMail); | 660 | return view->fetchBody(aMail); |
662 | } | 661 | } |
663 | 662 | ||
664 | void AccountView::setupFolderselect(Selectstore*sels) | 663 | void AccountView::setupFolderselect(Selectstore*sels) |
665 | { | 664 | { |
666 | sels->showMaximized(); | 665 | sels->showMaximized(); |
667 | QStringList sFolders; | 666 | QStringList sFolders; |
668 | unsigned int i = 0; | 667 | unsigned int i = 0; |
669 | for (i=0; i < mhAccounts.count();++i) { | 668 | for (i=0; i < mhAccounts.count();++i) { |
670 | mhAccounts[i]->refresh(false); | 669 | mhAccounts[i]->refresh(false); |
671 | sFolders = mhAccounts[i]->subFolders(); | 670 | sFolders = mhAccounts[i]->subFolders(); |
672 | sels->addAccounts(mhAccounts[i]->getWrapper(),sFolders); | 671 | sels->addAccounts(mhAccounts[i]->getWrapper(),sFolders); |
673 | } | 672 | } |
674 | for (i=0; i < imapAccounts.count();++i) { | 673 | for (i=0; i < imapAccounts.count();++i) { |
675 | if (imapAccounts[i]->offline()) | 674 | if (imapAccounts[i]->offline()) |
676 | continue; | 675 | continue; |
677 | imapAccounts[i]->refreshFolders(false); | 676 | imapAccounts[i]->refreshFolders(false); |
678 | sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders()); | 677 | sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders()); |
679 | } | 678 | } |
680 | } | 679 | } |
681 | 680 | ||
682 | void AccountView::downloadMails(Folder*fromFolder,AbstractMail*fromWrapper) | 681 | void AccountView::downloadMails(Folder*fromFolder,AbstractMail*fromWrapper) |
683 | { | 682 | { |
684 | AbstractMail*targetMail = 0; | 683 | AbstractMail*targetMail = 0; |
685 | QString targetFolder = ""; | 684 | QString targetFolder = ""; |
686 | Selectstore sels; | 685 | Selectstore sels; |
687 | setupFolderselect(&sels); | 686 | setupFolderselect(&sels); |
688 | if (!sels.exec()) return; | 687 | if (!sels.exec()) return; |
689 | targetMail = sels.currentMail(); | 688 | targetMail = sels.currentMail(); |
690 | targetFolder = sels.currentFolder(); | 689 | targetFolder = sels.currentFolder(); |
691 | if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) || | 690 | if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) || |
692 | targetFolder.isEmpty()) { | 691 | targetFolder.isEmpty()) { |
693 | return; | 692 | return; |
694 | } | 693 | } |
695 | if (sels.newFolder() && !targetMail->createMbox(targetFolder)) { | 694 | if (sels.newFolder() && !targetMail->createMbox(targetFolder)) { |
696 | QMessageBox::critical(0,tr("Error creating new Folder"), | 695 | QMessageBox::critical(0,tr("Error creating new Folder"), |
697 | tr("<center>Error while creating<br>new folder - breaking.</center>")); | 696 | tr("<center>Error while creating<br>new folder - breaking.</center>")); |
698 | return; | 697 | return; |
699 | } | 698 | } |
700 | qDebug("Targetfolder: %s",targetFolder.latin1()); | 699 | qDebug("Targetfolder: %s",targetFolder.latin1()); |
701 | qDebug("Fromfolder: %s",fromFolder->getName().latin1()); | 700 | qDebug("Fromfolder: %s",fromFolder->getName().latin1()); |
702 | fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails()); | 701 | fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails()); |
703 | refreshCurrent(); | 702 | refreshCurrent(); |
704 | } | 703 | } |
705 | 704 | ||
706 | /** | 705 | /** |
707 | * MH Account stuff | 706 | * MH Account stuff |
708 | */ | 707 | */ |
709 | 708 | /* MH is a little bit different - the top folder can contains messages other than in IMAP and | |
709 | POP3 and MBOX */ | ||
710 | MHviewItem::MHviewItem( const QString&aPath, AccountView *parent ) | 710 | MHviewItem::MHviewItem( const QString&aPath, AccountView *parent ) |
711 | : AccountViewItem( parent ) | 711 | : AccountViewItem( parent ) |
712 | { | 712 | { |
713 | m_Path = aPath; | 713 | m_Path = aPath; |
714 | /* be carefull - the space within settext is wanted - thats why the string twice */ | 714 | /* be carefull - the space within settext is wanted - thats why the string twice */ |
715 | wrapper = AbstractMail::getWrapper( m_Path,"Local Folders"); | 715 | wrapper = AbstractMail::getWrapper( m_Path,"Local Folders"); |
716 | setPixmap( 0, PIXMAP_LOCALFOLDER ); | 716 | setPixmap( 0, PIXMAP_LOCALFOLDER ); |
717 | setText( 0, " Local Folders" ); | 717 | setText( 0, " Local Folders" ); |
718 | setOpen( true ); | 718 | setOpen( true ); |
719 | folder = 0; | ||
719 | } | 720 | } |
720 | 721 | ||
721 | MHviewItem::~MHviewItem() | 722 | MHviewItem::~MHviewItem() |
722 | { | 723 | { |
723 | delete wrapper; | 724 | delete wrapper; |
725 | if (folder) delete folder; | ||
724 | } | 726 | } |
725 | 727 | ||
726 | AbstractMail *MHviewItem::getWrapper() | 728 | AbstractMail *MHviewItem::getWrapper() |
727 | { | 729 | { |
728 | return wrapper; | 730 | return wrapper; |
729 | } | 731 | } |
730 | 732 | ||
731 | void MHviewItem::refresh( QList<RecMail> & ) | 733 | void MHviewItem::refresh( QList<RecMail> & target) |
732 | { | 734 | { |
733 | refresh(false); | 735 | refresh(false); |
736 | getWrapper()->listMessages( "",target ); | ||
734 | } | 737 | } |
735 | 738 | ||
736 | void MHviewItem::refresh(bool force) | 739 | void MHviewItem::removeChilds() |
737 | { | 740 | { |
738 | if (childCount()>0 && force==false) return; | ||
739 | QList<Folder> *folders = wrapper->listFolders(); | ||
740 | QListViewItem *child = firstChild(); | 741 | QListViewItem *child = firstChild(); |
741 | while ( child ) { | 742 | while ( child ) { |
742 | QListViewItem *tmp = child; | 743 | QListViewItem *tmp = child; |
743 | child = child->nextSibling(); | 744 | child = child->nextSibling(); |
744 | delete tmp; | 745 | delete tmp; |
745 | } | 746 | } |
747 | } | ||
748 | |||
749 | void MHviewItem::refresh(bool force) | ||
750 | { | ||
751 | if (childCount()>0 && force==false) return; | ||
752 | removeChilds(); | ||
753 | QList<Folder> *folders = wrapper->listFolders(); | ||
746 | Folder *it; | 754 | Folder *it; |
747 | QListViewItem*item = 0; | 755 | MHfolderItem*item = 0; |
756 | MHfolderItem*pmaster = 0; | ||
757 | QString fname = ""; | ||
748 | for ( it = folders->first(); it; it = folders->next() ) { | 758 | for ( it = folders->first(); it; it = folders->next() ) { |
749 | item = new MHfolderItem( it, this , item ); | 759 | fname = it->getDisplayName(); |
760 | /* this folder itself */ | ||
761 | if (fname=="/") { | ||
762 | folder = it; | ||
763 | continue; | ||
764 | } | ||
765 | if (pmaster) { | ||
766 | item = new MHfolderItem( it, pmaster, item, this ); | ||
767 | } else { | ||
768 | item = new MHfolderItem( it, this , item ); | ||
769 | } | ||
750 | item->setSelectable(it->may_select()); | 770 | item->setSelectable(it->may_select()); |
751 | } | 771 | } |
752 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 772 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
753 | folders->setAutoDelete(false); | 773 | folders->setAutoDelete(false); |
754 | delete folders; | 774 | delete folders; |
755 | } | 775 | } |
756 | 776 | ||
757 | RecBody MHviewItem::fetchBody( const RecMail &mail ) | 777 | RecBody MHviewItem::fetchBody( const RecMail &mail ) |
758 | { | 778 | { |
759 | qDebug( "MH fetchBody" ); | 779 | qDebug( "MH fetchBody" ); |
760 | return wrapper->fetchBody( mail ); | 780 | return wrapper->fetchBody( mail ); |
761 | } | 781 | } |
762 | 782 | ||
763 | QPopupMenu * MHviewItem::getContextMenu() | 783 | QPopupMenu * MHviewItem::getContextMenu() |
764 | { | 784 | { |
765 | QPopupMenu *m = new QPopupMenu(0); | 785 | QPopupMenu *m = new QPopupMenu(0); |
766 | if (m) { | 786 | if (m) { |
767 | m->insertItem(QObject::tr("Refresh folder list",contextName),0); | 787 | m->insertItem(QObject::tr("Refresh folder list",contextName),0); |
768 | m->insertItem(QObject::tr("Create new folder",contextName),1); | 788 | m->insertItem(QObject::tr("Create new folder",contextName),1); |
789 | m->insertItem(QObject::tr("Delete all mails",contextName),2); | ||
790 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),3); | ||
769 | } | 791 | } |
770 | return m; | 792 | return m; |
771 | } | 793 | } |
772 | 794 | ||
773 | void MHviewItem::createFolder() | 795 | void MHviewItem::createFolder() |
774 | { | 796 | { |
775 | Newmdirdlg ndirdlg(0,0,true); | 797 | Newmdirdlg ndirdlg(0,0,true); |
776 | ndirdlg.showMaximized(); | 798 | ndirdlg.showMaximized(); |
777 | if (ndirdlg.exec()) { | 799 | if (ndirdlg.exec()) { |
778 | QString ndir = ndirdlg.Newdir(); | 800 | QString ndir = ndirdlg.Newdir(); |
779 | if (wrapper->createMbox(ndir)) { | 801 | if (wrapper->createMbox(ndir)) { |
780 | refresh(true); | 802 | refresh(true); |
781 | } | 803 | } |
782 | } | 804 | } |
783 | } | 805 | } |
784 | 806 | ||
807 | void MHviewItem::downloadMails() | ||
808 | { | ||
809 | AccountView*bl = accountView(); | ||
810 | if (!bl) return; | ||
811 | bl->downloadMails(folder,getWrapper()); | ||
812 | } | ||
813 | |||
785 | QStringList MHviewItem::subFolders() | 814 | QStringList MHviewItem::subFolders() |
786 | { | 815 | { |
787 | QStringList result; | 816 | QStringList result; |
788 | QListViewItem *child = firstChild(); | 817 | QListViewItem *child = firstChild(); |
818 | result.append("/"); | ||
789 | while ( child ) { | 819 | while ( child ) { |
790 | MHfolderItem *tmp = (MHfolderItem*)child; | 820 | MHfolderItem *tmp = (MHfolderItem*)child; |
791 | child = child->nextSibling(); | 821 | child = child->nextSibling(); |
792 | result.append(tmp->getFolder()->getDisplayName()); | 822 | result.append(tmp->getFolder()->getDisplayName()); |
793 | } | 823 | } |
794 | qDebug("Size of result: %i",result.count()); | 824 | qDebug("Size of result: %i",result.count()); |
795 | return result; | 825 | return result; |
796 | } | 826 | } |
797 | 827 | ||
798 | void MHviewItem::contextMenuSelected(int which) | 828 | void MHviewItem::contextMenuSelected(int which) |
799 | { | 829 | { |
800 | switch (which) { | 830 | switch (which) { |
801 | case 0: | 831 | case 0: |
802 | refresh(true); | 832 | refresh(true); |
803 | break; | 833 | break; |
804 | case 1: | 834 | case 1: |
805 | createFolder(); | 835 | createFolder(); |
806 | break; | 836 | break; |
837 | case 2: | ||
838 | deleteAllMail(getWrapper(),folder); | ||
839 | break; | ||
840 | case 3: | ||
841 | downloadMails(); | ||
842 | break; | ||
807 | default: | 843 | default: |
808 | break; | 844 | break; |
809 | } | 845 | } |
810 | } | 846 | } |
811 | 847 | ||
812 | MHfolderItem::~MHfolderItem() | 848 | MHfolderItem::~MHfolderItem() |
813 | { | 849 | { |
814 | delete folder; | 850 | delete folder; |
815 | } | 851 | } |
816 | 852 | ||
817 | MHfolderItem::MHfolderItem( Folder *folderInit, MHviewItem *parent , QListViewItem*after ) | 853 | MHfolderItem::MHfolderItem( Folder *folderInit, MHviewItem *parent , QListViewItem*after ) |
818 | : AccountViewItem( parent,after ) | 854 | : AccountViewItem( parent,after ) |
819 | { | 855 | { |
820 | folder = folderInit; | 856 | folder = folderInit; |
821 | mbox = parent; | 857 | mbox = parent; |
822 | if (folder->getDisplayName().lower() == "outgoing") { | 858 | initName(); |
859 | } | ||
860 | |||
861 | MHfolderItem::MHfolderItem( Folder *folderInit, MHfolderItem *parent, QListViewItem*after, MHviewItem*master) | ||
862 | : AccountViewItem( parent,after ) | ||
863 | { | ||
864 | folder = folderInit; | ||
865 | mbox = master; | ||
866 | initName(); | ||
867 | } | ||
868 | |||
869 | void MHfolderItem::initName() | ||
870 | { | ||
871 | QString bName = folder->getDisplayName(); | ||
872 | if (bName.startsWith("/")&&bName.length()>1) { | ||
873 | bName.replace(0,1,""); | ||
874 | } | ||
875 | if (bName.lower() == "outgoing") { | ||
823 | setPixmap( 0, PIXMAP_OUTBOXFOLDER ); | 876 | setPixmap( 0, PIXMAP_OUTBOXFOLDER ); |
824 | } else if (folder->getDisplayName().lower() == "inbox") { | 877 | } else if (bName.lower() == "inbox") { |
825 | setPixmap( 0, PIXMAP_INBOXFOLDER); | 878 | setPixmap( 0, PIXMAP_INBOXFOLDER); |
826 | } else { | 879 | } else { |
827 | setPixmap( 0, PIXMAP_MBOXFOLDER ); | 880 | setPixmap( 0, PIXMAP_MBOXFOLDER ); |
828 | } | 881 | } |
829 | setText( 0, folder->getDisplayName() ); | 882 | setText( 0, bName ); |
830 | } | 883 | } |
831 | 884 | ||
832 | Folder*MHfolderItem::getFolder() | 885 | Folder*MHfolderItem::getFolder() |
833 | { | 886 | { |
834 | return folder; | 887 | return folder; |
835 | } | 888 | } |
836 | 889 | ||
837 | void MHfolderItem::refresh(QList<RecMail>&target) | 890 | void MHfolderItem::refresh(QList<RecMail>&target) |
838 | { | 891 | { |
839 | if (folder->may_select()) | 892 | if (folder->may_select()) |
840 | mbox->getWrapper()->listMessages( folder->getName(),target ); | 893 | mbox->getWrapper()->listMessages( folder->getName(),target ); |
841 | } | 894 | } |
842 | 895 | ||
843 | RecBody MHfolderItem::fetchBody(const RecMail&aMail) | 896 | RecBody MHfolderItem::fetchBody(const RecMail&aMail) |
844 | { | 897 | { |
845 | return mbox->getWrapper()->fetchBody(aMail); | 898 | return mbox->getWrapper()->fetchBody(aMail); |
846 | } | 899 | } |
847 | 900 | ||
848 | void MHfolderItem::deleteFolder() | 901 | void MHfolderItem::deleteFolder() |
849 | { | 902 | { |
850 | int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), | 903 | int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), |
851 | QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), | 904 | QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), |
852 | QObject::tr("Yes",contextName), | 905 | QObject::tr("Yes",contextName), |
853 | QObject::tr("No",contextName),QString::null,1,1); | 906 | QObject::tr("No",contextName),QString::null,1,1); |
854 | qDebug("Auswahl: %i",yesno); | 907 | qDebug("Auswahl: %i",yesno); |
855 | if (yesno == 0) { | 908 | if (yesno == 0) { |
856 | if (mbox->getWrapper()->deleteMbox(folder)) { | 909 | if (mbox->getWrapper()->deleteMbox(folder)) { |
857 | QListView*v=listView(); | 910 | QListView*v=listView(); |
858 | MHviewItem * box = mbox; | 911 | MHviewItem * box = mbox; |
859 | /* be carefull - after that this object is destroyd so don't use | 912 | /* be carefull - after that this object is destroyd so don't use |
860 | * any member of it after that call!!*/ | 913 | * any member of it after that call!!*/ |
861 | mbox->refresh(true); | 914 | mbox->refresh(true); |
862 | if (v) { | 915 | if (v) { |
863 | v->setSelected(box,true); | 916 | v->setSelected(box,true); |
864 | } | 917 | } |
865 | } | 918 | } |
866 | } | 919 | } |
867 | } | 920 | } |
868 | 921 | ||
869 | QPopupMenu * MHfolderItem::getContextMenu() | 922 | QPopupMenu * MHfolderItem::getContextMenu() |
870 | { | 923 | { |
871 | QPopupMenu *m = new QPopupMenu(0); | 924 | QPopupMenu *m = new QPopupMenu(0); |
872 | if (m) { | 925 | if (m) { |
873 | m->insertItem(QObject::tr("Delete all mails",contextName),0); | 926 | m->insertItem(QObject::tr("Delete all mails",contextName),0); |
874 | m->insertItem(QObject::tr("Delete folder",contextName),1); | 927 | m->insertItem(QObject::tr("Delete folder",contextName),1); |
875 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); | 928 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); |
929 | m->insertItem(QObject::tr("Create new folder",contextName),3); | ||
876 | } | 930 | } |
877 | return m; | 931 | return m; |
878 | } | 932 | } |
879 | 933 | ||
880 | void MHfolderItem::downloadMails() | 934 | void MHfolderItem::downloadMails() |
881 | { | 935 | { |
882 | AccountView*bl = mbox->accountView(); | 936 | AccountView*bl = mbox->accountView(); |
883 | if (!bl) return; | 937 | if (!bl) return; |
884 | bl->downloadMails(folder,mbox->getWrapper()); | 938 | bl->downloadMails(folder,mbox->getWrapper()); |
885 | } | 939 | } |
886 | 940 | ||
887 | void MHfolderItem::contextMenuSelected(int which) | 941 | void MHfolderItem::contextMenuSelected(int which) |
888 | { | 942 | { |
889 | switch(which) { | 943 | switch(which) { |
890 | case 0: | 944 | case 0: |
891 | deleteAllMail(mbox->getWrapper(),folder); | 945 | deleteAllMail(mbox->getWrapper(),folder); |
892 | break; | 946 | break; |
893 | case 1: | 947 | case 1: |
894 | deleteFolder(); | 948 | deleteFolder(); |
895 | break; | 949 | break; |
896 | case 2: | 950 | case 2: |
897 | downloadMails(); | 951 | downloadMails(); |
898 | break; | 952 | break; |
899 | default: | 953 | default: |
900 | break; | 954 | break; |
901 | } | 955 | } |
902 | } | 956 | } |
957 | |||
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h index f5a2973..60e2b4b 100644 --- a/noncore/net/mail/accountview.h +++ b/noncore/net/mail/accountview.h | |||
@@ -41,150 +41,154 @@ public: | |||
41 | POP3viewItem( POP3account *a, AccountView *parent ); | 41 | POP3viewItem( POP3account *a, AccountView *parent ); |
42 | virtual ~POP3viewItem(); | 42 | virtual ~POP3viewItem(); |
43 | virtual void refresh( QList<RecMail> &target ); | 43 | virtual void refresh( QList<RecMail> &target ); |
44 | virtual RecBody fetchBody( const RecMail &mail ); | 44 | virtual RecBody fetchBody( const RecMail &mail ); |
45 | AbstractMail *getWrapper(); | 45 | AbstractMail *getWrapper(); |
46 | virtual QPopupMenu * getContextMenu(); | 46 | virtual QPopupMenu * getContextMenu(); |
47 | virtual void contextMenuSelected(int); | 47 | virtual void contextMenuSelected(int); |
48 | 48 | ||
49 | protected: | 49 | protected: |
50 | POP3account *account; | 50 | POP3account *account; |
51 | virtual void refresh(); | 51 | virtual void refresh(); |
52 | AbstractMail *wrapper; | 52 | AbstractMail *wrapper; |
53 | void disconnect(); | 53 | void disconnect(); |
54 | void setOnOffline(); | 54 | void setOnOffline(); |
55 | }; | 55 | }; |
56 | 56 | ||
57 | class POP3folderItem : public AccountViewItem | 57 | class POP3folderItem : public AccountViewItem |
58 | { | 58 | { |
59 | 59 | ||
60 | public: | 60 | public: |
61 | POP3folderItem( Folder *folder, POP3viewItem *parent , QListViewItem*after ); | 61 | POP3folderItem( Folder *folder, POP3viewItem *parent , QListViewItem*after ); |
62 | virtual ~POP3folderItem(); | 62 | virtual ~POP3folderItem(); |
63 | virtual void refresh(QList<RecMail>&); | 63 | virtual void refresh(QList<RecMail>&); |
64 | virtual RecBody fetchBody(const RecMail&); | 64 | virtual RecBody fetchBody(const RecMail&); |
65 | virtual QPopupMenu * getContextMenu(); | 65 | virtual QPopupMenu * getContextMenu(); |
66 | virtual void contextMenuSelected(int); | 66 | virtual void contextMenuSelected(int); |
67 | 67 | ||
68 | protected: | 68 | protected: |
69 | void downloadMails(); | 69 | void downloadMails(); |
70 | Folder *folder; | 70 | Folder *folder; |
71 | POP3viewItem *pop3; | 71 | POP3viewItem *pop3; |
72 | }; | 72 | }; |
73 | 73 | ||
74 | class IMAPfolderItem; | 74 | class IMAPfolderItem; |
75 | 75 | ||
76 | class IMAPviewItem : public AccountViewItem | 76 | class IMAPviewItem : public AccountViewItem |
77 | { | 77 | { |
78 | friend class IMAPfolderItem; | 78 | friend class IMAPfolderItem; |
79 | public: | 79 | public: |
80 | IMAPviewItem( IMAPaccount *a, AccountView *parent ); | 80 | IMAPviewItem( IMAPaccount *a, AccountView *parent ); |
81 | virtual ~IMAPviewItem(); | 81 | virtual ~IMAPviewItem(); |
82 | virtual void refresh(QList<RecMail>&); | 82 | virtual void refresh(QList<RecMail>&); |
83 | virtual RecBody fetchBody(const RecMail&); | 83 | virtual RecBody fetchBody(const RecMail&); |
84 | AbstractMail *getWrapper(); | 84 | AbstractMail *getWrapper(); |
85 | virtual QPopupMenu * getContextMenu(); | 85 | virtual QPopupMenu * getContextMenu(); |
86 | virtual void contextMenuSelected(int); | 86 | virtual void contextMenuSelected(int); |
87 | const QStringList&subFolders(); | 87 | const QStringList&subFolders(); |
88 | virtual void refreshFolders(bool force=false); | 88 | virtual void refreshFolders(bool force=false); |
89 | bool offline(); | 89 | bool offline(); |
90 | 90 | ||
91 | protected: | 91 | protected: |
92 | IMAPfolderItem*findSubItem(const QString&path,IMAPfolderItem*start=0); | 92 | IMAPfolderItem*findSubItem(const QString&path,IMAPfolderItem*start=0); |
93 | virtual void createNewFolder(); | 93 | virtual void createNewFolder(); |
94 | virtual void removeChilds(); | 94 | virtual void removeChilds(); |
95 | IMAPaccount *account; | 95 | IMAPaccount *account; |
96 | AbstractMail *wrapper; | 96 | AbstractMail *wrapper; |
97 | QStringList currentFolders; | 97 | QStringList currentFolders; |
98 | }; | 98 | }; |
99 | 99 | ||
100 | class IMAPfolderItem : public AccountViewItem | 100 | class IMAPfolderItem : public AccountViewItem |
101 | { | 101 | { |
102 | 102 | ||
103 | public: | 103 | public: |
104 | IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after ); | 104 | IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after ); |
105 | IMAPfolderItem( Folder *folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ); | 105 | IMAPfolderItem( Folder *folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ); |
106 | virtual ~IMAPfolderItem(); | 106 | virtual ~IMAPfolderItem(); |
107 | virtual void refresh(QList<RecMail>&); | 107 | virtual void refresh(QList<RecMail>&); |
108 | virtual RecBody fetchBody(const RecMail&); | 108 | virtual RecBody fetchBody(const RecMail&); |
109 | bool matchName(const QString&name)const; | 109 | bool matchName(const QString&name)const; |
110 | virtual QPopupMenu * getContextMenu(); | 110 | virtual QPopupMenu * getContextMenu(); |
111 | virtual void contextMenuSelected(int); | 111 | virtual void contextMenuSelected(int); |
112 | virtual const QString& Delemiter()const; | 112 | virtual const QString& Delemiter()const; |
113 | protected: | 113 | protected: |
114 | virtual void createNewFolder(); | 114 | virtual void createNewFolder(); |
115 | virtual void deleteFolder(); | 115 | virtual void deleteFolder(); |
116 | virtual void downloadMails(); | 116 | virtual void downloadMails(); |
117 | Folder *folder; | 117 | Folder *folder; |
118 | IMAPviewItem *imap; | 118 | IMAPviewItem *imap; |
119 | }; | 119 | }; |
120 | 120 | ||
121 | class MHviewItem : public AccountViewItem | 121 | class MHviewItem : public AccountViewItem |
122 | { | 122 | { |
123 | friend class MHfolderItem; | 123 | friend class MHfolderItem; |
124 | 124 | ||
125 | public: | 125 | public: |
126 | MHviewItem( const QString&aMboxPath, AccountView *parent ); | 126 | MHviewItem( const QString&aMboxPath, AccountView *parent ); |
127 | virtual ~MHviewItem(); | 127 | virtual ~MHviewItem(); |
128 | virtual void refresh( QList<RecMail> &target ); | 128 | virtual void refresh( QList<RecMail> &target ); |
129 | virtual RecBody fetchBody( const RecMail &mail ); | 129 | virtual RecBody fetchBody( const RecMail &mail ); |
130 | AbstractMail *getWrapper(); | 130 | AbstractMail *getWrapper(); |
131 | virtual QPopupMenu * getContextMenu(); | 131 | virtual QPopupMenu * getContextMenu(); |
132 | virtual void contextMenuSelected(int); | 132 | virtual void contextMenuSelected(int); |
133 | QStringList subFolders(); | 133 | QStringList subFolders(); |
134 | virtual void refresh(bool force=false); | 134 | virtual void refresh(bool force=false); |
135 | 135 | ||
136 | protected: | 136 | protected: |
137 | void downloadMails(); | ||
138 | void removeChilds(); | ||
137 | virtual void createFolder(); | 139 | virtual void createFolder(); |
138 | QString m_Path; | 140 | QString m_Path; |
139 | AbstractMail *wrapper; | 141 | AbstractMail *wrapper; |
140 | 142 | Folder *folder; | |
141 | }; | 143 | }; |
142 | 144 | ||
143 | class MHfolderItem : public AccountViewItem | 145 | class MHfolderItem : public AccountViewItem |
144 | { | 146 | { |
145 | 147 | ||
146 | public: | 148 | public: |
147 | MHfolderItem( Folder *folder, MHviewItem *parent , QListViewItem*after ); | 149 | MHfolderItem( Folder *folder, MHviewItem *parent , QListViewItem*after ); |
150 | MHfolderItem( Folder *folder, MHfolderItem *parent, QListViewItem*after, MHviewItem*master); | ||
148 | virtual ~MHfolderItem(); | 151 | virtual ~MHfolderItem(); |
149 | virtual void refresh(QList<RecMail>&); | 152 | virtual void refresh(QList<RecMail>&); |
150 | virtual RecBody fetchBody(const RecMail&); | 153 | virtual RecBody fetchBody(const RecMail&); |
151 | virtual QPopupMenu * getContextMenu(); | 154 | virtual QPopupMenu * getContextMenu(); |
152 | virtual void contextMenuSelected(int); | 155 | virtual void contextMenuSelected(int); |
153 | virtual Folder*getFolder(); | 156 | virtual Folder*getFolder(); |
154 | 157 | ||
155 | protected: | 158 | protected: |
156 | void downloadMails(); | 159 | void downloadMails(); |
157 | virtual void deleteFolder(); | 160 | virtual void deleteFolder(); |
161 | void initName(); | ||
158 | Folder *folder; | 162 | Folder *folder; |
159 | MHviewItem *mbox; | 163 | MHviewItem *mbox; |
160 | }; | 164 | }; |
161 | 165 | ||
162 | class AccountView : public QListView | 166 | class AccountView : public QListView |
163 | { | 167 | { |
164 | Q_OBJECT | 168 | Q_OBJECT |
165 | 169 | ||
166 | public: | 170 | public: |
167 | AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); | 171 | AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); |
168 | virtual ~AccountView(); | 172 | virtual ~AccountView(); |
169 | virtual void populate( QList<Account> list ); | 173 | virtual void populate( QList<Account> list ); |
170 | virtual RecBody fetchBody(const RecMail&aMail); | 174 | virtual RecBody fetchBody(const RecMail&aMail); |
171 | virtual void downloadMails(Folder*fromFolder,AbstractMail*fromWrapper); | 175 | virtual void downloadMails(Folder*fromFolder,AbstractMail*fromWrapper); |
172 | 176 | ||
173 | public slots: | 177 | public slots: |
174 | virtual void refreshAll(); | 178 | virtual void refreshAll(); |
175 | virtual void refresh(QListViewItem *item); | 179 | virtual void refresh(QListViewItem *item); |
176 | virtual void refreshCurrent(); | 180 | virtual void refreshCurrent(); |
177 | virtual void slotHold(int, QListViewItem *,const QPoint&,int); | 181 | virtual void slotHold(int, QListViewItem *,const QPoint&,int); |
178 | virtual void slotContextMenu(int id); | 182 | virtual void slotContextMenu(int id); |
179 | void setupFolderselect(Selectstore*sels); | 183 | void setupFolderselect(Selectstore*sels); |
180 | 184 | ||
181 | signals: | 185 | signals: |
182 | void refreshMailview(QList<RecMail>*); | 186 | void refreshMailview(QList<RecMail>*); |
183 | 187 | ||
184 | protected: | 188 | protected: |
185 | QListViewItem* m_currentItem; | 189 | QListViewItem* m_currentItem; |
186 | QValueList<IMAPviewItem*> imapAccounts; | 190 | QValueList<IMAPviewItem*> imapAccounts; |
187 | QValueList<MHviewItem*> mhAccounts; | 191 | QValueList<MHviewItem*> mhAccounts; |
188 | }; | 192 | }; |
189 | 193 | ||
190 | #endif | 194 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.cpp b/noncore/net/mail/libmailwrapper/mhwrapper.cpp index 5adba55..512f778 100644 --- a/noncore/net/mail/libmailwrapper/mhwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mhwrapper.cpp | |||
@@ -238,96 +238,164 @@ void MHwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) | |||
238 | { | 238 | { |
239 | QString f = buildPath(mailbox); | 239 | QString f = buildPath(mailbox); |
240 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 240 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
241 | if (r!=MAIL_NO_ERROR) { | 241 | if (r!=MAIL_NO_ERROR) { |
242 | qDebug("deleteMails: error selecting folder!"); | 242 | qDebug("deleteMails: error selecting folder!"); |
243 | return; | 243 | return; |
244 | } | 244 | } |
245 | RecMail*c = 0; | 245 | RecMail*c = 0; |
246 | for (unsigned int i=0; i < target.count();++i) { | 246 | for (unsigned int i=0; i < target.count();++i) { |
247 | c = target.at(i); | 247 | c = target.at(i); |
248 | r = mailsession_remove_message(m_storage->sto_session,c->getNumber()); | 248 | r = mailsession_remove_message(m_storage->sto_session,c->getNumber()); |
249 | if (r != MAIL_NO_ERROR) { | 249 | if (r != MAIL_NO_ERROR) { |
250 | qDebug("error deleting mail"); | 250 | qDebug("error deleting mail"); |
251 | break; | 251 | break; |
252 | } | 252 | } |
253 | } | 253 | } |
254 | } | 254 | } |
255 | 255 | ||
256 | int MHwrapper::deleteAllMail(const Folder*tfolder) | 256 | int MHwrapper::deleteAllMail(const Folder*tfolder) |
257 | { | 257 | { |
258 | init_storage(); | 258 | init_storage(); |
259 | if (!m_storage) { | 259 | if (!m_storage) { |
260 | return 0; | 260 | return 0; |
261 | } | 261 | } |
262 | int res = 1; | 262 | int res = 1; |
263 | if (!tfolder) return 0; | 263 | if (!tfolder) return 0; |
264 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | 264 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); |
265 | if (r!=MAIL_NO_ERROR) { | 265 | if (r!=MAIL_NO_ERROR) { |
266 | qDebug("error selecting folder!"); | 266 | qDebug("error selecting folder!"); |
267 | return 0; | 267 | return 0; |
268 | } | 268 | } |
269 | mailmessage_list*l=0; | 269 | mailmessage_list*l=0; |
270 | r = mailsession_get_messages_list(m_storage->sto_session,&l); | 270 | r = mailsession_get_messages_list(m_storage->sto_session,&l); |
271 | if (r != MAIL_NO_ERROR) { | 271 | if (r != MAIL_NO_ERROR) { |
272 | qDebug("Error message list"); | 272 | qDebug("Error message list"); |
273 | res = 0; | 273 | res = 0; |
274 | } | 274 | } |
275 | unsigned j = 0; | 275 | unsigned j = 0; |
276 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | 276 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { |
277 | mailmessage * msg; | 277 | mailmessage * msg; |
278 | msg = (mailmessage*)carray_get(l->msg_tab, i); | 278 | msg = (mailmessage*)carray_get(l->msg_tab, i); |
279 | j = msg->msg_index; | 279 | j = msg->msg_index; |
280 | r = mailsession_remove_message(m_storage->sto_session,j); | 280 | r = mailsession_remove_message(m_storage->sto_session,j); |
281 | if (r != MAIL_NO_ERROR) { | 281 | if (r != MAIL_NO_ERROR) { |
282 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 282 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
283 | res = 0; | 283 | res = 0; |
284 | break; | 284 | break; |
285 | } | 285 | } |
286 | } | 286 | } |
287 | if (l) mailmessage_list_free(l); | 287 | if (l) mailmessage_list_free(l); |
288 | return res; | 288 | return res; |
289 | } | 289 | } |
290 | 290 | ||
291 | int MHwrapper::deleteMbox(const Folder*tfolder) | 291 | int MHwrapper::deleteMbox(const Folder*tfolder) |
292 | { | 292 | { |
293 | init_storage(); | 293 | init_storage(); |
294 | if (!m_storage) { | 294 | if (!m_storage) { |
295 | return 0; | 295 | return 0; |
296 | } | 296 | } |
297 | if (!tfolder) return 0; | 297 | if (!tfolder) return 0; |
298 | int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | 298 | int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); |
299 | if (r != MAIL_NO_ERROR) { | 299 | if (r != MAIL_NO_ERROR) { |
300 | qDebug("error deleting mail box"); | 300 | qDebug("error deleting mail box"); |
301 | return 0; | 301 | return 0; |
302 | } | 302 | } |
303 | qDebug("mail box deleted"); | 303 | qDebug("mail box deleted"); |
304 | mailstorage_disconnect(m_storage); | 304 | mailstorage_disconnect(m_storage); |
305 | return 1; | 305 | return 1; |
306 | } | 306 | } |
307 | 307 | ||
308 | void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | 308 | void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) |
309 | { | 309 | { |
310 | init_storage(); | 310 | init_storage(); |
311 | if (!m_storage) { | 311 | if (!m_storage) { |
312 | return; | 312 | return; |
313 | } | 313 | } |
314 | target_stat.message_count = 0; | 314 | target_stat.message_count = 0; |
315 | target_stat.message_unseen = 0; | 315 | target_stat.message_unseen = 0; |
316 | target_stat.message_recent = 0; | 316 | target_stat.message_recent = 0; |
317 | QString f = buildPath(mailbox); | 317 | QString f = buildPath(mailbox); |
318 | int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, | 318 | int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, |
319 | &target_stat.message_recent,&target_stat.message_unseen); | 319 | &target_stat.message_recent,&target_stat.message_unseen); |
320 | if (r != MAIL_NO_ERROR) { | 320 | if (r != MAIL_NO_ERROR) { |
321 | Global::statusMessage(tr("Error retrieving status")); | 321 | Global::statusMessage(tr("Error retrieving status")); |
322 | } | 322 | } |
323 | } | 323 | } |
324 | 324 | ||
325 | const QString&MHwrapper::getType()const | 325 | const QString&MHwrapper::getType()const |
326 | { | 326 | { |
327 | return wrapperType; | 327 | return wrapperType; |
328 | } | 328 | } |
329 | 329 | ||
330 | const QString&MHwrapper::getName()const | 330 | const QString&MHwrapper::getName()const |
331 | { | 331 | { |
332 | return MHName; | 332 | return MHName; |
333 | } | 333 | } |
334 | void MHwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | ||
335 | { | ||
336 | init_storage(); | ||
337 | if (!m_storage) { | ||
338 | return; | ||
339 | } | ||
340 | if (targetWrapper != this) { | ||
341 | qDebug("Using generic"); | ||
342 | Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); | ||
343 | return; | ||
344 | } | ||
345 | qDebug("Using internal routines for move/copy"); | ||
346 | QString tf = buildPath(targetFolder); | ||
347 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); | ||
348 | if (r != MAIL_NO_ERROR) { | ||
349 | qDebug("Error selecting source mailbox"); | ||
350 | return; | ||
351 | } | ||
352 | if (moveit) { | ||
353 | r = mailsession_move_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1()); | ||
354 | } else { | ||
355 | r = mailsession_copy_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1()); | ||
356 | } | ||
357 | if (r != MAIL_NO_ERROR) { | ||
358 | qDebug("Error copy/moving mail internal (%i)",r); | ||
359 | } | ||
360 | } | ||
361 | |||
362 | void MHwrapper::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | ||
363 | { | ||
364 | init_storage(); | ||
365 | if (!m_storage) { | ||
366 | return; | ||
367 | } | ||
368 | if (targetWrapper != this) { | ||
369 | qDebug("Using generic"); | ||
370 | Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); | ||
371 | return; | ||
372 | } | ||
373 | if (!fromFolder) return; | ||
374 | int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1()); | ||
375 | if (r!=MAIL_NO_ERROR) { | ||
376 | qDebug("error selecting source folder!"); | ||
377 | return; | ||
378 | } | ||
379 | QString tf = buildPath(targetFolder); | ||
380 | mailmessage_list*l=0; | ||
381 | r = mailsession_get_messages_list(m_storage->sto_session,&l); | ||
382 | if (r != MAIL_NO_ERROR) { | ||
383 | qDebug("Error message list"); | ||
384 | } | ||
385 | unsigned j = 0; | ||
386 | for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) { | ||
387 | mailmessage * msg; | ||
388 | msg = (mailmessage*)carray_get(l->msg_tab, i); | ||
389 | j = msg->msg_index; | ||
390 | if (moveit) { | ||
391 | r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1()); | ||
392 | } else { | ||
393 | r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1()); | ||
394 | } | ||
395 | if (r != MAIL_NO_ERROR) { | ||
396 | qDebug("Error copy/moving mail internal (%i)",r); | ||
397 | break; | ||
398 | } | ||
399 | } | ||
400 | if (l) mailmessage_list_free(l); | ||
401 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.h b/noncore/net/mail/libmailwrapper/mhwrapper.h index 7f028b4..79dec30 100644 --- a/noncore/net/mail/libmailwrapper/mhwrapper.h +++ b/noncore/net/mail/libmailwrapper/mhwrapper.h | |||
@@ -1,50 +1,52 @@ | |||
1 | #ifndef __MH_WRAPPER_H | 1 | #ifndef __MH_WRAPPER_H |
2 | #define __MH_WRAPPER_H | 2 | #define __MH_WRAPPER_H |
3 | 3 | ||
4 | #include "genericwrapper.h" | 4 | #include "genericwrapper.h" |
5 | #include <qstring.h> | 5 | #include <qstring.h> |
6 | 6 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | class encodedString; | 9 | class encodedString; |
10 | struct mailmbox_folder; | 10 | struct mailmbox_folder; |
11 | 11 | ||
12 | class MHwrapper : public Genericwrapper | 12 | class MHwrapper : public Genericwrapper |
13 | { | 13 | { |
14 | Q_OBJECT | 14 | Q_OBJECT |
15 | public: | 15 | public: |
16 | MHwrapper(const QString & dir,const QString&name); | 16 | MHwrapper(const QString & dir,const QString&name); |
17 | virtual ~MHwrapper(); | 17 | virtual ~MHwrapper(); |
18 | 18 | ||
19 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 19 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
20 | virtual QList<Folder>* listFolders(); | 20 | virtual QList<Folder>* listFolders(); |
21 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | 21 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); |
22 | 22 | ||
23 | virtual void deleteMail(const RecMail&mail); | 23 | virtual void deleteMail(const RecMail&mail); |
24 | virtual void answeredMail(const RecMail&mail); | 24 | virtual void answeredMail(const RecMail&mail); |
25 | virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | ||
26 | virtual void mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | ||
25 | 27 | ||
26 | virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false); | 28 | virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false); |
27 | virtual int deleteMbox(const Folder*); | 29 | virtual int deleteMbox(const Folder*); |
28 | 30 | ||
29 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); | 31 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); |
30 | 32 | ||
31 | virtual RecBody fetchBody( const RecMail &mail ); | 33 | virtual RecBody fetchBody( const RecMail &mail ); |
32 | static void mbox_progress( size_t current, size_t maximum ); | 34 | static void mbox_progress( size_t current, size_t maximum ); |
33 | 35 | ||
34 | virtual encodedString* fetchRawBody(const RecMail&mail); | 36 | virtual encodedString* fetchRawBody(const RecMail&mail); |
35 | virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); | 37 | virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); |
36 | virtual int deleteAllMail(const Folder*); | 38 | virtual int deleteAllMail(const Folder*); |
37 | virtual const QString&getType()const; | 39 | virtual const QString&getType()const; |
38 | virtual const QString&getName()const; | 40 | virtual const QString&getName()const; |
39 | 41 | ||
40 | protected: | 42 | protected: |
41 | QString buildPath(const QString&p); | 43 | QString buildPath(const QString&p); |
42 | QString MHPath; | 44 | QString MHPath; |
43 | QString MHName; | 45 | QString MHName; |
44 | static const QString wrapperType; | 46 | static const QString wrapperType; |
45 | 47 | ||
46 | void init_storage(); | 48 | void init_storage(); |
47 | void clean_storage(); | 49 | void clean_storage(); |
48 | }; | 50 | }; |
49 | 51 | ||
50 | #endif | 52 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index f5eca4a..14c2059 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp | |||
@@ -1,266 +1,255 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include "pop3wrapper.h" | 2 | #include "pop3wrapper.h" |
3 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
4 | #include "logindialog.h" | 4 | #include "logindialog.h" |
5 | #include <libetpan/libetpan.h> | 5 | #include <libetpan/libetpan.h> |
6 | #include <qpe/global.h> | 6 | #include <qpe/global.h> |
7 | #include <qfile.h> | 7 | #include <qfile.h> |
8 | #include <qstring.h> | 8 | #include <qstring.h> |
9 | 9 | ||
10 | /* we don't fetch messages larger than 5 MB */ | 10 | /* we don't fetch messages larger than 5 MB */ |
11 | #define HARD_MSG_SIZE_LIMIT 5242880 | 11 | #define HARD_MSG_SIZE_LIMIT 5242880 |
12 | 12 | ||
13 | POP3wrapper::POP3wrapper( POP3account *a ) | 13 | POP3wrapper::POP3wrapper( POP3account *a ) |
14 | : Genericwrapper() { | 14 | : Genericwrapper() { |
15 | account = a; | 15 | account = a; |
16 | m_pop3 = NULL; | 16 | m_pop3 = NULL; |
17 | m_folder = NULL; | ||
18 | msgTempName = a->getFileName()+"_msg_cache"; | 17 | msgTempName = a->getFileName()+"_msg_cache"; |
19 | last_msg_id = 0; | 18 | last_msg_id = 0; |
20 | } | 19 | } |
21 | 20 | ||
22 | POP3wrapper::~POP3wrapper() { | 21 | POP3wrapper::~POP3wrapper() { |
23 | logout(); | 22 | logout(); |
24 | QFile msg_cache(msgTempName); | 23 | QFile msg_cache(msgTempName); |
25 | if (msg_cache.exists()) { | 24 | if (msg_cache.exists()) { |
26 | msg_cache.remove(); | 25 | msg_cache.remove(); |
27 | } | 26 | } |
28 | } | 27 | } |
29 | 28 | ||
30 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { | 29 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { |
31 | qDebug( "POP3: %i of %i", current, maximum ); | 30 | qDebug( "POP3: %i of %i", current, maximum ); |
32 | } | 31 | } |
33 | 32 | ||
34 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) { | 33 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) { |
35 | int err = MAILPOP3_NO_ERROR; | 34 | int err = MAILPOP3_NO_ERROR; |
36 | char *message = 0; | 35 | char *message = 0; |
37 | size_t length = 0; | 36 | size_t length = 0; |
38 | 37 | ||
39 | login(); | 38 | login(); |
40 | if ( !m_pop3 ) { | 39 | if ( !m_pop3 ) { |
41 | return RecBody(); | 40 | return RecBody(); |
42 | } | 41 | } |
43 | 42 | ||
44 | RecBody body; | 43 | RecBody body; |
45 | mailmessage * mailmsg; | 44 | mailmessage * mailmsg; |
46 | if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { | 45 | if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { |
47 | qDebug("Message to large: %i",mail.Msgsize()); | 46 | qDebug("Message to large: %i",mail.Msgsize()); |
48 | return body; | 47 | return body; |
49 | } | 48 | } |
50 | 49 | ||
51 | QFile msg_cache(msgTempName); | 50 | QFile msg_cache(msgTempName); |
52 | 51 | ||
53 | cleanMimeCache(); | 52 | cleanMimeCache(); |
54 | 53 | ||
55 | if (mail.getNumber()!=last_msg_id) { | 54 | if (mail.getNumber()!=last_msg_id) { |
56 | if (msg_cache.exists()) { | 55 | if (msg_cache.exists()) { |
57 | msg_cache.remove(); | 56 | msg_cache.remove(); |
58 | } | 57 | } |
59 | msg_cache.open(IO_ReadWrite|IO_Truncate); | 58 | msg_cache.open(IO_ReadWrite|IO_Truncate); |
60 | last_msg_id = mail.getNumber(); | 59 | last_msg_id = mail.getNumber(); |
61 | err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); | 60 | err = mailsession_get_message(m_pop3->sto_session, mail.getNumber(), &mailmsg); |
62 | err = mailmessage_fetch(mailmsg,&message,&length); | 61 | err = mailmessage_fetch(mailmsg,&message,&length); |
63 | msg_cache.writeBlock(message,length); | 62 | msg_cache.writeBlock(message,length); |
64 | } else { | 63 | } else { |
65 | QString msg=""; | 64 | QString msg=""; |
66 | msg_cache.open(IO_ReadOnly); | 65 | msg_cache.open(IO_ReadOnly); |
67 | message = new char[4096]; | 66 | message = new char[4096]; |
68 | memset(message,0,4096); | 67 | memset(message,0,4096); |
69 | while (msg_cache.readBlock(message,4095)>0) { | 68 | while (msg_cache.readBlock(message,4095)>0) { |
70 | msg+=message; | 69 | msg+=message; |
71 | memset(message,0,4096); | 70 | memset(message,0,4096); |
72 | } | 71 | } |
73 | delete message; | 72 | delete message; |
74 | message = (char*)malloc(msg.length()+1*sizeof(char)); | 73 | message = (char*)malloc(msg.length()+1*sizeof(char)); |
75 | memset(message,0,msg.length()+1); | 74 | memset(message,0,msg.length()+1); |
76 | memcpy(message,msg.latin1(),msg.length()); | 75 | memcpy(message,msg.latin1(),msg.length()); |
77 | /* transform to libetpan stuff */ | 76 | /* transform to libetpan stuff */ |
78 | mailmsg = mailmessage_new(); | 77 | mailmsg = mailmessage_new(); |
79 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); | 78 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); |
80 | generic_message_t * msg_data; | 79 | generic_message_t * msg_data; |
81 | msg_data = (generic_message_t *)mailmsg->msg_data; | 80 | msg_data = (generic_message_t *)mailmsg->msg_data; |
82 | msg_data->msg_fetched = 1; | 81 | msg_data->msg_fetched = 1; |
83 | msg_data->msg_message = message; | 82 | msg_data->msg_message = message; |
84 | msg_data->msg_length = strlen(message); | 83 | msg_data->msg_length = strlen(message); |
85 | } | 84 | } |
86 | body = parseMail(mailmsg); | 85 | body = parseMail(mailmsg); |
87 | 86 | ||
88 | /* clean up */ | 87 | /* clean up */ |
89 | if (mailmsg) | 88 | if (mailmsg) |
90 | mailmessage_free(mailmsg); | 89 | mailmessage_free(mailmsg); |
91 | if (message) | 90 | if (message) |
92 | free(message); | 91 | free(message); |
93 | 92 | ||
94 | return body; | 93 | return body; |
95 | } | 94 | } |
96 | 95 | ||
97 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) { | 96 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) |
97 | { | ||
98 | login(); | 98 | login(); |
99 | if (!m_pop3) | 99 | if (!m_pop3) |
100 | return; | 100 | return; |
101 | uint32_t res_messages,res_recent,res_unseen; | 101 | uint32_t res_messages,res_recent,res_unseen; |
102 | mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen); | 102 | mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); |
103 | parseList(target,m_folder->fld_session,"INBOX"); | 103 | parseList(target,m_pop3->sto_session,"INBOX"); |
104 | Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); | 104 | Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); |
105 | } | 105 | } |
106 | 106 | ||
107 | void POP3wrapper::login() { | 107 | void POP3wrapper::login() |
108 | { | ||
108 | if (account->getOffline()) | 109 | if (account->getOffline()) |
109 | return; | 110 | return; |
110 | /* we'll hold the line */ | 111 | /* we'll hold the line */ |
111 | if ( m_pop3 != NULL ) | 112 | if ( m_pop3 != NULL ) |
112 | return; | 113 | return; |
113 | 114 | ||
114 | const char *server, *user, *pass; | 115 | const char *server, *user, *pass; |
115 | uint16_t port; | 116 | uint16_t port; |
116 | int err = MAILPOP3_NO_ERROR; | 117 | int err = MAILPOP3_NO_ERROR; |
117 | 118 | ||
118 | server = account->getServer().latin1(); | 119 | server = account->getServer().latin1(); |
119 | port = account->getPort().toUInt(); | 120 | port = account->getPort().toUInt(); |
120 | 121 | ||
121 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 122 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
122 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 123 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
123 | login.show(); | 124 | login.show(); |
124 | if ( QDialog::Accepted == login.exec() ) { | 125 | if ( QDialog::Accepted == login.exec() ) { |
125 | // ok | 126 | // ok |
126 | user = login.getUser().latin1(); | 127 | user = login.getUser().latin1(); |
127 | pass = login.getPassword().latin1(); | 128 | pass = login.getPassword().latin1(); |
128 | } else { | 129 | } else { |
129 | // cancel | 130 | // cancel |
130 | qDebug( "POP3: Login canceled" ); | 131 | qDebug( "POP3: Login canceled" ); |
131 | return; | 132 | return; |
132 | } | 133 | } |
133 | } else { | 134 | } else { |
134 | user = account->getUser().latin1(); | 135 | user = account->getUser().latin1(); |
135 | pass = account->getPassword().latin1(); | 136 | pass = account->getPassword().latin1(); |
136 | } | 137 | } |
137 | 138 | ||
138 | // bool ssl = account->getSSL(); | 139 | // bool ssl = account->getSSL(); |
139 | 140 | ||
140 | m_pop3=mailstorage_new(NULL); | 141 | m_pop3=mailstorage_new(NULL); |
141 | 142 | ||
142 | int conntypeset = account->ConnectionType(); | 143 | int conntypeset = account->ConnectionType(); |
143 | int conntype = 0; | 144 | int conntype = 0; |
144 | if ( conntypeset == 3 ) { | 145 | if ( conntypeset == 3 ) { |
145 | conntype = CONNECTION_TYPE_COMMAND; | 146 | conntype = CONNECTION_TYPE_COMMAND; |
146 | } else if ( conntypeset == 2 ) { | 147 | } else if ( conntypeset == 2 ) { |
147 | conntype = CONNECTION_TYPE_TLS; | 148 | conntype = CONNECTION_TYPE_TLS; |
148 | } else if ( conntypeset == 1 ) { | 149 | } else if ( conntypeset == 1 ) { |
149 | conntype = CONNECTION_TYPE_STARTTLS; | 150 | conntype = CONNECTION_TYPE_STARTTLS; |
150 | } else if ( conntypeset == 0 ) { | 151 | } else if ( conntypeset == 0 ) { |
151 | conntype = CONNECTION_TYPE_TRY_STARTTLS; | 152 | conntype = CONNECTION_TYPE_TRY_STARTTLS; |
152 | } | 153 | } |
153 | 154 | ||
154 | //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); | 155 | //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); |
155 | 156 | ||
156 | pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, | 157 | pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, |
157 | (char*)user,(char*)pass,0,0,0); | 158 | (char*)user,(char*)pass,0,0,0); |
158 | 159 | ||
159 | 160 | ||
160 | 161 | err = mailstorage_connect(m_pop3); | |
161 | m_folder = mailfolder_new(m_pop3, NULL, NULL); | ||
162 | |||
163 | if (m_folder==0) { | ||
164 | Global::statusMessage(tr("Error initializing folder")); | ||
165 | mailstorage_free(m_pop3); | ||
166 | m_pop3 = NULL; | ||
167 | return; | ||
168 | } | ||
169 | err = mailfolder_connect(m_folder); | ||
170 | if (err != MAIL_NO_ERROR) { | 162 | if (err != MAIL_NO_ERROR) { |
171 | qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) ); | 163 | qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) ); |
172 | Global::statusMessage(tr("Error initializing folder")); | 164 | Global::statusMessage(tr("Error initializing folder")); |
173 | mailfolder_free(m_folder); | ||
174 | m_folder = 0; | ||
175 | mailstorage_free(m_pop3); | 165 | mailstorage_free(m_pop3); |
176 | m_pop3 = 0; | 166 | m_pop3 = 0; |
177 | } | 167 | } |
178 | } | 168 | } |
179 | 169 | ||
180 | void POP3wrapper::logout() { | 170 | void POP3wrapper::logout() |
171 | { | ||
181 | int err = MAILPOP3_NO_ERROR; | 172 | int err = MAILPOP3_NO_ERROR; |
182 | if ( m_pop3 == NULL ) | 173 | if ( m_pop3 == NULL ) |
183 | return; | 174 | return; |
184 | mailfolder_free(m_folder); | ||
185 | m_folder = 0; | ||
186 | mailstorage_free(m_pop3); | 175 | mailstorage_free(m_pop3); |
187 | m_pop3 = 0; | 176 | m_pop3 = 0; |
188 | } | 177 | } |
189 | 178 | ||
190 | 179 | ||
191 | QList<Folder>* POP3wrapper::listFolders() { | 180 | QList<Folder>* POP3wrapper::listFolders() { |
192 | QList<Folder> * folders = new QList<Folder>(); | 181 | QList<Folder> * folders = new QList<Folder>(); |
193 | folders->setAutoDelete( false ); | 182 | folders->setAutoDelete( false ); |
194 | Folder*inb=new Folder("INBOX","/"); | 183 | Folder*inb=new Folder("INBOX","/"); |
195 | folders->append(inb); | 184 | folders->append(inb); |
196 | return folders; | 185 | return folders; |
197 | } | 186 | } |
198 | 187 | ||
199 | void POP3wrapper::deleteMail(const RecMail&mail) { | 188 | void POP3wrapper::deleteMail(const RecMail&mail) { |
200 | login(); | 189 | login(); |
201 | if (!m_pop3) | 190 | if (!m_pop3) |
202 | return; | 191 | return; |
203 | int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber()); | 192 | int err = mailsession_remove_message(m_pop3->sto_session,mail.getNumber()); |
204 | if (err != MAIL_NO_ERROR) { | 193 | if (err != MAIL_NO_ERROR) { |
205 | Global::statusMessage(tr("error deleting mail")); | 194 | Global::statusMessage(tr("error deleting mail")); |
206 | } | 195 | } |
207 | } | 196 | } |
208 | 197 | ||
209 | void POP3wrapper::answeredMail(const RecMail&) {} | 198 | void POP3wrapper::answeredMail(const RecMail&) {} |
210 | 199 | ||
211 | int POP3wrapper::deleteAllMail(const Folder*) { | 200 | int POP3wrapper::deleteAllMail(const Folder*) { |
212 | login(); | 201 | login(); |
213 | if (!m_pop3) | 202 | if (!m_pop3) |
214 | return 0; | 203 | return 0; |
215 | int res = 1; | 204 | int res = 1; |
216 | 205 | ||
217 | uint32_t result = 0; | 206 | uint32_t result = 0; |
218 | int err = mailsession_messages_number(m_folder->fld_session,NULL,&result); | 207 | int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); |
219 | if (err != MAIL_NO_ERROR) { | 208 | if (err != MAIL_NO_ERROR) { |
220 | Global::statusMessage(tr("Error getting folder info")); | 209 | Global::statusMessage(tr("Error getting folder info")); |
221 | return 0; | 210 | return 0; |
222 | } | 211 | } |
223 | for (unsigned int i = 0; i < result; ++i) { | 212 | for (unsigned int i = 0; i < result; ++i) { |
224 | err = mailsession_remove_message(m_folder->fld_session,i+1); | 213 | err = mailsession_remove_message(m_pop3->sto_session,i+1); |
225 | if (err != MAIL_NO_ERROR) { | 214 | if (err != MAIL_NO_ERROR) { |
226 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 215 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
227 | res=0; | 216 | res=0; |
228 | } | 217 | } |
229 | break; | 218 | break; |
230 | } | 219 | } |
231 | return res; | 220 | return res; |
232 | } | 221 | } |
233 | 222 | ||
234 | void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { | 223 | void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { |
235 | login(); | 224 | login(); |
236 | target_stat.message_count = 0; | 225 | target_stat.message_count = 0; |
237 | target_stat.message_unseen = 0; | 226 | target_stat.message_unseen = 0; |
238 | target_stat.message_recent = 0; | 227 | target_stat.message_recent = 0; |
239 | if (!m_pop3) | 228 | if (!m_pop3) |
240 | return; | 229 | return; |
241 | int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count, | 230 | int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, |
242 | &target_stat.message_recent,&target_stat.message_unseen); | 231 | &target_stat.message_recent,&target_stat.message_unseen); |
243 | } | 232 | } |
244 | 233 | ||
245 | encodedString* POP3wrapper::fetchRawBody(const RecMail&mail) { | 234 | encodedString* POP3wrapper::fetchRawBody(const RecMail&mail) { |
246 | char*target=0; | 235 | char*target=0; |
247 | size_t length=0; | 236 | size_t length=0; |
248 | encodedString*res = 0; | 237 | encodedString*res = 0; |
249 | mailmessage * mailmsg = 0; | 238 | mailmessage * mailmsg = 0; |
250 | int err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); | 239 | int err = mailsession_get_message(m_pop3->sto_session, mail.getNumber(), &mailmsg); |
251 | err = mailmessage_fetch(mailmsg,&target,&length); | 240 | err = mailmessage_fetch(mailmsg,&target,&length); |
252 | if (mailmsg) | 241 | if (mailmsg) |
253 | mailmessage_free(mailmsg); | 242 | mailmessage_free(mailmsg); |
254 | if (target) { | 243 | if (target) { |
255 | res = new encodedString(target,length); | 244 | res = new encodedString(target,length); |
256 | } | 245 | } |
257 | return res; | 246 | return res; |
258 | } | 247 | } |
259 | 248 | ||
260 | const QString&POP3wrapper::getType()const { | 249 | const QString&POP3wrapper::getType()const { |
261 | return account->getType(); | 250 | return account->getType(); |
262 | } | 251 | } |
263 | 252 | ||
264 | const QString&POP3wrapper::getName()const { | 253 | const QString&POP3wrapper::getName()const{ |
265 | return account->getAccountName(); | 254 | return account->getAccountName(); |
266 | } | 255 | } |
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index d2b708d..a24b9cf 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h | |||
@@ -1,43 +1,42 @@ | |||
1 | #ifndef __POP3WRAPPER | 1 | #ifndef __POP3WRAPPER |
2 | #define __POP3WRAPPER | 2 | #define __POP3WRAPPER |
3 | 3 | ||
4 | #include "mailwrapper.h" | 4 | #include "mailwrapper.h" |
5 | #include "genericwrapper.h" | 5 | #include "genericwrapper.h" |
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | 7 | ||
8 | class encodedString; | 8 | class encodedString; |
9 | struct mailstorage; | 9 | struct mailstorage; |
10 | struct mailfolder; | 10 | struct mailfolder; |
11 | 11 | ||
12 | class POP3wrapper : public Genericwrapper | 12 | class POP3wrapper : public Genericwrapper |
13 | { | 13 | { |
14 | Q_OBJECT | 14 | Q_OBJECT |
15 | 15 | ||
16 | public: | 16 | public: |
17 | POP3wrapper( POP3account *a ); | 17 | POP3wrapper( POP3account *a ); |
18 | virtual ~POP3wrapper(); | 18 | virtual ~POP3wrapper(); |
19 | /* mailbox will be ignored */ | 19 | /* mailbox will be ignored */ |
20 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 20 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
21 | virtual QList<Folder>* listFolders(); | 21 | virtual QList<Folder>* listFolders(); |
22 | /* mailbox will be ignored */ | 22 | /* mailbox will be ignored */ |
23 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | 23 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); |
24 | 24 | ||
25 | virtual void deleteMail(const RecMail&mail); | 25 | virtual void deleteMail(const RecMail&mail); |
26 | virtual void answeredMail(const RecMail&mail); | 26 | virtual void answeredMail(const RecMail&mail); |
27 | virtual int deleteAllMail(const Folder*); | 27 | virtual int deleteAllMail(const Folder*); |
28 | 28 | ||
29 | virtual RecBody fetchBody( const RecMail &mail ); | 29 | virtual RecBody fetchBody( const RecMail &mail ); |
30 | virtual encodedString* fetchRawBody(const RecMail&mail); | 30 | virtual encodedString* fetchRawBody(const RecMail&mail); |
31 | virtual void logout(); | 31 | virtual void logout(); |
32 | virtual const QString&getType()const; | 32 | virtual const QString&getType()const; |
33 | virtual const QString&getName()const; | 33 | virtual const QString&getName()const; |
34 | static void pop3_progress( size_t current, size_t maximum ); | 34 | static void pop3_progress( size_t current, size_t maximum ); |
35 | 35 | ||
36 | protected: | 36 | protected: |
37 | void login(); | 37 | void login(); |
38 | POP3account *account; | 38 | POP3account *account; |
39 | mailstorage*m_pop3; | 39 | mailstorage*m_pop3; |
40 | mailfolder*m_folder; | ||
41 | }; | 40 | }; |
42 | 41 | ||
43 | #endif | 42 | #endif |