commit a931dc8d28d1aa6482739e98bcabcba4053c2498 Author: davidontop Date: Tue May 21 06:50:03 2024 +0200 Innit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..66b09d6 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,25 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +indent_style = tab +indent_size = 4 +charset = utf-8 +trim_trailing_whitespace = true + +[*.{yml,yaml}] +indent_style = space +indent_size = 2 + +[*.fs] +indent_style = space +indent_size = 4 +fsharp_newline_between_type_definition_and_members=true +fsharp_multiline_bracket_style=aligned +fsharp_keep_max_number_of_blank_lines=1 +fsharp_multiline_bracket_style = stroustrup + +[*.fsi] +fsharp_newline_between_type_definition_and_members=true +fsharp_keep_max_number_of_blank_lines=1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..51d6621 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +bin +obj diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..0612b80 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,11 @@ +condense_wildcard_suffixes = true +edition = "2021" +fn_single_line = true +format_code_in_doc_comments = true +format_macro_matchers = true +hard_tabs = true +match_block_trailing_comma = true +imports_granularity = "Crate" +newline_style = "Unix" +group_imports = "StdExternalCrate" +tab_spaces = 4 diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..21d1505 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,39 @@ +[package] +name = "iomail-server" +version = "0.1.0" +edition = "2021" +description = "iomail" +authors = ["davidontop "] +readme = "README.md" +documentation = "https://docs.rs/iomail" +license = "GLWTPL" +repository = "git@github.com:davidontop/iomail.git" + +[dependencies] +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +tracing = "0.1" +tracing-subscriber = "0.3" +tokio = { version = "1.0", features = ["full"] } + +[profile.release] +codegen-units = 1 +lto = true +opt-level = 'z' + +[[workspace.metadata.leptos]] +name = "iomail" +bin-package = "server" +lib-package = "client" +site-root = "target/site" +site-pkg-dir = "pkg" +style-file = "client/globaltw.css" +assets-dir = "public" +site-addr = "127.0.0.1:8690" +reload-port = 3001 +watch = false +env = "DEV" +bin-features = [] +bin-default-features = false +lib-features = [] +lib-default-features = false diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3c3602f --- /dev/null +++ b/LICENSE @@ -0,0 +1,26 @@ + GLWTS(Good Luck With That Shit) Public License + Copyright (c) Every-fucking-one + +Everyone is permitted to copy, distribute, modify, merge, sell, publish, +sublicense or whatever the fuck they want with this software but at their +OWN RISK. + + Preamble + +The author has absolutely no fucking clue what the code in this project +does. It might just fucking work or not, there is no third option. + + + GOOD LUCK WITH THAT SHIT PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION, AND MODIFICATION + + 0. You just DO WHATEVER THE FUCK YOU WANT TO as long as you NEVER LEAVE +A FUCKING TRACE TO TRACK THE AUTHOR of the original product to blame for +or held responsible. + +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + +Good luck and Godspeed. diff --git a/README.md b/README.md new file mode 100644 index 0000000..2170cc6 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# iomail diff --git a/app/Cargo.toml b/app/Cargo.toml new file mode 100644 index 0000000..211d3b2 --- /dev/null +++ b/app/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "app" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/app/src/lib.rs b/app/src/lib.rs new file mode 100644 index 0000000..06d268d --- /dev/null +++ b/app/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: usize, right: usize) -> usize { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} diff --git a/pgmodeler.dbm b/pgmodeler.dbm new file mode 100644 index 0000000..6b05272 --- /dev/null +++ b/pgmodeler.dbm @@ -0,0 +1,400 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/server/Cargo.toml b/server/Cargo.toml new file mode 100644 index 0000000..e69de29 diff --git a/server/src/main.rs b/server/src/main.rs new file mode 100644 index 0000000..a30eb95 --- /dev/null +++ b/server/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/smtp/go.mod b/smtp/go.mod new file mode 100644 index 0000000..db500ab --- /dev/null +++ b/smtp/go.mod @@ -0,0 +1,9 @@ +module git.davidon.top/iomail.git + +go 1.22.3 + +require ( + github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 // indirect + github.com/emersion/go-smtp v0.21.2 // indirect + github.com/rabbitmq/amqp091-go v1.10.0 // indirect +) diff --git a/smtp/go.sum b/smtp/go.sum new file mode 100644 index 0000000..3f8964a --- /dev/null +++ b/smtp/go.sum @@ -0,0 +1,6 @@ +github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 h1:OJyUGMJTzHTd1XQp98QTaHernxMYzRaOasRir9hUlFQ= +github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ= +github.com/emersion/go-smtp v0.21.2 h1:OLDgvZKuofk4em9fT5tFG5j4jE1/hXnX75UMvcrL4AA= +github.com/emersion/go-smtp v0.21.2/go.mod h1:qm27SGYgoIPRot6ubfQ/GpiPy/g3PaZAVRxiO/sDUgQ= +github.com/rabbitmq/amqp091-go v1.10.0 h1:STpn5XsHlHGcecLmMFCtg7mqq0RnD+zFr4uzukfVhBw= +github.com/rabbitmq/amqp091-go v1.10.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o= diff --git a/smtp/main.go b/smtp/main.go new file mode 100644 index 0000000..9b9e8b4 --- /dev/null +++ b/smtp/main.go @@ -0,0 +1,127 @@ +package main + +import ( + "bytes" + "encoding/base64" + "encoding/json" + "io" + "log" + "os" + + "github.com/emersion/go-smtp" + "github.com/rabbitmq/amqp091-go" +) + +type Mail struct { + From *string `json:"from"` + To *string `json:"to"` + Body *string `json:"body"` + UTF8 *bool `json:"UTF8"` +} + +type backend struct{ + Queue *amqp091.Queue + Channel *amqp091.Channel +} + +func (bkd *backend) NewSession(c *smtp.Conn) (smtp.Session, error) { + return &session{ + Queue: bkd.Queue, + Channel: bkd.Channel, + MailBuilder: Mail{}, + }, nil +} + +type session struct{ + Queue *amqp091.Queue + MailBuilder Mail + Channel *amqp091.Channel +} + +func (s *session) AuthPlain(username, password string) error { + return nil +} + +func (s *session) Mail(from string, opts *smtp.MailOptions) error { + s.MailBuilder.From = &from + s.MailBuilder.UTF8 = &opts.UTF8 + return nil +} + +func (s *session) Rcpt(to string, opts *smtp.RcptOptions) error { + s.MailBuilder.To = &to + return nil +} + +func (s *session) Data(r io.Reader) error { + buf := new(bytes.Buffer) + if _, err := buf.ReadFrom(r); err != nil { + log.Fatal(err) + } + body := base64.StdEncoding.EncodeToString(buf.Bytes()) + s.MailBuilder.Body = &body + return nil +} + +func (s *session) Reset() { + submitMail(s.MailBuilder, s.Channel, s.Queue) +} + +func (s *session) Logout() error { + return nil +} + +func submitMail(mail Mail, ch *amqp091.Channel, q *amqp091.Queue) { + mb, err := json.Marshal(mail) + if err != nil { + log.Fatal(err) + } + err = ch.Publish( + "", + q.Name, + false, + false, + amqp091.Publishing{ + ContentType: "application/octet-stream", + Body: []byte(base64.StdEncoding.EncodeToString(mb)), + }, + ) + if err != nil { + log.Println("oh uh") + log.Fatal(err) + } + log.Println("Submited mail to rabbitmq") +} + + +func main() { + conn, err := amqp091.Dial("amqp://d:8o9HGX!CFx!2sg!@dUqN@localhost:5672/") + if err != nil { + log.Fatal(err) + } + defer conn.Close() + + ch, err := conn.Channel() + if err != nil { + log.Fatal(err) + } + defer ch.Close() + + q, err := ch.QueueDeclare("mail", true, false, false, false, nil) + if err != nil { + log.Fatal(err) + } + + s := smtp.NewServer(&backend{ + Queue: &q, + Channel: ch, + }) + + s.Addr = "0.0.0.0:8700" + s.AllowInsecureAuth = true + s.Debug = os.Stderr + + log.Println("Starting smtp server") + log.Fatal(s.ListenAndServe()) + +}