-rw-r--r-- | kmicromail/accountitem.cpp | 14 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.cpp | 4 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/mhwrapper.cpp | 2 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/settings.cpp | 4 | ||||
-rw-r--r-- | kmicromail/mainwindow.cpp | 7 | ||||
-rw-r--r-- | kmicromail/mainwindow.h | 1 | ||||
-rw-r--r-- | kmicromail/opiemail.cpp | 10 | ||||
-rw-r--r-- | kmicromail/opiemail.h | 1 |
8 files changed, 28 insertions, 15 deletions
diff --git a/kmicromail/accountitem.cpp b/kmicromail/accountitem.cpp index 7b9b881..59c8abb 100644 --- a/kmicromail/accountitem.cpp +++ b/kmicromail/accountitem.cpp @@ -1,236 +1,238 @@ #include "accountitem.h" #include "accountview.h" #include "newmaildir.h" #include "nntpgroupsdlg.h" #include "defines.h" #include <libmailwrapper/mailtypes.h> #include <libmailwrapper/abstractmail.h> #include <libmailwrapper/mailwrapper.h> /* OPIE */ //#include <qpe/qpeapplication.h> /* QT */ #include <qpopupmenu.h> #include <qmessagebox.h> #include <kiconloader.h> +#define GET_NEW_MAILS 101 + using namespace Opie::Core; #define SETPIX(x) if (!account->getOffline()) {setPixmap( 0,x);} else {setPixmap( 0, PIXMAP_OFFLINE );} /** * POP3 Account stuff */ POP3viewItem::POP3viewItem( POP3account *a, AccountView *parent ) : AccountViewItem( parent ) { account = a; wrapper = AbstractMail::getWrapper( account ); SETPIX(PIXMAP_POP3FOLDER); #if 0 if (!account->getOffline()) { setPixmap( 0, ); } else { setPixmap( 0, PIXMAP_OFFLINE ); } #endif setText( 0, account->getAccountName() ); setOpen( true ); } POP3viewItem::~POP3viewItem() { delete wrapper; } AbstractMail *POP3viewItem::getWrapper() { return wrapper; } void POP3viewItem::refresh(QValueList<Opie::Core::OSmartPointer<RecMail> > & ) { refresh(); } void POP3viewItem::refresh() { if (account->getOffline()) return; QValueList<FolderP> *folders = wrapper->listFolders(); QListViewItem *child = firstChild(); while ( child ) { QListViewItem *tmp = child; child = child->nextSibling(); delete tmp; } QValueList<FolderP>::ConstIterator it; QListViewItem*item = 0; for ( it = folders->begin(); it!=folders->end(); ++it) { item = new POP3folderItem( (*it), this , item ); item->setSelectable( (*it)->may_select()); } delete folders; } RECBODYP POP3viewItem::fetchBody( const RecMailP &mail ) { return wrapper->fetchBody( mail ); } QPopupMenu * POP3viewItem::getContextMenu() { QPopupMenu *m = new QPopupMenu(0); if (m) { if (!account->getOffline()) { m->insertItem(QObject::tr("Disconnect",contextName),0); m->insertItem(QObject::tr("Set offline",contextName),1); - m->insertItem(QObject::tr("Download new INBOX messages",contextName),2); + m->insertItem(QObject::tr("Get new messages",contextName),GET_NEW_MAILS); } else { m->insertItem(QObject::tr("Set online",contextName),1); - m->insertItem(QObject::tr("Download new INBOX messages",contextName),2); + m->insertItem(QObject::tr("Get new messages",contextName),GET_NEW_MAILS); } } return m; } void POP3viewItem::disconnect() { QListViewItem *child = firstChild(); while ( child ) { QListViewItem *tmp = child; child = child->nextSibling(); delete tmp; } wrapper->logout(); } void POP3viewItem::setOnOffline() { if (!account->getOffline()) { disconnect(); } account->setOffline(!account->getOffline()); account->save(); SETPIX(PIXMAP_POP3FOLDER); refresh(); } void POP3viewItem::contextMenuSelected(int which) { switch (which) { case 0: disconnect(); break; case 1: setOnOffline(); break; - case 2: // daunlood + case GET_NEW_MAILS: // daunlood if (account->getOffline()) setOnOffline(); AccountView*bl = accountView(); if (!bl) return; AccountViewItem* in = findSubItem( "inbox" , 0); if ( ! in ) return; bl->downloadMailsInbox(in->getFolder() ,getWrapper()); setOnOffline(); break; } } POP3folderItem::~POP3folderItem() {} POP3folderItem::POP3folderItem( const FolderP&folderInit, POP3viewItem *parent , QListViewItem*after ) : AccountViewItem(folderInit,parent,after ) { pop3 = parent; if (folder->getDisplayName().lower()!="inbox") { setPixmap( 0, PIXMAP_POP3FOLDER ); } else { setPixmap( 0, PIXMAP_INBOXFOLDER); } setText( 0, folder->getDisplayName() ); } void POP3folderItem::refresh(QValueList<RecMailP>&target) { if (folder->may_select()) pop3->getWrapper()->listMessages( folder->getName(),target ); } RECBODYP POP3folderItem::fetchBody(const RecMailP&aMail) { return pop3->getWrapper()->fetchBody(aMail); } QPopupMenu * POP3folderItem::getContextMenu() { QPopupMenu *m = new QPopupMenu(0); if (m) { m->insertItem(QObject::tr("Refresh header list",contextName),0); m->insertItem(QObject::tr("Delete all mails",contextName),1); m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); } return m; } void POP3folderItem::downloadMails() { AccountView*bl = pop3->accountView(); if (!bl) return; bl->downloadMails(folder,pop3->getWrapper()); } void POP3folderItem::contextMenuSelected(int which) { AccountView * view = (AccountView*)listView(); switch (which) { case 0: /* must be 'cause pop3 lists are cached */ pop3->getWrapper()->logout(); view->refreshCurrent(); break; case 1: deleteAllMail(pop3->getWrapper(),folder); break; case 2: downloadMails(); break; default: break; } } /** * NNTP Account stuff */ NNTPviewItem::NNTPviewItem( NNTPaccount *a, AccountView *parent ) : AccountViewItem( parent ) { account = a; wrapper = AbstractMail::getWrapper( account ); //FIXME SETPIX(PIXMAP_POP3FOLDER); #if 0 if (!account->getOffline()) { setPixmap( 0, ); @@ -424,253 +426,253 @@ void NNTPfolderItem::contextMenuSelected(int which) /** * IMAP Account stuff */ IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent ) : AccountViewItem( parent ) { account = a; wrapper = AbstractMail::getWrapper( account ); SETPIX(PIXMAP_IMAPFOLDER); setText( 0, account->getAccountName() ); setOpen( true ); } IMAPviewItem::~IMAPviewItem() { delete wrapper; } AbstractMail *IMAPviewItem::getWrapper() { return wrapper; } void IMAPviewItem::refresh(QValueList<RecMailP>&) { refreshFolders(false); } const QStringList&IMAPviewItem::subFolders() { return currentFolders; } void IMAPviewItem::refreshFolders(bool force) { if (childCount()>0 && force==false) return; if (account->getOffline()) return; removeChilds(); currentFolders.clear(); QValueList<FolderP> * folders = wrapper->listFolders(); QValueList<FolderP>::Iterator it; QListViewItem*item = 0; QListViewItem*titem = 0; QString fname,del,search; int pos; for ( it = folders->begin(); it!=folders->end(); ++it) { if ((*it)->getDisplayName().lower()=="inbox") { item = new IMAPfolderItem( (*it), this , item ); folders->remove(it); break; } } for ( it = folders->begin(); it!=folders->end(); ++it) { fname = (*it)->getDisplayName(); currentFolders.append((*it)->getName()); pos = fname.findRev((*it)->Separator()); if (pos != -1) { fname = fname.left(pos); } IMAPfolderItem*pitem = (IMAPfolderItem*)findSubItem(fname); if (pitem) { titem = item; item = new IMAPfolderItem( (*it),pitem,pitem->firstChild(),this); /* setup the short name */ item->setText(0,(*it)->getDisplayName().right((*it)->getDisplayName().length()-pos-1)); item = titem; } else { item = new IMAPfolderItem( (*it), this , item ); } } delete folders; } QPopupMenu * IMAPviewItem::getContextMenu() { QPopupMenu *m = new QPopupMenu(0); if (m) { if (!account->getOffline()) { m->insertItem(QObject::tr("Refresh folder list",contextName),0); m->insertItem(QObject::tr("Create new folder",contextName),1); m->insertSeparator(); m->insertItem(QObject::tr("Disconnect",contextName),2); m->insertItem(QObject::tr("Set offline",contextName),3); m->insertSeparator(); - m->insertItem(QObject::tr("Download new INBOX messages",contextName),4); + m->insertItem(QObject::tr("Get new messages",contextName),GET_NEW_MAILS); } else { m->insertItem(QObject::tr("Set online",contextName),3); m->insertSeparator(); - m->insertItem(QObject::tr("Download new INBOX messages",contextName),4); + m->insertItem(QObject::tr("Get new messages",contextName),GET_NEW_MAILS); } } return m; } void IMAPviewItem::createNewFolder() { Newmdirdlg ndirdlg; ndirdlg.showMaximized(); if ( ndirdlg.exec() ) { QString ndir = ndirdlg.Newdir(); bool makesubs = ndirdlg.subpossible(); QString delemiter = "/"; IMAPfolderItem*item = (IMAPfolderItem*)firstChild(); if (item) { delemiter = item->Delemiter(); } if (wrapper->createMbox(ndir,0,delemiter,makesubs)) { refreshFolders(true); } } } void IMAPviewItem::contextMenuSelected(int id) { switch (id) { case 0: refreshFolders(true); break; case 1: createNewFolder(); break; case 2: removeChilds(); wrapper->logout(); break; case 3: if (account->getOffline()==false) { removeChilds(); wrapper->logout(); } account->setOffline(!account->getOffline()); account->save(); SETPIX(PIXMAP_IMAPFOLDER); refreshFolders(false); break; - case 4: // daunlood + case GET_NEW_MAILS: // daunlood { if (account->getOffline()) { contextMenuSelected( 3 ); } AccountView*bl = accountView(); if (!bl) return; AccountViewItem* in = findSubItem( "inbox" , 0); if ( ! in ) return; bl->downloadMailsInbox(in->getFolder(),getWrapper()); } break; default: break; } } RECBODYP IMAPviewItem::fetchBody(const RecMailP&) { return new RecBody(); } bool IMAPviewItem::offline() { return account->getOffline(); } IMAPfolderItem::IMAPfolderItem( const FolderP& folderInit, IMAPviewItem *parent , QListViewItem*after ) : AccountViewItem( folderInit, parent , after ) { imap = parent; if (folder->getDisplayName().lower()!="inbox") { setPixmap( 0, PIXMAP_IMAPFOLDER ); } else { setPixmap( 0, PIXMAP_INBOXFOLDER); } setText( 0, folder->getDisplayName() ); } IMAPfolderItem::IMAPfolderItem(const FolderP &folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ) : AccountViewItem(folderInit, parent,after ) { imap = master; if (folder->getDisplayName().lower()!="inbox") { setPixmap( 0, PIXMAP_IMAPFOLDER ); } else { setPixmap( 0, PIXMAP_INBOXFOLDER); } setText( 0, folder->getDisplayName() ); } IMAPfolderItem::~IMAPfolderItem() {} const QString& IMAPfolderItem::Delemiter()const { return folder->Separator(); } void IMAPfolderItem::refresh(QValueList<RecMailP>&target) { if (folder->may_select()) { imap->getWrapper()->listMessages( folder->getName(),target ); } else { target.clear(); } } RECBODYP IMAPfolderItem::fetchBody(const RecMailP&aMail) { return imap->getWrapper()->fetchBody(aMail); } QPopupMenu * IMAPfolderItem::getContextMenu() { QPopupMenu *m = new QPopupMenu(0); if (m) { if (folder->may_select()) { m->insertItem(QObject::tr("Refresh header list",contextName),0); m->insertItem(QObject::tr("Move/Copie all mails",contextName),4); m->insertItem(QObject::tr("Delete all mails",contextName),1); } if (folder->no_inferior()==false) { m->insertItem(QObject::tr("Create new subfolder",contextName),2); diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index 5441a9b..91332c3 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp @@ -78,193 +78,193 @@ bool IMAPwrapper::start_tls(bool force_tls) err = mailimap_capability(m_imap,&cap_data); if (err != MAILIMAP_NO_ERROR) { Global::statusMessage("error getting capabilities!"); return false; } clistiter * cur; for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { struct mailimap_capability * cap; cap = (struct mailimap_capability *)clist_content(cur); if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { try_tls = true; break; } } } if (cap_data) { mailimap_capability_data_free(cap_data); } if (try_tls) { err = mailimap_starttls(m_imap); if (err != MAILIMAP_NO_ERROR && force_tls) { Global::statusMessage(tr("Server has no TLS support!")); try_tls = false; } else { mailstream_low * low; mailstream_low * new_low; low = mailstream_get_low(m_imap->imap_stream); if (!low) { try_tls = false; } else { int fd = mailstream_low_get_fd(low); if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { mailstream_low_free(low); mailstream_set_low(m_imap->imap_stream, new_low); } else { try_tls = false; } } } } return try_tls; } void IMAPwrapper::login() { QString server, user, pass; uint16_t port; int err = MAILIMAP_NO_ERROR; if (account->getOffline()) return; /* we are connected this moment */ /* TODO: setup a timer holding the line or if connection closed - delete the value */ if (m_imap) { err = mailimap_noop(m_imap); if (err!=MAILIMAP_NO_ERROR) { logout(); } else { mailstream_flush(m_imap->imap_stream); return; } } server = account->getServer(); port = account->getPort().toUInt(); if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); login.show(); if ( QDialog::Accepted == login.exec() ) { // ok user = login.getUser(); pass = login.getPassword(); } else { // cancel return; } } else { user = account->getUser(); pass = account->getPassword(); } m_imap = mailimap_new( 20, &imap_progress ); /* connect */ bool ssl = false; bool try_tls = false; bool force_tls = false; if ( account->ConnectionType() == 2 ) { ssl = true; } if (account->ConnectionType()==1) { force_tls = true; } if ( ssl ) { - qDebug("using ssl "); + //qDebug("using ssl "); err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); } else { err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); } if ( err != MAILIMAP_NO_ERROR && err != MAILIMAP_NO_ERROR_AUTHENTICATED && err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { QString failure = ""; if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { failure="Connection refused"; } else { failure="Unknown failure"; } Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); mailimap_free( m_imap ); m_imap = 0; return; } if (!ssl) { try_tls = start_tls(force_tls); } bool ok = true; if (force_tls && !try_tls) { Global::statusMessage(tr("Server has no TLS support!")); ok = false; } /* login */ if (ok) { err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); if ( err != MAILIMAP_NO_ERROR ) { Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); ok = false; } } if (!ok) { err = mailimap_close( m_imap ); mailimap_free( m_imap ); m_imap = 0; } } void IMAPwrapper::logout() { int err = MAILIMAP_NO_ERROR; if (!m_imap) return; err = mailimap_logout( m_imap ); err = mailimap_close( m_imap ); mailimap_free( m_imap ); m_imap = 0; m_Lastmbox = ""; } void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) { int err = MAILIMAP_NO_ERROR; clist *result = 0; clistcell *current; mailimap_fetch_type *fetchType = 0; mailimap_set *set = 0; login(); if (!m_imap) { return; } /* select mailbox READONLY for operations */ err = selectMbox(mailbox); if ( err != MAILIMAP_NO_ERROR ) { return; } int last = m_imap->imap_selection_info->sel_exists; if (last == 0) { Global::statusMessage(tr("Mailbox has no mails")); return; } else { } Global::statusMessage(tr("Fetching header list")); qApp->processEvents(); /* the range has to start at 1!!! not with 0!!!! */ set = mailimap_set_new_interval( 1, last ); fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); err = mailimap_fetch( m_imap, set, fetchType, &result ); mailimap_set_free( set ); @@ -1154,154 +1154,154 @@ int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,cons } return 1; } int IMAPwrapper::deleteMbox(const FolderP&folder) { if (!folder) return 0; login(); if (!m_imap) {return 0;} int res = mailimap_delete(m_imap,folder->getName()); if (res != MAILIMAP_NO_ERROR) { Global::statusMessage(tr("%1").arg(m_imap->imap_response)); return 0; } return 1; } void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) { mailimap_status_att_list * att_list =0; mailimap_mailbox_data_status * status=0; clistiter * cur = 0; int r = 0; target_stat.message_count = 0; target_stat.message_unseen = 0; target_stat.message_recent = 0; login(); if (!m_imap) { return; } att_list = mailimap_status_att_list_new_empty(); if (!att_list) return; r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { for (cur = clist_begin(status->st_info_list); cur != NULL ; cur = clist_next(cur)) { mailimap_status_info * status_info; status_info = (mailimap_status_info *)clist_content(cur); switch (status_info->st_att) { case MAILIMAP_STATUS_ATT_MESSAGES: target_stat.message_count = status_info->st_value; break; case MAILIMAP_STATUS_ATT_RECENT: target_stat.message_recent = status_info->st_value; break; case MAILIMAP_STATUS_ATT_UNSEEN: target_stat.message_unseen = status_info->st_value; break; } } } else { // odebug << "Error retrieving status" << oendl; } if (status) mailimap_mailbox_data_status_free(status); if (att_list) mailimap_status_att_list_free(att_list); } void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) { login(); if (!m_imap) return; if (!msg) return; int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); if (r != MAILIMAP_NO_ERROR) { Global::statusMessage("Error storing mail!"); } } MAILLIB::ATYPE IMAPwrapper::getType()const { return account->getType(); } const QString&IMAPwrapper::getName()const { // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; return account->getAccountName(); } encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) { // dummy QValueList<int> path; return fetchRawPart(mail,path,false); } void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) { if (targetWrapper != this || maxSizeInKb > 0 ) { mMax = 0; progress( tr("Copy")); AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); - qDebug("IMAPwrapper::mvcpAllMails::Using generic"); + //qDebug("IMAPwrapper::mvcpAllMails::Using generic"); // odebug << "Using generic" << oendl; return; } mailimap_set *set = 0; login(); if (!m_imap) { return; } int err = selectMbox(fromFolder->getName()); if ( err != MAILIMAP_NO_ERROR ) { return; } Global::statusMessage( tr("Copying mails on server...") ); int last = m_imap->imap_selection_info->sel_exists; set = mailimap_set_new_interval( 1, last ); err = mailimap_copy(m_imap,set,targetFolder.latin1()); mailimap_set_free( set ); if ( err != MAILIMAP_NO_ERROR ) { QString error_msg = tr("Error copy mails: %1").arg(m_imap->imap_response); Global::statusMessage(error_msg); // odebug << error_msg << oendl; return; } if (moveit) { deleteAllMail(fromFolder); } } void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) { if (targetWrapper != this) { // odebug << "Using generic" << oendl; AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); return; } mailimap_set *set = 0; login(); if (!m_imap) { return; } int err = selectMbox(mail->getMbox()); if ( err != MAILIMAP_NO_ERROR ) { return; } set = mailimap_set_new_single(mail->getNumber()); err = mailimap_copy(m_imap,set,targetFolder.latin1()); mailimap_set_free( set ); if ( err != MAILIMAP_NO_ERROR ) { QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); Global::statusMessage(error_msg); // odebug << error_msg << oendl; return; } if (moveit) { deleteMail(mail); } } diff --git a/kmicromail/libmailwrapper/mhwrapper.cpp b/kmicromail/libmailwrapper/mhwrapper.cpp index 962dac0..641d4d9 100644 --- a/kmicromail/libmailwrapper/mhwrapper.cpp +++ b/kmicromail/libmailwrapper/mhwrapper.cpp @@ -1,293 +1,291 @@ // CHANGED 2004-09-31 Lutz Rogowski #include "mhwrapper.h" #include "mailtypes.h" #include "mailwrapper.h" #include <libetpan/libetpan.h> #include <qdir.h> #include <qmessagebox.h> #include <stdlib.h> #include <qpe/global.h> #include <oprocess.h> //#include <opie2/odebug.h> using namespace Opie::Core; MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) { if (MHPath.length()>0) { if (MHPath[MHPath.length()-1]=='/') { MHPath=MHPath.left(MHPath.length()-1); } //odebug << MHPath << oendl; QDir dir(MHPath); if (!dir.exists()) { dir.mkdir(MHPath); } init_storage(); } } void MHwrapper::init_storage() { int r; QString pre = MHPath; if (!m_storage) { m_storage = mailstorage_new(NULL); r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); if (r != MAIL_NO_ERROR) { qDebug(" error init storage "); mailstorage_free(m_storage); m_storage = 0; return; } } r = mailstorage_connect(m_storage); if (r!=MAIL_NO_ERROR) { qDebug("error connecting storage "); mailstorage_free(m_storage); m_storage = 0; } } void MHwrapper::clean_storage() { if (m_storage) { mailstorage_disconnect(m_storage); mailstorage_free(m_storage); m_storage = 0; } } MHwrapper::~MHwrapper() { clean_storage(); } void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) { - qDebug("MHwrapper::listMessages "); init_storage(); if (!m_storage) { return; } QString f = buildPath(mailbox); int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); if (r!=MAIL_NO_ERROR) { qDebug("listMessages: error selecting folder! "); return; } parseList(target,m_storage->sto_session,f, false, maxSizeInKb ); Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); } QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() { QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); /* this is needed! */ if (m_storage) mailstorage_disconnect(m_storage); init_storage(); if (!m_storage) { return folders; } mail_list*flist = 0; clistcell*current=0; int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); if (r != MAIL_NO_ERROR || !flist) { qDebug("error getting folder list "); return folders; } for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { QString t = (char*)current->data; t.replace(0,MHPath.length(),""); folders->append(new MHFolder(t,MHPath)); } mail_list_free(flist); return folders; } void MHwrapper::deleteMail(const RecMailP&mail) { init_storage(); if (!m_storage) { return; } int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); if (r!=MAIL_NO_ERROR) { qDebug("error selecting folder! "); return; } r = mailsession_remove_message(m_storage->sto_session,mail->getNumber()); if (r != MAIL_NO_ERROR) { qDebug("error deleting mail "); } } void MHwrapper::answeredMail(const RecMailP&) { } RecBodyP MHwrapper::fetchBody( const RecMailP &mail ) { RecBodyP body = new RecBody(); init_storage(); if (!m_storage) { return body; } mailmessage * msg; char*data=0; /* mail should hold the complete path! */ int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); if (r != MAIL_NO_ERROR) { return body; } r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); if (r != MAIL_NO_ERROR) { qDebug("Error fetching mail "); return body; } body = parseMail(msg); mailmessage_fetch_result_free(msg,data); return body; } void MHwrapper::mbox_progress( size_t current, size_t maximum ) { qDebug("MBox Progress %d of %d",current,maximum ); //odebug << "MH " << current << " von " << maximum << "" << oendl; } QString MHwrapper::buildPath(const QString&p) { QString f=""; if (p.length()==0||p=="/") return MHPath; if (!p.startsWith(MHPath)) { f+=MHPath; } if (!p.startsWith("/")) { f+="/"; } f+=p; return f; } int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool ) { init_storage(); if (!m_storage) { return 0; } QString f; if (!pfolder) { // toplevel folder f = buildPath(folder); } else { f = pfolder->getName(); f+="/"; f+=folder; } int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); if (r != MAIL_NO_ERROR) { qDebug("error creating folder "); return 0; } - qDebug("Folder created "); return 1; } void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) { init_storage(); if (!m_storage) { return; } QString f = buildPath(Folder); int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); if (r!=MAIL_NO_ERROR) { qDebug("error selecting folder! "); return; } r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); if (r!=MAIL_NO_ERROR) { qDebug("error storing mail "); } return; } encodedString* MHwrapper::fetchRawBody(const RecMailP&mail) { encodedString*result = 0; init_storage(); if (!m_storage) { return result; } mailmessage * msg = 0; char*data=0; size_t size; int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); if (r!=MAIL_NO_ERROR) { qDebug("error selecting folder! "); return result; } r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); if (r != MAIL_NO_ERROR) { Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); return 0; } r = mailmessage_fetch(msg,&data,&size); if (r != MAIL_NO_ERROR) { Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); if (msg) mailmessage_free(msg); return 0; } result = new encodedString(data,size); if (msg) mailmessage_free(msg); return result; } void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) { QString f = buildPath(mailbox); int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); if (r!=MAIL_NO_ERROR) { qDebug("deleteMails: error selecting folder! "); return; } QValueList<RecMailP>::ConstIterator it; for (it=target.begin(); it!=target.end();++it) { r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber()); if (r != MAIL_NO_ERROR) { qDebug("error deleting mail "); break; } } } int MHwrapper::deleteAllMail(const FolderP&tfolder) { init_storage(); if (!m_storage) { return 0; } int res = 1; if (!tfolder) return 0; int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); if (r!=MAIL_NO_ERROR) { qDebug("error selecting folder! "); return 0; } mailmessage_list*l=0; r = mailsession_get_messages_list(m_storage->sto_session,&l); if (r != MAIL_NO_ERROR) { qDebug("Error message list "); res = 0; } unsigned j = 0; for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { mailmessage * msg; msg = (mailmessage*)carray_get(l->msg_tab, i); j = msg->msg_index; r = mailsession_remove_message(m_storage->sto_session,j); diff --git a/kmicromail/libmailwrapper/settings.cpp b/kmicromail/libmailwrapper/settings.cpp index 766eba0..40b5591 100644 --- a/kmicromail/libmailwrapper/settings.cpp +++ b/kmicromail/libmailwrapper/settings.cpp @@ -1,317 +1,315 @@ #include <stdlib.h> #include <qdir.h> //#include <opie2/odebug.h> #include <kconfig.h> #include <kstandarddirs.h> #include "settings.h" //#include "defines.h" #define IMAP_PORT "143" #define IMAP_SSL_PORT "993" #define SMTP_PORT "25" #define SMTP_SSL_PORT "465" #define POP3_PORT "110" #define POP3_SSL_PORT "995" #define NNTP_PORT "119" #define NNTP_SSL_PORT "563" Settings::Settings() : QObject() { updateAccounts(); } void Settings::checkDirectory() { - qDebug("Settings::checkDirectory() "); return; locateLocal("data", "kopiemail" ); /* if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { system( "mkdir -p $HOME/Applications/opiemail" ); qDebug("$HOME/Applications/opiemail created "); } */ } QList<Account> Settings::getAccounts() { return accounts; } void Settings::addAccount( Account *account ) { accounts.append( account ); } void Settings::delAccount( Account *account ) { accounts.remove( account ); account->remove(); } void Settings::updateAccounts() { accounts.clear(); QDir dir( locateLocal("data", "kopiemail" ) ); QStringList::Iterator it; QStringList imap = dir.entryList( "imap-*" ); for ( it = imap.begin(); it != imap.end(); it++ ) { IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); accounts.append( account ); } QStringList pop3 = dir.entryList( "pop3-*" ); for ( it = pop3.begin(); it != pop3.end(); it++ ) { POP3account *account = new POP3account( (*it).replace(0, 5, "") ); accounts.append( account ); } QStringList smtp = dir.entryList( "smtp-*" ); for ( it = smtp.begin(); it != smtp.end(); it++ ) { SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); accounts.append( account ); } QStringList nntp = dir.entryList( "nntp-*" ); for ( it = nntp.begin(); it != nntp.end(); it++ ) { NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); accounts.append( account ); } readAccounts(); } void Settings::saveAccounts() { checkDirectory(); Account *it; for ( it = accounts.first(); it; it = accounts.next() ) { it->save(); } } void Settings::readAccounts() { checkDirectory(); Account *it; for ( it = accounts.first(); it; it = accounts.next() ) { it->read(); } } Account::Account() { accountName = "changeMe"; type = MAILLIB::A_UNDEFINED; ssl = false; connectionType = 1; offline = false; maxMailSize = 0; lastFetch; leaveOnServer = false; } void Account::remove() { QFile file( getFileName() ); file.remove(); } void Account::setPasswordList(const QStringList &str) { password = ""; int i; for ( i = 0; i < str.count() ; ++i ) { QChar c ( (str[i].toUInt()-131)/(str.count()- (i%3))); password.append( c ); } //qDebug("password %s ", password.latin1()); } QStringList Account::getPasswordList() { int i; int len = password.length(); QStringList str; for ( i = 0; i < len ; ++i ) { int val = password.at(i).unicode()*(len-(i%3))+131; str.append( QString::number( val ) ); // qDebug("append %s ", str[i].latin1()); } return str; } IMAPaccount::IMAPaccount() : Account() { file = IMAPaccount::getUniqueFileName(); accountName = "New IMAP Account"; ssl = false; connectionType = 1; type = MAILLIB::A_IMAP; port = IMAP_PORT; } IMAPaccount::IMAPaccount( QString filename ) : Account() { file = filename; accountName = "New IMAP Account"; ssl = false; connectionType = 1; type = MAILLIB::A_IMAP; port = IMAP_PORT; } QString IMAPaccount::getUniqueFileName() { int num = 0; QString unique; QDir dir( locateLocal("data", "kopiemail" ) ); QStringList imap = dir.entryList( "imap-*" ); do { unique.setNum( num++ ); } while ( imap.contains( "imap-" + unique ) > 0 ); return unique; } void IMAPaccount::read() { KConfig *conf = new KConfig( getFileName() ); conf->setGroup( "IMAP Account" ); accountName = conf->readEntry( "Account","" ); if (accountName.isNull()) accountName = ""; server = conf->readEntry( "Server","" ); if (server.isNull()) server=""; port = conf->readEntry( "Port","" ); if (port.isNull()) port="143"; connectionType = conf->readNumEntry( "ConnectionType" ); ssl = conf->readBoolEntry( "SSL",false ); user = conf->readEntry( "User","" ); if (user.isNull()) user = ""; //password = conf->readEntryCrypt( "Password","" ); setPasswordList( conf->readListEntry( "FolderHistory")); if (password.isNull()) password = ""; prefix = conf->readEntry("MailPrefix",""); if (prefix.isNull()) prefix = ""; offline = conf->readBoolEntry("Offline",false); localFolder = conf->readEntry( "LocalFolder" ); maxMailSize = conf->readNumEntry( "MaxSize",0 ); int lf = conf->readNumEntry( "LastFetch",0 ); QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); leaveOnServer = conf->readBoolEntry("LeaveOnServer",false); - qDebug("reading last fetch: %d ", lf); if ( lf < 0 ) lf = 0; lastFetch = dt.addSecs( lf ); delete conf; } void IMAPaccount::save() { - qDebug("saving %s ",getFileName().latin1() ); + Settings::checkDirectory(); KConfig *conf = new KConfig( getFileName() ); conf->setGroup( "IMAP Account" ); conf->writeEntry( "Account", accountName ); conf->writeEntry( "Server", server ); conf->writeEntry( "Port", port ); conf->writeEntry( "SSL", ssl ); conf->writeEntry( "ConnectionType", connectionType ); conf->writeEntry( "User", user ); //conf->writeEntryCrypt( "Password", password ); conf->writeEntry( "FolderHistory",getPasswordList() ); conf->writeEntry( "MailPrefix",prefix); conf->writeEntry( "Offline",offline); conf->writeEntry( "LocalFolder", localFolder ); conf->writeEntry( "MaxSize", maxMailSize ); QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); int lf = dt.secsTo ( lastFetch ); conf->writeEntry( "LastFetch", lf ); conf->writeEntry( "LeaveOnServer", leaveOnServer); conf->sync(); delete conf; } QString IMAPaccount::getFileName() { return locateLocal("data", "kopiemail" ) +"/imap-" + file; } POP3account::POP3account() : Account() { file = POP3account::getUniqueFileName(); accountName = "New POP3 Account"; ssl = false; connectionType = 1; type = MAILLIB::A_POP3; port = POP3_PORT; } POP3account::POP3account( QString filename ) : Account() { file = filename; accountName = "New POP3 Account"; ssl = false; connectionType = 1; type = MAILLIB::A_POP3; port = POP3_PORT; } QString POP3account::getUniqueFileName() { int num = 0; QString unique; QDir dir( locateLocal("data", "kopiemail" ) ); QStringList imap = dir.entryList( "pop3-*" ); do { unique.setNum( num++ ); } while ( imap.contains( "pop3-" + unique ) > 0 ); return unique; } void POP3account::read() { KConfig *conf = new KConfig( getFileName()); conf->setGroup( "POP3 Account" ); accountName = conf->readEntry( "Account" ); server = conf->readEntry( "Server" ); port = conf->readEntry( "Port" ); ssl = conf->readBoolEntry( "SSL" ); connectionType = conf->readNumEntry( "ConnectionType" ); user = conf->readEntry( "User" ); //password = conf->readEntryCrypt( "Password" ); setPasswordList( conf->readListEntry( "FolderHistory")); offline = conf->readBoolEntry("Offline",false); localFolder = conf->readEntry( "LocalFolder" ); maxMailSize = conf->readNumEntry( "MaxSize",0 ); int lf = conf->readNumEntry( "LastFetch",0 ); QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); leaveOnServer = conf->readBoolEntry("LeaveOnServer",false); lastFetch = dt.addSecs( lf ); delete conf; } void POP3account::save() { Settings::checkDirectory(); KConfig *conf = new KConfig( getFileName() ); conf->setGroup( "POP3 Account" ); conf->writeEntry( "Account", accountName ); diff --git a/kmicromail/mainwindow.cpp b/kmicromail/mainwindow.cpp index 21edfd2..5f777a3 100644 --- a/kmicromail/mainwindow.cpp +++ b/kmicromail/mainwindow.cpp @@ -1,134 +1,139 @@ // CHANGED 2004-08-06 Lutz Rogowski #include <qlabel.h> #include <qvbox.h> #include <qheader.h> #include <qtimer.h> #include <qlayout.h> #include <kdialog.h> #include <kiconloader.h> #include <kapplication.h> #ifndef DESKTOP_VERSION #include <qpe/qpeapplication.h> #endif #include "defines.h" #include "mainwindow.h" #include <KDGanttMinimizeSplitter.h> #include <kabc/stdaddressbook.h> MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags ) : QMainWindow( parent, name ) //, flags ) { setCaption( tr( "KOpieMail/Pi" ) ); setToolBarsMovable( false ); //KABC::StdAddressBook::self(); toolBar = new QToolBar( this ); menuBar = new QPEMenuBar( toolBar ); mailMenu = new QPopupMenu( menuBar ); menuBar->insertItem( tr( "Mail" ), mailMenu ); settingsMenu = new QPopupMenu( menuBar ); menuBar->insertItem( tr( "Settings" ), settingsMenu ); addToolBar( toolBar ); toolBar->setHorizontalStretchable( true ); - + QAction* getMail = new QAction( tr( "Get new mail" ), SmallIcon("add"), + 0, 0, this ); + getMail->addTo( toolBar ); + getMail->addTo( mailMenu ); + connect(getMail, SIGNAL( activated() ), + SLOT( slotGetMail() ) ); composeMail = new QAction( tr( "Compose new mail" ), SmallIcon("composemail"), 0, 0, this ); composeMail->addTo( toolBar ); composeMail->addTo( mailMenu ); sendQueued = new QAction( tr( "Send queued mails" ), SmallIcon("sendqueued") , 0, 0, this ); sendQueued->addTo( toolBar ); sendQueued->addTo( mailMenu ); /* syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC, 0, 0, this ); syncFolders->addTo( toolBar ); syncFolders->addTo( mailMenu ); */ showFolders = new QAction( tr( "Show/Hide folders" ), SmallIcon("showfolders") , 0, 0, this, 0, true ); showFolders->addTo( toolBar ); showFolders->addTo( mailMenu ); showFolders->setOn( true ); connect(showFolders, SIGNAL( toggled(bool) ), SLOT( slotShowFolders(bool) ) ); /* searchMails = new QAction( tr( "Search mails" ), SmallIcon("find") ), 0, 0, this ); searchMails->addTo( toolBar ); searchMails->addTo( mailMenu ); */ deleteMails = new QAction(tr("Delete Mail"), SmallIcon("trash"), 0, 0, this); deleteMails->addTo( toolBar ); deleteMails->addTo( mailMenu ); connect( deleteMails, SIGNAL( activated() ), SLOT( slotDeleteMail() ) ); editSettings = new QAction( tr( "Edit settings" ), SmallIcon("SettingsIcon") , 0, 0, this ); editSettings->addTo( settingsMenu ); connect( editSettings, SIGNAL( activated() ), SLOT( slotEditSettings() ) ); editAccounts = new QAction( tr( "Configure accounts" ), SmallIcon("editaccounts") , 0, 0, this ); editAccounts->addTo( settingsMenu ); //setCentralWidget( view ); QVBox* wrapperBox = new QVBox( this ); setCentralWidget( wrapperBox ); // QWidget *view = new QWidget( wrapperBox ); KDGanttMinimizeSplitter* split = new KDGanttMinimizeSplitter( Qt::Horizontal, wrapperBox); split->setMinimizeDirection( KDGanttMinimizeSplitter::Left); //layout = new QBoxLayout ( split, QBoxLayout::LeftToRight ); folderView = new AccountView( split ); folderView->header()->hide(); folderView->setRootIsDecorated( false ); folderView->addColumn( tr( "Mailbox" ) ); //layout->addWidget( folderView ); mailView = new QListView( split ); mailView->addColumn( tr( " " ) ); mailView->addColumn( tr( "Subject" ),QListView::Manual ); mailView->addColumn( tr( "Sender" ),QListView::Manual ); mailView->addColumn( tr( "Size" ),QListView::Manual); mailView->addColumn( tr( "Date" ),QListView::Manual); mailView->setAllColumnsShowFocus(true); //mailView->setSorting(-1); mailView->setRootIsDecorated( false ); statusWidget = new StatusWidget( wrapperBox ); statusWidget->hide(); //layout->addWidget( mailView ); //layout->setStretchFactor( folderView, 1 ); //layout->setStretchFactor( mailView, 2 ); slotAdjustLayout(); #ifndef DESKTOP_VERSION QPEApplication::setStylusOperation( mailView->viewport(),QPEApplication::RightOnHold); QPEApplication::setStylusOperation( folderView->viewport(),QPEApplication::RightOnHold); #endif connect( mailView, SIGNAL( doubleClicked (QListViewItem* )),this, SLOT( mailLeftClicked(QListViewItem*) ) ); connect( mailView, SIGNAL( returnPressed (QListViewItem* )),this, SLOT( mailLeftClicked(QListViewItem*) ) ); connect( mailView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),this, SLOT( mailHold(int,QListViewItem*,const QPoint&,int) ) ); connect(folderView, SIGNAL(refreshMailview(const QValueList<RecMailP>&)), this,SLOT(refreshMailView(const QValueList<RecMailP>&))); connect( composeMail, SIGNAL( activated() ), SLOT( slotComposeMail() ) ); connect( sendQueued, SIGNAL( activated() ), SLOT( slotSendQueued() ) ); diff --git a/kmicromail/mainwindow.h b/kmicromail/mainwindow.h index 680f0a9..ff0ff20 100644 --- a/kmicromail/mainwindow.h +++ b/kmicromail/mainwindow.h @@ -1,65 +1,66 @@ // CHANGED 2004-08-06 Lutz Rogowski #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <qmainwindow.h> #include <qlistview.h> #include <qaction.h> #include <qtoolbar.h> #ifdef DESKTOP_VERSION #include <qmenubar.h> #else #include <qpe/qpemenubar.h> #endif #include "accountview.h" #include "statuswidget.h" #include <libmailwrapper/mailtypes.h> #include <opie2/osmartpointer.h> class RecMail; class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); virtual ~MainWindow(); public slots: virtual void slotAdjustColumns(); virtual void appMessage(const QCString &msg, const QByteArray &data); virtual void slotComposeMail(); protected slots: virtual void slotSendQueued(); virtual void slotEditAccounts(); virtual void slotShowFolders( bool show ); virtual void refreshMailView(const QValueList<RecMailP>&); virtual void displayMail(); + virtual void slotGetMail() = 0; virtual void slotDeleteMail(); virtual void mailHold(int, QListViewItem *,const QPoint&,int); virtual void slotAdjustLayout(); virtual void slotEditSettings(); virtual void mailLeftClicked( QListViewItem * ); void showLicence(); void showAbout(); void showEtpanLicence(); protected: QToolBar *toolBar; StatusWidget *statusWidget; QPEMenuBar *menuBar; QPopupMenu *mailMenu, *settingsMenu; QAction *composeMail, *sendQueued, *showFolders, *searchMails, *deleteMails, *editSettings, *editAccounts, *syncFolders; AccountView *folderView; QListView *mailView; //QBoxLayout *layout; }; #endif diff --git a/kmicromail/opiemail.cpp b/kmicromail/opiemail.cpp index b2119e6..19ffdb3 100644 --- a/kmicromail/opiemail.cpp +++ b/kmicromail/opiemail.cpp @@ -1,107 +1,108 @@ // CHANGED 2004-09-31 Lutz Rogowski // CHANGED 2004-08-06 Lutz Rogowski #include "settingsdialog.h" #include "opiemail.h" #include "editaccounts.h" #include "composemail.h" #include "mailistviewitem.h" #include "viewmail.h" #include "selectstore.h" #include "selectsmtp.h" +#include "accountitem.h" #include <qmessagebox.h> #include <qtimer.h> #include <libkdepim/externalapphandler.h> #include <qpe/qpeapplication.h> #include <libmailwrapper/smtpwrapper.h> #include <libmailwrapper/mailtypes.h> #include <libmailwrapper/abstractmail.h> /* OPIE */ //#include <qpe/resource.h> //#include <qpe/qpeapplication.h> /* QT */ //using namespace Opie::Core; OpieMail::OpieMail( QWidget *parent, const char *name ) : MainWindow( parent, name) //, WStyle_ContextHelp ) { settings = new Settings(); folderView->populate( settings->getAccounts() ); } OpieMail::~OpieMail() { if (settings) delete settings; } void OpieMail::appMessage(const QCString &msg, const QByteArray &data) { } #include <stdlib.h> void OpieMail::message(const QCString &msg, const QByteArray &data) { // copied from old mail2 static int ii = 0; //qDebug("QCOP CALL ############################# %d ", ii); //QString mess ( msg ); //qDebug("Message = %s ",mess.latin1()); ++ii; //qDebug("KM:appMessage %d *%s* %x", ii, msg.data(), this); mPendingEmail = QString::null; mPendingName = QString::null; if (msg == "writeMail(QString,QString)") { //qDebug("writeMail(QString,QString) "); QDataStream stream(data,IO_ReadOnly); stream >> mPendingName >> mPendingEmail; // removing the whitespaces at beginning and end is needed! QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); } else if (msg == "newMail()") { //qDebug("slotComposeMail() "); // we cannot call slotComposeMail(); directly, because may be executing a QCOP call // and a QCOP call does not like a processevents in his execution // with the Qtimer we call slotComposeMail() after we reached the main event loop QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); // slotComposeMail(); } else if (msg == "newMail(QString)") { //qDebug(" newMail(QString)"); QDataStream stream(data,IO_ReadOnly); stream >> mPendingName; // the format is // NAME <EMAIL>:SUBJECT QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); } else { if ( ii == 1 ) { qDebug("Kopiemail::Error:: Initial QCOP call for ExternalAppHandler not supported "); return; } ExternalAppHandler::instance()->appMessage ( msg, data); } //qDebug("END OpieMail::message "); } void OpieMail::slotwriteMail2(const QString& namemail ) { //qDebug("OpieMail::slotwriteMail2 "); //qApp->processEvents(); ComposeMail compose( settings, this, 0, true ); if ( !namemail.isEmpty() ) { QString to = namemail; if ( namemail.find( " <") > 1 ) { to = "\"" +to.replace( QRegExp( " <"), "\" <") ; } else if ( namemail.find( "<") > 1 ) { to = "\"" +to.replace( QRegExp( "<"), "\" <") ; } @@ -151,193 +152,200 @@ void OpieMail::slotComposeMail() } //slotwriteMail(0l,0l); } void OpieMail::slotSendQueued() { SMTPaccount *smtp = 0; QList<Account> list = settings->getAccounts(); QList<SMTPaccount> smtpList; smtpList.setAutoDelete(false); Account *it; for ( it = list.first(); it; it = list.next() ) { if ( it->getType() == MAILLIB::A_SMTP ) { smtp = static_cast<SMTPaccount *>(it); smtpList.append(smtp); } } if (smtpList.count()==0) { QMessageBox::information(0,tr("Info"),tr("Define a smtp account first!\n")); return; } if (smtpList.count()==1) { smtp = smtpList.at(0); } else { smtp = 0; selectsmtp selsmtp; selsmtp.setSelectionlist(&smtpList); selsmtp.showMaximized(); if ( selsmtp.exec() == QDialog::Accepted ) { smtp = selsmtp.selected_smtp(); } } if (smtp) { SMTPwrapper * wrap = new SMTPwrapper(smtp); if ( wrap->flushOutbox() ) { QMessageBox::information(0,tr("Info"),tr("Mail queue flushed")); } delete wrap; } } void OpieMail::slotSearchMails() { qDebug("OpieMail::slotSearchMails():not implemented "); } void OpieMail::slotEditSettings() { SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp ); settingsDialog.showMaximized(); settingsDialog.exec(); } void OpieMail::slotEditAccounts() { EditAccounts eaDialog( settings, this, 0, true, WStyle_ContextHelp ); eaDialog.slotAdjustColumns(); eaDialog.showMaximized(); eaDialog.exec(); if ( settings ) delete settings; settings = new Settings(); folderView->populate( settings->getAccounts() ); } void OpieMail::displayMail() { QListViewItem*item = mailView->currentItem(); if (!item) return; RecMailP mail = ((MailListViewItem*)item)->data(); RecBodyP body = folderView->fetchBody(mail); ViewMail readMail( this,"", Qt::WType_Modal | WStyle_ContextHelp ); readMail.setBody( body ); readMail.setMail( mail ); readMail.showMaximized(); readMail.exec(); if ( readMail.deleted ) { folderView->refreshCurrent(); } else { ( (MailListViewItem*)item )->setPixmap( 0, QPixmap() ); } } - +void OpieMail::slotGetMail() +{ + QListViewItem * item = folderView->currentItem(); + if ( ! item ) return; + while ( item->parent () ) + item = item->parent (); + ((AccountViewItem *)item)->contextMenuSelected( 101 ); +} void OpieMail::slotDeleteMail() { if (!mailView->currentItem()) return; RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { mail->Wrapper()->deleteMail( mail ); folderView->refreshCurrent(); } } void OpieMail::slotDeleteAllMail() { QValueList<RecMailP> t; if ( QMessageBox::warning(this, tr("Delete All Mails"), tr("Do you really want to delete\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { MailListViewItem* item = (MailListViewItem*)mailView->firstChild (); while ( item ) { if ( item->isSelected() ) { t.append( item->data() ); } item = (MailListViewItem*)item->nextSibling(); } } else return; if ( t.count() == 0 ) return; RecMailP mail = t.first(); mail->Wrapper()->deleteMailList(t); folderView->refreshCurrent(); } void OpieMail::clearSelection() { mailView->clearSelection(); } void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int ) { if (!mailView->currentItem()) return; MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType(); /* just the RIGHT button - or hold on pda */ if (button!=2) {return;} if (!item) return; QPopupMenu *m = new QPopupMenu(0); if (m) { if (mailtype==MAILLIB::A_NNTP) { m->insertItem(tr("Read this posting"),this,SLOT(displayMail())); // m->insertItem(tr("Copy this posting"),this,SLOT(slotMoveCopyMail())); } else { if (folderView->currentisDraft()) { m->insertItem(tr("Edit this mail"),this,SLOT(reEditMail())); } m->insertItem(tr("Read this mail"),this,SLOT(displayMail())); m->insertItem(tr("Move/Copy this mail"),this,SLOT(slotMoveCopyMail())); m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail())); m->insertSeparator(); m->insertItem(tr("Move/Copy all selected mail"),this,SLOT(slotMoveCopyAllMail())); m->insertItem(tr("Delete all selected mails"),this,SLOT(slotDeleteAllMail())); m->insertItem(tr("Clear selection"),this,SLOT(clearSelection())); } m->setFocus(); m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); delete m; } } void OpieMail::slotShowFolders( bool show ) { if ( show && folderView->isHidden() ) { folderView->show(); } else if ( !show && !folderView->isHidden() ) { folderView->hide(); } } void OpieMail::refreshMailView(const QValueList<RecMailP>&list) { MailListViewItem*item = 0; mailView->clear(); QValueList<RecMailP>::ConstIterator it; for (it = list.begin(); it != list.end();++it) { item = new MailListViewItem(mailView,item); item->storeData((*it)); item->showEntry(); } } diff --git a/kmicromail/opiemail.h b/kmicromail/opiemail.h index 1de5f6b..e054b9e 100644 --- a/kmicromail/opiemail.h +++ b/kmicromail/opiemail.h @@ -1,50 +1,51 @@ // CHANGED 2004-09-31 Lutz Rogowski #ifndef OPIEMAIL_H #define OPIEMAIL_H #include "mainwindow.h" #include <libmailwrapper/settings.h> #include <opie2/osmartpointer.h> #include <libmailwrapper/mailtypes.h> class OpieMail : public MainWindow { Q_OBJECT public: OpieMail( QWidget *parent = 0, const char *name = 0 ); virtual ~OpieMail(); static QString appName() { return QString::fromLatin1("kopiemail"); } public slots: virtual void slotwriteMail(const QString&name,const QString&email); virtual void slotwriteMail2(const QString&nameemail); virtual void slotComposeMail(); virtual void appMessage(const QCString &msg, const QByteArray &data); virtual void message(const QCString &msg, const QByteArray &data); protected slots: virtual void slotSendQueued(); virtual void slotSearchMails(); virtual void slotEditSettings(); virtual void slotEditAccounts(); virtual void displayMail(); virtual void slotDeleteMail(); + virtual void slotGetMail(); virtual void slotDeleteAllMail(); virtual void mailHold(int, QListViewItem *,const QPoint&,int); virtual void slotShowFolders( bool show ); virtual void refreshMailView(const QValueList<RecMailP>&); virtual void mailLeftClicked( QListViewItem * ); virtual void slotMoveCopyMail(); virtual void slotMoveCopyAllMail(); virtual void reEditMail(); void clearSelection(); private: QString mPendingEmail; QString mPendingName; Settings *settings; }; #endif |