mirror of
https://github.com/axllent/mailpit.git
synced 2025-07-03 00:46:58 +02:00
Chore: Remove function duplication - use common tools.InArray()
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/PuerkitoBio/goquery"
|
"github.com/PuerkitoBio/goquery"
|
||||||
|
"github.com/axllent/mailpit/internal/tools"
|
||||||
"github.com/gomarkdown/markdown"
|
"github.com/gomarkdown/markdown"
|
||||||
"github.com/gomarkdown/markdown/html"
|
"github.com/gomarkdown/markdown/html"
|
||||||
"github.com/gomarkdown/markdown/parser"
|
"github.com/gomarkdown/markdown/parser"
|
||||||
@ -136,12 +137,12 @@ func (c CanIEmail) getTest(k string) (Warning, error) {
|
|||||||
var y, n, p float32
|
var y, n, p float32
|
||||||
|
|
||||||
for family, stats := range found.Stats {
|
for family, stats := range found.Stats {
|
||||||
if len(LimitFamilies) != 0 && !inArray(family, LimitFamilies) {
|
if len(LimitFamilies) != 0 && !tools.InArray(family, LimitFamilies) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for platform, clients := range stats.(map[string]interface{}) {
|
for platform, clients := range stats.(map[string]interface{}) {
|
||||||
if len(LimitPlatforms) != 0 && !inArray(platform, LimitPlatforms) {
|
if len(LimitPlatforms) != 0 && !tools.InArray(platform, LimitPlatforms) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for version, support := range clients.(map[string]interface{}) {
|
for version, support := range clients.(map[string]interface{}) {
|
||||||
@ -182,18 +183,6 @@ func (c CanIEmail) getTest(k string) (Warning, error) {
|
|||||||
return warning, nil
|
return warning, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func inArray(n string, h []string) bool {
|
|
||||||
n = strings.ToLower(n)
|
|
||||||
|
|
||||||
for _, v := range h {
|
|
||||||
if strings.ToLower(v) == n {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert markdown to HTML, stripping <p> & </p>
|
// Convert markdown to HTML, stripping <p> & </p>
|
||||||
func mdToHTML(str string) string {
|
func mdToHTML(str string) string {
|
||||||
md := []byte(str)
|
md := []byte(str)
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package htmlcheck
|
package htmlcheck
|
||||||
|
|
||||||
import "sort"
|
import (
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"github.com/axllent/mailpit/internal/tools"
|
||||||
|
)
|
||||||
|
|
||||||
// Platforms returns all platforms with their respective email clients
|
// Platforms returns all platforms with their respective email clients
|
||||||
func Platforms() (map[string][]string, error) {
|
func Platforms() (map[string][]string, error) {
|
||||||
@ -19,7 +23,7 @@ func Platforms() (map[string][]string, error) {
|
|||||||
if !found {
|
if !found {
|
||||||
data[platform] = []string{}
|
data[platform] = []string{}
|
||||||
}
|
}
|
||||||
if !inArray(niceFamily, c) {
|
if !tools.InArray(niceFamily, c) {
|
||||||
c = append(c, niceFamily)
|
c = append(c, niceFamily)
|
||||||
data[platform] = c
|
data[platform] = c
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ func SetMessageTags(id string, tags []string) error {
|
|||||||
applyTags := []string{}
|
applyTags := []string{}
|
||||||
for _, t := range tags {
|
for _, t := range tags {
|
||||||
t = tools.CleanTag(t)
|
t = tools.CleanTag(t)
|
||||||
if t != "" && config.ValidTagRegexp.MatchString(t) && !inArray(t, applyTags) {
|
if t != "" && config.ValidTagRegexp.MatchString(t) && !tools.InArray(t, applyTags) {
|
||||||
applyTags = append(applyTags, t)
|
applyTags = append(applyTags, t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ func SetMessageTags(id string, tags []string) error {
|
|||||||
origTagCount := len(currentTags)
|
origTagCount := len(currentTags)
|
||||||
|
|
||||||
for _, t := range applyTags {
|
for _, t := range applyTags {
|
||||||
if t == "" || !config.ValidTagRegexp.MatchString(t) || inArray(t, currentTags) {
|
if t == "" || !config.ValidTagRegexp.MatchString(t) || tools.InArray(t, currentTags) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ func SetMessageTags(id string, tags []string) error {
|
|||||||
currentTags = getMessageTags(id)
|
currentTags = getMessageTags(id)
|
||||||
|
|
||||||
for _, t := range currentTags {
|
for _, t := range currentTags {
|
||||||
if !inArray(t, applyTags) {
|
if !tools.InArray(t, applyTags) {
|
||||||
if err := DeleteMessageTag(id, t); err != nil {
|
if err := DeleteMessageTag(id, t); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -87,18 +87,6 @@ func isFile(path string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests if a string is within an array. It is not case sensitive.
|
|
||||||
func inArray(k string, arr []string) bool {
|
|
||||||
k = strings.ToLower(k)
|
|
||||||
for _, v := range arr {
|
|
||||||
if strings.ToLower(v) == k {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert `%` to `%%` for SQL searches
|
// Convert `%` to `%%` for SQL searches
|
||||||
func escPercentChar(s string) string {
|
func escPercentChar(s string) string {
|
||||||
return strings.ReplaceAll(s, "%", "%%")
|
return strings.ReplaceAll(s, "%", "%%")
|
||||||
|
Reference in New Issue
Block a user