diff --git a/src/filestorage.cpp b/src/filestorage.cpp --- a/src/filestorage.cpp +++ b/src/filestorage.cpp @@ -109,15 +109,20 @@ productId = iCal.loadedProductId(); } else { if (iCal.exception()) { - if (iCal.exception()->code() == Exception::CalVersion1) { - // Expected non vCalendar file, but detected vCalendar - qCDebug(KCALCORE_LOG) << "Fallback to VCalFormat"; + if ((iCal.exception()->code() == Exception::ParseErrorIcal) || + (iCal.exception()->code() == Exception::CalVersion1)) { + // Possible vCalendar or invalid iCalendar encountered + qCDebug(KCALCORE_LOG) << d->mFileName + << " is an invalid iCalendar or possibly a vCalendar."; + qCDebug(KCALCORE_LOG) << "Try to load it as a vCalendar"; VCalFormat vCal; success = vCal.load(calendar(), d->mFileName); productId = vCal.loadedProductId(); if (!success) { if (vCal.exception()) { - qCWarning(KCALCORE_LOG) << "Exception while importing:" << vCal.exception()->code(); + qCWarning(KCALCORE_LOG) << d->mFileName + << " is not a valid vCalendar file." + << " exception code " << vCal.exception()->code(); } return false; } diff --git a/src/icalformat.cpp b/src/icalformat.cpp --- a/src/icalformat.cpp +++ b/src/icalformat.cpp @@ -73,19 +73,24 @@ QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) { - qCritical() << "load error"; + qCritical() << "load error: unable to open " << fileName; setException(new Exception(Exception::LoadError)); return false; } const QByteArray text = file.readAll().trimmed(); file.close(); - if (text.isEmpty()) { - // empty files are valid - return true; - } else { - return fromRawString(calendar, text, false, fileName); + if (!text.isEmpty()) { + if (!fromRawString(calendar, text, false, fileName)) { + qCWarning(KCALCORE_LOG) << fileName << " is not a valid iCalendar file"; + setException(new Exception(Exception::ParseErrorIcal)); + return false; + } } + + // Note: we consider empty files to be valid + + return true; } bool ICalFormat::save(const Calendar::Ptr &calendar, const QString &fileName)