Attached is a patch (diff -u) for MessageLogger.py to maintain a concise
logfile (3 lines per message instead of 6), in addition to the usual
more verbose one.
Background: I typically leave a window open on my mail server, doing a
tail -f on my procmail log, which produces 3-4 lines per incoming
message. (This is largely because my IMAP clients can't tell when a new
message gets filtered into an arbitrary folder.) With TMDA, I don't want
to watch the procmail log directly (then I still see the spam coming
in), or the usual incoming log (ditto, plus it's more verbose). So I
put together this hack to give me a concise log, so I could finally
attain the Enjoy A "Milk Bone" In A Spam-Free World Phase.
I did not add a new configuration variable; instead, the concise logfile
has the same name as the usual logfile plus ".concise"; if it doesn't
exist, it will not be created. If you think the concise logfile is
useful enough to roll into the main codebase, I can go ahead and add the
config var for it.
An entry in the concise logfile looks something like:
From: Foo <[EMAIL PROTECTED]>: Dest
Subject: Concise Logfiles
When the action is OK, Dest is "Inbox"; when it's DELIVER, Dest is where
the message was delivered (e.g., an mbox). The From: address omits
extensions, for readability (it can't know whether the sender uses + or
-, so it accepts both; this will be fine 99% of the time).
Please CC: me on replies (if any :-), since I'm not on this list--though
I will check the archive tomorrow night in case.
(IANAL note: patch is under the GPL, of course.)
--
/================================================================\
|John Stracke | http://www.thibault.org |HTML OK |
|Francois Thibault |===========================================|
|East Kingdom |"Genius, Brain! But what if the dragon eats|
|[EMAIL PROTECTED]|us?" "That would alter our plans." |
\================================================================/
--- MessageLogger.py 2003-05-28 22:51:29.000000000 -0400
+++ MessageLogger.py.bak 2003-05-28 20:42:50.000000000 -0400
@@ -27,9 +27,7 @@
from email.Utils import parseaddr
import Util
-import Defaults
-import os
-import stat
+
class MessageLogger:
def __init__(self, logfile, msg, **vardict):
@@ -45,40 +43,6 @@
self.vardict = vardict
self.logfile = logfile
self.log = open(self.logfile, 'a')
- logfile_concise=self.logfile+".concise"
- try:
- st=os.stat(logfile_concise)
- except OSError:
- logfile_concise=None
- if logfile_concise:
- self.log_concise=open(logfile_concise,'a')
- else:
- self.log_concise=None
-
- def write_concise(self):
- if not self.log_concise:
- return
- Action=self.vardict.get('action_msg')
- verb=Action.split(' ')[0]
- rcpt=self.vardict.get('envrecip')
- reportedAction=None
- if (verb=='OK'):
- reportedAction='Inbox'
- else:
- if (verb=='DELIVER' and rcpt!=Defaults.CONFIRM_CC):
- reportedAction=filter(lambda x: x.find('deliver=')==0, Action.split('
'))[0].split('=')[1].split(')')[0]
- if reportedAction:
- f=self.msg.get('from') or self.msg.get('reply-to') or
self.vardict.get('envsender', None) or '<>'
- fromParts=f.split('<')
- if len(fromParts)==2:
- fromName=fromParts[0]
- f=fromParts[1].split('>')[0]
- else:
- fromName=''
- (fromUser,fromDomain)=f.split('@')
- fromUser=fromUser.split('+')[0].split('-')[0]
- subject=self.msg.get('subject') or ''
- self.log_concise.write('From: %s<[EMAIL PROTECTED]>: %s\nSubject: %s\n\n'
% (fromName,fromUser,fromDomain, reportedAction,subject))
def write(self):
"""
@@ -93,7 +57,6 @@
Subj: (Subject header)
Actn: (message trigger and size of message)
"""
- self.write_concise()
self.__writeline('Date', Util.unixdate())
XPri = self.msg.get('x-primary-address')
if XPri:
@@ -123,5 +86,3 @@
def __close(self):
self.log.write('\n')
self.log.close()
- if self.log_concise:
- self.log_concise.close()