Diffstat (limited to 'noncore/net/mailit/popclient.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mailit/popclient.cpp | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/noncore/net/mailit/popclient.cpp b/noncore/net/mailit/popclient.cpp index 5da3bcb..1df6b2b 100644 --- a/noncore/net/mailit/popclient.cpp +++ b/noncore/net/mailit/popclient.cpp @@ -28,20 +28,21 @@ extern "C" { #include <qcstring.h> PopClient::PopClient() { - + socket = new QSocket(this, "popClient"); connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); - + stream = new QTextStream(socket); - + receiving = FALSE; synchronize = FALSE; lastSync = 0; headerLimit = 0; + mailList = 0; preview = FALSE; } PopClient::~PopClient() @@ -55,23 +56,23 @@ void PopClient::newConnection(const 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(tr("DNS lookup")); } void PopClient::setAccount(const QString &popUser, const QString &popPasswd) { popUserName = popUser; popPassword = popPasswd; -} +} void PopClient::setSynchronize(int lastCount) { synchronize = TRUE; @@ -122,11 +123,11 @@ void PopClient::incomingData() char md5Digest[16]; // if ( !socket->canReadLine() ) // return; - + response = socket->readLine(); - + switch(status) { //logging in case Init: { #ifdef APOP_TEST @@ -135,16 +136,16 @@ void PopClient::incomingData() if( start >= 0 && end > start ) { timeStamp = response.mid( start , end - start + 1); md5Source = timeStamp + popPassword; - + md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); for(int j =0;j < MD5_DIGEST_LENGTH ;j++) { printf("%x", md5Digest[j]); } - printf("\n"); + printf("\n"); // qDebug(md5Digest); *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; // qDebug("%s", stream); status = Stat; @@ -155,23 +156,23 @@ void PopClient::incomingData() timeStamp = ""; *stream << "USER " << popUserName << "\r\n"; status = Pass; } - + break; } - + 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; + status = Mcnt; } else errorHandlingWithMsg(ErrLoginFailed, response); break; } //get count of messages, eg "+OK 4 900.." -> int 4 @@ -182,22 +183,22 @@ void PopClient::incomingData() 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 = 1; } - - if (selected) { + + if (selected && mailList ) { int *ptr = mailList->first(); if (ptr != 0) { newMessages++; //to ensure no early jumpout messageCount = *ptr; - } else newMessages = 0; + } else newMessages = 0; } } else errorHandlingWithMsg(ErrUnknownResponse, response); } @@ -223,9 +224,9 @@ void PopClient::incomingData() } else { 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] == '+') { @@ -233,29 +234,29 @@ void PopClient::incomingData() int x = temp.find(" ", 0); temp = temp.right(temp.length() - ((uint) x + 1) ); mailSize = temp.toInt(); emit currentMailSize(mailSize); - + status = Retr; } else { //qWarning(response); errorHandlingWithMsg(ErrUnknownResponse, response); } } - } + } //Read message number x, count upwards to messageCount case Retr: { if (status != Quit) { - if ((selected)||(mailSize <= headerLimit)) + if ((selected)||(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 = ""; @@ -285,25 +286,25 @@ void PopClient::incomingData() emit newMessage(message, messageCount-1, mailSize, TRUE); } else { //incomplete mail downloaded emit newMessage(message, messageCount-1, mailSize, FALSE); } - + if ((messageCount > newMessages)||(selected)) //last message ? { status = Quit; if (selected) { //grab next from queue newMessages--; status = Quit; } } - else + else { *stream << "LIST " << messageCount << "\r\n"; status = Size; temp2.setNum(newMessages - lastSync); temp.setNum(messageCount - lastSync); emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); - + break; } } } @@ -319,9 +320,9 @@ void PopClient::incomingData() emit updateStatus(temp + tr(" new messages")); } else { emit updateStatus(tr("No new messages")); } - + socket->close(); receiving = FALSE; emit mailTransfered(newM); break; |