Skip to content

Commit

Permalink
Add filtering on body
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed May 20, 2022
1 parent 57b2839 commit b593646
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions custom_components/o365/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class EventResponse(Enum):
CONF_ALIASES = "aliases"
CONF_ALT_AUTH_FLOW = "alt_auth_flow"
CONF_ALT_AUTH_METHOD = "alt_auth_method"
CONF_BODY_CONTAINS = "body_contains"
CONF_CACHE_PATH = "cache_path"
CONF_CALENDAR_NAME = "calendar_name"
CONF_CAL_IDS = "cal_ids"
Expand Down
2 changes: 2 additions & 0 deletions custom_components/o365/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
CONF_ACCOUNTS,
CONF_ALT_AUTH_FLOW,
CONF_ALT_AUTH_METHOD,
CONF_BODY_CONTAINS,
CONF_CAL_ID,
CONF_CHAT_SENSORS,
CONF_CLIENT_ID,
Expand Down Expand Up @@ -96,6 +97,7 @@
vol.Optional(CONF_HAS_ATTACHMENT): bool,
vol.Optional(CONF_IMPORTANCE): cv.string,
vol.Optional(CONF_IS_UNREAD): bool,
vol.Exclusive(CONF_BODY_CONTAINS, "body_*"): cv.string,
vol.Exclusive(CONF_SUBJECT_CONTAINS, "subject_*"): cv.string,
vol.Exclusive(CONF_SUBJECT_IS, "subject_*"): cv.string,
vol.Optional(CONF_DOWNLOAD_ATTACHMENTS): bool,
Expand Down
6 changes: 5 additions & 1 deletion custom_components/o365/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ATTR_SUMMARY,
CONF_ACCOUNT,
CONF_ACCOUNT_NAME,
CONF_BODY_CONTAINS,
CONF_CHAT_SENSORS,
CONF_DOWNLOAD_ATTACHMENTS,
CONF_EMAIL_SENSORS,
Expand Down Expand Up @@ -173,6 +174,7 @@ def __init__(self, conf, mail_folder):
"""Initialise the O365 Query."""
super().__init__(conf, mail_folder)

self._body_contains = conf.get(CONF_BODY_CONTAINS)
self._subject_contains = conf.get(CONF_SUBJECT_CONTAINS)
self._subject_is = conf.get(CONF_SUBJECT_IS)
self._has_attachment = conf.get(CONF_HAS_ATTACHMENT)
Expand All @@ -183,14 +185,16 @@ def __init__(self, conf, mail_folder):
self._query.order_by("receivedDateTime", ascending=False)

if (
self._subject_contains is not None
self._body_contains is not None
or self._subject_contains is not None
or self._subject_is is not None
or self._has_attachment is not None
or self._importance is not None
or self._email_from is not None
or self._is_unread is not None
):
self._add_to_query("ge", "receivedDateTime", dt.datetime(1900, 5, 1))
self._add_to_query("contains", "body", self._body_contains)
self._add_to_query("contains", "subject", self._subject_contains)
self._add_to_query("equals", "subject", self._subject_is)
self._add_to_query("equals", "hasAttachments", self._has_attachment)
Expand Down

0 comments on commit b593646

Please sign in to comment.