v3
This commit is contained in:
parent
c5ff318833
commit
365ab67691
@ -22,7 +22,7 @@ $lang = [
|
|||||||
|
|
||||||
// Manual Email
|
// Manual Email
|
||||||
"option_1" => "الخيار 1: رفع ملف بريد إلكتروني",
|
"option_1" => "الخيار 1: رفع ملف بريد إلكتروني",
|
||||||
"choose_email_file" => "اختر ملف البريد الإلكتروني (.eml أو .txt)",
|
"choose_email_file" => "اختر ملفًا (.eml, .txt, .pdf, .doc, .docx)",
|
||||||
"analyze_and_populate" => "تحليل الملف وتعبئة الحقول",
|
"analyze_and_populate" => "تحليل الملف وتعبئة الحقول",
|
||||||
"option_2" => "الخيار 2: إدخال يدوي",
|
"option_2" => "الخيار 2: إدخال يدوي",
|
||||||
"from" => "من",
|
"from" => "من",
|
||||||
@ -43,6 +43,10 @@ $lang = [
|
|||||||
"language" => "اللغة",
|
"language" => "اللغة",
|
||||||
"arabic" => "العربية",
|
"arabic" => "العربية",
|
||||||
"english" => "English",
|
"english" => "English",
|
||||||
"french" => "Français"
|
"french" => "Français",
|
||||||
|
|
||||||
|
// أخطاء تحميل الملفات
|
||||||
|
"unsupported_file_type" => "نوع الملف غير مدعوم. يرجى رفع ملف من نوع .eml, .txt, .pdf, .doc, or .docx.",
|
||||||
|
"error_parsing_file" => "تعذر استخراج النص من الملف. قد يكون فارغًا أو تالفًا أو محميًا بكلمة مرور."
|
||||||
];
|
];
|
||||||
?>
|
?>
|
||||||
@ -22,7 +22,7 @@ $lang = [
|
|||||||
|
|
||||||
// Manual Email
|
// Manual Email
|
||||||
"option_1" => "Option 1: Upload Email File",
|
"option_1" => "Option 1: Upload Email File",
|
||||||
"choose_email_file" => "Choose an email file (.eml or .txt)",
|
"choose_email_file" => "Choose a file (.eml, .txt, .pdf, .doc, .docx)",
|
||||||
"analyze_and_populate" => "Analyze and Populate Fields",
|
"analyze_and_populate" => "Analyze and Populate Fields",
|
||||||
"option_2" => "Option 2: Manual Entry",
|
"option_2" => "Option 2: Manual Entry",
|
||||||
"from" => "From",
|
"from" => "From",
|
||||||
@ -43,6 +43,10 @@ $lang = [
|
|||||||
"language" => "Language",
|
"language" => "Language",
|
||||||
"arabic" => "العربية",
|
"arabic" => "العربية",
|
||||||
"english" => "English",
|
"english" => "English",
|
||||||
"french" => "Français"
|
"french" => "Français",
|
||||||
|
|
||||||
|
// File Upload Errors
|
||||||
|
"unsupported_file_type" => "Unsupported file type. Please upload a .eml, .txt, .pdf, .doc, or .docx file.",
|
||||||
|
"error_parsing_file" => "Could not extract text from the file. It might be empty, corrupted, or password-protected."
|
||||||
];
|
];
|
||||||
?>
|
?>
|
||||||
@ -22,7 +22,7 @@ $lang = [
|
|||||||
|
|
||||||
// Manual Email
|
// Manual Email
|
||||||
"option_1" => "Option 1 : Télécharger un fichier e-mail",
|
"option_1" => "Option 1 : Télécharger un fichier e-mail",
|
||||||
"choose_email_file" => "Choisissez un fichier e-mail (.eml ou .txt)",
|
"choose_email_file" => "Choisissez un fichier (.eml, .txt, .pdf, .doc, .docx)",
|
||||||
"analyze_and_populate" => "Analyser et remplir les champs",
|
"analyze_and_populate" => "Analyser et remplir les champs",
|
||||||
"option_2" => "Option 2 : Saisie manuelle",
|
"option_2" => "Option 2 : Saisie manuelle",
|
||||||
"from" => "De",
|
"from" => "De",
|
||||||
@ -43,6 +43,10 @@ $lang = [
|
|||||||
"language" => "Langue",
|
"language" => "Langue",
|
||||||
"arabic" => "العربية",
|
"arabic" => "العربية",
|
||||||
"english" => "English",
|
"english" => "English",
|
||||||
"french" => "Français"
|
"french" => "Français",
|
||||||
|
|
||||||
|
// Erreurs de téléchargement de fichiers
|
||||||
|
"unsupported_file_type" => "Type de fichier non pris en charge. Veuillez télécharger un fichier .eml, .txt, .pdf, .doc ou .docx.",
|
||||||
|
"error_parsing_file" => "Impossible d'extraire le texte du fichier. Il est peut-être vide, corrompu ou protégé par un mot de passe."
|
||||||
];
|
];
|
||||||
?>
|
?>
|
||||||
@ -11,32 +11,62 @@ $upload_error = '';
|
|||||||
// Handle File Upload and Parsing
|
// Handle File Upload and Parsing
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['email_file']) && $_FILES['email_file']['error'] == UPLOAD_ERR_OK) {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['email_file']) && $_FILES['email_file']['error'] == UPLOAD_ERR_OK) {
|
||||||
$file_tmp_path = $_FILES['email_file']['tmp_name'];
|
$file_tmp_path = $_FILES['email_file']['tmp_name'];
|
||||||
$file_content = file_get_contents($file_tmp_path);
|
$file_name = $_FILES['email_file']['name'];
|
||||||
|
$file_ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
|
||||||
|
|
||||||
if ($file_content) {
|
$message = ''; // Initialize message
|
||||||
// Basic EML parsing
|
$subject = pathinfo($file_name, PATHINFO_FILENAME); // Use filename as subject by default
|
||||||
$headers = [];
|
$from = ''; // From is not available in these files
|
||||||
$body_started = false;
|
|
||||||
$body_lines = [];
|
|
||||||
$lines = explode("\n", $file_content);
|
|
||||||
|
|
||||||
foreach ($lines as $line) {
|
// IMPORTANT: Ensure the temp file path is properly escaped to prevent command injection
|
||||||
if (!$body_started) {
|
$escaped_path = escapeshellarg($file_tmp_path);
|
||||||
if (preg_match('/^From:\s*(.*)/i', $line, $matches)) {
|
|
||||||
$from = trim($matches[1]);
|
switch ($file_ext) {
|
||||||
} elseif (preg_match('/^Subject:\s*(.*)/i', $line, $matches)) {
|
case 'pdf':
|
||||||
$subject = trim($matches[1]);
|
$message = shell_exec("pdftotext " . $escaped_path . " -");
|
||||||
} elseif (trim($line) === '') {
|
break;
|
||||||
$body_started = true; // Headers are done, body begins
|
case 'docx':
|
||||||
|
$message = shell_exec("docx2txt < " . $escaped_path);
|
||||||
|
break;
|
||||||
|
case 'doc':
|
||||||
|
$message = shell_exec("antiword " . $escaped_path);
|
||||||
|
break;
|
||||||
|
case 'eml':
|
||||||
|
case 'txt':
|
||||||
|
$file_content = file_get_contents($file_tmp_path);
|
||||||
|
if ($file_content) {
|
||||||
|
// Basic EML parsing
|
||||||
|
$body_started = false;
|
||||||
|
$body_lines = [];
|
||||||
|
$lines = explode("\n", $file_content);
|
||||||
|
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
if (!$body_started) {
|
||||||
|
if (preg_match('/^From:\s*(.*)/i', $line, $matches)) {
|
||||||
|
$from = trim($matches[1]);
|
||||||
|
} elseif (preg_match('/^Subject:\s*(.*)/i', $line, $matches)) {
|
||||||
|
$subject = trim($matches[1]);
|
||||||
|
} elseif (trim($line) === '') {
|
||||||
|
$body_started = true; // Headers are done, body begins
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$body_lines[] = $line;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
$message = implode("\n", $body_lines);
|
||||||
} else {
|
} else {
|
||||||
$body_lines[] = $line;
|
$upload_error = 'Failed to read uploaded file.';
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
$message = implode("\n", $body_lines);
|
default:
|
||||||
} else {
|
$upload_error = 'Unsupported file type. Please upload a .eml, .txt, .pdf, .doc, or .docx file.';
|
||||||
$upload_error = 'Failed to read uploaded file.';
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (empty($message) && empty($upload_error)) {
|
||||||
|
$upload_error = 'Could not extract text from the file. It might be empty, corrupted, or password-protected.';
|
||||||
|
}
|
||||||
|
|
||||||
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
// Handle Manual Form Submission
|
// Handle Manual Form Submission
|
||||||
$from = isset($_POST['from']) ? $_POST['from'] : '';
|
$from = isset($_POST['from']) ? $_POST['from'] : '';
|
||||||
@ -129,7 +159,7 @@ try {
|
|||||||
<form action="manual_email.php" method="POST" enctype="multipart/form-data">
|
<form action="manual_email.php" method="POST" enctype="multipart/form-data">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="email_file" class="form-label"><?php echo t('choose_email_file'); ?></label>
|
<label for="email_file" class="form-label"><?php echo t('choose_email_file'); ?></label>
|
||||||
<input type="file" class="form-control" id="email_file" name="email_file" accept=".eml,.txt">
|
<input type="file" class="form-control" id="email_file" name="email_file" accept=".eml,.txt,.pdf,.doc,.docx">
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-secondary"><?php echo t('analyze_and_populate'); ?></button>
|
<button type="submit" class="btn btn-secondary"><?php echo t('analyze_and_populate'); ?></button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user