tilia-vobject 4.0.0.pre.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rubocop.yml +32 -0
- data/.simplecov +4 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.sabre.md +626 -0
- data/CONTRIBUTING.md +25 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +68 -0
- data/LICENSE +27 -0
- data/LICENSE.sabre +27 -0
- data/README.md +63 -0
- data/Rakefile +17 -0
- data/bin/vobject +7 -0
- data/lib/tilia/v_object/birthday_calendar_generator.rb +142 -0
- data/lib/tilia/v_object/cli.rb +582 -0
- data/lib/tilia/v_object/component/available.rb +107 -0
- data/lib/tilia/v_object/component/v_alarm.rb +114 -0
- data/lib/tilia/v_object/component/v_availability.rb +128 -0
- data/lib/tilia/v_object/component/v_calendar.rb +468 -0
- data/lib/tilia/v_object/component/v_card.rb +457 -0
- data/lib/tilia/v_object/component/v_event.rb +127 -0
- data/lib/tilia/v_object/component/v_free_busy.rb +81 -0
- data/lib/tilia/v_object/component/v_journal.rb +75 -0
- data/lib/tilia/v_object/component/v_time_zone.rb +51 -0
- data/lib/tilia/v_object/component/v_todo.rb +147 -0
- data/lib/tilia/v_object/component.rb +591 -0
- data/lib/tilia/v_object/date_time_parser.rb +486 -0
- data/lib/tilia/v_object/document.rb +218 -0
- data/lib/tilia/v_object/element_list.rb +18 -0
- data/lib/tilia/v_object/eof_exception.rb +8 -0
- data/lib/tilia/v_object/free_busy_data.rb +149 -0
- data/lib/tilia/v_object/free_busy_generator.rb +465 -0
- data/lib/tilia/v_object/i_tip/broker.rb +909 -0
- data/lib/tilia/v_object/i_tip/i_tip_exception.rb +9 -0
- data/lib/tilia/v_object/i_tip/message.rb +109 -0
- data/lib/tilia/v_object/i_tip/same_organizer_for_all_components_exception.rb +13 -0
- data/lib/tilia/v_object/i_tip.rb +10 -0
- data/lib/tilia/v_object/node.rb +192 -0
- data/lib/tilia/v_object/parameter.rb +327 -0
- data/lib/tilia/v_object/parse_exception.rb +7 -0
- data/lib/tilia/v_object/parser/json.rb +149 -0
- data/lib/tilia/v_object/parser/mime_dir.rb +543 -0
- data/lib/tilia/v_object/parser/parser.rb +61 -0
- data/lib/tilia/v_object/parser/xml/element/key_value.rb +60 -0
- data/lib/tilia/v_object/parser/xml/element.rb +11 -0
- data/lib/tilia/v_object/parser/xml.rb +322 -0
- data/lib/tilia/v_object/parser.rb +10 -0
- data/lib/tilia/v_object/property/binary.rb +96 -0
- data/lib/tilia/v_object/property/boolean.rb +57 -0
- data/lib/tilia/v_object/property/flat_text.rb +52 -0
- data/lib/tilia/v_object/property/float_value.rb +107 -0
- data/lib/tilia/v_object/property/i_calendar/cal_address.rb +49 -0
- data/lib/tilia/v_object/property/i_calendar/date.rb +15 -0
- data/lib/tilia/v_object/property/i_calendar/date_time.rb +330 -0
- data/lib/tilia/v_object/property/i_calendar/duration.rb +65 -0
- data/lib/tilia/v_object/property/i_calendar/period.rb +124 -0
- data/lib/tilia/v_object/property/i_calendar/recur.rb +173 -0
- data/lib/tilia/v_object/property/i_calendar.rb +14 -0
- data/lib/tilia/v_object/property/integer_value.rb +60 -0
- data/lib/tilia/v_object/property/text.rb +352 -0
- data/lib/tilia/v_object/property/time.rb +85 -0
- data/lib/tilia/v_object/property/unknown.rb +30 -0
- data/lib/tilia/v_object/property/uri.rb +78 -0
- data/lib/tilia/v_object/property/utc_offset.rb +56 -0
- data/lib/tilia/v_object/property/v_card/date.rb +31 -0
- data/lib/tilia/v_object/property/v_card/date_and_or_time.rb +343 -0
- data/lib/tilia/v_object/property/v_card/date_time.rb +22 -0
- data/lib/tilia/v_object/property/v_card/language_tag.rb +41 -0
- data/lib/tilia/v_object/property/v_card/time_stamp.rb +74 -0
- data/lib/tilia/v_object/property/v_card.rb +13 -0
- data/lib/tilia/v_object/property.rb +532 -0
- data/lib/tilia/v_object/reader.rb +73 -0
- data/lib/tilia/v_object/recur/event_iterator.rb +417 -0
- data/lib/tilia/v_object/recur/no_instances_exception.rb +11 -0
- data/lib/tilia/v_object/recur/r_date_iterator.rb +138 -0
- data/lib/tilia/v_object/recur/r_rule_iterator.rb +717 -0
- data/lib/tilia/v_object/recur.rb +10 -0
- data/lib/tilia/v_object/settings.rb +32 -0
- data/lib/tilia/v_object/splitter/i_calendar.rb +95 -0
- data/lib/tilia/v_object/splitter/splitter_interface.rb +31 -0
- data/lib/tilia/v_object/splitter/v_card.rb +56 -0
- data/lib/tilia/v_object/splitter.rb +9 -0
- data/lib/tilia/v_object/string_util.rb +58 -0
- data/lib/tilia/v_object/time_zone_data/exchange_zones.rb +96 -0
- data/lib/tilia/v_object/time_zone_data/lotus_zones.rb +104 -0
- data/lib/tilia/v_object/time_zone_data/php_zones.rb +49 -0
- data/lib/tilia/v_object/time_zone_data/windows_zones.rb +121 -0
- data/lib/tilia/v_object/time_zone_data.rb +10 -0
- data/lib/tilia/v_object/time_zone_util.rb +213 -0
- data/lib/tilia/v_object/uuid_util.rb +51 -0
- data/lib/tilia/v_object/v_card_converter.rb +354 -0
- data/lib/tilia/v_object/version.rb +9 -0
- data/lib/tilia/v_object/writer.rb +56 -0
- data/lib/tilia/v_object.rb +45 -0
- data/lib/tilia/vobject.rb +1 -0
- data/resources/schema/xcal.rng +1192 -0
- data/resources/schema/xcard.rng +388 -0
- data/test/test_helper.rb +56 -0
- data/test/v_object/attach_issue_test.rb +19 -0
- data/test/v_object/birthday_calendar_generator_test.rb +463 -0
- data/test/v_object/cli_mock.rb +19 -0
- data/test/v_object/cli_test.rb +460 -0
- data/test/v_object/component/available_test.rb +59 -0
- data/test/v_object/component/v_alarm_test.rb +160 -0
- data/test/v_object/component/v_availability_test.rb +388 -0
- data/test/v_object/component/v_calendar_test.rb +646 -0
- data/test/v_object/component/v_card_test.rb +258 -0
- data/test/v_object/component/v_event_test.rb +85 -0
- data/test/v_object/component/v_free_busy_test.rb +59 -0
- data/test/v_object/component/v_journal_test.rb +85 -0
- data/test/v_object/component/v_time_zone_test.rb +47 -0
- data/test/v_object/component/v_todo_test.rb +172 -0
- data/test/v_object/component_test.rb +419 -0
- data/test/v_object/date_time_parser_test.rb +526 -0
- data/test/v_object/document_test.rb +71 -0
- data/test/v_object/element_list_test.rb +27 -0
- data/test/v_object/em_client_test.rb +53 -0
- data/test/v_object/empty_parameter_test.rb +65 -0
- data/test/v_object/empty_value_issue_test.rb +25 -0
- data/test/v_object/fake_component.rb +21 -0
- data/test/v_object/free_busy_data_test.rb +285 -0
- data/test/v_object/free_busy_generator_test.rb +637 -0
- data/test/v_object/google_colon_escaping_test.rb +27 -0
- data/test/v_object/i_calendar/attach_parse_test.rb +24 -0
- data/test/v_object/i_tip/broker_attendee_reply_test.rb +1042 -0
- data/test/v_object/i_tip/broker_delete_event_test.rb +175 -0
- data/test/v_object/i_tip/broker_new_event_test.rb +440 -0
- data/test/v_object/i_tip/broker_process_message_test.rb +153 -0
- data/test/v_object/i_tip/broker_process_reply_test.rb +402 -0
- data/test/v_object/i_tip/broker_tester.rb +71 -0
- data/test/v_object/i_tip/broker_update_event_test.rb +763 -0
- data/test/v_object/i_tip/evolution_test.rb +2644 -0
- data/test/v_object/i_tip/message_test.rb +25 -0
- data/test/v_object/issue153.vcf +352 -0
- data/test/v_object/issue153_test.rb +12 -0
- data/test/v_object/issue26_test.rb +25 -0
- data/test/v_object/issue36_work_around_test.rb +37 -0
- data/test/v_object/issue40_test.rb +26 -0
- data/test/v_object/issue64.vcf +351 -0
- data/test/v_object/issue64_test.rb +17 -0
- data/test/v_object/issue96_test.rb +22 -0
- data/test/v_object/issue_undefined_index_test.rb +24 -0
- data/test/v_object/j_cal_test.rb +150 -0
- data/test/v_object/j_card_test.rb +192 -0
- data/test/v_object/line_folding_issue_test.rb +19 -0
- data/test/v_object/mock_document.rb +6 -0
- data/test/v_object/parameter_test.rb +109 -0
- data/test/v_object/parser/json_test.rb +370 -0
- data/test/v_object/parser/mime_dir_test.rb +14 -0
- data/test/v_object/parser/quoted_printable_test.rb +78 -0
- data/test/v_object/parser/xml_test.rb +2563 -0
- data/test/v_object/property/binary_test.rb +12 -0
- data/test/v_object/property/boolean_test.rb +18 -0
- data/test/v_object/property/compound_test.rb +43 -0
- data/test/v_object/property/float_test.rb +20 -0
- data/test/v_object/property/i_calendar/cal_address_test.rb +26 -0
- data/test/v_object/property/i_calendar/date_time_test.rb +303 -0
- data/test/v_object/property/i_calendar/duration_test.rb +14 -0
- data/test/v_object/property/i_calendar/recur_test.rb +39 -0
- data/test/v_object/property/text_test.rb +81 -0
- data/test/v_object/property/v_card/date_and_or_time_test.rb +205 -0
- data/test/v_object/property/v_card/language_tag_test.rb +35 -0
- data/test/v_object/property_test.rb +338 -0
- data/test/v_object/reader_test.rb +403 -0
- data/test/v_object/recur/event_iterator/by_month_in_daily_test.rb +52 -0
- data/test/v_object/recur/event_iterator/by_set_pos_hang_test.rb +55 -0
- data/test/v_object/recur/event_iterator/expand_floating_times_test.rb +109 -0
- data/test/v_object/recur/event_iterator/fifth_tuesday_problem_test.rb +45 -0
- data/test/v_object/recur/event_iterator/incorrect_expand_test.rb +53 -0
- data/test/v_object/recur/event_iterator/infinite_loop_problem_test.rb +75 -0
- data/test/v_object/recur/event_iterator/issue48_test.rb +43 -0
- data/test/v_object/recur/event_iterator/issue50_test.rb +123 -0
- data/test/v_object/recur/event_iterator/main_test.rb +1222 -0
- data/test/v_object/recur/event_iterator/missing_overridden_test.rb +55 -0
- data/test/v_object/recur/event_iterator/no_instances_test.rb +32 -0
- data/test/v_object/recur/event_iterator/override_first_event_test.rb +106 -0
- data/test/v_object/recur/r_date_iterator_test.rb +44 -0
- data/test/v_object/recur/r_rule_iterator_test.rb +608 -0
- data/test/v_object/recurrence_iterator/UntilRespectsTimezoneTest.ics +39 -0
- data/test/v_object/slash_r_test.rb +15 -0
- data/test/v_object/splitter/i_calendar_test.rb +299 -0
- data/test/v_object/splitter/v_card_test.rb +173 -0
- data/test/v_object/string_util_test.rb +37 -0
- data/test/v_object/test_case.rb +42 -0
- data/test/v_object/time_zone_util_test.rb +271 -0
- data/test/v_object/uuid_util_test.rb +18 -0
- data/test/v_object/v_card21_test.rb +43 -0
- data/test/v_object/v_card_converter_test.rb +419 -0
- data/test/v_object/version_test.rb +15 -0
- data/test/v_object/writer_test.rb +33 -0
- data/tilia-vobject.gemspec +17 -0
- metadata +308 -0
@@ -0,0 +1,457 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Component
|
4
|
+
# The VCard component.
|
5
|
+
#
|
6
|
+
# This component represents the BEGIN:VCARD and END:VCARD found in every
|
7
|
+
# vcard.
|
8
|
+
class VCard < Document
|
9
|
+
# The default name for this component.
|
10
|
+
#
|
11
|
+
# This should be 'VCALENDAR' or 'VCARD'.
|
12
|
+
#
|
13
|
+
# @var string
|
14
|
+
@default_name = 'VCARD'
|
15
|
+
|
16
|
+
# Caching the version number.
|
17
|
+
#
|
18
|
+
# @var int
|
19
|
+
# RUBY: attr_accessor :version
|
20
|
+
|
21
|
+
# List of value-types, and which classes they map to.
|
22
|
+
#
|
23
|
+
# @var array
|
24
|
+
@value_map = {
|
25
|
+
'BINARY' => Property::Binary,
|
26
|
+
'BOOLEAN' => Property::Boolean,
|
27
|
+
'CONTENT-ID' => Property::FlatText, # vCard 2.1 only
|
28
|
+
'DATE' => Property::VCard::Date,
|
29
|
+
'DATE-TIME' => Property::VCard::DateTime,
|
30
|
+
'DATE-AND-OR-TIME' => Property::VCard::DateAndOrTime, # vCard only
|
31
|
+
'FLOAT' => Property::FloatValue,
|
32
|
+
'INTEGER' => Property::IntegerValue,
|
33
|
+
'LANGUAGE-TAG' => Property::VCard::LanguageTag,
|
34
|
+
'TIMESTAMP' => Property::VCard::TimeStamp,
|
35
|
+
'TEXT' => Property::Text,
|
36
|
+
'TIME' => Property::Time,
|
37
|
+
'UNKNOWN' => Property::Unknown, # jCard / jCal-only.
|
38
|
+
'URI' => Property::Uri,
|
39
|
+
'URL' => Property::Uri, # vCard 2.1 only
|
40
|
+
'UTC-OFFSET' => Property::UtcOffset
|
41
|
+
}
|
42
|
+
|
43
|
+
# List of properties, and which classes they map to.
|
44
|
+
#
|
45
|
+
# @var array
|
46
|
+
@property_map = {
|
47
|
+
# vCard 2.1 properties and up
|
48
|
+
'N' => Property::Text,
|
49
|
+
'FN' => Property::FlatText,
|
50
|
+
'PHOTO' => Property::Binary,
|
51
|
+
'BDAY' => Property::VCard::DateAndOrTime,
|
52
|
+
'ADR' => Property::Text,
|
53
|
+
'LABEL' => Property::FlatText, # Removed in vCard 4.0
|
54
|
+
'TEL' => Property::FlatText,
|
55
|
+
'EMAIL' => Property::FlatText,
|
56
|
+
'MAILER' => Property::FlatText, # Removed in vCard 4.0
|
57
|
+
'GEO' => Property::FlatText,
|
58
|
+
'TITLE' => Property::FlatText,
|
59
|
+
'ROLE' => Property::FlatText,
|
60
|
+
'LOGO' => Property::Binary,
|
61
|
+
# 'AGENT' => Property::, // Todo: is an embedded vCard. Probably rare, so
|
62
|
+
# not supported at the moment
|
63
|
+
'ORG' => Property::Text,
|
64
|
+
'NOTE' => Property::FlatText,
|
65
|
+
'REV' => Property::VCard::TimeStamp,
|
66
|
+
'SOUND' => Property::FlatText,
|
67
|
+
'URL' => Property::Uri,
|
68
|
+
'UID' => Property::FlatText,
|
69
|
+
'VERSION' => Property::FlatText,
|
70
|
+
'KEY' => Property::FlatText,
|
71
|
+
'TZ' => Property::Text,
|
72
|
+
|
73
|
+
# vCard 3.0 properties
|
74
|
+
'CATEGORIES' => Property::Text,
|
75
|
+
'SORT-STRING' => Property::FlatText,
|
76
|
+
'PRODID' => Property::FlatText,
|
77
|
+
'NICKNAME' => Property::Text,
|
78
|
+
'CLASS' => Property::FlatText, # Removed in vCard 4.0
|
79
|
+
|
80
|
+
# rfc2739 properties
|
81
|
+
'FBURL' => Property::Uri,
|
82
|
+
'CAPURI' => Property::Uri,
|
83
|
+
'CALURI' => Property::Uri,
|
84
|
+
'CALADRURI' => Property::Uri,
|
85
|
+
|
86
|
+
# rfc4770 properties
|
87
|
+
'IMPP' => Property::Uri,
|
88
|
+
|
89
|
+
# vCard 4.0 properties
|
90
|
+
'SOURCE' => Property::Uri,
|
91
|
+
'XML' => Property::FlatText,
|
92
|
+
'ANNIVERSARY' => Property::VCard::DateAndOrTime,
|
93
|
+
'CLIENTPIDMAP' => Property::Text,
|
94
|
+
'LANG' => Property::VCard::LanguageTag,
|
95
|
+
'GENDER' => Property::Text,
|
96
|
+
'KIND' => Property::FlatText,
|
97
|
+
'MEMBER' => Property::Uri,
|
98
|
+
'RELATED' => Property::Uri,
|
99
|
+
|
100
|
+
# rfc6474 properties
|
101
|
+
'BIRTHPLACE' => Property::FlatText,
|
102
|
+
'DEATHPLACE' => Property::FlatText,
|
103
|
+
'DEATHDATE' => Property::VCard::DateAndOrTime,
|
104
|
+
|
105
|
+
# rfc6715 properties
|
106
|
+
'EXPERTISE' => Property::FlatText,
|
107
|
+
'HOBBY' => Property::FlatText,
|
108
|
+
'INTEREST' => Property::FlatText,
|
109
|
+
'ORG-DIRECTORY' => Property::FlatText
|
110
|
+
}
|
111
|
+
|
112
|
+
@component_map = {}
|
113
|
+
|
114
|
+
# Returns the current document type.
|
115
|
+
#
|
116
|
+
# @return int
|
117
|
+
def document_type
|
118
|
+
unless @version
|
119
|
+
version = self['VERSION'].to_s
|
120
|
+
|
121
|
+
case version
|
122
|
+
when '2.1'
|
123
|
+
@version = self.class::VCARD21
|
124
|
+
when '3.0'
|
125
|
+
@version = self.class::VCARD30
|
126
|
+
when '4.0'
|
127
|
+
@version = self.class::VCARD40
|
128
|
+
else
|
129
|
+
@version = self.class::UNKNOWN
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
@version
|
134
|
+
end
|
135
|
+
|
136
|
+
# Converts the document to a different vcard version.
|
137
|
+
#
|
138
|
+
# Use one of the VCARD constants for the target. This method will return
|
139
|
+
# a copy of the vcard in the new version.
|
140
|
+
#
|
141
|
+
# At the moment the only supported conversion is from 3.0 to 4.0.
|
142
|
+
#
|
143
|
+
# If input and output version are identical, a clone is returned.
|
144
|
+
#
|
145
|
+
# @param int target
|
146
|
+
#
|
147
|
+
# @return VCard
|
148
|
+
def convert(target)
|
149
|
+
converter = VCardConverter.new
|
150
|
+
converter.convert(self, target)
|
151
|
+
end
|
152
|
+
|
153
|
+
# VCards with version 2.1, 3.0 and 4.0 are found.
|
154
|
+
#
|
155
|
+
# If the VCARD doesn't know its version, 2.1 is assumed.
|
156
|
+
DEFAULT_VERSION ||= VCARD21
|
157
|
+
|
158
|
+
# Validates the node for correctness.
|
159
|
+
#
|
160
|
+
# The following options are supported:
|
161
|
+
# Node::REPAIR - May attempt to automatically repair the problem.
|
162
|
+
#
|
163
|
+
# This method returns an array with detected problems.
|
164
|
+
# Every element has the following properties:
|
165
|
+
#
|
166
|
+
# * level - problem level.
|
167
|
+
# * message - A human-readable string describing the issue.
|
168
|
+
# * node - A reference to the problematic node.
|
169
|
+
#
|
170
|
+
# The level means:
|
171
|
+
# 1 - The issue was repaired (only happens if REPAIR was turned on)
|
172
|
+
# 2 - An inconsequential issue
|
173
|
+
# 3 - A severe issue.
|
174
|
+
#
|
175
|
+
# @param int options
|
176
|
+
#
|
177
|
+
# @return array
|
178
|
+
def validate(options = 0)
|
179
|
+
warnings = []
|
180
|
+
|
181
|
+
version_map = {
|
182
|
+
self.class::VCARD21 => '2.1',
|
183
|
+
self.class::VCARD30 => '3.0',
|
184
|
+
self.class::VCARD40 => '4.0'
|
185
|
+
}
|
186
|
+
|
187
|
+
version = select('VERSION')
|
188
|
+
if version.size == 1
|
189
|
+
version = self['VERSION'].to_s
|
190
|
+
unless ['2.1', '3.0', '4.0'].include?(version)
|
191
|
+
warnings << {
|
192
|
+
'level' => 3,
|
193
|
+
'message' => 'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.',
|
194
|
+
'node' => self
|
195
|
+
}
|
196
|
+
if options & self.class::REPAIR > 0
|
197
|
+
self['VERSION'] = version_map[self.class::DEFAULT_VERSION]
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
if version == '2.1' && options & self.class::PROFILE_CARDDAV > 0
|
202
|
+
warnings << {
|
203
|
+
'level' => 3,
|
204
|
+
'message' => 'CardDAV servers are not allowed to accept vCard 2.1.',
|
205
|
+
'node' => self
|
206
|
+
}
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
uid = select('UID')
|
211
|
+
if uid.size == 0
|
212
|
+
if options & self.class::PROFILE_CARDDAV > 0
|
213
|
+
# Required for CardDAV
|
214
|
+
warning_level = 3
|
215
|
+
message = 'vCards on CardDAV servers MUST have a UID property.'
|
216
|
+
else
|
217
|
+
# Not required for regular vcards
|
218
|
+
warning_level = 2
|
219
|
+
message = 'Adding a UID to a vCard property is recommended.'
|
220
|
+
end
|
221
|
+
|
222
|
+
if options & self.class::REPAIR > 0
|
223
|
+
self['UID'] = UuidUtil.uuid
|
224
|
+
warning_level = 1
|
225
|
+
end
|
226
|
+
|
227
|
+
warnings << {
|
228
|
+
'level' => warning_level,
|
229
|
+
'message' => message,
|
230
|
+
'node' => self
|
231
|
+
}
|
232
|
+
end
|
233
|
+
|
234
|
+
fn = select('FN')
|
235
|
+
if fn.size != 1
|
236
|
+
repaired = false
|
237
|
+
|
238
|
+
if options & self.class::REPAIR > 0 && fn.size == 0
|
239
|
+
# We're going to try to see if we can use the contents of the
|
240
|
+
# N property.
|
241
|
+
if key?('N')
|
242
|
+
value = self['N'].to_s.split(';')
|
243
|
+
if value[1]
|
244
|
+
self['FN'] = value[1] + ' ' + value[0]
|
245
|
+
else
|
246
|
+
self['FN'] = value[0]
|
247
|
+
end
|
248
|
+
|
249
|
+
repaired = true
|
250
|
+
|
251
|
+
# Otherwise, the ORG property may work
|
252
|
+
elsif key?('ORG')
|
253
|
+
self['FN'] = self['ORG'].to_s
|
254
|
+
repaired = true
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
warnings << {
|
259
|
+
'level' => repaired ? 1 : 3,
|
260
|
+
'message' => 'The FN property must appear in the VCARD component exactly 1 time',
|
261
|
+
'node' => self
|
262
|
+
}
|
263
|
+
end
|
264
|
+
|
265
|
+
w = super(options)
|
266
|
+
w.concat warnings
|
267
|
+
|
268
|
+
w
|
269
|
+
end
|
270
|
+
|
271
|
+
# A simple list of validation rules.
|
272
|
+
#
|
273
|
+
# This is simply a list of properties, and how many times they either
|
274
|
+
# must or must not appear.
|
275
|
+
#
|
276
|
+
# Possible values per property:
|
277
|
+
# * 0 - Must not appear.
|
278
|
+
# * 1 - Must appear exactly once.
|
279
|
+
# * + - Must appear at least once.
|
280
|
+
# * * - Can appear any number of times.
|
281
|
+
# * ? - May appear, but not more than once.
|
282
|
+
#
|
283
|
+
# @var array
|
284
|
+
def validation_rules
|
285
|
+
{
|
286
|
+
'ADR' => '*',
|
287
|
+
'ANNIVERSARY' => '?',
|
288
|
+
'BDAY' => '?',
|
289
|
+
'CALADRURI' => '*',
|
290
|
+
'CALURI' => '*',
|
291
|
+
'CATEGORIES' => '*',
|
292
|
+
'CLIENTPIDMAP' => '*',
|
293
|
+
'EMAIL' => '*',
|
294
|
+
'FBURL' => '*',
|
295
|
+
'IMPP' => '*',
|
296
|
+
'GENDER' => '?',
|
297
|
+
'GEO' => '*',
|
298
|
+
'KEY' => '*',
|
299
|
+
'KIND' => '?',
|
300
|
+
'LANG' => '*',
|
301
|
+
'LOGO' => '*',
|
302
|
+
'MEMBER' => '*',
|
303
|
+
'N' => '?',
|
304
|
+
'NICKNAME' => '*',
|
305
|
+
'NOTE' => '*',
|
306
|
+
'ORG' => '*',
|
307
|
+
'PHOTO' => '*',
|
308
|
+
'PRODID' => '?',
|
309
|
+
'RELATED' => '*',
|
310
|
+
'REV' => '?',
|
311
|
+
'ROLE' => '*',
|
312
|
+
'SOUND' => '*',
|
313
|
+
'SOURCE' => '*',
|
314
|
+
'TEL' => '*',
|
315
|
+
'TITLE' => '*',
|
316
|
+
'TZ' => '*',
|
317
|
+
'URL' => '*',
|
318
|
+
'VERSION' => '1',
|
319
|
+
'XML' => '*',
|
320
|
+
|
321
|
+
# FN is commented out, because it's already handled by the
|
322
|
+
# validate function, which may also try to repair it.
|
323
|
+
# 'FN' => '+',
|
324
|
+
'UID' => '?'
|
325
|
+
}
|
326
|
+
end
|
327
|
+
|
328
|
+
# Returns a preferred field.
|
329
|
+
#
|
330
|
+
# VCards can indicate wether a field such as ADR, TEL or EMAIL is
|
331
|
+
# preferred by specifying TYPE=PREF (vcard 2.1, 3) or PREF=x (vcard 4, x
|
332
|
+
# being a number between 1 and 100).
|
333
|
+
#
|
334
|
+
# If neither of those parameters are specified, the first is returned, if
|
335
|
+
# a field with that name does not exist, null is returned.
|
336
|
+
#
|
337
|
+
# @param string field_name
|
338
|
+
#
|
339
|
+
# @return VObject\Property|null
|
340
|
+
def preferred(property_name)
|
341
|
+
preferred = nil
|
342
|
+
last_pref = 101
|
343
|
+
select(property_name).each do |field|
|
344
|
+
pref = 101
|
345
|
+
|
346
|
+
if field.key?('TYPE') && field['TYPE'].has('PREF')
|
347
|
+
pref = 1
|
348
|
+
elsif field.key?('PREF')
|
349
|
+
pref = field['PREF'].value.to_i
|
350
|
+
end
|
351
|
+
|
352
|
+
if pref < last_pref || preferred.nil?
|
353
|
+
preferred = field
|
354
|
+
last_pref = pref
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
preferred
|
359
|
+
end
|
360
|
+
|
361
|
+
protected
|
362
|
+
|
363
|
+
# This method should return a list of default property values.
|
364
|
+
#
|
365
|
+
# @return array
|
366
|
+
def defaults
|
367
|
+
{
|
368
|
+
'VERSION' => '3.0',
|
369
|
+
'PRODID' => "-//Tilia//Tilia VObject #{Version::VERSION}//EN"
|
370
|
+
}
|
371
|
+
end
|
372
|
+
|
373
|
+
public
|
374
|
+
|
375
|
+
# This method returns an array, with the representation as it should be
|
376
|
+
# encoded in json. This is used to create jCard or jCal documents.
|
377
|
+
#
|
378
|
+
# @return array
|
379
|
+
def json_serialize
|
380
|
+
# A vcard does not have sub-components, so we're overriding this
|
381
|
+
# method to remove that array element.
|
382
|
+
properties = []
|
383
|
+
|
384
|
+
children.each do |child|
|
385
|
+
properties << child.json_serialize
|
386
|
+
end
|
387
|
+
|
388
|
+
[@name.downcase, properties]
|
389
|
+
end
|
390
|
+
|
391
|
+
# This method serializes the data into XML. This is used to create xCard or
|
392
|
+
# xCal documents.
|
393
|
+
#
|
394
|
+
# @param Xml\Writer writer XML writer.
|
395
|
+
#
|
396
|
+
# @return void
|
397
|
+
def xml_serialize(writer)
|
398
|
+
properties_by_group = {}
|
399
|
+
|
400
|
+
children.each do |property|
|
401
|
+
group = property.group
|
402
|
+
|
403
|
+
properties_by_group[group] = [] unless properties_by_group[group]
|
404
|
+
properties_by_group[group] << property
|
405
|
+
end
|
406
|
+
|
407
|
+
writer.start_element(@name.downcase)
|
408
|
+
|
409
|
+
properties_by_group.each do |group, properties|
|
410
|
+
unless group.blank?
|
411
|
+
writer.start_element('group')
|
412
|
+
writer.write_attribute('name', group.downcase)
|
413
|
+
end
|
414
|
+
|
415
|
+
properties.each do |property|
|
416
|
+
case property.name
|
417
|
+
when 'VERSION'
|
418
|
+
next
|
419
|
+
when 'XML'
|
420
|
+
value = property.parts
|
421
|
+
fragment = Tilia::Xml::Element::XmlFragment.new(value[0])
|
422
|
+
writer.write(fragment)
|
423
|
+
else
|
424
|
+
property.xml_serialize(writer)
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
writer.end_element unless group.blank?
|
429
|
+
end
|
430
|
+
|
431
|
+
writer.end_element
|
432
|
+
end
|
433
|
+
|
434
|
+
# Returns the default class for a property name.
|
435
|
+
#
|
436
|
+
# @param string property_name
|
437
|
+
#
|
438
|
+
# @return string
|
439
|
+
def class_name_for_property_name(property_name)
|
440
|
+
class_name = super(property_name)
|
441
|
+
|
442
|
+
# In vCard 4, BINARY no longer exists, and we need URI instead.
|
443
|
+
if class_name == Property::Binary && document_type == self.class::VCARD40
|
444
|
+
return Property::Uri
|
445
|
+
end
|
446
|
+
|
447
|
+
class_name
|
448
|
+
end
|
449
|
+
|
450
|
+
def initialize(*args)
|
451
|
+
super(*args)
|
452
|
+
@version = nil
|
453
|
+
end
|
454
|
+
end
|
455
|
+
end
|
456
|
+
end
|
457
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Component
|
4
|
+
# VEvent component.
|
5
|
+
#
|
6
|
+
# This component contains some additional functionality specific for VEVENT's.
|
7
|
+
class VEvent < Component
|
8
|
+
# Returns true or false depending on if the event falls in the specified
|
9
|
+
# time-range. This is used for filtering purposes.
|
10
|
+
#
|
11
|
+
# The rules used to determine if an event falls within the specified
|
12
|
+
# time-range is based on the CalDAV specification.
|
13
|
+
#
|
14
|
+
# @param DateTimeInterface start
|
15
|
+
# @param DateTimeInterface end
|
16
|
+
#
|
17
|
+
# @return bool
|
18
|
+
def in_time_range?(start, ending)
|
19
|
+
if self['RRULE']
|
20
|
+
begin
|
21
|
+
it = Tilia::VObject::Recur::EventIterator.new(self, nil, start.time_zone)
|
22
|
+
rescue Tilia::VObject::Recur::NoInstancesException
|
23
|
+
# If we've catched this exception, there are no instances
|
24
|
+
# for the event that fall into the specified time-range.
|
25
|
+
return false
|
26
|
+
end
|
27
|
+
|
28
|
+
it.fast_forward(start)
|
29
|
+
|
30
|
+
# We fast-forwarded to a spot where the end-time of the
|
31
|
+
# recurrence instance exceeded the start of the requested
|
32
|
+
# time-range.
|
33
|
+
#
|
34
|
+
# If the starttime of the recurrence did not exceed the
|
35
|
+
# end of the time range as well, we have a match.
|
36
|
+
return false unless it.dt_start
|
37
|
+
return (it.dt_start < ending && it.dt_end > start)
|
38
|
+
end
|
39
|
+
|
40
|
+
effective_start = self['DTSTART'].date_time(start.time_zone)
|
41
|
+
if self.key?('DTEND')
|
42
|
+
|
43
|
+
# The DTEND property is considered non inclusive. So for a 3 day
|
44
|
+
# event in july, dtstart and dtend would have to be July 1st and
|
45
|
+
# July 4th respectively.
|
46
|
+
#
|
47
|
+
# See:
|
48
|
+
# http://tools.ietf.org/html/rfc5545#page-54
|
49
|
+
effective_end = self['DTEND'].date_time(ending.time_zone)
|
50
|
+
|
51
|
+
elsif self.key?('DURATION')
|
52
|
+
effective_end = effective_start + Tilia::VObject::DateTimeParser.parse_duration(self['DURATION'])
|
53
|
+
elsif !self['DTSTART'].time?
|
54
|
+
effective_end = effective_start + 1.day
|
55
|
+
else
|
56
|
+
effective_end = effective_start
|
57
|
+
end
|
58
|
+
|
59
|
+
start < effective_end && ending > effective_start
|
60
|
+
end
|
61
|
+
|
62
|
+
protected
|
63
|
+
|
64
|
+
# This method should return a list of default property values.
|
65
|
+
#
|
66
|
+
# @return array
|
67
|
+
def defaults
|
68
|
+
{
|
69
|
+
'UID' => 'sabre-vobject-' + Tilia::VObject::UuidUtil.uuid,
|
70
|
+
'DTSTAMP' => Time.zone.now.utc.strftime('%Y%m%dT%H%M%SZ')
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
public
|
75
|
+
|
76
|
+
# A simple list of validation rules.
|
77
|
+
#
|
78
|
+
# This is simply a list of properties, and how many times they either
|
79
|
+
# must or must not appear.
|
80
|
+
#
|
81
|
+
# Possible values per property:
|
82
|
+
# * 0 - Must not appear.
|
83
|
+
# * 1 - Must appear exactly once.
|
84
|
+
# * + - Must appear at least once.
|
85
|
+
# * * - Can appear any number of times.
|
86
|
+
# * ? - May appear, but not more than once.
|
87
|
+
#
|
88
|
+
# @var array
|
89
|
+
def validation_rules
|
90
|
+
{
|
91
|
+
'UID' => 1,
|
92
|
+
'DTSTAMP' => 1,
|
93
|
+
'DTSTART' => parent.key?('METHOD') ? '?' : '1',
|
94
|
+
'CLASS' => '?',
|
95
|
+
'CREATED' => '?',
|
96
|
+
'DESCRIPTION' => '?',
|
97
|
+
'GEO' => '?',
|
98
|
+
'LAST-MODIFIED' => '?',
|
99
|
+
'LOCATION' => '?',
|
100
|
+
'ORGANIZER' => '?',
|
101
|
+
'PRIORITY' => '?',
|
102
|
+
'SEQUENCE' => '?',
|
103
|
+
'STATUS' => '?',
|
104
|
+
'SUMMARY' => '?',
|
105
|
+
'TRANSP' => '?',
|
106
|
+
'URL' => '?',
|
107
|
+
'RECURRENCE-ID' => '?',
|
108
|
+
'RRULE' => '?',
|
109
|
+
'DTEND' => '?',
|
110
|
+
'DURATION' => '?',
|
111
|
+
|
112
|
+
'ATTACH' => '*',
|
113
|
+
'ATTENDEE' => '*',
|
114
|
+
'CATEGORIES' => '*',
|
115
|
+
'COMMENT' => '*',
|
116
|
+
'CONTACT' => '*',
|
117
|
+
'EXDATE' => '*',
|
118
|
+
'REQUEST-STATUS' => '*',
|
119
|
+
'RELATED-TO' => '*',
|
120
|
+
'RESOURCES' => '*',
|
121
|
+
'RDATE' => '*'
|
122
|
+
}
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Component
|
4
|
+
# The VFreeBusy component.
|
5
|
+
#
|
6
|
+
# This component adds functionality to a component, specific for VFREEBUSY
|
7
|
+
# components.
|
8
|
+
class VFreeBusy < Component
|
9
|
+
# Checks based on the contained FREEBUSY information, if a timeslot is
|
10
|
+
# available.
|
11
|
+
#
|
12
|
+
# @param DateTimeInterface start
|
13
|
+
# @param DateTimeInterface end
|
14
|
+
#
|
15
|
+
# @return bool
|
16
|
+
def free?(start, ending)
|
17
|
+
select('FREEBUSY').each do |freebusy|
|
18
|
+
# We are only interested in FBTYPE=BUSY (the default),
|
19
|
+
# FBTYPE=BUSY-TENTATIVE or FBTYPE=BUSY-UNAVAILABLE.
|
20
|
+
if freebusy.key?('FBTYPE') && freebusy['FBTYPE'].to_s[0...4].upcase != 'BUSY'
|
21
|
+
next
|
22
|
+
end
|
23
|
+
|
24
|
+
# The freebusy component can hold more than 1 value, separated by
|
25
|
+
# commas.
|
26
|
+
periods = freebusy.to_s.split(/,/)
|
27
|
+
|
28
|
+
periods.each do |period|
|
29
|
+
# Every period is formatted as [start]/[end]. The start is an
|
30
|
+
# absolute UTC time, the end may be an absolute UTC time, or
|
31
|
+
# duration (relative) value.
|
32
|
+
(busy_start, busy_end) = period.split('/')
|
33
|
+
|
34
|
+
busy_start = Tilia::VObject::DateTimeParser.parse(busy_start)
|
35
|
+
busy_end = Tilia::VObject::DateTimeParser.parse(busy_end)
|
36
|
+
|
37
|
+
if busy_end.is_a?(ActiveSupport::Duration)
|
38
|
+
busy_end = busy_start + busy_end
|
39
|
+
end
|
40
|
+
|
41
|
+
return false if start < busy_end && ending > busy_start
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
true
|
46
|
+
end
|
47
|
+
|
48
|
+
# A simple list of validation rules.
|
49
|
+
#
|
50
|
+
# This is simply a list of properties, and how many times they either
|
51
|
+
# must or must not appear.
|
52
|
+
#
|
53
|
+
# Possible values per property:
|
54
|
+
# * 0 - Must not appear.
|
55
|
+
# * 1 - Must appear exactly once.
|
56
|
+
# * + - Must appear at least once.
|
57
|
+
# * * - Can appear any number of times.
|
58
|
+
# * ? - May appear, but not more than once.
|
59
|
+
#
|
60
|
+
# @var array
|
61
|
+
def validation_rules
|
62
|
+
{
|
63
|
+
'UID' => 1,
|
64
|
+
'DTSTAMP' => 1,
|
65
|
+
|
66
|
+
'CONTACT' => '?',
|
67
|
+
'DTSTART' => '?',
|
68
|
+
'DTEND' => '?',
|
69
|
+
'ORGANIZER' => '?',
|
70
|
+
'URL' => '?',
|
71
|
+
|
72
|
+
'ATTENDEE' => '*',
|
73
|
+
'COMMENT' => '*',
|
74
|
+
'FREEBUSY' => '*',
|
75
|
+
'REQUEST-STATUS' => '*'
|
76
|
+
}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|