Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions apps/mail/app/(routes)/settings/privacy/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import { useTRPC } from '@/providers/query-provider';
import { useMutation } from '@tanstack/react-query';
// import { saveUserSettings } from '@/actions/settings';
import { useSettings } from '@/hooks/use-settings';
import { Button } from '@/components/ui/button';
import { Switch } from '@/components/ui/switch';
import { Button } from '@/components/ui/button';
import { useState, useEffect } from 'react';
import { m } from '@/paraglide/messages';
import { useForm } from 'react-hook-form';
import { m } from '@/paraglide/messages';
import { XIcon } from 'lucide-react';
import { toast } from 'sonner';
import * as z from 'zod';
Expand All @@ -32,17 +32,16 @@ export default function PrivacyPage() {

const form = useForm<z.infer<typeof userSettingsSchema>>({
resolver: zodResolver(userSettingsSchema),
defaultValues: {
externalImages: true,
trustedSenders: [],
},
});
Comment on lines 33 to 35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Form validation will fail until form is initialized. Add default values here to match schema.

Suggested change
const form = useForm<z.infer<typeof userSettingsSchema>>({
resolver: zodResolver(userSettingsSchema),
defaultValues: {
externalImages: true,
trustedSenders: [],
},
});
const form = useForm<z.infer<typeof userSettingsSchema>>({
resolver: zodResolver(userSettingsSchema),
defaultValues: {
externalImages: false,
trustedSenders: []
}
});


const externalImages = form.watch('externalImages');

const externalImages = data?.settings.externalImages;
useEffect(() => {
if (data) {
form.reset(data.settings);
form.reset({
...data.settings,
trustedSenders: data.settings.trustedSenders,
externalImages: !!data.settings.externalImages,
});
}
}, [form, data]);

Expand Down Expand Up @@ -87,10 +86,10 @@ export default function PrivacyPage() {
<FormItem className="bg-popover flex w-full flex-row items-center justify-between rounded-lg border p-4 md:w-auto">
<div className="space-y-0.5">
<FormLabel className="text-base">
{m['pages.settings.privacy.externalImages']()}
{m['pages.settings.privacy.externalImages']()}
</FormLabel>
<FormDescription>
{m['pages.settings.privacy.externalImagesDescription']()}
{m['pages.settings.privacy.externalImagesDescription']()}
</FormDescription>
</div>
<FormControl className="ml-4">
Expand All @@ -107,10 +106,10 @@ export default function PrivacyPage() {
<FormItem className="bg-popover flex w-full flex-col rounded-lg border p-4">
<div className="space-y-0.5">
<FormLabel className="text-base">
{m['pages.settings.privacy.trustedSenders']()}
{m['pages.settings.privacy.trustedSenders']()}
</FormLabel>
<FormDescription>
{m['pages.settings.privacy.trustedSendersDescription']()}
{m['pages.settings.privacy.trustedSendersDescription']()}
</FormDescription>
</div>
<ScrollArea className="flex max-h-32 flex-col pr-3">
Expand Down
5 changes: 3 additions & 2 deletions apps/mail/components/mail/mail-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import { cn } from '@/lib/utils';
import { toast } from 'sonner';

interface MailContentProps {
id: string;
html: string;
senderEmail: string;
}

export function MailContent({ html, senderEmail }: MailContentProps) {
export function MailContent({ id, html, senderEmail }: MailContentProps) {
const { data, refetch } = useSettings();
const queryClient = useQueryClient();
const isTrustedSender = useMemo(
Expand Down Expand Up @@ -67,7 +68,7 @@ export function MailContent({ html, senderEmail }: MailContentProps) {
);

const { data: processedData } = useQuery({
queryKey: ['email-content', html, isTrustedSender || temporaryImagesEnabled, resolvedTheme],
queryKey: ['email-content', id, isTrustedSender || temporaryImagesEnabled, resolvedTheme],
queryFn: async () => {
const result = await processEmailContent({
html,
Expand Down
6 changes: 5 additions & 1 deletion apps/mail/components/mail/mail-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1768,7 +1768,11 @@ const MailDisplay = ({ emailData, index, totalEmails, demo, threadAttachments }:
<div className="h-fit w-full p-0">
{/* mail main body */}
{emailData?.decodedBody ? (
<MailContent html={emailData?.decodedBody} senderEmail={emailData.sender.email} />
<MailContent
id={emailData.id}
html={emailData?.decodedBody}
senderEmail={emailData.sender.email}
/>
) : null}
{/* mail attachments */}
{emailData?.attachments && emailData?.attachments.length > 0 ? (
Expand Down
20 changes: 12 additions & 8 deletions apps/mail/hooks/use-mail-navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useOptimisticActions } from './use-optimistic-actions';
import { useMail } from '@/components/mail/use-mail';
import { useHotkeys } from 'react-hotkeys-hook';
import { atom, useAtom } from 'jotai';
import { useQueryState } from 'nuqs';

export const focusedIndexAtom = atom<number | null>(null);
export const mailNavigationCommandAtom = atom<null | 'next' | 'previous'>(null);
Expand All @@ -23,7 +24,8 @@ export function useMailNavigation({ items, containerRef, onNavigate }: UseMailNa
itemsRef.current = items;
const onNavigateRef = useRef(onNavigate);
onNavigateRef.current = onNavigate;
const { open: isCommandPaletteOpen } = useCommandPalette();
const [threadId] = useQueryState('threadId');
const [isCommandPaletteOpen] = useQueryState('isCommandPaletteOpen');
Comment on lines +27 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Both these query state hooks should specify their types. Add generic type parameters to useQueryState.

Suggested change
const [threadId] = useQueryState('threadId');
const [isCommandPaletteOpen] = useQueryState('isCommandPaletteOpen');
const [threadId] = useQueryState<string | null>('threadId');
const [isCommandPaletteOpen] = useQueryState<boolean>('isCommandPaletteOpen');


const hoveredMailRef = useRef<string | null>(null);
const keyboardActiveRef = useRef(false);
Expand Down Expand Up @@ -77,8 +79,7 @@ export function useMailNavigation({ items, containerRef, onNavigate }: UseMailNa
const message = itemsRef.current[index];
const threadId = message.id;

const currentThreadId = window.location.search.includes('threadId=');
if (currentThreadId) {
if (threadId) {
onNavigateRef.current(threadId);
optimisticMarkAsRead([threadId], true);
}
Expand All @@ -88,7 +89,7 @@ export function useMailNavigation({ items, containerRef, onNavigate }: UseMailNa
bulkSelected: [],
}));
},
[setMail],
[setMail, threadId],
);

const navigateNext = useCallback(() => {
Expand Down Expand Up @@ -196,11 +197,14 @@ export function useMailNavigation({ items, containerRef, onNavigate }: UseMailNa
}, [setFocusedIndex, onNavigateRef]);

useHotkeys('ArrowUp', handleArrowUp, { preventDefault: true, enabled: !isCommandPaletteOpen });
useHotkeys('ArrowDown', handleArrowDown, { preventDefault: true, enabled: !isCommandPaletteOpen });
useHotkeys('j', handleArrowDown,{enabled: !isCommandPaletteOpen });
useHotkeys('ArrowDown', handleArrowDown, {
preventDefault: true,
enabled: !isCommandPaletteOpen,
});
useHotkeys('j', handleArrowDown, { enabled: !isCommandPaletteOpen });
useHotkeys('k', handleArrowUp, { enabled: !isCommandPaletteOpen });
useHotkeys('Enter', handleEnter, { preventDefault: true,enabled: !isCommandPaletteOpen });
useHotkeys('Escape', handleEscape, { preventDefault: true,enabled: !isCommandPaletteOpen });
useHotkeys('Enter', handleEnter, { preventDefault: true, enabled: !isCommandPaletteOpen });
useHotkeys('Escape', handleEscape, { preventDefault: true, enabled: !isCommandPaletteOpen });

const handleMouseEnter = useCallback(
(threadId: string) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/lib/email-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function processEmailHtml({ html, shouldLoadImages, theme }: ProcessEmail
let hasBlockedImages = false;

const sanitizeConfig: sanitizeHtml.IOptions = {
allowedTags: false,
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img']),
allowedAttributes: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Setting allowedAttributes: false permits all attributes. Consider whitelisting specific attributes needed for email display (src, href, style, etc).

Suggested change
allowedAttributes: false,
allowedAttributes: {
'*': ['style', 'class'],
'a': ['href', 'target', 'rel'],
'img': ['src', 'alt', 'width', 'height']
},

allowedSchemes: shouldLoadImages
? ['http', 'https', 'mailto', 'tel', 'data', 'cid', 'blob']
Expand Down