4
4
"bytes"
5
5
"fmt"
6
6
"github.com/jordan-wright/email"
7
+ "golang.org/x/crypto/sha3"
7
8
"html/template"
8
9
"net/textproto"
9
10
"os"
@@ -68,6 +69,10 @@ func (tm *TemplateManager) RenderTemplate(name string, data interface{}) (string
68
69
if err != nil {
69
70
return template .HTML (fmt .Sprintf ("Failed to read image: %s" , imageSrc ))
70
71
}
72
+ // Inline images must have unique names
73
+ // 메일 읽지도 않았는데 탈락 이미지 이름이 미리보기에 나오면 슬프지 않을까요?
74
+ ext := filepath .Ext (imageSrc )
75
+ imageSrc = fmt .Sprintf ("%s%s" , hashString (imageSrc ), ext )
71
76
header := textproto.MIMEHeader {
72
77
"Content-ID" : {fmt .Sprintf ("<%s>" , imageSrc )},
73
78
}
@@ -89,6 +94,10 @@ func (tm *TemplateManager) RenderTemplate(name string, data interface{}) (string
89
94
if err != nil {
90
95
return template .HTML (fmt .Sprintf ("Failed to read image: %s" , imageSrc ))
91
96
}
97
+ // Inline images must have unique names
98
+ // 메일 읽지도 않았는데 탈락 이미지 이름이 미리보기에 나오면 슬프지 않을까요?
99
+ ext := filepath .Ext (imageSrc )
100
+ imageSrc = fmt .Sprintf ("%s-%s%s" , hashString (imageSrc ), width , ext )
92
101
header := textproto.MIMEHeader {
93
102
"Content-ID" : {fmt .Sprintf ("<%s>" , imageSrc )},
94
103
}
@@ -148,3 +157,9 @@ func (tm *TemplateManager) DeleteTemplate(name string) {
148
157
func (tm * TemplateManager ) Templates () map [string ]* template.Template {
149
158
return tm .ExportedTemplates ()
150
159
}
160
+
161
+ func hashString (s string ) string {
162
+ h := sha3 .New512 ()
163
+ h .Write ([]byte (s ))
164
+ return fmt .Sprintf ("%x" , h .Sum (nil ))
165
+ }
0 commit comments