From 52b3fa61ca5274e7393f5fcf68f6e0387e6f03fb Mon Sep 17 00:00:00 2001 From: Guilherme Rugai Freire Date: Wed, 10 Jul 2024 16:02:03 -0300 Subject: [PATCH] style web pages --- cmd/web_server/header.templ | 13 ++ cmd/web_server/inbox.templ | 33 +++-- cmd/web_server/index.templ | 9 +- cmd/web_server/mail.templ | 37 ++++-- cmd/web_server/main.go | 3 + cmd/web_server/styles.templ | 236 +++++++++++++++++++++++++++++++++++ pkg/mail_utils/mail_utils.go | 4 +- 7 files changed, 307 insertions(+), 28 deletions(-) create mode 100644 cmd/web_server/header.templ create mode 100644 cmd/web_server/styles.templ diff --git a/cmd/web_server/header.templ b/cmd/web_server/header.templ new file mode 100644 index 0000000..cca29cd --- /dev/null +++ b/cmd/web_server/header.templ @@ -0,0 +1,13 @@ +package main + +templ header(rcpt_addr string) { +
+

+ nthmail.xyz +

+
+

inbox:

+ { rcpt_addr } +
+
+} diff --git a/cmd/web_server/inbox.templ b/cmd/web_server/inbox.templ index df47ec8..fe3cac2 100644 --- a/cmd/web_server/inbox.templ +++ b/cmd/web_server/inbox.templ @@ -13,26 +13,35 @@ templ inbox_body(rcpt_addr string, ms []mail_utils.Mail_obj) { nthmail.xyz + @styles() - -

Emails for { rcpt_addr }:

- + } templ mail_comp(m mail_utils.Mail_obj, rcpt_addr string) { -
-

{ m.Subject }

-

From { m.From }

+
+

{ m.Subject }

+

{ m.From }

-

{ m.Date }

+

{ m.Date.Format("3:04 PM") }

} diff --git a/cmd/web_server/index.templ b/cmd/web_server/index.templ index 4c403a6..67165e3 100644 --- a/cmd/web_server/index.templ +++ b/cmd/web_server/index.templ @@ -8,15 +8,16 @@ templ index_page() { nthmail.xyz + @styles() - +

nthmail.xyz

A disposable, temporary and private mail address!

-
- -
+ } diff --git a/cmd/web_server/mail.templ b/cmd/web_server/mail.templ index da59566..5a6fedc 100644 --- a/cmd/web_server/mail.templ +++ b/cmd/web_server/mail.templ @@ -13,12 +13,24 @@ templ mail_body_comp(rcpt_addr string, m mail_utils.Mail_obj) { nthmail.xyz + @styles() - -
-

{m.Subject}

-

{m.From}

-
+ + @header(rcpt_addr) +
+
+ From: +

{ m.From }

+
+
+ Subject: +

{ m.Subject }

+
+
+ At: +

{ m.Date.Format("15:04:05 02/01/2006") }

+
+
@mime_type(m.Body[m.PreferedBodyIndex])
@@ -40,16 +52,21 @@ templ mime_type(b mail_utils.Mail_body) { } templ body_plain(s string) { -

{ s }

+
+
+			{ s }
+		
+
} templ body_html(s string) { -

+

@templ.Raw(s) -

+
} templ body_markdown(s string) { - @body_html(string(blackfriday.Run([]byte(s)))) - ) +
+ { string(blackfriday.Run([]byte(s))) } +
} diff --git a/cmd/web_server/main.go b/cmd/web_server/main.go index adb7e86..aa0f401 100644 --- a/cmd/web_server/main.go +++ b/cmd/web_server/main.go @@ -7,6 +7,7 @@ import ( "net/http" "os" "strconv" + "time" "github.com/GRFreire/nthmail/pkg/mail_utils" "github.com/GRFreire/nthmail/pkg/rig" @@ -133,6 +134,7 @@ func (sr ServerResouces) handleInbox(res http.ResponseWriter, req *http.Request) } mail_obj, err := mail_utils.Parse_mail(m.Data, true) + mail_obj.Date = time.Unix(m.Arrived_at, 0) mail_obj.Id = m.Id if err != nil { res.WriteHeader(500) @@ -198,6 +200,7 @@ func (sr ServerResouces) handleMail(res http.ResponseWriter, req *http.Request) } mail_obj, err := mail_utils.Parse_mail(m.Data, false) + mail_obj.Date = time.Unix(m.Arrived_at, 0) mail_obj.Id = m.Id if err != nil { res.WriteHeader(500) diff --git a/cmd/web_server/styles.templ b/cmd/web_server/styles.templ new file mode 100644 index 0000000..c93e368 --- /dev/null +++ b/cmd/web_server/styles.templ @@ -0,0 +1,236 @@ +package main + +templ styles() { + +} diff --git a/pkg/mail_utils/mail_utils.go b/pkg/mail_utils/mail_utils.go index 38de32c..f0687b3 100644 --- a/pkg/mail_utils/mail_utils.go +++ b/pkg/mail_utils/mail_utils.go @@ -11,6 +11,7 @@ import ( "net/mail" "slices" "strings" + "time" ) type MIMEType uint8 @@ -36,7 +37,7 @@ type Mail_body struct { type Mail_obj struct { Id int From string - Date string + Date time.Time To string Bcc string Subject string @@ -78,7 +79,6 @@ func Parse_mail(m_data []byte, header_only bool) (Mail_obj, error) { // HEADERS dec := new(mime.WordDecoder) m.From, _ = dec.DecodeHeader(mail_msg.Header.Get("From")) - m.Date, _ = dec.DecodeHeader(mail_msg.Header.Get("Date")) m.To, _ = dec.DecodeHeader(mail_msg.Header.Get("To")) m.Bcc, _ = dec.DecodeHeader(mail_msg.Header.Get("Bcc")) m.Subject, _ = dec.DecodeHeader(mail_msg.Header.Get("Subject"))