Escape necessary characters in SUMMARY on export

Escape semicolons, commas, and backslashes when exporting a calendar
item to iCal format.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Kelvin Jackson 2020-02-19 14:13:41 +02:00 committed by Lukas Fleischer
parent 96c0790804
commit 80b60d63cb

View File

@ -72,6 +72,27 @@ static void ical_export_footer(FILE *);
static const char *ical_recur_type[RECUR_TYPES] = static const char *ical_recur_type[RECUR_TYPES] =
{ "", "DAILY", "WEEKLY", "MONTHLY", "YEARLY" }; { "", "DAILY", "WEEKLY", "MONTHLY", "YEARLY" };
/* Escape characters in field before printing */
static void ical_format_line(FILE * stream, char * field, char * msg)
{
char * p;
fputs(field, stream);
for (p = msg; *p; p++) {
switch (*p) {
case ',':
case ';':
case '\\':
fprintf(stream, "\\%c", *p);
break;
default:
fputc(*p, stream);
break;
}
}
fputc('\n', stream);
}
/* iCal alarm notification. */ /* iCal alarm notification. */
static void ical_export_valarm(FILE * stream) static void ical_export_valarm(FILE * stream)
{ {
@ -130,7 +151,7 @@ static void ical_export_recur_events(FILE * stream, int export_uid)
} }
} }
fprintf(stream, "SUMMARY:%s\n", rev->mesg); ical_format_line(stream, "SUMMARY:", rev->mesg);
if (export_uid) { if (export_uid) {
char *hash = recur_event_hash(rev); char *hash = recur_event_hash(rev);
@ -153,7 +174,7 @@ static void ical_export_events(FILE * stream, int export_uid)
date_sec2date_fmt(ev->day, ICALDATEFMT, ical_date); date_sec2date_fmt(ev->day, ICALDATEFMT, ical_date);
fputs("BEGIN:VEVENT\n", stream); fputs("BEGIN:VEVENT\n", stream);
fprintf(stream, "DTSTART;VALUE=DATE:%s\n", ical_date); fprintf(stream, "DTSTART;VALUE=DATE:%s\n", ical_date);
fprintf(stream, "SUMMARY:%s\n", ev->mesg); ical_format_line(stream, "SUMMARY:", ev->mesg);
if (export_uid) { if (export_uid) {
char *hash = event_hash(ev); char *hash = event_hash(ev);
@ -209,7 +230,7 @@ static void ical_export_recur_apoints(FILE * stream, int export_uid)
} }
} }
fprintf(stream, "SUMMARY:%s\n", rapt->mesg); ical_format_line(stream, "SUMMARY:", rapt->mesg);
if (rapt->state & APOINT_NOTIFY) if (rapt->state & APOINT_NOTIFY)
ical_export_valarm(stream); ical_export_valarm(stream);
@ -244,7 +265,7 @@ static void ical_export_apoints(FILE * stream, int export_uid)
(apt->dur / MININSEC) % HOURINMIN, (apt->dur / MININSEC) % HOURINMIN,
apt->dur % MININSEC); apt->dur % MININSEC);
} }
fprintf(stream, "SUMMARY:%s\n", apt->mesg); ical_format_line(stream, "SUMMARY:", apt->mesg);
if (apt->state & APOINT_NOTIFY) if (apt->state & APOINT_NOTIFY)
ical_export_valarm(stream); ical_export_valarm(stream);
@ -271,7 +292,7 @@ static void ical_export_todo(FILE * stream, int export_uid)
if (todo->completed) if (todo->completed)
fprintf(stream, "STATUS:COMPLETED\n"); fprintf(stream, "STATUS:COMPLETED\n");
fprintf(stream, "PRIORITY:%d\n", todo->id); fprintf(stream, "PRIORITY:%d\n", todo->id);
fprintf(stream, "SUMMARY:%s\n", todo->mesg); ical_format_line(stream, "SUMMARY:", todo->mesg);
if (export_uid) { if (export_uid) {
char *hash = todo_hash(todo); char *hash = todo_hash(todo);