xing-vpim 0.658.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/CHANGES +504 -0
  2. data/COPYING +58 -0
  3. data/README +182 -0
  4. data/bin/reminder +203 -0
  5. data/bin/rrule +71 -0
  6. data/lib/atom.rb +728 -0
  7. data/lib/atom/pub.rb +206 -0
  8. data/lib/atom/version.rb +9 -0
  9. data/lib/atom/xml/parser.rb +305 -0
  10. data/lib/plist.rb +22 -0
  11. data/lib/plist/generator.rb +224 -0
  12. data/lib/plist/parser.rb +225 -0
  13. data/lib/vpim.rb +13 -0
  14. data/lib/vpim/address.rb +219 -0
  15. data/lib/vpim/attachment.rb +102 -0
  16. data/lib/vpim/date.rb +222 -0
  17. data/lib/vpim/dirinfo.rb +277 -0
  18. data/lib/vpim/duration.rb +119 -0
  19. data/lib/vpim/enumerator.rb +32 -0
  20. data/lib/vpim/field.rb +614 -0
  21. data/lib/vpim/icalendar.rb +381 -0
  22. data/lib/vpim/maker/vcard.rb +16 -0
  23. data/lib/vpim/property/base.rb +193 -0
  24. data/lib/vpim/property/common.rb +315 -0
  25. data/lib/vpim/property/location.rb +49 -0
  26. data/lib/vpim/property/priority.rb +43 -0
  27. data/lib/vpim/property/recurrence.rb +69 -0
  28. data/lib/vpim/property/resources.rb +24 -0
  29. data/lib/vpim/repo.rb +181 -0
  30. data/lib/vpim/rfc2425.rb +367 -0
  31. data/lib/vpim/rrule.rb +591 -0
  32. data/lib/vpim/time.rb +40 -0
  33. data/lib/vpim/vcard.rb +1429 -0
  34. data/lib/vpim/version.rb +18 -0
  35. data/lib/vpim/vevent.rb +188 -0
  36. data/lib/vpim/view.rb +90 -0
  37. data/lib/vpim/vjournal.rb +58 -0
  38. data/lib/vpim/vpim.rb +65 -0
  39. data/lib/vpim/vtodo.rb +103 -0
  40. data/samples/README.mutt +93 -0
  41. data/samples/ab-query.rb +57 -0
  42. data/samples/cmd-itip.rb +156 -0
  43. data/samples/ex_cpvcard.rb +55 -0
  44. data/samples/ex_get_vcard_photo.rb +22 -0
  45. data/samples/ex_mkv21vcard.rb +34 -0
  46. data/samples/ex_mkvcard.rb +64 -0
  47. data/samples/ex_mkyourown.rb +29 -0
  48. data/samples/ics-dump.rb +210 -0
  49. data/samples/ics-to-rss.rb +84 -0
  50. data/samples/mutt-aliases-to-vcf.rb +45 -0
  51. data/samples/osx-wrappers.rb +86 -0
  52. data/samples/reminder.rb +203 -0
  53. data/samples/rrule.rb +71 -0
  54. data/samples/tabbed-file-to-vcf.rb +390 -0
  55. data/samples/vcf-dump.rb +86 -0
  56. data/samples/vcf-lines.rb +61 -0
  57. data/samples/vcf-to-ics.rb +22 -0
  58. data/samples/vcf-to-mutt.rb +121 -0
  59. data/test/test_all.rb +17 -0
  60. data/test/test_date.rb +120 -0
  61. data/test/test_dur.rb +41 -0
  62. data/test/test_field.rb +156 -0
  63. data/test/test_ical.rb +415 -0
  64. data/test/test_repo.rb +158 -0
  65. data/test/test_rrule.rb +1030 -0
  66. data/test/test_vcard.rb +973 -0
  67. data/test/test_view.rb +79 -0
  68. metadata +132 -0
data/COPYING ADDED
@@ -0,0 +1,58 @@
1
+ vPim is copyrighted free software by Sam Roberts <sroberts@uniserve.com>.
2
+
3
+ You can redistribute it and/or modify it under either the terms of the GPL (see
4
+ the file GPL), or the conditions below:
5
+
6
+ 1. You may make and give away verbatim copies of the source form of the
7
+ software without restriction, provided that you duplicate all of the
8
+ original copyright notices and associated disclaimers.
9
+
10
+ 2. You may modify your copy of the software in any way, provided that
11
+ you do at least ONE of the following:
12
+
13
+ a) place your modifications in the Public Domain or otherwise make them
14
+ Freely Available, such as by posting said modifications to Usenet or an
15
+ equivalent medium, or by allowing the author to include your
16
+ modifications in the software.
17
+
18
+ b) use the modified software only within your corporation or
19
+ organization.
20
+
21
+ c) give non-standard binaries non-standard names, with instructions on
22
+ where to get the original software distribution.
23
+
24
+ d) make other distribution arrangements with the author.
25
+
26
+ 3. You may distribute the software in object code or binary form,
27
+ provided that you do at least ONE of the following:
28
+
29
+ a) distribute the binaries and library files of the software, together
30
+ with instructions (in the manual page or equivalent) on where to get the
31
+ original distribution.
32
+
33
+ b) accompany the distribution with the machine-readable source of the
34
+ software.
35
+
36
+ c) give non-standard binaries non-standard names, with instructions on
37
+ where to get the original software distribution.
38
+
39
+ d) make other distribution arrangements with the author.
40
+
41
+ 4. You may modify and include the part of the software into any other
42
+ software (possibly commercial). But some files in the distribution
43
+ are not written by the author, so that they are not under these terms.
44
+
45
+ For the list of those files and their copying conditions, see the
46
+ file LEGAL.
47
+
48
+ 5. The scripts and library files supplied as input to or produced as
49
+ output from the software do not automatically fall under the
50
+ copyright of the software, but belong to whomever generated them,
51
+ and may be sold commercially, and may be aggregated with this
52
+ software.
53
+
54
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
55
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
56
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57
+ PURPOSE.
58
+
data/README ADDED
@@ -0,0 +1,182 @@
1
+ Author:: Sam Roberts <vieuxtech@gmail.com>
2
+ Copyright:: Copyright (C) 2008 Sam Roberts
3
+ License:: May be distributed under the same terms as Ruby
4
+ Homepage:: http://vpim.rubyforge.org
5
+ Download:: http://rubyforge.org/projects/vpim
6
+ Install:: sudo gem install vpim
7
+
8
+ vPim provides calendaring, scheduling, and contact support for Ruby through the
9
+ standard iCalendar and vCard data formats for "personal information" exchange.
10
+
11
+ = Thanks
12
+
13
+ - http://ZipDX.com: for sponsoring development of FREQ=weekly and BYSETPOS in
14
+ recurrence rules.
15
+ - http://RubyForge.org: for their generous hosting of this project.
16
+
17
+ = Installation
18
+
19
+ There is a vPim package installable using ruby-gems:
20
+
21
+ # sudo gem install vpim (may require root privilege)
22
+
23
+ It is also installable in the standard way. Untar the package, and do:
24
+
25
+ $ ruby setup.rb --help
26
+
27
+ or do:
28
+
29
+ $ ruby setup.rb config
30
+ $ ruby setup.rb setup
31
+ # ruby setup.rb install (may require root privilege)
32
+
33
+ = Overview
34
+
35
+ vCard (RFC 2426) is a format for personal information, see Vpim::Vcard and
36
+ Vpim::Maker::Vcard.
37
+
38
+ iCalendar (RFC 2445) is a format for calendar related information, see
39
+ Vpim::Icalendar.
40
+
41
+ vCard and iCalendar support is built on top of an implementation of the MIME
42
+ Content-Type for Directory Information (RFC 2425). The basic RFC 2425 format is
43
+ implemented by Vpim::DirectoryInfo and Vpim::DirectoryInfo::Field.
44
+
45
+ The libary is quite useful, but improvements are ongoing. If you find
46
+ something missing or have suggestions, please contact me. I can't promise
47
+ instantaneous turnaround, but I might be able to suggest another approach, and
48
+ features requested by users of vPim go to the top of the todo list. If you need
49
+ a feature for a commercial project, consider sponsoring development.
50
+
51
+ = Examples
52
+
53
+ Here's an example to give a sense for how iCalendars are encoded and decoded:
54
+
55
+ require 'vpim/icalendar'
56
+
57
+ cal = Vpim::Icalendar.create2
58
+
59
+ cal.add_event do |e|
60
+ e.dtstart Date.new(2005, 04, 28)
61
+ e.dtend Date.new(2005, 04, 29)
62
+ e.summary "Monthly meet-the-CEO day"
63
+ e.description <<'---'
64
+ Unlike last one, this meeting will change your life because
65
+ we are going to discuss your likely demotion if your work isn't
66
+ done soon.
67
+ ---
68
+ e.categories [ 'APPOINTMENT' ]
69
+ e.categories do |c| c.push 'EDUCATION' end
70
+ e.url 'http://www.example.com'
71
+ e.sequence 0
72
+ e.access_class "PRIVATE"
73
+ e.transparency 'OPAQUE'
74
+
75
+ now = Time.now
76
+ e.created now
77
+ e.lastmod now
78
+
79
+
80
+ e.organizer do |o|
81
+ o.cn = "Example Organizer, Mr."
82
+ o.uri = "mailto:organizer@example.com"
83
+ end
84
+
85
+ attendee = Vpim::Icalendar::Address.create("mailto:attendee@example.com")
86
+ attendee.rsvp = true
87
+ e.add_attendee attendee
88
+ end
89
+
90
+ icsfile = cal.encode
91
+
92
+ puts '--- Encode:'
93
+
94
+ puts icsfile
95
+
96
+ puts '--- Decode:'
97
+
98
+ cal = Vpim::Icalendar.decode(icsfile).first
99
+
100
+ cal.components do |e|
101
+ puts e.summary
102
+ puts e.description
103
+ puts e.dtstart.to_s
104
+ puts e.dtend.to_s
105
+ end
106
+
107
+ This produces:
108
+
109
+ --- Encode:
110
+ BEGIN:VCALENDAR
111
+ VERSION:2.0
112
+ PRODID:-//Ensemble Independent//vPim 0.357//EN
113
+ CALSCALE:Gregorian
114
+ BEGIN:VEVENT
115
+ DTSTART;VALUE=DATE:20050428
116
+ DTEND;VALUE=DATE:20050429
117
+ SUMMARY:Monthly meet-the-CEO day
118
+ DESCRIPTION:Unlike last one, this meeting will change your life because\nwe
119
+ are going to discuss your likely demotion if your work isn't\ndone soon.\n
120
+ CATEGORIES:APPOINTMENT,EDUCATION
121
+ URL:http://www.example.com
122
+ SEQUENCE:0
123
+ CLASS:PRIVATE
124
+ CREATED:20060402T231755
125
+ LAST-MODIFIED:20060402T231755
126
+ ORGANIZER;CN="Example Organizer, Mr.":mailto:organizer@example.com
127
+ ATTENDEE;RSVP=true:mailto:attendee@example.com
128
+ END:VEVENT
129
+ END:VCALENDAR
130
+ --- Decode:
131
+ Monthly meet-the-CEO day
132
+ Unlike last one, this meeting will change your life because
133
+ we are going to discuss your likely demotion if your work isn't
134
+ done soon.
135
+ Thu Apr 28 00:00:00 UTC 2005
136
+ Fri Apr 29 00:00:00 UTC 2005
137
+
138
+
139
+ More examples of using vPim are provided in samples/.
140
+
141
+ vCard examples are:
142
+ - link:ex_mkvcard.txt: example of creating a vCard
143
+ - link:ex_cpvcard.txt: example of copying and them modifying a vCard
144
+ - link:ex_mkv21vcard.txt: example of creating version 2.1 vCard
145
+ - link:mutt-aliases-to-vcf.txt: convert a mutt aliases file to vCards
146
+ - link:ex_get_vcard_photo.txt: pull photo data from a vCard
147
+ - link:ab-query.txt: query the OS X Address Book to find vCards
148
+ - link:vcf-to-mutt.txt: query vCards for matches, output in formats useful
149
+ with Mutt (see link:README.mutt for details)
150
+ - link:tabbed-file-to-vcf.txt: convert a tab-delimited file to vCards, a
151
+ (small but) complete application contributed by Dane G. Avilla, thanks!
152
+ - link:vcf-to-ics.txt: example of how to create calendars of birthdays from vCards
153
+ - link:vcf-dump.txt: utility for dumping contents of .vcf files
154
+
155
+ iCalendar examples are:
156
+ - link:ics-to-rss.txt: prints todos as RSS, or starts a WEBrick servlet
157
+ that publishes todos as a RSS feed. Thanks to Dave Thomas for this idea,
158
+ from http://pragprog.com/pragdave/Tech/Blog/ToDos.rdoc.
159
+ - link:cmd-itip.txt: prints emailed iCalendar invitations in human-readable
160
+ form, and see link:README.mutt for instruction on mutt integration. I get
161
+ a lot of meeting invitations from Lotus Notes/Domino users at work, and
162
+ this is pretty useful in figuring out where and when I am supposed to be.
163
+ - link:reminder.txt: prints upcoming events and todos, by default from
164
+ Apple's iCal calendars
165
+ - link:rrule.txt: utility for printing recurrence rules
166
+ - link:ics-dump.txt: utility for dumping contents of .ics files
167
+
168
+ = Project Information
169
+
170
+ vPim can be downloaded from the Ruby Forge project page:
171
+
172
+ - http://rubyforge.org/projects/vpim
173
+
174
+ or installed as a gem:
175
+
176
+ - sudo gem install vpim
177
+
178
+ For notifications about new releases, or to ask questions about vPim, please
179
+ subscribe to "vpim-talk":
180
+
181
+ - http://rubyforge.org/mailman/listinfo/vpim-talk
182
+
data/bin/reminder ADDED
@@ -0,0 +1,203 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $-w = true
4
+
5
+ require 'ubygems' rescue "ignored"
6
+
7
+ require 'getoptlong'
8
+ require 'pp'
9
+ require 'plist'
10
+
11
+ require 'vpim/repo'
12
+
13
+ $stdout.sync = true
14
+ $stderr.sync = true
15
+
16
+ HELP =<<EOF
17
+ Usage: #{$0} [where]
18
+
19
+ Shows events and todos occuring soon.
20
+
21
+ By default, the Apple iCal v3 calendars are used, but if a location where
22
+ .ics files is specified, any calendars found there will be used.
23
+
24
+ Options
25
+ -h,--help Print this helpful message.
26
+ -n,--days N How many of the next days are considered to be "soon", default
27
+ is seven.
28
+ -v,--verbose Print more information about upcoming events.
29
+ EOF
30
+
31
+ opt_debug = nil
32
+ opt_verbose = nil
33
+ opt_days = 7
34
+
35
+ opts = GetoptLong.new(
36
+ [ "--help", "-h", GetoptLong::NO_ARGUMENT ],
37
+ [ "--days", "-n", GetoptLong::REQUIRED_ARGUMENT ],
38
+ [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ],
39
+ [ "--debug", "-d", GetoptLong::NO_ARGUMENT ]
40
+ )
41
+
42
+ opts.each do |opt, arg|
43
+ case opt
44
+ when "--help" then
45
+ puts HELP
46
+ exit 0
47
+
48
+ when "--days" then
49
+ opt_days = arg.to_i
50
+
51
+ when "--verbose" then
52
+ opt_verbose = true
53
+
54
+ when "--debug" then
55
+ opt_verbose = true
56
+ opt_debug = true
57
+ end
58
+ end
59
+
60
+ calendars = []
61
+
62
+ if ARGV.length > 0
63
+ Vpim::Repo::Directory.each(ARGV.first) do |cal|
64
+ calendars << cal
65
+ end
66
+ else
67
+ Vpim::Repo::Ical3.each() do |cal|
68
+ calendars << cal
69
+ end
70
+ end
71
+
72
+ if opt_debug
73
+ pp ARGV
74
+ pp calendars
75
+ end
76
+
77
+ SECSPERDAY = (24 * 60 * 60)
78
+
79
+ t0 = Time.new.to_a
80
+ t0[0] = t0[1] = t0[2] = 0 # sec,min,hour = 0
81
+ t0 = Time.local(*t0)
82
+ t1 = t0 + opt_days * SECSPERDAY
83
+
84
+ if opt_debug
85
+ puts "to: #{t0}"
86
+ puts "t1: #{t1}"
87
+ end
88
+
89
+ if opt_verbose
90
+ puts "Events in the next #{opt_days} days:"
91
+ end
92
+
93
+ # Collect all events, then all todos.
94
+ all_events = []
95
+ all_todos = []
96
+
97
+ calendars.each do |cal|
98
+ if opt_debug; puts cal.name; end
99
+
100
+ begin
101
+ cal.events.each do |e|
102
+ begin
103
+ if opt_debug; pp e; end
104
+ if e.occurs_in?(t0, t1)
105
+ if e.summary
106
+ all_events.push(e)
107
+ end
108
+ end
109
+ rescue
110
+ $stderr.puts "error in #{cal.name} (\"#{e.summary}\"): #{$!.to_s}"
111
+ end
112
+ end
113
+
114
+ all_todos.concat(cal.todos)
115
+ end
116
+ end
117
+
118
+ puts
119
+
120
+ def start_of_first_occurrence(t0, t1, e)
121
+ e.occurrences(t1) do |t|
122
+ # An event might start before t0, but end after it..., in which case
123
+ # we are still interested.
124
+ if (t + (e.duration || 0)) >= t0
125
+ return t
126
+ end
127
+ end
128
+ nil
129
+ end
130
+
131
+ all_events.sort! do |lhs, rhs|
132
+ start_of_first_occurrence(t0, t1, lhs) <=> start_of_first_occurrence(t0, t1, rhs)
133
+ end
134
+
135
+ all_events.each do |e|
136
+ puts "#{e.summary}:"
137
+
138
+ if opt_verbose
139
+ if e.description; puts " description=#{e.description}"; end
140
+ if e.comments; puts " comment=#{e.comments.first}"; end
141
+ if e.location; puts " location=#{e.location}"; end
142
+ if e.status; puts " status=#{e.status}"; end
143
+ if e.dtstart; puts " dtstart=#{e.dtstart}"; end
144
+ if e.duration; puts " duration=#{Vpim::Duration.new(e.duration).to_s}"; end
145
+ end
146
+
147
+ i = 1
148
+ e.occurrences.each_until(t1).each do |t|
149
+ # An event might start before t0, but end after it..., in which case
150
+ # we are still interested.
151
+ dstr = ''
152
+ if e.duration
153
+ d = e.duration
154
+ dstr = " for #{Vpim::Duration.new(e.duration).to_s}"
155
+ end
156
+
157
+ if (t + (e.duration || 0)) >= t0
158
+ puts " ##{i} on #{t}#{dstr}"
159
+ i += 1
160
+ end
161
+ end
162
+ end
163
+
164
+ =begin
165
+ def fix_priority(vtodo)
166
+ p = vtodo.priority
167
+ if !p
168
+ p = 10
169
+
170
+ end
171
+ =end
172
+
173
+ all_todos.sort! do |x,y|
174
+ x = x.priority
175
+ y = y.priority
176
+
177
+ # 0 means no priority, put these last, not first
178
+ x = 10 if x == 0
179
+ y = 10 if y == 0
180
+
181
+ x <=> y
182
+ end
183
+
184
+ priorities = [
185
+ 'no importance',
186
+ 'very important',
187
+ 'very important',
188
+ 'very important',
189
+ 'important',
190
+ 'important',
191
+ 'important',
192
+ 'not important',
193
+ 'not important',
194
+ 'not important'
195
+ ]
196
+
197
+ all_todos.each do |e|
198
+ status = e.status || 'Todo'
199
+ if status != 'COMPLETED'
200
+ puts "#{status.capitalize}: #{e.summary}" # (#{priorities[e.priority]})"
201
+ end
202
+ end
203
+
data/bin/rrule ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $-w = true
4
+ $:.unshift File.dirname($0) + "/../lib"
5
+
6
+ require 'vpim/rrule'
7
+ require 'getoptlong'
8
+ require 'parsedate'
9
+
10
+ HELP =<<EOF
11
+ Usage: #{$0} [options] rrule
12
+
13
+ Options
14
+ -h,--help Print this helpful message.
15
+ -t,--start Start time for recurrence rule, defaults to current time.
16
+
17
+ Examples:
18
+
19
+ FREQ=DAILY;COUNT=10
20
+ FREQ=DAILY;UNTIL=19971224T000000Z
21
+ FREQ=DAILY;INTERVAL=2
22
+ FREQ=DAILY;INTERVAL=10;COUNT=5
23
+
24
+ Demonstrate DST time change:
25
+
26
+ #{$0} --start '2004-04-03 02:00' 'FREQ=daily;count=3'
27
+ #{$0} --start '2004-10-30 02:00' 'FREQ=daily;count=3'
28
+
29
+ Note: In the US DST starts at 2AM, on the first Sunday of April, and reverts
30
+ at 2AM on the last Sunday of October.
31
+
32
+ EOF
33
+
34
+ dtstart = Time.new
35
+
36
+ opts = GetoptLong.new(
37
+ [ "--help", "-h", GetoptLong::NO_ARGUMENT ],
38
+ [ "--start", "-t", GetoptLong::REQUIRED_ARGUMENT]
39
+ )
40
+
41
+ opts.each do |opt, arg|
42
+ case opt
43
+ when "--help" then
44
+ puts HELP
45
+ exit 0
46
+
47
+ when "--start" then
48
+ date = ParseDate.parsedate(arg)
49
+ date.pop
50
+ date.pop
51
+ dtstart = Time.local(*date)
52
+ end
53
+ end
54
+
55
+ if ARGV.length < 1
56
+ puts "no rrule specified, try -h!\n"
57
+ exit 1
58
+ end
59
+
60
+ puts "Start: #{Vpim.encode_date_time(dtstart)}"
61
+
62
+ ARGV.each do |rule|
63
+ rrule = Vpim::Rrule.new(dtstart, rule)
64
+
65
+ puts "Rule: #{rule}"
66
+
67
+ rrule.each_with_index do |t, count|
68
+ puts format("count=%3d %s", count, t.to_s)
69
+ end
70
+ end
71
+