Thread Euro Zeichen in MIME (10 answers)
Opened by bianca at 2012-07-19 10:10

bianca
 2012-07-19 10:10
#160045 #160045
User since
2009-09-13
6977 Artikel
BenutzerIn

user image
In Folge des Thread Zeichensatz bei MIME::Lite habe ich mir nun also selbst was gebastelt, im Netz gefunden usw.
Das Ergebnis sieht so aus:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Data::Dumper;

my $testtext = <<TEXTPLAIN
Kleiner Test mit Umlauten:
ae = 'ä'
Ae = 'A'
oe = 'ö'
Oe = 'Ö'
ue = 'ü'
Ue = 'Ü'
ss = 'ß'
Euro = '€'
At = '\@'
TEXTPLAIN
;
print "Mime: ".mime_encode($testtext)."\n\n\n";
print "qp: ".qp_encode($testtext)."\n\n\n";

#--------#
    sub mime_encode {
        return '' if !defined $_[0] || $_[0] eq '';
        my $return = $_[0];
        my $noprint = "\\x00-\\x1F\\x7F-\\xFF";
        my ($word,@lines);
        my $line = '';
        $return =~ s{[a-zA-Z0-9\x7F-\xFF]{1,18}}{
            $word = $&;
            (($word !~ /[$noprint]/o)
            ? $word
            : "=?ISO-8859-15?Q?".&_encode($word,$noprint)."?=");
        }xeg;
        my @words = split(/ /,$return);
        foreach $word (@words) {
            my $sameword = 0;
            if (length($word) > 75) {
                while ($word) {
                    if ($word =~ /^(.+?\?=)(=\?.*)$/) {
                        addword($1,\$line,\@lines,$sameword);
                        $word = $2;
                    }
                    else {
                        addword($word,\$line,\@lines,$sameword);
                        $word = '';
                    }
                    $sameword = 1;
                }
            }
            else { addword($word,\$line,\@lines,$sameword); }
        }
        push(@lines,$line."\n") if ($line);
        return substr(join('',@lines),1);
        sub addword {
            my ($word,$line,$lines,$sameword) = @_;
            if (!$sameword && $word =~ /^=\?[^\?]+?\?[Qq]\?(.+\?=)$/) {
                my $newword = $1;
                if ($$line =~ /^(.+)\?=$/) {
                    $$line = $1.'_';
                    if (length($$line) + length($newword) > $75) {
                        $$line .= '?=';
                        push(@$lines,$$line."\n");
                        $$line = ' '.$word;
                    }
                    else { $$line .= $newword }
                    return 0;
                }
            }
            if (length($$line) > 0 && length($$line) + length($word) > 75) {
                push(@$lines,$$line."\n");
                $$line = '';
            }
            $$line .= ' '.$word;
        }
        sub _encode {
            my ($str,$noprint) = @_;
            $str =~ s{[\?\=\_$noprint]}{sprintf("=%02X",ord($&))}eog;
            $str;
        }
    }

    sub qp_encode {
        my $text = shift;
        $text =~ s/([^ \t\n!-<>-~])/sprintf("=%02X", ord($1))/eg;
        $text =~ s/([ \t]+)$/
            join('', map { sprintf("=%02X", ord($_)) } split('', $1))/egm;
        my $ret = '';
        $ret .= "$1=\n"
            while $text =~ s/(.*?^[^\n]{73} (?:
             [^=\n]{2} (?! [^=\n]{0,1} $)
            |[^=\n]    (?! [^=\n]{0,2} $)
            |          (?! [^=\n]{0,3} $)
            ))//xsm;
        $ret.$text;
    }

Problem ist das Euro-Zeichen. Wenn ich obiges Script in ANSI in Notepad++ speichere bringt es mir =80 raus.
Konvertiere ich das Script in UTF-8 dann bringt es mir für das Euro-Zeichen =E2=82=AC raus.
Sende ich nun mit dem Script als ANSI eine Mail erscheint in den Mailclients alles korrekt bis auf das Euro-Zeichen.
Sende ich die Mail mit dem selben Script als UTF-8 sind alle Umlaute falsch, das Euro-Zeichen ist dann korrekt.

Liegt das vielleicht daran, dass Notepad++ im ANSI Format in latin-1 speichert und dort das Euro-Zeichen nicht kennt? Oder habe ich einen Fehler im Script?
Danke
10 print "Hallo"
20 goto 10

View full thread Euro Zeichen in MIME