public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
Michael Hartl (author)
Tue May 13 11:21:28 -0700 2008
commit  ab2d05492b97caac5d9032338ac01bc5b1ff36de
tree    c38e7af1faf55f037bff5e7be5172328b3c5908d
parent  292658c0d3ece68ff48ebd51614d32d1facadeaf
insoshi / app / models / person_mailer.rb
100644 80 lines (67 sloc) 2.755 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
class PersonMailer < ActionMailer::Base
  extend PreferencesHelper
  
  def domain
    @domain ||= PersonMailer.global_prefs.domain
  end
  
  def server
    @server_name ||= PersonMailer.global_prefs.server_name
  end
  
  def password_reminder(person)
    from "Password reminder <password-reminder@#{domain}>"
    recipients person.email
    subject formatted_subject("Password reminder")
    body "domain" => server, "person" => person
  end
  
  def message_notification(message)
    from "Message notification <message@#{domain}>"
    recipients message.recipient.email
    subject formatted_subject("New message")
    body "domain" => server, "message" => message
  end
  
  def connection_request(connection)
    from "Contact request <connection@#{domain}>"
    recipients connection.contact.email
    subject formatted_subject("New contact request")
    body "domain" => server,
                 "connection" => connection,
                 "url" => edit_connection_path(connection),
                 "preferences_note" => preferences_note(connection.contact)
  end
  
  def blog_comment_notification(comment)
    from "Comment notification <comment@#{domain}>"
    recipients comment.commented_person.email
    subject formatted_subject("New blog comment")
    body "domain" => server, "comment" => comment,
                 "url" =>
                 blog_post_path(comment.commentable.blog, comment.commentable),
                 "preferences_note" =>
                    preferences_note(comment.commented_person)
  end
  
  def wall_comment_notification(comment)
    from "Comment notification <comment@#{domain}>"
    recipients comment.commented_person.email
    subject formatted_subject("New wall comment")
    body "domain" => server, "comment" => comment,
                 "url" => person_path(comment.commentable, :anchor => "wall"),
                 "preferences_note" =>
                    preferences_note(comment.commented_person)
  end
  
  def email_verification(ev)
    from "Email verification <email@#{domain}>"
    recipients ev.person.email
    subject formatted_subject("Email verification")
    body "server_name" => server,
                 "code" => ev.code
  end
  
  private
  
    # Prepend the application name to subjects if present in preferences.
    def formatted_subject(text)
      name = PersonMailer.global_prefs.app_name
      label = name.blank? ? "" : "[#{name}] "
      "#{label}#{text}"
    end
  
    def preferences_note(person)
      %(To change your email notification preferences, visit
http://#{server}/people/#{person.to_param}/edit)
    end
end