Commit d7b3f1f6 authored by David Jarvie's avatar David Jarvie
Browse files

Re-enable sendmail for email alarms

parent bf98ee8d
KAlarm Change Log
=== Version 2.11.2 --- 24 September 2015 ===
=== Version 2.11.3 --- 3 November 2015 ===
- Re-enable use of sendmail for email alarms.
=== Version 2.11.2 (KDE Applications 15.08.2) --- 24 September 2015 ===
- Enable typing into New Alarm dialogue while alarm is displayed (Unity desktop) [KDE Bug 352889]
=== Version 2.11.1 (KDE Applications 15.08.1)--- 1 September 2015 ===
=== Version 2.11.1 (KDE Applications 15.08.1) --- 1 September 2015 ===
- Fix conversion error in sub-repetition value from command line or D-Bus command.
=== Version 2.11.0 (KDE Applications 15.08.0) --- 30 July 2015 ===
- Disable use of sendmail for email alarms, due to removal from Akonadi.
=== Version 2.11.0 --- July 2015 ===
- Use KDE Frameworks.
......
......@@ -24,7 +24,7 @@
#undef QT3_SUPPORT
#define VERSION_SUFFIX "-5ak"
#define KALARM_VERSION "2.11.2" VERSION_SUFFIX
#define KALARM_VERSION "2.11.3" VERSION_SUFFIX
#define KALARM_NAME "KAlarm"
#define KALARM_DBUS_SERVICE "org.kde.kalarm" // D-Bus service name of KAlarm application
......
/*
* kamail.cpp - email functions
* Program: kalarm
* Copyright © 2002-2011 by David Jarvie <djarvie@kde.org>
* Copyright © 2002-2015 by David Jarvie <djarvie@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
......@@ -48,6 +48,7 @@
#include <kemailsettings.h>
#include <kcodecs.h>
#include <kcharsets.h>
#include <kshell.h>
#include <QUrl>
#include <QFile>
......@@ -149,41 +150,84 @@ int KAMail::send(JobData& jobdata, QStringList& errmsgs)
qCDebug(KALARM_LOG) << "To:" << jobdata.event.emailAddresses(QStringLiteral(","))
<< endl << "Subject:" << jobdata.event.emailSubject();
KMime::Message::Ptr message = KMime::Message::Ptr(new KMime::Message);
MailTransport::TransportManager* manager = MailTransport::TransportManager::self();
MailTransport::Transport* transport = Q_NULLPTR;
#warning Remove sendmail support!
#if 0
if (Preferences::emailClient() == Preferences::sendmail)
{
qCDebug(KALARM_LOG) << "Sending via sendmail";
const QList<MailTransport::Transport*> transports = manager->transports();
for (int i = 0, count = transports.count(); i < count; ++i)
QStringList paths;
paths << QStringLiteral("/sbin") << QStringLiteral("/usr/sbin") << QStringLiteral("/usr/lib");
QString command = QStandardPaths::findExecutable(QStringLiteral("sendmail"), paths);
if (!command.isNull())
{
command += QStringLiteral(" -f ");
command += extractEmailAndNormalize(jobdata.from);
command += QStringLiteral(" -oi -t ");
initHeaders(*message, jobdata);
}
else
{
if (transports[i]->type() == MailTransport::Transport::EnumType::Sendmail)
command = QStandardPaths::findExecutable(QStringLiteral("mail"), paths);
if (command.isNull())
{
// Use the first sendmail transport found
transport = transports[i];
break;
qCCritical(KALARM_LOG) << "sendmail not found";
errmsgs = errors(xi18nc("@info", "<command>%1</command> not found", QStringLiteral("sendmail"))); // give up
return -1;
}
command += QStringLiteral(" -s ");
command += KShell::quoteArg(jobdata.event.emailSubject());
if (!jobdata.bcc.isEmpty())
{
command += QStringLiteral(" -b ");
command += extractEmailAndNormalize(jobdata.bcc);
}
command += QLatin1Char(' ');
command += jobdata.event.emailPureAddresses(QStringLiteral(" ")); // locally provided, okay
}
if (!transport)
// Add the body and attachments to the message.
// (Sendmail requires attachments to have already been included in the message.)
err = appendBodyAttachments(*message, jobdata);
if (!err.isNull())
{
qCCritical(KALARM_LOG) << "Error compiling message:" << err;
errmsgs = errors(err);
return -1;
}
// Execute the send command
FILE* fd = ::popen(command.toLocal8Bit(), "w");
if (!fd)
{
qCCritical(KALARM_LOG) << "Unable to open a pipe to " << command;
errmsgs = errors();
return -1;
}
message->assemble();
QByteArray encoded = message->encodedContent();
fwrite(encoded, encoded.length(), 1, fd);
pclose(fd);
#ifdef KMAIL_SUPPORTED
if (Preferences::emailCopyToKMail())
{
QStringList paths;
paths << QStringLiteral("/sbin") << QStringLiteral("/usr/sbin") << QStringLiteral("/usr/lib");
QString command = QStandardPaths::findExecutable(QStringLiteral("sendmail"), paths);
transport = manager->createTransport();
transport->setName(QStringLiteral("sendmail"));
transport->setType(MailTransport::Transport::EnumType::Sendmail);
transport->setHost(command);
transport->setRequiresAuthentication(false);
transport->setStorePassword(false);
manager->addTransport(transport);
transport->save();
qCDebug(KALARM_LOG) << "Creating sendmail transport, id=" << transport->id();
// Create a copy of the sent email in KMail's 'sent-mail' folder,
// or if there was a send error, in KMail's 'outbox' folder.
err = addToKMailFolder(jobdata, "sent-mail", true);
if (!err.isNull())
errmsgs += errors(err, COPY_ERROR); // not a fatal error - continue
}
#endif
if (jobdata.allowNotify)
notifyQueued(jobdata.event);
return 1;
}
else
#endif
{
qCDebug(KALARM_LOG) << "Sending via KDE";
const int transportId = identity.transport().isEmpty() ? -1 : identity.transport().toInt();
......@@ -194,39 +238,38 @@ int KAMail::send(JobData& jobdata, QStringList& errmsgs)
errmsgs = errors(xi18nc("@info", "No mail transport configured for email identity <resource>%1</resource>", identity.identityName()));
return -1;
}
}
qCDebug(KALARM_LOG) << "Using transport" << transport->name() << ", id=" << transport->id();
qCDebug(KALARM_LOG) << "Using transport" << transport->name() << ", id=" << transport->id();
KMime::Message::Ptr message = KMime::Message::Ptr(new KMime::Message);
initHeaders(*message, jobdata);
err = appendBodyAttachments(*message, jobdata);
if (!err.isNull())
{
qCCritical(KALARM_LOG) << "Error compiling message:" << err;
errmsgs = errors(err);
return -1;
}
initHeaders(*message, jobdata);
err = appendBodyAttachments(*message, jobdata);
if (!err.isNull())
{
qCCritical(KALARM_LOG) << "Error compiling message:" << err;
errmsgs = errors(err);
return -1;
}
MailTransport::MessageQueueJob* mailjob = new MailTransport::MessageQueueJob(kapp);
mailjob->setMessage(message);
mailjob->transportAttribute().setTransportId(transport->id());
// MessageQueueJob email addresses must be pure, i.e. without display name. Note
// that display names are included in the actual headers set up by initHeaders().
mailjob->addressAttribute().setFrom(extractEmailAndNormalize(jobdata.from));
mailjob->addressAttribute().setTo(extractEmailsAndNormalize(jobdata.event.emailAddresses(QStringLiteral(","))));
if (!jobdata.bcc.isEmpty())
mailjob->addressAttribute().setBcc(extractEmailsAndNormalize(jobdata.bcc));
MailTransport::SentBehaviourAttribute::SentBehaviour sentAction =
(Preferences::emailClient() == Preferences::kmail || Preferences::emailCopyToKMail())
? MailTransport::SentBehaviourAttribute::MoveToDefaultSentCollection : MailTransport::SentBehaviourAttribute::Delete;
mailjob->sentBehaviourAttribute().setSentBehaviour(sentAction);
mJobs.enqueue(mailjob);
mJobData.enqueue(jobdata);
if (mJobs.count() == 1)
{
// There are no jobs already active or queued, so send now
connect(mailjob, &KJob::result, instance(), &KAMail::slotEmailSent);
mailjob->start();
MailTransport::MessageQueueJob* mailjob = new MailTransport::MessageQueueJob(kapp);
mailjob->setMessage(message);
mailjob->transportAttribute().setTransportId(transport->id());
// MessageQueueJob email addresses must be pure, i.e. without display name. Note
// that display names are included in the actual headers set up by initHeaders().
mailjob->addressAttribute().setFrom(extractEmailAndNormalize(jobdata.from));
mailjob->addressAttribute().setTo(extractEmailsAndNormalize(jobdata.event.emailAddresses(QStringLiteral(","))));
if (!jobdata.bcc.isEmpty())
mailjob->addressAttribute().setBcc(extractEmailsAndNormalize(jobdata.bcc));
MailTransport::SentBehaviourAttribute::SentBehaviour sentAction =
(Preferences::emailClient() == Preferences::kmail || Preferences::emailCopyToKMail())
? MailTransport::SentBehaviourAttribute::MoveToDefaultSentCollection : MailTransport::SentBehaviourAttribute::Delete;
mailjob->sentBehaviourAttribute().setSentBehaviour(sentAction);
mJobs.enqueue(mailjob);
mJobData.enqueue(jobdata);
if (mJobs.count() == 1)
{
// There are no jobs already active or queued, so send now
connect(mailjob, &KJob::result, instance(), &KAMail::slotEmailSent);
mailjob->start();
}
}
return 0;
}
......@@ -384,7 +427,7 @@ QString KAMail::appendBodyAttachments(KMime::Message& message, JobData& data)
return attachError;
}
contents = downloadJob->data();
if (contents.size() < fi.size())
if (static_cast<unsigned>(contents.size()) < fi.size())
{
qCDebug(KALARM_LOG) << "Read error:" << attachment;
atterror = true;
......@@ -614,6 +657,9 @@ QStringList KAMail::errors(const QString& err, ErrType prefix)
{
case SEND_FAIL: error1 = i18nc("@info", "Failed to send email"); break;
case SEND_ERROR: error1 = i18nc("@info", "Error sending email"); break;
#ifdef KMAIL_SUPPORTED
case COPY_ERROR: error1 = i18nc("@info", "Error copying sent email to <application>KMail</application> <resource>%1</resource> folder", i18n_sent_mail()); break;
#endif
}
if (err.isEmpty())
return QStringList(error1);
......@@ -627,11 +673,9 @@ QStringList KAMail::errors(const QString& err, ErrType prefix)
*/
QString KAMail::getMailBody(quint32 serialNumber)
{
//TODO: Need to use Akonadi instead
QList<QVariant> args;
args << serialNumber << (int)0;
#ifdef __GNUC__
#warning Set correct DBus interface/object for kmail
#endif
QDBusInterface iface(KMAIL_DBUS_SERVICE, QString(), QStringLiteral("KMailIface"));
QDBusReply<QString> reply = iface.callWithArgumentList(QDBus::Block, QStringLiteral("getDecodedBodyPart"), args);
if (!reply.isValid())
......
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