-rw-r--r-- | noncore/net/mailit/smtpclient.cpp | 10 | ||||
-rw-r--r-- | noncore/unsupported/mailit/smtpclient.cpp | 10 |
2 files changed, 18 insertions, 2 deletions
diff --git a/noncore/net/mailit/smtpclient.cpp b/noncore/net/mailit/smtpclient.cpp index 3bdc072..6699a90 100644 --- a/noncore/net/mailit/smtpclient.cpp +++ b/noncore/net/mailit/smtpclient.cpp @@ -42,122 +42,130 @@ SmtpClient::~SmtpClient() void SmtpClient::newConnection(QString target, int port) { if (sending) { qWarning("socket in use, connection refused"); return; } status = Init; sending = TRUE; socket->connectToHost(target, port); emit updateStatus(tr("DNS lookup")); } void SmtpClient::addMail(QString from, QString subject, QStringList to, QString body) { RawEmail *mail = new RawEmail; mail->from = from; mail->subject = subject; mail->to = to; mail->body = body; mailList.append(mail); } void SmtpClient::connectionEstablished() { emit updateStatus(tr("Connection established")); } void SmtpClient::errorHandling(int status) { emit errorOccurred(status); socket->close(); mailList.clear(); sending = FALSE; } void SmtpClient::incomingData() { QString response; if (!socket->canReadLine()) return; response = socket->readLine(); - + qDebug(response); + switch(status) { case Init: { if (response[0] == '2') { status = From; mailPtr = mailList.first(); *stream << "HELO there\r\n"; + qDebug("HELO"); } else errorHandling(ErrUnknownResponse); break; } case From: { if (response[0] == '2') { *stream << "MAIL FROM: <" << mailPtr->from << ">\r\n"; status = Recv; + qDebug("MAIL FROM: "+mailPtr->from); } else errorHandling(ErrUnknownResponse); break; } case Recv: { if (response[0] == '2') { it = mailPtr->to.begin(); if (it == NULL) errorHandling(ErrUnknownResponse); *stream << "RCPT TO: <" << *it << ">\r\n"; + qDebug("RCPT TO: "+ *it); status = MRcv; } else errorHandling(ErrUnknownResponse); break; } case MRcv: { if (response[0] == '2') { it++; if ( it != mailPtr->to.end() ) { *stream << "RCPT TO: <" << *it << ">\r\n"; + qDebug("RCPT TO: "+ *it); break; } else { status = Data; } } else errorHandling(ErrUnknownResponse); } case Data: { if (response[0] == '2') { *stream << "DATA\r\n"; status = Body; + qDebug("DATA"); emit updateStatus(tr("Sending: ") + mailPtr->subject); } else errorHandling(ErrUnknownResponse); break; } case Body: { if (response[0] == '3') { *stream << mailPtr->body << "\r\n.\r\n"; mailPtr = mailList.next(); if (mailPtr != NULL) { status = From; } else { status = Quit; } + qDebug("BODY"); } else errorHandling(ErrUnknownResponse); break; } case Quit: { if (response[0] == '2') { *stream << "QUIT\r\n"; status = Done; QString temp; temp.setNum(mailList.count()); emit updateStatus(tr("Sent ") + temp + tr(" messages")); emit mailSent(); mailList.clear(); sending = FALSE; socket->close(); + qDebug("QUIT"); } else errorHandling(ErrUnknownResponse); break; } } } diff --git a/noncore/unsupported/mailit/smtpclient.cpp b/noncore/unsupported/mailit/smtpclient.cpp index 3bdc072..6699a90 100644 --- a/noncore/unsupported/mailit/smtpclient.cpp +++ b/noncore/unsupported/mailit/smtpclient.cpp @@ -42,122 +42,130 @@ SmtpClient::~SmtpClient() void SmtpClient::newConnection(QString target, int port) { if (sending) { qWarning("socket in use, connection refused"); return; } status = Init; sending = TRUE; socket->connectToHost(target, port); emit updateStatus(tr("DNS lookup")); } void SmtpClient::addMail(QString from, QString subject, QStringList to, QString body) { RawEmail *mail = new RawEmail; mail->from = from; mail->subject = subject; mail->to = to; mail->body = body; mailList.append(mail); } void SmtpClient::connectionEstablished() { emit updateStatus(tr("Connection established")); } void SmtpClient::errorHandling(int status) { emit errorOccurred(status); socket->close(); mailList.clear(); sending = FALSE; } void SmtpClient::incomingData() { QString response; if (!socket->canReadLine()) return; response = socket->readLine(); - + qDebug(response); + switch(status) { case Init: { if (response[0] == '2') { status = From; mailPtr = mailList.first(); *stream << "HELO there\r\n"; + qDebug("HELO"); } else errorHandling(ErrUnknownResponse); break; } case From: { if (response[0] == '2') { *stream << "MAIL FROM: <" << mailPtr->from << ">\r\n"; status = Recv; + qDebug("MAIL FROM: "+mailPtr->from); } else errorHandling(ErrUnknownResponse); break; } case Recv: { if (response[0] == '2') { it = mailPtr->to.begin(); if (it == NULL) errorHandling(ErrUnknownResponse); *stream << "RCPT TO: <" << *it << ">\r\n"; + qDebug("RCPT TO: "+ *it); status = MRcv; } else errorHandling(ErrUnknownResponse); break; } case MRcv: { if (response[0] == '2') { it++; if ( it != mailPtr->to.end() ) { *stream << "RCPT TO: <" << *it << ">\r\n"; + qDebug("RCPT TO: "+ *it); break; } else { status = Data; } } else errorHandling(ErrUnknownResponse); } case Data: { if (response[0] == '2') { *stream << "DATA\r\n"; status = Body; + qDebug("DATA"); emit updateStatus(tr("Sending: ") + mailPtr->subject); } else errorHandling(ErrUnknownResponse); break; } case Body: { if (response[0] == '3') { *stream << mailPtr->body << "\r\n.\r\n"; mailPtr = mailList.next(); if (mailPtr != NULL) { status = From; } else { status = Quit; } + qDebug("BODY"); } else errorHandling(ErrUnknownResponse); break; } case Quit: { if (response[0] == '2') { *stream << "QUIT\r\n"; status = Done; QString temp; temp.setNum(mailList.count()); emit updateStatus(tr("Sent ") + temp + tr(" messages")); emit mailSent(); mailList.clear(); sending = FALSE; socket->close(); + qDebug("QUIT"); } else errorHandling(ErrUnknownResponse); break; } } } |