Created
May 29, 2010 22:44
-
-
Save johnl/418603 to your computer and use it in GitHub Desktop.
smtp to www gateway. Tested with Postfix. Inspired by rms.
This file contains 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/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