Last active
December 11, 2015 05:28
-
-
Save sandro/4552206 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 [email protected] Wed Jan 16 14:52:43 2013 | |
Return-Path: <[email protected]> | |
X-Original-To: [email protected] | |
Delivered-To: [email protected] | |
Received: by careful.dev (Postfix, from userid 501) | |
id E9A8816391C3; Wed, 16 Jan 2013 14:52:43 -0800 (PST) | |
To: [email protected] | |
Subject: test | |
Message-Id: <[email protected]> | |
Date: Wed, 16 Jan 2013 14:52:43 -0800 (PST) | |
From: [email protected] (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