Matthew Wegner
6bf42ad43d
Added Search Configuration to IMAP Sensor ( #19749 )
...
* Added Search Configuration to IMAP Sensor
The IMAP sensor currently only counts unread emails in a folder. By exposing the IMAP search parameter, the sensor can be used to count other results:
- All emails in an inbox
- Emails sent from an address
- Emails matching a subject
- Other advanced searches, especially with vendor-specific extensions. Gmail in particular supports X-GM-RAW, which lets you use any Gmail search directly ("emails with X label older than 14 days with", etc)
For my use case, I just wanted total emails in a folder, to show an "X/Y" counter for total/unread. I started work on a one-off script to throw the data in, but figured I'd try to extend Home Assistant more directly, especially since this IMAP sensor correctly handles servers that push data. This is my first Home Assistant contribution, so apologies in advance if something is out of place! It's a pretty minimal modification.
* Added Server Response Checking
Looks like no library exception is thrown, so check for response text before parsing out results (previous code just counts spaces, so an error actually returns a state value of 4).
* IMAP Warning -> Error, Count Initializes to None
IMAP search response parsing throws an error instead of a warning.
Email count initializes as None instead 0.
Email count is untouched in case of failure to parse response (i.e. if server is temporarily down or throwing errors, or maybe due to user updating their authentication/login/etc).
Fixed line length on error so it fits under 80 characters.
* Fixed Indent on Logger Error
Sorry about the churn! Python is pretty far from my daily-use language. (I did run this one through pep8, at least)
2019-01-19 21:37:02 +01:00
..
2019-01-13 09:38:22 -08:00
2018-11-23 14:51:26 +01:00
2018-08-24 16:37:30 +02:00
2018-10-01 08:55:43 +02:00
2018-12-27 10:01:57 -08:00
2018-11-15 10:23:46 -07:00
2018-10-01 08:55:43 +02:00
2018-08-27 22:00:20 +02:00
2019-01-16 09:08:23 +01:00
2018-10-01 08:55:43 +02:00
2018-10-01 08:55:43 +02:00
2018-09-02 15:51:15 +02:00
2018-10-14 17:12:34 +02:00
2018-10-02 07:32:03 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-10-01 08:55:43 +02:00
2019-01-08 09:14:16 -05:00
2019-01-03 14:41:18 +01:00
2018-08-24 16:37:30 +02:00
2018-10-10 12:17:11 +02:00
2018-08-24 16:37:30 +02:00
2019-01-10 17:24:35 -08:00
2018-08-24 16:37:30 +02:00
2018-10-13 10:23:00 +02:00
2018-10-10 12:17:11 +02:00
2019-01-03 11:35:13 -07:00
2018-10-11 10:55:22 +02:00
2018-11-21 20:41:53 -05:00
2018-08-24 16:37:30 +02:00
2018-12-18 15:23:53 +01:00
2018-10-01 08:55:43 +02:00
2018-08-24 16:37:30 +02:00
2018-12-07 11:08:41 +01:00
2018-10-01 08:55:43 +02:00
2018-11-04 09:50:00 +01:00
2018-08-24 16:37:30 +02:00
2018-10-01 08:55:43 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-12-19 08:18:40 +01:00
2019-01-06 20:52:55 +01:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-11-28 13:38:26 +01:00
2018-10-01 08:55:43 +02:00
2018-10-12 09:30:35 +02:00
2018-08-24 16:37:30 +02:00
2018-10-20 22:07:47 +02:00
2018-11-02 22:48:17 +01:00
2019-01-14 10:51:37 +01:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-10-01 08:55:43 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-10-10 23:52:45 +02:00
2018-09-16 01:17:47 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-12-14 13:25:28 +01:00
2018-11-12 16:10:28 +01:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-10-01 14:10:32 +02:00
2018-12-25 23:43:46 +01:00
2018-08-24 16:37:30 +02:00
2018-10-01 08:55:43 +02:00
2018-08-24 16:37:30 +02:00
2019-01-11 12:54:47 -08:00
2018-11-28 13:16:43 +01:00
2018-08-24 16:37:30 +02:00
2019-01-11 15:29:54 -08:00
2018-10-01 08:55:43 +02:00
2018-10-01 08:55:43 +02:00
2018-08-24 16:37:30 +02:00
2018-12-18 13:21:08 +01:00
2018-10-09 11:18:46 -06:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2019-01-09 19:38:19 -07:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2019-01-10 17:13:29 -08:00
2018-11-06 12:43:16 +01:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-12-12 16:11:18 +01:00
2018-12-16 11:14:36 +01:00
2018-10-11 07:43:15 +02:00
2018-08-24 16:37:30 +02:00
2018-12-29 21:01:47 +01:00
2018-10-04 14:02:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-11-01 10:46:11 +01:00
2018-12-09 23:32:48 +01:00
2019-01-15 13:39:43 +01:00
2018-08-29 21:13:01 +02:00
2018-10-10 13:46:03 +02:00
2018-08-24 16:37:30 +02:00
2018-09-29 21:22:24 +02:00
2019-01-08 20:15:12 -08:00
2019-01-01 16:25:57 +01:00
2018-12-25 10:40:21 +01:00
2018-08-24 16:37:30 +02:00
2018-10-10 12:17:11 +02:00
2018-12-14 14:51:13 +01:00
2018-08-24 16:37:30 +02:00
2018-10-01 08:55:43 +02:00
2018-11-22 09:45:40 +01:00
2019-01-16 10:59:54 -08:00
2019-01-19 21:37:02 +01:00
2019-01-08 23:31:39 +00:00
2018-10-01 08:55:43 +02:00
2018-09-26 08:56:23 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-12-20 22:52:43 +01:00
2018-08-24 16:37:30 +02:00
2019-01-10 16:27:34 -08:00
2018-08-26 21:25:39 +02:00
2018-08-24 16:37:30 +02:00
2018-10-15 03:29:36 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2019-01-10 17:43:31 -08:00
2018-12-25 23:47:19 +01:00
2018-10-20 15:30:10 +02:00
2018-08-24 16:37:30 +02:00
2018-10-28 13:46:28 +01:00
2018-08-24 16:37:30 +02:00
2018-12-31 06:24:52 -08:00
2018-08-24 16:37:30 +02:00
2019-01-01 14:21:02 +01:00
2018-08-24 16:37:30 +02:00
2018-11-13 23:41:58 +01:00
2018-10-29 23:22:47 +01:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-12-06 11:54:44 +01:00
2019-01-10 13:48:24 +01:00
2018-12-06 11:54:44 +01:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-10-17 18:42:39 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-10-01 14:44:11 +02:00
2018-12-06 11:54:44 +01:00
2019-01-12 13:51:01 -05:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2019-01-10 09:28:01 -08:00
2018-09-25 13:41:29 +02:00
2018-12-19 23:42:16 +01:00
2018-09-19 00:42:09 +02:00
2018-09-23 18:58:09 +02:00
2018-08-24 16:37:30 +02:00
2018-12-14 09:52:34 +01:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-19 22:29:08 +02:00
2018-08-24 16:37:30 +02:00
2018-10-11 09:52:13 +02:00
2018-12-30 00:07:48 +01:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-10-19 07:31:19 +02:00
2018-12-26 14:46:59 -05:00
2018-10-01 08:55:43 +02:00
2018-10-29 11:27:37 +01:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-12-13 16:40:56 +01:00
2018-11-18 18:35:36 -07:00
2019-01-11 14:59:31 -08:00
2019-01-11 09:51:41 -08:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-11-29 20:40:26 +01:00
2018-09-10 16:19:17 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2019-01-16 10:03:53 -08:00
2018-10-21 13:05:02 +02:00
2018-08-24 16:37:30 +02:00
2018-10-16 10:06:00 +02:00
2018-08-24 16:37:30 +02:00
2018-10-26 20:18:14 +02:00
2018-12-01 12:00:35 +01:00
2018-12-22 14:01:31 +01:00
2018-08-24 16:37:30 +02:00
2019-01-07 19:16:04 +01:00
2018-11-06 12:34:11 +01:00
2018-12-01 22:08:15 +01:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-10-01 08:55:43 +02:00
2018-12-12 19:07:06 +01:00
2018-10-09 22:37:50 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2019-01-06 19:20:19 +02:00
2018-08-24 16:37:30 +02:00
2019-01-11 10:47:53 -05:00
2018-10-01 08:55:43 +02:00
2018-08-24 16:37:30 +02:00
2019-01-18 15:02:27 +01:00
2018-08-24 16:37:30 +02:00
2018-11-28 13:16:43 +01:00
2018-08-24 16:37:30 +02:00
2018-12-18 15:48:06 +01:00
2018-11-08 19:19:30 +01:00
2018-09-18 15:55:10 +02:00
2018-10-01 08:55:43 +02:00
2018-12-06 11:54:44 +01:00
2018-08-24 16:37:30 +02:00
2018-07-18 10:54:54 +02:00
2018-02-28 19:31:38 -08:00
2018-08-24 16:37:30 +02:00
2018-11-11 17:48:44 +01:00
2018-09-20 08:45:16 +02:00
2018-10-13 14:31:53 +02:00
2018-08-24 16:37:30 +02:00
2018-12-28 10:28:40 +01:00
2019-01-07 19:16:04 +01:00
2018-08-24 16:37:30 +02:00
2018-09-14 13:31:08 -06:00
2018-08-26 21:25:39 +02:00
2019-01-11 08:48:36 +01:00
2018-10-25 23:15:20 +03:00
2018-08-24 16:37:30 +02:00
2018-10-01 08:55:43 +02:00
2018-12-23 13:13:49 -05:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-10-11 11:38:35 +02:00
2018-08-24 16:37:30 +02:00
2018-10-19 17:48:46 +02:00
2018-10-01 08:55:43 +02:00
2018-08-24 16:37:30 +02:00
2019-01-19 10:23:22 -08:00
2018-10-01 08:55:43 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-10-02 11:03:09 +02:00
2018-08-27 06:19:51 +02:00
2018-08-24 16:37:30 +02:00
2018-11-05 08:27:20 +01:00
2018-08-24 16:37:30 +02:00
2018-09-14 12:08:33 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-12-21 17:25:23 +00:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2019-01-08 09:54:22 +01:00
2018-09-18 15:51:22 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-11-13 21:00:21 +01:00
2018-10-01 08:55:43 +02:00
2018-08-27 15:05:36 +02:00
2018-11-30 19:07:42 +01:00
2018-08-24 16:37:30 +02:00
2018-10-01 08:55:43 +02:00
2018-11-29 06:04:12 -05:00
2018-11-12 11:09:39 +01:00
2018-08-24 16:37:30 +02:00
2018-10-01 08:55:43 +02:00
2018-09-13 09:48:17 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-10-01 08:55:43 +02:00
2018-08-24 16:37:30 +02:00
2018-11-01 14:10:43 +01:00
2018-08-24 16:37:30 +02:00
2019-01-04 18:25:37 +01:00
2018-12-05 18:19:30 +01:00
2018-09-20 11:31:05 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-08-24 16:37:30 +02:00
2018-10-16 14:58:25 +02:00