[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kmail-devel
Subject:    Threaded mails - missing reference
From:       ravemax () gmx ! net
Date:       2000-11-29 14:56:35
[Download RAW message or body]

This is a MIME encapsulated multipart message -
please use a MIME-compliant e-mail program to open it.

Dies ist eine mehrteilige Nachricht im MIME-Format -
bitte verwenden Sie zum Lesen ein MIME-konformes Mailprogramm.


First of all thanks for KMail, a little bit user-friendlier than Pine ;)

I like this Thread-option to see mails and their replies as a tree, but
the problem is that some reply-mails ("subject: RE...") don't contain a
"In-Reply-To" or "References"-field.
A solution is to get the subjects of all reply-mails w/o reference, search
for matching (same subject w/o "RE:") level0-mails (top-node) and then
adding the level0-message-ID to the reply-mail.
I attached a small Perl-script...


-- 
---[ mail from ]---
P.Gleichmann
ravemax@gmx.net

Sent through GMX FreeMail - http://www.gmx.net
["fixrmail" (text/plain)]

#!/usr/bin/perl
#
# fixrmail
#
# description -> '$UsageStr'
#
# v0.01
# Ravemax (ravemax@dextrose.com)
#

use strict;

#---------------
# Initialisation

my $UsageStr =
   "Inserts the 'In-Reply-To'-field into mails (req. for KMail).\n".
   "usage: fixrmail mail-file [-v]\n";

# Check args
die $UsageStr if ((@ARGV == 0) || ($ARGV[0] =~ /--(\?|h(elp)?)/i));
my $verboseMode = ($ARGV[1] eq '-v');

# Open file
open(INMAIL,'<',$ARGV[0]) or
   die "error: failed to open '$ARGV[0]' - $!\n";

#--------------------------------------------------
# Search reply-mails w/o reference and level0-mails

my (%mailsWORef,%mailsSubj);
my ($replyMail,$subj,$subjOfs,$msgID,$refFound);

while (<INMAIL>) {
   # Seek to beginning of the next mail
   next unless (/^From [\w.-]+\@/);

   # set some local vars
   $refFound = 0;

   # Go through mail header
   while ((my $rline = <INMAIL>) ne "\n") {
      chomp;
      if ($rline =~ /^(References|In-Reply-To):/i) {
         $refFound = 1;
      } elsif ($rline =~ /Subject: (.+)/i) {
         $subj = uc $1;
         $replyMail = ($subj =~ /^RE:\s*(.+)/i);
         $subj = $1 if ($replyMail);
         $subjOfs = tell(INMAIL);
      } elsif ($rline =~ /^Message-ID: (.+)/i) {
         $msgID = $1;
      }
   }

   # Add to hash
   if (!$replyMail) {
      $mailsSubj{$subj} = $msgID;
   } elsif (!$refFound) {
      push(@{$mailsWORef{$subj}->{'ofs'}},$subjOfs);
   }
}

# Print filled hashs
if ($verboseMode) {
   print "---Level 0---\n";
   foreach (keys %mailsSubj) {
      print "  '$_' = '$mailsSubj{$_}'\n";
   }
   print "---W/O Ref---\n";
   foreach my $k(keys %mailsWORef) {
      print "  '$k' = <";
      foreach (@{$mailsWORef{$k}->{'ofs'}}) {
         print "$_,";
      }
      print ">\n";
   }
}

#--------------------------
# Message-ID for reply-mail

# Assign id to mail
foreach $subj(keys %mailsSubj) {
   if (exists $mailsWORef{$subj}) {
      $mailsWORef{$subj}->{'id'} = \$mailsSubj{$subj};
   }
}

# Print fixed mails
if ($verboseMode) {
   print "--- Fixed ---\n";
   foreach (keys %mailsWORef) {
      print "  '$_' = ";
      my $iref = $mailsWORef{$_}->{'id'};
      print (($iref eq undef) ? 'UNDEF' : ${$iref});
      print "\n";
   }
}

# Remove mails where no id was found
foreach (keys %mailsWORef) {
   delete($mailsWORef{$_}) if ($mailsWORef{$_}->{'id'} eq undef);
}

#-----------------------
# Create fixed mail-file

# Open
my $fixName = "$ARGV[0]-fixed";
open(OUTMAIL,"> $fixName") or
   die "error: unable to create '$fixName' - $!\n";

# Copy content and insert reference
seek(INMAIL,0,0);
while (my $rline = <INMAIL>) {
   print OUTMAIL $rline;
   # Line with Subject ?
   if ($rline =~ /Subject: RE:\s*(.+)/i) {
      $subj = uc $1;
      if (exists $mailsWORef{$subj}) {
         my $curOfs = tell(INMAIL);
         print OUTMAIL "In-Reply-To: ",${$mailsWORef{$subj}->{'id'}},"\n"
            if (grep($curOfs == $_,@{$mailsWORef{$subj}->{'ofs'}}));
      }
   }
}

#----------
# That's it

close(OUTMAIL);
close(INMAIL);


_______________________________________________
Kmail Developers mailing list
Kmail@master.kde.org
http://master.kde.org/mailman/listinfo/kmail


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic