-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMailRecordPatterns.php
84 lines (58 loc) · 2.25 KB
/
MailRecordPatterns.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
<?php
/**
* A filter designed specifcally for MongoDB. It sets the date_sent to the current date object
* generated by the MongoDate class.
*/
MailRecords::addFilter('MailRecords', 'create','filter', function($data, $options) {
if(PVDatabase::getDatabaseType() == 'mongo') {
$data['data']['date_sent'] = new MongoDate();
}
return $data;
}, array('type' => 'closure', 'event' => 'args'));
/**
* Adds an oberser to emails sent through sendEmailPHP method. The observer utilizes the model MailRecords
* and adds emails to the collection owned by the model.
*/
PVMail::addObserver('PVMail::sendEmailPHP', 'read_closure', function($args) {
$mail = new MailRecords();
$mail -> create($args);
}, array('type' => 'closure'));
/**
* Adds an oberser to emails sent through sendEmailSMTP method. The observer utilizes the model MailRecords
* and adds emails to the collection owned by the model.
*/
PVMail::addObserver('PVMail::sendEMailSMTP', 'read_closure', function($args) {
$mail = new MailRecords();
$mail -> create($args);
}, array('type' => 'closure'));
/**
* If Postmarkapp is installed, it will utilize the observer at the end of that application. Every email sent using Postmarkapp will be
* added to the MailRecords method with the feilds return from PostMarkApp
*/
if(class_exists('Postmarkapp')) {
Postmarkapp::addObserver('Postmarkapp::send', 'read_closure', function($args, $feedback) {
$data = array();
if(isset($args['To']))
$data['receiver'] = $args['To'];
if(isset($args['From']))
$data['sender'] = $args['From'];
if(isset($args['HtmlBody']))
$data['html_message'] = $args['HtmlBody'];
if(isset($args['TextBody']))
$data['text_message'] = $args['TextBody'];
if(isset($args['Subject']))
$data['subject'] = $args['Subject'];
if(isset($args['Cc']))
$data['carboncopy'] = $args['Cc'];
if(isset($args['Bcc']))
$data['blindcopy'] = $args['Bcc'];
if(isset($args['ReplyTo']))
$data['reply_to'] = $args['ReplyTo'];
$callback = json_decode($feedback);
$data['message_id'] = $callback -> MessageID;
$data['error_code'] = $callback -> ErrorCode;
$data['response'] = $callback -> Message;
$mail = new MailRecords();
$mail -> create($data);
}, array('type' => 'closure'));
}