Skip to content

Commit

Permalink
Enhanced iCalendar protocol support
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenbra committed Jan 14, 2019
1 parent c121c58 commit b485b5b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 20 deletions.
78 changes: 61 additions & 17 deletions ora/icalendar_util_pkg.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,30 @@ as
m_protocol_version constant varchar2(3) := '2.0';
m_date_format constant varchar2(30) := 'YYYYMMDD"T"HH24MISS';
m_line_delimiter constant varchar2(2) := chr(13) || chr(10);

m_prodid varchar2(2000);


procedure set_prodid (p_prodid in varchar2)
as
begin

/*

Purpose: set prodid (company/product name)

Remarks:

Who Date Description
------ ---------- --------------------------------
MBR 07.03.2018 Created

*/

m_prodid := substr(p_prodid, 1, 2000);

end set_prodid;


function fmt_date (p_date in date) return varchar2
as
Expand Down Expand Up @@ -85,6 +108,8 @@ begin
*/

-- TODO: "Actual line feeds in data items are encoded as a backslash followed by the letter N (the bytes 5C 6E or 5C 4E in UTF-8). "

-- TODO: Encode text according to https://tools.ietf.org/html/rfc5545#section-3.3.11

l_returnvalue := p_text;

Expand All @@ -93,8 +118,7 @@ begin
end fmt_text;


function add_core_object (p_ical_body in varchar2,
p_prod_id in varchar2 := null) return varchar2
function add_core_object (p_ical_body in varchar2) return varchar2
as
l_returnvalue string_util_pkg.t_max_pl_varchar2;
begin
Expand All @@ -113,7 +137,7 @@ begin

l_returnvalue := 'BEGIN:VCALENDAR' || m_line_delimiter ||
'VERSION:' || m_protocol_version || m_line_delimiter ||
'PRODID:' || nvl(p_prod_id, '-//My Company//NONSGML My Product//EN') || m_line_delimiter ||
'PRODID:' || nvl(m_prodid, '-//My Company//NONSGML My Product//EN') || m_line_delimiter ||
p_ical_body || m_line_delimiter ||
'END:VCALENDAR';

Expand All @@ -122,14 +146,14 @@ begin
end add_core_object;


function get_event (p_event in t_event) return varchar2
function get_event_str (p_event in t_event) return varchar2
as
l_returnvalue string_util_pkg.t_max_pl_varchar2;
begin

/*

Purpose: get event
Purpose: get event string

Remarks:

Expand All @@ -147,42 +171,62 @@ begin
'DTSTART:' || fmt_date(p_event.start_date) || m_line_delimiter ||
'DTEND:' || fmt_date(nvl(p_event.end_date, p_event.start_date)) || m_line_delimiter ||
'DTSTAMP:' || fmt_date(sysdate) || m_line_delimiter ||
'UID:' || nvl(p_event.uid, rawtohex(sys_guid()) || '@domain.example') || m_line_delimiter ||
'STATUS:NEEDS-ACTION' || m_line_delimiter ||
'UID:' || nvl(p_event.uid, rawtohex(sys_guid()) || chr(64) || 'domain.example') || m_line_delimiter ||
'STATUS:' || nvl(p_event.status, 'CONFIRMED') || m_line_delimiter ||
'END:VEVENT';

l_returnvalue := add_core_object (l_returnvalue);

return l_returnvalue;

end get_event;

end get_event_str;

procedure download_event (p_event in t_event)
procedure download_event_str (p_event_str in varchar2,
p_filename in varchar2 := null)
as
l_event_str string_util_pkg.t_max_pl_varchar2;
begin

/*

Purpose: download event
Purpose: download event string

Remarks:

Who Date Description
------ ---------- --------------------------------
MBR 26.10.2012 Created
MBR 07.03.2018 Created

*/

l_event_str := get_event (p_event);

owa_util.mime_header('text/calendar', false);
htp.p('Content-length: ' || length(l_event_str));
htp.p('Content-Disposition: attachment; filename="' || file_util_pkg.get_filename_str(p_event.summary, 'ics') || '"');
htp.p('Content-length: ' || length(p_event_str));
htp.p('Content-Disposition: attachment; filename="' || nvl(p_filename, 'event.ics') || '"');
owa_util.http_header_close;

htp.prn (l_event_str);
htp.prn (p_event_str);

end download_event_str;


procedure download_event (p_event in t_event)
as
begin

/*

Purpose: download event

Remarks:

Who Date Description
------ ---------- --------------------------------
MBR 26.10.2012 Created
MBR 07.03.2018 Refactored

*/

download_event_str (p_event_str => get_event_str (p_event), p_filename => file_util_pkg.get_filename_str(p_event.summary, 'ics'));

end download_event;

Expand Down
13 changes: 10 additions & 3 deletions ora/icalendar_util_pkg.pks
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ as
Purpose: Package handles the iCalendar protocol (RFC 5545)

Remarks: see http://en.wikipedia.org/wiki/ICalendar and http://tools.ietf.org/html/rfc5545

Who Date Description
------ ---------- --------------------------------
MBR 26.10.2012 Created
Expand All @@ -21,13 +21,20 @@ as
location varchar2(2000),
organizer_name varchar2(2000),
organizer_email varchar2(2000),
status varchar2(2000),
uid varchar2(2000)
);

-- set prodid (company/product name)
procedure set_prodid (p_prodid in varchar2);

-- get event
function get_event (p_event in t_event) return varchar2;
-- get event string
function get_event_str (p_event in t_event) return varchar2;

-- download event string
procedure download_event_str (p_event_str in varchar2,
p_filename in varchar2 := null);

-- download event
procedure download_event (p_event in t_event);

Expand Down

0 comments on commit b485b5b

Please sign in to comment.