Skip to content

Commit

Permalink
Update open_email.php
Browse files Browse the repository at this point in the history
Dynamic Email File Path Detection in open_email.php:

Issue: Hardcoded file path to the D: drive for email files caused issues for users with different drive setups.
Fix: Introduced a function to dynamically check both C:/laragon/bin/sendmail/output/ and D:/laragon/bin/sendmail/output/ directories. The script now searches both paths and reads the email file from whichever path it finds the file.
Code Change:
Added function findEmailFile to check both potential paths.
Updated logic to call this function and fetch the email file dynamically.

Thanks to @martic for the spotlight on this issue
  • Loading branch information
LebToki authored Jun 6, 2024
1 parent 2e789e3 commit 582a0d0
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions assets/inbox/open_email.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
<?php
const EML_FILE_PATH = 'D:/laragon/bin/sendmail/output/';

if (isset($_GET['email'])) {
$emailFile = EML_FILE_PATH . basename($_GET['email']);
if (file_exists($emailFile)) {
$content = file_get_contents($emailFile);
if ($content === false) {
echo "Error reading email file.";
} else {
// Decode and display content as HTML
$decodedContent = htmlspecialchars_decode($content, ENT_QUOTES);
echo nl2br($decodedContent);
}
} else {
echo "Email not found.";
}
} else {
echo "No email specified.";
}
?>
// Define potential paths
$emailFilePaths = [
'C:/laragon/bin/sendmail/output/',
'D:/laragon/bin/sendmail/output/',
];

function findEmailFile($filename, $paths)
{
foreach ($paths as $path) {
$filePath = rtrim($path, '/') . '/' . basename($filename);
if (file_exists($filePath)) {
return $filePath;
}
}
return false;
}

if (isset($_GET['email'])) {
$emailFile = findEmailFile($_GET['email'], $emailFilePaths);
if ($emailFile) {
$content = file_get_contents($emailFile);
if ($content === false) {
echo "Error reading email file.";
} else {
// Decode and display content as HTML
$decodedContent = htmlspecialchars_decode($content, ENT_QUOTES);
echo nl2br($decodedContent);
}
} else {
echo "Email not found.";
}
} else {
echo "No email specified.";
}

0 comments on commit 582a0d0

Please sign in to comment.