Skip to content

Instantly share code, notes, and snippets.

@klochner
Created July 30, 2009 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klochner/158483 to your computer and use it in GitHub Desktop.
Save klochner/158483 to your computer and use it in GitHub Desktop.
class ActionMailer::Base
@@name_regex = '[\w\.%\+\-]+'.freeze
@@dom_head_regex = '(?:[A-Z0-9\-]+\.)+'.freeze
@@dom_tld_regex = '(?:com|org|net|edu|gov|mil|biz|info|mobi|name|aero|jobs|museum|[A-Z]{2})'.freeze
@@carated_regex = /\A.*<\s*(#{@@name_regex}@#{@@dom_head_regex}#{@@dom_tld_regex})\s*>.*\z/i
@@uncarated_regex = /\A\s*(#{@@name_regex}@#{@@dom_head_regex}#{@@dom_tld_regex})\s*\z/i
def valid_recipient(s)
addr = $1 if s=~@@carated_regex || s=~@@uncarated_regex
addr && Unsubscribe.find_by_email(addr).nil?
end
def valid_recipients(recipients_str)
recipient_list = []
recipients_str.split(",").each{|r| recipient_list << r if valid_recipient(r)}
recipients recipient_list.join(",")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment