Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

* `Template::Message` accepts `mime_content` (Base64 MIME, with `mime_content_charset`, default `UTF-8`) and an explicit `message_disposition`; the builder now emits `t:MimeContent` for items, and `IncludeMimeContent` is built by `include_mime_content!`
* Replace the `logging` gem with stdlib `logger`
* `EWSClient.new` and `Viewpoint::EWS::Connection.new` now take an `auth` hash (`endpoint:`, `type:`, `user:`, `password:`, `token:`) instead of positional `endpoint, username, password` arguments; OAuth bearer-token authentication is supported via `type: 'oauth'` with a `token:`, which is sent as an `Authorization: Bearer` header

Expand Down
11 changes: 9 additions & 2 deletions lib/ews/soap/builders/ews_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def item_shape!(item_shape)
@nbuild[NS_EWS_MESSAGES].ItemShape {
@nbuild.parent.default_namespace = @default_ns
base_shape!(item_shape[:base_shape])
mime_content!(item_shape[:include_mime_content]) if item_shape.key?(:include_mime_content)
include_mime_content!(item_shape[:include_mime_content]) if item_shape.key?(:include_mime_content)
body_type!(item_shape[:body_type]) if item_shape[:body_type]
additional_properties!(item_shape[:additional_properties]) if item_shape[:additional_properties]
}
Expand All @@ -152,7 +152,7 @@ def base_shape!(base_shape)
@nbuild[NS_EWS_TYPES].BaseShape(camel_case(base_shape))
end

def mime_content!(include_mime_content)
def include_mime_content!(include_mime_content)
@nbuild[NS_EWS_TYPES].IncludeMimeContent(include_mime_content.to_s.downcase)
end

Expand Down Expand Up @@ -948,6 +948,13 @@ def body!(body)
}
end

# @see https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/mimecontent
def mime_content!(mime_content)
nbuild[NS_EWS_TYPES].MimeContent(mime_content[:text]) { |x|
x.parent['CharacterSet'] = mime_content[:character_set] if mime_content[:character_set]
}
end

def new_body_content!(body)
nbuild[NS_EWS_TYPES].NewBodyContent(body[:text]) { |x|
x.parent['BodyType'] = body[:body_type] if body[:body_type]
Expand Down
4 changes: 3 additions & 1 deletion lib/ews/templates/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ def init_defaults!
self.item_attachments ||= []
self.inline_attachments ||= []
self.extended_properties ||= []
self.mime_content_charset ||= 'UTF-8'
end

def to_ews_basic
ews_opts = {}
ews_opts[:message_disposition] = (draft ? 'SaveOnly' : 'SendAndSaveCopy')
ews_opts[:message_disposition] = message_disposition || (draft ? 'SaveOnly' : 'SendAndSaveCopy')

if saved_item_folder_id
ews_opts[:saved_item_folder_id] = if saved_item_folder_id.is_a?(Hash)
Expand All @@ -51,6 +52,7 @@ def to_ews_basic
end

msg = {}
msg[:mime_content] = { text: mime_content, character_set: mime_content_charset } if mime_content
msg[:subject] = subject if subject
msg[:body] = { text: body, body_type: body_type } if body

Expand Down
16 changes: 16 additions & 0 deletions spec/unit/soap/builders/ews_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@
expect(doc.xpath('//t:BodyType[3]').text).to eq('Best')
end

it 'should build MimeContent for a message item' do
doc = builder.build! { |section|
builder.message!(mime_content: { text: 'TUlNRQ==', character_set: 'UTF-8' }) if section == :body
}
mime_content = doc.at_xpath('//t:Message/t:MimeContent', namespaces)
expect(mime_content.text).to eq('TUlNRQ==')
expect(mime_content['CharacterSet']).to eq('UTF-8')
end

it 'should build IncludeMimeContent' do
doc = builder.build! { |section|
builder.include_mime_content!(true) if section == :body
}
expect(doc.at_xpath('//t:IncludeMimeContent', namespaces).text).to eq('true')
end

it 'should format various Time inputs' do
expect(builder.send(:format_time, Date.iso8601('2013-01-01'))).to eq('2013-01-01T00:00:00+00:00')
expect(builder.send(:format_time, DateTime.iso8601('2013-01-01T23:01:00-05:00'))).to eq('2013-01-02T04:01:00+00:00')
Expand Down
33 changes: 33 additions & 0 deletions spec/unit/templates/message_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require_relative '../../spec_helper'

describe Viewpoint::EWS::Template::Message do
describe '#to_ews' do
it 'defaults the message disposition from the draft flag' do
expect(described_class.new.to_ews[:message_disposition]).to eq('SendAndSaveCopy')
expect(described_class.new(draft: true).to_ews[:message_disposition]).to eq('SaveOnly')
end

it 'uses an explicit message disposition' do
msg = described_class.new(draft: true, message_disposition: 'SendOnly')
expect(msg.to_ews[:message_disposition]).to eq('SendOnly')
end

it 'omits MimeContent unless given' do
expect(described_class.new.to_ews[:items].first[:message]).not_to have_key(:mime_content)
end

it 'includes MimeContent with a UTF-8 character set by default' do
msg = described_class.new(mime_content: 'TUlNRQ==')
expect(msg.to_ews[:items].first[:message][:mime_content]).to eq(text: 'TUlNRQ==', character_set: 'UTF-8')
end

it 'includes MimeContent set in a block-style assignment with a custom character set' do
msg = described_class.new
msg.mime_content = 'TUlNRQ=='
msg.mime_content_charset = 'ISO-8859-1'
expect(msg.to_ews[:items].first[:message][:mime_content]).to eq(text: 'TUlNRQ==', character_set: 'ISO-8859-1')
end
end
end
Loading