Compare commits
No commits in common. "master" and "0.5" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1 @@
|
||||||
/output/*
|
/output/*
|
||||||
/.token
|
|
||||||
|
|
30
Makefile
30
Makefile
|
@ -1,9 +1,8 @@
|
||||||
VERS_MAJOR := 0
|
VERS_MAJOR := 0
|
||||||
VERS_MINOR := 6
|
VERS_MINOR := 5
|
||||||
VERSION := $(VERS_MAJOR).$(VERS_MINOR)
|
VERSION := $(VERS_MAJOR).$(VERS_MINOR)
|
||||||
NEW_MINOR := $$(( $(VERS_MINOR) + 1 ))
|
NEW_MINOR := $$(( $(VERS_MINOR) + 1 ))
|
||||||
NEW_MAJOR := $$(( $(VERS_MAJOR) + 1 ))
|
NEW_MAJOR := $$(( $(VERS_MAJOR) + 1 ))
|
||||||
GITEA_URL := https://git.abbiamoundominio.org
|
|
||||||
|
|
||||||
output:
|
output:
|
||||||
|
|
||||||
|
@ -14,7 +13,7 @@ output/sendmail-dev: output
|
||||||
go build -o output/sendmail-dev ./...
|
go build -o output/sendmail-dev ./...
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f output/*
|
rm output/*
|
||||||
|
|
||||||
build: clean output/sendmail
|
build: clean output/sendmail
|
||||||
|
|
||||||
|
@ -35,37 +34,14 @@ bumpvers-major:
|
||||||
git commit -m "Bump version $(VERSION) -> $(NEW_MAJOR).$(VERS_MINOR)"
|
git commit -m "Bump version $(VERSION) -> $(NEW_MAJOR).$(VERS_MINOR)"
|
||||||
git tag $(NEW_MAJOR).$(VERS_MINOR)
|
git tag $(NEW_MAJOR).$(VERS_MINOR)
|
||||||
|
|
||||||
new-release:
|
|
||||||
@last_tag=$$(git tag|tail -n2|head -n1); \
|
|
||||||
diffs=$$(git log --pretty=oneline --abbrev-commit $${last_tag}..HEAD~); \
|
|
||||||
release_id=$$(curl -X POST -s \
|
|
||||||
"$(GITEA_URL)/api/v1/repos/blallo/sendmail/releases" \
|
|
||||||
-H "Authorization: token $$(cat .token)" \
|
|
||||||
-H "accept: application/json" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{\"body\": \"${diffs}\", \"draft\": false, \"name\": \"$(VERSION)\", \"prerelease\": false, \"tag_name\": \"$(VERSION)\", \"target_commitish\": \"$$(git rev-parse HEAD)\" }" \
|
|
||||||
| jq '.id'); \
|
|
||||||
curl -X POST -s \
|
|
||||||
"$(GITEA_URL)/api/v1/repos/blallo/sendmail/releases/$${release_id}/assets?name=sendmail" \
|
|
||||||
-H "Authorization: token $$(cat .token)" \
|
|
||||||
-H "accept: application/json" \
|
|
||||||
-H "Content-Type: multipart/form-data" \
|
|
||||||
-F "attachment=@output/sendmail"
|
|
||||||
|
|
||||||
release-min:
|
release-min:
|
||||||
make bumpvers-minor
|
make bumpvers-minor
|
||||||
make build
|
make build
|
||||||
make docker-build
|
make docker-build
|
||||||
git push unit
|
|
||||||
git push --tags unit
|
|
||||||
make new-release
|
|
||||||
|
|
||||||
release-maj:
|
release-maj:
|
||||||
make bumpvers-major
|
make bumpvers-major
|
||||||
make build
|
make build
|
||||||
make docker-build
|
make docker-build
|
||||||
git push unit
|
|
||||||
git push --tags unit
|
|
||||||
make new-release
|
|
||||||
|
|
||||||
PHONY: bumpvers-minor bumpvers-major release-min release-maj clean docker-build new-release
|
PHONY: bumpvers-minor bumpvers-major release-min release-maj clean docker-build
|
||||||
|
|
20
config.go
20
config.go
|
@ -3,7 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
|
|
||||||
toml "github.com/pelletier/go-toml"
|
toml "github.com/pelletier/go-toml"
|
||||||
)
|
)
|
||||||
|
@ -41,12 +40,11 @@ type Config struct {
|
||||||
Bcc []string `toml:bcc,omitempty`
|
Bcc []string `toml:bcc,omitempty`
|
||||||
Subject string `toml:subject,omitempty`
|
Subject string `toml:subject,omitempty`
|
||||||
Text string `toml:text,omitempty`
|
Text string `toml:text,omitempty`
|
||||||
Attachments []string `toml:attachments,omitempty`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) String() string {
|
func (c Config) String() string {
|
||||||
msg := fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
"From: %s\nTo: %s\nCc: %s\nBcc: %s\nSubject: %s\nText:\n%s\nServer:\n%s\n",
|
"From: %s\nTo: %s\nCc: %s\nBcc: %s\nSubject: %s\nText:\n%s\nServer:\n%s",
|
||||||
c.From,
|
c.From,
|
||||||
c.To,
|
c.To,
|
||||||
c.Cc,
|
c.Cc,
|
||||||
|
@ -55,11 +53,6 @@ func (c Config) String() string {
|
||||||
c.Text,
|
c.Text,
|
||||||
c.Server,
|
c.Server,
|
||||||
)
|
)
|
||||||
msg += "Attachments:"
|
|
||||||
for _, attachment := range c.Attachments {
|
|
||||||
msg += fmt.Sprintf(" - %s\n", attachment)
|
|
||||||
}
|
|
||||||
return msg
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig() *Config {
|
func NewConfig() *Config {
|
||||||
|
@ -125,15 +118,6 @@ func (c *Config) Validate() error {
|
||||||
msg += fmt.Sprintf("%s: pass a value either via command line (-%s) or in configuration file section (%s)\n", v.Param, v.CmdFlag, v.ConfFlag)
|
msg += fmt.Sprintf("%s: pass a value either via command line (-%s) or in configuration file section (%s)\n", v.Param, v.CmdFlag, v.ConfFlag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if len(c.Attachments) > 0 {
|
|
||||||
for _, file := range c.Attachments {
|
|
||||||
if _, err := os.Lstat(file); err != nil {
|
|
||||||
msg += fmt.Sprintf("Error with attachment: %s -> %s\n", file, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if msg != "" {
|
|
||||||
return errors.New(msg)
|
return errors.New(msg)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
4
mail.go
4
mail.go
|
@ -19,10 +19,6 @@ func formatMessage(config *Config) *mail.Message {
|
||||||
}
|
}
|
||||||
m.SetHeader("Subject", config.Subject)
|
m.SetHeader("Subject", config.Subject)
|
||||||
m.SetBody("text/plain", config.Text)
|
m.SetBody("text/plain", config.Text)
|
||||||
for _, attachment := range config.Attachments {
|
|
||||||
Debug.F("Attacching: %s", attachment)
|
|
||||||
m.Attach(attachment)
|
|
||||||
}
|
|
||||||
Debug.F("Message to deliver:\n%s", m)
|
Debug.F("Message to deliver:\n%s", m)
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
|
29
main.go
29
main.go
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
@ -13,27 +12,6 @@ import (
|
||||||
var noVersion = "dev"
|
var noVersion = "dev"
|
||||||
var version string
|
var version string
|
||||||
|
|
||||||
type attachmentList []string
|
|
||||||
|
|
||||||
func (a *attachmentList) String() string {
|
|
||||||
var str string
|
|
||||||
for _, attachment := range *a {
|
|
||||||
str += fmt.Sprintf("%s\n", attachment)
|
|
||||||
}
|
|
||||||
return str
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *attachmentList) Set(file string) error {
|
|
||||||
if _, err := os.Lstat(file); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if file == "" {
|
|
||||||
return errors.New("no file provided")
|
|
||||||
}
|
|
||||||
*a = append(*a, file)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func readFromConsole(result chan string) {
|
func readFromConsole(result chan string) {
|
||||||
var text, line string
|
var text, line string
|
||||||
var err error
|
var err error
|
||||||
|
@ -95,7 +73,6 @@ func main() {
|
||||||
var encryption, dbg, versionFlag, interactive bool
|
var encryption, dbg, versionFlag, interactive bool
|
||||||
var serverPortAux int
|
var serverPortAux int
|
||||||
var serverPort int64
|
var serverPort int64
|
||||||
var attachments attachmentList
|
|
||||||
|
|
||||||
flag.BoolVar(&versionFlag, "version", false, "Prints the version and exits")
|
flag.BoolVar(&versionFlag, "version", false, "Prints the version and exits")
|
||||||
flag.StringVar(&configPath, "conf", "", "Path to a config file (defaults to /etc/sendmail.toml)")
|
flag.StringVar(&configPath, "conf", "", "Path to a config file (defaults to /etc/sendmail.toml)")
|
||||||
|
@ -112,7 +89,6 @@ func main() {
|
||||||
flag.StringVar(&bcc, "bcc", "", "Comma-separated list of blind carbon-copy recipient(s)")
|
flag.StringVar(&bcc, "bcc", "", "Comma-separated list of blind carbon-copy recipient(s)")
|
||||||
flag.StringVar(&from, "from", "", "Sender of the mail (used as default account user to log in on the SMTP server)")
|
flag.StringVar(&from, "from", "", "Sender of the mail (used as default account user to log in on the SMTP server)")
|
||||||
flag.StringVar(&subject, "sub", "", "Subject of the mail")
|
flag.StringVar(&subject, "sub", "", "Subject of the mail")
|
||||||
flag.Var(&attachments, "attach", "Attachment to the mail (may be repeated)")
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
LogInit(dbg)
|
LogInit(dbg)
|
||||||
|
@ -160,8 +136,7 @@ parameters:
|
||||||
password: %s
|
password: %s
|
||||||
to: %s
|
to: %s
|
||||||
from: %s
|
from: %s
|
||||||
subject: %s
|
subject: %s`,
|
||||||
attachments: %s`,
|
|
||||||
configPath,
|
configPath,
|
||||||
dbg,
|
dbg,
|
||||||
serverAddress,
|
serverAddress,
|
||||||
|
@ -172,7 +147,6 @@ parameters:
|
||||||
to,
|
to,
|
||||||
from,
|
from,
|
||||||
subject,
|
subject,
|
||||||
attachments,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
config := initializeConfig(configPath, section)
|
config := initializeConfig(configPath, section)
|
||||||
|
@ -187,7 +161,6 @@ parameters:
|
||||||
config.Merge("Bcc", toList(bcc))
|
config.Merge("Bcc", toList(bcc))
|
||||||
config.Merge("Subject", subject)
|
config.Merge("Subject", subject)
|
||||||
config.Merge("Text", text)
|
config.Merge("Text", text)
|
||||||
config.Merge("Attachments", attachments)
|
|
||||||
|
|
||||||
Debug.F("---\nPre-validation config\n%s", config)
|
Debug.F("---\nPre-validation config\n%s", config)
|
||||||
err = config.Validate()
|
err = config.Validate()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user