• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.4 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 
38 void 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 
66 void BugMailer::slotSend() {
67  kDebug();
68  qApp->exit(0);
69 }
70 
71 int 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"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jun 1 2013 22:01:51 by doxygen 1.8.3.1 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.10.4 API Reference

Skip menu "kdelibs-4.10.4 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