"""nnthread.py - various threading goodies.""" # meoWWW # Copyright 1999 G.J. Andruk # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or (at # your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import string, mimify class Threader: def __init__(self, server, novlist): self.novlist = novlist self.artlist = {} for item in range(len(self.novlist)): # self.artlist {msgid:[item, hasmom, kids, kidnums], ...} self.artlist[self.novlist[item][4]] = [item, 0, [], []] for item in self.artlist.keys(): for ref in range(len(self.novlist[self.artlist[item][0]][5]) -1, -1, -1): reftry = self.novlist[self.artlist[item][0]][5][ref] if self.artlist.has_key(reftry): self.artlist[item][1] = 1 # I have a mom! self.artlist[reftry][2].append(item) # Tell mom break itemlist = self.artlist.keys() itemlist.sort() subjlist = [] for item in itemlist: if self.artlist[item][1] == 0: subjline = string.lower(mimify.mime_decode_header( self.novlist[self.artlist[item][0]][1])) if string.lower(subjline[0:3]) == 're:': subjline=string.lstrip(subjline[3:]) subjlist.append((subjline, item)) subjlist.sort() self.arttable = [] for item in subjlist: self.dumptitle(self.artlist[item[1]], '', self.novlist[self.artlist[item[1]][0]]) self.artlist[item[1]][3] = self.subthread( self.artlist[item[1]][2], '', self.artlist[item[1]][3]) def subthread(self, kidlist, lvl, kidarray): kidmax = len(kidlist) - 1 for kid in range(len(kidlist)): if kid == len(kidlist) - 1: newlvl = '`-' elif (kid == 0) or kidmax: newlvl = '|-' else: newlvl = '| ' self.dumptitle(self.artlist[kidlist[kid]], lvl + newlvl, self.novlist[self.artlist[kidlist[kid]][0]]) kidarray.append( str(self.novlist[self.artlist[kidlist[kid]][0]][0])) if kid == kidmax: newlvl = ' ' else: newlvl = '| ' kidarray = self.subthread(self.artlist[kidlist[kid]][2], lvl + newlvl, kidarray) return kidarray def dumptitle(self, artitm, ldr, novitm): import rfc822, time ldr = ldr[:30] addy = rfc822.parseaddr(novitm[2]) # FIXME: this is very slow try: bytecnt = float(novitm[6]) / 1024. except: bytecnt = 0 #artitm[2] == haskids self.arttable.append((novitm[0], artitm, len(ldr)/2, (bytecnt, ldr, novitm[1], (addy[0] or addy[1] or '???'), novitm[4])))