procmail
[Top] [All Lists]

Re: re-sort headers?

1999-04-17 18:07:58
On Sat, 17 Apr 1999, Timothy J Luoma wrote:

My MUA shows the headers as they appear in the text of the message.

If I can change the way they are in the actual message, it will display them  
in that order.

Ah. Then I'd suggest sending the messages through a filter just before
they're delivered:

#-----------------------
:0f
|/path/to/this/script/or/the/one/era/wrote
#-----------------------

#-----------------------
#!/usr/bin/perl

# re-sort mail headers

while (<>) {
  my ($hdr, $text, $i);

  last if /^$/;
  chomp;
  $i = index($_, ':');
  $hdr = substr($_, 0, $i);
  $text = substr($_, $i+2);
# can't split /:/, as fields may have : in them
  $hash{$hdr}=$text;
}

# put these in whatever order you like
print
      'Date: ' . $hash{'Date'} . "\n" .
      'From: ' . $hash{'From'} . "\n" .
      'To: ' . $hash{'To'} . "\n" .
      'Subject: ' . $hash{'Subject'} . "\n";

delete $hash{'Date'};
delete $hash{'From'};
delete $hash{'To'};
delete $hash{'Subject'};
foreach (keys %hash) {
  print $_ . ': ' . $hash{$_} . "\n";
}

print "\n";

print <>;
#-----------------------

-jeff
----
Conversation, n.:
  A vocal competition in which the one who is catching his breath
  is called the listener.


<Prev in Thread] Current Thread [Next in Thread>