tilia-vobject 4.0.0.pre.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rubocop.yml +32 -0
  4. data/.simplecov +4 -0
  5. data/.travis.yml +3 -0
  6. data/CHANGELOG.sabre.md +626 -0
  7. data/CONTRIBUTING.md +25 -0
  8. data/Gemfile +17 -0
  9. data/Gemfile.lock +68 -0
  10. data/LICENSE +27 -0
  11. data/LICENSE.sabre +27 -0
  12. data/README.md +63 -0
  13. data/Rakefile +17 -0
  14. data/bin/vobject +7 -0
  15. data/lib/tilia/v_object/birthday_calendar_generator.rb +142 -0
  16. data/lib/tilia/v_object/cli.rb +582 -0
  17. data/lib/tilia/v_object/component/available.rb +107 -0
  18. data/lib/tilia/v_object/component/v_alarm.rb +114 -0
  19. data/lib/tilia/v_object/component/v_availability.rb +128 -0
  20. data/lib/tilia/v_object/component/v_calendar.rb +468 -0
  21. data/lib/tilia/v_object/component/v_card.rb +457 -0
  22. data/lib/tilia/v_object/component/v_event.rb +127 -0
  23. data/lib/tilia/v_object/component/v_free_busy.rb +81 -0
  24. data/lib/tilia/v_object/component/v_journal.rb +75 -0
  25. data/lib/tilia/v_object/component/v_time_zone.rb +51 -0
  26. data/lib/tilia/v_object/component/v_todo.rb +147 -0
  27. data/lib/tilia/v_object/component.rb +591 -0
  28. data/lib/tilia/v_object/date_time_parser.rb +486 -0
  29. data/lib/tilia/v_object/document.rb +218 -0
  30. data/lib/tilia/v_object/element_list.rb +18 -0
  31. data/lib/tilia/v_object/eof_exception.rb +8 -0
  32. data/lib/tilia/v_object/free_busy_data.rb +149 -0
  33. data/lib/tilia/v_object/free_busy_generator.rb +465 -0
  34. data/lib/tilia/v_object/i_tip/broker.rb +909 -0
  35. data/lib/tilia/v_object/i_tip/i_tip_exception.rb +9 -0
  36. data/lib/tilia/v_object/i_tip/message.rb +109 -0
  37. data/lib/tilia/v_object/i_tip/same_organizer_for_all_components_exception.rb +13 -0
  38. data/lib/tilia/v_object/i_tip.rb +10 -0
  39. data/lib/tilia/v_object/node.rb +192 -0
  40. data/lib/tilia/v_object/parameter.rb +327 -0
  41. data/lib/tilia/v_object/parse_exception.rb +7 -0
  42. data/lib/tilia/v_object/parser/json.rb +149 -0
  43. data/lib/tilia/v_object/parser/mime_dir.rb +543 -0
  44. data/lib/tilia/v_object/parser/parser.rb +61 -0
  45. data/lib/tilia/v_object/parser/xml/element/key_value.rb +60 -0
  46. data/lib/tilia/v_object/parser/xml/element.rb +11 -0
  47. data/lib/tilia/v_object/parser/xml.rb +322 -0
  48. data/lib/tilia/v_object/parser.rb +10 -0
  49. data/lib/tilia/v_object/property/binary.rb +96 -0
  50. data/lib/tilia/v_object/property/boolean.rb +57 -0
  51. data/lib/tilia/v_object/property/flat_text.rb +52 -0
  52. data/lib/tilia/v_object/property/float_value.rb +107 -0
  53. data/lib/tilia/v_object/property/i_calendar/cal_address.rb +49 -0
  54. data/lib/tilia/v_object/property/i_calendar/date.rb +15 -0
  55. data/lib/tilia/v_object/property/i_calendar/date_time.rb +330 -0
  56. data/lib/tilia/v_object/property/i_calendar/duration.rb +65 -0
  57. data/lib/tilia/v_object/property/i_calendar/period.rb +124 -0
  58. data/lib/tilia/v_object/property/i_calendar/recur.rb +173 -0
  59. data/lib/tilia/v_object/property/i_calendar.rb +14 -0
  60. data/lib/tilia/v_object/property/integer_value.rb +60 -0
  61. data/lib/tilia/v_object/property/text.rb +352 -0
  62. data/lib/tilia/v_object/property/time.rb +85 -0
  63. data/lib/tilia/v_object/property/unknown.rb +30 -0
  64. data/lib/tilia/v_object/property/uri.rb +78 -0
  65. data/lib/tilia/v_object/property/utc_offset.rb +56 -0
  66. data/lib/tilia/v_object/property/v_card/date.rb +31 -0
  67. data/lib/tilia/v_object/property/v_card/date_and_or_time.rb +343 -0
  68. data/lib/tilia/v_object/property/v_card/date_time.rb +22 -0
  69. data/lib/tilia/v_object/property/v_card/language_tag.rb +41 -0
  70. data/lib/tilia/v_object/property/v_card/time_stamp.rb +74 -0
  71. data/lib/tilia/v_object/property/v_card.rb +13 -0
  72. data/lib/tilia/v_object/property.rb +532 -0
  73. data/lib/tilia/v_object/reader.rb +73 -0
  74. data/lib/tilia/v_object/recur/event_iterator.rb +417 -0
  75. data/lib/tilia/v_object/recur/no_instances_exception.rb +11 -0
  76. data/lib/tilia/v_object/recur/r_date_iterator.rb +138 -0
  77. data/lib/tilia/v_object/recur/r_rule_iterator.rb +717 -0
  78. data/lib/tilia/v_object/recur.rb +10 -0
  79. data/lib/tilia/v_object/settings.rb +32 -0
  80. data/lib/tilia/v_object/splitter/i_calendar.rb +95 -0
  81. data/lib/tilia/v_object/splitter/splitter_interface.rb +31 -0
  82. data/lib/tilia/v_object/splitter/v_card.rb +56 -0
  83. data/lib/tilia/v_object/splitter.rb +9 -0
  84. data/lib/tilia/v_object/string_util.rb +58 -0
  85. data/lib/tilia/v_object/time_zone_data/exchange_zones.rb +96 -0
  86. data/lib/tilia/v_object/time_zone_data/lotus_zones.rb +104 -0
  87. data/lib/tilia/v_object/time_zone_data/php_zones.rb +49 -0
  88. data/lib/tilia/v_object/time_zone_data/windows_zones.rb +121 -0
  89. data/lib/tilia/v_object/time_zone_data.rb +10 -0
  90. data/lib/tilia/v_object/time_zone_util.rb +213 -0
  91. data/lib/tilia/v_object/uuid_util.rb +51 -0
  92. data/lib/tilia/v_object/v_card_converter.rb +354 -0
  93. data/lib/tilia/v_object/version.rb +9 -0
  94. data/lib/tilia/v_object/writer.rb +56 -0
  95. data/lib/tilia/v_object.rb +45 -0
  96. data/lib/tilia/vobject.rb +1 -0
  97. data/resources/schema/xcal.rng +1192 -0
  98. data/resources/schema/xcard.rng +388 -0
  99. data/test/test_helper.rb +56 -0
  100. data/test/v_object/attach_issue_test.rb +19 -0
  101. data/test/v_object/birthday_calendar_generator_test.rb +463 -0
  102. data/test/v_object/cli_mock.rb +19 -0
  103. data/test/v_object/cli_test.rb +460 -0
  104. data/test/v_object/component/available_test.rb +59 -0
  105. data/test/v_object/component/v_alarm_test.rb +160 -0
  106. data/test/v_object/component/v_availability_test.rb +388 -0
  107. data/test/v_object/component/v_calendar_test.rb +646 -0
  108. data/test/v_object/component/v_card_test.rb +258 -0
  109. data/test/v_object/component/v_event_test.rb +85 -0
  110. data/test/v_object/component/v_free_busy_test.rb +59 -0
  111. data/test/v_object/component/v_journal_test.rb +85 -0
  112. data/test/v_object/component/v_time_zone_test.rb +47 -0
  113. data/test/v_object/component/v_todo_test.rb +172 -0
  114. data/test/v_object/component_test.rb +419 -0
  115. data/test/v_object/date_time_parser_test.rb +526 -0
  116. data/test/v_object/document_test.rb +71 -0
  117. data/test/v_object/element_list_test.rb +27 -0
  118. data/test/v_object/em_client_test.rb +53 -0
  119. data/test/v_object/empty_parameter_test.rb +65 -0
  120. data/test/v_object/empty_value_issue_test.rb +25 -0
  121. data/test/v_object/fake_component.rb +21 -0
  122. data/test/v_object/free_busy_data_test.rb +285 -0
  123. data/test/v_object/free_busy_generator_test.rb +637 -0
  124. data/test/v_object/google_colon_escaping_test.rb +27 -0
  125. data/test/v_object/i_calendar/attach_parse_test.rb +24 -0
  126. data/test/v_object/i_tip/broker_attendee_reply_test.rb +1042 -0
  127. data/test/v_object/i_tip/broker_delete_event_test.rb +175 -0
  128. data/test/v_object/i_tip/broker_new_event_test.rb +440 -0
  129. data/test/v_object/i_tip/broker_process_message_test.rb +153 -0
  130. data/test/v_object/i_tip/broker_process_reply_test.rb +402 -0
  131. data/test/v_object/i_tip/broker_tester.rb +71 -0
  132. data/test/v_object/i_tip/broker_update_event_test.rb +763 -0
  133. data/test/v_object/i_tip/evolution_test.rb +2644 -0
  134. data/test/v_object/i_tip/message_test.rb +25 -0
  135. data/test/v_object/issue153.vcf +352 -0
  136. data/test/v_object/issue153_test.rb +12 -0
  137. data/test/v_object/issue26_test.rb +25 -0
  138. data/test/v_object/issue36_work_around_test.rb +37 -0
  139. data/test/v_object/issue40_test.rb +26 -0
  140. data/test/v_object/issue64.vcf +351 -0
  141. data/test/v_object/issue64_test.rb +17 -0
  142. data/test/v_object/issue96_test.rb +22 -0
  143. data/test/v_object/issue_undefined_index_test.rb +24 -0
  144. data/test/v_object/j_cal_test.rb +150 -0
  145. data/test/v_object/j_card_test.rb +192 -0
  146. data/test/v_object/line_folding_issue_test.rb +19 -0
  147. data/test/v_object/mock_document.rb +6 -0
  148. data/test/v_object/parameter_test.rb +109 -0
  149. data/test/v_object/parser/json_test.rb +370 -0
  150. data/test/v_object/parser/mime_dir_test.rb +14 -0
  151. data/test/v_object/parser/quoted_printable_test.rb +78 -0
  152. data/test/v_object/parser/xml_test.rb +2563 -0
  153. data/test/v_object/property/binary_test.rb +12 -0
  154. data/test/v_object/property/boolean_test.rb +18 -0
  155. data/test/v_object/property/compound_test.rb +43 -0
  156. data/test/v_object/property/float_test.rb +20 -0
  157. data/test/v_object/property/i_calendar/cal_address_test.rb +26 -0
  158. data/test/v_object/property/i_calendar/date_time_test.rb +303 -0
  159. data/test/v_object/property/i_calendar/duration_test.rb +14 -0
  160. data/test/v_object/property/i_calendar/recur_test.rb +39 -0
  161. data/test/v_object/property/text_test.rb +81 -0
  162. data/test/v_object/property/v_card/date_and_or_time_test.rb +205 -0
  163. data/test/v_object/property/v_card/language_tag_test.rb +35 -0
  164. data/test/v_object/property_test.rb +338 -0
  165. data/test/v_object/reader_test.rb +403 -0
  166. data/test/v_object/recur/event_iterator/by_month_in_daily_test.rb +52 -0
  167. data/test/v_object/recur/event_iterator/by_set_pos_hang_test.rb +55 -0
  168. data/test/v_object/recur/event_iterator/expand_floating_times_test.rb +109 -0
  169. data/test/v_object/recur/event_iterator/fifth_tuesday_problem_test.rb +45 -0
  170. data/test/v_object/recur/event_iterator/incorrect_expand_test.rb +53 -0
  171. data/test/v_object/recur/event_iterator/infinite_loop_problem_test.rb +75 -0
  172. data/test/v_object/recur/event_iterator/issue48_test.rb +43 -0
  173. data/test/v_object/recur/event_iterator/issue50_test.rb +123 -0
  174. data/test/v_object/recur/event_iterator/main_test.rb +1222 -0
  175. data/test/v_object/recur/event_iterator/missing_overridden_test.rb +55 -0
  176. data/test/v_object/recur/event_iterator/no_instances_test.rb +32 -0
  177. data/test/v_object/recur/event_iterator/override_first_event_test.rb +106 -0
  178. data/test/v_object/recur/r_date_iterator_test.rb +44 -0
  179. data/test/v_object/recur/r_rule_iterator_test.rb +608 -0
  180. data/test/v_object/recurrence_iterator/UntilRespectsTimezoneTest.ics +39 -0
  181. data/test/v_object/slash_r_test.rb +15 -0
  182. data/test/v_object/splitter/i_calendar_test.rb +299 -0
  183. data/test/v_object/splitter/v_card_test.rb +173 -0
  184. data/test/v_object/string_util_test.rb +37 -0
  185. data/test/v_object/test_case.rb +42 -0
  186. data/test/v_object/time_zone_util_test.rb +271 -0
  187. data/test/v_object/uuid_util_test.rb +18 -0
  188. data/test/v_object/v_card21_test.rb +43 -0
  189. data/test/v_object/v_card_converter_test.rb +419 -0
  190. data/test/v_object/version_test.rb +15 -0
  191. data/test/v_object/writer_test.rb +33 -0
  192. data/tilia-vobject.gemspec +17 -0
  193. metadata +308 -0
@@ -0,0 +1,61 @@
1
+ module Tilia
2
+ module VObject
3
+ module Parser
4
+ # Abstract parser.
5
+ #
6
+ # This class serves as a base-class for the different parsers.
7
+ class Parser
8
+ # Turning on this option makes the parser more forgiving.
9
+ #
10
+ # In the case of the MimeDir parser, this means that the parser will
11
+ # accept slashes and underscores in property names, and it will also
12
+ # attempt to fix Microsoft vCard 2.1's broken line folding.
13
+ OPTION_FORGIVING ||= 1
14
+
15
+ # If this option is turned on, any lines we cannot parse will be ignored
16
+ # by the reader.
17
+ OPTION_IGNORE_INVALID_LINES ||= 2
18
+
19
+ # Bitmask of parser options.
20
+ #
21
+ # @var int
22
+ # RUBY: attr_accessor :options
23
+
24
+ # Creates the parser.
25
+ #
26
+ # Optionally, it's possible to parse the input stream here.
27
+ #
28
+ # @param mixed input
29
+ # @param int options Any parser options (OPTION constants).
30
+ #
31
+ # @return void
32
+ def initialize(input = nil, options = 0)
33
+ self.input = input unless input.nil?
34
+ @options = options
35
+ end
36
+
37
+ # This method starts the parsing process.
38
+ #
39
+ # If the input was not supplied during construction, it's possible to pass
40
+ # it here instead.
41
+ #
42
+ # If either input or options are not supplied, the defaults will be used.
43
+ #
44
+ # @param mixed input
45
+ # @param int options
46
+ #
47
+ # @return array
48
+ def parse(_input = nil, _options = 0)
49
+ end
50
+
51
+ # Sets the input data.
52
+ #
53
+ # @param mixed input
54
+ #
55
+ # @return void
56
+ def input=(_input)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,60 @@
1
+ module Tilia
2
+ module VObject
3
+ module Parser
4
+ class Xml
5
+ module Element
6
+ # Our own sabre/xml key-value element.
7
+ #
8
+ # It just removes the clark notation.
9
+ class KeyValue < Tilia::Xml::Element::KeyValue
10
+ # The deserialize method is called during xml parsing.
11
+ #
12
+ # This method is called staticly, this is because in theory this method
13
+ # may be used as a type of constructor, or factory method.
14
+ #
15
+ # Often you want to return an instance of the current class, but you are
16
+ # free to return other data as well.
17
+ #
18
+ # Important note 2: You are responsible for advancing the reader to the
19
+ # next element. Not doing anything will result in a never-ending loop.
20
+ #
21
+ # If you just want to skip parsing for this element altogether, you can
22
+ # just call reader.next
23
+ #
24
+ # reader.parse_inner_tree will parse the entire sub-tree, and advance to
25
+ # the next element.
26
+ #
27
+ # @param XML\Reader reader
28
+ #
29
+ # @return mixed
30
+ def self.xml_deserialize(reader)
31
+ # If there's no children, we don't do anything.
32
+ if reader.empty_element?
33
+ reader.next
34
+ return {}
35
+ end
36
+
37
+ values = {}
38
+ reader.read
39
+
40
+ loop do
41
+ if reader.node_type == ::LibXML::XML::Reader::TYPE_ELEMENT
42
+ name = reader.local_name
43
+ values[name] = reader.parse_current_element['value']
44
+ else
45
+ reader.read
46
+ end
47
+
48
+ break if reader.node_type == ::LibXML::XML::Reader::TYPE_END_ELEMENT
49
+ end
50
+
51
+ reader.read
52
+
53
+ values
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,11 @@
1
+ module Tilia
2
+ module VObject
3
+ module Parser
4
+ class Xml
5
+ module Element
6
+ require 'tilia/v_object/parser/xml/element/key_value'
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,322 @@
1
+ module Tilia
2
+ module VObject
3
+ module Parser
4
+ # XML Parser.
5
+ #
6
+ # This parser parses both the xCal and xCard formats.
7
+ class Xml < Parser
8
+ require 'tilia/v_object/parser/xml/element'
9
+
10
+ XCAL_NAMESPACE ||= 'urn:ietf:params:xml:ns:icalendar-2.0'
11
+ XCARD_NAMESPACE ||= 'urn:ietf:params:xml:ns:vcard-4.0'
12
+
13
+ # The input data.
14
+ #
15
+ # @var array
16
+ # RUBY: attr_accessor :input
17
+
18
+ # A pointer/reference to the input.
19
+ #
20
+ # @var array
21
+ # RUBY: attr_accessor :pointer
22
+
23
+ # Document, root component.
24
+ #
25
+ # @var Sabre\VObject\Document
26
+ # RUBY: attr_accessor :root
27
+
28
+ # Creates the parser.
29
+ #
30
+ # Optionally, it's possible to parse the input stream here.
31
+ #
32
+ # @param mixed input
33
+ # @param int options Any parser options (OPTION constants).
34
+ #
35
+ # @return void
36
+ def initialize(input = nil, options = 0)
37
+ @input = nil
38
+ @pointer = nil
39
+ @root = nil
40
+
41
+ options = self.class::OPTION_FORGIVING if options == 0
42
+
43
+ super(input, options)
44
+ end
45
+
46
+ # Parse xCal or xCard.
47
+ #
48
+ # @param resource|string input
49
+ # @param int options
50
+ #
51
+ # @throws \Exception
52
+ #
53
+ # @return Sabre\VObject\Document
54
+ def parse(input = nil, options = 0)
55
+ self.input = input unless input.nil?
56
+ @options = options if options != 0
57
+ if @input.nil?
58
+ fail Tilia::VObject::EofException, 'End of input stream, or no input supplied'
59
+ end
60
+
61
+ case @input['name']
62
+ when "{#{self.class::XCAL_NAMESPACE}}icalendar"
63
+ @root = Tilia::VObject::Component::VCalendar.new({}, false)
64
+ @pointer = @input['value'][0]
65
+ parse_v_calendar_components(@root)
66
+ when "{#{self.class::XCARD_NAMESPACE}}vcards"
67
+ @input['value'].each do |v_card|
68
+ @root = Tilia::VObject::Component::VCard.new({ 'version' => '4.0' }, false)
69
+ @pointer = v_card
70
+ parse_v_card_components(@root)
71
+
72
+ # We just parse the first <vcard /> element.
73
+ break
74
+ end
75
+ else
76
+ fail Tilia::VObject::ParseException, 'Unsupported XML standard'
77
+ end
78
+
79
+ @root
80
+ end
81
+
82
+ protected
83
+
84
+ # Parse a xCalendar component.
85
+ #
86
+ # @param Component parent_component
87
+ #
88
+ # @return void
89
+ def parse_v_calendar_components(parent_component)
90
+ components = @pointer['value'] ? @pointer['value'] : []
91
+
92
+ components.each do |children|
93
+ case self.class.tag_name(children['name'])
94
+ when 'properties'
95
+ @pointer = children['value']
96
+ parse_properties(parent_component)
97
+ when 'components'
98
+ @pointer = children
99
+ parse_component(parent_component)
100
+ end
101
+ end
102
+ end
103
+
104
+ # Parse a xCard component.
105
+ #
106
+ # @param Component parent_component
107
+ #
108
+ # @return void
109
+ def parse_v_card_components(parent_component)
110
+ @pointer = @pointer['value']
111
+ parse_properties(parent_component)
112
+ end
113
+
114
+ # Parse xCalendar and xCard properties.
115
+ #
116
+ # @param Component parent_component
117
+ # @param string property_name_prefix
118
+ #
119
+ # @return void
120
+ def parse_properties(parent_component, property_name_prefix = '')
121
+ properties = @pointer ? @pointer : {}
122
+
123
+ properties.each do |xml_property|
124
+ (namespace, tag_name) = Tilia::Xml::Service.parse_clark_notation(xml_property['name'])
125
+
126
+ property_name = tag_name
127
+ property_value = nil
128
+ property_parameters = {}
129
+ property_type = 'text'
130
+
131
+ # A property which is not part of the standard.
132
+ if namespace != Tilia::VObject::Parser::Xml::XCAL_NAMESPACE && namespace != Tilia::VObject::Parser::Xml::XCARD_NAMESPACE
133
+ property_name = 'xml'
134
+ value = "<#{tag_name} xmlns=\"#{namespace}\""
135
+
136
+ xml_property['attributes'].each do |attribute_name, attribute_value|
137
+ value += " #{attribute_name}=\"#{attribute_value.gsub('"', '\\"')}\""
138
+ end
139
+ value += ">#{xml_property['value']}</#{tag_name}>"
140
+
141
+ property_value = [value]
142
+
143
+ create_property(
144
+ parent_component,
145
+ property_name,
146
+ property_parameters,
147
+ property_type,
148
+ property_value
149
+ )
150
+
151
+ next
152
+ end
153
+
154
+ # xCard group.
155
+ if property_name == 'group'
156
+ next unless xml_property['attributes'].key?('name')
157
+
158
+ @pointer = xml_property['value']
159
+ parse_properties(
160
+ parent_component,
161
+ xml_property['attributes']['name'].upcase + '.'
162
+ )
163
+
164
+ next
165
+ end
166
+
167
+ # Collect parameters.
168
+ xml_property['value'] = xml_property['value'].map do |xml_property_child|
169
+ if !xml_property_child.is_a?(Hash) || 'parameters' != self.class.tag_name(xml_property_child['name'])
170
+ xml_property_child
171
+ else
172
+ xml_parameters = xml_property_child['value']
173
+
174
+ xml_parameters.each do |xml_parameter|
175
+ property_parameter_values = []
176
+
177
+ xml_parameter['value'].each do |xml_parameter_values|
178
+ property_parameter_values << xml_parameter_values['value']
179
+ end
180
+
181
+ property_parameters[self.class.tag_name(xml_parameter['name'])] = property_parameter_values.join(',')
182
+ end
183
+
184
+ nil # We will delete this with compact()
185
+ end
186
+ end
187
+
188
+ xml_property['value'].compact!
189
+
190
+ property_name_extended = (@root.is_a?(Tilia::VObject::Component::VCalendar) ? 'xcal' : 'xcard') + ':' + property_name
191
+
192
+ case property_name_extended
193
+ when 'xcal:geo'
194
+ property_type = 'float'
195
+ property_value ||= {}
196
+ property_value['latitude'] = 0.0
197
+ property_value['longitude'] = 0.0
198
+
199
+ xml_property['value'].each do |xml_request_child|
200
+ property_value[self.class.tag_name(xml_request_child['name'])] = xml_request_child['value']
201
+ end
202
+ when 'xcal:request-status'
203
+ property_type = 'text'
204
+
205
+ property_value ||= {}
206
+ xml_property['value'].each do |xml_request_child|
207
+ property_value[self.class.tag_name(xml_request_child['name'])] = xml_request_child['value']
208
+ end
209
+ when 'xcal:freebusy', 'xcal:categories', 'xcal:resources', 'xcal:exdate'
210
+ property_type = 'freebusy' if property_name_extended == 'xcal:freebusy'
211
+ # We don't break because we only want to set
212
+ # another property type.
213
+
214
+ xml_property['value'].each do |special_child|
215
+ property_value ||= {}
216
+ property_value[self.class.tag_name(special_child['name'])] = special_child['value']
217
+ end
218
+ when 'xcal:rdate'
219
+ property_type = 'date-time'
220
+ property_value ||= []
221
+
222
+ xml_property['value'].each do |special_child|
223
+ tag_name = self.class.tag_name(special_child['name'])
224
+
225
+ if 'period' == tag_name
226
+ property_parameters['value'] = 'PERIOD'
227
+ property_value << special_child['value'].values.join('/')
228
+ else
229
+ property_value << special_child['value']
230
+ end
231
+ end
232
+ else
233
+ property_type = self.class.tag_name(xml_property['value'][0]['name'])
234
+
235
+ property_value ||= []
236
+ xml_property['value'].each do |value|
237
+ property_value << value['value']
238
+ end
239
+
240
+ property_parameters['value'] = 'DATE' if 'date' == property_type
241
+ end
242
+
243
+ create_property(
244
+ parent_component,
245
+ property_name_prefix + property_name,
246
+ property_parameters,
247
+ property_type,
248
+ property_value
249
+ )
250
+ end
251
+ end
252
+
253
+ # Parse a component.
254
+ #
255
+ # @param Component parent_component
256
+ #
257
+ # @return void
258
+ def parse_component(parent_component)
259
+ components = @pointer['value'] ? @pointer['value'] : []
260
+
261
+ components.each do |component|
262
+ component_name = self.class.tag_name(component['name'])
263
+ current_component = @root.create_component(component_name, nil, false)
264
+
265
+ @pointer = component
266
+ parse_v_calendar_components(current_component)
267
+
268
+ parent_component.add(current_component)
269
+ end
270
+ end
271
+
272
+ # Create a property.
273
+ #
274
+ # @param Component parent_component
275
+ # @param string name
276
+ # @param array parameters
277
+ # @param string type
278
+ # @param mixed value
279
+ #
280
+ # @return void
281
+ def create_property(parent_component, name, parameters, type, value)
282
+ property = @root.create_property(name, nil, parameters, type)
283
+ parent_component.add(property)
284
+ property.xml_value = value
285
+ end
286
+
287
+ public
288
+
289
+ # Sets the input data.
290
+ #
291
+ # @param resource|string input
292
+ #
293
+ # @return void
294
+ def input=(input)
295
+ input = input.readlines.join('') if input.respond_to?(:readlines)
296
+
297
+ if input.is_a?(String)
298
+ reader = Tilia::Xml::Reader.new
299
+ reader.element_map["{#{self.class::XCAL_NAMESPACE}}period"] = Tilia::VObject::Parser::Xml::Element::KeyValue
300
+ reader.element_map["{#{self.class::XCAL_NAMESPACE}}recur"] = Tilia::VObject::Parser::Xml::Element::KeyValue
301
+ reader.xml(input)
302
+ input = reader.parse
303
+ end
304
+
305
+ @input = input
306
+ end
307
+
308
+ protected
309
+
310
+ # Get tag name from a Clark notation.
311
+ #
312
+ # @param string clarked_tag_name
313
+ #
314
+ # @return string
315
+ def self.tag_name(clarked_tag_name)
316
+ (_, tag_name) = Tilia::Xml::Service.parse_clark_notation(clarked_tag_name)
317
+ tag_name
318
+ end
319
+ end
320
+ end
321
+ end
322
+ end
@@ -0,0 +1,10 @@
1
+ module Tilia
2
+ module VObject
3
+ module Parser
4
+ require 'tilia/v_object/parser/parser'
5
+ require 'tilia/v_object/parser/mime_dir'
6
+ require 'tilia/v_object/parser/json'
7
+ require 'tilia/v_object/parser/xml'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,96 @@
1
+ require 'base64'
2
+ module Tilia
3
+ module VObject
4
+ class Property
5
+ # BINARY property.
6
+ #
7
+ # This object represents BINARY values.
8
+ #
9
+ # Binary values are most commonly used by the iCalendar ATTACH property, and
10
+ # the vCard PHOTO property.
11
+ #
12
+ # This property will transparently encode and decode to base64.
13
+ class Binary < Property
14
+ # In case this is a multi-value property. This string will be used as a
15
+ # delimiter.
16
+ #
17
+ # @var string|null
18
+ attr_accessor :delimiter
19
+
20
+ # Updates the current value.
21
+ #
22
+ # This may be either a single, or multiple strings in an array.
23
+ #
24
+ # @param string|array value
25
+ #
26
+ # @return void
27
+ def value=(value)
28
+ if value.is_a?(Array)
29
+ if value.size == 1
30
+ @value = value.first
31
+ else
32
+ fail ArgumentError, 'The argument must either be a string or an array with only one child'
33
+ end
34
+ else
35
+ @value = value
36
+ end
37
+ end
38
+
39
+ # Sets a raw value coming from a mimedir (iCalendar/vCard) file.
40
+ #
41
+ # This has been 'unfolded', so only 1 line will be passed. Unescaping is
42
+ # not yet done, but parameters are not included.
43
+ #
44
+ # @param string val
45
+ #
46
+ # @return void
47
+ def raw_mime_dir_value=(val)
48
+ @value = Base64.decode64(val)
49
+ end
50
+
51
+ # Returns a raw mime-dir representation of the value.
52
+ #
53
+ # @return string
54
+ def raw_mime_dir_value
55
+ Base64.strict_encode64(@value)
56
+ end
57
+
58
+ # Returns the type of value.
59
+ #
60
+ # This corresponds to the VALUE= parameter. Every property also has a
61
+ # 'default' valueType.
62
+ #
63
+ # @return string
64
+ def value_type
65
+ 'BINARY'
66
+ end
67
+
68
+ # Returns the value, in the format it should be encoded for json.
69
+ #
70
+ # This method must always return an array.
71
+ #
72
+ # @return array
73
+ def json_value
74
+ [Base64.strict_encode64(value)]
75
+ end
76
+
77
+ # Sets the json value, as it would appear in a jCard or jCal object.
78
+ #
79
+ # The value must always be an array.
80
+ #
81
+ # @param array value
82
+ #
83
+ # @return void
84
+ def json_value=(value)
85
+ value = value.map { |v| Base64.decode64(v) }
86
+ super(value)
87
+ end
88
+
89
+ def initialize(*args)
90
+ super(*args)
91
+ @delimiter = nil
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,57 @@
1
+ module Tilia
2
+ module VObject
3
+ class Property
4
+ # Boolean property.
5
+ #
6
+ # This object represents BOOLEAN values. These are always the case-insenstive
7
+ # string TRUE or FALSE.
8
+ #
9
+ # Automatic conversion to PHP's true and false are done.
10
+ class Boolean < Property
11
+ # Sets a raw value coming from a mimedir (iCalendar/vCard) file.
12
+ #
13
+ # This has been 'unfolded', so only 1 line will be passed. Unescaping is
14
+ # not yet done, but parameters are not included.
15
+ #
16
+ # @param string val
17
+ #
18
+ # @return void
19
+ def raw_mime_dir_value=(val)
20
+ val = val.upcase == 'TRUE' ? true : false
21
+ self.value = val
22
+ end
23
+
24
+ # Returns a raw mime-dir representation of the value.
25
+ #
26
+ # @return string
27
+ def raw_mime_dir_value
28
+ @value ? 'TRUE' : 'FALSE'
29
+ end
30
+
31
+ # Returns the type of value.
32
+ #
33
+ # This corresponds to the VALUE= parameter. Every property also has a
34
+ # 'default' valueType.
35
+ #
36
+ # @return string
37
+ def value_type
38
+ 'BOOLEAN'
39
+ end
40
+
41
+ # Hydrate data from a XML subtree, as it would appear in a xCard or xCal
42
+ # object.
43
+ #
44
+ # @param array value
45
+ #
46
+ # @return void
47
+ def xml_value=(value)
48
+ value = value.map do |v|
49
+ 'true' == v
50
+ end
51
+
52
+ super(value)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,52 @@
1
+ module Tilia
2
+ module VObject
3
+ class Property
4
+ # FlatText property.
5
+ #
6
+ # This object represents certain TEXT values.
7
+ #
8
+ # Specifically, this property is used for text values where there is only 1
9
+ # part. Semi-colons and colons will be de-escaped when deserializing, but if
10
+ # any semi-colons or commas appear without a backslash, we will not assume
11
+ # that they are delimiters.
12
+ #
13
+ # vCard 2.1 specifically has a whole bunch of properties where this may
14
+ # happen, as it only defines a delimiter for a few properties.
15
+ #
16
+ # vCard 4.0 states something similar. An unescaped semi-colon _may_ be a
17
+ # delimiter, depending on the property.
18
+ class FlatText < Property::Text
19
+ # Field separator.
20
+ #
21
+ # @var string
22
+ attr_accessor :delimiter
23
+
24
+ # Sets the value as a quoted-printable encoded string.
25
+ #
26
+ # Overriding this so we're not splitting on a ; delimiter.
27
+ #
28
+ # @param string val
29
+ #
30
+ # @return void
31
+ def quoted_printable_value=(val)
32
+ val = Mail::Encodings::QuotedPrintable.decode(val)
33
+ val = val.gsub(/\n/, "\r\n").gsub(/\r\r/, "\r")
34
+
35
+ # force the correct encoding
36
+ begin
37
+ val.force_encoding(Encoding.find(@parameters['CHARSET'].to_s))
38
+ rescue
39
+ val.force_encoding(Encoding::UTF_8)
40
+ end
41
+
42
+ self.value = val
43
+ end
44
+
45
+ def initialize(*args)
46
+ super(*args)
47
+ @delimiter = ','
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end