basic structure to represent and get default config values

This commit is contained in:
Johannes 2023-04-17 14:43:22 +02:00
parent f213f8eaba
commit 1b72e9afe7
2 changed files with 111 additions and 0 deletions

102
listconfig.py Normal file
View file

@ -0,0 +1,102 @@
from typing import Any, Dict, Iterable
from types import MathebauMLType
# source of which keys exist: https://docs.mailman3.org/projects/mailman/en/latest/src/mailman/rest/docs/listconf.html
_DEFAULTS: Dict[str, Any] = {
'acceptable_aliases': ['one@example.com', 'two@example.com'],
'accept_these_nonmembers': ['aperson@example.com'],
'admin_immed_notify': False,
'admin_notify_mchanges': True,
'administrivia': False,
'advertised': False,
'anonymous_list': True,
'archive_policy': 'never',
'archive_rendering_mode': 'text',
'autorespond_owner': 'respond_and_discard',
'autorespond_postings': 'respond_and_continue',
'autorespond_requests': 'respond_and_discard',
'autoresponse_grace_period': '45d',
'autoresponse_owner_text': 'the owner',
'autoresponse_postings_text': 'the mailing list',
'autoresponse_request_text': 'the robot',
'bounce_info_stale_after': '5d',
'bounce_notify_owner_on_bounce_increment': False,
'bounce_notify_owner_on_disable': True,
'bounce_notify_owner_on_removal': True,
'bounce_score_threshold': 5,
'bounce_you_are_disabled_warnings': 3,
'bounce_you_are_disabled_warnings_interval': '1d',
'forward_unrecognized_bounces_to': 'administrators',
'filter_extensions': ['.mkv'],
'filter_types': ['application/zip'],
'process_bounces': True,
'discard_these_nonmembers': ['^name_*bperson*@example.com'],
'display_name': 'Fnords',
'description': 'This is my mailing list',
'include_rfc2369_headers': False,
'info': 'This is the mailing list information',
'allow_list_posts': False,
'digest_send_periodic': False,
'digest_size_threshold': 10.5,
'digest_volume_frequency': 'yearly',
'digests_enabled': False,
'dmarc_mitigate_action': 'munge_from',
'dmarc_mitigate_unconditionally': False,
'dmarc_moderation_notice': 'Some moderation notice',
'dmarc_wrapped_message_text': 'some message text',
'personalize': 'none',
'preferred_language': 'ja',
'posting_pipeline': 'virgin',
'filter_content': True,
'first_strip_reply_to': True,
'gateway_to_mail': True,
'gateway_to_news': True,
'linked_newsgroup': 'my.group',
'newsgroup_moderation': 'moderated',
'nntp_prefix_subject_too': False,
'convert_html_to_plaintext': True,
'collapse_alternatives': False,
'reject_these_nonmembers': ['^b[hello]*@example.com'],
'hold_these_nonmembers': ['^re[gG]ex@example.com'],
'reply_goes_to_list': 'point_to_list',
'reply_to_address': 'bee@example.com',
'require_explicit_destination': False,
'member_roster_visibility': 'members',
'send_goodbye_message': False,
'send_welcome_message': False,
'subject_prefix': '[ant]',
'subscription_policy': 'moderate',
'unsubscription_policy': 'confirm',
'default_member_action': 'hold',
'default_nonmember_action': 'discard',
'moderator_password': 'password',
'max_message_size': '500',
'respond_to_post_requests': True,
'max_days_to_hold': '20',
'max_num_recipients': '20',
'pass_extensions': ['.pdf'],
'pass_types': ['image/jpeg'],
'filter_action': 'preserve',
'emergency': False
}
def get_single_default(key: str, listtype: MathebauMLType) -> Any:
"""Get the default value for a single key of a specific list type"""
val = _DEFAULTS.get(key)
if isinstance(val, dict):
return val.get(listtype)
return val
def get_config_keys() -> Iterable[str]:
"""Get names of all config attributes a mailinglist has."""
return _DEFAULTS.keys()
def get_default_config(listtype: MathebauMLType) -> Dict[str, Any]:
ret = dict()
for key in get_config_keys():
ret[key] = get_single_default(key, listtype)
return ret

9
types.py Normal file
View file

@ -0,0 +1,9 @@
import enum
class MathebauMLType(enum.Enum):
"""Different types of mailinglists at the mathebau."""
internPublic = 10
internPrivate = 15
broadPublic = 20
broadPrivate = 25