-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 5 | ||||
-rw-r--r-- | kmicromail/accountitem.cpp | 97 | ||||
-rw-r--r-- | kmicromail/accountview.cpp | 9 | ||||
-rw-r--r-- | kmicromail/addresspicker.cpp | 6 | ||||
-rw-r--r-- | kmicromail/composemail.cpp | 66 | ||||
-rw-r--r-- | kmicromail/editaccounts.cpp | 45 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/abstractmail.cpp | 22 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.cpp | 58 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/mboxwrapper.cpp | 29 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/pop3wrapper.cpp | 21 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/smtpwrapper.cpp | 59 | ||||
-rw-r--r-- | kmicromail/nntpgroupsdlg.cpp | 3 | ||||
-rw-r--r-- | kmicromail/selectsmtp.cpp | 5 | ||||
-rw-r--r-- | kmicromail/viewmail.cpp | 23 | ||||
-rw-r--r-- | kmicromail/viewmailbase.cpp | 21 |
15 files changed, 240 insertions, 229 deletions
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index 99e8618..d6df981 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp @@ -1,335 +1,336 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <sys/types.h> #include <sys/stat.h> -//#include <unistd.h> - +#ifndef _WIN32_ +#include <unistd.h> +#endif #include <qdir.h> #include <qfile.h> #include <qtextstream.h> #include <qfileinfo.h> #include <qregexp.h> //US #include <qtimer.h> #include <kapplication.h> #include <kconfig.h> #include <kdebug.h> #include <klocale.h> //US #include <ksavefile.h> #include <kstandarddirs.h> #include <kmessagebox.h> #include "resourceqtopiaconfig.h" #include "stdaddressbook.h" #include "qtopiaconverter.h" #include "resourceqtopia.h" using namespace KABC; extern "C" #ifdef _WIN32_ __declspec(dllexport) #else { #endif void *init_microkabc_qtopia() { return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig>(); } #ifndef _WIN32_ } #endif ResourceQtopia::ResourceQtopia( const KConfig *config ) : Resource( config ), mConverter (0) { // we can not choose the filename. Therefore use the default to display QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; init( fileName ); } ResourceQtopia::ResourceQtopia( const QString &fileName ) : Resource( 0 ) { init( fileName ); } void ResourceQtopia::init( const QString &fileName ) { #ifdef _USE_DIRWATCH_ connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); #endif setFileName( fileName ); } ResourceQtopia::~ResourceQtopia() { if (mConverter != 0) delete mConverter; } void ResourceQtopia::writeConfig( KConfig *config ) { Resource::writeConfig( config ); } Ticket *ResourceQtopia::requestSaveTicket() { kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); if ( !addressBook() ) return 0; if ( !lock( fileName() ) ) { kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" << fileName() << "'" << endl; return 0; } return createTicket( this ); } bool ResourceQtopia::doOpen() { qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); if (mConverter == 0) { mConverter = new QtopiaConverter(); bool res = mConverter->init(); if ( !res ) { QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); qDebug(msg); return false; } } return true; } void ResourceQtopia::doClose() { qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); // it seems so, that deletion of access deletes backend as well //delete backend; return; } bool ResourceQtopia::load() { QFile file( fileName() ); if ( !file.open(IO_ReadOnly ) ) { return false; } QDomDocument doc("mydocument" ); if ( !doc.setContent( &file ) ) { file.close(); return false; } bool res; QDomElement docElem = doc.documentElement( ); QDomNode n = docElem.firstChild(); while ( !n.isNull() ) { QDomElement e = n.toElement(); if ( !e.isNull() ) { if ( e.tagName() == QString::fromLatin1( "Contacts" ) ) { QDomNode no = e.firstChild(); while ( !no.isNull() ) { QDomElement el = no.toElement(); if ( !el.isNull() ) { KABC::Addressee addressee; res = mConverter->qtopiaToAddressee( el, addressee ); if ( !addressee.isEmpty() && res ) { addressee.setResource( this ); addressBook()->insertAddressee( addressee ); } } no = no.nextSibling(); } } } n = n.nextSibling(); } return true; } bool ResourceQtopia::save( Ticket *ticket ) { #ifdef _USE_DIRWATCH_ mDirWatch.stopScan(); #endif KABC::AddressBook::Iterator it; bool res; QFile file( fileName() ); if (!file.open( IO_WriteOnly ) ) { return false; } QTextStream ts( &file ); QTextStream *stream = &ts; stream->setEncoding( QTextStream::UnicodeUTF8 ); *stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>" << endl; *stream << " <Groups>" << endl; *stream << " </Groups>" << endl; *stream << " <Contacts> " << endl; // for all entries KABC::Addressee ab; for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { KABC::Addressee addressee = (*it); res = mConverter->addresseeToQtopia( addressee, stream ); if (!res == true) { qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); } } *stream << "</Contacts>" << endl; *stream << "</AddressBook>" << endl; file.close(); #ifdef _USE_DIRWATCH_ mDirWatch.startScan(); #endif delete ticket; unlock( fileName() ); return true; } bool ResourceQtopia::lock( const QString &lockfileName ) { //disabled return true; qDebug("ResourceQtopia::lock: %s", fileName().latin1()); QString fn = lockfileName; KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); if (QFile::exists( lockName )) { qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); return false; } QString lockUniqueName; lockUniqueName = fn + KApplication::randomString( 8 ); url = lockUniqueName; //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; // Create unique file QFile file( mLockUniqueName ); file.open( IO_WriteOnly ); file.close(); // Create lock file int result = 0; #ifndef _WIN32_ result = ::link( QFile::encodeName( mLockUniqueName ), QFile::encodeName( lockName ) ); #endif if ( result == 0 ) { addressBook()->emitAddressBookLocked(); return true; } // TODO: check stat return false; } void ResourceQtopia::unlock( const QString &fileName ) { //disabled return; qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); QString fn = fileName; KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); QFile::remove( lockName ); QFile::remove( mLockUniqueName ); addressBook()->emitAddressBookUnlocked(); } void ResourceQtopia::setFileName( const QString &newFileName ) { #ifdef _USE_DIRWATCH_ mDirWatch.stopScan(); #endif mDirWatch.removeFile( fileName() ); Resource::setFileName( newFileName ); mDirWatch.addFile( fileName() ); #ifdef _USE_DIRWATCH_ mDirWatch.startScan(); #endif } void ResourceQtopia::fileChanged() { // There is a small theoretical chance that KDirWatch calls us before // we are fully constructed if (!addressBook()) return; QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { load(); addressBook()->emitAddressBookChanged(); } } void ResourceQtopia::removeAddressee( const Addressee &addr ) { } void ResourceQtopia::cleanUp() { unlock( fileName() ); } //US #include "resourceqtopia.moc" diff --git a/kmicromail/accountitem.cpp b/kmicromail/accountitem.cpp index 49d86fc..567de87 100644 --- a/kmicromail/accountitem.cpp +++ b/kmicromail/accountitem.cpp @@ -1,1182 +1,1183 @@ #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> +#include <klocale.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("Get new messages",contextName),GET_NEW_MAILS); - m->insertItem(QObject::tr("Disconnect",contextName),0); - m->insertItem(QObject::tr("Set offline",contextName),1); + m->insertItem(i18n("Get new messages"),GET_NEW_MAILS); + m->insertItem(i18n("Disconnect"),0); + m->insertItem(i18n("Set offline"),1); } else { - m->insertItem(QObject::tr("Get new messages",contextName),GET_NEW_MAILS); - m->insertItem(QObject::tr("Set online",contextName),1); + m->insertItem(i18n("Get new messages"),GET_NEW_MAILS); + m->insertItem(i18n("Set online"),1); } } 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 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("Get new messages",contextName),GET_NEW_MAILS); - 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); + m->insertItem(i18n("Get new messages"),GET_NEW_MAILS); + m->insertItem(i18n("Refresh header list"),0); + m->insertItem(i18n("Delete all mails"),1); + m->insertItem(i18n("Move/Copie all mails"),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; case GET_NEW_MAILS: // daunlood view->downloadMailsInbox(getFolder() ,pop3->getWrapper()); 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, ); } else { setPixmap( 0, PIXMAP_OFFLINE ); } #endif setText( 0, account->getAccountName() ); setOpen( true ); } NNTPviewItem::~NNTPviewItem() { delete wrapper; } AbstractMail *NNTPviewItem::getWrapper() { return wrapper; } void NNTPviewItem::refresh( QValueList<RecMailP> & ) { refresh(); } void NNTPviewItem::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 NNTPfolderItem( (*it), this , item ); item->setSelectable( (*it)->may_select()); } delete folders; } RECBODYP NNTPviewItem::fetchBody( const RecMailP &mail ) { return wrapper->fetchBody( mail ); } QPopupMenu * NNTPviewItem::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("(Un-)Subscribe groups",contextName),2); + m->insertItem(i18n("Disconnect"),0); + m->insertItem(i18n("Set offline"),1); + //m->insertItem(i18n("(Un-)Subscribe groups"),2); } else { - m->insertItem(QObject::tr("Set online",contextName),1); + m->insertItem(i18n("Set online"),1); } } return m; } void NNTPviewItem::subscribeGroups() { NNTPGroupsDlg dlg(account); dlg.showMaximized(); if ( dlg.exec()== QDialog::Accepted ){ refresh(); } } void NNTPviewItem::disconnect() { QListViewItem *child = firstChild(); while ( child ) { QListViewItem *tmp = child; child = child->nextSibling(); delete tmp; } wrapper->logout(); } void NNTPviewItem::setOnOffline() { if (!account->getOffline()) { disconnect(); } account->setOffline(!account->getOffline()); account->save(); //FIXME SETPIX(PIXMAP_POP3FOLDER); refresh(); } void NNTPviewItem::contextMenuSelected(int which) { switch (which) { case 0: disconnect(); break; case 1: setOnOffline(); break; case 2: subscribeGroups(); break; } } NNTPfolderItem::~NNTPfolderItem() {} NNTPfolderItem::NNTPfolderItem( const FolderP &folderInit, NNTPviewItem *parent , QListViewItem*after ) : AccountViewItem( folderInit, parent,after ) { nntp = parent; if (folder->getDisplayName().lower()!="inbox") { setPixmap( 0, PIXMAP_POP3FOLDER ); } else { setPixmap( 0, PIXMAP_INBOXFOLDER); } setText( 0, folder->getDisplayName() ); } void NNTPfolderItem::refresh(QValueList<RecMailP>&target) { if (folder->may_select()) nntp->getWrapper()->listMessages( folder->getName(),target ); } RECBODYP NNTPfolderItem::fetchBody(const RecMailP&aMail) { return nntp->getWrapper()->fetchBody(aMail); } QPopupMenu * NNTPfolderItem::getContextMenu() { QPopupMenu *m = new QPopupMenu(0); if (m) { - m->insertItem(QObject::tr("Refresh header list",contextName),0); - m->insertItem(QObject::tr("Copy all postings",contextName),1); + m->insertItem(i18n("Refresh header list"),0); + m->insertItem(i18n("Copy all postings"),1); } return m; } void NNTPfolderItem::downloadMails() { AccountView*bl = nntp->accountView(); if (!bl) return; bl->downloadMails(folder,nntp->getWrapper()); } void NNTPfolderItem::contextMenuSelected(int which) { AccountView * view = (AccountView*)listView(); switch (which) { case 0: /* must be 'cause pop3 lists are cached */ nntp->getWrapper()->logout(); view->refreshCurrent(); break; case 1: downloadMails(); break; default: break; } } /** * 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().mid(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("Get new messages",contextName),GET_NEW_MAILS); - m->insertItem(QObject::tr("Refresh folder list",contextName),0); - m->insertItem(QObject::tr("Create new folder",contextName),1); + m->insertItem(i18n("Get new messages"),GET_NEW_MAILS); + m->insertItem(i18n("Refresh folder list"),0); + m->insertItem(i18n("Create new folder"),1); m->insertSeparator(); - m->insertItem(QObject::tr("Disconnect",contextName),2); - m->insertItem(QObject::tr("Set offline",contextName),3); + m->insertItem(i18n("Disconnect"),2); + m->insertItem(i18n("Set offline"),3); m->insertSeparator(); } else { - m->insertItem(QObject::tr("Get new messages",contextName),GET_NEW_MAILS); - m->insertItem(QObject::tr("Set online",contextName),3); + m->insertItem(i18n("Get new messages"),GET_NEW_MAILS); + m->insertItem(i18n("Set online"),3); } } 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 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("Get new messages",contextName),GET_NEW_MAILS); - 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); + m->insertItem(i18n("Get new messages"),GET_NEW_MAILS); + m->insertItem(i18n("Refresh header list"),0); + m->insertItem(i18n("Move/Copie all mails"),4); + m->insertItem(i18n("Delete all mails"),1); } if (folder->no_inferior()==false) { - m->insertItem(QObject::tr("Create new subfolder",contextName),2); + m->insertItem(i18n("Create new subfolder"),2); } if (folder->getDisplayName().lower()!="inbox") { - m->insertItem(QObject::tr("Delete folder",contextName),3); + m->insertItem(i18n("Delete folder"),3); } } return m; } void IMAPfolderItem::createNewFolder() { Newmdirdlg ndirdlg; ndirdlg.showMaximized(); if ( ndirdlg.exec() ) { QString ndir = ndirdlg.Newdir(); bool makesubs = ndirdlg.subpossible(); QString delemiter = Delemiter(); if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) { imap->refreshFolders(true); } } } void IMAPfolderItem::deleteFolder() { - int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), - QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), - QObject::tr("Yes",contextName), - QObject::tr("No",contextName),QString::null,1,1); + int yesno = QMessageBox::warning(0,i18n("Delete folder"), + i18n("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>").arg(folder->getDisplayName()), + i18n("Yes"), + i18n("No"),QString::null,1,1); if (yesno == 0) { if (imap->getWrapper()->deleteMbox(folder)) { QListView*v=listView(); IMAPviewItem * box = imap; /* be carefull - after that this object is destroyd so don't use * any member of it after that call!!*/ imap->refreshFolders(true); if (v) { v->setSelected(box,true); } } } } void IMAPfolderItem::downloadMails() { AccountView*bl = imap->accountView(); if (!bl) return; bl->downloadMails(folder,imap->getWrapper()); } void IMAPfolderItem::contextMenuSelected(int id) { AccountView * view = (AccountView*)listView(); switch(id) { case 0: view->refreshCurrent(); break; case 1: deleteAllMail(imap->getWrapper(),folder); break; case 2: createNewFolder(); break; case 3: deleteFolder(); break; case 4: downloadMails(); break; case GET_NEW_MAILS: // daunlood { if (!view) return; view->downloadMailsInbox(getFolder(),imap->getWrapper()); } break; default: break; } } /** * MH Account stuff */ /* MH is a little bit different - the top folder can contains messages other than in IMAP and POP3 and MBOX */ MHviewItem::MHviewItem( const QString&aPath, AccountView *parent ) : AccountViewItem( parent ) { m_Path = aPath; /* be carefull - the space within settext is wanted - thats why the string twice */ wrapper = AbstractMail::getWrapper( m_Path,"Local Folders"); setPixmap( 0, PIXMAP_LOCALFOLDER ); setText( 0, " Local Folders" ); setOpen( true ); folder = 0; } MHviewItem::~MHviewItem() { delete wrapper; } AbstractMail *MHviewItem::getWrapper() { return wrapper; } void MHviewItem::refresh( QValueList<RecMailP> & target) { refresh(false); getWrapper()->listMessages( "",target ); } void MHviewItem::refresh(bool force) { if (childCount()>0 && force==false) return; removeChilds(); currentFolders.clear(); QValueList<FolderP> *folders = wrapper->listFolders(); QValueList<FolderP>::ConstIterator it; MHfolderItem*item = 0; MHfolderItem*pmaster = 0; QString fname = ""; int pos; for ( it = folders->begin(); it!=folders->end(); ++it) { fname = (*it)->getDisplayName(); /* this folder itself */ if (fname=="/") { currentFolders.append(fname); folder = (*it); continue; } currentFolders.append(fname); pos = fname.findRev("/"); if (pos > 0) { fname = fname.left(pos); pmaster = (MHfolderItem*)findSubItem(fname); } else { pmaster = 0; } if (pmaster) { item = new MHfolderItem( (*it), pmaster, item, this ); } else { item = new MHfolderItem( (*it), this , item ); } item->setSelectable((*it)->may_select()); } delete folders; } RECBODYP MHviewItem::fetchBody( const RecMailP &mail ) { return wrapper->fetchBody( mail ); } QPopupMenu * MHviewItem::getContextMenu() { QPopupMenu *m = new QPopupMenu(0); if (m) { - m->insertItem(QObject::tr("Refresh folder list",contextName),0); - m->insertItem(QObject::tr("Create new folder",contextName),1); - m->insertItem(QObject::tr("Delete all mails",contextName),2); - m->insertItem(QObject::tr("Move/Copie all mails",contextName),3); + m->insertItem(i18n("Refresh folder list"),0); + m->insertItem(i18n("Create new folder"),1); + m->insertItem(i18n("Delete all mails"),2); + m->insertItem(i18n("Move/Copie all mails"),3); } return m; } void MHviewItem::createFolder() { Newmdirdlg ndirdlg(0,0,true); ndirdlg.showMaximized(); if ( ndirdlg.exec() ) { QString ndir = ndirdlg.Newdir(); if (wrapper->createMbox(ndir)) { refresh(true); } } } void MHviewItem::downloadMails() { AccountView*bl = accountView(); if (!bl) return; bl->downloadMails(folder,getWrapper()); } QStringList MHviewItem::subFolders() { return currentFolders; } void MHviewItem::contextMenuSelected(int which) { switch (which) { case 0: refresh(true); break; case 1: createFolder(); break; case 2: deleteAllMail(getWrapper(),folder); break; case 3: downloadMails(); break; default: break; } } MHfolderItem::~MHfolderItem() {} MHfolderItem::MHfolderItem( const FolderP &folderInit, MHviewItem *parent , QListViewItem*after ) : AccountViewItem(folderInit, parent,after ) { mbox = parent; initName(); } MHfolderItem::MHfolderItem(const FolderP& folderInit, MHfolderItem *parent, QListViewItem*after, MHviewItem*master) : AccountViewItem(folderInit, parent,after ) { folder = folderInit; mbox = master; initName(); } void MHfolderItem::initName() { QString bName = folder->getDisplayName(); if (bName.startsWith("/")&&bName.length()>1) { bName.replace(0,1,""); } int pos = bName.findRev("/"); if (pos > 0) { bName.replace(0,pos+1,""); } if (bName.lower() == "outgoing") { setPixmap( 0, PIXMAP_OUTBOXFOLDER ); } else if (bName.lower() == "inbox") { setPixmap( 0, PIXMAP_INBOXFOLDER); } else if (bName.lower() == "drafts") { setPixmap(0, SmallIcon ("edit")); } else { setPixmap( 0, PIXMAP_MBOXFOLDER ); } setText( 0, bName ); } const FolderP&MHfolderItem::getFolder()const { return folder; } void MHfolderItem::refresh(QValueList<RecMailP>&target) { if (folder->may_select()) mbox->getWrapper()->listMessages( folder->getName(),target ); } RECBODYP MHfolderItem::fetchBody(const RecMailP&aMail) { return mbox->getWrapper()->fetchBody(aMail); } void MHfolderItem::deleteFolder() { - int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), - QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), - QObject::tr("Yes",contextName), - QObject::tr("No",contextName),QString::null,1,1); + int yesno = QMessageBox::warning(0,i18n("Delete folder"), + i18n("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>").arg(folder->getDisplayName()), + i18n("Yes"), + i18n("No"),QString::null,1,1); if (yesno == 0) { if (mbox->getWrapper()->deleteMbox(folder)) { QListView*v=listView(); MHviewItem * box = mbox; /* be carefull - after that this object is destroyd so don't use * any member of it after that call!!*/ mbox->refresh(true); if (v) { v->setSelected(box,true); } } } } QPopupMenu * MHfolderItem::getContextMenu() { QPopupMenu *m = new QPopupMenu(0); if (m) { - m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); - m->insertItem(QObject::tr("Delete all mails",contextName),0); - m->insertItem(QObject::tr("Create new subfolder",contextName),3); - m->insertItem(QObject::tr("Delete folder",contextName),1); + m->insertItem(i18n("Move/Copie all mails"),2); + m->insertItem(i18n("Delete all mails"),0); + m->insertItem(i18n("Create new subfolder"),3); + m->insertItem(i18n("Delete folder"),1); } return m; } void MHfolderItem::downloadMails() { AccountView*bl = mbox->accountView(); if (!bl) return; bl->downloadMails(folder,mbox->getWrapper()); } void MHfolderItem::createFolder() { Newmdirdlg ndirdlg(0,0,true); ndirdlg.showMaximized(); if (ndirdlg.exec() ) { QString ndir = ndirdlg.Newdir(); if (mbox->getWrapper()->createMbox(ndir,folder)) { QListView*v=listView(); MHviewItem * box = mbox; /* be carefull - after that this object is destroyd so don't use * any member of it after that call!!*/ mbox->refresh(true); if (v) { v->setSelected(box,true); } } } } void MHfolderItem::contextMenuSelected(int which) { switch(which) { case 0: deleteAllMail(mbox->getWrapper(),folder); break; case 1: deleteFolder(); break; case 2: downloadMails(); break; case 3: createFolder(); break; default: break; } } bool MHfolderItem::isDraftfolder() { if (folder && folder->getName()==AbstractMail::defaultLocalfolder()+"/"+AbstractMail::draftFolder()) return true; return false; } /** * Generic stuff */ const QString AccountViewItem::contextName="AccountViewItem"; AccountViewItem::AccountViewItem( AccountView *parent ) : QListViewItem( parent ) { init(); m_Backlink = parent; } AccountViewItem::AccountViewItem( QListViewItem *parent) : QListViewItem( parent),folder(0) { init(); } AccountViewItem::AccountViewItem( QListViewItem *parent , QListViewItem*after ) :QListViewItem( parent,after ),folder(0) { init(); } AccountViewItem::AccountViewItem( const Opie::Core::OSmartPointer<Folder>&folderInit,QListViewItem *parent , QListViewItem*after ) :QListViewItem( parent,after ),folder(folderInit) { init(); } void AccountViewItem::init() { m_Backlink = 0; } AccountViewItem::~AccountViewItem() { folder = 0; } AccountView*AccountViewItem::accountView() { return m_Backlink; } void AccountViewItem::deleteAllMail(AbstractMail*wrapper,const FolderP&folder) { if (!wrapper) return; QString fname=""; if (folder) fname = folder->getDisplayName(); - int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName), - QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName). + int yesno = QMessageBox::warning(0,i18n("Delete all mails"), + i18n("<center>Realy delete all mails in box <br>%1</center>"). arg(fname), - QObject::tr("Yes",contextName), - QObject::tr("No",contextName),QString::null,1,1); + i18n("Yes"), + i18n("No"),QString::null,1,1); if (yesno == 0) { if (wrapper->deleteAllMail(folder)) { AccountView * view = (AccountView*)listView(); if (view) view->refreshCurrent(); } } } void AccountViewItem::removeChilds() { QListViewItem *child = firstChild(); while ( child ) { QListViewItem *tmp = child; child = child->nextSibling(); delete tmp; } } bool AccountViewItem::matchName(const QString&name)const { if (!folder) return false; return folder->getDisplayName().lower()==name.lower(); } AccountViewItem*AccountViewItem::findSubItem(const QString&path,AccountViewItem*start) { AccountViewItem*pitem,*sitem; if (!start) pitem = (AccountViewItem*)firstChild(); else pitem = (AccountViewItem*)start->firstChild(); while (pitem) { if (pitem->matchName(path)) { break; } if (pitem->childCount()>0) { sitem = findSubItem(path,pitem); if (sitem) { pitem = sitem; break; } } pitem=(AccountViewItem*)pitem->nextSibling(); } return pitem; } bool AccountViewItem::isDraftfolder() { return false; } diff --git a/kmicromail/accountview.cpp b/kmicromail/accountview.cpp index de8c5bb..c10d384 100644 --- a/kmicromail/accountview.cpp +++ b/kmicromail/accountview.cpp @@ -1,206 +1,207 @@ #include "accountview.h" #include "accountitem.h" #include "selectstore.h" #include <libmailwrapper/settings.h> #include <libmailwrapper/mailwrapper.h> #include <libmailwrapper/mailtypes.h> #include <libmailwrapper/abstractmail.h> /* OPIE */ #include <qpe/qpeapplication.h> /* QT */ #include <qmessagebox.h> #include <qpopupmenu.h> #include <qcheckbox.h> #include <qspinbox.h> +#include <klocale.h> using namespace Opie::Core; AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) : QListView( parent, name, flags ) { connect( this, SIGNAL( selectionChanged(QListViewItem*) ), SLOT( refresh(QListViewItem*) ) ); connect( this, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),this, SLOT( slotHold(int,QListViewItem*,const QPoint&,int) ) ); setSorting(0); } AccountView::~AccountView() { imapAccounts.clear(); mhAccounts.clear(); } void AccountView::slotContextMenu(int id) { AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); if (!view) return; view->contextMenuSelected(id); } void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int) { if (button==1) {return;} if (!item) return; AccountViewItem *view = static_cast<AccountViewItem *>(item); QPopupMenu*m = view->getContextMenu(); if (!m) return; connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int))); m->setFocus(); m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); delete m; } void AccountView::populate( QList<Account> list ) { clear(); imapAccounts.clear(); mhAccounts.clear(); mhAccounts.append(new MHviewItem(AbstractMail::defaultLocalfolder(),this)); Account *it; for ( it = list.first(); it; it = list.next() ) { if ( it->getType() == MAILLIB::A_IMAP ) { IMAPaccount *imap = static_cast<IMAPaccount *>(it); imapAccounts.append(new IMAPviewItem( imap, this )); } else if ( it->getType() == MAILLIB::A_POP3 ) { POP3account *pop3 = static_cast<POP3account *>(it); /* must not be hold 'cause it isn't required */ (void) new POP3viewItem( pop3, this ); } else if ( it->getType() == MAILLIB::A_NNTP ) { NNTPaccount *nntp = static_cast<NNTPaccount *>(it); /* must not be hold 'cause it isn't required */ (void) new NNTPviewItem( nntp, this ); } } } void AccountView::refresh(QListViewItem *item) { if ( item ) { m_currentItem = item; QValueList<RecMailP> headerlist; AccountViewItem *view = static_cast<AccountViewItem *>(item); view->refresh(headerlist); emit refreshMailview(headerlist); } } void AccountView::refreshCurrent() { m_currentItem = currentItem(); if ( !m_currentItem ) return; QValueList<RecMailP> headerlist; AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); view->refresh(headerlist); emit refreshMailview(headerlist); } void AccountView::refreshAll() { } RecBodyP AccountView::fetchBody(const RecMailP&aMail) { QListViewItem*item = selectedItem (); if (!item) return new RecBody(); AccountViewItem *view = static_cast<AccountViewItem *>(item); return view->fetchBody(aMail); } void AccountView::setupFolderselect(Selectstore*sels) { sels->showMaximized(); QStringList sFolders; unsigned int i = 0; for (i=0; i < mhAccounts.count();++i) { mhAccounts[i]->refresh(false); sFolders = mhAccounts[i]->subFolders(); sels->addAccounts(mhAccounts[i]->getWrapper(),sFolders); } for (i=0; i < imapAccounts.count();++i) { if (imapAccounts[i]->offline()) continue; imapAccounts[i]->refreshFolders(false); sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders()); } } void AccountView::downloadMailsInbox(const FolderP&fromFolder,AbstractMail*fromWrapper) { #if 0 AbstractMail*targetMail = 0; QString targetFolder = ""; Selectstore sels; setupFolderselect(&sels); if (!sels.exec()) return; targetMail = sels.currentMail(); targetFolder = sels.currentFolder(); if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) || targetFolder.isEmpty()) { return; } if (sels.newFolder() && !targetMail->createMbox(targetFolder)) { - QMessageBox::critical(0,tr("Error creating new Folder"), - tr("<center>Error while creating<br>new folder - breaking.</center>")); + QMessageBox::critical(0,i18n("Error creating new Folder"), + i18n("<center>Error while creating<br>new folder - breaking.</center>")); return; } int maxsize = 0; if ( sels.useSize->isChecked()) maxsize = sels.sizeSpinBox->value(); fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails(), maxsize); #endif fromWrapper->downloadNewMails( fromFolder, mhAccounts[0]->getWrapper()); refreshCurrent(); } void AccountView::downloadMails(const FolderP&fromFolder,AbstractMail*fromWrapper) { AbstractMail*targetMail = 0; QString targetFolder = ""; Selectstore sels; setupFolderselect(&sels); if (!sels.exec()) return; targetMail = sels.currentMail(); targetFolder = sels.currentFolder(); if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) || targetFolder.isEmpty()) { return; } if (sels.newFolder() && !targetMail->createMbox(targetFolder)) { - QMessageBox::critical(0,tr("Error creating new Folder"), - tr("<center>Error while creating<br>new folder - breaking.</center>")); + QMessageBox::critical(0,i18n("Error creating new Folder"), + i18n("<center>Error while creating<br>new folder - breaking.</center>")); return; } int maxsize = 0; if ( sels.useSize->isChecked()) maxsize = sels.sizeSpinBox->value(); fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails(), maxsize); refreshCurrent(); } bool AccountView::currentisDraft() { AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); if (!view) return false; return view->isDraftfolder(); } diff --git a/kmicromail/addresspicker.cpp b/kmicromail/addresspicker.cpp index ec6da49..f4234b4 100644 --- a/kmicromail/addresspicker.cpp +++ b/kmicromail/addresspicker.cpp @@ -1,116 +1,116 @@ #include "composemail.h" /* OPIE */ //#include <opie2/ocontactaccess.h> //#include <opie2/opimcontact.h> #include <qpe/resource.h> #include <qpe/qpeapplication.h> /* QT */ #include <qpushbutton.h> #include <qmessagebox.h> #include <qlistbox.h> /* STD */ #include <stdlib.h> AddressPicker::AddressPicker( QWidget *parent, const char *name, bool modal, WFlags flags ) : AddressPickerUI( parent, name, modal, flags ) { okButton->setIconSet( Resource::loadPixmap( "enter" ) ); cancelButton->setIconSet( Resource::loadPixmap( "editdelete" ) ); connect(okButton, SIGNAL(clicked()), SLOT(accept())); connect(cancelButton, SIGNAL(clicked()), SLOT(close())); qDebug("AddressPicker::AddressPicker pending access KA/PI "); #if 0 Opie::OPimContactAccess::List::Iterator it; QString lineEmail, lineName, contactLine; /* what name has to set here???? */ Opie::OPimContactAccess m_contactdb("opiemail"); QStringList mails; QString pre,suf; Opie::OPimContactAccess::List m_list = m_contactdb.sorted( true, 0, 0, 0 ); for ( it = m_list.begin(); it != m_list.end(); ++it ) { if ((*it).defaultEmail().length()!=0) { mails = (*it).emailList(); if ((*it).fileAs().length()>0) { pre = "\""+(*it).firstName()+" "+(*it).lastName()+"\" <"; suf = ">"; } else { pre = ""; suf = ""; } QStringList::ConstIterator sit = mails.begin(); for (;sit!=mails.end();++sit) { contactLine=pre+(*sit)+suf; addressList->insertItem(contactLine); } } } if ( addressList->count() <= 0 ) { #if 0 // makes this realy sense?? addressList->insertItem( - tr( "There are no entries in the addressbook." ) ); + i18n( "There are no entries in the addressbook." ) ); #endif addressList->setEnabled( false ); okButton->setEnabled( false ); } else { // addressList->sort(); } #endif } void AddressPicker::accept() { QListBoxItem *item = addressList->firstItem(); QString names; while ( item ) { if ( item->selected() ) names += item->text() + ", "; item = item->next(); } names.replace( names.length() - 2, 2, "" ); if ( names.isEmpty() ) { - QMessageBox::information(this, tr("Error"), tr("<p>You have to select" - " at least one address entry.</p>"), tr("Ok")); + QMessageBox::information(this, i18n("Error"), i18n("<p>You have to select" + " at least one address entry.</p>"), i18n("Ok")); return; } selectedNames = names; QDialog::accept(); } QString AddressPicker::getNames() { QString names = 0; AddressPicker picker(0, 0, true); picker.showMaximized(); int ret = picker.exec(); if ( QDialog::Accepted == ret ) { return picker.selectedNames; } return 0; } diff --git a/kmicromail/composemail.cpp b/kmicromail/composemail.cpp index 946e97d..35ad367 100644 --- a/kmicromail/composemail.cpp +++ b/kmicromail/composemail.cpp @@ -1,483 +1,483 @@ // CHANGED 2004-08-06 Lutz Rogowski #include "composemail.h" #include <libmailwrapper/smtpwrapper.h> #include <libmailwrapper/storemail.h> #include <libmailwrapper/abstractmail.h> #include <libmailwrapper/mailtypes.h> /* OPIE */ //#include <opie2/ofiledialog.h> //#include <opie2/odebug.h> #include <kfiledialog.h> //#include <qpe/resource.h> #include <qpe/global.h> //#include <qpe/contact.h> #include <qcombobox.h> #include <qcheckbox.h> #include <qtimer.h> #include <qmessagebox.h> #include <qpushbutton.h> #include <qmultilineedit.h> #include <qlabel.h> #include <qtabwidget.h> #include <qlistview.h> #include <kabc/addresseedialog.h> #include <kabc/stdaddressbook.h> #include <kabc/addressee.h> #ifdef DESKTOP_VERSION #include <kabc/addresseedialog.h> #else //DESKTOP_VERSION #include <libkdepim/externalapphandler.h> #endif //DESKTOP_VERSION #include "koprefs.h" //using namespace Opie::Core; //using namespace Opie::Ui; ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal ) : ComposeMailUI( parent, name, modal ) { mPickLineEdit = 0; connect(ExternalAppHandler::instance(), SIGNAL(receivedNameEmailUidListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&)), this, SLOT(insertAttendees(const QString&, const QStringList&, const QStringList&, const QStringList&))); settings = s; m_replyid = ""; if ( KOPrefs::instance()->mUseKapi) { KConfig config( locateLocal("config", "kabcrc") ); config.setGroup( "General" ); QString whoami_uid = config.readEntry( "WhoAmI" ); if ( whoami_uid.isEmpty() ) { - QMessageBox::information( 0, tr( "Hint" ), - tr( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), - tr( "Ok" ) ); + QMessageBox::information( 0, i18n( "Hint" ), + i18n( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), + i18n( "Ok" ) ); fillSettings(); } else ExternalAppHandler::instance()->requestDetailsFromKAPI("", "sendbacklist", whoami_uid); #ifdef DESKTOP_VERSION KABC::Addressee con = KABC::StdAddressBook::self()->whoAmI( ); QStringList mails = con.emails(); QString defmail = con.preferredEmail(); if ( mails.count() == 0) - QMessageBox::information( 0, tr( "Hint" ), - tr( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), - tr( "Ok" ) ); + QMessageBox::information( 0, i18n( "Hint" ), + i18n( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), + i18n( "Ok" ) ); if (defmail.length()!=0) { fromBox->insertItem(defmail); } QStringList::ConstIterator sit = mails.begin(); for (;sit!=mails.end();++sit) { if ( (*sit)==defmail) continue; fromBox->insertItem((*sit)); } senderNameEdit->setText(con.formattedName()); #endif } else { fillSettings(); } checkBoxLater->setChecked( KOPrefs::instance()->mSendLater ); - attList->addColumn( tr( "Name" ) ); - attList->addColumn( tr( "Size" ) ); + attList->addColumn( i18n( "Name" ) ); + attList->addColumn( i18n( "Size" ) ); QList<Account> accounts = settings->getAccounts(); if ( QApplication::desktop()->width() < 320 ) smtpAccountBox->setMaximumWidth( 80 ); Account *it; for ( it = accounts.first(); it; it = accounts.next() ) { if ( it->getType()==MAILLIB::A_SMTP ) { SMTPaccount *smtp = static_cast<SMTPaccount *>(it); smtpAccountBox->insertItem( smtp->getAccountName() ); smtpAccounts.append( smtp ); } } connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); connect( SaveButton, SIGNAL( clicked() ), SLOT( saveAsDraft()) ); mMail = 0; warnAttach = true; if ( smtpAccounts.count() > 0 ) { fillValues( smtpAccountBox->currentItem() ); } else { - QMessageBox::information( 0, tr( "Problem" ), - tr( "Please create an SMTP account first.\nThe SMTP is needed for sending mail.\n" ), - tr( "Ok" ) ); + QMessageBox::information( 0, i18n( "Problem" ), + i18n( "Please create an SMTP account first.\nThe SMTP is needed for sending mail.\n" ), + i18n( "Ok" ) ); return; } connect( smtpAccountBox, SIGNAL( activated(int) ), SLOT( fillValues(int) ) ); message->setFont ( KOPrefs::instance()->mComposeFont ); message->setWordWrap (QMultiLineEdit::WidgetWidth); #ifndef DESKTOP_VERSION QPEApplication::setStylusOperation( message, QPEApplication::RightOnHold ); #endif } void ComposeMail::fillSettings() { if ( QApplication::desktop()->width() < 320 ) fromBox->setMaximumWidth( 100 ); QStringList mailList = QStringList::split(";",KOPrefs::instance()->mEmail); QStringList::ConstIterator sit = mailList.begin(); int pref = 0; for (;sit!=mailList.end();++sit) { fromBox->insertItem((*sit)); } senderNameEdit->setText(KOPrefs::instance()->mName); } void ComposeMail::saveAsDraft() { Opie::Core::OSmartPointer<Mail> mail= new Mail(); mail->setMail(fromBox->currentText()); mail->setTo( toLine->text() ); mail->setName(senderNameEdit->text()); mail->setCC( ccLine->text() ); mail->setBCC( bccLine->text() ); mail->setReply( replyLine->text() ); mail->setSubject( subjectLine->text() ); if (!m_replyid.isEmpty()) { QStringList ids; ids.append(m_replyid); mail->setInreply(ids); } QString txt = message->text(); if ( !sigMultiLine->text().isEmpty() ) { txt.append( "\n--\n" ); txt.append( sigMultiLine->text() ); } mail->setMessage( txt ); /* only use the default drafts folder name! */ Storemail wrapper(AbstractMail::draftFolder()); wrapper.storeMail(mail); AttachViewItem *it = (AttachViewItem *) attList->firstChild(); /* attachments we will ignore! */ if ( it != 0 ) { if ( warnAttach ) - QMessageBox::warning(0,tr("Store message"), - tr("<center>Attachments will not be stored in \"Draft\" folder</center>")); + QMessageBox::warning(0,i18n("Store message"), + i18n("<center>Attachments will not be stored in \"Draft\" folder</center>")); warnAttach = false; } - setStatus( tr("Mail saved as draft!") ); + setStatus( i18n("Mail saved as draft!") ); } void ComposeMail::clearStatus() { - topLevelWidget()->setCaption( tr("Compose mail") ); + topLevelWidget()->setCaption( i18n("Compose mail") ); } void ComposeMail::setStatus( QString status ) { topLevelWidget()->setCaption( status ); QTimer::singleShot ( 10000, this, SLOT( clearStatus() ) ) ; } void ComposeMail::pickAddress( ) { QLineEdit *line = mPickLineEdit; if ( line == 0 ) return; #ifdef DESKTOP_VERSION //qDebug(" ComposeMail::pickAddress "); QString names ;//= AddressPicker::getNames(); KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); uint i=0; for (i=0; i < list.count(); i++) { if ( !list[i].preferredEmail().isEmpty()) { if ( ! names.isEmpty() ) names+= ","; names+= "\""+list[i].realName() +"\"<" +list[i].preferredEmail() +">"; } } if ( line->text().isEmpty() ) { line->setText( names ); } else if ( !names.isEmpty() ) { line->setText( line->text() + ", " + names ); } #else bool res = ExternalAppHandler::instance()->requestNameEmailUidListFromKAPI("QPE/Application/ompi", this->name() /* name is here the unique uid*/); // the result should now arrive through method insertAttendees #endif } //the map includes name/email pairs, that comes from Ka/Pi void ComposeMail::insertAttendees(const QString& uid,const QStringList& nameList,const QStringList& emailList,const QStringList& uidList) { //qDebug("ComposeMail::insertAttendees "); raise(); if ( mPickLineEdit == 0 ) { //whoami received QString defmail = uidList[0]; if ( emailList.count() == 0 ) - QMessageBox::information( 0, tr( "Hint" ), - tr( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), - tr( "Ok" ) ); + QMessageBox::information( 0, i18n( "Hint" ), + i18n( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), + i18n( "Ok" ) ); if (defmail.length()!=0) { fromBox->insertItem(defmail); } QStringList::ConstIterator sit = emailList.begin(); int pref = 0; for (;sit!=emailList.end();++sit) { if ( (*sit)==defmail) continue; fromBox->insertItem((*sit)); } senderNameEdit->setText(nameList[0]); return; } QString names ; QLineEdit *line = mPickLineEdit; if (uid == this->name()) { for ( int i = 0; i < nameList.count(); i++) { QString _name = nameList[i]; QString _email = emailList[i]; QString _uid = uidList[i]; if ( ! _email.isEmpty() ) { if ( ! names.isEmpty() ) names+= ","; names+= "\""+_name +"\"<" +_email +">"; } } } if ( line->text().isEmpty() ) { line->setText( names ); } else if ( !names.isEmpty() ) { line->setText( line->text() + ", " + names ); } } void ComposeMail::setTo( const QString & to ) { toLine->setText( to ); } void ComposeMail::setSubject( const QString & subject ) { subjectLine->setText( subject ); } void ComposeMail::setInReplyTo( const QString & messageId ) { m_replyid = messageId; } void ComposeMail::setMessage( const QString & text ) { message->setText( text ); } void ComposeMail::pickAddressTo() { mPickLineEdit = toLine; pickAddress( ); } void ComposeMail::pickAddressCC() { mPickLineEdit = ccLine; pickAddress( ); } void ComposeMail::pickAddressBCC() { mPickLineEdit = bccLine; pickAddress( ); } void ComposeMail::pickAddressReply() { mPickLineEdit = replyLine; pickAddress( ); } void ComposeMail::fillValues( int ) { #if 0 SMTPaccount *smtp = smtpAccounts.at( current ); ccLine->clear(); if ( smtp->getUseCC() ) { ccLine->setText( smtp->getCC() ); } bccLine->clear(); if ( smtp->getUseBCC() ) { bccLine->setText( smtp->getBCC() ); } replyLine->clear(); if ( smtp->getUseReply() ) { replyLine->setText( smtp->getReply() ); } sigMultiLine->setText( smtp->getSignature() ); #endif } void ComposeMail::slotAdjustColumns() { int currPage = tabWidget->currentPageIndex(); tabWidget->showPage( attachTab ); attList->setColumnWidth( 0, attList->visibleWidth() - 80 ); attList->setColumnWidth( 1, 80 ); tabWidget->setCurrentPage( currPage ); } void ComposeMail::addAttachment() { QString lnk = KFileDialog::getOpenFileName( "", "Add Attachment", this ); if ( !lnk.isEmpty() ) { Attachment *att = new Attachment( lnk ); (void) new AttachViewItem( attList, att ); } } void ComposeMail::removeAttachment() { if ( !attList->currentItem() ) { - QMessageBox::information( this, tr( "Error" ), - tr( "<p>Please select a File.</p>" ), - tr( "Ok" ) ); + QMessageBox::information( this, i18n( "Error" ), + i18n( "<p>Please select a File.</p>" ), + i18n( "Ok" ) ); } else { attList->takeItem( attList->currentItem() ); } } void ComposeMail::accept() { if ( smtpAccountBox->count() == 0 ) { reject(); return; } if (! checkBoxLater->isChecked() ) { - int yesno = QMessageBox::warning(0,tr("Stop editing message"), - tr("Send this message?"), - tr("Yes"), - tr("Cancel")); + int yesno = QMessageBox::warning(0,i18n("Stop editing message"), + i18n("Send this message?"), + i18n("Yes"), + i18n("Cancel")); if (yesno == 1) { return; } } #if 0 odebug << "Sending Mail with " << smtpAccounts.at( smtpAccountBox->currentItem() )->getAccountName() << oendl; #endif Opie::Core::OSmartPointer<Mail> mail=new Mail; SMTPaccount *smtp = smtpAccounts.at( smtpAccountBox->currentItem() ); mail->setMail(fromBox->currentText()); if ( !toLine->text().isEmpty() ) { mail->setTo( toLine->text() ); } else { - QMessageBox::warning(0,tr("Sending mail"), - tr("No Receiver spezified" ) ); + QMessageBox::warning(0,i18n("Sending mail"), + i18n("No Receiver spezified" ) ); return; } mail->setName(senderNameEdit->text()); mail->setCC( ccLine->text() ); mail->setBCC( bccLine->text() ); mail->setReply( replyLine->text() ); mail->setSubject( subjectLine->text() ); if (!m_replyid.isEmpty()) { QStringList ids; ids.append(m_replyid); mail->setInreply(ids); } QString txt = message->text(); if ( !sigMultiLine->text().isEmpty() ) { txt.append( "\n--\n" ); txt.append( sigMultiLine->text() ); } mail->setMessage( txt ); AttachViewItem *it = (AttachViewItem *) attList->firstChild(); while ( it != 0 ) { mail->addAttachment( it->getAttachment() ); it = (AttachViewItem *) it->nextSibling(); } SMTPwrapper wrapper( smtp ); if ( wrapper.sendMail( mail,checkBoxLater->isChecked() ) ) setStatus( tr ("Mail sent")); else { setStatus( tr ("Error: Something went wrong. Nothing sent")); return; } QDialog::accept(); } void ComposeMail::reject() { //qDebug("ComposeMail::reject() "); - int yesno = QMessageBox::warning(0,tr("Store message?"), - tr("Store message into drafts?\n"), - tr("Yes"), - tr("No")); + int yesno = QMessageBox::warning(0,i18n("Store message?"), + i18n("Store message into drafts?\n"), + i18n("Yes"), + i18n("No")); //qDebug("button %d ", yesno); if (yesno == 0) { if ( toLine->text().isEmpty() ) { - QMessageBox::warning(0,tr("Sending mail"), - tr("No Receiver spezified" ) ); + QMessageBox::warning(0,i18n("Sending mail"), + i18n("No Receiver spezified" ) ); return; } saveAsDraft(); } if (yesno == 2) { qDebug("return "); return; } QDialog::reject(); } ComposeMail::~ComposeMail() { } void ComposeMail::reEditMail(const RecMailP¤t) { RecMailP data = current; message->setText(data->Wrapper()->fetchBody(current)->Bodytext()); subjectLine->setText( data->getSubject()); toLine->setText(data->To().join(",")); ccLine->setText(data->CC().join(",")); bccLine->setText(data->Bcc().join(",")); replyLine->setText(data->Replyto()); } AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) : QListViewItem( parent ) { attachment = att; if ( !attachment->getPixmap().isNull() ) setPixmap( 0,attachment->getPixmap() ); setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() ); setText( 1, QString::number( att->getSize() ) ); } diff --git a/kmicromail/editaccounts.cpp b/kmicromail/editaccounts.cpp index 733e38a..7ad4ec8 100644 --- a/kmicromail/editaccounts.cpp +++ b/kmicromail/editaccounts.cpp @@ -1,661 +1,662 @@ #include "defines.h" #include "editaccounts.h" #include "kapplication.h" /* OPIE */ #include <qpe/qpeapplication.h> /* QT */ #include <qstringlist.h> #include <qcombobox.h> #include <qcheckbox.h> #include <qmessagebox.h> #include <qpushbutton.h> #include <qlineedit.h> #include <qlabel.h> #include <qtabwidget.h> #include <qlistview.h> #include <qspinbox.h> +#include <klocale.h> #include <libmailwrapper/nntpwrapper.h> using namespace Opie::Core; AccountListItem::AccountListItem( QListView *parent, Account *a) : QListViewItem( parent ) { account = a; setText( 0, account->getAccountName() ); QString ttext = ""; switch (account->getType()) { case MAILLIB::A_NNTP: ttext="NNTP"; break; case MAILLIB::A_POP3: ttext = "POP3"; break; case MAILLIB::A_IMAP: ttext = "IMAP"; break; case MAILLIB::A_SMTP: ttext = "SMTP"; break; default: ttext = "UNKNOWN"; break; } setText( 1, ttext); } EditAccounts::EditAccounts( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) : EditAccountsUI( parent, name, modal, flags ) { settings = s; - mailList->addColumn( tr( "Account" ) ); - mailList->addColumn( tr( "Type" ) ); + mailList->addColumn( i18n( "Account" ) ); + mailList->addColumn( i18n( "Type" ) ); - newsList->addColumn( tr( "Account" ) ); + newsList->addColumn( i18n( "Account" ) ); connect( newMail, SIGNAL( clicked() ), SLOT( slotNewMail() ) ); connect( editMail, SIGNAL( clicked() ), SLOT( slotEditMail() ) ); connect( deleteMail, SIGNAL( clicked() ), SLOT( slotDeleteMail() ) ); connect( newNews, SIGNAL( clicked() ), SLOT( slotNewNews() ) ); connect( editNews, SIGNAL( clicked() ), SLOT( slotEditNews() ) ); connect( deleteNews, SIGNAL( clicked() ), SLOT( slotDeleteNews() ) ); slotFillLists(); } void EditAccounts::slotFillLists() { mailList->clear(); newsList->clear(); QList<Account> accounts = settings->getAccounts(); Account *it; for ( it = accounts.first(); it; it = accounts.next() ) { if ( it->getType()==MAILLIB::A_NNTP ) { (void) new AccountListItem( newsList, it ); } else { (void) new AccountListItem( mailList, it ); } } } void EditAccounts::slotNewMail() { QString *selection = new QString(); SelectMailType selType( selection, this, 0, true ); selType.show(); if ( QDialog::Accepted == selType.exec() ) { slotNewAccount( *selection ); } } void EditAccounts::slotNewAccount( const QString &type ) { if ( type.compare( "IMAP" ) == 0 ) { IMAPaccount *account = new IMAPaccount(); IMAPconfig imap( account, this, 0, true ); imap.showMaximized(); if ( QDialog::Accepted == imap.exec() ) { settings->addAccount( account ); account->save(); slotFillLists(); } else { account->remove(); } } else if ( type.compare( "POP3" ) == 0 ) { POP3account *account = new POP3account(); POP3config pop3( account, this, 0, true, WStyle_ContextHelp ); if ( QDialog::Accepted == KApplication::execDialog( &pop3 ) ) { settings->addAccount( account ); account->save(); slotFillLists(); } else { account->remove(); } } else if ( type.compare( "SMTP" ) == 0 ) { SMTPaccount *account = new SMTPaccount(); SMTPconfig smtp( account, this, 0, true, WStyle_ContextHelp ); if ( QDialog::Accepted == KApplication::execDialog( &smtp ) ) { settings->addAccount( account ); account->save(); slotFillLists(); } else { account->remove(); } } else if ( type.compare( "NNTP" ) == 0 ) { NNTPaccount *account = new NNTPaccount(); NNTPconfig nntp( account, this, 0, true, WStyle_ContextHelp ); if ( QDialog::Accepted == KApplication::execDialog( &nntp ) ) { settings->addAccount( account ); account->save(); slotFillLists(); } else { account->remove(); } } } void EditAccounts::slotEditAccount( Account *account ) { if ( account->getType() == MAILLIB::A_IMAP ) { IMAPaccount *imapAcc = static_cast<IMAPaccount *>(account); IMAPconfig imap( imapAcc, this, 0, true, WStyle_ContextHelp ); if ( QDialog::Accepted == KApplication::execDialog( &imap ) ) { slotFillLists(); } } else if ( account->getType()==MAILLIB::A_POP3 ) { POP3account *pop3Acc = static_cast<POP3account *>(account); POP3config pop3( pop3Acc, this, 0, true, WStyle_ContextHelp ); if ( QDialog::Accepted == KApplication::execDialog( &pop3 ) ) { slotFillLists(); } } else if ( account->getType()==MAILLIB::A_SMTP ) { SMTPaccount *smtpAcc = static_cast<SMTPaccount *>(account); SMTPconfig smtp( smtpAcc, this, 0, true, WStyle_ContextHelp ); if ( QDialog::Accepted == KApplication::execDialog( &smtp ) ) { slotFillLists(); } } else if ( account->getType()==MAILLIB::A_NNTP) { NNTPaccount *nntpAcc = static_cast<NNTPaccount *>(account); NNTPconfig nntp( nntpAcc, this, 0, true, WStyle_ContextHelp ); if ( QDialog::Accepted == KApplication::execDialog( &nntp ) ) { slotFillLists(); } } } void EditAccounts::slotDeleteAccount( Account *account ) { - if ( QMessageBox::information( this, tr( "Question" ), - tr( "<p>Do you really want to delete the selected Account?</p>" ), - tr( "Yes" ), tr( "No" ) ) == 0 ) + if ( QMessageBox::information( this, i18n( "Question" ), + i18n( "<p>Do you really want to delete the selected Account?</p>" ), + i18n( "Yes" ), i18n( "No" ) ) == 0 ) { settings->delAccount( account ); slotFillLists(); } } void EditAccounts::slotEditMail() { if ( !mailList->currentItem() ) { - QMessageBox::information( this, tr( "Error" ), - tr( "<p>Please select an account.</p>" ), - tr( "Ok" ) ); + QMessageBox::information( this, i18n( "Error" ), + i18n( "<p>Please select an account.</p>" ), + i18n( "Ok" ) ); return; } Account *a = ((AccountListItem *) mailList->currentItem())->getAccount(); slotEditAccount( a ); } void EditAccounts::slotDeleteMail() { if ( !mailList->currentItem() ) { - QMessageBox::information( this, tr( "Error" ), - tr( "<p>Please select an account.</p>" ), - tr( "Ok" ) ); + QMessageBox::information( this, i18n( "Error" ), + i18n( "<p>Please select an account.</p>" ), + i18n( "Ok" ) ); return; } Account *a = ((AccountListItem *) mailList->currentItem())->getAccount(); slotDeleteAccount( a ); } void EditAccounts::slotNewNews() { slotNewAccount( "NNTP" ); } void EditAccounts::slotEditNews() { if ( !newsList->currentItem() ) { - QMessageBox::information( this, tr( "Error" ), - tr( "<p>Please select an account.</p>" ), - tr( "Ok" ) ); + QMessageBox::information( this, i18n( "Error" ), + i18n( "<p>Please select an account.</p>" ), + i18n( "Ok" ) ); return; } Account *a = ((AccountListItem *) newsList->currentItem())->getAccount(); slotEditAccount( a ); } void EditAccounts::slotDeleteNews() { if ( !newsList->currentItem() ) { - QMessageBox::information( this, tr( "Error" ), - tr( "<p>Please select an account.</p>" ), - tr( "Ok" ) ); + QMessageBox::information( this, i18n( "Error" ), + i18n( "<p>Please select an account.</p>" ), + i18n( "Ok" ) ); return; } Account *a = ((AccountListItem *) newsList->currentItem())->getAccount(); slotDeleteAccount( a ); } void EditAccounts::slotAdjustColumns() { int currPage = configTab->currentPageIndex(); configTab->showPage( mailTab ); mailList->setColumnWidth( 0, mailList->visibleWidth() - 50 ); mailList->setColumnWidth( 1, 50 ); configTab->showPage( newsTab ); newsList->setColumnWidth( 0, newsList->visibleWidth() ); configTab->setCurrentPage( currPage ); } void EditAccounts::accept() { settings->saveAccounts(); QDialog::accept(); } /** * SelectMailType */ SelectMailType::SelectMailType( QString *selection, QWidget *parent, const char *name, bool modal, WFlags flags ) : SelectMailTypeUI( parent, name, modal, flags ) { selected = selection; selected->replace( 0, selected->length(), typeBox->currentText() ); connect( typeBox, SIGNAL( activated(const QString&) ), SLOT( slotSelection(const QString&) ) ); } void SelectMailType::slotSelection( const QString &sel ) { selected->replace( 0, selected->length(), sel ); } /** * IMAPconfig */ IMAPconfig::IMAPconfig( IMAPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags ) : IMAPconfigUI( parent, name, modal, flags ) { data = account; fillValues(); connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) ); ComboBox1->insertItem( "Only if available", 0 ); ComboBox1->insertItem( "Always, Negotiated", 1 ); ComboBox1->insertItem( "Connect on secure port", 2 ); ComboBox1->insertItem( "Run command instead", 3 ); CommandEdit->hide(); ComboBox1->setCurrentItem( data->ConnectionType() ); } void IMAPconfig::slotConnectionToggle( int index ) { if ( index == 2 ) { portLine->setText( IMAP_SSL_PORT ); } else if ( index == 3 ) { portLine->setText( IMAP_PORT ); CommandEdit->show(); } else { portLine->setText( IMAP_PORT ); } } void IMAPconfig::fillValues() { accountLine->setText( data->getAccountName() ); serverLine->setText( data->getServer() ); portLine->setText( data->getPort() ); ComboBox1->setCurrentItem( data->ConnectionType() ); userLine->setText( data->getUser() ); passLine->setText( data->getPassword() ); prefixLine->setText(data->getPrefix()); localFolder->setText( data->getLocalFolder() ); int max = data->getMaxMailSize() ; if ( max ) { CheckBoxDown->setChecked( true ); SpinBoxDown->setValue ( max ); } else { CheckBoxDown->setChecked( false ); SpinBoxDown->setValue ( 5 ); } CheckBoxLeaveOn->setChecked( data->getLeaveOnServer() ); } void IMAPconfig::accept() { data->setAccountName( accountLine->text() ); data->setServer( serverLine->text() ); data->setPort( portLine->text() ); data->setConnectionType( ComboBox1->currentItem() ); data->setUser( userLine->text() ); data->setPassword( passLine->text() ); data->setPrefix(prefixLine->text()); data->setLocalFolder( localFolder->text() ); data->setMaxMailSize( CheckBoxDown->isChecked()?SpinBoxDown->value():0 ) ; data->setLeaveOnServer( CheckBoxLeaveOn->isChecked() ); QDialog::accept(); } /** * POP3config */ POP3config::POP3config( POP3account *account, QWidget *parent, const char *name, bool modal, WFlags flags ) : POP3configUI( parent, name, modal, flags ) { data = account; fillValues(); connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) ); ComboBox1->insertItem( "Only if available", 0 ); ComboBox1->insertItem( "Always, Negotiated", 1 ); ComboBox1->insertItem( "Connect on secure port", 2 ); ComboBox1->insertItem( "Run command instead", 3 ); CommandEdit->hide(); ComboBox1->setCurrentItem( data->ConnectionType() ); } void POP3config::slotConnectionToggle( int index ) { // 2 is ssl connection if ( index == 2 ) { portLine->setText( POP3_SSL_PORT ); } else if ( index == 3 ) { portLine->setText( POP3_PORT ); CommandEdit->show(); } else { portLine->setText( POP3_PORT ); } } void POP3config::fillValues() { accountLine->setText( data->getAccountName() ); serverLine->setText( data->getServer() ); portLine->setText( data->getPort() ); ComboBox1->setCurrentItem( data->ConnectionType() ); userLine->setText( data->getUser() ); passLine->setText( data->getPassword() ); localFolder->setText( data->getLocalFolder() ); int max = data->getMaxMailSize() ; if ( max ) { CheckBoxDown->setChecked( true ); SpinBoxDown->setValue ( max ); } else { CheckBoxDown->setChecked( false ); SpinBoxDown->setValue ( 5 ); } CheckBoxLeaveOn->setChecked( data->getLeaveOnServer() ); } void POP3config::accept() { data->setAccountName( accountLine->text() ); data->setServer( serverLine->text() ); data->setPort( portLine->text() ); data->setConnectionType( ComboBox1->currentItem() ); data->setUser( userLine->text() ); data->setPassword( passLine->text() ); data->setLocalFolder( localFolder->text() ); data->setMaxMailSize( CheckBoxDown->isChecked()?SpinBoxDown->value():0 ) ; data->setLeaveOnServer( CheckBoxLeaveOn->isChecked() ); QDialog::accept(); } /** * SMTPconfig */ SMTPconfig::SMTPconfig( SMTPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags ) : SMTPconfigUI( parent, name, modal, flags ) { data = account; connect( loginBox, SIGNAL( toggled(bool) ), userLine, SLOT( setEnabled(bool) ) ); connect( loginBox, SIGNAL( toggled(bool) ), passLine, SLOT( setEnabled(bool) ) ); fillValues(); connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) ); ComboBox1->insertItem( "Only if available", 0 ); ComboBox1->insertItem( "Always, Negotiated", 1 ); ComboBox1->insertItem( "Connect on secure port", 2 ); ComboBox1->insertItem( "Run command instead", 3 ); CommandEdit->hide(); ComboBox1->setCurrentItem( data->ConnectionType() ); } void SMTPconfig::slotConnectionToggle( int index ) { // 2 is ssl connection if ( index == 2 ) { portLine->setText( SMTP_SSL_PORT ); } else if ( index == 3 ) { portLine->setText( SMTP_PORT ); CommandEdit->show(); } else { portLine->setText( SMTP_PORT ); } } void SMTPconfig::fillValues() { accountLine->setText( data->getAccountName() ); serverLine->setText( data->getServer() ); portLine->setText( data->getPort() ); ComboBox1->setCurrentItem( data->ConnectionType() ); loginBox->setChecked( data->getLogin() ); userLine->setText( data->getUser() ); passLine->setText( data->getPassword() ); } void SMTPconfig::accept() { data->setAccountName( accountLine->text() ); data->setServer( serverLine->text() ); data->setPort( portLine->text() ); data->setConnectionType( ComboBox1->currentItem() ); data->setLogin( loginBox->isChecked() ); data->setUser( userLine->text() ); data->setPassword( passLine->text() ); QDialog::accept(); } /** * NNTPconfig */ NNTPconfig::NNTPconfig( NNTPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags ) : NNTPconfigUI( parent, name, modal, flags ) { data = account; connect( loginBox, SIGNAL( toggled(bool) ), userLine, SLOT( setEnabled(bool) ) ); connect( loginBox, SIGNAL( toggled(bool) ), passLine, SLOT( setEnabled(bool) ) ); connect( GetNGButton, SIGNAL( clicked() ), this, SLOT( slotGetNG() ) ); connect( ShowSubcribed, SIGNAL( clicked() ), this, SLOT( slotShowSub() ) ); connect( FilterButton, SIGNAL( clicked() ), this, SLOT( slotShowFilter() ) ); fillValues(); connect( sslBox, SIGNAL( toggled(bool) ), SLOT( slotSSL(bool) ) ); } void NNTPconfig::slotShowSub() { save(); data->save(); ListViewGroups->clear(); for ( QStringList::Iterator it = subscribedGroups.begin(); it != subscribedGroups.end(); ++it ) { QCheckListItem *item; item = new QCheckListItem( ListViewGroups, (*it), QCheckListItem::CheckBox ); item->setOn( true ); } - topLevelWidget()->setCaption( tr("%1 groups subscribed").arg( subscribedGroups.count())); + topLevelWidget()->setCaption( i18n("%1 groups subscribed").arg( subscribedGroups.count())); } void NNTPconfig::slotShowFilter() { save(); data->save(); ListViewGroups->clear(); int count = 0; for ( QStringList::Iterator it = allGroups.begin(); it != allGroups.end(); ++it ) { QCheckListItem *item; if ( GroupFilter->text().isEmpty() || (*it).find( GroupFilter->text() ) >= 0 ) { item = new QCheckListItem( ListViewGroups, (*it), QCheckListItem::CheckBox ); ++count; if ( subscribedGroups.contains( (*it) ) >= 1 ) { item->setOn( true ); } } } - topLevelWidget()->setCaption( tr("Filter found %1 groups").arg( count)); + topLevelWidget()->setCaption( i18n("Filter found %1 groups").arg( count)); } void NNTPconfig::slotGetNG() { save(); data->save(); - topLevelWidget()->setCaption( tr("Fetching group list...")); + topLevelWidget()->setCaption( i18n("Fetching group list...")); qApp->processEvents(); NNTPwrapper* tmp = new NNTPwrapper( data ); allGroups = tmp->listAllNewsgroups(); - topLevelWidget()->setCaption( tr("Downloaded %1 group names").arg( allGroups.count())); + topLevelWidget()->setCaption( i18n("Downloaded %1 group names").arg( allGroups.count())); ListViewGroups->clear(); for ( QStringList::Iterator it = allGroups.begin(); it != allGroups.end(); ++it ) { QCheckListItem *item; item = new QCheckListItem( ListViewGroups, (*it), QCheckListItem::CheckBox ); if ( subscribedGroups.contains( (*it) ) >= 1 ) { item->setOn( true ); } } delete tmp; } void NNTPconfig::slotSSL( bool enabled ) { if ( enabled ) { portLine->setText( NNTP_SSL_PORT ); } else { portLine->setText( NNTP_PORT ); } } void NNTPconfig::fillValues() { accountLine->setText( data->getAccountName() ); serverLine->setText( data->getServer() ); portLine->setText( data->getPort() ); sslBox->setChecked( data->getSSL() ); loginBox->setChecked( data->getLogin() ); userLine->setText( data->getUser() ); passLine->setText( data->getPassword() ); subscribedGroups = data->getGroups(); /* don't forget that - you will overwrite values if user clicks cancel! */ for ( QStringList::Iterator it = subscribedGroups.begin(); it != subscribedGroups.end(); ++it ) { QCheckListItem *item; item = new QCheckListItem( ListViewGroups, (*it), QCheckListItem::CheckBox ); item->setOn( true ); } } void NNTPconfig::save() { data->setAccountName( accountLine->text() ); data->setServer( serverLine->text() ); data->setPort( portLine->text() ); data->setSSL( sslBox->isChecked() ); data->setLogin( loginBox->isChecked() ); data->setUser( userLine->text() ); data->setPassword( passLine->text() ); QListViewItemIterator list_it( ListViewGroups ); for ( ; list_it.current(); ++list_it ) { if ( ( (QCheckListItem*)list_it.current() )->isOn() ) { if ( subscribedGroups.contains( list_it.current()->text(0) ) < 1 ) subscribedGroups.append( list_it.current()->text(0) ); } else { if ( subscribedGroups.contains( list_it.current()->text(0) ) >= 1 ) subscribedGroups.remove( list_it.current()->text(0) ); } } data->setGroups( subscribedGroups ); } void NNTPconfig::accept() { save(); QDialog::accept(); } diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp index 2d7533c..8ee112c 100644 --- a/kmicromail/libmailwrapper/abstractmail.cpp +++ b/kmicromail/libmailwrapper/abstractmail.cpp @@ -1,278 +1,278 @@ // CHANGED 2004-09-31 Lutz Rogowski #include "abstractmail.h" #include "imapwrapper.h" #include "pop3wrapper.h" #include "nntpwrapper.h" #include "mhwrapper.h" #include "mailtypes.h" #include <qpe/global.h> #include <qprogressbar.h> #include <qapplication.h> #include <qmessagebox.h> - +#include <klocale.h> #include <kdecore/kstandarddirs.h> #include <qfile.h> #include <qtextstream.h> #include <stdlib.h> #include <libetpan/mailmime_content.h> #include <libetpan/mailmime.h> using namespace Opie::Core; AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) { return new IMAPwrapper(a); } AbstractMail* AbstractMail::getWrapper(POP3account *a) { return new POP3wrapper(a); } AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) { return new NNTPwrapper(a); } AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) { return new MHwrapper(a,name); } AbstractMail* AbstractMail::getWrapper(Account*a) { if (!a) return 0; switch (a->getType()) { case MAILLIB::A_IMAP: return new IMAPwrapper((IMAPaccount*)a); break; case MAILLIB::A_POP3: return new POP3wrapper((POP3account*)a); break; case MAILLIB::A_NNTP: return new NNTPwrapper((NNTPaccount*)a); break; default: return 0; } } encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) { // odebug << "Decode string start" << oendl; char*result_text; size_t index = 0; /* reset for recursive use! */ size_t target_length = 0; result_text = 0; int mimetype = MAILMIME_MECHANISM_7BIT; if (enc.lower()=="quoted-printable") { mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; } else if (enc.lower()=="base64") { mimetype = MAILMIME_MECHANISM_BASE64; } else if (enc.lower()=="8bit") { mimetype = MAILMIME_MECHANISM_8BIT; } else if (enc.lower()=="binary") { mimetype = MAILMIME_MECHANISM_BINARY; } int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, &result_text,&target_length); encodedString* result = new encodedString(); if (err == MAILIMF_NO_ERROR) { result->setContent(result_text,target_length); } //odebug << "Decode string finished" << oendl; return result; } QString AbstractMail::convert_String(const char*text) { size_t index = 0; char*res = 0; int err = MAILIMF_NO_ERROR; QString result(text); err = mailmime_encoded_phrase_parse("iso-8859-1", text, strlen(text),&index, "iso-8859-1",&res); if (err == MAILIMF_NO_ERROR && res && strlen(res)) { result = QString(res); } //qDebug("convert_String:%s ",result.latin1() ); if (res) free(res); return result; } /* cp & paste from launcher */ QString AbstractMail::gen_attachment_id() { QFile file( "/proc/sys/kernel/random/uuid" ); if (!file.open(IO_ReadOnly ) ) return QString::null; QTextStream stream(&file); return "{" + stream.read().stripWhiteSpace() + "}"; } int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) { return 0; } QString AbstractMail::defaultLocalfolder() { // QString f = getenv( "HOME" ); QString f = locateLocal( "data", "kopiemail/localmail"); // f += "/Applications/opiemail/localmail"; return f; } QString AbstractMail::draftFolder() { return QString("Drafts"); } /* temporary - will be removed when implemented in all classes */ void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) { } void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) { //qDebug("AbstractMail::deleteMailList:: Please reimplement! "); // this is currently re-implemented in pop3wrapper and imapwrapper int iii = 0; int count = target.count(); QProgressBar wid ( count ); - wid.setCaption( tr("Deleting ...")); + wid.setCaption( i18n("Deleting ...")); wid.show(); while (iii < count ) { - Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count)); + Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); wid.setProgress( iii ); wid.raise(); qApp->processEvents(); RecMailP mail = (*target.at( iii )); deleteMail(mail); ++iii; } } void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail ) { //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1()); // get local folder Account * acc = getAccount(); if ( !acc ) return; QString lfName = acc->getLocalFolder(); if ( lfName.isEmpty() ) lfName = acc->getAccountName(); // create local folder if ( !targetMail->createMbox(lfName)) { - QMessageBox::critical(0,tr("Error creating new Folder"), - tr("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName)); + QMessageBox::critical(0,i18n("Error creating new Folder"), + i18n("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName)); return; } QValueList<RecMailP> t; listMessages(fromFolder->getName(),t,acc->getMaxMailSize() ); if ( t.count() == 0 ) { qDebug("There are no new messages %s", fromFolder->getName().latin1()); - Global::statusMessage(tr("There are no new messages")); + Global::statusMessage(i18n("There are no new messages")); return; } QValueList<RecMailP> e; targetMail->listMessages(lfName,e,acc->getMaxMailSize() ); //qDebug("target has mails %d ", e.count()); QValueList<RecMailP> n; int iii = 0; int count = t.count(); while (iii < count ) { RecMailP r = (*t.at( iii )); bool found = false; int jjj = 0; int countE = e.count(); while (jjj < countE ) { RecMailP re = (*e.at( jjj )); if ( re->isEqual(r) ) { found = true; break; } ++jjj; } if ( !found ) { //qDebug("AAAdate *%s* ", r->isodate.latin1() ); n.append( r ); } ++iii; } qDebug("Downloaded %d messages ",n.count() ); if ( n.count() == 0 ) { - Global::statusMessage(tr("There are no new messages")); + Global::statusMessage(i18n("There are no new messages")); return; } mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer()); - Global::statusMessage(tr("Downloaded %1 messages").arg(n.count())); + Global::statusMessage(i18n("Downloaded %1 messages").arg(n.count())); #if 0 QValueList<RecMailP> t; listMessages(fromFolder->getName(),t, maxSizeInKb); mvcpMailList( t,targetFolder,targetWrapper,moveit); #endif } void AbstractMail::mvcpAllMails(const FolderP&fromFolder, const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) { QValueList<RecMailP> t; listMessages(fromFolder->getName(),t, maxSizeInKb); mvcpMailList( t,targetFolder,targetWrapper,moveit); } void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) { encodedString*st = 0; int iii = 0; int count = t.count(); if ( count == 0 ) return; // wel, processevents is qite strange, we need a widget for getting - // Global::statusMessage(tr("Copy2 message %1").arg(iii)); displaye + // Global::statusMessage(i18n("Copy2 message %1").arg(iii)); displaye QProgressBar wid ( count ); - wid.setCaption( tr("Copying ...")); + wid.setCaption( i18n("Copying...")); wid.show(); while (iii < count ) { - Global::statusMessage(tr("Copy message %1 of %2").arg(iii).arg(count)); + Global::statusMessage(i18n("Copy message %1 of %2").arg(iii).arg(count)); wid.setProgress( iii ); wid.raise(); qApp->processEvents(); RecMailP r = (*t.at( iii )); st = fetchRawBody(r); if (st) { targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); delete st; } ++iii; } if (moveit) { deleteMailList( t ); //deleteAllMail(fromFolder); } } void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) { encodedString*st = 0; st = fetchRawBody(mail); if (st) { targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); delete st; } if (moveit) { deleteMail(mail); } } diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index 8150453..3aec13d 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp @@ -1,1336 +1,1336 @@ // CHANGED 2004-09-31 Lutz Rogowski #include <stdlib.h> #include <libetpan/libetpan.h> #include <qpe/global.h> #include <qapplication.h> #include "imapwrapper.h" #include "mailtypes.h" #include "logindialog.h" #include <qprogressbar.h> #include "genericwrapper.h" #include <kglobal.h> using namespace Opie::Core; int IMAPwrapper::mMax = 0; int IMAPwrapper::mCurrent = 0; IMAPwrapper::IMAPwrapper( IMAPaccount *a ) : AbstractMail() { account = a; m_imap = 0; m_Lastmbox = ""; mCurrent = 0; mMax = 0; } IMAPwrapper::~IMAPwrapper() { logout(); } /* to avoid to often select statements in loops etc. we trust that we are logged in and connection is established!*/ int IMAPwrapper::selectMbox(const QString&mbox) { if (mbox == m_Lastmbox) { return MAILIMAP_NO_ERROR; } int err = mailimap_select( m_imap, (char*)mbox.latin1()); if ( err != MAILIMAP_NO_ERROR ) { m_Lastmbox = ""; return err; } m_Lastmbox = mbox; return err; } void IMAPwrapper::imap_progress( size_t current, size_t maximum ) { //qDebug("imap progress %d of %d ",current,maximum ); - //Global::statusMessage(tr("Downloading message %1 of %2").arg( current).arg(maximum)); + //Global::statusMessage(i18n("Downloading message %1 of %2").arg( current).arg(maximum)); //qApp->processEvents() static int last = 0; if ( last != current ) IMAPwrapper::progress(); last = current; } void IMAPwrapper::progress( QString m ) { static QString mProgrMess; if ( m != QString::null ) { mProgrMess = m; mCurrent = 1; return; } QString mess; //qDebug("progress "); - if ( mMax ) mess = mProgrMess +tr(" message %1 of %2").arg( mCurrent++).arg(mMax); - else mess = mProgrMess +tr(" message %1").arg( mCurrent++); + if ( mMax ) mess = mProgrMess +i18n(" message %1 of %2").arg( mCurrent++).arg(mMax); + else mess = mProgrMess +i18n(" message %1").arg( mCurrent++); Global::statusMessage(mess); //qDebug("Progress %s %s", mess.latin1(), m.latin1()); qApp->processEvents(); } bool IMAPwrapper::start_tls(bool force_tls) { int err; bool try_tls; mailimap_capability_data * cap_data = 0; 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!")); + Global::statusMessage(i18n("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 "); 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)); + Global::statusMessage(i18n("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!")); + Global::statusMessage(i18n("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)); + Global::statusMessage(i18n("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 tryAgain = 1; while ( tryAgain >= 0 ) { 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")); + Global::statusMessage(i18n("Mailbox has no mails")); return; } else { } - progress( tr("Fetch ")); + progress( i18n("Fetch ")); mMax = last; //qDebug("last %d ", last); - Global::statusMessage(tr("Fetching header list")); + Global::statusMessage(i18n("Fetching header list")); qApp->processEvents(); /* the range has to start at 1!!! not with 0!!!! */ //LR the access to web.de imap server is no working with value 1 //qDebug("interval %d - %d ", tryAgain, last-1+tryAgain ); set = mailimap_set_new_interval( tryAgain, 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 ); mailimap_fetch_type_free( fetchType ); QString date,subject,from; if ( err == MAILIMAP_NO_ERROR ) { tryAgain = -1; mailimap_msg_att * msg_att; int i = 0; for (current = clist_begin(result); current != 0; current=clist_next(current)) { ++i; //qDebug("iii %d ",i); msg_att = (mailimap_msg_att*)current->data; RecMail*m = parse_list_result(msg_att); if (m) { if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) { m->setNumber(i); m->setMbox(mailbox); m->setWrapper(this); target.append(m); } } } - Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); + Global::statusMessage(i18n("Mailbox has %1 mails").arg(target.count())); } else { --tryAgain; --tryAgain;//disabled tryagain by adding this line if ( tryAgain < 0 ) - Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); + Global::statusMessage(i18n("Error fetching headers: %1").arg(m_imap->imap_response)); else qDebug("try again... "); } if (result) mailimap_fetch_list_free(result); } } QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() { const char *path, *mask; int err = MAILIMAP_NO_ERROR; clist *result = 0; clistcell *current = 0; clistcell*cur_flag = 0; mailimap_mbx_list_flags*bflags = 0; QValueList<FolderP>* folders = new QValueList<FolderP>(); login(); if (!m_imap) { return folders; } /* * First we have to check for INBOX 'cause it sometimes it's not inside the path. * We must not forget to filter them out in next loop! * it seems like ugly code. and yes - it is ugly code. but the best way. */ - Global::statusMessage(tr("Fetching folder list")); + Global::statusMessage(i18n("Fetching folder list")); qApp->processEvents(); QString temp; mask = "INBOX" ; mailimap_mailbox_list *list; err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); QString del; bool selectable = true; bool no_inferiors = false; if ( err == MAILIMAP_NO_ERROR ) { current = result->first; for ( int i = result->count; i > 0; i-- ) { list = (mailimap_mailbox_list *) current->data; // it is better use the deep copy mechanism of qt itself // instead of using strdup! temp = list->mb_name; del = list->mb_delimiter; current = current->next; if ( (bflags = list->mb_flag) ) { selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { no_inferiors = true; } } } folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); } } else { qDebug("error fetching folders: "); } mailimap_list_result_free( result ); /* * second stage - get the other then inbox folders */ mask = "*" ; path = account->getPrefix().latin1(); if (!path) path = ""; err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); if ( err == MAILIMAP_NO_ERROR ) { current = result->first; for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { no_inferiors = false; list = (mailimap_mailbox_list *) current->data; // it is better use the deep copy mechanism of qt itself // instead of using strdup! temp = list->mb_name; if (temp.lower()=="inbox") continue; if (temp.lower()==account->getPrefix().lower()) continue; if ( (bflags = list->mb_flag) ) { selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { no_inferiors = true; } } } del = list->mb_delimiter; folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); } } else { qDebug("error fetching folders "); } if (result) mailimap_list_result_free( result ); return folders; } RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) { RecMail * m = 0; mailimap_msg_att_item *item=0; clistcell *current,*c,*cf; mailimap_msg_att_dynamic*flist; mailimap_flag_fetch*cflag; int size; QBitArray mFlags(7); QStringList addresslist; if (!m_att) { return m; } m = new RecMail(); for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { current = c; size = 0; item = (mailimap_msg_att_item*)current->data; if ( !item ) continue; if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; if (!flist || !flist->att_list) { continue; } cf = flist->att_list->first; if( ! cf ) for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { cflag = (mailimap_flag_fetch*)cf->data; if( ! cflag ) qDebug("imap:not cflag "); if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { switch (cflag->fl_flag->fl_type) { case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ mFlags.setBit(FLAG_ANSWERED); break; case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ mFlags.setBit(FLAG_FLAGGED); break; case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ mFlags.setBit(FLAG_DELETED); break; case MAILIMAP_FLAG_SEEN: /* \Seen flag */ mFlags.setBit(FLAG_SEEN); break; case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ mFlags.setBit(FLAG_DRAFT); break; case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ break; case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ break; default: break; } } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { mFlags.setBit(FLAG_RECENT); } } continue; } if ( item->att_data.att_static == NULL ) continue; if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { mailimap_envelope * head = item->att_data.att_static->att_data.att_env; if ( head == NULL ) continue; if ( head->env_date != NULL ) { m->setDate(head->env_date); struct mailimf_date_time result; struct mailimf_date_time* date = &result; struct mailimf_date_time **re = &date; size_t length = m->getDate().length(); size_t index = 0; if ( mailimf_date_time_parse(head->env_date, length,&index, re ) == MAILIMF_NO_ERROR ) { QDateTime dt = Genericwrapper::parseDateTime( date ); QString ret; if ( dt.date() == QDate::currentDate () ) ret = KGlobal::locale()->formatTime( dt.time(),true); else { ret = KGlobal::locale()->formatDateTime( dt,true,true); } m->setDate( ret ); char tmp[20]; snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); //qDebug("%d iso %s %s ", date->dt_zone, tmp, head->env_date); m->setIsoDate( QString( tmp ) ); } else { m->setIsoDate(head->env_date); } } if ( head->env_subject != NULL ) m->setSubject(convert_String((const char*)head->env_subject)); //m->setSubject(head->env_subject); if (head->env_from!=NULL) { addresslist = address_list_to_stringlist(head->env_from->frm_list); if (addresslist.count()) { m->setFrom(addresslist.first()); } } if (head->env_to!=NULL) { addresslist = address_list_to_stringlist(head->env_to->to_list); m->setTo(addresslist); } if (head->env_cc!=NULL) { addresslist = address_list_to_stringlist(head->env_cc->cc_list); m->setCC(addresslist); } if (head->env_bcc!=NULL) { addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); m->setBcc(addresslist); } /* reply to address, eg. email. */ if (head->env_reply_to!=NULL) { addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); if (addresslist.count()) { m->setReplyto(addresslist.first()); } } if (head->env_in_reply_to!=NULL) { QString h(head->env_in_reply_to); while (h.length()>0 && h[0]=='<') { h.remove(0,1); } while (h.length()>0 && h[h.length()-1]=='>') { h.remove(h.length()-1,1); } if (h.length()>0) { m->setInreply(QStringList(h)); } } if (head->env_message_id != NULL) { m->setMsgid(QString(head->env_message_id)); } } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { #if 0 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); qDebug("time %s ",da.toString().latin1() ); #endif } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { size = item->att_data.att_static->att_data.att_rfc822_size; } } /* msg is already deleted */ if (mFlags.testBit(FLAG_DELETED) && m) { delete m; m = 0; } if (m) { m->setFlags(mFlags); m->setMsgsize(size); } return m; } RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) { RecBodyP body = new RecBody(); const char *mb; int err = MAILIMAP_NO_ERROR; clist *result = 0; clistcell *current; mailimap_fetch_att *fetchAtt = 0; mailimap_fetch_type *fetchType = 0; mailimap_set *set = 0; mailimap_body*body_desc = 0; mb = mail->getMbox().latin1(); login(); if (!m_imap) { return body; } err = selectMbox(mail->getMbox()); if ( err != MAILIMAP_NO_ERROR ) { return body; } /* the range has to start at 1!!! not with 0!!!! */ set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); fetchAtt = mailimap_fetch_att_new_bodystructure(); fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); err = mailimap_fetch( m_imap, set, fetchType, &result ); mailimap_set_free( set ); mailimap_fetch_type_free( fetchType ); if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { mailimap_msg_att * msg_att; msg_att = (mailimap_msg_att*)current->data; mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; QValueList<int> path; body_desc = item->att_data.att_static->att_data.att_body; traverseBody(mail,body_desc,body,0,path); } else { //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; } if (result) mailimap_fetch_list_free(result); return body; } QStringList IMAPwrapper::address_list_to_stringlist(clist*list) { QStringList l; QString from; bool named_from; clistcell *current = NULL; mailimap_address * current_address=NULL; if (!list) { return l; } unsigned int count = 0; for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { from = ""; named_from = false; current_address=(mailimap_address*)current->data; if (current_address->ad_personal_name){ from+=convert_String((const char*)current_address->ad_personal_name); from+=" "; named_from = true; } if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { from+="<"; } if (current_address->ad_mailbox_name) { from+=QString(current_address->ad_mailbox_name); from+="@"; } if (current_address->ad_host_name) { from+=QString(current_address->ad_host_name); } if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { from+=">"; } l.append(QString(from)); if (++count > 99) { break; } } return l; } encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) { encodedString*res=new encodedString; int err; mailimap_fetch_type *fetchType; mailimap_set *set; clistcell*current,*cur; mailimap_section_part * section_part = 0; mailimap_section_spec * section_spec = 0; mailimap_section * section = 0; mailimap_fetch_att * fetch_att = 0; login(); if (!m_imap) { return res; } if (!internal_call) { err = selectMbox(mail->getMbox()); if ( err != MAILIMAP_NO_ERROR ) { return res; } } set = mailimap_set_new_single(mail->getNumber()); clist*id_list = 0; /* if path == empty then its a request for the whole rfc822 mail and generates a "fetch <id> (body[])" statement on imap server */ if (path.count()>0 ) { id_list = clist_new(); for (unsigned j=0; j < path.count();++j) { uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); *p_id = path[j]; clist_append(id_list,p_id); } section_part = mailimap_section_part_new(id_list); section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); } section = mailimap_section_new(section_spec); fetch_att = mailimap_fetch_att_new_body_section(section); fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); clist*result = 0; err = mailimap_fetch( m_imap, set, fetchType, &result ); mailimap_set_free( set ); mailimap_fetch_type_free( fetchType ); if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { mailimap_msg_att * msg_att; msg_att = (mailimap_msg_att*)current->data; mailimap_msg_att_item*msg_att_item; for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { msg_att_item = (mailimap_msg_att_item*)clist_content(cur); if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; /* detach - we take over the content */ msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); } } } } else { ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; } if (result) mailimap_fetch_list_free(result); return res; } /* current_recursion is for recursive calls. current_count means the position inside the internal loop! */ void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, int current_recursion,QValueList<int>recList,int current_count) { if (!body || current_recursion>=10) { return; } switch (body->bd_type) { case MAILIMAP_BODY_1PART: { QValueList<int>countlist = recList; countlist.append(current_count); RecPartP currentPart = new RecPart(); mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; QString id(""); currentPart->setPositionlist(countlist); for (unsigned int j = 0; j < countlist.count();++j) { id+=(j>0?" ":""); id+=QString("%1").arg(countlist[j]); } //odebug << "ID = " << id.latin1() << "" << oendl; currentPart->setIdentifier(id); fillSinglePart(currentPart,part1); /* important: Check for is NULL 'cause a body can be empty! And we put it only into the mail if it is the FIRST part */ if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); target_body->setDescription(currentPart); target_body->setBodytext(body_text); if (countlist.count()>1) { target_body->addPart(currentPart); } } else { target_body->addPart(currentPart); } if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); } } break; case MAILIMAP_BODY_MPART: { QValueList<int>countlist = recList; clistcell*current=0; mailimap_body*current_body=0; unsigned int ccount = 1; mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { current_body = (mailimap_body*)current->data; if (current_body->bd_type==MAILIMAP_BODY_MPART) { RecPartP targetPart = new RecPart(); targetPart->setType("multipart"); fillMultiPart(targetPart,mailDescription); countlist.append(current_count); targetPart->setPositionlist(countlist); target_body->addPart(targetPart); QString id(""); for (unsigned int j = 0; j < countlist.count();++j) { id+=(j>0?" ":""); id+=QString("%1").arg(countlist[j]); } // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; } traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); if (current_body->bd_type==MAILIMAP_BODY_MPART) { countlist = recList; } ++ccount; } } break; default: break; } } void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) { if (!Description) { return; } switch (Description->bd_type) { case MAILIMAP_BODY_TYPE_1PART_TEXT: target_part->setType("text"); fillSingleTextPart(target_part,Description->bd_data.bd_type_text); break; case MAILIMAP_BODY_TYPE_1PART_BASIC: fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); break; case MAILIMAP_BODY_TYPE_1PART_MSG: target_part->setType("message"); fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); break; default: break; } } void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) { if (!which) { return; } QString sub; sub = which->bd_media_text; //odebug << "Type= text/" << which->bd_media_text << "" << oendl; target_part->setSubtype(sub.lower()); target_part->setLines(which->bd_lines); fillBodyFields(target_part,which->bd_fields); } void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) { if (!which) { return; } target_part->setSubtype("rfc822"); //odebug << "Message part" << oendl; /* we set this type to text/plain */ target_part->setLines(which->bd_lines); fillBodyFields(target_part,which->bd_fields); } void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) { if (!which) return; QString sub = which->bd_media_subtype; target_part->setSubtype(sub.lower()); if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { clistcell*cur = 0; mailimap_single_body_fld_param*param=0; for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { param = (mailimap_single_body_fld_param*)cur->data; if (param) { target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); } } } } void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) { if (!which) { return; } QString type,sub; switch (which->bd_media_basic->med_type) { case MAILIMAP_MEDIA_BASIC_APPLICATION: type = "application"; break; case MAILIMAP_MEDIA_BASIC_AUDIO: type = "audio"; break; case MAILIMAP_MEDIA_BASIC_IMAGE: type = "image"; break; case MAILIMAP_MEDIA_BASIC_MESSAGE: type = "message"; break; case MAILIMAP_MEDIA_BASIC_VIDEO: type = "video"; break; case MAILIMAP_MEDIA_BASIC_OTHER: default: if (which->bd_media_basic->med_basic_type) { type = which->bd_media_basic->med_basic_type; } else { type = ""; } break; } if (which->bd_media_basic->med_subtype) { sub = which->bd_media_basic->med_subtype; } else { sub = ""; } // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; target_part->setType(type.lower()); target_part->setSubtype(sub.lower()); fillBodyFields(target_part,which->bd_fields); } void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) { if (!which) return; if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { clistcell*cur; mailimap_single_body_fld_param*param=0; for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { param = (mailimap_single_body_fld_param*)cur->data; if (param) { target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); } } } mailimap_body_fld_enc*enc = which->bd_encoding; QString encoding(""); switch (enc->enc_type) { case MAILIMAP_BODY_FLD_ENC_7BIT: encoding = "7bit"; break; case MAILIMAP_BODY_FLD_ENC_8BIT: encoding = "8bit"; break; case MAILIMAP_BODY_FLD_ENC_BINARY: encoding="binary"; break; case MAILIMAP_BODY_FLD_ENC_BASE64: encoding="base64"; break; case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: encoding="quoted-printable"; break; case MAILIMAP_BODY_FLD_ENC_OTHER: default: if (enc->enc_value) { char*t=enc->enc_value; encoding=QString(enc->enc_value); enc->enc_value=0L; free(t); } } if (which->bd_description) { target_part->setDescription(QString(which->bd_description)); } target_part->setEncoding(encoding); target_part->setSize(which->bd_size); } void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) { //#if 0 mailimap_flag_list*flist; mailimap_set *set; mailimap_store_att_flags * store_flags; int err; login(); //#endif if (!m_imap) { return; } int iii = 0; int count = target.count(); // qDebug("imap remove count %d ", count); mMax = count; - progress( tr("Delete")); + progress( i18n("Delete")); QProgressBar wid ( count ); - wid.setCaption( tr("Deleting ...")); + wid.setCaption( i18n("Deleting ...")); wid.show(); while (iii < count ) { - Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count)); + Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); wid.setProgress( iii ); wid.raise(); qApp->processEvents(); RecMailP mail = (*target.at( iii )); //#if 0 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() ); err = selectMbox(mail->getMbox()); if ( err != MAILIMAP_NO_ERROR ) { return; } flist = mailimap_flag_list_new_empty(); mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); store_flags = mailimap_store_att_flags_new_set_flags(flist); set = mailimap_set_new_single(mail->getNumber()); err = mailimap_store(m_imap,set,store_flags); mailimap_set_free( set ); mailimap_store_att_flags_free(store_flags); if (err != MAILIMAP_NO_ERROR) { // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; return; } // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; /* should we realy do that at this moment? */ // err = mailimap_expunge(m_imap); //if (err != MAILIMAP_NO_ERROR) { - // Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response)); + // Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response)); // } //#endif //deleteMail( mail); ++iii; } //qDebug("Deleting imap mails... "); err = mailimap_expunge(m_imap); if (err != MAILIMAP_NO_ERROR) { - Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response)); + Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response)); } } void IMAPwrapper::deleteMail(const RecMailP&mail) { mailimap_flag_list*flist; mailimap_set *set; mailimap_store_att_flags * store_flags; int err; login(); if (!m_imap) { return; } err = selectMbox(mail->getMbox()); if ( err != MAILIMAP_NO_ERROR ) { return; } flist = mailimap_flag_list_new_empty(); mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); store_flags = mailimap_store_att_flags_new_set_flags(flist); set = mailimap_set_new_single(mail->getNumber()); err = mailimap_store(m_imap,set,store_flags); mailimap_set_free( set ); mailimap_store_att_flags_free(store_flags); if (err != MAILIMAP_NO_ERROR) { // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; return; } // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; /* should we realy do that at this moment? */ err = mailimap_expunge(m_imap); if (err != MAILIMAP_NO_ERROR) { - Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); + Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); } //qDebug("IMAPwrapper::deleteMail 2"); } void IMAPwrapper::answeredMail(const RecMailP&mail) { mailimap_flag_list*flist; mailimap_set *set; mailimap_store_att_flags * store_flags; int err; login(); if (!m_imap) { return; } err = selectMbox(mail->getMbox()); if ( err != MAILIMAP_NO_ERROR ) { return; } flist = mailimap_flag_list_new_empty(); mailimap_flag_list_add(flist,mailimap_flag_new_answered()); store_flags = mailimap_store_att_flags_new_add_flags(flist); set = mailimap_set_new_single(mail->getNumber()); err = mailimap_store(m_imap,set,store_flags); mailimap_set_free( set ); mailimap_store_att_flags_free(store_flags); if (err != MAILIMAP_NO_ERROR) { // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; return; } } QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) { QString body(""); encodedString*res = fetchRawPart(mail,path,internal_call); encodedString*r = decode_String(res,enc); delete res; if (r) { if (r->Length()>0) { body = r->Content(); } delete r; } return body; } QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) { return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); } encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) { encodedString*res = fetchRawPart(mail,part->Positionlist(),false); encodedString*r = decode_String(res,part->Encoding()); delete res; return r; } encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) { return fetchRawPart(mail,part->Positionlist(),false); } int IMAPwrapper::deleteAllMail(const FolderP&folder) { login(); if (!m_imap) { return 0; } mailimap_flag_list*flist; mailimap_set *set; mailimap_store_att_flags * store_flags; int err = selectMbox(folder->getName()); if ( err != MAILIMAP_NO_ERROR ) { return 0; } int last = m_imap->imap_selection_info->sel_exists; if (last == 0) { - Global::statusMessage(tr("Mailbox has no mails!")); + Global::statusMessage(i18n("Mailbox has no mails!")); return 0; } flist = mailimap_flag_list_new_empty(); mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); store_flags = mailimap_store_att_flags_new_set_flags(flist); set = mailimap_set_new_interval( 1, last ); err = mailimap_store(m_imap,set,store_flags); mailimap_set_free( set ); mailimap_store_att_flags_free(store_flags); if (err != MAILIMAP_NO_ERROR) { - Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); + Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); return 0; } // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; /* should we realy do that at this moment? */ err = mailimap_expunge(m_imap); if (err != MAILIMAP_NO_ERROR) { - Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); + Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); return 0; } // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; return 1; } int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) { if (folder.length()==0) return 0; login(); if (!m_imap) {return 0;} QString pre = account->getPrefix(); if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { pre+=delemiter; } if (parentfolder) { pre += parentfolder->getDisplayName()+delemiter; } pre+=folder; if (getsubfolder) { if (delemiter.length()>0) { pre+=delemiter; } else { - Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); + Global::statusMessage(i18n("Cannot create folder %1 for holding subfolders").arg(pre)); return 0; } } // odebug << "Creating " << pre.latin1() << "" << oendl; int res = mailimap_create(m_imap,pre.latin1()); if (res != MAILIMAP_NO_ERROR) { - Global::statusMessage(tr("%1").arg(m_imap->imap_response)); + Global::statusMessage(i18n("%1").arg(m_imap->imap_response)); return 0; } 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)); + Global::statusMessage(i18n("%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")); + progress( i18n("Copy")); AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); //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...") ); + Global::statusMessage( i18n("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); + QString error_msg = i18n("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); + QString error_msg = i18n("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/mboxwrapper.cpp b/kmicromail/libmailwrapper/mboxwrapper.cpp index 39dd156..0cdbae4 100644 --- a/kmicromail/libmailwrapper/mboxwrapper.cpp +++ b/kmicromail/libmailwrapper/mboxwrapper.cpp @@ -1,338 +1,339 @@ #include "mboxwrapper.h" #include "mailtypes.h" #include "mailwrapper.h" #include <libetpan/libetpan.h> #include <qdir.h> #include <stdlib.h> +#include <klocale.h> #include <qpe/global.h> using namespace Opie::Core; MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name) : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name) { QDir dir(MBOXPath); if (!dir.exists()) { dir.mkdir(MBOXPath); } } MBOXwrapper::~MBOXwrapper() { } void MBOXwrapper::listMessages(const QString & mailbox, QValueList<RecMailP> &target ) { mailstorage*storage = mailstorage_new(NULL); QString p = MBOXPath+"/"; p+=mailbox; int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); mailfolder*folder; folder = mailfolder_new( storage,(char*)p.latin1(),NULL); r = mailfolder_connect(folder); if (r != MAIL_NO_ERROR) { //odebug << "Error initializing mbox" << oendl; mailfolder_free(folder); mailstorage_free(storage); return; } parseList(target,folder->fld_session,mailbox); mailfolder_disconnect(folder); mailfolder_free(folder); mailstorage_free(storage); - Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); + Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count())); } QValueList<Opie::Core::OSmartPointer<Folder> >* MBOXwrapper::listFolders() { QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); QDir dir(MBOXPath); if (!dir.exists()) return folders; dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); QStringList entries = dir.entryList(); QStringList::ConstIterator it = entries.begin(); for (;it!=entries.end();++it) { FolderP inb=new Folder(*it,"/"); folders->append(inb); } return folders; } void MBOXwrapper::deleteMail(const RecMailP & mail) { mailstorage*storage = mailstorage_new(NULL); QString p = MBOXPath+"/"; p+=mail->getMbox(); int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); mailfolder*folder; folder = mailfolder_new( storage,(char*)p.latin1(),NULL); r = mailfolder_connect(folder); if (r != MAIL_NO_ERROR) { ; // << "Error initializing mbox" << oendl; mailfolder_free(folder); mailstorage_free(storage); return; } r = mailsession_remove_message(folder->fld_session,mail->getNumber()); if (r != MAIL_NO_ERROR) { ; // << "error deleting mail" << oendl; } mailfolder_free(folder); mailstorage_free(storage); } void MBOXwrapper::answeredMail(const RecMailP&) { } RecBodyP MBOXwrapper::fetchBody( const RecMailP &mail ) { RecBodyP body = new RecBody(); mailstorage*storage = mailstorage_new(NULL); QString p = MBOXPath+"/"; p+=mail->getMbox(); mailmessage * msg; char*data=0; size_t size; int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); mailfolder*folder; folder = mailfolder_new( storage,(char*)p.latin1(),NULL); r = mailfolder_connect(folder); if (r != MAIL_NO_ERROR) { ; // << "Error initializing mbox" << oendl; mailfolder_free(folder); mailstorage_free(storage); return body; } r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); if (r != MAIL_NO_ERROR) { ; // << "Error fetching mail " << mail->getNumber() << "" << oendl; mailfolder_free(folder); mailstorage_free(storage); return body; } r = mailmessage_fetch(msg,&data,&size); if (r != MAIL_NO_ERROR) { ; // << "Error fetching mail " << mail->getNumber() << "" << oendl; mailfolder_free(folder); mailstorage_free(storage); mailmessage_free(msg); return body; } body = parseMail(msg); mailmessage_fetch_result_free(msg,data); mailfolder_free(folder); mailstorage_free(storage); return body; } void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) { ; // << "MBOX " << current << " von " << maximum << "" << oendl; } int MBOXwrapper::createMbox(const QString&folder,const FolderP&,const QString&,bool ) { QString p = MBOXPath+"/"; p+=folder; QFileInfo fi(p); if (fi.exists()) { - Global::statusMessage(tr("Mailbox exists.")); + Global::statusMessage(i18n("Mailbox exists.")); return 0; } mailmbox_folder*f = 0; if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { - Global::statusMessage(tr("Error init folder")); + Global::statusMessage(i18n("Error init folder")); return 0; } if (f) mailmbox_done(f); return 1; } void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) { QString p = MBOXPath+"/"; p+=folder; mailmbox_folder*f = 0; int r = mailmbox_init(p.latin1(),0,1,0,&f); if (r != MAIL_NO_ERROR) { - Global::statusMessage(tr("Error init folder")); + Global::statusMessage(i18n("Error init folder")); return; } r = mailmbox_append_message(f,msg,length); if (r != MAIL_NO_ERROR) { - Global::statusMessage(tr("Error writing to message folder")); + Global::statusMessage(i18n("Error writing to message folder")); } mailmbox_done(f); } encodedString* MBOXwrapper::fetchRawBody(const RecMailP&mail) { RecBody body; mailstorage*storage = mailstorage_new(NULL); QString p = MBOXPath+"/"; p+=mail->getMbox(); mailmessage * msg; char*data=0; size_t size; int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); mailfolder*folder; folder = mailfolder_new( storage,(char*)p.latin1(),NULL); r = mailfolder_connect(folder); if (r != MAIL_NO_ERROR) { - Global::statusMessage(tr("Error initializing mbox")); + Global::statusMessage(i18n("Error initializing mbox")); mailfolder_free(folder); mailstorage_free(storage); return 0; } r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); if (r != MAIL_NO_ERROR) { - Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); + Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); mailfolder_free(folder); mailstorage_free(storage); return 0; } r = mailmessage_fetch(msg,&data,&size); if (r != MAIL_NO_ERROR) { - Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); + Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); mailfolder_free(folder); mailstorage_free(storage); mailmessage_free(msg); return 0; } encodedString*result = new encodedString(data,size); mailfolder_free(folder); mailstorage_free(storage); mailmessage_free(msg); return result; } void MBOXwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) { QString p = MBOXPath+"/"; p+=mailbox; mailmbox_folder*f = 0; int r = mailmbox_init(p.latin1(),0,1,0,&f); if (r != MAIL_NO_ERROR) { ; // << "Error init folder" << oendl; return; } deleteMails(f,target); mailmbox_done(f); } void MBOXwrapper::deleteMails(mailmbox_folder*f,const QValueList<RecMailP> &target) { if (!f) return; int r; QValueList<RecMailP>::ConstIterator it; for (it=target.begin(); it != target.end();++it) { r = mailmbox_delete_msg(f,(*it)->getNumber()); if (r!=MAILMBOX_NO_ERROR) { ; // << "error delete mail" << oendl; } } r = mailmbox_expunge(f); if (r != MAILMBOX_NO_ERROR) { ; // << "error expunge mailbox" << oendl; } } int MBOXwrapper::deleteAllMail(const FolderP&tfolder) { if (!tfolder) return 0; QString p = MBOXPath+"/"+tfolder->getDisplayName(); int res = 1; mailfolder*folder = 0; mailmessage_list*l=0; mailstorage*storage = mailstorage_new(NULL); int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); if (r != MAIL_NO_ERROR) { - Global::statusMessage(tr("Error initializing mbox")); + Global::statusMessage(i18n("Error initializing mbox")); res = 0; } if (res) { folder = mailfolder_new( storage,(char*)p.latin1(),NULL); r = mailfolder_connect(folder); if (r != MAIL_NO_ERROR) { - Global::statusMessage(tr("Error initializing mbox")); + Global::statusMessage(i18n("Error initializing mbox")); res = 0; } } if (res) { r = mailsession_get_messages_list(folder->fld_session,&l); if (r != MAIL_NO_ERROR) { ; // << "Error message list" << oendl; res=0; } } for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { r = mailsession_remove_message(folder->fld_session,i+1); if (r != MAIL_NO_ERROR) { - Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); + Global::statusMessage(i18n("Error deleting mail %1").arg(i+1)); res = 0; break; } } if (l) mailmessage_list_free(l); if (folder) mailfolder_free(folder); if (storage) mailstorage_free(storage); return res; } int MBOXwrapper::deleteMbox(const FolderP&tfolder) { if (!tfolder) return 0; QString p = MBOXPath+"/"+tfolder->getDisplayName(); QFile fi(p); if (!fi.exists()) { - Global::statusMessage(tr("Mailbox doesn't exist.")); + Global::statusMessage(i18n("Mailbox doesn't exist.")); return 0; } if (!fi.remove()) { - Global::statusMessage(tr("Error deleting Mailbox.")); + Global::statusMessage(i18n("Error deleting Mailbox.")); return 0; } return 1; } void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) { mailfolder*folder = 0; mailstorage*storage = mailstorage_new(NULL); target_stat.message_count = 0; target_stat.message_unseen = 0; target_stat.message_recent = 0; QString p = MBOXPath+"/"+mailbox; QFile fi(p); if (!fi.exists()) { - Global::statusMessage(tr("Mailbox doesn't exist.")); + Global::statusMessage(i18n("Mailbox doesn't exist.")); return; } int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); folder = mailfolder_new( storage,(char*)p.latin1(),NULL); r = mailfolder_connect(folder); r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, &target_stat.message_recent,&target_stat.message_unseen); if (folder) mailfolder_free(folder); if (storage) mailstorage_free(storage); } MAILLIB::ATYPE MBOXwrapper::getType()const { return MAILLIB::A_MBOX; } const QString&MBOXwrapper::getName()const { return MBOXName; } diff --git a/kmicromail/libmailwrapper/pop3wrapper.cpp b/kmicromail/libmailwrapper/pop3wrapper.cpp index 9d52f52..2888f7c 100644 --- a/kmicromail/libmailwrapper/pop3wrapper.cpp +++ b/kmicromail/libmailwrapper/pop3wrapper.cpp @@ -1,302 +1,303 @@ // CHANGED 2004-09-31 Lutz Rogowski #include <stdlib.h> #include "pop3wrapper.h" #include "mailtypes.h" #include "logindialog.h" #include <libetpan/libetpan.h> +#include <klocale.h> #include <qpe/global.h> #include <qfile.h> #include <qprogressbar.h> #include <qapplication.h> /* we don't fetch messages larger than 5 MB */ #define HARD_MSG_SIZE_LIMIT 5242880 using namespace Opie::Core; POP3wrapper::POP3wrapper( POP3account *a ) : Genericwrapper() { account = a; m_pop3 = NULL; msgTempName = a->getFileName()+"_msg_cache"; last_msg_id = 0; } POP3wrapper::~POP3wrapper() { logout(); QFile msg_cache(msgTempName); if (msg_cache.exists()) { msg_cache.remove(); } } void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; } RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { int err = MAILPOP3_NO_ERROR; char *message = 0; size_t length = 0; RecBodyP body = new RecBody(); login(); if ( !m_pop3 ) { return body; } mailmessage * mailmsg; if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl; return body; } QFile msg_cache(msgTempName); cleanMimeCache(); if (mail->getNumber()!=last_msg_id) { if (msg_cache.exists()) { msg_cache.remove(); } msg_cache.open(IO_ReadWrite|IO_Truncate); last_msg_id = mail->getNumber(); err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); err = mailmessage_fetch(mailmsg,&message,&length); msg_cache.writeBlock(message,length); } else { QString msg=""; msg_cache.open(IO_ReadOnly); message = new char[4096]; memset(message,0,4096); while (msg_cache.readBlock(message,4095)>0) { msg+=message; memset(message,0,4096); } delete message; message = (char*)malloc(msg.length()+1*sizeof(char)); memset(message,0,msg.length()+1); memcpy(message,msg.latin1(),msg.length()); /* transform to libetpan stuff */ mailmsg = mailmessage_new(); mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); generic_message_t * msg_data; msg_data = (generic_message_t *)mailmsg->msg_data; msg_data->msg_fetched = 1; msg_data->msg_message = message; msg_data->msg_length = strlen(message); } body = parseMail(mailmsg); /* clean up */ if (mailmsg) mailmessage_free(mailmsg); if (message) free(message); return body; } void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) { login(); if (!m_pop3) return; uint32_t res_messages,res_recent,res_unseen; mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb); - Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); + Global::statusMessage( i18n("Mailbox contains %1 mail(s)").arg(res_messages)); } void POP3wrapper::login() { if (account->getOffline()) return; /* we'll hold the line */ if ( m_pop3 != NULL ) return; QString server,user, pass; uint16_t port; int err = MAILPOP3_NO_ERROR; server = account->getServer(); port = account->getPort().toUInt(); if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { qApp->processEvents(); 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 ; // odebug << "POP3: Login canceled" << oendl; return; } } else { user = account->getUser(); pass = account->getPassword(); } // bool ssl = account->getSSL(); m_pop3=mailstorage_new(NULL); int conntypeset = account->ConnectionType(); int conntype = 0; if ( conntypeset == 3 ) { conntype = CONNECTION_TYPE_COMMAND; } else if ( conntypeset == 2 ) { conntype = CONNECTION_TYPE_TLS; } else if ( conntypeset == 1 ) { conntype = CONNECTION_TYPE_STARTTLS; } else if ( conntypeset == 0 ) { conntype = CONNECTION_TYPE_TRY_STARTTLS; } //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); pop3_mailstorage_init(m_pop3,(char*)server.latin1(), port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, (char*)user.latin1(),(char*)pass.latin1(),0,0,0); err = mailstorage_connect(m_pop3); if (err != MAIL_NO_ERROR) { ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; - Global::statusMessage(tr("Error %1 initializing folder").arg( err )); + Global::statusMessage(i18n("Error %1 initializing folder").arg( err )); mailstorage_free(m_pop3); m_pop3 = 0; } else { mailsession * session = m_pop3->sto_session; mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; if (mail) { mail->pop3_progr_fun = &pop3_progress; } } } void POP3wrapper::logout() { if ( m_pop3 == NULL ) return; mailstorage_free(m_pop3); m_pop3 = 0; } QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); FolderP inb=new Folder("INBOX","/"); folders->append(inb); return folders; } void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target) { login(); if (!m_pop3) return; int iii = 0; int count = target.count(); QProgressBar wid ( count ); - wid.setCaption( tr("Deleting ...")); + wid.setCaption( i18n("Deleting ...")); wid.show(); while (iii < count ) { - Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count)); + Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); wid.setProgress( iii ); wid.raise(); qApp->processEvents(); //qDebug("delete "); RecMailP mail = (*target.at( iii )); int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); if (err != MAIL_NO_ERROR) { - Global::statusMessage(tr("Error deleting mail")); + Global::statusMessage(i18n("Error deleting mail")); } ++iii; } } void POP3wrapper::deleteMail(const RecMailP&mail) { login(); if (!m_pop3) return; int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); if (err != MAIL_NO_ERROR) { - Global::statusMessage(tr("error deleting mail")); + Global::statusMessage(i18n("error deleting mail")); } } void POP3wrapper::answeredMail(const RecMailP&) {} int POP3wrapper::deleteAllMail(const FolderP&) { login(); if (!m_pop3) return 0; int res = 1; uint32_t result = 0; int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); if (err != MAIL_NO_ERROR) { - Global::statusMessage(tr("Error getting folder info")); + Global::statusMessage(i18n("Error getting folder info")); return 0; } QProgressBar wid ( result ); - wid.setCaption( tr("Deleting ...")); + wid.setCaption( i18n("Deleting ...")); wid.show(); for (unsigned int i = 0; i < result; ++i) { - Global::statusMessage(tr("Delete message %1 of %2").arg(i).arg(result)); + Global::statusMessage(i18n("Delete message %1 of %2").arg(i).arg(result)); wid.setProgress( i ); wid.raise(); qApp->processEvents(); err = mailsession_remove_message(m_pop3->sto_session,i+1); if (err != MAIL_NO_ERROR) { - Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); + Global::statusMessage(i18n("Error deleting mail %1").arg(i+1)); res=0; } break; } return res; } void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { login(); target_stat.message_count = 0; target_stat.message_unseen = 0; target_stat.message_recent = 0; if (!m_pop3) return; int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, &target_stat.message_recent,&target_stat.message_unseen); if (r != MAIL_NO_ERROR) { ; // odebug << "error getting folter status." << oendl; } } encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) { char*target=0; size_t length=0; encodedString*res = 0; mailmessage * mailmsg = 0; int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); err = mailmessage_fetch(mailmsg,&target,&length); if (mailmsg) mailmessage_free(mailmsg); if (target) { res = new encodedString(target,length); } return res; } MAILLIB::ATYPE POP3wrapper::getType()const { return account->getType(); } const QString&POP3wrapper::getName()const{ return account->getAccountName(); } diff --git a/kmicromail/libmailwrapper/smtpwrapper.cpp b/kmicromail/libmailwrapper/smtpwrapper.cpp index d5a528c..dee1477 100644 --- a/kmicromail/libmailwrapper/smtpwrapper.cpp +++ b/kmicromail/libmailwrapper/smtpwrapper.cpp @@ -1,460 +1,461 @@ #include "smtpwrapper.h" #include "mailwrapper.h" #include "abstractmail.h" #include "logindialog.h" #include "mailtypes.h" #include "sendmailprogress.h" //#include <opie2/odebug.h> //#include <qt.h> #include <qapplication.h> #include <qmessagebox.h> #include <stdlib.h> #include <qpe/config.h> #include <qpe/qcopenvelope_qws.h> #include <libetpan/libetpan.h> +#include <klocale.h> using namespace Opie::Core; progressMailSend*SMTPwrapper::sendProgress = 0; SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) : Generatemail() { m_SmtpAccount = aSmtp; Config cfg( "mail" ); cfg.setGroup( "Status" ); m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); emit queuedMails( m_queuedMail ); connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); m_smtp = 0; } SMTPwrapper::~SMTPwrapper() { disc_server(); } void SMTPwrapper::emitQCop( int queued ) { QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); env << queued; } QString SMTPwrapper::mailsmtpError( int errnum ) { switch ( errnum ) { case MAILSMTP_NO_ERROR: - return tr( "No error" ); + return i18n( "No error" ); case MAILSMTP_ERROR_UNEXPECTED_CODE: - return tr( "Unexpected error code" ); + return i18n( "Unexpected error code" ); case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: - return tr( "Service not available" ); + return i18n( "Service not available" ); case MAILSMTP_ERROR_STREAM: - return tr( "Stream error" ); + return i18n( "Stream error" ); case MAILSMTP_ERROR_HOSTNAME: - return tr( "gethostname() failed" ); + return i18n( "gethostname() failed" ); case MAILSMTP_ERROR_NOT_IMPLEMENTED: - return tr( "Not implemented" ); + return i18n( "Not implemented" ); case MAILSMTP_ERROR_ACTION_NOT_TAKEN: - return tr( "Error, action not taken" ); + return i18n( "Error, action not taken" ); case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: - return tr( "Data exceeds storage allocation" ); + return i18n( "Data exceeds storage allocation" ); case MAILSMTP_ERROR_IN_PROCESSING: - return tr( "Error in processing" ); + return i18n( "Error in processing" ); case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: - return tr( "Starttls not supported" ); + return i18n( "Starttls not supported" ); // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: - // return tr( "Insufficient system storage" ); + // return i18n( "Insufficient system storage" ); case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: - return tr( "Mailbox unavailable" ); + return i18n( "Mailbox unavailable" ); case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: - return tr( "Mailbox name not allowed" ); + return i18n( "Mailbox name not allowed" ); case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: - return tr( "Bad command sequence" ); + return i18n( "Bad command sequence" ); case MAILSMTP_ERROR_USER_NOT_LOCAL: - return tr( "User not local" ); + return i18n( "User not local" ); case MAILSMTP_ERROR_TRANSACTION_FAILED: - return tr( "Transaction failed" ); + return i18n( "Transaction failed" ); case MAILSMTP_ERROR_MEMORY: - return tr( "Memory error" ); + return i18n( "Memory error" ); case MAILSMTP_ERROR_CONNECTION_REFUSED: - return tr( "Connection refused" ); + return i18n( "Connection refused" ); default: - return tr( "Unknown error code" ); + return i18n( "Unknown error code" ); } } void SMTPwrapper::progress( size_t current, size_t maximum ) { if (SMTPwrapper::sendProgress) { SMTPwrapper::sendProgress->setSingleMail(current, maximum ); qApp->processEvents(); } } void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { if (!mail) return; QString localfolders = AbstractMail::defaultLocalfolder(); AbstractMail*wrap = AbstractMail::getWrapper(localfolders); wrap->createMbox(box); wrap->storeMessage(mail,length,box); delete wrap; } bool SMTPwrapper::smtpSend( mailmime *mail,bool later) { clist *rcpts = 0; char *from, *data; size_t size; from = data = 0; mailmessage * msg = 0; msg = mime_message_init(mail); mime_message_set_tmpdir(msg,getenv( "HOME" )); int r = mailmessage_fetch(msg,&data,&size); mime_message_detach_mime(msg); mailmessage_free(msg); if (r != MAIL_NO_ERROR || !data) { if (data) free(data); qDebug("Error fetching mime... "); return false; } msg = 0; if (later) { storeMail(data,size,"Outgoing"); if (data) free( data ); Config cfg( "mail" ); cfg.setGroup( "Status" ); cfg.writeEntry( "outgoing", ++m_queuedMail ); emit queuedMails( m_queuedMail ); return true; } from = getFrom( mail ); rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); bool result = smtpSend(from,rcpts,data,size); if (data) { free(data); } if (from) { free(from); } if (rcpts) smtp_address_list_free( rcpts ); return result; } void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) { if (data) { storeMail(data,size,"Sendfailed"); } if (failuremessage) { - QMessageBox::critical(0,tr("Error sending mail"), - tr("<center>%1</center>").arg(failuremessage)); + QMessageBox::critical(0,i18n("Error sending mail"), + i18n("<center>%1</center>").arg(failuremessage)); } } int SMTPwrapper::start_smtp_tls() { if (!m_smtp) { return MAILSMTP_ERROR_IN_PROCESSING; } int err = mailesmtp_starttls(m_smtp); if (err != MAILSMTP_NO_ERROR) return err; mailstream_low * low; mailstream_low * new_low; low = mailstream_get_low(m_smtp->stream); if (!low) { return MAILSMTP_ERROR_IN_PROCESSING; } 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_smtp->stream, new_low); } else { return MAILSMTP_ERROR_IN_PROCESSING; } return err; } void SMTPwrapper::connect_server() { QString server, user, pass; bool ssl; uint16_t port; ssl = false; bool try_tls = true; bool force_tls=false; QString failuretext = ""; if (m_smtp || !m_SmtpAccount) { return; } server = m_SmtpAccount->getServer(); if ( m_SmtpAccount->ConnectionType() == 2 ) { ssl = true; try_tls = false; } else if (m_SmtpAccount->ConnectionType() == 1) { force_tls = true; } int result = 1; port = m_SmtpAccount->getPort().toUInt(); m_smtp = mailsmtp_new( 20, &progress ); if ( m_smtp == NULL ) { /* no failure message cause this happens when problems with memory - than we we can not display any messagebox */ return; } int err = MAILSMTP_NO_ERROR; ; // odebug << "Servername " << server << " at port " << port << "" << oendl; if ( ssl ) { ; // odebug << "SSL session" << oendl; err = mailsmtp_ssl_connect( m_smtp, server.latin1(), port ); } else { ; // odebug << "No SSL session" << oendl; err = mailsmtp_socket_connect( m_smtp, server.latin1(), port ); } if ( err != MAILSMTP_NO_ERROR ) { ; // odebug << "Error init connection" << oendl; - failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); + failuretext = i18n("Error init SMTP connection: %1").arg(mailsmtpError(err)); result = 0; } /* switch to tls after init 'cause there it will send the ehlo */ if (result) { err = mailsmtp_init( m_smtp ); if (err != MAILSMTP_NO_ERROR) { result = 0; - failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); + failuretext = i18n("Error init SMTP connection: %1").arg(mailsmtpError(err)); } } if (try_tls) { err = start_smtp_tls(); if (err != MAILSMTP_NO_ERROR) { try_tls = false; } else { err = mailesmtp_ehlo(m_smtp); } } if (!try_tls && force_tls) { result = 0; - failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); + failuretext = i18n("Error init SMTP tls: %1").arg(mailsmtpError(err)); } if (result==1 && m_SmtpAccount->getLogin() ) { ; // odebug << "smtp with auth" << oendl; if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { // get'em LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); login.show(); if ( QDialog::Accepted == login.exec() ) { // ok user = login.getUser(); pass = login.getPassword(); } else { result = 0; - failuretext=tr("Login aborted - storing mail to localfolder"); + failuretext=i18n("Login aborted - storing mail to localfolder"); } } else { user = m_SmtpAccount->getUser(); pass = m_SmtpAccount->getPassword(); } ; // odebug << "session->auth: " << m_smtp->auth << "" << oendl; if (result) { err = mailsmtp_auth( m_smtp, (char*)user.latin1(), (char*)pass.latin1() ); if ( err == MAILSMTP_NO_ERROR ) { ; // odebug << "auth ok" << oendl; } else { - failuretext = tr("Authentification failed"); + failuretext = i18n("Authentification failed"); result = 0; } } } } void SMTPwrapper::disc_server() { if (m_smtp) { mailsmtp_quit( m_smtp ); mailsmtp_free( m_smtp ); m_smtp = 0; } } int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) { int err,result; QString failuretext = ""; connect_server(); result = 1; if (m_smtp) { err = mailsmtp_send( m_smtp, from, rcpts, data, size ); if ( err != MAILSMTP_NO_ERROR ) { - failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); + failuretext=i18n("Error sending mail: %1").arg(mailsmtpError(err)); result = 0; } } else { result = 0; } if (!result) { storeFailedMail(data,size,failuretext); } else { ; // odebug << "Mail sent." << oendl; storeMail(data,size,"Sent"); } return result; } bool SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later ) { mailmime * mimeMail; bool result = true; mimeMail = createMimeMail(mail ); if ( mimeMail == 0 ) { qDebug("SMTP wrapper:Error creating mail! "); return false; } else { sendProgress = new progressMailSend(); sendProgress->show(); sendProgress->setMaxMails(1); result = smtpSend( mimeMail,later); ; // odebug << "Clean up done" << oendl; sendProgress->hide(); delete sendProgress; sendProgress = 0; mailmime_free( mimeMail ); } return result; } int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) { size_t curTok = 0; mailimf_fields *fields = 0; mailimf_field*ffrom = 0; clist *rcpts = 0; char*from = 0; int res = 0; encodedString * data = wrap->fetchRawBody(which); if (!data) return 0; int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); if (err != MAILIMF_NO_ERROR) { delete data; delete wrap; return 0; } rcpts = createRcptList( fields ); ffrom = getField(fields, MAILIMF_FIELD_FROM ); from = getFrom(ffrom); if (rcpts && from) { res = smtpSend(from,rcpts,data->Content(),data->Length()); } if (fields) { mailimf_fields_free(fields); fields = 0; } if (data) { delete data; } if (from) { free(from); } if (rcpts) { smtp_address_list_free( rcpts ); } return res; } /* this is a special fun */ bool SMTPwrapper::flushOutbox() { bool returnValue = true; ; // odebug << "Sending the queue" << oendl; if (!m_SmtpAccount) { ; // odebug << "No smtp account given" << oendl; return false; } bool reset_user_value = false; QString localfolders = AbstractMail::defaultLocalfolder(); AbstractMail*wrap = AbstractMail::getWrapper(localfolders); if (!wrap) { ; // odebug << "memory error" << oendl; return false; } QString oldPw, oldUser; QValueList<RecMailP> mailsToSend; QValueList<RecMailP> mailsToRemove; QString mbox("Outgoing"); wrap->listMessages(mbox,mailsToSend); if (mailsToSend.count()==0) { delete wrap; ; // odebug << "No mails to send" << oendl; return false; } oldPw = m_SmtpAccount->getPassword(); oldUser = m_SmtpAccount->getUser(); if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { // get'em QString user,pass; LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); login.show(); if ( QDialog::Accepted == login.exec() ) { // ok user = login.getUser().latin1(); pass = login.getPassword().latin1(); reset_user_value = true; m_SmtpAccount->setUser(user); m_SmtpAccount->setPassword(pass); } else { return true; } } sendProgress = new progressMailSend(); sendProgress->show(); sendProgress->setMaxMails(mailsToSend.count()); while (mailsToSend.count()>0) { if (sendQueuedMail(wrap, (*mailsToSend.begin()))==0) { - QMessageBox::critical(0,tr("Error sending mail"), - tr("Error sending queued mail - breaking")); + QMessageBox::critical(0,i18n("Error sending mail"), + i18n("Error sending queued mail - breaking")); returnValue = false; break; } mailsToRemove.append((*mailsToSend.begin())); mailsToSend.remove(mailsToSend.begin()); sendProgress->setCurrentMails(mailsToRemove.count()); } if (reset_user_value) { m_SmtpAccount->setUser(oldUser); m_SmtpAccount->setPassword(oldPw); } Config cfg( "mail" ); cfg.setGroup( "Status" ); m_queuedMail = 0; cfg.writeEntry( "outgoing", m_queuedMail ); emit queuedMails( m_queuedMail ); sendProgress->hide(); delete sendProgress; sendProgress = 0; wrap->deleteMails(mbox,mailsToRemove); delete wrap; return returnValue; } diff --git a/kmicromail/nntpgroupsdlg.cpp b/kmicromail/nntpgroupsdlg.cpp index c94d9fa..a461bdf 100644 --- a/kmicromail/nntpgroupsdlg.cpp +++ b/kmicromail/nntpgroupsdlg.cpp @@ -1,29 +1,30 @@ #include "nntpgroupsdlg.h" #include "nntpgroups.h" +#include <klocale.h> #include <libmailwrapper/settings.h> #include <qlayout.h> NNTPGroupsDlg::NNTPGroupsDlg(NNTPaccount *account,QWidget * parent, const char * name) : QDialog(parent,name,true,WStyle_ContextHelp) { - setCaption(tr("Subscribed newsgroups")); + setCaption(i18n("Subscribed newsgroups")); m_Account = account; QVBoxLayout*dlglayout = new QVBoxLayout(this); dlglayout->setSpacing(2); dlglayout->setMargin(1); groupsWidget = new NNTPGroups(account,this); dlglayout->addWidget(groupsWidget); } NNTPGroupsDlg::~NNTPGroupsDlg() { } void NNTPGroupsDlg::accept() { groupsWidget->storeValues(); m_Account->save(); QDialog::accept(); } diff --git a/kmicromail/selectsmtp.cpp b/kmicromail/selectsmtp.cpp index 24eced1..ff8b524 100644 --- a/kmicromail/selectsmtp.cpp +++ b/kmicromail/selectsmtp.cpp @@ -1,63 +1,64 @@ #include "selectsmtp.h" #include <libmailwrapper/mailwrapper.h> #include <qcombobox.h> #include <qcheckbox.h> #include <qmessagebox.h> #include <qpushbutton.h> #include <qlineedit.h> #include <qlabel.h> #include <qtabwidget.h> #include <qlistview.h> +#include <klocale.h> selectsmtp::selectsmtp(QWidget* parent, const char* name, bool modal, WFlags fl) : selectstoreui(parent,name,modal,fl) { //m_smtpList.setAutoDelete(false); m_smtpList = 0; - //headlabel->setText(tr("<center>Select SMTP account to use</center>")); + //headlabel->setText(i18n("<center>Select SMTP account to use</center>")); headlabel->hide(); folderSelection->hide(); folderLabel->hide(); accountlabel->setText("<center>SMTP Accounts</center>"); Line1->hide(); newFoldersel->hide(); newFolderedit->hide(); newFolderLabel->hide(); Line2->hide(); selMove->hide(); m_current_smtp = 0; - setCaption(tr("Select SMTP Account")); + setCaption(i18n("Select SMTP Account")); } selectsmtp::~selectsmtp() { } void selectsmtp::slotAccountselected(int which) { if (!m_smtpList || (unsigned)which>=m_smtpList->count() || which < 0) { m_current_smtp = 0; return; } m_current_smtp = m_smtpList->at(which); } void selectsmtp::setSelectionlist(QList<SMTPaccount>*list) { m_smtpList = list; accountSelection->clear(); if (!m_smtpList || m_smtpList->count()==0) { accountSelection->setEnabled(false); return; } accountSelection->setEnabled(true); for (unsigned i = 0; m_smtpList!=0 && i < m_smtpList->count(); ++i) { accountSelection->insertItem( m_smtpList->at(i)->getAccountName()); } m_current_smtp = m_smtpList->at(0); } SMTPaccount*selectsmtp::selected_smtp() { return m_current_smtp; } diff --git a/kmicromail/viewmail.cpp b/kmicromail/viewmail.cpp index 32a3b7c..7cf5c8e 100644 --- a/kmicromail/viewmail.cpp +++ b/kmicromail/viewmail.cpp @@ -1,531 +1,532 @@ // CHANGED 2004-08-06 Lutz Rogowski #include "composemail.h" #include "viewmail.h" #include <libmailwrapper/settings.h> #include <libmailwrapper/abstractmail.h> #include <libmailwrapper/mailtypes.h> #include <kapplication.h> /* OPIE */ //#include <opie2/odebug.h> //#include <opie2/ofiledialog.h> //#include <opie2/oimagescrollview.h> #include <kfiledialog.h> #include <kdialog.h> #include <qpe/qpeapplication.h> /* QT */ #include <qtextbrowser.h> #include <qmessagebox.h> #include <qtextstream.h> #include <qaction.h> #include <qpopupmenu.h> #include <qfile.h> #include <qlayout.h> #include "koprefs.h" +#include <klocale.h> //using namespace Opie::Ui; //using namespace Opie::Core; AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, const QString&fsize,int num,const QValueList<int>&path) : QListViewItem(parent,after),_partNum(num) { _path=path; setText(0, mime); setText(1, desc); setText(2, file); setText(3, fsize); } AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, const QString&fsize,int num,const QValueList<int>&path) : QListViewItem(parent,after),_partNum(num) { _path=path; setText(0, mime); setText(1, desc); setText(2, file); setText(3, fsize); } bool AttachItem::isParentof(const QValueList<int>&path) { /* if not set, then no parent */ if (path.count()==0||_path.count()==0) return false; /* the parent must have one digit less then a child */ if (path.count()!=_path.count()+1) return false; for (unsigned int i=0; i < _path.count();++i) { if (_path[i]!=path[i]) return false; } return true; } AttachItem* ViewMail::searchParent(const QValueList<int>&path) { QListViewItemIterator it( attachments ); for ( ; it.current(); ++it ) { AttachItem*ati = (AttachItem*)it.current(); if (ati->isParentof(path)) return ati; } return 0; } AttachItem* ViewMail::lastChild(AttachItem*parent) { if (!parent) return 0; AttachItem* item = (AttachItem*)parent->firstChild(); if (!item) return item; AttachItem*temp=0; while( (temp=(AttachItem*)item->nextSibling())) { item = temp; } return item; } void ViewMail::setBody(const RecBodyP&body ) { m_body = body; m_mail[2] = body->Bodytext(); attachbutton->setEnabled(body->Parts().count()>0); attachments->setEnabled(body->Parts().count()>0); if (body->Parts().count()==0) { return; } AttachItem * curItem=0; AttachItem * parentItem = 0; QString type=body->Description()->Type()+"/"+body->Description()->Subtype(); QString desc,fsize; double s = body->Description()->Size(); int w; w=0; while (s>1024) { s/=1024; ++w; if (w>=2) break; } QString q=""; switch(w) { case 1: q="k"; break; case 2: q="M"; break; default: break; } { /* I did not found a method to make a CONTENT reset on a QTextStream so I use this construct that the stream will re-constructed in each loop. To let it work, the textstream is packed into a own area of code is it will be destructed after finishing its small job. */ QTextOStream o(&fsize); if (w>0) o.precision(2); else o.precision(0); o.setf(QTextStream::fixed); o << s << " " << q << "Byte"; } curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body->Description()->Positionlist()); QString filename = ""; for (unsigned int i = 0; i < body->Parts().count();++i) { filename = ""; type = body->Parts()[i]->Type()+"/"+body->Parts()[i]->Subtype(); part_plist_t::ConstIterator it = body->Parts()[i]->Parameters().begin(); for (;it!=body->Parts()[i]->Parameters().end();++it) { if (it.key().lower()=="name") { filename=it.data(); } } s = body->Parts()[i]->Size(); w = 0; while (s>1024) { s/=1024; ++w; if (w>=2) break; } switch(w) { case 1: q="k"; break; case 2: q="M"; break; default: q=""; break; } QTextOStream o(&fsize); if (w>0) o.precision(2); else o.precision(0); o.setf(QTextStream::fixed); o << s << " " << q << "Byte"; desc = body->Parts()[i]->Description(); parentItem = searchParent(body->Parts()[i]->Positionlist()); if (parentItem) { AttachItem*temp = lastChild(parentItem); if (temp) curItem = temp; curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist()); attachments->setRootIsDecorated(true); curItem = parentItem; } else { curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist()); } } } void ViewMail::slotShowHtml( bool state ) { m_showHtml = state; setText(); } void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) { if (!item ) return; if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { setText(); return; } QPopupMenu *menu = new QPopupMenu(); int ret=0; if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) { - menu->insertItem( tr( "Show Text" ), 1 ); + menu->insertItem( i18n( "Show Text" ), 1 ); } if (item->text(0).left(6)=="image/") { - menu->insertItem(tr("Display image preview"),2); + menu->insertItem(i18n("Display image preview"),2); } - menu->insertItem( tr( "Save Attachment" ), 0 ); + menu->insertItem( i18n( "Save Attachment" ), 0 ); menu->insertSeparator(1); ret = menu->exec( point, 0 ); switch(ret) { case 0: { //MimeTypes types; //types.insert( "all", "*" ); QString str = KFileDialog::getSaveFileName( "/", item->text( 2 ), this ); if( !str.isEmpty() ) { encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); if (content) { QFile output(str); output.open(IO_WriteOnly); output.writeBlock(content->Content(),content->Length()); output.close(); delete content; } } } break ; case 2: { #ifdef DESKTOP_VERSION QString tmpfile = locateLocal( "tmp", "opiemail-image"); #else QString tmpfile = "/tmp/opiemail-image"; #endif encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); if (content) { QFile output(tmpfile); output.open(IO_WriteOnly); output.writeBlock(content->Content(),content->Length()); output.close(); delete content; MailImageDlg iview(""); iview.setName(tmpfile); KApplication::execDialog(&iview); output.remove(); } } break; case 1: if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { setText(); } else { if ( m_recMail->Wrapper() != 0l ) { // make sure that there is a wrapper , even after delete or simular actions browser->setText( m_recMail->Wrapper()->fetchTextPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); } } break; } delete menu; } void ViewMail::setMail(const RecMailP&mail ) { m_recMail = mail; m_mail[0] = mail->getFrom(); m_mail[1] = mail->getSubject(); m_mail[3] = mail->getDate(); m_mail[4] = mail->Msgid(); m_mail2[0] = mail->To(); m_mail2[1] = mail->CC(); m_mail2[2] = mail->Bcc(); setText(); } ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) : ViewMailBase(parent, name, fl), _inLoop(false) { m_gotBody = false; deleted = false; connect( reply, SIGNAL(activated()), SLOT(slotReply())); connect( forward, SIGNAL(activated()), SLOT(slotForward())); connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) ); connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) ); connect( closeMail, SIGNAL( activated() ), SLOT( close() ) ); attachments->setEnabled(m_gotBody); connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) ); readConfig(); attachments->setSorting(-1); } void ViewMail::readConfig() { setFont ( KOPrefs::instance()->mReadFont ); m_showHtml = KOPrefs::instance()->mViewAsHtml; showHtml->setOn( m_showHtml ); } void ViewMail::setText() { QString toString; QString ccString; QString bccString; for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) { toString += (*it); } for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) { ccString += (*it); } for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) { bccString += (*it); } - setCaption( tr("E-Mail by %1").arg( m_mail[0] ) ); + setCaption( i18n("E-Mail by %1").arg( m_mail[0] ) ); m_mailHtml = "<html><body>" "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" - "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" - "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + - tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" - "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + + "<b>" + i18n( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" + "<b>" + i18n( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + + i18n( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" + "<b>" + i18n( "Date" ) + ": </b> " + m_mail[3] + "</td></tr></table><font>"; if ( !m_showHtml ) { browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); } else { browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); } // remove later in favor of a real handling m_gotBody = true; } ViewMail::~ViewMail() { m_recMail->Wrapper()->cleanMimeCache(); hide(); } void ViewMail::hide() { QWidget::hide(); if (_inLoop) { _inLoop = false; qApp->exit_loop(); } } void ViewMail::exec() { show(); if (!_inLoop) { _inLoop = true; qApp->enter_loop(); } } QString ViewMail::deHtml(const QString &string) { QString string_ = string; string_.replace(QRegExp("&"), "&"); string_.replace(QRegExp("<"), "<"); string_.replace(QRegExp(">"), ">"); string_.replace(QRegExp("\\n"), "<br>"); return string_; } void ViewMail::slotReply() { if (!m_gotBody) { - QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); + QMessageBox::information(this, i18n("Error"), i18n("<p>The mail body is not yet downloaded, so you cannot reply yet."), i18n("Ok")); return; } QString rtext; rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose .arg( m_mail[0] ) .arg( m_mail[3] ); QString text = m_mail[2]; QStringList lines = QStringList::split(QRegExp("\\n"), text); QStringList::Iterator it; for (it = lines.begin(); it != lines.end(); it++) { rtext += "> " + *it + "\n"; } rtext += "\n"; QString prefix; if ( m_mail[1].find(QRegExp("^Re: .*$")) != -1) prefix = ""; else prefix = "Re: "; // no i18n on purpose Settings *settings = new Settings(); ComposeMail composer( settings ,this, 0, true); if (m_recMail->Replyto().isEmpty()) { composer.setTo( m_recMail->getFrom()); } else { composer.setTo( m_recMail->Replyto()); } composer.setSubject( prefix + m_mail[1] ); composer.setMessage( rtext ); composer.setInReplyTo(m_recMail->Msgid()); if ( QDialog::Accepted == KApplication::execDialog( &composer ) ) { m_recMail->Wrapper()->answeredMail(m_recMail); } } void ViewMail::slotForward() { if (!m_gotBody) { - QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); + QMessageBox::information(this, i18n("Error"), i18n("<p>The mail body is not yet downloaded, so you cannot forward yet."), i18n("Ok")); return; } QString ftext; ftext += QString("\n----- Forwarded message from %1 -----\n\n") .arg( m_mail[0] ); if (!m_mail[3].isNull()) ftext += QString("Date: %1\n") .arg( m_mail[3] ); if (!m_mail[0].isNull()) ftext += QString("From: %1\n") .arg( m_mail[0] ); if (!m_mail[1].isNull()) ftext += QString("Subject: %1\n") .arg( m_mail[1] ); ftext += QString("\n%1\n") .arg( m_mail[2]); ftext += QString("----- End forwarded message -----\n"); Settings *settings = new Settings(); ComposeMail composer( settings ,this, 0, true); composer.setSubject( "Fwd: " + m_mail[1] ); composer.setMessage( ftext ); if ( QDialog::Accepted == KApplication::execDialog( &composer )) { } } void ViewMail::slotDeleteMail( ) { - if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) + if ( QMessageBox::warning(this, i18n("Delete Mail"), QString( i18n("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { m_recMail->Wrapper()->deleteMail( m_recMail ); hide(); deleted = true; } } MailImageDlg::MailImageDlg(const QString&fname,QWidget *parent, const char *name, bool modal, WFlags f) : KDialog(parent,name,modal) { QVBoxLayout*dlglayout = new QVBoxLayout(this); dlglayout->setSpacing(2); dlglayout->setMargin(1); //m_imageview = new Opie::MM::OImageScrollView(this); //dlglayout->addWidget(m_imageview); } MailImageDlg::~MailImageDlg() { } void MailImageDlg::setName(const QString&fname) { qDebug("viewmail.cpp: MailImageDlg::setName Pending"); // m_imageview->setImage(fname); } diff --git a/kmicromail/viewmailbase.cpp b/kmicromail/viewmailbase.cpp index 705b57f..3d7ed42 100644 --- a/kmicromail/viewmailbase.cpp +++ b/kmicromail/viewmailbase.cpp @@ -1,92 +1,93 @@ // CHANGED 2004-08-06 Lutz Rogowski #include <qtextbrowser.h> #include <qlistview.h> #include <qaction.h> #include <qlabel.h> #include <qvbox.h> #include <qtoolbar.h> #include <qmenubar.h> #include <kiconloader.h> //#include <qpe/resource.h> +#include <klocale.h> #include "viewmailbase.h" //#include "opendiag.h" ViewMailBase::ViewMailBase(QWidget *parent, const char *name, WFlags fl) : QMainWindow(parent, name, fl) { setToolBarsMovable(false); toolbar = new QToolBar(this); menubar = new QMenuBar( toolbar ); mailmenu = new QPopupMenu( menubar ); - menubar->insertItem( tr( "Mail" ), mailmenu ); + menubar->insertItem( i18n( "Mail" ), mailmenu ); toolbar->setHorizontalStretchable(true); addToolBar(toolbar); - reply = new QAction(tr("Reply"),SmallIcon("reply"), 0, 0, this); + reply = new QAction(i18n("Reply"),SmallIcon("reply"), 0, 0, this); reply->addTo(toolbar); reply->addTo(mailmenu); - forward = new QAction(tr("Forward"),SmallIcon("forward"), 0, 0, this); + forward = new QAction(i18n("Forward"),SmallIcon("forward"), 0, 0, this); forward->addTo(toolbar); forward->addTo(mailmenu); - attachbutton = new QAction(tr("Attachments"),SmallIcon("attach"), 0, 0, this, 0, true); + attachbutton = new QAction(i18n("Attachments"),SmallIcon("attach"), 0, 0, this, 0, true); attachbutton->addTo(toolbar); attachbutton->addTo(mailmenu); connect(attachbutton, SIGNAL(toggled(bool)), SLOT(slotChangeAttachview(bool))); - showHtml = new QAction( tr( "Show Html" ), SmallIcon( "html" ), 0, 0, this, 0, true ); + showHtml = new QAction( i18n( "Show Html" ), SmallIcon( "html" ), 0, 0, this, 0, true ); showHtml->addTo( toolbar ); showHtml->addTo( mailmenu ); - deleteMail = new QAction(tr("Delete Mail"),SmallIcon("trash"), 0, 0, this); + deleteMail = new QAction(i18n("Delete Mail"),SmallIcon("trash"), 0, 0, this); deleteMail->addTo(toolbar); deleteMail->addTo(mailmenu); - closeMail = new QAction(tr("Close"),SmallIcon("exit"), 0, 0, this); + closeMail = new QAction(i18n("Close"),SmallIcon("exit"), 0, 0, this); QLabel *spacer = new QLabel(toolbar); spacer->setBackgroundMode(QWidget::PaletteButton); toolbar->setStretchableWidget(spacer); closeMail->addTo(toolbar); closeMail->addTo(mailmenu); QVBox *view = new QVBox(this); setCentralWidget(view); attachments = new QListView(view); attachments->setMinimumHeight(90); attachments->setMaximumHeight(90); attachments->setAllColumnsShowFocus(true); attachments->addColumn("Mime Type", 60); - attachments->addColumn(tr("Description"), 100); - attachments->addColumn(tr("Filename"), 80); - attachments->addColumn(tr("Size"), 80); + attachments->addColumn(i18n("Description"), 100); + attachments->addColumn(i18n("Filename"), 80); + attachments->addColumn(i18n("Size"), 80); attachments->setSorting(-1); attachments->hide(); browser = new QTextBrowser(view); // openDiag = new OpenDiag(view); // openDiag->hide(); } void ViewMailBase::slotChangeAttachview(bool state) { if (state) attachments->show(); else attachments->hide(); } void ViewMailBase::keyPressEvent ( QKeyEvent * e ) { if( e->key()==Qt::Key_Escape ) { close(); e->accept(); return; } QWidget::keyPressEvent(e); } |