Skip to content

Commit 52ee817

Browse files
committed
fix mail view
1 parent 4e81fdb commit 52ee817

File tree

4 files changed

+66
-58
lines changed

4 files changed

+66
-58
lines changed

examples/mokapi/http_handler.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ export default async function() {
7474
if (mail == null) {
7575
response.statusCode = 404
7676
} else {
77-
response.data = mail
77+
response.data = {
78+
service: mailServices[0].name,
79+
data: mail
80+
}
7881
}
7982
return true
8083
case 'smtpMailAttachment':

examples/mokapi/mail.js

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,53 @@ import {metrics} from "./metrics.js";
22

33
export let mails = [
44
{
5-
service: 'Mail Testserver',
6-
data: {
7-
from: [{name: 'Alice', address: 'alice@mokapi.io'}],
8-
to: [{name: 'Bob', address: 'bob@mokapi.io'}, {address: 'carol@mokapi.io'}],
9-
date: '2023-02-23T08:49:25+01:00',
10-
contentType: 'text/html',
11-
encoding: 'quoted-printable',
12-
messageId: '20230223-084925.763-4196@mokapi.io',
13-
inReplyTo: '20230222-084925.763-4196@mokapi.io',
14-
subject: 'A test mail',
15-
body: `<style>
16-
.container {color: black; }
17-
@media (prefers-color-scheme: dark ) {
18-
.container {color: white; }
19-
}
20-
21-
</style>
22-
<div class="container">
23-
<h1>Hello</h1>
24-
Mail message from Alice<img src="cid:icon.png" />
25-
</div>`,
26-
attachments: [
27-
{
28-
name: 'foo.txt',
29-
contentType: 'text/plain',
30-
disposition: 'attachment',
31-
size: 34056,
32-
data: 'foobar'
33-
},
34-
{
35-
name: 'icon.png',
36-
contentType: 'image/png',
37-
disposition: 'inline',
38-
contentId: 'icon.png',
39-
size: 372,
40-
data: open('icon.png', {as: 'binary'})
41-
}
42-
],
43-
duration: 30016,
44-
actions: [
45-
{
46-
duration: 20,
47-
tags: {
48-
name: "dashboard",
49-
file: "/Users/maesi/GolandProjects/mokapi/examples/mokapi/http_handler.js",
50-
event: "http"
5+
from: [{name: 'Alice', address: 'alice@mokapi.io'}],
6+
to: [{name: 'Bob', address: 'bob@mokapi.io'}, {address: 'carol@mokapi.io'}],
7+
date: '2023-02-23T08:49:25+01:00',
8+
contentType: 'text/html',
9+
encoding: 'quoted-printable',
10+
messageId: '20230223-084925.763-4196@mokapi.io',
11+
inReplyTo: '20230222-084925.763-4196@mokapi.io',
12+
subject: 'A test mail',
13+
body: `<style>
14+
.container {color: black; }
15+
@media (prefers-color-scheme: dark ) {
16+
.container {color: white; }
5117
}
18+
19+
</style>
20+
<div class="container">
21+
<h1>Hello</h1>
22+
Mail message from Alice<img src="cid:icon.png" />
23+
</div>`,
24+
attachments: [
25+
{
26+
name: 'foo.txt',
27+
contentType: 'text/plain',
28+
disposition: 'attachment',
29+
size: 34056,
30+
data: 'foobar'
31+
},
32+
{
33+
name: 'icon.png',
34+
contentType: 'image/png',
35+
disposition: 'inline',
36+
contentId: 'icon.png',
37+
size: 372,
38+
data: open('icon.png', {as: 'binary'})
39+
}
40+
],
41+
duration: 30016,
42+
actions: [
43+
{
44+
duration: 20,
45+
tags: {
46+
name: "dashboard",
47+
file: "/Users/maesi/GolandProjects/mokapi/examples/mokapi/http_handler.js",
48+
event: "http"
5249
}
53-
]
54-
}
50+
}
51+
]
5552
},
5653
]
5754

@@ -124,7 +121,7 @@ export let mailEvents = [
124121

125122
export function getMail(messageId) {
126123
for (let m of mails) {
127-
if (m.data.messageId === messageId) {
124+
if (m.messageId === messageId) {
128125
return m
129126
}
130127
}

webui/src/components/dashboard/mail/Mailbox.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ onUnmounted(() => res.close());
3131
const res = useFetch(
3232
`/api/services/mail/${props.service.name}/mailboxes/${props.mailboxName}/messages`,
3333
);
34-
const messages = ref<Message[]>()
34+
const messages = ref<MessageInfo[]>()
3535
3636
watchEffect(() => {
3737
if (!res.data) {
@@ -41,10 +41,10 @@ watchEffect(() => {
4141
messages.value = res.data;
4242
});
4343
44-
function goToMail(msg: Message) {
44+
function goToMail(msg: MessageInfo) {
4545
router.push({
4646
name: "smtpMail",
47-
params: { id: msg.data.messageId },
47+
params: { id: msg.messageId },
4848
});
4949
}
5050
</script>
@@ -136,13 +136,13 @@ function goToMail(msg: Message) {
136136
<tbody>
137137
<tr
138138
v-for="message in messages"
139-
:key="message.data.messageId"
139+
:key="message.messageId"
140140
@click="goToMail(message)"
141141
>
142-
<td>{{ message.data.subject }}</td>
142+
<td>{{ message.subject }}</td>
143143
<td>
144144
<ul class="list-unstyled">
145-
<li v-for="addr of message.data.from">
145+
<li v-for="addr of message.from">
146146
<strong v-if="addr.name">{{ addr.name }}</strong>
147147
<span v-if="addr.name"> &lt;{{ addr.address }}&gt;</span>
148148
<span v-else>{{ addr.address }}</span>
@@ -151,14 +151,14 @@ function goToMail(msg: Message) {
151151
</td>
152152
<td>
153153
<ul class="list-unstyled">
154-
<li v-for="addr of message.data.to">
154+
<li v-for="addr of message.to">
155155
<strong v-if="addr.name">{{ addr.name }}</strong>
156156
<span v-if="addr.name"> &lt;{{ addr.address }}&gt;</span>
157157
<span v-else>{{ addr.address }}</span>
158158
</li>
159159
</ul>
160160
</td>
161-
<td class="text-center">{{ format(message.data.date) }}</td>
161+
<td class="text-center">{{ format(message.date) }}</td>
162162
</tr>
163163
</tbody>
164164
</table>

webui/src/types/mail.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ declare interface SmtpEventData {
5353
actions: Action[]
5454
}
5555

56+
declare interface MessageInfo {
57+
messageId: string
58+
subject: string
59+
from: MailAddress[]
60+
to: MailAddress[]
61+
date: string
62+
}
63+
5664
declare interface Message {
5765
service: string
5866
data: MessageData

0 commit comments

Comments
 (0)