Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
76dbafba
Commit
76dbafba
authored
Aug 19, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Send a rejection email when the incoming email couldn't be processed.
parent
170aa3b4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
12 deletions
+85
-12
app/mailers/email_rejection_mailer.rb
app/mailers/email_rejection_mailer.rb
+35
-0
app/views/email_rejection_mailer/rejection.html.haml
app/views/email_rejection_mailer/rejection.html.haml
+5
-0
app/views/email_rejection_mailer/rejection.text.haml
app/views/email_rejection_mailer/rejection.text.haml
+4
-0
app/workers/email_receiver_worker.rb
app/workers/email_receiver_worker.rb
+31
-6
lib/gitlab/email_receiver.rb
lib/gitlab/email_receiver.rb
+10
-6
No files found.
app/mailers/email_rejection_mailer.rb
0 → 100644
View file @
76dbafba
class
EmailRejectionMailer
<
ActionMailer
::
Base
add_template_helper
ApplicationHelper
add_template_helper
GitlabMarkdownHelper
helper_method
:current_user
,
:can?
default
from:
"
#{
Gitlab
.
config
.
gitlab
.
email_display_name
}
<
#{
Gitlab
.
config
.
gitlab
.
email_from
}
>"
default
reply_to:
"
#{
Gitlab
.
config
.
gitlab
.
email_display_name
}
<
#{
Gitlab
.
config
.
gitlab
.
email_reply_to
}
>"
def
rejection
(
reason
,
original_raw
,
can_retry
=
false
)
@reason
=
reason
@original_message
=
Mail
::
Message
.
new
(
original_raw
)
headers
=
{
to:
@original_message
.
from
,
subject:
"[Rejected]
#{
@original_message
.
subject
}
"
}
headers
[
'Message-ID'
]
=
SecureRandom
.
hex
headers
[
'In-Reply-To'
]
=
@original_message
.
message_id
headers
[
'References'
]
=
@original_message
.
message_id
headers
[
'Reply-To'
]
=
@original_message
.
to
.
first
if
can_retry
mail
(
headers
)
end
def
current_user
nil
end
def
can?
false
end
end
app/views/email_rejection_mailer/rejection.html.haml
0 → 100644
View file @
76dbafba
%p
Unfortunately, your email message to GitLab could not be processed.
%p
=
gfm
@reason
app/views/email_rejection_mailer/rejection.text.haml
0 → 100644
View file @
76dbafba
Unfortunately, your email message to GitLab could not be processed.
=
@reason
app/workers/email_receiver_worker.rb
View file @
76dbafba
...
@@ -6,17 +6,42 @@ class EmailReceiverWorker
...
@@ -6,17 +6,42 @@ class EmailReceiverWorker
def
perform
(
raw
)
def
perform
(
raw
)
return
unless
Gitlab
::
ReplyByEmail
.
enabled?
return
unless
Gitlab
::
ReplyByEmail
.
enabled?
#
begin
begin
Gitlab
::
EmailReceiver
.
new
(
raw
).
process
Gitlab
::
EmailReceiver
.
new
(
raw
).
execute
#
rescue => e
rescue
=>
e
#
handle_failure(raw, e)
handle_failure
(
raw
,
e
)
#
end
end
end
end
private
private
def
handle_failure
(
raw
,
e
)
def
handle_failure
(
raw
,
e
)
# TODO: Handle better.
Rails
.
logger
.
warn
(
"Email can not be processed:
#{
e
}
\n\n
#{
raw
}
"
)
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
end
end
lib/gitlab/email_receiver.rb
View file @
76dbafba
...
@@ -5,7 +5,7 @@ module Gitlab
...
@@ -5,7 +5,7 @@ module Gitlab
class
EmailUnparsableError
<
ProcessingError
;
end
class
EmailUnparsableError
<
ProcessingError
;
end
class
EmptyEmailError
<
ProcessingError
;
end
class
EmptyEmailError
<
ProcessingError
;
end
class
UserNotFoundError
<
ProcessingError
;
end
class
UserNotFoundError
<
ProcessingError
;
end
class
UserNotAuthorized
Level
Error
<
ProcessingError
;
end
class
UserNotAuthorizedError
<
ProcessingError
;
end
class
NoteableNotFoundError
<
ProcessingError
;
end
class
NoteableNotFoundError
<
ProcessingError
;
end
class
AutoGeneratedEmailError
<
ProcessingError
;
end
class
AutoGeneratedEmailError
<
ProcessingError
;
end
class
SentNotificationNotFound
<
ProcessingError
;
end
class
SentNotificationNotFound
<
ProcessingError
;
end
...
@@ -21,20 +21,20 @@ module Gitlab
...
@@ -21,20 +21,20 @@ module Gitlab
raise
EmailUnparsableError
,
e
raise
EmailUnparsableError
,
e
end
end
def
process
def
execute
raise
SentNotificationNotFound
unless
sent_notification
raise
EmptyEmailError
if
@raw
.
blank?
raise
EmptyEmailError
if
@raw
.
blank?
raise
AutoGeneratedEmailError
if
message
.
header
.
to_s
=~
/auto-(generated|replied)/
raise
AutoGeneratedEmailError
if
message
.
header
.
to_s
=~
/auto-(generated|replied)/
raise
SentNotificationNotFound
unless
sent_notification
author
=
sent_notification
.
recipient
author
=
sent_notification
.
recipient
raise
UserNotFoundError
unless
author
raise
UserNotFoundError
unless
author
project
=
sent_notification
.
project
project
=
sent_notification
.
project
raise
UserNotAuthorized
Level
Error
unless
author
.
can?
(
:create_note
,
project
)
raise
UserNotAuthorizedError
unless
author
.
can?
(
:create_note
,
project
)
raise
NoteableNotFoundError
unless
sent_notification
.
noteable
raise
NoteableNotFoundError
unless
sent_notification
.
noteable
...
@@ -54,7 +54,11 @@ module Gitlab
...
@@ -54,7 +54,11 @@ module Gitlab
).
execute
).
execute
unless
note
.
persisted?
unless
note
.
persisted?
raise
InvalidNote
,
note
.
errors
.
full_messages
.
join
(
"
\n
"
)
message
=
"The comment could not be created for the following reasons:"
note
.
errors
.
full_messages
.
each
do
|
error
|
message
<<
"
\n\n
-
#{
error
}
"
end
raise
InvalidNote
,
message
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment