diff options
author | Camil Staps | 2020-02-03 09:47:21 +0100 |
---|---|---|
committer | Camil Staps | 2020-02-03 09:47:21 +0100 |
commit | 2af4ffce19df7cdb34d4b509a66bc916ffcb88d1 (patch) | |
tree | 481bc542d1298e1bcb3e39c107a22b39f13f0395 /fetch.php |
Initial commit
Diffstat (limited to 'fetch.php')
-rw-r--r-- | fetch.php | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/fetch.php b/fetch.php new file mode 100644 index 0000000..1adccc6 --- /dev/null +++ b/fetch.php @@ -0,0 +1,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 '—'; + 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> |