-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
55 lines (49 loc) · 2.29 KB
/
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
<?php
// phpinfo();
// print imap_base64("SU1BUCBleHRlbnNpb24gc2VlbXMgdG8gYmUgaW5zdGFsbGVkLiA=");
// check for common errors
if (version_compare(phpversion(), '7.2', '<')) {
die("ERROR! The php version isn't high enough, you need at least 7.2 to run this application! But you have: " . phpversion());
}
extension_loaded("imap") || die('ERROR: IMAP extension not loaded. Please see the installation instructions in the README.md');
# load php dependencies:
require_once './vendor/autoload.php';
require_once './config_helper.php';
require_once './sqlite_connector.php';
require_once './User.php';
require_once './imap_client.php';
require_once './controller.php';
load_config();
$databaseClient = new DatabaseController($config['db_name'], $config['table_name']);
$imapClient = new ImapClient($config['imap']['url'], $config['imap']['username'], $config['imap']['password']);
$ip = "";
/** */
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
if (DisplayEmailsController::matches()) {
DisplayEmailsController::invoke($imapClient, $config, $databaseClient);
} elseif (RedirectToAddressController::matches()) {
RedirectToAddressController::invoke($imapClient, $config);
} elseif (RedirectToRandomAddressController::matches()) {
RedirectToRandomAddressController::invoke($imapClient, $config, $ip);
} elseif (DownloadEmailController::matches()) {
DownloadEmailController::invoke($imapClient, $config);
} elseif (DeleteEmailController::matches()) {
DeleteEmailController::invoke($imapClient, $config);
} elseif (HasNewMessagesControllerJson::matches()) {
HasNewMessagesControllerJson::invoke($imapClient, $config, $databaseClient);
} elseif (GenerateRSSFeedController::matches()){
GenerateRSSFeedController::invoke($imapClient, $config, $databaseClient);
} elseif (DeletePanelController::matches()){
DeletePanelController::invoke($imapClient, $databaseClient, $config);
} else {
// If requesting the main site, just redirect to a new random mailbox.
RedirectToRandomAddressController::invoke($imapClient, $config, $ip);
}
// delete after each request
$imapClient->delete_old_messages($config['delete_messages_older_than']);