| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# main.cpp

    00001 // $Id: main.cpp,v 1.10 2001/10/10 17:40:41 mueller Exp $
    00002
    00003 #include <sys/types.h>
    00004 #include <main.h>
    00005 #include <pwd.h>
    00006 #include <stdlib.h>
    00007 #include <unistd.h>
    00008
    00009 #include <qtextstream.h>
    00010
    00011 #include <kapplication.h>
    00012 #include <kemailsettings.h>
    00013 #include <klocale.h>
    00014 #include <kcmdlineargs.h>
    00015 #include <kaboutdata.h>
    00016 #include <kdebug.h>
    00017 #include <kconfig.h>
    00018
    00019 #include <smtp.h>
    00020
    00021 static KCmdLineOptions options[] = {
    00022     { "subject <argument>", I18N_NOOP("Subject line"), 0 },
    00023     { "recipient <argument>", I18N_NOOP("Recipient"), "submit@bugs.kde.org" },
    00024     { 0, 0, 0 }
    00025 };
    00026
    00027 void BugMailer::slotError(int errornum) {
    00028     kdDebug() << "slotError\n";
    00029     QString str, lstr;
    00030
    00031     switch(errornum) {
    00032         case SMTP::CONNECTERROR:
    00033             lstr = i18n("Error connecting to server.");
    00034             break;
    00035         case SMTP::NOTCONNECTED:
    00036             lstr = i18n("Not connected.");
    00037             break;
    00038         case SMTP::CONNECTTIMEOUT:
    00039             lstr = i18n("Connection timed out.");
    00040             break;
    00041         case SMTP::INTERACTTIMEOUT:
    00042             lstr = i18n("Time out waiting for server interaction.");
    00043             break;
    00044         default:
    00045             lstr = sm->getLastLine().stripWhiteSpace();
    00046             lstr = i18n("Server said: \"%1\"").arg(lstr);
    00047     }
    00048     fputs(lstr.utf8().data(), stdout);
    00049     fflush(stdout);
    00050
    00051     ::exit(1);
    00052 }
    00053
    00054 void BugMailer::slotSend() {
    00055     kdDebug() << "slotSend\n";
    00056     ::exit(0);
    00057 }
    00058
    00059 int main(int argc, char **argv) {
    00060
    00061     KLocale::setMainCatalogue("kdelibs");
    00062     KAboutData d("ksendbugmail", I18N_NOOP("KSendBugMail"), "1.0",
    00063                  I18N_NOOP("Sends a short bug report to submit@bugs.kde.org"),
    00064                  KAboutData::License_GPL, "(c) 2000 Stephan Kulow");
    00065     d.addAuthor("Stephan Kulow", I18N_NOOP("Author"), "coolo@kde.org");
    00066
    00067     KCmdLineArgs::init(argc, argv, &d);
    00068     KCmdLineArgs::addCmdLineOptions(options);
    00069     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    00070
    00071     KApplication a(false, false);
    00072
    00073     QCString recipient = args->getOption("recipient");
    00074     if (recipient.isEmpty())
    00075         recipient = "submit@bugs.kde.org";
    00076     else {
    00077         if (recipient.at(0) == '\'') {
    00078             recipient = recipient.mid(1).left(recipient.length() - 2);
    00079         }
    00080     }
    00081     kdDebug() << "recp \"" << recipient << "\"\n";
    00082
    00083     QCString subject = args->getOption("subject");
    00084     if (subject.isEmpty())
    00085         subject = "(no subject)";
    00086     else {
    00087         if (subject.at(0) == '\'')
    00088             subject = subject.mid(1).left(subject.length() - 2);
    00089     }
    00090     QTextIStream input(stdin);
    00091     QString text, line;
    00092     while (!input.eof()) {
    00093         line = input.readLine();
    00094         text += line + "\r\n";
    00095     }
    00096     kdDebug() << text << endl;
    00097
    00098     KEMailSettings emailConfig;
    00099     emailConfig.setProfile(emailConfig.defaultProfileName());
    00100     QString fromaddr = emailConfig.getSetting(KEMailSettings::EmailAddress);
    00101     if (!fromaddr.isEmpty()) {
    00102         QString name = emailConfig.getSetting(KEMailSettings::RealName);
    00103         if (!name.isEmpty())
    00104             fromaddr = name + QString::fromLatin1(" <") + fromaddr + QString::fromLatin1(">");
    00105     } else {
    00106         struct passwd *p;
    00107         p = getpwuid(getuid());
    00108         fromaddr = QString::fromLatin1(p->pw_name);
    00109         fromaddr += "@";
    00110         char buffer[200];
    00111         gethostname(buffer, 200);
    00112         fromaddr += buffer;
    00113     }
    00114     kdDebug() << "fromaddr \"" << fromaddr << "\"" << endl;
    00115
    00116     QString  server = emailConfig.getSetting(KEMailSettings::OutServer);
    00117     if (server.isEmpty())
    00118         server=QString::fromLatin1("bugs.kde.org");
    00119
    00120     SMTP *sm = new SMTP;
    00121     BugMailer bm(sm);
    00122
    00123     QObject::connect(sm, SIGNAL(messageSent()), &bm, SLOT(slotSend()));
    00124     QObject::connect(sm, SIGNAL(error(int)), &bm, SLOT(slotError(int)));
    00125     sm->setServerHost(server);
    00126     sm->setPort(25);
    00127     sm->setSenderAddress(fromaddr);
    00128     sm->setRecipientAddress(recipient);
    00129     sm->setMessageSubject(subject);
    00130     sm->setMessageHeader(QString::fromLatin1("From: %1\r\nTo: %2\r\n").arg(fromaddr).arg(recipient));
    00131     sm->setMessageBody(text);
    00132     sm->sendMessage();
    00133
    00134     int r = a.exec();
    00135     kdDebug() << "execing " << r << endl;
    00136     delete sm;
    00137     return r;
    00138 }
    00139
    00140 #include "main.moc"

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:14:35 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001