Created
November 4, 2012 15:32
-
-
Save reinvented/4012320 to your computer and use it in GitHub Desktop.
PHP script to use as a target for Postmark Inbound webhooks to create Trac tickets
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
<?php | |
include 'Mail.php'; | |
include 'Mail/mime.php' ; | |
define("MAIL_MIME_CRLF","\r\n"); | |
$json = file_get_contents('php://input'); | |
$email = json_decode($json); | |
$text = $email->TextBody; | |
$html = $email->HtmlBody; | |
$crlf = "\n"; | |
$hdrs = array( | |
'From' => $email->From, | |
'Subject' => $email->Subject, | |
'Cc' => $email->Cc, | |
); | |
$mime = new Mail_mime(array('eol' => $crlf)); | |
$mime->setTXTBody($text); | |
$mime->setHTMLBody($html); | |
if ($email->Attachments) { | |
foreach($email->Attachments as $key => $a) { | |
$blob = base64_decode($a->Content); | |
$uid = uniqid(); | |
$fp = fopen("/tmp/file-$uid","w"); | |
fwrite($fp,$blob); | |
fclose($fp); | |
$mime->addAttachment("/tmp/file-$uid", $a->ContentType, $a->Name); | |
} | |
} | |
$filename = "/tmp/inbound-test-" . uniqid() . ".txt"; | |
$fp = fopen($filename,"w"); | |
fwrite($fp,$mime->getMessage("\n\n",null,$hdrs)); | |
fclose($fp); | |
system("/usr/local/bin/email2trac < $filename"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment