summaryrefslogtreecommitdiff
path: root/feed.php
blob: b1f76305d7789af9a81af1b904d6e372bca8fd84 (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
<?php
use Suin\RSSWriter\Channel;
use Suin\RSSWriter\Feed;
use Suin\RSSWriter\Item;    

function generate_feed($mail, $user_string, $inbox_string) {
	$feed = new Feed();

	$channel = new Channel();
	$channel
	    ->title(htmlspecialchars($user_string . " / " . $inbox_string, ENT_XML1, 'UTF-8'))
	    ->description($inbox_string)
	    ->url("https://www.maxmail.xyz")
	    ->language('en-US')
	    ->copyright('Copyright 2016, maxmail.xyz')
	    ->pubDate(strtotime("r", date(time())))
	    ->lastBuildDate(strtotime("r", date(time())))
	    ->ttl(60)
	    ->appendTo($feed);

	for( $i = 0; $i < count($mail); $i++ ) {
		$item = new Item();

		if( is_null($mail[$i]['textPlain']) ) {
			$body = $mail[$i]['textHtml'];
		} else {
			$body = $mail[$i]['textPlain'];
		}
		$item
		    ->title( htmlspecialchars($mail[$i]["mailbox"] . ": " . $mail[$i]['subject'], ENT_XML1, 'UTF-8') )
		    ->description( "<pre>" . $body . "</pre>" )
		    #->description($body)
		    ->url("https://www.maxmail.xyz/" . $user_string)
		    ->author( htmlspecialchars($mail[$i]['fromName'] . "<" . $mail[$i]['fromAddress'] . ">", ENT_XML1, 'UTF-8') )
		    ->pubDate( strtotime($mail[$i]['date'] ) )
		    ->appendTo($channel);
	}

	ob_start();
	echo $feed;
	return ob_get_clean();
}