mail page rest dang

This commit is contained in:
alma 2025-04-21 16:07:55 +02:00
parent 273442d42c
commit 287941f42f
6 changed files with 13 additions and 1907 deletions

View File

@ -44,7 +44,7 @@ export async function GET(req: NextRequest) {
date: new Date().toISOString(),
isUnread: true
}],
mailUrl: `${nextcloudUrl}/apps/mail/box/unified`
mailUrl: `${nextcloudUrl}/apps/courrier/box/unified`
});
} catch (error) {
console.error('Error:', error);

View File

@ -22,7 +22,7 @@ export default function MailLoginPage() {
setLoading(true);
try {
const response = await fetch('/api/mail/login', {
const response = await fetch('/api/courrier/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',

View File

@ -429,13 +429,13 @@ export default function CourrierPage() {
const checkCredentials = async () => {
try {
console.log('Checking for stored credentials...');
const response = await fetch('/api/mail');
const response = await fetch('/api/courrier');
if (!response.ok) {
const errorData = await response.json();
console.log('API response error:', errorData);
if (errorData.error === 'No stored credentials found') {
console.log('No credentials found, redirecting to login...');
router.push('/mail/login');
router.push('/courrier/login');
return;
}
throw new Error(errorData.error || 'Failed to check credentials');
@ -463,7 +463,7 @@ export default function CourrierPage() {
}
setError(null);
const response = await fetch(`/api/mail?folder=${currentView}&page=${page}&limit=${emailsPerPage}`);
const response = await fetch(`/api/courrier?folder=${currentView}&page=${page}&limit=${emailsPerPage}`);
if (!response.ok) {
throw new Error('Failed to load emails');
}
@ -557,7 +557,7 @@ export default function CourrierPage() {
setSelectedEmail(email);
// Fetch the full email content
const response = await fetch(`/api/mail/${emailId}`);
const response = await fetch(`/api/courrier/${emailId}`);
if (!response.ok) {
throw new Error('Failed to fetch full email content');
}
@ -575,7 +575,7 @@ export default function CourrierPage() {
// Try to mark as read in the background
try {
const markReadResponse = await fetch(`/api/mail/mark-read`, {
const markReadResponse = await fetch(`/api/courrier/mark-read`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@ -630,7 +630,7 @@ export default function CourrierPage() {
}
try {
const response = await fetch('/api/mail/bulk-actions', {
const response = await fetch('/api/courrier/bulk-actions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@ -673,7 +673,7 @@ export default function CourrierPage() {
// Add handleDeleteConfirm function
const handleDeleteConfirm = async () => {
try {
const response = await fetch('/api/mail/bulk-actions', {
const response = await fetch('/api/courrier/bulk-actions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@ -1221,7 +1221,7 @@ export default function CourrierPage() {
}
try {
const response = await fetch('/api/mail/send', {
const response = await fetch('/api/courrier/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@ -1271,7 +1271,7 @@ export default function CourrierPage() {
if (!email) return;
try {
const response = await fetch('/api/mail/toggle-star', {
const response = await fetch('/api/courrier/toggle-star', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@ -1369,7 +1369,7 @@ export default function CourrierPage() {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout
const response = await fetch(`/api/mail?folder=${encodeURIComponent(newMailbox)}&page=1&limit=${emailsPerPage}`, {
const response = await fetch(`/api/courrier?folder=${encodeURIComponent(newMailbox)}&page=1&limit=${emailsPerPage}`, {
signal: controller.signal
});

View File

@ -1,116 +0,0 @@
'use client';
import { useState } from 'react';
import { useRouter } from 'next/navigation';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
export default function MailLoginPage() {
const router = useRouter();
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [host, setHost] = useState('mail.infomaniak.com');
const [port, setPort] = useState('993');
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setError('');
setLoading(true);
try {
const response = await fetch('/api/mail/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email,
password,
host,
port,
}),
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || 'Failed to connect to email server');
}
// Redirect to mail page
router.push('/mail');
} catch (err) {
setError(err instanceof Error ? err.message : 'An error occurred');
} finally {
setLoading(false);
}
};
return (
<div className="min-h-screen flex items-center justify-center bg-gray-50">
<Card className="w-full max-w-md">
<CardHeader>
<CardTitle>Email Configuration</CardTitle>
</CardHeader>
<CardContent>
<form onSubmit={handleSubmit} className="space-y-4">
<div>
<Label htmlFor="email">Email</Label>
<Input
id="email"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
/>
</div>
<div>
<Label htmlFor="password">Password</Label>
<Input
id="password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
/>
</div>
<div>
<Label htmlFor="host">IMAP Host</Label>
<Input
id="host"
type="text"
value={host}
onChange={(e) => setHost(e.target.value)}
required
/>
</div>
<div>
<Label htmlFor="port">IMAP Port</Label>
<Input
id="port"
type="text"
value={port}
onChange={(e) => setPort(e.target.value)}
required
/>
</div>
{error && (
<div className="text-red-500 text-sm">{error}</div>
)}
<Button
type="submit"
className="w-full"
disabled={loading}
>
{loading ? 'Connecting...' : 'Connect'}
</Button>
</form>
</CardContent>
</Card>
</div>
);
}

File diff suppressed because it is too large Load Diff

View File

@ -72,7 +72,7 @@ export function Email() {
}));
setEmails(validatedEmails);
setMailUrl(data.mailUrl || 'https://espace.slm-lab.net/apps/mail/');
setMailUrl(data.mailUrl || 'https://espace.slm-lab.net/apps/courrier/');
setError(null);
} catch (err) {
setError(err instanceof Error ? err.message : 'Error fetching emails');