コード例 #1
0
ファイル: knnetaccess.cpp プロジェクト: serghei/kde3-kdepim
void KNNetAccess::startJobSmtp()
{
    if(smtpJobQueue.isEmpty())
        return;

    currentSmtpJob = smtpJobQueue.first();
    smtpJobQueue.remove(smtpJobQueue.begin());
    currentSmtpJob->prepareForExecution();
    if(currentSmtpJob->success())
    {
        KNLocalArticle *art = static_cast<KNLocalArticle *>(currentSmtpJob->data());
        // create url query part
        QString query("headers=0&from=");
        query += KURL::encode_string(art->from()->email());
        QStrList emails;
        art->to()->emails(&emails);
        for(char *e = emails.first(); e; e = emails.next())
        {
            query += "&to=" + KURL::encode_string(e);
        }
        // create url
        KURL destination;
        KNServerInfo *account = currentSmtpJob->account();
        if(account->encryption() == KNServerInfo::SSL)
            destination.setProtocol("smtps");
        else
            destination.setProtocol("smtp");
        destination.setHost(account->server());
        destination.setPort(account->port());
        destination.setQuery(query);
        if(account->needsLogon())
        {
            destination.setUser(account->user());
            destination.setPass(account->pass());
        }
        KIO::Job *job = KIO::storedPut(art->encodedContent(true), destination, -1, false, false, false);
        connect(job, SIGNAL(result(KIO::Job *)),
                SLOT(slotJobResult(KIO::Job *)));
        if(account->encryption() == KNServerInfo::TLS)
            job->addMetaData("tls", "on");
        else
            job->addMetaData("tls", "off");
        currentSmtpJob->setJob(job);

        kdDebug(5003) << "KNNetAccess::startJobSmtp(): job started" << endl;
    }
    else
    {
        threadDoneSmtp();
    }
}
コード例 #2
0
ファイル: knnntpclient.cpp プロジェクト: serghei/kde3-kdepim
void KNNntpClient::doPostArticle()
{
    KNLocalArticle *art = static_cast<KNLocalArticle *>(job->data());

    sendSignal(TSsendArticle);

    if(art->messageID(false) != 0)
    {
        int rep;
        if(!sendCommand(QCString("STAT ") + art->messageID(false)->as7BitString(false), rep))
            return;

        if(rep == 223)    // 223 n <a> article retrieved - request text separately
        {
#ifndef NDEBUG
            qDebug("knode: STAT successful, we have probably already sent this article.");
#endif
            return;       // the article is already on the server, lets put it silently into the send folder
        }
    }

    if(!sendCommandWCheck("POST", 340))       // 340 send article to be posted. End with <CR-LF>.<CR-LF>
        return;

    if(art->messageID(false) == 0)   // article has no message ID => search for a ID in the response
    {
        QCString s = getCurrentLine();
        int start = s.findRev(QRegExp("<[^\\s]*@[^\\s]*>"));
        if(start != -1)           // post response includes a recommended id
        {
            int end = s.find('>', start);
            art->messageID()->from7BitString(s.mid(start, end - start + 1));
            art->assemble();
#ifndef NDEBUG
            qDebug("knode: using the message-id recommended by the server: %s", s.mid(start, end - start + 1).data());
#endif
        }
    }

    if(!sendMsg(art->encodedContent(true)))
        return;

    if(!checkNextResponse(240))             // 240 article posted ok
        return;
}