summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2003-04-06 18:09:49 (UTC)
committer llornkcor <llornkcor>2003-04-06 18:09:49 (UTC)
commitedbdd8c8df7ff99f4273ae0296386fecf4f3b189 (patch) (side-by-side diff)
tree4d4c68fbf014ff762c3d3402bcdec5814128037e
parent8bc3b4fff609fa7f4809173724ab197ec08e599a (diff)
downloadopie-edbdd8c8df7ff99f4273ae0296386fecf4f3b189.zip
opie-edbdd8c8df7ff99f4273ae0296386fecf4f3b189.tar.gz
opie-edbdd8c8df7ff99f4273ae0296386fecf4f3b189.tar.bz2
add some tr to status messages
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mailit/popclient.cpp22
-rw-r--r--noncore/net/mailit/smtpclient.cpp8
-rw-r--r--noncore/unsupported/mailit/popclient.cpp22
-rw-r--r--noncore/unsupported/mailit/smtpclient.cpp8
4 files changed, 30 insertions, 30 deletions
diff --git a/noncore/net/mailit/popclient.cpp b/noncore/net/mailit/popclient.cpp
index a406af2..2f14ed2 100644
--- a/noncore/net/mailit/popclient.cpp
+++ b/noncore/net/mailit/popclient.cpp
@@ -36,340 +36,340 @@ PopClient::PopClient()
stream = new QTextStream(socket);
receiving = FALSE;
synchronize = FALSE;
lastSync = 0;
headerLimit = 0;
preview = FALSE;
}
PopClient::~PopClient()
{
delete socket;
delete stream;
}
void PopClient::newConnection(QString target, int port)
{
if (receiving) {
qWarning("socket in use, connection refused");
return;
}
status = Init;
socket->connectToHost(target, port);
receiving = TRUE;
selected = FALSE;
emit updateStatus("DNS lookup");
}
void PopClient::setAccount(QString popUser, QString popPasswd)
{
popUserName = popUser;
popPassword = popPasswd;
}
void PopClient::setSynchronize(int lastCount)
{
synchronize = TRUE;
lastSync = lastCount;
}
void PopClient::removeSynchronize()
{
synchronize = FALSE;
lastSync = 0;
}
void PopClient::headersOnly(bool headers, int limit)
{
preview = headers;
headerLimit = limit;
}
void PopClient::setSelectedMails(MailList *list)
{
selected = TRUE;
mailList = list;
}
void PopClient::connectionEstablished()
{
- emit updateStatus("Connection established");
+ emit updateStatus(tr("Connection established"));
}
void PopClient::errorHandling(int status)
{
- emit updateStatus("Error Occured");
+ emit updateStatus(tr("Error Occured"));
emit errorOccurred(status);
socket->close();
receiving = FALSE;
}
void PopClient::incomingData()
{
QString response, temp, temp2, timeStamp;
QString md5Source;
int start, end;
// char *md5Digest;
char md5Digest[16];
// if ( !socket->canReadLine() )
// return;
response = socket->readLine();
qDebug(response +" %d", status);
switch(status) {
//logging in
case Init: {
#ifdef APOP_TEST
start = response.find('<',0);
end = response.find('>', start);
if( start >= 0 && end > start )
{
timeStamp = response.mid( start , end - start + 1);
md5Source = timeStamp + popPassword;
qDebug( md5Source);
// for( int i = 0; i < md5Source.length(); i++) {
// buff[i] = (QChar)md5Source[i];
// }
md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]);
// md5_buffer(char const *buffer, unsigned int len, char *digest);
// MD5_Init( &ctx);
// MD5_Update( &ctx, buff, sizeof( buff) );
// MD5_Final( md5Digest, &ctx);
// MD5( buff, md5Source.length(), md5Digest);
for(int j =0;j < MD5_DIGEST_LENGTH ;j++)
{
printf("%x", md5Digest[j]);
}
printf("\n");
// qDebug(md5Digest);
*stream << "APOP " << popUserName << " " << md5Digest << "\r\n";
// qDebug("%s", stream);
status = Stat;
}
else
#endif
{
timeStamp = "";
*stream << "USER " << popUserName << "\r\n";
status = Pass;
}
break;
}
//password shhh. don't tell anyone (implement APOP...)
case Pass: {
*stream << "PASS " << popPassword << "\r\n";
status = Stat;
break;
}
//ask for number of messages
case Stat: {
if (response[0] == '+') {
*stream << "STAT" << "\r\n";
status = Mcnt;
} else errorHandling(ErrLoginFailed);
break;
}
//get count of messages, eg "+OK 4 900.." -> int 4
case Mcnt: {
if (response[0] == '+') {
temp = response.replace(0, 4, "");
int x = temp.find(" ", 0);
temp.truncate((uint) x);
newMessages = temp.toInt();
messageCount = 1;
status = List;
if (synchronize) {
//messages deleted from server, reload all
if (newMessages < lastSync)
lastSync = 0;
messageCount = lastSync + 1;
}
if (selected) {
int *ptr = mailList->first();
if (ptr != 0) {
newMessages++; //to ensure no early jumpout
messageCount = *(mailList->first());
} else newMessages = 0;
}
} else errorHandling(ErrUnknownResponse);
}
//Read message number x, count upwards to messageCount
case List: {
if (messageCount <= newMessages) {
*stream << "LIST " << messageCount << "\r\n";
status = Size;
temp2.setNum(newMessages - lastSync);
temp.setNum(messageCount - lastSync);
if (!selected) {
- emit updateStatus("Retrieving " + temp + "/" + temp2);
+ emit updateStatus(tr("Retrieving ") + temp + "/" + temp2);
} else {
//completing a previously closed transfer
if ( (messageCount - lastSync) <= 0) {
temp.setNum(messageCount);
- emit updateStatus("Previous message " + temp);
+ emit updateStatus(tr("Previous message ") + temp);
} else {
- emit updateStatus("Completing message " + temp);
+ emit updateStatus(tr("Completing message ") + temp);
}
}
break;
} else {
- emit updateStatus("No new Messages");
+ emit updateStatus(tr("No new Messages"));
status = Quit;
}
}
//get size of message, eg "500 characters in message.." -> int 500
case Size: {
if (status != Quit) { //because of idiotic switch
if (response[0] == '+') {
temp = response.replace(0, 4, "");
int x = temp.find(" ", 0);
temp = temp.right(temp.length() - ((uint) x + 1) );
mailSize = temp.toInt();
emit currentMailSize(mailSize);
status = Retr;
} else {
qWarning(response);
errorHandling(ErrUnknownResponse);
}
}
}
//Read message number x, count upwards to messageCount
case Retr: {
if (status != Quit) {
if (!preview || mailSize <= headerLimit) {
*stream << "RETR " << messageCount << "\r\n";
} else { //only header
*stream << "TOP " << messageCount << " 0\r\n";
}
messageCount++;
status = Ignore;
break;
} }
case Ignore: {
if (status != Quit) { //because of idiotic switch
if (response[0] == '+') {
message = "";
status = Read;
if (!socket->canReadLine()) //sync. problems
break;
response = socket->readLine();
} else errorHandling(ErrUnknownResponse);
}
}
//add all incoming lines to body. When size is reached, send
//message, and go back to read new message
case Read: {
if (status != Quit) { //because of idiotic switch
message += response;
while ( socket->canReadLine() ) {
response = socket->readLine();
message += response;
}
emit downloadedSize(message.length());
int x = message.find("\r\n.\r\n",-5);
if (x == -1) {
break;
} else { //message reach entire size
//complete mail downloaded
if ( (!preview ) || ((preview) && (mailSize <= headerLimit)) ){
emit newMessage(message, messageCount-1, mailSize, TRUE);
} else { //incomplete mail downloaded
emit newMessage(message, messageCount-1, mailSize, FALSE);
}
if (messageCount > newMessages) //that was the last message
status = Quit;
else { //ask for new message
if (selected) { //grab next from queue
int *ptr = mailList->next();
if (ptr != 0) {
messageCount = *ptr;
*stream << "LIST " << messageCount << "\r\n";
status = Size;
//completing a previously closed transfer
if ( (messageCount - lastSync) <= 0) {
temp.setNum(messageCount);
- emit updateStatus("Previous message " + temp);
+ emit updateStatus(tr("Previous message ") + temp);
} else {
temp.setNum(messageCount - lastSync);
- emit updateStatus("Completing message " + temp);
+ emit updateStatus(tr("Completing message ") + temp);
}
break;
} else {
newMessages--;
status = Quit;
}
} else {
*stream << "LIST " << messageCount << "\r\n";
status = Size;
temp2.setNum(newMessages - lastSync);
temp.setNum(messageCount - lastSync);
- emit updateStatus("Retrieving " + temp + "/" + temp2);
+ emit updateStatus(tr("Retrieving ") + temp + "/" + temp2);
break;
}
}
}
if (status != Quit)
break;
}
}
case Quit: {
*stream << "Quit\r\n";
status = Done;
int newM = newMessages - lastSync;
if (newM > 0) {
temp.setNum(newM);
- emit updateStatus(temp + " new messages");
+ emit updateStatus(temp + tr(" new messages"));
} else {
- emit updateStatus("No new messages");
+ emit updateStatus(tr("No new messages"));
}
socket->close();
receiving = FALSE;
emit mailTransfered(newM);
break;
}
}
}
// if( bAPOPAuthentication )
// {
// if( m_strTimeStamp.IsEmpty() )
// {
// SetLastError("Apop error!");
// return false;
// }
// strMD5Source = m_strTimeStamp+pszPassword;
// strMD5Dst = MD5_GetMD5( (BYTE*)(const char*)strMD5Source , strMD5Source.GetLength() );
// sprintf(msg , "apop %s %s\r\n" , pszUser , strMD5Dst);
// ret = send(m_sPop3Socket , msg , strlen(msg) , NULL);
// if(ret == SOCKET_ERROR)
// {
// SetLastError("Socket error!");
// m_bSocketOK = false;
// m_bConnected = false;
// return false;
// }
// if( !GetSocketResult(&strResult , COMMAND_END_FLAG) )
// return false;
// if( 0 == strResult.Find('-' , 0) )
// {
// SetLastError("Username or Password error!");
// return false;
// }
// m_bConnected = true;
// }
diff --git a/noncore/net/mailit/smtpclient.cpp b/noncore/net/mailit/smtpclient.cpp
index 7bb7933..3bdc072 100644
--- a/noncore/net/mailit/smtpclient.cpp
+++ b/noncore/net/mailit/smtpclient.cpp
@@ -1,163 +1,163 @@
/**********************************************************************
** Copyright (C) 2001 Trolltech AS. All rights reserved.
**
** This file is part of Qt Palmtop Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "smtpclient.h"
#include "emailhandler.h"
SmtpClient::SmtpClient()
{
socket = new QSocket(this, "smtpClient");
stream = new QTextStream(socket);
mailList.setAutoDelete(TRUE);
connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int)));
connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished()));
connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData()));
sending = FALSE;
}
SmtpClient::~SmtpClient()
{
delete socket;
delete stream;
}
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("DNS lookup");
+ 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("Connection established");
+ 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();
switch(status) {
case Init: {
if (response[0] == '2') {
status = From;
mailPtr = mailList.first();
*stream << "HELO there\r\n";
} else errorHandling(ErrUnknownResponse);
break;
}
case From: {
if (response[0] == '2') {
*stream << "MAIL FROM: <" << mailPtr->from << ">\r\n";
status = Recv;
} 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";
status = MRcv;
} else errorHandling(ErrUnknownResponse);
break;
}
case MRcv: {
if (response[0] == '2') {
it++;
if ( it != mailPtr->to.end() ) {
*stream << "RCPT TO: <" << *it << ">\r\n";
break;
} else {
status = Data;
}
} else errorHandling(ErrUnknownResponse);
}
case Data: {
if (response[0] == '2') {
*stream << "DATA\r\n";
status = Body;
- emit updateStatus("Sending: " + mailPtr->subject);
+ 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;
}
} else errorHandling(ErrUnknownResponse);
break;
}
case Quit: {
if (response[0] == '2') {
*stream << "QUIT\r\n";
status = Done;
QString temp;
temp.setNum(mailList.count());
- emit updateStatus("Sent " + temp + " messages");
+ emit updateStatus(tr("Sent ") + temp + tr(" messages"));
emit mailSent();
mailList.clear();
sending = FALSE;
socket->close();
} else errorHandling(ErrUnknownResponse);
break;
}
}
}
diff --git a/noncore/unsupported/mailit/popclient.cpp b/noncore/unsupported/mailit/popclient.cpp
index a406af2..2f14ed2 100644
--- a/noncore/unsupported/mailit/popclient.cpp
+++ b/noncore/unsupported/mailit/popclient.cpp
@@ -36,340 +36,340 @@ PopClient::PopClient()
stream = new QTextStream(socket);
receiving = FALSE;
synchronize = FALSE;
lastSync = 0;
headerLimit = 0;
preview = FALSE;
}
PopClient::~PopClient()
{
delete socket;
delete stream;
}
void PopClient::newConnection(QString target, int port)
{
if (receiving) {
qWarning("socket in use, connection refused");
return;
}
status = Init;
socket->connectToHost(target, port);
receiving = TRUE;
selected = FALSE;
emit updateStatus("DNS lookup");
}
void PopClient::setAccount(QString popUser, QString popPasswd)
{
popUserName = popUser;
popPassword = popPasswd;
}
void PopClient::setSynchronize(int lastCount)
{
synchronize = TRUE;
lastSync = lastCount;
}
void PopClient::removeSynchronize()
{
synchronize = FALSE;
lastSync = 0;
}
void PopClient::headersOnly(bool headers, int limit)
{
preview = headers;
headerLimit = limit;
}
void PopClient::setSelectedMails(MailList *list)
{
selected = TRUE;
mailList = list;
}
void PopClient::connectionEstablished()
{
- emit updateStatus("Connection established");
+ emit updateStatus(tr("Connection established"));
}
void PopClient::errorHandling(int status)
{
- emit updateStatus("Error Occured");
+ emit updateStatus(tr("Error Occured"));
emit errorOccurred(status);
socket->close();
receiving = FALSE;
}
void PopClient::incomingData()
{
QString response, temp, temp2, timeStamp;
QString md5Source;
int start, end;
// char *md5Digest;
char md5Digest[16];
// if ( !socket->canReadLine() )
// return;
response = socket->readLine();
qDebug(response +" %d", status);
switch(status) {
//logging in
case Init: {
#ifdef APOP_TEST
start = response.find('<',0);
end = response.find('>', start);
if( start >= 0 && end > start )
{
timeStamp = response.mid( start , end - start + 1);
md5Source = timeStamp + popPassword;
qDebug( md5Source);
// for( int i = 0; i < md5Source.length(); i++) {
// buff[i] = (QChar)md5Source[i];
// }
md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]);
// md5_buffer(char const *buffer, unsigned int len, char *digest);
// MD5_Init( &ctx);
// MD5_Update( &ctx, buff, sizeof( buff) );
// MD5_Final( md5Digest, &ctx);
// MD5( buff, md5Source.length(), md5Digest);
for(int j =0;j < MD5_DIGEST_LENGTH ;j++)
{
printf("%x", md5Digest[j]);
}
printf("\n");
// qDebug(md5Digest);
*stream << "APOP " << popUserName << " " << md5Digest << "\r\n";
// qDebug("%s", stream);
status = Stat;
}
else
#endif
{
timeStamp = "";
*stream << "USER " << popUserName << "\r\n";
status = Pass;
}
break;
}
//password shhh. don't tell anyone (implement APOP...)
case Pass: {
*stream << "PASS " << popPassword << "\r\n";
status = Stat;
break;
}
//ask for number of messages
case Stat: {
if (response[0] == '+') {
*stream << "STAT" << "\r\n";
status = Mcnt;
} else errorHandling(ErrLoginFailed);
break;
}
//get count of messages, eg "+OK 4 900.." -> int 4
case Mcnt: {
if (response[0] == '+') {
temp = response.replace(0, 4, "");
int x = temp.find(" ", 0);
temp.truncate((uint) x);
newMessages = temp.toInt();
messageCount = 1;
status = List;
if (synchronize) {
//messages deleted from server, reload all
if (newMessages < lastSync)
lastSync = 0;
messageCount = lastSync + 1;
}
if (selected) {
int *ptr = mailList->first();
if (ptr != 0) {
newMessages++; //to ensure no early jumpout
messageCount = *(mailList->first());
} else newMessages = 0;
}
} else errorHandling(ErrUnknownResponse);
}
//Read message number x, count upwards to messageCount
case List: {
if (messageCount <= newMessages) {
*stream << "LIST " << messageCount << "\r\n";
status = Size;
temp2.setNum(newMessages - lastSync);
temp.setNum(messageCount - lastSync);
if (!selected) {
- emit updateStatus("Retrieving " + temp + "/" + temp2);
+ emit updateStatus(tr("Retrieving ") + temp + "/" + temp2);
} else {
//completing a previously closed transfer
if ( (messageCount - lastSync) <= 0) {
temp.setNum(messageCount);
- emit updateStatus("Previous message " + temp);
+ emit updateStatus(tr("Previous message ") + temp);
} else {
- emit updateStatus("Completing message " + temp);
+ emit updateStatus(tr("Completing message ") + temp);
}
}
break;
} else {
- emit updateStatus("No new Messages");
+ emit updateStatus(tr("No new Messages"));
status = Quit;
}
}
//get size of message, eg "500 characters in message.." -> int 500
case Size: {
if (status != Quit) { //because of idiotic switch
if (response[0] == '+') {
temp = response.replace(0, 4, "");
int x = temp.find(" ", 0);
temp = temp.right(temp.length() - ((uint) x + 1) );
mailSize = temp.toInt();
emit currentMailSize(mailSize);
status = Retr;
} else {
qWarning(response);
errorHandling(ErrUnknownResponse);
}
}
}
//Read message number x, count upwards to messageCount
case Retr: {
if (status != Quit) {
if (!preview || mailSize <= headerLimit) {
*stream << "RETR " << messageCount << "\r\n";
} else { //only header
*stream << "TOP " << messageCount << " 0\r\n";
}
messageCount++;
status = Ignore;
break;
} }
case Ignore: {
if (status != Quit) { //because of idiotic switch
if (response[0] == '+') {
message = "";
status = Read;
if (!socket->canReadLine()) //sync. problems
break;
response = socket->readLine();
} else errorHandling(ErrUnknownResponse);
}
}
//add all incoming lines to body. When size is reached, send
//message, and go back to read new message
case Read: {
if (status != Quit) { //because of idiotic switch
message += response;
while ( socket->canReadLine() ) {
response = socket->readLine();
message += response;
}
emit downloadedSize(message.length());
int x = message.find("\r\n.\r\n",-5);
if (x == -1) {
break;
} else { //message reach entire size
//complete mail downloaded
if ( (!preview ) || ((preview) && (mailSize <= headerLimit)) ){
emit newMessage(message, messageCount-1, mailSize, TRUE);
} else { //incomplete mail downloaded
emit newMessage(message, messageCount-1, mailSize, FALSE);
}
if (messageCount > newMessages) //that was the last message
status = Quit;
else { //ask for new message
if (selected) { //grab next from queue
int *ptr = mailList->next();
if (ptr != 0) {
messageCount = *ptr;
*stream << "LIST " << messageCount << "\r\n";
status = Size;
//completing a previously closed transfer
if ( (messageCount - lastSync) <= 0) {
temp.setNum(messageCount);
- emit updateStatus("Previous message " + temp);
+ emit updateStatus(tr("Previous message ") + temp);
} else {
temp.setNum(messageCount - lastSync);
- emit updateStatus("Completing message " + temp);
+ emit updateStatus(tr("Completing message ") + temp);
}
break;
} else {
newMessages--;
status = Quit;
}
} else {
*stream << "LIST " << messageCount << "\r\n";
status = Size;
temp2.setNum(newMessages - lastSync);
temp.setNum(messageCount - lastSync);
- emit updateStatus("Retrieving " + temp + "/" + temp2);
+ emit updateStatus(tr("Retrieving ") + temp + "/" + temp2);
break;
}
}
}
if (status != Quit)
break;
}
}
case Quit: {
*stream << "Quit\r\n";
status = Done;
int newM = newMessages - lastSync;
if (newM > 0) {
temp.setNum(newM);
- emit updateStatus(temp + " new messages");
+ emit updateStatus(temp + tr(" new messages"));
} else {
- emit updateStatus("No new messages");
+ emit updateStatus(tr("No new messages"));
}
socket->close();
receiving = FALSE;
emit mailTransfered(newM);
break;
}
}
}
// if( bAPOPAuthentication )
// {
// if( m_strTimeStamp.IsEmpty() )
// {
// SetLastError("Apop error!");
// return false;
// }
// strMD5Source = m_strTimeStamp+pszPassword;
// strMD5Dst = MD5_GetMD5( (BYTE*)(const char*)strMD5Source , strMD5Source.GetLength() );
// sprintf(msg , "apop %s %s\r\n" , pszUser , strMD5Dst);
// ret = send(m_sPop3Socket , msg , strlen(msg) , NULL);
// if(ret == SOCKET_ERROR)
// {
// SetLastError("Socket error!");
// m_bSocketOK = false;
// m_bConnected = false;
// return false;
// }
// if( !GetSocketResult(&strResult , COMMAND_END_FLAG) )
// return false;
// if( 0 == strResult.Find('-' , 0) )
// {
// SetLastError("Username or Password error!");
// return false;
// }
// m_bConnected = true;
// }
diff --git a/noncore/unsupported/mailit/smtpclient.cpp b/noncore/unsupported/mailit/smtpclient.cpp
index 7bb7933..3bdc072 100644
--- a/noncore/unsupported/mailit/smtpclient.cpp
+++ b/noncore/unsupported/mailit/smtpclient.cpp
@@ -1,163 +1,163 @@
/**********************************************************************
** Copyright (C) 2001 Trolltech AS. All rights reserved.
**
** This file is part of Qt Palmtop Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "smtpclient.h"
#include "emailhandler.h"
SmtpClient::SmtpClient()
{
socket = new QSocket(this, "smtpClient");
stream = new QTextStream(socket);
mailList.setAutoDelete(TRUE);
connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int)));
connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished()));
connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData()));
sending = FALSE;
}
SmtpClient::~SmtpClient()
{
delete socket;
delete stream;
}
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("DNS lookup");
+ 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("Connection established");
+ 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();
switch(status) {
case Init: {
if (response[0] == '2') {
status = From;
mailPtr = mailList.first();
*stream << "HELO there\r\n";
} else errorHandling(ErrUnknownResponse);
break;
}
case From: {
if (response[0] == '2') {
*stream << "MAIL FROM: <" << mailPtr->from << ">\r\n";
status = Recv;
} 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";
status = MRcv;
} else errorHandling(ErrUnknownResponse);
break;
}
case MRcv: {
if (response[0] == '2') {
it++;
if ( it != mailPtr->to.end() ) {
*stream << "RCPT TO: <" << *it << ">\r\n";
break;
} else {
status = Data;
}
} else errorHandling(ErrUnknownResponse);
}
case Data: {
if (response[0] == '2') {
*stream << "DATA\r\n";
status = Body;
- emit updateStatus("Sending: " + mailPtr->subject);
+ 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;
}
} else errorHandling(ErrUnknownResponse);
break;
}
case Quit: {
if (response[0] == '2') {
*stream << "QUIT\r\n";
status = Done;
QString temp;
temp.setNum(mailList.count());
- emit updateStatus("Sent " + temp + " messages");
+ emit updateStatus(tr("Sent ") + temp + tr(" messages"));
emit mailSent();
mailList.clear();
sending = FALSE;
socket->close();
} else errorHandling(ErrUnknownResponse);
break;
}
}
}