Created
January 31, 2012 21:49
-
-
Save practicingruby/1713184 to your computer and use it in GitHub Desktop.
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
require_relative "../lib/postal_service" | |
require_relative "config" | |
list_members = [] | |
PostalService.run(CONFIGURATION_DATA) do |incoming, outgoing| | |
if incoming.to.any? { |e| e[/\+subscribe@#{CONFIGURATION_DATA[:domain]}/] } | |
if list_members.include?(incoming.from) | |
outgoing.subject = "ERROR: Already subscribed" | |
outgoing.body = "You are already subscribed, you can't subscribe again" | |
else | |
outgoing.subject = "SUBSCRIBED!" | |
list_members << incoming.from | |
end | |
elsif incoming.to.any? { |e| e[/\+unsubscribe@#{CONFIGURATION_DATA[:domain]}/] } | |
if list_members.delete(incoming.from) | |
outgoing.subject = "UNSUBSCRIBED!" | |
outgoing.body = "Sorry to see you go!" | |
else | |
outgoing.subject = "ERROR: Not on subscriber list" | |
outgoing.body = "You tried to unsubscribe, but you are not on our list!" | |
end | |
else | |
outgoing.reply_to = CONFIGURATION_DATA[:default_sender] | |
outgoing.bcc = list_members.join(", ") | |
outgoing.subject = incoming.subject | |
outgoing.body = incoming.body.to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment