-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.php
executable file
·46 lines (37 loc) · 1.52 KB
/
app.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
#!/usr/bin/php -q
<?php
//debug
//$mail = file_get_contents("/tmp/trello2slack/record.txt",true);
require_once("Mail/mimeDecode.php");
if (!STDIN) exit("ERROR");
$mail = "";
while(!feof(STDIN)) {
$mail .= fgets(STDIN);
}
$params['include_bodies'] = true;
$params['decode_bodies'] = true;
$params['decode_headers'] = true;
$decoder = new Mail_mimeDecode($mail);
$structure = $decoder->decode($params);
// elements
//////////////////////////////////////////////////////////////////////////////
$from = $structure -> headers['from'];
$to = $structure -> headers['delivered-to'];
$subject = $structure -> headers['subject'];
$date = $structure -> headers['date'];
$textObj = explode(" is due ",explode("\n",$structure -> parts[0] -> {'body'})[4]);
$task = explode(" (",explode(" on ",$textObj[0])[0]);
$taskTitle = $task[0];
$taskUrl = rtrim($task[1],")");
$dueDate = $textObj[1];
//////////////////////////////////////////////////////////////////////////////
// read info.taxt
$slackInfo = explode("\n",file_get_contents(dirname(__FILE__)."/info.txt",true));
$domain = $slackInfo[0];
$token = $slackInfo[1];
$channel = $slackInfo[2];
$botName = $slackInfo[3];
$iconEmoji = $slackInfo[4];
$text = ">>> Task: *<$taskUrl|$taskTitle>* Due Date: *$dueDate*";
$text = trim($text);
exec("curl -X POST --data-urlencode 'payload={\"channel\": \"$channel\", \"username\": \"$botName\", \"text\": \"$text\", \"icon_emoji\": \"$iconEmoji\"}' https://$domain.slack.com/services/hooks/incoming-webhook?token=$token");