minor cleanup

Signed-off-by: Michael <michael.lindman@gmail.com>
This commit is contained in:
Michael 2021-11-17 23:12:19 +00:00
parent 172b18f962
commit 629ece947e
4 changed files with 32 additions and 7 deletions

28
Makefile Normal file
View File

@ -0,0 +1,28 @@
APP=gomail
PREFIX=/usr/local
run: build
./$(APP)
doc:
godoc -http=:6090 -index
build:
go build
install:
install -m755 -- $(APP) $(PREFIX)/bin/
debs:
go get ./...
update-debs:
go get -u ./...
fmt:
gofmt -l -s .
clean:
go clean
.PHONY: run doc build install debs update-debs fmt clean

2
go.mod
View File

@ -3,8 +3,6 @@ module git.0cd.xyz/michael/gomail
go 1.16 go 1.16
require ( require (
git.0cd.xyz/michael/gtools v0.1.5
github.com/emersion/go-imap v1.1.0 github.com/emersion/go-imap v1.1.0
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
) )

View File

@ -2,12 +2,13 @@ package mail
import ( import (
"errors" "errors"
"fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"os"
"strconv" "strconv"
"time" "time"
"git.0cd.xyz/michael/gtools/colour"
"github.com/emersion/go-imap" "github.com/emersion/go-imap"
"github.com/emersion/go-imap/client" "github.com/emersion/go-imap/client"
) )
@ -30,7 +31,7 @@ type Messages struct {
} }
func Login(addr, username, password string) (mail *Mail, err error) { func Login(addr, username, password string) (mail *Mail, err error) {
colour.Green("Connecting to %s\n", addr) fmt.Fprintf(os.Stdout, "\x1b[32mConnecting to %s\n\x1b[0m", addr)
client, err := client.DialTLS(addr, nil) client, err := client.DialTLS(addr, nil)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -8,13 +8,11 @@ import (
"time" "time"
"git.0cd.xyz/michael/gomail/mail" "git.0cd.xyz/michael/gomail/mail"
"git.0cd.xyz/michael/gtools/logger"
) )
func main() { func main() {
cfgFile, mailbox, msgs := ui() cfgFile, mailbox, msgs := ui()
cfg := NewConfig(*cfgFile) cfg := NewConfig(*cfgFile)
logger := logger.New(cfg.Logger.Path, cfg.Logger.Mode, cfg.Logger.Level)
chErr, chDone := make(chan error), make(chan bool) chErr, chDone := make(chan error), make(chan bool)
for _, account := range cfg.Account { for _, account := range cfg.Account {
go func(addr, username, password string, chErr chan<- error, chDone chan<- bool) { go func(addr, username, password string, chErr chan<- error, chDone chan<- bool) {
@ -44,7 +42,7 @@ func main() {
for c := 0; c < len(cfg.Account); { for c := 0; c < len(cfg.Account); {
select { select {
case err := <-chErr: case err := <-chErr:
logger.Error.Error(err) log.Println(err)
case <-chDone: case <-chDone:
c++ c++
} }