File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -72,7 +72,12 @@ func (e *emailTypeNotifier) buildMessage(entries []*log.Entry) []byte {
7272 for k , v := range header {
7373 message += fmt .Sprintf ("%s: %s\r \n " , k , v )
7474 }
75- message += "\r \n " + base64 .StdEncoding .EncodeToString ([]byte (body ))
75+
76+ encodedBody := base64 .StdEncoding .EncodeToString ([]byte (body ))
77+ //RFC 2045 base64 encoding demands line no longer than 76 characters.
78+ for _ , line := range SplitSubN (encodedBody , 76 ) {
79+ message += "\r \n " + line
80+ }
7681
7782 return []byte (message )
7883}
Original file line number Diff line number Diff line change 1+ package notifications
2+
3+ import "bytes"
4+
5+ // SplitSubN splits a string into a list of string with each having
6+ // a maximum number of characters n
7+ func SplitSubN (s string , n int ) []string {
8+ sub := ""
9+ subs := []string {}
10+
11+ runes := bytes .Runes ([]byte (s ))
12+ l := len (runes )
13+ for i , r := range runes {
14+ sub = sub + string (r )
15+ if (i + 1 )% n == 0 {
16+ subs = append (subs , sub )
17+ sub = ""
18+ } else if (i + 1 ) == l {
19+ subs = append (subs , sub )
20+ }
21+ }
22+
23+ return subs
24+ }
You can’t perform that action at this time.
0 commit comments