up
We'll setup an email address that takes all email it receives and puts it into a database. Add a user and put the following in their ~/.forward file:

"|IFS=' ' && exec /usr/local/bin/db.sh -f- || exit 75 #replace_with_login_name"

We use the db.sh php script in /usr/local/bin to put the email into the database:

#!/usr/local/bin/php -q
<?php

$fd = fopen ("/dev/stdin", "r");
while (!feof ($fd)) {
    $buffer .= fgets($fd, 4096);
}
fclose ($fd);

// debug stuff
//$fd = fopen ("/tmp/db.tmp", "w");
//fwrite ($fd, $buffer, strlen($buffer));
//fclose($fd);

require_once("DB.php");
require_once("db_config.php");

$db_name = "rawio";
$dsn = "mysql://$user:$password@$host/$db_name";

$db = DB::connect($dsn);

if (DB::isError($db))
    die ($db->getMessage());
$sql = "INSERT INTO test (id, text) VALUES ('', '".addslashes($buffer)."')";
$result = $db->query($sql);

if (DB::isError($result))
    die ($result->getMessage());

?>

Note that we are using DB.php from PEAR to abstract the database. Local database settings (user, password, etc) are stored in the db_config.php file. Be sure to chmod +x db.sh.

The simple database schema for test:

CREATE TABLE test (
   id int(11) NOT NULL auto_increment,
   text text NOT NULL,
   PRIMARY KEY (id),
   UNIQUE id (id),
   KEY id_2 (id)
);

That pretty much wraps it up... Now we can go ahead and enhance the database schema and work on integrating this information into our websites. I am personally using this for a PIM (personal information something or other). Now I can easily forward anything important to the new email address and have it automatically stored in my database for future reference. It might make more sense to use procmail to sort out the stuff that you want sent to the db (for example in subject put [PIM] and mail it to yourself, have a procmail recipe grab anything with [PIM] in it and shove it off to the php script). That way you can avoid using an additional email address... We are also susceptible to spam and email sent from other people attempting to break our system or pollute it. Something to consider...