File: 006.phpt

package info (click to toggle)
php-mailparse 3.1.4%2B2.1.7~dev20160128-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,484 kB
  • sloc: ansic: 4,080; xml: 363; php: 38; makefile: 2
file content (98 lines) | stat: -rw-r--r-- 1,992 bytes parent folder | download | duplicates (5)
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
98
--TEST--
Check extract_part_file
--SKIPIF--
<?php 
/* vim600: sw=4 ts=4 fdm=marker syn=php
*/
if (!extension_loaded("mailparse")) @dl("mailparse.so");
if (!extension_loaded("mailparse")) print "skip"; ?>
--POST--
--GET--
--FILE--
<?php
if (!extension_loaded("mailparse")) @dl("mailparse.so");
$text = <<<EOD
To: fred@bloggs.com
Mime-Version: 1.0
Content-Type: text/plain
Subject: A simple MIME message

hello, this is some text hello.
blah blah blah.

EOD;

$fp = tmpfile();
fwrite($fp, $text);
rewind($fp);


$mime = mailparse_msg_create();
mailparse_msg_parse($mime, $text);

echo "Extract to output\n";
mailparse_msg_extract_part_file($mime, $fp);

echo "Extract and return as string\n";
$result = mailparse_msg_extract_part_file($mime, $fp, null);
echo "-->\n";
echo $result;

echo "\nExtract to open file\n";
$fpdest = tmpfile();
mailparse_msg_extract_part_file($mime, $fp, $fpdest);
echo "\nrewinding\n";
rewind($fpdest);
fpassthru($fpdest);

echo "\nExtract via user function\n";
$cbdata = "";
function callbackfunc($data) {
	$GLOBALS["cbdata"] .= $data;
}
mailparse_msg_extract_part_file($mime, $fp, "callbackfunc");
echo "callback data is:\n";
var_dump($cbdata);

echo "\nExtract whole part to output\n";
mailparse_msg_extract_whole_part_file($mime, $fp);

echo "\nExtract part from string to output\n";
mailparse_msg_extract_part($mime, $text);
fclose($fpdest);
fclose($fp);

?>
--EXPECT--
Extract to output
hello, this is some text hello.
blah blah blah.
Extract and return as string
-->
hello, this is some text hello.
blah blah blah.

Extract to open file

rewinding
hello, this is some text hello.
blah blah blah.

Extract via user function
callback data is:
string(48) "hello, this is some text hello.
blah blah blah.
"

Extract whole part to output
To: fred@bloggs.com
Mime-Version: 1.0
Content-Type: text/plain
Subject: A simple MIME message

hello, this is some text hello.
blah blah blah.

Extract part from string to output
hello, this is some text hello.
blah blah blah.