summaryrefslogtreecommitdiffstats
path: root/framework/src/accounts/gmailcontroller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/accounts/gmailcontroller.cpp')
-rw-r--r--framework/src/accounts/gmailcontroller.cpp89
1 files changed, 89 insertions, 0 deletions
diff --git a/framework/src/accounts/gmailcontroller.cpp b/framework/src/accounts/gmailcontroller.cpp
new file mode 100644
index 00000000..fda24b26
--- /dev/null
+++ b/framework/src/accounts/gmailcontroller.cpp
@@ -0,0 +1,89 @@
1/*
2 * Copyright (C) 2017 Michael Bohlender, <michael.bohlender@kdemail.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#include "gmailcontroller.h"
20
21#include <sink/store.h>
22
23using namespace Sink;
24using namespace Sink::ApplicationDomain;
25
26GmailController::GmailController() : Kube::Controller(),
27action_create{new Kube::ControllerAction{this, &GmailController::create}},
28action_modify{new Kube::ControllerAction{this, &GmailController::modify}},
29action_remove{new Kube::ControllerAction{this, &GmailController::remove}}
30{
31
32}
33
34void GmailController::create() {
35
36 //account
37 auto account = ApplicationDomainType::createEntity<SinkAccount>();
38 account.setProperty("type", "imap");
39 account.setProperty("name", getName());
40 Store::create(account).exec().waitForFinished();
41
42 //imap
43 auto resource = ApplicationDomainType::createEntity<SinkResource>();
44 resource.setResourceType("sink.imap");
45 resource.setAccount(account);
46 resource.setProperty("server","imaps://imap.gmail.com:993");
47 resource.setProperty("username", getEmailAddress());
48 resource.setProperty("password", getPassword());
49 Store::create(resource).exec().waitForFinished();
50
51 //smtp
52 resource = ApplicationDomainType::createEntity<SinkResource>();
53 resource.setResourceType("sink.mailtransport");
54 resource.setAccount(account);
55 resource.setProperty("server", "smtps://smtp.gmail.com:465");
56 resource.setProperty("username", getEmailAddress());
57 resource.setProperty("password", getPassword());
58 Store::create(resource).exec().waitForFinished();
59
60 //identity
61 auto identity = ApplicationDomainType::createEntity<Identity>();
62 m_identityId = identity.identifier();
63 identity.setAccount(account);
64 identity.setName(getIdentityName());
65 identity.setAddress(getEmailAddress());
66 Store::create(identity).exec();
67}
68
69void GmailController::modify() {
70 //TODO
71}
72
73void GmailController::remove() {
74 SinkAccount account(m_accountId);
75 Store::remove(account).exec();
76}
77
78void GmailController::load(const QByteArray &id) {
79
80 m_accountId = id;
81
82 Store::fetchOne<SinkAccount>(Query().filter(m_accountId))
83 .then([this](const SinkAccount &account) {
84 setName(account.getName());
85 }).exec();
86
87 //TODO
88}
89