Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'rubygems'
- require 'mail'
- # this is kept in ~/scripts but the /tmp/ directory used is
- # actually ~/tmp. I guess webfaction runs the mail script
- # from the home folder no matter where the script actually is
- # TODO deal with encoding issues
- # (real quation marks, hyphens, brackets, etc)
- begin
- # empty the error output
- File.open('tmp/pinboard-error.txt', "w") do |f|
- f.puts "#{Time.new.inspect}"
- f.puts "NO ERROR\n\n"
- end
- # have to write to a file then read that in
- # the Mail gem throws an error reading from STDIN/ARGF
- # (with webfaction anyway)
- File.open('tmp/pinboard-input.txt', "w") do |f|
- f.puts STDIN.read
- end
- #mail_in = Mail.read(STDIN.read) # ERROR file name too long
- mail = Mail.read('tmp/pinboard-input.txt')
- if mail.from.to_s == 'YOU@YOUR_DOMAIN.COM'
- # get rid of the 'Article: ' that Instapaper puts in front of the subject
- title = mail.subject.to_s.gsub(/^Article: /, "")
- recipient = 'YOUR_SECRET_EMAIL@pinboard.in'
- else
- title = "PINBOARD ERROR from " + mail.from.to_s + " -- " + mail.subject
- recipient = 'YOU@YOUR_DOMAIN.COM'
- end
- if mail.multipart?
- link_quote_tags = mail.text_part.body.to_s
- else
- link_quote_tags = mail.body.decoded
- end
- pinboard_mail = Mail.new do
- from 'YOU@YOUR_DOMAIN.COM'
- to recipient
- subject title
- body link_quote_tags
- end
- pinboard_mail.delivery_method :sendmail
- pinboard_mail.deliver
- rescue Exception => e
- File.open('tmp/pinboard-error.txt', "w") do |f|
- f.puts "#{Time.new.inspect}"
- f.puts "ERROR:\n\n"
- f.puts e
- end
- end
Add Comment
Please, Sign In to add comment