summaryrefslogtreecommitdiffstats
path: root/examples/imapresource/imapserverproxy.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-26 16:50:42 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-26 16:50:42 +0200
commit350824b0ecacabab7c7bb565df165d8c108ea43f (patch)
tree90ddd063b4d87470a85236623b33faeb1cbf8f10 /examples/imapresource/imapserverproxy.cpp
parent9450bcb17d9633e56bf43242463583ae9c0c53e9 (diff)
downloadsink-350824b0ecacabab7c7bb565df165d8c108ea43f.tar.gz
sink-350824b0ecacabab7c7bb565df165d8c108ea43f.zip
Only create one session
And not one for every imap proxy
Diffstat (limited to 'examples/imapresource/imapserverproxy.cpp')
-rw-r--r--examples/imapresource/imapserverproxy.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp
index d3ad2d4..7fa0b5a 100644
--- a/examples/imapresource/imapserverproxy.cpp
+++ b/examples/imapresource/imapserverproxy.cpp
@@ -99,17 +99,25 @@ static KAsync::Job<void> runJob(KJob *job)
99 }); 99 });
100} 100}
101 101
102ImapServerProxy::ImapServerProxy(const QString &serverUrl, int port, SessionCache *sessionCache) : mSession(new KIMAP2::Session(serverUrl, qint16(port))), mSessionCache(sessionCache) 102KIMAP2::Session *createNewSession(const QString &serverUrl, int port)
103{ 103{
104 QObject::connect(mSession, &KIMAP2::Session::sslErrors, [this](const QList<QSslError> &errors) { 104 auto newSession = new KIMAP2::Session(serverUrl, qint16(port));
105 if (Sink::Test::testModeEnabled()) {
106 newSession->setTimeout(1);
107 } else {
108 newSession->setTimeout(40);
109 }
110 QObject::connect(newSession, &KIMAP2::Session::sslErrors, [=](const QList<QSslError> &errors) {
105 SinkLog() << "Received ssl error: " << errors; 111 SinkLog() << "Received ssl error: " << errors;
106 mSession->ignoreErrors(errors); 112 newSession->ignoreErrors(errors);
107 }); 113 });
114 return newSession;
115}
108 116
109 if (Sink::Test::testModeEnabled()) { 117ImapServerProxy::ImapServerProxy(const QString &serverUrl, int port, SessionCache *sessionCache) : mSessionCache(sessionCache), mSession(nullptr)
110 mSession->setTimeout(1); 118{
111 } else { 119 if (!mSessionCache || mSessionCache->isEmpty()) {
112 mSession->setTimeout(40); 120 mSession = createNewSession(serverUrl, port);
113 } 121 }
114} 122}
115 123