#!/usr/bin/perl # # Hypermail Flat Threads 0.2 # This program is written by Georgi Chorbadzhiyski # You can contact the author at this email (georgi AT top DOT bg) # # This program is distributed under GNU GPL version 2.0 # # Sample output of this program can be found at this urls # http://georgi.top.bg/hm-threads/ # http://georgi.top.bg/hm-threads/0002-thread.html # # Changelog # # v0.2 - Added thread id to messages # v0.1 - Initial version # use strict; use integer; my $VERSION = "0.2"; if ($ARGV[0] eq '') { print <; close(FILE); chomp(@index); foreach $line (@index) { if ( $line eq '') { $offset--; next; } push @parsed, $offset.':-:'.$line; } # # Generate thread files # for ($i=0;$i<$#parsed;$i++) { ($offset,$line) = split(":-:",$parsed[$i]); ($offset_f,$line_f) = split(":-:",$parsed[$i+1]); if ($offset_f > 1) { $HTML = ''; ($msgid) = ($line =~ /\"([0-9]{4})\.html\"/)[0]; ($title) = ($line =~ /\(.*?)\<\/STRONG\>/)[0]; $parent_msgid=$msgid; $parent_msgs{$parent_msgid}=1; $HTML = " $title

$title

"; if ( -e "$DIRECTORY/$msgid.html" ) { open(FILE, "<$DIRECTORY/$msgid.html") || die "Can`t open file $DIRECTORY/$msgid.html, $!\n"; @msgtxt = ; close(FILE); put_msg(); }; while ($offset_f > 1) { $i++; ($offset,$line) = split(":-:",$parsed[$i]); ($offset_f,$line_f) = split(":-:",$parsed[$i+1]); ($msgid) = ($line =~ /\"([0-9]{4})\.html\"/)[0]; if ( -e "$DIRECTORY/$msgid.html" ) { open(FILE, "<$DIRECTORY/$msgid.html") || die "Can`t open file $DIRECTORY/$msgid.html, $!\n"; @msgtxt = ; close(FILE); put_msg(); }; }; $HTML .= "
"; open(FILE, ">$DIRECTORY/$parent_msgid$FILE_ADD-tmp.html") || die "Can`t create file $DIRECTORY/$parent_msgid$FILE_ADD-tmp.html, $!\n"; print FILE $HTML; close(FILE); # If Exist if ( -e "$DIRECTORY/$parent_msgid$FILE_ADD.html" ) { my $size1 = -s "$DIRECTORY/$parent_msgid$FILE_ADD.html"; my $size2 = -s "$DIRECTORY/$parent_msgid$FILE_ADD-tmp.html"; # If new file size is different then we assume that there new msgs in the thread if ( $size1 != $size2 ) { unlink("$DIRECTORY/$parent_msgid$FILE_ADD.html") || warn "Can`t delete $DIRECTORY/$parent_msgid$FILE_ADD.html, $!\n"; rename("$DIRECTORY/$parent_msgid$FILE_ADD-tmp.html", "$DIRECTORY/$parent_msgid$FILE_ADD.html") || warn "Can`t rename $DIRECTORY/$parent_msgid$FILE_ADD-tmp.html, $!\n"; } else { unlink("$DIRECTORY/$parent_msgid$FILE_ADD-tmp.html") || warn "Can`t delete $DIRECTORY/$parent_msgid$FILE_ADD-tmp.html, $!\n"; }; # Just rename it... } else { rename("$DIRECTORY/$parent_msgid$FILE_ADD-tmp.html", "$DIRECTORY/$parent_msgid$FILE_ADD.html") || warn "Can`t rename $DIRECTORY/$parent_msgid$FILE_ADD-tmp.html, $!\n"; } $parent_msgs{$parent_msgid.'_size'}= -s "$DIRECTORY/$parent_msgid$FILE_ADD.html"; } } # # Generate index-threads # open(FILE, ">$DIRECTORY/index$FILE_ADD-tmp.html") || die "Can`t create $DIRECTORY/index$FILE_ADD-tmp.html, $!\n"; foreach $line (@index) { if ( $line =~ /^\\/
  • <[Aa] HRE[Ff]="$msgid$FILE_ADD.html?$size">thread<\/A><\/SMALL> /; } }; print FILE $line."\n"; } close(FILE); if ($INDEX_HTML_DEFAULT eq 'yes') { unlink("$DIRECTORY/index.html") if ( -e "$DIRECTORY/index.html" ); rename("$DIRECTORY/index$FILE_ADD-tmp.html", "$DIRECTORY/index.html"); } else { unlink("$DIRECTORY/index$FILE_ADD.html") if ( -e "$DIRECTORY/index$FILE_ADD.html" ); rename("$DIRECTORY/index$FILE_ADD-tmp.html", "$DIRECTORY/index$FILE_ADD.html"); } # # Format message # sub put_msg() { my $color = "#FFFFFF"; my $blank1 = ""; my $blank2 = ""; if ($offset == 2) { $color = "#f0f0f0"; $blank1 = ' WIDTH="7%"' ; $blank2 = ' WIDTH="93%"'; }; if ($offset == 3) { $color = "#e7e7e7"; $blank1 = ' WIDTH="15%"'; $blank2 = ' WIDTH="85%"'; }; if ($offset == 4) { $color = "#e0e0e0"; $blank1 = ' WIDTH="20%"'; $blank2 = ' WIDTH="80%"'; }; if ($offset == 5) { $color = "#d7d7d7"; $blank1 = ' WIDTH="25%"'; $blank2 = ' WIDTH="75%"'; }; if ($offset == 6) { $color = "#d0d0d0"; $blank1 = ' WIDTH="30%"'; $blank2 = ' WIDTH="70%"'; }; if ($offset == 7) { $color = "#c7c7c7"; $blank1 = ' WIDTH="35%"'; $blank2 = ' WIDTH="65%"'; }; if ($offset == 8) { $color = "#c0c0c0"; $blank1 = ' WIDTH="40%"'; $blank2 = ' WIDTH="60%"'; }; if ($offset == 9) { $color = "#b7b7b7"; $blank1 = ' WIDTH="45%"'; $blank2 = ' WIDTH="55%"'; }; my $msgbeg = 0; my $msgend = 0; my $i; my $line; my $m_author; my $m_subject; my $m_date; foreach $line (@msgtxt) { if ($line =~ //) { ($m_date) = ($line =~ /\"(.*?)\"/)[0]; }; if ($line =~ /\