Move most code from the repo root into subdirectories

The intention is to keep to repo root clean while the list of packages
is slowly growing.

Additionally, a bunch of small (~30 LoC) files in the repo root is
merged into a single maddy.go file, for the same reason.

Most of the internal code is moved into the internal/ directory. Go
toolchain will make it impossible to import these packages from external
applications.

Some packages are renamed and moved into the pkg/ directory in the root.
According to https://github.com/golang-standards/project-layout this is
the de-facto standard to place "library code that's ok to use by
external applications" in.

To clearly define the purpose of top-level directories, README.md files
are added to each.
This commit is contained in:
fox.cpp 2019-12-06 01:25:29 +03:00
parent c4df3af4af
commit bf188e454f
No known key found for this signature in database
GPG key ID: E76D97CCEDE90B6C
180 changed files with 722 additions and 684 deletions

View file

@ -63,8 +63,8 @@ initialization path, so they are always initialized directly.
## Error handling
Familarize yourself with the github.com/foxcpp/maddy/exterrors package and
make sure you have the following for returned errors.
Familarize yourself with the github.com/foxcpp/maddy/internal/exterrors package
and make sure you have the following for returned errors:
- SMTP status information (smtp\_code, smtp\_enchcode, smtp\_msg fields)
- SMTP message text should contain a generic description of the error
condition without any details to prevent accidental disclosure of the
@ -101,9 +101,9 @@ bugs will not bring the whole server down.
"Check" is a module that inspects the message and flags it as spam or rejects
it altogether based on some condition.
The skeleton for the stateful check module can be found in check/skeleton.go.
Throw it into a file in `check/check_name` directory and start ~~breaking~~
extending it.
The skeleton for the stateful check module can be found in
internal/check/skeleton.go. Throw it into a file in
`internal/check/check_name` directory and start ~~breaking~~ extending it.
If you don't need any per-message state, you can use StatelessCheck wrapper.
See check/dns directory for a working example.

View file

@ -1,17 +0,0 @@
package maddy
import (
"runtime/debug"
)
var Version = "unknown (built from source tree)"
func BuildInfo() string {
if info, ok := debug.ReadBuildInfo(); ok {
if info.Main.Version == "(devel)" {
return Version
}
return info.Main.Version + " " + info.Main.Sum
}
return Version + " (GOPATH build)"
}

18
cmd/README.md Normal file
View file

@ -0,0 +1,18 @@
maddy executables
-------------------
### maddy
Main server executable.
### maddyctl
IMAP index and authentication database inspection and manipulation utility.
### maddy-pam-helper, maddy-shadow-helper
__Deprecated: Currently they are unusable due to changes made to the storage
implementation.__
Utilities compatible with the extauth module that call libpam or read
/etc/shadow on Unix systems.

View file

@ -5,7 +5,7 @@ import (
"fmt"
"os"
"github.com/foxcpp/maddy/auth/shadow"
"github.com/foxcpp/maddy/internal/auth/shadow"
)
func main() {

View file

@ -5,8 +5,8 @@ import (
"os"
"github.com/foxcpp/maddy"
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/config/parser"
"github.com/foxcpp/maddy/internal/config"
parser "github.com/foxcpp/maddy/pkg/cfgparser"
)
func findBlockInCfg(path, cfgBlock string) (root, block *config.Node, err error) {

View file

@ -1,8 +1,8 @@
package main
import (
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/storage/sql"
"github.com/foxcpp/maddy/internal/config"
"github.com/foxcpp/maddy/internal/storage/sql"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"

View file

@ -6,8 +6,8 @@ import (
"os"
"path/filepath"
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/log"
"github.com/foxcpp/maddy/internal/config"
"github.com/foxcpp/maddy/internal/log"
)
/*

View file

@ -1,43 +0,0 @@
package maddy
var (
// ConfigDirectory specifies platform-specific value
// that should be used as a location of default configuration
//
// It should not be changed and is defined as a variable
// only for purposes of modification using -X linker flag.
ConfigDirectory = "/etc/maddy"
// DefaultStateDirectory specifies platform-specific
// default for StateDirectory.
//
// Most code should use StateDirectory instead since
// it will contain the effective location of the state
// directory.
//
// It should not be changed and is defined as a variable
// only for purposes of modification using -X linker flag.
DefaultStateDirectory = "/var/lib/maddy"
// DefaultRuntimeDirectory specifies platform-specific
// default for RuntimeDirectory.
//
// Most code should use RuntimeDirectory instead since
// it will contain the effective location of the state
// directory.
//
// It should not be changed and is defined as a variable
// only for purposes of modification using -X linker flag.
DefaultRuntimeDirectory = "/run/maddy"
// DefaultLibexecDirectory specifies platform-specific
// default for LibexecDirectory.
//
// Most code should use LibexecDirectory since it will
// contain the effective location of the libexec
// directory.
//
// It should not be changed and is defined as a variable
// only for purposes of modification using -X linker flag.
DefaultLibexecDirectory = "/usr/lib/maddy"
)

3
dist/README.md vendored
View file

@ -1,4 +1,5 @@
# Distribution files for maddy
Distribution files for maddy
------------------------------
**Disclaimer:** Most of the files here are maintained in a "best-effort" way.
That is, they may break or become outdated from time to time. Caveat emptor.

24
internal/README.md Normal file
View file

@ -0,0 +1,24 @@
maddy source tree
------------------
Main maddy code base lives here. No packages are intended to be used in
third-party software hence API is not stable.
Subdirectories are organised as follows:
```
/
auxiliary libraries
endpoint/
modules - protocol listeners (e.g. SMTP server, etc)
target/
modules - final delivery targets (including outbound delivery, such as
smtp_downstream, remote)
auth/
modules - authentication providers
check/
modules - message checkers (module.Check)
modify/
modules - message modifiers (module.Modifier)
storage/
modules - local messages storage implementations (module.Storage)
```

View file

@ -4,7 +4,7 @@ import (
"strings"
"unicode/utf8"
"github.com/foxcpp/maddy/dns"
"github.com/foxcpp/maddy/internal/dns"
"golang.org/x/net/idna"
"golang.org/x/text/unicode/norm"
)

View file

@ -6,10 +6,10 @@ import (
"os"
"path/filepath"
"github.com/foxcpp/maddy/auth"
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/log"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/internal/auth"
"github.com/foxcpp/maddy/internal/config"
"github.com/foxcpp/maddy/internal/log"
"github.com/foxcpp/maddy/internal/module"
)
type ExternalAuth struct {

View file

@ -5,7 +5,7 @@ import (
"os/exec"
"strings"
"github.com/foxcpp/maddy/log"
"github.com/foxcpp/maddy/internal/log"
)
func AuthUsingHelper(l log.Logger, binaryPath, accountName, password string) bool {

View file

@ -6,10 +6,10 @@ import (
"os"
"path/filepath"
"github.com/foxcpp/maddy/auth/external"
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/log"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/internal/auth/external"
"github.com/foxcpp/maddy/internal/config"
"github.com/foxcpp/maddy/internal/log"
"github.com/foxcpp/maddy/internal/module"
)
type Auth struct {

View file

@ -8,10 +8,10 @@ import (
"os"
"path/filepath"
"github.com/foxcpp/maddy/auth/external"
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/log"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/internal/auth/external"
"github.com/foxcpp/maddy/internal/config"
"github.com/foxcpp/maddy/internal/log"
"github.com/foxcpp/maddy/internal/module"
)
type Auth struct {

View file

@ -6,9 +6,9 @@ import (
"strconv"
"strings"
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/exterrors"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/internal/config"
"github.com/foxcpp/maddy/internal/exterrors"
"github.com/foxcpp/maddy/internal/module"
)
// FailAction specifies actions that messages pipeline should take based on the

View file

@ -14,13 +14,13 @@ import (
"strings"
"github.com/emersion/go-message/textproto"
"github.com/foxcpp/maddy/buffer"
"github.com/foxcpp/maddy/check"
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/exterrors"
"github.com/foxcpp/maddy/log"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/target"
"github.com/foxcpp/maddy/internal/buffer"
"github.com/foxcpp/maddy/internal/check"
"github.com/foxcpp/maddy/internal/config"
"github.com/foxcpp/maddy/internal/exterrors"
"github.com/foxcpp/maddy/internal/log"
"github.com/foxcpp/maddy/internal/module"
"github.com/foxcpp/maddy/internal/target"
)
const modName = "command"

View file

@ -10,13 +10,13 @@ import (
"github.com/emersion/go-message/textproto"
"github.com/emersion/go-msgauth/authres"
"github.com/emersion/go-msgauth/dkim"
"github.com/foxcpp/maddy/buffer"
"github.com/foxcpp/maddy/check"
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/exterrors"
"github.com/foxcpp/maddy/log"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/target"
"github.com/foxcpp/maddy/internal/buffer"
"github.com/foxcpp/maddy/internal/check"
"github.com/foxcpp/maddy/internal/config"
"github.com/foxcpp/maddy/internal/exterrors"
"github.com/foxcpp/maddy/internal/log"
"github.com/foxcpp/maddy/internal/module"
"github.com/foxcpp/maddy/internal/target"
)
type Check struct {

View file

@ -5,11 +5,11 @@ import (
"net"
"strings"
"github.com/foxcpp/maddy/address"
"github.com/foxcpp/maddy/check"
"github.com/foxcpp/maddy/dns"
"github.com/foxcpp/maddy/exterrors"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/internal/address"
"github.com/foxcpp/maddy/internal/check"
"github.com/foxcpp/maddy/internal/dns"
"github.com/foxcpp/maddy/internal/exterrors"
"github.com/foxcpp/maddy/internal/module"
)
func requireMatchingRDNS(ctx check.StatelessCheckContext) module.CheckResult {

View file

@ -6,10 +6,10 @@ import (
"github.com/emersion/go-smtp"
"github.com/foxcpp/go-mockdns"
"github.com/foxcpp/maddy/check"
"github.com/foxcpp/maddy/future"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/testutils"
"github.com/foxcpp/maddy/internal/check"
"github.com/foxcpp/maddy/internal/future"
"github.com/foxcpp/maddy/internal/module"
"github.com/foxcpp/maddy/internal/testutils"
)
func TestRequireMatchingRDNS(t *testing.T) {

View file

@ -6,8 +6,8 @@ import (
"strconv"
"strings"
"github.com/foxcpp/maddy/dns"
"github.com/foxcpp/maddy/exterrors"
"github.com/foxcpp/maddy/internal/dns"
"github.com/foxcpp/maddy/internal/exterrors"
)
type ListedErr struct {

View file

@ -7,15 +7,15 @@ import (
"github.com/emersion/go-message/textproto"
"github.com/emersion/go-smtp"
"github.com/foxcpp/maddy/address"
"github.com/foxcpp/maddy/buffer"
"github.com/foxcpp/maddy/check"
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/dns"
"github.com/foxcpp/maddy/exterrors"
"github.com/foxcpp/maddy/log"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/target"
"github.com/foxcpp/maddy/internal/address"
"github.com/foxcpp/maddy/internal/buffer"
"github.com/foxcpp/maddy/internal/check"
"github.com/foxcpp/maddy/internal/config"
"github.com/foxcpp/maddy/internal/dns"
"github.com/foxcpp/maddy/internal/exterrors"
"github.com/foxcpp/maddy/internal/log"
"github.com/foxcpp/maddy/internal/module"
"github.com/foxcpp/maddy/internal/target"
"golang.org/x/sync/errgroup"
)

View file

@ -6,7 +6,7 @@ import (
"testing"
"github.com/foxcpp/go-mockdns"
"github.com/foxcpp/maddy/testutils"
"github.com/foxcpp/maddy/internal/testutils"
)
func TestCheckList(t *testing.T) {

View file

@ -9,11 +9,11 @@ package directory_name_here
import (
"github.com/emersion/go-message/textproto"
"github.com/foxcpp/maddy/buffer"
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/log"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/target"
"github.com/foxcpp/maddy/internal/buffer"
"github.com/foxcpp/maddy/internal/config"
"github.com/foxcpp/maddy/internal/log"
"github.com/foxcpp/maddy/internal/module"
"github.com/foxcpp/maddy/internal/target"
)
const modName = "check_things"

View file

@ -11,16 +11,16 @@ import (
"github.com/emersion/go-message/textproto"
"github.com/emersion/go-msgauth/authres"
"github.com/emersion/go-msgauth/dmarc"
"github.com/foxcpp/maddy/address"
"github.com/foxcpp/maddy/buffer"
"github.com/foxcpp/maddy/check"
maddydmarc "github.com/foxcpp/maddy/check/dmarc"
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/dns"
"github.com/foxcpp/maddy/exterrors"
"github.com/foxcpp/maddy/log"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/target"
"github.com/foxcpp/maddy/internal/address"
"github.com/foxcpp/maddy/internal/buffer"
"github.com/foxcpp/maddy/internal/check"
"github.com/foxcpp/maddy/internal/config"
maddydmarc "github.com/foxcpp/maddy/internal/dmarc"
"github.com/foxcpp/maddy/internal/dns"
"github.com/foxcpp/maddy/internal/exterrors"
"github.com/foxcpp/maddy/internal/log"
"github.com/foxcpp/maddy/internal/module"
"github.com/foxcpp/maddy/internal/target"
"golang.org/x/net/idna"
)

View file

@ -5,12 +5,12 @@ import (
"net"
"github.com/emersion/go-message/textproto"
"github.com/foxcpp/maddy/buffer"
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/dns"
"github.com/foxcpp/maddy/log"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/target"
"github.com/foxcpp/maddy/internal/buffer"
"github.com/foxcpp/maddy/internal/config"
"github.com/foxcpp/maddy/internal/dns"
"github.com/foxcpp/maddy/internal/log"
"github.com/foxcpp/maddy/internal/module"
"github.com/foxcpp/maddy/internal/target"
)
type (

View file

@ -3,7 +3,7 @@ package config
import (
"fmt"
"github.com/foxcpp/maddy/config/parser"
parser "github.com/foxcpp/maddy/pkg/cfgparser"
)
type (

View file

@ -4,7 +4,7 @@ import (
"strconv"
"time"
"github.com/foxcpp/maddy/limiters"
"github.com/foxcpp/maddy/internal/limiters"
)
// GlobalRateLimit reads '... <burst> <interval>' config directive and returns

View file

@ -9,7 +9,7 @@ import (
"time"
"unicode"
"github.com/foxcpp/maddy/config/parser"
parser "github.com/foxcpp/maddy/pkg/cfgparser"
)
type matcher struct {

View file

@ -1,8 +1,8 @@
package modconfig
import (
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/internal/config"
"github.com/foxcpp/maddy/internal/module"
)
func AuthDirective(m *config.Map, node *config.Node) (interface{}, error) {

View file

@ -1,8 +1,8 @@
package modconfig
import (
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/internal/config"
"github.com/foxcpp/maddy/internal/module"
)
func MessageCheck(globals map[string]interface{}, args []string, block *config.Node) (module.Check, error) {

View file

@ -1,8 +1,8 @@
package modconfig
import (
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/internal/config"
"github.com/foxcpp/maddy/internal/module"
)
// deliveryDirective is a callback for use in config.Map.Custom.

View file

@ -13,10 +13,10 @@ import (
"reflect"
"strings"
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/config/parser"
"github.com/foxcpp/maddy/log"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/internal/config"
"github.com/foxcpp/maddy/internal/log"
"github.com/foxcpp/maddy/internal/module"
parser "github.com/foxcpp/maddy/pkg/cfgparser"
)
// createInlineModule is a helper function for config matchers that can create inline modules.

View file

@ -1,8 +1,8 @@
package modconfig
import (
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/internal/config"
"github.com/foxcpp/maddy/internal/module"
)
func MsgModifier(globals map[string]interface{}, args []string, block *config.Node) (module.Modifier, error) {

View file

@ -1,8 +1,8 @@
package modconfig
import (
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/internal/config"
"github.com/foxcpp/maddy/internal/module"
)
func StorageDirective(m *config.Map, node *config.Node) (interface{}, error) {

View file

@ -6,7 +6,7 @@ import (
"fmt"
"io/ioutil"
"github.com/foxcpp/maddy/log"
"github.com/foxcpp/maddy/internal/log"
)
func TLSClientBlock(m *Map, node *Node) (interface{}, error) {

View file

@ -3,7 +3,7 @@ package config
import (
"crypto/tls"
"github.com/foxcpp/maddy/log"
"github.com/foxcpp/maddy/internal/log"
)
var strVersionsMap = map[string]uint16{

View file

@ -12,7 +12,7 @@ import (
"os"
"time"
"github.com/foxcpp/maddy/log"
"github.com/foxcpp/maddy/internal/log"
)
func TLSDirective(m *Map, node *Node) (interface{}, error) {

View file

@ -11,7 +11,7 @@ import (
"github.com/emersion/go-message/textproto"
"github.com/emersion/go-msgauth/authres"
"github.com/emersion/go-msgauth/dmarc"
"github.com/foxcpp/maddy/address"
"github.com/foxcpp/maddy/internal/address"
"golang.org/x/net/publicsuffix"
)

View file

@ -12,8 +12,8 @@ import (
"github.com/emersion/go-message/textproto"
"github.com/emersion/go-smtp"
"github.com/foxcpp/maddy/address"
"github.com/foxcpp/maddy/dns"
"github.com/foxcpp/maddy/internal/address"
"github.com/foxcpp/maddy/internal/dns"
)
type ReportingMTAInfo struct {

View file

@ -20,10 +20,10 @@ import (
"github.com/emersion/go-message"
_ "github.com/emersion/go-message/charset"
"github.com/foxcpp/go-imap-sql/children"
"github.com/foxcpp/maddy/config"
modconfig "github.com/foxcpp/maddy/config/module"
"github.com/foxcpp/maddy/log"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/internal/config"
modconfig "github.com/foxcpp/maddy/internal/config/module"
"github.com/foxcpp/maddy/internal/log"
"github.com/foxcpp/maddy/internal/module"
)
type Endpoint struct {

View file

@ -16,18 +16,18 @@ import (
"github.com/emersion/go-message/textproto"
"github.com/emersion/go-smtp"
"github.com/foxcpp/maddy/address"
"github.com/foxcpp/maddy/buffer"
"github.com/foxcpp/maddy/config"
modconfig "github.com/foxcpp/maddy/config/module"
"github.com/foxcpp/maddy/dns"
"github.com/foxcpp/maddy/exterrors"
"github.com/foxcpp/maddy/future"
"github.com/foxcpp/maddy/limiters"
"github.com/foxcpp/maddy/log"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/msgpipeline"
"github.com/foxcpp/maddy/target"
"github.com/foxcpp/maddy/internal/address"
"github.com/foxcpp/maddy/internal/buffer"
"github.com/foxcpp/maddy/internal/config"
modconfig "github.com/foxcpp/maddy/internal/config/module"
"github.com/foxcpp/maddy/internal/dns"
"github.com/foxcpp/maddy/internal/exterrors"
"github.com/foxcpp/maddy/internal/future"
"github.com/foxcpp/maddy/internal/limiters"
"github.com/foxcpp/maddy/internal/log"
"github.com/foxcpp/maddy/internal/module"
"github.com/foxcpp/maddy/internal/msgpipeline"
"github.com/foxcpp/maddy/internal/target"
"golang.org/x/net/idna"
)

View file

@ -13,11 +13,11 @@ import (
"github.com/emersion/go-sasl"
"github.com/emersion/go-smtp"
"github.com/foxcpp/go-mockdns"
"github.com/foxcpp/maddy/config"
"github.com/foxcpp/maddy/exterrors"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/msgpipeline"
"github.com/foxcpp/maddy/testutils"
"github.com/foxcpp/maddy/internal/config"
"github.com/foxcpp/maddy/internal/exterrors"
"github.com/foxcpp/maddy/internal/module"
"github.com/foxcpp/maddy/internal/msgpipeline"
"github.com/foxcpp/maddy/internal/testutils"
)
var testPort string

View file

@ -6,9 +6,9 @@ import (
"github.com/emersion/go-smtp"
"github.com/foxcpp/go-mockdns"
"github.com/foxcpp/maddy/exterrors"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/testutils"
"github.com/foxcpp/maddy/internal/exterrors"
"github.com/foxcpp/maddy/internal/module"
"github.com/foxcpp/maddy/internal/testutils"
)
func TestSMTPUTF8_MangleStatusMessage(t *testing.T) {

View file

@ -7,8 +7,8 @@ import (
"time"
"github.com/emersion/go-message/textproto"
"github.com/foxcpp/maddy/exterrors"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/internal/exterrors"
"github.com/foxcpp/maddy/internal/module"
"github.com/google/uuid"
)

View file

@ -7,7 +7,7 @@ import (
"github.com/emersion/go-message/textproto"
"github.com/emersion/go-smtp"
"github.com/foxcpp/maddy/module"
"github.com/foxcpp/maddy/internal/module"
)
func init() {

View file

@ -9,7 +9,7 @@ import (
"strings"
"time"
"github.com/foxcpp/maddy/exterrors"
"github.com/foxcpp/maddy/internal/exterrors"
)
// Logger is the structure that writes formatted output to the underlying

Some files were not shown because too many files have changed in this diff Show more