 #   Mail System
 #
 # Dependencies:
-#   None
+#   "moment": "^2.5.1"
 #
 # Configuration:
 #   None
 #
 # Commands:
 #   hubot mail <recipient> <message> - Sends a <message> to <recipient> when found available
+#   hubot unmail [<recipient>] - Deletes all mail sent by you. Optionally, if <recipient> is specified, all mail sent to <recipient> by you will be deleted
 #
 # Author:
 #   MrSaints
+
+moment = require 'moment'
 
 module.exports = (robot) ->
     getMails = ->


        if recipient is robot.name
            msg.reply "Thanks, but no thanks! I do not need any mail."

        if recipient is sender
            msg.reply "Are you sure you want to send a mail to yourself? Sad."

        recipient = recipient.toLowerCase()

        getMails()[recipient] or= []
        getMails()[recipient].push [sender, message]
        msg.reply "Your mail has been prepared for #{recipient}."

    robot.enter (response) ->


        if mails = getMails()[recipient]
            for mail in mails
                context.send "#{robot.brain.userForName(recipient).name}: [From #{mail[0]}, #{moment.unix(mail[1]).fromNow()}] #{mail[2]}"
            delete getMails()[recipient]

    robot.respond /unmail(\s?.*)/i, (msg) ->
        # TODO

    robot.respond /mail (\S+) (.+)/i, (msg) ->
        [command, recipient, message] = msg.match
