-
Notifications
You must be signed in to change notification settings - Fork 4
/
cmd_smtp.php
193 lines (146 loc) · 3.15 KB
/
cmd_smtp.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
<?php
define("MAX_DATA_LEN", 1024);
$smtp_to_email = "";
$smtp_to_name = "";
$smtp_subject = "";
$smtp_data = "";
function cmd_smtp_server($cmd)
{
if(count($cmd) < 4)
{
esmtp_msa("", 0);
return slave_write(ERR_OK);
}
echo "cmd_smtp_server: ", $cmd[2], " ", $cmd[3], "\r\n";
esmtp_msa($cmd[2], (int)$cmd[3]);
return slave_write(ERR_OK);
}
function cmd_smtp_login($cmd)
{
if(count($cmd) < 4)
return slave_write(ERR_CMD_ARG);
echo "cmd_smtp_login: ", $cmd[2], " ", $cmd[3], "\r\n";
esmtp_auth($cmd[2], $cmd[3]);
return slave_write(ERR_OK);
}
function cmd_smtp_from($cmd)
{
slave_write(ERR_OK);
$email = "";
$name = "";
if(!slave_read_data($email, 10))
return 0;
if(!slave_read_data($name, 10))
return 0;
echo "cmd_smtp_from: \"$name\" <$email>\r\n";
esmtp_account($email, $name);
return 0;
}
function cmd_smtp_to($cmd)
{
global $smtp_to_email, $smtp_to_name;
slave_write(ERR_OK);
$email = "";
$name = "";
if(!slave_read_data($email, 10))
return 0;
if(!slave_read_data($name, 10))
return 0;
echo "cmd_smtp_to: \"$name\" <$email>\r\n";
$smtp_to_email = $email;
$smtp_to_name = $name;
return 0;
}
function cmd_smtp_subject($cmd)
{
global $smtp_subject;
slave_write(ERR_OK);
$rlen = slave_read_data($smtp_subject, 10);
echo "cmd_smtp_subject: $smtp_subject\r\n";
return 0;
}
function cmd_smtp_data($cmd)
{
global $smtp_data;
if(count($cmd) > 2)
{
if($cmd[2] == "begin")
{
echo "cmd_smtp_data: begin\r\n";
$smtp_data = "";
return slave_write(ERR_OK);
}
else
return slave_write(ERR_CMD_ARG);
}
slave_write(ERR_OK);
$rbuf = "";
$rlen = slave_read_data($rbuf, 10);
echo "$rbuf";
if((strlen($smtp_data) + $rlen) <= MAX_DATA_LEN)
$smtp_data .= $rbuf;
return 0;
}
function cmd_smtp_send($cmd)
{
global $smtp_to_email, $smtp_to_name;
global $smtp_subject, $smtp_data;
global $tcp_pid;
if($tcp_pid[TCP_ID_SMTP])
{
pid_close($tcp_pid[TCP_ID_SMTP]);
$tcp_pid[TCP_ID_SMTP] = 0;
}
if(count($cmd) > 2)
{
if($cmd[2] == "ip6")
$ip6 = true;
else
return slave_write(ERR_CMD_ARG);
}
else
$ip6 = false;
esmtp_setup(UDP_ID_DNS, TCP_ID_SMTP, "", $ip6);
esmtp_start($smtp_to_email, $smtp_to_name, $smtp_subject, $smtp_data);
return slave_write(ERR_OK);
}
function cmd_smtp_status($cmd)
{
$msg = esmtp_loop();
if($msg === false)
return slave_write(ERR_OK);
else
{
if(!$msg)
return slave_write(ERR_OK, "0");
else
return slave_write(ERR_OK, $msg);
}
}
function cmd_smtp($cmd)
{
if(count($cmd) < 2)
return slave_write(ERR_CMD_ARG);
switch($cmd[1])
{
case "server":
return cmd_smtp_server($cmd);
case "login":
return cmd_smtp_login($cmd);
case "from":
return cmd_smtp_from($cmd);
case "to":
return cmd_smtp_to($cmd);
case "subject":
return cmd_smtp_subject($cmd);
case "data":
return cmd_smtp_data($cmd);
case "send":
return cmd_smtp_send($cmd);
case "status":
return cmd_smtp_status($cmd);
default:
return slave_write(ERR_CMD_ARG);
}
}
?>