Installation
Section titled “Installation”pnpm dlx shadcn@latest add pxl-ui/registry/schemas/imapflow
Install the following dependencies:
pnpm add zod
Copy and paste the following code into your project.
1import z from "zod";2
3const SpecialUseFlagSchema = z.union([4 z.literal("\\All"),5 z.literal("\\Trash"),6 z.literal("\\Junk"),7 z.literal("\\Sent"),8 z.literal("\\Flagged"),9 z.literal("\\Drafts"),10 z.literal("\\Inbox"),11]);12
13const MailBoxSchema = z.object({14 path: z.string().describe("Mailbox path (unicode string)"),15 name: z.string().describe("Mailbox name (last part of path after delimiter)"),16 parent: z17 .array(z.string())18 .describe("An array of parent folder names. All names are in unicode"),19 parentPath: z20 .string()21 .describe("Same as parent, but as a complete string path (unicode string)"),22 flags: z.array(z.string()).describe("A set of flags for this mailbox"),23 specialUse: SpecialUseFlagSchema.optional().describe(24 "One of special-use flags (if applicable)",25 ),26}).describe("A Mailbox object from imapflow");27
28const MessageAddressSchema = z.object({29 name: z.string().optional().describe("Name of the address object (unicode)"),30 address: z.email().optional().describe("Email address"),31});32
33const MessageEnvelopeSchema = z.object({34 date: z.string().optional().describe("Header date"),35 subject: z.string().optional().describe("Message subject (unicode)"),36 messageId: z.string().optional().describe("Message ID of the message"),37 inReplyTo: z38 .string()39 .optional()40 .describe("Message ID from In-Reply-To header"),41 from: z42 .array(MessageAddressSchema)43 .optional()44 .describe("Array of addresses from the From: header"),45 sender: z46 .array(MessageAddressSchema)47 .optional()48 .describe("Array of addresses from the Sender: header"),49 replyTo: z50 .array(MessageAddressSchema)51 .optional()52 .describe("Array of addresses from the Reply-To: header"),53 to: z54 .array(MessageAddressSchema)55 .optional()56 .describe("Array of addresses from the To: header"),57 cc: z58 .array(MessageAddressSchema)59 .optional()60 .describe("Array of addresses from the Cc: header"),61 bcc: z62 .array(MessageAddressSchema)63 .optional()64 .describe("Array of addresses from the Bcc: header"),65});66
67const MessageSchema = z.object({68 uid: z69 .number()70 .describe("Message UID number. Always included in the response"),71 flags: z.array(z.string()).optional().describe("A set of message flags"),72 flagColor: z73 .string()74 .optional()75 .describe(76 "Flag color like 'red', or 'yellow'. This value is derived from the flags Set",77 ),78 envelope: MessageEnvelopeSchema.optional().describe("Message envelope"),79 source: z80 .string()81 .optional()82 .describe("Message source for the requested byte range"),83}).describe("A Message object from imapflow");84
85const ParsedMessageSchema = z.object({86 html: z.union([87 z.string(),88 z.literal(false)89 ]).describe("The HTML body of the message. Sets to `false` when there is no HTML body. If the message included embedded images as cid: urls then these are all replaced with base64 formatted data: URIs."),90 text: z.string().optional().describe("The plaintext body of the message."),91 textAsHtml: z.string().optional().describe("The plaintext body of the message formatted as HTML."),92}).describe("A Message object from mailparser")93
94const ImapFlowSchemas = {95 MailBox: MailBoxSchema,96 Message: MessageSchema,97 MessageAddress: MessageAddressSchema,98 MessageEnvelope: MessageEnvelopeSchema,99};100
101type MailBox = z.infer<typeof MailBoxSchema>;102type Message = z.infer<typeof MessageSchema>;103type MessageAddress = z.infer<typeof MessageAddressSchema>;104type MessageEnvelope = z.infer<typeof MessageEnvelopeSchema>;105type ParsedMessage = z.infer<typeof ParsedMessageSchema>;106
107declare namespace ImapFlow {108 export type { MailBox, Message, MessageAddress, MessageEnvelope, ParsedMessage };109}110
111export type { ImapFlow, MailBox, Message, MessageAddress, MessageEnvelope, ParsedMessage };112export {113 ImapFlowSchemas,114 MailBoxSchema,115 MessageAddressSchema,116 MessageEnvelopeSchema,117 MessageSchema,118 ParsedMessageSchema,119};120export default ImapFlowSchemas;Update the import paths to match your project setup.
import type { ImapFlow } from "@/lib/schemas/pxl/imapflow";const message: ImapFlow.Message = { ... }API Reference
Section titled “API Reference”MailBox
Section titled “MailBox”An ImapFlow mailbox
Message
Section titled “Message”An ImapFlow message