summaryrefslogtreecommitdiff
path: root/t/ViewWebmail.t
blob: b1dd75f717c8e1116c0ec07f68928c42ff62673d (plain)
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
use v5.22;
use warnings;
use strict;
use utf8;

use Test::More;

use Encode 'decode';
use MIME::Words 'decode_mimewords';

use JWebmail;
use JWebmail::View::Webmail;


subtest 'print_size10' => sub {
    my %TESTS = (
        1 => '1 Byte',
        10 => '10 Byte',
        100 => '100 Byte',
        1000 => '1 kByte',
        10000 => '10 kByte',
        100000 => '100 kByte',
        1000000 => '1 MByte',
        10 * 10**6 => '10 MByte',
        10 * 2**20 => '10 MByte',
        800 => '800 Byte',
        9999 => '10 kByte',
        9500 => '10 kByte',
        1024 => '1 kByte',
        1023 => '1 kByte',
    );

    plan tests => scalar keys %TESTS;

    while (my ($input, $want) = each %TESTS) {
        is(JWebmail::View::Webmail->print_sizes10($input), $want);
    }
};


subtest 'vaild_mail_line' => sub {
    my %TESTS = (
        'abc@example.com' => 1,
        'ABC Ex <abc@example.com>' => 1,
        '"ABC Ex" <abc@example.com>' => 1,
        '"A@B.V Ex" <abc@example.com>' => 1,
        '"A@B.V Ex\"" <abc@example.com>' => 1,
        'ABC Ex abc@example.com' => 0,
    );

    plan tests => scalar keys %TESTS;

    while (my ($input, $want) = each %TESTS) {
        cmp_ok(JWebmail->_mail_line('', $input), '!=', $want);
    }
};


subtest 'mime_word_decode' => sub {
    my $input = "=?utf-8?Q?Jannis_wir_vermissen_dich!=20Komm=20zur=C3=BCck=20und=20spare=20mit=20uns=20beim=20shoppen=20deiner=20Lieblingsmarken?=";
    my $want = "Jannis wir vermissen dich! Komm zurück und spare mit uns beim shoppen deiner Lieblingsmarken";
    my $got = scalar decode_mimewords $input;

    isnt $want, $got;
    is $want, _to_perl_enc(decode_mimewords $input);
    is $want, decode('MIME-Header', $input);

    done_testing 3;
};

sub _to_perl_enc {
    my $out = '';
    for (@_) {
        if ($_->[1]) {
            $out .= decode($_->[1], $_->[0]);
        }
        else {
            $out .= $_->[0];
        }
    }
    return $out;
}

done_testing;