Commit a684ba1a authored by Àlex Fiestas's avatar Àlex Fiestas
Browse files

Added createmail KJob

parent adc88ef0
......@@ -12,12 +12,17 @@ set(webaccounts_SRCS
jobs/createcalendar.cpp
jobs/createtask.cpp
jobs/createchat.cpp
jobs/createmail.cpp
)
qt4_add_dbus_interface(webaccounts_SRCS
jobs/org.kde.Akonadi.GoogleCalendar.Settings.xml
google_calendar_settings
)
qt4_add_dbus_interface(webaccounts_SRCS
jobs/org.kde.Akonadi.Imap.Settings.xml
akonadi_imap_settings
)
qt4_automoc(${webaccounts_SRCS})
......
/*************************************************************************************
* Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
*************************************************************************************/
#include "createmail.h"
#include "akonadi_imap_settings.h"
#include <QDBusInterface>
#include <akonadi/agenttype.h>
#include <akonadi/agentmanager.h>
#include <akonadi/agentinstancecreatejob.h>
#include <mailtransport/transport.h>
#include <mailtransport/transportmanager.h>
#include <KWallet/Wallet>
using namespace KWallet;
using namespace Akonadi;
CreateMail::CreateMail(KConfigGroup& group, QObject* parent)
: KJob(parent)
, m_config(group)
{
}
CreateMail::~CreateMail()
{
}
void CreateMail::start()
{
QMetaObject::invokeMethod(this, "createResource", Qt::QueuedConnection);
}
void CreateMail::createResource()
{
const AgentType type = AgentManager::self()->type( "akonadi_imap_resource");
AgentInstanceCreateJob *job = new AgentInstanceCreateJob( type, this );
connect( job, SIGNAL(result(KJob*)), SLOT(instanceCreateResult(KJob*)) );
job->start();
}
void CreateMail::instanceCreateResult(KJob* job)
{
QString password;
Wallet *wallet = Wallet::openWallet(Wallet::NetworkWallet(), 0, Wallet::Synchronous);
wallet->setFolder("WebAccounts");
if (wallet->readPassword(m_config.name(), password) != 0) {
qWarning("Can't open wallet");
return;
}
AgentInstance m_instance = qobject_cast<AgentInstanceCreateJob*>( job )->instance();
QDBusInterface iface( "org.freedesktop.Akonadi.Resource." + m_instance.identifier(), "/Settings");
m_instance.setName(m_config.name() + " Disconnected IMAP");
QString service = "org.freedesktop.Akonadi.Resource." + m_instance.identifier();
org::kde::Akonadi::Imap::Settings *settings = new org::kde::Akonadi::Imap::Settings(service, "/Settings", QDBusConnection::sessionBus());
settings->setAuthentication(7);
settings->setDisconnectedModeEnabled(true);
settings->setImapPort(993);
settings->setImapServer("imap.gmail.com");
settings->setIntervalCheckTime(60);
settings->setSafety("SSL");
settings->setSubscriptionEnabled(true);
settings->setUseDefaultIdentity(true);
settings->setUserName(m_config.name());
org::kde::Akonadi::Imap::Wallet *imapWallet = new org::kde::Akonadi::Imap::Wallet(service, "/Settings", QDBusConnection::sessionBus());
imapWallet->setPassword(password);
m_instance.reconfigure();
MailTransport::Transport* mt = MailTransport::TransportManager::self()->createTransport();
mt->setName("smtp.googlemail.com");
mt->setHost("smtp.googlemail.com");
mt->setPort(465);
mt->setUserName(m_config.name());
mt->setStorePassword(true);
mt->setPassword(password);
mt->setEncryption(MailTransport::Transport::EnumEncryption::SSL);
mt->setAuthenticationType(MailTransport::Transport::EnumAuthenticationType::PLAIN );
mt->setRequiresAuthentication(true);
mt->writeConfig();
MailTransport::TransportManager::self()->addTransport( mt );
MailTransport::TransportManager::self()->setDefaultTransport( mt->id() );
}
/*************************************************************************************
* Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
*************************************************************************************/
#ifndef CREATEMAIL_H
#define CREATEMAIL_H
#include <kconfiggroup.h>
#include <KDE/KJob>
class CreateMail : public KJob
{
Q_OBJECT
public:
explicit CreateMail(KConfigGroup &group, QObject* parent = 0);
virtual ~CreateMail();
virtual void start();
private Q_SLOTS:
void createResource();
void instanceCreateResult(KJob* job);
private:
KConfigGroup m_config;
};
#endif // CREATEMAIL_H
\ No newline at end of file
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.kde.Akonadi.Imap.Wallet">
<method name="password">
<arg type="s" direction="out"/>
</method>
<method name="setPassword">
<arg name="password" type="s" direction="in"/>
</method>
</interface>
<interface name="org.kde.Akonadi.Imap.Settings">
<method name="writeConfig"/>
<method name="imapServer">
<arg direction="out" type="s"/>
</method>
<method name="setImapServer">
<arg direction="in" identifier="value" type="s"/>
</method>
<method name="imapPort">
<arg direction="out" type="i"/>
</method>
<method name="setImapPort">
<arg direction="in" identifier="value" type="i"/>
</method>
<method name="userName">
<arg direction="out" type="s"/>
</method>
<method name="setUserName">
<arg direction="in" identifier="value" type="s"/>
</method>
<method name="safety">
<arg direction="out" type="s"/>
</method>
<method name="setSafety">
<arg direction="in" identifier="value" type="s"/>
</method>
<method name="authentication">
<arg direction="out" type="i"/>
</method>
<method name="setAuthentication">
<arg direction="in" identifier="value" type="i"/>
</method>
<method name="subscriptionEnabled">
<arg direction="out" type="b"/>
</method>
<method name="setSubscriptionEnabled">
<arg direction="in" identifier="value" type="b"/>
</method>
<method name="sessionTimeout">
<arg direction="out" type="i"/>
</method>
<method name="setSessionTimeout">
<arg direction="in" identifier="value" type="i"/>
</method>
<method name="disconnectedModeEnabled">
<arg direction="out" type="b"/>
</method>
<method name="setDisconnectedModeEnabled">
<arg direction="in" identifier="value" type="b"/>
</method>
<method name="intervalCheckEnabled">
<arg direction="out" type="b"/>
</method>
<method name="setIntervalCheckEnabled">
<arg direction="in" identifier="value" type="b"/>
</method>
<method name="intervalCheckTime">
<arg direction="out" type="i"/>
</method>
<method name="setIntervalCheckTime">
<arg direction="in" identifier="value" type="i"/>
</method>
<method name="retrieveMetadataOnFolderListing">
<arg direction="out" type="b"/>
</method>
<method name="setRetrieveMetadataOnFolderListing">
<arg direction="in" identifier="value" type="b"/>
</method>
<method name="automaticExpungeEnabled">
<arg direction="out" type="b"/>
</method>
<method name="setAutomaticExpungeEnabled">
<arg direction="in" identifier="value" type="b"/>
</method>
<method name="trashCollection">
<arg direction="out" type="x"/>
</method>
<method name="setTrashCollection">
<arg direction="in" identifier="value" type="x"/>
</method>
<method name="useDefaultIdentity">
<arg direction="out" type="b"/>
</method>
<method name="setUseDefaultIdentity">
<arg direction="in" identifier="value" type="b"/>
</method>
<method name="accountIdentity">
<arg direction="out" type="i"/>
</method>
<method name="setAccountIdentity">
<arg direction="in" identifier="value" type="i"/>
</method>
<method name="knownMailBoxes">
<arg direction="out" type="as"/>
</method>
<method name="setKnownMailBoxes">
<arg direction="in" identifier="value" type="as"/>
</method>
<method name="idleRidPath">
<arg direction="out" type="as"/>
</method>
<method name="setIdleRidPath">
<arg direction="in" identifier="value" type="as"/>
</method>
<method name="sieveSupport">
<arg direction="out" type="b"/>
</method>
<method name="setSieveSupport">
<arg direction="in" identifier="value" type="b"/>
</method>
<method name="sieveReuseConfig">
<arg direction="out" type="b"/>
</method>
<method name="setSieveReuseConfig">
<arg direction="in" identifier="value" type="b"/>
</method>
<method name="sievePort">
<arg direction="out" type="i"/>
</method>
<method name="setSievePort">
<arg direction="in" identifier="value" type="i"/>
</method>
<method name="sieveAlternateUrl">
<arg direction="out" type="s"/>
</method>
<method name="setSieveAlternateUrl">
<arg direction="in" identifier="value" type="s"/>
</method>
<method name="sieveVacationFilename">
<arg direction="out" type="s"/>
</method>
<method name="setSieveVacationFilename">
<arg direction="in" identifier="value" type="s"/>
</method>
</interface>
</node>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment