<commit_before>package gov.nih.nci.cabig.caaers.tools.mail;

import gov.nih.nci.cabig.caaers.CaaersSystemException;
import gov.nih.nci.cabig.caaers.tools.configuration.Configuration;

import java.io.File;
import java.util.Properties;

import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;

/**
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 */
public class CaaersJavaMailSender extends JavaMailSenderImpl implements InitializingBean {
	
	public static boolean SUPRESS_MAIL_SEND_EXCEPTION = false;
	
    private Configuration configuration;

    public String getHost() {
        return configuration.get(Configuration.SMTP_ADDRESS);
    }

    public void setHost(String host) {
        throw unsupported("host");
    }
    
   @Override
   public String getUsername() {
	   return configuration.get(Configuration.SMTP_USER);
   }
   
   @Override
   public void setUsername(String username) {
	   throw unsupported("username");
   }
   
   public int getPort(){
	   return configuration.get(Configuration.SMTP_PORT);
   }
   
    public void setPort(int port) {
        throw unsupported("port");
    }

    public String getPassword() {
        return configuration.get(Configuration.SMTP_PASSWORD);
    }

    public void setPassword(String password) {
        throw unsupported("password");
    }
    
    /**
     * We will check the configuration, and populate the propertes in the JavaMailSenderImpl bean.
     */
    public void afterPropertiesSet() throws Exception {
    	Properties properties = new Properties();
    	
    	if (StringUtils.isNotBlank(getPassword())) {
    		properties.setProperty("mail.smtp.auth", "true");
    	}
    	
    	if(configuration.get(Configuration.SMTP_SSL_ENABLED) != null && configuration.get(Configuration.SMTP_SSL_ENABLED)){
    		
//    		properties.setProperty("mail.smtp.starttls.enable", "true");
//
//    		properties.put("mail.transport.protocol", "smtps");
//    		properties.put("mail.smtps.host", configuration.get(Configuration.SMTP_ADDRESS));
//    		properties.put("mail.smtps.auth", "true");

            properties.setProperty("mail.smtp.auth", "true");
            properties.setProperty("mail.smtp.starttls.enable", "true");
            properties.setProperty("mail.smtp.timeout", "8500");        		
    	}
    	if (!properties.isEmpty()) {
    		setJavaMailProperties(properties);
    	}
    }
    
    
    @Override
    public void send(SimpleMailMessage message) {
        String fromAddress = configuration.get(Configuration.SYSTEM_FROM_EMAIL);
        if (!StringUtils.isBlank(fromAddress)) message.setFrom(fromAddress);
        super.send(message);
    }
    
    @Override
    public void send(MimeMessage message) {
        try {
			String fromAddress = configuration.get(Configuration.SYSTEM_FROM_EMAIL);
			if (!fromAddress.equals("")) message.setFrom(new InternetAddress(fromAddress));
			super.send(message);
		
		} catch (MessagingException e) {
			 throw new CaaersSystemException("Error while sending email", e);
		}
    }
    
    /**
     * This method is used to send an email
     */
	public void sendMail(String[] to, String subject, String content, String[] attachmentFilePaths){
		try {		
		    MimeMessage message = createMimeMessage();
		    message.setSubject(subject);
		
		    // use the true flag to indicate you need a multipart message
		    MimeMessageHelper helper = new MimeMessageHelper(message, true);
		    helper.setTo(to);
		    helper.setText(content);
		    
		    for(String attachmentPath : attachmentFilePaths){
		    	if(StringUtils.isNotEmpty(attachmentPath)){
		    		File f = new File(attachmentPath);
		    		FileSystemResource file = new FileSystemResource(f);
				    helper.addAttachment(file.getFilename(), file);
		    	}
		    }
			send(message);
		    
		} catch (Exception e) {
			 if(SUPRESS_MAIL_SEND_EXCEPTION) return; //supress the excetion related to email sending
			 throw new CaaersSystemException("Error while sending email", e);
		}
	}
    
    @Required
    public void setConfiguration(Configuration configuration) {
        this.configuration = configuration;
    }

    private UnsupportedOperationException unsupported(String prop) {
        return new UnsupportedOperationException(prop
                        + " is set through the application configuration");
    }
}
<commit_msg>fixed a bug in caaers/tools/mail/CaaersJavaMailSender.java.<commit_after>package gov.nih.nci.cabig.caaers.tools.mail;

import gov.nih.nci.cabig.caaers.CaaersSystemException;
import gov.nih.nci.cabig.caaers.tools.configuration.Configuration;

import java.io.File;
import java.util.Properties;

import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;

/**
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 */
public class CaaersJavaMailSender extends JavaMailSenderImpl implements InitializingBean {
	
	public static boolean SUPRESS_MAIL_SEND_EXCEPTION = false;
	
    private Configuration configuration;

    public String getHost() {
        return configuration.get(Configuration.SMTP_ADDRESS);
    }

    public void setHost(String host) {
        throw unsupported("host");
    }
    
   @Override
   public String getUsername() {
	   return configuration.get(Configuration.SMTP_USER);
   }
   
   @Override
   public void setUsername(String username) {
	   throw unsupported("username");
   }
   
   public int getPort(){
	   return configuration.get(Configuration.SMTP_PORT);
   }
   
    public void setPort(int port) {
        throw unsupported("port");
    }

    public String getPassword() {
        return configuration.get(Configuration.SMTP_PASSWORD);
    }

    public void setPassword(String password) {
        throw unsupported("password");
    }
    
    /**
     * We will check the configuration, and populate the propertes in the JavaMailSenderImpl bean.
     */
    public void afterPropertiesSet() throws Exception {
    	Properties properties = new Properties();
    	
    	if (StringUtils.isNotBlank(getPassword()) || StringUtils.isNotBlank(getUsername())) {
    		properties.setProperty("mail.smtp.auth", "true");
    	}
    	
    	if(configuration.get(Configuration.SMTP_SSL_ENABLED) != null && configuration.get(Configuration.SMTP_SSL_ENABLED)){
    		
//    		properties.setProperty("mail.smtp.starttls.enable", "true");
//
//    		properties.put("mail.transport.protocol", "smtps");
//    		properties.put("mail.smtps.host", configuration.get(Configuration.SMTP_ADDRESS));
//    		properties.put("mail.smtps.auth", "true");

            properties.setProperty("mail.smtp.auth", "true");
            properties.setProperty("mail.smtp.starttls.enable", "true");
            properties.setProperty("mail.smtp.timeout", "8500");        		
    	}
    	if (!properties.isEmpty()) {
    		setJavaMailProperties(properties);
    	}
    }
    
    
    @Override
    public void send(SimpleMailMessage message) {
        String fromAddress = configuration.get(Configuration.SYSTEM_FROM_EMAIL);
        if (!StringUtils.isBlank(fromAddress)) message.setFrom(fromAddress);
        super.send(message);
    }
    
    @Override
    public void send(MimeMessage message) {
        try {
			String fromAddress = configuration.get(Configuration.SYSTEM_FROM_EMAIL);
			if (!fromAddress.equals("")) message.setFrom(new InternetAddress(fromAddress));
			super.send(message);
		
		} catch (MessagingException e) {
			 throw new CaaersSystemException("Error while sending email", e);
		}
    }
    
    /**
     * This method is used to send an email
     */
	public void sendMail(String[] to, String subject, String content, String[] attachmentFilePaths){
		try {		
		    MimeMessage message = createMimeMessage();
		    message.setSubject(subject);
		
		    // use the true flag to indicate you need a multipart message
		    MimeMessageHelper helper = new MimeMessageHelper(message, true);
		    helper.setTo(to);
		    helper.setText(content);
		    
		    for(String attachmentPath : attachmentFilePaths){
		    	if(StringUtils.isNotEmpty(attachmentPath)){
		    		File f = new File(attachmentPath);
		    		FileSystemResource file = new FileSystemResource(f);
				    helper.addAttachment(file.getFilename(), file);
		    	}
		    }
			send(message);
		    
		} catch (Exception e) {
			 if(SUPRESS_MAIL_SEND_EXCEPTION) return; //supress the excetion related to email sending
			 throw new CaaersSystemException("Error while sending email", e);
		}
	}
    
    @Required
    public void setConfiguration(Configuration configuration) {
        this.configuration = configuration;
    }

    private UnsupportedOperationException unsupported(String prop) {
        return new UnsupportedOperationException(prop
                        + " is set through the application configuration");
    }
}

{'fraction_non_alphanumeric': 0.10435862925768713, 'fraction_numerical': 0.0008282430893467233, 'mean_word_length': 3.36117381489842, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3638940', 'n_tokens_mistral': 2872, 'n_tokens_neox': 2695, 'n_words': 553}