Skip to content

Instantly share code, notes, and snippets.

@johnl
Created May 29, 2010 22:44
Show Gist options
  • Save johnl/418603 to your computer and use it in GitHub Desktop.
Save johnl/418603 to your computer and use it in GitHub Desktop.
smtp to www gateway. Tested with Postfix. Inspired by rms.
#!/usr/bin/ruby
#
# smtp to www gateway. Tested with Postfix. Inspired by rms.
#
# Pipe to this command from your .forward file (or in my case, an alias extension,
# so .forward-webgateway). For every http or https url found in the message
# (headers and body), it will send an email back to you with the output of a text
# web browser visiting.
#
# * Requires elinks and the mail command
# * Won't read messages larger than 32k (to make DoS slightly harder, but not much)
# * Is careful not to let command injection attack, though needs more testing on this
#
# Not really designed for safe public (read: untrusted) use, so try to keep your
# gateway email address to yourself!
input = STDIN.read(32 * 1024)
re = Regexp.new('(https?://[^\s$]+)', Regexp::EXTENDED)
input.scan(re).each do |url|
url = url.first.gsub("'", '\\''')
system("/usr/bin/elinks -dump 1 '#{url}' | /usr/bin/mail -s '#{url}' '#{ENV['SENDER']}'")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment