Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

source.go 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package smtp
  5. import (
  6. "code.gitea.io/gitea/models/auth"
  7. "code.gitea.io/gitea/modules/json"
  8. )
  9. // _________ __________________________
  10. // / _____/ / \__ ___/\______ \
  11. // \_____ \ / \ / \| | | ___/
  12. // / \/ Y \ | | |
  13. // /_______ /\____|__ /____| |____|
  14. // \/ \/
  15. // Source holds configuration for the SMTP login source.
  16. type Source struct {
  17. Auth string
  18. Host string
  19. Port int
  20. AllowedDomains string `xorm:"TEXT"`
  21. ForceSMTPS bool
  22. SkipVerify bool
  23. HeloHostname string
  24. DisableHelo bool
  25. SkipLocalTwoFA bool `json:",omitempty"`
  26. // reference to the authSource
  27. authSource *auth.Source
  28. }
  29. // FromDB fills up an SMTPConfig from serialized format.
  30. func (source *Source) FromDB(bs []byte) error {
  31. return json.UnmarshalHandleDoubleEncode(bs, &source)
  32. }
  33. // ToDB exports an SMTPConfig to a serialized format.
  34. func (source *Source) ToDB() ([]byte, error) {
  35. return json.Marshal(source)
  36. }
  37. // IsSkipVerify returns if SkipVerify is set
  38. func (source *Source) IsSkipVerify() bool {
  39. return source.SkipVerify
  40. }
  41. // HasTLS returns true for SMTP
  42. func (source *Source) HasTLS() bool {
  43. return true
  44. }
  45. // UseTLS returns if TLS is set
  46. func (source *Source) UseTLS() bool {
  47. return source.ForceSMTPS || source.Port == 465
  48. }
  49. // SetAuthSource sets the related AuthSource
  50. func (source *Source) SetAuthSource(authSource *auth.Source) {
  51. source.authSource = authSource
  52. }
  53. func init() {
  54. auth.RegisterTypeConfig(auth.SMTP, &Source{})
  55. }