|
| 1 | +<script setup lang="ts"> |
| 2 | +import PostalMime from 'postal-mime'; |
| 3 | +
|
| 4 | +const emailContent = ref(''); |
| 5 | +
|
| 6 | +const parsedEmail = computedAsync(async () => { |
| 7 | + const emailContentValue = emailContent.value; |
| 8 | + try { |
| 9 | + return await PostalMime.parse(emailContentValue); |
| 10 | + } |
| 11 | + catch (e: any) { |
| 12 | + return e.toString(); |
| 13 | + } |
| 14 | +}); |
| 15 | +
|
| 16 | +function downloadFile(data: Uint8Array, fileName: string, fileType: string) { |
| 17 | + const blob = new Blob([data], { type: fileType || 'application/octet-stream' }); |
| 18 | + const downloadUrl = URL.createObjectURL(blob); |
| 19 | + const a = document.createElement('a'); |
| 20 | + a.href = downloadUrl; |
| 21 | + a.download = fileName; |
| 22 | + document.body.appendChild(a); |
| 23 | + a.click(); |
| 24 | + URL.revokeObjectURL(downloadUrl); |
| 25 | +} |
| 26 | +</script> |
| 27 | + |
| 28 | +<template> |
| 29 | + <div style="max-width: 600px;"> |
| 30 | + <c-card title="Input" mb-2> |
| 31 | + <c-input-text |
| 32 | + v-model:value="emailContent" |
| 33 | + label="Email Content" |
| 34 | + multiline |
| 35 | + placeholder="Put your eml/email content here..." |
| 36 | + rows="15" |
| 37 | + mb-2 |
| 38 | + /> |
| 39 | + </c-card> |
| 40 | + |
| 41 | + <c-card v-if="parsedEmail && emailContent" title="Output"> |
| 42 | + <input-copyable v-if="parsedEmail.date" label="Date" :value="parsedEmail.date" /> |
| 43 | + <input-copyable v-if="parsedEmail.from?.name" label="From (name)" :value="parsedEmail.from?.name" /> |
| 44 | + <input-copyable v-if="parsedEmail.from" label="From (address)" :value="parsedEmail.from?.address || parsedEmail.from" /> |
| 45 | + <input-copyable v-if="parsedEmail.to" label="To" :value="JSON.stringify(parsedEmail.to)" /> |
| 46 | + <input-copyable v-if="parsedEmail.cc" label="Cc" :value="JSON.stringify(parsedEmail.cc)" /> |
| 47 | + <input-copyable v-if="parsedEmail.bcc?.name" label="Bcc" :value="JSON.stringify(parsedEmail.bcc)" /> |
| 48 | + <input-copyable v-if="parsedEmail.replyTo" label="Reply-To" :value="JSON.stringify(parsedEmail.replyTo)" /> |
| 49 | + <input-copyable v-if="parsedEmail.subject" label="Subject" :value="parsedEmail.subject" /> |
| 50 | + <c-card v-if="parsedEmail.text" title="Plain Content" mb-2> |
| 51 | + <details> |
| 52 | + <summary>See content</summary> |
| 53 | + <textarea-copyable :value="parsedEmail.text" /> |
| 54 | + </details> |
| 55 | + </c-card> |
| 56 | + <c-card v-if="parsedEmail.html" title="Html Content" mb-2> |
| 57 | + <details> |
| 58 | + <summary>See content</summary> |
| 59 | + <textarea-copyable :value="parsedEmail.html" /> |
| 60 | + </details> |
| 61 | + </c-card> |
| 62 | + <c-card v-if="parsedEmail?.attachments?.length" title="Attachments" mb-2> |
| 63 | + <n-table> |
| 64 | + <thead> |
| 65 | + <tr> |
| 66 | + <th>Attachment</th><th /> |
| 67 | + </tr> |
| 68 | + </thead> |
| 69 | + <tbody> |
| 70 | + <tr |
| 71 | + v-for="(h, index) in parsedEmail.attachments || []" |
| 72 | + :key="index" |
| 73 | + > |
| 74 | + <td> |
| 75 | + {{ `${h.filename || h.contentId || 'noname'} (${h.mimeType}) / ${h.disposition}` }} |
| 76 | + </td> |
| 77 | + <td> |
| 78 | + <c-button @click="downloadFile(h.content, h.filename || h.contentId || 'noname', h.mimeType)"> |
| 79 | + Download |
| 80 | + </c-button> |
| 81 | + </td> |
| 82 | + </tr> |
| 83 | + </tbody> |
| 84 | + </n-table> |
| 85 | + </c-card> |
| 86 | + |
| 87 | + <input-copyable v-if="parsedEmail.messageId" label="Message Id" :value="parsedEmail.messageId" /> |
| 88 | + <input-copyable v-if="parsedEmail.inReplyTo" label="In Reply To" :value="parsedEmail.inReplyTo" /> |
| 89 | + <input-copyable v-if="parsedEmail.references" label="References" :value="parsedEmail.references" /> |
| 90 | + <input-copyable v-if="parsedEmail.deliveredTo" label="Delivered To" :value="parsedEmail.deliveredTo" /> |
| 91 | + <input-copyable v-if="parsedEmail.returnPath" label="Return Path" :value="parsedEmail.returnPath" /> |
| 92 | + <input-copyable v-if="parsedEmail.sender?.name" label="Sender (name)" :value="parsedEmail.sender?.name" /> |
| 93 | + <input-copyable v-if="parsedEmail.sender" label="Sender (address)" :value="parsedEmail.sender?.address || parsedEmail.sender" /> |
| 94 | + |
| 95 | + <c-card title="All Headers" mt-2> |
| 96 | + <input-copyable |
| 97 | + v-for="(h, index) in parsedEmail.headers || []" |
| 98 | + :key="index" |
| 99 | + :label="h.key" |
| 100 | + :value="h.value" |
| 101 | + /> |
| 102 | + </c-card> |
| 103 | + </c-card> |
| 104 | + </div> |
| 105 | +</template> |
0 commit comments