-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_inbox.php
executable file
·66 lines (57 loc) · 1.86 KB
/
check_inbox.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
<?php
require_once 'common.php';
function check_inbox(){
$mbox = imap_open('{'.SMTP_SERVER.':143/novalidate-cert}INBOX', EMAIL_USERNAME, EMAIL_PASSWORD);
$total = imap_num_msg($mbox);
if($total) {
for($n=1;$n<=$total;$n++) {
$header = imap_header($mbox,$n);
$fromaddress = $header->fromaddress;
$toaddress = $header->toaddress;
$subject = $header->subject;
$message_id = $header->message_id;
$date = date('Y-m-d H:i:s', $header->udate);
$body = "";
$st = imap_fetchstructure($mbox,$n);
if (!empty($st->parts)) {
for ($i=0,$j=count($st->parts);$i<$j;$i++) {
$parts = $st->parts[$i];
if ($parts->subtype == 'PLAIN') {
$body = imap_fetchbody($mbox,$n,$i+1);
if ($parts->encoding == 4)
$body = quoted_printable_decode($body);
elseif ($parts->encoding == 3)
$body = base64_decode($body);
}
}
} else {
$body = imap_body($mbox,$n);
if ($st->encoding == 4)
$body = quoted_printable_decode($body);
elseif ($st->encoding == 3)
$body = base64_decode($body);
}
list($from_name,$from_email) = split_email_string($fromaddress);
list($to_name,$to_email) = split_email_string($toaddress);
/* echo "Message No. ".(string)$n."\n";
echo "-----------------\n";
echo 'From: ' .$from_name. '='.$from_email.'=' ."\n";
echo 'To: ' .$to_name. '='.$to_email.'=' ."\n";
echo "Message ID: ".$message_id."\n";
echo 'Subject: ' . $subject ."\n";
echo 'Date: ' . $date."\n";
echo $body;
echo "\n"; */
if (is_valid_subscriber_email($from_email)){
// TODO - Add check for "To Email Address"
insert_to_process_email($from_email,$from_name,$subject,$to_email,$to_name,$body);
} else {
log("Error Inserting Unauthorized Email to Process Email: ".$from_email);
}
imap_delete($mbox, $n);
}
}
imap_expunge($mbox);
imap_close($mbox);
}
?>