#!/usr/bin/perl #---------------------------------------------------------------------------- # /var/spool/hylafax/mimeconverters/text/plain-std - plain2ps converter # # Creation: 2007-01-25 jed # Last Update: $Id$ # # Copyright (c) 2007-@@YEAR@@ Holger Bruenjes, holgerbruenjes(at)gmx(dot)net # # Comment: Converts text attachments to PS (mime type: text/plain) # # 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.. #---------------------------------------------------------------------------- # # adapted from a script written by Martin Domig - Wed Aug 7 17:15:04 CEST 2002 # converts plaintext mail to html and parses the output to /usr/bin/html2ps. use HTML::Entities; open(STDIN, $ARGV[0]); open(STDOUT, "| /usr/bin/html2ps"); print("\n
\n");

$inheaders = 0;
$special = 0;

my %headers;

$headers{"From"} = "Von";
$headers{"To"} = "An";
$headers{"Date"} = "Datum";
$headers{"Cc"} = "Kopie an";
$headers{"Subject"} = "Betreff";

while() {
    $special = 0;

    if(/--- APPENDED HEADERS END/) {
        $inheaders = 0;
        $special = 1;
        print("\n\n");
    }

    if((/--- APPENDED HEADERS/) && ($special == 0)) {
        $inheaders = 1;
        $special = 1;
    }

    if($special == 0) {
        if($inheaders == 1) {
            ($header, $text)=(/^([^:]+): (.*)/);
            $text = HTML::Entities::encode($text);
            $text =~ s/\¤\;/\&euro\;/g;
            $header = $headers{$header};
            print("$header: $text\n");
        } else {
            # Lange zeilen umbrechen
            $_ =~ s/(.{75}\s+)/$1\n/g;

            # Wenn nach 90 zeichen kein \n kommt eins einfuegen
            $_ =~ s/([^\n]{90})/$1\n/g;

            my $escaped = HTML::Entities::encode($_);
            $escaped =~ s/\¤\;/\&euro\;/g;
            print $escaped;
        }
    }
}

print("
\n"); close(STDOUT);