mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-09-05 23:47:50 +08:00
fix: rpc headers covert & typo (#559)
Co-authored-by: liuzhicong <liuzhicong@dhgate.com>
This commit is contained in:
+12
-3
@@ -292,13 +292,14 @@ export const commonParseMail = async (parsedEmailContext: ParsedEmailContext): P
|
|||||||
try {
|
try {
|
||||||
const { default: PostalMime } = await import('postal-mime');
|
const { default: PostalMime } = await import('postal-mime');
|
||||||
const parsedEmail = await PostalMime.parse(raw_mail);
|
const parsedEmail = await PostalMime.parse(raw_mail);
|
||||||
return {
|
parsedEmailContext.parsedEmail = {
|
||||||
sender: parsedEmail.from ? `${parsedEmail.from.name} <${parsedEmail.from.address}>` : "",
|
sender: parsedEmail.from ? `${parsedEmail.from.name} <${parsedEmail.from.address}>` : "",
|
||||||
subject: parsedEmail.subject || "",
|
subject: parsedEmail.subject || "",
|
||||||
text: parsedEmail.text || "",
|
text: parsedEmail.text || "",
|
||||||
html: parsedEmail.html || "",
|
html: parsedEmail.html || "",
|
||||||
headers: parsedEmail.headers || [],
|
headers: parsedEmail.headers || [],
|
||||||
};
|
};
|
||||||
|
return parsedEmailContext.parsedEmail;
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
console.error("Failed use PostalMime to parse email", e);
|
console.error("Failed use PostalMime to parse email", e);
|
||||||
@@ -451,9 +452,17 @@ export async function triggerAnotherWorker(
|
|||||||
console.log(`worker.binding = ${bindingName} not match keywords, parsedText = ${parsedText}`);
|
console.log(`worker.binding = ${bindingName} not match keywords, parsedText = ${parsedText}`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const requestBody = JSON.stringify(rpcEmailMessage);
|
const bodyObj = { ...rpcEmailMessage } as any;
|
||||||
|
if (bodyObj.headers && typeof bodyObj.headers.forEach === "function") {
|
||||||
|
const headerObj: any = {}
|
||||||
|
bodyObj.headers.forEach((value: string, key: string) => {
|
||||||
|
headerObj[key] = value;
|
||||||
|
});
|
||||||
|
bodyObj.headers = headerObj
|
||||||
|
}
|
||||||
|
const requestBody = JSON.stringify(bodyObj);
|
||||||
|
console.log(`exec worker , binding = ${bindingName} , requestBody = ${requestBody}`);
|
||||||
await method(requestBody);
|
await method(requestBody);
|
||||||
} catch (e1) {
|
} catch (e1) {
|
||||||
console.error(`execute method = ${methodName} error`, e1);
|
console.error(`execute method = ${methodName} error`, e1);
|
||||||
|
|||||||
@@ -80,16 +80,13 @@ async function email(message: ForwardableEmailMessage, env: Bindings, ctx: Execu
|
|||||||
|
|
||||||
// trigger another worker
|
// trigger another worker
|
||||||
try {
|
try {
|
||||||
const headersMap = new Map<string, string>();
|
const parsedEmail = (await commonParseMail(parsedEmailContext));
|
||||||
if (message.headers) {
|
const parsedText = parsedEmail?.text ?? ""
|
||||||
message.headers.forEach((value, key) => { headersMap.set(key, value); });
|
|
||||||
}
|
|
||||||
const parsedText = (await commonParseMail(parsedEmailContext))?.text ?? ""
|
|
||||||
const rpcEmail: RPCEmailMessage = {
|
const rpcEmail: RPCEmailMessage = {
|
||||||
from: message.from,
|
from: message.from,
|
||||||
to: message.to,
|
to: message.to,
|
||||||
rawEmail: rawEmail,
|
rawEmail: rawEmail,
|
||||||
headers: headersMap
|
headers: message.headers
|
||||||
}
|
}
|
||||||
await triggerAnotherWorker({ env: env } as Context<HonoCustomType>, rpcEmail, parsedText);
|
await triggerAnotherWorker({ env: env } as Context<HonoCustomType>, rpcEmail, parsedText);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -338,8 +338,8 @@ export async function sendMailToTelegram(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const settings = await c.env.KV.get<TelegramSettings>(CONSTANTS.TG_KV_SETTINGS_KEY, "json");
|
const settings = await c.env.KV.get<TelegramSettings>(CONSTANTS.TG_KV_SETTINGS_KEY, "json");
|
||||||
const golbalPush = settings?.enableGlobalMailPush && settings?.globalMailPushList;
|
const globalPush = settings?.enableGlobalMailPush && settings?.globalMailPushList;
|
||||||
if (!userId && !golbalPush) {
|
if (!userId && !globalPush) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const mailId = await c.env.DB.prepare(
|
const mailId = await c.env.DB.prepare(
|
||||||
@@ -353,7 +353,7 @@ export async function sendMailToTelegram(
|
|||||||
url.searchParams.set("mail_id", mailId);
|
url.searchParams.set("mail_id", mailId);
|
||||||
miniAppButtons.push(Markup.button.webApp("查看邮件", url.toString()));
|
miniAppButtons.push(Markup.button.webApp("查看邮件", url.toString()));
|
||||||
}
|
}
|
||||||
if (golbalPush) {
|
if (globalPush) {
|
||||||
for (const pushId of settings.globalMailPushList) {
|
for (const pushId of settings.globalMailPushList) {
|
||||||
await bot.telegram.sendMessage(pushId, mail, {
|
await bot.telegram.sendMessage(pushId, mail, {
|
||||||
...Markup.inlineKeyboard([
|
...Markup.inlineKeyboard([
|
||||||
|
|||||||
Vendored
+1
-1
@@ -108,7 +108,7 @@ type RPCEmailMessage = {
|
|||||||
from: string | undefined | null,
|
from: string | undefined | null,
|
||||||
to: string | undefined | null,
|
to: string | undefined | null,
|
||||||
rawEmail: string | undefined | null,
|
rawEmail: string | undefined | null,
|
||||||
headers: Map<string, string>,
|
headers: object | undefined | null,
|
||||||
}
|
}
|
||||||
|
|
||||||
type ParsedEmailContext = {
|
type ParsedEmailContext = {
|
||||||
|
|||||||
Reference in New Issue
Block a user