Skip to content

Commit

Permalink
fix: use files in mock-incoming and better original message view
Browse files Browse the repository at this point in the history
  • Loading branch information
BlankParticle committed Aug 24, 2024
1 parent f2575a6 commit 5b1d745
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
26 changes: 23 additions & 3 deletions apps/mail-bridge/scripts/mock-incoming.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { cancel, group, intro, outro, text } from '@clack/prompts';
import { mailProcessorQueue } from '../queue/mail-processor';
import { typeIdValidator } from '@u22n/utils/typeid';
import { existsSync, readFileSync } from 'node:fs';
import { testEmail } from './email-templates';
import { nanoid } from 'nanoid';
import { z } from 'zod';

const fixWrappingQuotes = (str: string) => {
if (
(str.startsWith("'") && str.endsWith("'")) ||
(str.startsWith('"') && str.endsWith('"'))
) {
return str.slice(1, -1);
}
return str;
};

intro('Mock Incoming Mail');

const params = await group(
Expand Down Expand Up @@ -64,9 +75,18 @@ const message = await group(
}
}
}),
rawMessage: () =>
messagePath: () =>
text({
message: 'Enter raw email in RFC822 format',
message: 'Path to raw email file (drop file into terminal)',
validate: (value) => {
if (value.length === 0) return;
const fileExists = existsSync(fixWrappingQuotes(value))
? true
: false;
if (!fileExists) {
return `File at path ${fixWrappingQuotes(value)} does not exist`;
}
},
placeholder: '(Skip to use test email)',
initialValue: ''
})
Expand All @@ -80,7 +100,7 @@ const message = await group(
);

const encodedEmail = Buffer.from(
message.rawMessage ||
readFileSync(fixWrappingQuotes(message.messagePath), 'utf8') ||
testEmail({
from: message.from,
to: message.rcpt_to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
DialogTitle
} from '@/src/components/shadcn-ui/dialog';
import { ScrollArea } from '@/src/components/shadcn-ui/scroll-area';
import { Separator } from '@/src/components/shadcn-ui/separator';
import { useOrgShortcode } from '@/src/hooks/use-params';
import { SpinnerGap } from '@phosphor-icons/react';
import { type TypeId } from '@u22n/utils/typeid';
Expand Down Expand Up @@ -59,6 +58,8 @@ export function OriginalMessageView({
{data && (
<ScrollArea className="h-[92svh] w-[92vw]">
<div className="flex flex-col gap-2">
<span className="font-bold">Original Email</span>
<OriginalMessageIframe html={data.rawEmailData.html} />
<div>
<span className="font-bold">Wipe Date: </span>
<span>{data.rawEmailData.wipeDate.toLocaleString()}</span>
Expand All @@ -80,9 +81,6 @@ export function OriginalMessageView({
</div>
))}
</div>
<Separator className="my-4 w-full" />
<span className="font-bold">Original Email</span>
<OriginalMessageIframe html={data.rawEmailData.html} />
</div>
</ScrollArea>
)}
Expand Down

0 comments on commit 5b1d745

Please sign in to comment.