code.gitea.io/gitea@v1.21.7/services/auth/source/smtp/source.go (about)

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