Skip to content

Commit

Permalink
subject utf8
Browse files Browse the repository at this point in the history
  • Loading branch information
kakoyi committed Sep 17, 2021
1 parent 206da74 commit 3334e6f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
16 changes: 12 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/rand"
"crypto/tls"
"embed"
"encoding/base64"
"encoding/hex"
"encoding/json"
"flag"
Expand Down Expand Up @@ -212,7 +213,14 @@ func main() {

mapping := sync.Map{}
dict := map[string]string{}
tmpl, err := template.ParseFS(fsys, "login.html", "captcha.html")

tmpl, err := template.New("").
Funcs(template.FuncMap{
"base64": func(v string) template.HTML {
return template.HTML(base64.StdEncoding.EncodeToString(tobytes(v)))
},
}).
ParseFS(fsys, "login.html", "captcha.html")
if nil != err {
log.Println(err.Error())
}
Expand All @@ -227,19 +235,19 @@ func main() {
switch {
case http.MethodGet == req.Method:
case !valid(mail):
data["message"] = dict["mail_reject"]
data["message"] = dict["mail.reject"]
case "" == code:
code = nonce()
mapping.Store(mail, code)
data["code"] = code
data["required"] = "required"
data["message"] = dict["captcha_sent"]
data["message"] = dict["captcha.sent"]
log.Println("send mail:", mail, "code:", code, "error:", send(mail, tmpl, data))
default:
if v, ok := mapping.LoadAndDelete(mail); ok && code == v.(string) {
return setup(resp)
}
data["message"] = dict["captcha_failed"]
data["message"] = dict["captcha.failed"]
}
tmpl.ExecuteTemplate(resp, "login.html", data)
return false
Expand Down
10 changes: 5 additions & 5 deletions views/captcha.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Subject: {{ .dict.subject }}
Subject: =?UTF-8?B?{{ .dict.subject | base64 }}?=
To: {{ .to }}
From: {{ .from }}
MIME-version: 1.0;
Content-Type: text/html; charset="UTF-8";
Content-Type: text/html; charset=UTF-8;

<head>
<base target="_blank">
<style type="text/css">
<style>
::-webkit-scrollbar {
display: none;
}
Expand All @@ -21,12 +21,12 @@
<div style="width:680px;padding:0 10px;margin:0 auto;">
<div style="line-height:1.5;font-size:14px;margin-bottom:25px;color:#4d4d4d;">
<strong>
{{ .dict.mail_content }} <span style="color:#f60;font-size: 24px">{{ .code }}</span>
{{ index .dict "mail.content" }} <span style="color:#f60;font-size: 24px">{{ .code }}</span>
</strong>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</body>
</body>
8 changes: 4 additions & 4 deletions views/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"title": "邮箱验证",
"submit": "提交",
"subject": "验证码",
"mail_content": "您收到此邮件,以便我们确认您的电子邮件地址, 验证码:",
"captcha_failed": "咋啦还不对,再来一发",
"captcha_sent": "验证码已飞奔向您来咯",
"mail_reject": "这邮箱我不支持哦"
"mail.content": "您收到此邮件,以便我们确认您的电子邮件地址, 验证码:",
"captcha.failed": "咋啦还不对,再来一发",
"captcha.sent": "验证码已飞奔向您来咯",
"mail.reject": "这邮箱我不支持哦"
}
8 changes: 4 additions & 4 deletions views/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"title": "Mail Verify",
"submit": "OK",
"subject": "Captcha",
"mail_content": "You received this email so that we may confirm your email address, please enter captcha code:",
"mail_reject": "Sorry, this email not supported",
"captcha_failed": "Verify failed, please re-enter",
"captcha_sent": "The captcha code has been sent"
"mail.content": "You received this email so that we may confirm your email address, please enter captcha code:",
"mail.reject": "Sorry, this email not supported",
"captcha.failed": "Verify failed, please re-enter",
"captcha.sent": "The captcha code has been sent"
}
2 changes: 1 addition & 1 deletion views/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

input[type=text] {
padding: 10px;
width: 30px;
width: 40px;
border-left: 0;
border-right: 0;
outline: none;
Expand Down

0 comments on commit 3334e6f

Please sign in to comment.