calview 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/calview.rb +88 -0
  3. metadata +50 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: daad27c727002b1616c2a5c062627022d5d15ecbbf67f6af3ff4764da76a9aae
4
+ data.tar.gz: 050a3f83ed315ed809960c054287cfdf992be918c6d111fa354baa4e1cfbdc53
5
+ SHA512:
6
+ metadata.gz: 9cfbebf32263c920deacaa05d912400bd1f089cf6e219dabb4fd01339aafb986fe4b56bbd56c3045dfd34e8b5647a0bd6cb5c390b8f3e44202b6e29c95157bc5
7
+ data.tar.gz: 26777aae69cdf89343157a77bc334185cd62474b73bf0cf5e3a1c56a713b8c7d8d8e308e9a7b7f7fc7a89f19008b28a784ae9ab1d50cd4e9695347ae6fcc2626
data/bin/calview.rb ADDED
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This is a simple script that takes vcal attachments and displays them in
4
+ # pure text. This is suitable for displaying callendar invitations in mutt.
5
+ #
6
+ # Add this to your to your .mailcap:
7
+ # text/calendar; /<pathto>/calview.rb '%s'; copiousoutput
8
+ #
9
+ # Created by Geir Isene <g@isene.com> in 2020 and released into Public Domain.
10
+
11
+ require "date"
12
+
13
+ vcal = ARGF.read
14
+
15
+ # Fix multiline participants
16
+ vcal.gsub!( /(^ATTENDEE.*)\n^ (.*)/, '\1\2' )
17
+
18
+ # Get dates and times
19
+ if vcal.match( /^DTSTART;TZID=/ )
20
+ sdate = vcal[ /^DTSTART;TZID=.*:(.*)T/, 1 ].sub( /(\d\d\d\d)(\d\d)(\d\d)/, '\1-\2-\3')
21
+ edate = vcal[ /^DTEND;TZID=.*:(.*)T/, 1 ].sub( /(\d\d\d\d)(\d\d)(\d\d)/, '\1-\2-\3')
22
+ stime = vcal[ /^DTSTART;TZID=.*T(\d\d\d\d)/, 1 ].sub( /(\d\d)(\d\d)/, '\1:\2')
23
+ etime = vcal[ /^DTEND;TZID=.*T(\d\d\d\d)/, 1 ].sub( /(\d\d)(\d\d)/, '\1:\2')
24
+ elsif vcal.match( /DTSTART;VALUE=DATE:/ )
25
+ sdate = vcal[ /^DTSTART;VALUE=DATE:(.*)/, 1 ].sub( /(\d\d\d\d)(\d\d)(\d\d)/, '\1-\2-\3')
26
+ edate = vcal[ /^DTEND;VALUE=DATE:(.*)/, 1 ].sub( /(\d\d\d\d)(\d\d)(\d\d)/, '\1-\2-\3')
27
+ stime = vcal[ /^DTSTART.*T(\d\d\d\d)/, 1 ].sub( /(\d\d)(\d\d)/, '\1:\2')
28
+ begin
29
+ etime = vcal[ /^DTEND.*T(\d\d\d\d)/, 1 ].sub( /(\d\d)(\d\d)/, '\1:\2')
30
+ rescue
31
+ etime = stime
32
+ end
33
+ else
34
+ sdate = vcal[ /^DTSTART:(.*)T/, 1 ].sub( /(\d\d\d\d)(\d\d)(\d\d)/, '\1-\2-\3')
35
+ edate = vcal[ /^DTEND:(.*)T/, 1 ].sub( /(\d\d\d\d)(\d\d)(\d\d)/, '\1-\2-\3')
36
+ stime = vcal[ /^DTSTART.*T(\d\d\d\d)/, 1 ].sub( /(\d\d)(\d\d)/, '\1:\2')
37
+ etime = vcal[ /^DTEND.*T(\d\d\d\d)/, 1 ].sub( /(\d\d)(\d\d)/, '\1:\2')
38
+ end
39
+
40
+ # Adjust for local TZ offset
41
+ unless vcal.match( /^TZOFFSET/ )
42
+ stime = (stime.to_i + Time.now.getlocal.utc_offset / 3600).to_s + stime.sub( /\d\d/, '')
43
+ etime = (etime.to_i + Time.now.getlocal.utc_offset / 3600).to_s + etime.sub( /\d\d/, '')
44
+ end
45
+
46
+ # Get organizer
47
+ if vcal.match( /^ORGANIZER;CN=/ )
48
+ org = vcal[ /^ORGANIZER;CN=(.*)/, 1 ].sub( /:mailto:/i, ' <') + ">"
49
+ else
50
+ begin
51
+ org = vcal[ /^ORGANIZER:(.*)/, 1 ].sub( /MAILTO:/i, ' <') + ">"
52
+ rescue
53
+ org = "(None set)"
54
+ end
55
+ end
56
+
57
+ # Get description
58
+ if vcal.match( /^DESCRIPTION;.*?:(.*)^UID/m )
59
+ desc = vcal[ /^DESCRIPTION;.*?:(.*)^UID/m, 1 ].gsub( /\n /, '' ).gsub( /\\n/, "\n" ).gsub( /\n\n+/, "\n" ).gsub( / \| /, "\n" ).sub( /^\n/, '' )
60
+ else
61
+ begin
62
+ desc = vcal[ /^DESCRIPTION:(.*)^SUMMARY/m, 1 ].gsub( /\n /, '' ).gsub( /\\n/, "\n" ).gsub( /\n\n+/, "\n" ).gsub( / \| /, "\n" ).sub( /^\n/, '' )
63
+ rescue
64
+ desc = ""
65
+ end
66
+ end
67
+
68
+ sdate == edate ? dates = sdate : dates = sdate + " - " + edate
69
+ dobj = DateTime.parse( sdate )
70
+ wday = dobj.strftime('%A')
71
+ week = dobj.strftime('%-V')
72
+ stime == etime ? times = stime : times = stime + " - " + etime
73
+ times += " (GST)" if vcal.match( /DTSTART;TZID=Greenwich Standard Time/ )
74
+ # Get participants
75
+ part = vcal.scan( /^ATTENDEE.*CN=([\s\S]*?@.*)\n/ ).join('%').gsub( /\n /, '').gsub( /%/, ">\n " ).gsub( /:mailto:/i, " <" )
76
+ part = " " + part + ">" if part != ""
77
+ # Get summary and description
78
+ sum = vcal[ /^SUMMARY;.*:(.*)/, 1 ]
79
+ sum = vcal[ /^SUMMARY:(.*)/, 1 ] if sum == nil
80
+
81
+ # Print the result in a tidy fashion
82
+ puts "WHAT: " + (sum)
83
+ puts "WHEN: " + (dates + " (" + wday + " of week " + week + "), " + times)
84
+ puts ""
85
+ puts "ORGANIZER: " + org
86
+ puts "PARTICIPANTS:", part
87
+ puts ""
88
+ puts "DESCRIPTION:", desc
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: calview
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Geir Isene
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-09-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'Having used the [vcal2text](https://github.com/davebiffuk/vcal2text)
14
+ for many years to view calendar invites in my mutt e-mail client, it started to
15
+ fail on newer vcal attachments. It showed only parts of a calendar invite and spit
16
+ out lots of errors beyond that. As it is written in perl and carries a bundle of
17
+ dependencies, I decided to create my own in Ruby without dependencies. This solution
18
+ is leaner (and meaner), and it works. Check Github page for more info: https://github.com/isene/calview'
19
+ email: g@isene.com
20
+ executables:
21
+ - calview.rb
22
+ extensions: []
23
+ extra_rdoc_files: []
24
+ files:
25
+ - bin/calview.rb
26
+ homepage: https://isene.com/
27
+ licenses:
28
+ - Unlicense
29
+ metadata:
30
+ source_code_uri: https://github.com/isene/calview
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubygems_version: 3.1.2
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: VCAL viewer for MUTT (can also be used to view a vcal file in a terminal)
50
+ test_files: []