summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorbwarsaw2000-05-08 21:46:30 +0000
committerbwarsaw2000-05-08 21:46:30 +0000
commit33d7497da9d97aad49a5fc371859dc84e9a796c2 (patch)
tree64c78e405d76025d9176c3810409a057940d3dc6 /scripts
parent58a17b9f5a8763c1ea9224ee4e7c72c3e11e4197 (diff)
downloadmailman-33d7497da9d97aad49a5fc371859dc84e9a796c2.tar.gz
mailman-33d7497da9d97aad49a5fc371859dc84e9a796c2.tar.zst
mailman-33d7497da9d97aad49a5fc371859dc84e9a796c2.zip
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/post91
1 files changed, 53 insertions, 38 deletions
diff --git a/scripts/post b/scripts/post
index 1d191a4ce..688d5fcbf 100755
--- a/scripts/post
+++ b/scripts/post
@@ -27,10 +27,11 @@ import sys
import paths
from Mailman import mm_cfg
+from Mailman import Utils
from Mailman import MailList
from Mailman import Message
from Mailman import Errors
-from Mailman import Utils
+from Mailman import LockFile
from Mailman.Logging.Utils import LogStdErr
from Mailman.Handlers import HandlerAPI
from Mailman.pythonlib.StringIO import StringIO
@@ -39,42 +40,59 @@ LogStdErr("error", "post")
+def get_message(mlist):
+ msg = None
+ # Perhaps flow the message text through a filter program
+ prog = mlist.filter_prog
+ if prog:
+ import os, __main__
+ file = os.path.join(mm_cfg.PREFIX, 'filters', prog)
+ try:
+ execfile(file)
+ msg = Message.Message(StringIO(__main__.mailman_text))
+ except:
+ pass
+ if msg is None:
+ s = StringIO(sys.stdin.read())
+ msg = Message.Message(s)
+ return msg
+
+
+
def main():
- mlist = MailList.MailList(sys.argv[1])
+ # TBD: If you've configured your list or aliases so poorly as to get
+ # either of these first two errors, there's little that can be done to
+ # save your messages. They will be lost. Minimal testing of new lists
+ # should avoid either of these problems.
try:
- # get the message text, which might flow through a filter module
- prog = mlist.filter_prog
- msg = None
- if prog:
- import os, __main__
- file = os.path.join(mm_cfg.PREFIX, 'filters', prog)
- try:
- execfile(file)
- msg = Message.Message(StringIO(__main__.mailman_text))
- except:
- pass
- if msg is None:
- s = StringIO(sys.stdin.read())
- msg = Message.Message(s)
- # go ahead and post the message
- adminaddr = mlist.GetAdminEmail()
- try:
- mlist.Post(msg)
- # TBD: change this to use LoopError and/or move this to the message
- # pipeline where it probably ought to be.
- except Errors.MMLoopingPost:
- # let the list admin know this happened, but don't otherwise hold
- # the message for approval.
- sys.stderr.write('Message already came through this list\n')
- map(sys.stderr.write, msg.headers)
- sys.stderr.write('[body of message suppressed]\n')
- noticemsg = Message.UserNotification(
- adminaddr, adminaddr,
- 'Message loop detected [message discarded]',
- '\n---------- Original Message ----------\n' +
- str(msg))
- HandlerAPI.DeliverToUser(mlist, noticemsg)
- # Let another process run.
+ listname = sys.argv[1]
+ except IndexError:
+ sys.stderr.write('Mailman error: post got no listname.\n')
+ sys.exit(1)
+ try:
+ mlist = MailList.MailList(listname, lock=0)
+ except Errors.MMListError, e:
+ sys.stderr.write('Mailman error: post got bad listname: %s\n%s' %
+ (listname, e))
+ sys.exit(1)
+ # We have a valid, unlocked list. This is enough to extract the message
+ # object in a usable form. From here on out, we should never lose
+ # messages.
+ msg = get_message(mlist)
+ # Try to obtain the mailing list lock. If that fails, enqueue the message
+ # for delivery by the qrunner cron job.
+ try:
+ mlist.Lock(timeout=mm_cfg.LIST_LOCK_TIMEOUT)
+ except LockFile.TimeOutError:
+ msg.Enqueue(mlist)
+ return
+ try:
+ msgdata = {}
+ enqueue = HandlerAPI.DeliverToList(mlist, msg, msgdata)
+ if enqueue:
+ # The delivery failed for some reason. Queue the message up for
+ # another attempt later.
+ msg.Enqueue(mlist, newdata=msgdata)
finally:
mlist.Save()
mlist.Unlock()
@@ -82,7 +100,4 @@ def main():
if __name__ == '__main__':
-## sys.stderr.write('starting\n')
main()
-## sys.stderr.reprime()
-## sys.stderr.write('ending\n')