Skip to content

Commit 58af6af

Browse files
add example script to add bcc contacts
1 parent 1c97083 commit 58af6af

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

debian/changelog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ intelmq-mailgen (1.3.8-1) UNRELEASED; urgency=medium
22

33
* notifications:
44
* allow to pass an existing ticket number to mail_format_as_csv
5+
* allow to skip marking an email as sent (for re-using a ticket number)
6+
* add example script to add bcc contacts
57

68
-- Sebastian Wagner <swagner@intevation.de> Wed, 30 Apr 2025 17:30:43 +0200
79

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import types
2+
3+
bcc_contacts = {
4+
'Government': [{'recipients': ['internal-gov@cert.example'], 'format': 'CSV_inline'}],
5+
'Energy': [{'recipients': ['internal-energy@cert.example'], 'format': 'CSV_attachment'}],
6+
}
7+
8+
9+
def mail_format_as_csv_bcc(self, *args, **kwargs):
10+
notifications = self.old_mail_format_as_csv(*args, **kwargs)
11+
ticket_number = notifications[0].ticket
12+
13+
recipient_group = self.directive.aggregate_identifier.get('recipient_group')
14+
self.logger.debug(f'Recipient group {recipient_group} detected.')
15+
if recipient_group and recipient_group in bcc_contacts:
16+
for bcc_contact in bcc_contacts[recipient_group]:
17+
self.logger.debug(f"Sending email in bcc to {bcc_contact['recipients']} with format {bcc_contact['format']}'")
18+
notifications.extend(self.old_mail_format_as_csv(*args, **kwargs,
19+
envelope_tos=bcc_contact['recipients'],
20+
attach_event_data=bcc_contact['format'] == 'CSV_attachment',
21+
ticket_number=ticket_number,
22+
mark_as_sent=False))
23+
return notifications
24+
25+
26+
def create_notifications(context):
27+
# Replace the mail_format_as_csv method of the context
28+
context.old_mail_format_as_csv = context.mail_format_as_csv
29+
context.mail_format_as_csv = types.MethodType(mail_format_as_csv_bcc, context)
30+
31+
return None

0 commit comments

Comments
 (0)