-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreview-attachment.php
More file actions
executable file
·63 lines (51 loc) · 1.71 KB
/
preview-attachment.php
File metadata and controls
executable file
·63 lines (51 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
require_once 'config/config.php';
require_once 'classes/ImapClient.php';
// Verificar autenticación
if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true) {
http_response_code(401);
die('No autorizado');
}
// Verificar parámetros requeridos
$messageId = intval($_GET['message_id'] ?? 0);
$partId = $_GET['part_id'] ?? '';
$folder = $_GET['folder'] ?? 'INBOX';
if (!$messageId || !$partId) {
http_response_code(400);
die('Parámetros inválidos');
}
try {
$imapClient = new ImapClient($_SESSION['email'], $_SESSION['password'], $_SESSION['current_server'] ?? null);
$imapClient->selectFolder($folder);
// Obtener el adjunto
$attachment = $imapClient->getAttachment($messageId, $partId);
if (!$attachment) {
http_response_code(404);
die('Adjunto no encontrado');
}
$mimeType = $attachment['mime_type'] ?? 'application/octet-stream';
// Solo permitir preview de tipos seguros
$previewTypes = [
'image/jpeg',
'image/png',
'image/gif',
'image/bmp',
'text/plain',
'text/csv'
];
if (!in_array($mimeType, $previewTypes)) {
http_response_code(400);
die('Tipo de archivo no compatible para preview');
}
// Configurar headers para mostrar inline
header('Content-Type: ' . $mimeType);
header('Cache-Control: private, max-age=3600');
header('Content-Length: ' . strlen($attachment['data']));
// Enviar el contenido
echo $attachment['data'];
} catch (Exception $e) {
error_log('Error previewing attachment: ' . $e->getMessage());
http_response_code(500);
die('Error al mostrar el adjunto: ' . $e->getMessage());
}
?>