<commit_before>package util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.Scanner;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.SendFailedException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.InitialDirContext;

import model.ModelInJar;
import tlc2.output.MP;

public class MailSender {

	public static final String MODEL_NAME = "modelName";
	public static final String SPEC_NAME = "specName";
	public static final String MAIL_ADDRESS = "result.mail.address";

	/**
	 * @param from "<NAME> <<EMAIL>>"
	 * @param to An email address _with_ domain part (<EMAIL>)
	 * @param subject
	 * @param messages
	 */
	private static boolean send(final InternetAddress from, final InternetAddress to, final String subject, final String body, final File[] files) {
		
		// https://javaee.github.io/javamail/docs/api/com/sun/mail/smtp/package-summary.html
		final Properties properties = System.getProperties();
		// Prefer email to be delivered encrypted (assumes to lower likelihood of SMTP
		// rejection or classification as spam too). Falls back to plain text if SMTP
		// server does not support starttls.
		properties.put("mail.smtp.starttls.enable", "true");
		//properties.put("mail.debug", "true");
		
		if (!to.getAddress().contains("@")) {
			// no domain, no MX record to lookup
			return false;
		}
		List<MXRecord> mailhosts;
		try {
			mailhosts = getMXForDomain(to.getAddress().split("@")[1]);
		} catch (NamingException e) {
			e.printStackTrace();<commit_msg>Do not attempt to TLS encrypt SMTP traffic when connecting to local postfix with only a self-signed certificate.<commit_after>package util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.Scanner;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.SendFailedException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.InitialDirContext;

import model.ModelInJar;
import tlc2.output.MP;

public class MailSender {

	public static final String MODEL_NAME = "modelName";
	public static final String SPEC_NAME = "specName";
	public static final String MAIL_ADDRESS = "result.mail.address";

	/**
	 * @param from "Foo bar <<EMAIL>>"
	 * @param to An email address _with_ domain part (<EMAIL>)
	 * @param subject
	 * @param messages
	 */
	private static boolean send(final InternetAddress from, final InternetAddress to, final String subject, final String body, final File[] files) {
		
		// https://javaee.github.io/javamail/docs/api/com/sun/mail/smtp/package-summary.html
		final Properties properties = System.getProperties();
		//properties.put("mail.debug", "true");
		
		if (!to.getAddress().contains("@")) {
			// no domain, no MX record to lookup
			return false;
		} else if (!to.getAddress().endsWith("localhost")) {
			// Prefer email to be delivered encrypted (assumes to lower likelihood of SMTP
			// rejection or classification as spam too). Falls back to plain text if SMTP
			// server does not support starttls. Only activate unless sending to localhost
			// which is the (postfix) SMTP running locally which only has a self-signed
			// certificate which gets rejected by java mail.
			properties.put("mail.smtp.starttls.enable", "true");
		}
		
		List<MXRecord> mailhosts;
		try {
			mailhosts = getMXForDomain(to.getAddress().split("@")[1]);
		} catch (NamingException e) {
			e.printStackTrace();
{'fraction_non_alphanumeric': 0.10920860304865317, 'fraction_numerical': 0.0008352474420547087, 'mean_word_length': 4.827250608272506, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 2, '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': '952916', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1380, 'n_words': 399}