<commit_before><?php
/**
 * Send document mail with SMTP protocol
 *
 * @author Anakeen 2007
 * @version $Id: sendmail.php,v 1.4 2007/10/10 16:15:35 eric Exp $
 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
 * @package FREEDOM
 * @subpackage
 */
/**
 */
include('Mail/mime.php');
include('Net/SMTP.php');
/**
 * Send mail via smtp server
 * @param string $to mail addresses (, separate)
 * @param string $cc mail addresses (, separate)
 * @param string $bcc mail addresses (, separate)
 * @param string $from mail address
 * @param string $subject mail subject
 * @param Mail_mime &$mimemail mail mime object 
 * @return string error message : if no error: empty if no error
 */
function sendmail($to,$from,$cc,$bcc,$subject,&$mimemail,$multipart=null) {
 
  
  $rcpt = array_merge(explode(',',$to),
		      explode(',',$cc),
		      explode(',',$bcc));

  $host=getParam('SMTP_HOST','localhost');
  $port=getParam('SMTP_PORT',25);
  $login=getParam('SMTP_LOGIN');
  $password=getParam('SMTP_PASSWORD');



  if( is_a($mimemail, 'Mail_Mime') ) {
  	$mimemail->setFrom($from);
  	if ($cc!='') $mimemail->addCc($cc);
  }


  $xh['To']=$to;
  /* Create a new Net_SMTP object. */
  if (! ($smtp = new Net_SMTP($host,$port))) {
    die("Unable to instantiate Net_SMTP object\n");
  }
  $smtp->setDebug(false);
  
  /* Connect to the SMTP server. */
  if (PEAR::isError($e = $smtp->connect())) {
    return ("smtp connect:".$e->getMessage() );
  }

  if ($login) {
    if (PEAR::isError($e = $smtp->auth($login,$password))) {
      return ("smtp login:".$e->getMessage() );
    }
  }
  /* Send the 'MAIL FROM:' SMTP command. */
  if (PEAR::isError($smtp->mailFrom($from))) {
    return ("Unable to set sender to <$from>");
  }
  
  /* Address the message to each of the recipients. */
  foreach ($rcpt as $v) {
    if ($v) {
      if (preg_match("/<([^>]*)>/",$v,$reg)) {
	$v=$reg[1];
      }
      if (PEAR::isError($res = $smtp->rcptTo($v))) {
	return ("Unable to add recipient <$v>: " . $res->getMessage() );
      }
    }
   }
  setlocale(LC_TIME, 'C');

  $data = '';

  if( is_a($mimemail, 'Fdl_Mail_mimePart') ) {

  	$mm = new Mail_Mime();
  	$mm->_build_params['head_charset'] = 'UTF-8';

  	$mm->setFrom($from);
  	if( $cc != '' ) {
  		$mm->addCc($cc);
  	}

  	$email = $mimemail->encode();
	if( PEAR::isError($email) ) {
		$err = sprintf("Error encoding Fdl_Mail_mimePart : %s", $email->message);
		error_log(__CLASS__."::".__FUNCTION__." ".$err);
		return $err;
	}

	$txtHeaders = $mm->txtHeaders(<commit_msg>Remove leading and trailing whitespaces in sendmails recipient email addresses (closes #1577)<commit_after><?php
/**
 * Send document mail with SMTP protocol
 *
 * @author Anakeen 2007
 * @version $Id: sendmail.php,v 1.4 2007/10/10 16:15:35 eric Exp $
 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
 * @package FREEDOM
 * @subpackage
 */
/**
 */
include('Mail/mime.php');
include('Net/SMTP.php');
/**
 * Send mail via smtp server
 * @param string $to mail addresses (, separate)
 * @param string $cc mail addresses (, separate)
 * @param string $bcc mail addresses (, separate)
 * @param string $from mail address
 * @param string $subject mail subject
 * @param Mail_mime &$mimemail mail mime object 
 * @return string error message : if no error: empty if no error
 */
function sendmail($to,$from,$cc,$bcc,$subject,&$mimemail,$multipart=null) {
 
  
  $rcpt = array_merge(explode(',',$to),
		      explode(',',$cc),
		      explode(',',$bcc));

  $host=getParam('SMTP_HOST','localhost');
  $port=getParam('SMTP_PORT',25);
  $login=getParam('SMTP_LOGIN');
  $password=getParam('SMTP_PASSWORD');



  if( is_a($mimemail, 'Mail_Mime') ) {
  	$mimemail->setFrom($from);
  	if ($cc!='') $mimemail->addCc($cc);
  }


  $xh['To']=$to;
  /* Create a new Net_SMTP object. */
  if (! ($smtp = new Net_SMTP($host,$port))) {
    die("Unable to instantiate Net_SMTP object\n");
  }
  $smtp->setDebug(false);
  
  /* Connect to the SMTP server. */
  if (PEAR::isError($e = $smtp->connect())) {
    return ("smtp connect:".$e->getMessage() );
  }

  if ($login) {
    if (PEAR::isError($e = $smtp->auth($login,$password))) {
      return ("smtp login:".$e->getMessage() );
    }
  }
  /* Send the 'MAIL FROM:' SMTP command. */
  if (PEAR::isError($smtp->mailFrom($from))) {
    return ("Unable to set sender to <$from>");
  }
  
  /* Address the message to each of the recipients. */
  foreach ($rcpt as $v) {
	$v = trim($v);
    if ($v) {
      if (preg_match("/<([^>]*)>/",$v,$reg)) {
	$v=$reg[1];
      }
      if (PEAR::isError($res = $smtp->rcptTo($v))) {
	return ("Unable to add recipient <$v>: " . $res->getMessage() );
      }
    }
   }
  setlocale(LC_TIME, 'C');

  $data = '';

  if( is_a($mimemail, 'Fdl_Mail_mimePart') ) {

  	$mm = new Mail_Mime();
  	$mm->_build_params['head_charset'] = 'UTF-8';

  	$mm->setFrom($from);
  	if( $cc != '' ) {
  		$mm->addCc($cc);
  	}

  	$email = $mimemail->encode();
	if( PEAR::isError($email) ) {
		$err = sprintf("Error encoding Fdl_Mail_mimePart : %s", $email->message);
		error_log(__CLASS__."::".__FUNCTION__." ".$err);
		return $err;
	}

	$txtHeaders = $mm->txtHeaders(
{'fraction_non_alphanumeric': 0.20546636085626913, 'fraction_numerical': 0.010703363914373088, 'mean_word_length': 3.5984182776801408, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6847564', 'n_tokens_mistral': 2059, 'n_tokens_neox': 1951, 'n_words': 422}