Index: kioslave/pop3/pop3.cpp =================================================================== --- kioslave/pop3/pop3.cpp (revision 1108622) +++ kioslave/pop3/pop3.cpp (working copy) @@ -148,7 +148,10 @@ memcpy(readBuffer, &readBuffer[copyLen], readBufferLen); return copyLen; } - waitForResponse(600); + if (!isConnected()) + return 0; // from imap4 + //waitForResponse(600); + waitForResponse( responseTimeout() ); // from imap4 return read((char*)data, len); } @@ -167,7 +170,19 @@ memcpy(readBuffer, &readBuffer[copyLen], readBufferLen); return copyLen; } - waitForResponse(600); + //waitForResponse(600); + waitForResponse( responseTimeout() ); // from imap4 + kDebug(7105) << "gm: m_sServer" << m_sServer; + QByteArray zeichen= "abc"; + bool isOK; + isOK= isConnected(); + kDebug(7105) << "gm:istOK" << isOK; + //QString testen; + //bool ob= true; + //slaveStatus( testen, ob); + //kDebug(7105) << "gm: Testen" << testen; + int cT= connectTimeout(); + kDebug(7105) << "gm: cT" << cT; readLen = read(&readBuffer[readBufferLen], len - readBufferLen); readBufferLen += readLen; if (readLen <= 0) { @@ -296,7 +311,14 @@ POP3Protocol::Resp POP3Protocol::command(const QByteArray &cmd, char *recv_buf, unsigned int len) { - sendCommand(cmd); + // guy-kde + bool sendCmd; + + //sendCommand(cmd); + sendCmd= sendCommand(cmd); + if( !sendCmd){ + return Invalid; + } return getResponse(recv_buf, len); } @@ -627,7 +649,9 @@ do { closeConnection(); - if (!connectToHost((isAutoSsl() ? "pop3s" : "pop3"), m_sServer.toLatin1(), m_iPort)) { + //if (!connectToHost((isAutoSsl() ? "pop3s" : "pop3"), m_sServer.toLatin1(), m_iPort)) { + // guy-kde + if (!connectToHost("pop3", m_sServer.toLatin1(), m_iPort)) { // error(ERR_COULD_NOT_CONNECT, m_sServer); // ConnectToHost has already send an error message. return false; Index: kioslave/imap4/imapparser.cpp =================================================================== --- kioslave/imap4/imapparser.cpp (revision 1108622) +++ kioslave/imap4/imapparser.cpp (working copy) @@ -81,6 +81,14 @@ { int pl = 0; sendCommand (aCmd); + if (getState () == ISTATE_NO) { + QString command = aCmd->command(); + if ((command == "STATUS") || + (command == "NOOP" ) || + (command == "LOGOUT") ) { + return aCmd; + } + } while (pl != -1 && !aCmd->isComplete ()) { while ((pl = parseLoop ()) == 0) ; @@ -261,12 +269,14 @@ firstCommand += QString::fromLatin1( challenge.data(), challenge.size() ); } cmd = sendCommand (CommandPtr(new imapCommand ("AUTHENTICATE", firstCommand.toLatin1()))); + if (getState () == ISTATE_NO) return false; int pl = 0; while ( pl != -1 && !cmd->isComplete () ) { //read the next line while ( ( pl = parseLoop() ) == 0) { ; + if (getState () == ISTATE_NO) return false; } if (!continuation.isEmpty()) @@ -306,6 +316,7 @@ tmp.clear(); // kDebug(7116) <<"C:" << QCString(challenge.data(),challenge.size()+1); parseWriteLine (challenge); + if (getState () == ISTATE_NO) return false; continuation.resize(0); } } @@ -329,6 +340,7 @@ parseOneWord(result); // * QByteArray what = parseLiteral (result); // see whats coming next + if (getState () == ISTATE_NO) return ; switch (what[0]) { @@ -467,6 +479,7 @@ if (valid) { what = parseLiteral (result); + if (getState () == ISTATE_NO) return ; switch (what[0]) { case 'E': @@ -684,7 +697,9 @@ skipWS (result); this_one.setHierarchyDelimiter(parseLiteral(result)); + if (getState () == ISTATE_NO) return ; this_one.setName(QString::fromUtf8(KIMAP::decodeImapFolderName( parseLiteral(result)))); // decode modified UTF7 + if (getState () == ISTATE_NO) return ; listResponses.append (this_one); } @@ -713,6 +728,7 @@ // The result is user1 perm1 user2 perm2 etc. The caller will sort it out. while ( !result.isEmpty() ) { const QByteArray word = parseLiteral(result); + if (getState () == ISTATE_NO) return ; if ( word.isEmpty() ) break; lastResults.append (word); @@ -732,6 +748,7 @@ // The result is name1 value1 name2 value2 etc. The caller will sort it out. while ( !result.isEmpty() && result[0] != ')' ) { const QByteArray word = parseLiteral (result); + if (getState () == ISTATE_NO) return ; if ( word.isEmpty() ) break; lastResults.append (word); @@ -757,6 +774,7 @@ QStringList triplet; while ( !result.isEmpty() && result[0] != ')' ) { const QByteArray word = parseLiteral(result); + if (getState () == ISTATE_NO) return ; if ( word.isEmpty() ) break; triplet.append(word); @@ -775,6 +793,7 @@ QStringList roots; while ( !result.isEmpty() ) { const QByteArray word = parseLiteral (result); + if (getState () == ISTATE_NO) return ; if ( word.isEmpty() ) break; roots.append (word); @@ -785,6 +804,7 @@ void imapParser::parseCustom (parseString & result) { QByteArray word = parseLiteral (result, false, false); + if (getState () == ISTATE_NO) return ; lastResults.append( word ); } @@ -800,6 +820,7 @@ QStringList rights; while ( !result.isEmpty() ) { QByteArray word = parseLiteral ( result, false, false ); + if (getState () == ISTATE_NO) return ; rights.append( word ); } @@ -812,6 +833,7 @@ parseOneWord (result); // skip encoding QByteArray msg = parseLiteral (result, false, false); + if (getState () == ISTATE_NO) return ; lastResults.append( state + '^' + QString::fromUtf8( msg ) ); } @@ -838,6 +860,7 @@ lastStatus = imapInfo (); parseLiteral(inWords); // swallow the box + if (getState () == ISTATE_NO) return ; if (inWords[0] != '(') return; @@ -899,6 +922,7 @@ if (inWords[0] == '(') { mailAddress *addr = new mailAddress; parseAddress(inWords, *addr); + if (getState () == ISTATE_NO) return ; list.append(addr); } else { break; @@ -917,9 +941,13 @@ skipWS (inWords); retVal.setFullName(parseLiteral(inWords)); + if (getState () == ISTATE_NO) return retVal; retVal.setCommentRaw(parseLiteral(inWords)); + if (getState () == ISTATE_NO) return retVal; retVal.setUser(parseLiteral(inWords)); + if (getState () == ISTATE_NO) return retVal; retVal.setHost(parseLiteral(inWords)); + if (getState () == ISTATE_NO) return retVal; if (!inWords.isEmpty() && inWords[0] == ')') inWords.pos++; @@ -941,14 +969,17 @@ //date envelope->setDate(parseLiteral(inWords)); + if (getState () == ISTATE_NO) return envelope; //subject envelope->setSubject(parseLiteral(inWords)); + if (getState () == ISTATE_NO) return envelope; QList list; //from parseAddressList(inWords, list); + if (getState () == ISTATE_NO) return envelope; if (!list.isEmpty()) { envelope->setFrom(*list.last()); list.clear(); @@ -956,6 +987,7 @@ //sender parseAddressList(inWords, list); + if (getState () == ISTATE_NO) return envelope; if (!list.isEmpty()) { envelope->setSender(*list.last()); list.clear(); @@ -963,6 +995,7 @@ //reply-to parseAddressList(inWords, list); + if (getState () == ISTATE_NO) return envelope; if (!list.isEmpty()) { envelope->setReplyTo(*list.last()); list.clear(); @@ -970,18 +1003,23 @@ //to parseAddressList (inWords, envelope->to()); + if (getState () == ISTATE_NO) return envelope; //cc parseAddressList (inWords, envelope->cc()); + if (getState () == ISTATE_NO) return envelope; //bcc parseAddressList (inWords, envelope->bcc()); + if (getState () == ISTATE_NO) return envelope; //in-reply-to envelope->setInReplyTo(parseLiteral(inWords)); + if (getState () == ISTATE_NO) return envelope; //message-id envelope->setMessageId(parseLiteral(inWords)); + if (getState () == ISTATE_NO) return envelope; // see if we have more to come while (!inWords.isEmpty () && inWords[0] != ')') @@ -991,6 +1029,7 @@ parseSentence (inWords); else parseLiteral (inWords); + if (getState () == ISTATE_NO) return envelope; } if (!inWords.isEmpty() && inWords[0] == ')') @@ -1054,7 +1093,9 @@ while (!inWords.isEmpty () && inWords[0] != ')') { const QByteArray l1 = parseLiteral(inWords); + if (getState () == ISTATE_NO) return retVal; const QByteArray l2 = parseLiteral(inWords); + if (getState () == ISTATE_NO) return retVal; retVal.insert (l1.toLower(), QString(l2)); } @@ -1088,9 +1129,11 @@ //body type typeStr = parseLiteral(inWords); + if (getState () == ISTATE_NO) return localPart; //body subtype subtype = parseLiteral(inWords); + if (getState () == ISTATE_NO) return localPart; localPart->setType (typeStr + '/' + subtype); @@ -1109,12 +1152,15 @@ //body id localPart->setID (parseLiteral(inWords)); + if (getState () == ISTATE_NO) return localPart; //body description localPart->setDescription (parseLiteral(inWords)); + if (getState () == ISTATE_NO) return localPart; //body encoding localPart->setEncoding (parseLiteral(inWords)); + if (getState () == ISTATE_NO) return localPart; //body size if (parseOneNumber (inWords, size)) @@ -1125,11 +1171,13 @@ { //envelope structure mailHeader *envelope = parseEnvelope (inWords); + if (getState () == ISTATE_NO) return localPart; //body structure parseBodyStructure (inWords, inSection, envelope); localPart->setNestedMessage (envelope); + if (getState () == ISTATE_NO) return localPart; //text lines ulong lines; @@ -1146,6 +1194,7 @@ // md5 parseLiteral(inWords); + if (getState () == ISTATE_NO) return localPart; // body disposition parameters = parseDisposition (inWords); @@ -1164,6 +1213,7 @@ // body language parseSentence (inWords); + if (getState () == ISTATE_NO) return localPart; } // see if we have more to come @@ -1174,6 +1224,7 @@ parseSentence (inWords); else parseLiteral(inWords); + if (getState () == ISTATE_NO) return localPart; } if (inWords[0] == ')') @@ -1277,6 +1328,7 @@ // body language parseSentence (inWords); + if (getState () == ISTATE_NO) return localPart; } else @@ -1287,6 +1339,7 @@ if ( localPart ) inSection = inSection + ".1"; localPart = parseSimplePart (inWords, inSection, localPart); + if (getState () == ISTATE_NO) return localPart; inWords.pos--; inWords.data[inWords.pos] = ')'; //remove fake } @@ -1299,6 +1352,7 @@ parseSentence (inWords); else parseLiteral(inWords); + if (getState () == ISTATE_NO) return localPart; } if (inWords[0] == ')') @@ -1347,12 +1401,14 @@ kDebug(7116) <<"imapParser::parseBody - discarding" << envelope << seenUid.toAscii (); // don't know where to put it, throw it away parseLiteral(inWords, true); + if (getState () == ISTATE_NO) return ; } else { kDebug(7116) <<"imapParser::parseBody - reading" << envelope << seenUid.toAscii (); // fill it up with data QString theHeader = parseLiteral(inWords, true); + if (getState () == ISTATE_NO) return ; mimeIOQString myIO; myIO.setString (theHeader); @@ -1376,10 +1432,12 @@ kDebug(7116) <<"imapParser::parseBody - discarding" << envelope << seenUid.toAscii (); // don't know where to put it, throw it away parseLiteral (inWords, true); + if (getState () == ISTATE_NO) return ; } else { QByteArray references = parseLiteral(inWords, true); + if (getState () == ISTATE_NO) return ; int start = references.indexOf ('<'); int end = references.lastIndexOf ('>'); if (start < end) @@ -1390,6 +1448,7 @@ else { // not a header we care about throw it away parseLiteral(inWords, true); + if (getState () == ISTATE_NO) return ; } } else @@ -1398,6 +1457,7 @@ { mailHeader *envelope = new mailHeader; QString theHeader = parseLiteral(inWords, false); + if (getState () == ISTATE_NO) return ; mimeIOQString myIO; myIO.setString (theHeader); envelope->parseHeader (myIO); @@ -1408,6 +1468,7 @@ // throw it away kDebug(7116) <<"imapParser::parseBody - discarding" << seenUid.toAscii (); parseLiteral(inWords, true); + if (getState () == ISTATE_NO) return ; } } @@ -1422,6 +1483,7 @@ kDebug(7116) <<"imapParser::parseBody - discarding" << envelope << seenUid.toAscii (); // don't know where to put it, throw it away parseSentence (inWords); + if (getState () == ISTATE_NO) return ; } else { @@ -1447,11 +1509,13 @@ while (!inWords.isEmpty () && inWords[0] != ')') { - if (inWords[0] == '(') + if (inWords[0] == '(') { parseSentence (inWords); - else + if (getState () == ISTATE_NO) return ; + } else { const QByteArray word = parseLiteral(inWords, false, true); + if (getState () == ISTATE_NO) return ; switch (word[0]) { @@ -1470,6 +1534,7 @@ // we have seen this one already // or don't know where to put it parseSentence (inWords); + if (getState () == ISTATE_NO) return ; } else { @@ -1488,11 +1553,13 @@ if (word == "BODY") { parseBody (inWords); + if (getState () == ISTATE_NO) return ; } else if (word == "BODY[]" ) { // Do the same as with "RFC822" parseLiteral(inWords, true); + if (getState () == ISTATE_NO) return ; } else if (word == "BODYSTRUCTURE") { @@ -1552,6 +1619,7 @@ { // might be RFC822 RFC822.TEXT RFC822.HEADER parseLiteral(inWords, true); + if (getState () == ISTATE_NO) return ; } break; @@ -1575,6 +1643,7 @@ default: parseLiteral(inWords); + if (getState () == ISTATE_NO) return ; break; } } @@ -1588,6 +1657,7 @@ parseSentence (inWords); else parseLiteral(inWords); + if (getState () == ISTATE_NO) return ; } if (inWords.isEmpty() || inWords[0] != ')') @@ -1631,6 +1701,7 @@ break; default: parseLiteral(inWords); + if (getState () == ISTATE_NO) return ; skipWS (inWords); break; } @@ -1748,10 +1819,12 @@ default: { QByteArray tag = parseLiteral(result); + if (getState () == ISTATE_NO) return 0; if (current->id() == tag.data()) { result.data.resize(result.data.size() - 2); // tie off CRLF QByteArray resultCode = parseLiteral (result); //the result + if (getState () == ISTATE_NO) return 0; current->setResult (resultCode); current->setResultInfo(result.cstr()); current->setComplete (); @@ -1895,10 +1968,12 @@ parseRelay (runLen); QByteArray rv; parseRead (rv, runLen, relay ? runLen : 0); + if (getState () == ISTATE_NO) return rv; rv.resize(qMax(runLen, rv.size())); // what's the point? retVal = rv; inWords.clear(); parseReadLine (inWords.data); // must get more + if (getState () == ISTATE_NO) return rv; // no duplicate data transfers relay = false; Index: kioslave/imap4/imap4.cpp =================================================================== --- kioslave/imap4/imap4.cpp (revision 1108622) +++ kioslave/imap4/imap4.cpp (working copy) @@ -87,6 +87,8 @@ #include #include #include +#include +#include #include "common.h" #include "kdemacros.h" @@ -314,9 +316,11 @@ QString mySection = aSection; mySection.replace(']', ".MIME]"); cmd = sendCommand (imapCommand::clientFetch (aSequence, mySection)); + if (getState () == ISTATE_NO) return ; do { while (!parseLoop ()) {} + if (getState () == ISTATE_NO) return ; } while (!cmd->isComplete ()); completeQueue.removeAll (cmd); @@ -331,11 +335,13 @@ } cmd = sendCommand (imapCommand::clientFetch (aSequence, aSection)); + if (getState () == ISTATE_NO) return ; int res; aUpper = aSection.toUpper(); do { while (!(res = parseLoop())) {} + if (getState () == ISTATE_NO) return ; if (res == -1) break; mailHeader *lastone = 0; @@ -594,10 +600,12 @@ CommandPtr fetch = sendCommand (imapCommand:: clientFetch (mySequence, mySection)); + if (getState () == ISTATE_NO) return ; imapCache *cache; do { while (!parseLoop ()) {} + if (getState () == ISTATE_NO) return ; cache = getLastHandled (); @@ -749,6 +757,14 @@ closeConnection(); return false; } + //kDebug(7116) << "check the IP (wait_and_read_1)"; + if ( !theAddressWeUse.isSavedAddressStillAvailable() ) { + theAddressWeUse.resetAddressInUse (); + error ( ERR_CONNECTION_BROKEN, myHost ); + setState(ISTATE_CONNECT); + closeConnection(); + return false; + } if (!waitForResponse( responseTimeout() )) { error(ERR_SERVER_TIMEOUT, myHost); @@ -828,7 +844,9 @@ CommandPtr cmd = sendCommand (imapCommand::clientAppend (aBox, aSection, length)); + if (getState () == ISTATE_NO) return ; while (!parseLoop ()) {} + if (getState () == ISTATE_NO) return ; // see if server is waiting if (!cmd->isComplete () && !getContinuation ().isEmpty ()) @@ -859,6 +877,7 @@ } } parseWriteLine (""); + if (getState () == ISTATE_NO) return ; // Wait until cmd is complete, or connection breaks. while (!cmd->isComplete () && getState() != ISTATE_NO) parseLoop (); @@ -1245,6 +1264,7 @@ { // NOOP CommandPtr cmd = doCommand(imapCommand::clientNoop()); + if (getState () == ISTATE_NO) return ; if (cmd->result () != "OK") { kDebug(7116) <<"NOOP did not succeed - connection broken"; @@ -1606,13 +1626,24 @@ if ( type == 'E' ) { kDebug(7116) << "IMAP4Protocol::specialCustomCommand: extended mode" << endl; CommandPtr cmd = sendCommand (imapCommand::clientCustom( command, QString() )); + if (getState () == ISTATE_NO) return ; while ( !parseLoop () ) {}; + if (getState () == ISTATE_NO) return ; // see if server is waiting if (!cmd->isComplete () && !getContinuation ().isEmpty ()) { const QByteArray buffer = arguments.toUtf8(); + //kDebug(7116) << "check the IP (write_1)"; + if ( !theAddressWeUse.isSavedAddressStillAvailable() ) { + theAddressWeUse.resetAddressInUse (); + error ( ERR_CONNECTION_BROKEN, myHost ); + completeQueue.removeAll ( cmd ); + setState(ISTATE_CONNECT); + closeConnection(); + return; + } // send data to server bool sendOk = (write (buffer.data (), buffer.size ()) == (ssize_t)buffer.size ()); processedSize( buffer.size() ); @@ -1626,10 +1657,12 @@ } } parseWriteLine (""); + if (getState () == ISTATE_NO) return ; do { while (!parseLoop ()) {}; + if (getState () == ISTATE_NO) return ; } while (!cmd->isComplete ()); @@ -1866,6 +1899,7 @@ ok = cmd->result() == "OK"; cmdInfo = cmd->resultInfo(); completeQueue.removeAll(cmd); + if (getState () == ISTATE_NO) return ; } if (!ok) { @@ -1980,6 +2014,10 @@ void IMAP4Protocol::closeConnection() { + kDebug(7116) <<"state " << getState(); + if (getState() == ISTATE_NO) { + kDebug(7116) <<"state == ISTATE_NO"; + } if (getState() == ISTATE_NO) return; if (getState() == ISTATE_SELECT && metaData("expunge") == "auto") { @@ -2012,6 +2050,14 @@ myPort)) { // fcntl (m_iSock, F_SETFL, (fcntl (m_iSock, F_GETFL) | O_NDELAY)); + //catch the IP-address actually used, ie. from the connection/ socket + //transformed as a QString, in the format: + //IP-V4: 192.168.2.20 + //IP-V6: fe80::230:5ff:fed2:39a2 + KTcpSocket *kio_socket= static_cast(TCPSlaveBase::socket()); + QString myHostAddress = kio_socket->localAddress().toString(); + kDebug(7116) << "store the actual IP-localAddress" << myHostAddress; + theAddressWeUse.saveAddressInUse ( myHostAddress); setState(ISTATE_CONNECT); @@ -2023,6 +2069,7 @@ unhandled.clear (); if (!alreadyConnected) while (!parseLoop ()) {} //get greeting + if (getState () == ISTATE_NO) return false; QString greeting; if (!unhandled.isEmpty()) greeting = unhandled.first().trimmed(); unhandled.clear (); //get rid of it @@ -2185,6 +2232,14 @@ } // write it + //kDebug(7116) << "check the IP (write_2)"; + if ( !theAddressWeUse.isSavedAddressStillAvailable() ) { + theAddressWeUse.resetAddressInUse (); + error ( ERR_CONNECTION_BROKEN, myHost ); + setState(ISTATE_CONNECT); + closeConnection(); + return; + } write(writer.data(), len); } @@ -2389,6 +2444,7 @@ imapParser::parseURL (_url, _box, _section, _type, _uid, _validity, _info); // kDebug(7116) <<"URL: query - '" << KUrl::fromPercentEncoding(_url.query()) <<"'"; + if (getState () == ISTATE_NO) return retVal; // get the delimiter QString myNamespace = namespaceForBox( _box ); @@ -2405,6 +2461,7 @@ if (makeLogin ()) { + if (getState () == ISTATE_NO) return retVal; if (getCurrentBox () != _box || _type == "LIST" || _type == "LSUB" || _type == "LSUBNOCHECK") { @@ -2418,6 +2475,7 @@ CommandPtr cmd; cmd = doCommand (imapCommand::clientList ("", _box)); + if (getState () == ISTATE_NO) return retVal; if (cmd->result () == "OK") { for (QList< imapList >::Iterator it = listResponses.begin (); @@ -2451,6 +2509,7 @@ kDebug(7116) <<"IMAP4::parseURL - got error for" << _box; } completeQueue.removeAll (cmd); + if (getState () == ISTATE_NO) return retVal; } // cache } else // current == box @@ -2581,6 +2640,14 @@ return copyLen; } if (!isConnected()) return 0; + //kDebug(7116) << "check the IP (wait_and_read_2)"; + if ( !theAddressWeUse.isSavedAddressStillAvailable() ) { + theAddressWeUse.resetAddressInUse (); + error ( ERR_CONNECTION_BROKEN, myHost ); + setState(ISTATE_CONNECT); + closeConnection(); + return 0; + } waitForResponse( responseTimeout() ); return read((char*)data, len); } Index: kioslave/imap4/imap4.h =================================================================== --- kioslave/imap4/imap4.h (revision 1108622) +++ kioslave/imap4/imap4.h (working copy) @@ -27,6 +27,7 @@ #include "imap4-config.h" #include "imapparser.h" #include "mimeio.h" +#include "kipaddressinuse.h" #include #include @@ -191,6 +192,7 @@ QString myHost, myUser, myPass, myAuth, myTLS; int myPort; bool mySSL; + KIpAddressInUse theAddressWeUse; bool relayEnabled, cacheOutput, decodeContent; QByteArray outputCache; Index: kioslave/imap4/CMakeLists.txt =================================================================== --- kioslave/imap4/CMakeLists.txt (revision 1108622) +++ kioslave/imap4/CMakeLists.txt (working copy) @@ -27,7 +27,8 @@ imapparser.cpp mailheader.cpp mimehdrline.cpp - mimeio.cpp) + mimeio.cpp + kipaddressinuse.cpp) kde4_add_plugin(kio_imap4 ${kio_imap4_PART_SRCS})