'
if not poster:
poster = '*Unknown*'
if not datestr:
datestr = ''
output.write(''
"%s Mailing List: %s"
"%s
"
"%s (%s)
%s" %
(prefs['LABEL'], cgi.escape(subject),cgi.escape(subject),
cgi.escape(poster),cgi.escape(email),
cgi.escape(datestr)))
output.write('
\n')
html_mode=0
if prefs['SHOWHR']: output.write('
')
output.write('')
if not prefs['SHOWHTML']: output.write('
\n')
msg.rewindbody() # Seek to start of message body
quoted=-1
while (1):
L=msg.fp.readline()
if L=="": break
if html_mode:
# If in HTML mode, check for ending tag; otherwise, we
# copy the line without any changes.
if nohtmlpat.match(L)==-1:
output.write(L) ; continue
else:
html_mode=0
if not prefs['SHOWHTML']: output.write('\n')
continue
# Check for opening tag
elif htmlpat.match(L)!=-1:
html_mode=1
if not prefs['SHOWHTML']: output.write('\n')
continue
if prefs['SHOWHTML'] and prefs['IQUOTES']:
# Check for a line of quoted text and italicise it
# (We have to do this before escaping HTML special
# characters because '>' is commonly used.)
quoted=quotedpat.match(L)
if quoted!=-1:
L=cgi.escape(L[:quoted]) + '' + cgi.escape(L[quoted:]) + ''
# If we're flowing the message text together, quoted lines
# need explicit breaks, no matter what mode we're in.
if prefs['SHOWHTML']: L=L+'
'
else: L=cgi.escape(L)
else: L=cgi.escape(L)
# Check for an e-mail address
L2="" ; i=emailpat.search(L)
while i!=-1:
length=len(emailpat.group(1))
mailcmd=prefs['MAILCOMMAND'] % {'TO':L[i:i+length]}
L2=L2+'%s%s' % (L[:i],
mailcmd, L[i:i+length])
L=L[i+length:]
i=emailpat.search(L)
L=L2+L ; L2=""; i=urlpat.search(L)
while i!=-1:
length=len(urlpat.group(1))
L2=L2+'%s%s' % (L[:i],
L[i:i+length], L[i:i+length])
L=L[i+length:]
i=urlpat.search(L)
L=L2+L
if prefs['SHOWHTML']:
while (L!="" and L[-1] in '\015\012'): L=L[:-1]
if prefs['SHOWBR']:
# We don't want to flow quoted passages
if quoted==-1: L=L+'
'
else:
# If we're not adding
to each line, we'll need to
# insert markup on blank lines to separate paragraphs.
if blankpat.match(L)!=-1: L=L+'
'
L=L+'\n'
output.write(L)
if not prefs['SHOWHTML'] and not html_mode: output.write('
')
if prefs['SHOWHR']: output.write('
')
output.write('\n\n')
output.close()
def WriteHTMLIndex(prefs, fp, L, articles, indexname):
"""Process a list L into an HTML index, written to fp.
L is processed from left to right, and contains a list of 2-tuples;
an integer of 1 or more giving the depth of indentation, and
a list of strings which are used to reference the 'articles'
dictionary. Most of the time the lists contain only 1 element."""
fp.write('\n'
""
"%s Mailing List Archive by %s\n"
% (prefs['LABEL'], indexname))
fp.write(''
'- Most recent messages'
'
- Messages sorted by:'
% (prefs['LABEL'], indexname))
if indexname!='Date':
fp.write('[ date ]')
if indexname!='Subject':
fp.write('[ subject ]')
if indexname!='Author':
fp.write('[ author ]')
if indexname!='Thread':
fp.write('[ thread ]')
if prefs['ARCHIVES']!='NONE':
fp.write('
- Other mail archives' %
(prefs['ARCHIVES'],))
# This doesn't look professional. -- JV
# mailcmd=prefs['MAILCOMMAND'] % {'TO':'amk@magnet.com'}
# fp.write('
Please inform amk@magnet.com if any of the messages are formatted incorrectly.' % (mailcmd,) )
fp.write("
Starting: %s
"
"Ending: %s
Messages: %i
"
% (prefs['firstDate'], prefs['endDate'], len(L)) )
# Write the index
level=1
fp.write('
\n')
for indent, keys in L:
if indent>level and indent<=prefs['THRDLEVELS']:
fp.write((indent-level)*''+'\n')
if indent'+'\n')
level=indent
for j in keys:
subj, email, poster, date, datestr, parent, id=articles[j]
# XXX Should we put a mailto URL in here?
fp.write('- %s %s\n' %
(j, subj, poster) )
for i in range(0, indent): fp.write('
')
fp.write('')
# Write the footer
import time
now=time.asctime(time.localtime(time.time()))
# JV -- Fixed a bug here.
if prefs['ARCHIVES'] <> 'NONE':
otherstr=('
- Other mail archives' %
(prefs['ARCHIVES'],) )
else: otherstr=""
fp.write('Last message date: %s
'
'Archived on: %s' % (prefs['endDate'], now, otherstr))
fp.write('
This archive was generated by '
# JV Updated the URL.
''
'Pipermail %s.' % (VERSION,))
# Set the hard-wired preferences first
# JV Changed the SHOWHTML pref default to 0 because 1 looks bad.
prefs={'CONFIGFILE':'~/.pmrc', 'MBOX':'mbox',
'ARCHIVES': 'NONE', 'ABOUT':'NONE', 'REVERSE':0,
'SHOWHEADERS':0, 'SHOWHTML':0, 'LABEL':"",
'DIR':'archive', 'DIRMODE':0755,
'FILEMODE':0644, 'OVERWRITE':0, 'VERBOSE':0,
'THRDLEVELS':3, 'SHOWBR':0, 'IQUOTES':1,
'SHOWHR':1, 'MAILCOMMAND':'mailto:%(TO)s',
'INDEXFILE':'NONE'
}
# Read the ~/.pmrc file
ReadCfgFile(prefs)
# Read environment variables
ReadEnvironment(prefs)
# Parse command-line options
import getopt
options, params=getopt.getopt(sys.argv[1:], 'a:b:c:d:l:m:s:uipvxzh?')
for option, value in options:
if option=='-a': prefs['ARCHIVES']=value
if option=='-b': prefs['ABOUT']=value
if option=='-c': prefs['CONFIGFILE']=value
if option=='-d': prefs['DIR']=value
# if option=='-f': prefs.frames=1
if option=='-i': prefs['MBOX']='-'
if option=='-l': prefs['LABEL']=value
if option=='-m': prefs['MBOX']=value
if option=='-s': prefs['INDEXFILE']=value
if option=='-p' or option=='-v': prefs['VERBOSE']=1
if option=='-x': prefs['OVERWRITE']=1
if option=='-z' or option=='-h' or option=='-?': PrintUsage()
# Set up various variables
articles={} ; sequence=0
for key in ['INDEXFILE', 'MBOX', 'CONFIGFILE', 'DIR']:
prefs[key]=posixpath.expanduser(prefs[key])
if prefs['INDEXFILE']=='NONE':
if prefs['MBOX']!='-':
prefs['INDEXFILE']=prefs['MBOX']+'.pipermail'
else: prefs['INDEXFILE']='mbox.pipermail'
# Read an index file, if one can be found
if not prefs['OVERWRITE']:
# Look for a file contained pickled state
import pickle
try:
if prefs['VERBOSE']:
print 'Attempting to read index file', prefs['INDEXFILE']
f=open(prefs['INDEXFILE'], 'r')
articles, sequence =pickle.load(f)
f.close()
except IOError:
if prefs['VERBOSE']: print 'No index file found.'
pass # Ignore errors
# Open the input file
if prefs['MBOX']=='-': prefs['MBOX']=sys.stdin
else:
if prefs['VERBOSE']: print 'Opening input file', prefs['MBOX']
prefs['MBOX']=open(prefs['MBOX'], 'r')
# Create the destination directory; if it already exists, we don't care
try:
os.mkdir(prefs['DIR'], prefs['DIRMODE'])
if prefs['VERBOSE']: print 'Directory %s created'%(prefs['DIR'],)
except os.error, (errno, errmsg): pass
# Create various data structures:
# msgids maps Message-IDs to filenames.
# roots maps Subject lines to (date, filename) tuples, and is used to
# identify the oldest article with a given subject line for threading.
msgids={} ; roots={}
for i in articles.keys():
subject, email, poster, date, datestr, parent, id =articles[i]
if id: msgids[id]=i
if not roots.has_key(subject) or roots[subject]', '', L))
# Check if there's a name in parentheses
i=paren_name_pat.match(poster)
if i!=-1: poster=paren_name_pat.group(1)[1:-1]
datestr=m.getheader('Date')
# JV -- Hacks to make the getdate work.
# These hacks might skew the post time a bit.
# Crude, but so far, effective.
words = string.split(datestr)
if ((len(words[-1]) == 4) and (len(words) == 5)
and (words[-1][:-1] == '199')):
try:
date = time.mktime(rfc822.parsedate('%s, %s %s %s %s' %
(words[0], words[2], words[1],
words[4], words[3])))
except:
date = time.mktime(m.getdate('Date')) # Odd
elif len(words) > 4 and words[4][-1] == ',':
try:
date = time.mktime(rfc822.parsedate('%s, %s %s %s %s' %
(words[0], words[1], words[2],
words[3], words[4][:-1])))
except:
date = time.mktime(m.getdate('Date')) # Hmm
else:
try:
date=time.mktime(m.getdate('Date'))
except:
print 'Error getting date!'
print 'Subject = ', m.getheader('subject')
print 'Date = ', m.getheader('date')
id=m.getheader('Message-Id')
if id: id=id[1:-1] ; msgids[id]=filename
parent=None
in_reply_to=m.getheader('In-Reply-To')
if in_reply_to:
in_reply_to=in_reply_to[1:-1]
if msgids.has_key(in_reply_to): parent=msgids[in_reply_to]
elif roots.has_key(subj) and roots[subj][0]") ; f.close()
# JV changed...
f=open(posixpath.join(prefs['DIR'], mm_cfg.HOME_PAGE), 'w')
f.write("""%s Pipermail Archive
To access the %s Pipermail Archive, choose one of the following links:
Messages sorted by [ date ]
[ subject ]
[ author ]
[ thread ]
""" % (prefs['LABEL'],prefs['LABEL']) )
import pickle
if prefs['VERBOSE']: print 'Writing index file', prefs['INDEXFILE']
f=open(prefs['INDEXFILE'], 'w')
pickle.dump( (articles, sequence), f )
f.close()