v3
This commit is contained in:
parent
c5ff318833
commit
365ab67691
@ -22,7 +22,7 @@ $lang = [
|
||||
|
||||
// Manual Email
|
||||
"option_1" => "الخيار 1: رفع ملف بريد إلكتروني",
|
||||
"choose_email_file" => "اختر ملف البريد الإلكتروني (.eml أو .txt)",
|
||||
"choose_email_file" => "اختر ملفًا (.eml, .txt, .pdf, .doc, .docx)",
|
||||
"analyze_and_populate" => "تحليل الملف وتعبئة الحقول",
|
||||
"option_2" => "الخيار 2: إدخال يدوي",
|
||||
"from" => "من",
|
||||
@ -43,6 +43,10 @@ $lang = [
|
||||
"language" => "اللغة",
|
||||
"arabic" => "العربية",
|
||||
"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
|
||||
"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",
|
||||
"option_2" => "Option 2: Manual Entry",
|
||||
"from" => "From",
|
||||
@ -43,6 +43,10 @@ $lang = [
|
||||
"language" => "Language",
|
||||
"arabic" => "العربية",
|
||||
"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
|
||||
"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",
|
||||
"option_2" => "Option 2 : Saisie manuelle",
|
||||
"from" => "De",
|
||||
@ -43,6 +43,10 @@ $lang = [
|
||||
"language" => "Langue",
|
||||
"arabic" => "العربية",
|
||||
"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,11 +11,31 @@ $upload_error = '';
|
||||
// Handle File Upload and Parsing
|
||||
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_content = file_get_contents($file_tmp_path);
|
||||
$file_name = $_FILES['email_file']['name'];
|
||||
$file_ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
|
||||
|
||||
$message = ''; // Initialize message
|
||||
$subject = pathinfo($file_name, PATHINFO_FILENAME); // Use filename as subject by default
|
||||
$from = ''; // From is not available in these files
|
||||
|
||||
// IMPORTANT: Ensure the temp file path is properly escaped to prevent command injection
|
||||
$escaped_path = escapeshellarg($file_tmp_path);
|
||||
|
||||
switch ($file_ext) {
|
||||
case 'pdf':
|
||||
$message = shell_exec("pdftotext " . $escaped_path . " -");
|
||||
break;
|
||||
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
|
||||
$headers = [];
|
||||
$body_started = false;
|
||||
$body_lines = [];
|
||||
$lines = explode("\n", $file_content);
|
||||
@ -37,6 +57,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['email_file']) && $_F
|
||||
} else {
|
||||
$upload_error = 'Failed to read uploaded file.';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$upload_error = 'Unsupported file type. Please upload a .eml, .txt, .pdf, .doc, or .docx 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') {
|
||||
// Handle Manual Form Submission
|
||||
$from = isset($_POST['from']) ? $_POST['from'] : '';
|
||||
@ -129,7 +159,7 @@ try {
|
||||
<form action="manual_email.php" method="POST" enctype="multipart/form-data">
|
||||
<div class="mb-3">
|
||||
<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>
|
||||
<button type="submit" class="btn btn-secondary"><?php echo t('analyze_and_populate'); ?></button>
|
||||
</form>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user