diff options
author | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2010-07-13 20:28:43 +0200 |
---|---|---|
committer | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2010-07-29 19:49:16 +0200 |
commit | 9641aa1478f7a604eff2704edbfb7b6186bcb5e5 (patch) | |
tree | 7ad4ecf020174537db0415586d6ff4179d3b50da /app | |
parent | Add ability to receive emails through HTTP (diff) | |
download | recruiting-webapp-9641aa1478f7a604eff2704edbfb7b6186bcb5e5.tar.gz recruiting-webapp-9641aa1478f7a604eff2704edbfb7b6186bcb5e5.tar.bz2 recruiting-webapp-9641aa1478f7a604eff2704edbfb7b6186bcb5e5.zip |
Notify users trying to answer email question if question wasn't recognised
Diffstat (limited to 'app')
-rw-r--r-- | app/models/email_answer.rb | 7 | ||||
-rw-r--r-- | app/models/user_mailer.rb | 18 | ||||
-rw-r--r-- | app/views/user_mailer/unrecognized_email.erb | 7 |
3 files changed, 30 insertions, 2 deletions
diff --git a/app/models/email_answer.rb b/app/models/email_answer.rb index 730f483..db2af75 100644 --- a/app/models/email_answer.rb +++ b/app/models/email_answer.rb @@ -18,8 +18,11 @@ class EmailAnswer < Answer return unless user.token == subject.captures[1] question = Question.first :conditions => { :id => subject.captures[0] } - return if question.nil? - return unless question.content.is_a? QuestionContentEmail + + if(question.nil? || !question.content.is_a?(QuestionContentEmail)) + UserMailer.deliver_unrecognized_email(user, email) + return + end # Fetch existing answer, if it doesn't exist create a new one # them mark it as incorrect (if it passes all tests it will be correct) diff --git a/app/models/user_mailer.rb b/app/models/user_mailer.rb index 1c9521e..7773c38 100644 --- a/app/models/user_mailer.rb +++ b/app/models/user_mailer.rb @@ -39,6 +39,24 @@ class UserMailer < ActionMailer::Base @body = { :question_title=> question_title(comment.answer), :id => comment.answer.id } end + def unrecognized_email(user, email) + common(user, "Your email sent to #{@app_name} wasn't recognized") + + fields = [:subject, :from, :to].inject(String.new) do |res, cur| + field_name = cur.to_s.camelize + field_content = email.send(cur) + + if field_content.class == Array # string with comma-separated values + field_content = field_content.inject(String.new){ |r,c| r += "#{c.to_s}, " } + field_content = field_content[0..-3] + end + + res += "#{field_name}: #{field_content}\n" + end + + @body = { :email => email, :app_name => @app_name, :fields => fields } + end + def receive(email) # For now email answers for questions are only emails app receives # so try use any received email as answer. diff --git a/app/views/user_mailer/unrecognized_email.erb b/app/views/user_mailer/unrecognized_email.erb new file mode 100644 index 0000000..ae2fd5a --- /dev/null +++ b/app/views/user_mailer/unrecognized_email.erb @@ -0,0 +1,7 @@ +You sent email to <%= @app_name %> with following headers: + +<%= @fields %> +It was not recognized by <%= @app_name %>. + +If you are answering question check if your message has proper subject. +You will see proper subject for answer at bottom of question page. |