Created
June 25, 2013 16:30
-
-
Save nterray/5859965 to your computer and use it in GitHub Desktop.
Bootstrap for email gateway
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
// As of today you have to update the /etc/aliases to add the following line | |
// | |
// tuleap-123: "|/path/to/script.php 123" | |
// | |
// Where 123 is the id of the artifact. | |
// | |
// TODO: use postfix virtual/catchall to prevent having to modify the aliases | |
// foreach tuples (artifact, user) — see below for the email. | |
// | |
ini_set('error_reporting', 1); | |
ini_set('display_errors', 1); | |
error_reporting(E_ALL); | |
// file_put_contents('/tmp/log', "Artifact id: $argv[1]\n", FILE_APPEND); | |
// {{{ Extract the email content from the received email | |
// TODO: NIH, use existing tools for that | |
// TODO: Remove citations | |
// TODO: Use only the plain/text version | |
$fd = fopen("php://stdin", "r"); | |
$email = ""; | |
$is_in_body = false; | |
while (!feof($fd)) | |
{ | |
$ligne = fgets($fd); | |
if (!trim($ligne)) { | |
$is_in_body = true; | |
} | |
if ($is_in_body) { | |
$email .= $ligne; | |
} | |
} | |
fclose($fd); | |
// }}} | |
// {{{ Extract the user_id and the artifact from the headers | |
// eg: a+123-0ff41b664e02e40a8acf28e2f870e1fa68f64b6a-102@tuleap.example.net | |
// => artifact id = 123 | |
// => user id = 102 | |
// => hash (user id, artifact id, 'some private salt') = 0ff41b…f64b6a | |
// This allow to be sure that the email has not been forged? | |
$artifact_id = get_artifact_id_from_header(); | |
$user_id = get_user_from_header(); | |
// TODO: verify the incoming hash | |
// }}} | |
// {{{ Update the artifact | |
// TODO: use the internal api instead of soap | |
$host = 'http://localhost/'; | |
$host_login = $host .'/soap/?wsdl'; | |
$host_tracker = $host .'/plugins/tracker/soap/?wsdl'; | |
// SOAP options for debug | |
$soap_option = array( | |
'cache_wsdl' => WSDL_CACHE_NONE, | |
'exceptions' => 1, | |
'trace' => 1 | |
); | |
$client_login = new SoapClient($host_login, $soap_option); | |
$session_hash = $client_login->login('admin', 'siteadmin')->session_hash; | |
$session_hash = $client_login->loginAs($session_hash, $user_id); | |
$client_tracker = new SoapClient($host_tracker, $soap_option); | |
$client_tracker->updateArtifact($session_hash, 0, 0, $artifact_id, array(), $email, 'text'); | |
// }}} | |
// file_put_contents('/tmp/log', $email, FILE_APPEND); | |
function get_user_from_header() { | |
return 'nicolas'; | |
} | |
function get_artifact_id_from_header() { | |
global $argv; | |
return $argv[1]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment