Add exclude and include
This commit is contained in:
parent
1357b67334
commit
b3ce1369ec
2 changed files with 9 additions and 2 deletions
|
@ -46,7 +46,8 @@ For each section, you can have two parameters :
|
|||
|-------------|-------------------------------------------------------------------------------------------|---------------|
|
||||
| `activate` | If yes, the mailing will be synchronised. `no` is equivalent to no section at all | `no` |
|
||||
| `list_name` | list name (without domain) on mailman. If not given, the section name is taken by default | section name |
|
||||
|
||||
| `include` | list of email addresses separated by commas to include in the mailing list | '' |
|
||||
| `exclude` | list of email addresses separated by commas to exclude from the mailing list | '' |
|
||||
### Example
|
||||
```
|
||||
[Re2o]
|
||||
|
@ -69,6 +70,7 @@ activate = yes
|
|||
[rezotage]
|
||||
activate = yes
|
||||
list_name = rezo-admin
|
||||
exclude = bureau@rezometz.org,autremail@rezometz.org
|
||||
```
|
||||
|
||||
3 mailings are generated : one which is adherents@rezometz.org with all adherents, one which is is rezo@rezometz.org with the group rezo and the last one is rezo-admin@rezometz.org with the group rezotage.
|
||||
|
|
|
@ -20,19 +20,24 @@ if changed:
|
|||
for section in config.sections():
|
||||
if section not in ["Re2o", "Mailman"] and config.getboolean(section, 'activate'):
|
||||
list_name = config.get(section, "list_name", fallback=section)
|
||||
include = config.get(section, "include", fallback="").split(",")
|
||||
exclude = config.get(section, "exclude", fallback="").split(",")
|
||||
response1 = requests.get(roster_url.format(mailman_url=mailman_url, list_name=list_name, domain=domain), auth=(mailman_username, mailman_password))
|
||||
if "entries" in response1.json():
|
||||
entries = response1.json()['entries']
|
||||
old_emails = [entry['email'] for entry in entries]
|
||||
new_emails = open(path + "/generated/ml.{}.list".format(section)).read().split("\n")
|
||||
emails_to_delete = [email for email in old_emails if email not in new_emails]
|
||||
emails_to_delete += exclude
|
||||
if emails_to_delete:
|
||||
print("[..] Deleting non members from list {}".format(list_name))
|
||||
response = requests.delete(roster_url.format(mailman_url=mailman_url, list_name=list_name, domain=domain), auth=(mailman_username,mailman_password), params={'emails': emails_to_delete})
|
||||
print("[OK] Non members where deleted from list {}".format(list_name))
|
||||
else:
|
||||
print("[INFO] No member to delete for list {}".format(list_name))
|
||||
emails_to_add = [email for email in new_emails if email not in old_emails]
|
||||
emails_to_add = [email for email in new_emails if (email not in old_emails and email not in exclude)]
|
||||
emails_to_add += include
|
||||
print(emails_to_add)
|
||||
if emails_to_add:
|
||||
print("[..] Adding members to list {}".format(list_name))
|
||||
with open(path + "/tmp", "w+") as f:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue