-rw-r--r-- | kmicromail/accountview.cpp | 18 | ||||
-rw-r--r-- | kmicromail/accountview.h | 1 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/smtpwrapper.cpp | 26 | ||||
-rw-r--r-- | kmicromail/opiemail.cpp | 2 |
4 files changed, 35 insertions, 12 deletions
diff --git a/kmicromail/accountview.cpp b/kmicromail/accountview.cpp index c9c4a0f..3ad3e9b 100644 --- a/kmicromail/accountview.cpp +++ b/kmicromail/accountview.cpp @@ -5,192 +5,210 @@ #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::refreshOutgoing() +{ + m_currentItem = currentItem(); + if ( !m_currentItem ) return; + AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); + QString bName = view->getFolder()->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" ) + refreshCurrent(); +} 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) { #ifndef DESKTOP_VERSION sels->showMaximized(); #else sels->show(); #endif 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,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,i18n("Error creating new Folder"), i18n("<center>Error while creating<br>new folder - breaking.</center>")); diff --git a/kmicromail/accountview.h b/kmicromail/accountview.h index 79ed2e7..e403cb8 100644 --- a/kmicromail/accountview.h +++ b/kmicromail/accountview.h @@ -1,46 +1,47 @@ #ifndef ACCOUNTVIEW_H #define ACCOUNTVIEW_H #include <qlistview.h> #include <qlist.h> #include <opie2/osmartpointer.h> #include <libmailwrapper/mailtypes.h> class Selectstore; class Folder; class AbstractMail; class Account; class IMAPviewItem; class MHviewItem; class AccountView : public QListView { Q_OBJECT public: AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); virtual ~AccountView(); virtual void populate( QList<Account> list ); virtual RecBodyP fetchBody(const Opie::Core::OSmartPointer<RecMail>&aMail); virtual void downloadMails(const Opie::Core::OSmartPointer<Folder>&fromFolder,AbstractMail*fromWrapper); virtual void downloadMailsInbox(const Opie::Core::OSmartPointer<Folder>&fromFolder,AbstractMail*fromWrapper); virtual bool currentisDraft(); QValueList<MHviewItem*> allAccounts() { return mhAccounts;} public slots: virtual void refreshAll(); virtual void refresh(QListViewItem *item); virtual void refreshCurrent(); + virtual void refreshOutgoing(); virtual void slotHold(int, QListViewItem *,const QPoint&,int); virtual void slotContextMenu(int id); void setupFolderselect(Selectstore*sels); signals: void refreshMailview(const QValueList<RecMailP>& ); protected: QListViewItem* m_currentItem; QValueList<IMAPviewItem*> imapAccounts; QValueList<MHviewItem*> mhAccounts; }; #endif diff --git a/kmicromail/libmailwrapper/smtpwrapper.cpp b/kmicromail/libmailwrapper/smtpwrapper.cpp index f54fe2b..24f4786 100644 --- a/kmicromail/libmailwrapper/smtpwrapper.cpp +++ b/kmicromail/libmailwrapper/smtpwrapper.cpp @@ -66,340 +66,344 @@ QString SMTPwrapper::mailsmtpError( int errnum ) { case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: return i18n( "Data exceeds storage allocation" ); case MAILSMTP_ERROR_IN_PROCESSING: return i18n( "Error in processing" ); case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: return i18n( "Starttls not supported" ); // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: // return i18n( "Insufficient system storage" ); case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: return i18n( "Mailbox unavailable" ); case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: return i18n( "Mailbox name not allowed" ); case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: return i18n( "Bad command sequence" ); case MAILSMTP_ERROR_USER_NOT_LOCAL: return i18n( "User not local" ); case MAILSMTP_ERROR_TRANSACTION_FAILED: return i18n( "Transaction failed" ); case MAILSMTP_ERROR_MEMORY: return i18n( "Memory error" ); case MAILSMTP_ERROR_CONNECTION_REFUSED: return i18n( "Connection refused" ); default: 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 ); KConfig cfg( locateLocal("config", "kopiemailrc" ) ); 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,i18n("Error sending mail"), - i18n("<center>%1</center>").arg(failuremessage)); + 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; + qDebug("smtp: ssl_connect "); 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 = i18n("Error init SMTP connection: %1").arg(mailsmtpError(err)); + qDebug("Error init SMTP connection" ); + failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err)); result = 0; } + qDebug("SMTP connection inited "); /* 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 = i18n("Error init SMTP connection: %1").arg(mailsmtpError(err)); + qDebug("Error init SMTP connection "); + failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err)); } } - if (try_tls) { + qDebug("Smpt: Try tls "); err = start_smtp_tls(); if (err != MAILSMTP_NO_ERROR) { try_tls = false; + qDebug("no tls "); } else { err = mailesmtp_ehlo(m_smtp); } } - + //qDebug("mailesmtp_ehlo %d ",err ); if (!try_tls && force_tls) { result = 0; - failuretext = i18n("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=i18n("Login aborted - storing mail to localfolder"); + failuretext=i18n("Login aborted - \nstoring 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; + qDebug("Smtp authentification ok "); } else { 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=i18n("Error sending mail: %1").arg(mailsmtpError(err)); + qDebug("Error sending mail"); + failuretext=i18n("Error sending mail:\n%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; diff --git a/kmicromail/opiemail.cpp b/kmicromail/opiemail.cpp index e159b73..f68467c 100644 --- a/kmicromail/opiemail.cpp +++ b/kmicromail/opiemail.cpp @@ -143,193 +143,193 @@ void OpieMail::slotwriteMail2(const QString& namemail ) mCurrentComposer = &compose; compose.exec(); mCurrentComposer = 0; raise(); //qDebug("retttich "); } void OpieMail::slotwriteMail(const QString&name,const QString&email) { // qDebug("OpieMail::slotwriteMail "); ComposeMail compose( settings, this, 0, true ); if (!email.isEmpty()) { if (!name.isEmpty()) { compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">"); } else { compose.setTo(email); } } compose.slotAdjustColumns(); #ifndef DESKTOP_VERSION compose.showMaximized(); #endif mCurrentComposer = &compose; compose.exec(); mCurrentComposer = 0; raise(); } void OpieMail::slotComposeMail() { if ( mPendingEmail == QString::null && mPendingName == QString::null) slotwriteMail2( QString () ); else { if ( mPendingEmail == QString::null ) slotwriteMail2( mPendingName ); else slotwriteMail( mPendingName, mPendingEmail ); } //slotwriteMail(0l,0l); } void OpieMail::slotSendQueued() { SMTPaccount *smtp = 0; QList<Account> list = settings->getAccounts(); QList<SMTPaccount> smtpList; smtpList.setAutoDelete(false); Account *it; for ( it = list.first(); it; it = list.next() ) { if ( it->getType() == MAILLIB::A_SMTP ) { smtp = static_cast<SMTPaccount *>(it); smtpList.append(smtp); } } if (smtpList.count()==0) { QMessageBox::information(0,i18n("Info"),i18n("Define a smtp account first!\n")); return; } if ( QMessageBox::warning(this, i18n("Sending all mails"), i18n("Do you really want to send\nall queued mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No ) return; if (smtpList.count()==1) { smtp = smtpList.at(0); } else { smtp = 0; selectsmtp selsmtp; selsmtp.setSelectionlist(&smtpList); #ifndef DESKTOP_VERSION selsmtp.showMaximized(); #endif if ( selsmtp.exec() == QDialog::Accepted ) { smtp = selsmtp.selected_smtp(); } } if (smtp) { Global::statusMessage("Sending mails...!"); SMTPwrapper * wrap = new SMTPwrapper(smtp); if ( wrap->flushOutbox() ) { Global::statusMessage("Mails sent!"); } delete wrap; } - // pending refresh list view, if outgoing is displayed + folderView->refreshOutgoing(); } void OpieMail::slotSearchMails() { qDebug("OpieMail::slotSearchMails():not implemented "); } void OpieMail::slotEditSettings() { KOPrefsDialog settingsDialog( this, "koprefs", true ); #ifndef DESKTOP_VERSION settingsDialog.showMaximized(); #endif settingsDialog.exec(); slotSetCodec( KOPrefs::instance()->mCurrentCodec ); // KApplication::execDialog(settingsDialog); } void OpieMail::slotEditAccounts() { EditAccounts eaDialog( settings, this, 0, true ); eaDialog.slotAdjustColumns(); #ifndef DESKTOP_VERSION eaDialog.showMaximized(); #endif eaDialog.exec(); if ( settings ) delete settings; settings = new Settings(); folderView->populate( settings->getAccounts() ); } void OpieMail::replyMail() { QListViewItem*item = mailView->currentItem(); if (!item) return; RecMailP mail = ((MailListViewItem*)item)->data(); RecBodyP body = folderView->fetchBody(mail); QString rtext; rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose .arg( mail->getFrom()) .arg( mail->getDate()); QString text = body->Bodytext(); 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 ( mail->getSubject().find(QRegExp("^Re: .*$")) != -1) prefix = ""; else prefix = "Re: "; // no i18n on purpose Settings *settings = new Settings(); ComposeMail composer( settings ,this, 0, true); if (mail->Replyto().isEmpty()) { composer.setTo( mail->getFrom()); } else { composer.setTo( mail->Replyto()); } composer.setSubject( prefix + mail->getSubject()); composer.setMessage( rtext ); composer.setInReplyTo( mail->Msgid()); composer.setCharset( body->getCharset() ); mCurrentComposer = &composer; if ( QDialog::Accepted == KApplication::execDialog( &composer ) ) { mail->Wrapper()->answeredMail(mail); } mCurrentComposer = 0; delete settings; } void OpieMail::closeViewMail(ViewMail * vm) { vm->hide(); } void OpieMail::slotDownloadMail( ) { QListViewItem*item = mailView->currentItem(); if (!item ) { Global::statusMessage("Error: No item slected!"); return; } RecMailP mail = ((MailListViewItem*)item)->data(); Account * acc = mail->Wrapper()->getAccount(); if ( !acc ) { Global::statusMessage("Mail is already stored locally!"); |