Skip to content

Instantly share code, notes, and snippets.

@sandro
Last active December 11, 2015 05:28
Show Gist options
  • Save sandro/4552206 to your computer and use it in GitHub Desktop.
Save sandro/4552206 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# set the 'test' environment variable to test against the expected data at the bottom of the file
# test=1 ruby incoming_email_forwarder.rb
test_mode = ENV['test']
message = test_mode ? DATA : $stdin.read
headers = {}
headers_string = ""
full_text = ""
log_file = '/tmp/incoming_email_forwarder.log'
iterator = message.each_line
begin
iterator.next
while val = iterator.next
case val
when /: /
key, value = *val.strip.split(": ", 2)
headers[key] = value || ""
headers_string << val
when /^\n$/
while text = iterator.next
full_text << text.sub(/\=\r?\n/, '')
end
end
end
rescue StopIteration
end
data = "MESSAGE:\n#{message}\n\nHEADERS:\n#{headers.inspect}\n\n#{full_text}"
if test_mode
puts data
else
`curl --silent -d "to=#{headers['To']}&text=#{full_text}&from=#{headers['From']}&headers=#{headers_string}" http://careful.dev:3000/incoming_email`
if File.writable? File.dirname(log_file)
File.open(log_file, 'w') {|f| f.puts data}
end
end
__END__
From santuri@careful.dev Wed Jan 16 14:52:43 2013
Return-Path: <santuri@careful.dev>
X-Original-To: incoming_email@careful.dev
Delivered-To: incoming_email@careful.dev
Received: by careful.dev (Postfix, from userid 501)
id E9A8816391C3; Wed, 16 Jan 2013 14:52:43 -0800 (PST)
To: incoming_email@careful.dev
Subject: test
Message-Id: <20130116225243.E9A8816391C3@careful.dev>
Date: Wed, 16 Jan 2013 14:52:43 -0800 (PST)
From: santuri@careful.dev (Sandro Turriate)
Can you assess your heart disease risk by looking in the mirror and =
checking for a receding hairline, earlobe creases, and yellow lumps of =
fat around your eye? Will sprinkling flaxseed on your cereal reverse =
hypertension? What about popping a probiotic to lower cholesterol?
These are just some of the quirkier findings coming out of the American =
Heart Association=92s annual meeting in Los Angeles this week along with =
high-tech advances in the diagnosis and treatment of heart disease.
Keep in mind that while scientific meetings of large medical societies =
allow for researchers and doctors to gather in one place to discuss =
hundreds, if not thousands, of new findings, what=92s often presented =
may not pass muster for publication in prestigious medical journals, =
where they first undergo rigorous peer review.
A Danish study drawing a lot of attention, but which has not yet =
published in a peer-reviewed journal, suggested that common signs of =
aging can predict a person=92s heart disease risk. The researchers =
analyzed data from nearly 11,000 participants over age 40 in the =
Copenhagen Heart Study and found that those who had three to four aging =
signs at the beginning of the study -- such as a receding hairline, =
baldness at the top of the head, creases in the earlobes, and fatty =
deposits around the eye -- had a 57 percent increased risk of having a =
heart attack and a 39 percent increased risk of being diagnosed with =
heart disease during the 35-year study compared with those who had none =
of them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment