diff --git a/domain/mail/document.go b/domain/mail/document.go index aa283190..b4ed677a 100644 --- a/domain/mail/document.go +++ b/domain/mail/document.go @@ -36,6 +36,10 @@ func (m *Mailer) DocumentApprover(recipient, inviterName, inviterEmail, url, doc em.ReplyTo = inviterEmail em.ReplyName = inviterName + if IsBlockedEmailDomain(em.ToEmail) { + return + } + parameters := struct { Subject string Inviter string diff --git a/domain/mail/mail_test.go b/domain/mail/mail_test.go new file mode 100644 index 00000000..50858fb7 --- /dev/null +++ b/domain/mail/mail_test.go @@ -0,0 +1,28 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + +package mail + +import ( + "testing" +) + +func TestSpamDomains(t *testing.T) { + g1 := "good@example.org" + b1 := "bad@qq.com" + + if IsBlockedEmailDomain(g1) { + t.Errorf("%s should not be blocked email domain", g1) + } + if !IsBlockedEmailDomain(b1) { + t.Errorf("%s should be blocked email domain", b1) + } +} diff --git a/domain/mail/mailer.go b/domain/mail/mailer.go index f26bd141..61cd31b0 100644 --- a/domain/mail/mailer.go +++ b/domain/mail/mailer.go @@ -39,12 +39,6 @@ func (m *Mailer) Initialize() { m.Dialer, _ = ds.Connect(m.Config) } -// Send prepares and sends email. -func (m *Mailer) Send(em ds.EmailMessage) (ok bool, err error) { - ok, err = ds.SendMessage(m.Dialer, m.Config, em) - return -} - // ParseTemplate produces email template. func (m *Mailer) ParseTemplate(filename string, params interface{}) (html string, err error) { html = "" diff --git a/domain/mail/space.go b/domain/mail/space.go index 87692339..99e04ef6 100644 --- a/domain/mail/space.go +++ b/domain/mail/space.go @@ -34,6 +34,10 @@ func (m *Mailer) ShareSpaceExistingUser(recipient, inviterName, inviterEmail, ur em.ReplyTo = inviterEmail em.ReplyName = inviterName + if IsBlockedEmailDomain(em.ToEmail) { + return + } + parameters := struct { Subject string Inviter string @@ -62,7 +66,7 @@ func (m *Mailer) ShareSpaceExistingUser(recipient, inviterName, inviterEmail, ur m.Runtime.Log.Error(fmt.Sprintf("%s - unable to send email", method), err) } if !ok { - m.Runtime.Log.Info(fmt.Sprintf("%s unable to send email")) + m.Runtime.Log.Info(fmt.Sprintf("%s unable to send email", method)) } } @@ -83,6 +87,10 @@ func (m *Mailer) ShareSpaceNewUser(recipient, inviterName, inviterEmail, url, sp em.ReplyTo = inviterEmail em.ReplyName = inviterName + if IsBlockedEmailDomain(em.ToEmail) { + return + } + parameters := struct { Subject string Inviter string @@ -111,6 +119,6 @@ func (m *Mailer) ShareSpaceNewUser(recipient, inviterName, inviterEmail, url, sp m.Runtime.Log.Error(fmt.Sprintf("%s - unable to send email", method), err) } if !ok { - m.Runtime.Log.Info(fmt.Sprintf("%s unable to send email")) + m.Runtime.Log.Info(fmt.Sprintf("%s unable to send email", method)) } } diff --git a/domain/mail/spam.go b/domain/mail/spam.go new file mode 100644 index 00000000..e96ee82e --- /dev/null +++ b/domain/mail/spam.go @@ -0,0 +1,26 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + +package mail + +import ( + "strings" +) + +// IsBlockedEmailDomain checks to see if email domain +// is on spam/blacklisted email domain. +func IsBlockedEmailDomain(to string) bool { + if strings.HasSuffix(to, "@qq.com") { + return true + } + + return false +} diff --git a/domain/mail/user.go b/domain/mail/user.go index da63ce97..708c3507 100644 --- a/domain/mail/user.go +++ b/domain/mail/user.go @@ -34,6 +34,10 @@ func (m *Mailer) InviteNewUser(recipient, inviterName, inviterEmail, url, userna em.ReplyTo = inviterEmail em.ReplyName = inviterName + if IsBlockedEmailDomain(em.ToEmail) { + return + } + parameters := struct { Subject string Inviter string @@ -83,6 +87,10 @@ func (m *Mailer) InviteExistingUser(recipient, inviterName, inviterEmail, url st em.ReplyTo = inviterEmail em.ReplyName = inviterName + if IsBlockedEmailDomain(em.ToEmail) { + return + } + parameters := struct { Subject string Inviter string @@ -107,7 +115,7 @@ func (m *Mailer) InviteExistingUser(recipient, inviterName, inviterEmail, url st m.Runtime.Log.Error(fmt.Sprintf("%s - unable to send email", method), err) } if !ok { - m.Runtime.Log.Info(fmt.Sprintf("%s unable to send email")) + m.Runtime.Log.Info(fmt.Sprintf("%s unable to send email", method)) } } @@ -121,6 +129,10 @@ func (m *Mailer) PasswordReset(recipient, url string) { em.ToEmail = recipient em.ToName = recipient + if IsBlockedEmailDomain(em.ToEmail) { + return + } + parameters := struct { Subject string URL string @@ -143,6 +155,6 @@ func (m *Mailer) PasswordReset(recipient, url string) { m.Runtime.Log.Error(fmt.Sprintf("%s - unable to send email", method), err) } if !ok { - m.Runtime.Log.Info(fmt.Sprintf("%s unable to send email")) + m.Runtime.Log.Info(fmt.Sprintf("%s unable to send email", method)) } } diff --git a/domain/space/endpoint.go b/domain/space/endpoint.go index 9bf16296..35b4eced 100644 --- a/domain/space/endpoint.go +++ b/domain/space/endpoint.go @@ -935,6 +935,12 @@ func (h *Handler) Invite(w http.ResponseWriter, r *http.Request) { return } + // Spam checks. + if mail.IsBlockedEmailDomain(email) { + response.WriteForbiddenError(w) + return + } + if len(u.RefID) > 0 { // Ensure they have access to this organization accounts, err2 := h.Store.Account.GetUserAccounts(ctx, u.RefID) diff --git a/domain/user/endpoint.go b/domain/user/endpoint.go index 6a471b66..a93f6b4a 100644 --- a/domain/user/endpoint.go +++ b/domain/user/endpoint.go @@ -85,17 +85,21 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) { response.WriteMissingDataError(w, method, "email") return } - if len(userModel.Firstname) == 0 { response.WriteMissingDataError(w, method, "firsrtname") return } - if len(userModel.Lastname) == 0 { response.WriteMissingDataError(w, method, "lastname") return } + // Spam checks. + if mail.IsBlockedEmailDomain(userModel.Email) { + response.WriteForbiddenError(w) + return + } + userModel.Initials = stringutil.MakeInitials(userModel.Firstname, userModel.Lastname) requestedPassword := secrets.GenerateRandomPassword() userModel.Salt = secrets.GenerateSalt() @@ -808,6 +812,13 @@ func (h *Handler) BulkImport(w http.ResponseWriter, r *http.Request) { userID = uniqueid.Generate() userModel.RefID = userID + // Spam checks. + if mail.IsBlockedEmailDomain(userModel.Email) { + ctx.Transaction.Rollback() + response.WriteForbiddenError(w) + return + } + err = h.Store.User.Add(ctx, userModel) if err != nil { ctx.Transaction.Rollback()