scashin133-vpim 9.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/CHANGES +510 -0
  4. data/COPYING +58 -0
  5. data/LICENSE +20 -0
  6. data/Makefile +135 -0
  7. data/README +182 -0
  8. data/README.rdoc +17 -0
  9. data/Rakefile +54 -0
  10. data/THANKS +2 -0
  11. data/VERSION +1 -0
  12. data/ex_fmt_convert.rb +25 -0
  13. data/ex_ics_api.rb +54 -0
  14. data/lib/vpim/address.rb +219 -0
  15. data/lib/vpim/agent/atomize.rb +104 -0
  16. data/lib/vpim/agent/base.rb +73 -0
  17. data/lib/vpim/agent/calendars.rb +173 -0
  18. data/lib/vpim/agent/handler.rb +26 -0
  19. data/lib/vpim/agent/ics.rb +161 -0
  20. data/lib/vpim/attachment.rb +102 -0
  21. data/lib/vpim/date.rb +222 -0
  22. data/lib/vpim/dirinfo.rb +277 -0
  23. data/lib/vpim/duration.rb +119 -0
  24. data/lib/vpim/enumerator.rb +32 -0
  25. data/lib/vpim/field.rb +618 -0
  26. data/lib/vpim/icalendar.rb +384 -0
  27. data/lib/vpim/maker/vcard.rb +16 -0
  28. data/lib/vpim/property/base.rb +193 -0
  29. data/lib/vpim/property/common.rb +315 -0
  30. data/lib/vpim/property/location.rb +38 -0
  31. data/lib/vpim/property/priority.rb +43 -0
  32. data/lib/vpim/property/recurrence.rb +69 -0
  33. data/lib/vpim/property/resources.rb +24 -0
  34. data/lib/vpim/repo.rb +261 -0
  35. data/lib/vpim/rfc2425.rb +371 -0
  36. data/lib/vpim/rrule.rb +591 -0
  37. data/lib/vpim/time.rb +40 -0
  38. data/lib/vpim/vcard.rb +1426 -0
  39. data/lib/vpim/version.rb +19 -0
  40. data/lib/vpim/vevent.rb +187 -0
  41. data/lib/vpim/view.rb +90 -0
  42. data/lib/vpim/vjournal.rb +58 -0
  43. data/lib/vpim/vpim.rb +65 -0
  44. data/lib/vpim/vtodo.rb +103 -0
  45. data/lib/vpim.rb +13 -0
  46. data/mbox2vcard.rb +89 -0
  47. data/outline.sh +4 -0
  48. data/profile.rb +6 -0
  49. data/profile.txt +276 -0
  50. data/samples/README.mutt +93 -0
  51. data/samples/ab-query.rb +57 -0
  52. data/samples/agent.ru +10 -0
  53. data/samples/cmd-itip.rb +156 -0
  54. data/samples/ex_cpvcard.rb +55 -0
  55. data/samples/ex_get_vcard_photo.rb +22 -0
  56. data/samples/ex_mkv21vcard.rb +34 -0
  57. data/samples/ex_mkvcard.rb +64 -0
  58. data/samples/ex_mkyourown.rb +29 -0
  59. data/samples/ics-dump.rb +210 -0
  60. data/samples/ics-to-rss.rb +84 -0
  61. data/samples/mutt-aliases-to-vcf.rb +45 -0
  62. data/samples/osx-wrappers.rb +86 -0
  63. data/samples/reminder.rb +209 -0
  64. data/samples/rrule.rb +71 -0
  65. data/samples/tabbed-file-to-vcf.rb +390 -0
  66. data/samples/vcf-dump.rb +86 -0
  67. data/samples/vcf-lines.rb +61 -0
  68. data/samples/vcf-to-ics.rb +22 -0
  69. data/samples/vcf-to-mutt.rb +121 -0
  70. data/setup.rb +1585 -0
  71. data/stamp.rb +29 -0
  72. data/test/calendars/weather.calendar/Events/1205042405-0-0.ics +17 -0
  73. data/test/calendars/weather.calendar/Events/1205128857-1-1205128857.ics +21 -0
  74. data/test/calendars/weather.calendar/Events/1205215257-2--1884536782.ics +22 -0
  75. data/test/calendars/weather.calendar/Events/1205301657-3--679062325.ics +21 -0
  76. data/test/calendars/weather.calendar/Events/1205388057-4-526584932.ics +20 -0
  77. data/test/calendars/weather.calendar/Events/1205474457-5-1732404989.ics +21 -0
  78. data/test/calendars/weather.calendar/Events/1205560857-6--1356569450.ics +21 -0
  79. data/test/calendars/weather.calendar/Events/1205647257-7--150403793.ics +22 -0
  80. data/test/calendars/weather.calendar/Events/1205712057-8-1055761864.ics +20 -0
  81. data/test/calendars/weather.calendar/Info.plist +20 -0
  82. data/test/common.rb +51 -0
  83. data/test/test_agent_atomize.rb +84 -0
  84. data/test/test_agent_calendars.rb +128 -0
  85. data/test/test_agent_ics.rb +96 -0
  86. data/test/test_all.rb +14 -0
  87. data/test/test_date.rb +120 -0
  88. data/test/test_dur.rb +41 -0
  89. data/test/test_field.rb +156 -0
  90. data/test/test_ical.rb +437 -0
  91. data/test/test_misc.rb +13 -0
  92. data/test/test_repo.rb +129 -0
  93. data/test/test_rrule.rb +1030 -0
  94. data/test/test_vcard.rb +1017 -0
  95. data/test/test_view.rb +79 -0
  96. data/test/weekly.ics +40 -0
  97. data/vpim.gemspec +157 -0
  98. metadata +206 -0
data/test/test_date.rb ADDED
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'vpim/date'
4
+ require 'vpim/time'
5
+ require 'test/unit'
6
+
7
+ class TestVpimDate < Test::Unit::TestCase
8
+
9
+ def test_to_time
10
+ # Need to test with DateTime, but I don't have that with ruby 1.6.
11
+ assert_equal(Time.at(0), Date.new(1970, 1, 1).vpim_to_time)
12
+ assert_equal(Time.at(24 * 60 * 60), Date.new(1970, 1, 2).vpim_to_time)
13
+ end
14
+
15
+ def test_date_weekstart
16
+ assert_equal(Date.weekstart(2004, 01, 12, 'tu').to_s, Date.new(2004, 01, 6).to_s)
17
+ assert_equal(Date.weekstart(2004, 01, 12, 'we').to_s, Date.new(2004, 01, 7).to_s)
18
+ assert_equal(Date.weekstart(2004, 01, 12, 'th').to_s, Date.new(2004, 01, 8).to_s)
19
+ assert_equal(Date.weekstart(2004, 01, 12, 'fr').to_s, Date.new(2004, 01, 9).to_s)
20
+ assert_equal(Date.weekstart(2004, 01, 12, 'sa').to_s, Date.new(2004, 01, 10).to_s)
21
+ assert_equal(Date.weekstart(2004, 01, 12, 'su').to_s, Date.new(2004, 01, 11).to_s)
22
+ assert_equal(Date.weekstart(2004, 01, 12, 'mo').to_s, Date.new(2004, 01, 12).to_s)
23
+ end
24
+
25
+ def do_bywday(args, expect)
26
+ # Rewrite 'string' weekday specifications.
27
+ args = [ args[0], args[1], Date.str2wday(args[2]), args[3] ]
28
+ date = Date.bywday(*args)
29
+ dates = DateGen.bywday(*args)
30
+ need = Date.new(*expect)
31
+
32
+ assert_equal(date, need)
33
+
34
+ # Date.bywday always produces a single date, so should the generator, in
35
+ # this case.
36
+ assert_equal(dates[0], need)
37
+ end
38
+
39
+ def test_bywday
40
+
41
+ # 2004
42
+ #
43
+ # January February March
44
+ # S M Tu W Th F S S M Tu W Th F S S M Tu W Th F S
45
+ # 1 2 3 1 2 3 4 5 6 7 1 2 3 4 5 6
46
+ # 4 5 6 7 8 9 10 8 9 10 11 12 13 14 7 8 9 10 11 12 13
47
+ # 11 12 13 14 15 16 17 15 16 17 18 19 20 21 14 15 16 17 18 19 20
48
+ # 18 19 20 21 22 23 24 22 23 24 25 26 27 28 21 22 23 24 25 26 27
49
+ # 25 26 27 28 29 30 31 29 28 29 30 31
50
+ #
51
+ do_bywday([2004, 1, 4, 1], [2004, 1, 1])
52
+ do_bywday([2004, 1, 4, 2], [2004, 1, 8])
53
+ do_bywday([2004, 1, 4, -1], [2004, 1, 29])
54
+ do_bywday([2004, 1, 4, -2], [2004, 1, 22])
55
+ do_bywday([2004, 1, 4, -5], [2004, 1, 1])
56
+ do_bywday([2004,nil, 4, 1], [2004, 1, 1])
57
+ do_bywday([2004,nil, 4, 2], [2004, 1, 8])
58
+ do_bywday([2004,-12, 4, 1], [2004, 1, 1])
59
+ do_bywday([2004,-12, 4, 2], [2004, 1, 8])
60
+ do_bywday([2004,-12, 4, -1], [2004, 1, 29])
61
+ do_bywday([2004,-12, 4, -2], [2004, 1, 22])
62
+ do_bywday([2004,-12, 4, -5], [2004, 1, 1])
63
+
64
+ do_bywday([2004, 1, "th", 1], [2004, 1, 1])
65
+ do_bywday([2004, 1, "th", 2], [2004, 1, 8])
66
+ do_bywday([2004, 1, "th", -1], [2004, 1, 29])
67
+ do_bywday([2004, 1, "th", -2], [2004, 1, 22])
68
+ do_bywday([2004, 1, "th", -5], [2004, 1, 1])
69
+ do_bywday([2004,nil, "th", 1], [2004, 1, 1])
70
+ do_bywday([2004,nil, "th", 2], [2004, 1, 8])
71
+ do_bywday([2004,-12, "th", 1], [2004, 1, 1])
72
+ do_bywday([2004,-12, "th", 2], [2004, 1, 8])
73
+ do_bywday([2004,-12, "th", -1], [2004, 1, 29])
74
+ do_bywday([2004,-12, "th", -2], [2004, 1, 22])
75
+ do_bywday([2004,-12, "th", -5], [2004, 1, 1])
76
+
77
+ # October November December
78
+ # S M Tu W Th F S S M Tu W Th F S S M Tu W Th F S
79
+ # 1 2 1 2 3 4 5 6 1 2 3 4
80
+ # 3 4 5 6 7 8 9 7 8 9 10 11 12 13 5 6 7 8 9 10 11
81
+ # 10 11 12 13 14 15 16 14 15 16 17 18 19 20 12 13 14 15 16 17 18
82
+ # 17 18 19 20 21 22 23 21 22 23 24 25 26 27 19 20 21 22 23 24 25
83
+ # 24 25 26 27 28 29 30 28 29 30 26 27 28 29 30 31
84
+ # 31
85
+
86
+ do_bywday([2004, -1, 4, 1], [2004, 12, 2])
87
+ do_bywday([2004, -1, 4, -1], [2004, 12, 30])
88
+ do_bywday([2004, -1, 4, -2], [2004, 12, 23])
89
+ do_bywday([2004, -1, 4, -5], [2004, 12, 2])
90
+ do_bywday([2004,nil, 4, -1], [2004, 12, 30])
91
+ do_bywday([2004,nil, 4, -2], [2004, 12, 23])
92
+ do_bywday([2004,nil, 4, -5], [2004, 12, 2])
93
+ do_bywday([2004,nil, 4, -7], [2004, 11, 18])
94
+
95
+ end
96
+
97
+ def do_gen(args)
98
+ assert_nothing_thrown do
99
+ dates = DateGen.bywday(*args)
100
+ dates.each do |d|
101
+ assert_equal(args[0], d.year)
102
+ if(args[1])
103
+ mon = args[1]
104
+ if mon < 0
105
+ mon = 13 + args[1]
106
+ end
107
+ assert_equal(mon, d.mon)
108
+ end
109
+ assert_equal(args[2], d.wday)
110
+ end
111
+ end
112
+ end
113
+
114
+ def test_gen
115
+ do_gen([2004, 12, 1])
116
+ do_gen([2004, -1, 1])
117
+ do_gen([2004, nil, 1])
118
+ end
119
+ end
120
+
data/test/test_dur.rb ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'vpim/duration'
4
+ require 'test/unit'
5
+
6
+ include Vpim
7
+
8
+ class TestVpimDate < Test::Unit::TestCase
9
+
10
+ def duration(d0, h0, m0, s0)
11
+ # 3 hours, 2 mins, 39 secs
12
+ d = Duration.secs(d0 * 24 * 60 * 60 + h0 * 60 * 60 + m0 * 60 + s0)
13
+
14
+ assert_equal(d.secs, d0 * 24 * 60 * 60 + h0 * 60 * 60 + m0 * 60 + s0)
15
+ assert_equal(d.mins, d0 * 24 * 60 + h0 * 60 + m0)
16
+ assert_equal(d.hours, d0 * 24 + h0)
17
+ assert_equal(d.days, d0)
18
+ assert_equal(d.by_hours, [d0*24 + h0, m0, s0])
19
+ assert_equal(d.by_days, [d0, h0, m0, s0])
20
+
21
+ h, m, s = d.by_hours
22
+
23
+ assert_equal(h, h0 + d0*24)
24
+ assert_equal(m, m0)
25
+ assert_equal(s, s0)
26
+
27
+ d, h, m, s = d.by_days
28
+
29
+ assert_equal(d, d0)
30
+ assert_equal(h, h0)
31
+ assert_equal(m, m0)
32
+ assert_equal(s, s0)
33
+ end
34
+
35
+ def test_1
36
+ duration(0, 3, 2, 39)
37
+ duration(5, 23, 39, 1)
38
+ end
39
+
40
+ end
41
+
@@ -0,0 +1,156 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'pp'
5
+ require 'vpim/field'
6
+
7
+ Field=Vpim::DirectoryInfo::Field
8
+
9
+ class TestField < Test::Unit::TestCase
10
+
11
+ def test_encode_decode_text()
12
+ enc_in = "+\\\\+\\n+\\N+\\,+\\;+\\a+\\b+\\c+"
13
+ dec = Vpim.decode_text(enc_in)
14
+ #puts("<#{enc_in}> => <#{dec}>")
15
+ assert_equal("+\\+\n+\n+,+;+a+b+c+", dec)
16
+ enc_out = Vpim.encode_text(dec)
17
+ should_be = "+\\\\+\\n+\\n+\\,+\\;+a+b+c+"
18
+ # Note a, b, and c are allowed to be escaped, but shouldn't be and
19
+ # aren't in output
20
+ #puts("<#{dec}> => <#{enc_out}>")
21
+ assert_equal(should_be, enc_out)
22
+
23
+ end
24
+
25
+ def test_field4
26
+ line = 't;e=a,b: 4 '
27
+ part = Field.decode0(line)
28
+ assert_equal("4", part[ 3 ])
29
+ end
30
+
31
+ def test_field3
32
+ line = 't;e=a,b:4'
33
+ part = Field.decode0(line)
34
+ assert_equal("4", part[ 3 ])
35
+ assert_equal( {'E' => [ 'a','b' ] }, part[ 2 ])
36
+ end
37
+
38
+ def test_field2
39
+ line = 'tel;type=work,voice,msg:+1 313 747-4454'
40
+ part = Field.decode0(line)
41
+ assert_equal("+1 313 747-4454", part[ 3 ])
42
+ assert_equal( {'TYPE' => [ 'work','voice','msg' ] }, part[ 2 ])
43
+ end
44
+
45
+ def test_field1
46
+ line = 'ORGANIZER;CN="xxxx, xxxx [SC100:370:EXCH]":MAILTO:xxxx@americasm01.nt.com'
47
+ parts = Field.decode0(line)
48
+
49
+ assert_equal(nil, parts[0])
50
+ assert_equal('ORGANIZER', parts[1])
51
+ assert_equal({ 'CN' => [ "xxxx, xxxx [SC100:370:EXCH]" ] }, parts[2])
52
+ assert_equal('MAILTO:xxxx@americasm01.nt.com', parts[3])
53
+ end
54
+
55
+ =begin this can not be done :-(
56
+ def test_case_equiv
57
+ line = 'ORGANIZER;CN="xxxx, xxxx [SC100:370:EXCH]":MAILTO:xxxx@americasm01.nt.com'
58
+ field = Field.decode(line)
59
+ assert_equal(true, field.name?('organIZER'))
60
+ assert_equal(true, field === 'organIZER')
61
+
62
+ b = nil
63
+ case field
64
+ when 'organIZER'
65
+ b = true
66
+ end
67
+
68
+ assert_equal(true, b)
69
+ end
70
+ =end
71
+
72
+ def test_field0
73
+ assert_equal('name:', line = Field.encode0(nil, 'name'))
74
+ assert_equal([ nil, 'NAME', {}, ''], Field.decode0(line))
75
+
76
+ assert_equal('name:value', line = Field.encode0(nil, 'name', {}, 'value'))
77
+ assert_equal([ nil, 'NAME', {}, 'value'], Field.decode0(line))
78
+
79
+ assert_equal('name;encoding=B:dmFsdWU=', line = Field.encode0(nil, 'name', { 'encoding'=>:b64 }, 'value'))
80
+ assert_equal([ nil, 'NAME', { 'ENCODING'=>['B']}, ['value'].pack('m').chomp ], Field.decode0(line))
81
+
82
+ assert_equal('group.name:value', line = Field.encode0('group', 'name', {}, 'value'))
83
+ assert_equal([ 'GROUP', 'NAME', {}, 'value'], Field.decode0(line))
84
+ end
85
+
86
+ def tEst_invalid_fields
87
+ [
88
+ 'g.:',
89
+ ':v',
90
+ ].each do |line|
91
+ assert_raises(Vpim::InvalidEncodingError) { Field.decode0(line) }
92
+ end
93
+ end
94
+
95
+ def test_date_encode
96
+ assert_equal("DTSTART:20040101\n", Field.create('DTSTART', Date.new(2004, 1, 1) ).to_s)
97
+ assert_equal("DTSTART:20040101\n", Field.create('DTSTART', [Date.new(2004, 1, 1)]).to_s)
98
+ end
99
+
100
+ def test_field_modify
101
+ f = Field.create('name')
102
+
103
+ assert_equal('', f.value)
104
+ f.value = ''
105
+ assert_equal('', f.value)
106
+ f.value = 'z'
107
+ assert_equal('z', f.value)
108
+
109
+ f.group = 'z.b'
110
+ assert_equal('Z.B', f.group)
111
+ assert_equal("z.b.NAME:z\n", f.encode)
112
+
113
+ assert_raises(TypeError) { f.value = :group }
114
+
115
+ assert_equal('Z.B', f.group)
116
+
117
+ assert_equal("z.b.NAME:z\n", f.encode)
118
+
119
+ assert_raises(TypeError) { f.group = :group }
120
+
121
+ assert_equal("z.b.NAME:z\n", f.encode)
122
+ assert_equal('Z.B', f.group)
123
+
124
+ f['p0'] = "hi julie"
125
+
126
+ assert_equal("Z.B.NAME;P0=hi julie:z\n", f.encode)
127
+ assert_equal(['hi julie'], f.param('p0'))
128
+ assert_equal(['hi julie'], f['p0'])
129
+ assert_equal('NAME', f.name)
130
+ assert_equal('Z.B', f.group)
131
+
132
+ # FAIL assert_raises(ArgumentError) { f.group = 'z.b:' }
133
+
134
+ assert_equal('Z.B', f.group)
135
+
136
+ f.value = 'some text'
137
+
138
+ assert_equal('some text', f.value)
139
+ assert_equal('some text', f.value_raw)
140
+
141
+ f['encoding'] = :b64
142
+
143
+ assert_equal('some text', f.value)
144
+ assert_equal([ 'some text' ].pack('m*').chomp, f.value_raw)
145
+ end
146
+
147
+ def test_field_wrapping
148
+ assert_equal("0:x\n", Vpim::DirectoryInfo::Field.create('0', 'x' * 1).encode(4))
149
+ assert_equal("0:xx\n", Vpim::DirectoryInfo::Field.create('0', 'x' * 2).encode(4))
150
+ assert_equal("0:xx\n x\n", Vpim::DirectoryInfo::Field.create('0', 'x' * 3).encode(4))
151
+ assert_equal("0:xx\n xx\n", Vpim::DirectoryInfo::Field.create('0', 'x' * 4).encode(4))
152
+ assert_equal("0:xx\n xxxx\n", Vpim::DirectoryInfo::Field.create('0', 'x' * 6).encode(4))
153
+ assert_equal("0:xx\n xxxx\n x\n", Vpim::DirectoryInfo::Field.create('0', 'x' * 7).encode(4))
154
+ end
155
+ end
156
+