1<?php
2require_once "class.test.php";
3require_once INCLUDE_DIR."class.mailparse.php";
4
5abstract class Priorities {
6    const HIGH_PRIORITY = 1;
7    const NORMAL_PRIORITY = 2;
8    const LOW_PRIORITY = 3;
9    const NO_PRIORITY = 0;
10}
11
12class TestHeaderFunctions extends Test {
13    var $name = "Email Header Function Algorithm Regression Tests.";
14
15    function testMailParsePriority() {
16        $func_class_method = array('Mail_Parse','parsePriority');
17        $strlen_base = strlen($this->h());
18
19        foreach ( array (
20                // input => output
21                'X-Priority: isNAN' => Priorities::NO_PRIORITY,
22                'X-Priority: 1' => Priorities::HIGH_PRIORITY,
23                'X-Priority: 2' => Priorities::HIGH_PRIORITY,
24                'X-Priority: 3' => Priorities::NORMAL_PRIORITY,
25                'X-Priority: 4' => Priorities::NORMAL_PRIORITY,
26                'X-Priority: 5' => Priorities::LOW_PRIORITY,
27                'X-Priority: 6' => Priorities::LOW_PRIORITY,
28                'No priority set' => Priorities::NO_PRIORITY,
29                'Priority: normal' => Priorities::NORMAL_PRIORITY,
30                'xyz-priority: high' => Priorities::HIGH_PRIORITY,
31                'Priority: high' => Priorities::HIGH_PRIORITY,
32                'priority: low' => Priorities::LOW_PRIORITY,
33                'x-priority: 1000' => Priorities::HIGH_PRIORITY, // only matches first 1, not the full 1000
34                'priority: 3' => Priorities::NORMAL_PRIORITY,
35                'IPM-Importance: low' => Priorities::LOW_PRIORITY,
36                'My-Importance: URGENT' => Priorities::HIGH_PRIORITY,
37                'Urgency: High' => Priorities::NO_PRIORITY, //urgency doesn't match.. maybe it should?
38                'Importance: Low' => Priorities::LOW_PRIORITY,
39                'X-MSMail-Priority: High' => Priorities::HIGH_PRIORITY,
40                '' => Priorities::NO_PRIORITY
41        ) as $priority => $response ) {
42            $this->assert(is_int($response), "Setup fail, function should only return Integer values");
43            //get header
44            $header = $this->h($priority);
45
46            if(strlen($priority)){
47                $this->assert((strlen($header) > $strlen_base), "Setup fail, function h not returning correct string length");
48            }
49            if (! (call_user_func_array ($func_class_method , array($header) ) == $response)){
50                //TODO: make line number dynamic
51                $this->fail ( "class.mailparse.php", 351, "Algorithm mistake: $priority should return $response!" );
52            }else{
53                $this->pass();
54            }
55        }
56
57    }
58
59    /**
60     * Generate some header text to test with. Allows insertion of a known header variable
61     *
62     * @param string $setPriority
63     * @return string
64     */
65    function h($setPriority = "") {
66        return <<<HEADER
67Delivered-To: clonemeagain@gmail.com
68Received: by 10.69.18.42 with SMTP id gj10csp88238pbd;
69Fri, 20 Dec 2013 10:08:25 -0800 (PST)
70X-Received: by 10.224.13.80 with SMTP id b16mr16256982qaa.73.1387562904239;
71Fri, 20 Dec 2013 10:08:24 -0800 (PST)
72Return-Path: <noreply@github.com>
73Received: from github-smtp2a-ext-cp1-prd.iad.github.net (github-smtp2-ext5.iad.github.net. [192.30.252.196])
74by mx.google.com with ESMTPS id k3si6568083qao.74.2013.12.20.10.08.23
75for <clonemeagain@gmail.com>
76(version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
77Fri, 20 Dec 2013 10:08:23 -0800 (PST)
78Received-SPF: pass (google.com: domain of noreply@github.com designates 192.30.252.196 as permitted sender) client-ip=192.30.252.196;
79Authentication-Results: mx.google.com;
80spf=pass (google.com: domain of noreply@github.com designates 192.30.252.196 as permitted sender) smtp.mail=noreply@github.com
81Date: Fri, 20 Dec 2013 10:08:23 -0800
82From: Jared Hancock <notifications@github.com>
83Reply-To: "osTicket/osTicket-1.8" <reply+i-BUNCHORANDOMGIBBERIBBERISH-BUNCHORANDOMGIBBERIBBERISH@reply.github.com>
84To: "osTicket/osTicket-1.8" <osTicket-1.8@noreply.github.com>
85Cc: clonemeagain <clonemeagain@gmail.com>
86Message-ID: <osTicket/osTicket-1.8/pull/336/issue_event/82864993@github.com>
87In-Reply-To: <osTicket/osTicket-1.8/pull/336@github.com>
88References: <osTicket/osTicket-1.8/pull/336@github.com>
89Subject: Re: [osTicket-1.8] Landing page inline image correction (#336)
90Mime-Version: 1.0
91Content-Type: multipart/alternative;
92boundary="--==_mimepart_52b4879729712_d621217cfc567e3";
93charset=UTF-8
94Content-Transfer-Encoding: 7bit
95Precedence: list
96X-GitHub-Recipient: clonemeagain
97X-GitHub-Reason: author
98List-ID: osTicket/osTicket-1.8 <osTicket-1.8.osTicket.github.com>
99List-Archive: https://github.com/osTicket/osTicket-1.8
100List-Post: <mailto:reply+i-BUNCHORANDOMGIBBERIBBERISH-BUNCHORANDOMGIBBERIBBERISH@reply.github.com>
101List-Unsubscribe: <mailto:unsub+i-BUNCHORANDOMGIBBERIBBERISH-BUNCHORANDOMGIBBERIBBERISH@reply.github.com>,
102<https://github.com/notifications/unsubscribe/BUNCHORANDOMGIBBERIBBERISH-BUNCHORANDOMGIBBERIBBERISH-BUNCHORANDOMGIBBERIBBERISH-BUNCHORANDOMGIBBERIBBERISH-BUNCHORANDOMGIBBERIBBERISH-BUNCHORANDOMGIBBERIBBERISH-BUNCHORANDOMGIBBERIBBERISH-BUNCHORANDOMGIBBERIBBERISH-BUNCHORANDOMGIBBERIBBERISHBUNCHORANDOMGIBBERIBBERISHBUNCHORANDOMGIBBERIBBERISH>
103X-Auto-Response-Suppress: All
104X-GitHub-Recipient-Address: clonemeagain@gmail.com
105$setPriority
106
107HEADER;
108    }
109
110}
111return 'TestHeaderFunctions';
112?>
113