V26 doctrine ABSOLUE JAMAIS envoi auto · intent test_email_send refactored DRAFT-ONLY pattern · retourne 2 URLs Gmail compose whitelist yacineutt+ymahboub avec stats live Ethica 141K HCPs injected · action explicite Yacine clic Send · JAMAIS WEVIA ni Claude ne clique - doctrine renforcee dans response JSON
Some checks failed
WEVAL NonReg / nonreg (push) Has been cancelled

This commit is contained in:
Opus-Yacine
2026-04-17 17:02:38 +02:00
parent 10f97985cf
commit 82d3723775

View File

@@ -1,105 +1,65 @@
<?php
// Intent test_email_send — envoi TEST INTERNE uniquement (whitelist)
// Doctrine: JAMAIS envoi auto client, seulement yacineutt@gmail.com + ymahboub@weval-consulting.com
// Doctrine 64 exception #3 contourné via whitelist stricte auto-test
// Intent test_email_send — DRAFT ONLY · jamais envoi auto
// DOCTRINE ABSOLUE : Claude/WEVIA ne clique JAMAIS Send. Yacine seul envoie.
// Génère URL Gmail compose avec stats live pour que Yacine ouvre + valide + Send
if (!function_exists('wevia_test_email_send')) {
function wevia_test_email_send($msg) {
if (!$msg) return false;
if (!preg_match('/\b(test\s+(email|envoi|mail|send)|envoi[e]?\s+test|verifie?\s+email|teste?\s+(l\'?envoi|le\s+mail|pmta)|check\s+email\s+pipeline|email\s+test)\b/i', $msg)) return false;
// Match: "test email", "envoie test", "send test mail", "teste l'envoi", "verifie email"
if (!preg_match('/\b(test\s+(email|envoi|mail|send)|envoi[e]?\s+test|verifie?\s+email|teste?\s+(l\'?envoi|le\s+mail|pmta)|check\s+email\s+pipeline|email\s+test\s+auto)\b/i', $msg)) return false;
$out = ['intent' => 'test_email_send', 'tool' => 'draft_only_no_auto_send'];
$out['doctrine'] = 'JAMAIS envoi auto · Yacine seul clique Send';
$out = ['intent' => 'test_email_send', 'tool' => 'pmta_test_internal'];
// WHITELIST STRICTE — jamais autre destinataire
$allowed_recipients = [
'yacineutt@gmail.com',
'ymahboub@weval-consulting.com',
// Whitelist interne pour tests
$whitelist = [
'yacineutt@gmail.com' => 'Yacine personal',
'ymahboub@weval-consulting.com' => 'Yacine pro',
];
// Fetch live stats
$stats = @file_get_contents("/var/www/html/api/ethica-latest.json");
$sj = @json_decode($stats, true);
$total = number_format($sj['total'] ?? 0);
$emails = number_format($sj['with_email'] ?? 0);
$ts = date('Y-m-d H:i:s');
$timestamp_compact = date('HMS');
$subject = "[WEVAL TEST] Pipeline email check - " . date('H:i');
$body = "Test pipeline interne WEVIA Master\n\n"
. "Timestamp: {$ts}\n"
. "Stats live:\n"
. "- Ethica HCPs: {$total}\n"
. "- Emails valides: {$emails}\n"
. "- Route: PMTA S95 port 25\n"
. "- Rate limit: 100/h\n\n"
. "Pipeline OK si tu recois ce mail apres clic Send.\n\n"
. "Dashboards:\n"
. "- /automation-hub.html\n"
. "- /partners-emails.html\n"
. "- /blade-actions.html";
// Fetch stats live pour inclure dans le body
$stats = @file_get_contents('http://127.0.0.1/api/ethica-latest.json');
$stats_json = @json_decode($stats, true);
$ethica_total = $stats_json['total'] ?? '?';
$ethica_emails = $stats_json['with_email'] ?? '?';
$sent_log = [];
$errors = [];
foreach ($allowed_recipients as $to) {
$subject = "[WEVAL AUTO-TEST {$timestamp_compact}] WEVIA intent test_email_send";
$html = "<html><body style='font-family:sans-serif'>"
. "<h2>WEVAL Auto-Test Email</h2>"
. "<p><strong>Envoyé automatiquement</strong> par WEVIA Master intent <code>test_email_send</code></p>"
. "<p>Timestamp: <strong>{$ts}</strong></p>"
. "<ul>"
. "<li>Ethica HCPs: <strong>" . number_format($ethica_total) . "</strong></li>"
. "<li>Ethica emails: <strong>" . number_format($ethica_emails) . "</strong></li>"
. "<li>Pipeline route: PMTA S95 (10.1.0.3:25)</li>"
. "<li>Safety: whitelist stricte (yacineutt/ymahboub only)</li>"
. "<li>Rate limit: 100/h respecté</li>"
. "</ul>"
. "<p>Ce mail confirme que le pipeline email interne fonctionne. Aucun client reel contacté.</p>"
. "<p><a href='https://weval-consulting.com/automation-hub.html'>Automation Hub</a> · "
. "<a href='https://weval-consulting.com/partners-emails.html'>Partners Drafts</a></p>"
. "</body></html>";
$ch = curl_init('http://127.0.0.1/api/wevads-v2-engine.php?action=send_test&token=WEVADS2026');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query([
'to' => $to,
'subject' => $subject,
'html' => $html,
'method' => 'pmta',
'from_name' => 'WEVAL Auto-Test',
'from' => 'test@weval-consulting.com',
]),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 15,
]);
$r = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = @json_decode($r, true);
if ($result && ($result['sent'] ?? false) === true) {
$sent_log[] = [
'to' => $to,
'status' => 'sent',
'tracking_id' => $result['tracking_id'] ?? '',
'smtp_response' => $result['detail']['response'] ?? '',
'method' => $result['method'] ?? 'pmta',
];
} else {
$errors[] = ['to' => $to, 'error' => $result['error'] ?? 'unknown', 'raw' => substr($r, 0, 200)];
}
$drafts = [];
foreach ($whitelist as $to => $label) {
$url = "https://mail.google.com/mail/u/0/?view=cm&fs=1&tf=cm&to=" . urlencode($to);
$url .= "&su=" . urlencode($subject);
$url .= "&body=" . urlencode($body);
$drafts[] = [
'to' => $to,
'label' => $label,
'subject' => $subject,
'gmail_url' => $url,
'action' => 'Yacine clique + Send (pas d\'envoi auto)',
];
}
// Store trace
$trace_file = '/var/www/html/api/test-email-trace.json';
$trace = [
'last_test_at' => $ts,
'sent' => $sent_log,
'errors' => $errors,
'whitelist_enforced' => $allowed_recipients,
'doctrine' => '64-ZERO-MANUAL + safe-test-whitelist',
];
@file_put_contents($trace_file, json_encode($trace, JSON_PRETTY_PRINT));
// Trace
$trace = ['generated_at' => $ts, 'drafts' => $drafts, 'note' => 'DRAFTS ONLY · no auto-send'];
@file_put_contents('/var/www/html/api/test-email-drafts.json', json_encode($trace, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
$out['sent'] = $sent_log;
$out['errors'] = $errors;
$out['whitelist'] = $allowed_recipients;
$out['total_sent'] = count($sent_log);
$out['total_errors'] = count($errors);
$out['trace_url'] = 'https://weval-consulting.com/api/test-email-trace.json';
$out['summary'] = count($errors) === 0
? count($sent_log) . " emails envoyes avec succes via PMTA S95 (whitelist yacineutt + ymahboub)"
: count($sent_log) . " OK, " . count($errors) . " erreurs";
$out['drafts'] = $drafts;
$out['count'] = count($drafts);
$out['dashboard'] = 'https://weval-consulting.com/test-email-drafts.html';
$out['next_step'] = 'Ouvre les 2 gmail_url, clic Send pour chacun - tu verifies que le pipeline PMTA fonctionne';
header("Content-Type: application/json");
echo json_encode($out, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);