Class: SecretMail::MailAction
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SecretMail::MailAction
- Defined in:
- lib/secret_mail/record.rb
Class Method Summary collapse
Instance Method Summary collapse
- #action ⇒ Object
- #action=(v) ⇒ Object
- #from=(v) ⇒ Object
- #params ⇒ Object
- #params=(v) ⇒ Object
- #valid_sender?(v) ⇒ Boolean
Class Method Details
.create(from, action, params = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/secret_mail/record.rb', line 10 def self.create from, action, params = {} # Create a secret mail address r = SecureRandom.random_bytes(5) secret = Base32::Crockford.encode(r).downcase # Create object with sender record = MailAction.new({ :secret_mail => "#{secret}@#{self.mail_domain}", :from => from, :action => action, :params => params, }) end |
.find_valid(secret_mail, from) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/secret_mail/record.rb', line 25 def self.find_valid secret_mail, from s = find_by_secret_mail(secret_mail) if s && s.crypted_from s.valid_sender?(from) ? s : nil else s end end |
Instance Method Details
#action ⇒ Object
50 51 52 |
# File 'lib/secret_mail/record.rb', line 50 def action (self.packed_action && JSON.parse(self.packed_action)[0]) || nil end |
#action=(v) ⇒ Object
45 46 47 |
# File 'lib/secret_mail/record.rb', line 45 def action= v self.packed_action = [v].to_json end |
#from=(v) ⇒ Object
34 35 36 37 |
# File 'lib/secret_mail/record.rb', line 34 def from= v self.salt = UUIDTools::UUID::random_create.to_s self.crypted_from = MailAction.sign(salt, v) end |
#params ⇒ Object
60 61 62 |
# File 'lib/secret_mail/record.rb', line 60 def params (self.packed_params && JSON.parse(self.packed_params)[0]) || nil end |
#params=(v) ⇒ Object
55 56 57 |
# File 'lib/secret_mail/record.rb', line 55 def params= v self.packed_params = [v].to_json end |
#valid_sender?(v) ⇒ Boolean
40 41 42 |
# File 'lib/secret_mail/record.rb', line 40 def valid_sender? v crypted_from == MailAction.sign(salt, v) end |