fix: test connection always showed success; add per-account test endpoint

Agent-Logs-Url: https://github.com/christianlouis/InboxConverge/sessions/6268035d-325f-422a-886f-8b2919127261

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-28 18:57:25 +00:00
parent c09019d333
commit 441e8b54e9
5 changed files with 83 additions and 17 deletions
+28 -15
View File
@@ -115,24 +115,37 @@ export function AddMailAccountModal({ account, onClose }: AddMailAccountModalPro
};
const handleTestConnection = async () => {
if (!formData.username || !formData.password || !formData.host) {
alert('Please fill in username, password, and host');
return;
}
setTestStatus('testing');
setTestMessage('');
try {
await mailAccountsApi.test({
protocol: formData.protocol,
host: formData.host,
port: formData.port,
username: formData.username,
password: formData.password,
use_ssl: formData.use_ssl,
});
setTestStatus('success');
setTestMessage('Connection successful!');
let result: { success: boolean; message: string };
if (isEditMode && !formData.password && account?.id) {
// Edit mode with no new password entered — test using stored credentials
result = await mailAccountsApi.testExisting(account.id);
} else {
if (!formData.username || !formData.password || !formData.host) {
setTestStatus('error');
setTestMessage('Please fill in username, password, and host');
return;
}
result = await mailAccountsApi.test({
protocol: formData.protocol,
host: formData.host,
port: formData.port,
username: formData.username,
password: formData.password,
use_ssl: formData.use_ssl,
});
}
if (result.success) {
setTestStatus('success');
setTestMessage(result.message);
} else {
setTestStatus('error');
setTestMessage(result.message || 'Connection failed');
}
} catch (error) {
setTestStatus('error');
const errorMessage = error instanceof Error && 'response' in error
+7
View File
@@ -338,6 +338,13 @@ export const mailAccountsApi = {
return response.data;
},
async testExisting(accountId: number): Promise<{ success: boolean; message: string }> {
const response = await api.post<{ success: boolean; message: string }>(
`/mail-accounts/${accountId}/test`
);
return response.data;
},
async autoDetect(
emailAddress: string
): Promise<{ success: boolean; suggestions: AutoDetectSuggestion[] }> {