Add RFC 2047 MIME decoding for mail subjects
This commit is contained in:
@@ -7,6 +7,29 @@ import { sendTelegramNotification } from '@/lib/notifications';
|
||||
const WEBHOOK_SECRET = 'besiktasK1903*';
|
||||
const IMAP_PASSWORD = process.env.MAILCOW_MASTER_PASSWORD || ''; // Dovecot Master Password tavsiye edilir
|
||||
|
||||
// RFC 2047 Decode Fonksiyonu
|
||||
function decodeMimeText(text: string) {
|
||||
if (!text) return text;
|
||||
|
||||
// Eğer metin =? ile başlıyorsa decode etmeye çalış
|
||||
return text.replace(/=\?([^?]+)\?([QB])\?([^?]+)\?=/gi, (match, charset, encoding, data) => {
|
||||
try {
|
||||
if (encoding.toUpperCase() === 'Q') {
|
||||
// Quoted-Printable decode
|
||||
return data
|
||||
.replace(/_/g, ' ')
|
||||
.replace(/=([0-9A-F]{2})/gi, (_: any, hex: string) => String.fromCharCode(parseInt(hex, 16)));
|
||||
} else if (encoding.toUpperCase() === 'B') {
|
||||
// Base64 decode
|
||||
return Buffer.from(data, 'base64').toString(charset.toLowerCase() === 'utf-8' ? 'utf8' : 'binary');
|
||||
}
|
||||
} catch (e) {
|
||||
return match;
|
||||
}
|
||||
return match;
|
||||
});
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const secret = request.headers.get('x-ayristech-secret');
|
||||
|
||||
@@ -17,7 +40,8 @@ export async function POST(request: Request) {
|
||||
const body = await request.json();
|
||||
const { to, event, subject: incomingSubject, snippet: incomingSnippet, from: incomingFrom } = body;
|
||||
|
||||
console.log(`📩 Webhook Sinyali Alındı! Alıcı: ${to}`);
|
||||
const subject = decodeMimeText(incomingSubject || "");
|
||||
console.log(`📩 Webhook Sinyali Alındı! Alıcı: ${to} | Konu: ${subject}`);
|
||||
|
||||
try {
|
||||
// 1. Mailbox Mapping kontrolü
|
||||
@@ -35,9 +59,9 @@ export async function POST(request: Request) {
|
||||
let mailData = null;
|
||||
|
||||
if (incomingSubject || incomingSnippet) {
|
||||
console.log(`[Signal] İçerik worker'dan hazır geldi: ${incomingSubject}`);
|
||||
console.log(`[Signal] İçerik worker'dan hazır geldi: ${subject}`);
|
||||
mailData = {
|
||||
subject: incomingSubject || "(Konu Yok)",
|
||||
subject: subject || "(Konu Yok)",
|
||||
text: incomingSnippet || "",
|
||||
from: incomingFrom || "Bilinmiyor"
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user