Add handling for message reply via email
If the reply_email_domain configuration is set the messages plugin will use unique Reply-To addresses for every email. They contain enough information to reconstruct the message context and a hash to avoid user forgery and spam. A mail transfer agent must be configured to call the new rake task foodsoft:parse_reply_email for incoming mails. The rake task requires the receipt of the mail in the RECIPIENT variable and the raw message via standard input. An example invocation would look like: rake foodsoft:parse_reply_email RECIPIENT=f.1.1.HASH < test.eml
This commit is contained in:
parent
6b32d0c960
commit
4e35e2d58e
11 changed files with 135 additions and 11 deletions
|
|
@ -1,3 +1,5 @@
|
|||
require "base32"
|
||||
|
||||
class Message < ActiveRecord::Base
|
||||
belongs_to :sender, :class_name => "User", :foreign_key => "sender_id"
|
||||
belongs_to :group, :class_name => "Group", :foreign_key => "group_id"
|
||||
|
|
@ -23,6 +25,7 @@ class Message < ActiveRecord::Base
|
|||
validates_length_of :subject, :in => 1..255
|
||||
validates_inclusion_of :email_state, :in => EMAIL_STATE.values
|
||||
|
||||
before_create :create_salt
|
||||
before_validation :clean_up_recipient_ids, :on => :create
|
||||
|
||||
def self.deliver(message_id)
|
||||
|
|
@ -61,8 +64,18 @@ class Message < ActiveRecord::Base
|
|||
add_recipients([user])
|
||||
end
|
||||
|
||||
def mail_hash_for_user(user)
|
||||
digest = Digest::SHA1.new
|
||||
digest.update self.id.to_s
|
||||
digest.update ":"
|
||||
digest.update salt
|
||||
digest.update ":"
|
||||
digest.update user.id.to_s
|
||||
Base32.encode digest.digest
|
||||
end
|
||||
|
||||
# Returns true if this message is a system message, i.e. was sent automatically by Foodsoft itself.
|
||||
def system_message?
|
||||
def system_message?
|
||||
self.sender_id.nil?
|
||||
end
|
||||
|
||||
|
|
@ -94,6 +107,10 @@ class Message < ActiveRecord::Base
|
|||
def is_readable_for?(user)
|
||||
!private || sender == user || recipients_ids.include?(user.id)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_salt
|
||||
self.salt = [Array.new(6){rand(256).chr}.join].pack("m").chomp
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue