From 70460873acc3e28fbe0b9ff8e260e3dd74f5f343 Mon Sep 17 00:00:00 2001 From: Adora Laura Kalb Date: Wed, 24 Jul 2024 17:36:44 +0200 Subject: [PATCH] unfinished main.go --- cmd/mailcow-admin-aliases/main.go | 64 +++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 cmd/mailcow-admin-aliases/main.go diff --git a/cmd/mailcow-admin-aliases/main.go b/cmd/mailcow-admin-aliases/main.go new file mode 100644 index 0000000..abd8662 --- /dev/null +++ b/cmd/mailcow-admin-aliases/main.go @@ -0,0 +1,64 @@ +/* +Copyright © 2024 Laura Kalb +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 { + + } + } + +}