-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-message.php
More file actions
executable file
·98 lines (84 loc) · 3.57 KB
/
debug-message.php
File metadata and controls
executable file
·98 lines (84 loc) · 3.57 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
<?php
require_once 'config/config.php';
require_once 'classes/ImapClient.php';
// Verificar autenticación
if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true) {
header('Location: index.php');
exit;
}
$folder = $_GET['folder'] ?? 'INBOX';
$messageId = $_GET['id'] ?? null;
if (!$messageId) {
echo "Por favor proporciona un ID de mensaje: debug-message.php?id=X&folder=INBOX";
exit;
}
try {
$imapClient = new ImapClient($_SESSION['email'], $_SESSION['password'], $_SESSION['current_server'] ?? null);
$imapClient->connect();
$imapClient->selectFolder($folder);
echo "<h1>Debug del Mensaje $messageId</h1>";
// Método 1: imap_fetch_overview
echo "<h2>1. imap_fetch_overview</h2>";
$overview = imap_fetch_overview($imapClient->connection, $messageId);
if (!empty($overview)) {
echo "<pre>";
print_r($overview[0]);
echo "</pre>";
echo "<strong>Estado SEEN (overview): " . ($overview[0]->seen ?? 'no definido') . "</strong><br>";
}
// Método 2: imap_headerinfo
echo "<h2>2. imap_headerinfo</h2>";
$header = imap_headerinfo($imapClient->connection, $messageId);
if ($header) {
echo "Seen: " . ($header->Seen ?? 'no definido') . "<br>";
echo "Unseen: " . ($header->Unseen ?? 'no definido') . "<br>";
echo "Subject: " . ($header->subject ?? 'no definido') . "<br>";
}
// Método 3: Helper method
echo "<h2>3. Helper getMessageSeenStatus</h2>";
$reflection = new ReflectionClass($imapClient);
$method = $reflection->getMethod('getMessageSeenStatus');
$method->setAccessible(true);
$seenStatus = $method->invoke($imapClient, $messageId);
echo "<strong>Estado usando helper: " . ($seenStatus ? 'LEÍDO' : 'NO LEÍDO') . "</strong><br>";
// Método 4: Lo que devuelve getMessages
echo "<h2>4. Estado en getMessages</h2>";
$messages = $imapClient->getMessages($folder, 1, 100);
$currentMessage = null;
foreach ($messages['messages'] as $msg) {
if ($msg['id'] == $messageId) {
$currentMessage = $msg;
break;
}
}
if ($currentMessage) {
echo "<strong>Estado en lista: " . ($currentMessage['seen'] ? 'LEÍDO' : 'NO LEÍDO') . "</strong><br>";
echo "Subject: " . $currentMessage['subject'] . "<br>";
}
// Test de marcado
echo "<h2>5. Prueba de marcado</h2>";
echo "<a href='?id=$messageId&folder=$folder&action=mark_read'>Marcar como leído</a> | ";
echo "<a href='?id=$messageId&folder=$folder&action=mark_unread'>Marcar como no leído</a> | ";
echo "<a href='?id=$messageId&folder=$folder'>Refrescar</a>";
if (isset($_GET['action'])) {
echo "<br><br><strong>Acción: " . $_GET['action'] . "</strong><br>";
if ($_GET['action'] === 'mark_read') {
$imapClient->markAsRead($messageId);
echo "Mensaje marcado como leído<br>";
} elseif ($_GET['action'] === 'mark_unread') {
$imapClient->markAsUnread($messageId);
echo "Mensaje marcado como no leído<br>";
}
echo "<script>setTimeout(function(){ window.location.href = '?id=$messageId&folder=$folder'; }, 2000);</script>";
}
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
// Exponer la conexión para el debug
if (isset($imapClient)) {
$reflection = new ReflectionClass($imapClient);
$connectionProperty = $reflection->getProperty('connection');
$connectionProperty->setAccessible(true);
$imapClient->connection = $connectionProperty->getValue($imapClient);
}
?>