[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] phpgroupware mailpipe.php
From: |
Dave Hall |
Subject: |
[Phpgroupware-cvs] phpgroupware mailpipe.php |
Date: |
Tue, 26 Dec 2006 07:20:39 +0000 |
CVSROOT: /sources/phpgroupware
Module name: phpgroupware
Changes by: Dave Hall <skwashd> 06/12/26 07:20:39
Added files:
. : mailpipe.php
Log message:
add new mail handler code, still needs a gui in admin for managing
handlers
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/mailpipe.php?cvsroot=phpgroupware&rev=1.1
Patches:
Index: mailpipe.php
===================================================================
RCS file: mailpipe.php
diff -N mailpipe.php
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ mailpipe.php 26 Dec 2006 07:20:39 -0000 1.1
@@ -0,0 +1,100 @@
+#!/usr/bin/php
+<?php
+/**
+ * phpGroupWare generic mail pipe interface
+ *
+ * This script allows you to add add/update data via email
+ * @author Dave Hall skwashd at phpgroupware org
+ * @copyright (c) 2006-2007 Free Software Foundation Inc
+ */
+
+ /* anonymous user */
+ $user = 'demo';
+ /* anonymous password */
+ $pass = 'guest';
+
+ /*** DO NOT EDIT BELOW THIS LINE ***/
+
+ ini_set('html_errors', false);
+ ini_set('error_append_string', "\n");
+
+ if ( $_SERVER['argc'] != 3
+ || !isset($_SERVER['argv'][1]) || $_SERVER['argv'][1] !=
'--email'
+ || !isset($_SERVER['argv'][2]) || !strlen($_SERVER['argv'][2]) )
+ {
+ fwrite(STDERR, "ERROR: TTS mailpipe called improperly!\n");
+ fwrite(STDERR, "Usage: mailpipe.php --email address@hidden");
+ fwrite(STDERR, "Exiting.\n");
+ fwrite(STDERR, print_r($_SERVER['argv']) . "\nExiting.\n");
+ exit(1);
+ }
+ $email_to = $_SERVER['argv'][2];
+
+ // Hack around error in session class, need a flag to disable cookies
on a per call basis ? - skwashd Jan07
+ $_SERVER['REMOTE_ADDR'] =& $_SERVER['HTTP_HOST'];
+ $_SERVER['HTTP_HOST'] = '0.0.0.0';
+
+ $GLOBALS['phpgw_info']['flags'] = array
+ (
+ 'disable_Template_class' => true,
+ 'login' => true,
+ 'currentapp' => 'login',
+ 'noheader' => true
+ );
+ $phpgw_root = dirname($_SERVER['PHP_SELF']);
+ include_once($phpgw_root . '/header.inc.php');
+
+
+ $msg = createObject('phpgwapi.phpgwapi_mail2array');
+ $msg->parse_input(file_get_contents('php://stdin'));
+
+ $login = sender2phpgw_id($msg->from_email);
+
+ if ( !$login )
+ {
+ echo "ERROR: Sender's email address [{$msg->from_email}] does
not match any user's account, rejecting message\n";
+ $error = true;
+ }
+ else
+ {
+ // This is a hack and the data is a little dodgy, but it works,
so we have a more accurate source IP address
+ $_SERVER['HTTP_HOST'] = $msg->ip;
+
+ $sessionid = $GLOBALS['phpgw']->session->create($login, '',
'known'); //assume email is legit - possible DDoS vector ?
+
+ $mail_handlers =
createObject('phpgwapi.phpgwapi_mail_handlers');
+ $handler = $mail_handlers->get_handler($email_to);
+ if ( $handler )
+ {
+ $error = execMethod($handler, $msg);
+ }
+ else
+ {
+ echo "ERROR: No handler found for $email_to, rejecting
message\n";
+ $error = true;
+ }
+
+ $GLOBALS['phpgw']->session->destroy($sessionid,
$GLOBALS['phpgw']->session->kp3);
+ }
+
+ if ( $error )
+ {
+ exit(1);
+ }
+
+ function sender2phpgw_lid($sender_email)
+ {
+ $contacts = createObject('phpgwapi.contacts');
+ $contact_id = $contacts->search(array('comm_data'),
$sender_email);
+ unset($contacts);
+ if ( is_array($contact_id) && count($contact_id) )
+ {
+ $userid = (int)
ExecMethod('phpgwapi.accounts.search_person', $contact_id);
+ if ( $userid )
+ {
+ return
$GLOBALS['phpgw']->accounts->id2lid($userid);
+ }
+ }
+ return 0;
+ }
+?>
- [Phpgroupware-cvs] phpgroupware mailpipe.php,
Dave Hall <=