From 63fa2da6d77ebbd3938c5483914a33f905d41800 Mon Sep 17 00:00:00 2001 From: Adam Chalkley Date: Wed, 18 Nov 2020 07:07:35 -0600 Subject: [PATCH] Minor "happy path" fix When checking to see if the requested "folder" is available on the account, handle the problem path first, explicitly. Leave successful result handling in the outer/unindented code path. --- cmd/check_imap_mailbox/main.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/cmd/check_imap_mailbox/main.go b/cmd/check_imap_mailbox/main.go index 4196c659..87bfd2d3 100644 --- a/cmd/check_imap_mailbox/main.go +++ b/cmd/check_imap_mailbox/main.go @@ -178,15 +178,7 @@ func main() { } cfg.Log.Debug().Str("mailbox", folder).Msg("Performing case-sensitive validation") - if textutils.InList(folder, mailboxesList, false) { - - // At this point we have confirmed that the requested folder to - // monitor is in the list of folders found on the server - cfg.Log.Debug().Str("mailbox", folder).Bool("found", true).Msg("") - validatedMailboxesList = append(validatedMailboxesList, folder) - - } else { - + if !textutils.InList(folder, mailboxesList, false) { cfg.Log.Error().Str("mailbox", folder).Bool("found", false).Msg("") nagiosExitState.LastError = fmt.Errorf("mailbox not found: %q", folder) nagiosExitState.ServiceOutput = fmt.Sprintf( @@ -194,9 +186,15 @@ func main() { nagios.StateCRITICALLabel, ) nagiosExitState.ExitStatusCode = nagios.StateCRITICALExitCode + return } + // At this point we have confirmed that the requested folder to + // monitor is in the list of folders found on the server + cfg.Log.Debug().Str("mailbox", folder).Bool("found", true).Msg("") + validatedMailboxesList = append(validatedMailboxesList, folder) + } // At this point we have created a list of validated mailboxes. Process