unfinished main.go
This commit is contained in:
parent
710b99d02d
commit
70460873ac
1 changed files with 64 additions and 0 deletions
64
cmd/mailcow-admin-aliases/main.go
Normal file
64
cmd/mailcow-admin-aliases/main.go
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
Copyright © 2024 Laura Kalb <dev@lauka.net>
|
||||
The code of this project is available under the MIT license. See the LICENSE file for more info.
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"code.lila.network/adoralaura/mailcow-admin-aliases/internal/configuration"
|
||||
"code.lila.network/adoralaura/mailcow-admin-aliases/internal/logging"
|
||||
"code.lila.network/adoralaura/mailcow-admin-aliases/internal/mailcow"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
func main() {
|
||||
quiet := pflag.BoolP("quiet", "q", false, "Disable logging")
|
||||
verbose := pflag.Bool("debug", false, "Enable debug logging (beats --quiet)")
|
||||
pflag.BoolVarP(&configuration.DryRun, "dry-run", "d", false, "Show what this application *would* do")
|
||||
pflag.StringVarP(&configuration.ConfigFile, "config", "c", "", "Path to config file (default: $WorkDir/config.yaml)")
|
||||
|
||||
pflag.Parse()
|
||||
logging.NewSlogLogger(*quiet, *verbose)
|
||||
|
||||
var cfg configuration.Config
|
||||
err := cfg.LoadFromDisk()
|
||||
if err != nil {
|
||||
log.Fatalf("failed to load config: %v", err.Error())
|
||||
}
|
||||
|
||||
var wantedAliases []string
|
||||
|
||||
domains, err := mailcow.LoadDomains(cfg)
|
||||
if err != nil {
|
||||
slog.Error("failed to get domains", "error", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for _, domain := range domains {
|
||||
for _, prefix := range cfg.MailPrefixes {
|
||||
address := prefix + "@" + domain.DomainName
|
||||
if address != cfg.AdminEmail {
|
||||
wantedAliases = append(wantedAliases, address)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
aliases, err := mailcow.LoadAliases(cfg)
|
||||
if err != nil {
|
||||
slog.Error("failed to get aliases", "error", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
slog.Info(fmt.Sprintf("Found %v domains, %v aliases.", len(domains), len(aliases)))
|
||||
|
||||
for _, alias := range aliases {
|
||||
for _, wantedPrefix := range cfg.MailPrefixes {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue