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 { + + } + } + +}