summaryrefslogtreecommitdiff
path: root/cron/mailpasswds
blob: e7028ad8108cf9d358d4e66d66d67cf1f58cc62c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/local/bin/python 

"""Send password reminders for all lists to all users.

We accumulate users and their passwords, and use the last list to send a
single message to each user with their complete collection of passwords,
rather than sending a single message for each password."""

# This puppy should probably do lots of logging.

import sys, os, string

sys.path.append('/home/mailman/mailman/modules')

import maillist, mm_cfg, mm_message, mm_utils


users = {}				# user: (listname, password, url)

USERPASSWORDSTEXT = """
This is a reminder, sent out once a month, about your %s
mailing list memberships.  It includes your subscription info and
how to use it to change it or unsubscribe from a list.

Passwords for address %s:

%s
%s

The URLs have web-based interfaces for changing your membership status or
configuration for the respective list.

In addition to the URL web interfaces, you can also use email to make the
changes.  For more info, send a message to the '-request' address of the
list (for example, %s-request@%s) containing just the
word 'help' in the message body, and an email message will be sent to you
with instructions.

If you have questions, problems, comments, etc, send them to
mailman-owner@%s.  Thanks!
"""

def MailAllPasswords(list, users):
    """Send each user their complete list of passwords.

    The list can be any random one - it is only used for the message
    delivery mechanism."""
    subj = '%s maillist memberships reminder\n' % list.host_name
    for user, data in users.items():
	table = []
	for l, p, u in data:
	    if len(l) > 9:
		table.append("%s\n           %-10s  %s" % (l, p, u))
	    else:
		table.append("%-10s %-10s  %s" % (l, p, u))
	header = ("%-10s %-10s  %s\n%-10s %-10s  %s"
		  % ("List", "Password", "URL", "----", "--------", "---"))
	text = USERPASSWORDSTEXT % (list.host_name,
                                    user,
				    header,
				    string.join(table, "\n"),
				    l, list.host_name,
				    list.host_name)
   	list.SendTextToUser(subject = subj,
   			    recipient = user,
   			    text = text,
 			    sender = mm_cfg.MAILMAN_OWNER)

# Consolidate all the list/url/password info for each user, so we send
# the user a single message with the info for all their lists on this
# site.
list = None
for name in mm_utils.list_names():
    list = maillist.MailList(name)
    url = list.GetScriptURL('listinfo')
    list_name = list.real_name
    for user, password in list.passwords.items():
	if users.has_key(user):
	    users[user].append(list_name, password, url)
	else:
	    users[user] = [(list_name, password, url)]
    # Unlocking each list after identifying passwords, but before having
    # the consolidated list, means that there is a window for discrepancy
    # between the reported and actual password.  Big deal - if the user
    # changed the password in the meanwhile, they'll realize it, and it's
    # not worth the extra deadlock risk.
    list.Unlock()

if list:
    MailAllPasswords(list, users)