Git Product home page Git Product logo

vpim's Introduction

Author

Sam Roberts <[email protected]>

Copyright

Copyright © 2008 Sam Roberts

License

May be distributed under the same terms as Ruby

Homepage

vpim.rubyforge.org

Install

gem install vpim

vPim provides calendaring, scheduling, and contact support for Ruby through the standard iCalendar and vCard data formats for “personal information” exchange.

Thanks

  • ZipDX.com: for sponsoring development of FREQ=weekly and BYSETPOS in recurrence rules.

  • RubyForge.org: for their generous hosting of this project.

Installation

There is a vPim package installable using ruby-gems:

# gem install vpim (may require root privilege)

Overview

vCard (RFC 2426) is a format for personal information, see Vpim::Vcard and Vpim::Maker::Vcard.

iCalendar (RFC 2445) is a format for calendar related information, see Vpim::Icalendar.

vCard and iCalendar support is built on top of an implementation of the MIME Content-Type for Directory Information (RFC 2425). The basic RFC 2425 format is implemented by Vpim::DirectoryInfo and Vpim::DirectoryInfo::Field.

The libary is quite useful, but improvements are ongoing. If you find something missing or have suggestions, please contact me. I can’t promise instantaneous turnaround, but I might be able to suggest another approach, and features requested by users of vPim go to the top of the todo list. If you need a feature for a commercial project, consider sponsoring development.

Examples

Here’s an example to give a sense for how iCalendars are encoded and decoded:

require 'vpim/icalendar'

cal = Vpim::Icalendar.create2

cal.add_event do |e|
  e.dtstart       Date.new(2005, 04, 28)
  e.dtend         Date.new(2005, 04, 29)
  e.summary       "Monthly meet-the-CEO day"
  e.description <<'---'
Unlike last one, this meeting will change your life because
we are going to discuss your likely demotion if your work isn't
done soon.
---
  e.categories    [ 'APPOINTMENT' ]
  e.categories do |c| c.push 'EDUCATION' end
  e.url           'http://www.example.com'
  e.sequence      0
  e.access_class  "PRIVATE"
  e.transparency  'OPAQUE'

  now = Time.now
  e.created       now
  e.lastmod       now

  e.organizer do |o|
    o.cn = "Example Organizer, Mr."
    o.uri = "mailto:[email protected]"
  end

  attendee = Vpim::Icalendar::Address.create("mailto:[email protected]")
  attendee.rsvp = true
  e.add_attendee attendee
end

icsfile = cal.encode

puts '--- Encode:'

puts icsfile

puts '--- Decode:'

cal = Vpim::Icalendar.decode(icsfile).first

cal.components do |e|
  puts e.summary
  puts e.description
  puts e.dtstart.to_s
  puts e.dtend.to_s
end

This produces:

--- Encode:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Ensemble Independent//vPim 0.357//EN
CALSCALE:Gregorian
BEGIN:VEVENT
DTSTART;VALUE=DATE:20050428
DTEND;VALUE=DATE:20050429
SUMMARY:Monthly meet-the-CEO day
DESCRIPTION:Unlike last one, this meeting will change your life because\nwe
  are going to discuss your likely demotion if your work isn't\ndone soon.\n
CATEGORIES:APPOINTMENT,EDUCATION
URL:http://www.example.com
SEQUENCE:0
CLASS:PRIVATE
CREATED:20060402T231755
LAST-MODIFIED:20060402T231755
ORGANIZER;CN="Example Organizer, Mr.":mailto:[email protected]
ATTENDEE;RSVP=true:mailto:[email protected]
END:VEVENT
END:VCALENDAR
--- Decode:
Monthly meet-the-CEO day
Unlike last one, this meeting will change your life because
we are going to discuss your likely demotion if your work isn't
done soon.
Thu Apr 28 00:00:00 UTC 2005
Fri Apr 29 00:00:00 UTC 2005

More examples of using vPim are provided in samples/.

vCard examples are:

iCalendar examples are:

  • ics-to-rss.txt: prints todos as RSS, or starts a WEBrick servlet that publishes todos as a RSS feed. Thanks to Dave Thomas for this idea, from pragprog.com/pragdave/Tech/Blog/ToDos.rdoc.

  • cmd-itip.txt: prints emailed iCalendar invitations in human-readable form, and see README.mutt for instruction on mutt integration. I get a lot of meeting invitations from Lotus Notes/Domino users at work, and this is pretty useful in figuring out where and when I am supposed to be.

  • reminder.txt: prints upcoming events and todos, by default from Apple’s iCal calendars

  • rrule.txt: utility for printing recurrence rules

  • ics-dump.txt: utility for dumping contents of .ics files

Project Information

vPim can be downloaded from the Ruby Forge project page:

or installed as a gem:

  • sudo gem install vpim

For notifications about new releases, or to ask questions about vPim, please subscribe to “vpim-talk”:

vpim's People

Contributors

ahorek avatar dpocock avatar henrycatalinismith avatar pkunducere avatar ralph avatar rlivsey avatar sam-github avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vpim's Issues

Vtodo support?

I notice you haven't yet implemented add_todo or put a Maker in Vtodo

Do you know if those are implemented in any branch or fork of the project or would you welcome a pull request to add those things?

ADR fields with quoted-printable encoding not decoded

Crossposted from vcard on request of qoobaa.

I produced an Android vCard export; here's an excerpt:

BEGIN:VCARD
VERSION:2.1
FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=65=66=67=20=68=69=70
ADR;HOME;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;;=53=74=65=72=6E=73=74=72=61=C3=9F=65=20=31=30;=46=72=61=6E=6B=66=75=72=74;=48=65=73=73=65=6E;=36=30=33=31=38;=44=65=75=74=73=63=68=6C=61=6E=64
END:VCARD

As you will notice vcard will not decode the address field parameters (street, postalcode, etc.) because it uses the values_raw to split the parameters instead of the values (Method Address.decode(card, field) ):

parts = ::Vcard.decode_text_list(field.value_raw, ";")

After I changed it to use field.value instead it worked as expected.

Invalid Encoding Error (Unescaped Line Break)

Hi @sam-github
First I would like to thank you for the effort in this gem, really helpful!
So here is the problem I'm facing: I was testing with my customer an importing contacts feature using vCard files, so I've decided to use vpim gem to read files and then perform my business logic over the decoded file. The client reported a problem while trying to import a file, so I found out that the generated file has a line like this:

item2.TEL:777-888-9999
item2.X-ABLabel:Other
VOICE

With an unescaped line break. I've also noticed that between Other and VOICE there is just a LF character. According to the RFC 6350 https://tools.ietf.org/html/rfc6350 the delimiting character between lines should be CRLF, and I was able to overcome this situation with the following monkeypatch:

module Vpim
  #enforce CRLF line break according to RFC 6350 Session 3.2 https://tools.ietf.org/html/rfc6350
  def Vpim.unfold(card) # :nodoc:
    unfolded = []
    card.each_line("\r\n") do |line|
      line.chomp!
      # If it's a continuation line, add it to the last.
      # If it's an empty line, drop it from the input.
      if( line =~ /^[ \t]/ )
        unfolded[-1] << line[1, line.size-1]
      elsif (unfolded.last && unfolded.last =~ /;ENCODING=QUOTED-PRINTABLE:.*?=$/)
        unfolded.last << line
      elsif( line =~ /^$/ )
      else
        unfolded << line
      end
    end
    unfolded
  end
end

But I don't know how safe is to use this solution, do you have any ideas on this?
Thanks a lot!

uninitialized constant Enumerable::Enumerator

I'm trying to look at recurrences of a calendar event and running into that error

Here's my code

  calendars = Vpim::Icalendar.decode(ics)
  calendars.each do |calendar|
    cal_data = calendar.
        select  { |event| event.occurs_in?(Time.now, Time.now + 86400 * 10) }.
        collect { |event| event_hash(event) }.
        sort_by { |event| event['end'] }.
        each    { |event| puts event }
  end

The full trace is here

/opt/rubies/2.1.2/lib/ruby/gems/2.1.0/gems/vpim-13.11.11/lib/vpim/property/recurrence.rb:40:in `occurrences': uninitialized constant Enumerable::Enumerator (NameError)
    from jobs/confluence_calendar.rb:44:in `block (3 levels) in <main>'
    from /opt/rubies/2.1.2/lib/ruby/gems/2.1.0/gems/vpim-13.11.11/lib/vpim/icalendar.rb:347:in `block in components'
    from /opt/rubies/2.1.2/lib/ruby/gems/2.1.0/gems/vpim-13.11.11/lib/vpim/icalendar.rb:345:in `each'
    from /opt/rubies/2.1.2/lib/ruby/gems/2.1.0/gems/vpim-13.11.11/lib/vpim/icalendar.rb:345:in `components'
    from /opt/rubies/2.1.2/lib/ruby/gems/2.1.0/gems/vpim-13.11.11/lib/vpim/icalendar.rb:364:in `each'
    from jobs/confluence_calendar.rb:43:in `select'
    from jobs/confluence_calendar.rb:43:in `block (2 levels) in <main>'
    from jobs/confluence_calendar.rb:40:in `each'
    from jobs/confluence_calendar.rb:40:in `block in <main>'
    from jobs/confluence_calendar.rb:34:in `each'
    from jobs/confluence_calendar.rb:34:in `<main>'

I'm using ruby 2.1.2 and vpim 13.11.11 if that makes a difference.

travis-ci registration

Can you please create a travis-ci account for the project?

I will then submit a PR with the .travis.yml config file.

However, as project owner, you need to request the link to travis-ci

New gem using gemcutter

Hi Sam,

First of all.. thanks for the vpim stuff. Really great!

Would really be great to get an updated vpim gem. I tried building it myself but had to change the vpim.gemspec (there also is a typo on line 1 :)).

Would be great to have an updated version on gemcutter!

Thanks!

Joost

make gemspec usable via bundler git dependency

gem "vpim",                 :git => "https://github.com/sam-github/vpim.git"

this does not work, would be nice to try out the new changes,
otherwise please release a new version I'd like to try it.

Also the sourcecode url is missing from rubygems.org/gems/vpim, would make it easier to find the repo

@sam-github

Vpim::Icalendar incorrectly decoding `US/Pacific` timezone events during DST

Given a test.ics file with the following VTIMEZONE defined:

BEGIN:VTIMEZONE
TZID:US/Pacific
BEGIN:DAYLIGHT
TZOFFSETFROM:-0800
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
DTSTART:20070311T020000
TZNAME:PDT
TZOFFSETTO:-0700
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0700
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
DTSTART:20071104T020000
TZNAME:PST
TZOFFSETTO:-0800
END:STANDARD
END:VTIMEZONE

and a first event such as:

BEGIN:VEVENT
SUMMARY:Redacted
PRIORITY:5
X-MICROSOFT-CDO-BUSYSTATUS:BUSY
X-MICROSOFT-CDO-IMPORTANCE:1
CLASS:PUBLIC
TRANSP:OPAQUE
UID:redacted
DTSTART;TZID=US/Pacific:20180626T120000
SEQUENCE:0
X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY
X-MICROSOFT-CDO-APPT-SEQUENCE:0
X-MICROSOFT-CDO-INSTTYPE:0
X-MICROSOFT-DISALLOW-COUNTER:FALSE
STATUS:CONFIRMED
DTSTAMP:20180918T165239Z
CREATED:20180918T165240Z
DTEND;TZID=US/Pacific:20180626T123000
X-APPLE-TRAVEL-ADVISORY-BEHAVIOR:AUTOMATIC
DESCRIPTION:Redacted
END:VEVENT

If I do

file = open('test.ics')
cal = Vpim::Icalendar.decode(file).first
all_events = cal.events {}.to_a
first_event = all_events.first
timezone_of_first_event = first_event.properties.find { |f| f.name? 'DTSTART' }.pvalue('TZID')

As indicated by the DAYLIGHT rule in VTIMEZONE in this .ics file, I'd expect timezone_of_first_event to be Pacific Daylight Time, but it is Pacific Standard Time

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.