Skip to content

Commit

Permalink
explicitly support RFC 5322 email format for verification sender
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Sep 2, 2018
1 parent 4ddcada commit 443b415
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
6 changes: 3 additions & 3 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ You can specify the following environment viriables when issuing `docker run` co
| MYSQL_DSN | string | `'root@tcp(mysql)/tinode'` | MySQL [DSN](https://github.com/go-sql-driver/mysql#dsn-data-source-name) |
| RESET_DB | bool | `false` | Drop and recreate the database. |
| SMTP_PASSWORD | string | | Password to use for authentication with the SMTP server |
| SMTP_PORT | string | | Port number of the SMTP server to use for sending verification emails, e.g. `"25"` or `"587"`. |
| SMTP_SENDER | string | | Email address to use in the `FROM` field of verification emails and for authenticationwith the SMTP server. |
| SMTP_SERVER | string | | Name of the SMTP server to use for sending verification emails, e.g. `"smtp.gmail.com"`. If SMTP_SERVER is not defined, email verification will be disabled. |
| SMTP_PORT | number | | Port number of the SMTP server to use for sending verification emails, e.g. `25` or `587`. |
| SMTP_SENDER | string | | RFC 5322 email address to use in the `FROM` field of verification emails and for authentication with the SMTP server. |
| SMTP_SERVER | string | | Name of the SMTP server to use for sending verification emails, e.g. `smtp.gmail.com`. If SMTP_SERVER is not defined, email verification will be disabled. |
| TLS_CONTACT_ADDRESS | string | | Optional email address to use as contact for Lets Encrypt certificats. |
| TLS_DOMAIN_NAME | string | | If non-empty, enables TLS (http**s**) and configures domain name of your container. In order for TLS to work you have to correctly configure DNS for your container. |
| TLS_ENABLED | bool | `false` | |
Expand Down
2 changes: 1 addition & 1 deletion docker/tinode/config.template
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"acc_validation": {
"email": {
"add_to_tags": true,
"required": ["$EMAIL_VERIFICATION_REQUIRED"],
"required": [$EMAIL_VERIFICATION_REQUIRED],
"config": {
"smtp_server": "$SMTP_SERVER",
"smtp_port": "$SMTP_PORT",
Expand Down
2 changes: 1 addition & 1 deletion docker/tinode/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ rm -f working.config

# Enable email verification if $SMTP_SERVER is defined.
if [ ! -z "$SMTP_SERVER" ] ; then
EMAIL_VERIFICATION_REQUIRED=auth
EMAIL_VERIFICATION_REQUIRED='"auth"'
fi

# Enable TLS (httpS).
Expand Down
10 changes: 9 additions & 1 deletion server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,10 @@ func main() {
for _, req := range vconf.Required {
lvl := auth.ParseAuthLevel(req)
if lvl == auth.LevelNone {
// Skip unknown authentication level.
if req != "" {
log.Fatalf("Invalid required AuthLevel '%s' in validator '%s'", req, name)
}
// Skip empty string
continue
}
reqLevels = append(reqLevels, lvl)
Expand All @@ -302,6 +305,11 @@ func main() {
globals.authValidators[lvl] = append(globals.authValidators[lvl], name)
}

if len(reqLevels) == 0 {
// Ignore validator with empty levels.
continue
}

if val := store.GetValidator(name); val == nil {
log.Fatal("Config provided for an unknown validator '" + name + "'")
} else if err = val.Init(string(vconf.Config)); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion server/validate/email/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ func (v *validator) Init(jsonconf string) error {
return err
}

v.auth = smtp.PlainAuth("", v.SendFrom, v.SenderPassword, v.SMTPAddr)
// SendFrom could be an RFC 5322 address of the form "John Doe <jdoe@example.com>". Parse it.
if sender, err := mail.ParseAddress(v.SendFrom); err == nil {
v.auth = smtp.PlainAuth("", sender.Address, v.SenderPassword, v.SMTPAddr)
} else {
return err
}

// If a relative path is provided, try to resolve it relative to the exec file location,
// not whatever directory the user is in.
Expand Down

0 comments on commit 443b415

Please sign in to comment.