Created
February 1, 2012 02:22
-
-
Save practicingruby/1714655 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
| mailing_list = PostalService::MailingList.new("simple_mailing_list.store") | |
| PostalService.run(CONFIGURATION_DATA) do |incoming, outgoing| | |
| from_address = sender(incoming) | |
| case incoming | |
| when filter(:to, /\+subscribe@#{CONFIGURATION_DATA[:domain]}/) | |
| if mailing_list.subscriber?(from_address) | |
| outgoing.subject = "ERROR: Already subscribed" | |
| outgoing.body = "You are already subscribed, you can't subscribe again" | |
| else | |
| mailing_list.subscribe(from_address) | |
| outgoing.subject = "SUBSCRIBED!" | |
| outgoing.body = "Welcome to the club, buddy" | |
| end | |
| when filter(:to, /\+unsubscribe@#{CONFIGURATION_DATA[:domain]}/) | |
| if mailing_list.subscriber?(from_address) | |
| mailing_list.unsubscribe(from_address) | |
| 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 | |
| if mailing_list.subscriber?(from_address) | |
| outgoing.bcc = mailing_list.subscribers.join(", ") | |
| forward(incoming, outgoing) | |
| else | |
| outgoing.subject = "You are not subscribed" | |
| outgoing.body = "You must be a member to post on this list" | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment