-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSendgridParse.php
63 lines (55 loc) · 1.67 KB
/
SendgridParse.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
<?php
Class SendgridParse {
private function parseEmailAddress($raw) {
$name = "";
$email = trim($raw, " '\"");
if (preg_match("/^(.*)<(.*)>.*$/", $raw, $matches)) {
array_shift($matches);
$name = trim($matches[0], " '\"");
$email = trim($matches[1], " '\"");
}
return array(
"name" => $name,
"email" => $email,
"full" => $name . " <" . $email . ">"
);
}
private function parseEmailAddresses($raw) {
$arr = array();
foreach(explode(",", $raw) as $email)
$arr[] = $this->parseEmailAddress($email);
return $arr;
}
function __construct($post = NULL, $files = NULL) {
if (!@$post)
$post = $_POST;
if (!@$files)
$files = $_FILES;
$this->post = $post;
$this->files = $files;
$this->headers = @$post["headers"];
$this->text = @$post["text"];
$this->html = @$post["html"];
$this->fromRaw = @$post["from"];
$this->from = $this->parseEmailAddress(@$this->fromRaw);
$this->toRaw = @$post["to"];
$this->to = $this->parseEmailAddresses(@$this->toRaw);
$this->ccRaw = @$post["cc"];
$this->cc = $this->parseEmailAddresses(@$this->ccRaw);
$this->subject = @$post["subject"];
$this->dkimRaw = @$post["dkim"];
$this->dkim = json_decode(@$this->dkimRaw);
$this->spfRaw = @$post["SPF"];
$this->spf = json_decode(@$this->spfRaw);
$this->charsetsRaw = @$post["charsets"];
$this->charsets = json_decode(@$this->charsetsRaw);
$this->envelopeRaw = @$post["envelope"];
$this->envelope = json_decode(@$this->envelopeRaw);
$this->spam_score = @$post["spam_score"];
$this->spam_report = @$post["spam_report"];
$this->attachments = array();
foreach ($files as $key=>$value)
$this->attachments[] = $value;
}
}
?>