~proycon/MailyGo

ecbf660a17ca0d50f1853526c575248eb1473145 — Maarten van Gompel 1 year, 1 month ago f79df1a
added _subject field, use form name as From name, don't send empty fields
2 files changed, 17 insertions(+), 6 deletions(-)

M README.md
M mail.go
M README.md => README.md +2 -1
@@ 42,6 42,7 @@ You can find a sample form in the `form.html` file. Only fields whose name do no
| **`_replyTo`** | optional | - | Email address which should be configured as replyTo, (most probably not hidden) |
| **`_redirectTo`** | optional | - | URL to redirect to, hidden |
| **`_formName`** | optional | - | Name of the form, hidden |
| **`_subject`** | optional | - | Subject of the mail to send |
| **`_t_email`** | optional | - | (Default) "Honeypot" field, not hidden, advised (see notice below) |

## Spam protection


@@ 52,4 53,4 @@ If a Google Safe Browsing API key is set, submitted URLs will also get checked f

## License

MailyGo is licensed under the MIT license, so you can do basically everything with it, but nevertheless, please contribute your improvements to make MailyGo better for everyone. See the LICENSE file.
\ No newline at end of file
MailyGo is licensed under the MIT license, so you can do basically everything with it, but nevertheless, please contribute your improvements to make MailyGo better for everyone. See the LICENSE file.

M mail.go => mail.go +15 -5
@@ 17,7 17,7 @@ func sendForm(values *FormValues) {

func buildMessage(recipient string, date time.Time, values *FormValues) string {
	msgBuffer := &bytes.Buffer{}
	_, _ = fmt.Fprintf(msgBuffer, "From: Forms <%s>", appConfig.Sender)
	_, _ = fmt.Fprintf(msgBuffer, "From: \"%s\" <%s>", findFormName(values), appConfig.Sender)
	_, _ = fmt.Fprintln(msgBuffer)
	_, _ = fmt.Fprintf(msgBuffer, "To: %s", recipient)
	_, _ = fmt.Fprintln(msgBuffer)


@@ 27,7 27,7 @@ func buildMessage(recipient string, date time.Time, values *FormValues) string {
	}
	_, _ = fmt.Fprintf(msgBuffer, "Date: %s", date.Format(time.RFC1123Z))
	_, _ = fmt.Fprintln(msgBuffer)
	_, _ = fmt.Fprintf(msgBuffer, "Subject: New submission on %s", findFormName(values))
	_, _ = fmt.Fprintf(msgBuffer, "Subject: %s", findSubject(values))
	_, _ = fmt.Fprintln(msgBuffer)
	_, _ = fmt.Fprintln(msgBuffer)
	bodyValues := removeMetaValues(values)


@@ 37,9 37,12 @@ func buildMessage(recipient string, date time.Time, values *FormValues) string {
	}
	sort.Strings(keys)
	for _, key := range keys {
		_, _ = fmt.Fprint(msgBuffer, key)
		_, _ = fmt.Fprint(msgBuffer, ": ")
		_, _ = fmt.Fprintln(msgBuffer, strings.Join((*bodyValues)[key], ", "))
		value := (*bodyValues)[key];
		if len(value) > 0 {
			_, _ = fmt.Fprint(msgBuffer, key)
			_, _ = fmt.Fprint(msgBuffer, ": ")
			_, _ = fmt.Fprintln(msgBuffer, strings.Join(value, ", "))
		}
	}
	return msgBuffer.String()
}


@@ 71,6 74,13 @@ func findFormName(values *FormValues) string {
	return "a form"
}

func findSubject(values *FormValues) string {
	if len((*values)["_subject"]) == 1 && (*values)["_subject"][0] != "" {
		return (*values)["_subject"][0]
	}
	return "New form submission"
}

func findReplyTo(values *FormValues) string {
	if len((*values)["_replyTo"]) == 1 && (*values)["_replyTo"][0] != "" {
		return (*values)["_replyTo"][0]