Skip to content

Instantly share code, notes, and snippets.

Created May 17, 2013 20:22
Show Gist options
  • Save anonymous/ac0c88945da6ddf54d19 to your computer and use it in GitHub Desktop.
Save anonymous/ac0c88945da6ddf54d19 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'dotenv'
require 'mail'
# Load environment variables from .env file
Dotenv.load
class FFM
# Exit if there's nothing on STDIN
exit(1) unless STDIN.fcntl(Fcntl::F_GETFL, 0) == 0
# Create mail from STDIN
mail = Mail.new(STDIN.read())
# # Don't process email if "X-FFM: ignore" header exists
# # as the email has already been through FFM
if mail.header['X-FFM'].to_s == 'ignore'
$stderr.puts "This email has already been processed"
# Send the email to faxmaster?
exit(1)
end
# Read From and To headers
from = mail.from.first
from_domain = from.split("@").last
to = mail.to.first
to_domain = to.split("@").last
# Determine what type of email
if from_domain == ENV['DOMAIN'] && to_domain == ENV['FAX_DOMAIN']
# FAX SEND
elsif from == ENV['FAX_SAAS_PROVIDER_NOTIFICATION_EMAIL']
case mail.subject
when "Fax Sent"
# FAX SENT NOTIFICATION
# tiff2pdf conversion
# `tiff2pdf -o output.pdf input.tiff`
when "Fax Failed"
# FAX FAILED NOTIFICATION
when "Fax Received" # regex_here
# FAX RECEIVED NOTIFICATION
else
# Send the email to faxmaster?
end
else
# Send the email to faxmaster?
end
end
# Testing
require 'minitest/autorun'
class TestFFM < MiniTest::Unit::TestCase
def setup
@ffm = FFM.new
end
def test_that_mail_is_not_processed
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment