Exemplo n.º 1
0
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();
    }
}
Exemplo n.º 2
0
bool KNFolder::loadHdrs()
{
  if(isLoaded()) {
    kDebug(5003) <<"KNFolder::loadHdrs() : already loaded";
    return true;
  }

  if(!i_ndexFile.open(QIODevice::ReadOnly)) {
    kError(5003) <<"KNFolder::loadHdrs() : cannot open index-file!";
    closeFiles();
    return false;
  }

  if(!m_boxFile.open(QIODevice::ReadOnly)) {
    kError(5003) <<"KNFolder::loadHdrs() : cannot open mbox-file!";
    closeFiles();
    return false;
  }

  if(!resize(c_ount)) {
    closeFiles();
    return false;
  }

  QByteArray tmp;
  KNLocalArticle *art;
  DynData dynamic;
  int pos1=0, pos2=0, cnt=0, byteCount;

  knGlobals.top->setCursorBusy(true);
  knGlobals.setStatusMsg(i18n(" Loading folder..."));
  knGlobals.top->secureProcessEvents();

  while(!i_ndexFile.atEnd()) {

    //read index-data
    byteCount=i_ndexFile.read((char*)(&dynamic), sizeof(DynData));
    if(byteCount!=sizeof(DynData)) {
      if( i_ndexFile.error() == QFile::NoError ) {
        kWarning(5003) <<"KNFolder::loadHeaders() : found broken entry in index-file: Ignored!";
        continue;
      }
      else {
        kError(5003) <<"KNFolder::loadHeaders() : corrupted index-file, IO-error!";
        closeFiles();
        clear();
        knGlobals.top->setCursorBusy( false );
        return false;
      }
    }

    art=new KNLocalArticle(this);

    //set index-data
    dynamic.getData(art);

    //read overview
    if ( !m_boxFile.seek( art->startOffset() ) ) {
      kError(5003) <<"KNFolder::loadHdrs() : cannot set mbox file-pointer!";
      closeFiles();
      clear();
      knGlobals.top->setCursorBusy( false );
      return false;
    }
    tmp = m_boxFile.readLine();
    if ( tmp.endsWith( '\n' ) )
      tmp.resize( tmp.length() - 1 );
    if(tmp.isEmpty()) {
      if( m_boxFile.error() == QFile::NoError ) {
        kWarning(5003) <<"found broken entry in mbox-file: Ignored!";
        delete art;
        continue;
      }
      else {
        kError(5003) <<"KNFolder::loadHdrs() : corrupted mbox-file, IO-error!";
        closeFiles();
        clear();
        knGlobals.top->setCursorBusy( false );
        return false;
      }
    }

    //set overview
    bool end=false;
    pos1 = tmp.indexOf( ' ' ) + 1;
    pos2 = tmp.indexOf( '\t', pos1 );
    if (pos2 == -1) {
      pos2=tmp.length();
      end=true;
    }
    art->subject()->from7BitString(tmp.mid(pos1, pos2-pos1));

    if (!end) {
      pos1=pos2+1;
      pos2 = tmp.indexOf( '\t', pos1 );
      if (pos2 == -1) {
        pos2=tmp.length();
        end=true;
      }
      art->newsgroups()->from7BitString(tmp.mid(pos1, pos2-pos1));
    }

    if (!end) {
      pos1=pos2+1;
      pos2 = tmp.indexOf( '\t', pos1 );
      if (pos2 == -1) {
        pos2=tmp.length();
        end=true;
      }
      art->to()->from7BitString(tmp.mid(pos1,pos2-pos1));
    }

    if (!end) {
      pos1=pos2+1;
      pos2=tmp.length();
      art->lines()->from7BitString(tmp.mid(pos1,pos2-pos1));
    }

    if(!append(art)) {
      kError(5003) <<"KNFolder::loadHdrs() : cannot append article!";
      delete art;
      clear();
      closeFiles();

      knGlobals.setStatusMsg( QString() );
      knGlobals.top->setCursorBusy(false);
      return false;
    }

    cnt++;
  }

  closeFiles();
  setLastID();
  c_ount=cnt;
  updateListItem();

  knGlobals.setStatusMsg( QString() );
  knGlobals.top->setCursorBusy(false);

  return true;
}