Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-08-19 21:10:21 +0300
committerDouwe Maan <douwe@gitlab.com>2015-08-19 21:10:21 +0300
commit76dbafba86dda96b7ba2f93fc7e07eea3ca48302 (patch)
treea656779e1819fa65db805b6be09c9e009f2f92ea /app/workers
parent170aa3b43b5186f73b149eae6b80b96a9b1171b2 (diff)
Send a rejection email when the incoming email couldn't be processed.
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/email_receiver_worker.rb37
1 files changed, 31 insertions, 6 deletions
diff --git a/app/workers/email_receiver_worker.rb b/app/workers/email_receiver_worker.rb
index 94e346b5a51..2cfd64cefad 100644
--- a/app/workers/email_receiver_worker.rb
+++ b/app/workers/email_receiver_worker.rb
@@ -6,17 +6,42 @@ class EmailReceiverWorker
def perform(raw)
return unless Gitlab::ReplyByEmail.enabled?
- # begin
- Gitlab::EmailReceiver.new(raw).process
- # rescue => e
- # handle_failure(raw, e)
- # end
+ begin
+ Gitlab::EmailReceiver.new(raw).execute
+ rescue => e
+ handle_failure(raw, e)
+ end
end
private
def handle_failure(raw, e)
- # TODO: Handle better.
Rails.logger.warn("Email can not be processed: #{e}\n\n#{raw}")
+
+ can_retry = false
+ reason = nil
+
+ case e
+ when Gitlab::EmailReceiver::SentNotificationNotFound
+ reason = "We couldn't figure out what the email is in reply to. Please create your comment through the web interface."
+ when Gitlab::EmailReceiver::EmptyEmailError
+ can_retry = true
+ reason = "It appears that the email is blank. Make sure your reply is at the top of the email, we can't process inline replies."
+ when Gitlab::EmailReceiver::AutoGeneratedEmailError
+ reason = "The email was marked as 'auto generated', which we can't accept. Please create your comment through the web interface."
+ when Gitlab::EmailReceiver::UserNotFoundError
+ reason = "We couldn't figure out what user corresponds to the email. Please create your comment through the web interface."
+ when Gitlab::EmailReceiver::UserNotAuthorizedError
+ reason = "You are not allowed to respond to the thread you are replying to. If you believe this is in error, contact a staff member."
+ when Gitlab::EmailReceiver::NoteableNotFoundError
+ reason = "The thread you are replying to no longer exists, perhaps it was deleted? If you believe this is in error, contact a staff member."
+ when Gitlab::EmailReceiver::InvalidNote
+ can_retry = true
+ reason = e.message
+ else
+ return
+ end
+
+ EmailRejectionMailer.delay.rejection(reason, raw, can_retry)
end
end