-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemail.php
executable file
·61 lines (49 loc) · 1.16 KB
/
email.php
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
#!/usr/bin/php
<?php
// read from php://stdin
$email = file_get_contents('php://stdin');
class Email
{
const MULTIPART = 0;
const SINGLE = 1;
private $email_raw;
public $body_raw;
public $headers;
public $content_type;
public $body;
public $body_parts;
public $type;
public $boundary;
public function __construct($email)
{
$this->email_raw = $email;
$this->parse_email($email);
}
public function parse_email($email)
{
list($headers, $body) = explode("\n\n", $email, 2);
$this->headers = new EmailHeaders(trim($headers));
$this->parse_body($body);
}
public function parse_body($body)
{
$this->body_raw = $body;
if (preg_match('#^multipart/.*boundary=(\'|")(.*)(\1)#i', $this->headers->get('content-type'), $m)) {
$this->type = self::MULTIPART;
$this->boundary = $m[2];
$body = substr($body, strlen($this->boundary)+2);
$bodies = explode("--$this->boundary", $body, -1);
foreach ($bodies as $bod) {
$this->body_parts[] = new EmailBodyPart($bod);
}
}
else {
$this->type = self::SINGLE;
$this->body = $body;
}
}
}
include "emailheaders.php";
include "emailbodypart.php";
$e = new Email($email);
?>