-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresult.php
79 lines (61 loc) · 2.89 KB
/
result.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
<?php
$conf = parse_ini_file("search.conf", true);
require_once('function.php');
openlog('IMAP Headers Fetch', LOG_PID, LOG_MAIL);
$client_user = username();
$user = strtolower(utf8_encode($_POST['username']));
if ( !empty($_POST['folder']) ) $folder = mb_convert_encoding(utf8_encode($_POST['folder']), "UTF7-IMAP", "UTF-8");
else print '<p>'.htmlspecialchars('You insert no folder. I try to looking for from all folders I found!') . '</p>';
$imapsearch = array();
if ( isset($_POST['uid']) ) {
$imapsearch['uid'] = $_POST['uid'];
syslog(LOG_INFO, $client_user.': Looking for a known UID of value <'.$_POST['uid'].'>.');
if (filter_var($imapsearch['uid'], FILTER_VALIDATE_INT) === FALSE)
exit ('<p>'.htmlspecialchars('Please, insert a number, not <'.$imapsearch['uid'].'>').'.</p>');
}
else
$_POST['uid'] = NULL;
if ( isset($_POST['msgid']) )
$imapsearch['Message-ID'] = $_POST['msgid'];
if ( isset($_POST['from']) )
$imapsearch['FROM'] = $_POST['from'];
if ( isset($_POST['to']) )
$imapsearch['TO'] = $_POST['to'];
if ( isset($_POST['subject']) )
$imapsearch['SUBJECT'] = $_POST['subject'];
if (filter_var($user, FILTER_VALIDATE_EMAIL) === FALSE)
exit ('<p>'.htmlspecialchars('Please, insert a valid email address, not <'.$user.'>').'.</p>');
/* Determine the popserver */
$ldapconn = conn_ldap($client_user, $conf['ldap']['server'], $conf['ldap']['port'], $conf['ldap']['dnlog'], $conf['ldap']['password']);
if (!$ldapconn) {
$err = 'LDAP connection error. Exiting...';
syslog(LOG_ERR, $client_user.': Error: '.$err);
exit('Unable to proceed: <pre>'.htmlentities($err).'/pre>');
}
list($_,$dom) = explode('@',$user);
$mailhost = searchAttr($ldapconn,$conf['ldap']['host'],$conf['ldap']['uid'],$user,"o=$dom,".$conf['ldap']['base']);
ldap_close($ldapconn);
if (!isset($mailhost)) exit ('<p>ERROR: '.htmlspecialchars("I can't determine the popserver where <$user> lives.").'</p>');
/*****************************/
print "<hr>";
// connecting to imap mailserver
$openString = '{'.$mailhost.':143/imap/authuser='.$conf['imap']['authuser'].'}';
syslog(LOG_INFO, $client_user.': Looking into mailbox <'.$user.'>');
if ( empty($folder) ) {
$connection = imap_open($openString, $user,$conf['imap']['authpassword'], OP_READONLY)
or exit('<p>'.htmlspecialchars("ERROR connecting to <$mailhost>: " . imap_last_error()).'</p>');
$list = imap_list($connection, $openString, "*");
imap_close($connection);
if (is_array($list)) {
foreach ($list as $val)
print_msg ($client_user, $val,$user,$conf['imap']['authpassword'],$mailhost,$imapsearch,
imap_utf7_decode( ltrim(strstr($val,'}'),'}') ),$_POST['uid']);
} else {
exit( "Imap_list failed: " . imap_last_error() . "\n" );
}
}
else
// get imap_fetch header from folder
print_msg ($client_user, $openString.$folder, $user,$conf['imap']['authpassword'],$mailhost,$imapsearch, $folder, $_POST['uid']);
closelog();
?>