Skip to content

Commit

Permalink
[buteo-sync-plugin-caldav] Correct handling of percent encoded paths …
Browse files Browse the repository at this point in the history
…in discovery code.
  • Loading branch information
dcaliste committed Mar 25, 2020
1 parent 4d2f71e commit a9038a9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
15 changes: 3 additions & 12 deletions src/caldavclient.cpp
Expand Up @@ -320,23 +320,14 @@ struct CalendarSettings
enabled.clear();
}
};
QList<Settings::CalendarInfo> enabledCalendars(const QString &serverAddress)
QList<Settings::CalendarInfo> enabledCalendars()
{
if (!enabled.count()) {
return QList<Settings::CalendarInfo>();
}
QList<Settings::CalendarInfo> allCalendarInfo;
for (int i = 0; i < paths.count(); i++) {
if (!enabled.contains(paths[i])) {
continue;
}
// the calendar path may be percent-encoded. Return UTF-8 QString.
QString remotePath = QUrl::fromPercentEncoding(paths[i].toUtf8());
// Yahoo! seems to double-percent-encode for some reason
if (serverAddress.contains(QStringLiteral("caldav.calendar.yahoo.com"))) {
remotePath = QUrl::fromPercentEncoding(remotePath.toUtf8());
}
allCalendarInfo << Settings::CalendarInfo{remotePath,
allCalendarInfo << Settings::CalendarInfo{paths[i],
displayNames[i], colors[i], QString() };
}
return allCalendarInfo;
Expand Down Expand Up @@ -398,7 +389,7 @@ QList<Settings::CalendarInfo> CalDavClient::loadCalendars(Accounts::Account *acc
struct CalendarSettings calendarSettings(account);
account->selectService(Accounts::Service());

return calendarSettings.enabledCalendars(mSettings.serverAddress());
return calendarSettings.enabledCalendars();
}

void CalDavClient::mergeCalendars(const QList<Settings::CalendarInfo> &calendars)
Expand Down
12 changes: 9 additions & 3 deletions src/notebooksyncagent.cpp
Expand Up @@ -165,15 +165,15 @@ NotebookSyncAgent::NotebookSyncAgent(mKCal::ExtendedCalendar::Ptr calendar,
mKCal::ExtendedStorage::Ptr storage,
QNetworkAccessManager *networkAccessManager,
Settings *settings,
const QString &remoteCalendarPath,
const QString &encodedRemotePath,
QObject *parent)
: QObject(parent)
, mNetworkManager(networkAccessManager)
, mSettings(settings)
, mCalendar(calendar)
, mStorage(storage)
, mNotebook(0)
, mRemoteCalendarPath(remoteCalendarPath)
, mEncodedRemotePath(encodedRemotePath)
, mSyncMode(NoSyncMode)
, mRetriedReport(false)
, mNotebookNeedsDeletion(false)
Expand All @@ -182,6 +182,12 @@ NotebookSyncAgent::NotebookSyncAgent(mKCal::ExtendedCalendar::Ptr calendar,
, mEnableUpsync(true)
, mEnableDownsync(true)
{
// the calendar path may be percent-encoded. Return UTF-8 QString.
mRemoteCalendarPath = QUrl::fromPercentEncoding(mEncodedRemotePath.toUtf8());
// Yahoo! seems to double-percent-encode for some reason
if (mSettings->serverAddress().contains(QStringLiteral("caldav.calendar.yahoo.com"))) {
mRemoteCalendarPath = QUrl::fromPercentEncoding(mRemoteCalendarPath.toUtf8());
}
}

NotebookSyncAgent::~NotebookSyncAgent()
Expand Down Expand Up @@ -745,7 +751,7 @@ bool NotebookSyncAgent::isDeleted() const

const QString& NotebookSyncAgent::path() const
{
return mRemoteCalendarPath;
return mEncodedRemotePath;
}

// ------------------------------ Utility / implementation functions.
Expand Down
5 changes: 3 additions & 2 deletions src/notebooksyncagent.h
Expand Up @@ -50,7 +50,7 @@ class NotebookSyncAgent : public QObject
mKCal::ExtendedStorage::Ptr storage,
QNetworkAccessManager *networkAccessManager,
Settings *settings,
const QString &remoteCalendarPath,
const QString &encodedRemotePath,
QObject *parent = 0);
~NotebookSyncAgent();

Expand Down Expand Up @@ -121,7 +121,8 @@ private slots:
QDateTime mFromDateTime;
QDateTime mToDateTime;
KDateTime mNotebookSyncedDateTime;
QString mRemoteCalendarPath; // contains calendar path. resource prefix. doesn't include host.
QString mEncodedRemotePath;
QString mRemoteCalendarPath; // contains calendar path. resource prefix. doesn't include host, percent decoded.
SyncMode mSyncMode; // quick (etag-based delta detection) or slow (full report) sync
bool mRetriedReport; // some servers will fail the first request but succeed on second
bool mNotebookNeedsDeletion; // if the calendar was deleted remotely, we will need to delete it locally.
Expand Down
4 changes: 3 additions & 1 deletion src/propfind.cpp
Expand Up @@ -147,7 +147,9 @@ static bool readCalendarsResponse(QXmlStreamReader *reader, QList<Settings::Cale
Settings::CalendarInfo calendarInfo;
for (; !reader->atEnd(); reader->readNext()) {
if (reader->name() == "href" && reader->isStartElement() && calendarInfo.remotePath.isEmpty()) {
calendarInfo.remotePath = QUrl::fromPercentEncoding(reader->readElementText().toUtf8());
// The account stores this with the encoding, so we're converting from
// percent encoding later.
calendarInfo.remotePath = reader->readElementText();
}

if (reader->name() == "propstat" && reader->isStartElement()) {
Expand Down

0 comments on commit a9038a9

Please sign in to comment.