viewpoint 0.0.5 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +84 -45
- data/Rakefile +7 -5
- data/TODO +6 -0
- data/VERSION +1 -1
- data/lib/exceptions/exceptions.rb +34 -0
- data/lib/extensions/string.rb +37 -0
- data/lib/model/calendar_folder.rb +45 -0
- data/lib/model/calendar_item.rb +145 -0
- data/lib/model/contact.rb +58 -0
- data/lib/model/contacts_folder.rb +35 -0
- data/lib/model/distribution_list.rb +26 -0
- data/lib/model/event.rb +118 -0
- data/lib/model/folder.rb +36 -0
- data/lib/model/generic_folder.rb +302 -0
- data/lib/model/item.rb +126 -0
- data/lib/model/mailbox_user.rb +107 -0
- data/lib/model/meeting_cancellation.rb +28 -0
- data/lib/{viewpoint/errors.rb → model/meeting_message.rb} +10 -14
- data/lib/model/meeting_request.rb +26 -0
- data/lib/model/meeting_response.rb +26 -0
- data/lib/model/message.rb +73 -0
- data/lib/model/model.rb +161 -0
- data/lib/model/search_folder.rb +36 -0
- data/lib/model/task.rb +62 -0
- data/lib/model/task_list.rb +19 -0
- data/lib/model/tasks_folder.rb +33 -0
- data/lib/soap/handsoap/builder.rb +22 -0
- data/lib/soap/handsoap/builders/ews_build_helpers.rb +317 -0
- data/lib/soap/handsoap/builders/ews_builder.rb +86 -0
- data/lib/soap/handsoap/ews_service.rb +646 -0
- data/lib/soap/handsoap/parser.rb +106 -0
- data/lib/soap/handsoap/parsers/ews_parser.rb +165 -0
- data/lib/soap/soap_provider.rb +75 -0
- data/lib/viewpoint.rb +98 -3
- data/preamble +1 -1
- data/test/spec/basic_functions.spec +51 -0
- data/test/spec/folder_subscriptions.spec +35 -0
- data/test/spec/folder_synchronization.spec +28 -0
- data/utils/ewsWSDL2rb.rb +29 -0
- metadata +101 -43
- data/lib/exchwebserv.rb +0 -6
- data/lib/soap/viewpoint.conf +0 -3
- data/lib/viewpoint/calendar.rb +0 -128
- data/lib/viewpoint/calendar_item.rb +0 -118
- data/lib/viewpoint/event.rb +0 -0
- data/lib/viewpoint/exchange_headers.rb +0 -49
- data/lib/viewpoint/exchwebserv.rb +0 -236
- data/lib/viewpoint/folder.rb +0 -358
- data/lib/viewpoint/item.rb +0 -101
- data/lib/viewpoint/mail.rb +0 -117
- data/lib/viewpoint/message.rb +0 -132
- data/lib/viewpoint/task.rb +0 -0
- data/lib/viewpoint/tasks.rb +0 -0
- data/lib/wsdl/defaultMappingRegistry.rb +0 -10680
- data/lib/wsdl/exchangeServiceBinding.rb +0 -349
- data/lib/wsdl/exchangeServiceTypes.rb +0 -11013
- data/test/spec/basic_features_spec.rb +0 -37
- data/test/test_client.rb +0 -13
- data/test/testrestrict.rb +0 -75
data/lib/model/item.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
#############################################################################
|
2
|
+
# Copyright © 2010 Dan Wanek <dan.wanek@gmail.com>
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# This file is part of Viewpoint.
|
6
|
+
#
|
7
|
+
# Viewpoint is free software: you can redistribute it and/or
|
8
|
+
# modify it under the terms of the GNU General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or (at
|
10
|
+
# your option) any later version.
|
11
|
+
#
|
12
|
+
# Viewpoint is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
15
|
+
# Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License along
|
18
|
+
# with Viewpoint. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#############################################################################
|
20
|
+
|
21
|
+
|
22
|
+
# This class is inherited by all Item subtypes such as Message, Event,
|
23
|
+
# and Task. It will serve as the brain for all of the methods that
|
24
|
+
# each of these Item types have in common.
|
25
|
+
module Viewpoint
|
26
|
+
module EWS
|
27
|
+
class Item
|
28
|
+
include Model
|
29
|
+
|
30
|
+
# This is a class method that fetches an existing Item from the
|
31
|
+
# Exchange Store.
|
32
|
+
# @param [String] item_id The id of the item.
|
33
|
+
# @return [Item] Returns an Item or subclass of Item
|
34
|
+
# @todo Add support to fetch an item with a ChangeKey
|
35
|
+
def self.get_item(item_id)
|
36
|
+
conn = Viewpoint::EWS::EWS.instance
|
37
|
+
resp = conn.ews.get_item([item_id])
|
38
|
+
resp = resp.items.shift
|
39
|
+
self.new(resp[resp.keys.first])
|
40
|
+
end
|
41
|
+
|
42
|
+
attr_reader :item_id, :body_type
|
43
|
+
alias :id :item_id
|
44
|
+
|
45
|
+
# Initialize an Exchange Web Services item
|
46
|
+
# @param [Hash] ews_item A hash representing this item
|
47
|
+
# @param [Boolean] shallow Whether or not we have retrieved all the elements for this object
|
48
|
+
def initialize(ews_item, shallow = true)
|
49
|
+
super() # Calls initialize in Model (creates @ews_methods Array)
|
50
|
+
@ews_item = ews_item
|
51
|
+
@shallow = shallow
|
52
|
+
@item_id = ews_item[:item_id][:id]
|
53
|
+
|
54
|
+
init_methods
|
55
|
+
end
|
56
|
+
|
57
|
+
def deepen!
|
58
|
+
conn = Viewpoint::EWS::EWS.instance
|
59
|
+
resp = conn.ews.get_item([@item_id], {:base_shape => 'AllProperties'})
|
60
|
+
resp = resp.items.shift
|
61
|
+
@ews_item = resp[resp.keys.first]
|
62
|
+
@shallow = false
|
63
|
+
@ews_methods = []
|
64
|
+
@ews_methods_undef = []
|
65
|
+
init_methods
|
66
|
+
end
|
67
|
+
|
68
|
+
# Delete this item
|
69
|
+
# @param [Boolean] soft Whether or not to do a soft delete. By default EWS will do a
|
70
|
+
# hard delete of this item. See the MSDN docs for more info:
|
71
|
+
# http://msdn.microsoft.com/en-us/library/aa562961.aspx
|
72
|
+
# @return [Boolean] Whether or not the item was deleted
|
73
|
+
# @todo Add exception handling for failed deletes
|
74
|
+
def delete!(soft=false)
|
75
|
+
deltype = soft ? 'SoftDelete' : 'HardDelete'
|
76
|
+
resp = (Viewpoint::EWS::EWS.instance).ews.delete_item([@item_id], deltype)
|
77
|
+
self.clear_object!
|
78
|
+
resp.status == 'Success'
|
79
|
+
end
|
80
|
+
|
81
|
+
# Delete this item by moving it to the Deleted Items folder
|
82
|
+
# @see http://msdn.microsoft.com/en-us/library/aa562961.aspx
|
83
|
+
# @return [Boolean] Whether or not the item was deleted
|
84
|
+
# @todo Add exception handling for failed deletes
|
85
|
+
def recycle!
|
86
|
+
resp = (Viewpoint::EWS::EWS.instance).ews.delete_item([@item_id], 'MoveToDeletedItems')
|
87
|
+
self.clear_object!
|
88
|
+
resp.status == 'Success'
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
# @todo Handle:
|
94
|
+
# <Attachments/> <Categories/> <InternetMessageHeaders/> <ResponseObjects/>
|
95
|
+
# <ExtendedProperty/> <EffectiveRights/>
|
96
|
+
def init_methods
|
97
|
+
@parent_folder_id = @ews_item[:parent_folder_id][:id] if @ews_item[:parent_folder_id].is_a?(Hash)
|
98
|
+
@conversation_id = @ews_item[:conversation_id][:id] if @ews_item[:conversation_id].is_a?(Hash)
|
99
|
+
@ews_methods << :item_id
|
100
|
+
if(@ews_item[:body] && @ews_item[:body][:body_type])
|
101
|
+
@body_type = @ews_item[:body][:body_type]
|
102
|
+
@ews_methods << :body_type
|
103
|
+
end
|
104
|
+
if(@ews_item[:unique_body] && @ews_item[:unique_body][:body_type])
|
105
|
+
@unique_body_type = @ews_item[:body][:body_type]
|
106
|
+
@ews_methods << :unique_body_type
|
107
|
+
end
|
108
|
+
if(@ews_item[:mime_content] && @ews_item[:mime_content][:character_set])
|
109
|
+
@mime_charset = @ews_item[:mime_content][:character_set]
|
110
|
+
@ews_methods << :mime_charset
|
111
|
+
end
|
112
|
+
define_str_var :subject, :sensitivity, :body, :item_class, :importance, :in_reply_to, :unique_body
|
113
|
+
define_str_var :display_cc, :display_to, :culture, :last_modified_name, :mime_content
|
114
|
+
define_str_var :web_client_read_form_query_string, :web_client_edit_form_query_string
|
115
|
+
define_int_var :size, :reminder_minutes_before_start
|
116
|
+
define_bool_var :has_attachments, :is_submitted, :is_draft, :is_from_me, :is_resend, :is_unmodified, :reminder_is_set, :is_associated
|
117
|
+
define_datetime_var :date_time_sent, :date_time_created, :date_time_received, :reminder_due_by, :last_modified_time
|
118
|
+
end
|
119
|
+
|
120
|
+
def method_missing(m, *args, &block)
|
121
|
+
warn "!!! No such method: #{m}"
|
122
|
+
end
|
123
|
+
|
124
|
+
end # Item
|
125
|
+
end # EWS
|
126
|
+
end # Viewpoint
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#############################################################################
|
2
|
+
# Copyright © 2010 Dan Wanek <dan.wanek@gmail.com>
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# This file is part of Viewpoint.
|
6
|
+
#
|
7
|
+
# Viewpoint is free software: you can redistribute it and/or
|
8
|
+
# modify it under the terms of the GNU General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or (at
|
10
|
+
# your option) any later version.
|
11
|
+
#
|
12
|
+
# Viewpoint is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
15
|
+
# Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License along
|
18
|
+
# with Viewpoint. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#############################################################################
|
20
|
+
|
21
|
+
module Viewpoint
|
22
|
+
module EWS
|
23
|
+
|
24
|
+
# This represents a Mailbox object in the Exchange data store
|
25
|
+
# @see http://msdn.microsoft.com/en-us/library/aa565036.aspx MSDN docs
|
26
|
+
# @todo Design a Class method that resolves to an Array of MailboxUsers
|
27
|
+
class MailboxUser
|
28
|
+
include Model
|
29
|
+
|
30
|
+
# Resolve a user in the Exchange Data Store
|
31
|
+
# @param [String] A user to resolve to.
|
32
|
+
# @return [MailboxUser,Array] If it resolves to one user then it returns a MailboxUser.
|
33
|
+
# If it resolves to more than one user an Array of MailboxUsers are returned. If an
|
34
|
+
# error ocurrs an exception is raised.
|
35
|
+
def self.find_user(resolve)
|
36
|
+
resp = (Viewpoint::EWS::EWS.instance).ews.resolve_names(resolve)
|
37
|
+
if(resp.status == 'Success')
|
38
|
+
return self.new(resp.items.first[:mailbox])
|
39
|
+
elsif(resp.code == 'ErrorNameResolutionMultipleResults')
|
40
|
+
users = []
|
41
|
+
resp.items.each do |u|
|
42
|
+
users << self.new(u[:mailbox])
|
43
|
+
end
|
44
|
+
return users
|
45
|
+
else
|
46
|
+
raise EwsError, "Find User produced an error: #{resp.code}: #{resp.message}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def initialize(mbox_user)
|
51
|
+
super() # Calls initialize in Model (creates @ews_methods Array)
|
52
|
+
@ews_item = mbox_user
|
53
|
+
define_str_var :name, :email_address, :routing_type, :mailbox_type, :item_id
|
54
|
+
end
|
55
|
+
|
56
|
+
# Adds one or more delegates to a principal's mailbox and sets specific access permissions
|
57
|
+
# @see http://msdn.microsoft.com/en-us/library/bb856527.aspx
|
58
|
+
#
|
59
|
+
# @param [String,MailboxUser] delegate_email The user you would like to give delegate access to.
|
60
|
+
# This can either be a simple String e-mail address or you can pass in a MailboxUser object.
|
61
|
+
# @param [Hash] permissions A hash of folder type keys and permission type values. An example
|
62
|
+
# would be {:calendar_folder_permission_level => 'Editor'}. Possible keys are:
|
63
|
+
# :calendar_folder_permission_level, :tasks_folder_permission_level, :inbox_folder_permission_level
|
64
|
+
# :contacts_folder_permission_level, :notes_folder_permission_level, :journal_folder_permission_level
|
65
|
+
# and possible values are: None/Editor/Reviewer/Author/Custom
|
66
|
+
# @return [true] This method either returns true or raises an error with the message
|
67
|
+
# as to why this operation did not succeed.
|
68
|
+
def add_delegate!(delegate_email, permissions)
|
69
|
+
# Modify permissions so we can pass it to the builders
|
70
|
+
permissions.each_pair do |k,v|
|
71
|
+
permissions[k] = {:text => v}
|
72
|
+
end
|
73
|
+
|
74
|
+
resp = (Viewpoint::EWS::EWS.instance).ews.add_delegate(self.email_address, delegate_email, permissions)
|
75
|
+
if(resp.status == 'Success')
|
76
|
+
return true
|
77
|
+
else
|
78
|
+
raise EwsError, "Could not add delegate access for user #{delegate_email}: #{resp.code}, #{resp.message}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def update_delegate!(delegate_email, permissions)
|
83
|
+
# Modify permissions so we can pass it to the builders
|
84
|
+
permissions.each_pair do |k,v|
|
85
|
+
permissions[k] = {:text => v}
|
86
|
+
end
|
87
|
+
|
88
|
+
resp = (Viewpoint::EWS::EWS.instance).ews.update_delegate(self.email_address, delegate_email, permissions)
|
89
|
+
if(resp.status == 'Success')
|
90
|
+
return true
|
91
|
+
else
|
92
|
+
raise EwsError, "Could not update delegate access for user #{delegate_email}: #{resp.code}, #{resp.message}"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_delegate_info()
|
97
|
+
resp = (Viewpoint::EWS::EWS.instance).ews.get_delegate(self.email_address)
|
98
|
+
# if(resp.status == 'Success')
|
99
|
+
# return true
|
100
|
+
# else
|
101
|
+
# raise EwsError, "Could not update delegate access for user #{delegate_email}: #{resp.code}, #{resp.message}"
|
102
|
+
# end
|
103
|
+
end
|
104
|
+
|
105
|
+
end # MailboxUser
|
106
|
+
end # EWS
|
107
|
+
end # Viewpoint
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#############################################################################
|
2
|
+
# Copyright © 2010 Dan Wanek <dan.wanek@gmail.com>
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# This file is part of Viewpoint.
|
6
|
+
#
|
7
|
+
# Viewpoint is free software: you can redistribute it and/or
|
8
|
+
# modify it under the terms of the GNU General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or (at
|
10
|
+
# your option) any later version.
|
11
|
+
#
|
12
|
+
# Viewpoint is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
15
|
+
# Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License along
|
18
|
+
# with Viewpoint. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#############################################################################
|
20
|
+
|
21
|
+
module Viewpoint
|
22
|
+
module EWS
|
23
|
+
# Meeting cancellations have the exact same elements as a Meeting Message
|
24
|
+
# so MeetingCancellation is just a subclass of that.
|
25
|
+
class MeetingCancellation < MeetingMessage
|
26
|
+
end # MeetingCancellation
|
27
|
+
end # EWS
|
28
|
+
end # Viewpoint
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#############################################################################
|
2
|
-
# Copyright ©
|
2
|
+
# Copyright © 2010 Dan Wanek <dan.wanek@gmail.com>
|
3
3
|
#
|
4
4
|
#
|
5
5
|
# This file is part of Viewpoint.
|
@@ -17,18 +17,14 @@
|
|
17
17
|
# You should have received a copy of the GNU General Public License along
|
18
18
|
# with Viewpoint. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
#############################################################################
|
20
|
-
$:.unshift(File.dirname(__FILE__))
|
21
|
-
require 'viewpoint'
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
21
|
+
module Viewpoint
|
22
|
+
module EWS
|
23
|
+
class MeetingMessage < Item
|
28
24
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
25
|
+
def initialize(ews_item)
|
26
|
+
super(ews_item)
|
27
|
+
end
|
28
|
+
end # MeetingMessage
|
29
|
+
end # EWS
|
30
|
+
end # Viewpoint
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#############################################################################
|
2
|
+
# Copyright © 2010 Dan Wanek <dan.wanek@gmail.com>
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# This file is part of Viewpoint.
|
6
|
+
#
|
7
|
+
# Viewpoint is free software: you can redistribute it and/or
|
8
|
+
# modify it under the terms of the GNU General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or (at
|
10
|
+
# your option) any later version.
|
11
|
+
#
|
12
|
+
# Viewpoint is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
15
|
+
# Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License along
|
18
|
+
# with Viewpoint. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#############################################################################
|
20
|
+
|
21
|
+
module Viewpoint
|
22
|
+
module EWS
|
23
|
+
class MeetingRequest < Item
|
24
|
+
end # MeetingRequest
|
25
|
+
end # EWS
|
26
|
+
end # Viewpoint
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#############################################################################
|
2
|
+
# Copyright © 2010 Dan Wanek <dan.wanek@gmail.com>
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# This file is part of Viewpoint.
|
6
|
+
#
|
7
|
+
# Viewpoint is free software: you can redistribute it and/or
|
8
|
+
# modify it under the terms of the GNU General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or (at
|
10
|
+
# your option) any later version.
|
11
|
+
#
|
12
|
+
# Viewpoint is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
15
|
+
# Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License along
|
18
|
+
# with Viewpoint. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#############################################################################
|
20
|
+
|
21
|
+
module Viewpoint
|
22
|
+
module EWS
|
23
|
+
class MeetingResponse < Item
|
24
|
+
end # MeetingResponse
|
25
|
+
end # EWS
|
26
|
+
end # Viewpoint
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#############################################################################
|
2
|
+
# Copyright © 2010 Dan Wanek <dan.wanek@gmail.com>
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# This file is part of Viewpoint.
|
6
|
+
#
|
7
|
+
# Viewpoint is free software: you can redistribute it and/or
|
8
|
+
# modify it under the terms of the GNU General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or (at
|
10
|
+
# your option) any later version.
|
11
|
+
#
|
12
|
+
# Viewpoint is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
15
|
+
# Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License along
|
18
|
+
# with Viewpoint. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#############################################################################
|
20
|
+
|
21
|
+
module Viewpoint
|
22
|
+
module EWS
|
23
|
+
class Message < Item
|
24
|
+
|
25
|
+
# Send an E-mail message
|
26
|
+
#
|
27
|
+
# @param [String] subject The message subject
|
28
|
+
# @param [String] body The message body
|
29
|
+
# @param [Array] to_recipients An array of e-mail addresses to send to
|
30
|
+
# @param [Array] cc_recipients An array of e-mail addresses to send to
|
31
|
+
# @param [Array] bcc_recipients An array of e-mail addresses to send to
|
32
|
+
# @return [true] Returns true on successful send or it raises an error with
|
33
|
+
# a message stating why the e-mail could not be sent.
|
34
|
+
def self.send(subject, body, to_recipients, cc_recipients=[], bcc_recipients=[])
|
35
|
+
item = {}
|
36
|
+
item[:subject] = {:text => subject}
|
37
|
+
item[:body] = {:text => body, :body_type => 'Text'} unless body.nil?
|
38
|
+
to_recipients.each do |a|
|
39
|
+
item[:to_recipients] = [] unless item[:to_recipients].is_a?(Array)
|
40
|
+
item[:to_recipients] << {:mailbox => {:email_address => {:text => a}}}
|
41
|
+
end
|
42
|
+
cc_recipients.each do |a|
|
43
|
+
item[:cc_recipients] = [] unless item[:cc_recipients].is_a?(Array)
|
44
|
+
item[:cc_recipients] << {:mailbox => {:email_address => {:text => a}}}
|
45
|
+
end
|
46
|
+
bcc_recipients.each do |a|
|
47
|
+
item[:bcc_recipients] = [] unless item[:bcc_recipients].is_a?(Array)
|
48
|
+
item[:bcc_recipients] << {:mailbox => {:email_address => {:text => a}}}
|
49
|
+
end
|
50
|
+
|
51
|
+
conn = Viewpoint::EWS::EWS.instance
|
52
|
+
resp = conn.ews.create_message_item(:sentitems, item, 'SendAndSaveCopy')
|
53
|
+
(resp.status == 'Success') || (raise EwsError, "Could not retrieve item. #{resp.code}: #{resp.message}")
|
54
|
+
end
|
55
|
+
|
56
|
+
# Initialize an Exchange Web Services item of type Message
|
57
|
+
def initialize(ews_item)
|
58
|
+
super(ews_item)
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def init_methods
|
64
|
+
super()
|
65
|
+
define_str_var :conversation_index, :conversation_topic, :internet_message_id, :references
|
66
|
+
define_mbox_users :to_recipients, :cc_recipients, :bcc_recipients, :reply_to
|
67
|
+
define_mbox_user :from, :sender, :received_by, :received_representing
|
68
|
+
define_bool_var :is_read, :is_read_receipt_requested, :is_response_requested, :is_delivery_receipt_requested
|
69
|
+
end
|
70
|
+
|
71
|
+
end # Message
|
72
|
+
end # EWS
|
73
|
+
end # Viewpoint
|
data/lib/model/model.rb
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
#############################################################################
|
2
|
+
# Copyright © 2010 Dan Wanek <dan.wanek@gmail.com>
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# This file is part of Viewpoint.
|
6
|
+
#
|
7
|
+
# Viewpoint is free software: you can redistribute it and/or
|
8
|
+
# modify it under the terms of the GNU General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or (at
|
10
|
+
# your option) any later version.
|
11
|
+
#
|
12
|
+
# Viewpoint is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
15
|
+
# Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License along
|
18
|
+
# with Viewpoint. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#############################################################################
|
20
|
+
|
21
|
+
|
22
|
+
# This class is inherited by all Item subtypes such as Message, Event,
|
23
|
+
# and Task. It will serve as the brain for all of the methods that
|
24
|
+
# each of these Item types have in common.
|
25
|
+
module Viewpoint
|
26
|
+
module EWS
|
27
|
+
# This is the base model Module for shared code among all Model classes.
|
28
|
+
# @attr_reader [Array] :ews_methods The EWS methods created for this Model.
|
29
|
+
module Model
|
30
|
+
|
31
|
+
# These are convenience methods to quickly create instance methods for
|
32
|
+
# the various Model types when passed a Hash from the SOAP parser.
|
33
|
+
# These functions depend on each model type saving the passed Hash
|
34
|
+
# in an instance variable called @ews_item.
|
35
|
+
|
36
|
+
attr_reader :ews_methods, :ews_methods_undef
|
37
|
+
|
38
|
+
def initialize
|
39
|
+
# Defined EWS methods
|
40
|
+
@ews_methods = []
|
41
|
+
# Undefined EWS methods
|
42
|
+
@ews_methods_undef = []
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def define_str_var(*vars)
|
48
|
+
vars.each do |var|
|
49
|
+
if(@ews_item[var])
|
50
|
+
@ews_methods << var
|
51
|
+
self.instance_eval <<-EOF
|
52
|
+
def #{var.to_s}
|
53
|
+
@ews_item[:#{var}][:text]
|
54
|
+
end
|
55
|
+
EOF
|
56
|
+
else
|
57
|
+
@ews_methods_undef << var
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def define_int_var(*vars)
|
63
|
+
vars.each do |var|
|
64
|
+
if(@ews_item[var])
|
65
|
+
@ews_methods << var
|
66
|
+
self.instance_eval <<-EOF
|
67
|
+
def #{var}
|
68
|
+
@#{var} ||= @ews_item[:#{var}][:text].to_i
|
69
|
+
end
|
70
|
+
EOF
|
71
|
+
else
|
72
|
+
@ews_methods_undef << var
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def define_bool_var(*vars)
|
78
|
+
vars.each do |var|
|
79
|
+
if(@ews_item[var])
|
80
|
+
@ews_methods << "#{var}?".to_sym
|
81
|
+
self.instance_eval <<-EOF
|
82
|
+
def #{var}?
|
83
|
+
@#{var} ||= (@ews_item[:#{var}][:text] == 'true') ? true : false
|
84
|
+
end
|
85
|
+
EOF
|
86
|
+
else
|
87
|
+
@ews_methods_undef << "#{var}?".to_sym
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def define_datetime_var(*vars)
|
93
|
+
vars.each do |var|
|
94
|
+
if(@ews_item[var])
|
95
|
+
@ews_methods << var
|
96
|
+
self.instance_eval <<-EOF
|
97
|
+
def #{var}
|
98
|
+
@#{var} ||= DateTime.parse(@ews_item[:#{var}][:text])
|
99
|
+
end
|
100
|
+
EOF
|
101
|
+
else
|
102
|
+
@ews_methods_undef << var
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def define_mbox_users(*vars)
|
108
|
+
vars.each do |var|
|
109
|
+
if(@ews_item[var])
|
110
|
+
@ews_methods << var
|
111
|
+
self.instance_eval <<-EOF
|
112
|
+
def #{var}
|
113
|
+
return @#{var} if defined?(@#{var})
|
114
|
+
if( (@ews_item[:#{var}][:mailbox]).is_a?(Hash) )
|
115
|
+
@#{var} = [MailboxUser.new(@ews_item[:#{var}][:mailbox])]
|
116
|
+
elsif( (@ews_item[:#{var}][:mailbox]).is_a?(Array) )
|
117
|
+
@#{var} = []
|
118
|
+
@ews_item[:#{var}][:mailbox].each do |i|
|
119
|
+
@#{var} << MailboxUser.new(i)
|
120
|
+
end
|
121
|
+
else
|
122
|
+
raise EwsError, "Bad value for mailbox: " + @ews_item[:#{var}][:mailbox]
|
123
|
+
end
|
124
|
+
@#{var}
|
125
|
+
end
|
126
|
+
EOF
|
127
|
+
else
|
128
|
+
@ews_methods_undef << var
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def define_mbox_user(*vars)
|
134
|
+
vars.each do |var|
|
135
|
+
if(@ews_item[var])
|
136
|
+
@ews_methods << var
|
137
|
+
self.instance_eval <<-EOF
|
138
|
+
def #{var}
|
139
|
+
@#{var} ||= MailboxUser.new(@ews_item[:#{var}][:mailbox])
|
140
|
+
end
|
141
|
+
EOF
|
142
|
+
else
|
143
|
+
@ews_methods_undef << var
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# After a delete is called on an object this method will clear
|
149
|
+
# out all of the defined EWS methods so they can't be called on the
|
150
|
+
# instantiated object.
|
151
|
+
def clear_object!
|
152
|
+
@ews_methods.each do |m|
|
153
|
+
self.instance_variables.each do |iv|
|
154
|
+
self.instance_variable_set("#{iv}",nil)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
end # Model
|
160
|
+
end # EWS
|
161
|
+
end # Viewpoint
|