Skip to content
This repository has been archived by the owner on Nov 28, 2017. It is now read-only.
Permalink
Browse files Browse the repository at this point in the history
Fix code execution issue in email command.
  • Loading branch information
nealpoole committed Apr 26, 2013
1 parent 8f3dd0a commit feee5ab
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/scripts/email.coffee
Expand Up @@ -18,16 +18,18 @@

util = require 'util'
child_process = require 'child_process'
exec = child_process.exec

module.exports = (robot) ->
emailTime = null
sendEmail = (recipients, subject, msg, from) ->
mailCommand = """echo '#{msg}' | mail -s '#{subject}' -r '#{from}' '#{recipients}'"""
exec mailCommand, (error, stdout, stderr) ->
mailArgs = ['-s', subject, '-a', "From: #{from}", '--']
mailArgs = mailArgs.concat recipients
p = child_process.execFile 'mail', mailArgs, {}, (error, stdout, stderr) ->
util.print 'stdout: ' + stdout
util.print 'stderr: ' + stderr
p.stdin.write "#{msg}\n"
p.stdin.end()

robot.respond /email (.*) -s (.*) -m (.*)/i, (msg) ->
sendEmail msg.match[1], msg.match[2], msg.match[3], msg.message.user.id
sendEmail msg.match[1].split(" "), msg.match[2], msg.match[3], msg.message.user.id
msg.send "email sent"

0 comments on commit feee5ab

Please sign in to comment.