Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P29630
disable_list3.py
Active
Public
Actions
Authored by
Legoktm
on Jun 13 2022, 3:05 AM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Referenced Files
F35234032: disable_list3.py
Jun 13 2022, 3:05 AM
2022-06-13 03:05:05 (UTC+0)
Subscribers
None
#!/usr/bin/env python3
"""
Disables a Mailman3 mailing list
Copyright (C) 2021 Kunal Mehta <legoktm@debian.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
TODO: Support enabling a mailing list
"""
import
argparse
import
datetime
from
mailmanclient
import
Client
import
wmflib.config
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
"Disable a Mailman3 mailing list"
)
parser
.
add_argument
(
"listname"
,
help
=
"Mailing list name"
)
return
parser
.
parse_args
()
def
get_client
()
->
Client
:
cfg
=
wmflib
.
config
.
load_ini_config
(
"/etc/mailman3/mailman.cfg"
)
return
Client
(
"http://localhost:8001/3.1"
,
cfg
[
"webservice"
][
"admin_user"
],
cfg
[
"webservice"
][
"admin_pass"
]
)
def
main
():
args
=
parse_args
()
listname
=
args
.
listname
client
=
get_client
()
mlist
=
client
.
get_list
(
f
"{listname}@lists.wikimedia.org"
)
mlist
.
settings
[
"emergency"
]
=
True
mlist
.
settings
[
'default_member_action'
]
=
'discard'
mlist
.
settings
[
'default_nonmember_action'
]
=
'discard'
# TODO: not possible to disable subscription entirely (https://gitlab.com/mailman/mailman/-/issues/842)
# TODO: add a cronjob to periodically clear these out
mlist
.
settings
[
'subscription_policy'
]
=
'moderate'
new_desc
=
f
"[ARCHIVED] {mlist.settings['description']}"
mlist
.
settings
[
'description'
]
=
new_desc
cutoff
=
datetime
.
datetime
.
utcnow
()
-
datetime
.
timedelta
(
days
=
args
.
days
)
for
mlist
in
client
.
get_lists
():
for
message
in
mlist
.
held
:
hold_date
=
datetime
.
datetime
.
fromisoformat
(
message
.
hold_date
)
if
hold_date
<=
cutoff
:
if
args
.
dry_run
:
print
(
f
"Would have discarded {message.message_id} "
f
"from {message.sender} to {mlist.fqdn_listname}"
)
else
:
message
.
discard
()
print
(
f
"Discarded {message.message_id} "
f
"from {message.sender} to {mlist.fqdn_listname}"
)
if
__name__
==
"__main__"
:
main
()
Event Timeline
Legoktm
created this paste.
Jun 13 2022, 3:05 AM
2022-06-13 03:05:05 (UTC+0)
Log In to Comment