From 5e012fb5e0c1dca9e2dd245b2e96c57e16f1a5af Mon Sep 17 00:00:00 2001 From: nikkel Date: Fri, 20 Mar 2020 03:20:52 +0700 Subject: [PATCH] Upload files to 'src/main/java/ca/mgamble/postman/api/message' --- .../mgamble/postman/api/message/Header.java | 43 +++++ .../postman/api/message/PostmanMessage.java | 153 ++++++++++++++++++ .../api/message/PostmanMessageBuilder.java | 90 +++++++++++ .../api/message/PostmanRawMessage.java | 58 +++++++ .../api/message/PostmanRawMessageBuilder.java | 43 +++++ 5 files changed, 387 insertions(+) create mode 100644 src/main/java/ca/mgamble/postman/api/message/Header.java create mode 100644 src/main/java/ca/mgamble/postman/api/message/PostmanMessage.java create mode 100644 src/main/java/ca/mgamble/postman/api/message/PostmanMessageBuilder.java create mode 100644 src/main/java/ca/mgamble/postman/api/message/PostmanRawMessage.java create mode 100644 src/main/java/ca/mgamble/postman/api/message/PostmanRawMessageBuilder.java diff --git a/src/main/java/ca/mgamble/postman/api/message/Header.java b/src/main/java/ca/mgamble/postman/api/message/Header.java new file mode 100644 index 0000000..19fa92a --- /dev/null +++ b/src/main/java/ca/mgamble/postman/api/message/Header.java @@ -0,0 +1,43 @@ + +package ca.mgamble.postman.api.message; + +import lombok.Data; + +/** + * + * @author mgamble + */ +/* +The MIT License (MIT) + +Copyright (c) 2017 Matthew M. Gamble https://www.mgamble.ca + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +@Data +public class Header { + private String key; + private String value; + + public Header(String key, String value) { + this.key = key; + this.value = value; + } +} diff --git a/src/main/java/ca/mgamble/postman/api/message/PostmanMessage.java b/src/main/java/ca/mgamble/postman/api/message/PostmanMessage.java new file mode 100644 index 0000000..d1f2b92 --- /dev/null +++ b/src/main/java/ca/mgamble/postman/api/message/PostmanMessage.java @@ -0,0 +1,153 @@ +package ca.mgamble.postman.api.message; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author mgamble + */ +/* +The MIT License (MIT) + +Copyright (c) 2017 Matthew M. Gamble https://www.mgamble.ca + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +@Data +public class PostmanMessage { + + private List to; + private List cc; + private List bcc; + private List attachments; + private List embeddedImages; + + @SerializedName("Headers") + private List
headers; + + private String from; + private String subject; + private String tag; + private String reply_to; + private String plain_body; + private String html_body; + private boolean bounce; + + public PostmanMessage(List to, List cc, List bcc, List attachments, List embeddedImages, + List
headers, String from, String subject, String tag, String reply_to, String plain_body, String html_body, boolean bounce) { + this.to = to; + this.cc = cc; + this.bcc = bcc; + this.attachments = attachments; + this.embeddedImages = embeddedImages; + this.headers = headers; + this.from = from; + this.subject = subject; + this.tag = tag; + this.reply_to = reply_to; + this.plain_body = plain_body; + this.html_body = html_body; + this.bounce = bounce; + } + + public PostmanMessage() { + this.to = new ArrayList<>(); + this.cc = new ArrayList<>(); + this.bcc = new ArrayList<>(); + } + + public void addTo(String rcptTo) { + if (this.to == null) { + this.to = new ArrayList<>(); + } + this.to.add(rcptTo); + } + + public void addCC(String rcptCC) { + if (this.cc == null) { + this.cc = new ArrayList<>(); + } + this.cc.add(rcptCC); + } + + public void addBCC(String rcptBCC) { + if (this.bcc == null) { + this.bcc = new ArrayList<>(); + } + this.bcc.add(rcptBCC); + } + + public void addAttachment(String name, String content_type, String data) { + this.addAttachment(new Attachment(name, content_type, data)); + } + + public void addAttachment(Attachment attachment) { + if (this.attachments == null) { + this.attachments = new ArrayList<>(); + } + this.attachments.add(attachment); + } + + public void addEmbeddedImage(EmbeddedImage embeddedImage) { + if (this.embeddedImages == null) { + this.embeddedImages = new ArrayList<>(); + } + this.embeddedImages.add(embeddedImage); + } + + public void addHeader(Header header) { + if (this.headers == null) { + this.headers = new ArrayList<>(); + } + this.headers.add(header); + } + + public void addHeader(String key, String value) { + this.addHeader(new Header(key, value)); + } + + public String getReplyTo() { + return reply_to; + } + + public void setReplyTo(String reply_to) { + this.reply_to = reply_to; + } + + public String getPlainBody() { + return plain_body; + } + + public void setPlainBody(String plain_body) { + this.plain_body = plain_body; + } + + public String getHtmlBody() { + return html_body; + } + + public void setHtmlBody(String html_body) { + this.html_body = html_body; + } +} diff --git a/src/main/java/ca/mgamble/postman/api/message/PostmanMessageBuilder.java b/src/main/java/ca/mgamble/postman/api/message/PostmanMessageBuilder.java new file mode 100644 index 0000000..c123beb --- /dev/null +++ b/src/main/java/ca/mgamble/postman/api/message/PostmanMessageBuilder.java @@ -0,0 +1,90 @@ +package ca.mgamble.postman.api.message; + +import java.util.ArrayList; +import java.util.List; + +public class PostmanMessageBuilder { + + private List to = new ArrayList<>(); + private List cc = new ArrayList<>(); + private List bcc = new ArrayList<>(); + private List attachments = new ArrayList<>(); + private List embeddedImages = new ArrayList<>(); + private List
headers = new ArrayList<>(); + private String from; + private String subject; + private String tag; + private String reply_to; + private String plain_body; + private String html_body; + private boolean bounce; + + public PostmanMessageBuilder to(String to) { + this.to.add(to); + return this; + } + + public PostmanMessageBuilder cc(String cc) { + this.cc.add(cc); + return this; + } + + public PostmanMessageBuilder bcc(String bcc) { + this.bcc.add(bcc); + return this; + } + + public PostmanMessageBuilder addAttachment(Attachment attachment) { + this.attachments.add(attachment); + return this; + } + + public PostmanMessageBuilder addEmbeddedImage(EmbeddedImage embeddedImage) { + this.embeddedImages.add(embeddedImage); + return this; + } + + public PostmanMessageBuilder addHeader(Header header) { + this.headers.add(header); + return this; + } + + public PostmanMessageBuilder from(String from) { + this.from = from; + return this; + } + + public PostmanMessageBuilder withSubject(String subject) { + this.subject = subject; + return this; + } + + public PostmanMessageBuilder withTag(String tag) { + this.tag = tag; + return this; + } + + public PostmanMessageBuilder withReplyTo(String reply_to) { + this.reply_to = reply_to; + return this; + } + + public PostmanMessageBuilder withPlainBody(String plain_body) { + this.plain_body = plain_body; + return this; + } + + public PostmanMessageBuilder withHtmlBody(String html_body) { + this.html_body = html_body; + return this; + } + + public PostmanMessageBuilder withBounce(boolean bounce) { + this.bounce = bounce; + return this; + } + + public PostmanMessage build() { + return new PostmanMessage(to, cc, bcc, attachments, embeddedImages, headers, from, subject, tag, reply_to, plain_body, html_body, bounce); + } +} diff --git a/src/main/java/ca/mgamble/postman/api/message/PostmanRawMessage.java b/src/main/java/ca/mgamble/postman/api/message/PostmanRawMessage.java new file mode 100644 index 0000000..00df0df --- /dev/null +++ b/src/main/java/ca/mgamble/postman/api/message/PostmanRawMessage.java @@ -0,0 +1,58 @@ +package ca.mgamble.postman.api.message; + +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author mgamble + */ +/* +The MIT License (MIT) + +Copyright (c) 2017 Matthew M. Gamble https://www.mgamble.ca + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +@Data +@NoArgsConstructor +public class PostmanRawMessage { + private String mail_from; + private List rcpt_to; + private String data; + private boolean bounce; + + public PostmanRawMessage(String from, String data, boolean bounce, List rcpt_to) { + this.mail_from = from; + this.data = data; + this.bounce = bounce; + this.rcpt_to = rcpt_to; + } + + public void addTo(String rcptTo) { + if (this.rcpt_to == null) { + this.rcpt_to = new ArrayList<>(); + } + this.rcpt_to.add(rcptTo); + } +} diff --git a/src/main/java/ca/mgamble/postman/api/message/PostmanRawMessageBuilder.java b/src/main/java/ca/mgamble/postman/api/message/PostmanRawMessageBuilder.java new file mode 100644 index 0000000..c0dfe3a --- /dev/null +++ b/src/main/java/ca/mgamble/postman/api/message/PostmanRawMessageBuilder.java @@ -0,0 +1,43 @@ +package ca.mgamble.postman.api.message; + +import java.util.ArrayList; +import java.util.List; + +public class PostmanRawMessageBuilder { + private String mail_from; + private String data; + private boolean bounce; + private List rcpt_to; + + public PostmanRawMessageBuilder from(String mail_from) { + this.mail_from = mail_from; + return this; + } + + public PostmanRawMessageBuilder withData(String data) { + this.data = data; + return this; + } + + public PostmanRawMessageBuilder withBounce(boolean bounce) { + this.bounce = bounce; + return this; + } + + public PostmanRawMessageBuilder to(String rcptTo) { + if (this.rcpt_to == null) { + this.rcpt_to = new ArrayList<>(); + } + this.rcpt_to.add(rcptTo); + return this; + } + + public PostmanRawMessageBuilder tos(List tos) { + this.rcpt_to = tos; + return this; + } + + public PostmanRawMessage build() { + return new PostmanRawMessage(mail_from, data, bounce, rcpt_to); + } +}