• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KIO

main.cpp

Go to the documentation of this file.
00001 /*
00002    Copyright (c) 2000 Bernd Johannes Wuebben <wuebben@math.cornell.edu>
00003    Copyright (c) 2000 Stephan Kulow <coolo@kde.org>
00004 
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 2, or (at your option)
00008    any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 
00020 #include "main.h"
00021 #include <sys/types.h>
00022 #include <pwd.h>
00023 #include <stdlib.h>
00024 #include <unistd.h>
00025 
00026 #include <QtCore/QTextStream>
00027 
00028 #include <kapplication.h>
00029 #include <kemailsettings.h>
00030 #include <klocale.h>
00031 #include <kcmdlineargs.h>
00032 #include <kaboutdata.h>
00033 #include <kdebug.h>
00034 #include <kconfig.h>
00035 
00036 #include "smtp.h"
00037 
00038 void BugMailer::slotError(int errornum) {
00039     QString lstr;
00040 
00041     switch(errornum) {
00042         case SMTP::ConnectError:
00043             lstr = i18n("Error connecting to server.");
00044             break;
00045         case SMTP::NotConnected:
00046             lstr = i18n("Not connected.");
00047             break;
00048         case SMTP::ConnectTimeout:
00049             lstr = i18n("Connection timed out.");
00050             break;
00051         case SMTP::InteractTimeout:
00052             lstr = i18n("Time out waiting for server interaction.");
00053             break;
00054         default:
00055             lstr = sm->getLastLine().trimmed();
00056             lstr = i18n("Server said: \"%1\"", lstr);
00057     }
00058     kDebug() << lstr;
00059 
00060     fputs(lstr.toUtf8().data(), stdout);
00061     fflush(stdout);
00062 
00063     qApp->exit(1);
00064 }
00065 
00066 void BugMailer::slotSend() {
00067     kDebug();
00068     qApp->exit(0);
00069 }
00070 
00071 int main(int argc, char **argv) {
00072 
00073     KAboutData d("ksendbugmail", "kdelibs4", ki18n("KSendBugMail"), "1.0",
00074                  ki18n("Sends a bug report by email"),
00075                  KAboutData::License_GPL, ki18n("(c) 2000 Stephan Kulow"));
00076     d.addAuthor(ki18n("Stephan Kulow"), ki18n("Author"), "coolo@kde.org");
00077 
00078     KCmdLineOptions options;
00079     options.add("subject <argument>", ki18n("Subject line"));
00080     options.add("recipient <argument>", ki18n("Recipient"), "submit@bugs.kde.org");
00081 
00082     KCmdLineArgs::init(argc, argv, &d);
00083     KCmdLineArgs::addCmdLineOptions(options);
00084     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00085 
00086     KApplication a(false);
00087 
00088     QString recipient = args->getOption("recipient");
00089     if (recipient.isEmpty())
00090         recipient = "submit@bugs.kde.org";
00091     else {
00092         if (recipient.at(0) == '\'') {
00093             recipient = recipient.mid(1).left(recipient.length() - 2);
00094         }
00095     }
00096     kDebug() << "recp" << recipient;
00097 
00098     QString subject = args->getOption("subject");
00099     if (subject.isEmpty())
00100         subject = "(no subject)";
00101     else {
00102         if (subject.at(0) == '\'')
00103             subject = subject.mid(1).left(subject.length() - 2);
00104     }
00105     QTextStream input(stdin, QIODevice::ReadOnly);
00106     QString text, line;
00107     while (!input.atEnd()) {
00108         line = input.readLine();
00109         text += line + "\r\n";
00110     }
00111     kDebug() << text;
00112 
00113     KEMailSettings emailConfig;
00114     emailConfig.setProfile(emailConfig.defaultProfileName());
00115     QString fromaddr = emailConfig.getSetting(KEMailSettings::EmailAddress);
00116     if (!fromaddr.isEmpty()) {
00117         QString name = emailConfig.getSetting(KEMailSettings::RealName);
00118         if (!name.isEmpty())
00119             fromaddr = name + QLatin1String(" <") + fromaddr + QString::fromLatin1(">");
00120     } else {
00121         struct passwd *p;
00122         p = getpwuid(getuid());
00123         fromaddr = QLatin1String(p->pw_name);
00124         fromaddr += '@';
00125         char buffer[256];
00126     buffer[0] = '\0';
00127         if(!gethostname(buffer, sizeof(buffer)))
00128         buffer[sizeof(buffer)-1] = '\0';
00129         fromaddr += buffer;
00130     }
00131     kDebug() << "fromaddr \"" << fromaddr << "\"";
00132 
00133     QString  server = emailConfig.getSetting(KEMailSettings::OutServer);
00134     if (server.isEmpty())
00135         server=QLatin1String("bugs.kde.org");
00136 
00137     SMTP *sm = new SMTP;
00138     BugMailer bm(sm);
00139 
00140     QObject::connect(sm, SIGNAL(messageSent()), &bm, SLOT(slotSend()));
00141     QObject::connect(sm, SIGNAL(error(int)), &bm, SLOT(slotError(int)));
00142     sm->setServerHost(server);
00143     sm->setPort(25);
00144     sm->setSenderAddress(fromaddr);
00145     sm->setRecipientAddress(recipient);
00146     sm->setMessageSubject(subject);
00147     sm->setMessageHeader(QString::fromLatin1("From: %1\r\nTo: %2\r\n").arg(fromaddr).arg(QString(recipient)));
00148     sm->setMessageBody(text);
00149     sm->sendMessage();
00150 
00151     int r = a.exec();
00152     kDebug() << "execing " << r;
00153     delete sm;
00154     return r;
00155 }
00156 
00157 #include "main.moc"

KIO

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal