class Post

Mailing list post

Attributes

from_email_address[RW]
from_name[RW]

Public Class Methods

find_for_dates(mailing_list, month_start, month_end) click to toggle source
# File app/models/post.rb, line 17
def Post.find_for_dates(mailing_list, month_start, month_end)
  logger.debug("Post.find_for_dates(#{mailing_list}, #{month_start}, #{month_end})")
  mailing_list.posts.all(
    :select => "id, date, sender, subject, topica_message_id" ,
    :conditions => [ "date between ? and ?", month_start, month_end ],
    :order => "date desc"
  )
end
new(attributes = nil) click to toggle source
# File app/models/post.rb, line 26
def initialize(attributes = nil)
  super
  self.date = Time.zone.now if date.nil?
end

Public Instance Methods

add_post_text() click to toggle source
# File app/models/post.rb, line 105
def add_post_text
  updated_post_text = post_text(true) || build_post_text
  updated_post_text.text = subject
  updated_post_text.save
end
from_email_address=(value) click to toggle source
# File app/models/post.rb, line 64
def from_email_address=(value)
  @from_email_address = value
  update_sender
end
from_name=(value) click to toggle source
# File app/models/post.rb, line 73
def from_name=(value)
  @from_name = value
  update_sender
end
remove_list_prefix() click to toggle source
# File app/models/post.rb, line 59
def remove_list_prefix
  subject.gsub!(%r\[#{mailing_list.subject_line_prefix}\]\s*/, "")
  subject.strip!
end
sender=(value) click to toggle source
# File app/models/post.rb, line 55
def sender=(value)
  self[:sender] = value
end
sender_obscured() click to toggle source

Replace a couple letters from email addresses to avoid spammers

# File app/models/post.rb, line 79
def sender_obscured
  if sender.blank? or !topica_message_id.blank?
    return sender
  end
  
  sender_parts = sender.split("@")
  if sender_parts.size > 1
    person_name = sender_parts.first
    if person_name.length > 2
      return person_name[0..(person_name.length - 3)] + "..@" + sender_parts.last
    else
      return "..@" + sender_parts.last
    end
  end
  
  sender
end
topica?() click to toggle source
# File app/models/post.rb, line 69
def topica?
  topica_message_id.present?
end
update_sender() click to toggle source
# File app/models/post.rb, line 97
def update_sender
  if @from_name.present? && from_email_address.present? && @from_email_address.present? && !(@from_name.to_s == @from_email_address.to_s )
    self.sender = "#{@from_name} <#{@from_email_address}>"
  else
    self.sender = @from_email_address.to_s
  end
end