-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea55e3e
commit 339e3ab
Showing
9 changed files
with
317 additions
and
184 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
modules/core/core-api/src/main/java/com/enonic/xp/mail/MailAttachment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package com.enonic.xp.mail; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.io.ByteSource; | ||
|
||
import com.enonic.xp.annotation.PublicApi; | ||
import com.enonic.xp.util.MediaTypes; | ||
|
||
@PublicApi | ||
public final class MailAttachment | ||
{ | ||
private final String fileName; | ||
|
||
private final ByteSource data; | ||
|
||
private final String mimeType; | ||
|
||
private final Map<String, String> headers; | ||
|
||
private MailAttachment( final Builder builder ) | ||
{ | ||
this.fileName = Objects.requireNonNull( builder.fileName ); | ||
this.data = Objects.requireNonNull( builder.data ); | ||
this.mimeType = builder.mimeType != null ? builder.mimeType : resolveMimeType( builder.fileName ); | ||
this.headers = builder.headers != null ? ImmutableMap.copyOf( builder.headers ) : ImmutableMap.of(); | ||
} | ||
|
||
private String resolveMimeType( final String fileName ) | ||
{ | ||
return MediaTypes.instance().fromFile( fileName ).toString(); | ||
} | ||
|
||
public static Builder create() | ||
{ | ||
return new Builder(); | ||
} | ||
|
||
public String getFileName() | ||
{ | ||
return fileName; | ||
} | ||
|
||
public ByteSource getData() | ||
{ | ||
return data; | ||
} | ||
|
||
public String getMimeType() | ||
{ | ||
return mimeType; | ||
} | ||
|
||
public Map<String, String> getHeaders() | ||
{ | ||
return headers; | ||
} | ||
|
||
public static class Builder | ||
{ | ||
private String fileName; | ||
|
||
private ByteSource data; | ||
|
||
private String mimeType; | ||
|
||
private Map<String, String> headers; | ||
|
||
public Builder fileName( final String fileName ) | ||
{ | ||
this.fileName = fileName; | ||
return this; | ||
} | ||
|
||
public Builder data( final ByteSource data ) | ||
{ | ||
this.data = data; | ||
return this; | ||
} | ||
|
||
public Builder mimeType( final String mimeType ) | ||
{ | ||
this.mimeType = mimeType; | ||
return this; | ||
} | ||
|
||
public Builder headers( final Map<String, String> headers ) | ||
{ | ||
this.headers = headers; | ||
return this; | ||
} | ||
|
||
public MailAttachment build() | ||
{ | ||
return new MailAttachment( this ); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
modules/core/core-api/src/main/java/com/enonic/xp/mail/MailHeader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.enonic.xp.mail; | ||
|
||
import com.enonic.xp.annotation.PublicApi; | ||
|
||
@PublicApi | ||
public final class MailHeader | ||
{ | ||
private final String key; | ||
|
||
private final String value; | ||
|
||
public MailHeader( final String key, final String value ) | ||
{ | ||
this.key = key; | ||
this.value = value; | ||
} | ||
|
||
public static MailHeader from( final String key, final String value ) | ||
{ | ||
return new MailHeader( key, value ); | ||
} | ||
|
||
public String getKey() | ||
{ | ||
return key; | ||
} | ||
|
||
public String getValue() | ||
{ | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.