diff options
Diffstat (limited to 'worker/imap')
-rw-r--r-- | worker/imap/cache.go | 29 | ||||
-rw-r--r-- | worker/imap/checkmail.go | 3 | ||||
-rw-r--r-- | worker/imap/connect.go | 9 | ||||
-rw-r--r-- | worker/imap/fetch.go | 10 | ||||
-rw-r--r-- | worker/imap/flags.go | 10 | ||||
-rw-r--r-- | worker/imap/idler.go | 13 | ||||
-rw-r--r-- | worker/imap/list.go | 4 | ||||
-rw-r--r-- | worker/imap/observer.go | 7 | ||||
-rw-r--r-- | worker/imap/open.go | 13 | ||||
-rw-r--r-- | worker/imap/worker.go | 11 |
10 files changed, 56 insertions, 53 deletions
diff --git a/worker/imap/cache.go b/worker/imap/cache.go index ecbedd89..863b0714 100644 --- a/worker/imap/cache.go +++ b/worker/imap/cache.go @@ -9,6 +9,7 @@ import ( "path" "time" + "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/worker/types" "github.com/emersion/go-message" @@ -33,18 +34,18 @@ func (w *IMAPWorker) initCacheDb(acct string) { cd, err := cacheDir() if err != nil { w.cache = nil - w.worker.Logger.Panicf("cache: unable to find cache directory: %v", err) + logging.Errorf("unable to find cache directory: %v", err) return } p := path.Join(cd, acct) db, err := leveldb.OpenFile(p, nil) if err != nil { w.cache = nil - w.worker.Logger.Printf("cache: error opening cache db: %v", err) + logging.Errorf("failed opening cache db: %v", err) return } w.cache = db - w.worker.Logger.Printf("cache: cache db opened: %s", p) + logging.Infof("cache db opened: %s", p) if w.config.cacheMaxAge.Hours() > 0 { go w.cleanCache() } @@ -53,11 +54,11 @@ func (w *IMAPWorker) initCacheDb(acct string) { func (w *IMAPWorker) cacheHeader(mi *models.MessageInfo) { uv := fmt.Sprintf("%d", w.selected.UidValidity) uid := fmt.Sprintf("%d", mi.Uid) - w.worker.Logger.Printf("cache: caching header for message %s.%s", uv, uid) + logging.Debugf("caching header for message %s.%s", uv, uid) hdr := bytes.NewBuffer(nil) err := textproto.WriteHeader(hdr, mi.RFC822Headers.Header.Header) if err != nil { - w.worker.Logger.Printf("cache: error writing header %s.%s: %v", uv, uid, err) + logging.Errorf("cannot write header %s.%s: %v", uv, uid, err) return } h := &CachedHeader{ @@ -72,18 +73,18 @@ func (w *IMAPWorker) cacheHeader(mi *models.MessageInfo) { enc := gob.NewEncoder(data) err = enc.Encode(h) if err != nil { - w.worker.Logger.Printf("cache: error encoding message %s.%s: %v", uv, uid, err) + logging.Errorf("cannot encode message %s.%s: %v", uv, uid, err) return } err = w.cache.Put([]byte("header."+uv+"."+uid), data.Bytes(), nil) if err != nil { - w.worker.Logger.Printf("cache: error writing header to database for message %s.%s: %v", uv, uid, err) + logging.Errorf("cannot write header for message %s.%s: %v", uv, uid, err) return } } func (w *IMAPWorker) getCachedHeaders(msg *types.FetchMessageHeaders) []uint32 { - w.worker.Logger.Println("Retrieving headers from cache") + logging.Debugf("Retrieving headers from cache: %v", msg.Uids) var need, found []uint32 uv := fmt.Sprintf("%d", w.selected.UidValidity) for _, uid := range msg.Uids { @@ -97,14 +98,14 @@ func (w *IMAPWorker) getCachedHeaders(msg *types.FetchMessageHeaders) []uint32 { dec := gob.NewDecoder(bytes.NewReader(data)) err = dec.Decode(ch) if err != nil { - w.worker.Logger.Printf("cache: error decoding cached header %s.%s: %v", uv, u, err) + logging.Errorf("cannot decode cached header %s.%s: %v", uv, u, err) need = append(need, uid) continue } hr := bytes.NewReader(ch.Header) textprotoHeader, err := textproto.ReadHeader(bufio.NewReader(hr)) if err != nil { - w.worker.Logger.Printf("cache: error reading cached header %s.%s: %v", uv, u, err) + logging.Errorf("cannot read cached header %s.%s: %v", uv, u, err) need = append(need, uid) continue } @@ -118,7 +119,7 @@ func (w *IMAPWorker) getCachedHeaders(msg *types.FetchMessageHeaders) []uint32 { RFC822Headers: hdr, } found = append(found, uid) - w.worker.Logger.Printf("cache: located cached header %s.%s", uv, u) + logging.Debugf("located cached header %s.%s", uv, u) w.worker.PostMessage(&types.MessageInfo{ Message: types.RespondTo(msg), Info: mi, @@ -154,14 +155,14 @@ func (w *IMAPWorker) cleanCache() { dec := gob.NewDecoder(bytes.NewReader(data)) err := dec.Decode(ch) if err != nil { - w.worker.Logger.Printf("cache: error cleaning database %d: %v", w.selected.UidValidity, err) + logging.Errorf("cannot clean database %d: %v", w.selected.UidValidity, err) continue } exp := ch.Created.Add(w.config.cacheMaxAge) if exp.Before(time.Now()) { err = w.cache.Delete(iter.Key(), nil) if err != nil { - w.worker.Logger.Printf("cache: error cleaning database %d: %v", w.selected.UidValidity, err) + logging.Errorf("cannot clean database %d: %v", w.selected.UidValidity, err) continue } removed = removed + 1 @@ -170,5 +171,5 @@ func (w *IMAPWorker) cleanCache() { } iter.Release() elapsed := time.Since(start) - w.worker.Logger.Printf("cache: cleaned cache, removed %d of %d entries in %f seconds", removed, scanned, elapsed.Seconds()) + logging.Infof("cleaned cache, removed %d of %d entries in %s", removed, scanned, elapsed) } diff --git a/worker/imap/checkmail.go b/worker/imap/checkmail.go index 57af3af5..21f2e4bb 100644 --- a/worker/imap/checkmail.go +++ b/worker/imap/checkmail.go @@ -1,6 +1,7 @@ package imap import ( + "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/worker/types" "github.com/emersion/go-imap" @@ -13,7 +14,7 @@ func (w *IMAPWorker) handleCheckMailMessage(msg *types.CheckMail) { imap.StatusUnseen, } for _, dir := range msg.Directories { - w.worker.Logger.Printf("Getting status of directory %s", dir) + logging.Debugf("Getting status of directory %s", dir) status, err := w.client.Status(dir, items) if err != nil { w.worker.PostMessage(&types.Error{ diff --git a/worker/imap/connect.go b/worker/imap/connect.go index 2581c6dd..5f8cd1c0 100644 --- a/worker/imap/connect.go +++ b/worker/imap/connect.go @@ -7,6 +7,7 @@ import ( "time" "git.sr.ht/~rjarry/aerc/lib" + "git.sr.ht/~rjarry/aerc/logging" "github.com/emersion/go-imap" "github.com/emersion/go-imap/client" ) @@ -66,7 +67,7 @@ func (w *IMAPWorker) connect() (*client.Client, error) { return nil, fmt.Errorf("Unknown IMAP scheme %s", w.config.scheme) } - c.ErrorLog = w.worker.Logger + c.ErrorLog = logging.ErrorLogger() if w.config.user != nil { username := w.config.user.Username() @@ -162,14 +163,12 @@ func (w *IMAPWorker) setKeepaliveParameters(conn *net.TCPConn) error { // Max number of probes before failure err := lib.SetTcpKeepaliveProbes(fd, w.config.keepalive_probes) if err != nil { - w.worker.Logger.Printf( - "cannot set tcp keepalive probes: %v\n", err) + logging.Errorf("cannot set tcp keepalive probes: %v", err) } // Wait time after an unsuccessful probe err = lib.SetTcpKeepaliveInterval(fd, w.config.keepalive_interval) if err != nil { - w.worker.Logger.Printf( - "cannot set tcp keepalive interval: %v\n", err) + logging.Errorf("cannot set tcp keepalive interval: %v", err) } }) return err diff --git a/worker/imap/fetch.go b/worker/imap/fetch.go index cf27e382..6ef0baca 100644 --- a/worker/imap/fetch.go +++ b/worker/imap/fetch.go @@ -26,7 +26,7 @@ func (imapw *IMAPWorker) handleFetchMessageHeaders( nil) return } - imapw.worker.Logger.Printf("Fetching message headers") + logging.Infof("Fetching message headers: %v", toFetch) section := &imap.BodySectionName{ BodyPartName: imap.BodyPartName{ Specifier: imap.HeaderSpecifier, @@ -47,8 +47,8 @@ func (imapw *IMAPWorker) handleFetchMessageHeaders( reader := _msg.GetBody(section) textprotoHeader, err := textproto.ReadHeader(bufio.NewReader(reader)) if err != nil { - imapw.worker.Logger.Printf( - "message %v: could not read header: %v", _msg.Uid, err) + logging.Errorf( + "message %d: could not read header: %v", _msg.Uid, err) imapw.worker.PostMessage(&types.Error{ Message: types.RespondTo(msg), Error: err, @@ -78,7 +78,7 @@ func (imapw *IMAPWorker) handleFetchMessageHeaders( func (imapw *IMAPWorker) handleFetchMessageBodyPart( msg *types.FetchMessageBodyPart) { - imapw.worker.Logger.Printf("Fetching message part") + logging.Infof("Fetching message %d part: %v", msg.Uid, msg.Part) var partHeaderSection imap.BodySectionName partHeaderSection.Peek = true @@ -148,7 +148,7 @@ func (imapw *IMAPWorker) handleFetchMessageBodyPart( func (imapw *IMAPWorker) handleFetchFullMessages( msg *types.FetchFullMessages) { - imapw.worker.Logger.Printf("Fetching full messages") + logging.Infof("Fetching full messages: %v", msg.Uids) section := &imap.BodySectionName{} items := []imap.FetchItem{ imap.FetchEnvelope, diff --git a/worker/imap/flags.go b/worker/imap/flags.go index 2bded2ae..5b2ac410 100644 --- a/worker/imap/flags.go +++ b/worker/imap/flags.go @@ -28,7 +28,7 @@ func (imapw *IMAPWorker) handleDeleteMessages(msg *types.DeleteMessages) { for seqNum := range ch { if uid, found := imapw.seqMap.Pop(seqNum); !found { - imapw.worker.Logger.Printf("handleDeleteMessages unknown seqnum: %v", seqNum) + logging.Errorf("handleDeleteMessages unknown seqnum: %d", seqNum) } else { deleted = append(deleted, uid) } @@ -73,8 +73,8 @@ func (imapw *IMAPWorker) handleAnsweredMessages(msg *types.AnsweredMessages) { }, func(_msg types.WorkerMessage) { switch m := _msg.(type) { case *types.Error: - err := fmt.Errorf("handleAnsweredMessages: %v", m.Error) - imapw.worker.Logger.Printf("could not fetch headers: %s", err) + err := fmt.Errorf("handleAnsweredMessages: %w", m.Error) + logging.Errorf("could not fetch headers: %v", err) emitErr(err) case *types.Done: imapw.worker.PostMessage(&types.Done{Message: types.RespondTo(msg)}, nil) @@ -104,8 +104,8 @@ func (imapw *IMAPWorker) handleFlagMessages(msg *types.FlagMessages) { }, func(_msg types.WorkerMessage) { switch m := _msg.(type) { case *types.Error: - err := fmt.Errorf("handleFlagMessages: %v", m.Error) - imapw.worker.Logger.Printf("could not fetch headers: %s", err) + err := fmt.Errorf("handleFlagMessages: %w", m.Error) + logging.Errorf("could not fetch headers: %v", err) emitErr(err) case *types.Done: imapw.worker.PostMessage(&types.Done{Message: types.RespondTo(msg)}, nil) diff --git a/worker/imap/idler.go b/worker/imap/idler.go index bac690f1..055bab8b 100644 --- a/worker/imap/idler.go +++ b/worker/imap/idler.go @@ -84,8 +84,7 @@ func (i *idler) Start() { }) i.idleing = false i.done <- err - i.log("elapsed idle time:", - time.Since(now)) + i.log("elapsed idle time: %v", time.Since(now)) } }() @@ -105,7 +104,7 @@ func (i *idler) Stop() error { if err == nil { i.log("<=(idle)") } else { - i.log("<=(idle) with err:", err) + i.log("<=(idle) with err: %v", err) } reterr = nil case <-time.After(i.config.idle_timeout): @@ -144,7 +143,7 @@ func (i *idler) waitOnIdle() { Message: types.RespondTo(&types.Connect{}), }, nil) } else { - i.log("<=(idle) waited; with err:", err) + i.log("<=(idle) waited; with err: %v", err) } i.setWaiting(false) i.stop = make(chan struct{}) @@ -155,7 +154,7 @@ func (i *idler) waitOnIdle() { }() } -func (i *idler) log(args ...interface{}) { - header := fmt.Sprintf("idler (%p) [idle:%t,wait:%t]", i, i.idleing, i.waiting) - i.worker.Logger.Println(append([]interface{}{header}, args...)...) +func (i *idler) log(format string, v ...interface{}) { + msg := fmt.Sprintf(format, v...) + logging.Debugf("idler (%p) [idle:%t,wait:%t] %s", i, i.idleing, i.waiting, msg) } diff --git a/worker/imap/list.go b/worker/imap/list.go index 026aa9a7..51f4d3e6 100644 --- a/worker/imap/list.go +++ b/worker/imap/list.go @@ -10,7 +10,7 @@ import ( func (imapw *IMAPWorker) handleListDirectories(msg *types.ListDirectories) { mailboxes := make(chan *imap.MailboxInfo) - imapw.worker.Logger.Println("Listing mailboxes") + logging.Infof("Listing mailboxes") done := make(chan interface{}) go func() { @@ -62,7 +62,7 @@ func (imapw *IMAPWorker) handleSearchDirectory(msg *types.SearchDirectory) { }, nil) } - imapw.worker.Logger.Println("Executing search") + logging.Infof("Executing search") criteria, err := parseSearch(msg.Argv) if err != nil { emitError(err) diff --git a/worker/imap/observer.go b/worker/imap/observer.go index e49744cc..448128c7 100644 --- a/worker/imap/observer.go +++ b/worker/imap/observer.go @@ -6,6 +6,7 @@ import ( "sync" "time" + "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/worker/types" "github.com/emersion/go-imap" ) @@ -146,7 +147,7 @@ func (o *observer) emit(errMsg string) { }, nil) } -func (o *observer) log(args ...interface{}) { - header := fmt.Sprintf("observer (%p) [running:%t]", o, o.running) - o.worker.Logger.Println(append([]interface{}{header}, args...)...) +func (o *observer) log(format string, args ...interface{}) { + msg := fmt.Sprintf(format, args...) + logging.Debugf("observer (%p) [running:%t] %s", o, o.running, msg) } diff --git a/worker/imap/open.go b/worker/imap/open.go index b52a3c65..636b936c 100644 --- a/worker/imap/open.go +++ b/worker/imap/open.go @@ -5,11 +5,12 @@ import ( sortthread "github.com/emersion/go-imap-sortthread" + "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/worker/types" ) func (imapw *IMAPWorker) handleOpenDirectory(msg *types.OpenDirectory) { - imapw.worker.Logger.Printf("Opening %s", msg.Directory) + logging.Infof("Opening %s", msg.Directory) sel, err := imapw.client.Select(msg.Directory, false) if err != nil { @@ -26,7 +27,7 @@ func (imapw *IMAPWorker) handleOpenDirectory(msg *types.OpenDirectory) { func (imapw *IMAPWorker) handleFetchDirectoryContents( msg *types.FetchDirectoryContents) { - imapw.worker.Logger.Printf("Fetching UID list") + logging.Infof("Fetching UID list") searchCriteria, err := parseSearch(msg.FilterCriteria) if err != nil { @@ -51,7 +52,7 @@ func (imapw *IMAPWorker) handleFetchDirectoryContents( } else { if err != nil { // Non fatal, but we do want to print to get some debug info - imapw.worker.Logger.Printf("can't check for SORT support: %v", err) + logging.Errorf("can't check for SORT support: %v", err) } uids, err = imapw.client.UidSearch(searchCriteria) } @@ -61,7 +62,7 @@ func (imapw *IMAPWorker) handleFetchDirectoryContents( Error: err, }, nil) } else { - imapw.worker.Logger.Printf("Found %d UIDs", len(uids)) + logging.Infof("Found %d UIDs", len(uids)) imapw.seqMap.Clear() imapw.worker.PostMessage(&types.DirectoryContents{ Message: types.RespondTo(msg), @@ -97,7 +98,7 @@ func translateSortCriterions( func (imapw *IMAPWorker) handleDirectoryThreaded( msg *types.FetchDirectoryThreaded) { - imapw.worker.Logger.Printf("Fetching threaded UID list") + logging.Infof("Fetching threaded UID list") searchCriteria, err := parseSearch(msg.FilterCriteria) if err != nil { @@ -117,7 +118,7 @@ func (imapw *IMAPWorker) handleDirectoryThreaded( } else { aercThreads, count := convertThreads(threads, nil) sort.Sort(types.ByUID(aercThreads)) - imapw.worker.Logger.Printf("Found %d threaded messages", count) + logging.Infof("Found %d threaded messages", count) imapw.seqMap.Clear() imapw.worker.PostMessage(&types.DirectoryThreaded{ Message: types.RespondTo(msg), diff --git a/worker/imap/worker.go b/worker/imap/worker.go index 3ed646df..dee089e0 100644 --- a/worker/imap/worker.go +++ b/worker/imap/worker.go @@ -12,6 +12,7 @@ import ( "github.com/syndtr/goleveldb/leveldb" "git.sr.ht/~rjarry/aerc/lib" + "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/worker/handlers" "git.sr.ht/~rjarry/aerc/worker/types" @@ -89,12 +90,12 @@ func (w *IMAPWorker) newClient(c *client.Client) { sort, err := w.client.sort.SupportSort() if err == nil && sort { w.caps.Sort = true - w.worker.Logger.Println("Server Capability found: Sort") + logging.Infof("Server Capability found: Sort") } thread, err := w.client.thread.SupportThread() if err == nil && thread { w.caps.Thread = true - w.worker.Logger.Println("Server Capability found: Thread") + logging.Infof("Server Capability found: Thread") } } @@ -223,7 +224,7 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error { } func (w *IMAPWorker) handleImapUpdate(update client.Update) { - w.worker.Logger.Printf("(= %T", update) + logging.Debugf("(= %T", update) switch update := update.(type) { case *client.MailboxUpdate: status := update.Mailbox @@ -246,7 +247,7 @@ func (w *IMAPWorker) handleImapUpdate(update client.Update) { msg := update.Message if msg.Uid == 0 { if uid, found := w.seqMap.Get(msg.SeqNum); !found { - w.worker.Logger.Printf("MessageUpdate unknown seqnum: %v", msg.SeqNum) + logging.Errorf("MessageUpdate unknown seqnum: %d", msg.SeqNum) return } else { msg.Uid = uid @@ -263,7 +264,7 @@ func (w *IMAPWorker) handleImapUpdate(update client.Update) { }, nil) case *client.ExpungeUpdate: if uid, found := w.seqMap.Pop(update.SeqNum); !found { - w.worker.Logger.Printf("ExpungeUpdate unknown seqnum: %v", update.SeqNum) + logging.Errorf("ExpungeUpdate unknown seqnum: %d", update.SeqNum) } else { w.worker.PostMessage(&types.MessagesDeleted{ Uids: []uint32{uid}, |