From 13a5afb5fc39ab67d40a794eddbebd16f60985ee Mon Sep 17 00:00:00 2001 From: urosj Date: Tue, 25 Jul 2017 10:56:13 +0200 Subject: [PATCH] Initial commit. --- .gitignore | 3 ++ cmd/autoresponder.go | 73 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 .gitignore create mode 100644 cmd/autoresponder.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9e21f61 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +.*.swp +cmd/autoresponder diff --git a/cmd/autoresponder.go b/cmd/autoresponder.go new file mode 100644 index 0000000..710e225 --- /dev/null +++ b/cmd/autoresponder.go @@ -0,0 +1,73 @@ +package main + +// This is postfix autoresponder, which is rewrite of the autoresponder bash script V1.6.3, written by Charles Hamilton - musashi@nefaria.com +// +// Written by Uros Juvan 2017 + +import ( + "fmt" + "flag" + "os" +) + +const VERSION = "1.0.0001" +const DEBUG = true + +func DebugFmtPrintf(format string, v ...interface{}) { + if DEBUG { + fmt.Printf("DEBUG: " + format, v...) + } +} + +func main() { + // Parse command line arguments + recipientPtr := flag.String("r", "", "Recipient e-mail") + senderPtr := flag.String("s", "", "Sender e-mail") + saslUserPtr := flag.String("S", "", "SASL authenticated username") + clientIpPtr := flag.String("C", "", "Client IP address") + enableAutoResponsePtr := flag.String("e", "", "Enable autoresponse") + disableAutoResponsePtr := flag.String("d", "", "Disable autoresponse") + enableExAutoResponsePtr := flag.String("E", "", "Enable existing autoresponse") + deleteAutoResponsePtr := flag.String("D", "", "Delete autoresponse") + flag.Parse() + + if DEBUG { + DebugFmtPrintf(`Flags: + Recipient: %v + Sender: %v + SASL authenticated username: %v + Client IP: %v + Enable autoresponse: %v + Disable autoresponse: %v + Enable existing autoresponse: %v + Delete autoresponse: %v +`, + *recipientPtr, + *senderPtr, + *saslUserPtr, + *clientIpPtr, + *enableAutoResponsePtr, + *disableAutoResponsePtr, + *enableExAutoResponsePtr, + *deleteAutoResponsePtr) + } + + // Do some logic on command line arguments + // Mode + // There are two different modes of operation: + // mode=0 represents the actions that can not be executed from the command line + // mode=1 represents the actions that can be executed from the command line + mode := 0 + sendResponse := false + authenticated := false + if *recipientPtr != "" && *senderPtr != "" { + sendResponse = true + } + if *saslUserPtr != "" && os.Getenv("SASL_USERNAME") != "" { + authenticated = true + } + if *enableAutoResponsePtr != "" || *disableAutoResponsePtr != "" || *enableExAutoResponsePtr != "" || *deleteAutoResponsePtr != "" { + mode = 1 + } + DebugFmtPrintf("mode=%v, sendResponse=%v, authenticated=%v\n", mode, sendResponse, authenticated) +}