too long

I'm trying to make a ticketing system, but there are a few ways of doing it.

Piping

The problem with piping is trying to parse attachments and save them to a folder.

Here is a small script that I made

#!/usr/bin/php -q
<?php

//The concern here is having enough mem for emails with attachments.
ini_set('memory_limit', '256M'); 

ini_set("display_errors", "1");
error_reporting(E_ALL);

$data = isset($_SERVER['HTTP_HOST'])?file_get_contents('php://input'):file_get_contents('php://stdin');

$fdw = fopen("mail.txt", "w+");
fwrite($fdw, $data);
fclose($fdw);

?>

By using cPanel`s pipe to program.

It generates a raw email string, which contains alot of things that I don't understand. For example:

--_1f366895-b327-4f84-8985-e3826cdf604b_ Content-Type: application/octet-stream Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="something.zip" UEsFBBQACAAIAJuy1DgAAAAAAAAAAAAAAAAKAAAAcmVwb3J0LnhtbNVdW5fbNpJ+n1/B9Z6zb8Mh rgTPJplGt9N2HNvxiTPjM/vGltjdinUbUrLT+fVLUqJEUKSAYoE0p+10YkIdfwCBQl2+qvru73+s lt6XJM0Dm/X3z4gfPPOyXbyex8vNOvn+2VOSPfv7D3/5y3dpst2kux++28V3y+SH72ab5X61zqr/ 8NbxKv/0PN4Dz3747m+Hh43BWbzaxouHdecH4vlDutlvO8c/J09fN+m8e/zryyTb/SNddn5isdpm

Is there a way to parse them (img,docs,zip or etc) or put them in a folder/something.ext?

Is there another way to do this?

External services?

Is there already some service doing this?

First get your output after the filename and then you decode your content with base64, because as you see in the header: Content-Transfer-Encoding: base64:

file_put_contents('something.zip', base64_decode($output));