crcx / ent

Ent provides tools and services via an email interface

This URL has Read+Write access

ent / ent.php
100644 79 lines (63 sloc) 2.082 kb
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
<?php
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+----- . . -------
| |\ | |
+--- | \ | |
| | \ | |
+----- | \| |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ent is an application providing tools and services via an
email interface.
 
How it works:
 
- You send mail to an email address
- This code gets run somehow (I use a cron job)
- It parses an mbox file. (/var/mail/ent for me)
- The requests are taken from the subject line
- The results are emailed back to you and your message is
removed from the mbox
 
The code uses several pieces of code written by others. See
the individual files for copyright/license information.
 
This code was written by Charles Childers and is gifted to
the public domain.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
require_once 'mbox.php';
require_once 'html2txt.php';
require_once 'url_get.php';
require_once 'lastrss.php';
 
 
//reads a mbox file
$file = '/var/mail/ent';
 
$filter = array("<", ">");
 
$mbox = new Mail_Mbox($file);
$mbox->open();
 
for ($n = 0; $n < $mbox->size(); $n++)
{
  $type = "none";
  $message = $mbox->get($n);
 
  preg_match('/Return-path: (.*)$/m', $message, $returns);
  $who = str_replace($filter, "", $returns[1]);
 
  /* Stable */
  include 'leaves/www.leaf';
  include 'leaves/lookup.leaf';
  include 'leaves/define.leaf';
  include 'leaves/weather.leaf';
  include 'leaves/news.leaf';
  include 'leaves/ups.leaf';
  include 'leaves/help.leaf';
  include 'leaves/ustime.leaf';
  include 'leaves/man.leaf';
  include 'leaves/quotes.leaf';
  include 'leaves/c2.leaf';
 
  /* Beta */
  include 'leaves/citydata.leaf';
  include 'leaves/translate.leaf';
  include 'leaves/local.leaf';
 
  if ($type == "none")
  {
    $body = "Sorry, but Ent wasn't able to understand your request.";
    $header = "From: Ent <ent@retroforth.org>\r\n"; //optional headerfields
    mail($who, "Sorry...", $body, $header);
  }
 
  $mbox->remove($n);
}
 
$mbox->close();
?>