small pixel drawing of a pufferfish clist

Make new build script, remove logger
2 chainz 2chainz@example.com
Wed, 05 May 2021 16:44:47 +0000
commit

e232747304c3f9a43ec9022209b929e526a853a5

parent

0f77fc498e0b17e09eaee3ea076a6e381a31e633

5 files changed, 42 insertions(+), 81 deletions(-)

jump to
M .gitignore.gitignore

@@ -1,2 +1,3 @@

+bin clist vendor
D Makefile

@@ -1,25 +0,0 @@

-# clist - simple mailing list -.POSIX: - -include config.mk - -all: options clean clist - -options: - @echo clist build options: - @echo "VERSION = $(VERSION)" - @echo "PREFIX = $(PREFIX)" - -clean: - rm -f clist - -clist: - go build -o clist -v - -install: clist - mkdir -p $(DESTDIR)$(PREFIX)/bin - cp -f clist $(DESTDIR)$(PREFIX)/bin - chmod 755 $(DESTDIR)$(PREFIX)/bin/clist - -uninstall: - rm -f $(DESTDIR)$(PREFIX)/bin/clist
A build.sh

@@ -0,0 +1,17 @@

+#!/bin/sh + + +echo "Cleaning.." +rm -f ./bin/assembler +rm -f ./bin/emulator +rm -f ./bin/debugger +rm -f ./bin/boot.rom + +echo "Building.." +mkdir -p bin +go build -o bin/clist + +echo "Running.." +./bin/clist + +echo "Done."
D config.mk

@@ -1,6 +0,0 @@

-# clist version -VERSION = 0.1.0 - -# paths -PREFIX ?= /usr/local -MANPREFIX = $(PREFIX)/share/man
M main.gomain.go

@@ -6,8 +6,6 @@ "bytes"

"database/sql" "flag" "fmt" - "io" - "log" "net/mail" "net/smtp" "os"

@@ -62,15 +60,13 @@ fmt.Printf("Error: Command not specified\n")

os.Exit(1) } - requireLog() - if flag.Arg(0) == "message" { msg, err := parsemail.Parse(bufio.NewReader(os.Stdin)) if err != nil { - log.Printf("ERROR_PARSING_MESSAGE mail=%v msg=%q error=%q\n", os.Stdin, msg, err.Error()) + fmt.Printf("ERROR_PARSING_MESSAGE mail=%v msg=%q error=%q\n", os.Stdin, msg, err.Error()) os.Exit(0) } - log.Printf("MESSAGE_RECEIVED From=%q To=%q Cc=%q Bcc=%q Subject=%q\n", + fmt.Printf("MESSAGE_RECEIVED From=%q To=%q Cc=%q Bcc=%q Subject=%q\n", msg.From, msg.To, msg.Cc, msg.Bcc, msg.Subject) handleMessage(&msg) } else {

@@ -97,7 +93,7 @@ for _, l := range gConfig.Lists {

agg := append(msg.To, msg.Cc...) if checkAddress(agg, l.Address) { matchedLists = append(matchedLists, l) - log.Printf("matched list: %q", l.Address) + fmt.Printf("matched list: %q", l.Address) } }

@@ -106,13 +102,13 @@ list := matchedLists[0]

if list.CanPost(msg.From[0]) { msg := buildListEmail(msg, list) send(msg) - log.Printf("MESSAGE_SENT ListId=%q", + fmt.Printf("MESSAGE_SENT ListId=%q", list.Id) } else { handleNotAuthorisedToPost(msg) } } else { - log.Printf("LISTS: %q", msg) + fmt.Printf("LISTS: %q", msg) handleNoDestination(msg) } }

@@ -166,7 +162,7 @@ var body bytes.Buffer

fmt.Fprintf(&body, "No mailing lists addressed. Your message has not been delivered.\r\n") reply := buildCommandEmail(msg, body) send(reply) - log.Printf("UNKNOWN_DESTINATION From=%q To=%q Cc=%q Bcc=%q", msg.From, msg.To, msg.Cc, msg.Bcc) + fmt.Printf("UNKNOWN_DESTINATION From=%q To=%q Cc=%q Bcc=%q", msg.From, msg.To, msg.Cc, msg.Bcc) } // Reply that the user isn't authorised to post to the list

@@ -175,7 +171,7 @@ var body bytes.Buffer

fmt.Fprintf(&body, "You are not an approved poster for this mailing list. Your message has not been delivered.\r\n") reply := buildCommandEmail(msg, body) send(reply) - log.Printf("UNAUTHORISED_POST From=%q To=%q Cc=%q Bcc=%q", msg.From, msg.To, msg.Cc, msg.Bcc) + fmt.Printf("UNAUTHORISED_POST From=%q To=%q Cc=%q Bcc=%q", msg.From, msg.To, msg.Cc, msg.Bcc) } // Reply to an unknown command, giving some help

@@ -188,7 +184,7 @@ commandInfo(),

msg.Subject) reply := buildCommandEmail(msg, body) send(reply) - log.Printf("UNKNOWN_COMMAND From=%q", msg.From) + fmt.Printf("UNKNOWN_COMMAND From=%q", msg.From) } // Reply to a help command with help information

@@ -197,7 +193,7 @@ var body bytes.Buffer

fmt.Fprintf(&body, commandInfo()) reply := buildCommandEmail(msg, body) send(reply) - log.Printf("HELP_SENT To=%q", reply.To) + fmt.Printf("HELP_SENT To=%q", reply.To) } // Reply to a show mailing lists command with a list of mailing lists

@@ -220,7 +216,7 @@ gConfig.CommandAddress)

email := buildCommandEmail(msg, body) send(email) - log.Printf("LIST_SENT To=%q", msg.From) + fmt.Printf("LIST_SENT To=%q", msg.From) } // Handle a subscribe command

@@ -237,7 +233,7 @@

var body bytes.Buffer if isSubscribed(msg.From[0], listId) { fmt.Fprintf(&body, "You are already subscribed to %s\r\n", listId) - log.Printf("DUPLICATE_SUBSCRIPTION_REQUEST User=%q List=%q\n", msg.From, listId) + fmt.Printf("DUPLICATE_SUBSCRIPTION_REQUEST User=%q List=%q\n", msg.From, listId) } else { addSubscription(msg.From[0], listId) fmt.Fprintf(&body, "You are now subscribed to %s\r\n", listId)

@@ -261,7 +257,7 @@

var body bytes.Buffer if !isSubscribed(msg.From[0], listId) { fmt.Fprintf(&body, "You aren't subscribed to %s\r\n", listId) - log.Printf("DUPLICATE_UNSUBSCRIPTION_REQUEST User=%q List=%q\n", msg.From, listId) + fmt.Printf("DUPLICATE_UNSUBSCRIPTION_REQUEST User=%q List=%q\n", msg.From, listId) } else { removeSubscription(msg.From[0], listId) fmt.Fprintf(&body, "You are now unsubscribed from %s\r\n", listId)

@@ -275,7 +271,7 @@ var body bytes.Buffer

fmt.Fprintf(&body, "Unable to operate against %s, Invalid mailing list ID.\r\n", listId) reply := buildCommandEmail(msg, body) send(reply) - log.Printf("INVALID_MAILING_LIST From=%q To=%q Cc=%q Bcc=%q", msg.From, msg.To, msg.Cc, msg.Bcc) + fmt.Printf("INVALID_MAILING_LIST From=%q To=%q Cc=%q Bcc=%q", msg.From, msg.To, msg.Cc, msg.Bcc) } func badAddress(recipient string, e *parsemail.Email) bool {

@@ -358,7 +354,7 @@

auth := smtp.PlainAuth("", gConfig.SMTPUsername, gConfig.SMTPPassword, gConfig.SMTPHostname) err := smtp.SendMail(gConfig.SMTPHostname+":"+gConfig.SMTPPort, auth, e.Header.Get("Sender"), recipients, e.ToBytes()) if err != nil { - log.Printf("ERROR_SENDING_MAIL: Error=%q\n", err.Error()) + fmt.Printf("ERROR_SENDING_MAIL: Error=%q\n", err.Error()) } }

@@ -409,7 +405,7 @@ // Open the database or fail immediately

func requireDB() *sql.DB { db, err := openDB() if err != nil { - log.Printf("DATABASE_ERROR Error=%q\n", err.Error()) + fmt.Printf("DATABASE_ERROR Error=%q\n", err.Error()) os.Exit(1) } return db

@@ -421,7 +417,7 @@ db := requireDB()

rows, err := db.Query("SELECT user FROM subscriptions WHERE list=?", listId) if err != nil { - log.Printf("DATABASE_ERROR Error=%q\n", err.Error()) + fmt.Printf("DATABASE_ERROR Error=%q\n", err.Error()) os.Exit(0) }

@@ -446,7 +442,7 @@

if err == sql.ErrNoRows { return false } else if err != nil { - log.Printf("DATABASE_ERROR Error=%q\n", err.Error()) + fmt.Printf("DATABASE_ERROR Error=%q\n", err.Error()) os.Exit(0) }

@@ -458,10 +454,10 @@ func addSubscription(address *mail.Address, list string) {

db := requireDB() _, err := db.Exec("INSERT INTO subscriptions (user,list) VALUES(?,?)", address.Address, list) if err != nil { - log.Printf("DATABASE_ERROR Error=%q\n", err.Error()) + fmt.Printf("DATABASE_ERROR Error=%q\n", err.Error()) os.Exit(0) } - log.Printf("SUBSCRIPTION_ADDED Sender=%q List=%q\n", address, list) + fmt.Printf("SUBSCRIPTION_ADDED Sender=%q List=%q\n", address, list) } // Remove a subscription from the subscription database

@@ -469,32 +465,10 @@ func removeSubscription(address *mail.Address, list string) {

db := requireDB() _, err := db.Exec("DELETE FROM subscriptions WHERE user=? AND list=?", address.Address, list) if err != nil { - log.Printf("DATABASE_ERROR Error=%q\n", err.Error()) + fmt.Printf("DATABASE_ERROR Error=%q\n", err.Error()) os.Exit(0) } - log.Printf("SUBSCRIPTION_REMOVED Sender=%q List=%q\n", address, list) -} - -// HELPER FUNCTIONS /////////////////////////////////////////////////////////// - -// Open the log file for logging -func openLog() error { - logFile, err := os.OpenFile(gConfig.Log, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644) - if err != nil { - return err - } - out := io.MultiWriter(logFile, os.Stderr) - log.SetOutput(out) - return nil -} - -// Open the log, or fail immediately -func requireLog() { - err := openLog() - if err != nil { - log.Printf("LOG_ERROR Error=%q\n", err.Error()) - os.Exit(0) - } + fmt.Printf("SUBSCRIPTION_REMOVED Sender=%q List=%q\n", address, list) } // Load gConfig from the on-disk config file

@@ -511,13 +485,13 @@ cfg, err = ini.LooseLoad("clist.ini", "/etc/clist.ini")

} if err != nil { - log.Printf("CONFIG_ERROR Error=%q\n", err.Error()) + fmt.Printf("CONFIG_ERROR Error=%q\n", err.Error()) os.Exit(0) } err = cfg.Section("").MapTo(gConfig) if err != nil { - log.Printf("CONFIG_ERROR Error=%q\n", err.Error()) + fmt.Printf("CONFIG_ERROR Error=%q\n", err.Error()) os.Exit(0) }

@@ -527,7 +501,7 @@ for _, section := range cfg.ChildSections("list") {

list := &List{} err = section.MapTo(list) if err != nil { - log.Printf("CONFIG_ERROR Error=%q\n", err.Error()) + fmt.Printf("CONFIG_ERROR Error=%q\n", err.Error()) os.Exit(0) } list.Id = strings.TrimPrefix(section.Name(), "list.")