summaryrefslogtreecommitdiff
path: root/index.php
blob: e6213f3ba10c13def4c66483d4335c9c5ca70e63 (plain)
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
<?php
require_once __DIR__ . '/bootstrap.php';

$user = $_REQUEST['user'];
$pass = $_REQUEST['token'];
$inbox = strtoupper($_REQUEST['mailbox']);
$max_items = intval($_REQUEST['max_items']);
$ttl = 60*60;

if ( "" === $_REQUEST['user'] || "" === $_REQUEST['token'] ) {
	header( $_SERVER['SERVER_PROTOCOL'] . ' 400 Invalid Request.');
	echo "Invalid user or token supplied.";
	exit;
}

if ( "" === $_REQUEST['mailbox'] ) {
	$inbox = "INBOX";
}
$inbox = explode(",", $inbox);

if ( 0 <= $_REQUEST['max_items'] ) {
	$max_items = 10;
}
if ( $max_items > 100 ) {
	$max_items = 100;
}

#var_dump($user, $pass, $inbox, $max_items); exit;
$mail = getMail($user, $pass, $inbox, $max_items);

$inbox_string = implode(",", $inbox);

$cache_key = md5($user . $inbox_string);
$client = new Predis\Client('tcp://127.0.0.1:6379?database=2');

$feed = $client->get('feed_' . $cache_key);
if ( false !== $feed ) {
	$feed = generate_feed($mail, $user, $inbox_string);
	$client->set('feed_' . $cache_key, $feed);
	$client->expire('feed_' . $cache_key, $ttl);
}

header("Content-type: application/rss+xml");
echo $feed;