-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage.php
More file actions
executable file
·386 lines (343 loc) · 19.3 KB
/
message.php
File metadata and controls
executable file
·386 lines (343 loc) · 19.3 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<?php
require_once 'config/config.php';
require_once 'classes/ImapClient.php';
require_once 'classes/UserProfile.php';
Config::load();
// Inicializar sistema de traducciones
$i18n = I18n::getInstance();
// Verificar autenticación
if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true) {
header('Location: index.php');
exit;
}
$error = '';
$success = '';
$currentFolder = $_GET['folder'] ?? 'INBOX';
$messageId = intval($_GET['id'] ?? 0);
if (!$messageId) {
header('Location: mailbox.php?folder=' . urlencode($currentFolder));
exit;
}
try {
$imapClient = new ImapClient($_SESSION['email'], $_SESSION['password'], $_SESSION['current_server'] ?? null);
$imapClient->selectFolder($currentFolder);
// Cargar perfil de usuario y actualizar carpeta visitada
$userProfile = new UserProfile($_SESSION['email'], $_SESSION['current_server'] ?? null);
if ($currentFolder !== $userProfile->getLastFolder()) {
$userProfile->updateLastFolder($currentFolder);
}
// Procesar acciones
$accion = $_POST['action'] ?? '';
if ($accion === 'delete') {
$imapClient->deleteMessage($messageId);
header('Location: mailbox.php?folder=' . urlencode($currentFolder));
exit;
} elseif ($accion === 'move') {
if (isset($_POST['target_folder']) && !empty($_POST['target_folder'])) {
$targetFolder = $_POST['target_folder'];
try {
$imapClient->moveMessage($messageId, $targetFolder);
header('Location: mailbox.php?folder=' . urlencode($targetFolder));
exit;
} catch (Exception $moveError) {
$error = 'Error al mover el mensaje: ' . $moveError->getMessage();
}
} else {
$error = 'Debe seleccionar una carpeta de destino válida.';
}
} elseif ($accion === 'mark_read') {
$imapClient->markAsRead($messageId);
$success = 'Mensaje marcado como leído.';
} elseif ($accion === 'mark_unread') {
$imapClient->markAsUnread($messageId);
$success = 'Mensaje marcado como no leído.';
}
// Obtener carpetas para el selector de mover
$folders = $imapClient->getFolders();
$message = $imapClient->getMessage($messageId);
// Agregar automáticamente el contacto del remitente si el mensaje existe
if ($message && !empty($message['from'])) {
try {
$userProfile->autoAddContactFromMessage($message['from']);
// También actualizar el último contacto visto si ya existe
$userProfile->updateContactLastSeen($message['from']);
} catch (Exception $contactError) {
// Error al agregar contacto, pero no interrumpir la carga del mensaje
error_log("Error al agregar contacto automáticamente: " . $contactError->getMessage());
}
}
} catch (Exception $e) {
$error = 'Error al cargar el mensaje: ' . $e->getMessage();
$message = null;
$folders = [];
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo Config::get('APP_NAME', 'IMAP Client'); ?> - Mensaje</title>
<link rel="stylesheet" href="assets/style.css">
<!-- Favicon -->
<link rel="icon" type="image/svg+xml" href="assets/favicon.svg">
<link rel="icon" type="image/png" href="assets/favicon.png">
<link rel="apple-touch-icon" href="assets/favicon.png">
<!-- PWA Manifest -->
<link rel="manifest" href="manifest.json">
<meta name="theme-color" content="#764ba2">
<style>
.btn-group .btn-success {
margin-right: 5px;
}
.btn-group .btn-success:last-child {
margin-right: 0;
}
.reply-buttons {
display: flex;
gap: 5px;
flex-wrap: wrap;
}
.reply-buttons .btn {
min-width: 100px;
}
@media (max-width: 768px) {
.reply-buttons {
flex-direction: column;
}
.reply-buttons .btn {
width: 100%;
margin-bottom: 5px;
}
}
</style>
</head>
<body>
<header class="header">
<div class="container">
<div class="header-content">
<div class="logo">
<img src="assets/favicon.svg" alt="Logo" class="logo-icon">
<div class="logo-text">
<span class="logo-main"><?php echo Config::get('APP_NAME', 'IMAP Client'); ?></span>
<span class="logo-sub">Cliente de Correo</span>
</div>
</div>
<div class="user-info">
<span><?php echo htmlspecialchars($_SESSION['email']); ?></span>
<a href="profile.php" class="profile-btn" title="<?php echo __('navigation.profile'); ?>">👤</a>
<a href="contacts.php" class="profile-btn" title="<?php echo __('navigation.contacts'); ?>">📇</a>
<a href="logout.php" class="logout-btn"><?php echo __('navigation.logout'); ?></a>
</div>
</div>
</div>
</header>
<div class="container">
<div class="main-layout">
<aside class="sidebar">
<div class="btn-group" style="flex-direction: column; width: 100%;">
<a href="mailbox.php?folder=<?php echo urlencode($currentFolder); ?>" class="btn">
← <?php echo __('navigation.back_to_inbox'); ?>
</a>
<a href="compose.php" class="btn compose-btn">✉ <?php echo __('navigation.compose'); ?></a>
<a href="search.php" class="btn">🔍 <?php echo __('navigation.search'); ?></a>
<?php if ($message): ?>
<div class="reply-buttons">
<a href="compose.php?reply=<?php echo $messageId; ?>&folder=<?php echo urlencode($currentFolder); ?>"
class="btn btn-success" title="Responder solo al remitente">↩ Responder</a>
<a href="compose.php?reply_all=<?php echo $messageId; ?>&folder=<?php echo urlencode($currentFolder); ?>"
class="btn btn-success" title="Responder a todos los destinatarios">↩ Responder a todos</a>
</div>
<?php endif; ?>
</div>
</aside>
<main class="content">
<?php if ($error): ?>
<div class="alert alert-error"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<?php if ($success): ?>
<div class="alert alert-success"><?php echo htmlspecialchars($success); ?></div>
<?php endif; ?>
<?php if ($error && !$message): ?>
<a href="mailbox.php?folder=<?php echo urlencode($currentFolder); ?>" class="btn">
Volver al buzón
</a>
<?php elseif ($message): ?>
<div class="message-actions-header">
<div class="btn-group">
<div class="reply-buttons">
<a href="compose.php?reply=<?php echo $messageId; ?>&folder=<?php echo urlencode($currentFolder); ?>"
class="btn btn-sm btn-success" title="Responder solo al remitente">↩ Responder</a>
<a href="compose.php?reply_all=<?php echo $messageId; ?>&folder=<?php echo urlencode($currentFolder); ?>"
class="btn btn-sm btn-success" title="Responder a todos los destinatarios">↩ Todos</a>
</div>
<?php if (!$message['seen']): ?>
<form method="POST" class="inline-form">
<input type="hidden" name="action" value="mark_read">
<button type="submit" class="btn btn-sm btn-read">
✓ Marcar como leído
</button>
</form>
<?php else: ?>
<form method="POST" class="inline-form">
<input type="hidden" name="action" value="mark_unread">
<button type="submit" class="btn btn-sm btn-unread">
↺ Marcar como no leído
</button>
</form>
<?php endif; ?>
<form method="POST" class="inline-form">
<input type="hidden" name="action" value="delete">
<button type="submit" class="btn btn-sm btn-danger"
onclick="return confirm('¿Estás seguro de que quieres eliminar este mensaje?')">
🗑 Eliminar
</button>
</form>
<form method="POST" class="inline-form move-form">
<input type="hidden" name="action" value="move">
<select name="target_folder" class="folder-select"
onchange="if(this.value !== '') {
if(confirm('¿Mover este mensaje a la carpeta \"' + this.options[this.selectedIndex].text + '\"?')) {
this.form.submit();
} else {
this.selectedIndex = 0;
}
}">
<option value="">📁 Mover a...</option>
<?php foreach ($folders as $folderOption): ?>
<option value="<?php echo htmlspecialchars($folderOption); ?>"
<?php echo $folderOption === $currentFolder ? 'disabled' : ''; ?>>
<?php echo htmlspecialchars($folderOption); ?>
</option>
<?php endforeach; ?>
</select>
</form>
</div>
</div>
<div class="message-header">
<h2><?php echo htmlspecialchars($message['subject']); ?></h2>
<div class="message-meta">
<strong>De:</strong>
<span><?php echo htmlspecialchars($message['from_name'] ?: $message['from']); ?></span>
<strong>Para:</strong>
<span><?php echo htmlspecialchars($message['to']); ?></span>
<?php if (!empty($message['cc'])): ?>
<strong>CC:</strong>
<span><?php echo htmlspecialchars($message['cc']); ?></span>
<?php endif; ?>
<strong>Fecha:</strong>
<span><?php echo $message['date']; ?></span>
<?php if (!empty($message['attachments'])): ?>
<strong>Adjuntos:</strong>
<div class="attachments-list">
<?php foreach ($message['attachments'] as $attachment): ?>
<?php
// Determinar icono según extensión
$filename = $attachment['filename'];
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
$icon = '📎'; // Por defecto
switch ($extension) {
case 'pdf':
$icon = '📄';
break;
case 'doc':
case 'docx':
$icon = '📝';
break;
case 'xls':
case 'xlsx':
$icon = '📊';
break;
case 'ppt':
case 'pptx':
$icon = '📋';
break;
case 'zip':
case 'rar':
case '7z':
$icon = '🗜️';
break;
case 'jpg':
case 'jpeg':
case 'png':
case 'gif':
case 'bmp':
$icon = '🖼️';
break;
case 'mp3':
case 'wav':
case 'flac':
$icon = '🎵';
break;
case 'mp4':
case 'avi':
case 'mkv':
$icon = '🎬';
break;
case 'txt':
$icon = '📃';
break;
}
?>
<div class="attachment-item">
<span class="attachment-info">
<span class="attachment-icon"><?php echo $icon; ?></span>
<span class="attachment-details">
<span class="attachment-name"><?php echo htmlspecialchars($attachment['filename']); ?></span>
<span class="attachment-size">(<?php echo number_format($attachment['size'] / 1024, 1); ?> KB)</span>
</span>
</span>
<div class="attachment-actions">
<?php
// Determinar si se puede previsualizar
$canPreview = in_array($extension, ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'txt', 'csv']);
?>
<?php if ($canPreview): ?>
<a href="preview-attachment.php?message_id=<?php echo $messageId; ?>&part_id=<?php echo $attachment['part']; ?>&folder=<?php echo urlencode($currentFolder); ?>"
class="btn btn-sm btn-preview"
target="_blank"
title="Previsualizar <?php echo htmlspecialchars($attachment['filename']); ?>">
👁️ Ver
</a>
<?php endif; ?>
<a href="download-attachment.php?message_id=<?php echo $messageId; ?>&part_id=<?php echo $attachment['part']; ?>&folder=<?php echo urlencode($currentFolder); ?>"
class="btn btn-sm btn-attachment"
target="_blank"
title="Descargar <?php echo htmlspecialchars($attachment['filename']); ?>">
⬇️ Descargar
</a>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
<div class="message-body">
<?php echo $message['body']; ?>
</div>
<div class="move-message-container">
<form method="POST" class="move-message-form">
<input type="hidden" name="action" value="move">
<label for="target_folder">Mover a carpeta:</label>
<select name="target_folder" id="target_folder" required>
<option value="">Seleccionar carpeta</option>
<?php foreach ($folders as $folder): ?>
<option value="<?php echo htmlspecialchars($folder); ?>"
<?php echo $folder === $currentFolder ? 'disabled' : ''; ?>>
<?php echo htmlspecialchars($folder); ?>
</option>
<?php endforeach; ?>
</select>
<button type="submit" class="btn btn-move"
onclick="return confirm('¿Mover este mensaje a la carpeta seleccionada?')">
📦 Mover
</button>
</form>
</div>
<?php endif; ?>
</main>
</div>
</div>
</body>
</html>