aboutsummaryrefslogtreecommitdiff
path: root/fetch.php
blob: 1adccc6809c2c50aa0e33cd4e9e39414c95fc9cc (plain) (blame)
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
<!DOCTYPE html>
<html>
<head>
	<title>Fetching new events</title>
	<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<form action="add.php" method="post">
<table>
<tr>
	<th>Select</th>
	<th>Info</th>
	<th>Description</th>
	<th>Warnings</th>
</tr>
<?php
require_once ('mail.php');

$exceptions=[];

$messages=mail_get_unseen_messages();

foreach ($messages as $msg_id){
	try {
		$msg=mail_fetch_message ($msg_id);
		$parsed=mail_parse_message ($msg['body'],['source' => $msg['guessed_source']]);
		$info=$parsed['info'];
		$selected=count ($parsed['warnings'])==0;

		foreach ($info['keywords'] as $i => $keyword){
			$id=get_keyword ($keyword);
			if (is_null ($id)){
				$info['keywords'][$i]='<strong>'.htmlspecialchars ($keyword).'</strong>';
				$selected=false;
			} else
				$info['keywords'][$i]=htmlspecialchars ($keyword);
		}

		$id=get_source ($info['source']);
		if (is_null ($id)){
			$info['source']='<strong>'.htmlspecialchars ($info['source']).'</strong>';
			$selected=false;
		} else
			$info['source']=htmlspecialchars ($info['source']);

		echo '<tr>';

		$checked=$selected ? 'checked="checked"' : '';
		echo '<td><input type="checkbox" '.$checked.' name="messages[]" value="'.$msg_id.'"/></td>';

		echo '<td>';
		echo htmlspecialchars ($info['title']).'<br/>';
		echo htmlspecialchars ($info['location']).'<br/>';
		if ($info['start_date']==$info['end_date'])
			echo $info['start_date'].'<br/>';
		else
			echo $info['start_date'].' to '.$info['end_date'].'<br/>';
		echo implode (', ',$info['keywords']).'<br/>';
		echo $info['source'];
		echo '</td>';

		$description=nl2br (htmlspecialchars ($info['description']));
		echo '<td class="description">'.$description.'</td>';

		echo '<td>';
		if (count ($parsed['warnings'])==0)
			echo '&mdash;';
		else
			foreach ($parsed['warnings'] as $warning)
				echo htmlspecialchars ($warning).'<br/>';
		echo '</td>';

		echo '</tr>';
	} catch (Exception $e){
		$exceptions[]=$e->getMessage();
	}
}

echo '</table>';

if (count ($exceptions)>0){
	echo 'Exceptions:<br/>';
	foreach ($exceptions as $e)
		echo $e.'<br/>';
}

mail_finish();

if (count ($messages)>0)
	echo '<input type="submit" value="Add selected events"/>';
else
	echo '<tr><td colspan="4">No new events found.</td></tr>';
?>
</form>
</body>
</html>