Skip to content

Commit

Permalink
get full name from email
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcoder04 committed Nov 24, 2022
1 parent 4038252 commit 62cec16
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion iserv/email/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"

"github.com/alexcoder04/iserv2go/iserv/iutils"
"github.com/alexcoder04/iserv2go/iserv/types"
)

Expand All @@ -28,7 +29,7 @@ func buildMailBody(mail types.EMail) []byte {
strings.Join([]string{
"MIME-version: 1.0",
"Content-Type: text/plain; charset=utf-8",
"From: " + mail.From,
"From: " + iutils.GetNameFromAddress(mail.From) + "<" + mail.From + ">",
getToString(mail.To, mail.ToDispName, mail.CCs),
"Subject: " + mail.Subject,
"\r\n",
Expand Down
19 changes: 19 additions & 0 deletions iserv/iutils/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package iutils

import (
"strings"
"unicode"
)

// TODO move to friendly
func GetNameFromAddress(addr string) string {
arr := strings.Split(strings.Split(addr, "@")[0], ".")
res := ""
for i := range arr {
if len(arr[i]) == 1 {
continue
}
res += string(append([]rune{unicode.ToUpper([]rune(arr[i])[0])}, []rune(arr[i])[1:]...))
}
return res
}
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

"github.com/alexcoder04/iserv2go/iserv"
"github.com/alexcoder04/iserv2go/iserv/iutils"
"github.com/alexcoder04/iserv2go/iserv/types"
"github.com/joho/godotenv"
)
Expand Down Expand Up @@ -96,7 +97,7 @@ func main() {
Subject: "Hello World",
From: myMail,
To: myMail,
ToDispName: "ME",
ToDispName: iutils.GetNameFromAddress(myMail),
CCs: []string{},
Body: "Hello World, it's me via iserv2go!",
}
Expand Down

0 comments on commit 62cec16

Please sign in to comment.