/
email_queue_api.php
159 lines (126 loc) · 4.26 KB
/
email_queue_api.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
<?php
# Mantis - a php based bugtracking system
# Mantis is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# Mantis is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mantis. If not, see <http://www.gnu.org/licenses/>.
/**
* @package CoreAPI
* @subpackage EmailQueueAPI
* @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
* @copyright Copyright (C) 2002 - 2009 Mantis Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
*/
class EmailData {
// properties set during creation
var $email = '';
var $subject = '';
var $body = '';
var $metadata = array(
'headers' => array(),
);
// auto-populated properties
var $email_id = 0;
var $submitted = '';
};
# Return a copy of the bug structure with all the instvars prepared for db insertion
function email_queue_prepare_db( $p_email_data ) {
$p_email_data->email_id = db_prepare_int( $p_email_data->email_id );
return $p_email_data;
}
function email_queue_add( $p_email_data ) {
$t_email_data = email_queue_prepare_db( $p_email_data );
# email cannot be blank
if( is_blank( $t_email_data->email ) ) {
error_parameters( lang_get( 'email' ) );
trigger_error( ERROR_EMPTY_FIELD, ERROR );
}
# subject cannot be blank
if( is_blank( $t_email_data->subject ) ) {
error_parameters( lang_get( 'subject' ) );
trigger_error( ERROR_EMPTY_FIELD, ERROR );
}
# body cannot be blank
if( is_blank( $t_email_data->body ) ) {
error_parameters( lang_get( 'body' ) );
trigger_error( ERROR_EMPTY_FIELD, ERROR );
}
$t_email_table = db_get_table( 'mantis_email_table' );
$c_email = $t_email_data->email;
$c_subject = $t_email_data->subject;
$c_body = $t_email_data->body;
$c_metadata = serialize( $t_email_data->metadata );
$query = "INSERT INTO $t_email_table
( email,
subject,
body,
submitted,
metadata)
VALUES
( " . db_param() . ",
" . db_param() . ",
" . db_param() . ",
" . db_param() . ",
" . db_param() . "
)";
db_query_bound( $query, Array( $c_email, $c_subject, $c_body, db_now(), $c_metadata ) );
return db_insert_id( $t_email_table, 'email_id' );
}
function email_queue_row_to_object( $p_row ) {
# typically this function takes as an input the result of db_fetch_array() which can be false.
if( $p_row === false ) {
return false;
}
$t_row = $p_row;
$t_row['submitted'] = db_unixtimestamp( $t_row['submitted'] );
$t_row['metadata'] = unserialize( $t_row['metadata'] );
$t_email_data = new EmailData;
$t_row_keys = array_keys( $t_row );
$t_vars = get_object_vars( $t_email_data );
# Check each variable in the class
foreach( $t_vars as $t_var => $t_value ) {
# If we got a field from the DB with the same name
if( in_array( $t_var, $t_row_keys, true ) ) {
# Store that value in the object
$t_email_data->$t_var = $t_row[$t_var];
}
}
return $t_email_data;
}
function email_queue_get( $p_email_id ) {
$c_email_id = db_prepare_int( $p_email_id );
$t_email_table = db_get_table( 'mantis_email_table' );
$query = "SELECT *
FROM $t_email_table
WHERE email_id=" . db_param();
$result = db_query_bound( $query, Array( $c_email_id ) );
$t_row = db_fetch_array( $result );
return email_queue_row_to_object( $t_row );
}
function email_queue_delete( $p_email_id ) {
$c_email_id = db_prepare_int( $p_email_id );
$t_email_table = db_get_table( 'mantis_email_table' );
$query = "DELETE FROM $t_email_table
WHERE email_id=" . db_param();
db_query_bound( $query, Array( $c_email_id ) );
}
function email_queue_get_ids() {
$t_email_table = db_get_table( 'mantis_email_table' );
$query = "SELECT email_id
FROM $t_email_table
ORDER BY email_id DESC";
$result = db_query_bound( $query );
$t_ids = array();
while(( $t_row = db_fetch_array( $result ) ) !== false ) {
$t_ids[] = $t_row['email_id'];
}
return $t_ids;
}