"Fossies" - the Fresh Open Source Software Archive

Member "mailman-3.3.7/src/mailman/handlers/acknowledge.py" (10 Nov 2022, 3376 Bytes) of package /linux/misc/mailman-3.3.7.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "acknowledge.py" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 3.3.5_vs_3.3.6.

    1 # Copyright (C) 1998-2022 by the Free Software Foundation, Inc.
    2 #
    3 # This file is part of GNU Mailman.
    4 #
    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.
    9 #
   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.
   14 #
   15 # You should have received a copy of the GNU General Public License along with
   16 # GNU Mailman.  If not, see <https://www.gnu.org/licenses/>.
   17 
   18 """Send an acknowledgment of the successful post to the sender.
   19 
   20 This only happens if the sender has set their AcknowledgePosts attribute.
   21 """
   22 
   23 from mailman.core.i18n import _
   24 from mailman.email.message import UserNotification
   25 from mailman.interfaces.handler import IHandler
   26 from mailman.interfaces.languages import ILanguageManager
   27 from mailman.interfaces.template import ITemplateLoader
   28 from mailman.utilities.string import expand, oneline
   29 from public import public
   30 from zope.component import getUtility
   31 from zope.interface import implementer
   32 
   33 
   34 @public
   35 @implementer(IHandler)
   36 class Acknowledge:
   37     """Send an acknowledgment."""
   38 
   39     name = 'acknowledge'
   40     description = _("""Send an acknowledgment of a posting.""")
   41 
   42     def process(self, mlist, msg, msgdata):
   43         """See `IHandler`."""
   44         # Extract the sender's address and find them in the user database
   45         sender = msgdata.get('original_sender', msg.sender)
   46         member = mlist.members.get_member(sender)
   47         if member is None or not member.acknowledge_posts:
   48             # Either the sender is not a member, in which case we can't know
   49             # whether they want an acknowlegment or not, or they are a member
   50             # who definitely does not want an acknowlegment.
   51             return
   52         # Okay, they are a member that wants an acknowledgment of their post.
   53         # Give them their original subject.  BAW: do we want to use the
   54         # decoded header?
   55         original_subject = msgdata.get(
   56             'origsubj', msg.get('subject', _('(no subject)')))
   57         # Get the user's preferred language.
   58         language_manager = getUtility(ILanguageManager)
   59         language = (language_manager[msgdata['lang']]
   60                     if 'lang' in msgdata
   61                     else member.preferred_language)
   62         # Now get the acknowledgement template.
   63         display_name = mlist.display_name                        # noqa: F841
   64         template = getUtility(ITemplateLoader).get(
   65             'list:user:notice:post', mlist,
   66             language=language.code)
   67         text = expand(template, mlist, dict(
   68             subject=oneline(original_subject, in_unicode=True),
   69             # For backward compatibility.
   70             list_name=mlist.list_name,
   71             ))
   72         # Craft the outgoing message, with all headers and attributes
   73         # necessary for general delivery.  Then enqueue it to the outgoing
   74         # queue.
   75         subject = _('${display_name} post acknowledgment')
   76         usermsg = UserNotification(sender, mlist.bounces_address,
   77                                    subject, text, language)
   78         usermsg.send(mlist)