-
Notifications
You must be signed in to change notification settings - Fork 1
/
stanford.log.emailsettings.php
203 lines (153 loc) · 4.31 KB
/
stanford.log.emailsettings.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
// Include StanfordEmail
require_once(dirname(__FILE__) . "/stanford.email.php");
/**
* StanfordLog: E-mail settings
*
* E-mail configuration class for StanfordLog
*
* Copyright 2008,2009 Board of Trustees, Leland Stanford Jr. University
* See LICENSE for licensing terms.
*
*/
class StanfordLogEmailSettings {
// StanfordEmail object
private $email;
// Other settings
private $delay; // The delay between messages in seconds
private $truncate_on_send; // After sending an e-mail, truncate log (true) or preserve (false)
private $probability; // Probability of checking the log when the settings are loaded by StanfordLog
/**
* Creates a new StanfordLogEmailSettings object
*/
function __construct() {
// Initialize e-mail
$this->email = new StanfordEmail();
// Set defaults
$this->set_sender("[email protected]", "StanfordLog");
$this->set_subject("StanfordLog Update");
$this->set_delay(600);
$this->set_truncate_on_send(false);
$this->set_probability(.1);
}
/**
* Gets the e-mail object
*
* @return StanfordEmail The e-mail
*/
function get_email() {
return $this->email;
}
/**
* Gets the delay between messages
*
* @return int The delay between messages
*/
function get_delay() {
return $this->delay;
}
/**
* Gets the probability of checking the log when the settings are loaded by StanfordLog
*
* @return float The probability
*/
function get_probability() {
return $this->probability;
}
/**
* Gets the value of truncate on send
*
* @return boolean Truncate on send (true or false)
*/
function get_truncate_on_send() {
return $this->truncate_on_send;
}
/**
* Sets the body of the message (the log itself)
*
* @param string body The body
*/
function set_body($body) {
return $this->email->set_body($body, $is_html = false);
}
/**
* Sets the delay between subsequent e-mails in seconds
*
* @param int delay The delay, in seconds
*/
function set_delay($delay) {
if(is_int($delay) && $delay > 0) {
$this->delay = $delay;
}
else {
throw new Exception("Invalid delay in set_delay (must be greater than zero): $delay");
}
}
/**
* Sets probability of checking the log when the settings are loaded by StanfordLog
*
* @param float probability The probability (between 0 and 1)
*/
function set_probability($probability) {
if($probability >= 0 && $probability <= 1 && (is_float($probability) || is_int($probability))) {
$this->probability = $probability;
}
else {
throw new Exception("Invalid parameter in set_probability (accepts a float between 0 and 1): $probability");
}
}
/**
* Adds a recipient to the message
*
* @param string address E-mail address
* @param string name Name
*
* @return boolean True on success, false on failure
*/
function add_recipient($address, $name='') {
return $this->email->add_recipient($address, $name);
}
/**
* Adds a recipient to the message
*
* @param string address E-mail address
* @param string name Name
*
* @return boolean True on success, false on failure
*/
function set_recipient($address, $name='') {
return $this->email->add_recipient($address, $name);
}
/**
* Sets the sender of the message
*
* @param string address E-mail address
* @param string name Name
*
* @return boolean True on success, false on failure
*/
function set_sender($address, $name='StanfordLog') {
return $this->email->set_sender($address, $name);
}
/**
* Sets the subject of the message
*
* @param string subject The subject
*
* @return boolean True on success, false on failure
*/
function set_subject($subject) {
return $this->email->set_subject($subject);
}
/**
* After the e-mail is sent, should the log be truncated (true) or preserved (false)?
*
* @param boolean value True or false
*
* @return boolean True or false
*/
function set_truncate_on_send($value) {
return $this->truncate_on_send = $value;
}
};
?>