-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c6fbbf
commit 4038252
Showing
5 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package email | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/alexcoder04/iserv2go/iserv/types" | ||
) | ||
|
||
func getToString(addr string, dispName string, ccs []string) string { | ||
var res string | ||
|
||
if dispName == "" { | ||
res = fmt.Sprintf("To: %s", addr) | ||
} else { | ||
res = fmt.Sprintf("To: %s <%s>", dispName, addr) | ||
} | ||
|
||
if len(ccs) > 0 { | ||
res += fmt.Sprintf("\r\nCc: %s", strings.Join(ccs, ", ")) | ||
} | ||
|
||
return res | ||
} | ||
|
||
func buildMailBody(mail types.EMail) []byte { | ||
return []byte( | ||
strings.Join([]string{ | ||
"MIME-version: 1.0", | ||
"Content-Type: text/plain; charset=utf-8", | ||
"From: " + mail.From, | ||
getToString(mail.To, mail.ToDispName, mail.CCs), | ||
"Subject: " + mail.Subject, | ||
"\r\n", | ||
mail.Body, | ||
}, "\r\n"), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package types | ||
|
||
type EMail struct { | ||
Subject string | ||
From string | ||
To string | ||
ToDispName string | ||
CCs []string | ||
Body string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters