Force open .EML file in email client

0
Thunderbird allows a 'imagem' mail of the email to be saved to a file, this file comes in '.EML' format, and on my system, users upload this file to the system along with what they are doing related to a certain company.

Mechanisms like Steam, Mega, and torrent sites ask the user if they want to run a specific program or a default program for the file type.

I think it's something simple and with HTML, but I could not find how to do it.

  

How to open a direct .EML ext in the email client?

NOTE: It is an intranet system that is not a problem to be invasive.

    
asked by anonymous 23.11.2017 / 12:26

2 answers

1

This is just an additional answer. A nice tool for this would be link , although having a Unix-based or Linux-based system you can do this via the command line.

Assuming you want to detect other types of mime-type, in Ubuntu there is the command file , usage example:

file --mime-type arquivo.eml

In PHP (since it was the solution proposed in your answer) you can use fileinfo , something like:

function mimeType($file)
{
    $mimetype = false;

    if (class_exists('finfo')) {//PHP5.4+
        $finfo     = finfo_open(FILEINFO_MIME_TYPE);
        $mimetype  = finfo_file($finfo, $file);
        finfo_close($finfo);
    } else if (function_exists('mime_content_type')) {//php5.3 ou inferiror
        $mimetype = mime_content_type($file);
    }

    return $mimetype;
}

The usage would look something like:

$mime = mimeType($file);

if (!$mime) {
    die('Formato desconhecido');
} else {
    $filename = urlencode(basename($file));

    header("Content-Disposition: attachment; filename=$filename");
    header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-Type: $mime");
}

Note that I coded filename= should contain only the name (not sure if it passed the full name) it would be interesting to pass basename($file) to get only the same name.

It is also necessary to code, perhaps there is a spacing between the characters of the file name urlencode(basename($filename)) .

    
30.11.2017 / 14:10
0

Solution was only with headers same, it did not work just because it pointed to the default program because 'content-type' was set wrong, with / rfc822 worked correctly ( force the download and suggests the program, that's enough):

header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: message/rfc822");
header("Content-Transfer-Encoding: binary");
readfile($file);
    
23.11.2017 / 14:53