gitea源码

source.go 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package smtp
  4. import (
  5. "code.gitea.io/gitea/models/auth"
  6. "code.gitea.io/gitea/modules/json"
  7. )
  8. // _________ __________________________
  9. // / _____/ / \__ ___/\______ \
  10. // \_____ \ / \ / \| | | ___/
  11. // / \/ Y \ | | |
  12. // /_______ /\____|__ /____| |____|
  13. // \/ \/
  14. // Source holds configuration for the SMTP login source.
  15. type Source struct {
  16. auth.ConfigBase `json:"-"`
  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. }
  26. // FromDB fills up an SMTPConfig from serialized format.
  27. func (source *Source) FromDB(bs []byte) error {
  28. return json.UnmarshalHandleDoubleEncode(bs, &source)
  29. }
  30. // ToDB exports an SMTPConfig to a serialized format.
  31. func (source *Source) ToDB() ([]byte, error) {
  32. return json.Marshal(source)
  33. }
  34. // IsSkipVerify returns if SkipVerify is set
  35. func (source *Source) IsSkipVerify() bool {
  36. return source.SkipVerify
  37. }
  38. // HasTLS returns true for SMTP
  39. func (source *Source) HasTLS() bool {
  40. return true
  41. }
  42. // UseTLS returns if TLS is set
  43. func (source *Source) UseTLS() bool {
  44. return source.ForceSMTPS || source.Port == 465
  45. }
  46. func init() {
  47. auth.RegisterTypeConfig(auth.SMTP, &Source{})
  48. }