Encryption Module: How to Access User Information?
Added by Michael Wosnitza almost 12 years ago
Hello,
I am currently working on a plugin to encrypt notification emails. Every user is supposed to have a public GPG key and outgoing notification emails are encrypted with the according key.
I started with adding a new field in the web configuration so every user can input his public GPG key.
Then, I did some research and found out a good way to modify notification emails by patching the deliver_mail method in app/models/mailer.rb. My patch so far looks like this:
module MailerPatch
def self.included(base) # :nodoc:
base.send(:extend, ClassMethods)
base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
end
end
module ClassMethods
def deliver_mail(mail)
return false if mail.to.blank? && mail.cc.blank? && mail.bcc.blank?
mail.subject="New Subject"
super
end
end
end
What this does is changing the subject of all out-going notification emails to "New Subject".
What I actually want to do is encrypt mail.body with the GPG key belonging to mail.to
My question is: How do I access user information within this function? I need to find the key belonging to a specific email address. I could access directly the database but that appears cumbersome. I would prefer to use functions within redmine to do that but I am not familiar enough with Redmine or Ruby for that matter.
Please help.