From 00f3cb9fb48cfb9768b695bd0d9eb8367ad84782 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Thu, 2 Jan 2025 19:30:51 +0000 Subject: Deliver to inbox --- incoming.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'incoming.go') diff --git a/incoming.go b/incoming.go index f915ac0..169bde5 100644 --- a/incoming.go +++ b/incoming.go @@ -1,12 +1,28 @@ package main -import "go.lindenii.runxiyu.org/lindenii-common/clog" +import ( + "go.lindenii.runxiyu.org/lindenii-common/clog" + "os" + "path" + "time" +) -func deliver_incoming(envelope_from string, envelope_recipients []string, data []byte) { +func deliver_incoming(envelope_from string, envelope_recipients []string, data []byte) error { clog.Debug( "incoming_mail", "envelope_from", envelope_from, "envelope_recipients", envelope_recipients, "data", string(data), ) + t := time.Now() + fd, err := os.OpenFile(path.Join(config.Inbox_path, envelope_from+" "+t.Format(time.RFC3339Nano)+".eml"), os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0660) // TODO: vulnerability + if err != nil { + // TODO: handle fs.ErrExist + return err_deliver_write + } + _, err = fd.Write(data) + if err != nil { + return err_deliver_write + } + return nil } -- cgit v1.2.3