aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/crypto/crypto.go3
-rw-r--r--lib/crypto/gpg/gpg.go8
-rw-r--r--lib/crypto/gpg/gpgbin/gpgbin.go33
-rw-r--r--lib/crypto/pgp/pgp.go11
-rw-r--r--lib/msgstore.go2
-rw-r--r--lib/socket.go18
-rw-r--r--lib/threadbuilder.go10
7 files changed, 21 insertions, 64 deletions
diff --git a/lib/crypto/crypto.go b/lib/crypto/crypto.go
index 3c961ad4..8f895b42 100644
--- a/lib/crypto/crypto.go
+++ b/lib/crypto/crypto.go
@@ -3,7 +3,6 @@ package crypto
import (
"bytes"
"io"
- "log"
"git.sr.ht/~rjarry/aerc/lib/crypto/gpg"
"git.sr.ht/~rjarry/aerc/lib/crypto/pgp"
@@ -17,7 +16,7 @@ type Provider interface {
Encrypt(*bytes.Buffer, []string, string, openpgp.PromptFunction, *mail.Header) (io.WriteCloser, error)
Sign(*bytes.Buffer, string, openpgp.PromptFunction, *mail.Header) (io.WriteCloser, error)
ImportKeys(io.Reader) error
- Init(*log.Logger) error
+ Init() error
Close()
GetSignerKeyId(string) (string, error)
GetKeyId(string) (string, error)
diff --git a/lib/crypto/gpg/gpg.go b/lib/crypto/gpg/gpg.go
index 00125ba6..e545e1c9 100644
--- a/lib/crypto/gpg/gpg.go
+++ b/lib/crypto/gpg/gpg.go
@@ -3,7 +3,6 @@ package gpg
import (
"bytes"
"io"
- "log"
"os/exec"
"git.sr.ht/~rjarry/aerc/lib/crypto/gpg/gpgbin"
@@ -13,12 +12,9 @@ import (
)
// Mail satisfies the PGPProvider interface in aerc
-type Mail struct {
- logger *log.Logger
-}
+type Mail struct{}
-func (m *Mail) Init(l *log.Logger) error {
- m.logger = l
+func (m *Mail) Init() error {
_, err := exec.LookPath("gpg")
return err
}
diff --git a/lib/crypto/gpg/gpgbin/gpgbin.go b/lib/crypto/gpg/gpgbin/gpgbin.go
index 9f79e972..2eb83dc9 100644
--- a/lib/crypto/gpg/gpgbin/gpgbin.go
+++ b/lib/crypto/gpg/gpgbin/gpgbin.go
@@ -6,15 +6,12 @@ import (
"errors"
"fmt"
"io"
- "io/ioutil"
- "log"
- "os"
"os/exec"
"strconv"
"strings"
+ "git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/models"
- "github.com/mattn/go-isatty"
)
// gpg represents a gpg command with buffers attached to stdout and stderr
@@ -112,17 +109,6 @@ func longKeyToUint64(key string) (uint64, error) {
// parse parses the output of gpg --status-fd
func parse(r io.Reader, md *models.MessageDetails) error {
- var (
- logOut io.Writer
- logger *log.Logger
- )
- if !isatty.IsTerminal(os.Stdout.Fd()) {
- logOut = os.Stdout
- } else {
- logOut = ioutil.Discard
- os.Stdout, _ = os.Open(os.DevNull)
- }
- logger = log.New(logOut, "", log.LstdFlags)
var err error
var msgContent []byte
var msgCollecting bool
@@ -135,7 +121,7 @@ func parse(r io.Reader, md *models.MessageDetails) error {
}
if strings.HasPrefix(line, "[GNUPG:]") {
msgCollecting = false
- logger.Println(line)
+ logging.Debugf(line)
}
if msgCollecting {
msgContent = append(msgContent, scanner.Bytes()...)
@@ -270,18 +256,3 @@ var micalgs = map[int]string{
10: "pgp-sha512",
11: "pgp-sha224",
}
-
-func logger(s string) {
- var (
- logOut io.Writer
- logger *log.Logger
- )
- if !isatty.IsTerminal(os.Stdout.Fd()) {
- logOut = os.Stdout
- } else {
- logOut = ioutil.Discard
- os.Stdout, _ = os.Open(os.DevNull)
- }
- logger = log.New(logOut, "", log.LstdFlags)
- logger.Println(s)
-}
diff --git a/lib/crypto/pgp/pgp.go b/lib/crypto/pgp/pgp.go
index 4dbe37c7..647b091b 100644
--- a/lib/crypto/pgp/pgp.go
+++ b/lib/crypto/pgp/pgp.go
@@ -5,12 +5,12 @@ import (
"fmt"
"io"
"io/ioutil"
- "log"
"os"
"path"
"strings"
"time"
+ "git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/models"
"github.com/ProtonMail/go-crypto/openpgp"
"github.com/ProtonMail/go-crypto/openpgp/armor"
@@ -21,9 +21,7 @@ import (
"github.com/pkg/errors"
)
-type Mail struct {
- logger *log.Logger
-}
+type Mail struct{}
var (
Keyring openpgp.EntityList
@@ -31,9 +29,8 @@ var (
locked bool
)
-func (m *Mail) Init(l *log.Logger) error {
- m.logger = l
- m.logger.Println("Initializing PGP keyring")
+func (m *Mail) Init() error {
+ logging.Infof("Initializing PGP keyring")
os.MkdirAll(path.Join(xdg.DataHome(), "aerc"), 0700)
lockpath := path.Join(xdg.DataHome(), "aerc", "keyring.lock")
diff --git a/lib/msgstore.go b/lib/msgstore.go
index 240d4b7a..52cd739b 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -383,7 +383,7 @@ func (store *MessageStore) BuildThreads() bool {
func (store *MessageStore) runThreadBuilder() {
if store.builder == nil {
- store.builder = NewThreadBuilder(store.worker.Logger)
+ store.builder = NewThreadBuilder()
for _, msg := range store.Messages {
store.builder.Update(msg)
}
diff --git a/lib/socket.go b/lib/socket.go
index 902a7be2..fa36172e 100644
--- a/lib/socket.go
+++ b/lib/socket.go
@@ -4,7 +4,6 @@ import (
"bufio"
"errors"
"fmt"
- "log"
"net"
"net/url"
"os"
@@ -18,24 +17,21 @@ import (
)
type AercServer struct {
- logger *log.Logger
listener net.Listener
OnMailto func(addr *url.URL) error
OnMbox func(source string) error
}
-func StartServer(logger *log.Logger) (*AercServer, error) {
+func StartServer() (*AercServer, error) {
sockpath := path.Join(xdg.RuntimeDir(), "aerc.sock")
// remove the socket if it already exists
os.Remove(sockpath)
+ logging.Infof("Starting Unix server: %s", sockpath)
l, err := net.Listen("unix", sockpath)
if err != nil {
return nil, err
}
- as := &AercServer{
- logger: logger,
- listener: l,
- }
+ as := &AercServer{listener: l}
// TODO: stash clients and close them on exit... bleh racey
go func() {
defer logging.PanicHandler()
@@ -45,7 +41,7 @@ func StartServer(logger *log.Logger) (*AercServer, error) {
if err != nil {
// TODO: Something more useful, in some cases, on wednesdays,
// after 2 PM, I guess?
- as.logger.Printf("Closing Unix server: %v", err)
+ logging.Errorf("Closing Unix server: %v", err)
return
}
go func() {
@@ -66,13 +62,13 @@ var lastId int64 = 0 // access via atomic
func (as *AercServer) handleClient(conn net.Conn) {
clientId := atomic.AddInt64(&lastId, 1)
- as.logger.Printf("Accepted Unix connection %d", clientId)
+ logging.Debugf("unix:%d accepted connection", clientId)
scanner := bufio.NewScanner(conn)
conn.SetDeadline(time.Now().Add(1 * time.Minute))
for scanner.Scan() {
conn.SetDeadline(time.Now().Add(1 * time.Minute))
msg := scanner.Text()
- as.logger.Printf("unix:%d: got message %s", clientId, msg)
+ logging.Debugf("unix:%d got message %s", clientId, msg)
if !strings.ContainsRune(msg, ':') {
conn.Write([]byte("error: invalid command\n"))
continue
@@ -105,7 +101,7 @@ func (as *AercServer) handleClient(conn net.Conn) {
}
}
}
- as.logger.Printf("Closed Unix connection %d", clientId)
+ logging.Debugf("unix:%d closed connection", clientId)
}
func ConnectAndExec(msg string) error {
diff --git a/lib/threadbuilder.go b/lib/threadbuilder.go
index 334a8468..59abd2f6 100644
--- a/lib/threadbuilder.go
+++ b/lib/threadbuilder.go
@@ -1,9 +1,9 @@
package lib
import (
- "log"
"time"
+ "git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
"github.com/gatherstars-com/jwz"
@@ -14,15 +14,13 @@ type ThreadBuilder struct {
messageidToUid map[string]uint32
seen map[uint32]bool
threadedUids []uint32
- logger *log.Logger
}
-func NewThreadBuilder(logger *log.Logger) *ThreadBuilder {
+func NewThreadBuilder() *ThreadBuilder {
tb := &ThreadBuilder{
threadBlocks: make(map[uint32]jwz.Threadable),
messageidToUid: make(map[string]uint32),
seen: make(map[uint32]bool),
- logger: logger,
}
return tb
}
@@ -58,7 +56,7 @@ func (builder *ThreadBuilder) Threads(uids []uint32) []*types.Thread {
builder.RebuildUids(threads)
elapsed := time.Since(start)
- builder.logger.Println("ThreadBuilder:", len(threads), "threads created in", elapsed)
+ logging.Infof("%d threads created in %s", len(threads), elapsed)
return threads
}
@@ -74,7 +72,7 @@ func (builder *ThreadBuilder) generateStructure(uids []uint32) jwz.Threadable {
threader := jwz.NewThreader()
threadStructure, err := threader.ThreadSlice(jwzThreads)
if err != nil {
- builder.logger.Printf("ThreadBuilder: threading operation return error: %#v", err)
+ logging.Errorf("failed slicing threads: %v", err)
}
return threadStructure
}