3 class Message < ActiveRecord::Base
4 belongs_to :sender, :class_name => "User", :foreign_key => :from_user_id
5 belongs_to :recipient, :class_name => "User", :foreign_key => :to_user_id
7 validates :title, :presence => true, :utf8 => true, :length => 1..255
8 validates :body, :sent_on, :sender, :recipient, :presence => true
10 def self.from_mail(mail, from, to)
13 body = mail.text_part.decoded
15 body = HTMLEntities.new.decode(Sanitize.clean(mail.html_part.decoded))
17 elsif mail.text? && mail.sub_type == "html"
18 body = HTMLEntities.new.decode(Sanitize.clean(mail.decoded))
26 :sent_on => mail.date.new_offset(0),
27 :title => mail.subject.sub(/\[OpenStreetMap\] */, ""),
29 :body_format => "text"
34 RichText.new(self[:body_format], self[:body])
39 md5 << from_user_id.to_s
40 md5 << to_user_id.to_s
41 md5 << sent_on.xmlschema