<commit_before>/*
    knsmtpclient.cpp

    KNode, the KDE newsreader
    Copyright (c) 1999-2001 the KNode authors.
    See file AUTHORS for details

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, US
*/

#include <unistd.h>

#include <klocale.h>

#include "knmime.h"
#include "knjobdata.h"
#include "knsmtpclient.h"


KNSmtpClient::KNSmtpClient(int NfdPipeIn, int NfdPipeOut, QObject *parent, const char *name)
: KNProtocolClient(NfdPipeIn,NfdPipeOut,parent,name)
{}


KNSmtpClient::~KNSmtpClient()
{}


// examines the job and calls the suitable handling method
void KNSmtpClient::processJob()
{
  switch (job->type()) {
    case KNJobData::JTmail :
      doMail();
      break;
    default:
#ifndef NDEBUG
      qDebug("knode: KNSmtpClient::processJob(): mismatched job");
#endif
      break;
  }
}
  

void KNSmtpClient::doMail()
{
  KNLocalArticle *art=static_cast<KNLocalArticle*>(job->data());
  
  sendSignal(TSsendMail); 

  QCString cmd = "MAIL FROM:<";
  cmd += art->from()->email();
  cmd += ">";
  if(!sendCommandWCheck(cmd, 250))
    return;
    
  progressValue = 80;

  QStrList emails;
  art->to()->emails(&emails);
  bool rcptOK=false;

  for(char *e=emails.first() ; e; e=emails.next()) {
    cmd="RCPT TO:<" + QCString(e) + ">";
    if(sendCommandWCheck(cmd, 250))
      rcptOK=true;
  }

  if(!rcptOK) // mail has not been accepted by the smtp-host
    return;
    
  progressValue = 90;

  if(!sendCommandWCheck("DATA", 354))
    return;
    
  progressValue = 100;
  
  if(!sendMsg(art->encodedContent(true)))
    return;
    
  if(!checkNextResponse(250))
    return;
}


bool KNSmtpClient::openConnection()
{
  QString oldPrefix = errorPrefix;
  errorPrefix=i18n("Unable to connect.\nThe following error ocurred:\n");

  if (!KNProtocolClient::openConnection())
    return false;
    
  progressValue = 30;
    
  if (!checkNextResponse(220))
    return false;
    
  progressValue = 50;

  char hostName[500];

  QCString cmd = "HELO ";
    
  if (gethostname(hostName,490)==0) {
    cmd += hostName;
    //qDebug("knode: KNSmtpClient::openConnection(): %s",cmd.data());
  } else {
    cmd += "foo";
    //qDebug("knode: KNSmtpClient::openConnection(): can't detect hostname, using foo");
  }

  int rep;
  if (!sendCommand(cmd,rep))
    return;

  while (rep == 220) {  // some smtp servers send multiple "220 xxx" lines...
    if (!getNextResponse(rep))
      return false;
  }

  if (rep!=250) {
    handleErrors();
    return false;
  }
<commit_msg>/me being stupid...<commit_after>/*
    knsmtpclient.cpp

    KNode, the KDE newsreader
    Copyright (c) 1999-2001 the KNode authors.
    See file AUTHORS for details

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, US
*/

#include <unistd.h>

#include <klocale.h>

#include "knmime.h"
#include "knjobdata.h"
#include "knsmtpclient.h"


KNSmtpClient::KNSmtpClient(int NfdPipeIn, int NfdPipeOut, QObject *parent, const char *name)
: KNProtocolClient(NfdPipeIn,NfdPipeOut,parent,name)
{}


KNSmtpClient::~KNSmtpClient()
{}


// examines the job and calls the suitable handling method
void KNSmtpClient::processJob()
{
  switch (job->type()) {
    case KNJobData::JTmail :
      doMail();
      break;
    default:
#ifndef NDEBUG
      qDebug("knode: KNSmtpClient::processJob(): mismatched job");
#endif
      break;
  }
}
  

void KNSmtpClient::doMail()
{
  KNLocalArticle *art=static_cast<KNLocalArticle*>(job->data());
  
  sendSignal(TSsendMail); 

  QCString cmd = "MAIL FROM:<";
  cmd += art->from()->email();
  cmd += ">";
  if(!sendCommandWCheck(cmd, 250))
    return;
    
  progressValue = 80;

  QStrList emails;
  art->to()->emails(&emails);
  bool rcptOK=false;

  for(char *e=emails.first() ; e; e=emails.next()) {
    cmd="RCPT TO:<" + QCString(e) + ">";
    if(sendCommandWCheck(cmd, 250))
      rcptOK=true;
  }

  if(!rcptOK) // mail has not been accepted by the smtp-host
    return;
    
  progressValue = 90;

  if(!sendCommandWCheck("DATA", 354))
    return;
    
  progressValue = 100;
  
  if(!sendMsg(art->encodedContent(true)))
    return;
    
  if(!checkNextResponse(250))
    return;
}


bool KNSmtpClient::openConnection()
{
  QString oldPrefix = errorPrefix;
  errorPrefix=i18n("Unable to connect.\nThe following error ocurred:\n");

  if (!KNProtocolClient::openConnection())
    return false;
    
  progressValue = 30;
    
  if (!checkNextResponse(220))
    return false;
    
  progressValue = 50;

  char hostName[500];

  QCString cmd = "HELO ";
    
  if (gethostname(hostName,490)==0) {
    cmd += hostName;
    //qDebug("knode: KNSmtpClient::openConnection(): %s",cmd.data());
  } else {
    cmd += "foo";
    //qDebug("knode: KNSmtpClient::openConnection(): can't detect hostname, using foo");
  }

  int rep;
  if (!sendCommand(cmd,rep))
    return false;

  while (rep == 220) {  // some smtp servers send multiple "220 xxx" lines...
    if (!getNextResponse(rep))
      return false;
  }

  if (rep!=250) {
    handleErrors();
    return false;
  }

{'fraction_non_alphanumeric': 0.13158801240096452, 'fraction_numerical': 0.02307957285566655, 'mean_word_length': 3.3992424242424244, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '317572', 'n_tokens_mistral': 2125, 'n_tokens_neox': 1966, 'n_words': 527}