(options: EmailOptions)
| 39 | } |
| 40 | |
| 41 | function validateAndSanitize(options: EmailOptions): { |
| 42 | senderEmail: string |
| 43 | subject: string |
| 44 | replyTo?: string |
| 45 | } { |
| 46 | const senderEmail = options.from || getFromEmailAddress() |
| 47 | const recipients = Array.isArray(options.to) ? options.to : [options.to] |
| 48 | |
| 49 | if (recipients.some(hasEmailHeaderControlChars)) { |
| 50 | throw new Error('Invalid recipient email header') |
| 51 | } |
| 52 | if (hasEmailHeaderControlChars(senderEmail)) { |
| 53 | throw new Error('Invalid from email header') |
| 54 | } |
| 55 | if (options.replyTo && hasEmailHeaderControlChars(options.replyTo)) { |
| 56 | throw new Error('Invalid reply-to email header') |
| 57 | } |
| 58 | |
| 59 | const subject = sanitizeEmailSubject(options.subject) |
| 60 | if (subject.length === 0) { |
| 61 | throw new Error('Email subject cannot be empty') |
| 62 | } |
| 63 | |
| 64 | return { senderEmail, subject, replyTo: options.replyTo } |
| 65 | } |
| 66 | |
| 67 | export function processEmailData(options: EmailOptions): ProcessedEmailData { |
| 68 | const { senderEmail, subject, replyTo } = validateAndSanitize(options) |
no test coverage detected