KXmlGui

smtp.h
1 /*
2  SPDX-FileCopyrightText: 2000 Bernd Johannes Wuebben <[email protected]>
3  SPDX-FileCopyrightText: 2000 Stephan Kulow <[email protected]>
4 
5  SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #ifndef SMTP_H
9 #define SMTP_H
10 
11 #include <QObject>
12 #include <QTimer>
13 #include <QTcpSocket>
14 
15 /*int SMTPServerStatus[] = {
16  220, // greeting from server
17  221, // server acknolages goodbye
18  250, // command successful
19  354, // ready to receive data
20  501, // error
21  550, // user unknown
22  0 // null
23 };
24 
25 int SMTPClientStatus[] = {
26  50, // not logged in yet.
27  100, // logged in, got 220
28  150, // sent helo, got 250
29  200, // sent mail from, got 250
30  250, // sent rctp to, got 250
31  300, // data sent, got 354
32  350, // sent data/., got 250
33  400, // send quit, got 221
34  450, // finished, logged out
35  0 // null
36 };
37 */
38 
39 #define DEFAULT_SMTP_PORT 25
40 #define DEFAULT_SMTP_SERVER localhost
41 #define DEFAULT_SMTP_TIMEOUT 60
42 
43 #define SMTP_READ_BUFFER_SIZE 256
44 
45 class SMTP: public QObject
46 {
47  Q_OBJECT
48 public:
49  explicit SMTP(char *serverhost = nullptr, unsigned short int port = 0,
50  int timeout = DEFAULT_SMTP_TIMEOUT);
51  ~SMTP();
52 
53  void setServerHost(const QString &serverhost);
54  void setPort(unsigned short int port);
55  void setTimeOut(int timeout);
56 
57  bool isConnected() const
58  {
59  return connected;
60  }
61  bool isFinished() const
62  {
63  return finished;
64  }
65  QByteArray getLastLine() const
66  {
67  return lastLine;
68  }
69 
70  void setSenderAddress(const QString &sender);
71  void setRecipientAddress(const QString &recipient);
72  void setMessageSubject(const QString &subject);
73  void setMessageBody(const QString &message);
74  void setMessageHeader(const QString &header);
75 
76  typedef enum {
77  None = 0, // null
78  Greet = 220, // greeting from server
79  Goodbye = 221, // server acknolages quit
80  Successful = 250, // command successful
81  ReadyData = 354, // server ready to receive data
82  Error = 501, // error
83  Unknown = 550 // user unknown
84  } SMTPServerStatus;
85 
86  typedef enum {
87  Init = 50, // not logged in yet
88  In = 100, // logged in, got 220
89  Ready = 150, // sent HELO, got 250
90  SentFrom = 200, // sent MAIL FROM:, got 250
91  SentTo = 250, // sent RCTP TO:, got 250
92  Data = 300, // Data sent, got 354
93  Finished = 350, // finished sending data, got 250
94  Quit = 400, // sent Quit, got 221
95  Out = 450, // finished, logged out
96  CError = 500 // didn't finish, had error or connection drop
97  } SMTPClientStatus;
98 
99  typedef enum {
100  NoError = 0,
101  ConnectError = 10,
102  NotConnected = 11,
103  ConnectTimeout = 15,
104  InteractTimeout = 16,
105  UnknownResponse = 20,
106  UnknownUser = 30,
107  Command = 40
108  } SMTPError;
109 
110 protected:
111  void processLine(QByteArray *line);
112 
113 public Q_SLOTS:
114  void openConnection();
115  void sendMessage();
116  void closeConnection();
117 
118  void connectTimerTick();
119  void connectTimedOut();
120  void interactTimedOut();
121 
122  void socketReadyToRead();
123  void socketClosed();
124  void socketError(QAbstractSocket::SocketError);
125 
126 Q_SIGNALS:
127  void connectionClosed();
128  void messageSent();
129  void error(int);
130 
131 private:
132  QString serverHost;
133  unsigned short int hostPort;
134  int timeOut;
135 
136  bool connected;
137  bool finished;
138 
139  QString senderAddress;
140  QString recipientAddress;
141  QString messageSubject;
142  QString messageBody, messageHeader;
143 
144  SMTPClientStatus state;
145  SMTPClientStatus lastState;
146  SMTPServerStatus serverState;
147 
148  QString domainName;
149 
150  QTcpSocket *sock;
151  QTimer connectTimer;
152  QTimer timeOutTimer;
153  QTimer interactTimer;
154 
155  char readBuffer[SMTP_READ_BUFFER_SIZE];
156  QByteArray lineBuffer;
157  QByteArray lastLine;
158  QString writeString;
159 };
160 #endif
Q_SIGNALSQ_SIGNALS
Q_OBJECTQ_OBJECT
void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Aug 12 2020 22:50:46 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.