[pim/kdepim-addons] /: Parse iCal invitation ourselves

Laurent Montel <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit cd2772472b1bc0267cea751d481d724921533f69 by Laurent Montel, on behalf of Volker Krause.
Committed on 06/08/2026 at 10:55.
Pushed by vkrause into branch 'master'.

Parse iCal invitation ourselves

This doesn't gain us much yet, however it's the first step towards not
doing that multiple times (once the rest of the involved API can take
pre-parsed messages), and more importantly it'll prepares us for handling
non-invitation iCal attachments that are intended to be used like
invitations as well here.

M  +1    -1    CMakeLists.txt
M  +24   -15   plugins/messageviewer/bodypartformatter/calendar/text_calendar.cpp

https://invent.kde.org/pim/kdepim-addons/-/commit/cd2772472b1bc0267cea751d481d724921533f69

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 78b039ba1..a46c3a679 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -195,7 +195,7 @@ set(INCIDENCEEDITOR_LIB_VERSION "6.7.43")
 set(KTNEF_LIB_VERSION "6.7.41")
 set(MESSAGELIB_LIB_VERSION "6.7.40")
 set(AKONADICALENDAR_LIB_VERSION "6.7.42")
-set(CALENDAR_UTILS_VERSION "6.7.40")
+set(CALENDAR_UTILS_VERSION "6.7.41")
 set(KPIMTEXTEDIT_LIB_VERSION "6.7.40")
 set(KIMAP_LIB_VERSION "6.7.40")
 set(LIBKSIEVE_LIB_VERSION "6.7.40")
diff --git a/plugins/messageviewer/bodypartformatter/calendar/text_calendar.cpp b/plugins/messageviewer/bodypartformatter/calendar/text_calendar.cpp
index 816cf4f4e..3aa9b4962 100644
--- a/plugins/messageviewer/bodypartformatter/calendar/text_calendar.cpp
+++ b/plugins/messageviewer/bodypartformatter/calendar/text_calendar.cpp
@@ -166,6 +166,25 @@ static QString getSender(const MimeTreeParser::MessagePart *msgPart)
     return {};
 }
 
+static ScheduleMessage::Ptr stringToInvitation(const QString &iCal)
+{
+    MemoryCalendar::Ptr calendar(new MemoryCalendar(QTimeZone::systemTimeZone()));
+    ICalFormat format;
+    ScheduleMessage::Ptr message = format.parseScheduleMessage(calendar, iCal);
+    if (!message) {
+        // TODO: Error message?
+        qCWarning(TEXT_CALENDAR_LOG) << "Can't parse this ical string: " << iCal;
+    }
+
+    return message;
+}
+
+static Incidence::Ptr stringToIncidence(const QString &iCal)
+{
+    const auto message = stringToInvitation(iCal);
+    return message ? message->event().dynamicCast<Incidence>() : nullptr;
+}
+
 class Formatter : public MessageViewer::MessagePartRendererBase
 {
 public:
@@ -206,9 +225,13 @@ public:
                 }
 
                 MemoryCalendar::Ptr cl(new MemoryCalendar(QTimeZone::systemTimeZone()));
+                const auto msg = stringToInvitation(source);
+                if (!msg) {
+                    return false;
+                }
 
                 const auto sender = getSender(msgPart.get());
-                const QString html = KCalUtils::IncidenceFormatter::formatICalInvitationNoHtml(source, cl, &helper, sender);
+                const QString html = KCalUtils::IncidenceFormatter::formatICalInvitation(msg, &helper, sender);
 
                 if (html.isEmpty()) {
                     return false;
@@ -250,20 +273,6 @@ static QString directoryForStatus(Attendee::PartStat status)
     return dir;
 }
 
-static Incidence::Ptr stringToIncidence(const QString &iCal)
-{
-    MemoryCalendar::Ptr calendar(new MemoryCalendar(QTimeZone::systemTimeZone()));
-    ICalFormat format;
-    ScheduleMessage::Ptr message = format.parseScheduleMessage(calendar, iCal);
-    if (!message) {
-        // TODO: Error message?
-        qCWarning(TEXT_CALENDAR_LOG) << "Can't parse this ical string: " << iCal;
-        return {};
-    }
-
-    return message->event().dynamicCast<Incidence>();
-}
-
 class UrlHandler : public MessageViewer::Interface::BodyPartURLHandler
 {
 public:
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.