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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
import string, os, sys
import mm_cfg, mm_message, mm_err
# Text for various messages:
POSTACKTEXT = '''
Your message entitled:
%s
was successfully received by %s.
'''
SUBSCRIBEACKTEXT = '''Welcome to the %s@%s mailing list!
If you ever want to unsubscribe or change your options (eg, switch to
or from digest mode), visit the web page:
%s
You can also make these adjustments via email - send a message to
%s-request@%s
with the text "help" in the subject or body, and you will get back a
message with instructions.
You must know your password to change your options or unsubscribe. It is:
%s
If you forget your password, don't worry, you will receive a monthly
reminder telling you what your password is, and how to unsubscribe or
change your options.
You may also have your password mailed to you automatically off of
the web page noted above.
To post to this list, send your email to:
%s
%s
%s
'''
USERPASSWORDTEXT = '''
This is a reminder of how to unsubscribe or change your configuration
for the mailing list "%s". You need to have your password for
these things. YOUR PASSWORD IS:
%s
To make changes, use this password on the web site:
%s
Questions or comments? Send mail to Mailman-owner@%s
'''
# We could abstract these two better...
class Deliverer:
# This method assumes the sender is list-admin if you don't give one.
def SendTextToUser(self, subject, text, recipient, sender=None):
if not sender:
sender = self.GetAdminEmail()
msg = mm_message.OutgoingMessage()
msg.SetSender(sender)
msg.SetHeader('Subject', subject, 1)
msg.SetBody(self.QuotePeriods(text))
self.DeliverToUser(msg, recipient)
# This method assumes the sender is the one given by the message.
def DeliverToUser(self, msg, recipient):
file = os.popen(mm_cfg.SENDMAIL_CMD % (msg.GetSender(), recipient),
'w')
try:
msg.headers.remove('\n')
except:
pass
if not msg.getheader('to'):
msg.headers.append('To: %s\n' % recipient)
msg.headers.append('Errors-To: %s\n' % self.GetAdminEmail())
file.write(string.join(msg.headers, '')+ '\n')
file.write(self.QuotePeriods(msg.body))
file.close()
def QuotePeriods(self, text):
return string.join(string.split(text, '\n.\n'), '\n .\n')
def DeliverToList(self, msg, recipients, header, footer, remove_to=0,
tmpfile_prefix = ""):
if not(len(recipients)):
return
to_list = string.join(recipients)
# If this is a digest, or we ask to remove them,
# Remove old To: headers. We're going to stick our own in there.
# Also skip: Sender, return-receipt-to, errors-to, return-path, reply-to,
# (precidence, and received).
if remove_to:
# Writing to a file is better than waiting for sendmail to exit
tmp_file_name = '/tmp/%smailman.%d.digest' % (tmpfile_prefix,
os.getpid())
for item in msg.headers:
if (item[0:3] == 'To:' or
item[0:5] == 'X-To:'):
msg.headers.remove(item)
msg.headers.append('To: %s\n' % self.GetListEmail())
else:
tmp_file_name = '/tmp/%smailman.%d' % (tmpfile_prefix, os.getpid())
msg.headers.append('Errors-To: %s\n' % self.GetAdminEmail())
tmp_file = open(tmp_file_name, 'w+')
tmp_file.write(string.join(msg.headers,''))
# If replys don't go to the list, then they should go to the
# real sender
if self.reply_goes_to_list:
tmp_file.write('Reply-To: %s\n\n' % self.GetListEmail())
if header:
tmp_file.write(header + '\n\n')
tmp_file.write(self.QuotePeriods(msg.body))
if footer:
tmp_file.write('\n\n' + footer)
tmp_file.close()
file = os.popen("%s %s %s %s %s" %
(os.path.join(mm_cfg.MAILMAN_DIR, "mail/deliver"),
tmp_file_name, self.GetAdminEmail(),
self.num_spawns, to_list))
file.close()
def SendPostAck(self, msg, sender):
subject = msg.getheader('subject')
if not subject:
subject = '[none]'
body = POSTACKTEXT % (subject, self.real_name)
self.SendTextToUser('Post acknowlegement', body, sender)
def SendSubscribeAck(self, name, password, digest):
if digest:
digest_mode = '(Digest mode)'
else:
digest_mode = ''
if self.welcome_msg:
header = 'Here is the list-specific information:'
welcome = self.welcome_msg
else:
header = ''
welcome = ''
body = SUBSCRIBEACKTEXT % (self.real_name, self.host_name,
self.GetScriptURL('listinfo'),
self.real_name, self.host_name,
password,
self.GetListEmail(),
header,
welcome)
self.SendTextToUser(subject = 'Welcome To "%s"! %s' % (self.real_name,
digest_mode),
recipient = name,
text = body)
def SendUnsubscribeAck(self, name):
self.SendTextToUser(subject = 'Unsubscribed from "%s"\n' %
self.real_name,
recipient = name,
text = self.goodbye_msg)
def MailUserPassword(self, user):
self.SendTextToUser(subject = ('%s@%s maillist reminder\n'
% (self.real_name, self.host_name)),
recipient = user,
text = (USERPASSWORDTEXT
% (self.real_name,
self.passwords[user],
self.GetScriptURL('listinfo'),
self.host_name)))
|