Module: check_mk
Branch: master
Commit: b6476a2e09c01909178d8ac7fe6bffc66c621a56
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b6476a2e09c019…
Author: Marcel Arentz <ma(a)mathias-kettner.de>
Date: Wed Feb 8 17:07:34 2017 +0100
4193 FIX check_mail: Fixed bug with fetching mails
Previously the active check was not able to handle response messages containing
more information than expected. Additionally the check was not closing the
connection afterwards, so the messages never have been deleted.
Change-Id: I92ace2716b15d31549d79f9160315fafade59dd0
---
.werks/4193 | 11 +++++++++++
active_checks/check_mail | 17 ++++++++++-------
2 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/.werks/4193 b/.werks/4193
new file mode 100644
index 0000000..511fa06
--- /dev/null
+++ b/.werks/4193
@@ -0,0 +1,11 @@
+Title: check_mail: Fixed bug with fetching mails
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.4.0i4
+Date: 1486569909
+Class: fix
+
+Previously the active check was not able to handle response messages containing
+more information than expected. Additionally the check was not closing the
+connection afterwards, so the messages never have been deleted.
diff --git a/active_checks/check_mail b/active_checks/check_mail
index a07861c..44f2751 100755
--- a/active_checks/check_mail
+++ b/active_checks/check_mail
@@ -245,8 +245,8 @@ def cleanup_mailbox():
for index in g_forwarded:
if fetch_proto == 'POP3':
if cleanup_messages == 'delete':
- response = g_M.dele(index)
- if response != "+OK":
+ response = g_M.dele(index+1)
+ if not response.startswith("+OK"):
raise Exception("Response from server: [%s]" % response)
else:
if cleanup_messages != 'delete':
@@ -398,11 +398,14 @@ def main():
if opt_debug:
imaplib.Debug = 4
- connect()
- if forward_ec:
- forward_to_ec(fetch_mails())
- else:
- bail_out(0, 'Successfully logged in to mailbox')
+ try:
+ connect()
+ if forward_ec:
+ forward_to_ec(fetch_mails())
+ else:
+ bail_out(0, 'Successfully logged in to mailbox')
+ finally:
+ close_mailbox()
socket.setdefaulttimeout(conn_timeout)