Skip to content

Instantly share code, notes, and snippets.

@reinvented
Created November 4, 2012 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reinvented/4012320 to your computer and use it in GitHub Desktop.
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
<?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