From aaf0a0c65673db4b94c0dc200d7394a192128da1 Mon Sep 17 00:00:00 2001 From: Moritz Poldrack Date: Sun, 31 Jul 2022 22:16:40 +0200 Subject: [PATCH] lint: apply new formatting rules Run `make fmt`. Signed-off-by: Moritz Poldrack Acked-by: Robin Jarry --- commands/account/account.go | 4 +-- commands/account/cf.go | 4 +-- commands/cd.go | 4 +-- commands/compose/compose.go | 4 +-- commands/compose/header.go | 24 ++++++++---------- commands/compose/send.go | 7 +++--- commands/global.go | 4 +-- commands/msg/archive.go | 6 +++-- commands/msg/copy.go | 8 +++--- commands/msg/delete.go | 2 +- commands/msg/invite.go | 5 +--- commands/msg/modify-labels.go | 4 +-- commands/msg/move.go | 8 +++--- commands/msg/msg.go | 4 +-- commands/msg/read.go | 4 +-- commands/msg/recall.go | 3 --- commands/msg/reply.go | 9 ++++--- commands/msg/unsubscribe_test.go | 6 +++-- commands/msgview/msgview.go | 4 +-- commands/msgview/save.go | 9 +++---- commands/prompt.go | 3 ++- commands/set.go | 2 -- commands/terminal/terminal.go | 4 +-- config/bindings.go | 12 ++++----- config/config.go | 29 +++++++++++----------- config/style.go | 3 ++- config/triggers.go | 10 +++++--- lib/calendar/calendar.go | 1 - lib/crypto/gpg/gpg.go | 1 - lib/crypto/gpg/gpgbin/encrypt.go | 2 +- lib/crypto/pgp/pgp.go | 6 ++--- lib/format/format.go | 14 ++++++----- lib/messageview.go | 11 +++++---- lib/msgstore.go | 42 +++++++++++++++----------------- lib/oauthbearer.go | 1 + lib/open.go | 1 - lib/parse/hyperlinks.go | 8 +++--- lib/statusline/state.go | 9 ++++--- lib/structure_helpers_test.go | 20 +++++++-------- lib/templates/template.go | 4 +-- lib/ui/borders.go | 3 ++- lib/ui/context.go | 3 ++- lib/ui/tab.go | 6 +++-- lib/ui/textinput.go | 3 ++- lib/ui/ui.go | 1 - models/models.go | 2 +- widgets/account-wizard.go | 2 +- widgets/aerc.go | 3 ++- widgets/compose.go | 31 ++++++++++++----------- widgets/dirlist.go | 1 - widgets/dirtree.go | 2 +- widgets/exline.go | 8 +++--- widgets/getpasswd.go | 3 ++- widgets/msglist.go | 2 +- widgets/msgviewer.go | 18 +++++++------- widgets/scrollable.go | 1 - widgets/selector.go | 3 ++- widgets/terminal.go | 8 +++--- worker/imap/connect.go | 4 +-- worker/imap/fetch.go | 15 ++++++------ worker/imap/list.go | 1 - worker/imap/movecopy.go | 1 - worker/imap/observer.go | 3 ++- worker/imap/open.go | 10 +++++--- worker/lib/parse.go | 4 +-- worker/lib/search.go | 4 +-- worker/lib/sort.go | 12 ++++++--- worker/maildir/container.go | 12 ++++++--- worker/maildir/search.go | 3 ++- worker/maildir/worker.go | 10 +++++--- worker/mbox/create.go | 1 - worker/mbox/worker.go | 6 +++-- worker/notmuch/lib/database.go | 19 +++++++++------ worker/notmuch/message.go | 12 ++++----- worker/notmuch/worker.go | 39 ++++++++++++++++++----------- worker/types/thread.go | 4 ++- worker/types/thread_test.go | 2 +- worker/types/worker.go | 5 ++-- 78 files changed, 288 insertions(+), 285 deletions(-) diff --git a/commands/account/account.go b/commands/account/account.go index 4731c19..fc17fa2 100644 --- a/commands/account/account.go +++ b/commands/account/account.go @@ -4,9 +4,7 @@ import ( "git.sr.ht/~rjarry/aerc/commands" ) -var ( - AccountCommands *commands.Commands -) +var AccountCommands *commands.Commands func register(cmd commands.Command) { if AccountCommands == nil { diff --git a/commands/account/cf.go b/commands/account/cf.go index b5cda53..39b0bb8 100644 --- a/commands/account/cf.go +++ b/commands/account/cf.go @@ -9,9 +9,7 @@ import ( "git.sr.ht/~rjarry/aerc/widgets" ) -var ( - history map[string]string -) +var history map[string]string type ChangeFolder struct{} diff --git a/commands/cd.go b/commands/cd.go index edfc179..d856a06 100644 --- a/commands/cd.go +++ b/commands/cd.go @@ -9,9 +9,7 @@ import ( "github.com/mitchellh/go-homedir" ) -var ( - previousDir string -) +var previousDir string type ChangeDirectory struct{} diff --git a/commands/compose/compose.go b/commands/compose/compose.go index 563dcd1..f325e4e 100644 --- a/commands/compose/compose.go +++ b/commands/compose/compose.go @@ -4,9 +4,7 @@ import ( "git.sr.ht/~rjarry/aerc/commands" ) -var ( - ComposeCommands *commands.Commands -) +var ComposeCommands *commands.Commands func register(cmd commands.Command) { if ComposeCommands == nil { diff --git a/commands/compose/header.go b/commands/compose/header.go index ca5c869..dcee9aa 100644 --- a/commands/compose/header.go +++ b/commands/compose/header.go @@ -12,17 +12,15 @@ import ( type Header struct{} -var ( - headers = []string{ - "From", - "To", - "Cc", - "Bcc", - "Subject", - "Comments", - "Keywords", - } -) +var headers = []string{ + "From", + "To", + "Cc", + "Bcc", + "Subject", + "Comments", + "Keywords", +} func init() { register(Header{}) @@ -50,9 +48,7 @@ func (Header) Execute(aerc *widgets.Aerc, args []string) error { return errors.New("command parsing failed") } - var ( - force bool = false - ) + var force bool = false for _, opt := range opts { switch opt.Option { case 'f': diff --git a/commands/compose/send.go b/commands/compose/send.go index 5448b72..2bd6111 100644 --- a/commands/compose/send.go +++ b/commands/compose/send.go @@ -111,7 +111,7 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error { var copyBuf bytes.Buffer // for the Sent folder content if CopyTo is set failCh := make(chan error) - //writer + // writer go func() { defer logging.PanicHandler() @@ -144,7 +144,7 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error { failCh <- sender.Close() }() - //cleanup + copy to sent + // cleanup + copy to sent go func() { defer logging.PanicHandler() @@ -431,7 +431,8 @@ func connectSmtps(host string) (*smtp.Client, error) { } func copyToSent(worker *types.Worker, dest string, - n int, msg io.Reader) <-chan error { + n int, msg io.Reader, +) <-chan error { errCh := make(chan error) worker.PostAction(&types.AppendMessage{ Destination: dest, diff --git a/commands/global.go b/commands/global.go index 459192f..ec7d623 100644 --- a/commands/global.go +++ b/commands/global.go @@ -1,8 +1,6 @@ package commands -var ( - GlobalCommands *Commands -) +var GlobalCommands *Commands func register(cmd Command) { if GlobalCommands == nil { diff --git a/commands/msg/archive.go b/commands/msg/archive.go index d4ad8f9..b8d8ff6 100644 --- a/commands/msg/archive.go +++ b/commands/msg/archive.go @@ -86,7 +86,8 @@ func (Archive) Execute(aerc *widgets.Aerc, args []string) error { for dir, uids := range uidMap { store.Move(uids, dir, true, func( - msg types.WorkerMessage) { + msg types.WorkerMessage, + ) { switch msg := msg.(type) { case *types.Done: wg.Done() @@ -111,7 +112,8 @@ func (Archive) Execute(aerc *widgets.Aerc, args []string) error { } func groupBy(msgs []*models.MessageInfo, - grouper func(*models.MessageInfo) string) map[string][]uint32 { + grouper func(*models.MessageInfo) string, +) map[string][]uint32 { m := make(map[string][]uint32) for _, msg := range msgs { group := grouper(msg) diff --git a/commands/msg/copy.go b/commands/msg/copy.go index a68a22a..44257a7 100644 --- a/commands/msg/copy.go +++ b/commands/msg/copy.go @@ -34,9 +34,7 @@ func (Copy) Execute(aerc *widgets.Aerc, args []string) error { if err != nil { return err } - var ( - createParents bool - ) + var createParents bool for _, opt := range opts { switch opt.Option { case 'p': @@ -54,8 +52,8 @@ func (Copy) Execute(aerc *widgets.Aerc, args []string) error { } store.Copy(uids, strings.Join(args[optind:], " "), createParents, func( - msg types.WorkerMessage) { - + msg types.WorkerMessage, + ) { switch msg := msg.(type) { case *types.Done: aerc.PushStatus("Messages copied.", 10*time.Second) diff --git a/commands/msg/delete.go b/commands/msg/delete.go index 7cf8113..fdb2117 100644 --- a/commands/msg/delete.go +++ b/commands/msg/delete.go @@ -42,7 +42,7 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error { if err != nil { return err } - //caution, can be nil + // caution, can be nil next := findNextNonDeleted(uids, store) store.ClearVisualMark() store.Delete(uids, func(msg types.WorkerMessage) { diff --git a/commands/msg/invite.go b/commands/msg/invite.go index c15e265..936cea7 100644 --- a/commands/msg/invite.go +++ b/commands/msg/invite.go @@ -28,7 +28,6 @@ func (invite) Complete(aerc *widgets.Aerc, args []string) []string { } func (invite) Execute(aerc *widgets.Aerc, args []string) error { - acct := aerc.SelectedAccount() if acct == nil { return errors.New("no account selected") @@ -90,9 +89,7 @@ func (invite) Execute(aerc *widgets.Aerc, args []string) error { } } - var ( - to []*mail.Address - ) + var to []*mail.Address if len(msg.Envelope.ReplyTo) != 0 { to = msg.Envelope.ReplyTo diff --git a/commands/msg/modify-labels.go b/commands/msg/modify-labels.go index a3b4900..655004c 100644 --- a/commands/msg/modify-labels.go +++ b/commands/msg/modify-labels.go @@ -52,8 +52,8 @@ func (ModifyLabels) Execute(aerc *widgets.Aerc, args []string) error { } } store.ModifyLabels(uids, add, remove, func( - msg types.WorkerMessage) { - + msg types.WorkerMessage, + ) { switch msg := msg.(type) { case *types.Done: aerc.PushStatus("labels updated", 10*time.Second) diff --git a/commands/msg/move.go b/commands/msg/move.go index b13e94a..2e3d438 100644 --- a/commands/msg/move.go +++ b/commands/msg/move.go @@ -34,9 +34,7 @@ func (Move) Execute(aerc *widgets.Aerc, args []string) error { if err != nil { return err } - var ( - createParents bool - ) + var createParents bool for _, opt := range opts { switch opt.Option { case 'p': @@ -61,8 +59,8 @@ func (Move) Execute(aerc *widgets.Aerc, args []string) error { findNextNonDeleted(uids, store) joinedArgs := strings.Join(args[optind:], " ") store.Move(uids, joinedArgs, createParents, func( - msg types.WorkerMessage) { - + msg types.WorkerMessage, + ) { switch msg := msg.(type) { case *types.Done: aerc.PushStatus("Message moved to "+joinedArgs, 10*time.Second) diff --git a/commands/msg/msg.go b/commands/msg/msg.go index 7b6fb12..65a4056 100644 --- a/commands/msg/msg.go +++ b/commands/msg/msg.go @@ -4,9 +4,7 @@ import ( "git.sr.ht/~rjarry/aerc/commands" ) -var ( - MessageCommands *commands.Commands -) +var MessageCommands *commands.Commands func register(cmd commands.Command) { if MessageCommands == nil { diff --git a/commands/msg/read.go b/commands/msg/read.go index c6bcd0d..4c169b3 100644 --- a/commands/msg/read.go +++ b/commands/msg/read.go @@ -36,7 +36,6 @@ func (FlagMsg) Complete(aerc *widgets.Aerc, args []string) []string { // If this was called as 'read' or 'unread', it has the same effect as // 'flag' or 'unflag', respectively, but the 'Seen' flag is affected. func (FlagMsg) Execute(aerc *widgets.Aerc, args []string) error { - // The flag to change var flag models.Flag // User-readable name of the flag to change @@ -184,7 +183,8 @@ func (FlagMsg) Execute(aerc *widgets.Aerc, args []string) error { func submitFlagChange(aerc *widgets.Aerc, store *lib.MessageStore, uids []uint32, flag models.Flag, newState bool, - wg *sync.WaitGroup, success *bool) { + wg *sync.WaitGroup, success *bool, +) { store.Flag(uids, flag, newState, func(msg types.WorkerMessage) { wg.Add(1) switch msg := msg.(type) { diff --git a/commands/msg/recall.go b/commands/msg/recall.go index 477a363..1ce6ce6 100644 --- a/commands/msg/recall.go +++ b/commands/msg/recall.go @@ -136,7 +136,6 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error { ) aerc.AddDialog(confirm) } - }) } @@ -212,9 +211,7 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error { mu.Unlock() }) } - }) - }) return nil diff --git a/commands/msg/reply.go b/commands/msg/reply.go index a1254a1..dd5aa19 100644 --- a/commands/msg/reply.go +++ b/commands/msg/reply.go @@ -146,7 +146,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error { to = append(to, envTos...) for _, addr := range msg.Envelope.Cc { - //dedupe stuff from the to/from headers + // dedupe stuff from the to/from headers if recSet.Contains(addr) { continue } @@ -259,8 +259,8 @@ func (s addrSet) Contains(a *mail.Address) bool { return ok } -//setReferencesHeader adds the references header to target based on parent -//according to RFC2822 +// setReferencesHeader adds the references header to target based on parent +// according to RFC2822 func setReferencesHeader(target, parent *mail.Header) error { refs, err := parent.MsgIDList("references") if err != nil { @@ -285,7 +285,8 @@ func setReferencesHeader(target, parent *mail.Header) error { // addMimeType adds the proper mime type of the part to the originalMail struct func addMimeType(msg *models.MessageInfo, part []int, - orig *models.OriginalMail) error { + orig *models.OriginalMail, +) error { // caution, :forward uses the code as well, keep that in mind when modifying bs, err := msg.BodyStructure.PartAtIndex(part) if err != nil { diff --git a/commands/msg/unsubscribe_test.go b/commands/msg/unsubscribe_test.go index d34efb1..4613830 100644 --- a/commands/msg/unsubscribe_test.go +++ b/commands/msg/unsubscribe_test.go @@ -18,10 +18,12 @@ func TestParseUnsubscribe(t *testing.T) { {" is a URL", []string{ "https://example.com", }}, - {", ", + { + ", ", []string{ "mailto:user@host?subject=unsubscribe", "https://example.com", - }}, + }, + }, {"<>, ", []string{ "", "https://example", }}, diff --git a/commands/msgview/msgview.go b/commands/msgview/msgview.go index 0f0108e..fb32d8e 100644 --- a/commands/msgview/msgview.go +++ b/commands/msgview/msgview.go @@ -4,9 +4,7 @@ import ( "git.sr.ht/~rjarry/aerc/commands" ) -var ( - MessageViewCommands *commands.Commands -) +var MessageViewCommands *commands.Commands func register(cmd commands.Command) { if MessageViewCommands == nil { diff --git a/commands/msgview/save.go b/commands/msgview/save.go index f27a68c..993f427 100644 --- a/commands/msgview/save.go +++ b/commands/msgview/save.go @@ -129,7 +129,6 @@ func savePart( aerc *widgets.Aerc, params *saveParams, ) error { - if params.trailingSlash || isDirExists(path) { filename := generateFilename(pi.Part) path = filepath.Join(path, filename) @@ -137,7 +136,7 @@ func savePart( dir := filepath.Dir(path) if params.createDirs && dir != "" { - err := os.MkdirAll(dir, 0755) + err := os.MkdirAll(dir, 0o755) if err != nil { return err } @@ -177,7 +176,7 @@ func savePart( return nil } -//isDir returns true if path is a directory and exists +// isDir returns true if path is a directory and exists func isDirExists(path string) bool { pathinfo, err := os.Stat(path) if err != nil { @@ -189,14 +188,14 @@ func isDirExists(path string) bool { return false } -//pathExists returns true if path exists +// pathExists returns true if path exists func pathExists(path string) bool { _, err := os.Stat(path) return err == nil } -//isAbsPath returns true if path given is anchored to / or . or ~ +// isAbsPath returns true if path given is anchored to / or . or ~ func isAbsPath(path string) bool { if len(path) == 0 { return false diff --git a/commands/prompt.go b/commands/prompt.go index 1d2242c..8746bcf 100644 --- a/commands/prompt.go +++ b/commands/prompt.go @@ -2,8 +2,9 @@ package commands import ( "fmt" - "git.sr.ht/~rjarry/aerc/widgets" "strings" + + "git.sr.ht/~rjarry/aerc/widgets" ) type Prompt struct{} diff --git a/commands/set.go b/commands/set.go index 0259240..275f9e6 100644 --- a/commands/set.go +++ b/commands/set.go @@ -21,7 +21,6 @@ func init() { func (Set) Aliases() []string { return []string{"set"} - } func (Set) Complete(aerc *widgets.Aerc, args []string) []string { @@ -48,7 +47,6 @@ func SetCore(aerc *widgets.Aerc, args []string) error { new_file := ini.Empty() section, err := new_file.NewSection(category) - if err != nil { return nil } diff --git a/commands/terminal/terminal.go b/commands/terminal/terminal.go index c93f80e..edc8429 100644 --- a/commands/terminal/terminal.go +++ b/commands/terminal/terminal.go @@ -4,9 +4,7 @@ import ( "git.sr.ht/~rjarry/aerc/commands" ) -var ( - TerminalCommands *commands.Commands -) +var TerminalCommands *commands.Commands func register(cmd commands.Command) { if TerminalCommands == nil { diff --git a/config/bindings.go b/config/bindings.go index 1833244..fa9daa2 100644 --- a/config/bindings.go +++ b/config/bindings.go @@ -56,8 +56,8 @@ func MergeBindings(bindings ...*KeyBindings) *KeyBindings { } func (config AercConfig) MergeContextualBinds(baseBinds *KeyBindings, - contextType ContextType, reg string, bindCtx string) *KeyBindings { - + contextType ContextType, reg string, bindCtx string, +) *KeyBindings { bindings := baseBinds for _, contextualBind := range config.ContextualBinds { if contextualBind.ContextType != contextType { @@ -83,8 +83,8 @@ func (bindings *KeyBindings) Add(binding *Binding) { } func (bindings *KeyBindings) GetBinding( - input []KeyStroke) (BindingSearchResult, []KeyStroke) { - + input []KeyStroke, +) (BindingSearchResult, []KeyStroke) { incomplete := false // TODO: This could probably be a sorted list to speed things up // TODO: Deal with bindings that share a prefix @@ -165,9 +165,7 @@ func FormatKeyStrokes(keystrokes []KeyStroke) string { return sb.String() } -var ( - keyNames map[string]KeyStroke -) +var keyNames map[string]KeyStroke func ParseKeyStrokes(keystrokes string) ([]KeyStroke, error) { var strokes []KeyStroke diff --git a/config/config.go b/config/config.go index 75519ab..7e1261d 100644 --- a/config/config.go +++ b/config/config.go @@ -398,7 +398,7 @@ var searchDirs = buildDefaultDirs() func installTemplate(root, name string) error { var err error if _, err = os.Stat(root); os.IsNotExist(err) { - err = os.MkdirAll(root, 0755) + err = os.MkdirAll(root, 0o755) if err != nil { return err } @@ -413,7 +413,7 @@ func installTemplate(root, name string) error { if err != nil { return err } - err = ioutil.WriteFile(path.Join(root, name), data, 0644) + err = ioutil.WriteFile(path.Join(root, name), data, 0o644) if err != nil { return err } @@ -527,10 +527,9 @@ func (config *AercConfig) LoadConfig(file *ini.File) error { if err := validateBorderChars(uiSection, &uiSubConfig); err != nil { return err } - contextualUi := - UIConfigContext{ - UiConfig: uiSubConfig, - } + contextualUi := UIConfigContext{ + UiConfig: uiSubConfig, + } var index int if strings.Contains(sectionName, "~") { @@ -922,7 +921,6 @@ func LoadBindingSection(sec *ini.Section) (*KeyBindings, error) { } func (config *AercConfig) LoadBinds(binds *ini.File, baseName string, baseGroup **KeyBindings) error { - if sec, err := binds.GetSection(baseName); err == nil { binds, err := LoadBindingSection(sec) if err != nil { @@ -947,11 +945,10 @@ func (config *AercConfig) LoadBinds(binds *ini.File, baseName string, baseGroup return err } - contextualBind := - BindingConfigContext{ - Bindings: binds, - BindContext: baseName, - } + contextualBind := BindingConfigContext{ + Bindings: binds, + BindContext: baseName, + } var index int if strings.Contains(sectionName, "=") { @@ -1006,7 +1003,7 @@ func checkConfigPerms(filename string) error { perms := info.Mode().Perm() // group or others have read access - if perms&044 != 0 { + if perms&0o44 != 0 { fmt.Fprintf(os.Stderr, "The file %v has too open permissions.\n", filename) fmt.Fprintln(os.Stderr, "This is a security issue (it contains passwords).") fmt.Fprintf(os.Stderr, "To fix it, run `chmod 600 %v`\n", filename) @@ -1035,7 +1032,8 @@ func (ui *UIConfig) loadStyleSet(styleSetDirs []string) error { } func (config AercConfig) mergeContextualUi(baseUi UIConfig, - contextType ContextType, s string) UIConfig { + contextType ContextType, s string, +) UIConfig { for _, contextualUi := range config.ContextualUis { if contextualUi.ContextType != contextType { continue @@ -1078,7 +1076,8 @@ func (uiConfig UIConfig) GetStyleSelected(so StyleObject) tcell.Style { } func (uiConfig UIConfig) GetComposedStyle(base StyleObject, - styles []StyleObject) tcell.Style { + styles []StyleObject, +) tcell.Style { return uiConfig.style.Compose(base, styles) } diff --git a/config/style.go b/config/style.go index 71d39dc..d1fd557 100644 --- a/config/style.go +++ b/config/style.go @@ -265,7 +265,8 @@ func (ss StyleSet) Compose(so StyleObject, sos []StyleObject) tcell.Style { } func (ss StyleSet) ComposeSelected(so StyleObject, - sos []StyleObject) tcell.Style { + sos []StyleObject, +) tcell.Style { base := *ss.selected[so] styles := make([]*Style, len(sos)) for i, so := range sos { diff --git a/config/triggers.go b/config/triggers.go index daf4373..edaea45 100644 --- a/config/triggers.go +++ b/config/triggers.go @@ -12,8 +12,8 @@ import ( ) func (trig *TriggersConfig) ExecTrigger(triggerCmd string, - triggerFmt func(string) (string, error)) error { - + triggerFmt func(string) (string, error), +) error { if len(triggerCmd) == 0 { return errors.New("Trigger command empty") } @@ -34,7 +34,8 @@ func (trig *TriggersConfig) ExecTrigger(triggerCmd string, } func (trig *TriggersConfig) ExecNewEmail(account *AccountConfig, - conf *AercConfig, msg *models.MessageInfo) { + conf *AercConfig, msg *models.MessageInfo, +) { err := trig.ExecTrigger(trig.NewEmail, func(part string) (string, error) { formatstr, args, err := format.ParseMessageFormat( @@ -45,7 +46,8 @@ func (trig *TriggersConfig) ExecNewEmail(account *AccountConfig, format.Ctx{ FromAddress: account.From, AccountName: account.Name, - MsgInfo: msg}, + MsgInfo: msg, + }, ) if err != nil { return "", err diff --git a/lib/calendar/calendar.go b/lib/calendar/calendar.go index dbce6bc..ebe1b77 100644 --- a/lib/calendar/calendar.go +++ b/lib/calendar/calendar.go @@ -26,7 +26,6 @@ func (cr *Reply) AddOrganizer(o string) { // CreateReply parses a ics request and return a ics reply (RFC 2446, Section 3.2.3) func CreateReply(reader io.Reader, from *mail.Address, partstat string) (*Reply, error) { - cr := Reply{ MimeType: "text/calendar", Params: map[string]string{ diff --git a/lib/crypto/gpg/gpg.go b/lib/crypto/gpg/gpg.go index e545e1c..c73272a 100644 --- a/lib/crypto/gpg/gpg.go +++ b/lib/crypto/gpg/gpg.go @@ -37,7 +37,6 @@ func (m *Mail) ImportKeys(r io.Reader) error { } func (m *Mail) Encrypt(buf *bytes.Buffer, rcpts []string, signer string, decryptKeys openpgp.PromptFunction, header *mail.Header) (io.WriteCloser, error) { - return Encrypt(buf, header.Header.Header, rcpts, signer) } diff --git a/lib/crypto/gpg/gpgbin/encrypt.go b/lib/crypto/gpg/gpgbin/encrypt.go index e72ba14..31245a7 100644 --- a/lib/crypto/gpg/gpgbin/encrypt.go +++ b/lib/crypto/gpg/gpgbin/encrypt.go @@ -11,7 +11,7 @@ import ( // Encrypt runs gpg --encrypt [--sign] -r [recipient]. The default is to have // --trust-model always set func Encrypt(r io.Reader, to []string, from string) ([]byte, error) { - //TODO probably shouldn't have --trust-model always a default + // TODO probably shouldn't have --trust-model always a default args := []string{ "--armor", "--trust-model", "always", diff --git a/lib/crypto/pgp/pgp.go b/lib/crypto/pgp/pgp.go index 647b091..c305f06 100644 --- a/lib/crypto/pgp/pgp.go +++ b/lib/crypto/pgp/pgp.go @@ -31,10 +31,10 @@ var ( func (m *Mail) Init() error { logging.Infof("Initializing PGP keyring") - os.MkdirAll(path.Join(xdg.DataHome(), "aerc"), 0700) + os.MkdirAll(path.Join(xdg.DataHome(), "aerc"), 0o700) lockpath := path.Join(xdg.DataHome(), "aerc", "keyring.lock") - lockfile, err := os.OpenFile(lockpath, os.O_CREATE|os.O_EXCL, 0600) + lockfile, err := os.OpenFile(lockpath, os.O_CREATE|os.O_EXCL, 0o600) if err != nil { // TODO: Consider connecting to main process over IPC socket locked = false @@ -149,7 +149,7 @@ func (m *Mail) ImportKeys(r io.Reader) error { Keyring = append(Keyring, keys...) if locked { keypath := path.Join(xdg.DataHome(), "aerc", "keyring.asc") - keyfile, err := os.OpenFile(keypath, os.O_CREATE|os.O_APPEND, 0600) + keyfile, err := os.OpenFile(keypath, os.O_CREATE|os.O_APPEND, 0o600) if err != nil { return err } diff --git a/lib/format/format.go b/lib/format/format.go index cc9716d..0d14cb1 100644 --- a/lib/format/format.go +++ b/lib/format/format.go @@ -81,7 +81,8 @@ type Ctx struct { func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string, thisWeekTimeFmt string, thisYearTimeFmt string, ctx Ctx) ( - string, []interface{}, error) { + string, []interface{}, error, +) { retval := make([]byte, 0, len(format)) var args []interface{} @@ -289,10 +290,10 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string, } case 'Z': // calculate all flags - var readReplyFlag = "" - var delFlag = "" - var flaggedFlag = "" - var markedFlag = "" + readReplyFlag := "" + delFlag := "" + flaggedFlag := "" + markedFlag := "" seen := false recent := false answered := false @@ -390,7 +391,8 @@ handle_end_error: } func dummyIfZeroDate(date time.Time, format string, todayFormat string, - thisWeekFormat string, thisYearFormat string) string { + thisWeekFormat string, thisYearFormat string, +) string { if date.IsZero() { return strings.Repeat("?", len(format)) } diff --git a/lib/messageview.go b/lib/messageview.go index a1797d5..e0e86ea 100644 --- a/lib/messageview.go +++ b/lib/messageview.go @@ -62,10 +62,12 @@ type MessageStoreView struct { func NewMessageStoreView(messageInfo *models.MessageInfo, store *MessageStore, pgp crypto.Provider, decryptKeys openpgp.PromptFunction, - cb func(MessageView, error)) { - - msv := &MessageStoreView{messageInfo, store, - nil, nil, messageInfo.BodyStructure} + cb func(MessageView, error), +) { + msv := &MessageStoreView{ + messageInfo, store, + nil, nil, messageInfo.BodyStructure, + } if usePGP(messageInfo.BodyStructure) { store.FetchFull([]uint32{messageInfo.Uid}, func(fm *types.FullMessage) { @@ -117,7 +119,6 @@ func (msv *MessageStoreView) MessageDetails() *models.MessageDetails { } func (msv *MessageStoreView) FetchBodyPart(part []int, cb func(io.Reader)) { - if msv.message == nil { msv.messageStore.FetchBodyPart(msv.messageInfo.Uid, part, cb) return diff --git a/lib/msgstore.go b/lib/msgstore.go index b91cd82..bbaa70a 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -27,7 +27,7 @@ type MessageStore struct { bodyCallbacks map[uint32][]func(*types.FullMessage) headerCallbacks map[uint32][]func(*types.MessageInfo) - //marking + // marking marked map[uint32]struct{} lastMarked map[uint32]struct{} visualStartUid uint32 @@ -68,8 +68,8 @@ func NewMessageStore(worker *types.Worker, defaultSortCriteria []*types.SortCriterion, thread bool, clientThreads bool, clientThreadsDelay time.Duration, triggerNewEmail func(*models.MessageInfo), - triggerDirectoryChange func()) *MessageStore { - + triggerDirectoryChange func(), +) *MessageStore { if !dirInfo.Caps.Thread { clientThreads = true } @@ -102,8 +102,8 @@ func NewMessageStore(worker *types.Worker, } func (store *MessageStore) FetchHeaders(uids []uint32, - cb func(*types.MessageInfo)) { - + cb func(*types.MessageInfo), +) { // TODO: this could be optimized by pre-allocating toFetch and trimming it // at the end. In practice we expect to get most messages back in one frame. var toFetch []uint32 @@ -166,7 +166,6 @@ func (store *MessageStore) FetchFull(uids []uint32, cb func(*types.FullMessage)) } func (store *MessageStore) FetchBodyPart(uid uint32, part []int, cb func(io.Reader)) { - store.worker.PostAction(&types.FetchMessageBodyPart{ Uid: uid, Part: part, @@ -399,7 +398,6 @@ func (store *MessageStore) runThreadBuilder() { } } store.threadBuilderDebounce = time.AfterFunc(store.threadBuilderDelay, func() { - // temporarily deactiviate the selector in the message list by // setting SelectedUid to the MagicUid oldUid := store.SelectedUid() @@ -436,8 +434,8 @@ func (store *MessageStore) runThreadBuilder() { } func (store *MessageStore) Delete(uids []uint32, - cb func(msg types.WorkerMessage)) { - + cb func(msg types.WorkerMessage), +) { for _, uid := range uids { store.Deleted[uid] = nil } @@ -461,8 +459,8 @@ func (store *MessageStore) revertDeleted(uids []uint32) { } func (store *MessageStore) Copy(uids []uint32, dest string, createDest bool, - cb func(msg types.WorkerMessage)) { - + cb func(msg types.WorkerMessage), +) { if createDest { store.worker.PostAction(&types.CreateDirectory{ Directory: dest, @@ -477,8 +475,8 @@ func (store *MessageStore) Copy(uids []uint32, dest string, createDest bool, } func (store *MessageStore) Move(uids []uint32, dest string, createDest bool, - cb func(msg types.WorkerMessage)) { - + cb func(msg types.WorkerMessage), +) { for _, uid := range uids { store.Deleted[uid] = nil } @@ -505,8 +503,8 @@ func (store *MessageStore) Move(uids []uint32, dest string, createDest bool, } func (store *MessageStore) Flag(uids []uint32, flag models.Flag, - enable bool, cb func(msg types.WorkerMessage)) { - + enable bool, cb func(msg types.WorkerMessage), +) { store.worker.PostAction(&types.FlagMessages{ Enable: enable, Flag: flag, @@ -515,8 +513,8 @@ func (store *MessageStore) Flag(uids []uint32, flag models.Flag, } func (store *MessageStore) Answered(uids []uint32, answered bool, - cb func(msg types.WorkerMessage)) { - + cb func(msg types.WorkerMessage), +) { store.worker.PostAction(&types.AnsweredMessages{ Answered: answered, Uids: uids, @@ -524,7 +522,6 @@ func (store *MessageStore) Answered(uids []uint32, answered bool, } func (store *MessageStore) Uids() []uint32 { - if store.ThreadedView() && store.builder != nil { if uids := store.builder.Uids(); len(uids) > 0 { return uids @@ -608,13 +605,13 @@ func (store *MessageStore) checkMark() { } } -//IsMarked checks whether a MessageInfo has been marked +// IsMarked checks whether a MessageInfo has been marked func (store *MessageStore) IsMarked(uid uint32) bool { _, marked := store.marked[uid] return marked } -//ToggleVisualMark enters or leaves the visual marking mode +// ToggleVisualMark enters or leaves the visual marking mode func (store *MessageStore) ToggleVisualMark() { store.visualMarkMode = !store.visualMarkMode switch store.visualMarkMode { @@ -629,7 +626,7 @@ func (store *MessageStore) ToggleVisualMark() { } } -//ClearVisualMark leaves the visual marking mode and resets any marking +// ClearVisualMark leaves the visual marking mode and resets any marking func (store *MessageStore) ClearVisualMark() { store.resetMark() store.visualMarkMode = false @@ -793,7 +790,8 @@ func (store *MessageStore) PrevResult() { } func (store *MessageStore) ModifyLabels(uids []uint32, add, remove []string, - cb func(msg types.WorkerMessage)) { + cb func(msg types.WorkerMessage), +) { store.worker.PostAction(&types.ModifyLabels{ Uids: uids, Add: add, diff --git a/lib/oauthbearer.go b/lib/oauthbearer.go index 1030696..4954830 100644 --- a/lib/oauthbearer.go +++ b/lib/oauthbearer.go @@ -3,6 +3,7 @@ package lib import ( "context" "fmt" + "github.com/emersion/go-imap/client" "github.com/emersion/go-sasl" "golang.org/x/oauth2" diff --git a/lib/open.go b/lib/open.go index f395d13..c5d4b1c 100644 --- a/lib/open.go +++ b/lib/open.go @@ -29,7 +29,6 @@ func NewXDGOpen(filename string) *xdgOpen { errCh: errch, args: []string{filename}, } - } // SetArgs sets additional arguments to the open command prior to the filename diff --git a/lib/parse/hyperlinks.go b/lib/parse/hyperlinks.go index 7a00538..2087a55 100644 --- a/lib/parse/hyperlinks.go +++ b/lib/parse/hyperlinks.go @@ -8,8 +8,10 @@ import ( "strings" ) -var submatch = `(https?:\/\/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,10}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*))` -var httpRe = regexp.MustCompile("\"" + submatch + "\"" + "|" + "\\(" + submatch + "\\)" + "|" + "<" + submatch + ">" + "|" + submatch) +var ( + submatch = `(https?:\/\/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,10}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*))` + httpRe = regexp.MustCompile("\"" + submatch + "\"" + "|" + "\\(" + submatch + "\\)" + "|" + "<" + submatch + ">" + "|" + submatch) +) // HttpLinks searches a reader for a http link and returns a copy of the // reader and a slice with links. @@ -36,7 +38,7 @@ func HttpLinks(r io.Reader) (io.Reader, []string) { } results := []string{} - for link, _ := range linkMap { + for link := range linkMap { results = append(results, link) } diff --git a/lib/statusline/state.go b/lib/statusline/state.go index 54746fb..8384f20 100644 --- a/lib/statusline/state.go +++ b/lib/statusline/state.go @@ -32,10 +32,11 @@ type folderState struct { } func NewState(name string, multipleAccts bool, conf config.StatuslineConfig) *State { - return &State{separator: conf.Separator, - renderer: newRenderer(conf.RenderFormat, conf.DisplayMode), - acct: &accountState{Name: name, Multiple: multipleAccts}, - fldr: make(map[string]*folderState), + return &State{ + separator: conf.Separator, + renderer: newRenderer(conf.RenderFormat, conf.DisplayMode), + acct: &accountState{Name: name, Multiple: multipleAccts}, + fldr: make(map[string]*folderState), } } diff --git a/lib/structure_helpers_test.go b/lib/structure_helpers_test.go index f670735..a63825d 100644 --- a/lib/structure_helpers_test.go +++ b/lib/structure_helpers_test.go @@ -8,27 +8,26 @@ import ( ) func TestLib_FindAllNonMultipart(t *testing.T) { - testStructure := &models.BodyStructure{ MIMEType: "multipart", Parts: []*models.BodyStructure{ - &models.BodyStructure{}, - &models.BodyStructure{ + {}, + { MIMEType: "multipart", Parts: []*models.BodyStructure{ - &models.BodyStructure{}, - &models.BodyStructure{}, + {}, + {}, }, }, - &models.BodyStructure{}, + {}, }, } expected := [][]int{ - []int{1}, - []int{2, 1}, - []int{2, 2}, - []int{3}, + {1}, + {2, 1}, + {2, 2}, + {3}, } parts := lib.FindAllNonMultipart(testStructure, nil, nil) @@ -42,5 +41,4 @@ func TestLib_FindAllNonMultipart(t *testing.T) { t.Errorf("incorrect values; expected: %v, got: %v", expected[i], parts[i]) } } - } diff --git a/lib/templates/template.go b/lib/templates/template.go index 9c71c46..7254d49 100644 --- a/lib/templates/template.go +++ b/lib/templates/template.go @@ -19,7 +19,7 @@ import ( var version string -//SetVersion initializes the aerc version displayed in template functions +// SetVersion initializes the aerc version displayed in template functions func SetVersion(v string) { version = v } @@ -182,7 +182,7 @@ func findTemplate(templateName string, templateDirs []string) (string, error) { "Can't find template %q in any of %v ", templateName, templateDirs) } -//DummyData provides dummy data to test template validity +// DummyData provides dummy data to test template validity func DummyData() interface{} { from := &mail.Address{ Name: "John Doe", diff --git a/lib/ui/borders.go b/lib/ui/borders.go index 6a5e9dc..8d381b9 100644 --- a/lib/ui/borders.go +++ b/lib/ui/borders.go @@ -22,7 +22,8 @@ type Bordered struct { } func NewBordered( - content Drawable, borders uint, uiConfig *config.UIConfig) *Bordered { + content Drawable, borders uint, uiConfig *config.UIConfig, +) *Bordered { b := &Bordered{ borders: borders, content: content, diff --git a/lib/ui/context.go b/lib/ui/context.go index 7936f35..fc2104d 100644 --- a/lib/ui/context.go +++ b/lib/ui/context.go @@ -63,7 +63,8 @@ func (ctx *Context) SetCell(x, y int, ch rune, style tcell.Style) { } func (ctx *Context) Printf(x, y int, style tcell.Style, - format string, a ...interface{}) int { + format string, a ...interface{}, +) int { width, height := ctx.viewport.Size() if x >= width || y >= height { diff --git a/lib/ui/tab.go b/lib/ui/tab.go index fd49dfe..bcad23c 100644 --- a/lib/ui/tab.go +++ b/lib/ui/tab.go @@ -36,8 +36,10 @@ type Tab struct { uiConf *config.UIConfig } -type TabStrip Tabs -type TabContent Tabs +type ( + TabStrip Tabs + TabContent Tabs +) func NewTabs(uiConf *config.UIConfig) *Tabs { tabs := &Tabs{} diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go index 9d1de96..8f8f00d 100644 --- a/lib/ui/textinput.go +++ b/lib/ui/textinput.go @@ -59,7 +59,8 @@ func (ti *TextInput) Prompt(prompt string) *TextInput { } func (ti *TextInput) TabComplete( - tabcomplete func(s string) ([]string, string), d time.Duration) *TextInput { + tabcomplete func(s string) ([]string, string), d time.Duration, +) *TextInput { ti.tabcomplete = tabcomplete ti.completeDelay = d return ti diff --git a/lib/ui/ui.go b/lib/ui/ui.go index b65c06a..1f618a6 100644 --- a/lib/ui/ui.go +++ b/lib/ui/ui.go @@ -19,7 +19,6 @@ type UI struct { } func Initialize(content DrawableInteractive) (*UI, error) { - screen, err := tcell.NewScreen() if err != nil { return nil, err diff --git a/models/models.go b/models/models.go index e7325d2..820bc3f 100644 --- a/models/models.go +++ b/models/models.go @@ -142,7 +142,7 @@ type BodyStructure struct { DispositionParams map[string]string } -//PartAtIndex returns the BodyStructure at the requested index +// PartAtIndex returns the BodyStructure at the requested index func (bs *BodyStructure) PartAtIndex(index []int) (*BodyStructure, error) { if len(index) == 0 { return bs, nil diff --git a/widgets/account-wizard.go b/widgets/account-wizard.go index 8b78dcd..5703288 100644 --- a/widgets/account-wizard.go +++ b/widgets/account-wizard.go @@ -506,7 +506,7 @@ func (wizard *AccountWizard) finish(tutorial bool) { } if !wizard.temporary { - f, err := os.OpenFile(accountsConf, os.O_WRONLY|os.O_CREATE, 0600) + f, err := os.OpenFile(accountsConf, os.O_WRONLY|os.O_CREATE, 0o600) if err != nil { wizard.errorFor(nil, err) return diff --git a/widgets/aerc.go b/widgets/aerc.go index 68144aa..90e7a9e 100644 --- a/widgets/aerc.go +++ b/widgets/aerc.go @@ -51,7 +51,8 @@ type Choice struct { func NewAerc(conf *config.AercConfig, crypto crypto.Provider, cmd func(cmd []string) error, complete func(cmd string) []string, cmdHistory lib.History, - deferLoop chan struct{}) *Aerc { + deferLoop chan struct{}, +) *Aerc { tabs := ui.NewTabs(&conf.Ui) statusbar := ui.NewStack(conf.Ui) diff --git a/widgets/compose.go b/widgets/compose.go index a4ed27c..b9528e0 100644 --- a/widgets/compose.go +++ b/widgets/compose.go @@ -65,8 +65,8 @@ type Composer struct { func NewComposer(aerc *Aerc, acct *AccountView, conf *config.AercConfig, acctConfig *config.AccountConfig, worker *types.Worker, template string, - h *mail.Header, orig models.OriginalMail) (*Composer, error) { - + h *mail.Header, orig models.OriginalMail, +) (*Composer, error) { if h == nil { h = new(mail.Header) } @@ -78,7 +78,6 @@ func NewComposer(aerc *Aerc, acct *AccountView, conf *config.AercConfig, } if fl != nil { h.SetAddressList("from", fl) - } } @@ -134,7 +133,6 @@ func NewComposer(aerc *Aerc, acct *AccountView, conf *config.AercConfig, } func (c *Composer) buildComposeHeader(aerc *Aerc, cmpl *completer.Completer) { - c.layout = aerc.conf.Compose.HeaderLayout c.editors = make(map[string]*headerEditor) c.focusable = make([]ui.MouseableDrawableInteractive, 0) @@ -540,7 +538,7 @@ func (c *Composer) Worker() *types.Worker { return c.worker } -//PrepareHeader finalizes the header, adding the value from the editors +// PrepareHeader finalizes the header, adding the value from the editors func (c *Composer) PrepareHeader() (*mail.Header, error) { for _, editor := range c.editors { editor.storeValue() @@ -594,7 +592,7 @@ func getRecipientsEmail(c *Composer) ([]string, error) { // return email addresses as string slice results := []string{} - for email, _ := range rcpts { + for email := range rcpts { results = append(results, email) } return results, nil @@ -933,7 +931,8 @@ type headerEditor struct { } func newHeaderEditor(name string, h *mail.Header, - uiConfig *config.UIConfig) *headerEditor { + uiConfig *config.UIConfig, +) *headerEditor { he := &headerEditor{ input: ui.NewTextInput("", uiConfig), name: name, @@ -944,8 +943,8 @@ func newHeaderEditor(name string, h *mail.Header, return he } -//extractHumanHeaderValue extracts the human readable string for key from the -//header. If a parsing error occurs the raw value is returned +// extractHumanHeaderValue extracts the human readable string for key from the +// header. If a parsing error occurs the raw value is returned func extractHumanHeaderValue(key string, h *mail.Header) string { var val string var err error @@ -964,16 +963,16 @@ func extractHumanHeaderValue(key string, h *mail.Header) string { return val } -//loadValue loads the value of he.name form the underlying header -//the value is decoded and meant for human consumption. -//decoding issues are ignored and return their raw values +// loadValue loads the value of he.name form the underlying header +// the value is decoded and meant for human consumption. +// decoding issues are ignored and return their raw values func (he *headerEditor) loadValue() { he.input.Set(extractHumanHeaderValue(he.name, he.header)) he.input.Invalidate() } -//storeValue writes the current state back to the underlying header. -//errors are ignored +// storeValue writes the current state back to the underlying header. +// errors are ignored func (he *headerEditor) storeValue() { val := he.input.String() switch strings.ToLower(he.name) { @@ -996,8 +995,8 @@ func (he *headerEditor) storeValue() { } } -//setValue overwrites the current value of the header editor and flushes it -//to the underlying header +// setValue overwrites the current value of the header editor and flushes it +// to the underlying header func (he *headerEditor) setValue(val string) { he.input.Set(val) he.storeValue() diff --git a/widgets/dirlist.go b/widgets/dirlist.go index 2047c30..984fc01 100644 --- a/widgets/dirlist.go +++ b/widgets/dirlist.go @@ -119,7 +119,6 @@ func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) { var dirs []string dirlist.worker.PostAction( &types.ListDirectories{}, func(msg types.WorkerMessage) { - switch msg := msg.(type) { case *types.Directory: dirs = append(dirs, msg.Dir.Name) diff --git a/widgets/dirtree.go b/widgets/dirtree.go index 1130329..1b7e2e1 100644 --- a/widgets/dirtree.go +++ b/widgets/dirtree.go @@ -383,7 +383,7 @@ func buildTree(node *types.Thread, stree [][]string, defaultUid uint32) { } } keys := make([]string, 0) - for key, _ := range m { + for key := range m { keys = append(keys, key) } sort.Strings(keys) diff --git a/widgets/exline.go b/widgets/exline.go index 4a4b655..e172dd8 100644 --- a/widgets/exline.go +++ b/widgets/exline.go @@ -20,8 +20,8 @@ type ExLine struct { func NewExLine(conf *config.AercConfig, cmd string, commit func(cmd string), finish func(), tabcomplete func(cmd string) ([]string, string), - cmdHistory lib.History) *ExLine { - + cmdHistory lib.History, +) *ExLine { input := ui.NewTextInput("", &conf.Ui).Prompt(":").Set(cmd) if conf.Ui.CompletionPopovers { input.TabComplete(tabcomplete, conf.Ui.CompletionDelay) @@ -41,8 +41,8 @@ func NewExLine(conf *config.AercConfig, cmd string, commit func(cmd string), fin } func NewPrompt(conf *config.AercConfig, prompt string, commit func(text string), - tabcomplete func(cmd string) ([]string, string)) *ExLine { - + tabcomplete func(cmd string) ([]string, string), +) *ExLine { input := ui.NewTextInput("", &conf.Ui).Prompt(prompt) if conf.Ui.CompletionPopovers { input.TabComplete(tabcomplete, conf.Ui.CompletionDelay) diff --git a/widgets/getpasswd.go b/widgets/getpasswd.go index e4cf07b..e6de75e 100644 --- a/widgets/getpasswd.go +++ b/widgets/getpasswd.go @@ -19,7 +19,8 @@ type GetPasswd struct { } func NewGetPasswd(title string, prompt string, conf *config.AercConfig, - cb func(string, error)) *GetPasswd { + cb func(string, error), +) *GetPasswd { getpasswd := &GetPasswd{ callback: cb, title: title, diff --git a/widgets/msglist.go b/widgets/msglist.go index 23eb410..1ddf46d 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -102,7 +102,7 @@ func (ml *MessageList) Draw(ctx *ui.Context) { } counter-- if counter > len(store.Uids())-1-ml.Scroll() { - //skip messages which are higher than the viewport + // skip messages which are higher than the viewport return nil } msg := store.Messages[t.Uid] diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index eec786c..be578b9 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -52,8 +52,8 @@ type PartSwitcher struct { } func NewMessageViewer(acct *AccountView, - conf *config.AercConfig, msg lib.MessageView) *MessageViewer { - + conf *config.AercConfig, msg lib.MessageView, +) *MessageViewer { hf := HeaderLayoutFilter{ layout: HeaderLayout(conf.Viewer.HeaderLayout), keep: func(msg *models.MessageInfo, header string) bool { @@ -178,8 +178,8 @@ func fmtHeader(msg *models.MessageInfo, header string, timefmt string) string { func enumerateParts(acct *AccountView, conf *config.AercConfig, msg lib.MessageView, body *models.BodyStructure, - index []int) ([]*PartViewer, error) { - + index []int, +) ([]*PartViewer, error) { var parts []*PartViewer for i, part := range body.Parts { curindex := append(index, i+1) @@ -205,8 +205,8 @@ func enumerateParts(acct *AccountView, conf *config.AercConfig, } func createSwitcher(acct *AccountView, switcher *PartSwitcher, - conf *config.AercConfig, msg lib.MessageView) error { - + conf *config.AercConfig, msg lib.MessageView, +) error { var err error switcher.selected = -1 switcher.showHeaders = conf.Viewer.ShowHeaders @@ -530,8 +530,8 @@ type PartViewer struct { func NewPartViewer(acct *AccountView, conf *config.AercConfig, msg lib.MessageView, part *models.BodyStructure, - index []int) (*PartViewer, error) { - + index []int, +) (*PartViewer, error) { var ( filter *exec.Cmd pager *exec.Cmd @@ -634,7 +634,7 @@ func (pv *PartViewer) attemptCopy() { return } if pv.filter != nil { - pv.copyFilterOutToPager() //delayed until we write to the sink + pv.copyFilterOutToPager() // delayed until we write to the sink } go func() { defer logging.PanicHandler() diff --git a/widgets/scrollable.go b/widgets/scrollable.go index 0e8bb5a..f478f85 100644 --- a/widgets/scrollable.go +++ b/widgets/scrollable.go @@ -64,5 +64,4 @@ func (s *Scrollable) EnsureScroll(selectingIdx int) { if s.scroll > maxScroll { s.scroll = maxScroll } - } diff --git a/widgets/selector.go b/widgets/selector.go index ea1dd97..71224c9 100644 --- a/widgets/selector.go +++ b/widgets/selector.go @@ -176,7 +176,8 @@ type SelectorDialog struct { } func NewSelectorDialog(title string, prompt string, options []string, focus int, - uiConfig *config.UIConfig, cb func(string, error)) *SelectorDialog { + uiConfig *config.UIConfig, cb func(string, error), +) *SelectorDialog { sd := &SelectorDialog{ callback: cb, title: title, diff --git a/widgets/terminal.go b/widgets/terminal.go index e499e3e..962b02e 100644 --- a/widgets/terminal.go +++ b/widgets/terminal.go @@ -82,8 +82,7 @@ func init() { keyMap[tcell.KeyPgUp] = directKey(vterm.KeyPageUp) keyMap[tcell.KeyPgDn] = directKey(vterm.KeyPageDown) for i := 0; i < 64; i++ { - keyMap[tcell.Key(int(tcell.KeyF1)+i)] = - directKey(vterm.Key(int(vterm.KeyFunction0) + i + 1)) + keyMap[tcell.Key(int(tcell.KeyF1)+i)] = directKey(vterm.Key(int(vterm.KeyFunction0) + i + 1)) } keyMap[tcell.KeyTAB] = directKey(vterm.KeyTab) keyMap[tcell.KeyESC] = directKey(vterm.KeyEscape) @@ -302,7 +301,6 @@ func (term *Terminal) Draw(ctx *ui.Context) { term.damageMutex.Lock() for _, rect := range term.damage { for x := rect.StartCol(); x < rect.EndCol() && x < ctx.Width(); x += 1 { - for y := rect.StartRow(); y < rect.EndRow() && y < ctx.Height(); y += 1 { coords := coords{x, y} @@ -472,8 +470,8 @@ func (term *Terminal) onDamage(rect *vterm.Rect) int { } func (term *Terminal) onMoveCursor(old *vterm.Pos, - pos *vterm.Pos, visible bool) int { - + pos *vterm.Pos, visible bool, +) int { rows, cols, _ := pty.Getsize(term.pty) if pos.Row() >= rows || pos.Col() >= cols { return 1 diff --git a/worker/imap/connect.go b/worker/imap/connect.go index 5f8cd1c..bfd95d8 100644 --- a/worker/imap/connect.go +++ b/worker/imap/connect.go @@ -16,7 +16,6 @@ import ( // selects the default inbox. If no error is returned, the imap client will be // in the imap.SelectedState. func (w *IMAPWorker) connect() (*client.Client, error) { - var ( conn *net.TCPConn err error @@ -98,8 +97,7 @@ func (w *IMAPWorker) connect() (*client.Client, error) { // but a valid connection is eventually returned, ensure that it is properly // closed. func newTCPConn(addr string, timeout time.Duration) (*net.TCPConn, error) { - - var errTCPTimeout = fmt.Errorf("tcp connection timeout") + errTCPTimeout := fmt.Errorf("tcp connection timeout") type tcpConn struct { conn *net.TCPConn diff --git a/worker/imap/fetch.go b/worker/imap/fetch.go index 6ef0bac..b6a5509 100644 --- a/worker/imap/fetch.go +++ b/worker/imap/fetch.go @@ -16,7 +16,8 @@ import ( ) func (imapw *IMAPWorker) handleFetchMessageHeaders( - msg *types.FetchMessageHeaders) { + msg *types.FetchMessageHeaders, +) { toFetch := msg.Uids if imapw.config.cacheEnabled && imapw.cache != nil { toFetch = imapw.getCachedHeaders(msg) @@ -76,8 +77,8 @@ func (imapw *IMAPWorker) handleFetchMessageHeaders( } func (imapw *IMAPWorker) handleFetchMessageBodyPart( - msg *types.FetchMessageBodyPart) { - + msg *types.FetchMessageBodyPart, +) { logging.Infof("Fetching message %d part: %v", msg.Uid, msg.Part) var partHeaderSection imap.BodySectionName @@ -146,8 +147,8 @@ func (imapw *IMAPWorker) handleFetchMessageBodyPart( } func (imapw *IMAPWorker) handleFetchFullMessages( - msg *types.FetchFullMessages) { - + msg *types.FetchFullMessages, +) { logging.Infof("Fetching full messages: %v", msg.Uids) section := &imap.BodySectionName{} items := []imap.FetchItem{ @@ -205,8 +206,8 @@ func (imapw *IMAPWorker) handleFetchMessageFlags(msg *types.FetchMessageFlags) { func (imapw *IMAPWorker) handleFetchMessages( msg types.WorkerMessage, uids []uint32, items []imap.FetchItem, - procFunc func(*imap.Message) error) { - + procFunc func(*imap.Message) error, +) { messages := make(chan *imap.Message) done := make(chan error) diff --git a/worker/imap/list.go b/worker/imap/list.go index 51f4d3e..67d4c33 100644 --- a/worker/imap/list.go +++ b/worker/imap/list.go @@ -79,5 +79,4 @@ func (imapw *IMAPWorker) handleSearchDirectory(msg *types.SearchDirectory) { Message: types.RespondTo(msg), Uids: uids, }, nil) - } diff --git a/worker/imap/movecopy.go b/worker/imap/movecopy.go index f1f2b45..1d25c08 100644 --- a/worker/imap/movecopy.go +++ b/worker/imap/movecopy.go @@ -38,7 +38,6 @@ func (imapw *IMAPWorker) handleAppendMessage(msg *types.AppendMessage) { Reader: msg.Reader, Length: msg.Length, }); err != nil { - imapw.worker.PostMessage(&types.Error{ Message: types.RespondTo(msg), Error: err, diff --git a/worker/imap/observer.go b/worker/imap/observer.go index 448128c..866fac6 100644 --- a/worker/imap/observer.go +++ b/worker/imap/observer.go @@ -140,7 +140,8 @@ func (o *observer) DelayedReconnect() error { func (o *observer) emit(errMsg string) { o.log("disconnect done->") o.worker.PostMessage(&types.Done{ - Message: types.RespondTo(&types.Disconnect{})}, nil) + Message: types.RespondTo(&types.Disconnect{}), + }, nil) o.log("connection error->") o.worker.PostMessage(&types.ConnError{ Error: fmt.Errorf(errMsg), diff --git a/worker/imap/open.go b/worker/imap/open.go index 2d76f43..7abebea 100644 --- a/worker/imap/open.go +++ b/worker/imap/open.go @@ -25,8 +25,8 @@ func (imapw *IMAPWorker) handleOpenDirectory(msg *types.OpenDirectory) { } func (imapw *IMAPWorker) handleFetchDirectoryContents( - msg *types.FetchDirectoryContents) { - + msg *types.FetchDirectoryContents, +) { logging.Infof("Fetching UID list") searchCriteria, err := parseSearch(msg.FilterCriteria) @@ -88,7 +88,8 @@ var sortFieldMap sortFieldMapT = sortFieldMapT{ } func translateSortCriterions( - cs []*types.SortCriterion) []sortthread.SortCriterion { + cs []*types.SortCriterion, +) []sortthread.SortCriterion { result := make([]sortthread.SortCriterion, 0, len(cs)) for _, c := range cs { if f, ok := sortFieldMap[c.Field]; ok { @@ -99,7 +100,8 @@ func translateSortCriterions( } func (imapw *IMAPWorker) handleDirectoryThreaded( - msg *types.FetchDirectoryThreaded) { + msg *types.FetchDirectoryThreaded, +) { logging.Infof("Fetching threaded UID list") searchCriteria, err := parseSearch(msg.FilterCriteria) diff --git a/worker/lib/parse.go b/worker/lib/parse.go index bdd927f..d92eeda 100644 --- a/worker/lib/parse.go +++ b/worker/lib/parse.go @@ -46,7 +46,7 @@ func FetchEntityPartReader(e *message.Entity, index []int) (io.Reader, error) { return nil, fmt.Errorf("FetchEntityPartReader: unexpected code reached") } -//TODO: the UI doesn't seem to like readers which aren't buffers +// TODO: the UI doesn't seem to like readers which aren't buffers func bufReader(e *message.Entity) (io.Reader, error) { var buf bytes.Buffer if _, err := io.Copy(&buf, e.Body); err != nil { @@ -157,7 +157,7 @@ func parseEnvelope(h *mail.Header) (*models.Envelope, error) { } msgID, err := h.MessageID() if err != nil { - //proper parsing failed, so fall back to whatever is there + // proper parsing failed, so fall back to whatever is there msgID, err = h.Text("message-id") if err != nil { return nil, err diff --git a/worker/lib/search.go b/worker/lib/search.go index c7d3bee..dc29a66 100644 --- a/worker/lib/search.go +++ b/worker/lib/search.go @@ -97,8 +97,8 @@ func Search(messages []RawMessage, criteria *searchCriteria) ([]uint32, error) { // searchMessage executes the search criteria for the given RawMessage, // returns true if search succeeded func searchMessage(message RawMessage, criteria *searchCriteria, - parts MsgParts) (bool, error) { - + parts MsgParts, +) (bool, error) { // setup parts of the message to use in the search // this is so that we try to minimise reading unnecessary parts var ( diff --git a/worker/lib/sort.go b/worker/lib/sort.go index 958cbed..3bfd7d4 100644 --- a/worker/lib/sort.go +++ b/worker/lib/sort.go @@ -10,7 +10,8 @@ import ( ) func Sort(messageInfos []*models.MessageInfo, - criteria []*types.SortCriterion) ([]uint32, error) { + criteria []*types.SortCriterion, +) ([]uint32, error) { // loop through in reverse to ensure we sort by non-primary fields first for i := len(criteria) - 1; i >= 0; i-- { criterion := criteria[i] @@ -62,7 +63,8 @@ func Sort(messageInfos []*models.MessageInfo, } func sortAddresses(messageInfos []*models.MessageInfo, criterion *types.SortCriterion, - getValue func(*models.MessageInfo) []*mail.Address) { + getValue func(*models.MessageInfo) []*mail.Address, +) { sortSlice(criterion, messageInfos, func(i, j int) bool { addressI, addressJ := getValue(messageInfos[i]), getValue(messageInfos[j]) var firstI, firstJ *mail.Address @@ -92,7 +94,8 @@ func sortAddresses(messageInfos []*models.MessageInfo, criterion *types.SortCrit } func sortFlags(messageInfos []*models.MessageInfo, criterion *types.SortCriterion, - testFlag models.Flag) { + testFlag models.Flag, +) { var slice []*boolStore for _, msgInfo := range messageInfos { flagPresent := false @@ -116,7 +119,8 @@ func sortFlags(messageInfos []*models.MessageInfo, criterion *types.SortCriterio } func sortStrings(messageInfos []*models.MessageInfo, criterion *types.SortCriterion, - getValue func(*models.MessageInfo) string) { + getValue func(*models.MessageInfo) string, +) { var slice []*lexiStore for _, msgInfo := range messageInfos { slice = append(slice, &lexiStore{ diff --git a/worker/maildir/container.go b/worker/maildir/container.go index 83f850a..1d971a4 100644 --- a/worker/maildir/container.go +++ b/worker/maildir/container.go @@ -35,8 +35,10 @@ func NewContainer(dir string, maildirpp bool) (*Container, error) { if !s.IsDir() { return nil, fmt.Errorf("Given maildir '%s' not a directory", dir) } - return &Container{dir: dir, uids: uidstore.NewStore(), - recentUIDS: make(map[uint32]struct{}), maildirpp: maildirpp}, nil + return &Container{ + dir: dir, uids: uidstore.NewStore(), + recentUIDS: make(map[uint32]struct{}), maildirpp: maildirpp, + }, nil } // ListFolders returns a list of maildir folders in the container @@ -183,7 +185,8 @@ func (c *Container) DeleteAll(d maildir.Dir, uids []uint32) ([]uint32, error) { } func (c *Container) CopyAll( - dest maildir.Dir, src maildir.Dir, uids []uint32) error { + dest maildir.Dir, src maildir.Dir, uids []uint32, +) error { for _, uid := range uids { if err := c.copyMessage(dest, src, uid); err != nil { return fmt.Errorf("could not copy message %d: %v", uid, err) @@ -193,7 +196,8 @@ func (c *Container) CopyAll( } func (c *Container) copyMessage( - dest maildir.Dir, src maildir.Dir, uid uint32) error { + dest maildir.Dir, src maildir.Dir, uid uint32, +) error { key, ok := c.uids.GetKey(uid) if !ok { return fmt.Errorf("could not find key for message id %d", uid) diff --git a/worker/maildir/search.go b/worker/maildir/search.go index b8e91df..7a8ba0e 100644 --- a/worker/maildir/search.go +++ b/worker/maildir/search.go @@ -111,7 +111,8 @@ func (w *Worker) search(criteria *searchCriteria) ([]uint32, error) { // Execute the search criteria for the given key, returns true if search succeeded func (w *Worker) searchKey(key uint32, criteria *searchCriteria, - parts MsgParts) (bool, error) { + parts MsgParts, +) (bool, error) { message, err := w.c.Message(*w.selected, key) if err != nil { return false, err diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go index d60315b..838a3b7 100644 --- a/worker/maildir/worker.go +++ b/worker/maildir/worker.go @@ -406,7 +406,8 @@ func (w *Worker) handleOpenDirectory(msg *types.OpenDirectory) error { } func (w *Worker) handleFetchDirectoryContents( - msg *types.FetchDirectoryContents) error { + msg *types.FetchDirectoryContents, +) error { var ( uids []uint32 err error @@ -482,7 +483,8 @@ func (w *Worker) handleRemoveDirectory(msg *types.RemoveDirectory) error { } func (w *Worker) handleFetchMessageHeaders( - msg *types.FetchMessageHeaders) error { + msg *types.FetchMessageHeaders, +) error { for _, uid := range msg.Uids { info, err := w.msgInfoFromUid(uid) if err != nil { @@ -500,8 +502,8 @@ func (w *Worker) handleFetchMessageHeaders( } func (w *Worker) handleFetchMessageBodyPart( - msg *types.FetchMessageBodyPart) error { - + msg *types.FetchMessageBodyPart, +) error { // get reader m, err := w.c.Message(*w.selected, msg.Uid) if err != nil { diff --git a/worker/mbox/create.go b/worker/mbox/create.go index 7c4d9f7..266398a 100644 --- a/worker/mbox/create.go +++ b/worker/mbox/create.go @@ -8,7 +8,6 @@ import ( ) func createMailboxContainer(path string) (*mailboxContainer, error) { - file, err := os.Open(path) if err != nil { return nil, err diff --git a/worker/mbox/worker.go b/worker/mbox/worker.go index 4c0a127..6ba886a 100644 --- a/worker/mbox/worker.go +++ b/worker/mbox/worker.go @@ -99,7 +99,8 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error { if !ok { w.folder = w.data.Create(w.name) w.worker.PostMessage(&types.Done{ - Message: types.RespondTo(&types.CreateDirectory{})}, nil) + Message: types.RespondTo(&types.CreateDirectory{}), + }, nil) } w.worker.PostMessage(&types.DirectoryInfo{ Info: w.data.DirectoryInfo(msg.Directory), @@ -338,7 +339,8 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error { if !ok { folder = w.data.Create(msg.Destination) w.worker.PostMessage(&types.Done{ - Message: types.RespondTo(&types.CreateDirectory{})}, nil) + Message: types.RespondTo(&types.CreateDirectory{}), + }, nil) } if err := folder.Append(msg.Reader, msg.Flags); err != nil { diff --git a/worker/notmuch/lib/database.go b/worker/notmuch/lib/database.go index 801f122..ac1a28e 100644 --- a/worker/notmuch/lib/database.go +++ b/worker/notmuch/lib/database.go @@ -61,9 +61,9 @@ func (db *DB) connect(writable bool) error { return nil } -//withConnection calls callback on the DB object, cleaning up upon return. -//the error returned is from the connection attempt, if not successful, -//or from the callback otherwise. +// withConnection calls callback on the DB object, cleaning up upon return. +// the error returned is from the connection attempt, if not successful, +// or from the callback otherwise. func (db *DB) withConnection(writable bool, cb func(*notmuch.DB) error) error { too_old := time.Now().After(db.lastOpenTime.Add(MAX_DB_AGE)) if db.db == nil || writable || too_old { @@ -104,8 +104,8 @@ func (db *DB) ListTags() ([]string, error) { return result, err } -//getQuery returns a query based on the provided query string. -//It also configures the query as specified on the worker +// getQuery returns a query based on the provided query string. +// It also configures the query as specified on the worker func (db *DB) newQuery(ndb *notmuch.DB, query string) (*notmuch.Query, error) { q := ndb.NewQuery(query) q.SetExcludeScheme(notmuch.EXCLUDE_ALL) @@ -225,7 +225,8 @@ func (db *DB) MsgTags(key string) ([]string, error) { } func (db *DB) msgModify(key string, - cb func(*notmuch.Message) error) error { + cb func(*notmuch.Message) error, +) error { err := db.withConnection(true, func(ndb *notmuch.DB) error { msg, err := ndb.FindMessage(key) if err != nil { @@ -281,7 +282,8 @@ func (db *DB) KeyFromUid(uid uint32) (string, bool) { } func (db *DB) enumerateThread(nt *notmuch.Threads, - valid map[string]struct{}) ([]*types.Thread, error) { + valid map[string]struct{}, +) ([]*types.Thread, error) { var res []*types.Thread var thread *notmuch.Thread for nt.Next(&thread) { @@ -292,7 +294,8 @@ func (db *DB) enumerateThread(nt *notmuch.Threads, } func (db *DB) makeThread(parent *types.Thread, msgs *notmuch.Messages, - valid map[string]struct{}) *types.Thread { + valid map[string]struct{}, +) *types.Thread { var lastSibling *types.Thread var msg *notmuch.Message for msgs.Next(&msg) { diff --git a/worker/notmuch/message.go b/worker/notmuch/message.go index e39fb17..fe82700 100644 --- a/worker/notmuch/message.go +++ b/worker/notmuch/message.go @@ -160,16 +160,16 @@ func (m *Message) Filename() (string, error) { return m.db.MsgFilename(m.key) } -//AddTag adds a single tag. -//Consider using *Message.ModifyTags for multiple additions / removals -//instead of looping over a tag array +// AddTag adds a single tag. +// Consider using *Message.ModifyTags for multiple additions / removals +// instead of looping over a tag array func (m *Message) AddTag(tag string) error { return m.ModifyTags([]string{tag}, nil) } -//RemoveTag removes a single tag. -//Consider using *Message.ModifyTags for multiple additions / removals -//instead of looping over a tag array +// RemoveTag removes a single tag. +// Consider using *Message.ModifyTags for multiple additions / removals +// instead of looping over a tag array func (m *Message) RemoveTag(tag string) error { return m.ModifyTags(nil, []string{tag}) } diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go index 36ef10f..2c80dbd 100644 --- a/worker/notmuch/worker.go +++ b/worker/notmuch/worker.go @@ -51,8 +51,10 @@ type worker struct { // NewWorker creates a new notmuch worker with the provided worker. func NewWorker(w *types.Worker) (types.Backend, error) { events := make(chan eventType, 20) - return &worker{w: w, - nmEvents: events}, nil + return &worker{ + w: w, + nmEvents: events, + }, nil } // Run starts the worker's message handling loop. @@ -92,6 +94,7 @@ func (w *worker) err(msg types.WorkerMessage, err error) { Error: err, }, nil) } + func (w *worker) handleMessage(msg types.WorkerMessage) error { if w.setupErr != nil { // only configure can recover from a config error, bail for everything else @@ -211,12 +214,14 @@ func (w *worker) handleListDirectories(msg *types.ListDirectories) error { } func (w *worker) gatherDirectoryInfo(name string, query string) ( - *types.DirectoryInfo, error) { + *types.DirectoryInfo, error, +) { return w.buildDirInfo(name, query, false) } func (w *worker) buildDirInfo(name string, query string, skipSort bool) ( - *types.DirectoryInfo, error) { + *types.DirectoryInfo, error, +) { count, err := w.db.QueryCountMessages(query) if err != nil { return nil, err @@ -254,8 +259,8 @@ func (w *worker) emitDirectoryInfo(name string) error { return nil } -//queryFromName either returns the friendly ID if aliased or the name itself -//assuming it to be the query +// queryFromName either returns the friendly ID if aliased or the name itself +// assuming it to be the query func (w *worker) queryFromName(name string) string { // try the friendly name first, if that fails assume it's a query q, ok := w.nameQueryMap[name] @@ -281,7 +286,8 @@ func (w *worker) handleOpenDirectory(msg *types.OpenDirectory) error { } func (w *worker) handleFetchDirectoryContents( - msg *types.FetchDirectoryContents) error { + msg *types.FetchDirectoryContents, +) error { w.currentSortCriteria = msg.SortCriteria err := w.emitDirectoryContents(msg) if err != nil { @@ -292,7 +298,8 @@ func (w *worker) handleFetchDirectoryContents( } func (w *worker) handleFetchDirectoryThreaded( - msg *types.FetchDirectoryThreaded) error { + msg *types.FetchDirectoryThreaded, +) error { // w.currentSortCriteria = msg.SortCriteria err := w.emitDirectoryThreaded(msg) if err != nil { @@ -303,7 +310,8 @@ func (w *worker) handleFetchDirectoryThreaded( } func (w *worker) handleFetchMessageHeaders( - msg *types.FetchMessageHeaders) error { + msg *types.FetchMessageHeaders, +) error { for _, uid := range msg.Uids { m, err := w.msgFromUid(uid) if err != nil { @@ -350,8 +358,8 @@ func (w *worker) msgFromUid(uid uint32) (*Message, error) { } func (w *worker) handleFetchMessageBodyPart( - msg *types.FetchMessageBodyPart) error { - + msg *types.FetchMessageBodyPart, +) error { m, err := w.msgFromUid(msg.Uid) if err != nil { logging.Errorf("could not get message %d: %v", msg.Uid, err) @@ -542,7 +550,8 @@ func (w *worker) loadQueryMap(acctConfig *config.AccountConfig) error { } func (w *worker) loadExcludeTags( - acctConfig *config.AccountConfig) []string { + acctConfig *config.AccountConfig, +) []string { raw, ok := acctConfig.Params["exclude-tags"] if !ok { // nothing to do @@ -598,7 +607,8 @@ func (w *worker) emitDirectoryThreaded(parent types.WorkerMessage) error { } func (w *worker) emitMessageInfo(m *Message, - parent types.WorkerMessage) error { + parent types.WorkerMessage, +) error { info, err := m.MessageInfo() if err != nil { return fmt.Errorf("could not get MessageInfo: %v", err) @@ -620,7 +630,8 @@ func (w *worker) emitLabelList() { } func (w *worker) sort(uids []uint32, - criteria []*types.SortCriterion) ([]uint32, error) { + criteria []*types.SortCriterion, +) ([]uint32, error) { if len(criteria) == 0 { return uids, nil } diff --git a/worker/types/thread.go b/worker/types/thread.go index 7c0cc5b..705b3e4 100644 --- a/worker/types/thread.go +++ b/worker/types/thread.go @@ -94,7 +94,7 @@ var ErrSkipThread = errors.New("skip this Thread") type NewThreadWalkFn func(t *Thread, level int, currentErr error) error -//Implement interface to be able to sort threads by newest (max UID) +// Implement interface to be able to sort threads by newest (max UID) type ByUID []*Thread func getMaxUID(thread *Thread) uint32 { @@ -113,9 +113,11 @@ func getMaxUID(thread *Thread) uint32 { func (s ByUID) Len() int { return len(s) } + func (s ByUID) Swap(i, j int) { s[i], s[j] = s[j], s[i] } + func (s ByUID) Less(i, j int) bool { maxUID_i := getMaxUID(s[i]) maxUID_j := getMaxUID(s[j]) diff --git a/worker/types/thread_test.go b/worker/types/thread_test.go index e79dddd..803f7ba 100644 --- a/worker/types/thread_test.go +++ b/worker/types/thread_test.go @@ -85,7 +85,7 @@ func TestNewWalk(t *testing.T) { prefix = append(prefix, " ") } } else if lvl < lastLevel { - //ascended, need to trim the prefix layers + // ascended, need to trim the prefix layers diff := lastLevel - lvl prefix = prefix[:len(prefix)-diff] } diff --git a/worker/types/worker.go b/worker/types/worker.go index 8f179df..9e24798 100644 --- a/worker/types/worker.go +++ b/worker/types/worker.go @@ -36,7 +36,6 @@ func (worker *Worker) setId(msg WorkerMessage) { } func (worker *Worker) PostAction(msg WorkerMessage, cb func(msg WorkerMessage)) { - worker.setId(msg) if resp := msg.InResponseTo(); resp != nil { @@ -52,8 +51,8 @@ func (worker *Worker) PostAction(msg WorkerMessage, cb func(msg WorkerMessage)) } func (worker *Worker) PostMessage(msg WorkerMessage, - cb func(msg WorkerMessage)) { - + cb func(msg WorkerMessage), +) { worker.setId(msg) if resp := msg.InResponseTo(); resp != nil {