-
Notifications
You must be signed in to change notification settings - Fork 6
/
SMTP_Server_Index.php
83 lines (62 loc) · 1.45 KB
/
SMTP_Server_Index.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
<?php
/**
* SMTP_Server_Index
*
* @author Jason Johnson <jason@php-smtp.org>
* @copyright Copyright (c) 2008, Jason Johnson
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @version 1.0
* @package php-smtp
*/
class SMTP_Server_Index {
var $handle;
var $records = array();
function SMTP_Server_Index() {
$this->read();
}
function open($mode = 'a') {
$this->handle = fopen(SMTP_INDEX, $mode);
}
function read() {
$this->open('r');
while(!feof($this->handle)) {
$this->records[] = fgetcsv($this->handle);
}
$this->close();
}
function write($file = "", $to = array(), $from = array(), $timestamp = 0) {
$this->open();
for($i = 0; $i < count($to); $i++)
$to[$i] = ($to[$i]['user'].'@'.$to[$i]['domain']);
$from = ($from['user'].'@'.$from['domain']);
fputcsv($this->handle, array($file, join("\t", $to), $from, $timestamp));
$this->close();
}
function get($index) {
if(count($this->records[$index]) != 4)
return false;
$rec = $this->records[$index];
$rec[1] = explode("\t", $rec[1]);
return $rec;
}
function length() {
return count($this->records);
}
function lock() {
flock($this->handle, LOCK_EX);
}
function unlock() {
flock($this->handle, LOCK_UN);
}
function truncate() {
$this->open('r+');
$this->lock();
ftruncate($this->handle, 0);
$this->unlock();
$this->close();
}
function close() {
fclose($this->handle);
}
}
?>