[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kmail-devel
Subject:    kio_smtp patch
From:       "Aaron J. Seigo" <aseigo () mountlinux ! com>
Date:       2001-08-28 1:45:28
[Download RAW message or body]

hi...

i'm still working on the smtp auth stuff (if someone beats me too it, that is 
my own fault i suppose)... i would like to get the kmsender and kio_smtp 
patches into cvs as soon as practical however. i've attatched the diffs to 
this email and if Michael or someone else can review and if approved then 
commit them that would be great (i still haven't asked for a cvs account =).

thanks...

-- 
Aaron Seigo
["kio_smtp.patch" (text/x-diff)]

? kio_smtp.patch
Index: smtp.cc
===================================================================
RCS file: /home/projects/kdecvs/cvsroot/kdebase/kioslave/smtp/smtp.cc,v
retrieving revision 1.66
diff -u -3 -d -p -r1.66 smtp.cc
--- smtp.cc	2001/06/29 06:52:34	1.66
+++ smtp.cc	2001/08/28 01:42:05
@@ -140,28 +140,48 @@ void SMTPProtocol::HandleSMTPWriteError 
 	}
 }
 
+void SMTPProtocol::openConnection()
+{
+	if (smtp_open())
+	{
+		connected();
+	}
+	else
+	{
+		closeConnection();
+	}
+}
+
 // Usage: smtp://smtphost:port/send?to=user@host.com&subject=blah
 // If smtphost is the name of a profile, it'll use the information 
 // provided by that profile.  If it's not a profile name, it'll use it as
 // nature intended.
 // One can also specify in the query:
+// headers=0 (turns of header generation)
 // to=emailaddress
 // cc=emailaddress
 // bcc=emailaddress
 // subject=text
 // profile=text (this will override the "host" setting
-void SMTPProtocol::put (const KURL &url, int /*permissions*/, bool /*overwrite*/, \
bool /*resume*/) +void SMTPProtocol::put(const KURL &url, int /*permissions*/, bool \
/*overwrite*/, bool /*resume*/)  {
 	QString query = url.query();
 	QString subject = ASCII("missing subject");
 	QString profile = QString::null;
         QString from = QString::null;
 	QStringList recip, bcc, cc, temp_list;
+	bool headers = true;
 
 	GetAddresses(query, ASCII("to="), recip);
 	GetAddresses(query, ASCII("cc="), cc);
 	GetAddresses(query, ASCII("bcc="), bcc);
 
+	GetAddresses(query, ASCII("headers="), temp_list);
+	if (temp_list.count() && temp_list.last() == "0")
+	{
+		headers = false;
+	}
+
 	// find the subject
 	GetAddresses(query, ASCII("subject="), temp_list);
 	if (temp_list.count()) {
@@ -185,10 +205,14 @@ void SMTPProtocol::put (const KURL &url,
 	KURL open_url = url;
 	if (profile == QString::null) {
 	kdDebug() << "kio_smtp: Profile is null" << endl;
-		QStringList profiles = mset->profiles(); bool hasProfile=false;
+		QStringList profiles = mset->profiles(); 
+		bool hasProfile=false;
 		for (QStringList::Iterator it=profiles.begin(); it != profiles.end(); ++it) {
 			if ((*it) == open_url.host())
+			{
 				hasProfile=true;
+				break;
+			}
 		}
 		if (hasProfile) {
 			mset->setProfile(open_url.host());
@@ -226,7 +250,7 @@ void SMTPProtocol::put (const KURL &url,
 	}
 	from.prepend(ASCII("MAIL FROM: "));
 
-	if (!smtp_open(open_url))
+	if (!smtp_open())
 	        error(ERR_SERVICE_NOT_AVAILABLE, i18n("SMTPProtocol::smtp_open failed \
(%1)").arg(open_url.path()));  
 	if (!command(from)) {
@@ -245,36 +269,40 @@ void SMTPProtocol::put (const KURL &url,
 		HandleSMTPWriteError(open_url);
 	}
 
-	if (mset->getSetting(KEMailSettings::EmailAddress) != QString::null) {
-		if (mset->getSetting(KEMailSettings::RealName) != QString::null) {
-			from = ASCII("From: %1 \
<%2>\r\n").arg(mset->getSetting(KEMailSettings::RealName)).arg(mset->getSetting(KEMailSettings::EmailAddress));
 +	if (headers)
+	{
+		if (mset->getSetting(KEMailSettings::EmailAddress) != QString::null) {
+			if (mset->getSetting(KEMailSettings::RealName) != QString::null) {
+				from = ASCII("From: %1 \
<%2>\r\n").arg(mset->getSetting(KEMailSettings::RealName)) \
+						.arg(mset->getSetting(KEMailSettings::EmailAddress)); +			} else {
+				from = ASCII("From: \
%1\r\n").arg(mset->getSetting(KEMailSettings::EmailAddress)); +			}
 		} else {
-			from = ASCII("From: %1\r\n").arg(mset->getSetting(KEMailSettings::EmailAddress));
+			from = ASCII("From: %1\r\n").arg(DEFAULT_EMAIL);
 		}
-	} else {
-		from = ASCII("From: %1\r\n").arg(DEFAULT_EMAIL);
-	}
-	WRITE_STRING(from);
+		WRITE_STRING(from);
 
-	subject = ASCII("Subject: %1\r\n").arg(subject);
-	WRITE_STRING(subject);
+		subject = ASCII("Subject: %1\r\n").arg(subject);
+		WRITE_STRING(subject);
 
-	// Write out the To header for the benefit of the mail clients
-	query = ASCII("To: %1\r\n");
-	for ( QStringList::Iterator it = recip.begin(); it != recip.end(); ++it ) {
-		query = query.arg(*it);
-		WRITE_STRING(query);
-	}
+		// Write out the To header for the benefit of the mail clients
+		query = ASCII("To: %1\r\n");
+		for ( QStringList::Iterator it = recip.begin(); it != recip.end(); ++it ) {
+			query = query.arg(*it);
+			WRITE_STRING(query);
+		}
 
-	// Write out the CC header for the benefit of the mail clients
-	query = ASCII("CC: %1\r\n");
-	for ( QStringList::Iterator it = cc.begin(); it != cc.end(); ++it ) {
-		query = query.arg(*it);
-		WRITE_STRING(query);
+		// Write out the CC header for the benefit of the mail clients
+		query = ASCII("CC: %1\r\n");
+		for ( QStringList::Iterator it = cc.begin(); it != cc.end(); ++it ) {
+			query = query.arg(*it);
+			WRITE_STRING(query);
+		}
 	}
 
 	delete mset;
-
+	
 	// Loop until we got 0 (end of data)
 	int result;
 	QByteArray buffer;
@@ -397,10 +425,9 @@ bool SMTPProtocol::command (const QStrin
 	return (getResponse(recv_buf, len) < 400);
 }
 
-bool SMTPProtocol::smtp_open (const KURL &url)
+bool SMTPProtocol::smtp_open()
 {
-	kdDebug () << "kio_smtp: IT WANTS " << url.host() << endl;
-	if ( (m_iOldPort == GetPort(m_iPort)) && (m_sOldServer == m_sServer) && (m_sOldUser \
== m_sUser) ) { +	if (opened && (m_iOldPort == GetPort(m_iPort)) && (m_sOldServer == \
m_sServer) && (m_sOldUser == m_sUser)) {  return true;
 	} else {
 		smtp_close();
@@ -458,17 +485,14 @@ bool SMTPProtocol::smtp_open (const KURL
 
 	// Now we try and login
 	if (!m_sUser.isNull()) {
-		KURL auth_url=url;
 		if (m_sPass.isNull()) {
 			QString head=i18n("Username and password for your SMTP account:");
                         if (!openPassDlg(head, m_sUser, m_sPass)) {
 				error(ERR_COULD_NOT_LOGIN, i18n("When prompted, you ran away."));
 				return false;
 			}
-			auth_url.setPass(m_sPass);
-			auth_url.setUser(m_sUser);
 		}
-		if (!Authenticate(auth_url)) {
+		if (!Authenticate()) {
 			error(ERR_COULD_NOT_LOGIN, i18n("Authentication failed"));
 			return false;
 		}
@@ -482,7 +506,7 @@ bool SMTPProtocol::smtp_open (const KURL
 	return true;
 }
 
-bool SMTPProtocol::Authenticate (const KURL &url)
+bool SMTPProtocol::Authenticate()
 {
 	bool ret;
 	QString auth_method;
@@ -490,7 +514,7 @@ bool SMTPProtocol::Authenticate (const K
 	// Generate a new context.. now this isn't the most efficient way of doing things, \
but for now this suffices  if (m_pSASL)
 		delete m_pSASL;
-	m_pSASL = new KDESasl(url);
+	m_pSASL = new KDESasl(m_sUser, m_sPass);
 
 	// Choose available method from what the server has given us in  its greeting
 	QStringList sl = QStringList::split(' ', m_sAuthConfig);
Index: smtp.h
===================================================================
RCS file: /home/projects/kdecvs/cvsroot/kdebase/kioslave/smtp/smtp.h,v
retrieving revision 1.23
diff -u -3 -d -p -r1.23 smtp.h
--- smtp.h	2001/06/29 06:52:34	1.23
+++ smtp.h	2001/08/28 01:42:05
@@ -44,14 +44,15 @@ public:
 
 	virtual void put (const KURL &url, int permissions, bool overwrite, bool resume);
 	virtual void stat (const KURL &url);
+	virtual void openConnection();
 
 protected:
 
-	bool smtp_open (const KURL &u);
+	bool smtp_open ();
 	void smtp_close ();
 	bool command (const QString &buf, char *r_buf = NULL, unsigned int r_len = 0);
 	int getResponse (char *real_buf = NULL, unsigned int real_len = 0);
-	bool Authenticate (const KURL &url);
+	bool Authenticate ();
 	void HandleSMTPWriteError (const KURL &url);
 	void ParseFeatures (const char *buf);
 	void PutRecipients (QStringList &list, const KURL &url);


["kmail.patch" (text/x-diff)]

Index: kmsender.cpp
===================================================================
RCS file: /home/projects/kdecvs/cvsroot/kdenetwork/kmail/kmsender.cpp,v
retrieving revision 1.112
diff -u -3 -d -p -r1.112 kmsender.cpp
--- kmsender.cpp	2001/07/26 18:32:56	1.112
+++ kmsender.cpp	2001/08/28 01:40:38
@@ -16,6 +16,10 @@
 
 #include <kdebug.h>
 #include <kconfig.h>
+#include <kio/global.h>
+#include <kio/job.h>
+#include <kio/scheduler.h>
+#include <kio/slave.h>
 #include <kprocess.h>
 #include <kapp.h>
 #include <kmessagebox.h>
@@ -51,7 +55,9 @@ KMSender::KMSender()
   mMsgSendProc = NULL;
   mSendProcStarted = FALSE;
   mSendInProgress = FALSE;
+  mUseSSL = FALSE;
   mCurrentMsg = NULL;
+  mSendInfoChanged = FALSE;
   labelDialog = 0;
   readConfig();
   quitOnDone = false;
@@ -63,7 +69,8 @@ KMSender::KMSender()
 KMSender::~KMSender()
 {
   writeConfig(FALSE);
-  if (mSendProc) delete mSendProc;
+  delete mSendProc;
+  delete labelDialog;
 }
 
 //-----------------------------------------------------------------------------
@@ -89,11 +96,16 @@ void KMSender::readConfig(void)
   mSmtpHost = config->readEntry("Smtp Host", "localhost");
   mSmtpPort = config->readNumEntry("Smtp Port", 25);
   mPrecommand = config->readEntry("Precommand", "");
-
+  mUsername = config->readEntry("Smtp Username", "");
+  mPassword = config->readEntry("Smtp Password", "");
+  mUseSSL = (bool) config->readNumEntry("SSL", FALSE);
+  
   str = config->readEntry("Method");
   if (str=="mail") mMethod = smMail;
   else if (str=="smtp") mMethod = smSMTP;
   else mMethod = smUnknown;
+  
+  mSendInfoChanged = true;
 }
 
 
@@ -108,7 +120,20 @@ void KMSender::writeConfig(bool aWithSyn
   config->writeEntry("Mailer", mMailer);
   config->writeEntry("Smtp Host", mSmtpHost);
   config->writeEntry("Smtp Port", (int)mSmtpPort);
-  config->writeEntry("Method", (mMethod==smSMTP) ? "smtp" : "mail");
+  config->writeEntry("Smtp Username", mUsername);
+  config->writeEntry("Smtp Password", mPassword);
+  switch(mMethod)
+  {
+  case smMail:
+    config->writeEntry("Method", "mail");
+    break;
+  case smSMTP:
+    config->writeEntry("Method", "smtp");
+    break;
+  case smUnknown:
+    config->writeEntry("Method", "unknown");
+    break;
+  }  
   config->writeEntry("Precommand", mPrecommand);
 
   if (aWithSync) config->sync();
@@ -228,16 +253,22 @@ bool KMSender::sendQueued(void)
 
   kernel->sentFolder()->open();
 
-
-  // create a sender
-  if (mSendProc) delete mSendProc;
-  if (mMethod == smMail) mSendProc = new KMSendSendmail(this,mMailer);
-  else if (mMethod == smSMTP) mSendProc = new KMSendSMTP(this,mSmtpHost,mSmtpPort);
-  else mSendProc = NULL;
-  assert(mSendProc != NULL);
-  connect(mSendProc,SIGNAL(idle()),SLOT(slotIdle()));
-  connect(mSendProc,SIGNAL(started(bool)),this,SLOT(sendProcStarted(bool)));
 
+  // create a sender, but only if it isn't already created
+  if (mSendInfoChanged == true || !mSendProc || mSendProc->sendType() != mMethod) 
+  {
+    mSendInfoChanged = false;
+    delete mSendProc;
+    
+    if (mMethod == smMail) mSendProc = new KMSendSendmail(this,mMailer);
+    else if (mMethod == smSMTP) mSendProc = new KMSendSMTP(this, mSmtpHost, mSmtpPort);
+    else mSendProc = NULL;
+    
+    assert(mSendProc != NULL);
+    connect(mSendProc,SIGNAL(idle()),SLOT(slotIdle()));
+    connect(mSendProc,SIGNAL(started(bool)),this,SLOT(sendProcStarted(bool)));
+  }
+  
   // start sending the messages
   doSendMsg();
   return TRUE;
@@ -522,6 +553,7 @@ void KMSender::slotIdle()
 void KMSender::setMethod(Method aMethod)
 {
   mMethod = aMethod;
+  mSendInfoChanged = true;
 }
 
 
@@ -543,6 +575,7 @@ void KMSender::setSendQuotedPrintable(bo
 void KMSender::setMailer(const QString& aMailer)
 {
   mMailer = aMailer;
+  mSendInfoChanged = true;
 }
 
 
@@ -550,6 +583,7 @@ void KMSender::setMailer(const QString& 
 void KMSender::setSmtpHost(const QString& aSmtpHost)
 {
   mSmtpHost = aSmtpHost;
+  mSendInfoChanged = true;
 }
 
 
@@ -557,10 +591,25 @@ void KMSender::setSmtpHost(const QString
 void KMSender::setSmtpPort(unsigned short int aSmtpPort)
 {
   mSmtpPort = aSmtpPort;
+  mSendInfoChanged = true;
 }
 
+//-----------------------------------------------------------------------------
+void KMSender::setUsername(const QString& aUsername)
+{
+  mUsername = aUsername;
+  mSendInfoChanged = true;
+}
 
 //-----------------------------------------------------------------------------
+void KMSender::setPassword(const QString& aPassword)
+{
+  mPassword = aPassword;
+  mSendInfoChanged = true;
+}
+
+
+//-----------------------------------------------------------------------------
 KMSendProc* KMSender::createSendProcFromString(QString transport)
 {
   if (transport.left(7) == "smtp://") { // to i18n or not to i18n?
@@ -572,7 +621,7 @@ KMSendProc* KMSender::createSendProcFrom
       server = serverport.left(colon);
       port = serverport.mid(colon + 1);
     }
-    return new KMSendSMTP(this,server,port.toInt());
+    return new KMSendSMTP(this, server, serverport.toUInt());
   }
   else if (transport.left(7) == "file://") {
     return new KMSendSendmail(this,transport.mid(7));
@@ -918,7 +967,7 @@ void KMSendSendmail::sendmailExited(KPro
 
 
 //-----------------------------------------------------------------------------
-bool KMSendSendmail::addOneRecipient(const QString &aRcpt)
+bool KMSendSendmail::addOneRecipient(const QString& aRcpt)
 {
   assert(mMailerProc!=NULL);
   if (!aRcpt.isEmpty()) *mMailerProc << aRcpt;
@@ -926,143 +975,178 @@ bool KMSendSendmail::addOneRecipient(con
 }
 
 
+
+//-----------------------------------------------------------------------------
 //=============================================================================
 //=============================================================================
-KMSendSMTP::KMSendSMTP(KMSender* aSender, QString smtpHost,
-		       unsigned short int smtpPort ):
-    KMSendSMTPInherited(aSender), mSmtpHost(smtpHost), mSmtpPort(smtpPort)
+KMSendSMTP::KMSendSMTP(KMSender *_sender, QString server, unsigned short int port)
+  : KMSendProc(_sender), 
+    mJob(0),
+    mSlave(0),
+    mUseSSL(false),
+    mUseTLS(false),
+    mInProcess(false),
+    mServer(server),
+    mPort(port)
 {
-  smtp = 0;
+  if (mPort == 0) { mPort = 25; }
+  KIO::Scheduler::connect(SIGNAL(slaveError(KIO::Slave *, int, const QString &)),
+                          this, SLOT(slaveError(KIO::Slave *, int, const QString &)));
 }
 
-//-----------------------------------------------------------------------------
 KMSendSMTP::~KMSendSMTP()
 {
+    if (mJob) mJob->kill();
 }
 
-//-----------------------------------------------------------------------------
-void KMSendSMTP::start(void)
+bool KMSendSMTP::send(KMMessage *aMsg)
 {
-  statusMsg(i18n("connecting to server"));
-  emit started(true);
-}
+  assert(aMsg != NULL);
 
-//-----------------------------------------------------------------------------
-bool KMSendSMTP::finish(bool destructive)
-{
-  if (smtp) {
-    disconnect( smtp, SIGNAL(error(const QString&, const QString&)),
-	        this, SLOT(smtpFailed(const QString&, const QString& )) );
-    disconnect( smtp, SIGNAL(success()),
-		this, SIGNAL(idle()) );
-    smtp->quit();
-  }
-  smtp = 0;
-  if (destructive)
-      delete this;
-  return TRUE;
-}
+  // email this is from
+  mQuery = QString("headers=0&from=%1").arg(KMMessage::getEmailAddr(aMsg->from()));
+  aMsg->removeHeaderField("From");
 
-//-----------------------------------------------------------------------------
-void KMSendSMTP::abort()
-{
-  if (smtp) {
-    disconnect( smtp, SIGNAL(error(const QString&, const QString&)),
-	        this, SLOT(smtpFailed(const QString&, const QString& )) );
-    disconnect( smtp, SIGNAL(success()),
-		this, SIGNAL(idle()) );
-    smtp->quit();
+  // recipients
+  mQueryField = "&to=";
+  if(!addRecipients(aMsg->headerAddrField("To"))) 
+  {
+    return FALSE;
   }
-  smtp = 0;
-  idle();
-}
-
 
-//-----------------------------------------------------------------------------
-bool KMSendSMTP::send(KMMessage *msg)
-{
-  mSendOk = smtpSend(msg);
-  return mSendOk;
-}
+  if(!aMsg->cc().isEmpty())
+  {
+    mQueryField = "&cc=";
+    if(!addRecipients(aMsg->headerAddrField("Cc"))) return FALSE;
+  }
 
+  if(!aMsg->bcc().isEmpty())
+  {
+    mQueryField = "&bcc=";
+    if (!addRecipients(aMsg->headerAddrField("Bcc"))) return FALSE;
+    aMsg->removeHeaderField("Bcc");
+  }
 
-//-----------------------------------------------------------------------------
-bool KMSendSMTP::smtpSend(KMMessage* aMsg)
-{
-  QString str, msgStr, bccStr;
-  QString idStr = aMsg->headerField("X-KMail-Identity");
-  aMsg->removeHeaderField("X-KMail-Identity");
-  KMIdentity ident( idStr.isEmpty() ? i18n( "Default" ) : idStr );
-  ident.readConfig();
+  if(!aMsg->subject().isEmpty())
+    mQuery += QString("&subject=") + aMsg->subject();
+  
+  KURL destination;
+ 
+  if (mUseSSL)
+  {
+     destination.setProtocol("smtps");
+  }
+  else
+  {
+    destination.setProtocol("smtp");
+  }
+    
+  destination.setHost(mServer);
+  destination.setPort(mPort);
+  
+  if (!mSender->username().isEmpty())
+      destination.setUser(mSender->username());
+  if (!mSender->password().isEmpty())
+      destination.setPass(mSender->password());
+  
 
-  assert(aMsg != NULL);
-  recipients.clear();
+  if (!mSlave || !mInProcess)
+  {
+    mSlave = KIO::Scheduler::getConnectedSlave(destination.url(), mSlaveConfig);
+  }
 
-  if (!addRecipients(aMsg->headerAddrField("To"))) return FALSE;
+  if (!mSlave)
+  {
+    abort();
+    return false;
+  }
+  
+  destination.setPath("/send");
+  destination.setQuery(mQuery);
 
-  if (!aMsg->cc().isEmpty())
-    if (!addRecipients(aMsg->headerAddrField("Cc"))) return FALSE;
+  mQuery = "";
 
-  bccStr = aMsg->bcc();
-  if (!bccStr.isEmpty())
+  mMessage = prepareStr(aMsg->asString(), TRUE);
+  
+  if (mJob = KIO::put(destination, -1, false, false, false))
   {
-    if (!addRecipients(aMsg->headerAddrField("Bcc"))) return FALSE;
-    aMsg->removeHeaderField("Bcc");
+      KIO::Scheduler::assignJobToSlave(mSlave, mJob);
+      connect(mJob, SIGNAL(result(KIO::Job *)), this, SLOT(result(KIO::Job *)));
+      connect(mJob, SIGNAL(dataReq(KIO::Job *, QByteArray &)), 
+              this, SLOT(dataReq(KIO::Job *, QByteArray &)));
+      mSendOk = true;
+      mInProcess = true;
+      return mSendOk;
   }
-
-  msgStr = prepareStr(aMsg->asString(), TRUE );
-  if (!smtp) {
-      smtp = new Smtp( ident.emailAddr(), recipients,
-		       msgStr,
-		       mSmtpHost,
-		       mSmtpPort );
-      connect( smtp, SIGNAL(error(const QString&, const QString&)),
-	       this, SLOT(smtpFailed(const QString&, const QString& )) );
-      connect( smtp, SIGNAL(success()),
-	       this, SIGNAL(idle()) );
-  } else {
-      smtp->send( ident.emailAddr(), recipients, msgStr );
+  else 
+  {
+    abort();
+    return false;
   }
+}
 
-  if (!bccStr.isEmpty()) aMsg->setBcc(bccStr);
-  return TRUE;
+void KMSendSMTP::abort()
+{
+  finish(false);
+  emit idle();
 }
 
+bool KMSendSMTP::finish(bool b)
+{
+  if(mJob)
+  {
+    mJob->kill();
+    mJob = 0;
+  }
+  
+  if (mSlave)
+  {
+    KIO::Scheduler::disconnectSlave(mSlave);
+    mSlave = 0;
+  }
+  
+  mInProcess = false;
+  return KMSendProc::finish(b);
+}
 
-//-----------------------------------------------------------------------------
-bool KMSendSMTP::addOneRecipient(const QString &aRcpt)
+bool KMSendSMTP::addOneRecipient(const QString& _addr)
 {
-  if (aRcpt.isEmpty()) return TRUE;
+  if(!_addr.isEmpty())
+    mQuery += mQueryField + _addr;
 
-  recipients.append( aRcpt );
-  return TRUE;
+  return true;
 }
 
-
-//-----------------------------------------------------------------------------
-void KMSendSMTP::smtpFailed(const QString &command,
-			    const QString &response)
+void KMSendSMTP::dataReq(KIO::Job *, QByteArray &array)
 {
-  failed( i18n("a SMTP error occured.\n"
-	     "Command: %1\n"
-	     "Response: %2")
-	  .arg(command)
-	  .arg(response) );
-  if (smtp)
-      delete smtp;
-  smtp = 0;
-  idle();
+  if(mMessage.length())
+  {
+    array.duplicate(mMessage);
+    mMessage = "";
+  }
 }
 
-
-//-----------------------------------------------------------------------------
-void KMSendSMTP::smtpInCmd(const char* inCommand)
+void KMSendSMTP::result(KIO::Job *_job)
 {
-  QString str;
-  str = i18n("Sending SMTP command: %1").arg(inCommand);
-  statusMsg(str);
+  mJob = 0;
+
+  if(_job->error())
+  {
+    mSendOk = false;
+    failed(_job->errorString());
+  }
+
+  emit idle();
 }
 
+void KMSendSMTP::slaveError(KIO::Slave *aSlave, int error, const QString &errorMsg)
+{
+  if (aSlave == mSlave)
+  {
+    mSendOk = false;
+    failed(errorMsg);
+    abort();
+  }
+}
 
-//-----------------------------------------------------------------------------
 #include "kmsender.moc"
Index: kmsender.h
===================================================================
RCS file: /home/projects/kdecvs/cvsroot/kdenetwork/kmail/kmsender.h,v
retrieving revision 1.33
diff -u -3 -d -p -r1.33 kmsender.h
--- kmsender.h	2001/06/29 18:18:21	1.33
+++ kmsender.h	2001/08/28 01:40:38
@@ -7,10 +7,12 @@
 #include <mimelib/smtp.h>
 #include <mimelib/string.h>
 #include <mimelib/utility.h>
+#include <qcstring.h>
 #include <qstring.h>
 #include <qstringlist.h>
 #include <qobject.h>
 #include <qlabel.h>
+#include "kio/global.h"
 
 class KMMessage;
 class KMFolder;
@@ -24,13 +26,20 @@ class QStrList;
 class KMainWindow;
 class Smtp;
 
+namespace KIO
+{
+  class Job;
+  class TransferJob;
+  class Slave;
+}
+
 class KMSender: public QObject
 {
   Q_OBJECT
   friend class KMSendProc;
 
 public:
-  enum Method { smUnknown=0, smSMTP=1, smMail=2 };
+  enum Method { smUnknown=0, smSMTP=1, smMail=2, smKIOSMTP = 3 };
 
   KMSender();
   virtual ~KMSender();
@@ -79,6 +88,14 @@ public:
   unsigned short int smtpPort(void) const { return mSmtpPort; }
   virtual void setSmtpPort(unsigned short int);
 
+  /** Username to use for loging in if appropriate */
+  QString username(void) const { return mUsername; }
+  virtual void setUsername(const QString&);
+
+  /** Password to use for loging in if appropriate */
+  QString password(void) const { return mPassword; }
+  virtual void setPassword(const QString&);
+
   /** Precommand - command run before sending */
   const QString& precommand(void) const { return mPrecommand; }
   virtual void setPrecommand(const QString& cmd) { mPrecommand = cmd; }
@@ -135,13 +152,18 @@ protected:
 
 private:
   Method mMethod;
-  bool mSendImmediate, mSendQuotedPrintable;
+  bool mSendImmediate;
+  bool mSendQuotedPrintable;
+  bool mUseSSL;
   QString mMailer;
   QString mSmtpHost;
+  QString mUsername;
+  QString mPassword;
   unsigned short int mSmtpPort;
   QString mPrecommand;
 
   bool mSentOk, mSendAborted;
+  bool mSendInfoChanged;
   QString mErrorMsg;
   KMIOStatusDlg* mSendDlg;
   KMSendProc *mSendProc, *mMsgSendProc;
@@ -163,7 +185,8 @@ class KMSendProc: public QObject
 
 public:
   KMSendProc(KMSender*);
-
+  virtual ~KMSendProc() {}
+  
   /** Initialize sending of one or more messages. */
   virtual void start(void);
 
@@ -179,6 +202,9 @@ public:
   /** Abort sending the current message. Sets mSending to false */
   virtual void abort() = 0;
 
+  /** Return the type so we can identify it at run time **/
+  virtual KMSender::Method sendType() { return KMSender::smUnknown; }
+  
   /** Returns TRUE if send was successful, and FALSE otherwise.
       Returns FALSE if sending is still in progress. */
   bool sendOk(void) const { return mSendOk; }
@@ -242,6 +268,7 @@ public:
   virtual bool send(KMMessage* msg);
   virtual bool finish(bool destructive);
   virtual void abort();
+  KMSender::Method sendType() { return KMSender::smMail; }
 
 protected slots:
   void receivedStderr(KProcess*,char*,int);
@@ -259,30 +286,40 @@ protected:
 };
 
 //-----------------------------------------------------------------------------
-#define KMSendSMTPInherited KMSendProc
-class KMSendSMTP: public KMSendProc
+class KMSendSMTP : public KMSendProc
 {
-  Q_OBJECT
+Q_OBJECT
 public:
-  KMSendSMTP(KMSender*,QString,unsigned short int);
-  virtual ~KMSendSMTP();
-  virtual void start(void);
-  virtual bool send(KMMessage* msg);
-  virtual bool finish(bool destructive);
+  KMSendSMTP(KMSender *_sender, QString server, unsigned short int port);
+  ~KMSendSMTP();
+  
+  virtual bool send(KMMessage *);
   virtual void abort();
-
-public slots:
-  virtual void smtpFailed(const QString&, const QString &);
+  virtual bool finish(bool);
+  KMSender::Method sendType() { return KMSender::smSMTP; }
 
 protected:
-  virtual bool smtpSend(KMMessage* msg);
-  virtual void smtpInCmd(const char* inCommand);
   virtual bool addOneRecipient(const QString& aRecipient);
 
-  Smtp *smtp;
-  QStringList recipients;
-  QString mSmtpHost;
-  unsigned short int mSmtpPort;
+private slots:
+  void dataReq(KIO::Job *, QByteArray &);
+  void result(KIO::Job *);
+  void slaveError(KIO::Slave *, int, const QString &);
+
+private:
+  QString mServer;
+  unsigned short int mPort;
+  QString mQuery;
+  QString mQueryField;
+  QCString mMessage;
+
+  bool mUseSSL;
+  bool mUseTLS;
+  bool mInProcess;
+  
+  KIO::TransferJob *mJob;
+  KIO::Slave *mSlave;
+  KIO::MetaData mSlaveConfig;
 };
 
 #endif /*kmsender_h*/

_______________________________________________
Kmail Developers mailing list
Kmail@mail.kde.org
http://mail.kde.org/mailman/listinfo/kmail


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic