Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Ability to download mail as .EML+ #1307

Open
gregecslo opened this issue Sep 10, 2024 · 1 comment
Open

Feature request: Ability to download mail as .EML+ #1307

gregecslo opened this issue Sep 10, 2024 · 1 comment

Comments

@gregecslo
Copy link

gregecslo commented Sep 10, 2024

Hi.
Sometimes we need .EML file for various reasons... So we copied it over sftp, webmin etc...

So I had enough and wrote simple EML downloader, it is not pretty but it does job well.
Can it be included in next efa version?

How I did it:

Create file: /var/www/html/mailscanner/dl_mail.php

<?php

// Get the path from the URL parameter
$path = $_GET['path'];

if (file_exists($path)) {

    $basename = pathinfo($path, PATHINFO_FILENAME);

    $tempFile = tempnam(sys_get_temp_dir(), $basename);

    $emlFile = $tempFile . '.eml';
    rename($tempFile, $emlFile);

    copy($path, $emlFile);

    $filename = $basename . '.eml';
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="' . $filename . '"');
    header('Content-Length: ' . filesize($emlFile));

    readfile($emlFile);

    unlink($emlFile);

} else {
    // Handle the case where the file doesn't exist
    echo "File not found.";
}

Then in: /var/www/html/mailscanner/detail.php
Added to the very end:

// Add footer
html_end();
// Declare paths for mail download
$first_path = $quarantined[0]['path'];
// Download it
echo '<td>' . '<a href="dl_mail.php?path=' . urlencode($first_path) . '" target="_blank">Download .EML</a>' . "</td>\n";
// Close any open db connections
dbclose();

And now I can download mail in EML format from detail page.
It would be awesome if this would be a native feature...
My solution is not pretty but it works :)

image

Thanks!

@shawniverson
Copy link
Member

Code is mostly complete but needs our security-related enhancements added for session and parameter validation and cross site scripting protection. I'll work on this as time permits.

@shawniverson shawniverson self-assigned this Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants