diff options
Diffstat (limited to 'examples/imapresource/imapresource.cpp')
-rw-r--r-- | examples/imapresource/imapresource.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index 14c3a3e..cd3b69f 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp | |||
@@ -526,7 +526,7 @@ public: | |||
526 | 526 | ||
527 | KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE | 527 | KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE |
528 | { | 528 | { |
529 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort, &mSessionCache); | 529 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort, mEncryptionMode, &mSessionCache); |
530 | if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Folder>()) { | 530 | if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Folder>()) { |
531 | return login(imap) | 531 | return login(imap) |
532 | .then([=] { | 532 | .then([=] { |
@@ -634,7 +634,7 @@ public: | |||
634 | return KAsync::null<QByteArray>(); | 634 | return KAsync::null<QByteArray>(); |
635 | } | 635 | } |
636 | } | 636 | } |
637 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort, &mSessionCache); | 637 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort, mEncryptionMode, &mSessionCache); |
638 | auto login = imap->login(mUser, secret()); | 638 | auto login = imap->login(mUser, secret()); |
639 | KAsync::Job<QByteArray> job = KAsync::null<QByteArray>(); | 639 | KAsync::Job<QByteArray> job = KAsync::null<QByteArray>(); |
640 | if (operation == Sink::Operation_Creation) { | 640 | if (operation == Sink::Operation_Creation) { |
@@ -719,7 +719,7 @@ public: | |||
719 | return KAsync::error<QByteArray>("Tried to replay modification without old remoteId."); | 719 | return KAsync::error<QByteArray>("Tried to replay modification without old remoteId."); |
720 | } | 720 | } |
721 | } | 721 | } |
722 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort, &mSessionCache); | 722 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort, mEncryptionMode, &mSessionCache); |
723 | auto login = imap->login(mUser, secret()); | 723 | auto login = imap->login(mUser, secret()); |
724 | if (operation == Sink::Operation_Creation) { | 724 | if (operation == Sink::Operation_Creation) { |
725 | QString parentFolder; | 725 | QString parentFolder; |
@@ -793,6 +793,7 @@ public: | |||
793 | public: | 793 | public: |
794 | QString mServer; | 794 | QString mServer; |
795 | int mPort; | 795 | int mPort; |
796 | Imap::EncryptionMode mEncryptionMode = Imap::NoEncryption; | ||
796 | QString mUser; | 797 | QString mUser; |
797 | int mDaysToSync = 0; | 798 | int mDaysToSync = 0; |
798 | QByteArray mResourceInstanceIdentifier; | 799 | QByteArray mResourceInstanceIdentifier; |
@@ -839,7 +840,7 @@ protected: | |||
839 | } | 840 | } |
840 | KIMAP2::FetchJob::FetchScope scope; | 841 | KIMAP2::FetchJob::FetchScope scope; |
841 | scope.mode = KIMAP2::FetchJob::FetchScope::Full; | 842 | scope.mode = KIMAP2::FetchJob::FetchScope::Full; |
842 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); | 843 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort, mEncryptionMode); |
843 | auto messageByUid = QSharedPointer<QHash<qint64, Imap::Message>>::create(); | 844 | auto messageByUid = QSharedPointer<QHash<qint64, Imap::Message>>::create(); |
844 | SinkTrace() << "Connecting to:" << mServer << mPort; | 845 | SinkTrace() << "Connecting to:" << mServer << mPort; |
845 | SinkTrace() << "as:" << mUser; | 846 | SinkTrace() << "as:" << mUser; |
@@ -907,7 +908,7 @@ protected: | |||
907 | auto set = KIMAP2::ImapSet::fromImapSequenceSet("1:*"); | 908 | auto set = KIMAP2::ImapSet::fromImapSequenceSet("1:*"); |
908 | KIMAP2::FetchJob::FetchScope scope; | 909 | KIMAP2::FetchJob::FetchScope scope; |
909 | scope.mode = KIMAP2::FetchJob::FetchScope::Headers; | 910 | scope.mode = KIMAP2::FetchJob::FetchScope::Headers; |
910 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); | 911 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort, mEncryptionMode); |
911 | auto messageByUid = QSharedPointer<QHash<qint64, Imap::Message>>::create(); | 912 | auto messageByUid = QSharedPointer<QHash<qint64, Imap::Message>>::create(); |
912 | return imap->login(mUser, secret()) | 913 | return imap->login(mUser, secret()) |
913 | .then(imap->select(remoteId)) | 914 | .then(imap->select(remoteId)) |
@@ -925,7 +926,7 @@ protected: | |||
925 | auto folderByPath = QSharedPointer<QSet<QString>>::create(); | 926 | auto folderByPath = QSharedPointer<QSet<QString>>::create(); |
926 | auto folderByName = QSharedPointer<QSet<QString>>::create(); | 927 | auto folderByName = QSharedPointer<QSet<QString>>::create(); |
927 | 928 | ||
928 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); | 929 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort, mEncryptionMode); |
929 | auto inspectionJob = imap->login(mUser, secret()) | 930 | auto inspectionJob = imap->login(mUser, secret()) |
930 | .then(imap->fetchFolders([=](const Imap::Folder &f) { | 931 | .then(imap->fetchFolders([=](const Imap::Folder &f) { |
931 | *folderByPath << f.path(); | 932 | *folderByPath << f.path(); |
@@ -950,6 +951,7 @@ protected: | |||
950 | public: | 951 | public: |
951 | QString mServer; | 952 | QString mServer; |
952 | int mPort; | 953 | int mPort; |
954 | Imap::EncryptionMode mEncryptionMode = Imap::NoEncryption; | ||
953 | QString mUser; | 955 | QString mUser; |
954 | }; | 956 | }; |
955 | 957 | ||
@@ -962,6 +964,16 @@ ImapResource::ImapResource(const ResourceContext &resourceContext) | |||
962 | auto port = config.value("port").toInt(); | 964 | auto port = config.value("port").toInt(); |
963 | auto user = config.value("username").toString(); | 965 | auto user = config.value("username").toString(); |
964 | auto daysToSync = config.value("daysToSync", 14).toInt(); | 966 | auto daysToSync = config.value("daysToSync", 14).toInt(); |
967 | auto starttls = config.value("starttls", false).toBool(); | ||
968 | |||
969 | auto encryption = Imap::NoEncryption; | ||
970 | if (server.startsWith("imaps")) { | ||
971 | encryption = Imap::Tls; | ||
972 | } | ||
973 | if (starttls) { | ||
974 | encryption = Imap::Starttls; | ||
975 | } | ||
976 | |||
965 | if (server.startsWith("imap")) { | 977 | if (server.startsWith("imap")) { |
966 | server.remove("imap://"); | 978 | server.remove("imap://"); |
967 | server.remove("imaps://"); | 979 | server.remove("imaps://"); |
@@ -975,6 +987,7 @@ ImapResource::ImapResource(const ResourceContext &resourceContext) | |||
975 | auto synchronizer = QSharedPointer<ImapSynchronizer>::create(resourceContext); | 987 | auto synchronizer = QSharedPointer<ImapSynchronizer>::create(resourceContext); |
976 | synchronizer->mServer = server; | 988 | synchronizer->mServer = server; |
977 | synchronizer->mPort = port; | 989 | synchronizer->mPort = port; |
990 | synchronizer->mEncryptionMode = encryption; | ||
978 | synchronizer->mUser = user; | 991 | synchronizer->mUser = user; |
979 | synchronizer->mDaysToSync = daysToSync; | 992 | synchronizer->mDaysToSync = daysToSync; |
980 | setupSynchronizer(synchronizer); | 993 | setupSynchronizer(synchronizer); |
@@ -982,6 +995,7 @@ ImapResource::ImapResource(const ResourceContext &resourceContext) | |||
982 | auto inspector = QSharedPointer<ImapInspector>::create(resourceContext); | 995 | auto inspector = QSharedPointer<ImapInspector>::create(resourceContext); |
983 | inspector->mServer = server; | 996 | inspector->mServer = server; |
984 | inspector->mPort = port; | 997 | inspector->mPort = port; |
998 | inspector->mEncryptionMode = encryption; | ||
985 | inspector->mUser = user; | 999 | inspector->mUser = user; |
986 | setupInspector(inspector); | 1000 | setupInspector(inspector); |
987 | 1001 | ||