-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail_handle.php
93 lines (63 loc) · 1.86 KB
/
mail_handle.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
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
<?php
use MimeMailParser\Parser;
use MimeMailParser\Attachment;
$parser = new Parser();
$parser->setStream(fopen('php://stdin', 'r'));
if ($parser->getHeader('cc')){
exit; // feedback error (todo)
}
$subject = $parser->getHeader('subject');
if (!$subject){
exit; // feedback error (todo)
}
list($toId, $toDomain) = $this->decompose($parser->getHeader('to'));
list($fromId, $fromDomain) = $this->decompose($parser->getHeader('from'), $toDomain);
list($uniqueId, $domain) = $this->decompose($parser->getHeader('message-id'), $toDomain);
$returnPath = $parser->getHeader('return-path');
$body = $parser->getMessageBody('html');
if (!$body){
$body = $parser->getMessageBody('text');
if (!$body){
exit;
}
}
/*
$attachments = $parser->getAttachments();
foreach ($attachments as $attachment)
{
$filename = $attachment->filename;
if ($f = fopen($save_dir.$filename, 'w'))
{
while($bytes = $attachment->read())
{
fwrite($f, $bytes);
}
fclose($f);
}
}
*/
$output->writeln('from id:'.$fromId);
$output->writeln('to id:'.$toId);
$output->writeln('subject:'.$subject);
$output->writeln('return-path:'.$returnPath);
$output->writeln('message-id:'.$uniqueId.'@'.$domain);
$output->writeln('unique-id:'.$uniqueId);
$output->writeln('domain:'.$domain);
$output->writeln('body:'.$body);
$output->writeln('html:'.$html);
function decompose($address, $compareDomain = null)
{
$addressAry = mailparse_rfc822_parse_addresses($address);
if (!sizeOf($addressAry)){ // missing address
exit;
}
if (sizeOf($addressAry) > 1){ // more than one address (feedback error - todo )
exit;
}
$address = $addressAry[0]['address'];
list($id, $domain) = explode('@', $address);
if (!$id || !$domain || $domain == $compareDomain){
exit;
}
return array($id, $domain);
}