Skip to content

Commit

Permalink
Add possibility to encode mail subject and body to base64
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Feb 19, 2021
1 parent 1556510 commit 954e6c5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,16 @@ This is a sample JSON passed as HTTP-POST request to the 443 port (configured ab
}
}

You can encode subject and bodyhtml in base64 if the data contains special characters

{
"sendmail": {
"from": "sampleuser@gmail.com",
"to": "tomyfriend@postmail.com",
"subject": "VGVzdCBmcm9tIFBIUA==",
"subjectEncoding": "base64",
"bodyhtml": "VGhpcyBpcyByZWNlaXZlZCB0aHJvdWdoIDxoMT5SZXN0R29NYWlsPC9oMT4=",
"bodyhtmlEncoding": "base64"
}
}

18 changes: 18 additions & 0 deletions restgomail.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ func processRequest(req *[]byte, remote string) bool {
to, toType := jsonmsg.getStringByPath("sendmail/to")
subject, subjectType := jsonmsg.getStringByPath("sendmail/subject")
bodyhtml, bodyhtmlType := jsonmsg.getStringByPath("sendmail/bodyhtml")
subjectEnc := jsonmsg.getStringByPathWithDefault("sendmail/subjectEncoding", "none")
bodyhtmlEnc := jsonmsg.getStringByPathWithDefault("sendmail/bodyhtmlEncoding", "none")

if fromType == "none" || toType == "none" ||
subjectType == "none" || bodyhtmlType == "none" {
Expand All @@ -286,6 +288,22 @@ func processRequest(req *[]byte, remote string) bool {
}
return true
}
if subjectEnc == "base64" {
dec, err := base64.StdEncoding.DecodeString(subject)
if err != nil {
log.Printf("Error (%s) base64 decoding error (1)\n", remote)
return true
}
subject = string(dec)
}
if bodyhtmlEnc == "base64" {
dec, err := base64.StdEncoding.DecodeString(bodyhtml)
if err != nil {
log.Printf("Error (%s) base64 decoding error (2)\n", remote)
return true
}
bodyhtml = string(dec)
}

log.Printf("Received send mail request from %s\n", remote)
allowedSnAddr := getConfigString("smtpAllowedFromAddressOnly")
Expand Down

0 comments on commit 954e6c5

Please sign in to comment.