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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
379a40bd
Commit
379a40bd
authored
Feb 24, 2022
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify parsing of emails from headers
Also improves the regex to handle different types of whitespace
parent
8eeeb3d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
17 deletions
+7
-17
lib/gitlab/email/receiver.rb
lib/gitlab/email/receiver.rb
+7
-17
No files found.
lib/gitlab/email/receiver.rb
View file @
379a40bd
...
...
@@ -8,7 +8,7 @@ module Gitlab
class
Receiver
include
Gitlab
::
Utils
::
StrongMemoize
RECEIVE
R_HEADER_REGEX
=
/for \<(.*
)\>/
.
freeze
RECEIVE
D_HEADER_REGEX
=
/for\s+\<(.+
)\>/
.
freeze
def
initialize
(
raw
)
@raw
=
raw
...
...
@@ -40,7 +40,7 @@ module Gitlab
envelope_to:
envelope_to
.
map
(
&
:value
),
x_envelope_to:
x_envelope_to
.
map
(
&
:value
),
# reduced down to what looks like an email in the received headers
received_recipients:
rec
eived_headers_containing_possible_recipients
.
map
(
&
:value
).
map
{
|
v
|
RECEIVER_HEADER_REGEX
.
match
(
v
)[
1
]
}
,
received_recipients:
rec
ipients_from_received_headers
,
meta:
{
client_id:
"email/
#{
mail
.
from
.
first
}
"
,
project:
handler
&
.
project
&
.
full_path
...
...
@@ -148,25 +148,15 @@ module Gitlab
end
def
find_first_key_from_received_headers
# there are often multiple Received headers
# and we just want ones that has something that looks like an email
# and return the first one that matches
filtered
=
received_headers_containing_possible_recipients
matching
=
filtered
.
map
(
&
:value
).
grep
(
RECEIVER_HEADER_REGEX
)
matching
.
find
do
|
value
|
looks_like_email
=
RECEIVER_HEADER_REGEX
.
match
(
value
)
key
=
email_class
.
key_from_address
(
looks_like_email
[
1
])
recipients_from_received_headers
.
find
do
|
email
|
key
=
email_class
.
key_from_address
(
email
)
break
key
if
key
end
end
def
received_headers_containing_possible_recipients
strong_memoize
:matching_received_headers
do
# there are often multiple Received headers so we filter them out
# and also have some extra stuff so we have to strip that out
received
.
select
{
|
header
|
RECEIVER_HEADER_REGEX
=~
header
.
value
}
def
recipients_from_received_headers
strong_memoize
:emails_from_received_headers
do
received
.
map
{
|
header
|
header
.
value
[
RECEIVED_HEADER_REGEX
,
1
]
}.
compact
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