11/*************************************************
22 * MailerSend Java SDK
33 * https://github.com/mailersend/mailersend-java
4- *
4+ *
55 * @author MailerSend <support@mailersend.com>
66 * https://mailersend.com
77 **************************************************/
88
99package com .mailersend .sdk .emails ;
1010
11+ import com .google .gson .annotations .SerializedName ;
12+ import org .apache .commons .io .FileUtils ;
13+
1114import java .io .File ;
1215import java .io .IOException ;
1316import java .util .Base64 ;
1417
15- import org .apache .commons .io .FileUtils ;
16-
17- import com .google .gson .annotations .SerializedName ;
18-
1918/**
2019 * <p>Attachment class.</p>
2120 *
@@ -32,8 +31,10 @@ public class Attachment {
3231
3332 @ SerializedName ("id" )
3433 public String id ;
35-
36-
34+
35+ @ SerializedName ("disposition" )
36+ public String disposition ;
37+
3738 /**
3839 * Reads a file, encodes it to base64 and sets it as an attachment
3940 *
@@ -44,18 +45,56 @@ public void AddAttachmentFromFile(String path) throws IOException {
4445 File file = new File (path );
4546 this .content = Base64 .getEncoder ().encodeToString (FileUtils .readFileToByteArray (file ));
4647 this .filename = file .getName ();
48+ setDisposition (false );
4749 }
48-
49-
50+
5051 /**
5152 * Sets an attachments contents and filename
5253 *
53- * @param content The base64 contents of the attachment
54+ * @param content The base64 contents of the attachment
5455 * @param filename a {@link java.lang.String} object.
5556 */
5657 public void setAttachment (String content , String filename ) {
57-
5858 this .content = content ;
5959 this .filename = filename ;
60+ setDisposition (false );
61+ }
62+
63+ /**
64+ * Reads a file, encodes it to base64 and sets it as an attachment
65+ *
66+ * @param contentId The contentId of the image. If set and not empty, disposition will be set to inline, else to attachment
67+ * @param path a {@link java.lang.String} object.
68+ * @throws java.io.IOException
69+ */
70+ public void AddImageFromFile (String contentId , String path ) throws IOException {
71+ File file = new File (path );
72+ this .id = contentId ;
73+ this .content = Base64 .getEncoder ().encodeToString (FileUtils .readFileToByteArray (file ));
74+ this .filename = file .getName ();
75+ setDisposition (contentId != null && contentId .trim ().length () > 1 );
76+ }
77+
78+ /**
79+ * Sets an attachments contents and filename
80+ *
81+ * @param contentId The contentId of the image. If set and not empty, disposition will be set to inline, else to attachment
82+ * @param content The base64 contents of the attachment
83+ * @param filename a {@link java.lang.String} object.
84+ */
85+ public void setImage (String contentId , String content , String filename ) {
86+ this .id = contentId ;
87+ this .content = content ;
88+ this .filename = filename ;
89+ setDisposition (contentId != null && contentId .trim ().length () > 1 );
90+ }
91+
92+ /**
93+ * Sets the disposition of this attachment.
94+ *
95+ * @param inline If set to true, disposition will be set to "inline", if false to "attachment"
96+ */
97+ public void setDisposition (boolean inline ) {
98+ this .disposition = inline ? "inline" : "attachment" ;
6099 }
61- }
100+ }
0 commit comments