 
 handleMailchimpWebHook = (req, res) ->
   post = req.body
-  #badLog("Got post data: #{JSON.stringify(post, null, '\t')}")
 
   unless post.type in ['unsubscribe', 'profile']
     res.send 'Bad post type'

    matches = _.filter session.matches, (match) -> match.date >= getTimeFromDaysAgo now, daysAgo
    defeats = _.filter matches, (match) -> match.metrics.rank is 1 and match.opponents[0].metrics.rank is 0
    victories = _.filter matches, (match) -> match.metrics.rank is 0 and match.opponents[0].metrics.rank is 1
    #ties = _.filter matches, (match) -> match.metrics.rank is 0 and match.opponents[0].metrics.rank is 0
    defeat = _.last defeats
    victory = _.last victories

    #log.info "#{user.name} had #{matches.length} matches from last #{daysAgo} days out of #{session.matches.length} total matches. #{defeats.length} defeats, #{victories.length} victories, and #{ties.length} ties."
    #matchInfos = ("\t#{match.date}\t#{match.date >= getTimeFromDaysAgo(now, daysAgo)}\t#{match.metrics.rank}\t#{match.opponents[0].metrics.rank}" for match in session.matches)
    #log.info "Matches:\n#{matchInfos.join('\n')}"

    sendEmail = (defeatContext, victoryContext) ->
      # TODO: do something with the preferredLanguage?

  user.set 'mailChimp.email', post.data.email
  user.set 'mailChimp.euid', post.data.id


module.exports.handleUnsubscribe = handleUnsubscribe = (user) ->
  user.set 'emailSubscriptions', []
  for emailGroup in mail.NEWS_GROUPS
    user.setEmailSubscription emailGroup, false
