feat(mail) : composable useSystemFolderLabel — mapping dossiers système IMAP vers i18n + icônes
This commit is contained in:
75
frontend/composables/useSystemFolderLabel.ts
Normal file
75
frontend/composables/useSystemFolderLabel.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Mapping des chemins de dossiers système IMAP vers les clés i18n.
|
||||
* Les clés sont normalisées en minuscules pour la comparaison.
|
||||
* Couvre les variantes OVH courantes (INBOX, INBOX.Sent, Sent, etc.)
|
||||
*/
|
||||
const SYSTEM_FOLDER_MAP: Record<string, string> = {
|
||||
'inbox': 'mail.systemFolder.inbox',
|
||||
'sent': 'mail.systemFolder.sent',
|
||||
'inbox.sent': 'mail.systemFolder.sent',
|
||||
'sent messages': 'mail.systemFolder.sent',
|
||||
'drafts': 'mail.systemFolder.drafts',
|
||||
'inbox.drafts': 'mail.systemFolder.drafts',
|
||||
'archive': 'mail.systemFolder.archive',
|
||||
'archives': 'mail.systemFolder.archive',
|
||||
'inbox.archive': 'mail.systemFolder.archive',
|
||||
'trash': 'mail.systemFolder.trash',
|
||||
'deleted': 'mail.systemFolder.trash',
|
||||
'deleted items': 'mail.systemFolder.trash',
|
||||
'inbox.trash': 'mail.systemFolder.trash',
|
||||
'junk': 'mail.systemFolder.junk',
|
||||
'junk e-mail': 'mail.systemFolder.junk',
|
||||
'spam': 'mail.systemFolder.junk',
|
||||
'inbox.junk': 'mail.systemFolder.junk',
|
||||
}
|
||||
|
||||
/**
|
||||
* Icônes Material Symbols associées aux dossiers système.
|
||||
* Pour les dossiers non reconnus : utiliser une icône générique.
|
||||
*/
|
||||
const SYSTEM_FOLDER_ICONS: Record<string, string> = {
|
||||
'mail.systemFolder.inbox': 'material-symbols:inbox-outline',
|
||||
'mail.systemFolder.sent': 'material-symbols:send-outline',
|
||||
'mail.systemFolder.drafts': 'material-symbols:draft-outline',
|
||||
'mail.systemFolder.archive': 'material-symbols:archive-outline',
|
||||
'mail.systemFolder.trash': 'material-symbols:delete-outline',
|
||||
'mail.systemFolder.junk': 'material-symbols:report-outline',
|
||||
}
|
||||
|
||||
const DEFAULT_FOLDER_ICON = 'material-symbols:folder-outline'
|
||||
|
||||
export function useSystemFolderLabel() {
|
||||
const { t } = useI18n()
|
||||
|
||||
/**
|
||||
* Retourne le label traduit d'un dossier système, ou son displayName si inconnu.
|
||||
* @param path - Chemin IMAP du dossier (ex: "INBOX", "INBOX.Sent")
|
||||
* @param displayName - Nom affiché par défaut si non reconnu
|
||||
*/
|
||||
function getFolderLabel(path: string, displayName: string): string {
|
||||
const key = SYSTEM_FOLDER_MAP[path.toLowerCase()]
|
||||
return key ? t(key) : displayName
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne le nom de l'icône Material Symbols pour un dossier.
|
||||
* @param path - Chemin IMAP du dossier
|
||||
*/
|
||||
function getFolderIcon(path: string): string {
|
||||
const key = SYSTEM_FOLDER_MAP[path.toLowerCase()]
|
||||
return key ? (SYSTEM_FOLDER_ICONS[key] ?? DEFAULT_FOLDER_ICON) : DEFAULT_FOLDER_ICON
|
||||
}
|
||||
|
||||
/**
|
||||
* Indique si un dossier est un dossier système reconnu.
|
||||
*/
|
||||
function isSystemFolder(path: string): boolean {
|
||||
return path.toLowerCase() in SYSTEM_FOLDER_MAP
|
||||
}
|
||||
|
||||
return {
|
||||
getFolderLabel,
|
||||
getFolderIcon,
|
||||
isSystemFolder,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user