Class: FormMail

Inherits:
Object
  • Object
show all
Includes:
Forms::Models::Extension
Defined in:
app/models/form_mail.rb

Instance Method Summary collapse

Methods included from Forms::Models::Extension

included

Instance Method Details

#bodyObject



73
74
75
76
77
78
79
80
81
# File 'app/models/form_mail.rb', line 73

def body
  # This parses the content of the form
  @parser = Radius::Parser.new(PageContext.new(@page), :tag_prefix => 'r')
  if @config[:body]
    @parser.parse(@form.send(@config[:body]))
  else
    @parser.parse(@form.content)
  end
end

#ccObject



83
84
85
# File 'app/models/form_mail.rb', line 83

def cc
  @config[:cc]
end

#charsetObject



108
109
110
111
# File 'app/models/form_mail.rb', line 108

def charset
  charset = @config[:charset] || 'utf-8'
  charset = charset == '' ? nil : charset
end

#content_typeObject



104
105
106
# File 'app/models/form_mail.rb', line 104

def content_type
  content_type = @config[:content_type] || 'text/html'
end

#createObject



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
# File 'app/models/form_mail.rb', line 4

def create
  begin
    FormMailer.deliver_mail(
      :recipients     => recipients,
      :from           => from,
      :reply_to       => reply_to,
      :subject        => subject,
      :body           => body,
      :cc             => cc,
      :headers        => headers,
      :content_type   => content_type,
      :charset        => charset,
      :config         => @config
    )
    @sent = true
  rescue Exception => exception
    raise exception if RAILS_ENV['development']
    @message = exception
    @sent = false
  end
  
  @result = {
    :sent     => self.sent?,
    :message  => self.message,
    :subject  => self.subject,
    :from     => self.from
  }
end

#fromObject



33
34
35
36
37
38
39
# File 'app/models/form_mail.rb', line 33

def from
  begin
    Forms::Tags::Responses.retrieve(@data, @config[:field][:from])
  rescue
    @config[:from]
  end
end

#headersObject



95
96
97
98
99
100
101
102
# File 'app/models/form_mail.rb', line 95

def headers
  headers = { 'Reply-To' => reply_to }
  if sender
    headers['Return-Path'] = sender
    headers['Sender'] = sender
  end
  headers
end

#messageObject



91
92
93
# File 'app/models/form_mail.rb', line 91

def message
  @message || nil
end

#recipientsObject



41
42
43
44
45
46
47
# File 'app/models/form_mail.rb', line 41

def recipients
  begin
    Forms::Tags::Responses.retrieve(@data, @config[:field][:to])
  rescue
    @config[:to]
  end
end

#reply_toObject



49
50
51
52
53
54
55
# File 'app/models/form_mail.rb', line 49

def reply_to
  begin
    Forms::Tags::Responses.retrieve(@data, @config[:field][:reply_to])
  rescue
    @config[:reply_to]
  end
end

#senderObject



57
58
59
60
61
62
63
# File 'app/models/form_mail.rb', line 57

def sender
  begin
    Forms::Tags::Responses.retrieve(@data, @config[:field][:sender])
  rescue
    @config[:sender]
  end
end

#sent?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'app/models/form_mail.rb', line 87

def sent?
  @sent || false
end

#subjectObject



65
66
67
68
69
70
71
# File 'app/models/form_mail.rb', line 65

def subject
  begin
    Forms::Tags::Responses.retrieve(@data, @config[:field][:subject])
  rescue
    @config[:subject]
  end
end