Skip to content

Commit f3bc57a

Browse files
authored
Merge branch 'develop' into backport/ZEN-35326.7x
2 parents 617e0d9 + fc80138 commit f3bc57a

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/Products/ZenEvents/MailProcessor.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import rfc822
2222
import calendar
2323
from datetime import tzinfo, timedelta, datetime
24+
from email import header
2425

2526

2627
from Products.ZenEvents.Event import Event
@@ -120,7 +121,8 @@ def process(self, messageStr):
120121
fromIp = None
121122
log.info('Hostname lookup failed for host: %s', fromHost)
122123

123-
subject = message.get('Subject').replace("\r","").replace("\n", "")
124+
raw_subject = message.get('Subject').replace("\r","").replace("\n", "")
125+
subject = header.decode_header(raw_subject)[0][0]
124126

125127
secs = self.getReceiveTime(message)
126128

@@ -132,7 +134,12 @@ def process(self, messageStr):
132134
payload = 'This is the default message'
133135
if message.is_multipart():
134136
for msg in message.get_payload():
135-
if msg.get_content_maintype() == 'text' or msg.get_content_type() == 'message/rfc822':
137+
if msg.is_multipart():
138+
for m in msg.get_payload():
139+
if m.get_content_maintype() == 'text' or m.get_content_type() == 'message/rfc822':
140+
payload = m.get_payload(decode=True)
141+
break
142+
elif msg.get_content_maintype() == 'text' or msg.get_content_type() == 'message/rfc822':
136143
payload = msg.get_payload(decode=True)
137144
break
138145
else:

src/Products/ZenModel/actions.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,17 +398,21 @@ def _encodeBody(self, body):
398398
plain_body = MIMEText(body.decode('ascii', 'ignore'))
399399
return plain_body
400400

401-
def _targetsByTz(self, notification, signal, targets):
401+
def _targetsByTz(self, notification, targets):
402402
"""
403403
Take timezone from user property to convert a event time in
404404
notification and also group targets emails by those timezones.
405405
"""
406406
tz_targets = {}
407407
targetsCopy = set(targets)
408-
for recipient in self._get_recipients_from_signal(notification, signal):
409-
if recipient.email in targets:
410-
tz_targets.setdefault(recipient.timezone, set()).add(recipient.email)
411-
targetsCopy.discard(recipient.email)
408+
for recipient in notification.recipients:
409+
if recipient['type'] in ['group', 'user']:
410+
guid = recipient['value']
411+
target_obj = self.guidManager.getObject(guid)
412+
if target_obj:
413+
if target_obj.email in targets and target_obj.timezone:
414+
tz_targets.setdefault(target_obj.timezone, set()).add(target_obj.email)
415+
targetsCopy.discard(target_obj.email)
412416
if targetsCopy: #some emails are not from users in the system
413417
tz = time.tzname[time.daylight] # get current timezone factoring in daylight saving
414418
tz_targets.setdefault(tz, set()).update(targetsCopy)
@@ -425,7 +429,7 @@ def _adjustToTimezone(self, millis, timezone):
425429
def executeBatch(self, notification, signal, targets):
426430
log.debug("Executing %s action for targets: %s", self.name, targets)
427431
self.setupAction(notification.dmd)
428-
tz_targets = self._targetsByTz(notification, signal, targets)
432+
tz_targets = self._targetsByTz(notification, targets)
429433
original_lst = signal.event.last_seen_time
430434
original_fst = signal.event.first_seen_time
431435
original_sct = signal.event.status_change_time

0 commit comments

Comments
 (0)