diff --git a/CHANGELOG.md b/CHANGELOG.md index ad27eab7..81cfe6ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ # Nylas Java SDK Changelog -## Unreleased +### [Unreleased] ### Added +* Added support for custom headers field for Drafts and Messages * Added support for overriding various fields of outgoing requests ## [2.2.1] - Released 2024-03-05 diff --git a/src/main/kotlin/com/nylas/models/CreateDraftRequest.kt b/src/main/kotlin/com/nylas/models/CreateDraftRequest.kt index 8965bd5a..4eea7194 100644 --- a/src/main/kotlin/com/nylas/models/CreateDraftRequest.kt +++ b/src/main/kotlin/com/nylas/models/CreateDraftRequest.kt @@ -62,6 +62,11 @@ data class CreateDraftRequest( */ @Json(name = "tracking_options") val trackingOptions: TrackingOptions? = null, + /** + * A list of custom headers to add to the message. + */ + @Json(name = "custom_headers") + val customHeaders: List? = null, ) : IMessageAttachmentRequest { /** * Builder for [CreateDraftRequest]. @@ -78,6 +83,7 @@ data class CreateDraftRequest( private var sendAt: Int? = null private var replyToMessageId: String? = null private var trackingOptions: TrackingOptions? = null + private var customHeaders: List? = null /** * Sets the recipients. @@ -157,6 +163,13 @@ data class CreateDraftRequest( */ fun trackingOptions(trackingOptions: TrackingOptions?) = apply { this.trackingOptions = trackingOptions } + /** + * Sets the custom headers to add to the message. + * @param customHeaders The custom headers to add to the message. + * @return The builder. + */ + fun customHeaders(customHeaders: List?) = apply { this.customHeaders = customHeaders } + /** * Builds a [SendMessageRequest] instance. * @return The [SendMessageRequest] instance. @@ -174,6 +187,7 @@ data class CreateDraftRequest( sendAt, replyToMessageId, trackingOptions, + customHeaders, ) } } diff --git a/src/main/kotlin/com/nylas/models/CustomHeader.kt b/src/main/kotlin/com/nylas/models/CustomHeader.kt new file mode 100644 index 00000000..b8cd9b18 --- /dev/null +++ b/src/main/kotlin/com/nylas/models/CustomHeader.kt @@ -0,0 +1,36 @@ +package com.nylas.models + +import com.squareup.moshi.Json + +/** + * Custom headers to be used when drafting or sending an email. + */ +data class CustomHeader( + /** + * The name of the custom header. + */ + @Json(name = "name") + val name: String, + /** + * The value of the custom header. + */ + @Json(name = "value") + val value: String, +) { + /** + * Builder for [CustomHeader]. + * @property name The name of the custom header. + * @property value The value of the custom header. + */ + data class Builder( + private val name: String, + private val value: String, + ) { + /** + * Build the [CustomHeader] object. + */ + fun build(): CustomHeader { + return CustomHeader(name, value) + } + } +} diff --git a/src/main/kotlin/com/nylas/models/SendMessageRequest.kt b/src/main/kotlin/com/nylas/models/SendMessageRequest.kt index f091f269..fee41f45 100644 --- a/src/main/kotlin/com/nylas/models/SendMessageRequest.kt +++ b/src/main/kotlin/com/nylas/models/SendMessageRequest.kt @@ -68,6 +68,11 @@ data class SendMessageRequest( */ @Json(name = "use_draft") val useDraft: Boolean? = null, + /** + * A list of custom headers to add to the message. + */ + @Json(name = "custom_headers") + val customHeaders: List? = null, ) : IMessageAttachmentRequest { /** * Builder for [SendMessageRequest]. @@ -87,6 +92,7 @@ data class SendMessageRequest( private var replyToMessageId: String? = null private var trackingOptions: TrackingOptions? = null private var useDraft: Boolean? = null + private var customHeaders: List? = null /** * Sets the bcc recipients. @@ -167,6 +173,13 @@ data class SendMessageRequest( */ fun useDraft(useDraft: Boolean?) = apply { this.useDraft = useDraft } + /** + * Sets the custom headers to add to the message. + * @param customHeaders The custom headers to add to the message. + * @return The builder. + */ + fun customHeaders(customHeaders: List?) = apply { this.customHeaders = customHeaders } + /** * Builds a [SendMessageRequest] instance. * @return The [SendMessageRequest] instance. @@ -185,6 +198,7 @@ data class SendMessageRequest( replyToMessageId, trackingOptions, useDraft, + customHeaders, ) } } diff --git a/src/test/kotlin/com/nylas/resources/DraftsTests.kt b/src/test/kotlin/com/nylas/resources/DraftsTests.kt index 2d71b280..eb774273 100644 --- a/src/test/kotlin/com/nylas/resources/DraftsTests.kt +++ b/src/test/kotlin/com/nylas/resources/DraftsTests.kt @@ -230,6 +230,7 @@ class DraftsTests { sendAt = 1620000000, replyToMessageId = "reply-to-message-id", trackingOptions = TrackingOptions(label = "label", links = true, opens = true, threadReplies = true), + customHeaders = listOf(CustomHeader(name = "header", value = "value")), ) drafts.create(grantId, createDraftRequest) @@ -275,6 +276,7 @@ class DraftsTests { size = 100, ), ), + customHeaders = listOf(CustomHeader(name = "header", value = "value")), ) drafts.create(grantId, createDraftRequest) @@ -320,6 +322,7 @@ class DraftsTests { size = 3 * 1024 * 1024, ), ), + customHeaders = listOf(CustomHeader(name = "header", value = "value")), ) drafts.create(grantId, createDraftRequest) diff --git a/src/test/kotlin/com/nylas/resources/MessagesTests.kt b/src/test/kotlin/com/nylas/resources/MessagesTests.kt index dd5df73b..f98e27dc 100644 --- a/src/test/kotlin/com/nylas/resources/MessagesTests.kt +++ b/src/test/kotlin/com/nylas/resources/MessagesTests.kt @@ -384,6 +384,7 @@ class MessagesTests { sendAt = 1620000000, replyToMessageId = "reply-to-message-id", trackingOptions = TrackingOptions(label = "label", links = true, opens = true, threadReplies = true), + customHeaders = listOf(CustomHeader(name = "header-name", value = "header-value")), ) messages.send(grantId, sendMessageRequest) @@ -430,6 +431,7 @@ class MessagesTests { size = 100, ), ), + customHeaders = listOf(CustomHeader(name = "header-name", value = "header-value")), ) messages.send(grantId, sendMessageRequest) @@ -476,6 +478,7 @@ class MessagesTests { size = 3 * 1024 * 1024, ), ), + customHeaders = listOf(CustomHeader(name = "header-name", value = "header-value")), ) messages.send(grantId, sendMessageRequest)