Skip to content

Commit b9b9c17

Browse files
authored
Merge pull request #14 from hazcod/feat/overview
fix: correctly extract email
2 parents d2131af + 852039a commit b9b9c17

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

pkg/falcon/extractor.go

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,51 +53,46 @@ func getUniqueDeviceID(hostInfo models.DomainAPIVulnerabilityHostInfoV2) (string
5353
}
5454

5555
func findEmailTag(tags []string, emailDomains []string) (email string, err error) {
56-
theTag := ""
57-
5856
for _, tag := range tags {
5957
tag = strings.ToLower(tag)
60-
tag = strings.TrimLeft(tag, strings.ToLower(tagFalconPrefix))
58+
tag = strings.TrimPrefix(tag, strings.ToLower(tagFalconPrefix))
6159

6260
logrus.WithField("tag", tag).Trace("looking at falcon tag")
6361

6462
if !strings.HasPrefix(tag, tagEmailPrefix) {
6563
continue
6664
}
6765

68-
if theTag != "" {
69-
logrus.
70-
WithField("tag", tag).WithField("email", theTag).
71-
WithField("prefix", tagEmailPrefix).
72-
Warn("multiple user tags found")
73-
}
74-
75-
theTag = strings.TrimLeft(tag, tagEmailPrefix)
66+
email = strings.TrimPrefix(tag, tagEmailPrefix)
67+
break
7668
}
7769

78-
if theTag == "" {
70+
if email == "" {
7971
return "", errors.New("email tag not found")
8072
}
8173

82-
theTag = strings.ToLower(theTag)
83-
74+
domainFound := false
8475
for _, domain := range emailDomains {
85-
if ! strings.Contains(theTag ,strings.ToLower(domain)) {
76+
if ! strings.Contains(email, strings.ToLower(domain)) {
8677
continue
8778
}
8879

89-
email = theTag
9080
email = strings.Replace(email, fmt.Sprintf("/%s", domain), fmt.Sprintf("@%s", domain), 1)
9181
email = strings.ReplaceAll(email, "/", ".")
9282

83+
domainFound = true
9384
break
9485
}
9586

87+
if !domainFound {
88+
return "", errors.New("domain not recognized")
89+
}
90+
9691
if !strings.Contains(email, "@") || !strings.Contains(email, ".") {
9792
return "", errors.New("invalid email address: " + email)
9893
}
9994

100-
logrus.WithField("tag", theTag).WithField("email", email).Debug("converted tag to email")
95+
logrus.WithField("email", email).Debug("converted tag to email")
10196

10297
return email, nil
10398
}

0 commit comments

Comments
 (0)