• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KIO

  • kio
  • misc
  • ksendbugmail
main.cpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2000 Bernd Johannes Wuebben <wuebben@math.cornell.edu>
3 Copyright (c) 2000 Stephan Kulow <coolo@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20#include "main.h"
21#include <sys/types.h>
22#include <pwd.h>
23#include <stdlib.h>
24#include <unistd.h>
25
26#include <QtCore/QTextStream>
27
28#include <kapplication.h>
29#include <kemailsettings.h>
30#include <klocale.h>
31#include <kcmdlineargs.h>
32#include <kaboutdata.h>
33#include <kdebug.h>
34#include <kconfig.h>
35
36#include "smtp.h"
37
38void BugMailer::slotError(int errornum) {
39 QString lstr;
40
41 switch(errornum) {
42 case SMTP::ConnectError:
43 lstr = i18n("Error connecting to server.");
44 break;
45 case SMTP::NotConnected:
46 lstr = i18n("Not connected.");
47 break;
48 case SMTP::ConnectTimeout:
49 lstr = i18n("Connection timed out.");
50 break;
51 case SMTP::InteractTimeout:
52 lstr = i18n("Time out waiting for server interaction.");
53 break;
54 default:
55 lstr = sm->getLastLine().trimmed();
56 lstr = i18n("Server said: \"%1\"", lstr);
57 }
58 kDebug() << lstr;
59
60 fputs(lstr.toUtf8().data(), stdout);
61 fflush(stdout);
62
63 qApp->exit(1);
64}
65
66void BugMailer::slotSend() {
67 kDebug();
68 qApp->exit(0);
69}
70
71int main(int argc, char **argv) {
72
73 KAboutData d("ksendbugmail", "kdelibs4", ki18n("KSendBugMail"), "1.0",
74 ki18n("Sends a bug report by email"),
75 KAboutData::License_GPL, ki18n("(c) 2000 Stephan Kulow"));
76 d.addAuthor(ki18n("Stephan Kulow"), ki18n("Author"), "coolo@kde.org");
77
78 KCmdLineOptions options;
79 options.add("subject <argument>", ki18n("Subject line"));
80 options.add("recipient <argument>", ki18n("Recipient"), "submit@bugs.kde.org");
81
82 KCmdLineArgs::init(argc, argv, &d);
83 KCmdLineArgs::addCmdLineOptions(options);
84 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
85
86 KApplication a(false);
87
88 QString recipient = args->getOption("recipient");
89 if (recipient.isEmpty())
90 recipient = "submit@bugs.kde.org";
91 else {
92 if (recipient.at(0) == '\'') {
93 recipient = recipient.mid(1).left(recipient.length() - 2);
94 }
95 }
96 kDebug() << "recp" << recipient;
97
98 QString subject = args->getOption("subject");
99 if (subject.isEmpty())
100 subject = "(no subject)";
101 else {
102 if (subject.at(0) == '\'')
103 subject = subject.mid(1).left(subject.length() - 2);
104 }
105 QTextStream input(stdin, QIODevice::ReadOnly);
106 input.setCodec("UTF-8");
107 QString text, line;
108 while (!input.atEnd()) {
109 line = input.readLine();
110 text += line + "\r\n";
111 }
112 kDebug() << text;
113
114 KEMailSettings emailConfig;
115 emailConfig.setProfile(emailConfig.defaultProfileName());
116 QString fromaddr = emailConfig.getSetting(KEMailSettings::EmailAddress);
117 if (!fromaddr.isEmpty()) {
118 QString name = emailConfig.getSetting(KEMailSettings::RealName);
119 if (!name.isEmpty())
120 fromaddr = name + QLatin1String(" <") + fromaddr + QString::fromLatin1(">");
121 } else {
122 struct passwd *p;
123 p = getpwuid(getuid());
124 fromaddr = QLatin1String(p->pw_name);
125 fromaddr += '@';
126 char buffer[256];
127 buffer[0] = '\0';
128 if(!gethostname(buffer, sizeof(buffer)))
129 buffer[sizeof(buffer)-1] = '\0';
130 fromaddr += buffer;
131 }
132 kDebug() << "fromaddr \"" << fromaddr << "\"";
133
134 QString server = emailConfig.getSetting(KEMailSettings::OutServer);
135 if (server.isEmpty())
136 server=QLatin1String("bugs.kde.org");
137
138 SMTP *sm = new SMTP;
139 BugMailer bm(sm);
140
141 QObject::connect(sm, SIGNAL(messageSent()), &bm, SLOT(slotSend()));
142 QObject::connect(sm, SIGNAL(error(int)), &bm, SLOT(slotError(int)));
143 sm->setServerHost(server);
144 sm->setPort(25);
145 sm->setSenderAddress(fromaddr);
146 sm->setRecipientAddress(recipient);
147 sm->setMessageSubject(subject);
148 sm->setMessageHeader(QString::fromLatin1("From: %1\r\nTo: %2\r\n").arg(fromaddr).arg(QString(recipient)));
149 sm->setMessageBody(text);
150 sm->sendMessage();
151
152 int r = a.exec();
153 kDebug() << "execing " << r;
154 delete sm;
155 return r;
156}
157
158#include "main.moc"
BugMailer
Definition: main.h:27
BugMailer::slotError
void slotError(int)
Definition: main.cpp:38
BugMailer::slotSend
void slotSend()
Definition: main.cpp:66
KAboutData
KAboutData::addAuthor
KAboutData & addAuthor(const KLocalizedString &name, const KLocalizedString &task, const QByteArray &emailAddress, const QByteArray &webAddress, const QByteArray &ocsUsername)
KAboutData::License_GPL
License_GPL
KApplication
KCmdLineArgs
KCmdLineArgs::init
static void init(const KAboutData *about)
KCmdLineArgs::parsedArgs
static KCmdLineArgs * parsedArgs(const QByteArray &id=QByteArray())
KCmdLineArgs::addCmdLineOptions
static void addCmdLineOptions(const KCmdLineOptions &options, const KLocalizedString &name=KLocalizedString(), const QByteArray &id=QByteArray(), const QByteArray &afterId=QByteArray())
KCmdLineArgs::getOption
QString getOption(const QByteArray &option) const
KCmdLineOptions
KCmdLineOptions::add
KCmdLineOptions & add(const KCmdLineOptions &options)
KEMailSettings
This is just a small class to facilitate accessing e-mail settings in a sane way, and allowing any pr...
Definition: kemailsettings.h:46
KEMailSettings::getSetting
QString getSetting(KEMailSettings::Setting s) const
Get one of the predefined "basic" settings.
Definition: kemailsettings.cpp:48
KEMailSettings::setProfile
void setProfile(const QString &s)
Change the current profile.
Definition: kemailsettings.cpp:215
KEMailSettings::defaultProfileName
QString defaultProfileName() const
Returns the name of the default profile.
Definition: kemailsettings.cpp:43
KEMailSettings::RealName
@ RealName
Definition: kemailsettings.h:60
KEMailSettings::EmailAddress
@ EmailAddress
Definition: kemailsettings.h:61
KEMailSettings::OutServer
@ OutServer
Definition: kemailsettings.h:64
SMTP
Definition: smtp.h:58
SMTP::setMessageSubject
void setMessageSubject(const QString &subject)
Definition: smtp.cpp:118
SMTP::setMessageBody
void setMessageBody(const QString &message)
Definition: smtp.cpp:123
SMTP::setSenderAddress
void setSenderAddress(const QString &sender)
Definition: smtp.cpp:89
SMTP::sendMessage
void sendMessage()
Definition: smtp.cpp:145
SMTP::setServerHost
void setServerHost(const QString &serverhost)
Definition: smtp.cpp:74
SMTP::setRecipientAddress
void setRecipientAddress(const QString &recipient)
Definition: smtp.cpp:113
SMTP::InteractTimeout
@ InteractTimeout
Definition: smtp.h:107
SMTP::NotConnected
@ NotConnected
Definition: smtp.h:105
SMTP::ConnectError
@ ConnectError
Definition: smtp.h:104
SMTP::ConnectTimeout
@ ConnectTimeout
Definition: smtp.h:106
SMTP::getLastLine
QString getLastLine()
Definition: smtp.h:71
SMTP::setMessageHeader
void setMessageHeader(const QString &header)
Definition: smtp.cpp:128
SMTP::setPort
void setPort(unsigned short int port)
Definition: smtp.cpp:79
kDebug
#define kDebug
kaboutdata.h
kapplication.h
kcmdlineargs.h
kconfig.h
kdebug.h
kemailsettings.h
klocale.h
ki18n
KLocalizedString ki18n(const char *msg)
i18n
QString i18n(const char *text)
main
int main(int argc, char **argv)
Definition: main.cpp:71
main.h
name
const char * name(StandardAction id)
smtp.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal