<commit_before>#!/usr/bin/env ruby

require 'rubygems'
require 'net/smtp'
require 'mailfactory'

module Flapjack
  module Notifiers

    class Mailer

      def initialize(opts={})
        @from_address = opts[:from_address]
        @website_uri  = opts[:website_uri].gsub(/\/$/, '')
        @log = opts[:logger]
        @log ||= Log4r::Logger.new("notifier")
      end

      def notify(opts={})
        raise unless (opts[:who] && opts[:result])
    
        mail = MailFactory.new
        mail.to = opts[:who].email
        mail.from = @from_address
        mail.subject = "Check: #{opts[:result].id}, Status: #{opts[:result].status}"
        mail.text = <<-DESC
          Check #{opts[:result].id} returned the status "#{opts[:result].status}".
          
          Here was the output: 
            #{opts[:result].output}
    
          You can respond to this issue at:
            #{@website_uri}/issue/#{opts[:result].id}
        DESC

        begin 
          Net::SMTP.start('localhost') do |smtp|
            smtp.sendmail(mail.to_s, mail.from, mail.to)<commit_msg>default website_uri to hostname if not specified<commit_after>#!/usr/bin/env ruby

require 'rubygems'
require 'net/smtp'
require 'mailfactory'

module Flapjack
  module Notifiers

    class Mailer

      def initialize(opts={})
        @from_address = opts[:from_address]
        @website_uri  = opts[:website_uri] ? opts[:website_uri].gsub(/\/$/, '') : "http://#{`hostname`}"
        @log = opts[:logger]
        @log ||= Log4r::Logger.new("notifier")
      end

      def notify(opts={})
        raise unless (opts[:who] && opts[:result])
    
        mail = MailFactory.new
        mail.to = opts[:who].email
        mail.from = @from_address
        mail.subject = "Check: #{opts[:result].id}, Status: #{opts[:result].status}"
        mail.text = <<-DESC
          Check #{opts[:result].id} returned the status "#{opts[:result].status}".
          
          Here was the output: 
            #{opts[:result].output}
    
          You can respond to this issue at:
            #{@website_uri}/issue/#{opts[:result].id}
        DESC

        begin 
          Net::SMTP.start('localhost') do |smtp|
            smtp.sendmail(mail.to_s, mail.from, mail.to)
{'fraction_non_alphanumeric': 0.15436241610738255, 'fraction_numerical': 0.0008948545861297539, 'mean_word_length': 2.2452830188679247, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '5549799', 'n_tokens_mistral': 705, 'n_tokens_neox': 680, 'n_words': 149}