#!/usr/bin/php
<?php
$config['from'] = array('[email protected]');
$config['sendto'] = '[email protected]';
$config['xmpp']['host'] = 'localhost';
$config['xmpp']['port'] = 5222;
$config['xmpp']['user'] = 'username';
$config['xmpp']['pass'] = 'password';
$config['xmpp']['path'] = 'Home';
$config['xmpp']['domain'] = 'jabber.org';
$config['imap']['host'] = '{localhost:143/novalidate-cert}';
$config['imap']['user'] = 'username';
$config['imap']['pass'] = 'password';
require('xmpphp/XMPPHP/XMPP.php');
$xmpp = new XMPPHP_XMPP($config['xmpp']['host'], $config['xmpp']['port'], $config['xmpp']['user'], $config['xmpp']['pass'], $config['xmpp']['path'], $config['xmpp']['domain'], $printlog=true, $loglevel=XMPPHP_Log::LEVEL_WARNING);
$xmpp->connect();
$xmpp->processUntil('session_start');
$mbox = imap_open($config['imap']['host']."INBOX", $config['imap']['user'], $config['imap']['pass']);
if(($mbox == FALSE) || ($xmpp == FALSE)) {
echo 'Verbindung fehlgeschlagen';
$err = imap_errors();
print_r($err);
exit(1);
} else {
$info = imap_check($mbox);
if($info->Nmsgs >= 1) {
for($i=1;$i<=$info->Nmsgs;$i++) {
$header = imap_headerinfo($mbox, $i);
$sender = $header->from[0]->mailbox.'@'.$header->from[0]->host;
if (($header->Unseen == 'U') && (in_array($sender, $config['from']))) {
$message = "From: ".$header->senderaddress."\n";
$message .= "To: ".$header->toaddress."\n";
$message .= imap_body($mbox, $i);
$message = html_entity_decode($message);
$message = utf8_encode($message);
$xmpp->message($config['sendto'], $message);
}
}
}
}
imap_close($mbox);
$xmpp->disconnect();
?>