Coverage for gwcelery/email/signals.py: 100%
3 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-11-14 05:52 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-11-14 05:52 +0000
1"""Definitions of custom :doc:`Celery signals <celery:userguide/signals>`
2related to emails.
4These signals allow us to keep the VOEvent validation code decoupled from the
5email client itself.
6"""
7from celery.utils.dispatch import Signal
9email_received = Signal(
10 name='email_received', providing_args=('rfc822',))
11"""Fired whenever an email message is received.
13Parameters
14----------
15rfc822 : bytes
16 The :rfc:`822` contents of the message.
18Examples
19--------
21Register an email listener like this::
23 import email
24 import email.policy
26 @email_received.connect
27 def on_email_received(rfc822, **kwargs):
28 # Parse the RFC822 email.
29 message = email.message_from_bytes(rfc822, policy=email.policy.default)
30 # Print some of the message headers.
31 print('Subject:', message['Subject'])
32 print('From:', message['From'])
33 # Print the plain-text message body.
34 body = message.get_body(['plain']).get_content()
35 print(body)
36"""