From 978e8db8c4234a83e4f47be922597352af5454fc Mon Sep 17 00:00:00 2001 From: mailman Date: Wed, 25 Feb 1998 16:18:17 +0000 Subject: Initial revision --- modules/mm_mailcmd.py | 450 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 450 insertions(+) create mode 100644 modules/mm_mailcmd.py (limited to 'modules/mm_mailcmd.py') diff --git a/modules/mm_mailcmd.py b/modules/mm_mailcmd.py new file mode 100644 index 000000000..6c930a7ed --- /dev/null +++ b/modules/mm_mailcmd.py @@ -0,0 +1,450 @@ +# Process mail commands. +# Try to stay close to majordomo commands, but accept common mistakes. +# Not implemented: get / index / which + + + + +import string, os, sys +import mm_message, mm_err, mm_cfg, mm_utils + + + + +option_descs = { 'digest' : 'receive mail from the list bundled together instead of ' + 'one post at a time', + 'nomail' : 'Stop delivering mail. Useful if you plan on taking a ' + 'short vacation.', + 'norcv' : 'Turn this on to NOT receive posts you send to the list. ' + 'does not work if digest is set', + 'ack' : 'Turn this on to receive acknowlegement mail when you ' + 'send mail to the list', + 'fancy' : 'Get MIME-compliant digests (only works if digest is set)', + 'hide' : 'Conceals your email from the list of subscribers' + } +option_info = { 'digest' : 0, + 'nomail' : mm_cfg.DisableDelivery, + 'norcv' : mm_cfg.DontReceiveOwnPosts, + 'ack' : mm_cfg.AcknowlegePosts, + 'fancy' : mm_cfg.EnableMime, + 'hide' : mm_cfg.ConcealSubscription + } + +class MailCommandHandler: + def __init__(self): + self._response_buffer = '' + self._cmd_dispatch = { + 'subscribe' : self.ProcessSubscribeCmd, + 'unsubscribe' : self.ProcessUnsubscribeCmd, + 'who' : self.ProcessWhoCmd, + 'info' : self.ProcessInfoCmd, + 'lists' : self.ProcessListsCmd, + 'help' : self.ProcessHelpCmd, + 'set' : self.ProcessSetCmd, + 'options' : self.ProcessOptionsCmd, + 'password' : self.ProcessPasswordCmd, + } + + def AddToResponse(self, text): + self._response_buffer = self._response_buffer + text + "\n" + + def AddError(self, text): + self._response_buffer = self._response_buffer + "**** " + text + "\n" + + def ParseMailCommands(self): + mail = mm_message.IncomingMessage() + subject = mail.getheader("subject") + if subject: + subject = string.strip(subject) + if (subject and self._cmd_dispatch.has_key(string.split(subject)[0])): + lines = [subject] + string.split(mail.body, '\n') + else: + lines = string.split(mail.body, '\n') + if subject: + self.AddError("Subject line ignored.") + for line in lines: + line = string.strip(line) + if not line: + continue + self.AddToResponse("\n>>>> %s" % line) + line = string.strip(line) + if not line: + continue + args = string.split(line) + cmd = string.lower(args[0]) + args = args[1:] + if cmd == 'end': + self.AddError("End of commands.") + break + if not self._cmd_dispatch.has_key(cmd): + self.AddError("%s: Command UNKNOWN." % cmd) + else: + self._cmd_dispatch[cmd](args, line, mail) + self.SendMailCmdResponse(mail) + + def SendMailCmdResponse(self, mail): + self.SendTextToUser(subject = 'Mailman results for %s' % + self.real_name, + recipient = mail.GetSender(), + sender = self.GetRequestEmail(), + text = self._response_buffer) + self._response_buffer = '' + + def ProcessPasswordCmd(self, args, cmd, mail): + if len(args) <> 2: + self.AddError("Usage: password ") + return + try: + self.ChangeUserPassword(mail.GetSender(), args[0], args[1], args[1]) + self.AddToResponse('Succeded.') + except mm_err.MMListNotReady: + self.AddError("List is not functional.") + except mm_err.MMNotAMemberError: + self.AddError("%s isn't subscribed to this list." % mail.GetSender()) + except mm_err.MMBadPasswordError: + self.AddError("You gave the wrong password.") + except: + self.AddError("An unknown Mailman error occured.") + self.AddError("Please forward on your request to %s" % + self.GetAdminEmail()) + self.AddError("%s" % sys.exc_type) + + def ProcessOptionsCmd(self, args, cmd, mail): + sender = self.FindUser(mail.GetSender()) + if not sender: + self.AddError("%s is not a member of the list." % mail.GetSender()) + return + options = option_info.keys() + options.sort() + value = '' + for option in options: + if self.GetUserOption(sender, option_info[option]): + value = 'on' + else: + value = 'off' + self.AddToResponse("%s: %s" % (option, value)) + self.AddToResponse("") + self.AddToResponse("To change an option, do: set