1# Copyright (C) 2009-2020 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"""Autoresponder.""" 19 20from datetime import timedelta 21from enum import Enum 22from public import public 23from zope.interface import Attribute, Interface 24 25 26public(ALWAYS_REPLY=timedelta()) 27 28 29@public 30class Response(Enum): 31 # Your message was held for approval. 32 hold = 1 33 # Email commands, i.e. -request messages. 34 command = 2 35 # Messages to the list owner/administrator. 36 owner = 3 37 # Messages to the list's posting address. 38 postings = 4 39 40 41@public 42class ResponseAction(Enum): 43 # No automatic response. 44 none = 0 45 # Respond, but discard the original message. 46 respond_and_discard = 1 47 # Respond and continue processing the message. 48 respond_and_continue = 2 49 50 51@public 52class IAutoResponseRecord(Interface): 53 """An auto-response record. 54 55 Every time Mailman sends an automatic response to an address, on a 56 specific mailing list for a specific purpose, it records the response. To 57 limit the effects of blow back and other third party spam, Mailman will 58 only send a certain number of such automatic response per day. After the 59 maximum is reached, it will not send another such response to the same 60 address until the next day. 61 """ 62 address = Attribute("""The email address being sent the auto-response.""") 63 64 mailing_list = Attribute( 65 """The mailing list sending the auto-response.""") 66 67 response_type = Attribute("""The type of response sent.""") 68 69 70@public 71class IAutoResponseSet(Interface): 72 """Matching and setting auto-responses. 73 74 The `IAutoResponseSet` is contexted to a particular mailing list. 75 """ 76 77 def todays_count(address, response_type): 78 """The number of responses sent to an address today. 79 80 :param address: The address who is the recipient of the auto-response. 81 :type address: `IAddress` 82 :param response_type: The response type being sent. 83 :type response_type: `Response` 84 :return: The number of auto-responses already received by the user 85 today, of this type, from this mailing list. 86 :rtype: int 87 """ 88 89 def response_sent(address, response_type): 90 """Record the fact that another response is being sent to the address. 91 92 :param address: The address who is the recipient of the auto-response. 93 :type address: `IAddress` 94 :param response_type: The response type being sent. 95 :type response_type: `Response` 96 """ 97 98 def last_response(address, response_type): 99 """Record the fact that another response is being sent to the address. 100 101 :param address: The address who is the recipient of the auto-response. 102 :type address: `IAddress` 103 :param response_type: The response type being sent. 104 :type response_type: `Response` 105 :return: the last response recorded. 106 :rtype: `IAutoResponseRecord` 107 """ 108