Merge branch 'alias' into 'master'
[mailman.git] / src / mailman / handlers / to_digest.py
blob0836d5b5e771f7181b48302887c6c74a2a05fa3f
1 # Copyright (C) 1998-2019 by the Free Software Foundation, Inc.
3 # This file is part of GNU Mailman.
5 # GNU Mailman is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option)
8 # any later version.
10 # GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 # more details.
15 # You should have received a copy of the GNU General Public License along with
16 # GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18 """Add the message to the list's current digest."""
20 import os
22 from mailman.app.digests import maybe_send_digest_now
23 from mailman.core.i18n import _
24 from mailman.interfaces.handler import IHandler
25 from mailman.utilities.mailbox import Mailbox
26 from public import public
27 from zope.interface import implementer
30 @public
31 @implementer(IHandler)
32 class ToDigest:
33 """Add the message to the digest, possibly sending it."""
35 name = 'to-digest'
36 description = _('Add the message to the digest, possibly sending it.')
38 def process(self, mlist, msg, msgdata):
39 """See `IHandler`."""
40 # Short-circuit if digests are not enabled or if this message already
41 # is a digest.
42 if not mlist.digests_enabled or msgdata.get('isdigest'):
43 return
44 # Open the mailbox that will be used to collect the current digest.
45 mailbox_path = os.path.join(mlist.data_path, 'digest.mmdf')
46 # Lock the mailbox and append the message.
47 with Mailbox(mailbox_path, create=True) as mbox:
48 mbox.add(msg)
49 maybe_send_digest_now(mlist)