diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-21 12:06:49 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-21 12:07:39 +0200 |
commit | 8d20128618b427270c6c7db49a1716f65b8ff840 (patch) | |
tree | 1329134c8166040d6719aaa6a5f542dc67f578fc /examples/imapresource/imapserverproxy.cpp | |
parent | ac73ca1d2a23d3b62cca20545e019355f9d00035 (diff) | |
download | sink-8d20128618b427270c6c7db49a1716f65b8ff840.tar.gz sink-8d20128618b427270c6c7db49a1716f65b8ff840.zip |
Gmail support.
For the time being we hardcode a list of folders that we synchronize
that we know are not duplicating messages.
Diffstat (limited to 'examples/imapresource/imapserverproxy.cpp')
-rw-r--r-- | examples/imapresource/imapserverproxy.cpp | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp index 3305f60..36dbcf5 100644 --- a/examples/imapresource/imapserverproxy.cpp +++ b/examples/imapresource/imapserverproxy.cpp | |||
@@ -57,6 +57,7 @@ const char* Imap::FolderFlags::Trash = "\\Trash"; | |||
57 | const char* Imap::FolderFlags::Archive = "\\Archive"; | 57 | const char* Imap::FolderFlags::Archive = "\\Archive"; |
58 | const char* Imap::FolderFlags::Junk = "\\Junk"; | 58 | const char* Imap::FolderFlags::Junk = "\\Junk"; |
59 | const char* Imap::FolderFlags::Flagged = "\\Flagged"; | 59 | const char* Imap::FolderFlags::Flagged = "\\Flagged"; |
60 | const char* Imap::FolderFlags::Drafts = "\\Drafts"; | ||
60 | 61 | ||
61 | const char* Imap::Capabilities::Namespace = "NAMESPACE"; | 62 | const char* Imap::Capabilities::Namespace = "NAMESPACE"; |
62 | const char* Imap::Capabilities::Uidplus = "UIDPLUS"; | 63 | const char* Imap::Capabilities::Uidplus = "UIDPLUS"; |
@@ -192,6 +193,12 @@ KAsync::Job<void> ImapServerProxy::logout() | |||
192 | } | 193 | } |
193 | } | 194 | } |
194 | 195 | ||
196 | bool ImapServerProxy::isGmail() const | ||
197 | { | ||
198 | //Magic capability that only gmail has | ||
199 | return mCapabilities.contains("X-GM-EXT-1"); | ||
200 | } | ||
201 | |||
195 | KAsync::Job<SelectResult> ImapServerProxy::select(const QString &mailbox) | 202 | KAsync::Job<SelectResult> ImapServerProxy::select(const QString &mailbox) |
196 | { | 203 | { |
197 | auto select = new KIMAP2::SelectJob(mSession); | 204 | auto select = new KIMAP2::SelectJob(mSession); |
@@ -441,6 +448,15 @@ QString ImapServerProxy::getNamespace(const QString &name) | |||
441 | return ns.name; | 448 | return ns.name; |
442 | } | 449 | } |
443 | 450 | ||
451 | static bool caseInsensitiveContains(const QByteArray &f, const QByteArrayList &list) { | ||
452 | return list.contains(f) || list.contains(f.toLower()); | ||
453 | } | ||
454 | |||
455 | bool Imap::flagsContain(const QByteArray &f, const QByteArrayList &flags) | ||
456 | { | ||
457 | return caseInsensitiveContains(f, flags); | ||
458 | } | ||
459 | |||
444 | KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const Folder &)> callback) | 460 | KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const Folder &)> callback) |
445 | { | 461 | { |
446 | SinkTrace() << "Fetching folders"; | 462 | SinkTrace() << "Fetching folders"; |
@@ -448,8 +464,21 @@ KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const Folder | |||
448 | return list(KIMAP2::ListJob::NoOption, [=](const KIMAP2::MailBoxDescriptor &mailbox, const QList<QByteArray> &){ | 464 | return list(KIMAP2::ListJob::NoOption, [=](const KIMAP2::MailBoxDescriptor &mailbox, const QList<QByteArray> &){ |
449 | *subscribedList << mailbox.name; | 465 | *subscribedList << mailbox.name; |
450 | }).then(list(KIMAP2::ListJob::IncludeUnsubscribed, [=](const KIMAP2::MailBoxDescriptor &mailbox, const QList<QByteArray> &flags) { | 466 | }).then(list(KIMAP2::ListJob::IncludeUnsubscribed, [=](const KIMAP2::MailBoxDescriptor &mailbox, const QList<QByteArray> &flags) { |
451 | bool noselect = flags.contains(QByteArray(FolderFlags::Noselect).toLower()) || flags.contains(QByteArray(FolderFlags::Noselect)); | 467 | bool noselect = caseInsensitiveContains(FolderFlags::Noselect, flags); |
452 | bool subscribed = subscribedList->contains(mailbox.name); | 468 | bool subscribed = subscribedList->contains(mailbox.name); |
469 | if (isGmail()) { | ||
470 | bool inbox = mailbox.name.toLower() == "inbox"; | ||
471 | bool sent = caseInsensitiveContains(FolderFlags::Sent, flags); | ||
472 | bool drafts = caseInsensitiveContains(FolderFlags::Drafts, flags); | ||
473 | bool trash = caseInsensitiveContains(FolderFlags::Trash, flags); | ||
474 | bool isgmailParent = mailbox.name.toLower() == "[gmail]"; | ||
475 | /** | ||
476 | * Because gmail duplicates messages all over the place we only support a few selected folders for now that should be mostly exclusive. | ||
477 | */ | ||
478 | if (!(inbox || sent || drafts || trash || isgmailParent)) { | ||
479 | return; | ||
480 | } | ||
481 | } | ||
453 | SinkLog() << "Found mailbox: " << mailbox.name << flags << FolderFlags::Noselect << noselect << " sub: " << subscribed; | 482 | SinkLog() << "Found mailbox: " << mailbox.name << flags << FolderFlags::Noselect << noselect << " sub: " << subscribed; |
454 | auto ns = getNamespace(mailbox.name); | 483 | auto ns = getNamespace(mailbox.name); |
455 | callback(Folder{mailbox.name, ns, mailbox.separator, noselect, subscribed, flags}); | 484 | callback(Folder{mailbox.name, ns, mailbox.separator, noselect, subscribed, flags}); |